Skip to content

Commit

Permalink
[mkcal] Add a load method in storage for series.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcaliste committed May 29, 2020
1 parent d716be1 commit 58047c6
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 1 deletion.
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.5.19
Version: 0.5.20
Release: 1
Group: System/Libraries
License: LGPLv2+
Expand Down
4 changes: 4 additions & 0 deletions src/dummystorage.h
Expand Up @@ -111,6 +111,10 @@ class MKCAL_EXPORT DummyStorage : public mKCal::ExtendedStorage
{
return true;
}
bool loadSeries(const QString &)
{
return true;
}
bool loadNotebookIncidences(const QString &)
{
return true;
Expand Down
8 changes: 8 additions & 0 deletions src/extendedstorage.h
Expand Up @@ -153,6 +153,14 @@ class MKCAL_EXPORT ExtendedStorage
*/
virtual bool load(const QDate &start, const QDate &end) = 0;

/**
Load all incidences sharing the same uid into the memory.
@param uid is uid of the series
@return true if the load was successful; false otherwise.
*/
virtual bool loadSeries(const QString &uid) = 0;

/**
Load incidences of one notebook into the memory.
Expand Down
60 changes: 60 additions & 0 deletions src/sqlitestorage.cpp
Expand Up @@ -434,6 +434,66 @@ bool SqliteStorage::load(const QString &uid, const KDateTime &recurrenceId)
return count >= 0;
}

bool SqliteStorage::loadSeries(const QString &uid)
{
if (!d->mIsOpened) {
return false;
}

int rv = 0;
int count = -1;
d->mIsLoading = true;

const char *query1 = NULL;
const char *query2 = NULL;
const char *query3 = NULL;
const char *query4 = NULL;
const char *query5 = NULL;
const char *query6 = NULL;
int qsize1 = 0;
int qsize2 = 0;
int qsize3 = 0;
int qsize4 = 0;
int qsize5 = 0;
int qsize6 = 0;

sqlite3_stmt *stmt1 = NULL;
const char *tail1 = NULL;
int index = 1;
QByteArray u;

if (!uid.isEmpty()) {
query1 = SELECT_COMPONENTS_BY_UID;
qsize1 = sizeof(SELECT_COMPONENTS_BY_UID);

sqlite3_prepare_v2(d->mDatabase, query1, qsize1, &stmt1, &tail1);
u = uid.toUtf8();
sqlite3_bind_text(stmt1, index, u.constData(), u.length(), SQLITE_STATIC);

query2 = SELECT_CUSTOMPROPERTIES_BY_ID;
qsize2 = sizeof(SELECT_CUSTOMPROPERTIES_BY_ID);

query3 = SELECT_ATTENDEE_BY_ID;
qsize3 = sizeof(SELECT_ATTENDEE_BY_ID);

query4 = SELECT_ALARM_BY_ID;
qsize4 = sizeof(SELECT_ALARM_BY_ID);

query5 = SELECT_RECURSIVE_BY_ID;
qsize5 = sizeof(SELECT_RECURSIVE_BY_ID);

query6 = SELECT_RDATES_BY_ID;
qsize6 = sizeof(SELECT_RDATES_BY_ID);

count = d->loadIncidences(stmt1, query2, qsize2, query3, qsize3,
query4, qsize4, query5, qsize5, query6, qsize6);
}
error:
d->mIsLoading = false;

return count >= 0;
}

bool SqliteStorage::load(const QDate &date)
{
if (!d->mIsOpened) {
Expand Down
8 changes: 8 additions & 0 deletions src/sqlitestorage.h
Expand Up @@ -114,6 +114,12 @@ class MKCAL_EXPORT SqliteStorage : public ExtendedStorage
*/
bool load(const QDate &start, const QDate &end);

/**
@copydoc
ExtendedStorage::loadSeries(const QString &)
*/
bool loadSeries(const QString &uid);

/**
@copydoc
ExtendedStorage::loadNotebookIncidences(const QString &)
Expand Down Expand Up @@ -644,6 +650,8 @@ public Q_SLOTS:
"select * from Components where DateStart<=? and DateDeleted=0"
#define SELECT_COMPONENTS_BY_UID_AND_RECURID \
"select * from Components where UID=? and RecurId=? and DateDeleted=0"
#define SELECT_COMPONENTS_BY_UID \
"select * from Components where UID=? and DateDeleted=0"
#define SELECT_COMPONENTS_BY_NOTEBOOKUID \
"select * from Components where Notebook=? and DateDeleted=0"
#define SELECT_ROWID_FROM_COMPONENTS_BY_UID_AND_RECURID \
Expand Down
50 changes: 50 additions & 0 deletions tests/tst_storage.cpp
Expand Up @@ -1814,6 +1814,56 @@ void tst_storage::tst_load()
QVERIFY(m_calendar->deleteIncidence(m_calendar->incidence(event->uid())));
}

void tst_storage::tst_loadSeries()
{
mKCal::Notebook::Ptr notebook =
mKCal::Notebook::Ptr(new mKCal::Notebook("123456789-loadSeries",
"test notebook",
QLatin1String(""),
"#001122",
false, // Not shared.
true, // Is master.
false, // Not synced to Ovi.
false, // Writable.
true, // Visible.
QLatin1String(""),
QLatin1String(""),
0));
m_storage->addNotebook(notebook);

KCalCore::Event::Ptr event = KCalCore::Event::Ptr(new KCalCore::Event);
event->setDtStart(KDateTime::currentUtcDateTime());
event->setSummary("Parent event");
event->setCreated(KDateTime::currentUtcDateTime().addSecs(-3));
event->recurrence()->setDaily(1);
KCalCore::Event::Ptr occurrence(event->clone());
occurrence->clearRecurrence();
occurrence->setDtStart(event->dtStart().addDays(1));
occurrence->setRecurrenceId(event->dtStart().addDays(1));
occurrence->setSummary("Exception occurrence");
event->recurrence()->addExDateTime(occurrence->recurrenceId());
KCalCore::Event::Ptr single = KCalCore::Event::Ptr(new KCalCore::Event);
single->setDtStart(KDateTime::currentUtcDateTime().addDays(2));
single->setSummary("Single event");

QVERIFY(m_calendar->addEvent(event, notebook->uid()));
QVERIFY(m_calendar->addEvent(occurrence, notebook->uid()));
QVERIFY(m_calendar->addEvent(single, notebook->uid()));
QVERIFY(m_storage->save());
reloadDb();

QVERIFY(m_calendar->events().isEmpty());

QVERIFY(m_storage->loadSeries(event->uid()));
QCOMPARE(m_calendar->events().length(), 2);
QVERIFY(m_calendar->incidence(event->uid()));
QVERIFY(m_calendar->incidence(occurrence->uid(), occurrence->recurrenceId()));

QVERIFY(m_storage->loadSeries(single->uid()));
QCOMPARE(m_calendar->events().length(), 3);
QVERIFY(m_calendar->incidence(single->uid()));
}

void tst_storage::openDb(bool clear)
{
m_calendar = ExtendedCalendar::Ptr(new ExtendedCalendar(KDateTime::Spec::LocalZone()));
Expand Down
1 change: 1 addition & 0 deletions tests/tst_storage.h
Expand Up @@ -70,6 +70,7 @@ private slots:
void tst_calendarProperties();
void tst_alarms();
void tst_load();
void tst_loadSeries();

private:
void openDb(bool clear = false);
Expand Down

0 comments on commit 58047c6

Please sign in to comment.