Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'url' into 'master'
Save URL and colors

See merge request mer-core/mkcal!50
  • Loading branch information
pvuorela committed Jan 12, 2021
2 parents eedb0f5 + 93d5fab commit d3db397
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 12 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.5.26
Version: 0.5.30
Release: 1
License: LGPLv2+
URL: https://github.com/mer-packages/mkcal
Expand Down
27 changes: 20 additions & 7 deletions src/sqliteformat.cpp
Expand Up @@ -259,11 +259,11 @@ bool SqliteFormat::modifyComponents(const Incidence::Ptr &incidence, const QStri
QByteArray category;
QByteArray location;
QByteArray description;
QUrl uristr;
QByteArray uri;
QByteArray url;
QByteArray contact;
QByteArray attachments;
QByteArray relatedtouid;
QByteArray colorstr;
QByteArray comments;
QByteArray resources;
QDateTime dt;
Expand Down Expand Up @@ -426,9 +426,8 @@ bool SqliteFormat::modifyComponents(const Incidence::Ptr &incidence, const QStri
relatedtouid = incidence->relatedTo().toUtf8();
sqlite3_bind_text(stmt1, index, relatedtouid.constData(), relatedtouid.length(), SQLITE_STATIC);

uristr = incidence->uri();
uri = uristr.toString().toUtf8();
sqlite3_bind_text(stmt1, index, uri.constData(), uri.length(), SQLITE_STATIC);
url = incidence->url().toString().toUtf8();
sqlite3_bind_text(stmt1, index, url.constData(), url.length(), SQLITE_STATIC);

uid = incidence->uid().toUtf8();
sqlite3_bind_text(stmt1, index, uid.constData(), uid.length(), SQLITE_STATIC);
Expand Down Expand Up @@ -459,6 +458,9 @@ bool SqliteFormat::modifyComponents(const Incidence::Ptr &incidence, const QStri
sqlite3_bind_int(stmt1, index, percentComplete);
sqlite3_bind_date_time(d->mStorage, stmt1, index, effectiveDtCompleted, incidence->allDay());

colorstr = incidence->color().toUtf8();
sqlite3_bind_text(stmt1, index, colorstr.constData(), colorstr.length(), SQLITE_STATIC);

if (dbop == DBUpdate)
sqlite3_bind_int(stmt1, index, rowid);
}
Expand Down Expand Up @@ -1353,8 +1355,10 @@ Incidence::Ptr SqliteFormat::selectComponents(sqlite3_stmt *stmt1, sqlite3_stmt
QString relatedtouid = QString::fromUtf8((const char *) sqlite3_column_text(stmt1, index++));
incidence->setRelatedTo(relatedtouid);

//QString uri = QString::fromUtf8((const char *)sqlite3_column_text(stmt1, index++)); // uri
index++;
QUrl url(QString::fromUtf8((const char *)sqlite3_column_text(stmt1, index++)));
if (url.isValid()) {
incidence->setUrl(url);
}

// set the real uid to uid
incidence->setUid(QString::fromUtf8((const char *) sqlite3_column_text(stmt1, index++)));
Expand All @@ -1376,6 +1380,15 @@ Incidence::Ptr SqliteFormat::selectComponents(sqlite3_stmt *stmt1, sqlite3_stmt
if (completed.isValid())
todo->setCompleted(completed);
index += 3;
} else {
index += 4;
}

index++; //DateDeleted

QString colorstr = QString::fromUtf8((const char *) sqlite3_column_text(stmt1, index++));
if (!colorstr.isEmpty()) {
incidence->setColor(colorstr);
}
// kDebug() << "loaded component for incidence" << incidence->uid() << "notebook" << notebook;

Expand Down
9 changes: 5 additions & 4 deletions src/sqlitestorage.h
Expand Up @@ -518,13 +518,14 @@ public Q_SLOTS:
"CREATE TABLE IF NOT EXISTS Calendars(CalendarId TEXT PRIMARY KEY, Name TEXT, Description TEXT, Color INTEGER, Flags INTEGER, syncDate INTEGER, pluginName TEXT, account TEXT, attachmentSize INTEGER, modifiedDate INTEGER, sharedWith TEXT, syncProfile TEXT, createdDate INTEGER, extra1 STRING, extra2 STRING)"

//Extra fields added for future use in case they are needed. They will be documented here
//So we can add somthing without breaking the schema and not adding tables
//So we can add something without breaking the schema and not adding tables
//extra1: used to store the color of a single component.

#define CREATE_COMPONENTS \
"CREATE TABLE IF NOT EXISTS Components(ComponentId INTEGER PRIMARY KEY AUTOINCREMENT, Notebook TEXT, Type TEXT, Summary TEXT, Category TEXT, DateStart INTEGER, DateStartLocal INTEGER, StartTimeZone TEXT, HasDueDate INTEGER, DateEndDue INTEGER, DateEndDueLocal INTEGER, EndDueTimeZone TEXT, Duration INTEGER, Classification INTEGER, Location TEXT, Description TEXT, Status INTEGER, GeoLatitude REAL, GeoLongitude REAL, Priority INTEGER, Resources TEXT, DateCreated INTEGER, DateStamp INTEGER, DateLastModified INTEGER, Sequence INTEGER, Comments TEXT, Attachments TEXT, Contact TEXT, InvitationStatus INTEGER, RecurId INTEGER, RecurIdLocal INTEGER, RecurIdTimeZone TEXT, RelatedTo TEXT, URL TEXT, UID TEXT, Transparency INTEGER, LocalOnly INTEGER, Percent INTEGER, DateCompleted INTEGER, DateCompletedLocal INTEGER, CompletedTimeZone TEXT, DateDeleted INTEGER, extra1 STRING, extra2 STRING, extra3 INTEGER)"

//Extra fields added for future use in case they are needed. They will be documented here
//So we can add somthing without breaking the schema and not adding tables
//So we can add something without breaking the schema and not adding tables

#define CREATE_RDATES \
"CREATE TABLE IF NOT EXISTS Rdates(ComponentId INTEGER, Type INTEGER, Date INTEGER, DateLocal INTEGER, TimeZone TEXT)"
Expand Down Expand Up @@ -571,7 +572,7 @@ public Q_SLOTS:
#define INSERT_INVITATIONS \
"insert into Invitations values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
#define INSERT_COMPONENTS \
"insert into Components values (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, '', '', 0)"
"insert into Components values (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, '', 0)"
#define INSERT_CUSTOMPROPERTIES \
"insert into Customproperties values (?, ?, ?, ?)"
#define INSERT_CALENDARPROPERTIES \
Expand All @@ -590,7 +591,7 @@ public Q_SLOTS:
#define UPDATE_CALENDARS \
"update Calendars set Name=?, Description=?, Color=?, Flags=?, syncDate=?, pluginName=?, account=?, attachmentSize=?, modifiedDate=?, sharedWith=?, syncProfile=?, createdDate=? where CalendarId=?"
#define UPDATE_COMPONENTS \
"update Components set Notebook=?, Type=?, Summary=?, Category=?, DateStart=?, DateStartLocal=?, StartTimeZone=?, HasDueDate=?, DateEndDue=?, DateEndDueLocal=?, EndDueTimeZone=?, Duration=?, Classification=?, Location=?, Description=?, Status=?, GeoLatitude=?, GeoLongitude=?, Priority=?, Resources=?, DateCreated=?, DateStamp=?, DateLastModified=?, Sequence=?, Comments=?, Attachments=?, Contact=?, InvitationStatus=?, RecurId=?, RecurIdLocal=?, RecurIdTimeZone=?, RelatedTo=?, URL=?, UID=?, Transparency=?, LocalOnly=?, DateCompleted=?, DateCompletedLocal=?, CompletedTimeZone=?, Percent=? where ComponentId=?"
"update Components set Notebook=?, Type=?, Summary=?, Category=?, DateStart=?, DateStartLocal=?, StartTimeZone=?, HasDueDate=?, DateEndDue=?, DateEndDueLocal=?, EndDueTimeZone=?, Duration=?, Classification=?, Location=?, Description=?, Status=?, GeoLatitude=?, GeoLongitude=?, Priority=?, Resources=?, DateCreated=?, DateStamp=?, DateLastModified=?, Sequence=?, Comments=?, Attachments=?, Contact=?, InvitationStatus=?, RecurId=?, RecurIdLocal=?, RecurIdTimeZone=?, RelatedTo=?, URL=?, UID=?, Transparency=?, LocalOnly=?, Percent=?, DateCompleted=?, DateCompletedLocal=?, CompletedTimeZone=?, extra1=? where ComponentId=?"
#define UPDATE_COMPONENTS_AS_DELETED \
"update Components set DateDeleted=? where ComponentId=?"
//"update Components set DateDeleted=strftime('%s','now') where ComponentId=?"
Expand Down
62 changes: 62 additions & 0 deletions tests/tst_storage.cpp
Expand Up @@ -1749,6 +1749,68 @@ void tst_storage::tst_loadSeries()
QVERIFY(m_calendar->incidence(single->uid()));
}

void tst_storage::tst_url_data()
{
QTest::addColumn<QUrl>("url");

QTest::newRow("no URL")
<< QUrl();
QTest::newRow("simple URL")
<< QUrl("http://example.org/dav/123-456-789.ics");
QTest::newRow("percent encoded URL")
<< QUrl("https://example.org/dav%20user/123-456-789.ics");
}

void tst_storage::tst_url()
{
QFETCH(QUrl, url);

auto event = KCalendarCore::Event::Ptr(new KCalendarCore::Event);
event->setDtStart(QDateTime(QDate(2021, 1, 4), QTime(15, 37),
Qt::LocalTime));
event->setSummary("URL test event");
event->setUrl(url);
QCOMPARE(event->url(), url);

m_calendar->addEvent(event, NotebookId);
m_storage->save();
reloadDb();

auto fetchEvent = m_calendar->event(event->uid());
QVERIFY(fetchEvent);
QCOMPARE(fetchEvent->url(), url);
}

void tst_storage::tst_color()
{
const QString &red = QString::fromLatin1("red");
auto event = KCalendarCore::Event::Ptr(new KCalendarCore::Event);
event->setDtStart(QDateTime(QDate(2021, 1, 4), QTime(15, 59),
Qt::LocalTime));
event->setSummary("Color test event");
event->setColor(red);
QCOMPARE(event->color(), red);

m_calendar->addEvent(event, NotebookId);
m_storage->save();
reloadDb();

auto fetchEvent = m_calendar->event(event->uid());
QVERIFY(fetchEvent);
QCOMPARE(fetchEvent->color(), red);

const QString &green = QString::fromLatin1("green");
fetchEvent->setColor(green);
QCOMPARE(fetchEvent->color(), green);

m_storage->save();
reloadDb();

auto updatedEvent = m_calendar->event(event->uid());
QVERIFY(updatedEvent);
QCOMPARE(updatedEvent->color(), green);
}

void tst_storage::openDb(bool clear)
{
m_calendar = ExtendedCalendar::Ptr(new ExtendedCalendar(QTimeZone::systemTimeZone()));
Expand Down
3 changes: 3 additions & 0 deletions tests/tst_storage.h
Expand Up @@ -71,6 +71,9 @@ private slots:
void tst_alarms();
void tst_load();
void tst_loadSeries();
void tst_url_data();
void tst_url();
void tst_color();

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

0 comments on commit d3db397

Please sign in to comment.