Skip to content

Commit

Permalink
Merge branch 'attendee_fixes' into 'master'
Browse files Browse the repository at this point in the history
Attendee fixes

See merge request mer-core/mkcal!18
  • Loading branch information
pvuorela committed May 28, 2019
2 parents 7956707 + c6e9cd2 commit 2fe6c0c
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 75 deletions.
35 changes: 15 additions & 20 deletions plugins/defaultinvitationplugin/defaultinvitationplugin.cpp
Expand Up @@ -205,11 +205,9 @@ DefaultInvitationPlugin::~DefaultInvitationPlugin()
delete d;
}


bool DefaultInvitationPlugin::sendInvitation(const QString &accountId, const QString &notebookUid,
const Incidence::Ptr &invitation, const QString &body)
{

Q_UNUSED(body);
Q_UNUSED(notebookUid);

Expand Down Expand Up @@ -254,21 +252,22 @@ bool DefaultInvitationPlugin::sendUpdate(const QString &accountId, const Inciden

ICalFormat icf;
const QString remoteUidValue(invitation->nonKDECustomProperty("X-SAILFISHOS-REMOTE-UID"));
const bool cancelled = invitation->status() == Incidence::StatusCanceled;

Incidence::Ptr invitationCopy = Incidence::Ptr(invitation->clone());
if (!remoteUidValue.isEmpty()) {
invitation->setUid(remoteUidValue);
invitationCopy->setUid(remoteUidValue);
}
const bool cancelled = invitation->status() == Incidence::StatusCanceled;
const QString &ical = icf.createScheduleMessage(invitation, cancelled ? iTIPCancel : iTIPRefresh);
const QString &ical = icf.createScheduleMessage(invitationCopy, cancelled ? iTIPCancel : iTIPRequest);

QStringList emails;
foreach (const Attendee::Ptr &att, attendees) {
emails.append(att->email());
}

const QString &description = invitation->description();
const bool res = d->sendMail(accountId, emails, invitation->summary(), description, ical, cancelled);
const QString &description = invitationCopy->description();
const bool res = d->sendMail(accountId, emails, invitationCopy->summary(), description, ical, cancelled);

invitation->resetDirtyFields();
d->uninit();
return res;
}
Expand Down Expand Up @@ -297,17 +296,17 @@ bool DefaultInvitationPlugin::sendResponse(const QString &accountId, const Incid

ICalFormat icf;
const QString remoteUidValue(invitation->nonKDECustomProperty("X-SAILFISHOS-REMOTE-UID"));

Incidence::Ptr invitationCopy = Incidence::Ptr(invitation->clone());
if (!remoteUidValue.isEmpty()) {
invitation->setUid(remoteUidValue);
invitationCopy->setUid(remoteUidValue);
}

const QString &ical = icf.createScheduleMessage(invitation, iTIPReply) ;
const QString &ical = icf.createScheduleMessage(invitationCopy, iTIPReply);

bool res = d->sendMail(accountId, QStringList(organizer->email()), invitation->summary(), body, ical, false);
bool res = d->sendMail(accountId, QStringList(organizer->email()), invitationCopy->summary(), body, ical, false);

invitation->resetDirtyFields();
return res;

}

QString DefaultInvitationPlugin::pluginName() const
Expand All @@ -334,7 +333,6 @@ bool DefaultInvitationPlugin::multiCalendar() const

QString DefaultInvitationPlugin::emailAddress(const mKCal::Notebook::Ptr &notebook)
{
QString email;
if (notebook.isNull()) {
qCritical() << "Invalid notebook";
return QString();
Expand All @@ -343,10 +341,9 @@ QString DefaultInvitationPlugin::emailAddress(const mKCal::Notebook::Ptr &notebo
// just return quietly, it can be a local notebook
return QString();
}
email = d->accountEmailAddress(notebook->account());
if (!email.isEmpty()) {
qDebug() << "Using account email address" << email;
} else {

QString email = d->accountEmailAddress(notebook->account());
if (email.isEmpty()) {
qWarning() << "Notebook" << notebook->uid() << "do not have a valid account email address";
d->init();
email = d->defaultAddress();
Expand All @@ -368,7 +365,6 @@ bool DefaultInvitationPlugin::downloadAttachment(const mKCal::Notebook::Ptr &not
Q_UNUSED(path);
d->mErrorCode = ServiceInterface::ErrorNotSupported;
return false;

}

bool DefaultInvitationPlugin::deleteAttachment(const mKCal::Notebook::Ptr &notebook, const Incidence::Ptr &incidence,
Expand All @@ -379,7 +375,6 @@ bool DefaultInvitationPlugin::deleteAttachment(const mKCal::Notebook::Ptr &noteb
Q_UNUSED(uri);
d->mErrorCode = ServiceInterface::ErrorNotSupported;
return false;

}

bool DefaultInvitationPlugin::shareNotebook(const mKCal::Notebook::Ptr &notebook, const QStringList &sharedWith)
Expand Down
18 changes: 1 addition & 17 deletions src/extendedstorage.h
Expand Up @@ -58,23 +58,7 @@ enum DBOperation {
DBInsert,
DBUpdate,
DBDelete,
DBSelect,
DBSelectPlain,
DBSelectGeo,
DBSelectRecurring,
DBSelectAttendee
};

enum StorageOperation {
StorageNone = 0,
StorageOpen,
StorageLoad,
StorageSave,
StorageInserted,
StorageModified,
StorageDeleted,
StorageAll,
StorageDuplicate
DBSelect
};

// Default alarm receiver is the organiser application.
Expand Down
71 changes: 42 additions & 29 deletions src/servicehandler.cpp
Expand Up @@ -37,8 +37,9 @@ class ServiceHandlerPrivate
ServiceHandler::ErrorCode mError;

void loadPlugins();
bool executePlugin(ExecutedPlugin action, const Incidence::Ptr &invitation, const QString body,
const ExtendedCalendar::Ptr &calendar, const ExtendedStorage::Ptr &storage);
bool executePlugin(ExecutedPlugin action, const Incidence::Ptr &invitation, const QString &body,
const ExtendedCalendar::Ptr &calendar, const ExtendedStorage::Ptr &storage,
const Notebook::Ptr &notebook);
ServiceInterface *getServicePlugin(const Notebook::Ptr &notebook, const ExtendedStorage::Ptr &storage);

ServiceHandlerPrivate();
Expand Down Expand Up @@ -79,33 +80,47 @@ void ServiceHandlerPrivate::loadPlugins()
mLoaded = true;
}

bool ServiceHandlerPrivate::executePlugin(ExecutedPlugin action, const Incidence::Ptr &invitation, const QString body,
const ExtendedCalendar::Ptr &calendar, const ExtendedStorage::Ptr &storage)
bool ServiceHandlerPrivate::executePlugin(ExecutedPlugin action, const Incidence::Ptr &invitation, const QString &body,
const ExtendedCalendar::Ptr &calendar, const ExtendedStorage::Ptr &storage,
const Notebook::Ptr &notebook)
{
if (storage.isNull() || invitation.isNull() || calendar.isNull())
return false;

if (!mLoaded)
loadPlugins();

if (storage.isNull() || invitation.isNull() || calendar.isNull())
return false;
Notebook::Ptr accountNotebook;
QString notebookUid;

QString pluginName;
QString accountId;
if (!notebook.isNull()) {
accountNotebook = notebook;
notebookUid = notebook->uid();
} else {
notebookUid = calendar->notebook(invitation);
if (storage->isValidNotebook(notebookUid)) {
accountNotebook = storage->notebook(notebookUid);
}
}

QString notebookUid = calendar->notebook(invitation);
if (storage->isValidNotebook(notebookUid)) {
pluginName = storage->notebook(notebookUid)->pluginName();
accountId = storage->notebook(notebookUid)->account();
if (accountNotebook.isNull()) {
kWarning() << "No notebook available for invitation plugin to use";
return false;
}

QString pluginName = accountNotebook->pluginName();
QString accountId = accountNotebook->account() ;

if (pluginName.isEmpty() || !mPlugins.contains(pluginName))
pluginName = defaultName;

kDebug() << "Using plugin:" << pluginName;

QHash<QString, InvitationHandlerInterface *>::const_iterator i;
i = mPlugins.find(pluginName);
QHash<QString, InvitationHandlerInterface *>::const_iterator i = mPlugins.find(pluginName);

if (i != mPlugins.end()) {
// service needed to get possible error, because
// invitationhandlerinterface does'n have error-function
// invitationhandlerinterface doesn't have error-function
QHash<QString, ServiceInterface *>::const_iterator is = mServices.find(pluginName);

switch (action) {
Expand Down Expand Up @@ -162,8 +177,7 @@ ServiceInterface *ServiceHandlerPrivate::getServicePlugin(const Notebook::Ptr &n

kDebug() << "Using service:" << name;

QHash<QString, ServiceInterface *>::const_iterator i;
i = mServices.find(name);
QHash<QString, ServiceInterface *>::const_iterator i = mServices.find(name);

if (i != mServices.end()) {
return i.value();
Expand All @@ -178,32 +192,35 @@ ServiceHandler::ServiceHandler()
}

bool ServiceHandler::sendInvitation(const Incidence::Ptr &invitation, const QString &body,
const ExtendedCalendar::Ptr &calendar, const ExtendedStorage::Ptr &storage)
const ExtendedCalendar::Ptr &calendar, const ExtendedStorage::Ptr &storage,
const Notebook::Ptr &notebook)
{
if (storage.isNull() || invitation.isNull() || calendar.isNull())
return false;

return d->executePlugin(SendInvitation, invitation, body, calendar, storage);
return d->executePlugin(SendInvitation, invitation, body, calendar, storage, notebook);
}


bool ServiceHandler::sendUpdate(const Incidence::Ptr &invitation, const QString &body,
const ExtendedCalendar::Ptr &calendar, const ExtendedStorage::Ptr &storage)
const ExtendedCalendar::Ptr &calendar, const ExtendedStorage::Ptr &storage,
const Notebook::Ptr &notebook)
{
if (storage.isNull() || invitation.isNull() || calendar.isNull())
return false;

return d->executePlugin(SendUpdate, invitation, body, calendar, storage);
return d->executePlugin(SendUpdate, invitation, body, calendar, storage, notebook);
}


bool ServiceHandler::sendResponse(const Incidence::Ptr &invitation, const QString &body,
const ExtendedCalendar::Ptr &calendar, const ExtendedStorage::Ptr &storage)
const ExtendedCalendar::Ptr &calendar, const ExtendedStorage::Ptr &storage,
const Notebook::Ptr &notebook)
{
if (storage.isNull() || invitation.isNull() || calendar.isNull())
return false;

return d->executePlugin(SendResponse, invitation, body, calendar, storage);
return d->executePlugin(SendResponse, invitation, body, calendar, storage, notebook);
}

QString ServiceHandler::icon(const Notebook::Ptr &notebook, const ExtendedStorage::Ptr &storage)
Expand Down Expand Up @@ -360,7 +377,6 @@ QString ServiceHandler::defaultNotebook(const QString &productId)
Q_UNUSED(productId);

return QString(); //Empty implementation so far

}

QStringList ServiceHandler::availableServices()
Expand All @@ -374,16 +390,14 @@ QStringList ServiceHandler::availableServices()
}

return result;

}

QString ServiceHandler::icon(QString serviceId)
{
if (!d->mLoaded)
d->loadPlugins();

QHash<QString, ServiceInterface *>::const_iterator i;
i = d->mServices.find(serviceId);
QHash<QString, ServiceInterface *>::const_iterator i = d->mServices.find(serviceId);

if (i != d->mServices.end()) {
return i.value()->icon();
Expand All @@ -397,8 +411,7 @@ QString ServiceHandler::uiName(QString serviceId)
if (!d->mLoaded)
d->loadPlugins();

QHash<QString, ServiceInterface *>::const_iterator i;
i = d->mServices.find(serviceId);
QHash<QString, ServiceInterface *>::const_iterator i = d->mServices.find(serviceId);

if (i != d->mServices.end()) {
return i.value()->uiName();
Expand Down
15 changes: 8 additions & 7 deletions src/servicehandler.h
Expand Up @@ -36,7 +36,6 @@ class ServiceHandlerPrivate;

namespace mKCal {


/** Singleton class to get the exact handler (plugin) of the service
*/
class MKCAL_EXPORT ServiceHandler : QObject
Expand Down Expand Up @@ -81,10 +80,12 @@ class MKCAL_EXPORT ServiceHandler : QObject
@param body The body of the reply if any
@param calendar Pointer to the calendar in use
@param storage Pointer to the storage in use
@param notebook Optional notebook to use for account info
@return True if OK, false in case of error
*/
bool sendInvitation(const KCalCore::Incidence::Ptr &invitation, const QString &body,
const ExtendedCalendar::Ptr &calendar, const ExtendedStorage::Ptr &storage);
const ExtendedCalendar::Ptr &calendar, const ExtendedStorage::Ptr &storage,
const Notebook::Ptr &notebook = Notebook::Ptr());

/** Send the updated invitation to the list of people stated as attendees.
It would load the appropriate plugin to do it, and if there
Expand All @@ -93,10 +94,11 @@ class MKCAL_EXPORT ServiceHandler : QObject
@param body The body of the reply if any
@param calendar Pointer to the calendar in use
@param storage Pointer to the storage in use
@param notebook Optional notebook to use for account info
@return True if OK, false in case of error
*/
bool sendUpdate(const KCalCore::Incidence::Ptr &invitation, const QString &body, const ExtendedCalendar::Ptr &calendar,
const ExtendedStorage::Ptr &storage);
const ExtendedStorage::Ptr &storage, const Notebook::Ptr &notebook = Notebook::Ptr());

/** Send the updated invitation to the organiser.
It would load the appropriate plugin to do it, and if there
Expand All @@ -105,10 +107,12 @@ class MKCAL_EXPORT ServiceHandler : QObject
@param body The body of the reply if any
@param calendar Pointer to the calendar in use
@param storage Pointer to the storage in use
@param notebook Optional notebook to use for account info
@return True if OK, false in case of error
*/
bool sendResponse(const KCalCore::Incidence::Ptr &invitation, const QString &body,
const ExtendedCalendar::Ptr &calendar, const ExtendedStorage::Ptr &storage);
const ExtendedCalendar::Ptr &calendar, const ExtendedStorage::Ptr &storage,
const Notebook::Ptr &notebook = Notebook::Ptr());

/** Icon
It would load the appropriate plugin to do it
Expand Down Expand Up @@ -212,7 +216,6 @@ class MKCAL_EXPORT ServiceHandler : QObject
*/
QStringList availableServices();


/** \brief Get the Icon of a service based on the id of the plugin
@return Path to the icon
Expand All @@ -230,7 +233,6 @@ class MKCAL_EXPORT ServiceHandler : QObject
QString uiName(QString serviceId);

signals:

/** Monitors the progress of the download. The id is the return value got when download started */
void downloadProgress(int id, int percentage);

Expand All @@ -239,7 +241,6 @@ class MKCAL_EXPORT ServiceHandler : QObject

/** Informs that the download is finished with errors. The id is the return value got when download started */
void downloadError(int id, ErrorCode error);

};

}
Expand Down
17 changes: 15 additions & 2 deletions src/sqliteformat.cpp
Expand Up @@ -968,9 +968,13 @@ bool SqliteFormat::Private::modifyAttendees(Incidence::Ptr incidence, int rowid,
}

if (success && dbop != DBDelete) {
// FIXME: this doesn't fully save and restore attendees as they were set.
// e.g. has constraints that every attendee must have email and they need to be unique among the attendees.
// also this forces attendee list to include the organizer.
QString organizerEmail;
if (!incidence->organizer()->isEmpty()) {
Attendee::Ptr organizer = Attendee::Ptr(new Attendee(incidence->organizer()->name(),
incidence->organizer()->email()));
organizerEmail = incidence->organizer()->email();
Attendee::Ptr organizer = Attendee::Ptr(new Attendee(incidence->organizer()->name(), organizerEmail));
if (!modifyAttendee(rowid, organizer,
(dbop == DBUpdate ? DBInsert : dbop), stmt2, true)) {
kError() << "failed to modify organizer for incidence" << incidence->uid();
Expand All @@ -980,6 +984,12 @@ bool SqliteFormat::Private::modifyAttendees(Incidence::Ptr incidence, int rowid,
const Attendee::List &list = incidence->attendees();
Attendee::List::ConstIterator it;
for (it = list.begin(); it != list.end(); ++it) {
if ((*it)->email().isEmpty()) {
kWarning() << "Attendee doesn't have an email address";
continue;
} else if ((*it)->email() == organizerEmail) {
continue; // already added above
}
if (!modifyAttendee(rowid, *it, (dbop == DBUpdate ? DBInsert : dbop), stmt2, false)) {
kError() << "failed to modify attendee for incidence" << incidence->uid();
success = false;
Expand Down Expand Up @@ -1030,6 +1040,9 @@ bool SqliteFormat::Private::modifyAttendee(int rowid, Attendee::Ptr attendee, DB
success = true;

error:
if (!success) {
kWarning() << "Sqlite error:" << sqlite3_errmsg(mDatabase);
}
sqlite3_reset(stmt);

return success;
Expand Down

0 comments on commit 2fe6c0c

Please sign in to comment.