Skip to content

Commit

Permalink
[mkcal] Distinguish deletion from database and marked as deleted. Con…
Browse files Browse the repository at this point in the history
…tributes to MER#2070
  • Loading branch information
dcaliste committed Dec 13, 2019
1 parent 9e4ec96 commit 80d8b63
Show file tree
Hide file tree
Showing 8 changed files with 294 additions and 37 deletions.
2 changes: 1 addition & 1 deletion rpm/mkcal-qt5.spec
@@ -1,7 +1,7 @@
Name: mkcal-qt5

Summary: Extended KDE kcal calendar library port for Maemo
Version: 0.4.8
Version: 0.5.9
Release: 2
Group: System/Libraries
License: LGPLv2+
Expand Down
2 changes: 1 addition & 1 deletion src/extendedstorage.cpp
Expand Up @@ -428,7 +428,7 @@ bool ExtendedStorage::deleteNotebook(const Notebook::Ptr &nb, bool onlyMemory)
calendar()->deleteIncidence(toDelete);
}
if (!list.isEmpty()) {
save();
save(ExtendedStorage::PurgeDeleted);
}
} else {
qCWarning(lcMkcal) << "error when loading incidences for notebook" << nb->uid();
Expand Down
31 changes: 30 additions & 1 deletion src/extendedstorage.h
Expand Up @@ -57,6 +57,7 @@ enum DBOperation {
DBNone,
DBInsert,
DBUpdate,
DBMarkDeleted,
DBDelete,
DBSelect
};
Expand All @@ -81,6 +82,14 @@ class MKCAL_EXPORT ExtendedStorage

public:

/**
Action to be performed on save for deleted incidences.
*/
enum DeleteAction {
MarkDeleted,
PurgeDeleted
};

/**
A shared pointer to a ExtendedStorage
*/
Expand All @@ -97,7 +106,7 @@ class MKCAL_EXPORT ExtendedStorage
it can dead lock. If you do so, be ready to destroy it manually before the
application closes.
@warning Once an Incidende has been added to the ExtendedStorage the UID
@warning Once an Incidence has been added to the ExtendedStorage the UID
cannot change. It is possible to do so through the API, but the internal
hash tables will not be updated and hence the changes will not be tracked.
*/
Expand Down Expand Up @@ -306,12 +315,32 @@ class MKCAL_EXPORT ExtendedStorage
*/
virtual int loadJournals(int limit, KDateTime *last) = 0;

/**
Remove from storage all incidences that have been previously
marked as deleted and that matches the UID / RecID of the incidences
in list. The action is performed immediately on database.
@return True on success, false otherwise.
*/
virtual bool purgeDeletedIncidences(const KCalCore::Incidence::List &list) = 0;

/**
@copydoc
CalStorage::save()
*/
virtual bool save() = 0;

/**
This is an overload of save() method. When @deleteAction is
PurgeDeleted, the deleted incidences are not marked as deleted but completely
removed from the database and won't appear anymore when calling
deletedIncidences().
@param deleteAction the action to apply to deleted incidences
@return True if successful; false otherwise
*/
virtual bool save(DeleteAction deleteAction) = 0;

/**
Mark if supported by the storage that an incidence has been opened.
This should be called only if the Incidence has been opened by the user
Expand Down
55 changes: 54 additions & 1 deletion src/sqliteformat.cpp
Expand Up @@ -167,6 +167,55 @@ bool SqliteFormat::modifyCalendars(const Notebook::Ptr &notebook,
return false;
}

bool SqliteFormat::purgeDeletedComponents(const KCalCore::Incidence::Ptr &incidence,
sqlite3_stmt *stmt1, sqlite3_stmt *stmt2,
sqlite3_stmt *stmt3, sqlite3_stmt *stmt4,
sqlite3_stmt *stmt5, sqlite3_stmt *stmt6,
sqlite3_stmt *stmt7)
{
int rv;
int index = 1;
const QByteArray u(incidence->uid().toUtf8());
qint64 secsRecurId = incidence->hasRecurrenceId()
? d->mStorage->toOriginTime(incidence->recurrenceId()) : 0;

sqlite3_bind_text(stmt1, index, u.constData(), u.length(), SQLITE_STATIC);
sqlite3_bind_int64(stmt1, index, secsRecurId);

sqlite3_step(stmt1);
while (rv == SQLITE_ROW) {
int rowid = sqlite3_column_int(stmt1, 0);

int index2 = 1;
sqlite3_bind_int(stmt2, index2, rowid);
sqlite3_step(stmt2);
sqlite3_reset(stmt2);

if (!d->modifyCustomproperties(incidence, rowid, DBDelete, stmt3, NULL))
qCWarning(lcMkcal) << "failed to delete customproperties for incidence" << u;

if (!d->modifyAlarms(incidence, rowid, DBDelete, stmt4, NULL))
qCWarning(lcMkcal) << "failed to delete alarms for incidence" << u;

if (!d->modifyAttendees(incidence, rowid, DBDelete, stmt5, NULL))
qCWarning(lcMkcal) << "failed to delete attendees for incidence" << u;

if (!d->modifyRecursives(incidence, rowid, DBDelete, stmt6, NULL))
qCWarning(lcMkcal) << "failed to delete recursives for incidence" << u;

if (!d->modifyRdates(incidence, rowid, DBDelete, stmt7, NULL))
qCWarning(lcMkcal) << "failed to delete rdates for incidence" << u;

sqlite3_step(stmt1);
}

sqlite3_reset(stmt1);
return true;

error:
return false;
}

static bool setDateTime(SqliteStorage *storage, sqlite3_stmt *stmt, int &index, const KDateTime &dateTime)
{
int rv = 0;
Expand Down Expand Up @@ -227,7 +276,7 @@ bool SqliteFormat::modifyComponents(const Incidence::Ptr &incidence, const QStri
sqlite3_int64 secs;
int rowid = 0;

if (dbop == DBDelete || dbop == DBUpdate) {
if (dbop == DBDelete || dbop == DBMarkDeleted || dbop == DBUpdate) {
rowid = d->selectRowId(incidence);
if (!rowid) {
qCWarning(lcMkcal) << "failed to select rowid of incidence" << incidence->uid() << incidence->recurrenceId();
Expand All @@ -236,6 +285,10 @@ bool SqliteFormat::modifyComponents(const Incidence::Ptr &incidence, const QStri
}

if (dbop == DBDelete) {
sqlite3_bind_int(stmt1, index, rowid);
}

if (dbop == DBMarkDeleted) {
secs = d->mStorage->toOriginTime(KDateTime::currentUtcDateTime());
sqlite3_bind_int64(stmt1, index, secs);
sqlite3_bind_int(stmt1, index, rowid);
Expand Down
6 changes: 6 additions & 0 deletions src/sqliteformat.h
Expand Up @@ -110,6 +110,12 @@ class MKCAL_EXPORT SqliteFormat
sqlite3_stmt *stmt6, sqlite3_stmt *stmt7, sqlite3_stmt *stmt8,
sqlite3_stmt *stmt9, sqlite3_stmt *stmt10, sqlite3_stmt *stmt11);

bool purgeDeletedComponents(const KCalCore::Incidence::Ptr &incidence,
sqlite3_stmt *stmt1, sqlite3_stmt *stmt2,
sqlite3_stmt *stmt3, sqlite3_stmt *stmt4,
sqlite3_stmt *stmt5, sqlite3_stmt *stmt6,
sqlite3_stmt *stmt7);

/**
Select incidences from Components table.
Expand Down

0 comments on commit 80d8b63

Please sign in to comment.