Merge lp:~renatofilho/qtorganizer5-eds/recurrence into lp:~ubuntu-sdk-team/qtorganizer5-eds/trunk
- recurrence
- Merge into trunk
| Status: | Merged |
|---|---|
| Approved by: | Gustavo Pichorim Boiko |
| Approved revision: | 25 |
| Merged at revision: | 12 |
| Proposed branch: | lp:~renatofilho/qtorganizer5-eds/recurrence |
| Merge into: | lp:~ubuntu-sdk-team/qtorganizer5-eds/trunk |
| Diff against target: |
2806 lines (+2033/-178) 17 files modified
qorganizer/CMakeLists.txt (+4/-1) qorganizer/qorganizer-eds-collection-engineid.cpp (+12/-0) qorganizer/qorganizer-eds-collection-engineid.h (+3/-0) qorganizer/qorganizer-eds-engine.cpp (+922/-151) qorganizer/qorganizer-eds-engine.h (+62/-17) qorganizer/qorganizer-eds-fetchrequestdata.cpp (+19/-3) qorganizer/qorganizer-eds-removecollectionrequestdata.cpp (+76/-0) qorganizer/qorganizer-eds-removecollectionrequestdata.h (+44/-0) qorganizer/qorganizer-eds-removerequestdata.cpp (+0/-3) qorganizer/qorganizer-eds-requestdata.cpp (+2/-2) qorganizer/qorganizer-eds-requestdata.h (+1/-1) qorganizer/qorganizer-eds-savecollectionrequestdata.cpp (+139/-0) qorganizer/qorganizer-eds-savecollectionrequestdata.h (+49/-0) tests/unittest/CMakeLists.txt (+5/-0) tests/unittest/collections-test.cpp (+191/-0) tests/unittest/event-test.cpp (+138/-0) tests/unittest/parseecal-test.cpp (+366/-0) |
| To merge this branch: | bzr merge lp:~renatofilho/qtorganizer5-eds/recurrence |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| PS Jenkins bot | continuous-integration | Approve | |
| Gustavo Pichorim Boiko (community) | Approve | ||
|
Review via email:
|
|||
Commit message
- Implemented recurrence support;
- Implemented support for different collection type.
- Implemented Reminder support;
Description of the change
| PS Jenkins bot (ps-jenkins) wrote : | # |
| PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:25
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
| Gustavo Pichorim Boiko (boiko) wrote : | # |
Looks good.
| PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Autolanding.
Unapproved changes made after approval.
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
| PS Jenkins bot (ps-jenkins) : | # |
Preview Diff
| 1 | === modified file 'qorganizer/CMakeLists.txt' | |||
| 2 | --- qorganizer/CMakeLists.txt 2013-08-14 21:23:01 +0000 | |||
| 3 | +++ qorganizer/CMakeLists.txt 2013-09-09 21:01:24 +0000 | |||
| 4 | @@ -7,8 +7,10 @@ | |||
| 5 | 7 | qorganizer-eds-fetchrequestdata.cpp | 7 | qorganizer-eds-fetchrequestdata.cpp |
| 6 | 8 | qorganizer-eds-engine.cpp | 8 | qorganizer-eds-engine.cpp |
| 7 | 9 | qorganizer-eds-engineid.cpp | 9 | qorganizer-eds-engineid.cpp |
| 8 | 10 | qorganizer-eds-removecollectionrequestdata.cpp | ||
| 9 | 10 | qorganizer-eds-removerequestdata.cpp | 11 | qorganizer-eds-removerequestdata.cpp |
| 10 | 11 | qorganizer-eds-requestdata.cpp | 12 | qorganizer-eds-requestdata.cpp |
| 11 | 13 | qorganizer-eds-savecollectionrequestdata.cpp | ||
| 12 | 12 | qorganizer-eds-saverequestdata.cpp | 14 | qorganizer-eds-saverequestdata.cpp |
| 13 | 13 | ) | 15 | ) |
| 14 | 14 | 16 | ||
| 15 | @@ -17,8 +19,10 @@ | |||
| 16 | 17 | qorganizer-eds-fetchrequestdata.h | 19 | qorganizer-eds-fetchrequestdata.h |
| 17 | 18 | qorganizer-eds-engine.h | 20 | qorganizer-eds-engine.h |
| 18 | 19 | qorganizer-eds-engineid.h | 21 | qorganizer-eds-engineid.h |
| 19 | 22 | qorganizer-eds-removecollectionrequestdata.h | ||
| 20 | 20 | qorganizer-eds-removerequestdata.h | 23 | qorganizer-eds-removerequestdata.h |
| 21 | 21 | qorganizer-eds-requestdata.h | 24 | qorganizer-eds-requestdata.h |
| 22 | 25 | qorganizer-eds-savecollectionrequestdata.h | ||
| 23 | 22 | qorganizer-eds-saverequestdata.h | 26 | qorganizer-eds-saverequestdata.h |
| 24 | 23 | ) | 27 | ) |
| 25 | 24 | 28 | ||
| 26 | @@ -53,7 +57,6 @@ | |||
| 27 | 53 | ${EDATASERVER_LIBRARIES} | 57 | ${EDATASERVER_LIBRARIES} |
| 28 | 54 | ) | 58 | ) |
| 29 | 55 | 59 | ||
| 30 | 56 | |||
| 31 | 57 | qt5_use_modules(${QORGANIZER_BACKEND}-lib Core Organizer) | 60 | qt5_use_modules(${QORGANIZER_BACKEND}-lib Core Organizer) |
| 32 | 58 | qt5_use_modules(${QORGANIZER_BACKEND} Core Organizer) | 61 | qt5_use_modules(${QORGANIZER_BACKEND} Core Organizer) |
| 33 | 59 | 62 | ||
| 34 | 60 | 63 | ||
| 35 | === modified file 'qorganizer/qorganizer-eds-collection-engineid.cpp' | |||
| 36 | --- qorganizer/qorganizer-eds-collection-engineid.cpp 2013-08-14 21:23:01 +0000 | |||
| 37 | +++ qorganizer/qorganizer-eds-collection-engineid.cpp 2013-09-09 21:01:24 +0000 | |||
| 38 | @@ -18,12 +18,24 @@ | |||
| 39 | 18 | 18 | ||
| 40 | 19 | #include "qorganizer-eds-collection-engineid.h" | 19 | #include "qorganizer-eds-collection-engineid.h" |
| 41 | 20 | 20 | ||
| 42 | 21 | |||
| 43 | 22 | |||
| 44 | 21 | QOrganizerEDSCollectionEngineId::QOrganizerEDSCollectionEngineId(ESource *source, | 23 | QOrganizerEDSCollectionEngineId::QOrganizerEDSCollectionEngineId(ESource *source, |
| 45 | 22 | const QString &managerUri) | 24 | const QString &managerUri) |
| 46 | 23 | : m_managerUri(managerUri), m_esource(source) | 25 | : m_managerUri(managerUri), m_esource(source) |
| 47 | 24 | { | 26 | { |
| 48 | 25 | g_object_ref(m_esource); | 27 | g_object_ref(m_esource); |
| 49 | 26 | m_collectionId = QString::fromUtf8(e_source_get_uid(m_esource)); | 28 | m_collectionId = QString::fromUtf8(e_source_get_uid(m_esource)); |
| 50 | 29 | if (e_source_has_extension(m_esource, E_SOURCE_EXTENSION_CALENDAR)) { | ||
| 51 | 30 | m_sourceType = E_CAL_CLIENT_SOURCE_TYPE_EVENTS; | ||
| 52 | 31 | } else if (e_source_has_extension(m_esource, E_SOURCE_EXTENSION_TASK_LIST)) { | ||
| 53 | 32 | m_sourceType = E_CAL_CLIENT_SOURCE_TYPE_TASKS; | ||
| 54 | 33 | } else if (e_source_has_extension(m_esource, E_SOURCE_EXTENSION_MEMO_LIST)) { | ||
| 55 | 34 | m_sourceType = E_CAL_CLIENT_SOURCE_TYPE_MEMOS; | ||
| 56 | 35 | } else { | ||
| 57 | 36 | qWarning() << "Source extension not supported"; | ||
| 58 | 37 | Q_ASSERT(false); | ||
| 59 | 38 | } | ||
| 60 | 27 | } | 39 | } |
| 61 | 28 | 40 | ||
| 62 | 29 | QOrganizerEDSCollectionEngineId::QOrganizerEDSCollectionEngineId() | 41 | QOrganizerEDSCollectionEngineId::QOrganizerEDSCollectionEngineId() |
| 63 | 30 | 42 | ||
| 64 | === modified file 'qorganizer/qorganizer-eds-collection-engineid.h' | |||
| 65 | --- qorganizer/qorganizer-eds-collection-engineid.h 2013-08-14 21:23:01 +0000 | |||
| 66 | +++ qorganizer/qorganizer-eds-collection-engineid.h 2013-09-09 21:01:24 +0000 | |||
| 67 | @@ -22,6 +22,7 @@ | |||
| 68 | 22 | #include <QtOrganizer/QOrganizerCollectionEngineId> | 22 | #include <QtOrganizer/QOrganizerCollectionEngineId> |
| 69 | 23 | 23 | ||
| 70 | 24 | #include <libedataserver/libedataserver.h> | 24 | #include <libedataserver/libedataserver.h> |
| 71 | 25 | #include <libecal/libecal.h> | ||
| 72 | 25 | 26 | ||
| 73 | 26 | class QOrganizerEDSCollectionEngineId : public QtOrganizer::QOrganizerCollectionEngineId | 27 | class QOrganizerEDSCollectionEngineId : public QtOrganizer::QOrganizerCollectionEngineId |
| 74 | 27 | { | 28 | { |
| 75 | @@ -39,6 +40,7 @@ | |||
| 76 | 39 | 40 | ||
| 77 | 40 | QString toString() const; | 41 | QString toString() const; |
| 78 | 41 | 42 | ||
| 79 | 43 | |||
| 80 | 42 | uint hash() const; | 44 | uint hash() const; |
| 81 | 43 | 45 | ||
| 82 | 44 | #ifndef QT_NO_DEBUG_STREAM | 46 | #ifndef QT_NO_DEBUG_STREAM |
| 83 | @@ -49,6 +51,7 @@ | |||
| 84 | 49 | QString m_collectionId; | 51 | QString m_collectionId; |
| 85 | 50 | QString m_managerUri; | 52 | QString m_managerUri; |
| 86 | 51 | ESource *m_esource; | 53 | ESource *m_esource; |
| 87 | 54 | ECalClientSourceType m_sourceType; | ||
| 88 | 52 | 55 | ||
| 89 | 53 | QOrganizerEDSCollectionEngineId(ESource *source, const QString &managerUri); | 56 | QOrganizerEDSCollectionEngineId(ESource *source, const QString &managerUri); |
| 90 | 54 | 57 | ||
| 91 | 55 | 58 | ||
| 92 | === modified file 'qorganizer/qorganizer-eds-engine.cpp' | |||
| 93 | --- qorganizer/qorganizer-eds-engine.cpp 2013-08-16 02:22:42 +0000 | |||
| 94 | +++ qorganizer/qorganizer-eds-engine.cpp 2013-09-09 21:01:24 +0000 | |||
| 95 | @@ -23,11 +23,14 @@ | |||
| 96 | 23 | #include "qorganizer-eds-fetchrequestdata.h" | 23 | #include "qorganizer-eds-fetchrequestdata.h" |
| 97 | 24 | #include "qorganizer-eds-saverequestdata.h" | 24 | #include "qorganizer-eds-saverequestdata.h" |
| 98 | 25 | #include "qorganizer-eds-removerequestdata.h" | 25 | #include "qorganizer-eds-removerequestdata.h" |
| 99 | 26 | #include "qorganizer-eds-savecollectionrequestdata.h" | ||
| 100 | 27 | #include "qorganizer-eds-removecollectionrequestdata.h" | ||
| 101 | 26 | 28 | ||
| 102 | 27 | #include <QtCore/qdebug.h> | 29 | #include <QtCore/qdebug.h> |
| 103 | 28 | #include <QtCore/QPointer> | 30 | #include <QtCore/QPointer> |
| 104 | 29 | #include <QtCore/qstringbuilder.h> | 31 | #include <QtCore/qstringbuilder.h> |
| 105 | 30 | #include <QtCore/quuid.h> | 32 | #include <QtCore/quuid.h> |
| 106 | 33 | #include <QtCore/QCoreApplication> | ||
| 107 | 31 | 34 | ||
| 108 | 32 | #include <QtOrganizer/QOrganizerEventAttendee> | 35 | #include <QtOrganizer/QOrganizerEventAttendee> |
| 109 | 33 | #include <QtOrganizer/QOrganizerItemLocation> | 36 | #include <QtOrganizer/QOrganizerItemLocation> |
| 110 | @@ -36,11 +39,18 @@ | |||
| 111 | 36 | #include <QtOrganizer/QOrganizerItemSaveRequest> | 39 | #include <QtOrganizer/QOrganizerItemSaveRequest> |
| 112 | 37 | #include <QtOrganizer/QOrganizerItemRemoveRequest> | 40 | #include <QtOrganizer/QOrganizerItemRemoveRequest> |
| 113 | 38 | #include <QtOrganizer/QOrganizerCollectionFetchRequest> | 41 | #include <QtOrganizer/QOrganizerCollectionFetchRequest> |
| 114 | 42 | #include <QtOrganizer/QOrganizerCollectionSaveRequest> | ||
| 115 | 43 | #include <QtOrganizer/QOrganizerCollectionRemoveRequest> | ||
| 116 | 39 | #include <QtOrganizer/QOrganizerEvent> | 44 | #include <QtOrganizer/QOrganizerEvent> |
| 117 | 40 | #include <QtOrganizer/QOrganizerTodo> | 45 | #include <QtOrganizer/QOrganizerTodo> |
| 118 | 41 | #include <QtOrganizer/QOrganizerTodoTime> | 46 | #include <QtOrganizer/QOrganizerTodoTime> |
| 119 | 42 | #include <QtOrganizer/QOrganizerJournal> | 47 | #include <QtOrganizer/QOrganizerJournal> |
| 120 | 43 | #include <QtOrganizer/QOrganizerJournalTime> | 48 | #include <QtOrganizer/QOrganizerJournalTime> |
| 121 | 49 | #include <QtOrganizer/QOrganizerItemIdFetchRequest> | ||
| 122 | 50 | #include <QtOrganizer/QOrganizerItemIdFilter> | ||
| 123 | 51 | #include <QtOrganizer/QOrganizerItemReminder> | ||
| 124 | 52 | #include <QtOrganizer/QOrganizerItemAudibleReminder> | ||
| 125 | 53 | #include <QtOrganizer/QOrganizerItemVisualReminder> | ||
| 126 | 44 | 54 | ||
| 127 | 45 | #include <glib.h> | 55 | #include <glib.h> |
| 128 | 46 | #include <libecal/libecal.h> | 56 | #include <libecal/libecal.h> |
| 129 | @@ -95,7 +105,7 @@ | |||
| 130 | 95 | QOrganizerEDSCollectionEngineId *collection = data->nextCollection(); | 105 | QOrganizerEDSCollectionEngineId *collection = data->nextCollection(); |
| 131 | 96 | if (collection) { | 106 | if (collection) { |
| 132 | 97 | e_cal_client_connect(collection->m_esource, | 107 | e_cal_client_connect(collection->m_esource, |
| 134 | 98 | E_CAL_CLIENT_SOURCE_TYPE_EVENTS, | 108 | collection->m_sourceType, |
| 135 | 99 | data->cancellable(), | 109 | data->cancellable(), |
| 136 | 100 | (GAsyncReadyCallback) QOrganizerEDSEngine::itemsAsyncConnected, | 110 | (GAsyncReadyCallback) QOrganizerEDSEngine::itemsAsyncConnected, |
| 137 | 101 | data); | 111 | data); |
| 138 | @@ -115,7 +125,7 @@ | |||
| 139 | 115 | EClient *client = e_cal_client_connect_finish(res, &gError); | 125 | EClient *client = e_cal_client_connect_finish(res, &gError); |
| 140 | 116 | 126 | ||
| 141 | 117 | if (gError) { | 127 | if (gError) { |
| 143 | 118 | qWarning() << "Fail to open calendar" << gError->message; | 128 | qWarning() << "Fail to open calendar:" << gError->message; |
| 144 | 119 | g_error_free(gError); | 129 | g_error_free(gError); |
| 145 | 120 | gError = 0; | 130 | gError = 0; |
| 146 | 121 | data->finish(QOrganizerManager::InvalidCollectionError); | 131 | data->finish(QOrganizerManager::InvalidCollectionError); |
| 147 | @@ -150,26 +160,36 @@ | |||
| 148 | 150 | delete data; | 160 | delete data; |
| 149 | 151 | return; | 161 | return; |
| 150 | 152 | } else { | 162 | } else { |
| 151 | 153 | qDebug() << "Query size:" << g_slist_length(events); | ||
| 152 | 154 | data->appendResults(parseEvents(data->collection(), events)); | 163 | data->appendResults(parseEvents(data->collection(), events)); |
| 153 | 155 | } | 164 | } |
| 154 | 156 | itemsAsyncStart(data); | 165 | itemsAsyncStart(data); |
| 155 | 157 | } | 166 | } |
| 156 | 158 | 167 | ||
| 157 | 159 | |||
| 158 | 160 | |||
| 159 | 161 | QList<QOrganizerItem> QOrganizerEDSEngine::items(const QList<QOrganizerItemId> &itemIds, | 168 | QList<QOrganizerItem> QOrganizerEDSEngine::items(const QList<QOrganizerItemId> &itemIds, |
| 160 | 162 | const QOrganizerItemFetchHint &fetchHint, | 169 | const QOrganizerItemFetchHint &fetchHint, |
| 161 | 163 | QMap<int, QOrganizerManager::Error> *errorMap, | 170 | QMap<int, QOrganizerManager::Error> *errorMap, |
| 162 | 164 | QOrganizerManager::Error *error) | 171 | QOrganizerManager::Error *error) |
| 163 | 165 | { | 172 | { |
| 164 | 166 | qDebug() << Q_FUNC_INFO; | 173 | qDebug() << Q_FUNC_INFO; |
| 171 | 167 | Q_UNUSED(fetchHint) | 174 | QOrganizerItemIdFilter filter; |
| 172 | 168 | Q_UNUSED(itemIds); | 175 | filter.setIds(itemIds); |
| 173 | 169 | Q_UNUSED(errorMap); | 176 | |
| 174 | 170 | 177 | QOrganizerItemFetchRequest *req = new QOrganizerItemFetchRequest(this); | |
| 175 | 171 | QList<QOrganizerItem> items; | 178 | req->setFilter(filter); |
| 176 | 172 | return items; | 179 | req->setFetchHint(fetchHint); |
| 177 | 180 | |||
| 178 | 181 | startRequest(req); | ||
| 179 | 182 | waitForRequestFinished(req, -1); | ||
| 180 | 183 | |||
| 181 | 184 | if (error) { | ||
| 182 | 185 | *error = req->error(); | ||
| 183 | 186 | } | ||
| 184 | 187 | // TODO implement correct reply for errorMap | ||
| 185 | 188 | if (errorMap) { | ||
| 186 | 189 | *errorMap = QMap<int, QOrganizerManager::Error>(); | ||
| 187 | 190 | } | ||
| 188 | 191 | req->deleteLater(); | ||
| 189 | 192 | return req->items(); | ||
| 190 | 173 | } | 193 | } |
| 191 | 174 | 194 | ||
| 192 | 175 | QList<QOrganizerItem> QOrganizerEDSEngine::items(const QOrganizerItemFilter &filter, | 195 | QList<QOrganizerItem> QOrganizerEDSEngine::items(const QOrganizerItemFilter &filter, |
| 193 | @@ -181,12 +201,25 @@ | |||
| 194 | 181 | QOrganizerManager::Error *error) | 201 | QOrganizerManager::Error *error) |
| 195 | 182 | { | 202 | { |
| 196 | 183 | qDebug() << Q_FUNC_INFO; | 203 | qDebug() << Q_FUNC_INFO; |
| 199 | 184 | QList<QOrganizerItem> list; | 204 | |
| 200 | 185 | return list; | 205 | QOrganizerItemFetchRequest *req = new QOrganizerItemFetchRequest(this); |
| 201 | 206 | req->setFilter(filter); | ||
| 202 | 207 | req->setStartDate(startDateTime); | ||
| 203 | 208 | req->setEndDate(endDateTime); | ||
| 204 | 209 | req->setMaxCount(maxCount); | ||
| 205 | 210 | req->setSorting(sortOrders); | ||
| 206 | 211 | req->setFetchHint(fetchHint); | ||
| 207 | 212 | |||
| 208 | 213 | startRequest(req); | ||
| 209 | 214 | waitForRequestFinished(req, -1); | ||
| 210 | 215 | |||
| 211 | 216 | if (error) { | ||
| 212 | 217 | *error = req->error(); | ||
| 213 | 218 | } | ||
| 214 | 219 | req->deleteLater(); | ||
| 215 | 220 | return req->items(); | ||
| 216 | 186 | } | 221 | } |
| 217 | 187 | 222 | ||
| 218 | 188 | |||
| 219 | 189 | |||
| 220 | 190 | QList<QOrganizerItemId> QOrganizerEDSEngine::itemIds(const QOrganizerItemFilter &filter, | 223 | QList<QOrganizerItemId> QOrganizerEDSEngine::itemIds(const QOrganizerItemFilter &filter, |
| 221 | 191 | const QDateTime &startDateTime, | 224 | const QDateTime &startDateTime, |
| 222 | 192 | const QDateTime &endDateTime, | 225 | const QDateTime &endDateTime, |
| 223 | @@ -224,6 +257,7 @@ | |||
| 224 | 224 | { | 257 | { |
| 225 | 225 | qDebug() << Q_FUNC_INFO; | 258 | qDebug() << Q_FUNC_INFO; |
| 226 | 226 | if (req->items().count() == 0) { | 259 | if (req->items().count() == 0) { |
| 227 | 260 | qWarning() << "Items count is " << req->items().count(); | ||
| 228 | 227 | QOrganizerManagerEngine::updateItemSaveRequest(req, | 261 | QOrganizerManagerEngine::updateItemSaveRequest(req, |
| 229 | 228 | QList<QOrganizerItem>(), | 262 | QList<QOrganizerItem>(), |
| 230 | 229 | QOrganizerManager::NoError, | 263 | QOrganizerManager::NoError, |
| 231 | @@ -248,7 +282,7 @@ | |||
| 232 | 248 | 282 | ||
| 233 | 249 | SaveRequestData *data = new SaveRequestData(this, req, collectionId); | 283 | SaveRequestData *data = new SaveRequestData(this, req, collectionId); |
| 234 | 250 | e_cal_client_connect(collectionEngineId->m_esource, | 284 | e_cal_client_connect(collectionEngineId->m_esource, |
| 236 | 251 | E_CAL_CLIENT_SOURCE_TYPE_EVENTS, | 285 | collectionEngineId->m_sourceType, |
| 237 | 252 | data->cancellable(), | 286 | data->cancellable(), |
| 238 | 253 | (GAsyncReadyCallback) QOrganizerEDSEngine::saveItemsAsyncConnected, | 287 | (GAsyncReadyCallback) QOrganizerEDSEngine::saveItemsAsyncConnected, |
| 239 | 254 | data); | 288 | data); |
| 240 | @@ -258,6 +292,7 @@ | |||
| 241 | 258 | GAsyncResult *res, | 292 | GAsyncResult *res, |
| 242 | 259 | SaveRequestData *data) | 293 | SaveRequestData *data) |
| 243 | 260 | { | 294 | { |
| 244 | 295 | qDebug() << Q_FUNC_INFO; | ||
| 245 | 261 | Q_UNUSED(source_object); | 296 | Q_UNUSED(source_object); |
| 246 | 262 | 297 | ||
| 247 | 263 | GError *gError = 0; | 298 | GError *gError = 0; |
| 248 | @@ -271,7 +306,7 @@ | |||
| 249 | 271 | } else { | 306 | } else { |
| 250 | 272 | data->setClient(client); | 307 | data->setClient(client); |
| 251 | 273 | 308 | ||
| 253 | 274 | GSList *comps = parseItems(data->request<QOrganizerItemSaveRequest>()->items()); | 309 | GSList *comps = parseItems(data->client(), data->request<QOrganizerItemSaveRequest>()->items()); |
| 254 | 275 | if (comps) { | 310 | if (comps) { |
| 255 | 276 | if (data->isNew()) { | 311 | if (data->isNew()) { |
| 256 | 277 | e_cal_client_create_objects(E_CAL_CLIENT(client), | 312 | e_cal_client_create_objects(E_CAL_CLIENT(client), |
| 257 | @@ -300,6 +335,7 @@ | |||
| 258 | 300 | GAsyncResult *res, | 335 | GAsyncResult *res, |
| 259 | 301 | SaveRequestData *data) | 336 | SaveRequestData *data) |
| 260 | 302 | { | 337 | { |
| 261 | 338 | qDebug() << Q_FUNC_INFO; | ||
| 262 | 303 | Q_UNUSED(source_object); | 339 | Q_UNUSED(source_object); |
| 263 | 304 | 340 | ||
| 264 | 305 | GError *gError = 0; | 341 | GError *gError = 0; |
| 265 | @@ -324,6 +360,7 @@ | |||
| 266 | 324 | GAsyncResult *res, | 360 | GAsyncResult *res, |
| 267 | 325 | SaveRequestData *data) | 361 | SaveRequestData *data) |
| 268 | 326 | { | 362 | { |
| 269 | 363 | qDebug() << Q_FUNC_INFO; | ||
| 270 | 327 | Q_UNUSED(source_object); | 364 | Q_UNUSED(source_object); |
| 271 | 328 | 365 | ||
| 272 | 329 | GError *gError = 0; | 366 | GError *gError = 0; |
| 273 | @@ -334,7 +371,7 @@ | |||
| 274 | 334 | &gError); | 371 | &gError); |
| 275 | 335 | 372 | ||
| 276 | 336 | if (gError) { | 373 | if (gError) { |
| 278 | 337 | qWarning() << "Fail to create items" << gError->message; | 374 | qWarning() << "Fail to create items:" << gError->message; |
| 279 | 338 | g_error_free(gError); | 375 | g_error_free(gError); |
| 280 | 339 | gError = 0; | 376 | gError = 0; |
| 281 | 340 | data->finish(QOrganizerManager::InvalidDetailError); | 377 | data->finish(QOrganizerManager::InvalidDetailError); |
| 282 | @@ -367,7 +404,24 @@ | |||
| 283 | 367 | 404 | ||
| 284 | 368 | { | 405 | { |
| 285 | 369 | qDebug() << Q_FUNC_INFO; | 406 | qDebug() << Q_FUNC_INFO; |
| 287 | 370 | *error = QOrganizerManager::NoError; | 407 | |
| 288 | 408 | QOrganizerItemSaveRequest *req = new QOrganizerItemSaveRequest(this); | ||
| 289 | 409 | req->setItems(*items); | ||
| 290 | 410 | req->setDetailMask(detailMask); | ||
| 291 | 411 | |||
| 292 | 412 | startRequest(req); | ||
| 293 | 413 | waitForRequestFinished(req, -1); | ||
| 294 | 414 | |||
| 295 | 415 | *errorMap = req->errorMap(); | ||
| 296 | 416 | *error = req->error(); | ||
| 297 | 417 | |||
| 298 | 418 | if (*error == QOrganizerManager::NoError) { | ||
| 299 | 419 | *items = req->items(); | ||
| 300 | 420 | return true; | ||
| 301 | 421 | } else { | ||
| 302 | 422 | return false; | ||
| 303 | 423 | } | ||
| 304 | 424 | |||
| 305 | 371 | return true; | 425 | return true; |
| 306 | 372 | } | 426 | } |
| 307 | 373 | 427 | ||
| 308 | @@ -392,9 +446,8 @@ | |||
| 309 | 392 | QOrganizerCollectionId collection = data->begin(); | 446 | QOrganizerCollectionId collection = data->begin(); |
| 310 | 393 | if (!collection.isNull()) { | 447 | if (!collection.isNull()) { |
| 311 | 394 | QOrganizerEDSCollectionEngineId *collectionEngineId = data->parent()->m_collectionsMap[collection.toString()]; | 448 | QOrganizerEDSCollectionEngineId *collectionEngineId = data->parent()->m_collectionsMap[collection.toString()]; |
| 312 | 395 | qDebug() << "REmove items from sourcE: " << e_source_get_display_name(collectionEngineId->m_esource); | ||
| 313 | 396 | e_cal_client_connect(collectionEngineId->m_esource, | 449 | e_cal_client_connect(collectionEngineId->m_esource, |
| 315 | 397 | E_CAL_CLIENT_SOURCE_TYPE_EVENTS, | 450 | collectionEngineId->m_sourceType, |
| 316 | 398 | data->cancellable(), | 451 | data->cancellable(), |
| 317 | 399 | (GAsyncReadyCallback) QOrganizerEDSEngine::removeItemsAsyncConnected, | 452 | (GAsyncReadyCallback) QOrganizerEDSEngine::removeItemsAsyncConnected, |
| 318 | 400 | data); | 453 | data); |
| 319 | @@ -447,7 +500,6 @@ | |||
| 320 | 447 | data->finish(QOrganizerManager::InvalidCollectionError); | 500 | data->finish(QOrganizerManager::InvalidCollectionError); |
| 321 | 448 | delete data; | 501 | delete data; |
| 322 | 449 | } else { | 502 | } else { |
| 323 | 450 | qDebug() << "Item removed"; | ||
| 324 | 451 | data->commit(); | 503 | data->commit(); |
| 325 | 452 | removeItemsAsyncStart(data); | 504 | removeItemsAsyncStart(data); |
| 326 | 453 | } | 505 | } |
| 327 | @@ -479,23 +531,164 @@ | |||
| 328 | 479 | QList<QOrganizerCollection> QOrganizerEDSEngine::collections(QOrganizerManager::Error* error) | 531 | QList<QOrganizerCollection> QOrganizerEDSEngine::collections(QOrganizerManager::Error* error) |
| 329 | 480 | { | 532 | { |
| 330 | 481 | qDebug() << Q_FUNC_INFO; | 533 | qDebug() << Q_FUNC_INFO; |
| 333 | 482 | *error = QOrganizerManager::NoError; | 534 | |
| 334 | 483 | return m_collections; | 535 | QOrganizerCollectionFetchRequest *req = new QOrganizerCollectionFetchRequest(this); |
| 335 | 536 | |||
| 336 | 537 | startRequest(req); | ||
| 337 | 538 | waitForRequestFinished(req, -1); | ||
| 338 | 539 | |||
| 339 | 540 | *error = req->error(); | ||
| 340 | 541 | |||
| 341 | 542 | if (*error == QOrganizerManager::NoError) { | ||
| 342 | 543 | return req->collections(); | ||
| 343 | 544 | } else { | ||
| 344 | 545 | return QList<QOrganizerCollection>(); | ||
| 345 | 546 | } | ||
| 346 | 484 | } | 547 | } |
| 347 | 485 | 548 | ||
| 348 | 486 | bool QOrganizerEDSEngine::saveCollection(QOrganizerCollection* collection, QOrganizerManager::Error* error) | 549 | bool QOrganizerEDSEngine::saveCollection(QOrganizerCollection* collection, QOrganizerManager::Error* error) |
| 349 | 487 | { | 550 | { |
| 350 | 488 | qDebug() << Q_FUNC_INFO; | 551 | qDebug() << Q_FUNC_INFO; |
| 354 | 489 | *error = QOrganizerManager::NoError; | 552 | QOrganizerCollectionSaveRequest *req = new QOrganizerCollectionSaveRequest(this); |
| 355 | 490 | return true; | 553 | req->setCollection(*collection); |
| 356 | 491 | 554 | ||
| 357 | 555 | startRequest(req); | ||
| 358 | 556 | waitForRequestFinished(req, -1); | ||
| 359 | 557 | |||
| 360 | 558 | *error = req->error(); | ||
| 361 | 559 | if ((*error == QOrganizerManager::NoError) && | ||
| 362 | 560 | (req->collections().count())) { | ||
| 363 | 561 | *collection = req->collections()[0]; | ||
| 364 | 562 | return true; | ||
| 365 | 563 | } else { | ||
| 366 | 564 | return false; | ||
| 367 | 565 | } | ||
| 368 | 566 | } | ||
| 369 | 567 | |||
| 370 | 568 | void QOrganizerEDSEngine::saveCollectionAsync(QOrganizerCollectionSaveRequest *req) | ||
| 371 | 569 | { | ||
| 372 | 570 | qDebug() << Q_FUNC_INFO; | ||
| 373 | 571 | |||
| 374 | 572 | if (req->collections().count() == 0) { | ||
| 375 | 573 | QOrganizerManagerEngine::updateCollectionSaveRequest(req, | ||
| 376 | 574 | QList<QOrganizerCollection>(), | ||
| 377 | 575 | QOrganizerManager::NoError, | ||
| 378 | 576 | QMap<int, QOrganizerManager::Error>(), | ||
| 379 | 577 | QOrganizerAbstractRequest::FinishedState); | ||
| 380 | 578 | return; | ||
| 381 | 579 | } | ||
| 382 | 580 | |||
| 383 | 581 | GError *gError = 0; | ||
| 384 | 582 | ESourceRegistry *registry = e_source_registry_new_sync(0, &gError); | ||
| 385 | 583 | if (gError) { | ||
| 386 | 584 | qWarning() << "Fail to create sourge registry:" << gError->message; | ||
| 387 | 585 | g_error_free(gError); | ||
| 388 | 586 | QOrganizerManagerEngine::updateCollectionSaveRequest(req, | ||
| 389 | 587 | QList<QOrganizerCollection>(), | ||
| 390 | 588 | QOrganizerManager::UnspecifiedError, | ||
| 391 | 589 | QMap<int, QOrganizerManager::Error>(), | ||
| 392 | 590 | QOrganizerAbstractRequest::FinishedState); | ||
| 393 | 591 | return; | ||
| 394 | 592 | } | ||
| 395 | 593 | SaveCollectionRequestData *requestData = new SaveCollectionRequestData(this, req); | ||
| 396 | 594 | saveCollectionAsyncStart(registry, requestData); | ||
| 397 | 595 | } | ||
| 398 | 596 | |||
| 399 | 597 | void QOrganizerEDSEngine::saveCollectionAsyncStart(ESourceRegistry *registry, SaveCollectionRequestData *data) | ||
| 400 | 598 | { | ||
| 401 | 599 | qDebug() << Q_FUNC_INFO; | ||
| 402 | 600 | |||
| 403 | 601 | ESource *source = data->begin(); | ||
| 404 | 602 | if (source) { | ||
| 405 | 603 | e_source_registry_commit_source(registry, | ||
| 406 | 604 | source, | ||
| 407 | 605 | data->cancellable(), | ||
| 408 | 606 | (GAsyncReadyCallback) QOrganizerEDSEngine::saveCollectionAsyncCommited, | ||
| 409 | 607 | data); | ||
| 410 | 608 | } else { | ||
| 411 | 609 | data->finish(); | ||
| 412 | 610 | delete data; | ||
| 413 | 611 | } | ||
| 414 | 612 | } | ||
| 415 | 613 | |||
| 416 | 614 | void QOrganizerEDSEngine::saveCollectionAsyncCommited(GObject *source_object, | ||
| 417 | 615 | GAsyncResult *res, | ||
| 418 | 616 | SaveCollectionRequestData *data) | ||
| 419 | 617 | { | ||
| 420 | 618 | qDebug() << Q_FUNC_INFO; | ||
| 421 | 619 | GError *gError = 0; | ||
| 422 | 620 | e_source_registry_commit_source_finish(E_SOURCE_REGISTRY(source_object), res, &gError); | ||
| 423 | 621 | if (gError) { | ||
| 424 | 622 | qWarning() << "Fail to commit source:" << gError->message; | ||
| 425 | 623 | g_error_free(gError); | ||
| 426 | 624 | data->commit(QOrganizerManager::InvalidCollectionError); | ||
| 427 | 625 | } else { | ||
| 428 | 626 | data->commit(); | ||
| 429 | 627 | } | ||
| 430 | 628 | |||
| 431 | 629 | saveCollectionAsyncStart(E_SOURCE_REGISTRY(source_object), data); | ||
| 432 | 492 | } | 630 | } |
| 433 | 493 | 631 | ||
| 434 | 494 | bool QOrganizerEDSEngine::removeCollection(const QOrganizerCollectionId& collectionId, QOrganizerManager::Error* error) | 632 | bool QOrganizerEDSEngine::removeCollection(const QOrganizerCollectionId& collectionId, QOrganizerManager::Error* error) |
| 435 | 495 | { | 633 | { |
| 436 | 496 | qDebug() << Q_FUNC_INFO; | 634 | qDebug() << Q_FUNC_INFO; |
| 439 | 497 | *error = QOrganizerManager::NoError; | 635 | |
| 440 | 498 | return true; | 636 | QOrganizerCollectionRemoveRequest *req = new QOrganizerCollectionRemoveRequest(this); |
| 441 | 637 | req->setCollectionId(collectionId); | ||
| 442 | 638 | |||
| 443 | 639 | startRequest(req); | ||
| 444 | 640 | waitForRequestFinished(req, -1); | ||
| 445 | 641 | |||
| 446 | 642 | *error = req->error(); | ||
| 447 | 643 | return(*error == QOrganizerManager::NoError); | ||
| 448 | 644 | } | ||
| 449 | 645 | |||
| 450 | 646 | void QOrganizerEDSEngine::removeCollectionAsync(QtOrganizer::QOrganizerCollectionRemoveRequest *req) | ||
| 451 | 647 | { | ||
| 452 | 648 | qDebug() << Q_FUNC_INFO; | ||
| 453 | 649 | |||
| 454 | 650 | if (req->collectionIds().count() == 0) { | ||
| 455 | 651 | QOrganizerManagerEngine::updateCollectionRemoveRequest(req, | ||
| 456 | 652 | QOrganizerManager::NoError, | ||
| 457 | 653 | QMap<int, QOrganizerManager::Error>(), | ||
| 458 | 654 | QOrganizerAbstractRequest::FinishedState); | ||
| 459 | 655 | return; | ||
| 460 | 656 | } | ||
| 461 | 657 | |||
| 462 | 658 | RemoveCollectionRequestData *requestData = new RemoveCollectionRequestData(this, req); | ||
| 463 | 659 | removeCollectionAsyncStart(0, 0, requestData); | ||
| 464 | 660 | } | ||
| 465 | 661 | |||
| 466 | 662 | void QOrganizerEDSEngine::removeCollectionAsyncStart(GObject *source_object, | ||
| 467 | 663 | GAsyncResult *res, | ||
| 468 | 664 | RemoveCollectionRequestData *data) | ||
| 469 | 665 | { | ||
| 470 | 666 | if (source_object && res) { | ||
| 471 | 667 | GError *gError = 0; | ||
| 472 | 668 | e_source_remove_finish(E_SOURCE(source_object), res, &gError); | ||
| 473 | 669 | if (gError) { | ||
| 474 | 670 | qWarning() << "Fail to remove collection" << gError->message; | ||
| 475 | 671 | g_error_free(gError); | ||
| 476 | 672 | data->commit(QOrganizerManager::InvalidCollectionError); | ||
| 477 | 673 | } else { | ||
| 478 | 674 | data->commit(); | ||
| 479 | 675 | } | ||
| 480 | 676 | } | ||
| 481 | 677 | |||
| 482 | 678 | ESource *source = data->begin(); | ||
| 483 | 679 | if (source) { | ||
| 484 | 680 | if (e_source_get_removable(source)) { | ||
| 485 | 681 | e_source_remove(source, data->cancellable(), | ||
| 486 | 682 | (GAsyncReadyCallback) QOrganizerEDSEngine::removeCollectionAsyncStart, | ||
| 487 | 683 | data); | ||
| 488 | 684 | } else { | ||
| 489 | 685 | qWarning() << "Source not removable"; | ||
| 490 | 686 | data->commit(QOrganizerManager::InvalidCollectionError); | ||
| 491 | 687 | } | ||
| 492 | 688 | } else { | ||
| 493 | 689 | data->finish(); | ||
| 494 | 690 | delete data; | ||
| 495 | 691 | } | ||
| 496 | 499 | } | 692 | } |
| 497 | 500 | 693 | ||
| 498 | 501 | void QOrganizerEDSEngine::requestDestroyed(QOrganizerAbstractRequest* req) | 694 | void QOrganizerEDSEngine::requestDestroyed(QOrganizerAbstractRequest* req) |
| 499 | @@ -511,7 +704,7 @@ | |||
| 500 | 511 | if (!req) | 704 | if (!req) |
| 501 | 512 | return false; | 705 | return false; |
| 502 | 513 | 706 | ||
| 504 | 514 | 707 | updateRequestState(req, QOrganizerAbstractRequest::ActiveState); | |
| 505 | 515 | switch (req->type()) | 708 | switch (req->type()) |
| 506 | 516 | { | 709 | { |
| 507 | 517 | case QOrganizerAbstractRequest::ItemFetchRequest: | 710 | case QOrganizerAbstractRequest::ItemFetchRequest: |
| 508 | @@ -529,7 +722,14 @@ | |||
| 509 | 529 | case QOrganizerAbstractRequest::ItemRemoveRequest: | 722 | case QOrganizerAbstractRequest::ItemRemoveRequest: |
| 510 | 530 | removeItemsAsync(qobject_cast<QOrganizerItemRemoveRequest*>(req)); | 723 | removeItemsAsync(qobject_cast<QOrganizerItemRemoveRequest*>(req)); |
| 511 | 531 | break; | 724 | break; |
| 512 | 725 | case QOrganizerAbstractRequest::CollectionSaveRequest: | ||
| 513 | 726 | saveCollectionAsync(qobject_cast<QOrganizerCollectionSaveRequest*>(req)); | ||
| 514 | 727 | break; | ||
| 515 | 728 | case QOrganizerAbstractRequest::CollectionRemoveRequest: | ||
| 516 | 729 | removeCollectionAsync(qobject_cast<QOrganizerCollectionRemoveRequest*>(req)); | ||
| 517 | 730 | break; | ||
| 518 | 532 | default: | 731 | default: |
| 519 | 732 | updateRequestState(req, QOrganizerAbstractRequest::FinishedState); | ||
| 520 | 533 | qDebug() << "No implemented request" << req->type(); | 733 | qDebug() << "No implemented request" << req->type(); |
| 521 | 534 | break; | 734 | break; |
| 522 | 535 | } | 735 | } |
| 523 | @@ -540,16 +740,20 @@ | |||
| 524 | 540 | bool QOrganizerEDSEngine::cancelRequest(QOrganizerAbstractRequest* req) | 740 | bool QOrganizerEDSEngine::cancelRequest(QOrganizerAbstractRequest* req) |
| 525 | 541 | { | 741 | { |
| 526 | 542 | qDebug() << Q_FUNC_INFO; | 742 | qDebug() << Q_FUNC_INFO; |
| 528 | 543 | Q_UNUSED(req); // we can't cancel since we complete immediately | 743 | Q_UNUSED(req); |
| 529 | 744 | //TODO | ||
| 530 | 745 | Q_ASSERT(false); | ||
| 531 | 544 | return false; | 746 | return false; |
| 532 | 545 | } | 747 | } |
| 533 | 546 | 748 | ||
| 534 | 547 | bool QOrganizerEDSEngine::waitForRequestFinished(QOrganizerAbstractRequest* req, int msecs) | 749 | bool QOrganizerEDSEngine::waitForRequestFinished(QOrganizerAbstractRequest* req, int msecs) |
| 535 | 548 | { | 750 | { |
| 536 | 549 | qDebug() << Q_FUNC_INFO; | 751 | qDebug() << Q_FUNC_INFO; |
| 537 | 550 | // in our implementation, we always complete any operation we start. | ||
| 538 | 551 | Q_UNUSED(msecs); | 752 | Q_UNUSED(msecs); |
| 540 | 552 | Q_UNUSED(req); | 753 | |
| 541 | 754 | while(req->state() == QOrganizerAbstractRequest::ActiveState) { | ||
| 542 | 755 | QCoreApplication::processEvents(); | ||
| 543 | 756 | } | ||
| 544 | 553 | 757 | ||
| 545 | 554 | return true; | 758 | return true; |
| 546 | 555 | } | 759 | } |
| 547 | @@ -641,6 +845,23 @@ | |||
| 548 | 641 | << QOrganizerItemType::TypeTodoOccurrence; | 845 | << QOrganizerItemType::TypeTodoOccurrence; |
| 549 | 642 | } | 846 | } |
| 550 | 643 | 847 | ||
| 551 | 848 | void QOrganizerEDSEngine::registerCollection(const QOrganizerCollection &collection, QOrganizerEDSCollectionEngineId *edsId) | ||
| 552 | 849 | { | ||
| 553 | 850 | m_collections << collection; | ||
| 554 | 851 | m_collectionsMap.insert(collection.id().toString(), edsId); | ||
| 555 | 852 | } | ||
| 556 | 853 | |||
| 557 | 854 | void QOrganizerEDSEngine::unregisterCollection(const QOrganizerCollectionId &collectionId) | ||
| 558 | 855 | { | ||
| 559 | 856 | Q_FOREACH(QOrganizerCollection col, m_collections) { | ||
| 560 | 857 | if (col.id() == collectionId) { | ||
| 561 | 858 | m_collections.removeAll(col); | ||
| 562 | 859 | } | ||
| 563 | 860 | } | ||
| 564 | 861 | |||
| 565 | 862 | m_collectionsMap.remove(collectionId.toString()); | ||
| 566 | 863 | } | ||
| 567 | 864 | |||
| 568 | 644 | void QOrganizerEDSEngine::loadCollections() | 865 | void QOrganizerEDSEngine::loadCollections() |
| 569 | 645 | { | 866 | { |
| 570 | 646 | m_collections.clear(); | 867 | m_collections.clear(); |
| 571 | @@ -655,21 +876,24 @@ | |||
| 572 | 655 | } | 876 | } |
| 573 | 656 | 877 | ||
| 574 | 657 | ESource *defaultSource = e_source_registry_ref_default_address_book(registry); | 878 | ESource *defaultSource = e_source_registry_ref_default_address_book(registry); |
| 576 | 658 | GList *sources = e_source_registry_list_sources(registry, E_SOURCE_EXTENSION_CALENDAR); | 879 | GList *sources = e_source_registry_list_sources(registry, 0); |
| 577 | 659 | for(int i=0, iMax=g_list_length(sources); i < iMax; i++) { | 880 | for(int i=0, iMax=g_list_length(sources); i < iMax; i++) { |
| 578 | 660 | ESource *source = E_SOURCE(g_list_nth_data(sources, i)); | 881 | ESource *source = E_SOURCE(g_list_nth_data(sources, i)); |
| 591 | 661 | QOrganizerCollection collection; | 882 | |
| 592 | 662 | QOrganizerEDSCollectionEngineId *edsId = new QOrganizerEDSCollectionEngineId(source, managerUri()); | 883 | if (e_source_has_extension(source, E_SOURCE_EXTENSION_CALENDAR) || |
| 593 | 663 | QOrganizerCollectionId id(edsId); | 884 | e_source_has_extension(source, E_SOURCE_EXTENSION_TASK_LIST) || |
| 594 | 664 | collection.setId(id); | 885 | e_source_has_extension(source, E_SOURCE_EXTENSION_MEMO_LIST)) |
| 595 | 665 | collection.setMetaData(QOrganizerCollection::KeyName, | 886 | { |
| 596 | 666 | QString::fromUtf8(e_source_get_display_name(source))); | 887 | //TODO get metadata (color, etc..) |
| 597 | 667 | //TODO get metadata (color, etc..) | 888 | QOrganizerEDSCollectionEngineId *edsId = 0; |
| 598 | 668 | m_collections << collection; | 889 | QOrganizerCollection collection = parseSource(source, managerUri(), &edsId); |
| 599 | 669 | m_collectionsMap.insert(id.toString(), edsId); | 890 | |
| 600 | 670 | 891 | registerCollection(collection, edsId); | |
| 601 | 671 | if (e_source_compare_by_display_name(source, defaultSource) == 0) { | 892 | |
| 602 | 672 | m_defaultCollection = collection; | 893 | if (e_source_compare_by_display_name(source, defaultSource) == 0) { |
| 603 | 894 | qDebug() << "Default Source" << e_source_get_display_name(source); | ||
| 604 | 895 | m_defaultCollection = collection; | ||
| 605 | 896 | } | ||
| 606 | 673 | } | 897 | } |
| 607 | 674 | } | 898 | } |
| 608 | 675 | 899 | ||
| 609 | @@ -681,35 +905,117 @@ | |||
| 610 | 681 | qDebug() << m_collections.count() << "Collection loaded"; | 905 | qDebug() << m_collections.count() << "Collection loaded"; |
| 611 | 682 | } | 906 | } |
| 612 | 683 | 907 | ||
| 613 | 908 | ESource *QOrganizerEDSEngine::findSource(const QtOrganizer::QOrganizerCollectionId &id) const | ||
| 614 | 909 | { | ||
| 615 | 910 | if (!id.isNull() && m_collectionsMap.contains(id.toString())) { | ||
| 616 | 911 | QOrganizerEDSCollectionEngineId *edsId = m_collectionsMap[id.toString()]; | ||
| 617 | 912 | Q_ASSERT(edsId); | ||
| 618 | 913 | return edsId->m_esource; | ||
| 619 | 914 | } else { | ||
| 620 | 915 | return 0; | ||
| 621 | 916 | } | ||
| 622 | 917 | } | ||
| 623 | 918 | |||
| 624 | 919 | QOrganizerCollection QOrganizerEDSEngine::parseSource(ESource *source, | ||
| 625 | 920 | const QString &managerUri, | ||
| 626 | 921 | QOrganizerEDSCollectionEngineId **edsId) | ||
| 627 | 922 | { | ||
| 628 | 923 | *edsId = new QOrganizerEDSCollectionEngineId(source, managerUri); | ||
| 629 | 924 | QOrganizerCollectionId id(*edsId); | ||
| 630 | 925 | QOrganizerCollection collection; | ||
| 631 | 926 | |||
| 632 | 927 | collection.setId(id); | ||
| 633 | 928 | collection.setMetaData(QOrganizerCollection::KeyName, | ||
| 634 | 929 | QString::fromUtf8(e_source_get_display_name(source))); | ||
| 635 | 930 | |||
| 636 | 931 | return collection; | ||
| 637 | 932 | } | ||
| 638 | 933 | |||
| 639 | 934 | QOrganizerCollection QOrganizerEDSEngine::parseSource(ESource *source, const QString &managerUri) | ||
| 640 | 935 | { | ||
| 641 | 936 | QOrganizerEDSCollectionEngineId *edsId = 0; | ||
| 642 | 937 | return parseSource(source, managerUri, &edsId); | ||
| 643 | 938 | } | ||
| 644 | 939 | |||
| 645 | 684 | QDateTime QOrganizerEDSEngine::fromIcalTime(struct icaltimetype value) | 940 | QDateTime QOrganizerEDSEngine::fromIcalTime(struct icaltimetype value) |
| 646 | 685 | { | 941 | { |
| 650 | 686 | struct tm tmTime = icaltimetype_to_tm(&value); | 942 | uint tmTime = icaltime_as_timet(value); |
| 651 | 687 | g_date_time_new_from_unix_local(mktime(&tmTime)); | 943 | return QDateTime::fromTime_t(tmTime); |
| 649 | 688 | return QDateTime::fromTime_t(mktime(&tmTime)); | ||
| 652 | 689 | } | 944 | } |
| 653 | 690 | 945 | ||
| 654 | 691 | void QOrganizerEDSEngine::parseStartTime(ECalComponent *comp, QOrganizerItem *item) | 946 | void QOrganizerEDSEngine::parseStartTime(ECalComponent *comp, QOrganizerItem *item) |
| 655 | 692 | { | 947 | { |
| 659 | 693 | ECalComponentDateTime dt; | 948 | ECalComponentDateTime *dt = g_new0(ECalComponentDateTime, 1); |
| 660 | 694 | e_cal_component_get_dtstart(comp, &dt); | 949 | e_cal_component_get_dtstart(comp, dt); |
| 661 | 695 | if (dt.value) { | 950 | if (dt->value) { |
| 662 | 696 | QOrganizerEventTime etr = item->detail(QOrganizerItemDetail::TypeEventTime); | 951 | QOrganizerEventTime etr = item->detail(QOrganizerItemDetail::TypeEventTime); |
| 664 | 697 | etr.setStartDateTime(fromIcalTime(*dt.value)); | 952 | etr.setStartDateTime(fromIcalTime(*dt->value)); |
| 665 | 698 | item->saveDetail(&etr); | 953 | item->saveDetail(&etr); |
| 666 | 699 | } | 954 | } |
| 668 | 700 | e_cal_component_free_datetime(&dt); | 955 | e_cal_component_free_datetime(dt); |
| 669 | 701 | } | 956 | } |
| 670 | 702 | 957 | ||
| 671 | 703 | void QOrganizerEDSEngine::parseEndTime(ECalComponent *comp, QOrganizerItem *item) | 958 | void QOrganizerEDSEngine::parseEndTime(ECalComponent *comp, QOrganizerItem *item) |
| 672 | 704 | { | 959 | { |
| 676 | 705 | ECalComponentDateTime dt; | 960 | ECalComponentDateTime *dt = g_new0(ECalComponentDateTime, 1); |
| 677 | 706 | e_cal_component_get_dtend(comp, &dt); | 961 | e_cal_component_get_dtend(comp, dt); |
| 678 | 707 | if (dt.value) { | 962 | if (dt->value) { |
| 679 | 708 | QOrganizerEventTime etr = item->detail(QOrganizerItemDetail::TypeEventTime); | 963 | QOrganizerEventTime etr = item->detail(QOrganizerItemDetail::TypeEventTime); |
| 681 | 709 | etr.setEndDateTime(fromIcalTime(*dt.value)); | 964 | etr.setEndDateTime(fromIcalTime(*dt->value)); |
| 682 | 710 | item->saveDetail(&etr); | 965 | item->saveDetail(&etr); |
| 683 | 711 | } | 966 | } |
| 685 | 712 | e_cal_component_free_datetime(&dt); | 967 | e_cal_component_free_datetime(dt); |
| 686 | 968 | } | ||
| 687 | 969 | |||
| 688 | 970 | void QOrganizerEDSEngine::parseWeekRecurrence(struct icalrecurrencetype *rule, QtOrganizer::QOrganizerRecurrenceRule *qRule) | ||
| 689 | 971 | { | ||
| 690 | 972 | qRule->setFrequency(QOrganizerRecurrenceRule::Weekly); | ||
| 691 | 973 | |||
| 692 | 974 | QSet<Qt::DayOfWeek> daysOfWeek; | ||
| 693 | 975 | for (int d=0; d < Qt::Sunday; d++) { | ||
| 694 | 976 | short day = rule->by_day[d]; | ||
| 695 | 977 | if (day != ICAL_RECURRENCE_ARRAY_MAX) { | ||
| 696 | 978 | daysOfWeek.insert(static_cast<Qt::DayOfWeek>(icalrecurrencetype_day_day_of_week(rule->by_day[d]) - 1)); | ||
| 697 | 979 | } | ||
| 698 | 980 | } | ||
| 699 | 981 | qRule->setDaysOfWeek(daysOfWeek); | ||
| 700 | 982 | } | ||
| 701 | 983 | |||
| 702 | 984 | void QOrganizerEDSEngine::parseMonthRecurrence(struct icalrecurrencetype *rule, QtOrganizer::QOrganizerRecurrenceRule *qRule) | ||
| 703 | 985 | { | ||
| 704 | 986 | qRule->setFrequency(QOrganizerRecurrenceRule::Monthly); | ||
| 705 | 987 | |||
| 706 | 988 | QSet<int> daysOfMonth; | ||
| 707 | 989 | for (int d=0; d < ICAL_BY_MONTHDAY_SIZE; d++) { | ||
| 708 | 990 | short day = rule->by_month_day[d]; | ||
| 709 | 991 | if (day != ICAL_RECURRENCE_ARRAY_MAX) { | ||
| 710 | 992 | daysOfMonth.insert(day); | ||
| 711 | 993 | } | ||
| 712 | 994 | } | ||
| 713 | 995 | qRule->setDaysOfMonth(daysOfMonth); | ||
| 714 | 996 | } | ||
| 715 | 997 | |||
| 716 | 998 | void QOrganizerEDSEngine::parseYearRecurrence(struct icalrecurrencetype *rule, QtOrganizer::QOrganizerRecurrenceRule *qRule) | ||
| 717 | 999 | { | ||
| 718 | 1000 | qRule->setFrequency(QOrganizerRecurrenceRule::Yearly); | ||
| 719 | 1001 | |||
| 720 | 1002 | QSet<int> daysOfYear; | ||
| 721 | 1003 | for (int d=0; d < ICAL_BY_YEARDAY_SIZE; d++) { | ||
| 722 | 1004 | short day = rule->by_year_day[d]; | ||
| 723 | 1005 | if (day != ICAL_RECURRENCE_ARRAY_MAX) { | ||
| 724 | 1006 | daysOfYear.insert(day); | ||
| 725 | 1007 | } | ||
| 726 | 1008 | } | ||
| 727 | 1009 | qRule->setDaysOfYear(daysOfYear); | ||
| 728 | 1010 | |||
| 729 | 1011 | QSet<QOrganizerRecurrenceRule::Month> monthOfYear; | ||
| 730 | 1012 | for (int d=0; d < ICAL_BY_MONTH_SIZE; d++) { | ||
| 731 | 1013 | short month = rule->by_month[d]; | ||
| 732 | 1014 | if (month != ICAL_RECURRENCE_ARRAY_MAX) { | ||
| 733 | 1015 | monthOfYear.insert(static_cast<QOrganizerRecurrenceRule::Month>(month)); | ||
| 734 | 1016 | } | ||
| 735 | 1017 | } | ||
| 736 | 1018 | qRule->setMonthsOfYear(monthOfYear); | ||
| 737 | 713 | } | 1019 | } |
| 738 | 714 | 1020 | ||
| 739 | 715 | void QOrganizerEDSEngine::parseRecurrence(ECalComponent *comp, QOrganizerItem *item) | 1021 | void QOrganizerEDSEngine::parseRecurrence(ECalComponent *comp, QOrganizerItem *item) |
| 740 | @@ -735,6 +1041,7 @@ | |||
| 741 | 735 | if (e_cal_component_has_exdates(comp)) { | 1041 | if (e_cal_component_has_exdates(comp)) { |
| 742 | 736 | QSet<QDate> dates; | 1042 | QSet<QDate> dates; |
| 743 | 737 | GSList *exdateList = 0; | 1043 | GSList *exdateList = 0; |
| 744 | 1044 | |||
| 745 | 738 | e_cal_component_get_exdate_list(comp, &exdateList); | 1045 | e_cal_component_get_exdate_list(comp, &exdateList); |
| 746 | 739 | for(GSList *i = exdateList; i != 0; i = i->next) { | 1046 | for(GSList *i = exdateList; i != 0; i = i->next) { |
| 747 | 740 | ECalComponentDateTime* dateTime = (ECalComponentDateTime*) i->data; | 1047 | ECalComponentDateTime* dateTime = (ECalComponentDateTime*) i->data; |
| 748 | @@ -748,6 +1055,69 @@ | |||
| 749 | 748 | item->saveDetail(&irec); | 1055 | item->saveDetail(&irec); |
| 750 | 749 | } | 1056 | } |
| 751 | 750 | 1057 | ||
| 752 | 1058 | // rules | ||
| 753 | 1059 | GSList *ruleList = 0; | ||
| 754 | 1060 | e_cal_component_get_rrule_list(comp, &ruleList); | ||
| 755 | 1061 | if (ruleList) { | ||
| 756 | 1062 | QSet<QOrganizerRecurrenceRule> qRules; | ||
| 757 | 1063 | |||
| 758 | 1064 | for(GSList *i = ruleList; i != 0; i = i->next) { | ||
| 759 | 1065 | struct icalrecurrencetype *rule = (struct icalrecurrencetype*) i->data; | ||
| 760 | 1066 | QOrganizerRecurrenceRule qRule; | ||
| 761 | 1067 | switch (rule->freq) { | ||
| 762 | 1068 | case ICAL_SECONDLY_RECURRENCE: | ||
| 763 | 1069 | case ICAL_MINUTELY_RECURRENCE: | ||
| 764 | 1070 | case ICAL_HOURLY_RECURRENCE: | ||
| 765 | 1071 | qWarning() << "Recurrence frequency not supported"; | ||
| 766 | 1072 | break; | ||
| 767 | 1073 | case ICAL_DAILY_RECURRENCE: | ||
| 768 | 1074 | qRule.setFrequency(QOrganizerRecurrenceRule::Daily); | ||
| 769 | 1075 | break; | ||
| 770 | 1076 | case ICAL_WEEKLY_RECURRENCE: | ||
| 771 | 1077 | parseWeekRecurrence(rule, &qRule); | ||
| 772 | 1078 | break; | ||
| 773 | 1079 | case ICAL_MONTHLY_RECURRENCE: | ||
| 774 | 1080 | parseMonthRecurrence(rule, &qRule); | ||
| 775 | 1081 | break; | ||
| 776 | 1082 | case ICAL_YEARLY_RECURRENCE: | ||
| 777 | 1083 | parseYearRecurrence(rule, &qRule); | ||
| 778 | 1084 | break; | ||
| 779 | 1085 | case ICAL_NO_RECURRENCE: | ||
| 780 | 1086 | break; | ||
| 781 | 1087 | } | ||
| 782 | 1088 | |||
| 783 | 1089 | |||
| 784 | 1090 | if (rule->count > 0) { | ||
| 785 | 1091 | qRule.setLimit(rule->count); | ||
| 786 | 1092 | } else { | ||
| 787 | 1093 | QDateTime dt = fromIcalTime(rule->until); | ||
| 788 | 1094 | if (dt.isValid()) { | ||
| 789 | 1095 | qRule.setLimit(dt.date()); | ||
| 790 | 1096 | } else { | ||
| 791 | 1097 | qRule.clearLimit(); | ||
| 792 | 1098 | } | ||
| 793 | 1099 | } | ||
| 794 | 1100 | qRule.setInterval(rule->interval); | ||
| 795 | 1101 | |||
| 796 | 1102 | QSet<int> positions; | ||
| 797 | 1103 | for (int d=0; d < ICAL_BY_SETPOS_SIZE; d++) { | ||
| 798 | 1104 | short day = rule->by_set_pos[d]; | ||
| 799 | 1105 | if (day != ICAL_RECURRENCE_ARRAY_MAX) { | ||
| 800 | 1106 | positions.insert(day); | ||
| 801 | 1107 | } | ||
| 802 | 1108 | } | ||
| 803 | 1109 | qRule.setPositions(positions); | ||
| 804 | 1110 | |||
| 805 | 1111 | qRules << qRule; | ||
| 806 | 1112 | } | ||
| 807 | 1113 | |||
| 808 | 1114 | if (!qRules.isEmpty()) { | ||
| 809 | 1115 | QOrganizerItemRecurrence irec = item->detail(QOrganizerItemDetail::TypeRecurrence); | ||
| 810 | 1116 | irec.setRecurrenceRules(qRules); | ||
| 811 | 1117 | item->saveDetail(&irec); | ||
| 812 | 1118 | } | ||
| 813 | 1119 | } | ||
| 814 | 1120 | // TODO: free ruleList; | ||
| 815 | 751 | // TODO: exeptions rules | 1121 | // TODO: exeptions rules |
| 816 | 752 | } | 1122 | } |
| 817 | 753 | 1123 | ||
| 818 | @@ -866,6 +1236,143 @@ | |||
| 819 | 866 | return journal; | 1236 | return journal; |
| 820 | 867 | } | 1237 | } |
| 821 | 868 | 1238 | ||
| 822 | 1239 | void QOrganizerEDSEngine::parseSummary(ECalComponent *comp, QtOrganizer::QOrganizerItem *item) | ||
| 823 | 1240 | { | ||
| 824 | 1241 | ECalComponentText summary; | ||
| 825 | 1242 | e_cal_component_get_summary(comp, &summary); | ||
| 826 | 1243 | if (summary.value) { | ||
| 827 | 1244 | item->setDisplayLabel(QString::fromUtf8(summary.value)); | ||
| 828 | 1245 | } | ||
| 829 | 1246 | } | ||
| 830 | 1247 | |||
| 831 | 1248 | void QOrganizerEDSEngine::parseDescription(ECalComponent *comp, QtOrganizer::QOrganizerItem *item) | ||
| 832 | 1249 | { | ||
| 833 | 1250 | |||
| 834 | 1251 | GSList *descriptions = 0; | ||
| 835 | 1252 | e_cal_component_get_description_list(comp, &descriptions); | ||
| 836 | 1253 | |||
| 837 | 1254 | QStringList itemDescription; | ||
| 838 | 1255 | |||
| 839 | 1256 | for(GSList *descList = descriptions; descList != 0; descList = descList->next) { | ||
| 840 | 1257 | ECalComponentText *description = static_cast<ECalComponentText*>(descList->data); | ||
| 841 | 1258 | if (description) { | ||
| 842 | 1259 | itemDescription.append(QString::fromUtf8(description->value)); | ||
| 843 | 1260 | } | ||
| 844 | 1261 | } | ||
| 845 | 1262 | |||
| 846 | 1263 | item->setDescription(itemDescription.join("\n")); | ||
| 847 | 1264 | } | ||
| 848 | 1265 | |||
| 849 | 1266 | void QOrganizerEDSEngine::parseComments(ECalComponent *comp, QtOrganizer::QOrganizerItem *item) | ||
| 850 | 1267 | { | ||
| 851 | 1268 | GSList *comments = 0; | ||
| 852 | 1269 | e_cal_component_get_comment_list(comp, &comments); | ||
| 853 | 1270 | for(int ci=0, ciMax=g_slist_length(comments); ci < ciMax; ci++) { | ||
| 854 | 1271 | ECalComponentText *txt = static_cast<ECalComponentText*>(g_slist_nth_data(comments, ci)); | ||
| 855 | 1272 | item->addComment(QString::fromUtf8(txt->value)); | ||
| 856 | 1273 | } | ||
| 857 | 1274 | e_cal_component_free_text_list(comments); | ||
| 858 | 1275 | } | ||
| 859 | 1276 | |||
| 860 | 1277 | void QOrganizerEDSEngine::parseTags(ECalComponent *comp, QtOrganizer::QOrganizerItem *item) | ||
| 861 | 1278 | { | ||
| 862 | 1279 | GSList *categories = 0; | ||
| 863 | 1280 | e_cal_component_get_categories_list(comp, &categories); | ||
| 864 | 1281 | for(GSList *tag=categories; tag != 0; tag = tag->next) { | ||
| 865 | 1282 | item->addTag(QString::fromUtf8(static_cast<gchar*>(tag->data))); | ||
| 866 | 1283 | } | ||
| 867 | 1284 | e_cal_component_free_categories_list(categories); | ||
| 868 | 1285 | } | ||
| 869 | 1286 | |||
| 870 | 1287 | QByteArray QOrganizerEDSEngine::dencodeAttachment(ECalComponentAlarm *alarm) | ||
| 871 | 1288 | { | ||
| 872 | 1289 | QByteArray attachment; | ||
| 873 | 1290 | |||
| 874 | 1291 | icalattach *attach = 0; | ||
| 875 | 1292 | e_cal_component_alarm_get_attach(alarm, &attach); | ||
| 876 | 1293 | if (attach) { | ||
| 877 | 1294 | attachment = QByteArray::fromBase64(icalattach_get_url(attach)); | ||
| 878 | 1295 | icalattach_unref(attach); | ||
| 879 | 1296 | } | ||
| 880 | 1297 | |||
| 881 | 1298 | return attachment; | ||
| 882 | 1299 | } | ||
| 883 | 1300 | |||
| 884 | 1301 | |||
| 885 | 1302 | void QOrganizerEDSEngine::parseVisualReminderAttachment(ECalComponentAlarm *alarm, QOrganizerItemReminder *aDetail) | ||
| 886 | 1303 | { | ||
| 887 | 1304 | QByteArray attach = dencodeAttachment(alarm); | ||
| 888 | 1305 | if (!attach.isEmpty()) { | ||
| 889 | 1306 | QUrl url; | ||
| 890 | 1307 | QString txt; | ||
| 891 | 1308 | |||
| 892 | 1309 | QDataStream attachStream(&attach, QIODevice::ReadOnly); | ||
| 893 | 1310 | |||
| 894 | 1311 | attachStream >> url; | ||
| 895 | 1312 | attachStream >> txt; | ||
| 896 | 1313 | |||
| 897 | 1314 | aDetail->setValue(QOrganizerItemVisualReminder::FieldDataUrl, QVariant(url)); | ||
| 898 | 1315 | aDetail->setValue(QOrganizerItemVisualReminder::FieldMessage, QVariant(txt)); | ||
| 899 | 1316 | } | ||
| 900 | 1317 | } | ||
| 901 | 1318 | |||
| 902 | 1319 | |||
| 903 | 1320 | void QOrganizerEDSEngine::parseAudibleReminderAttachment(ECalComponentAlarm *alarm, QOrganizerItemReminder *aDetail) | ||
| 904 | 1321 | { | ||
| 905 | 1322 | QByteArray attach = dencodeAttachment(alarm); | ||
| 906 | 1323 | if (!attach.isEmpty()) { | ||
| 907 | 1324 | QUrl url; | ||
| 908 | 1325 | |||
| 909 | 1326 | QDataStream attachStream(&attach, QIODevice::ReadOnly); | ||
| 910 | 1327 | |||
| 911 | 1328 | attachStream >> url; | ||
| 912 | 1329 | |||
| 913 | 1330 | aDetail->setValue(QOrganizerItemAudibleReminder::FieldDataUrl, QVariant(url)); | ||
| 914 | 1331 | } | ||
| 915 | 1332 | } | ||
| 916 | 1333 | |||
| 917 | 1334 | void QOrganizerEDSEngine::parseReminders(ECalComponent *comp, QtOrganizer::QOrganizerItem *item) | ||
| 918 | 1335 | { | ||
| 919 | 1336 | GList *alarms = e_cal_component_get_alarm_uids(comp); | ||
| 920 | 1337 | for(GList *a = alarms; a != 0; a = a->next) { | ||
| 921 | 1338 | QOrganizerItemReminder *aDetail = 0; | ||
| 922 | 1339 | |||
| 923 | 1340 | ECalComponentAlarm *alarm = e_cal_component_get_alarm(comp, static_cast<const gchar*>(a->data)); | ||
| 924 | 1341 | if (!alarm) { | ||
| 925 | 1342 | continue; | ||
| 926 | 1343 | } | ||
| 927 | 1344 | ECalComponentAlarmAction aAction; | ||
| 928 | 1345 | |||
| 929 | 1346 | e_cal_component_alarm_get_action(alarm, &aAction); | ||
| 930 | 1347 | switch(aAction) | ||
| 931 | 1348 | { | ||
| 932 | 1349 | case E_CAL_COMPONENT_ALARM_DISPLAY: | ||
| 933 | 1350 | aDetail = new QOrganizerItemVisualReminder(); | ||
| 934 | 1351 | parseVisualReminderAttachment(alarm, aDetail); | ||
| 935 | 1352 | break; | ||
| 936 | 1353 | case E_CAL_COMPONENT_ALARM_AUDIO: | ||
| 937 | 1354 | // use audio as fallback | ||
| 938 | 1355 | default: | ||
| 939 | 1356 | aDetail = new QOrganizerItemAudibleReminder(); | ||
| 940 | 1357 | parseAudibleReminderAttachment(alarm, aDetail); | ||
| 941 | 1358 | break; | ||
| 942 | 1359 | } | ||
| 943 | 1360 | |||
| 944 | 1361 | ECalComponentAlarmTrigger trigger; | ||
| 945 | 1362 | e_cal_component_alarm_get_trigger(alarm, &trigger); | ||
| 946 | 1363 | if (trigger.type == E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START) { | ||
| 947 | 1364 | aDetail->setSecondsBeforeStart(icaldurationtype_as_int(trigger.u.rel_duration) * -1); | ||
| 948 | 1365 | } | ||
| 949 | 1366 | |||
| 950 | 1367 | ECalComponentAlarmRepeat aRepeat; | ||
| 951 | 1368 | e_cal_component_alarm_get_repeat(alarm, &aRepeat); | ||
| 952 | 1369 | aDetail->setRepetition(aRepeat.repetitions, icaldurationtype_as_int(aRepeat.duration)); | ||
| 953 | 1370 | |||
| 954 | 1371 | item->saveDetail(aDetail); | ||
| 955 | 1372 | delete aDetail; | ||
| 956 | 1373 | } | ||
| 957 | 1374 | } | ||
| 958 | 1375 | |||
| 959 | 869 | QList<QOrganizerItem> QOrganizerEDSEngine::parseEvents(QOrganizerEDSCollectionEngineId *collection, GSList *events) | 1376 | QList<QOrganizerItem> QOrganizerEDSEngine::parseEvents(QOrganizerEDSCollectionEngineId *collection, GSList *events) |
| 960 | 870 | { | 1377 | { |
| 961 | 871 | QList<QOrganizerItem> items; | 1378 | QList<QOrganizerItem> items; |
| 962 | @@ -905,32 +1412,11 @@ | |||
| 963 | 905 | collection->managerUri()); | 1412 | collection->managerUri()); |
| 964 | 906 | item->setId(QOrganizerItemId(eid)); | 1413 | item->setId(QOrganizerItemId(eid)); |
| 965 | 907 | item->setCollectionId(cId); | 1414 | item->setCollectionId(cId); |
| 992 | 908 | qDebug() << ">>>>>>>>>>>>>>>>>>Loaded item id: " << item->id().toString(); | 1415 | parseDescription(comp, item); |
| 993 | 909 | 1416 | parseSummary(comp, item); | |
| 994 | 910 | //summary | 1417 | parseComments(comp, item); |
| 995 | 911 | ECalComponentText summary; | 1418 | parseTags(comp, item); |
| 996 | 912 | e_cal_component_get_summary(comp, &summary); | 1419 | parseReminders(comp, item); |
| 971 | 913 | if (summary.value) { | ||
| 972 | 914 | item->setDisplayLabel(QString::fromUtf8(summary.value)); | ||
| 973 | 915 | } | ||
| 974 | 916 | |||
| 975 | 917 | //comments | ||
| 976 | 918 | GSList *comments = 0; | ||
| 977 | 919 | e_cal_component_get_comment_list(comp, &comments); | ||
| 978 | 920 | for(int ci=0, ciMax=g_slist_length(comments); ci < ciMax; ci++) { | ||
| 979 | 921 | ECalComponentText *txt = static_cast<ECalComponentText*>(g_slist_nth_data(comments, ci)); | ||
| 980 | 922 | item->addComment(QString::fromUtf8(txt->value)); | ||
| 981 | 923 | } | ||
| 982 | 924 | e_cal_component_free_text_list(comments); | ||
| 983 | 925 | |||
| 984 | 926 | //tags | ||
| 985 | 927 | GSList *categories = 0; | ||
| 986 | 928 | e_cal_component_get_categories_list(comp, &categories); | ||
| 987 | 929 | for(int ci=0, ciMax=g_slist_length(comments); ci < ciMax; ci++) { | ||
| 988 | 930 | item->addTag(QString::fromUtf8(static_cast<gchar*>(g_slist_nth_data(categories, ci)))); | ||
| 989 | 931 | } | ||
| 990 | 932 | e_cal_component_free_categories_list(categories); | ||
| 991 | 933 | |||
| 997 | 934 | 1420 | ||
| 998 | 935 | // //Attendee | 1421 | // //Attendee |
| 999 | 936 | // GList *attendeeList = 0; | 1422 | // GList *attendeeList = 0; |
| 1000 | @@ -958,10 +1444,12 @@ | |||
| 1001 | 958 | { | 1444 | { |
| 1002 | 959 | QOrganizerEventTime etr = item.detail(QOrganizerItemDetail::TypeEventTime); | 1445 | QOrganizerEventTime etr = item.detail(QOrganizerItemDetail::TypeEventTime); |
| 1003 | 960 | if (!etr.isEmpty()) { | 1446 | if (!etr.isEmpty()) { |
| 1008 | 961 | ECalComponentDateTime dt; | 1447 | ECalComponentDateTime *dt = g_new0(ECalComponentDateTime, 1); |
| 1009 | 962 | struct icaltimetype itt = icaltime_from_timet(etr.startDateTime().toTime_t(), FALSE); | 1448 | dt->value = g_new0(struct icaltimetype, 1); |
| 1010 | 963 | dt.value = &itt; | 1449 | *dt->value = icaltime_from_timet(etr.startDateTime().toTime_t(), FALSE); |
| 1011 | 964 | e_cal_component_set_dtstart(comp, &dt); | 1450 | |
| 1012 | 1451 | e_cal_component_set_dtstart(comp, dt); | ||
| 1013 | 1452 | e_cal_component_free_datetime(dt); | ||
| 1014 | 965 | } | 1453 | } |
| 1015 | 966 | } | 1454 | } |
| 1016 | 967 | 1455 | ||
| 1017 | @@ -969,12 +1457,98 @@ | |||
| 1018 | 969 | { | 1457 | { |
| 1019 | 970 | QOrganizerEventTime etr = item.detail(QOrganizerItemDetail::TypeEventTime); | 1458 | QOrganizerEventTime etr = item.detail(QOrganizerItemDetail::TypeEventTime); |
| 1020 | 971 | if (!etr.isEmpty()) { | 1459 | if (!etr.isEmpty()) { |
| 1027 | 972 | ECalComponentDateTime dt; | 1460 | ECalComponentDateTime *dt = g_new0(ECalComponentDateTime, 1); |
| 1028 | 973 | struct icaltimetype itt = icaltime_from_timet(etr.endDateTime().toTime_t(), FALSE); | 1461 | dt->value = g_new0(struct icaltimetype, 1); |
| 1029 | 974 | dt.value = &itt; | 1462 | *dt->value = icaltime_from_timet(etr.endDateTime().toTime_t(), FALSE); |
| 1030 | 975 | e_cal_component_set_dtend(comp, &dt);; | 1463 | e_cal_component_set_dtend(comp, dt); |
| 1031 | 976 | } | 1464 | e_cal_component_free_datetime(dt); |
| 1032 | 977 | } | 1465 | } |
| 1033 | 1466 | } | ||
| 1034 | 1467 | |||
| 1035 | 1468 | void QOrganizerEDSEngine::parseTodoStartTime(const QOrganizerItem &item, ECalComponent *comp) | ||
| 1036 | 1469 | { | ||
| 1037 | 1470 | QOrganizerTodoTime etr = item.detail(QOrganizerItemDetail::TypeTodoTime); | ||
| 1038 | 1471 | if (!etr.isEmpty()) { | ||
| 1039 | 1472 | ECalComponentDateTime *dt = g_new0(ECalComponentDateTime, 1); | ||
| 1040 | 1473 | dt->value = g_new0(struct icaltimetype, 1); | ||
| 1041 | 1474 | *dt->value = icaltime_from_timet(etr.startDateTime().toTime_t(), FALSE); | ||
| 1042 | 1475 | |||
| 1043 | 1476 | e_cal_component_set_dtstart(comp, dt); | ||
| 1044 | 1477 | e_cal_component_free_datetime(dt); | ||
| 1045 | 1478 | } | ||
| 1046 | 1479 | } | ||
| 1047 | 1480 | |||
| 1048 | 1481 | void QOrganizerEDSEngine::parseWeekRecurrence(const QOrganizerRecurrenceRule &qRule, struct icalrecurrencetype *rule) | ||
| 1049 | 1482 | { | ||
| 1050 | 1483 | static QMap<Qt::DayOfWeek, icalrecurrencetype_weekday> daysOfWeekMap; | ||
| 1051 | 1484 | if (daysOfWeekMap.isEmpty()) { | ||
| 1052 | 1485 | daysOfWeekMap.insert(Qt::Monday, ICAL_MONDAY_WEEKDAY); | ||
| 1053 | 1486 | daysOfWeekMap.insert(Qt::Thursday, ICAL_THURSDAY_WEEKDAY); | ||
| 1054 | 1487 | daysOfWeekMap.insert(Qt::Wednesday, ICAL_WEDNESDAY_WEEKDAY); | ||
| 1055 | 1488 | daysOfWeekMap.insert(Qt::Tuesday, ICAL_TUESDAY_WEEKDAY); | ||
| 1056 | 1489 | daysOfWeekMap.insert(Qt::Friday, ICAL_FRIDAY_WEEKDAY); | ||
| 1057 | 1490 | daysOfWeekMap.insert(Qt::Saturday, ICAL_SATURDAY_WEEKDAY); | ||
| 1058 | 1491 | daysOfWeekMap.insert(Qt::Sunday, ICAL_SUNDAY_WEEKDAY); | ||
| 1059 | 1492 | } | ||
| 1060 | 1493 | |||
| 1061 | 1494 | QList<Qt::DayOfWeek> daysOfWeek = qRule.daysOfWeek().toList(); | ||
| 1062 | 1495 | int c = 0; | ||
| 1063 | 1496 | |||
| 1064 | 1497 | rule->freq = ICAL_WEEKLY_RECURRENCE; | ||
| 1065 | 1498 | for(int d=Qt::Monday; d <= Qt::Sunday; d++) { | ||
| 1066 | 1499 | if (daysOfWeek.contains(static_cast<Qt::DayOfWeek>(d))) { | ||
| 1067 | 1500 | rule->by_day[c++] = daysOfWeekMap[static_cast<Qt::DayOfWeek>(d)]; | ||
| 1068 | 1501 | } | ||
| 1069 | 1502 | } | ||
| 1070 | 1503 | for (int d = c; d < ICAL_BY_DAY_SIZE; d++) { | ||
| 1071 | 1504 | rule->by_day[d] = ICAL_RECURRENCE_ARRAY_MAX; | ||
| 1072 | 1505 | } | ||
| 1073 | 1506 | } | ||
| 1074 | 1507 | |||
| 1075 | 1508 | void QOrganizerEDSEngine::parseMonthRecurrence(const QOrganizerRecurrenceRule &qRule, struct icalrecurrencetype *rule) | ||
| 1076 | 1509 | { | ||
| 1077 | 1510 | rule->freq = ICAL_MONTHLY_RECURRENCE; | ||
| 1078 | 1511 | |||
| 1079 | 1512 | QList<int> daysOfMonth = qRule.daysOfMonth().toList(); | ||
| 1080 | 1513 | int c = 0; | ||
| 1081 | 1514 | for (int d=1; d < ICAL_BY_MONTHDAY_SIZE; d++) { | ||
| 1082 | 1515 | if (daysOfMonth.contains(d)) { | ||
| 1083 | 1516 | rule->by_month_day[c++] = d; | ||
| 1084 | 1517 | } | ||
| 1085 | 1518 | } | ||
| 1086 | 1519 | for (int d = c; d < ICAL_BY_MONTHDAY_SIZE; d++) { | ||
| 1087 | 1520 | rule->by_month_day[d] = ICAL_RECURRENCE_ARRAY_MAX; | ||
| 1088 | 1521 | } | ||
| 1089 | 1522 | } | ||
| 1090 | 1523 | |||
| 1091 | 1524 | void QOrganizerEDSEngine::parseYearRecurrence(const QOrganizerRecurrenceRule &qRule, struct icalrecurrencetype *rule) | ||
| 1092 | 1525 | { | ||
| 1093 | 1526 | rule->freq = ICAL_YEARLY_RECURRENCE; | ||
| 1094 | 1527 | |||
| 1095 | 1528 | QList<int> daysOfYear = qRule.daysOfYear().toList(); | ||
| 1096 | 1529 | int c = 0; | ||
| 1097 | 1530 | for (int d=1; d < ICAL_BY_YEARDAY_SIZE; d++) { | ||
| 1098 | 1531 | if (daysOfYear.contains(d)) { | ||
| 1099 | 1532 | rule->by_year_day[c++] = d; | ||
| 1100 | 1533 | } | ||
| 1101 | 1534 | } | ||
| 1102 | 1535 | for (int d = c; d < ICAL_BY_YEARDAY_SIZE; d++) { | ||
| 1103 | 1536 | rule->by_year_day[d] = ICAL_RECURRENCE_ARRAY_MAX; | ||
| 1104 | 1537 | } | ||
| 1105 | 1538 | |||
| 1106 | 1539 | c = 0; | ||
| 1107 | 1540 | QList<QOrganizerRecurrenceRule::Month> monthOfYear = qRule.monthsOfYear().toList(); | ||
| 1108 | 1541 | for (int d=1; d < ICAL_BY_MONTH_SIZE; d++) { | ||
| 1109 | 1542 | if (monthOfYear.contains(static_cast<QOrganizerRecurrenceRule::Month>(d))) { | ||
| 1110 | 1543 | rule->by_month[c++] = d; | ||
| 1111 | 1544 | } | ||
| 1112 | 1545 | } | ||
| 1113 | 1546 | for (int d = c; d < ICAL_BY_YEARDAY_SIZE; d++) { | ||
| 1114 | 1547 | rule->by_month[d] = ICAL_RECURRENCE_ARRAY_MAX; | ||
| 1115 | 1548 | } | ||
| 1116 | 1549 | } | ||
| 1117 | 1550 | |||
| 1118 | 1551 | |||
| 1119 | 978 | 1552 | ||
| 1120 | 979 | void QOrganizerEDSEngine::parseRecurrence(const QOrganizerItem &item, ECalComponent *comp) | 1553 | void QOrganizerEDSEngine::parseRecurrence(const QOrganizerItem &item, ECalComponent *comp) |
| 1121 | 980 | { | 1554 | { |
| 1122 | @@ -983,7 +1557,7 @@ | |||
| 1123 | 983 | GSList *periodList = 0; | 1557 | GSList *periodList = 0; |
| 1124 | 984 | Q_FOREACH(QDate dt, rec.recurrenceDates()) { | 1558 | Q_FOREACH(QDate dt, rec.recurrenceDates()) { |
| 1125 | 985 | ECalComponentPeriod *period = g_new0(ECalComponentPeriod, 1); | 1559 | ECalComponentPeriod *period = g_new0(ECalComponentPeriod, 1); |
| 1127 | 986 | period->start = icaltime_from_timet(QDateTime(dt).toTime_t(), TRUE); | 1560 | period->start = icaltime_from_timet(QDateTime(dt).toTime_t(), FALSE); |
| 1128 | 987 | periodList = g_slist_append(periodList, period); | 1561 | periodList = g_slist_append(periodList, period); |
| 1129 | 988 | //TODO: period.end, period.duration | 1562 | //TODO: period.end, period.duration |
| 1130 | 989 | } | 1563 | } |
| 1131 | @@ -992,15 +1566,58 @@ | |||
| 1132 | 992 | 1566 | ||
| 1133 | 993 | GSList *exdateList = 0; | 1567 | GSList *exdateList = 0; |
| 1134 | 994 | Q_FOREACH(QDate dt, rec.exceptionDates()) { | 1568 | Q_FOREACH(QDate dt, rec.exceptionDates()) { |
| 1139 | 995 | ECalComponentDateTime dateTime; | 1569 | ECalComponentDateTime *dateTime = g_new0(ECalComponentDateTime, 1); |
| 1140 | 996 | struct icaltimetype itt = icaltime_from_timet(QDateTime(dt).toTime_t(), TRUE); | 1570 | struct icaltimetype *itt = g_new0(struct icaltimetype, 1); |
| 1141 | 997 | dateTime.value = &itt; | 1571 | *itt = icaltime_from_timet(QDateTime(dt).toTime_t(), FALSE); |
| 1142 | 998 | exdateList = g_slist_append(exdateList, &dateTime); | 1572 | dateTime->value = itt; |
| 1143 | 1573 | exdateList = g_slist_append(exdateList, dateTime); | ||
| 1144 | 999 | } | 1574 | } |
| 1145 | 1000 | e_cal_component_set_exdate_list(comp, exdateList); | 1575 | e_cal_component_set_exdate_list(comp, exdateList); |
| 1146 | 1001 | e_cal_component_free_exdate_list(exdateList); | 1576 | e_cal_component_free_exdate_list(exdateList); |
| 1147 | 1577 | |||
| 1148 | 1578 | GSList *ruleList = 0; | ||
| 1149 | 1579 | Q_FOREACH(QOrganizerRecurrenceRule qRule, rec.recurrenceRules()) { | ||
| 1150 | 1580 | struct icalrecurrencetype *rule = g_new0(struct icalrecurrencetype, 1); | ||
| 1151 | 1581 | switch(qRule.frequency()) { | ||
| 1152 | 1582 | case QOrganizerRecurrenceRule::Daily: | ||
| 1153 | 1583 | rule->freq = ICAL_DAILY_RECURRENCE; | ||
| 1154 | 1584 | break; | ||
| 1155 | 1585 | case QOrganizerRecurrenceRule::Weekly: | ||
| 1156 | 1586 | parseWeekRecurrence(qRule, rule); | ||
| 1157 | 1587 | break; | ||
| 1158 | 1588 | case QOrganizerRecurrenceRule::Monthly: | ||
| 1159 | 1589 | parseMonthRecurrence(qRule, rule); | ||
| 1160 | 1590 | break; | ||
| 1161 | 1591 | case QOrganizerRecurrenceRule::Yearly: | ||
| 1162 | 1592 | parseYearRecurrence(qRule, rule); | ||
| 1163 | 1593 | break; | ||
| 1164 | 1594 | case QOrganizerRecurrenceRule::Invalid: | ||
| 1165 | 1595 | rule->freq = ICAL_NO_RECURRENCE; | ||
| 1166 | 1596 | break; | ||
| 1167 | 1597 | } | ||
| 1168 | 1598 | |||
| 1169 | 1599 | if (qRule.limitDate().isValid()) { | ||
| 1170 | 1600 | rule->until = icaltime_from_timet(QDateTime(qRule.limitDate()).toTime_t(), TRUE); | ||
| 1171 | 1601 | rule->count = ICAL_RECURRENCE_ARRAY_MAX; | ||
| 1172 | 1602 | } else { | ||
| 1173 | 1603 | rule->count = qRule.limitCount(); | ||
| 1174 | 1604 | } | ||
| 1175 | 1605 | |||
| 1176 | 1606 | QSet<int> positions = qRule.positions(); | ||
| 1177 | 1607 | for (int d=1; d < ICAL_BY_SETPOS_SIZE; d++) { | ||
| 1178 | 1608 | if (positions.contains(d)) { | ||
| 1179 | 1609 | rule->by_set_pos[d] = d; | ||
| 1180 | 1610 | } else { | ||
| 1181 | 1611 | rule->by_set_pos[d] = ICAL_RECURRENCE_ARRAY_MAX; | ||
| 1182 | 1612 | } | ||
| 1183 | 1613 | } | ||
| 1184 | 1614 | |||
| 1185 | 1615 | rule->interval = qRule.interval(); | ||
| 1186 | 1616 | ruleList = g_slist_append(ruleList, rule); | ||
| 1187 | 1617 | } | ||
| 1188 | 1618 | e_cal_component_set_rrule_list(comp, ruleList); | ||
| 1189 | 1619 | //TODO: free ruleList | ||
| 1190 | 1002 | } | 1620 | } |
| 1191 | 1003 | // TODO: exeptions rules | ||
| 1192 | 1004 | } | 1621 | } |
| 1193 | 1005 | 1622 | ||
| 1194 | 1006 | void QOrganizerEDSEngine::parsePriority(const QOrganizerItem &item, ECalComponent *comp) | 1623 | void QOrganizerEDSEngine::parsePriority(const QOrganizerItem &item, ECalComponent *comp) |
| 1195 | @@ -1008,6 +1625,7 @@ | |||
| 1196 | 1008 | QOrganizerItemPriority priority = item.detail(QOrganizerItemDetail::TypePriority); | 1625 | QOrganizerItemPriority priority = item.detail(QOrganizerItemDetail::TypePriority); |
| 1197 | 1009 | if (!priority.isEmpty()) { | 1626 | if (!priority.isEmpty()) { |
| 1198 | 1010 | gint iPriority = (gint) priority.priority(); | 1627 | gint iPriority = (gint) priority.priority(); |
| 1199 | 1628 | qDebug() << "Priority" << iPriority; | ||
| 1200 | 1011 | e_cal_component_set_priority(comp, &iPriority); | 1629 | e_cal_component_set_priority(comp, &iPriority); |
| 1201 | 1012 | } | 1630 | } |
| 1202 | 1013 | } | 1631 | } |
| 1203 | @@ -1024,10 +1642,14 @@ | |||
| 1204 | 1024 | { | 1642 | { |
| 1205 | 1025 | QOrganizerTodoTime ttr = item.detail(QOrganizerItemDetail::TypeTodoTime); | 1643 | QOrganizerTodoTime ttr = item.detail(QOrganizerItemDetail::TypeTodoTime); |
| 1206 | 1026 | if (!ttr.isEmpty()) { | 1644 | if (!ttr.isEmpty()) { |
| 1208 | 1027 | ECalComponentDateTime due; | 1645 | qDebug() << "Due date" << ttr.dueDateTime(); |
| 1209 | 1646 | ECalComponentDateTime *due = g_new0(ECalComponentDateTime, 1); | ||
| 1210 | 1647 | due->value = g_new0(struct icaltimetype, 1); | ||
| 1211 | 1648 | |||
| 1212 | 1028 | struct icaltimetype itt = icaltime_from_timet(ttr.dueDateTime().toTime_t(), FALSE); | 1649 | struct icaltimetype itt = icaltime_from_timet(ttr.dueDateTime().toTime_t(), FALSE); |
| 1215 | 1029 | due.value = &itt; | 1650 | *due->value = itt; |
| 1216 | 1030 | e_cal_component_set_due(comp, &due); | 1651 | e_cal_component_set_due(comp, due); |
| 1217 | 1652 | e_cal_component_free_datetime(due); | ||
| 1218 | 1031 | } | 1653 | } |
| 1219 | 1032 | } | 1654 | } |
| 1220 | 1033 | 1655 | ||
| 1221 | @@ -1035,6 +1657,7 @@ | |||
| 1222 | 1035 | { | 1657 | { |
| 1223 | 1036 | QOrganizerTodoProgress tp = item.detail(QOrganizerItemDetail::TypeTodoProgress); | 1658 | QOrganizerTodoProgress tp = item.detail(QOrganizerItemDetail::TypeTodoProgress); |
| 1224 | 1037 | if (!tp.isEmpty()) { | 1659 | if (!tp.isEmpty()) { |
| 1225 | 1660 | qDebug() << "Progress" << tp.percentageComplete(); | ||
| 1226 | 1038 | e_cal_component_set_percent_as_int(comp, tp.percentageComplete()); | 1661 | e_cal_component_set_percent_as_int(comp, tp.percentageComplete()); |
| 1227 | 1039 | } | 1662 | } |
| 1228 | 1040 | } | 1663 | } |
| 1229 | @@ -1048,22 +1671,45 @@ | |||
| 1230 | 1048 | e_cal_component_set_status(comp, ICAL_STATUS_NONE); | 1671 | e_cal_component_set_status(comp, ICAL_STATUS_NONE); |
| 1231 | 1049 | break; | 1672 | break; |
| 1232 | 1050 | case QOrganizerTodoProgress::StatusInProgress: | 1673 | case QOrganizerTodoProgress::StatusInProgress: |
| 1233 | 1674 | qDebug() << "Set status in progress"; | ||
| 1234 | 1051 | e_cal_component_set_status(comp, ICAL_STATUS_INPROCESS); | 1675 | e_cal_component_set_status(comp, ICAL_STATUS_INPROCESS); |
| 1235 | 1052 | break; | 1676 | break; |
| 1236 | 1053 | case QOrganizerTodoProgress::StatusComplete: | 1677 | case QOrganizerTodoProgress::StatusComplete: |
| 1237 | 1054 | e_cal_component_set_status(comp, ICAL_STATUS_COMPLETED); | 1678 | e_cal_component_set_status(comp, ICAL_STATUS_COMPLETED); |
| 1238 | 1055 | break; | 1679 | break; |
| 1239 | 1056 | default: | 1680 | default: |
| 1240 | 1681 | qDebug() << "Set status cancelled"; | ||
| 1241 | 1057 | e_cal_component_set_status(comp, ICAL_STATUS_CANCELLED); | 1682 | e_cal_component_set_status(comp, ICAL_STATUS_CANCELLED); |
| 1242 | 1058 | break; | 1683 | break; |
| 1243 | 1059 | } | 1684 | } |
| 1244 | 1060 | } | 1685 | } |
| 1245 | 1061 | } | 1686 | } |
| 1246 | 1062 | 1687 | ||
| 1251 | 1063 | ECalComponent *QOrganizerEDSEngine::parseEventItem(const QOrganizerItem &item) | 1688 | ECalComponent *QOrganizerEDSEngine::createDefaultComponent(ECalClient *client, |
| 1252 | 1064 | { | 1689 | icalcomponent_kind iKind, |
| 1253 | 1065 | ECalComponent *comp = e_cal_component_new(); | 1690 | ECalComponentVType eType) |
| 1254 | 1066 | e_cal_component_set_new_vtype(comp, E_CAL_COMPONENT_EVENT); | 1691 | { |
| 1255 | 1692 | ECalComponent *comp; | ||
| 1256 | 1693 | icalcomponent *icalcomp = 0; | ||
| 1257 | 1694 | |||
| 1258 | 1695 | if (client && !e_cal_client_get_default_object_sync(client, &icalcomp, NULL, NULL)) { | ||
| 1259 | 1696 | icalcomp = icalcomponent_new(iKind); | ||
| 1260 | 1697 | } | ||
| 1261 | 1698 | |||
| 1262 | 1699 | comp = e_cal_component_new(); | ||
| 1263 | 1700 | if (icalcomp && !e_cal_component_set_icalcomponent(comp, icalcomp)) { | ||
| 1264 | 1701 | icalcomponent_free(icalcomp); | ||
| 1265 | 1702 | } | ||
| 1266 | 1703 | |||
| 1267 | 1704 | e_cal_component_set_new_vtype(comp, eType); | ||
| 1268 | 1705 | |||
| 1269 | 1706 | return comp; | ||
| 1270 | 1707 | } | ||
| 1271 | 1708 | |||
| 1272 | 1709 | ECalComponent *QOrganizerEDSEngine::parseEventItem(ECalClient *client, const QOrganizerItem &item) | ||
| 1273 | 1710 | { | ||
| 1274 | 1711 | qDebug() << Q_FUNC_INFO; | ||
| 1275 | 1712 | ECalComponent *comp = createDefaultComponent(client, ICAL_VEVENT_COMPONENT, E_CAL_COMPONENT_EVENT); | ||
| 1276 | 1067 | 1713 | ||
| 1277 | 1068 | parseStartTime(item, comp); | 1714 | parseStartTime(item, comp); |
| 1278 | 1069 | parseEndTime(item, comp); | 1715 | parseEndTime(item, comp); |
| 1279 | @@ -1074,12 +1720,12 @@ | |||
| 1280 | 1074 | 1720 | ||
| 1281 | 1075 | } | 1721 | } |
| 1282 | 1076 | 1722 | ||
| 1284 | 1077 | ECalComponent *QOrganizerEDSEngine::parseTodoItem(const QOrganizerItem &item) | 1723 | ECalComponent *QOrganizerEDSEngine::parseTodoItem(ECalClient *client, const QOrganizerItem &item) |
| 1285 | 1078 | { | 1724 | { |
| 1288 | 1079 | ECalComponent *comp = e_cal_component_new(); | 1725 | qDebug() << Q_FUNC_INFO; |
| 1289 | 1080 | e_cal_component_set_new_vtype(comp, E_CAL_COMPONENT_TODO); | 1726 | ECalComponent *comp = createDefaultComponent(client, ICAL_VTODO_COMPONENT, E_CAL_COMPONENT_TODO); |
| 1290 | 1081 | 1727 | ||
| 1292 | 1082 | parseStartTime(item, comp); | 1728 | parseTodoStartTime(item, comp); |
| 1293 | 1083 | parseDueDate(item, comp); | 1729 | parseDueDate(item, comp); |
| 1294 | 1084 | parseRecurrence(item, comp); | 1730 | parseRecurrence(item, comp); |
| 1295 | 1085 | parsePriority(item, comp); | 1731 | parsePriority(item, comp); |
| 1296 | @@ -1089,10 +1735,10 @@ | |||
| 1297 | 1089 | return comp; | 1735 | return comp; |
| 1298 | 1090 | } | 1736 | } |
| 1299 | 1091 | 1737 | ||
| 1301 | 1092 | ECalComponent *QOrganizerEDSEngine::parseJournalItem(const QOrganizerItem &item) | 1738 | ECalComponent *QOrganizerEDSEngine::parseJournalItem(ECalClient *client, const QOrganizerItem &item) |
| 1302 | 1093 | { | 1739 | { |
| 1305 | 1094 | ECalComponent *comp = e_cal_component_new(); | 1740 | qDebug() << Q_FUNC_INFO; |
| 1306 | 1095 | e_cal_component_set_new_vtype(comp, E_CAL_COMPONENT_JOURNAL); | 1741 | ECalComponent *comp = createDefaultComponent(client, ICAL_VJOURNAL_COMPONENT, E_CAL_COMPONENT_JOURNAL); |
| 1307 | 1096 | 1742 | ||
| 1308 | 1097 | QOrganizerJournalTime jtime = item.detail(QOrganizerItemDetail::TypeJournalTime); | 1743 | QOrganizerJournalTime jtime = item.detail(QOrganizerItemDetail::TypeJournalTime); |
| 1309 | 1098 | if (!jtime.isEmpty()) { | 1744 | if (!jtime.isEmpty()) { |
| 1310 | @@ -1105,7 +1751,147 @@ | |||
| 1311 | 1105 | return comp; | 1751 | return comp; |
| 1312 | 1106 | } | 1752 | } |
| 1313 | 1107 | 1753 | ||
| 1315 | 1108 | GSList *QOrganizerEDSEngine::parseItems(QList<QOrganizerItem> items) | 1754 | void QOrganizerEDSEngine::parseSummary(const QOrganizerItem &item, ECalComponent *comp) |
| 1316 | 1755 | { | ||
| 1317 | 1756 | //summary | ||
| 1318 | 1757 | if (!item.displayLabel().isEmpty()) { | ||
| 1319 | 1758 | ECalComponentText txt; | ||
| 1320 | 1759 | QByteArray str = item.displayLabel().toUtf8(); | ||
| 1321 | 1760 | txt.altrep = 0; | ||
| 1322 | 1761 | txt.value = str.constData(); | ||
| 1323 | 1762 | e_cal_component_set_summary(comp, &txt); | ||
| 1324 | 1763 | } | ||
| 1325 | 1764 | } | ||
| 1326 | 1765 | |||
| 1327 | 1766 | void QOrganizerEDSEngine::parseDescription(const QOrganizerItem &item, ECalComponent *comp) | ||
| 1328 | 1767 | { | ||
| 1329 | 1768 | //description | ||
| 1330 | 1769 | if (item.description().isEmpty()) { | ||
| 1331 | 1770 | GSList *descriptions = 0; | ||
| 1332 | 1771 | QByteArray str = item.description().toUtf8(); | ||
| 1333 | 1772 | ECalComponentText *txt = g_new0(ECalComponentText, 1); | ||
| 1334 | 1773 | |||
| 1335 | 1774 | txt->value = str.constData(); | ||
| 1336 | 1775 | descriptions = g_slist_append(descriptions, txt); | ||
| 1337 | 1776 | |||
| 1338 | 1777 | e_cal_component_set_description_list(comp, descriptions); | ||
| 1339 | 1778 | e_cal_component_free_text_list(descriptions); | ||
| 1340 | 1779 | } | ||
| 1341 | 1780 | } | ||
| 1342 | 1781 | |||
| 1343 | 1782 | void QOrganizerEDSEngine::parseComments(const QOrganizerItem &item, ECalComponent *comp) | ||
| 1344 | 1783 | { | ||
| 1345 | 1784 | //comments | ||
| 1346 | 1785 | GSList *comments = 0; | ||
| 1347 | 1786 | Q_FOREACH(QString comment, item.comments()) { | ||
| 1348 | 1787 | QByteArray str = comment.toUtf8(); | ||
| 1349 | 1788 | ECalComponentText *txt = g_new0(ECalComponentText, 1); | ||
| 1350 | 1789 | txt->value = str.constData(); | ||
| 1351 | 1790 | comments = g_slist_append(comments, txt); | ||
| 1352 | 1791 | } | ||
| 1353 | 1792 | |||
| 1354 | 1793 | if (comments) { | ||
| 1355 | 1794 | e_cal_component_set_comment_list(comp, comments); | ||
| 1356 | 1795 | e_cal_component_free_text_list(comments); | ||
| 1357 | 1796 | } | ||
| 1358 | 1797 | } | ||
| 1359 | 1798 | |||
| 1360 | 1799 | void QOrganizerEDSEngine::parseTags(const QOrganizerItem &item, ECalComponent *comp) | ||
| 1361 | 1800 | { | ||
| 1362 | 1801 | //tags | ||
| 1363 | 1802 | GSList *categories = 0; | ||
| 1364 | 1803 | Q_FOREACH(QString tag, item.tags()) { | ||
| 1365 | 1804 | QByteArray str = tag.toUtf8(); | ||
| 1366 | 1805 | ECalComponentText *txt = g_new0(ECalComponentText, 1); | ||
| 1367 | 1806 | txt->value = str.constData(); | ||
| 1368 | 1807 | categories = g_slist_append(categories, txt); | ||
| 1369 | 1808 | } | ||
| 1370 | 1809 | |||
| 1371 | 1810 | if (categories) { | ||
| 1372 | 1811 | e_cal_component_set_categories_list(comp, categories); | ||
| 1373 | 1812 | e_cal_component_free_text_list(categories); | ||
| 1374 | 1813 | } | ||
| 1375 | 1814 | } | ||
| 1376 | 1815 | |||
| 1377 | 1816 | void QOrganizerEDSEngine::encodeAttachment(QByteArray data, ECalComponentAlarm *alarm) | ||
| 1378 | 1817 | { | ||
| 1379 | 1818 | gchar *b64Bytes = strdup(data.toBase64()); | ||
| 1380 | 1819 | icalattach *attach = icalattach_new_from_url(b64Bytes); | ||
| 1381 | 1820 | |||
| 1382 | 1821 | e_cal_component_alarm_set_attach(alarm, attach); | ||
| 1383 | 1822 | |||
| 1384 | 1823 | icalattach_unref(attach); | ||
| 1385 | 1824 | } | ||
| 1386 | 1825 | |||
| 1387 | 1826 | void QOrganizerEDSEngine::parseVisualReminderAttachment(const QOrganizerItemDetail &detail, ECalComponentAlarm *alarm) | ||
| 1388 | 1827 | { | ||
| 1389 | 1828 | QByteArray attachBytes; | ||
| 1390 | 1829 | |||
| 1391 | 1830 | { | ||
| 1392 | 1831 | QDataStream attachData(&attachBytes, QIODevice::WriteOnly); | ||
| 1393 | 1832 | |||
| 1394 | 1833 | attachData << detail.value(QOrganizerItemVisualReminder::FieldDataUrl).toUrl(); | ||
| 1395 | 1834 | attachData << detail.value(QOrganizerItemVisualReminder::FieldMessage).toString(); | ||
| 1396 | 1835 | } | ||
| 1397 | 1836 | |||
| 1398 | 1837 | encodeAttachment(attachBytes, alarm); | ||
| 1399 | 1838 | } | ||
| 1400 | 1839 | |||
| 1401 | 1840 | void QOrganizerEDSEngine::parseAudibleReminderAttachment(const QOrganizerItemDetail &detail, ECalComponentAlarm *alarm) | ||
| 1402 | 1841 | { | ||
| 1403 | 1842 | QByteArray attachBytes; | ||
| 1404 | 1843 | |||
| 1405 | 1844 | { | ||
| 1406 | 1845 | QDataStream attachData(&attachBytes, QIODevice::WriteOnly); | ||
| 1407 | 1846 | attachData << detail.value(QOrganizerItemAudibleReminder::FieldDataUrl).toUrl(); | ||
| 1408 | 1847 | } | ||
| 1409 | 1848 | |||
| 1410 | 1849 | encodeAttachment(attachBytes, alarm); | ||
| 1411 | 1850 | } | ||
| 1412 | 1851 | |||
| 1413 | 1852 | void QOrganizerEDSEngine::parseReminders(const QOrganizerItem &item, ECalComponent *comp) | ||
| 1414 | 1853 | { | ||
| 1415 | 1854 | //reminders | ||
| 1416 | 1855 | QList<QOrganizerItemDetail> reminders = item.details(QOrganizerItemDetail::TypeAudibleReminder); | ||
| 1417 | 1856 | reminders += item.details(QOrganizerItemDetail::TypeVisualReminder); | ||
| 1418 | 1857 | |||
| 1419 | 1858 | Q_FOREACH(const QOrganizerItemDetail &detail, reminders) { | ||
| 1420 | 1859 | const QOrganizerItemReminder *reminder = static_cast<const QOrganizerItemReminder*>(&detail); | ||
| 1421 | 1860 | |||
| 1422 | 1861 | ECalComponentAlarm *alarm = e_cal_component_alarm_new(); | ||
| 1423 | 1862 | switch(reminder->type()) | ||
| 1424 | 1863 | { | ||
| 1425 | 1864 | case QOrganizerItemReminder::TypeVisualReminder: | ||
| 1426 | 1865 | e_cal_component_alarm_set_action(alarm, E_CAL_COMPONENT_ALARM_DISPLAY); | ||
| 1427 | 1866 | parseVisualReminderAttachment(detail, alarm); | ||
| 1428 | 1867 | break; | ||
| 1429 | 1868 | case QOrganizerItemReminder::TypeAudibleReminder: | ||
| 1430 | 1869 | default: | ||
| 1431 | 1870 | // use audio as fallback | ||
| 1432 | 1871 | e_cal_component_alarm_set_action(alarm, E_CAL_COMPONENT_ALARM_AUDIO); | ||
| 1433 | 1872 | parseAudibleReminderAttachment(detail, alarm); | ||
| 1434 | 1873 | break; | ||
| 1435 | 1874 | } | ||
| 1436 | 1875 | |||
| 1437 | 1876 | if (reminder->secondsBeforeStart() > 0) { | ||
| 1438 | 1877 | ECalComponentAlarmTrigger trigger; | ||
| 1439 | 1878 | trigger.type = E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START; | ||
| 1440 | 1879 | trigger.u.rel_duration = icaldurationtype_from_int(- reminder->secondsBeforeStart()); | ||
| 1441 | 1880 | e_cal_component_alarm_set_trigger(alarm, trigger); | ||
| 1442 | 1881 | } | ||
| 1443 | 1882 | |||
| 1444 | 1883 | ECalComponentAlarmRepeat aRepeat; | ||
| 1445 | 1884 | // TODO: check if this is really necessary | ||
| 1446 | 1885 | aRepeat.repetitions = reminder->repetitionCount(); //qMax(reminder->repetitionCount(), 1); | ||
| 1447 | 1886 | aRepeat.duration = icaldurationtype_from_int(reminder->repetitionDelay()); | ||
| 1448 | 1887 | e_cal_component_alarm_set_repeat(alarm, aRepeat); | ||
| 1449 | 1888 | |||
| 1450 | 1889 | e_cal_component_add_alarm(comp, alarm); | ||
| 1451 | 1890 | e_cal_component_alarm_free(alarm); | ||
| 1452 | 1891 | } | ||
| 1453 | 1892 | } | ||
| 1454 | 1893 | |||
| 1455 | 1894 | GSList *QOrganizerEDSEngine::parseItems(ECalClient *client, QList<QOrganizerItem> items) | ||
| 1456 | 1109 | { | 1895 | { |
| 1457 | 1110 | GSList *comps = 0; | 1896 | GSList *comps = 0; |
| 1458 | 1111 | 1897 | ||
| 1459 | @@ -1114,13 +1900,13 @@ | |||
| 1460 | 1114 | 1900 | ||
| 1461 | 1115 | switch(item.type()) { | 1901 | switch(item.type()) { |
| 1462 | 1116 | case QOrganizerItemType::TypeEvent: | 1902 | case QOrganizerItemType::TypeEvent: |
| 1464 | 1117 | comp = parseEventItem(item); | 1903 | comp = parseEventItem(client, item); |
| 1465 | 1118 | break; | 1904 | break; |
| 1466 | 1119 | case QOrganizerItemType::TypeTodo: | 1905 | case QOrganizerItemType::TypeTodo: |
| 1468 | 1120 | comp = parseTodoItem(item); | 1906 | comp = parseTodoItem(client, item); |
| 1469 | 1121 | break; | 1907 | break; |
| 1470 | 1122 | case QOrganizerItemType::TypeJournal: | 1908 | case QOrganizerItemType::TypeJournal: |
| 1472 | 1123 | comp = parseJournalItem(item); | 1909 | comp = parseJournalItem(client, item); |
| 1473 | 1124 | break; | 1910 | break; |
| 1474 | 1125 | case QOrganizerItemType::TypeEventOccurrence: | 1911 | case QOrganizerItemType::TypeEventOccurrence: |
| 1475 | 1126 | qWarning() << "Component TypeEventOccurrence not supported;"; | 1912 | qWarning() << "Component TypeEventOccurrence not supported;"; |
| 1476 | @@ -1136,41 +1922,26 @@ | |||
| 1477 | 1136 | 1922 | ||
| 1478 | 1137 | // id | 1923 | // id |
| 1479 | 1138 | if (!item.id().isNull()) { | 1924 | if (!item.id().isNull()) { |
| 1512 | 1139 | QOrganizerItemId id = item.id(); | 1925 | QOrganizerItemId id = item.id(); |
| 1513 | 1140 | QString cId = QOrganizerEDSEngineId::toComponentId(id); | 1926 | QString cId = QOrganizerEDSEngineId::toComponentId(id); |
| 1514 | 1141 | e_cal_component_set_uid(comp, cId.toUtf8().data()); | 1927 | e_cal_component_set_uid(comp, cId.toUtf8().data()); |
| 1515 | 1142 | } | 1928 | } |
| 1516 | 1143 | 1929 | ||
| 1517 | 1144 | //summary | 1930 | parseSummary(item, comp); |
| 1518 | 1145 | if (!item.displayLabel().isEmpty()) { | 1931 | parseDescription(item, comp); |
| 1519 | 1146 | ECalComponentText txt; | 1932 | parseComments(item, comp); |
| 1520 | 1147 | txt.altrep = ""; | 1933 | parseTags(item, comp); |
| 1521 | 1148 | txt.value = item.displayLabel().toUtf8().data(); | 1934 | parseReminders(item, comp); |
| 1522 | 1149 | e_cal_component_set_summary(comp, &txt); | 1935 | |
| 1523 | 1150 | } | 1936 | if (!item.id().isNull()) { |
| 1524 | 1151 | 1937 | e_cal_component_commit_sequence(comp); | |
| 1525 | 1152 | //comments | 1938 | } else { |
| 1526 | 1153 | GSList *comments = 0; | 1939 | e_cal_component_abort_sequence(comp); |
| 1527 | 1154 | Q_FOREACH(QString comment, item.comments()) { | 1940 | } |
| 1496 | 1155 | ECalComponentText *txt = g_new0(ECalComponentText, 1); | ||
| 1497 | 1156 | txt->value = comment.toUtf8().data(); | ||
| 1498 | 1157 | comments = g_slist_append(comments, txt); | ||
| 1499 | 1158 | } | ||
| 1500 | 1159 | e_cal_component_set_comment_list(comp, comments); | ||
| 1501 | 1160 | e_cal_component_free_text_list(comments); | ||
| 1502 | 1161 | |||
| 1503 | 1162 | //tags | ||
| 1504 | 1163 | GSList *categories = 0; | ||
| 1505 | 1164 | Q_FOREACH(QString tag, item.tags()) { | ||
| 1506 | 1165 | ECalComponentText *txt = g_new0(ECalComponentText, 1); | ||
| 1507 | 1166 | txt->value = tag.toUtf8().data(); | ||
| 1508 | 1167 | categories = g_slist_append(categories, txt); | ||
| 1509 | 1168 | } | ||
| 1510 | 1169 | e_cal_component_set_categories_list(comp, categories); | ||
| 1511 | 1170 | e_cal_component_free_text_list(categories); | ||
| 1528 | 1171 | 1941 | ||
| 1529 | 1172 | comps = g_slist_append(comps, | 1942 | comps = g_slist_append(comps, |
| 1530 | 1173 | icalcomponent_new_clone(e_cal_component_get_icalcomponent(comp))); | 1943 | icalcomponent_new_clone(e_cal_component_get_icalcomponent(comp))); |
| 1531 | 1944 | |||
| 1532 | 1174 | g_object_unref(comp); | 1945 | g_object_unref(comp); |
| 1533 | 1175 | } | 1946 | } |
| 1534 | 1176 | 1947 | ||
| 1535 | 1177 | 1948 | ||
| 1536 | === modified file 'qorganizer/qorganizer-eds-engine.h' | |||
| 1537 | --- qorganizer/qorganizer-eds-engine.h 2013-08-16 02:22:42 +0000 | |||
| 1538 | +++ qorganizer/qorganizer-eds-engine.h 2013-09-09 21:01:24 +0000 | |||
| 1539 | @@ -29,11 +29,15 @@ | |||
| 1540 | 29 | #include <QtOrganizer/QOrganizerItemFilter> | 29 | #include <QtOrganizer/QOrganizerItemFilter> |
| 1541 | 30 | #include <QtOrganizer/QOrganizerItemChangeSet> | 30 | #include <QtOrganizer/QOrganizerItemChangeSet> |
| 1542 | 31 | #include <QtOrganizer/QOrganizerCollectionId> | 31 | #include <QtOrganizer/QOrganizerCollectionId> |
| 1543 | 32 | #include <QtOrganizer/QOrganizerItemReminder> | ||
| 1544 | 32 | 33 | ||
| 1545 | 33 | #include <libecal/libecal.h> | 34 | #include <libecal/libecal.h> |
| 1546 | 35 | |||
| 1547 | 34 | class FetchRequestData; | 36 | class FetchRequestData; |
| 1548 | 35 | class SaveRequestData; | 37 | class SaveRequestData; |
| 1549 | 36 | class RemoveRequestData; | 38 | class RemoveRequestData; |
| 1550 | 39 | class SaveCollectionRequestData; | ||
| 1551 | 40 | class RemoveCollectionRequestData; | ||
| 1552 | 37 | 41 | ||
| 1553 | 38 | class QOrganizerEDSEngine : public QtOrganizer::QOrganizerManagerEngine | 42 | class QOrganizerEDSEngine : public QtOrganizer::QOrganizerManagerEngine |
| 1554 | 39 | { | 43 | { |
| 1555 | @@ -135,36 +139,68 @@ | |||
| 1556 | 135 | QList<FetchRequestData*> m_pendingFetchRequest; | 139 | QList<FetchRequestData*> m_pendingFetchRequest; |
| 1557 | 136 | 140 | ||
| 1558 | 137 | void loadCollections(); | 141 | void loadCollections(); |
| 1559 | 142 | void registerCollection(const QtOrganizer::QOrganizerCollection &collection, QOrganizerEDSCollectionEngineId *edsId); | ||
| 1560 | 143 | void unregisterCollection(const QtOrganizer::QOrganizerCollectionId &collectionId); | ||
| 1561 | 144 | |||
| 1562 | 145 | ESource *findSource(const QtOrganizer::QOrganizerCollectionId &id) const; | ||
| 1563 | 146 | |||
| 1564 | 147 | static QtOrganizer::QOrganizerCollection parseSource(ESource *source, const QString &managerUri); | ||
| 1565 | 148 | static QtOrganizer::QOrganizerCollection parseSource(ESource *source, const QString &managerUri, QOrganizerEDSCollectionEngineId **edsId); | ||
| 1566 | 138 | static QList<QtOrganizer::QOrganizerItem> parseEvents(QOrganizerEDSCollectionEngineId *collection, GSList *events); | 149 | static QList<QtOrganizer::QOrganizerItem> parseEvents(QOrganizerEDSCollectionEngineId *collection, GSList *events); |
| 1570 | 139 | static GSList *parseItems(QList<QtOrganizer::QOrganizerItem> items); | 150 | static GSList *parseItems(ECalClient *client, QList<QtOrganizer::QOrganizerItem> items); |
| 1571 | 140 | 151 | ||
| 1572 | 141 | static QDateTime fromIcalTime(struct icaltimetype value); | 152 | // QOrganizerItem -> ECalComponent |
| 1573 | 153 | static void parseSummary(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | ||
| 1574 | 154 | static void parseDescription(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | ||
| 1575 | 155 | static void parseComments(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | ||
| 1576 | 156 | static void parseTags(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | ||
| 1577 | 157 | static void parseReminders(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | ||
| 1578 | 158 | static void encodeAttachment(QByteArray data, ECalComponentAlarm *alarm); | ||
| 1579 | 159 | static void parseVisualReminderAttachment(const QtOrganizer::QOrganizerItemDetail &detail, ECalComponentAlarm *alarm); | ||
| 1580 | 160 | static void parseAudibleReminderAttachment(const QtOrganizer::QOrganizerItemDetail &detail, ECalComponentAlarm *alarm); | ||
| 1581 | 161 | static void parseStartTime(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | ||
| 1582 | 162 | static void parseEndTime(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | ||
| 1583 | 163 | static void parseTodoStartTime(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | ||
| 1584 | 164 | static void parseRecurrence(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | ||
| 1585 | 165 | static void parseWeekRecurrence(const QtOrganizer::QOrganizerRecurrenceRule &qRule, struct icalrecurrencetype *rule); | ||
| 1586 | 166 | static void parseMonthRecurrence(const QtOrganizer::QOrganizerRecurrenceRule &qRule, struct icalrecurrencetype *rule); | ||
| 1587 | 167 | static void parseYearRecurrence(const QtOrganizer::QOrganizerRecurrenceRule &qRule, struct icalrecurrencetype *rule); | ||
| 1588 | 168 | static void parsePriority(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | ||
| 1589 | 169 | static void parseLocation(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | ||
| 1590 | 170 | static void parseDueDate(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | ||
| 1591 | 171 | static void parseProgress(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | ||
| 1592 | 172 | static void parseStatus(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | ||
| 1593 | 173 | |||
| 1594 | 174 | // ECalComponent -> QOrganizerItem | ||
| 1595 | 175 | static void parseSummary(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); | ||
| 1596 | 176 | static void parseDescription(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); | ||
| 1597 | 177 | static void parseComments(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); | ||
| 1598 | 178 | static void parseTags(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); | ||
| 1599 | 179 | static void parseReminders(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); | ||
| 1600 | 180 | static QByteArray dencodeAttachment(ECalComponentAlarm *alarm); | ||
| 1601 | 181 | static void parseAudibleReminderAttachment(ECalComponentAlarm *alarm, QtOrganizer::QOrganizerItemReminder *aDetail); | ||
| 1602 | 182 | static void parseVisualReminderAttachment(ECalComponentAlarm *alarm, QtOrganizer::QOrganizerItemReminder *aDetail); | ||
| 1603 | 142 | static void parseStartTime(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); | 183 | static void parseStartTime(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); |
| 1604 | 143 | static void parseEndTime(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); | 184 | static void parseEndTime(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); |
| 1605 | 144 | static void parseRecurrence(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); | 185 | static void parseRecurrence(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); |
| 1606 | 186 | static void parseWeekRecurrence(struct icalrecurrencetype *rule, QtOrganizer::QOrganizerRecurrenceRule *qRule); | ||
| 1607 | 187 | static void parseMonthRecurrence(struct icalrecurrencetype *rule, QtOrganizer::QOrganizerRecurrenceRule *qRule); | ||
| 1608 | 188 | static void parseYearRecurrence(struct icalrecurrencetype *rule, QtOrganizer::QOrganizerRecurrenceRule *qRule); | ||
| 1609 | 145 | static void parsePriority(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); | 189 | static void parsePriority(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); |
| 1610 | 146 | static void parseLocation(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); | 190 | static void parseLocation(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); |
| 1611 | 147 | static void parseDueDate(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); | 191 | static void parseDueDate(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); |
| 1612 | 148 | static void parseProgress(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); | 192 | static void parseProgress(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); |
| 1613 | 149 | static void parseStatus(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); | 193 | static void parseStatus(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); |
| 1614 | 150 | 194 | ||
| 1615 | 195 | static QDateTime fromIcalTime(struct icaltimetype value); | ||
| 1616 | 151 | static QtOrganizer::QOrganizerItem *parseEvent(ECalComponent *comp); | 196 | static QtOrganizer::QOrganizerItem *parseEvent(ECalComponent *comp); |
| 1617 | 152 | static QtOrganizer::QOrganizerItem *parseToDo(ECalComponent *comp); | 197 | static QtOrganizer::QOrganizerItem *parseToDo(ECalComponent *comp); |
| 1618 | 153 | static QtOrganizer::QOrganizerItem *parseJournal(ECalComponent *comp); | 198 | static QtOrganizer::QOrganizerItem *parseJournal(ECalComponent *comp); |
| 1619 | 154 | 199 | ||
| 1633 | 155 | 200 | static ECalComponent *createDefaultComponent(ECalClient *client, icalcomponent_kind iKind, ECalComponentVType eType); | |
| 1634 | 156 | static void parseStartTime(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | 201 | static ECalComponent *parseEventItem(ECalClient *client, const QtOrganizer::QOrganizerItem &item); |
| 1635 | 157 | static void parseEndTime(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | 202 | static ECalComponent *parseTodoItem(ECalClient *client, const QtOrganizer::QOrganizerItem &item); |
| 1636 | 158 | static void parseRecurrence(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | 203 | static ECalComponent *parseJournalItem(ECalClient *client, const QtOrganizer::QOrganizerItem &item); |
| 1624 | 159 | static void parsePriority(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | ||
| 1625 | 160 | static void parseLocation(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | ||
| 1626 | 161 | static void parseDueDate(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | ||
| 1627 | 162 | static void parseProgress(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | ||
| 1628 | 163 | static void parseStatus(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); | ||
| 1629 | 164 | |||
| 1630 | 165 | static ECalComponent *parseEventItem(const QtOrganizer::QOrganizerItem &item); | ||
| 1631 | 166 | static ECalComponent *parseTodoItem(const QtOrganizer::QOrganizerItem &item); | ||
| 1632 | 167 | static ECalComponent *parseJournalItem(const QtOrganizer::QOrganizerItem &item); | ||
| 1637 | 168 | 204 | ||
| 1638 | 169 | // glib callback | 205 | // glib callback |
| 1639 | 170 | void itemsAsync(QtOrganizer::QOrganizerItemFetchRequest *req); | 206 | void itemsAsync(QtOrganizer::QOrganizerItemFetchRequest *req); |
| 1640 | @@ -181,6 +217,13 @@ | |||
| 1641 | 181 | static void removeItemsAsyncStart(RemoveRequestData *data); | 217 | static void removeItemsAsyncStart(RemoveRequestData *data); |
| 1642 | 182 | static void removeItemsAsyncConnected(GObject *source_object, GAsyncResult *res, RemoveRequestData *data); | 218 | static void removeItemsAsyncConnected(GObject *source_object, GAsyncResult *res, RemoveRequestData *data); |
| 1643 | 183 | static void removeItemsAsyncRemoved(GObject *source_object, GAsyncResult *res, RemoveRequestData *data); | 219 | static void removeItemsAsyncRemoved(GObject *source_object, GAsyncResult *res, RemoveRequestData *data); |
| 1644 | 220 | |||
| 1645 | 221 | void saveCollectionAsync(QtOrganizer::QOrganizerCollectionSaveRequest *req); | ||
| 1646 | 222 | static void saveCollectionAsyncStart(ESourceRegistry *registry, SaveCollectionRequestData *data); | ||
| 1647 | 223 | static void saveCollectionAsyncCommited(GObject *source_object, GAsyncResult *res, SaveCollectionRequestData *data); | ||
| 1648 | 224 | |||
| 1649 | 225 | void removeCollectionAsync(QtOrganizer::QOrganizerCollectionRemoveRequest *req); | ||
| 1650 | 226 | static void removeCollectionAsyncStart(GObject *source_object, GAsyncResult *res, RemoveCollectionRequestData *data); | ||
| 1651 | 184 | /* | 227 | /* |
| 1652 | 185 | QList<QtOrganizer::QOrganizerItem> internalItemOccurrences(const QtOrganizer::QOrganizerItem& parentItem, | 228 | QList<QtOrganizer::QOrganizerItem> internalItemOccurrences(const QtOrganizer::QOrganizerItem& parentItem, |
| 1653 | 186 | const QDateTime& periodStart, | 229 | const QDateTime& periodStart, |
| 1654 | @@ -200,7 +243,9 @@ | |||
| 1655 | 200 | bool forExport) const; | 243 | bool forExport) const; |
| 1656 | 201 | QtOrganizer::QOrganizerItem item(const QtOrganizer::QOrganizerItemId& organizeritemId) const; | 244 | QtOrganizer::QOrganizerItem item(const QtOrganizer::QOrganizerItemId& organizeritemId) const; |
| 1657 | 202 | */ | 245 | */ |
| 1659 | 203 | friend class FetchRequestData; | 246 | friend class FetchRequestData; |
| 1660 | 247 | friend class SaveCollectionRequestData; | ||
| 1661 | 248 | friend class RemoveCollectionRequestData; | ||
| 1662 | 204 | }; | 249 | }; |
| 1663 | 205 | 250 | ||
| 1664 | 206 | #endif | 251 | #endif |
| 1665 | 207 | 252 | ||
| 1666 | === modified file 'qorganizer/qorganizer-eds-fetchrequestdata.cpp' | |||
| 1667 | --- qorganizer/qorganizer-eds-fetchrequestdata.cpp 2013-08-14 21:23:01 +0000 | |||
| 1668 | +++ qorganizer/qorganizer-eds-fetchrequestdata.cpp 2013-09-09 21:01:24 +0000 | |||
| 1669 | @@ -60,14 +60,30 @@ | |||
| 1670 | 60 | 60 | ||
| 1671 | 61 | void FetchRequestData::appendResults(QList<QOrganizerItem> results) | 61 | void FetchRequestData::appendResults(QList<QOrganizerItem> results) |
| 1672 | 62 | { | 62 | { |
| 1674 | 63 | m_results += results; | 63 | QOrganizerItemFetchRequest *req = request<QOrganizerItemFetchRequest>(); |
| 1675 | 64 | Q_FOREACH(QOrganizerItem item, results) { | ||
| 1676 | 65 | if (QOrganizerManagerEngine::testFilter(req->filter(), item)) { | ||
| 1677 | 66 | m_results << item; | ||
| 1678 | 67 | } | ||
| 1679 | 68 | } | ||
| 1680 | 64 | } | 69 | } |
| 1681 | 65 | 70 | ||
| 1682 | 66 | QString FetchRequestData::dateFilter() | 71 | QString FetchRequestData::dateFilter() |
| 1683 | 67 | { | 72 | { |
| 1684 | 73 | QDateTime startDate = request<QOrganizerItemFetchRequest>()->startDate(); | ||
| 1685 | 74 | QDateTime endDate = request<QOrganizerItemFetchRequest>()->endDate(); | ||
| 1686 | 75 | |||
| 1687 | 76 | if (!startDate.isValid()) { | ||
| 1688 | 77 | startDate.setMSecsSinceEpoch(0); | ||
| 1689 | 78 | } | ||
| 1690 | 79 | |||
| 1691 | 80 | if (!endDate.isValid()) { | ||
| 1692 | 81 | endDate.setMSecsSinceEpoch(std::numeric_limits<qint64>::max()); | ||
| 1693 | 82 | } | ||
| 1694 | 83 | |||
| 1695 | 68 | QString query = QString("(occur-in-time-range? " | 84 | QString query = QString("(occur-in-time-range? " |
| 1696 | 69 | "(make-time \"%1\") (make-time \"%2\"))") | 85 | "(make-time \"%1\") (make-time \"%2\"))") |
| 1699 | 70 | .arg(isodate_from_time_t(request<QOrganizerItemFetchRequest>()->startDate().toTime_t())) | 86 | .arg(isodate_from_time_t(startDate.toTime_t())) |
| 1700 | 71 | .arg(isodate_from_time_t(request<QOrganizerItemFetchRequest>()->endDate().toTime_t())); | 87 | .arg(isodate_from_time_t(endDate.toTime_t())); |
| 1701 | 72 | return query; | 88 | return query; |
| 1702 | 73 | } | 89 | } |
| 1703 | 74 | 90 | ||
| 1704 | === added file 'qorganizer/qorganizer-eds-removecollectionrequestdata.cpp' | |||
| 1705 | --- qorganizer/qorganizer-eds-removecollectionrequestdata.cpp 1970-01-01 00:00:00 +0000 | |||
| 1706 | +++ qorganizer/qorganizer-eds-removecollectionrequestdata.cpp 2013-09-09 21:01:24 +0000 | |||
| 1707 | @@ -0,0 +1,76 @@ | |||
| 1708 | 1 | /* | ||
| 1709 | 2 | * Copyright 2013 Canonical Ltd. | ||
| 1710 | 3 | * | ||
| 1711 | 4 | * This file is part of ubuntu-pim-service. | ||
| 1712 | 5 | * | ||
| 1713 | 6 | * contact-service-app is free software; you can redistribute it and/or modify | ||
| 1714 | 7 | * it under the terms of the GNU General Public License as published by | ||
| 1715 | 8 | * the Free Software Foundation; version 3. | ||
| 1716 | 9 | * | ||
| 1717 | 10 | * contact-service-app is distributed in the hope that it will be useful, | ||
| 1718 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 1719 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 1720 | 13 | * GNU General Public License for more details. | ||
| 1721 | 14 | * | ||
| 1722 | 15 | * You should have received a copy of the GNU General Public License | ||
| 1723 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 1724 | 17 | */ | ||
| 1725 | 18 | |||
| 1726 | 19 | #include "qorganizer-eds-removecollectionrequestdata.h" | ||
| 1727 | 20 | #include "qorganizer-eds-engineid.h" | ||
| 1728 | 21 | |||
| 1729 | 22 | #include <QtOrganizer/QOrganizerManagerEngine> | ||
| 1730 | 23 | #include <QtOrganizer/QOrganizerCollectionRemoveRequest> | ||
| 1731 | 24 | |||
| 1732 | 25 | using namespace QtOrganizer; | ||
| 1733 | 26 | |||
| 1734 | 27 | RemoveCollectionRequestData::RemoveCollectionRequestData(QOrganizerEDSEngine *engine, QtOrganizer::QOrganizerAbstractRequest *req) | ||
| 1735 | 28 | : RequestData(engine, req), | ||
| 1736 | 29 | m_currentCollection(0) | ||
| 1737 | 30 | { | ||
| 1738 | 31 | m_pendingCollections = request<QOrganizerCollectionRemoveRequest>()->collectionIds(); | ||
| 1739 | 32 | } | ||
| 1740 | 33 | |||
| 1741 | 34 | RemoveCollectionRequestData::~RemoveCollectionRequestData() | ||
| 1742 | 35 | { | ||
| 1743 | 36 | } | ||
| 1744 | 37 | |||
| 1745 | 38 | void RemoveCollectionRequestData::finish(QtOrganizer::QOrganizerManager::Error error) | ||
| 1746 | 39 | { | ||
| 1747 | 40 | QOrganizerManagerEngine::updateCollectionRemoveRequest(request<QOrganizerCollectionRemoveRequest>(), | ||
| 1748 | 41 | error, | ||
| 1749 | 42 | m_errorMap, | ||
| 1750 | 43 | QOrganizerAbstractRequest::FinishedState); | ||
| 1751 | 44 | |||
| 1752 | 45 | // emit collection removed signal | ||
| 1753 | 46 | QList<QOrganizerCollectionId> removedIds = m_pendingCollections; | ||
| 1754 | 47 | Q_FOREACH(int index, m_errorMap.keys()) { | ||
| 1755 | 48 | removedIds.removeAt(index); | ||
| 1756 | 49 | } | ||
| 1757 | 50 | |||
| 1758 | 51 | // remove source from engine | ||
| 1759 | 52 | Q_FOREACH(QOrganizerCollectionId id, removedIds) { | ||
| 1760 | 53 | parent()->unregisterCollection(id); | ||
| 1761 | 54 | } | ||
| 1762 | 55 | |||
| 1763 | 56 | Q_EMIT parent()->collectionsRemoved(removedIds); | ||
| 1764 | 57 | } | ||
| 1765 | 58 | |||
| 1766 | 59 | void RemoveCollectionRequestData::commit(QtOrganizer::QOrganizerManager::Error error) | ||
| 1767 | 60 | { | ||
| 1768 | 61 | if (error != QOrganizerManager::NoError) { | ||
| 1769 | 62 | m_errorMap.insert(m_currentCollection, error); | ||
| 1770 | 63 | } | ||
| 1771 | 64 | |||
| 1772 | 65 | m_currentCollection++; | ||
| 1773 | 66 | } | ||
| 1774 | 67 | |||
| 1775 | 68 | ESource *RemoveCollectionRequestData::begin() | ||
| 1776 | 69 | { | ||
| 1777 | 70 | if (m_pendingCollections.count() > m_currentCollection) { | ||
| 1778 | 71 | QOrganizerCollectionId cId = m_pendingCollections.at(m_currentCollection); | ||
| 1779 | 72 | return parent()->findSource(cId); | ||
| 1780 | 73 | } else { | ||
| 1781 | 74 | return 0; | ||
| 1782 | 75 | } | ||
| 1783 | 76 | } | ||
| 1784 | 0 | 77 | ||
| 1785 | === added file 'qorganizer/qorganizer-eds-removecollectionrequestdata.h' | |||
| 1786 | --- qorganizer/qorganizer-eds-removecollectionrequestdata.h 1970-01-01 00:00:00 +0000 | |||
| 1787 | +++ qorganizer/qorganizer-eds-removecollectionrequestdata.h 2013-09-09 21:01:24 +0000 | |||
| 1788 | @@ -0,0 +1,44 @@ | |||
| 1789 | 1 | /* | ||
| 1790 | 2 | * Copyright 2013 Canonical Ltd. | ||
| 1791 | 3 | * | ||
| 1792 | 4 | * This file is part of ubuntu-pim-service. | ||
| 1793 | 5 | * | ||
| 1794 | 6 | * contact-service-app is free software; you can redistribute it and/or modify | ||
| 1795 | 7 | * it under the terms of the GNU General Public License as published by | ||
| 1796 | 8 | * the Free Software Foundation; version 3. | ||
| 1797 | 9 | * | ||
| 1798 | 10 | * contact-service-app is distributed in the hope that it will be useful, | ||
| 1799 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 1800 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 1801 | 13 | * GNU General Public License for more details. | ||
| 1802 | 14 | * | ||
| 1803 | 15 | * You should have received a copy of the GNU General Public License | ||
| 1804 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 1805 | 17 | */ | ||
| 1806 | 18 | |||
| 1807 | 19 | #ifndef __QORGANIZER_EDS_REMOVECOLLECTIONQUESTDATA_H__ | ||
| 1808 | 20 | #define __QORGANIZER_EDS_REMOVECOLLECTIONQUESTDATA_H__ | ||
| 1809 | 21 | |||
| 1810 | 22 | #include "qorganizer-eds-requestdata.h" | ||
| 1811 | 23 | |||
| 1812 | 24 | #include <glib.h> | ||
| 1813 | 25 | |||
| 1814 | 26 | class RemoveCollectionRequestData : public RequestData | ||
| 1815 | 27 | { | ||
| 1816 | 28 | public: | ||
| 1817 | 29 | RemoveCollectionRequestData(QOrganizerEDSEngine *engine, QtOrganizer::QOrganizerAbstractRequest *req); | ||
| 1818 | 30 | ~RemoveCollectionRequestData(); | ||
| 1819 | 31 | |||
| 1820 | 32 | void finish(QtOrganizer::QOrganizerManager::Error error = QtOrganizer::QOrganizerManager::NoError); | ||
| 1821 | 33 | |||
| 1822 | 34 | ESource* begin(); | ||
| 1823 | 35 | void commit(QtOrganizer::QOrganizerManager::Error error = QtOrganizer::QOrganizerManager::NoError); | ||
| 1824 | 36 | |||
| 1825 | 37 | private: | ||
| 1826 | 38 | QList<QtOrganizer::QOrganizerCollectionId> m_pendingCollections; | ||
| 1827 | 39 | QMap<int, QtOrganizer::QOrganizerManager::Error> m_errorMap; | ||
| 1828 | 40 | int m_currentCollection; | ||
| 1829 | 41 | |||
| 1830 | 42 | }; | ||
| 1831 | 43 | |||
| 1832 | 44 | #endif | ||
| 1833 | 0 | 45 | ||
| 1834 | === modified file 'qorganizer/qorganizer-eds-removerequestdata.cpp' | |||
| 1835 | --- qorganizer/qorganizer-eds-removerequestdata.cpp 2013-08-14 21:23:01 +0000 | |||
| 1836 | +++ qorganizer/qorganizer-eds-removerequestdata.cpp 2013-09-09 21:01:24 +0000 | |||
| 1837 | @@ -56,7 +56,6 @@ | |||
| 1838 | 56 | ECalComponentId *id = g_new0(ECalComponentId, 1); | 56 | ECalComponentId *id = g_new0(ECalComponentId, 1); |
| 1839 | 57 | 57 | ||
| 1840 | 58 | id->uid = g_strdup(QOrganizerEDSEngineId::toComponentId(item.id()).toUtf8().data()); | 58 | id->uid = g_strdup(QOrganizerEDSEngineId::toComponentId(item.id()).toUtf8().data()); |
| 1841 | 59 | qDebug() << "Remove item:" << id->uid; | ||
| 1842 | 60 | ids = g_slist_append(ids, id); | 59 | ids = g_slist_append(ids, id); |
| 1843 | 61 | 60 | ||
| 1844 | 62 | m_pendingItems.removeAll(item); | 61 | m_pendingItems.removeAll(item); |
| 1845 | @@ -102,9 +101,7 @@ | |||
| 1846 | 102 | QSet<QtOrganizer::QOrganizerCollectionId>::const_iterator i = m_pendingCollections.constBegin(); | 101 | QSet<QtOrganizer::QOrganizerCollectionId>::const_iterator i = m_pendingCollections.constBegin(); |
| 1847 | 103 | m_pendingCollections.remove(*i); | 102 | m_pendingCollections.remove(*i); |
| 1848 | 104 | m_currentCollectionId = *i; | 103 | m_currentCollectionId = *i; |
| 1849 | 105 | qDebug() << "Will get item for sourcE:" << m_currentCollectionId.isNull() << m_currentCollectionId; | ||
| 1850 | 106 | m_currentCompIds = takeItemsIds(m_currentCollectionId); | 104 | m_currentCompIds = takeItemsIds(m_currentCollectionId); |
| 1851 | 107 | qDebug() << "DONE Will get item for sourcE:" << m_currentCollectionId.isNull() << m_currentCollectionId; | ||
| 1852 | 108 | return m_currentCollectionId; | 105 | return m_currentCollectionId; |
| 1853 | 109 | } | 106 | } |
| 1854 | 110 | return QOrganizerCollectionId(); | 107 | return QOrganizerCollectionId(); |
| 1855 | 111 | 108 | ||
| 1856 | === modified file 'qorganizer/qorganizer-eds-requestdata.cpp' | |||
| 1857 | --- qorganizer/qorganizer-eds-requestdata.cpp 2013-08-14 21:23:01 +0000 | |||
| 1858 | +++ qorganizer/qorganizer-eds-requestdata.cpp 2013-09-09 21:01:24 +0000 | |||
| 1859 | @@ -51,9 +51,9 @@ | |||
| 1860 | 51 | return !m_req.isNull(); | 51 | return !m_req.isNull(); |
| 1861 | 52 | } | 52 | } |
| 1862 | 53 | 53 | ||
| 1864 | 54 | EClient *RequestData::client() const | 54 | ECalClient *RequestData::client() const |
| 1865 | 55 | { | 55 | { |
| 1867 | 56 | return m_client; | 56 | return E_CAL_CLIENT(m_client); |
| 1868 | 57 | } | 57 | } |
| 1869 | 58 | 58 | ||
| 1870 | 59 | QOrganizerEDSEngine *RequestData::parent() const | 59 | QOrganizerEDSEngine *RequestData::parent() const |
| 1871 | 60 | 60 | ||
| 1872 | === modified file 'qorganizer/qorganizer-eds-requestdata.h' | |||
| 1873 | --- qorganizer/qorganizer-eds-requestdata.h 2013-08-14 21:23:01 +0000 | |||
| 1874 | +++ qorganizer/qorganizer-eds-requestdata.h 2013-09-09 21:01:24 +0000 | |||
| 1875 | @@ -35,7 +35,7 @@ | |||
| 1876 | 35 | GCancellable* cancellable() const; | 35 | GCancellable* cancellable() const; |
| 1877 | 36 | bool isLive() const; | 36 | bool isLive() const; |
| 1878 | 37 | void setClient(EClient *client); | 37 | void setClient(EClient *client); |
| 1880 | 38 | EClient *client() const; | 38 | ECalClient *client() const; |
| 1881 | 39 | virtual void finish(QtOrganizer::QOrganizerManager::Error error = QtOrganizer::QOrganizerManager::NoError) = 0; | 39 | virtual void finish(QtOrganizer::QOrganizerManager::Error error = QtOrganizer::QOrganizerManager::NoError) = 0; |
| 1882 | 40 | QOrganizerEDSEngine *parent() const; | 40 | QOrganizerEDSEngine *parent() const; |
| 1883 | 41 | virtual void cancel(); | 41 | virtual void cancel(); |
| 1884 | 42 | 42 | ||
| 1885 | === added file 'qorganizer/qorganizer-eds-savecollectionrequestdata.cpp' | |||
| 1886 | --- qorganizer/qorganizer-eds-savecollectionrequestdata.cpp 1970-01-01 00:00:00 +0000 | |||
| 1887 | +++ qorganizer/qorganizer-eds-savecollectionrequestdata.cpp 2013-09-09 21:01:24 +0000 | |||
| 1888 | @@ -0,0 +1,139 @@ | |||
| 1889 | 1 | /* | ||
| 1890 | 2 | * Copyright 2013 Canonical Ltd. | ||
| 1891 | 3 | * | ||
| 1892 | 4 | * This file is part of ubuntu-pim-service. | ||
| 1893 | 5 | * | ||
| 1894 | 6 | * contact-service-app is free software; you can redistribute it and/or modify | ||
| 1895 | 7 | * it under the terms of the GNU General Public License as published by | ||
| 1896 | 8 | * the Free Software Foundation; version 3. | ||
| 1897 | 9 | * | ||
| 1898 | 10 | * contact-service-app is distributed in the hope that it will be useful, | ||
| 1899 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 1900 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 1901 | 13 | * GNU General Public License for more details. | ||
| 1902 | 14 | * | ||
| 1903 | 15 | * You should have received a copy of the GNU General Public License | ||
| 1904 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 1905 | 17 | */ | ||
| 1906 | 18 | |||
| 1907 | 19 | #include "qorganizer-eds-savecollectionrequestdata.h" | ||
| 1908 | 20 | |||
| 1909 | 21 | #include <QtOrganizer/QOrganizerManagerEngine> | ||
| 1910 | 22 | #include <QtOrganizer/QOrganizerCollectionSaveRequest> | ||
| 1911 | 23 | |||
| 1912 | 24 | using namespace QtOrganizer; | ||
| 1913 | 25 | |||
| 1914 | 26 | #define COLLECTION_CALLENDAR_TYPE_METADATA "collection-type" | ||
| 1915 | 27 | |||
| 1916 | 28 | SaveCollectionRequestData::SaveCollectionRequestData(QOrganizerEDSEngine *engine, | ||
| 1917 | 29 | QtOrganizer::QOrganizerAbstractRequest *req) | ||
| 1918 | 30 | : RequestData(engine, req), | ||
| 1919 | 31 | m_sources(0), | ||
| 1920 | 32 | m_currentSource(0) | ||
| 1921 | 33 | { | ||
| 1922 | 34 | parseCollections(); | ||
| 1923 | 35 | } | ||
| 1924 | 36 | |||
| 1925 | 37 | SaveCollectionRequestData::~SaveCollectionRequestData() | ||
| 1926 | 38 | { | ||
| 1927 | 39 | } | ||
| 1928 | 40 | |||
| 1929 | 41 | |||
| 1930 | 42 | void SaveCollectionRequestData::finish(QtOrganizer::QOrganizerManager::Error error) | ||
| 1931 | 43 | { | ||
| 1932 | 44 | qDebug() << "update request collections" << m_results; | ||
| 1933 | 45 | |||
| 1934 | 46 | QOrganizerManagerEngine::updateCollectionSaveRequest(request<QOrganizerCollectionSaveRequest>(), | ||
| 1935 | 47 | m_results, | ||
| 1936 | 48 | error, | ||
| 1937 | 49 | m_errorMap, | ||
| 1938 | 50 | QOrganizerAbstractRequest::FinishedState); | ||
| 1939 | 51 | |||
| 1940 | 52 | QList<QOrganizerCollectionId> added; | ||
| 1941 | 53 | Q_FOREACH(QOrganizerCollection col, m_results) { | ||
| 1942 | 54 | added.append(col.id()); | ||
| 1943 | 55 | } | ||
| 1944 | 56 | Q_EMIT parent()->collectionsAdded(added); | ||
| 1945 | 57 | } | ||
| 1946 | 58 | |||
| 1947 | 59 | void SaveCollectionRequestData::commit(QtOrganizer::QOrganizerManager::Error error) | ||
| 1948 | 60 | { | ||
| 1949 | 61 | if (error != QOrganizerManager::NoError) { | ||
| 1950 | 62 | m_errorMap.insert(m_currentSource, error); | ||
| 1951 | 63 | } else { | ||
| 1952 | 64 | ESource *source = E_SOURCE(g_list_nth_data(m_sources, m_currentSource)); | ||
| 1953 | 65 | QOrganizerEDSCollectionEngineId *edsId = 0; | ||
| 1954 | 66 | |||
| 1955 | 67 | QOrganizerCollection collection = QOrganizerEDSEngine::parseSource(source, parent()->managerUri(), &edsId); | ||
| 1956 | 68 | parent()->registerCollection(collection, edsId); | ||
| 1957 | 69 | |||
| 1958 | 70 | m_results.append(collection); | ||
| 1959 | 71 | } | ||
| 1960 | 72 | m_currentSource++; | ||
| 1961 | 73 | } | ||
| 1962 | 74 | |||
| 1963 | 75 | GList *SaveCollectionRequestData::sources() const | ||
| 1964 | 76 | { | ||
| 1965 | 77 | return m_sources; | ||
| 1966 | 78 | } | ||
| 1967 | 79 | |||
| 1968 | 80 | QList<QOrganizerCollection> SaveCollectionRequestData::results() const | ||
| 1969 | 81 | { | ||
| 1970 | 82 | return m_results; | ||
| 1971 | 83 | } | ||
| 1972 | 84 | |||
| 1973 | 85 | void SaveCollectionRequestData::parseCollections() | ||
| 1974 | 86 | { | ||
| 1975 | 87 | if (m_sources) { | ||
| 1976 | 88 | g_list_free_full(m_sources, g_object_unref); | ||
| 1977 | 89 | m_sources = 0; | ||
| 1978 | 90 | } | ||
| 1979 | 91 | |||
| 1980 | 92 | m_errorMap.clear(); | ||
| 1981 | 93 | int index = 0; | ||
| 1982 | 94 | Q_FOREACH(QOrganizerCollection collection, request<QOrganizerCollectionSaveRequest>()->collections()) { | ||
| 1983 | 95 | ESource *source = 0; | ||
| 1984 | 96 | if (collection.id().isNull()) { | ||
| 1985 | 97 | GError *gError = 0; | ||
| 1986 | 98 | source = e_source_new(0, 0, &gError); | ||
| 1987 | 99 | if (gError) { | ||
| 1988 | 100 | m_errorMap.insert(index, QOrganizerManager::UnspecifiedError); | ||
| 1989 | 101 | qWarning() << "Fail to create source:" << gError->message; | ||
| 1990 | 102 | g_error_free(gError); | ||
| 1991 | 103 | } | ||
| 1992 | 104 | } else { | ||
| 1993 | 105 | qDebug() << "Collection update not implemented"; | ||
| 1994 | 106 | Q_ASSERT(FALSE); | ||
| 1995 | 107 | } | ||
| 1996 | 108 | |||
| 1997 | 109 | QString name = collection.metaData(QOrganizerCollection::KeyName).toString(); | ||
| 1998 | 110 | e_source_set_display_name(source, name.toUtf8().data()); | ||
| 1999 | 111 | e_source_set_parent(source, "local-stub"); | ||
| 2000 | 112 | |||
| 2001 | 113 | QVariant callendarType = collection.extendedMetaData(COLLECTION_CALLENDAR_TYPE_METADATA); | ||
| 2002 | 114 | ESourceBackend *extCalendar = 0; | ||
| 2003 | 115 | |||
| 2004 | 116 | if (callendarType.toString() == E_SOURCE_EXTENSION_TASK_LIST) { | ||
| 2005 | 117 | extCalendar = E_SOURCE_BACKEND(e_source_get_extension(source, E_SOURCE_EXTENSION_TASK_LIST)); | ||
| 2006 | 118 | } else if (callendarType.toString() == E_SOURCE_EXTENSION_MEMO_LIST) { | ||
| 2007 | 119 | extCalendar = E_SOURCE_BACKEND(e_source_get_extension(source, E_SOURCE_EXTENSION_MEMO_LIST)); | ||
| 2008 | 120 | } else { | ||
| 2009 | 121 | extCalendar = E_SOURCE_BACKEND(e_source_get_extension(source, E_SOURCE_EXTENSION_CALENDAR)); | ||
| 2010 | 122 | } | ||
| 2011 | 123 | |||
| 2012 | 124 | if (extCalendar) { | ||
| 2013 | 125 | e_source_backend_set_backend_name(extCalendar, "local"); | ||
| 2014 | 126 | } else { | ||
| 2015 | 127 | qWarning() << "Fail to get source callendar"; | ||
| 2016 | 128 | } | ||
| 2017 | 129 | m_sources = g_list_append(m_sources, source); | ||
| 2018 | 130 | index++; | ||
| 2019 | 131 | } | ||
| 2020 | 132 | |||
| 2021 | 133 | qDebug() << "Request with" << g_list_length(m_sources) << "sources"; | ||
| 2022 | 134 | } | ||
| 2023 | 135 | |||
| 2024 | 136 | ESource *SaveCollectionRequestData::begin() const | ||
| 2025 | 137 | { | ||
| 2026 | 138 | return E_SOURCE(g_list_nth_data(m_sources, m_currentSource)); | ||
| 2027 | 139 | } | ||
| 2028 | 0 | 140 | ||
| 2029 | === added file 'qorganizer/qorganizer-eds-savecollectionrequestdata.h' | |||
| 2030 | --- qorganizer/qorganizer-eds-savecollectionrequestdata.h 1970-01-01 00:00:00 +0000 | |||
| 2031 | +++ qorganizer/qorganizer-eds-savecollectionrequestdata.h 2013-09-09 21:01:24 +0000 | |||
| 2032 | @@ -0,0 +1,49 @@ | |||
| 2033 | 1 | /* | ||
| 2034 | 2 | * Copyright 2013 Canonical Ltd. | ||
| 2035 | 3 | * | ||
| 2036 | 4 | * This file is part of ubuntu-pim-service. | ||
| 2037 | 5 | * | ||
| 2038 | 6 | * contact-service-app is free software; you can redistribute it and/or modify | ||
| 2039 | 7 | * it under the terms of the GNU General Public License as published by | ||
| 2040 | 8 | * the Free Software Foundation; version 3. | ||
| 2041 | 9 | * | ||
| 2042 | 10 | * contact-service-app is distributed in the hope that it will be useful, | ||
| 2043 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 2044 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 2045 | 13 | * GNU General Public License for more details. | ||
| 2046 | 14 | * | ||
| 2047 | 15 | * You should have received a copy of the GNU General Public License | ||
| 2048 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 2049 | 17 | */ | ||
| 2050 | 18 | |||
| 2051 | 19 | #ifndef __QORGANIZER_EDS_SAVECOLLECTIONREQUESTDATA_H__ | ||
| 2052 | 20 | #define __QORGANIZER_EDS_SAVECOLLECTIONREQUESTDATA_H__ | ||
| 2053 | 21 | |||
| 2054 | 22 | #include "qorganizer-eds-requestdata.h" | ||
| 2055 | 23 | |||
| 2056 | 24 | class SaveCollectionRequestData : public RequestData | ||
| 2057 | 25 | { | ||
| 2058 | 26 | public: | ||
| 2059 | 27 | SaveCollectionRequestData(QOrganizerEDSEngine *engine, | ||
| 2060 | 28 | QtOrganizer::QOrganizerAbstractRequest *req); | ||
| 2061 | 29 | ~SaveCollectionRequestData(); | ||
| 2062 | 30 | |||
| 2063 | 31 | void finish(QtOrganizer::QOrganizerManager::Error error = QtOrganizer::QOrganizerManager::NoError); | ||
| 2064 | 32 | bool isNew(int index) const; | ||
| 2065 | 33 | |||
| 2066 | 34 | GList *sources() const; | ||
| 2067 | 35 | QList<QtOrganizer::QOrganizerCollection> results() const; | ||
| 2068 | 36 | ESource *begin() const; | ||
| 2069 | 37 | void commit(QtOrganizer::QOrganizerManager::Error error = QtOrganizer::QOrganizerManager::NoError); | ||
| 2070 | 38 | |||
| 2071 | 39 | private: | ||
| 2072 | 40 | QMap<int, QtOrganizer::QOrganizerManager::Error> m_errorMap; | ||
| 2073 | 41 | QList<QtOrganizer::QOrganizerCollection> m_results; | ||
| 2074 | 42 | GList *m_sources; | ||
| 2075 | 43 | int m_currentSource; | ||
| 2076 | 44 | |||
| 2077 | 45 | void parseCollections(); | ||
| 2078 | 46 | |||
| 2079 | 47 | }; | ||
| 2080 | 48 | |||
| 2081 | 49 | #endif | ||
| 2082 | 0 | 50 | ||
| 2083 | === modified file 'tests/unittest/CMakeLists.txt' | |||
| 2084 | --- tests/unittest/CMakeLists.txt 2013-08-14 21:23:01 +0000 | |||
| 2085 | +++ tests/unittest/CMakeLists.txt 2013-09-09 21:01:24 +0000 | |||
| 2086 | @@ -39,3 +39,8 @@ | |||
| 2087 | 39 | endif() | 39 | endif() |
| 2088 | 40 | 40 | ||
| 2089 | 41 | declare_test(itemid-test) | 41 | declare_test(itemid-test) |
| 2090 | 42 | declare_test(parseecal-test) | ||
| 2091 | 43 | # Jenkins will not be able to run these tests because they need EDS running | ||
| 2092 | 44 | # FIXME: Mock EDS to run the tests bellow | ||
| 2093 | 45 | #declare_test(collections-test) | ||
| 2094 | 46 | #declare_test(event-test) | ||
| 2095 | 42 | 47 | ||
| 2096 | === added file 'tests/unittest/collections-test.cpp' | |||
| 2097 | --- tests/unittest/collections-test.cpp 1970-01-01 00:00:00 +0000 | |||
| 2098 | +++ tests/unittest/collections-test.cpp 2013-09-09 21:01:24 +0000 | |||
| 2099 | @@ -0,0 +1,191 @@ | |||
| 2100 | 1 | /* | ||
| 2101 | 2 | * Copyright 2013 Canonical Ltd. | ||
| 2102 | 3 | * | ||
| 2103 | 4 | * This file is part of qtorganizer5-eds. | ||
| 2104 | 5 | * | ||
| 2105 | 6 | * contact-service-app is free software; you can redistribute it and/or modify | ||
| 2106 | 7 | * it under the terms of the GNU General Public License as published by | ||
| 2107 | 8 | * the Free Software Foundation; version 3. | ||
| 2108 | 9 | * | ||
| 2109 | 10 | * contact-service-app is distributed in the hope that it will be useful, | ||
| 2110 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 2111 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 2112 | 13 | * GNU General Public License for more details. | ||
| 2113 | 14 | * | ||
| 2114 | 15 | * You should have received a copy of the GNU General Public License | ||
| 2115 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 2116 | 17 | */ | ||
| 2117 | 18 | |||
| 2118 | 19 | |||
| 2119 | 20 | #include <QObject> | ||
| 2120 | 21 | #include <QtTest> | ||
| 2121 | 22 | #include <QDebug> | ||
| 2122 | 23 | |||
| 2123 | 24 | #include <QtOrganizer> | ||
| 2124 | 25 | |||
| 2125 | 26 | #include "qorganizer-eds-engine.h" | ||
| 2126 | 27 | |||
| 2127 | 28 | |||
| 2128 | 29 | using namespace QtOrganizer; | ||
| 2129 | 30 | |||
| 2130 | 31 | class CollectionTest : public QObject | ||
| 2131 | 32 | { | ||
| 2132 | 33 | Q_OBJECT | ||
| 2133 | 34 | private: | ||
| 2134 | 35 | static const QString defaultCollectionName; | ||
| 2135 | 36 | static const QString defaultTaskCollectionName; | ||
| 2136 | 37 | static const QString collectionTypePropertyName; | ||
| 2137 | 38 | static const QString taskListTypeName; | ||
| 2138 | 39 | private Q_SLOTS: | ||
| 2139 | 40 | void testCreateCollection() | ||
| 2140 | 41 | { | ||
| 2141 | 42 | QOrganizerEDSEngine *engine = QOrganizerEDSEngine::createEDSEngine(QMap<QString, QString>()); | ||
| 2142 | 43 | |||
| 2143 | 44 | QOrganizerCollection collection; | ||
| 2144 | 45 | QtOrganizer::QOrganizerManager::Error error; | ||
| 2145 | 46 | collection.setMetaData(QOrganizerCollection::KeyName, defaultCollectionName); | ||
| 2146 | 47 | |||
| 2147 | 48 | QVERIFY(engine->saveCollection(&collection, &error)); | ||
| 2148 | 49 | QCOMPARE(error, QOrganizerManager::NoError); | ||
| 2149 | 50 | QVERIFY(!collection.id().isNull()); | ||
| 2150 | 51 | } | ||
| 2151 | 52 | |||
| 2152 | 53 | void testCreateTaskList() | ||
| 2153 | 54 | { | ||
| 2154 | 55 | QOrganizerEDSEngine *engine = QOrganizerEDSEngine::createEDSEngine(QMap<QString, QString>()); | ||
| 2155 | 56 | |||
| 2156 | 57 | QOrganizerCollection collection; | ||
| 2157 | 58 | QtOrganizer::QOrganizerManager::Error error; | ||
| 2158 | 59 | collection.setMetaData(QOrganizerCollection::KeyName, defaultTaskCollectionName); | ||
| 2159 | 60 | collection.setExtendedMetaData(collectionTypePropertyName, taskListTypeName); | ||
| 2160 | 61 | |||
| 2161 | 62 | QSignalSpy createdCollection(engine, SIGNAL(collectionsAdded(QList<QOrganizerCollectionId>))); | ||
| 2162 | 63 | QVERIFY(engine->saveCollection(&collection, &error)); | ||
| 2163 | 64 | QCOMPARE(error, QOrganizerManager::NoError); | ||
| 2164 | 65 | QVERIFY(!collection.id().isNull()); | ||
| 2165 | 66 | |||
| 2166 | 67 | //verify signal | ||
| 2167 | 68 | QCOMPARE(createdCollection.count(), 1); | ||
| 2168 | 69 | QList<QVariant> args = createdCollection.takeFirst(); | ||
| 2169 | 70 | QCOMPARE(args.count(), 1); | ||
| 2170 | 71 | |||
| 2171 | 72 | QVERIFY(engine->collections(&error).contains(collection)); | ||
| 2172 | 73 | delete engine; | ||
| 2173 | 74 | |||
| 2174 | 75 | // recreate and check if the new collection is listed | ||
| 2175 | 76 | engine = QOrganizerEDSEngine::createEDSEngine(QMap<QString, QString>()); | ||
| 2176 | 77 | QVERIFY(engine->collections(&error).contains(collection)); | ||
| 2177 | 78 | } | ||
| 2178 | 79 | |||
| 2179 | 80 | void testCreateTask() | ||
| 2180 | 81 | { | ||
| 2181 | 82 | static QString displayLabelValue = QStringLiteral("Todo test"); | ||
| 2182 | 83 | static QString descriptionValue = QStringLiteral("Todo description"); | ||
| 2183 | 84 | |||
| 2184 | 85 | QOrganizerEDSEngine *engine = QOrganizerEDSEngine::createEDSEngine(QMap<QString, QString>()); | ||
| 2185 | 86 | |||
| 2186 | 87 | QOrganizerCollection collection; | ||
| 2187 | 88 | QtOrganizer::QOrganizerManager::Error error; | ||
| 2188 | 89 | collection.setMetaData(QOrganizerCollection::KeyName, defaultTaskCollectionName + "2"); | ||
| 2189 | 90 | collection.setExtendedMetaData(collectionTypePropertyName, taskListTypeName); | ||
| 2190 | 91 | QVERIFY(engine->saveCollection(&collection, &error)); | ||
| 2191 | 92 | |||
| 2192 | 93 | QOrganizerTodo todo; | ||
| 2193 | 94 | todo.setCollectionId(collection.id()); | ||
| 2194 | 95 | todo.setStartDateTime(QDateTime(QDate(2013, 9, 3), QTime(0,30,0))); | ||
| 2195 | 96 | todo.setDisplayLabel(displayLabelValue); | ||
| 2196 | 97 | todo.setDescription(descriptionValue); | ||
| 2197 | 98 | |||
| 2198 | 99 | QMap<int, QtOrganizer::QOrganizerManager::Error> errorMap; | ||
| 2199 | 100 | QList<QOrganizerItem> items; | ||
| 2200 | 101 | QSignalSpy createdItem(engine, SIGNAL(itemsAdded(QList<QOrganizerItemId>))); | ||
| 2201 | 102 | items << todo; | ||
| 2202 | 103 | bool saveResult = engine->saveItems(&items, | ||
| 2203 | 104 | QList<QtOrganizer::QOrganizerItemDetail::DetailType>(), | ||
| 2204 | 105 | &errorMap, | ||
| 2205 | 106 | &error); | ||
| 2206 | 107 | QVERIFY(saveResult); | ||
| 2207 | 108 | QCOMPARE(error, QOrganizerManager::NoError); | ||
| 2208 | 109 | QVERIFY(errorMap.isEmpty()); | ||
| 2209 | 110 | QVERIFY(!items[0].id().isNull()); | ||
| 2210 | 111 | |||
| 2211 | 112 | //verify signal | ||
| 2212 | 113 | QCOMPARE(createdItem.count(), 1); | ||
| 2213 | 114 | QList<QVariant> args = createdItem.takeFirst(); | ||
| 2214 | 115 | QCOMPARE(args.count(), 1); | ||
| 2215 | 116 | |||
| 2216 | 117 | // check if the item is listead inside the correct collection | ||
| 2217 | 118 | QOrganizerItemSortOrder sort; | ||
| 2218 | 119 | QOrganizerItemFetchHint hint; | ||
| 2219 | 120 | QOrganizerItemCollectionFilter filter; | ||
| 2220 | 121 | |||
| 2221 | 122 | filter.setCollectionId(collection.id()); | ||
| 2222 | 123 | |||
| 2223 | 124 | items = engine->items(filter, | ||
| 2224 | 125 | QDateTime(), | ||
| 2225 | 126 | QDateTime(), | ||
| 2226 | 127 | 10, | ||
| 2227 | 128 | sort, | ||
| 2228 | 129 | hint, | ||
| 2229 | 130 | &error); | ||
| 2230 | 131 | |||
| 2231 | 132 | QCOMPARE(items.count(), 1); | ||
| 2232 | 133 | QOrganizerTodo result = static_cast<QOrganizerTodo>(items[0]); | ||
| 2233 | 134 | todo = items[0]; | ||
| 2234 | 135 | QCOMPARE(result.id(), todo.id()); | ||
| 2235 | 136 | QCOMPARE(result.startDateTime(), todo.startDateTime()); | ||
| 2236 | 137 | QCOMPARE(result.displayLabel(), todo.displayLabel()); | ||
| 2237 | 138 | QCOMPARE(result.description(), todo.description()); | ||
| 2238 | 139 | |||
| 2239 | 140 | |||
| 2240 | 141 | // check if the item is listead by id | ||
| 2241 | 142 | QList<QOrganizerItemId> ids; | ||
| 2242 | 143 | ids << todo.id(); | ||
| 2243 | 144 | |||
| 2244 | 145 | items = engine->items(ids, hint, &errorMap, &error); | ||
| 2245 | 146 | QCOMPARE(items.count(), 1); | ||
| 2246 | 147 | result = static_cast<QOrganizerTodo>(items[0]); | ||
| 2247 | 148 | todo = items[0]; | ||
| 2248 | 149 | QCOMPARE(result.id(), todo.id()); | ||
| 2249 | 150 | QCOMPARE(result.startDateTime(), todo.startDateTime()); | ||
| 2250 | 151 | QCOMPARE(result.displayLabel(), todo.displayLabel()); | ||
| 2251 | 152 | QCOMPARE(result.description(), todo.description()); | ||
| 2252 | 153 | |||
| 2253 | 154 | delete engine; | ||
| 2254 | 155 | } | ||
| 2255 | 156 | |||
| 2256 | 157 | void testRemoveCollection() | ||
| 2257 | 158 | { | ||
| 2258 | 159 | static QString removableCollectionName = defaultTaskCollectionName + QStringLiteral("_REMOVABLE"); | ||
| 2259 | 160 | |||
| 2260 | 161 | QOrganizerEDSEngine *engine = QOrganizerEDSEngine::createEDSEngine(QMap<QString, QString>()); | ||
| 2261 | 162 | |||
| 2262 | 163 | // Create a collection | ||
| 2263 | 164 | QOrganizerCollection collection; | ||
| 2264 | 165 | QtOrganizer::QOrganizerManager::Error error; | ||
| 2265 | 166 | collection.setMetaData(QOrganizerCollection::KeyName, removableCollectionName); | ||
| 2266 | 167 | QVERIFY(engine->saveCollection(&collection, &error)); | ||
| 2267 | 168 | delete engine; | ||
| 2268 | 169 | |||
| 2269 | 170 | QTest::qSleep(1000); | ||
| 2270 | 171 | |||
| 2271 | 172 | engine = QOrganizerEDSEngine::createEDSEngine(QMap<QString, QString>()); | ||
| 2272 | 173 | // remove recent created collection | ||
| 2273 | 174 | QVERIFY(engine->removeCollection(collection.id(), &error)); | ||
| 2274 | 175 | |||
| 2275 | 176 | // Check if collection is not listed anymore | ||
| 2276 | 177 | QTest::qSleep(1000); | ||
| 2277 | 178 | QList<QOrganizerCollection> collections = engine->collections(&error); | ||
| 2278 | 179 | QVERIFY(!collections.contains(collection)); | ||
| 2279 | 180 | } | ||
| 2280 | 181 | }; | ||
| 2281 | 182 | |||
| 2282 | 183 | const QString CollectionTest::defaultCollectionName = QStringLiteral("TEST COLLECTION"); | ||
| 2283 | 184 | const QString CollectionTest::defaultTaskCollectionName = QStringLiteral("TEST COLLECTION TASK LIST"); | ||
| 2284 | 185 | const QString CollectionTest::collectionTypePropertyName = QStringLiteral("collection-type"); | ||
| 2285 | 186 | const QString CollectionTest::taskListTypeName = QStringLiteral("Task List"); | ||
| 2286 | 187 | |||
| 2287 | 188 | |||
| 2288 | 189 | QTEST_MAIN(CollectionTest) | ||
| 2289 | 190 | |||
| 2290 | 191 | #include "collections-test.moc" | ||
| 2291 | 0 | 192 | ||
| 2292 | === added file 'tests/unittest/event-test.cpp' | |||
| 2293 | --- tests/unittest/event-test.cpp 1970-01-01 00:00:00 +0000 | |||
| 2294 | +++ tests/unittest/event-test.cpp 2013-09-09 21:01:24 +0000 | |||
| 2295 | @@ -0,0 +1,138 @@ | |||
| 2296 | 1 | /* | ||
| 2297 | 2 | * Copyright 2013 Canonical Ltd. | ||
| 2298 | 3 | * | ||
| 2299 | 4 | * This file is part of qtorganizer5-eds. | ||
| 2300 | 5 | * | ||
| 2301 | 6 | * contact-service-app is free software; you can redistribute it and/or modify | ||
| 2302 | 7 | * it under the terms of the GNU General Public License as published by | ||
| 2303 | 8 | * the Free Software Foundation; version 3. | ||
| 2304 | 9 | * | ||
| 2305 | 10 | * contact-service-app is distributed in the hope that it will be useful, | ||
| 2306 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 2307 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 2308 | 13 | * GNU General Public License for more details. | ||
| 2309 | 14 | * | ||
| 2310 | 15 | * You should have received a copy of the GNU General Public License | ||
| 2311 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 2312 | 17 | */ | ||
| 2313 | 18 | |||
| 2314 | 19 | |||
| 2315 | 20 | #include <QObject> | ||
| 2316 | 21 | #include <QtTest> | ||
| 2317 | 22 | #include <QDebug> | ||
| 2318 | 23 | |||
| 2319 | 24 | #include <QtOrganizer> | ||
| 2320 | 25 | |||
| 2321 | 26 | #include "qorganizer-eds-engine.h" | ||
| 2322 | 27 | |||
| 2323 | 28 | |||
| 2324 | 29 | using namespace QtOrganizer; | ||
| 2325 | 30 | |||
| 2326 | 31 | class EventTest : public QObject | ||
| 2327 | 32 | { | ||
| 2328 | 33 | Q_OBJECT | ||
| 2329 | 34 | private: | ||
| 2330 | 35 | static const QString defaultCollectionName; | ||
| 2331 | 36 | static const QString defaultTaskCollectionName; | ||
| 2332 | 37 | static const QString collectionTypePropertyName; | ||
| 2333 | 38 | static const QString taskListTypeName; | ||
| 2334 | 39 | |||
| 2335 | 40 | private Q_SLOTS: | ||
| 2336 | 41 | void testCreateEventWithReminder() | ||
| 2337 | 42 | { | ||
| 2338 | 43 | static QString displayLabelValue = QStringLiteral("Todo test"); | ||
| 2339 | 44 | static QString descriptionValue = QStringLiteral("Todo description"); | ||
| 2340 | 45 | |||
| 2341 | 46 | QOrganizerEDSEngine *engine = QOrganizerEDSEngine::createEDSEngine(QMap<QString, QString>()); | ||
| 2342 | 47 | |||
| 2343 | 48 | QOrganizerCollection collection; | ||
| 2344 | 49 | QtOrganizer::QOrganizerManager::Error error; | ||
| 2345 | 50 | collection.setMetaData(QOrganizerCollection::KeyName, defaultCollectionName); | ||
| 2346 | 51 | collection.setExtendedMetaData(collectionTypePropertyName, taskListTypeName); | ||
| 2347 | 52 | |||
| 2348 | 53 | engine->saveCollection(&collection, &error); | ||
| 2349 | 54 | |||
| 2350 | 55 | QOrganizerTodo todo; | ||
| 2351 | 56 | todo.setCollectionId(collection.id()); | ||
| 2352 | 57 | todo.setStartDateTime(QDateTime(QDate(2013, 9, 3), QTime(0,30,0))); | ||
| 2353 | 58 | todo.setDisplayLabel(displayLabelValue); | ||
| 2354 | 59 | todo.setDescription(descriptionValue); | ||
| 2355 | 60 | |||
| 2356 | 61 | QOrganizerItemVisualReminder vReminder; | ||
| 2357 | 62 | vReminder.setDataUrl(QUrl("http://www.alarms.com")); | ||
| 2358 | 63 | vReminder.setMessage("Test visual reminder"); | ||
| 2359 | 64 | |||
| 2360 | 65 | QOrganizerItemAudibleReminder aReminder; | ||
| 2361 | 66 | aReminder.setSecondsBeforeStart(10); | ||
| 2362 | 67 | aReminder.setRepetition(10, 20); | ||
| 2363 | 68 | aReminder.setDataUrl(QUrl("file://home/user/My Musics/play as alarm.wav")); | ||
| 2364 | 69 | |||
| 2365 | 70 | |||
| 2366 | 71 | todo.saveDetail(&aReminder); | ||
| 2367 | 72 | todo.saveDetail(&vReminder); | ||
| 2368 | 73 | |||
| 2369 | 74 | QMap<int, QtOrganizer::QOrganizerManager::Error> errorMap; | ||
| 2370 | 75 | QList<QOrganizerItem> items; | ||
| 2371 | 76 | items << todo; | ||
| 2372 | 77 | bool saveResult = engine->saveItems(&items, | ||
| 2373 | 78 | QList<QtOrganizer::QOrganizerItemDetail::DetailType>(), | ||
| 2374 | 79 | &errorMap, | ||
| 2375 | 80 | &error); | ||
| 2376 | 81 | QVERIFY(saveResult); | ||
| 2377 | 82 | |||
| 2378 | 83 | // delete engine to make sure the new engine will be loaded from scratch | ||
| 2379 | 84 | delete engine; | ||
| 2380 | 85 | |||
| 2381 | 86 | engine = QOrganizerEDSEngine::createEDSEngine(QMap<QString, QString>()); | ||
| 2382 | 87 | |||
| 2383 | 88 | QOrganizerItemSortOrder sort; | ||
| 2384 | 89 | QOrganizerItemFetchHint hint; | ||
| 2385 | 90 | QOrganizerItemIdFilter filter; | ||
| 2386 | 91 | |||
| 2387 | 92 | QList<QOrganizerItemId> ids; | ||
| 2388 | 93 | ids << items[0].id(); | ||
| 2389 | 94 | filter.setIds(ids); | ||
| 2390 | 95 | |||
| 2391 | 96 | items = engine->items(filter, | ||
| 2392 | 97 | QDateTime(), | ||
| 2393 | 98 | QDateTime(), | ||
| 2394 | 99 | 10, | ||
| 2395 | 100 | sort, | ||
| 2396 | 101 | hint, | ||
| 2397 | 102 | &error); | ||
| 2398 | 103 | QCOMPARE(items.count(), 1); | ||
| 2399 | 104 | |||
| 2400 | 105 | // audible | ||
| 2401 | 106 | QList<QOrganizerItemDetail> reminders = items[0].details(QOrganizerItemDetail::TypeAudibleReminder); | ||
| 2402 | 107 | QCOMPARE(reminders.size(), 1); | ||
| 2403 | 108 | |||
| 2404 | 109 | QOrganizerItemAudibleReminder aReminder2 = reminders[0]; | ||
| 2405 | 110 | QCOMPARE(aReminder2.secondsBeforeStart(), aReminder.secondsBeforeStart()); | ||
| 2406 | 111 | QCOMPARE(aReminder2.repetitionCount(), aReminder.repetitionCount()); | ||
| 2407 | 112 | QCOMPARE(aReminder2.repetitionDelay(), aReminder.repetitionDelay()); | ||
| 2408 | 113 | QCOMPARE(aReminder2.dataUrl(), aReminder.dataUrl()); | ||
| 2409 | 114 | //QCOMPARE(aReminder2, aReminder); | ||
| 2410 | 115 | |||
| 2411 | 116 | // visual | ||
| 2412 | 117 | reminders = items[0].details(QOrganizerItemDetail::TypeVisualReminder); | ||
| 2413 | 118 | QCOMPARE(reminders.size(), 1); | ||
| 2414 | 119 | |||
| 2415 | 120 | QOrganizerItemVisualReminder vReminder2 = reminders[0]; | ||
| 2416 | 121 | //vReminder.setRepetition(1, 0); | ||
| 2417 | 122 | QCOMPARE(vReminder2.secondsBeforeStart(), vReminder.secondsBeforeStart()); | ||
| 2418 | 123 | QCOMPARE(vReminder2.repetitionCount(), vReminder.repetitionCount()); | ||
| 2419 | 124 | QCOMPARE(vReminder2.repetitionDelay(), vReminder.repetitionDelay()); | ||
| 2420 | 125 | QCOMPARE(vReminder2.dataUrl(), vReminder.dataUrl()); | ||
| 2421 | 126 | QCOMPARE(vReminder2.message(), vReminder.message()); | ||
| 2422 | 127 | } | ||
| 2423 | 128 | }; | ||
| 2424 | 129 | |||
| 2425 | 130 | const QString EventTest::defaultCollectionName = QStringLiteral("TEST_EVENT_COLLECTION"); | ||
| 2426 | 131 | const QString EventTest::defaultTaskCollectionName = QStringLiteral("TEST_EVENT_COLLECTION TASK LIST"); | ||
| 2427 | 132 | const QString EventTest::collectionTypePropertyName = QStringLiteral("collection-type"); | ||
| 2428 | 133 | const QString EventTest::taskListTypeName = QStringLiteral("Task List"); | ||
| 2429 | 134 | |||
| 2430 | 135 | |||
| 2431 | 136 | QTEST_MAIN(EventTest) | ||
| 2432 | 137 | |||
| 2433 | 138 | #include "event-test.moc" | ||
| 2434 | 0 | 139 | ||
| 2435 | === added file 'tests/unittest/parseecal-test.cpp' | |||
| 2436 | --- tests/unittest/parseecal-test.cpp 1970-01-01 00:00:00 +0000 | |||
| 2437 | +++ tests/unittest/parseecal-test.cpp 2013-09-09 21:01:24 +0000 | |||
| 2438 | @@ -0,0 +1,366 @@ | |||
| 2439 | 1 | /* | ||
| 2440 | 2 | * Copyright 2013 Canonical Ltd. | ||
| 2441 | 3 | * | ||
| 2442 | 4 | * This file is part of qtorganizer5-eds. | ||
| 2443 | 5 | * | ||
| 2444 | 6 | * contact-service-app is free software; you can redistribute it and/or modify | ||
| 2445 | 7 | * it under the terms of the GNU General Public License as published by | ||
| 2446 | 8 | * the Free Software Foundation; version 3. | ||
| 2447 | 9 | * | ||
| 2448 | 10 | * contact-service-app is distributed in the hope that it will be useful, | ||
| 2449 | 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 2450 | 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 2451 | 13 | * GNU General Public License for more details. | ||
| 2452 | 14 | * | ||
| 2453 | 15 | * You should have received a copy of the GNU General Public License | ||
| 2454 | 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 2455 | 17 | */ | ||
| 2456 | 18 | |||
| 2457 | 19 | //ugly hack but this allow us to test the engine without mock EDS | ||
| 2458 | 20 | #define private public | ||
| 2459 | 21 | #include "qorganizer-eds-engine.h" | ||
| 2460 | 22 | #undef private | ||
| 2461 | 23 | |||
| 2462 | 24 | #include <QObject> | ||
| 2463 | 25 | #include <QtTest> | ||
| 2464 | 26 | #include <QDebug> | ||
| 2465 | 27 | |||
| 2466 | 28 | #include <QtOrganizer> | ||
| 2467 | 29 | |||
| 2468 | 30 | #include <libecal/libecal.h> | ||
| 2469 | 31 | |||
| 2470 | 32 | using namespace QtOrganizer; | ||
| 2471 | 33 | |||
| 2472 | 34 | class ParseEcalTest : public QObject | ||
| 2473 | 35 | { | ||
| 2474 | 36 | Q_OBJECT | ||
| 2475 | 37 | |||
| 2476 | 38 | private Q_SLOTS: | ||
| 2477 | 39 | void testParseStartTime() | ||
| 2478 | 40 | { | ||
| 2479 | 41 | QDateTime startTime = QDateTime::currentDateTime(); | ||
| 2480 | 42 | QDateTime endTime(startTime); | ||
| 2481 | 43 | endTime = endTime.addDays(2); | ||
| 2482 | 44 | |||
| 2483 | 45 | ECalComponent *comp = e_cal_component_new(); | ||
| 2484 | 46 | e_cal_component_set_new_vtype(comp, E_CAL_COMPONENT_EVENT); | ||
| 2485 | 47 | |||
| 2486 | 48 | ECalComponentDateTime dt; | ||
| 2487 | 49 | |||
| 2488 | 50 | struct icaltimetype itt = icaltime_from_timet(startTime.toTime_t(), FALSE); | ||
| 2489 | 51 | dt.value = &itt; | ||
| 2490 | 52 | dt.tzid = ""; | ||
| 2491 | 53 | e_cal_component_set_dtstart(comp, &dt); | ||
| 2492 | 54 | |||
| 2493 | 55 | QOrganizerEvent item; | ||
| 2494 | 56 | QOrganizerEDSEngine::parseStartTime(comp, &item); | ||
| 2495 | 57 | QCOMPARE(item.startDateTime().toTime_t(), startTime.toTime_t()); | ||
| 2496 | 58 | |||
| 2497 | 59 | itt = icaltime_from_timet(endTime.toTime_t(), FALSE); | ||
| 2498 | 60 | dt.value = &itt; | ||
| 2499 | 61 | e_cal_component_set_dtend(comp, &dt); | ||
| 2500 | 62 | |||
| 2501 | 63 | QOrganizerEDSEngine::parseEndTime(comp, &item); | ||
| 2502 | 64 | QCOMPARE(item.endDateTime().toTime_t(), endTime.toTime_t()); | ||
| 2503 | 65 | } | ||
| 2504 | 66 | |||
| 2505 | 67 | void testParseRemindersQOrganizerEvent2ECalComponent() | ||
| 2506 | 68 | { | ||
| 2507 | 69 | QOrganizerEvent event; | ||
| 2508 | 70 | QOrganizerItemAudibleReminder aReminder; | ||
| 2509 | 71 | |||
| 2510 | 72 | // Check audible reminder | ||
| 2511 | 73 | aReminder.setRepetition(10, 30); | ||
| 2512 | 74 | aReminder.setSecondsBeforeStart(10); | ||
| 2513 | 75 | QCOMPARE(aReminder.secondsBeforeStart(), 10); | ||
| 2514 | 76 | event.saveDetail(&aReminder); | ||
| 2515 | 77 | |||
| 2516 | 78 | ECalComponent *comp = e_cal_component_new(); | ||
| 2517 | 79 | e_cal_component_set_new_vtype(comp, E_CAL_COMPONENT_EVENT); | ||
| 2518 | 80 | |||
| 2519 | 81 | QOrganizerEDSEngine::parseReminders(event, comp); | ||
| 2520 | 82 | |||
| 2521 | 83 | GList *aIds = e_cal_component_get_alarm_uids(comp); | ||
| 2522 | 84 | QCOMPARE(g_list_length(aIds), (guint) 1); | ||
| 2523 | 85 | |||
| 2524 | 86 | ECalComponentAlarm *alarm = e_cal_component_get_alarm(comp, (const gchar*)aIds->data); | ||
| 2525 | 87 | QVERIFY(alarm); | ||
| 2526 | 88 | |||
| 2527 | 89 | ECalComponentAlarmAction aAction; | ||
| 2528 | 90 | e_cal_component_alarm_get_action(alarm, &aAction); | ||
| 2529 | 91 | QCOMPARE(aAction, E_CAL_COMPONENT_ALARM_AUDIO); | ||
| 2530 | 92 | |||
| 2531 | 93 | ECalComponentAlarmTrigger trigger; | ||
| 2532 | 94 | e_cal_component_alarm_get_trigger(alarm, &trigger); | ||
| 2533 | 95 | QCOMPARE(trigger.type, E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START); | ||
| 2534 | 96 | QCOMPARE(icaldurationtype_as_int(trigger.u.rel_duration) * -1, aReminder.secondsBeforeStart()); | ||
| 2535 | 97 | |||
| 2536 | 98 | ECalComponentAlarmRepeat aRepeat; | ||
| 2537 | 99 | e_cal_component_alarm_get_repeat(alarm, &aRepeat); | ||
| 2538 | 100 | QCOMPARE(aRepeat.repetitions, aReminder.repetitionCount()); | ||
| 2539 | 101 | QCOMPARE(icaldurationtype_as_int(aRepeat.duration), aReminder.repetitionDelay()); | ||
| 2540 | 102 | |||
| 2541 | 103 | g_object_unref(comp); | ||
| 2542 | 104 | } | ||
| 2543 | 105 | |||
| 2544 | 106 | void testParseRemindersECalComponent2QOrganizerEvent() | ||
| 2545 | 107 | { | ||
| 2546 | 108 | ECalComponent *comp = e_cal_component_new(); | ||
| 2547 | 109 | e_cal_component_set_new_vtype(comp, E_CAL_COMPONENT_EVENT); | ||
| 2548 | 110 | |||
| 2549 | 111 | ECalComponentAlarm *alarm = e_cal_component_alarm_new(); | ||
| 2550 | 112 | e_cal_component_alarm_set_action(alarm, E_CAL_COMPONENT_ALARM_DISPLAY); | ||
| 2551 | 113 | |||
| 2552 | 114 | ECalComponentAlarmTrigger trigger; | ||
| 2553 | 115 | trigger.type = E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START; | ||
| 2554 | 116 | trigger.u.rel_duration = icaldurationtype_from_int(-10); | ||
| 2555 | 117 | e_cal_component_alarm_set_trigger(alarm, trigger); | ||
| 2556 | 118 | |||
| 2557 | 119 | ECalComponentAlarmRepeat aRepeat; | ||
| 2558 | 120 | aRepeat.repetitions = 5; | ||
| 2559 | 121 | aRepeat.duration = icaldurationtype_from_int(100); | ||
| 2560 | 122 | e_cal_component_alarm_set_repeat(alarm, aRepeat); | ||
| 2561 | 123 | |||
| 2562 | 124 | e_cal_component_add_alarm(comp, alarm); | ||
| 2563 | 125 | e_cal_component_alarm_free(alarm); | ||
| 2564 | 126 | |||
| 2565 | 127 | QOrganizerItem alarmItem; | ||
| 2566 | 128 | QOrganizerEDSEngine::parseReminders(comp, &alarmItem); | ||
| 2567 | 129 | |||
| 2568 | 130 | QOrganizerItemVisualReminder vReminder = alarmItem.detail(QOrganizerItemDetail::TypeVisualReminder); | ||
| 2569 | 131 | QCOMPARE(vReminder.repetitionCount(), 5); | ||
| 2570 | 132 | QCOMPARE(vReminder.repetitionDelay(), 100); | ||
| 2571 | 133 | QCOMPARE(vReminder.secondsBeforeStart(), 10); | ||
| 2572 | 134 | |||
| 2573 | 135 | g_object_unref(comp); | ||
| 2574 | 136 | } | ||
| 2575 | 137 | |||
| 2576 | 138 | void testParseRecurenceQOrganizerEvent2ECalComponent() | ||
| 2577 | 139 | { | ||
| 2578 | 140 | // by date | ||
| 2579 | 141 | QOrganizerEvent event; | ||
| 2580 | 142 | QOrganizerItemRecurrence rec; | ||
| 2581 | 143 | |||
| 2582 | 144 | QList<QDate> rDates; | ||
| 2583 | 145 | rDates << QDate(2010, 1, 20) | ||
| 2584 | 146 | << QDate(2011, 2, 21) | ||
| 2585 | 147 | << QDate(2012, 3, 22); | ||
| 2586 | 148 | |||
| 2587 | 149 | rec.setRecurrenceDates(rDates.toSet()); | ||
| 2588 | 150 | |||
| 2589 | 151 | QList<QDate> rExeptDates; | ||
| 2590 | 152 | rExeptDates << QDate(2013, 4, 23) | ||
| 2591 | 153 | << QDate(2014, 5, 24) | ||
| 2592 | 154 | << QDate(2015, 6, 25); | ||
| 2593 | 155 | rec.setExceptionDates(rExeptDates.toSet()); | ||
| 2594 | 156 | |||
| 2595 | 157 | QOrganizerRecurrenceRule dailyRule; | ||
| 2596 | 158 | QList<QOrganizerRecurrenceRule> rrules; | ||
| 2597 | 159 | |||
| 2598 | 160 | dailyRule.setFrequency(QOrganizerRecurrenceRule::Daily); | ||
| 2599 | 161 | dailyRule.setLimit(1000); | ||
| 2600 | 162 | rrules << dailyRule; | ||
| 2601 | 163 | |||
| 2602 | 164 | QOrganizerRecurrenceRule weeklyRule; | ||
| 2603 | 165 | weeklyRule.setFrequency(QOrganizerRecurrenceRule::Weekly); | ||
| 2604 | 166 | weeklyRule.setLimit(1001); | ||
| 2605 | 167 | QList<Qt::DayOfWeek> daysOfWeek; | ||
| 2606 | 168 | daysOfWeek << Qt::Monday | ||
| 2607 | 169 | << Qt::Tuesday | ||
| 2608 | 170 | << Qt::Wednesday | ||
| 2609 | 171 | << Qt::Thursday | ||
| 2610 | 172 | << Qt::Friday; | ||
| 2611 | 173 | weeklyRule.setDaysOfWeek(daysOfWeek.toSet()); | ||
| 2612 | 174 | weeklyRule.setFirstDayOfWeek(Qt::Sunday); | ||
| 2613 | 175 | rrules << weeklyRule; | ||
| 2614 | 176 | |||
| 2615 | 177 | QOrganizerRecurrenceRule monthlyRule; | ||
| 2616 | 178 | monthlyRule.setFrequency(QOrganizerRecurrenceRule::Monthly); | ||
| 2617 | 179 | monthlyRule.setLimit(1002); | ||
| 2618 | 180 | |||
| 2619 | 181 | QList<int> daysOfMonth; | ||
| 2620 | 182 | daysOfMonth << 1 | ||
| 2621 | 183 | << 15 | ||
| 2622 | 184 | << 30; | ||
| 2623 | 185 | monthlyRule.setDaysOfMonth(daysOfMonth.toSet()); | ||
| 2624 | 186 | rrules << monthlyRule; | ||
| 2625 | 187 | |||
| 2626 | 188 | QOrganizerRecurrenceRule yearlyRule; | ||
| 2627 | 189 | yearlyRule.setFrequency(QOrganizerRecurrenceRule::Yearly); | ||
| 2628 | 190 | yearlyRule.setLimit(1003); | ||
| 2629 | 191 | QList<int> daysOfYear; | ||
| 2630 | 192 | daysOfYear << 1 | ||
| 2631 | 193 | << 10 | ||
| 2632 | 194 | << 20 | ||
| 2633 | 195 | << 50 | ||
| 2634 | 196 | << 300; | ||
| 2635 | 197 | yearlyRule.setDaysOfYear(daysOfYear.toSet()); | ||
| 2636 | 198 | |||
| 2637 | 199 | |||
| 2638 | 200 | QList<QOrganizerRecurrenceRule::Month> monthsOfYear; | ||
| 2639 | 201 | monthsOfYear << QOrganizerRecurrenceRule::January | ||
| 2640 | 202 | << QOrganizerRecurrenceRule::March | ||
| 2641 | 203 | << QOrganizerRecurrenceRule::December; | ||
| 2642 | 204 | yearlyRule.setMonthsOfYear(monthsOfYear.toSet()); | ||
| 2643 | 205 | rrules << yearlyRule; | ||
| 2644 | 206 | |||
| 2645 | 207 | rec.setRecurrenceRules(rrules.toSet()); | ||
| 2646 | 208 | |||
| 2647 | 209 | // save recurrence | ||
| 2648 | 210 | event.saveDetail(&rec); | ||
| 2649 | 211 | |||
| 2650 | 212 | ECalComponent *comp = e_cal_component_new(); | ||
| 2651 | 213 | e_cal_component_set_new_vtype(comp, E_CAL_COMPONENT_EVENT); | ||
| 2652 | 214 | QOrganizerEDSEngine::parseRecurrence(event, comp); | ||
| 2653 | 215 | |||
| 2654 | 216 | // recurrence dates | ||
| 2655 | 217 | GSList *periodList = 0; | ||
| 2656 | 218 | e_cal_component_get_rdate_list(comp, &periodList); | ||
| 2657 | 219 | |||
| 2658 | 220 | QCOMPARE(g_slist_length(periodList), (guint)3); | ||
| 2659 | 221 | |||
| 2660 | 222 | for(GSList *pIter = periodList; pIter != 0; pIter = pIter->next) { | ||
| 2661 | 223 | ECalComponentPeriod *period = static_cast<ECalComponentPeriod*>(pIter->data); | ||
| 2662 | 224 | QDate periodDate = QDateTime::fromTime_t(icaltime_as_timet(period->start)).date(); | ||
| 2663 | 225 | |||
| 2664 | 226 | QVERIFY(rDates.contains(periodDate)); | ||
| 2665 | 227 | } | ||
| 2666 | 228 | e_cal_component_free_period_list(periodList); | ||
| 2667 | 229 | |||
| 2668 | 230 | // exception dates | ||
| 2669 | 231 | GSList *exDateList = 0; | ||
| 2670 | 232 | e_cal_component_get_exdate_list(comp, &exDateList); | ||
| 2671 | 233 | for(GSList *pIter = exDateList; pIter != 0; pIter = pIter->next) { | ||
| 2672 | 234 | ECalComponentDateTime *exDate = static_cast<ECalComponentDateTime*>(pIter->data); | ||
| 2673 | 235 | QDate exDateValue = QDateTime::fromTime_t(icaltime_as_timet(*exDate->value)).date(); | ||
| 2674 | 236 | QVERIFY(rExeptDates.contains(exDateValue)); | ||
| 2675 | 237 | } | ||
| 2676 | 238 | e_cal_component_free_exdate_list(exDateList); | ||
| 2677 | 239 | |||
| 2678 | 240 | |||
| 2679 | 241 | // rules | ||
| 2680 | 242 | GSList *recurList = 0; | ||
| 2681 | 243 | e_cal_component_get_rrule_list(comp, &recurList); | ||
| 2682 | 244 | QCOMPARE(g_slist_length(recurList), (guint) rrules.count()); | ||
| 2683 | 245 | |||
| 2684 | 246 | for(GSList *recurListIter = recurList; recurListIter != 0; recurListIter = recurListIter->next) { | ||
| 2685 | 247 | struct icalrecurrencetype *rule = static_cast<struct icalrecurrencetype*>(recurListIter->data); | ||
| 2686 | 248 | |||
| 2687 | 249 | switch(rule->freq) | ||
| 2688 | 250 | { | ||
| 2689 | 251 | case ICAL_DAILY_RECURRENCE: | ||
| 2690 | 252 | QCOMPARE(rule->count, dailyRule.limitCount()); | ||
| 2691 | 253 | break; | ||
| 2692 | 254 | case ICAL_WEEKLY_RECURRENCE: | ||
| 2693 | 255 | QCOMPARE(rule->count, weeklyRule.limitCount()); | ||
| 2694 | 256 | for (int d = Qt::Monday; d <= Qt::Sunday; d++) { | ||
| 2695 | 257 | if (daysOfWeek.contains(static_cast<Qt::DayOfWeek>(d))) { | ||
| 2696 | 258 | QVERIFY(rule->by_day[(d-1)] != ICAL_RECURRENCE_ARRAY_MAX); | ||
| 2697 | 259 | } else { | ||
| 2698 | 260 | QVERIFY(rule->by_day[d-1] == ICAL_RECURRENCE_ARRAY_MAX); | ||
| 2699 | 261 | } | ||
| 2700 | 262 | } | ||
| 2701 | 263 | break; | ||
| 2702 | 264 | case ICAL_MONTHLY_RECURRENCE: | ||
| 2703 | 265 | { | ||
| 2704 | 266 | QCOMPARE(rule->count, monthlyRule.limitCount()); | ||
| 2705 | 267 | |||
| 2706 | 268 | QList<int> ruleDays; | ||
| 2707 | 269 | for (int d=0; d < ICAL_BY_MONTHDAY_SIZE; d++) { | ||
| 2708 | 270 | if (rule->by_month_day[d] != ICAL_RECURRENCE_ARRAY_MAX) { | ||
| 2709 | 271 | ruleDays << rule->by_month_day[d]; | ||
| 2710 | 272 | } | ||
| 2711 | 273 | } | ||
| 2712 | 274 | QCOMPARE(ruleDays.count(), daysOfMonth.count()); | ||
| 2713 | 275 | Q_FOREACH(int day, ruleDays) { | ||
| 2714 | 276 | QVERIFY(daysOfMonth.contains(day)); | ||
| 2715 | 277 | } | ||
| 2716 | 278 | break; | ||
| 2717 | 279 | } | ||
| 2718 | 280 | case ICAL_YEARLY_RECURRENCE: | ||
| 2719 | 281 | { | ||
| 2720 | 282 | QCOMPARE(rule->count, yearlyRule.limitCount()); | ||
| 2721 | 283 | QList<int> ruleDays; | ||
| 2722 | 284 | |||
| 2723 | 285 | for (int d=0; d < ICAL_BY_YEARDAY_SIZE; d++) { | ||
| 2724 | 286 | if (rule->by_year_day[d] != ICAL_RECURRENCE_ARRAY_MAX) { | ||
| 2725 | 287 | |||
| 2726 | 288 | ruleDays << rule->by_year_day[d]; | ||
| 2727 | 289 | } | ||
| 2728 | 290 | } | ||
| 2729 | 291 | QCOMPARE(ruleDays.count(), daysOfYear.count()); | ||
| 2730 | 292 | Q_FOREACH(int day, ruleDays) { | ||
| 2731 | 293 | QVERIFY(daysOfYear.contains(day)); | ||
| 2732 | 294 | } | ||
| 2733 | 295 | |||
| 2734 | 296 | QList<int> ruleMonths; | ||
| 2735 | 297 | for (int d=0; d < ICAL_BY_MONTH_SIZE; d++) { | ||
| 2736 | 298 | if (rule->by_month[d] != ICAL_RECURRENCE_ARRAY_MAX) { | ||
| 2737 | 299 | ruleMonths << rule->by_month[d]; | ||
| 2738 | 300 | } | ||
| 2739 | 301 | } | ||
| 2740 | 302 | QCOMPARE(ruleMonths.count(), monthsOfYear.count()); | ||
| 2741 | 303 | Q_FOREACH(int month, ruleMonths) { | ||
| 2742 | 304 | QVERIFY(monthsOfYear.contains(static_cast<QOrganizerRecurrenceRule::Month>(month))); | ||
| 2743 | 305 | } | ||
| 2744 | 306 | } | ||
| 2745 | 307 | default: | ||
| 2746 | 308 | break; | ||
| 2747 | 309 | } | ||
| 2748 | 310 | } | ||
| 2749 | 311 | |||
| 2750 | 312 | // invert | ||
| 2751 | 313 | QOrganizerEvent event2; | ||
| 2752 | 314 | QOrganizerEDSEngine::parseRecurrence(comp, &event2); | ||
| 2753 | 315 | |||
| 2754 | 316 | QCOMPARE(event2.recurrenceDates(), event.recurrenceDates()); | ||
| 2755 | 317 | QCOMPARE(event2.exceptionDates(), event.exceptionDates()); | ||
| 2756 | 318 | |||
| 2757 | 319 | QList<QOrganizerRecurrenceRule> rrules2 = event2.recurrenceRules().toList(); | ||
| 2758 | 320 | QCOMPARE(rrules2.count(), rrules.count()); | ||
| 2759 | 321 | |||
| 2760 | 322 | Q_FOREACH(QOrganizerRecurrenceRule rule2, rrules2) { | ||
| 2761 | 323 | switch(rule2.frequency()) { | ||
| 2762 | 324 | case QOrganizerRecurrenceRule::Daily: | ||
| 2763 | 325 | QCOMPARE(rule2.limitCount(), dailyRule.limitCount()); | ||
| 2764 | 326 | break; | ||
| 2765 | 327 | case QOrganizerRecurrenceRule::Weekly: | ||
| 2766 | 328 | { | ||
| 2767 | 329 | QCOMPARE(rule2.limitCount(), weeklyRule.limitCount()); | ||
| 2768 | 330 | QList<Qt::DayOfWeek> daysOfWeek2 = rule2.daysOfWeek().toList(); | ||
| 2769 | 331 | qSort(daysOfWeek2); | ||
| 2770 | 332 | QCOMPARE(daysOfWeek2, daysOfWeek); | ||
| 2771 | 333 | break; | ||
| 2772 | 334 | } | ||
| 2773 | 335 | case QOrganizerRecurrenceRule::Monthly: | ||
| 2774 | 336 | { | ||
| 2775 | 337 | QCOMPARE(rule2.limitCount(), monthlyRule.limitCount()); | ||
| 2776 | 338 | QList<int> daysOfMonth2 = rule2.daysOfMonth().toList(); | ||
| 2777 | 339 | qSort(daysOfMonth2); | ||
| 2778 | 340 | QCOMPARE(daysOfMonth2, daysOfMonth); | ||
| 2779 | 341 | break; | ||
| 2780 | 342 | } | ||
| 2781 | 343 | case QOrganizerRecurrenceRule::Yearly: | ||
| 2782 | 344 | { | ||
| 2783 | 345 | QCOMPARE(rule2.limitCount(), yearlyRule.limitCount()); | ||
| 2784 | 346 | QList<int> daysOfYear2 = rule2.daysOfYear().toList(); | ||
| 2785 | 347 | qSort(daysOfYear2); | ||
| 2786 | 348 | QCOMPARE(daysOfYear2, daysOfYear); | ||
| 2787 | 349 | |||
| 2788 | 350 | QList<QOrganizerRecurrenceRule::Month> monthsOfYear2 = rule2.monthsOfYear().toList(); | ||
| 2789 | 351 | qSort(monthsOfYear2); | ||
| 2790 | 352 | QCOMPARE(monthsOfYear2, monthsOfYear); | ||
| 2791 | 353 | break; | ||
| 2792 | 354 | } | ||
| 2793 | 355 | default: | ||
| 2794 | 356 | QVERIFY(false); | ||
| 2795 | 357 | } | ||
| 2796 | 358 | } | ||
| 2797 | 359 | |||
| 2798 | 360 | g_object_unref(comp); | ||
| 2799 | 361 | } | ||
| 2800 | 362 | }; | ||
| 2801 | 363 | |||
| 2802 | 364 | QTEST_MAIN(ParseEcalTest) | ||
| 2803 | 365 | |||
| 2804 | 366 | #include "parseecal-test.moc" | ||
| 2805 | 0 | 367 | ||
| 2806 | === added file 'tests/unittest/parseitem-test.cpp' | |||
FAILED: Continuous integration, rev:24 jenkins. qa.ubuntu. com/job/ qtorganizer5- eds-ci/ 1/ jenkins. qa.ubuntu. com/job/ qtorganizer5- eds-saucy- amd64-ci/ 1/console jenkins. qa.ubuntu. com/job/ qtorganizer5- eds-saucy- armhf-ci/ 1/console jenkins. qa.ubuntu. com/job/ qtorganizer5- eds-saucy- i386-ci/ 1/console
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins: 8080/job/ qtorganizer5- eds-ci/ 1/rebuild
http://