qtorganizer5-eds-0.1.1+16.04.20160317/0000755000015600001650000000000012672563136017273 5ustar pbuserpbgroup00000000000000qtorganizer5-eds-0.1.1+16.04.20160317/cmake/0000755000015600001650000000000012672563136020353 5ustar pbuserpbgroup00000000000000qtorganizer5-eds-0.1.1+16.04.20160317/cmake/lcov.cmake0000644000015600001650000000502012672562647022323 0ustar pbuserpbgroup00000000000000# - This module creates a new 'lcov' target which generates # a coverage analysis html output. # LCOV is a graphical front-end for GCC's coverage testing tool gcov. Please see # http://ltp.sourceforge.net/coverage/lcov.php # # Usage: you must add an option to your CMakeLists.txt to build your application # with coverage support. Then you need to include this file to the lcov target. # # Example: # IF(BUILD_WITH_COVERAGE) # SET(CMAKE_C_FLAGS "-g -O0 -Wall -fprofile-arcs -ftest-coverage") # SET(CMAKE_CXX_FLAGS "-g -O0 -Wall -fprofile-arcs -ftest-coverage") # SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -lgcov") # include(${CMAKE_SOURCE_DIR}/cmake/lcov.cmake) # ENDIF(BUILD_WITH_COVERAGE) #============================================================================= # Copyright 2010 ascolab GmbH # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. # # This software is distributed WITHOUT ANY WARRANTY; without even the # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the License for more information. #============================================================================= # (To distributed this file outside of CMake, substitute the full # License text for the above reference.) set(REMOVE_PATTERN q*.h *.moc moc_*.cpp locale_facets.h new move.h) ## lcov target ADD_CUSTOM_TARGET(lcov) ADD_CUSTOM_COMMAND(TARGET lcov COMMAND mkdir -p coverage WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) ADD_CUSTOM_COMMAND(TARGET lcov COMMAND lcov --directory . --zerocounters WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) ADD_CUSTOM_COMMAND(TARGET lcov COMMAND make test WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) ADD_CUSTOM_COMMAND(TARGET lcov COMMAND lcov --directory . --capture --output-file ./coverage/stap_all.info --no-checksum --compat-libtool WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) ADD_CUSTOM_COMMAND(TARGET lcov COMMAND lcov --directory . -r ./coverage/stap_all.info ${REMOVE_PATTERN} --output-file ./coverage/stap.info WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) ADD_CUSTOM_COMMAND(TARGET lcov COMMAND genhtml -o ./coverage --title "Code Coverage" --legend --show-details --demangle-cpp ./coverage/stap.info WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) ADD_CUSTOM_COMMAND(TARGET lcov COMMAND echo "Open ${CMAKE_BINARY_DIR}/coverage/index.html to view the coverage analysis results." WORKING_DIRECTORY ${CMAKE_BINARY_DIR} ) qtorganizer5-eds-0.1.1+16.04.20160317/cmake/chewieplugin.cmake0000644000015600001650000000177712672562647024062 0ustar pbuserpbgroup00000000000000# -*- cmake -*- # Generates a rule to create chewie plugin # # Typical use - # # SET(SRC_FILES head1.h head2.h head3.h) # SET(LIBRARIES foolib barlib) # SET(QT_MODULES Core Qml) # SET(EXTRA_INCLUDE ${GLIB_INCLUDE_DIRS}) # CREATE_CHEWIE_PLUGIN(fooplugin LIBRARIES QT_MODULES EXTRA_INCLUDE SRC_FILES) macro(CREATE_CHEWIE_PLUGIN PLUGIN_NAME PLUGIN_LINK_LIBRARIES PLUGIN_QT_MODULES PLUGIN_EXTRA_INCLUDE PLUGIN_SOURCE) add_library(${PLUGIN_NAME} MODULE ${${PLUGIN_SOURCE}}) set_target_properties(${PLUGIN_NAME} PROPERTIES PREFIX "" LIBRARY_OUTPUT_DIRECTORY ${chewieplugins_BINARY_DIR}) target_link_libraries(${PLUGIN_NAME} ${${PLUGIN_LINK_LIBRARIES}}) qt5_use_modules(${PLUGIN_NAME} ${${PLUGIN_QT_MODULES}}) include_directories( ${libchewieui_SOURCE_DIR} ${${PLUGIN_EXTRA_INCLUDE}}) install(TARGETS ${PLUGIN_NAME} LIBRARY DESTINATION ${CHEWIE_PLUGINS_DIR}) endmacro() qtorganizer5-eds-0.1.1+16.04.20160317/tests/0000755000015600001650000000000012672563136020435 5ustar pbuserpbgroup00000000000000qtorganizer5-eds-0.1.1+16.04.20160317/tests/unittest/0000755000015600001650000000000012672563136022314 5ustar pbuserpbgroup00000000000000qtorganizer5-eds-0.1.1+16.04.20160317/tests/unittest/filter-test.cpp0000644000015600001650000001545712672562647025304 0ustar pbuserpbgroup00000000000000/* * Copyright 2015 Canonical Ltd. * * This file is part of qtorganizer5-eds. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include "qorganizer-eds-engine.h" #include "eds-base-test.h" using namespace QtOrganizer; class FilterTest : public QObject, public EDSBaseTest { Q_OBJECT private: QOrganizerEDSEngine *m_engine; void createCollection(QOrganizerCollection **collection) { QtOrganizer::QOrganizerManager::Error error; *collection = new QOrganizerCollection(); (*collection)->setMetaData(QOrganizerCollection::KeyName, uniqueCollectionName()); QSignalSpy createdCollection(m_engine, SIGNAL(collectionsAdded(QList))); bool saveResult = m_engine->saveCollection(*collection, &error); QVERIFY(saveResult); QCOMPARE(error, QtOrganizer::QOrganizerManager::NoError); QTRY_COMPARE(createdCollection.count(), 1); } private Q_SLOTS: void initTestCase() { EDSBaseTest::init(); m_engine = QOrganizerEDSEngine::createEDSEngine(QMap()); } void cleanupTestCase() { delete m_engine; EDSBaseTest::cleanup(); } // test functions void testFilterEventByCollectionId() { static QString displayLabelValue = QStringLiteral("Todo test %1 - %2"); static QString descriptionValue = QStringLiteral("Todo description %1 - %2"); QList items; QDateTime currentDate = QDateTime::currentDateTime(); // create items on default collection for(int i=0; i < 10; i++) { QOrganizerEvent ev; ev.setStartDateTime(currentDate); ev.setEndDateTime(currentDate.addDays(1)); ev.setDisplayLabel(displayLabelValue.arg(i).arg("default")); ev.setDescription(descriptionValue.arg(i).arg("default")); items << ev; } // create items on new collection QOrganizerCollection *collection; createCollection(&collection); for(int i=0; i < 10; i++) { QOrganizerEvent ev; ev.setCollectionId(collection->id()); ev.setStartDateTime(currentDate); ev.setEndDateTime(currentDate.addDays(1)); ev.setDisplayLabel(displayLabelValue.arg(i).arg("new")); ev.setDescription(descriptionValue.arg(i).arg("new")); items << ev; } // save all items QtOrganizer::QOrganizerManager::Error error; QMap errorMap; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QtOrganizer::QOrganizerManager::NoError); QOrganizerItemSortOrder sort; QOrganizerItemFetchHint hint; QOrganizerItemCollectionFilter filter; // filter items from default collection filter.setCollectionId(m_engine->defaultCollection(0).id()); items = m_engine->items(filter, QDateTime(), QDateTime(), 100, sort, hint, &error); QCOMPARE(items.count(), 10); // check returned items Q_FOREACH(const QOrganizerItem &i, items) { QVERIFY(static_cast(i).displayLabel().endsWith("default")); } // filter items from new collection filter.setCollectionId(collection->id()); items = m_engine->items(filter, QDateTime(), QDateTime(), 100, sort, hint, &error); QCOMPARE(items.count(), 10); // check returned items Q_FOREACH(const QOrganizerItem &i, items) { QVERIFY(static_cast(i).displayLabel().endsWith("new")); } // filter items from both collections QSet ids; ids << m_engine->defaultCollection(0).id() << collection->id(); filter.setCollectionIds(ids); items = m_engine->items(filter, QDateTime(), QDateTime(), 100, sort, hint, &error); QCOMPARE(items.count(), 20); // filter using union filter // filter events from new collection or ends with 'default' QOrganizerItemUnionFilter uFilter; filter.setCollectionId(collection->id()); QOrganizerItemDetailFieldFilter dFilter; dFilter.setDetail(QOrganizerItemDetail::TypeDescription, QOrganizerItemDescription::FieldDescription); dFilter.setMatchFlags(QOrganizerItemFilter::MatchEndsWith); dFilter.setValue("default"); uFilter.append(filter); uFilter.append(dFilter); items = m_engine->items(uFilter, QDateTime(), QDateTime(), 100, sort, hint, &error); QCOMPARE(items.count(), 20); // filter using intersection filter // filter events from new collection and ends with 'new' QOrganizerItemIntersectionFilter iFilter; dFilter.setValue("new"); iFilter.append(filter); iFilter.append(dFilter); items = m_engine->items(iFilter, QDateTime(), QDateTime(), 100, sort, hint, &error); QCOMPARE(items.count(), 10); // check returned items Q_FOREACH(const QOrganizerItem &i, items) { QVERIFY(static_cast(i).displayLabel().endsWith("new")); } delete collection; } }; QTEST_MAIN(FilterTest) #include "filter-test.moc" qtorganizer5-eds-0.1.1+16.04.20160317/tests/unittest/parseitem-test.cpp0000644000015600001650000000000012672562647025762 0ustar pbuserpbgroup00000000000000qtorganizer5-eds-0.1.1+16.04.20160317/tests/unittest/eds-base-test.h0000644000015600001650000000236212672562647025136 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __EDS_BASE_TEST__ #define __EDS_BASE_TEST__ #include #include #include class QOrganizerEDSEngine; class EDSBaseTest { public: EDSBaseTest(); ~EDSBaseTest(); protected: virtual void initTestCase(); virtual void init(); virtual void cleanup(); QString getEventFromEvolution(const QtOrganizer::QOrganizerItemId &id, const QtOrganizer::QOrganizerCollectionId &collectionId = QtOrganizer::QOrganizerCollectionId()); QString uniqueCollectionName() const; }; #endif qtorganizer5-eds-0.1.1+16.04.20160317/tests/unittest/collections-test.cpp0000644000015600001650000003657312672562647026337 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of qtorganizer5-eds. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include "qorganizer-eds-engine.h" #include "qorganizer-eds-source-registry.h" #include "eds-base-test.h" using namespace QtOrganizer; class CollectionTest : public QObject, public EDSBaseTest { Q_OBJECT private: static const QString collectionTypePropertyName; static const QString taskListTypeName; QOrganizerEDSEngine *m_engineWrite; QOrganizerEDSEngine *m_engineRead; bool containsCollection(const QList &lst, const QOrganizerCollection &collection ) { bool found = false; Q_FOREACH(const QOrganizerCollection &col, lst) { if (col.id() == collection.id()) { found = true; } } return found; } private Q_SLOTS: void initTestCase() { EDSBaseTest::init(); m_engineWrite = QOrganizerEDSEngine::createEDSEngine(QMap()); m_engineRead = QOrganizerEDSEngine::createEDSEngine(QMap()); } void cleanupTestCase() { delete m_engineRead; delete m_engineWrite; m_engineRead = 0; m_engineWrite = 0; EDSBaseTest::cleanup(); } void testCreateTask() { static const QString collectionName = uniqueCollectionName(); static QString displayLabelValue = QStringLiteral("Todo test"); static QString descriptionValue = QStringLiteral("Todo description"); QOrganizerCollection collection; QtOrganizer::QOrganizerManager::Error error; collection.setMetaData(QOrganizerCollection::KeyName, collectionName); collection.setExtendedMetaData(collectionTypePropertyName, taskListTypeName); QSignalSpy createCollection(m_engineRead, SIGNAL(collectionsAdded(QList))); QVERIFY(m_engineWrite->saveCollection(&collection, &error)); QVERIFY(!collection.id().isNull()); QTRY_COMPARE(createCollection.count(), 1); QOrganizerTodo todo; todo.setCollectionId(collection.id()); todo.setStartDateTime(QDateTime::currentDateTime()); todo.setDisplayLabel(displayLabelValue); todo.setDescription(descriptionValue); QMap errorMap; QList items; QSignalSpy createdItem(m_engineRead, SIGNAL(itemsAdded(QList))); items << todo; bool saveResult = m_engineWrite->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QOrganizerManager::NoError); QVERIFY(errorMap.isEmpty()); QVERIFY(!items[0].id().isNull()); //verify signal QTRY_COMPARE(createdItem.count(), 1); QCOMPARE(createdItem.takeFirst().count(), 1); // check if the item is listead inside the correct collection QOrganizerItemSortOrder sort; QOrganizerItemFetchHint hint; QOrganizerItemCollectionFilter filter; filter.setCollectionId(collection.id()); items = m_engineRead->items(filter, QDateTime(), QDateTime(), 10, sort, hint, &error); QCOMPARE(items.count(), 1); QOrganizerTodo result = static_cast(items[0]); todo = items[0]; QCOMPARE(result.id(), todo.id()); QCOMPARE(result.startDateTime(), todo.startDateTime()); QCOMPARE(result.displayLabel(), todo.displayLabel()); QCOMPARE(result.description(), todo.description()); // check if the item is listead by id QList ids; ids << todo.id(); items = m_engineRead->items(ids, hint, &errorMap, &error); QCOMPARE(items.count(), 1); result = static_cast(items[0]); todo = items[0]; QCOMPARE(result.id(), todo.id()); QCOMPARE(result.startDateTime(), todo.startDateTime()); QCOMPARE(result.displayLabel(), todo.displayLabel()); QCOMPARE(result.description(), todo.description()); } void testCreateCollection() { static const QString collectionName = uniqueCollectionName(); QOrganizerCollection collection; QtOrganizer::QOrganizerManager::Error error; collection.setMetaData(QOrganizerCollection::KeyName, collectionName); collection.setMetaData(QOrganizerCollection::KeyColor, QStringLiteral("red")); QList collections = m_engineRead->collections(&error); int initalCollectionCount = collections.count(); QSignalSpy createCollection(m_engineRead, SIGNAL(collectionsAdded(QList))); QVERIFY(m_engineWrite->saveCollection(&collection, &error)); QCOMPARE(error, QOrganizerManager::NoError); QVERIFY(!collection.id().isNull()); QTRY_COMPARE(createCollection.count(), 1); collections = m_engineWrite->collections(&error); QCOMPARE(collections.count(), initalCollectionCount + 1); collections = m_engineRead->collections(&error); QCOMPARE(collections.count(), initalCollectionCount + 1); // Check if data was correct saved QOrganizerCollection newCollection = m_engineRead->collection(collection.id(), &error); QCOMPARE(error, QOrganizerManager::NoError); QCOMPARE(newCollection.metaData(QOrganizerCollection::KeyName).toString(), collectionName); QCOMPARE(newCollection.metaData(QOrganizerCollection::KeyColor).toString(), QStringLiteral("red")); QCOMPARE(newCollection.extendedMetaData("collection-type").toString(), QStringLiteral("Calendar")); QCOMPARE(newCollection.extendedMetaData("collection-selected").toBool(), false); } void testUpdateCollection() { static const QString collectionName = uniqueCollectionName(); QOrganizerCollection collection; QtOrganizer::QOrganizerManager::Error error; collection.setMetaData(QOrganizerCollection::KeyName, collectionName); collection.setMetaData(QOrganizerCollection::KeyColor, QStringLiteral("red")); collection.setExtendedMetaData(QStringLiteral("collection-selected"), false); QSignalSpy collectionCreated(m_engineRead, SIGNAL(collectionsAdded(QList))); QVERIFY(m_engineWrite->saveCollection(&collection, &error)); QCOMPARE(error, QOrganizerManager::NoError); QVERIFY(!collection.id().isNull()); QTRY_COMPARE(collectionCreated.count(), 1); // wait for the collection to became writable QTRY_COMPARE_WITH_TIMEOUT(collection.extendedMetaData(QStringLiteral(COLLECTION_READONLY_METADATA)).toBool(), true, 10000); // Check if the collection was stored correct QOrganizerCollection newCollection = m_engineRead->collection(collection.id(), &error); QCOMPARE(newCollection.metaData(QOrganizerCollection::KeyName).toString(), collectionName); QCOMPARE(newCollection.metaData(QOrganizerCollection::KeyColor).toString(), QStringLiteral("red")); QCOMPARE(newCollection.extendedMetaData(QStringLiteral("collection-selected")).toBool(), false); // wait collection to became writable QTRY_VERIFY_WITH_TIMEOUT(!m_engineRead->collection(newCollection.id(), 0).extendedMetaData("collection-readonly").toBool(), 5000); // update the collection QSignalSpy updateCollection(m_engineRead, SIGNAL(collectionsChanged(QList))); collection.setMetaData(QOrganizerCollection::KeyColor, "blue"); collection.setExtendedMetaData("collection-selected", true); QVERIFY(m_engineWrite->saveCollection(&collection, &error)); QCOMPARE(error, QOrganizerManager::NoError); QTRY_VERIFY(updateCollection.count() > 0); QList args = updateCollection.takeFirst(); QCOMPARE(args.count(), 1); QCOMPARE(args[0].value >().at(0).toString(), collection.id().toString()); // Check if the collection was updated correct newCollection = m_engineRead->collection(collection.id(), &error); QCOMPARE(error, QOrganizerManager::NoError); QCOMPARE(newCollection.metaData(QOrganizerCollection::KeyName).toString(), collectionName); QCOMPARE(newCollection.metaData(QOrganizerCollection::KeyColor).toString(), QStringLiteral("blue")); QCOMPARE(newCollection.extendedMetaData("collection-selected").toBool(), true); } void testCreateTaskList() { static const QString collectionName = uniqueCollectionName() + QStringLiteral("_TASKS") ; QOrganizerCollection collection; QtOrganizer::QOrganizerManager::Error error; collection.setMetaData(QOrganizerCollection::KeyName, collectionName); collection.setExtendedMetaData(collectionTypePropertyName, taskListTypeName); QSignalSpy createdCollection(m_engineRead, SIGNAL(collectionsAdded(QList))); QVERIFY(m_engineWrite->saveCollection(&collection, &error)); QCOMPARE(error, QOrganizerManager::NoError); QVERIFY(!collection.id().isNull()); //verify signal QTRY_COMPARE(createdCollection.count(), 1); QList args = createdCollection.takeFirst(); QCOMPARE(args.count(), 1); QVERIFY(containsCollection(m_engineWrite->collections(&error), collection)); QVERIFY(containsCollection(m_engineRead->collections(&error), collection)); } void testRemoveCollection() { static QString removableCollectionName = uniqueCollectionName(); // Create a collection QOrganizerCollection collection; QtOrganizer::QOrganizerManager::Error error; collection.setMetaData(QOrganizerCollection::KeyName, removableCollectionName); QList collections = m_engineRead->collections(&error); int initalCollectionCount = collections.count(); QSignalSpy createCollection(m_engineRead, SIGNAL(collectionsAdded(QList))); QVERIFY(m_engineWrite->saveCollection(&collection, &error)); QTRY_COMPARE(createCollection.count(), 1); // wait collection to became writable QTRY_VERIFY_WITH_TIMEOUT(!m_engineRead->collection(collection.id(), 0).extendedMetaData("collection-readonly").toBool(), 5000); // remove recent created collection QSignalSpy removeCollection(m_engineRead, SIGNAL(collectionsRemoved(QList))); QVERIFY(m_engineWrite->removeCollection(collection.id(), &error)); QTRY_COMPARE(removeCollection.count(), 1); collections = m_engineWrite->collections(&error); QCOMPARE(collections.count(), initalCollectionCount); QVERIFY(!containsCollection(collections, collection)); collections = m_engineRead->collections(&error); QCOMPARE(collections.count(), initalCollectionCount); QVERIFY(!containsCollection(collections, collection)); } void testReadOnlyCollection() { // check if the anniversaries collection is read-only static const QString anniversariesCollectionName = QStringLiteral("Birthdays & Anniversaries"); QtOrganizer::QOrganizerManager::Error error; QList collections = m_engineRead->collections(&error); Q_FOREACH(const QOrganizerCollection &col, collections) { if (col.metaData(QOrganizerCollection::KeyName) == anniversariesCollectionName) { QVERIFY(col.extendedMetaData("collection-readonly").toBool()); } } } void testCreateNewDefaultCollection() { static QString newCollection = uniqueCollectionName(); // Create a new default collection QOrganizerCollection collection; QtOrganizer::QOrganizerManager::Error error; collection.setMetaData(QOrganizerCollection::KeyName, newCollection); collection.setMetaData(QOrganizerCollection::KeyColor, QStringLiteral("red")); collection.setExtendedMetaData(QStringLiteral("collection-selected"), true); collection.setExtendedMetaData(QStringLiteral("collection-default"), true); QSignalSpy createdCollection(m_engineRead, SIGNAL(collectionsAdded(QList))); QVERIFY(m_engineWrite->saveCollection(&collection, &error)); // create collection QTRY_COMPARE(createdCollection.count(), 1); // wait collection to became the default one QTRY_COMPARE_WITH_TIMEOUT(m_engineRead->defaultCollection(0).id(), collection.id(), 5000); } void testUpdateDefaultCollection() { static QString newCollectionId = uniqueCollectionName(); // store current default collection QOrganizerCollection defaultCollection = m_engineRead->defaultCollection(0); // Create a collection QOrganizerCollection collection; QtOrganizer::QOrganizerManager::Error error; collection.setMetaData(QOrganizerCollection::KeyName, newCollectionId); QSignalSpy createCollection(m_engineRead, SIGNAL(collectionsAdded(QList))); QVERIFY(m_engineWrite->saveCollection(&collection, &error)); QTRY_COMPARE(createCollection.count(), 1); // wait collection to became writable QTRY_VERIFY_WITH_TIMEOUT(!m_engineRead->collection(collection.id(), 0).extendedMetaData("collection-readonly").toBool(), 5000); // make sure that the new collection is not default QOrganizerCollection newCollection = m_engineRead->collection(collection.id(), 0); QCOMPARE(newCollection.extendedMetaData(QStringLiteral("collection-default")).toBool(), false); QVERIFY(newCollection.id() != defaultCollection.id()); // mark new collection as default QSignalSpy changedCollection(m_engineRead, SIGNAL(collectionsChanged(QList))); newCollection.setExtendedMetaData(QStringLiteral("collection-default"), true); QVERIFY(m_engineWrite->saveCollection(&newCollection, &error)); // old default collection will change, and the new one QTRY_COMPARE(changedCollection.count() , 3); // wait collection to became the default one QTRY_COMPARE_WITH_TIMEOUT(m_engineRead->defaultCollection(0).id(), newCollection.id(), 5000); } }; const QString CollectionTest::collectionTypePropertyName = QStringLiteral("collection-type"); const QString CollectionTest::taskListTypeName = QStringLiteral("Task List"); QTEST_MAIN(CollectionTest) #include "collections-test.moc" qtorganizer5-eds-0.1.1+16.04.20160317/tests/unittest/eds-base-test.cpp0000644000015600001650000000663412672562647025477 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "config.h" #include "eds-base-test.h" #include "qorganizer-eds-engine.h" #include #include #include using namespace QtOrganizer; class GScopedPointerUnref { public: static inline void cleanup(void *pointer) { if (pointer) { g_clear_object(&pointer); } } }; template class GScopedPointer : public QScopedPointer { public: GScopedPointer(KLASS* obj = 0) : QScopedPointer(obj) {} }; EDSBaseTest::EDSBaseTest() { qRegisterMetaType >(); qRegisterMetaType >(); qRegisterMetaType >(); QCoreApplication::addLibraryPath(QORGANIZER_DEV_PATH); } EDSBaseTest::~EDSBaseTest() { } void EDSBaseTest::initTestCase() { QTest::qWait(1000); } void EDSBaseTest::init() { } void EDSBaseTest::cleanup() { QTest::qWait(1000); } QString EDSBaseTest::getEventFromEvolution(const QOrganizerItemId &id, const QOrganizerCollectionId &collectionId) { QString uid = id.toString().split("/").last(); GError *error = 0; GScopedPointer sourceRegistry(e_source_registry_new_sync(0, &error)); if (error) { qWarning() << "Fail to create source registry" << error->message; g_error_free(error); return QString(); } GScopedPointer calendar; if (collectionId.isNull()) { calendar.reset(e_source_registry_ref_default_calendar(sourceRegistry.data())); } else { calendar.reset(e_source_registry_ref_source(sourceRegistry.data(), collectionId.toString().toUtf8().data())); } GScopedPointer client(E_CAL_CLIENT_CONNECT_SYNC(calendar.data(), E_CAL_CLIENT_SOURCE_TYPE_EVENTS, 0, &error)); if (error) { qWarning() << "Fail to connect to calendar" << error->message; g_error_free(error); return QString(); } icalcomponent *obj = 0; e_cal_client_get_object_sync(reinterpret_cast(client.data()), uid.toUtf8().data(), 0, &obj, 0, &error); if (error) { qWarning() << "Fail to retrieve object:" << error->message; g_error_free(error); } QString result = QString::fromUtf8(icalcomponent_as_ical_string(obj)); icalcomponent_free (obj); return result; } QString EDSBaseTest::uniqueCollectionName() const { return QUuid::createUuid().toString(); } qtorganizer5-eds-0.1.1+16.04.20160317/tests/unittest/fetchitem-test.cpp0000644000015600001650000001341512672562647025757 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of qtorganizer5-eds. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include "qorganizer-eds-engine.h" #include "qorganizer-eds-requestdata.h" #include "eds-base-test.h" using namespace QtOrganizer; class FetchItemTest : public QObject, public EDSBaseTest { Q_OBJECT private: QOrganizerEDSEngine *m_engine; QOrganizerCollection m_collection; QList m_events; private Q_SLOTS: void initTestCase() { EDSBaseTest::initTestCase(); const QString collectionName = uniqueCollectionName(); EDSBaseTest::init(); m_engine = QOrganizerEDSEngine::createEDSEngine(QMap()); // create test collection m_collection = QOrganizerCollection(); QtOrganizer::QOrganizerManager::Error error; m_collection.setMetaData(QOrganizerCollection::KeyName, collectionName); QVERIFY(m_engine->saveCollection(&m_collection, &error)); // create test events static QString displayLabelValue = QStringLiteral("Display Label %1"); static QString descriptionValue = QStringLiteral("Description event %1"); // use this becaue EDS does not store msecs QTime currentTime = QTime::currentTime(); QDateTime date = QDateTime(QDateTime::currentDateTime().date(), QTime(currentTime.hour(), currentTime.minute(), currentTime.second())); m_events.clear(); for(int i=0; i<10; i++) { QOrganizerEvent ev; ev.setCollectionId(m_collection.id()); ev.setStartDateTime(date); ev.setEndDateTime(date.addSecs(60*30)); ev.setDisplayLabel(displayLabelValue.arg(i)); ev.setDescription(descriptionValue.arg(i)); QList evs; evs << ev; QMap errorMap; bool saveResult = m_engine->saveItems(&evs, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QOrganizerManager::NoError); QVERIFY(errorMap.isEmpty()); m_events << evs[0]; date = date.addDays(1); } } void cleanupTestCase() { m_collection = QOrganizerCollection(); m_events.clear(); delete m_engine; m_engine = 0; EDSBaseTest::cleanup(); } void cleanup() { QTRY_COMPARE(RequestData::instanceCount(), 0); } void testFetchById() { QList request; request << m_events[4].id(); QOrganizerItemFetchByIdRequest req; req.setIds(request); m_engine->startRequest(&req); m_engine->waitForRequestFinished(&req, 0); QList expected; expected << m_events[4]; QCOMPARE(expected.size(), req.items().size()); QList dr = req.items()[0].details(); Q_FOREACH(const QOrganizerItemDetail &de, m_events[4].details()) { Q_FOREACH(const QOrganizerItemDetail &d, dr) { if (de.type() == d.type()) { if (de != d) { qDebug() << "Detail not equal"; qDebug() << "\t" << de; qDebug() << "\t" << d; QFAIL("Retrieved item is not equal"); } } } } } void testFetchWithInvalidId() { // malformated id QList request; request << QOrganizerItemId::fromString("qorganizer:eds::invalidcollection/invalidcontact"); QOrganizerItemFetchByIdRequest req; req.setIds(request); m_engine->startRequest(&req); m_engine->waitForRequestFinished(&req, 0); QCOMPARE(req.items().size(), 0); QMap errors = req.errorMap(); QCOMPARE(errors.size(), 1); QCOMPARE(errors[0], QOrganizerManager::DoesNotExistError); // id does not exists request.clear(); request << QOrganizerItemId::fromString("qtorganizer:eds::1386099272.14397.0@organizer/20131203T193432Z-14397-1000-14367-9@organizer"); QOrganizerItemFetchByIdRequest reqNotFound; reqNotFound.setIds(request); m_engine->startRequest(&reqNotFound); m_engine->waitForRequestFinished(&reqNotFound, 0); QCOMPARE(reqNotFound.items().size(), 0); errors = reqNotFound.errorMap(); QCOMPARE(errors.size(), 1); QCOMPARE(errors[0], QOrganizerManager::DoesNotExistError); } void testFetchWithoutDate() { QOrganizerItemFilter filter; QOrganizerItemFetchHint hint; QOrganizerManager::Error error; QList sort; QList result = m_engine->items(filter, QDateTime(), QDateTime(), 100, sort, hint, &error); QCOMPARE(result.size(), 10); } }; QTEST_MAIN(FetchItemTest) #include "fetchitem-test.moc" qtorganizer5-eds-0.1.1+16.04.20160317/tests/unittest/event-test.cpp0000644000015600001650000015164712672562647025142 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of qtorganizer5-eds. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include "qorganizer-eds-engine.h" #include "eds-base-test.h" using namespace QtOrganizer; class EventTest : public QObject, public EDSBaseTest { Q_OBJECT private: static const QString collectionTypePropertyName; static const QString taskListTypeName; static int signalIndex; QDateTime m_itemRemovedTime; QDateTime m_requestFinishedTime; QOrganizerEDSEngine *m_engine; QOrganizerCollection m_collection; private Q_SLOTS: void initTestCase() { EDSBaseTest::init(); m_engine = QOrganizerEDSEngine::createEDSEngine(QMap()); QtOrganizer::QOrganizerManager::Error error; m_collection = QOrganizerCollection(); m_collection.setMetaData(QOrganizerCollection::KeyName, uniqueCollectionName()); m_collection.setExtendedMetaData(collectionTypePropertyName, taskListTypeName); QSignalSpy createdCollection(m_engine, SIGNAL(collectionsAdded(QList))); bool saveResult = m_engine->saveCollection(&m_collection, &error); QVERIFY(saveResult); QCOMPARE(error, QtOrganizer::QOrganizerManager::NoError); QTRY_COMPARE(createdCollection.count(), 1); } void cleanupTestCase() { delete m_engine; EDSBaseTest::cleanup(); } void init() { signalIndex = 0; m_itemRemovedTime = QDateTime(); m_requestFinishedTime = QDateTime(); } //helper void itemRemoved() { m_itemRemovedTime = QDateTime::currentDateTime(); // avoid both signals to be fired at the same time QTest::qSleep(100); } void requestFinished(QOrganizerAbstractRequest::State state) { if (state == QOrganizerAbstractRequest::FinishedState) { m_requestFinishedTime = QDateTime::currentDateTime(); // avoid both signals to be fired at the same time QTest::qSleep(100); } } // test functions void testCreateEventWithReminder() { static QString displayLabelValue = QStringLiteral("Todo test"); static QString descriptionValue = QStringLiteral("Todo description"); QOrganizerTodo todo; todo.setCollectionId(m_collection.id()); todo.setStartDateTime(QDateTime::currentDateTime()); todo.setDisplayLabel(displayLabelValue); todo.setDescription(descriptionValue); QOrganizerItemVisualReminder vReminder; vReminder.setDataUrl(QUrl("http://www.alarms.com")); vReminder.setMessage("Test visual reminder"); QOrganizerItemAudibleReminder aReminder; aReminder.setSecondsBeforeStart(10); aReminder.setRepetition(10, 20); aReminder.setDataUrl(QUrl("file://home/user/My Musics/play as alarm.wav")); todo.saveDetail(&aReminder); todo.saveDetail(&vReminder); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; items << todo; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QtOrganizer::QOrganizerManager::NoError); QOrganizerItemSortOrder sort; QOrganizerItemFetchHint hint; QOrganizerItemIdFilter filter; QList ids; ids << items[0].id(); filter.setIds(ids); items = m_engine->items(filter, QDateTime(), QDateTime(), 10, sort, hint, &error); QCOMPARE(items.count(), 1); // audible QList reminders = items[0].details(QOrganizerItemDetail::TypeAudibleReminder); QCOMPARE(reminders.size(), 1); QOrganizerItemAudibleReminder aReminder2 = reminders[0]; QCOMPARE(aReminder2.secondsBeforeStart(), aReminder.secondsBeforeStart()); QCOMPARE(aReminder2.repetitionCount(), aReminder.repetitionCount()); QCOMPARE(aReminder2.repetitionDelay(), aReminder.repetitionDelay()); QCOMPARE(aReminder2.dataUrl(), aReminder.dataUrl()); //QCOMPARE(aReminder2, aReminder); // visual reminders = items[0].details(QOrganizerItemDetail::TypeVisualReminder); QCOMPARE(reminders.size(), 1); QOrganizerItemVisualReminder vReminder2 = reminders[0]; //vReminder.setRepetition(1, 0); QCOMPARE(vReminder2.secondsBeforeStart(), vReminder.secondsBeforeStart()); QCOMPARE(vReminder2.repetitionCount(), vReminder.repetitionCount()); QCOMPARE(vReminder2.repetitionDelay(), vReminder.repetitionDelay()); QCOMPARE(vReminder2.dataUrl(), vReminder.dataUrl()); QCOMPARE(vReminder2.message(), vReminder.message()); } void testCreateEventWithEmptyReminder() { static QString displayLabelValue = QStringLiteral("Todo test with empty reminder"); static QString descriptionValue = QStringLiteral("Todo description with empty reminder"); QOrganizerTodo todo; todo.setCollectionId(m_collection.id()); todo.setStartDateTime(QDateTime::currentDateTime()); todo.setDisplayLabel(displayLabelValue); todo.setDescription(descriptionValue); QOrganizerItemVisualReminder vReminder; vReminder.setDataUrl(QUrl("")); vReminder.setMessage("reminder message"); QOrganizerItemAudibleReminder aReminder; aReminder.setSecondsBeforeStart(0); aReminder.setDataUrl(QString()); todo.saveDetail(&aReminder); todo.saveDetail(&vReminder); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; items << todo; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QtOrganizer::QOrganizerManager::NoError); QOrganizerItemSortOrder sort; QOrganizerItemFetchHint hint; QOrganizerItemIdFilter filter; QList ids; ids << items[0].id(); filter.setIds(ids); items = m_engine->items(filter, QDateTime(), QDateTime(), 10, sort, hint, &error); QCOMPARE(items.count(), 1); // audible QList reminders = items[0].details(QOrganizerItemDetail::TypeAudibleReminder); QCOMPARE(reminders.size(), 1); QOrganizerItemAudibleReminder aReminder2 = reminders[0]; QCOMPARE(aReminder2.isEmpty(), false); QCOMPARE(aReminder2.secondsBeforeStart(), 0); QCOMPARE(aReminder2.repetitionCount(), 0); QCOMPARE(aReminder2.repetitionDelay(), 0); QVERIFY(aReminder2.dataUrl().isEmpty()); // visual reminders = items[0].details(QOrganizerItemDetail::TypeVisualReminder); QCOMPARE(reminders.size(), 1); QOrganizerItemVisualReminder vReminder2 = reminders[0]; //vReminder.setRepetition(1, 0); QCOMPARE(vReminder2.isEmpty(), false); QCOMPARE(vReminder2.secondsBeforeStart(), vReminder.secondsBeforeStart()); QCOMPARE(vReminder2.repetitionCount(), vReminder.repetitionCount()); QCOMPARE(vReminder2.repetitionDelay(), vReminder.repetitionDelay()); QVERIFY(vReminder2.dataUrl().isEmpty()); QCOMPARE(vReminder2.message(), QString("reminder message")); } void testRemoveEvent() { static QString displayLabelValue = QStringLiteral("event to be removed"); static QString descriptionValue = QStringLiteral("removable event"); QOrganizerTodo todo; todo.setCollectionId(m_collection.id()); todo.setStartDateTime(QDateTime::currentDateTime()); todo.setDisplayLabel(displayLabelValue); todo.setDescription(descriptionValue); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; items << todo; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QOrganizerManager::NoError); QCOMPARE(items.size(), 1); QVERIFY(errorMap.isEmpty()); QVERIFY(!items[0].id().isNull()); QOrganizerItemRemoveRequest req; connect(&req, SIGNAL(stateChanged(QOrganizerAbstractRequest::State)), this, SLOT(requestFinished(QOrganizerAbstractRequest::State))); connect(m_engine, SIGNAL(itemsRemoved(QList)), this, SLOT(itemRemoved())); req.setItem(items[0]); m_engine->startRequest(&req); m_engine->waitForRequestFinished(&req, -1); // check if the signal item removed was fired after the request finish QTRY_VERIFY(m_requestFinishedTime.isValid()); QTRY_VERIFY(m_itemRemovedTime.isValid()); if (m_itemRemovedTime < m_requestFinishedTime) { qDebug() << "Item removed before request finish"; qDebug() << "Removed time" << m_itemRemovedTime; qDebug() << "RequestFinished time" << m_requestFinishedTime; } QVERIFY(m_itemRemovedTime >= m_requestFinishedTime); } void testRemoveItemById() { static QString displayLabelValue = QStringLiteral("event to be removed"); static QString descriptionValue = QStringLiteral("removable event"); QOrganizerTodo todo; todo.setCollectionId(m_collection.id()); todo.setStartDateTime(QDateTime::currentDateTime()); todo.setDisplayLabel(displayLabelValue); todo.setDescription(descriptionValue); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; items << todo; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QOrganizerManager::NoError); QVERIFY(errorMap.isEmpty()); QOrganizerItemId id = items[0].id(); QVERIFY(!id.isNull()); QOrganizerItemRemoveByIdRequest req; connect(&req, SIGNAL(stateChanged(QOrganizerAbstractRequest::State)), this, SLOT(requestFinished(QOrganizerAbstractRequest::State))); connect(m_engine, SIGNAL(itemsRemoved(QList)), this, SLOT(itemRemoved())); req.setItemId(id); m_engine->startRequest(&req); m_engine->waitForRequestFinished(&req, -1); // check if the signal item removed was fired after the request finish QTRY_VERIFY(m_requestFinishedTime.isValid()); QTRY_VERIFY(m_itemRemovedTime.isValid()); QVERIFY(m_itemRemovedTime > m_requestFinishedTime); // check if item was removed QOrganizerItemSortOrder sort; QOrganizerItemFetchHint hint; QOrganizerItemIdFilter filter; QList ids; ids << id; filter.setIds(ids); items = m_engine->items(filter, QDateTime(), QDateTime(), 10, sort, hint, &error); QCOMPARE(items.count(), 0); } void testCreateEventWithoutCollection() { static QString displayLabelValue = QStringLiteral("event without collection"); static QString descriptionValue = QStringLiteral("event without collection"); QOrganizerEvent event; event.setStartDateTime(QDateTime::currentDateTime()); event.setDisplayLabel(displayLabelValue); event.setDescription(descriptionValue); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; items << event; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QOrganizerManager::NoError); QVERIFY(errorMap.isEmpty()); QVERIFY(!items[0].id().isNull()); // check if item was created on the default collection QOrganizerItemFetchHint hint; QList ids; ids << items[0].id(); items = m_engine->items(ids, hint, 0, 0); QCOMPARE(items.count(), 1); QOrganizerCollection collection = m_engine->defaultCollection(0); QCOMPARE(items[0].collectionId(), collection.id()); } void testCreateMultipleItemsWithSameCollection() { static QString displayLabelValue = QStringLiteral("Multiple Item:%1"); static QString descriptionValue = QStringLiteral("Multiple Item desc:%1"); QList evs; for(int i=0; i<10; i++) { QOrganizerTodo todo; todo.setCollectionId(m_collection.id()); todo.setStartDateTime(QDateTime::currentDateTime()); todo.setDisplayLabel(displayLabelValue.arg(i)); todo.setDescription(descriptionValue.arg(i)); evs << todo; } QtOrganizer::QOrganizerManager::Error error; QMap errorMap; bool saveResult = m_engine->saveItems(&evs, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QOrganizerManager::NoError); QVERIFY(errorMap.isEmpty()); QCOMPARE(evs.count(), 10); Q_FOREACH(const QOrganizerItem &i, evs) { QVERIFY(!i.id().isNull()); } } void testCreateMultipleItemsWithDiffCollections() { static QString displayLabelValue = QStringLiteral("Multiple Item:%1"); static QString descriptionValue = QStringLiteral("Multiple Item desc:%1"); QList evs; for(int i=0; i<10; i++) { QOrganizerTodo todo; todo.setCollectionId(m_collection.id()); todo.setStartDateTime(QDateTime(QDate(2013, 9, 3+1), QTime(0,30,0))); todo.setDisplayLabel(displayLabelValue.arg(i)); todo.setDescription(descriptionValue.arg(i)); evs << todo; } QtOrganizer::QOrganizerManager::Error error; QOrganizerCollection eventCollection = QOrganizerCollection(); eventCollection.setMetaData(QOrganizerCollection::KeyName, uniqueCollectionName()); bool saveResult = m_engine->saveCollection(&eventCollection, &error); QVERIFY(saveResult); for(int i=0; i<10; i++) { QOrganizerEvent ev; ev.setCollectionId(eventCollection.id()); ev.setStartDateTime(QDateTime(QDate(2013, 10, 3+1), QTime(0,30,0))); ev.setDisplayLabel(displayLabelValue.arg(i)); ev.setDescription(descriptionValue.arg(i)); evs << ev; } QMap errorMap; saveResult = m_engine->saveItems(&evs, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QOrganizerManager::NoError); QVERIFY(errorMap.isEmpty()); QCOMPARE(evs.count(), 20); Q_FOREACH(const QOrganizerItem &i, evs) { QVERIFY(!i.id().isNull()); } } void testCauseErrorDuringCreateMultipleItems() { static QString displayLabelValue = QStringLiteral("Multiple Item:%1"); static QString descriptionValue = QStringLiteral("Multiple Item desc:%1"); QList evs; QOrganizerTodo todo; todo.setCollectionId(m_collection.id()); todo.setStartDateTime(QDateTime(QDate(2013, 9, 1), QTime(0,30,0))); todo.setDisplayLabel(displayLabelValue.arg(1)); todo.setDescription(descriptionValue.arg(1)); evs << todo; // This item will cause error, because the collection ID is invalid QOrganizerEvent ev; QOrganizerEDSCollectionEngineId *edsCollectionId = new QOrganizerEDSCollectionEngineId("XXXXXX"); QOrganizerCollectionId cid(edsCollectionId); QVERIFY(!cid.isNull()); QCOMPARE(cid.toString(), QStringLiteral("qtorganizer:eds::XXXXXX")); ev.setCollectionId(cid); ev.setStartDateTime(QDateTime(QDate(2013, 10, 2), QTime(0,30,0))); ev.setDisplayLabel(displayLabelValue.arg(2)); ev.setDescription(descriptionValue.arg(2)); evs << ev; todo.setStartDateTime(QDateTime(QDate(2013, 9, 3), QTime(0,30,0))); todo.setDisplayLabel(displayLabelValue.arg(3)); todo.setDescription(descriptionValue.arg(3)); evs << todo; QtOrganizer::QOrganizerManager::Error error; QMap errorMap; bool saveResult = m_engine->saveItems(&evs, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QOrganizerManager::NoError); QCOMPARE(evs.count(), 2); QCOMPARE(errorMap.size(), 1); QCOMPARE(errorMap[1], QOrganizerManager::InvalidCollectionError); } void testCreateAllDayTodo() { static QString displayLabelValue = QStringLiteral("All day title"); static QString descriptionValue = QStringLiteral("All day description"); QDateTime eventDateTime = QDateTime(QDate(2013, 9, 3), QTime(0,30,0)); QOrganizerTodo todo; todo.setCollectionId(m_collection.id()); todo.setAllDay(true); todo.setStartDateTime(eventDateTime); todo.setDisplayLabel(displayLabelValue); todo.setDescription(descriptionValue); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; items << todo; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QOrganizerManager::NoError); QVERIFY(errorMap.isEmpty()); QOrganizerItemId id = items[0].id(); QVERIFY(!id.isNull()); QOrganizerItemFetchHint hint; QList ids; ids << items[0].id(); items = m_engine->items(ids, hint, &errorMap, &error); QCOMPARE(items.count(), 1); QOrganizerTodo todoResult = static_cast(items[0]); QCOMPARE(todoResult.isAllDay(), true); QCOMPARE(todoResult.startDateTime().date(), eventDateTime.date()); QCOMPARE(todoResult.startDateTime().time(), QTime(0, 0, 0)); } void testCreateAllDayEvent() { static QString displayLabelValue = QStringLiteral("All day title"); static QString descriptionValue = QStringLiteral("All day description"); QDateTime eventDateTime = QDateTime(QDate(2013, 9, 3), QTime(0,30,0)); QOrganizerEvent event; event.setStartDateTime(eventDateTime); event.setEndDateTime(eventDateTime.addDays(1)); event.setDisplayLabel(displayLabelValue); event.setDescription(descriptionValue); event.setAllDay(true); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; items << event; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QOrganizerManager::NoError); QVERIFY(errorMap.isEmpty()); QOrganizerItemId id = items[0].id(); QVERIFY(!id.isNull()); QOrganizerItemFetchHint hint; QList ids; ids << items[0].id(); items = m_engine->items(ids, hint, &errorMap, &error); QCOMPARE(items.count(), 1); QOrganizerEvent eventResult = static_cast(items[0]); QCOMPARE(eventResult.isAllDay(), true); QCOMPARE(eventResult.startDateTime().date(), eventDateTime.date()); QCOMPARE(eventResult.startDateTime().time(), QTime(0, 0, 0)); QCOMPARE(eventResult.endDateTime().date(), eventDateTime.date().addDays(1)); QCOMPARE(eventResult.endDateTime().time(), QTime(0, 0, 0)); } void testModifyAllDayEvent() { static QString displayLabelValue = QStringLiteral("All day title"); static QString descriptionValue = QStringLiteral("All day description"); QDateTime eventDateTime = QDateTime(QDate(2013, 9, 3), QTime(0,30,0)); QOrganizerEvent event; event.setStartDateTime(eventDateTime); event.setEndDateTime(eventDateTime.addDays(1)); event.setDisplayLabel(displayLabelValue); event.setDescription(descriptionValue); event.setAllDay(true); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; items << event; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QOrganizerEvent eventResult = static_cast(items[0]); eventResult.setDescription(QStringLiteral("New description")); items.clear(); items << eventResult; saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QOrganizerItemFetchHint hint; QList ids; ids << items[0].id(); items = m_engine->items(ids, hint, &errorMap, &error); QCOMPARE(items.count(), 1); eventResult = static_cast(items[0]); QCOMPARE(eventResult.description(), QStringLiteral("New description")); QCOMPARE(eventResult.isAllDay(), true); QCOMPARE(eventResult.startDateTime().date(), eventDateTime.date()); QCOMPARE(eventResult.startDateTime().time(), QTime(0, 0, 0)); QCOMPARE(eventResult.endDateTime().date(), eventDateTime.date().addDays(1)); QCOMPARE(eventResult.endDateTime().time(), QTime(0, 0, 0)); } void testCreateAllDayEventWithInvalidEndDate() { static QString displayLabelValue = QStringLiteral("All day title"); static QString descriptionValue = QStringLiteral("All day description"); QDateTime eventDateTime = QDateTime(QDate(2013, 9, 3), QTime(0,30,0)); QOrganizerEvent event; event.setStartDateTime(eventDateTime); event.setEndDateTime(eventDateTime.addDays(-10)); event.setDisplayLabel(displayLabelValue); event.setDescription(descriptionValue); event.setAllDay(true); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; items << event; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QOrganizerManager::NoError); QVERIFY(errorMap.isEmpty()); QOrganizerItemId id = items[0].id(); QVERIFY(!id.isNull()); QOrganizerItemFetchHint hint; QList ids; ids << items[0].id(); items = m_engine->items(ids, hint, &errorMap, &error); QCOMPARE(items.count(), 1); QOrganizerEvent eventResult = static_cast(items[0]); QCOMPARE(eventResult.isAllDay(), true); QCOMPARE(eventResult.startDateTime().date(), eventDateTime.date()); QCOMPARE(eventResult.startDateTime().time(), QTime(0, 0, 0)); QCOMPARE(eventResult.endDateTime().date(), eventDateTime.date().addDays(1)); QCOMPARE(eventResult.endDateTime().time(), QTime(0, 0, 0)); } void testCreateTodoEventWithStartDate() { static QString displayLabelValue = QStringLiteral("Event todo with start date"); static QString descriptionValue = QStringLiteral("Event todo with start date description"); static QDateTime startDateTime = QDateTime(QDate(2013, 9, 3), QTime(0,30,0)); // create a new item QOrganizerTodo todo; todo.setCollectionId(m_collection.id()); todo.setStartDateTime(startDateTime); todo.setDisplayLabel(displayLabelValue); todo.setDescription(descriptionValue); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; items << todo; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QOrganizerManager::NoError); QVERIFY(errorMap.isEmpty()); // query by the new item QOrganizerItemFetchHint hint; QList ids; ids << items[0].id(); items = m_engine->items(ids, hint, &errorMap, &error); QCOMPARE(items.count(), 1); // compare start datetime QOrganizerTodo newTodo = static_cast(items[0]); QCOMPARE(newTodo.startDateTime(), startDateTime); } void testCreateWithDiffTimeZone() { static QString displayLabelValue = QStringLiteral("Event with diff timezone"); static QString descriptionValue = QStringLiteral("Event with diff timezone description"); static QDateTime startDateTime = QDateTime(QDate(2013, 9, 3), QTime(0, 30, 0), QTimeZone("Asia/Bangkok")); // create a new item QOrganizerTodo todo; todo.setCollectionId(m_collection.id()); todo.setStartDateTime(startDateTime); todo.setDisplayLabel(displayLabelValue); todo.setDescription(descriptionValue); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; items << todo; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QOrganizerManager::NoError); QVERIFY(errorMap.isEmpty()); // query by the new item QOrganizerItemFetchHint hint; QList ids; ids << items[0].id(); items = m_engine->items(ids, hint, &errorMap, &error); QCOMPARE(items.count(), 1); // compare start datetime QOrganizerTodo newTodo = static_cast(items[0]); QDateTime newStartDateTime = newTodo.startDateTime(); QCOMPARE(newStartDateTime.timeSpec(), Qt::TimeZone); QCOMPARE(newStartDateTime.timeZone(), QTimeZone("Asia/Bangkok")); QCOMPARE(newTodo.startDateTime(), startDateTime); } void testEventWithTags() { static QString displayLabelValue = QStringLiteral("event with tag"); static QString descriptionValue = QStringLiteral("event with tag descs"); QOrganizerTodo todo; todo.setCollectionId(m_collection.id()); todo.setStartDateTime(QDateTime::currentDateTime()); todo.setDisplayLabel(displayLabelValue); todo.setDescription(descriptionValue); todo.setTags(QStringList() << "Tag0" << "Tag1" << "Tag2"); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; QSignalSpy createdItem(m_engine, SIGNAL(itemsAdded(QList))); items << todo; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QOrganizerManager::NoError); QCOMPARE(items.size(), 1); QVERIFY(errorMap.isEmpty()); QVERIFY(!items[0].id().isNull()); QOrganizerTodo newTodo = static_cast(items[0]); QStringList expectedTags; expectedTags << "Tag0" << "Tag1" << "Tag2"; Q_FOREACH(QString tag, newTodo.tags()) { expectedTags.removeAll(tag); } QCOMPARE(expectedTags.size(), 0); // check saved item QTRY_COMPARE(createdItem.count(), 1); QOrganizerItemFetchHint hint; QList ids; ids << items[0].id(); items = m_engine->items(ids, hint, &errorMap, &error); QCOMPARE(items.count(), 1); newTodo = static_cast(items[0]); expectedTags << "Tag0" << "Tag1" << "Tag2"; Q_FOREACH(QString tag, newTodo.tags()) { expectedTags.removeAll(tag); } QCOMPARE(expectedTags.size(), 0); } void testFloatingTime() { static QString displayLabelValue = QStringLiteral("event with floating time"); static QString descriptionValue = QStringLiteral("event with floating time descs"); QOrganizerTodo todo; todo.setCollectionId(m_collection.id()); QDateTime startDate = QDateTime::currentDateTime(); startDate = QDateTime(startDate.date(), startDate.time(), QTimeZone()); todo.setStartDateTime(startDate); todo.setDisplayLabel(displayLabelValue); todo.setDescription(descriptionValue); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; QSignalSpy createdItem(m_engine, SIGNAL(itemsAdded(QList))); items << todo; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QOrganizerManager::NoError); QCOMPARE(items.size(), 1); QVERIFY(errorMap.isEmpty()); QVERIFY(!items[0].id().isNull()); // check saved item QTRY_COMPARE(createdItem.count(), 1); QOrganizerItemFetchHint hint; QList ids; ids << items[0].id(); items = m_engine->items(ids, hint, &errorMap, &error); QCOMPARE(items.count(), 1); QOrganizerTodo newTodo = static_cast(items[0]); QCOMPARE(newTodo.startDateTime().timeSpec(), todo.startDateTime().timeSpec()); QVERIFY(!newTodo.startDateTime().timeZone().isValid()); QCOMPARE(newTodo.startDateTime().date(), startDate.date()); QCOMPARE(newTodo.startDateTime().time().hour(), startDate.time().hour()); QCOMPARE(newTodo.startDateTime().time().minute(), startDate.time().minute()); // Update floating event QSignalSpy updateItem(m_engine, SIGNAL(itemsChanged(QList))); startDate = QDateTime::currentDateTime(); startDate.addSecs(360); startDate = QDateTime(startDate.date(), startDate.time(), QTimeZone()); items << newTodo; saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QTRY_COMPARE(updateItem.count(), 1); ids.clear(); ids << items[0].id(); items = m_engine->items(ids, hint, &errorMap, &error); QCOMPARE(items.count(), 1); newTodo = static_cast(items[0]); QCOMPARE(newTodo.startDateTime().timeSpec(), todo.startDateTime().timeSpec()); QVERIFY(!newTodo.startDateTime().timeZone().isValid()); QCOMPARE(newTodo.startDateTime().date(), startDate.date()); QCOMPARE(newTodo.startDateTime().time().hour(), startDate.time().hour()); QCOMPARE(newTodo.startDateTime().time().minute(), startDate.time().minute()); // Remove floating event QOrganizerItemRemoveByIdRequest req; connect(&req, SIGNAL(stateChanged(QOrganizerAbstractRequest::State)), this, SLOT(requestFinished(QOrganizerAbstractRequest::State))); connect(m_engine, SIGNAL(itemsRemoved(QList)), this, SLOT(itemRemoved())); req.setItemId(newTodo.id()); m_engine->startRequest(&req); m_engine->waitForRequestFinished(&req, -1); // check if the signal item removed was fired after the request finish QTRY_VERIFY(m_requestFinishedTime.isValid()); QTRY_VERIFY(m_itemRemovedTime.isValid()); QVERIFY(m_itemRemovedTime > m_requestFinishedTime); // check if item was removed QOrganizerItemSortOrder sort; QOrganizerItemIdFilter filter; ids.clear(); ids << newTodo.id(); filter.setIds(ids); items = m_engine->items(filter, QDateTime(), QDateTime(), 10, sort, hint, &error); QCOMPARE(items.count(), 0); } void testCreateEventWithAttendees() { static QString displayLabelValue = QStringLiteral("event with collection attendee"); static QString descriptionValue = QStringLiteral("event without collection"); QOrganizerEvent event; event.setStartDateTime(QDateTime::currentDateTime()); event.setDisplayLabel(displayLabelValue); event.setDescription(descriptionValue); QOrganizerEventAttendee attendee; attendee.setAttendeeId("Attendee ID"); attendee.setEmailAddress("test@email.com"); attendee.setName("Attendee Name"); attendee.setParticipationRole(QOrganizerEventAttendee::RoleHost); attendee.setParticipationStatus(QOrganizerEventAttendee::StatusAccepted); event.saveDetail(&attendee); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; QSignalSpy createdItem(m_engine, SIGNAL(itemsAdded(QList))); items << event; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QTRY_COMPARE(createdItem.count(), 1); QVERIFY(saveResult); QCOMPARE(error, QOrganizerManager::NoError); QCOMPARE(items.size(), 1); QVERIFY(errorMap.isEmpty()); QVERIFY(!items[0].id().isNull()); QList ids; QOrganizerItemFetchHint hint; ids << items[0].id(); QList newItems = m_engine->items(ids, hint, &errorMap, &error); QCOMPARE(newItems.size(), 1); QList atts = newItems[0].details(QOrganizerItemDetail::TypeEventAttendee); QCOMPARE(atts.size(), 1); QOrganizerEventAttendee newAttendee = static_cast(atts[0]); QCOMPARE(newAttendee.attendeeId(), attendee.attendeeId()); QCOMPARE(newAttendee.emailAddress(), attendee.emailAddress()); QCOMPARE(newAttendee.name(), attendee.name()); QCOMPARE(newAttendee.participationRole(), attendee.participationRole()); QCOMPARE(newAttendee.participationStatus(), attendee.participationStatus()); } // BUG: #1440878 void testReminderOnTime() { static QString displayLabelValue = QStringLiteral("event reminder"); static QString descriptionValue = QStringLiteral("event with reminder"); QOrganizerEvent event; QOrganizerItemAudibleReminder aReminder; event.setStartDateTime(QDateTime::currentDateTime()); event.setDisplayLabel(displayLabelValue); event.setDescription(descriptionValue); aReminder.setSecondsBeforeStart(0); aReminder.setDataUrl(QString()); event.saveDetail(&aReminder); QOrganizerEvent event2; aReminder = QOrganizerItemAudibleReminder(); event2.setStartDateTime(QDateTime::currentDateTime().addDays(2)); event2.setDisplayLabel(displayLabelValue + "_2"); event2.setDescription(descriptionValue); aReminder.setSecondsBeforeStart(60); aReminder.setDataUrl(QString()); event2.saveDetail(&aReminder); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; QSignalSpy createdItem(m_engine, SIGNAL(itemsAdded(QList))); items << event << event2; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QTRY_COMPARE(createdItem.count(), 1); QVERIFY(saveResult); QString vcard = getEventFromEvolution(items[0].id()); QVERIFY(vcard.contains("TRIGGER;VALUE=DURATION;RELATED=START:PT0S")); vcard = getEventFromEvolution(items[1].id()); QVERIFY(vcard.contains("TRIGGER;VALUE=DURATION;RELATED=START:-PT1M")); } // BUG: #1445577 void testUTCEvent() { static QString displayLabelValue = QStringLiteral("UTC event"); static QString descriptionValue = QStringLiteral("UTC event"); const QDateTime startDate(QDateTime::currentDateTime().toUTC()); QOrganizerEvent event; event.setStartDateTime(startDate); event.setDisplayLabel(displayLabelValue); event.setDescription(descriptionValue); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; QSignalSpy createdItem(m_engine, SIGNAL(itemsAdded(QList))); items << event; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QTRY_COMPARE(createdItem.count(), 1); QVERIFY(saveResult); QList ids; QOrganizerItemFetchHint hint; ids << items[0].id(); QList newItems = m_engine->items(ids, hint, &errorMap, &error); QCOMPARE(newItems.size(), 1); QOrganizerEvent newEvent = static_cast(newItems[0]); QCOMPARE(newEvent.startDateTime().timeZoneAbbreviation(), QStringLiteral("UTC")); QCOMPARE(newEvent.startDateTime().date(), startDate.date()); QCOMPARE(newEvent.startDateTime().time().hour(), startDate.time().hour()); QCOMPARE(newEvent.startDateTime().time().minute(), startDate.time().minute()); QCOMPARE(newEvent.startDateTime().time().second(), startDate.time().second()); } void testExtendedProperties() { static QString displayLabelValue = QStringLiteral("event with extended property"); static QString descriptionValue = QStringLiteral("event with extended property"); QOrganizerItemId itemId; QDateTime currentTime = QDateTime::currentDateTime(); { // create a item with X-URL QOrganizerEvent event; event.setStartDateTime(currentTime); event.setEndDateTime(currentTime.addSecs(60 * 30)); event.setDisplayLabel(displayLabelValue); event.setDescription(descriptionValue); QOrganizerItemExtendedDetail ex; ex.setName(QStringLiteral("X-URL")); ex.setData(QByteArray("http://canonical.com")); event.saveDetail(&ex); // save the new item QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; QSignalSpy createdItem(m_engine, SIGNAL(itemsAdded(QList))); items << event; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QTRY_COMPARE(createdItem.count(), 1); QVERIFY(saveResult); QCOMPARE(error, QOrganizerManager::NoError); QCOMPARE(items.size(), 1); QVERIFY(errorMap.isEmpty()); QVERIFY(!items[0].id().isNull()); QCOMPARE(items[0].details(QOrganizerItemDetail::TypeExtendedDetail).size(), 1); itemId = items[0].id(); } // fetch for the item { QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList ids; QOrganizerItemFetchHint hint; ids << itemId; QList items = m_engine->items(ids, hint, &errorMap, &error); QCOMPARE(items.size(), 1); QList exs = items[0].details(QOrganizerItemDetail::TypeExtendedDetail); QCOMPARE(exs.size(), 1); QCOMPARE(exs[0].value(QOrganizerItemExtendedDetail::FieldName).toString(), QStringLiteral("X-URL")); QCOMPARE(exs[0].value(QOrganizerItemExtendedDetail::FieldData).toByteArray(), QByteArray("http://canonical.com")); } } void testFetchHint() { static QString displayLabelValue = QStringLiteral("event for fetch hint test"); static QString descriptionValue = QStringLiteral("event for fetch hint test"); QOrganizerItemId itemId; { QOrganizerEvent event; event.setStartDateTime(QDateTime::currentDateTime()); event.setEndDateTime(QDateTime::currentDateTime().addSecs(60 * 30)); event.setDisplayLabel(displayLabelValue); event.setDescription(descriptionValue); // TAGS event.setTags(QStringList() << "Tag0" << "Tag1" << "Tag2"); // ExtendedDetails QOrganizerItemExtendedDetail ex; ex.setName(QStringLiteral("X-URL")); ex.setData(QByteArray("http://canonical.com")); event.saveDetail(&ex); // Reminders QOrganizerItemVisualReminder vReminder; vReminder.setDataUrl(QUrl("http://www.alarms.com")); vReminder.setMessage("Test visual reminder"); event.saveDetail(&vReminder); QOrganizerItemAudibleReminder aReminder; aReminder.setSecondsBeforeStart(0); aReminder.setDataUrl(QUrl("http://www.audible.com")); event.saveDetail(&aReminder); // Attendee QOrganizerEventAttendee attendee; attendee.setAttendeeId("Attendee ID"); attendee.setEmailAddress("test@email.com"); attendee.setName("Attendee Name"); attendee.setParticipationRole(QOrganizerEventAttendee::RoleHost); attendee.setParticipationStatus(QOrganizerEventAttendee::StatusAccepted); event.saveDetail(&attendee); // save the new item QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; QSignalSpy createdItem(m_engine, SIGNAL(itemsAdded(QList))); items << event; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QTRY_COMPARE(createdItem.count(), 1); QVERIFY(saveResult); itemId = items[0].id(); } QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList ids; QOrganizerItemFetchHint hint; ids << itemId; // Fetch ExtendedDetails { QList details; details << QOrganizerItemDetail::TypeExtendedDetail; hint.setDetailTypesHint(details); QList items = m_engine->items(ids, hint, &errorMap, &error); QCOMPARE(items.size(), 1); QOrganizerEvent event = items[0]; QList xDetails = event.details(QOrganizerItemDetail::TypeExtendedDetail); QList vreminders = event.details(QOrganizerItemDetail::TypeVisualReminder); QList areminders = event.details(QOrganizerItemDetail::TypeAudibleReminder); QList attendee = event.details(QOrganizerItemDetail::TypeEventAttendee); QStringList tags = event.tags(); QCOMPARE(xDetails.size(), 1); QCOMPARE(vreminders.size(), 0); QCOMPARE(areminders.size(), 0); QCOMPARE(attendee.size(), 0); QCOMPARE(tags.size(), 0); } // Fetch TAGS, Attendee { QList details; details << QOrganizerItemDetail::TypeTag << QOrganizerItemDetail::TypeEventAttendee; hint.setDetailTypesHint(details); QList items = m_engine->items(ids, hint, &errorMap, &error); QCOMPARE(items.size(), 1); QOrganizerEvent event = items[0]; QList xDetails = event.details(QOrganizerItemDetail::TypeExtendedDetail); QList vreminders = event.details(QOrganizerItemDetail::TypeVisualReminder); QList areminders = event.details(QOrganizerItemDetail::TypeAudibleReminder); QList attendee = event.details(QOrganizerItemDetail::TypeEventAttendee); QStringList tags = event.tags(); QCOMPARE(xDetails.size(), 0); QCOMPARE(vreminders.size(), 0); QCOMPARE(areminders.size(), 0); QCOMPARE(attendee.size(), 1); QCOMPARE(tags.size(), 3); } // Fetch TAGS, Reminders, Attendee { QList details; details << QOrganizerItemDetail::TypeTag << QOrganizerItemDetail::TypeEventAttendee << QOrganizerItemDetail::TypeReminder; hint.setDetailTypesHint(details); QList items = m_engine->items(ids, hint, &errorMap, &error); QCOMPARE(items.size(), 1); QOrganizerEvent event = items[0]; QList xDetails = event.details(QOrganizerItemDetail::TypeExtendedDetail); QList vreminders = event.details(QOrganizerItemDetail::TypeVisualReminder); QList areminders = event.details(QOrganizerItemDetail::TypeAudibleReminder); QList attendee = event.details(QOrganizerItemDetail::TypeEventAttendee); QStringList tags = event.tags(); QCOMPARE(xDetails.size(), 0); QCOMPARE(vreminders.size(), 1); QCOMPARE(areminders.size(), 1); QCOMPARE(attendee.size(), 1); QCOMPARE(tags.size(), 3); } // Fetch VisualReminders { QList details; details << QOrganizerItemDetail::TypeVisualReminder; hint.setDetailTypesHint(details); QList items = m_engine->items(ids, hint, &errorMap, &error); QCOMPARE(items.size(), 1); QOrganizerEvent event = items[0]; QList xDetails = event.details(QOrganizerItemDetail::TypeExtendedDetail); QList vreminders = event.details(QOrganizerItemDetail::TypeVisualReminder); QList areminders = event.details(QOrganizerItemDetail::TypeAudibleReminder); QList attendee = event.details(QOrganizerItemDetail::TypeEventAttendee); QStringList tags = event.tags(); QCOMPARE(xDetails.size(), 0); QCOMPARE(vreminders.size(), 1); QCOMPARE(areminders.size(), 0); QCOMPARE(attendee.size(), 0); QCOMPARE(tags.size(), 0); } // Fetch AudibleReminders { QList details; details << QOrganizerItemDetail::TypeAudibleReminder; hint.setDetailTypesHint(details); QList items = m_engine->items(ids, hint, &errorMap, &error); QCOMPARE(items.size(), 1); QOrganizerEvent event = items[0]; QList xDetails = event.details(QOrganizerItemDetail::TypeExtendedDetail); QList vreminders = event.details(QOrganizerItemDetail::TypeVisualReminder); QList areminders = event.details(QOrganizerItemDetail::TypeAudibleReminder); QList attendee = event.details(QOrganizerItemDetail::TypeEventAttendee); QStringList tags = event.tags(); QCOMPARE(xDetails.size(), 0); QCOMPARE(vreminders.size(), 0); QCOMPARE(areminders.size(), 1); QCOMPARE(attendee.size(), 0); QCOMPARE(tags.size(), 0); } } }; const QString EventTest::collectionTypePropertyName = QStringLiteral("collection-type"); const QString EventTest::taskListTypeName = QStringLiteral("Task List"); int EventTest::signalIndex = 0; QTEST_MAIN(EventTest) #include "event-test.moc" qtorganizer5-eds-0.1.1+16.04.20160317/tests/unittest/filter-test.cpp.moved0000644000015600001650000001545712672562647026415 0ustar pbuserpbgroup00000000000000/* * Copyright 2015 Canonical Ltd. * * This file is part of qtorganizer5-eds. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include "qorganizer-eds-engine.h" #include "eds-base-test.h" using namespace QtOrganizer; class FilterTest : public QObject, public EDSBaseTest { Q_OBJECT private: QOrganizerEDSEngine *m_engine; void createCollection(QOrganizerCollection **collection) { QtOrganizer::QOrganizerManager::Error error; *collection = new QOrganizerCollection(); (*collection)->setMetaData(QOrganizerCollection::KeyName, uniqueCollectionName()); QSignalSpy createdCollection(m_engine, SIGNAL(collectionsAdded(QList))); bool saveResult = m_engine->saveCollection(*collection, &error); QVERIFY(saveResult); QCOMPARE(error, QtOrganizer::QOrganizerManager::NoError); QTRY_COMPARE(createdCollection.count(), 1); } private Q_SLOTS: void initTestCase() { EDSBaseTest::init(); m_engine = QOrganizerEDSEngine::createEDSEngine(QMap()); } void cleanupTestCase() { delete m_engine; EDSBaseTest::cleanup(); } // test functions void testFilterEventByCollectionId() { static QString displayLabelValue = QStringLiteral("Todo test %1 - %2"); static QString descriptionValue = QStringLiteral("Todo description %1 - %2"); QList items; QDateTime currentDate = QDateTime::currentDateTime(); // create items on default collection for(int i=0; i < 10; i++) { QOrganizerEvent ev; ev.setStartDateTime(currentDate); ev.setEndDateTime(currentDate.addDays(1)); ev.setDisplayLabel(displayLabelValue.arg(i).arg("default")); ev.setDescription(descriptionValue.arg(i).arg("default")); items << ev; } // create items on new collection QOrganizerCollection *collection; createCollection(&collection); for(int i=0; i < 10; i++) { QOrganizerEvent ev; ev.setCollectionId(collection->id()); ev.setStartDateTime(currentDate); ev.setEndDateTime(currentDate.addDays(1)); ev.setDisplayLabel(displayLabelValue.arg(i).arg("new")); ev.setDescription(descriptionValue.arg(i).arg("new")); items << ev; } // save all items QtOrganizer::QOrganizerManager::Error error; QMap errorMap; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QtOrganizer::QOrganizerManager::NoError); QOrganizerItemSortOrder sort; QOrganizerItemFetchHint hint; QOrganizerItemCollectionFilter filter; // filter items from default collection filter.setCollectionId(m_engine->defaultCollection(0).id()); items = m_engine->items(filter, QDateTime(), QDateTime(), 100, sort, hint, &error); QCOMPARE(items.count(), 10); // check returned items Q_FOREACH(const QOrganizerItem &i, items) { QVERIFY(static_cast(i).displayLabel().endsWith("default")); } // filter items from new collection filter.setCollectionId(collection->id()); items = m_engine->items(filter, QDateTime(), QDateTime(), 100, sort, hint, &error); QCOMPARE(items.count(), 10); // check returned items Q_FOREACH(const QOrganizerItem &i, items) { QVERIFY(static_cast(i).displayLabel().endsWith("new")); } // filter items from both collections QSet ids; ids << m_engine->defaultCollection(0).id() << collection->id(); filter.setCollectionIds(ids); items = m_engine->items(filter, QDateTime(), QDateTime(), 100, sort, hint, &error); QCOMPARE(items.count(), 20); // filter using union filter // filter events from new collection or ends with 'default' QOrganizerItemUnionFilter uFilter; filter.setCollectionId(collection->id()); QOrganizerItemDetailFieldFilter dFilter; dFilter.setDetail(QOrganizerItemDetail::TypeDescription, QOrganizerItemDescription::FieldDescription); dFilter.setMatchFlags(QOrganizerItemFilter::MatchEndsWith); dFilter.setValue("default"); uFilter.append(filter); uFilter.append(dFilter); items = m_engine->items(uFilter, QDateTime(), QDateTime(), 100, sort, hint, &error); QCOMPARE(items.count(), 20); // filter using intersection filter // filter events from new collection and ends with 'new' QOrganizerItemIntersectionFilter iFilter; dFilter.setValue("new"); iFilter.append(filter); iFilter.append(dFilter); items = m_engine->items(iFilter, QDateTime(), QDateTime(), 100, sort, hint, &error); QCOMPARE(items.count(), 10); // check returned items Q_FOREACH(const QOrganizerItem &i, items) { QVERIFY(static_cast(i).displayLabel().endsWith("new")); } delete collection; } }; QTEST_MAIN(FilterTest) #include "filter-test.moc" qtorganizer5-eds-0.1.1+16.04.20160317/tests/unittest/parseecal-test.cpp0000644000015600001650000003775412672562647025762 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of qtorganizer5-eds. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ //ugly hack but this allow us to test the engine without mock EDS #define private public #include "qorganizer-eds-engine.h" #undef private #include #include #include #include #include using namespace QtOrganizer; class ParseEcalTest : public QObject { Q_OBJECT private: static const QString vEvent; QList m_itemsParsed; public Q_SLOTS: void onEventAsyncParsed(QList items) { m_itemsParsed = items; } private Q_SLOTS: void cleanup() { m_itemsParsed.clear(); } void testParseStartTime() { QDateTime startTime = QDateTime::currentDateTime(); QDateTime endTime(startTime); endTime = endTime.addDays(2); ECalComponent *comp = e_cal_component_new(); e_cal_component_set_new_vtype(comp, E_CAL_COMPONENT_EVENT); ECalComponentDateTime dt; struct icaltimetype itt = icaltime_from_timet(startTime.toTime_t(), FALSE); dt.value = &itt; dt.tzid = ""; e_cal_component_set_dtstart(comp, &dt); QOrganizerEvent item; QOrganizerEDSEngine::parseStartTime(comp, &item); QCOMPARE(item.startDateTime().toTime_t(), startTime.toTime_t()); itt = icaltime_from_timet(endTime.toTime_t(), FALSE); dt.value = &itt; e_cal_component_set_dtend(comp, &dt); QOrganizerEDSEngine::parseEndTime(comp, &item); QCOMPARE(item.endDateTime().toTime_t(), endTime.toTime_t()); } void testParseRemindersQOrganizerEvent2ECalComponent() { QOrganizerEvent event; QOrganizerItemAudibleReminder aReminder; // Check audible reminder aReminder.setRepetition(10, 30); aReminder.setSecondsBeforeStart(10); QCOMPARE(aReminder.secondsBeforeStart(), 10); event.saveDetail(&aReminder); ECalComponent *comp = e_cal_component_new(); e_cal_component_set_new_vtype(comp, E_CAL_COMPONENT_EVENT); QOrganizerEDSEngine::parseReminders(event, comp); GList *aIds = e_cal_component_get_alarm_uids(comp); QCOMPARE(g_list_length(aIds), (guint) 1); ECalComponentAlarm *alarm = e_cal_component_get_alarm(comp, (const gchar*)aIds->data); QVERIFY(alarm); ECalComponentAlarmAction aAction; e_cal_component_alarm_get_action(alarm, &aAction); QCOMPARE(aAction, E_CAL_COMPONENT_ALARM_AUDIO); ECalComponentAlarmTrigger trigger; e_cal_component_alarm_get_trigger(alarm, &trigger); QCOMPARE(trigger.type, E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START); QCOMPARE(icaldurationtype_as_int(trigger.u.rel_duration) * -1, aReminder.secondsBeforeStart()); ECalComponentAlarmRepeat aRepeat; e_cal_component_alarm_get_repeat(alarm, &aRepeat); QCOMPARE(aRepeat.repetitions, aReminder.repetitionCount()); QCOMPARE(icaldurationtype_as_int(aRepeat.duration), aReminder.repetitionDelay()); g_object_unref(comp); } void testParseRemindersECalComponent2QOrganizerEvent() { ECalComponent *comp = e_cal_component_new(); e_cal_component_set_new_vtype(comp, E_CAL_COMPONENT_EVENT); ECalComponentAlarm *alarm = e_cal_component_alarm_new(); e_cal_component_alarm_set_action(alarm, E_CAL_COMPONENT_ALARM_DISPLAY); ECalComponentAlarmTrigger trigger; trigger.type = E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START; trigger.u.rel_duration = icaldurationtype_from_int(-10); e_cal_component_alarm_set_trigger(alarm, trigger); ECalComponentAlarmRepeat aRepeat; aRepeat.repetitions = 5; aRepeat.duration = icaldurationtype_from_int(100); e_cal_component_alarm_set_repeat(alarm, aRepeat); e_cal_component_add_alarm(comp, alarm); e_cal_component_alarm_free(alarm); QOrganizerItem alarmItem; QOrganizerEDSEngine::parseReminders(comp, &alarmItem); QOrganizerItemVisualReminder vReminder = alarmItem.detail(QOrganizerItemDetail::TypeVisualReminder); QCOMPARE(vReminder.repetitionCount(), 5); QCOMPARE(vReminder.repetitionDelay(), 100); QCOMPARE(vReminder.secondsBeforeStart(), 10); g_object_unref(comp); } void testParseRecurenceQOrganizerEvent2ECalComponent() { // by date QOrganizerEvent event; QOrganizerItemRecurrence rec; QList rDates; rDates << QDate(2010, 1, 20) << QDate(2011, 2, 21) << QDate(2012, 3, 22); rec.setRecurrenceDates(rDates.toSet()); QList rExeptDates; rExeptDates << QDate(2013, 4, 23) << QDate(2014, 5, 24) << QDate(2015, 6, 25); rec.setExceptionDates(rExeptDates.toSet()); QOrganizerRecurrenceRule dailyRule; QList rrules; dailyRule.setFrequency(QOrganizerRecurrenceRule::Daily); dailyRule.setLimit(1000); rrules << dailyRule; QOrganizerRecurrenceRule weeklyRule; weeklyRule.setFrequency(QOrganizerRecurrenceRule::Weekly); weeklyRule.setLimit(1001); QList daysOfWeek; daysOfWeek << Qt::Monday << Qt::Tuesday << Qt::Wednesday << Qt::Thursday << Qt::Friday; weeklyRule.setDaysOfWeek(daysOfWeek.toSet()); weeklyRule.setFirstDayOfWeek(Qt::Sunday); rrules << weeklyRule; QOrganizerRecurrenceRule monthlyRule; monthlyRule.setFrequency(QOrganizerRecurrenceRule::Monthly); monthlyRule.setLimit(1002); QList daysOfMonth; daysOfMonth << 1 << 15 << 30; monthlyRule.setDaysOfMonth(daysOfMonth.toSet()); rrules << monthlyRule; QOrganizerRecurrenceRule yearlyRule; yearlyRule.setFrequency(QOrganizerRecurrenceRule::Yearly); yearlyRule.setLimit(1003); QList daysOfYear; daysOfYear << 1 << 10 << 20 << 50 << 300; yearlyRule.setDaysOfYear(daysOfYear.toSet()); QList monthsOfYear; monthsOfYear << QOrganizerRecurrenceRule::January << QOrganizerRecurrenceRule::March << QOrganizerRecurrenceRule::December; yearlyRule.setMonthsOfYear(monthsOfYear.toSet()); rrules << yearlyRule; rec.setRecurrenceRules(rrules.toSet()); // save recurrence event.saveDetail(&rec); ECalComponent *comp = e_cal_component_new(); e_cal_component_set_new_vtype(comp, E_CAL_COMPONENT_EVENT); QOrganizerEDSEngine::parseRecurrence(event, comp); // recurrence dates GSList *periodList = 0; e_cal_component_get_rdate_list(comp, &periodList); QCOMPARE(g_slist_length(periodList), (guint)3); for(GSList *pIter = periodList; pIter != 0; pIter = pIter->next) { ECalComponentPeriod *period = static_cast(pIter->data); QDate periodDate = QDateTime::fromTime_t(icaltime_as_timet(period->start)).date(); QVERIFY(rDates.contains(periodDate)); } e_cal_component_free_period_list(periodList); // exception dates GSList *exDateList = 0; e_cal_component_get_exdate_list(comp, &exDateList); for(GSList *pIter = exDateList; pIter != 0; pIter = pIter->next) { ECalComponentDateTime *exDate = static_cast(pIter->data); QDate exDateValue = QDateTime::fromTime_t(icaltime_as_timet(*exDate->value)).date(); QVERIFY(rExeptDates.contains(exDateValue)); } e_cal_component_free_exdate_list(exDateList); // rules GSList *recurList = 0; e_cal_component_get_rrule_list(comp, &recurList); QCOMPARE(g_slist_length(recurList), (guint) rrules.count()); for(GSList *recurListIter = recurList; recurListIter != 0; recurListIter = recurListIter->next) { struct icalrecurrencetype *rule = static_cast(recurListIter->data); switch(rule->freq) { case ICAL_DAILY_RECURRENCE: QCOMPARE(rule->count, dailyRule.limitCount()); break; case ICAL_WEEKLY_RECURRENCE: QCOMPARE(rule->count, weeklyRule.limitCount()); for (int d = Qt::Monday; d <= Qt::Sunday; d++) { if (daysOfWeek.contains(static_cast(d))) { QVERIFY(rule->by_day[(d-1)] != ICAL_RECURRENCE_ARRAY_MAX); } else { QVERIFY(rule->by_day[d-1] == ICAL_RECURRENCE_ARRAY_MAX); } } break; case ICAL_MONTHLY_RECURRENCE: { QCOMPARE(rule->count, monthlyRule.limitCount()); QList ruleDays; for (int d=0; d < ICAL_BY_MONTHDAY_SIZE; d++) { if (rule->by_month_day[d] != ICAL_RECURRENCE_ARRAY_MAX) { ruleDays << rule->by_month_day[d]; } } QCOMPARE(ruleDays.count(), daysOfMonth.count()); Q_FOREACH(int day, ruleDays) { QVERIFY(daysOfMonth.contains(day)); } break; } case ICAL_YEARLY_RECURRENCE: { QCOMPARE(rule->count, yearlyRule.limitCount()); QList ruleDays; for (int d=0; d < ICAL_BY_YEARDAY_SIZE; d++) { if (rule->by_year_day[d] != ICAL_RECURRENCE_ARRAY_MAX) { ruleDays << rule->by_year_day[d]; } } QCOMPARE(ruleDays.count(), daysOfYear.count()); Q_FOREACH(int day, ruleDays) { QVERIFY(daysOfYear.contains(day)); } QList ruleMonths; for (int d=0; d < ICAL_BY_MONTH_SIZE; d++) { if (rule->by_month[d] != ICAL_RECURRENCE_ARRAY_MAX) { ruleMonths << rule->by_month[d]; } } QCOMPARE(ruleMonths.count(), monthsOfYear.count()); Q_FOREACH(int month, ruleMonths) { QVERIFY(monthsOfYear.contains(static_cast(month))); } } default: break; } } // invert QOrganizerEvent event2; QOrganizerEDSEngine::parseRecurrence(comp, &event2); QCOMPARE(event2.recurrenceDates(), event.recurrenceDates()); QCOMPARE(event2.exceptionDates(), event.exceptionDates()); QList rrules2 = event2.recurrenceRules().toList(); QCOMPARE(rrules2.count(), rrules.count()); Q_FOREACH(const QOrganizerRecurrenceRule &rule2, rrules2) { switch(rule2.frequency()) { case QOrganizerRecurrenceRule::Daily: QCOMPARE(rule2.limitCount(), dailyRule.limitCount()); break; case QOrganizerRecurrenceRule::Weekly: { QCOMPARE(rule2.limitCount(), weeklyRule.limitCount()); QList daysOfWeek2 = rule2.daysOfWeek().toList(); qSort(daysOfWeek2); QCOMPARE(daysOfWeek2, daysOfWeek); break; } case QOrganizerRecurrenceRule::Monthly: { QCOMPARE(rule2.limitCount(), monthlyRule.limitCount()); QList daysOfMonth2 = rule2.daysOfMonth().toList(); qSort(daysOfMonth2); QCOMPARE(daysOfMonth2, daysOfMonth); break; } case QOrganizerRecurrenceRule::Yearly: { QCOMPARE(rule2.limitCount(), yearlyRule.limitCount()); QList daysOfYear2 = rule2.daysOfYear().toList(); qSort(daysOfYear2); QCOMPARE(daysOfYear2, daysOfYear); QList monthsOfYear2 = rule2.monthsOfYear().toList(); qSort(monthsOfYear2); QCOMPARE(monthsOfYear2, monthsOfYear); break; } default: QVERIFY(false); } } g_object_unref(comp); } void testAsyncParse() { qRegisterMetaType >(); QOrganizerEDSEngine *engine = QOrganizerEDSEngine::createEDSEngine(QMap()); QVERIFY(engine); icalcomponent *ical = icalcomponent_new_from_string(vEvent.toUtf8().data()); QVERIFY(ical); QVERIFY(icalcomponent_is_valid(ical)); QList detailsHint; GSList *events = g_slist_append(0, ical); QMap eventMap; eventMap.insert(engine->defaultCollection(0).id().toString(), events); engine->parseEventsAsync(eventMap, true, detailsHint, this, SLOT(onEventAsyncParsed(QList))); QTRY_COMPARE(m_itemsParsed.size(), 1); QOrganizerEvent ev = m_itemsParsed.at(0); QDateTime eventTime(QDate(2015,04, 8), QTime(19, 0, 0), QTimeZone("America/Recife")); QCOMPARE(ev.startDateTime(), eventTime); QCOMPARE(ev.endDateTime(), eventTime.addSecs(30 * 60)); QCOMPARE(ev.displayLabel(), QStringLiteral("one minute after start")); QCOMPARE(ev.description(), QStringLiteral("event to parse")); QOrganizerRecurrenceRule rrule = ev.recurrenceRule(); QCOMPARE(rrule.frequency(), QOrganizerRecurrenceRule::Daily); QCOMPARE(rrule.limitType(), QOrganizerRecurrenceRule::NoLimit); QList except = ev.exceptionDates().toList(); qSort(except); QCOMPARE(except.size(), 2); QCOMPARE(except.at(0), QDate(2015, 4, 9)); QCOMPARE(except.at(1), QDate(2015, 5, 1)); QOrganizerItemVisualReminder vreminder = ev.detail(QOrganizerItemDetail::TypeVisualReminder); QCOMPARE(vreminder.secondsBeforeStart(), 60); QCOMPARE(vreminder.message(), QStringLiteral("alarm to parse")); g_slist_free_full(events, (GDestroyNotify)icalcomponent_free); delete engine; } }; const QString ParseEcalTest::vEvent = QStringLiteral("" "BEGIN:VEVENT\r\n" "UID:20150408T215243Z-19265-1000-5926-24@renato-ubuntu\r\n" "DTSTAMP:20150408T214536Z\r\n" "DTSTART;TZID=/freeassociation.sourceforge.net/Tzfile/America/Recife:\r\n" " 20150408T190000\r\n" "DTEND;TZID=/freeassociation.sourceforge.net/Tzfile/America/Recife:\r\n" " 20150408T193000\r\n" "TRANSP:OPAQUE\r\n" "SEQUENCE:6\r\n" "SUMMARY:one minute after start\r\n" "DESCRIPTION:event to parse\r\n" "CLASS:PUBLIC\r\n" "CREATED:20150408T215308Z\r\n" "LAST-MODIFIED:20150409T200807Z\r\n" "RRULE:FREQ=DAILY\r\n" "EXDATE;VALUE=DATE:20150501\r\n" "EXDATE;VALUE=DATE:20150409\r\n" "BEGIN:VALARM\r\n" "X-EVOLUTION-ALARM-UID:20150408T215549Z-19265-1000-5926-38@renato-ubuntu\r\n" "ACTION:DISPLAY\r\n" "TRIGGER;VALUE=DURATION;RELATED=START:-PT1M\r\n" "DESCRIPTION:alarm to parse\r\n" "END:VALARM\r\n" "END:VEVENT\r\n" ""); QTEST_MAIN(ParseEcalTest) #include "parseecal-test.moc" qtorganizer5-eds-0.1.1+16.04.20160317/tests/unittest/run-eds-test.sh0000755000015600001650000000341212672562647025213 0ustar pbuserpbgroup00000000000000#!/bin/sh echo ARG0=$0 # this script echo ARG1=$1 # full executable path of dbus-test-runner echo ARG2=$2 # full executable path of test app echo ARG3=$3 # test name echo ARG4=$4 # full executable path of evolution-calendar-factory echo ARG5=$5 # bus service name of calendar factory echo ARG6=$6 # full exectuable path of evolution-source-registry echo ARG7=$7 # bus service name of evolution-source-registry echo ARG7=$8 # full executable path of gvfs echo ARG8=$9 # config files # set up the tmpdir and tell the shell to purge it when we exit export TEST_TMP_DIR=$(mktemp -p "${TMPDIR:-/tmp}" -d $3-XXXXXXXXXX) || exit 1 echo "running test '$3' in ${TEST_TMP_DIR}" # set up the environment variables export QT_QPA_PLATFORM=minimal export HOME=${TEST_TMP_DIR} export XDG_RUNTIME_DIR=${TEST_TMP_DIR} export XDG_CACHE_HOME=${TEST_TMP_DIR}/.cache export XDG_CONFIG_HOME=${TEST_TMP_DIR}/.config export XDG_DATA_HOME=${TEST_TMP_DIR}/.local/share export XDG_DESKTOP_DIR=${TEST_TMP_DIR} export XDG_DOCUMENTS_DIR=${TEST_TMP_DIR} export XDG_DOWNLOAD_DIR=${TEST_TMP_DIR} export XDG_MUSIC_DIR=${TEST_TMP_DIR} export XDG_PICTURES_DIR=${TEST_TMP_DIR} export XDG_PUBLICSHARE_DIR=${TEST_TMP_DIR} export XDG_TEMPLATES_DIR=${TEST_TMP_DIR} export XDG_VIDEOS_DIR=${TEST_TMP_DIR} export EDS_TESTING=1 export QORGANIZER_EDS_DEBUG=On export GIO_USE_VFS=local # needed to ensure GVFS shuts down cleanly after the test is over echo HOMEDIR=${HOME} rm -rf ${XDG_DATA_HOME} # run dbus-test-runner $1 --keep-env --max-wait=90 \ --task $2 --task-name $3 --wait-until-complete --wait-for=$5 \ --task $4 --task-name "evolution" --wait-until-complete --wait-for=$7 -r \ --task $6 --task-name "source-registry" -r rv=$? # if the test passed, blow away the tmpdir if [ $rv -eq 0 ]; then rm -rf $TEST_TMP_DIR fi return $rv qtorganizer5-eds-0.1.1+16.04.20160317/tests/unittest/cancel-operation-test.cpp0000644000015600001650000001250712672562647027233 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of qtorganizer5-eds. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include "qorganizer-eds-engine.h" #include "qorganizer-eds-requestdata.h" #include "eds-base-test.h" using namespace QtOrganizer; class CancelOperationTest : public QObject, public EDSBaseTest { Q_OBJECT private: QOrganizerEDSEngine *m_engine; QOrganizerCollection m_collection; private Q_SLOTS: void init() { EDSBaseTest::init(); QMap parameters; parameters.insert("sleepMode", "true"); m_engine = QOrganizerEDSEngine::createEDSEngine(parameters); QtOrganizer::QOrganizerManager::Error error; m_collection = QOrganizerCollection(); m_collection.setMetaData(QOrganizerCollection::KeyName, uniqueCollectionName()); bool saveResult = m_engine->saveCollection(&m_collection, &error); QVERIFY(saveResult); QCOMPARE(error, QtOrganizer::QOrganizerManager::NoError); } void cleanup() { QTRY_COMPARE(RequestData::instanceCount(), 0); delete m_engine; m_engine = 0; EDSBaseTest::cleanup(); } void cancelOperationAfterStart() { QOrganizerEvent event; event.setStartDateTime(QDateTime::currentDateTime()); event.setDisplayLabel("displayLabelValue"); event.setDescription("descriptionValue"); event.setCollectionId(m_collection.id()); QSignalSpy createdItem(m_engine, SIGNAL(itemsAdded(QList))); // Try cancel a create item operation QOrganizerItemSaveRequest req; req.setItem(event); m_engine->startRequest(&req); QCOMPARE(req.state(), QOrganizerAbstractRequest::ActiveState); m_engine->cancelRequest(&req); QCOMPARE(req.state(), QOrganizerAbstractRequest::CanceledState); QTRY_COMPARE(createdItem.count(), 0); QTRY_COMPARE(m_engine->runningRequestCount(), 0); } void deleteManagerBeforeRequestFinish() { QOrganizerEvent event; event.setStartDateTime(QDateTime::currentDateTime()); event.setDisplayLabel("displayLabelValue"); event.setDescription("descriptionValue"); event.setCollectionId(m_collection.id()); QOrganizerEDSEngine *engine = QOrganizerEDSEngine::createEDSEngine(QMap()); // Start a request QOrganizerItemSaveRequest req; req.setItem(event); engine->startRequest(&req); QCOMPARE(req.state(), QOrganizerAbstractRequest::ActiveState); // delete engine delete engine; } void cancelBeforeStart() { QOrganizerEvent event; event.setStartDateTime(QDateTime::currentDateTime()); event.setDisplayLabel("displayLabelValue"); event.setDescription("descriptionValue"); event.setCollectionId(m_collection.id()); // Cancel before start QOrganizerItemSaveRequest req; req.setItem(event); m_engine->cancelRequest(&req); QTRY_COMPARE(m_engine->runningRequestCount(), 0); } void destroyRequestAfterStart() { QOrganizerEvent event; event.setStartDateTime(QDateTime::currentDateTime()); event.setDisplayLabel("displayLabelValue"); event.setDescription("descriptionValue"); event.setCollectionId(m_collection.id()); QOrganizerManager *mgr = new QOrganizerManager("eds"); QOrganizerItemSaveRequest *req = new QOrganizerItemSaveRequest; req->setManager(mgr); req->setItem(event); req->start(); req->deleteLater(); delete mgr; } void startMultipleRequests() { QList collections = m_engine->collections(0); QList requests; for(int i=0; i < 100; i++) { QOrganizerEvent event; event.setStartDateTime(QDateTime::currentDateTime()); event.setDisplayLabel(QString("displayLabelValue_%1").arg(i)); event.setDescription(QString("descriptionValue_%2").arg(i)); event.setCollectionId(m_collection.id()); QOrganizerItemSaveRequest *req = new QOrganizerItemSaveRequest; req->setItem(event); m_engine->startRequest(req); QCOMPARE(req->state(), QOrganizerAbstractRequest::ActiveState); requests << req; } Q_FOREACH(QOrganizerItemSaveRequest *r, requests) { m_engine->cancelRequest(r); QCOMPARE(r->state(), QOrganizerAbstractRequest::CanceledState); } QTRY_COMPARE(m_engine->runningRequestCount(), 0); } }; QTEST_MAIN(CancelOperationTest) #include "cancel-operation-test.moc" qtorganizer5-eds-0.1.1+16.04.20160317/tests/unittest/CMakeLists.txt0000644000015600001650000000277112672562647025071 0ustar pbuserpbgroup00000000000000macro(declare_test TESTNAME) add_executable(${TESTNAME} ${TESTNAME}.cpp eds-base-test.cpp eds-base-test.h ) qt5_use_modules(${TESTNAME} Core Organizer Test) if(TEST_XML_OUTPUT) set(TEST_ARGS -p -xunitxml -p -o -p test_${testname}.xml) else() set(TEST_ARGS "") endif() target_link_libraries(${TESTNAME} qtorganizer_eds-lib ${GLIB_LIBRARIES} ${GIO_LIBRARIES} ${ECAL_LIBRARIES} ${EDATASERVER_LIBRARIES} ) add_test(${TESTNAME} ${CMAKE_CURRENT_SOURCE_DIR}/run-eds-test.sh ${DBUS_RUNNER} ${CMAKE_CURRENT_BINARY_DIR}/${TESTNAME} ${TESTNAME} ${EVOLUTION_CALENDAR_FACTORY} ${EVOLUTION_CALENDAR_SERVICE_NAME} ${EVOLUTION_SOURCE_REGISTRY} ${EVOLUTION_SOURCE_SERVICE_NAME} ${GVFSD}) endmacro(declare_test testname) include_directories( ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${qorganizer-eds-src_SOURCE_DIR} ${GLIB_INCLUDE_DIRS} ${GIO_INCLUDE_DIRS} ${ECAL_INCLUDE_DIRS} ${EDATASERVER_INCLUDE_DIRS} ) add_definitions(-DTEST_SUITE) declare_test(itemid-test) declare_test(parseecal-test) declare_test(collections-test) declare_test(event-test) declare_test(fetchitem-test) declare_test(recurrence-test) declare_test(cancel-operation-test) declare_test(filter-test) qtorganizer5-eds-0.1.1+16.04.20160317/tests/unittest/itemid-test.cpp0000644000015600001650000000477312672562647025271 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of qtorganizer5-eds. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include "qorganizer-eds-engineid.h" #include "qorganizer-eds-collection-engineid.h" using namespace QtOrganizer; class ItemIdTest : public QObject { Q_OBJECT private Q_SLOTS: void testRetriveItemId() { QString rId; QString id("qtorganizer:eds::system-calendar/20130814T212003Z-13580-1000-1995-22@ubuntu#100200023"); QCOMPARE(QOrganizerEDSEngineId::toComponentId(id, &rId), QStringLiteral("20130814T212003Z-13580-1000-1995-22@ubuntu")); QCOMPARE(rId, QStringLiteral("100200023")); } void testCreateFromString() { QOrganizerEDSEngineId id("system-calendar", "20130814T212003Z-13580-1000-1995-22@ubuntu"); QCOMPARE(id.toString(), QStringLiteral("system-calendar/20130814T212003Z-13580-1000-1995-22@ubuntu")); } void testCollectionIdFromString() { QOrganizerEDSCollectionEngineId id(QStringLiteral("qtorganizer:eds::system-calendar/20130814T212003Z-13580-1000-1995-22@ubuntu")); QOrganizerEDSCollectionEngineId id2(QStringLiteral("eds::system-calendar/20130814T212003Z-13580-1000-1995-22@ubuntu")); QOrganizerEDSCollectionEngineId id3(QStringLiteral("system-calendar/20130814T212003Z-13580-1000-1995-22@ubuntu")); QVERIFY(id.isEqualTo(&id2)); QVERIFY(id2.isEqualTo(&id3)); } void testCreateOrganizerId() { QOrganizerEDSEngineId id("system-calendar", "20130814T212003Z-13580-1000-1995-22@ubuntu"); QOrganizerItemId id2(new QOrganizerEDSEngineId(id)); QCOMPARE(id2.managerUri(), QStringLiteral("qtorganizer:eds:")); QString targetId = QString("qtorganizer:eds::") + id.toString(); QCOMPARE(id2.toString(), targetId); } }; QTEST_MAIN(ItemIdTest) #include "itemid-test.moc" qtorganizer5-eds-0.1.1+16.04.20160317/tests/unittest/recurrence-test.cpp0000644000015600001650000007277412672562647026161 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of qtorganizer5-eds. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include #include #include #include #include "qorganizer-eds-engine.h" #include "eds-base-test.h" using namespace QtOrganizer; class RecurrenceTest : public QObject, public EDSBaseTest { Q_OBJECT private: static const QString defaultCollectionName; QOrganizerEDSEngine *m_engine; QOrganizerCollection m_collection; QOrganizerItem createTestEvent() { static QString displayLabelValue = QStringLiteral("Recurrence event test"); static QString descriptionValue = QStringLiteral("Recucurrence event description"); QOrganizerEvent ev; ev.setCollectionId(m_collection.id()); ev.setStartDateTime(QDateTime(QDate(2013, 12, 2), QTime(0,0,0), QTimeZone("America/Recife"))); ev.setEndDateTime(QDateTime(QDate(2013, 12, 2), QTime(0,30,0), QTimeZone("America/Recife"))); ev.setDisplayLabel(displayLabelValue); ev.setDescription(descriptionValue); QOrganizerRecurrenceRule rule; rule.setFrequency(QOrganizerRecurrenceRule::Weekly); rule.setDaysOfWeek(QSet() << Qt::Monday); rule.setLimit(QDate(2013, 12, 31)); ev.setRecurrenceRule(rule); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; items << ev; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); if (!saveResult) { qWarning() << "Fail to save items"; } Q_ASSERT(saveResult); Q_ASSERT(error == QtOrganizer::QOrganizerManager::NoError); return items[0]; } private Q_SLOTS: void initTestCase() { EDSBaseTest::initTestCase(); } void init() { EDSBaseTest::init(); m_engine = QOrganizerEDSEngine::createEDSEngine(QMap()); QtOrganizer::QOrganizerManager::Error error; m_collection = QOrganizerCollection(); m_collection.setMetaData(QOrganizerCollection::KeyName, uniqueCollectionName()); bool saveResult = m_engine->saveCollection(&m_collection, &error); QVERIFY(saveResult); QCOMPARE(error, QtOrganizer::QOrganizerManager::NoError); } void cleanup() { m_collection = QOrganizerCollection(); delete m_engine; m_engine = 0; EDSBaseTest::cleanup(); } void testCreateDailyEvent() { static QString displayLabelValue = QStringLiteral("Daily test"); static QString descriptionValue = QStringLiteral("Daily description"); QOrganizerEvent ev; ev.setCollectionId(m_collection.id()); ev.setStartDateTime(QDateTime(QDate(2013, 12, 2), QTime(0,0,0))); ev.setEndDateTime(QDateTime(QDate(2013, 12, 2), QTime(0,30,0))); ev.setDisplayLabel(displayLabelValue); ev.setDescription(descriptionValue); QOrganizerRecurrenceRule rule; rule.setFrequency(QOrganizerRecurrenceRule::Daily); rule.setLimit(QDate(2013, 12, 31)); ev.setRecurrenceRule(rule); QSignalSpy itemsAdded(m_engine, SIGNAL(itemsAdded(QList))); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; items << ev; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QtOrganizer::QOrganizerManager::NoError); QTRY_COMPARE_WITH_TIMEOUT(itemsAdded.count(), 1, 10000); } void testCreateWeeklyEvent() { static QString displayLabelValue = QStringLiteral("Weekly test"); static QString descriptionValue = QStringLiteral("Weekly description"); QOrganizerEvent ev; ev.setCollectionId(m_collection.id()); ev.setStartDateTime(QDateTime(QDate(2013, 12, 2), QTime(0,0,0))); ev.setEndDateTime(QDateTime(QDate(2013, 12, 2), QTime(0,30,0))); ev.setDisplayLabel(displayLabelValue); ev.setDescription(descriptionValue); QOrganizerRecurrenceRule rule; rule.setFrequency(QOrganizerRecurrenceRule::Weekly); rule.setDaysOfWeek(QSet() << Qt::Monday); rule.setLimit(QDate(2013, 12, 31)); ev.setRecurrenceRule(rule); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; items << ev; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QtOrganizer::QOrganizerManager::NoError); QOrganizerItemId parentId = items[0].id(); QOrganizerItemSortOrder sort; QOrganizerItemFetchHint hint; QOrganizerItemCollectionFilter filter; filter.setCollectionId(m_collection.id()); items = m_engine->items(filter, QDateTime(QDate(2013, 11, 30), QTime(0,0,0)), QDateTime(QDate(2015, 1, 1), QTime(0,0,0)), 100, sort, hint, &error); QCOMPARE(items.count(), 5); QList expectedDates; expectedDates << QDateTime(QDate(2013, 12, 2), QTime(0,0,0)) << QDateTime(QDate(2013, 12, 9), QTime(0,0,0)) << QDateTime(QDate(2013, 12, 16), QTime(0,0,0)) << QDateTime(QDate(2013, 12, 23), QTime(0,0,0)) << QDateTime(QDate(2013, 12, 30), QTime(0,0,0)); for(int i=0; i < 5; i++) { QOrganizerItemParent itemParent = items[i].detail(QOrganizerItemDetail::TypeParent); QOrganizerEventTime time = items[i].detail(QOrganizerItemDetail::TypeEventTime); QCOMPARE(itemParent.parentId(), parentId); QCOMPARE(time.startDateTime(), expectedDates[i]); } } void testCreateMonthlyEvent() { static QString displayLabelValue = QStringLiteral("Monthly test"); static QString descriptionValue = QStringLiteral("Monthly description"); static QDateTime eventStartDate = QDateTime(QDate(2013, 1, 1), QTime(0, 0, 0)); static QDateTime eventEndDate = QDateTime(QDate(2013, 1, 1), QTime(0, 30, 0)); QOrganizerEvent ev; ev.setCollectionId(m_collection.id()); ev.setStartDateTime(eventStartDate); ev.setEndDateTime(eventEndDate); ev.setDisplayLabel(displayLabelValue); ev.setDescription(descriptionValue); QOrganizerRecurrenceRule rule; rule.setFrequency(QOrganizerRecurrenceRule::Monthly); rule.setDaysOfMonth(QSet() << 1 << 5); rule.setLimit(QDate(2013, 12, 31)); ev.setRecurrenceRule(rule); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; items << ev; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QtOrganizer::QOrganizerManager::NoError); QOrganizerItemSortOrder sort; QOrganizerItemFetchHint hint; QOrganizerItemCollectionFilter filter; filter.setCollectionId(m_collection.id()); items = m_engine->items(filter, eventStartDate, eventStartDate.addYears(1), 100, sort, hint, &error); QCOMPARE(items.count(), 24); for(int i=0; i < 12; i++) { QOrganizerEventTime time = items[i*2].detail(QOrganizerItemDetail::TypeEventTime); QCOMPARE(time.startDateTime(), eventStartDate.addMonths(i)); time = items[(i*2)+1].detail(QOrganizerItemDetail::TypeEventTime); QCOMPARE(time.startDateTime(), QDateTime(QDate(2013, i+1, 5), QTime(0,0,0), Qt::LocalTime)); } } void testModifyReccurenceEvents() { createTestEvent().id(); QtOrganizer::QOrganizerManager::Error error; QOrganizerItemSortOrder sort; QOrganizerItemFetchHint hint; QOrganizerItemCollectionFilter filter; filter.setCollectionId(m_collection.id()); QList items; items = m_engine->items(filter, QDateTime(QDate(2013, 11, 30), QTime(0,0,0)), QDateTime(QDate(2014, 1, 1), QTime(0,0,0)), 100, sort, hint, &error); QCOMPARE(items.count(), 5); QMap errorMap; // remove only one item bool removeResult = m_engine->removeItems(QList() << items[3].id(), &errorMap, &error); QCOMPARE(removeResult, true); QCOMPARE(error, QOrganizerManager::NoError); QCOMPARE(errorMap.size(), 0); items = m_engine->items(filter, QDateTime(QDate(2013, 11, 30), QTime(0,0,0)), QDateTime(QDate(2014, 1, 1), QTime(0,0,0)), 100, sort, hint, &error); QCOMPARE(items.count(), 4); // edit only one item QList updateItems; QOrganizerItem updateItem = items[2]; QList mask; updateItem.setDisplayLabel("Updated item 2"); updateItems << updateItem; bool saveResult = m_engine->saveItems(&updateItems, mask, &errorMap, &error); QCOMPARE(saveResult, true); QCOMPARE(errorMap.size(), 0); QCOMPARE(error, QOrganizerManager::NoError); items = m_engine->items(QList() << updateItem.id(), hint, &errorMap, &error); QCOMPARE(errorMap.size(), 0); QCOMPARE(error, QOrganizerManager::NoError); QCOMPARE(items.size(), 1); QCOMPARE(items[0].displayLabel(), QStringLiteral("Updated item 2")); } void testQueryRecurrenceForAParentItem() { QOrganizerItem recurrenceEvent = createTestEvent(); QtOrganizer::QOrganizerManager::Error error; QOrganizerItemSortOrder sort; QOrganizerItemFetchHint hint; QOrganizerItemCollectionFilter filter; filter.setCollectionId(m_collection.id()); QList items = m_engine->items(filter, QDateTime(), QDateTime(), 100, sort, hint, &error); // this should return only the parent event QCOMPARE(error, QOrganizerManager::NoError); QCOMPARE(items.count(), 1); QCOMPARE(items[0].id(), recurrenceEvent.id()); QOrganizerEvent parentEvent = static_cast(items[0]); QCOMPARE(parentEvent.recurrenceRules().size(), 1); // Check if the limit date was saved correct QOrganizerRecurrenceRule rrule = parentEvent.recurrenceRule(); QCOMPARE(rrule.limitDate(), QDate(2013, 12, 31)); // query recurrence events for the event items = m_engine->itemOccurrences(recurrenceEvent, QDateTime(QDate(2013, 11, 30), QTime(0,0,0)), QDateTime(QDate(2014, 1, 1), QTime(0,0,0)), 100, hint, &error); // check if all recurrence was returned QCOMPARE(items.count(), 5); QList expectedDates; expectedDates << QDateTime(QDate(2013, 12, 2), QTime(0,0,0), QTimeZone("America/Recife")) << QDateTime(QDate(2013, 12, 9), QTime(0,0,0), QTimeZone("America/Recife")) << QDateTime(QDate(2013, 12, 16), QTime(0,0,0), QTimeZone("America/Recife")) << QDateTime(QDate(2013, 12, 23), QTime(0,0,0), QTimeZone("America/Recife")) << QDateTime(QDate(2013, 12, 30), QTime(0,0,0), QTimeZone("America/Recife")); for(int i=0; i < 5; i++) { QCOMPARE(items[i].type(), QOrganizerItemType::TypeEventOccurrence); QOrganizerEventTime time = items[i].detail(QOrganizerItemDetail::TypeEventTime); QCOMPARE(time.startDateTime(), expectedDates[i]); } } void testCreateSunTueWedThuFriSatEvents() { static QString displayLabelValue = QStringLiteral("testCreateSunTueWedThuFriSatEvents test"); static QString descriptionValue = QStringLiteral("testCreateSunTueWedThuFriSatEvents description"); QOrganizerEvent ev; ev.setCollectionId(m_collection.id()); ev.setStartDateTime(QDateTime(QDate(2014, 03, 1), QTime(0,0,0), QTimeZone("America/Recife"))); ev.setEndDateTime(QDateTime(QDate(2014, 03, 1), QTime(0,30,0), QTimeZone("America/Recife"))); ev.setDisplayLabel(displayLabelValue); ev.setDescription(descriptionValue); QOrganizerRecurrenceRule rule; rule.setFrequency(QOrganizerRecurrenceRule::Weekly); QSet dasyOfWeek; dasyOfWeek << Qt::Sunday << Qt::Tuesday << Qt::Wednesday << Qt::Thursday << Qt::Friday << Qt::Saturday; rule.setDaysOfWeek(dasyOfWeek); ev.setRecurrenceRule(rule); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; items << ev; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QtOrganizer::QOrganizerManager::NoError); QOrganizerItemId parentId = items[0].id(); QOrganizerItemSortOrder sort; QOrganizerItemFetchHint hint; QOrganizerItemCollectionFilter filter; filter.setCollectionId(m_collection.id()); // check if the parent was saved correct items = m_engine->items(QList() << parentId, hint, &errorMap, &error); QCOMPARE(items.size(), 1); QOrganizerEvent result = items[0]; QCOMPARE(result.collectionId(), ev.collectionId()); QCOMPARE(result.startDateTime(), ev.startDateTime()); QCOMPARE(result.endDateTime(), ev.endDateTime()); QCOMPARE(result.displayLabel(), ev.displayLabel()); QCOMPARE(result.description(), ev.description()); QOrganizerRecurrenceRule savedRule = result.recurrenceRule(); QCOMPARE(savedRule.frequency(), rule.frequency()); QCOMPARE(savedRule.daysOfWeek(), rule.daysOfWeek()); items = m_engine->items(filter, QDateTime(QDate(2014, 03, 1), QTime(0,0,0)), QDateTime(QDate(2014, 03, 8), QTime(24,0,0)), 100, sort, hint, &error); QList expectedDates; expectedDates << QDateTime(QDate(2014, 03, 1), QTime(0,0,0), QTimeZone("America/Recife")) << QDateTime(QDate(2014, 03, 2), QTime(0,0,0), QTimeZone("America/Recife")) << QDateTime(QDate(2014, 03, 4), QTime(0,0,0), QTimeZone("America/Recife")) << QDateTime(QDate(2014, 03, 5), QTime(0,0,0), QTimeZone("America/Recife")) << QDateTime(QDate(2014, 03, 6), QTime(0,0,0), QTimeZone("America/Recife")) << QDateTime(QDate(2014, 03, 7), QTime(0,0,0), QTimeZone("America/Recife")); QCOMPARE(items.count(), expectedDates.size()); for(int i=0, iMax=expectedDates.size(); i < iMax; i++) { QOrganizerItemParent itemParent = items[i].detail(QOrganizerItemDetail::TypeParent); QOrganizerEventTime time = items[i].detail(QOrganizerItemDetail::TypeEventTime); QCOMPARE(itemParent.parentId(), parentId); QCOMPARE(time.startDateTime(), expectedDates[i]); } } void testModifyAllRecurrence() { static const QString newDisplayLabel("New Display label for all items"); QOrganizerItem item = createTestEvent(); // edit all items QMap errorMap; QtOrganizer::QOrganizerManager::Error error; QList updateItems; QList mask; item.setDisplayLabel(newDisplayLabel); updateItems << item; bool saveResult = m_engine->saveItems(&updateItems, mask, &errorMap, &error); QCOMPARE(saveResult, true); QCOMPARE(errorMap.size(), 0); QCOMPARE(error, QOrganizerManager::NoError); QOrganizerItemSortOrder sort; QOrganizerItemFetchHint hint; QOrganizerItemCollectionFilter filter; filter.setCollectionId(m_collection.id()); QList items = m_engine->items(filter, QDateTime(QDate(2013, 11, 30), QTime(0,0,0)), QDateTime(QDate(2014, 1, 1), QTime(0,0,0)), 100, sort, hint, &error); QCOMPARE(items.count(), 5); Q_FOREACH(const QOrganizerItem &i, items) { QCOMPARE(i.displayLabel(), newDisplayLabel); } } void testModifyPriorEvents() { static const QString newDisplayLabel("New Display label for prior items"); static const QDateTime startInteval(QDateTime(QDate(2013, 12, 2), QTime(0,0,0), QTimeZone("America/Recife"))); static const QDateTime endInteval(QDateTime(QDate(2014, 1, 1), QTime(0,0,0), QTimeZone("America/Recife"))); QOrganizerItem item = createTestEvent(); QtOrganizer::QOrganizerManager::Error error; QOrganizerItemFetchHint hint; QList items; items = m_engine->itemOccurrences(item, startInteval, endInteval, 100, hint, &error); QCOMPARE(items.count(), 5); // edit only events before 16/12/2013 QOrganizerEventOccurrence changeItem = static_cast(items[2]); QDate changeItemDate(2013, 12, 16); QCOMPARE(changeItem.startDateTime().date(), changeItemDate); // edit only one item changeItem.setDisplayLabel(newDisplayLabel); changeItem.setDescription("New Event Description"); QtOrganizer::QOrganizerItemSaveRequest req(m_engine); changeItem.setDisplayLabel(newDisplayLabel); req.setItem(changeItem); req.setProperty("update-mode", 1 << 1); m_engine->startRequest(&req); m_engine->waitForRequestFinished(&req, 0); QCOMPARE(req.error(), QtOrganizer::QOrganizerManager::NoError); QOrganizerItemSortOrder sort; QOrganizerItemCollectionFilter filter; filter.setCollectionId(m_collection.id()); items = m_engine->items(filter, startInteval, endInteval, 100, sort, hint, &error); QCOMPARE(items.count(), 5); //FIXME #if 0 Q_FOREACH(const QOrganizerItem &i, items) { QOrganizerEventOccurrence event = static_cast(i); qDebug() << i.displayLabel() << event.startDateTime().time() << i.description(); //if (event.startDateTime().date() <= changeItemDate) { // QCOMPARE(i.displayLabel(), newDisplayLabel); //} else { // QCOMPARE(i.displayLabel(), item.displayLabel()); //} } #endif } void testCreateWeeklyEventWithoutEndDate() { static QString displayLabelValue = QStringLiteral("testCreateWeeklyEventWithoutEndDate test"); static QString descriptionValue = QStringLiteral("testCreateWeeklyEventWithoutEndDate description"); QOrganizerEvent ev; ev.setCollectionId(m_collection.id()); ev.setStartDateTime(QDateTime(QDate(2014, 03, 1), QTime(0,0,0), QTimeZone("America/Recife"))); ev.setEndDateTime(QDateTime(QDate(2014, 03, 1), QTime(0,30,0), QTimeZone("America/Recife"))); ev.setDisplayLabel(displayLabelValue); ev.setDescription(descriptionValue); QOrganizerRecurrenceRule rule; rule.setFrequency(QOrganizerRecurrenceRule::Weekly); QSet dasyOfWeek; dasyOfWeek << Qt::Monday << Qt::Tuesday << Qt::Wednesday << Qt::Thursday << Qt::Friday; rule.setDaysOfWeek(dasyOfWeek); ev.setRecurrenceRule(rule); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; items << ev; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QtOrganizer::QOrganizerManager::NoError); QOrganizerItemId parentId = items[0].id(); // check if the parent was saved correct items = m_engine->items(QList() << parentId, QOrganizerItemFetchHint(), &errorMap, &error); QCOMPARE(items.size(), 1); QOrganizerEvent result = items[0]; QCOMPARE(result.collectionId(), ev.collectionId()); QCOMPARE(result.startDateTime(), ev.startDateTime()); QCOMPARE(result.endDateTime(), ev.endDateTime()); QCOMPARE(result.displayLabel(), ev.displayLabel()); QCOMPARE(result.description(), ev.description()); QOrganizerRecurrenceRule savedRule = result.recurrenceRule(); QCOMPARE(savedRule.frequency(), rule.frequency()); QCOMPARE(savedRule.daysOfWeek(), rule.daysOfWeek()); QCOMPARE(savedRule.limitType(), QOrganizerRecurrenceRule::NoLimit); QCOMPARE(savedRule.limitDate().isValid(), false); QCOMPARE(savedRule.limitCount(), -1); // edit event dasyOfWeek.remove(Qt::Monday); rule.setDaysOfWeek(dasyOfWeek); result.setRecurrenceRule(rule); items.clear(); items << result; saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QtOrganizer::QOrganizerManager::NoError); // check if the item was updated items = m_engine->items(QList() << parentId, QOrganizerItemFetchHint(), &errorMap, &error); QCOMPARE(items.size(), 1); result = items[0]; QCOMPARE(result.collectionId(), ev.collectionId()); QCOMPARE(result.startDateTime(), ev.startDateTime()); QCOMPARE(result.endDateTime(), ev.endDateTime()); QCOMPARE(result.displayLabel(), ev.displayLabel()); QCOMPARE(result.description(), ev.description()); savedRule = result.recurrenceRule(); QCOMPARE(savedRule.frequency(), rule.frequency()); QCOMPARE(savedRule.daysOfWeek(), rule.daysOfWeek()); QVERIFY(!savedRule.daysOfWeek().contains(Qt::Monday)); QCOMPARE(savedRule.limitType(), QOrganizerRecurrenceRule::NoLimit); QCOMPARE(savedRule.limitDate().isValid(), false); QCOMPARE(savedRule.limitCount(), -1); } void testModifiedRecurrenceDescription() { static QString displayLabelValue = QStringLiteral("testModifiedRecurrenceDescription test"); static QString descriptionValue = QStringLiteral("testModifiedRecurrenceDescription description"); // create a recurrence event QOrganizerEvent ev; ev.setCollectionId(m_collection.id()); ev.setStartDateTime(QDateTime(QDate(2013, 12, 2), QTime(0,0,0))); ev.setEndDateTime(QDateTime(QDate(2013, 12, 2), QTime(0,30,0))); ev.setDisplayLabel(displayLabelValue); ev.setDescription(descriptionValue); QOrganizerRecurrenceRule rule; rule.setFrequency(QOrganizerRecurrenceRule::Daily); rule.setLimit(QDate(2013, 12, 31)); ev.setRecurrenceRule(rule); QSignalSpy itemsAdded(m_engine, SIGNAL(itemsAdded(QList))); QtOrganizer::QOrganizerManager::Error error; QMap errorMap; QList items; items << ev; bool saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QtOrganizer::QOrganizerManager::NoError); QTRY_COMPARE_WITH_TIMEOUT(itemsAdded.count(), 1, 10000); // modify the second ocurrence QOrganizerItemSortOrder sort; QOrganizerItemFetchHint hint; QOrganizerItemCollectionFilter filter; filter.setCollectionId(m_collection.id()); items = m_engine->items(filter, QDateTime(QDate(2013, 12, 1), QTime(0,0,0)), QDateTime(QDate(2013, 12, 31), QTime(0,0,0)), 100, sort, hint, &error); QOrganizerItem ocurr = items.at(1); ocurr.setDescription(QString("%1 modified").arg(descriptionValue)); items.clear(); items << ocurr; saveResult = m_engine->saveItems(&items, QList(), &errorMap, &error); QVERIFY(saveResult); QCOMPARE(error, QtOrganizer::QOrganizerManager::NoError); QVERIFY(errorMap.isEmpty()); QTRY_COMPARE_WITH_TIMEOUT(itemsAdded.count(), 2, 10000); // Fetch items by date and check if the modified recurrence has his own id items = m_engine->items(filter, QDateTime(QDate(2013, 12, 1), QTime(0,0,0)), QDateTime(QDate(2013, 12, 31), QTime(0,0,0)), 100, sort, hint, &error); // Check if the modified item appear on the list QOrganizerItem ocurr1 = items.at(1); QCOMPARE(ocurr1.description(), QString("%1 modified").arg(descriptionValue)); QVERIFY(!ocurr1.id().isNull()); } }; QTEST_MAIN(RecurrenceTest) #include "recurrence-test.moc" qtorganizer5-eds-0.1.1+16.04.20160317/tests/CMakeLists.txt0000644000015600001650000000003312672562647023177 0ustar pbuserpbgroup00000000000000add_subdirectory(unittest) qtorganizer5-eds-0.1.1+16.04.20160317/README0000644000015600001650000000002712672562647020160 0ustar pbuserpbgroup00000000000000canonical pim service. qtorganizer5-eds-0.1.1+16.04.20160317/config.h.in0000644000015600001650000000133112672562647021322 0ustar pbuserpbgroup00000000000000#ifndef __CONFIG_H__ #define __CONFIG_H__ #define TMP_DIR "@TMP_DIR@" #define EVOLUTION_CALENDAR_FACTORY "@EVOLUTION_CALENDAR_FACTORY@" #define EVOLUTION_CALENDAR_SERVICE_NAME "@EVOLUTION_CALENDAR_SERVICE@" #define QORGANIZER_DEV_PATH "@CMAKE_BINARY_DIR@" #define EVOLUTION_API_3_17 @EVOLUTION_API_3_17@ #if EVOLUTION_API_3_17 #define E_CAL_CLIENT_CONNECT_SYNC(SOURCE, SOURCE_TYPE, CANCELLABLE, ERROR) \ e_cal_client_connect_sync(SOURCE, SOURCE_TYPE, -1, CANCELLABLE, ERROR) #else #define E_CAL_CLIENT_CONNECT_SYNC(SOURCE, SOURCE_TYPE, CANCELLABLE, ERROR) \ e_cal_client_connect_sync(SOURCE, SOURCE_TYPE, CANCELLABLE, ERROR) #endif #endif qtorganizer5-eds-0.1.1+16.04.20160317/cmake_uninstall.cmake.in0000644000015600001650000000165412672562647024067 0ustar pbuserpbgroup00000000000000IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") MESSAGE(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") ENDIF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) STRING(REGEX REPLACE "\n" ";" files "${files}") FOREACH(file ${files}) MESSAGE(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") IF(EXISTS "$ENV{DESTDIR}${file}") EXEC_PROGRAM( "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" OUTPUT_VARIABLE rm_out RETURN_VALUE rm_retval ) IF(NOT "${rm_retval}" STREQUAL 0) MESSAGE(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") ENDIF(NOT "${rm_retval}" STREQUAL 0) ELSE(EXISTS "$ENV{DESTDIR}${file}") MESSAGE(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") ENDIF(EXISTS "$ENV{DESTDIR}${file}") ENDFOREACH(file) qtorganizer5-eds-0.1.1+16.04.20160317/COPYING0000644000015600001650000010451312672562647020340 0ustar pbuserpbgroup00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . qtorganizer5-eds-0.1.1+16.04.20160317/buildOnDevice.sh0000755000015600001650000000643612672562647022365 0ustar pbuserpbgroup00000000000000#!/bin/sh CODE_DIR=qtorganizer5-eds USER=phablet USER_ID=32011 PASSWORD=phablet PACKAGE=qtorganizer5-eds BINARY=maliit-server TARGET_IP=127.0.0.1 TARGET_SSH_PORT=2222 TARGET_DEBUG_PORT=3768 RUN_OPTIONS="" # -qmljsdebugger=port:$TARGET_DEBUG_PORT" SETUP=false SUDO="echo $PASSWORD | sudo -S" usage() { echo "usage: run_on_device [OPTIONS]\n" echo "Script to setup a build environment for the shell and sync build and run it on the device\n" echo "OPTIONS:" echo " -s, --setup Setup the build environment" echo "" echo "IMPORTANT:" echo " * Make sure to have the networking and PPAs setup on the device beforehand (phablet-deploy-networking && phablet-ppa-fetch)." echo " * Execute that script from a directory containing a branch of the shell code." exit 1 } exec_with_ssh() { ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -t $USER@$TARGET_IP -p $TARGET_SSH_PORT "bash -ic \"$@\"" } adb_root() { adb root adb wait-for-device } install_ssh_key() { ssh-keygen -R $TARGET_IP HOME_DIR=/home/phablet adb push ~/.ssh/id_rsa.pub $HOME_DIR/.ssh/authorized_keys adb shell chown $USER_ID:$USER_ID $HOME_DIR/.ssh adb shell chown $USER_ID:$USER_ID $HOME_DIR/.ssh/authorized_keys adb shell chmod 700 $HOME_DIR/.ssh adb shell chmod 600 $HOME_DIR/.ssh/authorized_keys adb shell rm /etc/init/ssh.override } install_dependencies() { adb shell apt-get -y install openssh-server adb shell start ssh sleep 2 exec_with_ssh $SUDO apt-get update exec_with_ssh $SUDO apt-get -y install build-essential rsync bzr ccache gdb libglib2.0-bin unzip fakeroot # exec_with_ssh $SUDO add-apt-repository -s -y ppa:phablet-team/ppa exec_with_ssh $SUDO apt-get update exec_with_ssh $SUDO apt-get -y build-dep $PACKAGE exec_with_ssh $SUDO apt-get -y install presage libpinyin-dev } setup_adb_forwarding() { adb forward tcp:$TARGET_SSH_PORT tcp:22 adb forward tcp:$TARGET_DEBUG_PORT tcp:$TARGET_DEBUG_PORT } sync_code() { bzr export --uncommitted --format=dir /tmp/$CODE_DIR rsync -crlOzv -e "ssh -p $TARGET_SSH_PORT -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" /tmp/$CODE_DIR/ $USER@$TARGET_IP:$CODE_DIR/ rm -rf /tmp/$CODE_DIR } build() { # same options as in debian/rules #QMAKE_OPTIONS="-recursive MALIIT_DEFAULT_PROFILE=ubuntu CONFIG+=\\\"debug nodoc enable-presage enable-hunspell enable-pinyin\\\"" exec_with_ssh "mkdir -p $CODE_DIR/build" exec_with_ssh "cd $CODE_DIR/build && cmake ../ -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug && make -j 4" echo "Installing" exec_with_ssh "cd $CODE_DIR/build && " $SUDO " make install/fast" } run() { echo "Ready to run" # exec_with_ssh "$BINARY $RUN_OPTIONS" } set -- `getopt -n$0 -u -a --longoptions="setup,help" "sh" "$@"` # FIXME: giving incorrect arguments does not call usage and exit while [ $# -gt 0 ] do case "$1" in -s|--setup) SETUP=true;; -h|--help) usage;; --) shift;break;; esac shift done adb_root setup_adb_forwarding if $SETUP; then echo "Setting up environment for building shell.." install_ssh_key install_dependencies sync_code else echo "Transferring code.." sync_code echo "Building.." build # echo "Running.." # run fi qtorganizer5-eds-0.1.1+16.04.20160317/organizer/0000755000015600001650000000000012672563136021273 5ustar pbuserpbgroup00000000000000qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-enginedata.cpp0000644000015600001650000000340312672562647027034 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of canonical-pim-service * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "qorganizer-eds-enginedata.h" #include "qorganizer-eds-viewwatcher.h" #include "qorganizer-eds-source-registry.h" QOrganizerEDSEngineData::QOrganizerEDSEngineData() : QSharedData(), m_sourceRegistry(0) { } QOrganizerEDSEngineData::QOrganizerEDSEngineData(const QOrganizerEDSEngineData& other) : QSharedData(other) { } QOrganizerEDSEngineData::~QOrganizerEDSEngineData() { qDeleteAll(m_viewWatchers); m_viewWatchers.clear(); if (m_sourceRegistry) { delete m_sourceRegistry; m_sourceRegistry = 0; } } ViewWatcher* QOrganizerEDSEngineData::watch(const QString &collectionId) { ViewWatcher *vw = m_viewWatchers[collectionId]; if (!vw) { EClient *client = m_sourceRegistry->client(collectionId); vw = new ViewWatcher(collectionId, this, client); m_viewWatchers.insert(collectionId, vw); g_object_unref(client); } return vw; } void QOrganizerEDSEngineData::unWatch(const QString &collectionId) { ViewWatcher *viewW = m_viewWatchers.take(collectionId); if (viewW) { delete viewW; } } qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-removecollectionrequestdata.h0000644000015600001650000000326312672562647032222 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __QORGANIZER_EDS_REMOVECOLLECTIONQUESTDATA_H__ #define __QORGANIZER_EDS_REMOVECOLLECTIONQUESTDATA_H__ #include "qorganizer-eds-requestdata.h" #include class RemoveCollectionRequestData : public RequestData { public: RemoveCollectionRequestData(QOrganizerEDSEngine *engine, QtOrganizer::QOrganizerAbstractRequest *req); ~RemoveCollectionRequestData(); void finish(QtOrganizer::QOrganizerManager::Error error = QtOrganizer::QOrganizerManager::NoError, QtOrganizer::QOrganizerAbstractRequest::State state = QtOrganizer::QOrganizerAbstractRequest::FinishedState); ESource* begin(); void commit(QtOrganizer::QOrganizerManager::Error error = QtOrganizer::QOrganizerManager::NoError); bool remoteDeletable() const; void setRemoteDeletable(bool deletable); private: QList m_pendingCollections; QMap m_errorMap; int m_currentCollection; bool m_remoteDeletable; }; #endif qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-source-registry.cpp0000644000015600001650000003421412672562654030105 0ustar pbuserpbgroup00000000000000#include "qorganizer-eds-source-registry.h" #include "config.h" #include using namespace QtOrganizer; static const QString DEFAULT_COLLECTION_SETTINGS("qtpim/default-colection"); SourceRegistry::SourceRegistry(QObject *parent) : QObject(parent), m_sourceRegistry(0), m_sourceAddedId(0), m_sourceRemovedId(0), m_sourceChangedId(0), m_sourceEnabledId(0), m_sourceDisabledId(0), m_defaultSourceChangedId(0) { } SourceRegistry::~SourceRegistry() { clear(); if (m_sourceRegistry) { g_signal_handler_disconnect(m_sourceRegistry, m_sourceAddedId); g_signal_handler_disconnect(m_sourceRegistry, m_sourceRemovedId); g_signal_handler_disconnect(m_sourceRegistry, m_sourceChangedId); g_signal_handler_disconnect(m_sourceRegistry, m_sourceEnabledId); g_signal_handler_disconnect(m_sourceRegistry, m_sourceDisabledId); g_signal_handler_disconnect(m_sourceRegistry, m_defaultSourceChangedId); g_clear_object(&m_sourceRegistry); } } ESourceRegistry *SourceRegistry::object() const { return m_sourceRegistry; } void SourceRegistry::load() { if (m_sourceRegistry) { return; } clear(); GError *error = 0; m_sourceRegistry = e_source_registry_new_sync(0, &error); if (error) { qWarning() << "Fail to create sourge registry:" << error->message; g_error_free(error); return; } m_sourceAddedId = g_signal_connect(m_sourceRegistry, "source-added", (GCallback) SourceRegistry::onSourceAdded, this); m_sourceChangedId = g_signal_connect(m_sourceRegistry, "source-changed", (GCallback) SourceRegistry::onSourceChanged, this); m_sourceDisabledId = g_signal_connect(m_sourceRegistry, "source-disabled", (GCallback) SourceRegistry::onSourceRemoved, this); m_sourceEnabledId = g_signal_connect(m_sourceRegistry, "source-enabled", (GCallback) SourceRegistry::onSourceAdded, this); m_sourceRemovedId = g_signal_connect(m_sourceRegistry, "source-removed", (GCallback) SourceRegistry::onSourceRemoved, this); m_defaultSourceChangedId = g_signal_connect(m_sourceRegistry, "notify::default-calendar", G_CALLBACK(SourceRegistry::onDefaultCalendarChanged), this); QByteArray defaultId = defaultCollectionId(); GList *sources = e_source_registry_list_sources(m_sourceRegistry, 0); bool foundDefault = false; for(int i = 0, iMax = g_list_length(sources); i < iMax; i++) { ESource *source = E_SOURCE(g_list_nth_data(sources, i)); bool isDefault = (g_strcmp0(defaultId.constData(), e_source_get_uid(source)) == 0); QOrganizerCollection collection = registerSource(source, isDefault); if (isDefault) { foundDefault = true; m_defaultCollection = collection; } } if (!foundDefault) { //fallback to first collection m_defaultCollection = m_collections.first(); } g_list_free_full(sources, g_object_unref); } QtOrganizer::QOrganizerCollection SourceRegistry::defaultCollection() const { return m_defaultCollection; } void SourceRegistry::setDefaultCollection(QtOrganizer::QOrganizerCollection &collection) { if (m_defaultCollection.id() == collection.id()) return; updateDefaultCollection(&collection); QString edsId = m_defaultCollection.id().toString().split(":").last(); m_settings.setValue(DEFAULT_COLLECTION_SETTINGS, edsId); } QOrganizerCollection SourceRegistry::collection(const QString &collectionId) const { return m_collections.value(collectionId); } QList SourceRegistry::collections() const { return m_collections.values(); } QStringList SourceRegistry::collectionsIds() const { return m_collections.keys(); } QList SourceRegistry::collectionsEngineIds() const { return m_collectionsMap.values(); } QOrganizerEDSCollectionEngineId *SourceRegistry::collectionEngineId(const QString &collectionId) const { return m_collectionsMap.value(collectionId, 0); } ESource *SourceRegistry::source(const QString &collectionId) const { return m_sources[collectionId]; } QOrganizerCollection SourceRegistry::collection(ESource *source) const { QString collectionId = findCollection(source); return m_collections[collectionId]; } QOrganizerCollection SourceRegistry::insert(ESource *source) { return registerSource(source); } void SourceRegistry::remove(ESource *source) { QString collectionId = findCollection(source); remove(collectionId); } void SourceRegistry::remove(const QString &collectionId) { if (collectionId.isEmpty()) { return; } QOrganizerCollection collection = m_collections.take(collectionId); if (!collection.id().isNull()) { Q_EMIT sourceRemoved(collectionId); m_collectionsMap.remove(collectionId); g_object_unref(m_sources.take(collectionId)); EClient *client = m_clients.take(collectionId); if (client) { g_object_unref(client); } } // update default collection if necessary if (m_defaultCollection.id().toString() == collectionId) { m_defaultCollection = QOrganizerCollection(); setDefaultCollection(m_collections.first()); } } EClient* SourceRegistry::client(const QString &collectionId) { if (collectionId.isEmpty()) { return 0; } EClient *client = m_clients.value(collectionId, 0); if (!client) { QOrganizerEDSCollectionEngineId *eid = m_collectionsMap[collectionId]; if (eid) { GError *gError = 0; client = E_CAL_CLIENT_CONNECT_SYNC(eid->m_esource, eid->m_sourceType, 0, &gError); if (gError) { qWarning() << "Fail to connect with client" << gError->message; g_error_free(gError); } else { // If the client is read only update the collection if (e_client_is_readonly(client)) { QOrganizerCollection &c = m_collections[collectionId]; c.setExtendedMetaData(COLLECTION_READONLY_METADATA, true); Q_EMIT sourceUpdated(collectionId); } m_clients.insert(collectionId, client); } } } if (client) { g_object_ref(client); } return client; } void SourceRegistry::clear() { Q_FOREACH(ESource *source, m_sources.values()) { g_object_unref(source); } Q_FOREACH(EClient *client, m_clients.values()) { g_object_unref(client); } m_sources.clear(); m_collections.clear(); m_collectionsMap.clear(); m_clients.clear(); } QString SourceRegistry::findCollection(ESource *source) const { QMap::ConstIterator i = m_sources.constBegin(); while (i != m_sources.constEnd()) { if (e_source_equal(source, i.value())) { return i.key(); } i++; } return QString(); } QOrganizerCollection SourceRegistry::registerSource(ESource *source, bool isDefault) { QString collectionId = findCollection(source); if (collectionId.isEmpty()) { bool isEnabled = e_source_get_enabled(source); bool isCalendar = e_source_has_extension(source, E_SOURCE_EXTENSION_CALENDAR); bool isTaskList = e_source_has_extension(source, E_SOURCE_EXTENSION_TASK_LIST); bool isMemoList = e_source_has_extension(source, E_SOURCE_EXTENSION_MEMO_LIST); bool isAlarms = e_source_has_extension(source, E_SOURCE_EXTENSION_ALARMS); if ( isEnabled && (isCalendar || isTaskList || isMemoList || isAlarms)) { QOrganizerEDSCollectionEngineId *edsId = 0; QOrganizerCollection collection = parseSource(source, isDefault, &edsId); QString collectionId = collection.id().toString(); if (!m_collectionsMap.contains(collectionId)) { m_collections.insert(collectionId, collection); m_collectionsMap.insert(collectionId, edsId); m_sources.insert(collectionId, source); g_object_ref(source); Q_EMIT sourceAdded(collectionId); } else { Q_ASSERT(false); } return collection; } return QOrganizerCollection(); } else { return m_collections.value(collectionId); } } void SourceRegistry::updateDefaultCollection(QOrganizerCollection *collection) { if (m_defaultCollection.id() != collection->id()) { QString oldDefaultCollectionId = m_defaultCollection.id().toString(); collection->setExtendedMetaData(COLLECTION_DEFAULT_METADATA, true); m_defaultCollection = *collection; Q_EMIT sourceUpdated(m_defaultCollection.id().toString()); if (m_collections.contains(oldDefaultCollectionId)) { QOrganizerCollection &old = m_collections[oldDefaultCollectionId]; old.setExtendedMetaData(COLLECTION_DEFAULT_METADATA, false); Q_EMIT sourceUpdated(oldDefaultCollectionId); } } } QOrganizerCollection SourceRegistry::parseSource(ESource *source, bool isDefault, QOrganizerEDSCollectionEngineId **edsId) { *edsId = new QOrganizerEDSCollectionEngineId(source); QOrganizerCollectionId id(*edsId); QOrganizerCollection collection; collection.setId(id); updateCollection(&collection, isDefault, source); return collection; } QByteArray SourceRegistry::defaultCollectionId() const { QVariant id = m_settings.value(DEFAULT_COLLECTION_SETTINGS); if (id.isValid()) { return id.toString().toUtf8(); } // fallback to eds default collection ESource *defaultCalendarSource = e_source_registry_ref_default_calendar(m_sourceRegistry); QString eId = QString::fromUtf8(e_source_get_uid(defaultCalendarSource)); g_object_unref(defaultCalendarSource); return eId.toUtf8(); } void SourceRegistry::onSourceAdded(ESourceRegistry *registry, ESource *source, SourceRegistry *self) { Q_UNUSED(registry); self->insert(source); } void SourceRegistry::onSourceChanged(ESourceRegistry *registry, ESource *source, SourceRegistry *self) { Q_UNUSED(registry); QString collectionId = self->findCollection(source); if (!collectionId.isEmpty() && self->m_collections.contains(collectionId)) { QOrganizerCollection &collection = self->m_collections[collectionId]; self->updateCollection(&collection, self->m_defaultCollection.id() == collection.id(), source, self->m_clients.value(collectionId)); Q_EMIT self->sourceUpdated(collectionId); } else { qWarning() << "Source changed not found"; } } void SourceRegistry::onSourceRemoved(ESourceRegistry *registry, ESource *source, SourceRegistry *self) { Q_UNUSED(registry); self->remove(source); } void SourceRegistry::onDefaultCalendarChanged(ESourceRegistry *registry, GParamSpec *pspec, SourceRegistry *self) { Q_UNUSED(registry); Q_UNUSED(pspec); if (self->m_settings.value(DEFAULT_COLLECTION_SETTINGS).isValid()) { // we are using client confinguration return; } ESource *defaultCalendar = e_source_registry_ref_default_calendar(self->m_sourceRegistry); if (!defaultCalendar) return; QString collectionId = self->findCollection(defaultCalendar); if (!collectionId.isEmpty()) { QOrganizerCollection &collection = self->m_collections[collectionId]; self->updateDefaultCollection(&collection); } g_object_unref(defaultCalendar); } void SourceRegistry::updateCollection(QOrganizerCollection *collection, bool isDefault, ESource *source, EClient *client) { // name collection->setMetaData(QOrganizerCollection::KeyName, QString::fromUtf8(e_source_get_display_name(source))); // extension ESourceBackend *extCalendar; if (e_source_has_extension(source, E_SOURCE_EXTENSION_TASK_LIST)) { extCalendar = E_SOURCE_BACKEND(e_source_get_extension(source, E_SOURCE_EXTENSION_TASK_LIST)); collection->setExtendedMetaData(COLLECTION_CALLENDAR_TYPE_METADATA, E_SOURCE_EXTENSION_TASK_LIST); } else if (e_source_has_extension(source, E_SOURCE_EXTENSION_MEMO_LIST)) { extCalendar = E_SOURCE_BACKEND(e_source_get_extension(source, E_SOURCE_EXTENSION_MEMO_LIST)); collection->setExtendedMetaData(COLLECTION_CALLENDAR_TYPE_METADATA, E_SOURCE_EXTENSION_MEMO_LIST); } else { extCalendar = E_SOURCE_BACKEND(e_source_get_extension(source, E_SOURCE_EXTENSION_CALENDAR)); collection->setExtendedMetaData(COLLECTION_CALLENDAR_TYPE_METADATA, E_SOURCE_EXTENSION_CALENDAR); } // color const gchar *color = e_source_selectable_get_color(E_SOURCE_SELECTABLE(extCalendar)); collection->setMetaData(QOrganizerCollection::KeyColor, QString::fromUtf8(color)); // selected bool selected = (e_source_selectable_get_selected(E_SOURCE_SELECTABLE(extCalendar)) == TRUE); collection->setExtendedMetaData(COLLECTION_SELECTED_METADATA, selected); // writable bool writable = e_source_get_writable(source); // the source and client need to be writable if (client) { writable = writable && !e_client_is_readonly(client); } collection->setExtendedMetaData(COLLECTION_READONLY_METADATA, !writable); // default collection->setExtendedMetaData(COLLECTION_DEFAULT_METADATA, isDefault); } qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-removebyidrequestdata.cpp0000644000015600001650000001022612672562647031346 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "qorganizer-eds-removebyidrequestdata.h" #include "qorganizer-eds-engineid.h" #include "qorganizer-eds-enginedata.h" #include #include using namespace QtOrganizer; RemoveByIdRequestData::RemoveByIdRequestData(QOrganizerEDSEngine *engine, QtOrganizer::QOrganizerAbstractRequest *req) : RequestData(engine, req), m_sessionStaterd(0), m_currentCompIds(0) { Q_FOREACH(const QOrganizerItemId &id, request()->itemIds()) { QString strId = id.toString(); QString collectionId; if (strId.contains("/")) { collectionId = strId.split("/").first(); QSet ids = m_pending.value(collectionId); ids << id; m_pending.insert(collectionId, ids); } } } RemoveByIdRequestData::~RemoveByIdRequestData() { } void RemoveByIdRequestData::finish(QtOrganizer::QOrganizerManager::Error error, QtOrganizer::QOrganizerAbstractRequest::State state) { e_client_refresh_sync(m_client, 0, 0); QOrganizerManagerEngine::updateItemRemoveByIdRequest(request(), error, QMap(), state); //The signal will be fired by the view watcher. Check ViewWatcher::onObjectsRemoved //emitChangeset(&m_changeSet); RequestData::finish(error, state); } GSList *RemoveByIdRequestData::compIds() const { return m_currentCompIds; } void RemoveByIdRequestData::commit() { Q_ASSERT(m_sessionStaterd); QOrganizerManagerEngine::updateItemRemoveByIdRequest(request(), QtOrganizer::QOrganizerManager::NoError, QMap(), QOrganizerAbstractRequest::ActiveState); reset(); } GSList *RemoveByIdRequestData::parseIds(QSet iids) { GSList *ids = 0; Q_FOREACH(const QOrganizerItemId &iid, iids) { ECalComponentId *id = QOrganizerEDSEngineId::toComponentIdObject(iid); if (id) { ids = g_slist_append(ids, id); } } return ids; } QString RemoveByIdRequestData::next() { Q_ASSERT(!m_sessionStaterd); if (m_pending.count() > 0) { m_sessionStaterd = true; m_currentCollectionId = m_pending.keys().first(); m_currentIds = m_pending[m_currentCollectionId]; m_currentCompIds = parseIds(m_currentIds); m_pending.remove(m_currentCollectionId); return m_currentCollectionId; } return QString(QString::null); } void RemoveByIdRequestData::reset() { m_currentIds.clear(); m_currentCollectionId = QString(QString::null); if (m_currentCompIds) { g_slist_free_full(m_currentCompIds, (GDestroyNotify)e_cal_component_free_id); m_currentCompIds = 0; } m_sessionStaterd = false; } void RemoveByIdRequestData::cancel() { Q_ASSERT(m_sessionStaterd); RequestData::cancel(); clear(); } void RemoveByIdRequestData::clear() { reset(); m_pending.clear(); setClient(0); } QString RemoveByIdRequestData::collectionId() const { return m_currentCollectionId; } qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-collection-engineid.cpp0000644000015600001650000000737612672562647030665 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of canonical-pim-service * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "qorganizer-eds-collection-engineid.h" #include "qorganizer-eds-engineid.h" #include QOrganizerEDSCollectionEngineId::QOrganizerEDSCollectionEngineId(ESource *source) : m_esource(source) { g_object_ref(m_esource); m_collectionId = QString::fromUtf8(e_source_get_uid(m_esource)); if (e_source_has_extension(m_esource, E_SOURCE_EXTENSION_CALENDAR)) { m_sourceType = E_CAL_CLIENT_SOURCE_TYPE_EVENTS; } else if (e_source_has_extension(m_esource, E_SOURCE_EXTENSION_TASK_LIST)) { m_sourceType = E_CAL_CLIENT_SOURCE_TYPE_TASKS; } else if (e_source_has_extension(m_esource, E_SOURCE_EXTENSION_MEMO_LIST)) { m_sourceType = E_CAL_CLIENT_SOURCE_TYPE_MEMOS; } else { qWarning() << "Source extension not supported"; Q_ASSERT(false); } } QOrganizerEDSCollectionEngineId::QOrganizerEDSCollectionEngineId() : QOrganizerCollectionEngineId(), m_esource(0) { } QOrganizerEDSCollectionEngineId::QOrganizerEDSCollectionEngineId(const QOrganizerEDSCollectionEngineId& other) : QOrganizerCollectionEngineId(), m_collectionId(other.m_collectionId), m_esource(other.m_esource), m_sourceType(other.m_sourceType) { if (m_esource) { g_object_ref(m_esource); } } QOrganizerEDSCollectionEngineId::QOrganizerEDSCollectionEngineId(const QString& idString) : QOrganizerCollectionEngineId(), m_esource(0) { // separate engine id part, if full id given m_collectionId = idString.contains(":") ? idString.mid(idString.lastIndexOf(":")+1) : idString; } QOrganizerEDSCollectionEngineId::~QOrganizerEDSCollectionEngineId() { if (m_esource) { g_clear_object(&m_esource); } } bool QOrganizerEDSCollectionEngineId::isEqualTo(const QOrganizerCollectionEngineId* other) const { // note: we don't need to check the managerUri because this function is not called // if the managerUris are different. if (m_collectionId != static_cast(other)->m_collectionId) return false; return true; } bool QOrganizerEDSCollectionEngineId::isLessThan(const QOrganizerCollectionEngineId* other) const { // order by collection, then by item in collection. const QOrganizerEDSCollectionEngineId* otherPtr = static_cast(other); if (m_collectionId < otherPtr->m_collectionId) return true; return false; } QString QOrganizerEDSCollectionEngineId::managerUri() const { return QOrganizerEDSEngineId::managerUriStatic(); } QString QOrganizerEDSCollectionEngineId::toString() const { return m_collectionId; } QOrganizerEDSCollectionEngineId* QOrganizerEDSCollectionEngineId::clone() const { return new QOrganizerEDSCollectionEngineId(m_esource); } uint QOrganizerEDSCollectionEngineId::hash() const { return qHash(m_collectionId); } #ifndef QT_NO_DEBUG_STREAM QDebug& QOrganizerEDSCollectionEngineId::debugStreamOut(QDebug& dbg) const { dbg.nospace() << "QOrganizerEDSCollectionEngineId(" << managerUri() << "," << m_collectionId << ")"; return dbg.maybeSpace(); } #endif qtorganizer5-eds-0.1.1+16.04.20160317/organizer/eds.json0000644000015600001650000000003212672562647022742 0ustar pbuserpbgroup00000000000000{ "Keys": [ "eds" ] } qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-fetchrequestdata.cpp0000644000015600001650000002432412672562647030276 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "qorganizer-eds-fetchrequestdata.h" #include "qorganizer-eds-engineid.h" #include #include #include #include #include using namespace QtOrganizer; FetchRequestData::FetchRequestData(QOrganizerEDSEngine *engine, QStringList collections, QOrganizerAbstractRequest *req) : RequestData(engine, req), m_parseListener(0), m_currentComponents(0) { // filter collections related with the query m_collections = filterCollections(collections); } FetchRequestData::~FetchRequestData() { delete m_parseListener; Q_FOREACH(GSList *components, m_components.values()) { g_slist_free_full(components, (GDestroyNotify)icalcomponent_free); } m_components.clear(); } QString FetchRequestData::nextCollection() { if (m_currentComponents) { m_components.insert(m_current, m_currentComponents); m_currentComponents = 0; } m_current = ""; setClient(0); if (m_collections.size()) { m_current = m_collections.takeFirst(); return m_current; } else { return QString(); } } QString FetchRequestData::nextParentId() { QString nextId; if (!m_currentParentIds.isEmpty()) { nextId = m_currentParentIds.values().first(); m_currentParentIds.remove(nextId); } return nextId; } QString FetchRequestData::collection() const { return m_current; } time_t FetchRequestData::startDate() const { QDateTime startDate = request()->startDate(); if (!startDate.isValid()) { QDate currentDate = QDate::currentDate(); startDate.setTime(QTime(0, 0, 0)); startDate.setDate(QDate(currentDate.year(), 1, 1)); qWarning() << "Start date is invalid using " << startDate; } return startDate.toTime_t(); } time_t FetchRequestData::endDate() const { QDateTime endDate = request()->endDate(); if (!endDate.isValid()) { QDate currentDate = QDate::currentDate(); endDate.setTime(QTime(0, 0, 0)); endDate.setDate(QDate(currentDate.year()+1, 1, 1)); qWarning() << "End date is invalid using " << endDate; } return endDate.toTime_t(); } bool FetchRequestData::hasDateInterval() const { if (!filterIsValid()) { return false; } QDateTime endDate = request()->endDate(); QDateTime startDate = request()->startDate(); return (endDate.isValid() && startDate.isValid()); } bool FetchRequestData::filterIsValid() const { return (request()->filter().type() != QOrganizerItemFilter::InvalidFilter); } void FetchRequestData::cancel() { if (m_parseListener) { delete m_parseListener; m_parseListener = 0; } RequestData::cancel(); } void FetchRequestData::compileCurrentIds() { for(GSList *e = m_currentComponents; e != NULL; e = e->next) { icalcomponent *icalComp = static_cast(e->data); if (e_cal_util_component_has_recurrences (icalComp)) { m_currentParentIds.insert(QString::fromUtf8(icalcomponent_get_uid(icalComp))); } } } void FetchRequestData::finish(QOrganizerManager::Error error, QOrganizerAbstractRequest::State state) { if (!m_components.isEmpty()) { m_parseListener = new FetchRequestDataParseListener(this, error, state); QOrganizerItemFetchRequest *req = request(); if (req) { parent()->parseEventsAsync(m_components, true, req->fetchHint().detailTypesHint(), m_parseListener, SLOT(onParseDone(QList))); return; } } finishContinue(error, state); } void FetchRequestData::finishContinue(QOrganizerManager::Error error, QOrganizerAbstractRequest::State state) { if (m_parseListener) { m_parseListener->deleteLater(); m_parseListener = 0; } Q_FOREACH(GSList *components, m_components.values()) { g_slist_free_full(components, (GDestroyNotify)icalcomponent_free); } m_components.clear(); QOrganizerItemFetchRequest *req = request(); if (req) { QOrganizerManagerEngine::updateItemFetchRequest(req, m_results, error, state); } // TODO: emit changeset??? RequestData::finish(error, state); } void FetchRequestData::appendResult(icalcomponent *comp) { m_currentComponents = g_slist_append(m_currentComponents, comp); } void FetchRequestData::appendDeatachedResult(icalcomponent *comp) { const gchar *uid; struct icaltimetype rid; uid = icalcomponent_get_uid(comp); rid = icalcomponent_get_recurrenceid(comp); for(GSList *e=m_currentComponents; e != NULL; e = e->next) { icalcomponent *ical = static_cast(e->data); if ((g_strcmp0(uid, icalcomponent_get_uid(ical)) == 0) && (icaltime_compare(rid, icalcomponent_get_recurrenceid(ical)) == 0)) { // replace instance event icalcomponent_free (ical); e->data = icalcomponent_new_clone(comp); QString itemId = QString("%1/%2#%3") .arg(QString(m_current).replace(QOrganizerEDSEngineId::managerUriStatic() + ":", "")) .arg(QString::fromUtf8(uid)) .arg(QString::fromUtf8(icaltime_as_ical_string(rid))); m_deatachedIds.append(itemId); break; } } } int FetchRequestData::appendResults(QList results) { int count = 0; QOrganizerItemFetchRequest *req = request(); QOrganizerItemFilter filter = req->filter(); QList sorting = req->sorting(); Q_FOREACH(QOrganizerItem item, results) { if (QOrganizerManagerEngine::testFilter(filter, item)) { QOrganizerManagerEngine::addSorted(&m_results, item, sorting); count++; } } return count; } QString FetchRequestData::dateFilter() { QOrganizerItemFetchRequest *r = request(); if (r->filter().type() == QOrganizerItemFilter::InvalidFilter) { qWarning("Query for events with invalid filter type"); return QStringLiteral(""); } QDateTime startDate = r->startDate(); QDateTime endDate = r->endDate(); if (!startDate.isValid() || !endDate.isValid()) { return QStringLiteral("#t"); // match all } gchar *startDateStr = isodate_from_time_t(startDate.toTime_t()); gchar *endDateStr = isodate_from_time_t(endDate.toTime_t()); QString query = QString("(occur-in-time-range? " "(make-time \"%1\") (make-time \"%2\"))") .arg(startDateStr) .arg(endDateStr); g_free(startDateStr); g_free(endDateStr); return query; } QStringList FetchRequestData::filterCollections(const QStringList &collections) const { QStringList result; if (filterIsValid()) { QOrganizerItemFilter f = request()->filter(); QStringList cFilters = collectionsFromFilter(f); if (cFilters.contains("*") || cFilters.isEmpty()) { result = collections; } else { Q_FOREACH(const QString &f, collections) { if (cFilters.contains(f)) { result << f; } } } } return result; } QStringList FetchRequestData::collectionsFromFilter(const QOrganizerItemFilter &f) const { QStringList result; switch(f.type()) { case QOrganizerItemFilter::CollectionFilter: { QOrganizerItemCollectionFilter cf = static_cast(f); Q_FOREACH(const QOrganizerCollectionId &id, cf.collectionIds()) { result << id.toString(); } break; } case QOrganizerItemFilter::IntersectionFilter: { QOrganizerItemIntersectionFilter intersec = static_cast(f); Q_FOREACH(const QOrganizerItemFilter &f, intersec.filters()) { result << collectionsFromFilter(f); } break; } case QOrganizerItemFilter::UnionFilter: // TODO: better handle union filters, for now they will consider all collections result << "*"; break; default: break; } return result; } FetchRequestDataParseListener::FetchRequestDataParseListener(FetchRequestData *data, QOrganizerManager::Error error, QOrganizerAbstractRequest::State state) : QObject(0), m_data(data), m_error(error), m_state(state) { } void FetchRequestDataParseListener::onParseDone(QList results) { m_data->appendResults(results); m_data->finishContinue(m_error, m_state); } qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-engineid.h0000644000015600001650000000444612672562647026174 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of canonical-pim-service * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __QORGANIZER_EDS_ENGINEID_H__ #define __QORGANIZER_EDS_ENGINEID_H__ #include "qorganizer-eds-collection-engineid.h" #include #include #include class QOrganizerEDSEngineId : public QtOrganizer::QOrganizerItemEngineId { public: QOrganizerEDSEngineId(); QOrganizerEDSEngineId(const QString& collectionId, const QString& id); ~QOrganizerEDSEngineId(); QOrganizerEDSEngineId(const QOrganizerEDSEngineId& other); QOrganizerEDSEngineId(const QString& idString); bool isEqualTo(const QtOrganizer::QOrganizerItemEngineId* other) const; bool isLessThan(const QtOrganizer::QOrganizerItemEngineId* other) const; QString managerUri() const; QtOrganizer::QOrganizerItemEngineId* clone() const; QString toString() const; uint hash() const; #ifndef QT_NO_DEBUG_STREAM QDebug& debugStreamOut(QDebug& dbg) const; #endif static QString managerUriStatic(); static QString managerNameStatic(); static QString toComponentId(const QtOrganizer::QOrganizerItemId &itemId, QString *rid); static QString toComponentId(const QString &itemId, QString *rid); static ECalComponentId *toComponentIdObject(const QtOrganizer::QOrganizerItemId &itemId); static QOrganizerEDSEngineId *fromComponentId(const QString &cId, ECalComponentId *id, QOrganizerEDSEngineId **parentId); private: QString m_collectionId; QString m_itemId; friend class QOrganizerEDSEngine; }; #endif qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-collection-engineid.h0000644000015600001650000000355112672562647030321 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of canonical-pim-service * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __QORGANIZER_EDS_COLLECTION_ENGINEID_H__ #define __QORGANIZER_EDS_COLLECTION_ENGINEID_H__ #include #include #include class QOrganizerEDSCollectionEngineId : public QtOrganizer::QOrganizerCollectionEngineId { public: QOrganizerEDSCollectionEngineId(); QOrganizerEDSCollectionEngineId(const QOrganizerEDSCollectionEngineId& other); QOrganizerEDSCollectionEngineId(const QString& idString); QOrganizerEDSCollectionEngineId(ESource *source); ~QOrganizerEDSCollectionEngineId(); bool isEqualTo(const QtOrganizer::QOrganizerCollectionEngineId* other) const; bool isLessThan(const QtOrganizer::QOrganizerCollectionEngineId* other) const; QString managerUri() const; QOrganizerEDSCollectionEngineId *clone() const; QString toString() const; uint hash() const; #ifndef QT_NO_DEBUG_STREAM QDebug& debugStreamOut(QDebug& dbg) const; #endif private: QString m_collectionId; ESource *m_esource; ECalClientSourceType m_sourceType; friend class SourceRegistry; //friend class ViewWatcher; friend class QOrganizerEDSEngine; }; #endif qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-savecollectionrequestdata.h0000644000015600001650000000413112672562647031656 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __QORGANIZER_EDS_SAVECOLLECTIONREQUESTDATA_H__ #define __QORGANIZER_EDS_SAVECOLLECTIONREQUESTDATA_H__ #include "qorganizer-eds-requestdata.h" class SaveCollectionRequestData : public RequestData { public: SaveCollectionRequestData(QOrganizerEDSEngine *engine, QtOrganizer::QOrganizerAbstractRequest *req); ~SaveCollectionRequestData(); void finish(QtOrganizer::QOrganizerManager::Error error = QtOrganizer::QOrganizerManager::NoError, QtOrganizer::QOrganizerAbstractRequest::State state = QtOrganizer::QOrganizerAbstractRequest::FinishedState); bool isNew(int index) const; bool prepareToCreate(); bool prepareToUpdate(); void setRegistry(ESourceRegistry *registry); ESourceRegistry *registry() const; GList *sourcesToCreate() const; void commitSourceCreated(); void commitSourceUpdated(ESource *source, QtOrganizer::QOrganizerManager::Error error = QtOrganizer::QOrganizerManager::NoError); ESource *nextSourceToUpdate(); private: GList *m_currentSources; ESourceRegistry *m_registry; QMap m_errorMap; QMap m_results; QMap m_sources; QMap m_sourcesToCreate; QMap m_sourcesToUpdate; QtOrganizer::QOrganizerCollectionChangeSet m_changeSet; void parseCollections(); }; #endif qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-requestdata.cpp0000644000015600001650000000753612672562647027272 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "qorganizer-eds-requestdata.h" #include #include #include #include #include using namespace QtOrganizer; int RequestData::m_instanceCount = 0; RequestData::RequestData(QOrganizerEDSEngine *engine, QtOrganizer::QOrganizerAbstractRequest *req) : m_parent(engine), m_client(0), m_finished(false), m_req(req) { QOrganizerManagerEngine::updateRequestState(req, QOrganizerAbstractRequest::ActiveState); m_cancellable = g_cancellable_new(); m_parent->m_runningRequests.insert(req, this); m_instanceCount++; } RequestData::~RequestData() { if (m_cancellable) { g_clear_object(&m_cancellable); } if (m_client) { g_clear_object(&m_client); } m_instanceCount--; } GCancellable* RequestData::cancellable() const { return m_cancellable; } bool RequestData::isLive() const { return (!m_req.isNull() && (m_req->state() == QOrganizerAbstractRequest::ActiveState)); } ECalClient *RequestData::client() const { return E_CAL_CLIENT(m_client); } QOrganizerEDSEngine *RequestData::parent() const { return m_parent; } void RequestData::cancel() { if (m_cancellable) { g_cancellable_cancel(m_cancellable); } if (isLive()) { finish(QOrganizerManager::UnspecifiedError, QOrganizerAbstractRequest::CanceledState); } } void RequestData::wait(int msec) { QMutexLocker locker(&m_waiting); QEventLoop *loop = new QEventLoop; QOrganizerAbstractRequest *req = m_req.data(); QObject::connect(req, &QOrganizerAbstractRequest::stateChanged, [req, loop](QOrganizerAbstractRequest::State newState) { if (newState != QOrganizerAbstractRequest::ActiveState) { loop->quit(); } }); QTimer timeout; if (msec > 0) { timeout.setInterval(msec); timeout.setSingleShot(true); timeout.start(); } loop->exec(QEventLoop::AllEvents|QEventLoop::WaitForMoreEvents); delete loop; } bool RequestData::isWaiting() { bool result = true; if (m_waiting.tryLock()) { result = false; m_waiting.unlock(); } return result; } int RequestData::instanceCount() { return m_instanceCount; } void RequestData::deleteLater() { if (isWaiting()) { // still running return; } if (!m_parent.isNull()) { m_parent->m_runningRequests.remove(m_req); } delete this; } void RequestData::finish(QOrganizerManager::Error error, QOrganizerAbstractRequest::State state) { Q_UNUSED(error); Q_UNUSED(state); m_finished = true; // When cancelling an operation the callback passed for the async function // will be called and the request data object will be destroyed there if (state != QOrganizerAbstractRequest::CanceledState) { deleteLater(); } } void RequestData::setClient(EClient *client) { if (m_client == client) { return; } if (m_client) { g_clear_object(&m_client); } if (client) { m_client = client; g_object_ref(m_client); } } qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-engineid.cpp0000644000015600001650000001167312672562647026527 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of canonical-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "qorganizer-eds-engineid.h" #include #include using namespace QtOrganizer; QOrganizerEDSEngineId::QOrganizerEDSEngineId() : QOrganizerItemEngineId() { } QOrganizerEDSEngineId::QOrganizerEDSEngineId(const QString &collectionId, const QString &id) : QOrganizerItemEngineId() { if (!collectionId.isNull() && !collectionId.isEmpty()) { m_collectionId = collectionId.contains(":") ? collectionId.mid(collectionId.lastIndexOf(":")+1) : collectionId; } if (!id.isNull() && !id.isEmpty()) { m_itemId = id.contains(":") ? id.mid(id.lastIndexOf(":")+1) : id; } } QOrganizerEDSEngineId::~QOrganizerEDSEngineId() { } QOrganizerEDSEngineId::QOrganizerEDSEngineId(const QOrganizerEDSEngineId& other) : QOrganizerItemEngineId(), m_collectionId(other.m_collectionId), m_itemId(other.m_itemId) { } QOrganizerEDSEngineId::QOrganizerEDSEngineId(const QString& idString) : QOrganizerItemEngineId() { QString edsIdPart = idString.contains(":") ? idString.mid(idString.lastIndexOf(":")+1) : idString; QStringList idParts = edsIdPart.split("/"); Q_ASSERT(idParts.count() == 2); m_collectionId = idParts.first(); m_itemId = idParts.last(); } bool QOrganizerEDSEngineId::isEqualTo(const QOrganizerItemEngineId* other) const { // note: we don't need to check the collectionId because itemIds in the memory // engine are unique regardless of which collection the item is in; also, we // don't need to check the managerUri, because this function is not called if // the managerUris don't match. if (m_itemId != static_cast(other)->m_itemId) return false; return true; } bool QOrganizerEDSEngineId::isLessThan(const QOrganizerItemEngineId* other) const { // order by collection, then by item in collection. const QOrganizerEDSEngineId* otherPtr = static_cast(other); if (m_collectionId < otherPtr->m_collectionId) return true; if (m_collectionId == otherPtr->m_collectionId) return (m_itemId < otherPtr->m_itemId); return false; } QString QOrganizerEDSEngineId::managerUri() const { return managerUriStatic(); } QString QOrganizerEDSEngineId::toString() const { return QString("%1/%2").arg(m_collectionId).arg(m_itemId); } QOrganizerItemEngineId* QOrganizerEDSEngineId::clone() const { return new QOrganizerEDSEngineId(m_collectionId, m_itemId); } uint QOrganizerEDSEngineId::hash() const { return qHash(m_itemId); } #ifndef QT_NO_DEBUG_STREAM QDebug& QOrganizerEDSEngineId::debugStreamOut(QDebug& dbg) const { dbg.nospace() << "QOrganizerEDSEngineId(" << managerNameStatic() << ", " << m_collectionId << ", " << m_itemId << ")"; return dbg.maybeSpace(); } #endif QString QOrganizerEDSEngineId::managerNameStatic() { return QStringLiteral("eds"); } QString QOrganizerEDSEngineId::managerUriStatic() { return QStringLiteral("qtorganizer:eds:"); } QString QOrganizerEDSEngineId::toComponentId(const QtOrganizer::QOrganizerItemId &itemId, QString *rid) { return toComponentId(itemId.toString(), rid); } QString QOrganizerEDSEngineId::toComponentId(const QString &itemId, QString *rid) { QStringList ids = itemId.split("/").last().split("#"); if (ids.size() == 2) { *rid = ids[1]; } return ids[0]; } ECalComponentId *QOrganizerEDSEngineId::toComponentIdObject(const QOrganizerItemId &itemId) { QString rId; QString cId = toComponentId(itemId, &rId); ECalComponentId *id = g_new0(ECalComponentId, 1); id->uid = g_strdup(cId.toUtf8().data()); if (rId.isEmpty()) { id->rid = NULL; } else { id->rid = g_strdup(rId.toUtf8().data()); } return id; } QOrganizerEDSEngineId *QOrganizerEDSEngineId::fromComponentId(const QString &cId, ECalComponentId *id, QOrganizerEDSEngineId **parentId) { QString iId = QString::fromUtf8(id->uid); QString rId = QString::fromUtf8(id->rid); if(!rId.isEmpty()) { *parentId = new QOrganizerEDSEngineId(cId, iId); iId += "#" + rId; } return new QOrganizerEDSEngineId(cId, iId); } qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-fetchocurrencedata.h0000644000015600001650000000262312672562647030236 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __QORGANIZER_EDS_FETCHOCURRENCEDATA_H__ #define __QORGANIZER_EDS_FETCHOCURRENCEDATA_H__ #include "qorganizer-eds-requestdata.h" #include class FetchOcurrenceData : public RequestData { public: FetchOcurrenceData(QOrganizerEDSEngine *engine, QtOrganizer::QOrganizerAbstractRequest *req); ~FetchOcurrenceData(); time_t startDate() const; time_t endDate() const; void finish(QtOrganizer::QOrganizerManager::Error error = QtOrganizer::QOrganizerManager::NoError, QtOrganizer::QOrganizerAbstractRequest::State state = QtOrganizer::QOrganizerAbstractRequest::FinishedState); void appendResult(icalcomponent *comp); private: GSList *m_components; }; #endif qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-savecollectionrequestdata.cpp0000644000015600001650000001700412672562647032214 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "qorganizer-eds-savecollectionrequestdata.h" #include "qorganizer-eds-enginedata.h" #include "qorganizer-eds-source-registry.h" #include #include #include #include using namespace QtOrganizer; SaveCollectionRequestData::SaveCollectionRequestData(QOrganizerEDSEngine *engine, QtOrganizer::QOrganizerAbstractRequest *req) : RequestData(engine, req), m_currentSources(0), m_registry(0) { parseCollections(); } SaveCollectionRequestData::~SaveCollectionRequestData() { if (m_registry) { g_object_unref(m_registry); m_registry = 0; } if (m_currentSources) { g_list_free_full(m_currentSources, g_object_unref); m_currentSources = 0; } } void SaveCollectionRequestData::finish(QtOrganizer::QOrganizerManager::Error error, QtOrganizer::QOrganizerAbstractRequest::State state) { QOrganizerManagerEngine::updateCollectionSaveRequest(request(), m_results.values(), error, m_errorMap, state); // changes will be fired by source-registry m_changeSet.clearAll(); RequestData::finish(error, state); } void SaveCollectionRequestData::commitSourceCreated() { GList *i = g_list_first(m_currentSources); for(; i != 0; i = i->next) { ESource *source = E_SOURCE(i->data); SourceRegistry *registry = parent()->d->m_sourceRegistry; Q_ASSERT(registry); QOrganizerCollection collection = registry->insert(source); bool isDefault = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(source), "is-default")); if (isDefault) { registry->setDefaultCollection(collection); } m_results.insert(m_sources.key(source), collection); m_changeSet.insertAddedCollection(collection.id()); } } void SaveCollectionRequestData::commitSourceUpdated(ESource *source, QOrganizerManager::Error error) { int index = m_sourcesToUpdate.firstKey(); m_sourcesToUpdate.remove(index); if (error == QOrganizerManager::NoError) { QOrganizerEDSCollectionEngineId *id; bool isDefault = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(source), "is-default")); QOrganizerCollection collection = SourceRegistry::parseSource(source, isDefault, &id); m_results.insert(index, collection); if (isDefault) { SourceRegistry *registry = parent()->d->m_sourceRegistry; Q_ASSERT(registry); registry->setDefaultCollection(collection); } m_changeSet.insertChangedCollection(collection.id()); } else { m_errorMap.insert(index, error); } } ESource *SaveCollectionRequestData::nextSourceToUpdate() { if (m_sourcesToUpdate.size() > 0) { return m_sourcesToUpdate.first(); } else { return 0; } } bool SaveCollectionRequestData::prepareToCreate() { Q_FOREACH(ESource *source, m_sourcesToCreate.values()) { m_currentSources = g_list_append(m_currentSources, source); } return (g_list_length(m_currentSources) > 0); } bool SaveCollectionRequestData::prepareToUpdate() { return (m_sourcesToUpdate.size() > 0); } void SaveCollectionRequestData::setRegistry(ESourceRegistry *registry) { if (m_registry) { g_object_unref(m_registry); m_registry = 0; } if (registry) { m_registry = registry; g_object_ref(m_registry); } } ESourceRegistry *SaveCollectionRequestData::registry() const { return m_registry; } GList *SaveCollectionRequestData::sourcesToCreate() const { return m_currentSources; } void SaveCollectionRequestData::parseCollections() { m_sources.clear(); m_errorMap.clear(); int index = 0; Q_FOREACH(const QOrganizerCollection &collection, request()->collections()) { ESource *source = 0; bool isNew = true; if (collection.id().isNull()) { GError *gError = 0; source = e_source_new(0, 0, &gError); if (gError) { m_errorMap.insert(index, QOrganizerManager::UnspecifiedError); qWarning() << "Fail to create source:" << gError->message; g_error_free(gError); Q_ASSERT(false); } e_source_set_parent(source, "local-stub"); } else { source = m_parent->d->m_sourceRegistry->source(collection.id().toString()); isNew = false; } QVariant callendarType = collection.extendedMetaData(COLLECTION_CALLENDAR_TYPE_METADATA); ESourceBackend *extCalendar = 0; if (callendarType.toString() == E_SOURCE_EXTENSION_TASK_LIST) { extCalendar = E_SOURCE_BACKEND(e_source_get_extension(source, E_SOURCE_EXTENSION_TASK_LIST)); } else if (callendarType.toString() == E_SOURCE_EXTENSION_MEMO_LIST) { extCalendar = E_SOURCE_BACKEND(e_source_get_extension(source, E_SOURCE_EXTENSION_MEMO_LIST)); } else { extCalendar = E_SOURCE_BACKEND(e_source_get_extension(source, E_SOURCE_EXTENSION_CALENDAR)); } if (source) { if (isNew) { if (extCalendar) { e_source_backend_set_backend_name(extCalendar, "local"); } else { qWarning() << "Fail to get source callendar"; } } // update name QString name = collection.metaData(QOrganizerCollection::KeyName).toString(); e_source_set_display_name(source, name.toUtf8().constData()); // update color QString color = collection.metaData(QOrganizerCollection::KeyColor).toString(); e_source_selectable_set_color(E_SOURCE_SELECTABLE(extCalendar), color.toUtf8().constData()); // update selected bool selected = collection.extendedMetaData(COLLECTION_SELECTED_METADATA).toBool(); e_source_selectable_set_selected(E_SOURCE_SELECTABLE(extCalendar), selected); // default collection bool isDefault = collection.extendedMetaData(COLLECTION_DEFAULT_METADATA).toBool(); g_object_set_data(G_OBJECT(source), "is-default", GINT_TO_POINTER(isDefault)); m_sources.insert(index, source); if (isNew) { m_sourcesToCreate.insert(index, source); } else { m_sourcesToUpdate.insert(index, source); } index++; } } } qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-removebyidrequestdata.h0000644000015600001650000000330712672562647031015 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __QORGANIZER_EDS_REMOVEBYIDQUESTDATA_H__ #define __QORGANIZER_EDS_REMOVEBYIDQUESTDATA_H__ #include "qorganizer-eds-requestdata.h" #include class RemoveByIdRequestData : public RequestData { public: RemoveByIdRequestData(QOrganizerEDSEngine *engine, QtOrganizer::QOrganizerAbstractRequest *req); ~RemoveByIdRequestData(); QString collectionId() const; void finish(QtOrganizer::QOrganizerManager::Error error = QtOrganizer::QOrganizerManager::NoError, QtOrganizer::QOrganizerAbstractRequest::State state = QtOrganizer::QOrganizerAbstractRequest::FinishedState); GSList *compIds() const; QString next(); void commit(); virtual void cancel(); private: QHash > m_pending; QSet m_currentIds; QString m_currentCollectionId; bool m_sessionStaterd; GSList *m_currentCompIds; void reset(); void clear(); GSList *parseIds(QSet iids); }; #endif qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-removecollectionrequestdata.cpp0000644000015600001650000000554112672562647032556 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "qorganizer-eds-removecollectionrequestdata.h" #include "qorganizer-eds-engineid.h" #include "qorganizer-eds-enginedata.h" #include "qorganizer-eds-source-registry.h" #include #include #include using namespace QtOrganizer; RemoveCollectionRequestData::RemoveCollectionRequestData(QOrganizerEDSEngine *engine, QtOrganizer::QOrganizerAbstractRequest *req) : RequestData(engine, req), m_currentCollection(0), m_remoteDeletable(false) { m_pendingCollections = request()->collectionIds(); } RemoveCollectionRequestData::~RemoveCollectionRequestData() { } void RemoveCollectionRequestData::finish(QOrganizerManager::Error error, QOrganizerAbstractRequest::State state) { QOrganizerManagerEngine::updateCollectionRemoveRequest(request(), error, m_errorMap, state); // changes will be fired by source-registry RequestData::finish(error, state); } void RemoveCollectionRequestData::commit(QtOrganizer::QOrganizerManager::Error error) { if (error != QOrganizerManager::NoError) { m_errorMap.insert(m_currentCollection, error); } else { QOrganizerCollectionId cId = m_pendingCollections.at(m_currentCollection); parent()->d->m_sourceRegistry->remove(cId.toString()); } m_currentCollection++; m_remoteDeletable = false; } bool RemoveCollectionRequestData::remoteDeletable() const { return m_remoteDeletable; } void RemoveCollectionRequestData::setRemoteDeletable(bool deletable) { m_remoteDeletable = deletable; } ESource *RemoveCollectionRequestData::begin() { if (m_pendingCollections.count() > m_currentCollection) { QOrganizerCollectionId cId = m_pendingCollections.at(m_currentCollection); return parent()->d->m_sourceRegistry->source(cId.toString()); } else { return 0; } } qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-enginedata.h0000644000015600001650000000334012672562647026501 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of canonical-pim-service * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __QORGANIZER_EDS_ENGINEDATA_H__ #define __QORGANIZER_EDS_ENGINEDATA_H__ #include #include #include #include #include #include class SourceRegistry; class ViewWatcher; class RequestData; class QOrganizerEDSEngineData : public QSharedData { public: QOrganizerEDSEngineData(); QOrganizerEDSEngineData(const QOrganizerEDSEngineData& other); ~QOrganizerEDSEngineData(); template void emitSharedSignals(K* cs) { Q_FOREACH(QtOrganizer::QOrganizerManagerEngine* engine, m_sharedEngines) { cs->emitSignals(engine); } } ViewWatcher* watch(const QString &collectionId); void unWatch(const QString &collectionId); QAtomicInt m_refCount; SourceRegistry *m_sourceRegistry; QSet m_sharedEngines; private: QMap m_viewWatchers; }; #endif qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-engine.cpp0000644000015600001650000031125612672562647026212 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of canonical-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "qorganizer-eds-engine.h" #include "qorganizer-eds-engineid.h" #include "qorganizer-eds-collection-engineid.h" #include "qorganizer-eds-fetchrequestdata.h" #include "qorganizer-eds-fetchbyidrequestdata.h" #include "qorganizer-eds-fetchocurrencedata.h" #include "qorganizer-eds-saverequestdata.h" #include "qorganizer-eds-removerequestdata.h" #include "qorganizer-eds-removebyidrequestdata.h" #include "qorganizer-eds-savecollectionrequestdata.h" #include "qorganizer-eds-removecollectionrequestdata.h" #include "qorganizer-eds-viewwatcher.h" #include "qorganizer-eds-enginedata.h" #include "qorganizer-eds-source-registry.h" #include "qorganizer-eds-parseeventthread.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace QtOrganizer; QOrganizerEDSEngineData *QOrganizerEDSEngine::m_globalData = 0; QOrganizerEDSEngine* QOrganizerEDSEngine::createEDSEngine(const QMap& parameters) { Q_UNUSED(parameters); if (!m_globalData) { m_globalData = new QOrganizerEDSEngineData(); m_globalData->m_sourceRegistry = new SourceRegistry; } m_globalData->m_refCount.ref(); return new QOrganizerEDSEngine(m_globalData); } QOrganizerEDSEngine::QOrganizerEDSEngine(QOrganizerEDSEngineData *data) : d(data) { d->m_sharedEngines << this; Q_FOREACH(const QString &collectionId, d->m_sourceRegistry->collectionsIds()){ onSourceAdded(collectionId); } connect(d->m_sourceRegistry, SIGNAL(sourceAdded(QString)), SLOT(onSourceAdded(QString))); connect(d->m_sourceRegistry, SIGNAL(sourceRemoved(QString)), SLOT(onSourceRemoved(QString))); connect(d->m_sourceRegistry, SIGNAL(sourceUpdated(QString)), SLOT(onSourceUpdated(QString))); d->m_sourceRegistry->load(); } QOrganizerEDSEngine::~QOrganizerEDSEngine() { while(m_runningRequests.count()) { QOrganizerAbstractRequest *req = m_runningRequests.keys().first(); req->cancel(); QOrganizerEDSEngine::requestDestroyed(req); } d->m_sharedEngines.remove(this); if (!d->m_refCount.deref()) { delete d; m_globalData = 0; } } QString QOrganizerEDSEngine::managerName() const { return QOrganizerEDSEngineId::managerNameStatic(); } /*! \reimp */ QMap QOrganizerEDSEngine::managerParameters() const { QMap params; return params; } void QOrganizerEDSEngine::itemsAsync(QOrganizerItemFetchRequest *req) { FetchRequestData *data = new FetchRequestData(this, d->m_sourceRegistry->collectionsIds(), req); // avoid query if the filter is invalid if (data->filterIsValid()) { itemsAsyncStart(data); } else { data->finish(); } } void QOrganizerEDSEngine::itemsAsyncStart(FetchRequestData *data) { // check if request was destroyed by the caller if (!data->isLive()) { releaseRequestData(data); return; } QString collection = data->nextCollection(); if (!collection.isEmpty()) { EClient *client = data->parent()->d->m_sourceRegistry->client(collection); data->setClient(client); g_object_unref(client); if (data->hasDateInterval()) { e_cal_client_generate_instances(data->client(), data->startDate(), data->endDate(), data->cancellable(), (ECalRecurInstanceFn) QOrganizerEDSEngine::itemsAsyncListed, data, (GDestroyNotify) QOrganizerEDSEngine::itemsAsyncDone); } else { // if no date interval was set we return only the main events without recurrence e_cal_client_get_object_list_as_comps(E_CAL_CLIENT(client), data->dateFilter().toUtf8().data(), data->cancellable(), (GAsyncReadyCallback) QOrganizerEDSEngine::itemsAsyncListedAsComps, data); } } else { data->finish(); } } void QOrganizerEDSEngine::itemsAsyncDone(FetchRequestData *data) { if (data->isLive()) { data->compileCurrentIds(); itemsAsyncFetchDeatachedItems(data); } else { releaseRequestData(data); } } void QOrganizerEDSEngine::itemsAsyncFetchDeatachedItems(FetchRequestData *data) { QString parentId = data->nextParentId(); if (!parentId.isEmpty()) { e_cal_client_get_objects_for_uid(E_CAL_CLIENT(data->client()), parentId.toUtf8().data(), data->cancellable(), (GAsyncReadyCallback) QOrganizerEDSEngine::itemsAsyncListByIdListed, data); } else { itemsAsyncStart(data); } } void QOrganizerEDSEngine::itemsAsyncListByIdListed(GObject *source, GAsyncResult *res, FetchRequestData *data) { Q_UNUSED(source); GError *gError = 0; GSList *events = 0; e_cal_client_get_objects_for_uid_finish(E_CAL_CLIENT(data->client()), res, &events, &gError); if (gError) { qWarning() << "Fail to list deatached events in calendar" << gError->message; g_error_free(gError); gError = 0; if (data->isLive()) { data->finish(QOrganizerManager::InvalidCollectionError); } else { releaseRequestData(data); } return; } for(GSList *e = events; e != NULL; e = e->next) { icalcomponent * ical = e_cal_component_get_icalcomponent(static_cast(e->data)); data->appendDeatachedResult(ical); } itemsAsyncFetchDeatachedItems(data); } gboolean QOrganizerEDSEngine::itemsAsyncListed(ECalComponent *comp, time_t instanceStart, time_t instanceEnd, FetchRequestData *data) { Q_UNUSED(instanceStart); Q_UNUSED(instanceEnd); if (data->isLive()) { icalcomponent *icalComp = icalcomponent_new_clone(e_cal_component_get_icalcomponent(comp)); if (icalComp) { data->appendResult(icalComp); } return TRUE; } return FALSE; } void QOrganizerEDSEngine::itemsAsyncListedAsComps(GObject *source, GAsyncResult *res, FetchRequestData *data) { Q_UNUSED(source); GError *gError = 0; GSList *events = 0; e_cal_client_get_object_list_as_comps_finish(E_CAL_CLIENT(data->client()), res, &events, &gError); if (gError) { qWarning() << "Fail to list events in calendar" << gError->message; g_error_free(gError); gError = 0; if (data->isLive()) { data->finish(QOrganizerManager::InvalidCollectionError); } else { releaseRequestData(data); } return; } // check if request was destroyed by the caller if (data->isLive()) { QOrganizerItemFetchRequest *req = data->request(); data->appendResults(data->parent()->parseEvents(data->collection(), events, false, req->fetchHint().detailTypesHint())); itemsAsyncStart(data); } else { releaseRequestData(data); } } void QOrganizerEDSEngine::itemsByIdAsync(QOrganizerItemFetchByIdRequest *req) { FetchByIdRequestData *data = new FetchByIdRequestData(this, req); itemsByIdAsyncStart(data); } void QOrganizerEDSEngine::itemsByIdAsyncStart(FetchByIdRequestData *data) { // check if request was destroyed by the caller if (!data->isLive()) { releaseRequestData(data); return; } QString id = data->nextId(); if (!id.isEmpty()) { QStringList ids = id.split("/"); if (ids.length() == 2) { Q_ASSERT(ids.length() == 2); QString collectionId = ids[0]; QString rId; QString itemId = QOrganizerEDSEngineId::toComponentId(ids[1], &rId); EClient *client = data->parent()->d->m_sourceRegistry->client(collectionId); if (client) { data->setClient(client); e_cal_client_get_object(data->client(), itemId.toUtf8().data(), rId.toUtf8().data(), data->cancellable(), (GAsyncReadyCallback) QOrganizerEDSEngine::itemsByIdAsyncListed, data); g_object_unref(client); return; } } } else if (data->end()) { data->finish(); return; } qWarning() << "Invalid item id" << id; data->appendResult(QOrganizerItem()); itemsByIdAsyncStart(data); } void QOrganizerEDSEngine::itemsByIdAsyncListed(GObject *client, GAsyncResult *res, FetchByIdRequestData *data) { Q_UNUSED(client); GError *gError = 0; icalcomponent *icalComp = 0; e_cal_client_get_object_finish(data->client(), res, &icalComp, &gError); if (gError) { qWarning() << "Fail to list events in calendar" << gError->message; g_error_free(gError); gError = 0; data->appendResult(QOrganizerItem()); } else if (icalComp && data->isLive()) { GSList *events = g_slist_append(0, icalComp); QList items; QOrganizerItemFetchByIdRequest *req = data->request(); items = data->parent()->parseEvents(data->currentCollectionId(), events, true, req->fetchHint().detailTypesHint()); Q_ASSERT(items.size() == 1); data->appendResult(items[0]); g_slist_free_full(events, (GDestroyNotify) icalcomponent_free); } if (data->isLive()) { itemsByIdAsyncStart(data); } else { releaseRequestData(data); } } void QOrganizerEDSEngine::itemOcurrenceAsync(QOrganizerItemOccurrenceFetchRequest *req) { FetchOcurrenceData *data = new FetchOcurrenceData(this, req); QString rId; QString cId = QOrganizerEDSEngineId::toComponentId(req->parentItem().id(), &rId); EClient *client = data->parent()->d->m_sourceRegistry->client(req->parentItem().collectionId().toString()); if (client) { data->setClient(client); e_cal_client_get_object(data->client(), cId.toUtf8(), rId.toUtf8(), data->cancellable(), (GAsyncReadyCallback) QOrganizerEDSEngine::itemOcurrenceAsyncGetObjectDone, data); g_object_unref(client); } else { qWarning() << "Fail to find collection:" << req->parentItem().collectionId(); data->finish(QOrganizerManager::DoesNotExistError); } } void QOrganizerEDSEngine::itemOcurrenceAsyncGetObjectDone(GObject *source, GAsyncResult *res, FetchOcurrenceData *data) { Q_UNUSED(source); GError *error = 0; icalcomponent *comp = 0; e_cal_client_get_object_finish(data->client(), res, &comp, &error); if (error) { qWarning() << "Fail to get object for id:" << data->request()->parentItem(); g_error_free(error); if (data->isLive()) { data->finish(QOrganizerManager::DoesNotExistError); } else { releaseRequestData(data); } return; } if (data->isLive()) { e_cal_client_generate_instances_for_object(data->client(), comp, data->startDate(), data->endDate(), data->cancellable(), (ECalRecurInstanceFn) QOrganizerEDSEngine::itemOcurrenceAsyncListed, data, (GDestroyNotify) QOrganizerEDSEngine::itemOcurrenceAsyncDone); } else { releaseRequestData(data); } } void QOrganizerEDSEngine::itemOcurrenceAsyncListed(ECalComponent *comp, time_t instanceStart, time_t instanceEnd, FetchOcurrenceData *data) { Q_UNUSED(instanceStart); Q_UNUSED(instanceEnd); // check if request was destroyed by the caller if (!data->isLive()) { releaseRequestData(data); return; } icalcomponent *icalComp = icalcomponent_new_clone(e_cal_component_get_icalcomponent(comp)); if (icalComp) { data->appendResult(icalComp); } } void QOrganizerEDSEngine::itemOcurrenceAsyncDone(FetchOcurrenceData *data) { if (data->isLive()) { data->finish(); } else { releaseRequestData(data); } } QList QOrganizerEDSEngine::items(const QList &itemIds, const QOrganizerItemFetchHint &fetchHint, QMap *errorMap, QOrganizerManager::Error *error) { QOrganizerItemFetchByIdRequest *req = new QOrganizerItemFetchByIdRequest(this); req->setIds(itemIds); req->setFetchHint(fetchHint); startRequest(req); waitForRequestFinished(req, 0); if (error) { *error = req->error(); } if (errorMap) { *errorMap = req->errorMap(); } req->deleteLater(); return req->items(); } QList QOrganizerEDSEngine::items(const QOrganizerItemFilter &filter, const QDateTime &startDateTime, const QDateTime &endDateTime, int maxCount, const QList &sortOrders, const QOrganizerItemFetchHint &fetchHint, QOrganizerManager::Error *error) { QOrganizerItemFetchRequest *req = new QOrganizerItemFetchRequest(this); req->setFilter(filter); req->setStartDate(startDateTime); req->setEndDate(endDateTime); req->setMaxCount(maxCount); req->setSorting(sortOrders); req->setFetchHint(fetchHint); startRequest(req); waitForRequestFinished(req, 0); if (error) { *error = req->error(); } req->deleteLater(); return req->items(); } QList QOrganizerEDSEngine::itemIds(const QOrganizerItemFilter &filter, const QDateTime &startDateTime, const QDateTime &endDateTime, const QList &sortOrders, QOrganizerManager::Error *error) { qWarning() << Q_FUNC_INFO << "Not implemented"; QList items; if (error) { *error = QOrganizerManager::NotSupportedError; } return items; } QList QOrganizerEDSEngine::itemOccurrences(const QOrganizerItem &parentItem, const QDateTime &startDateTime, const QDateTime &endDateTime, int maxCount, const QOrganizerItemFetchHint &fetchHint, QOrganizerManager::Error *error) { QOrganizerItemOccurrenceFetchRequest *req = new QOrganizerItemOccurrenceFetchRequest(this); req->setParentItem(parentItem); req->setStartDate(startDateTime); req->setEndDate(endDateTime); req->setMaxOccurrences(maxCount); req->setFetchHint(fetchHint); startRequest(req); waitForRequestFinished(req, 0); if (error) { *error = req->error(); } req->deleteLater(); return req->itemOccurrences(); } QList QOrganizerEDSEngine::itemsForExport(const QDateTime &startDateTime, const QDateTime &endDateTime, const QOrganizerItemFilter &filter, const QList &sortOrders, const QOrganizerItemFetchHint &fetchHint, QOrganizerManager::Error *error) { qWarning() << Q_FUNC_INFO << "Not implemented"; if (error) { *error = QOrganizerManager::NotSupportedError; } return QList(); } void QOrganizerEDSEngine::saveItemsAsync(QOrganizerItemSaveRequest *req) { if (req->items().count() == 0) { QOrganizerManagerEngine::updateItemSaveRequest(req, QList(), QOrganizerManager::NoError, QMap(), QOrganizerAbstractRequest::FinishedState); return; } SaveRequestData *data = new SaveRequestData(this, req); saveItemsAsyncStart(data); } void QOrganizerEDSEngine::saveItemsAsyncStart(SaveRequestData *data) { // check if request was destroyed by the caller if (!data->isLive()) { releaseRequestData(data); return; } QString collectionId = data->nextCollection(); if (collectionId.isNull() && data->end()) { data->finish(); return; } else { bool createItems = true; QList items = data->takeItemsToCreate(); if (items.isEmpty()) { createItems = false; items = data->takeItemsToUpdate(); } if (items.isEmpty()) { saveItemsAsyncStart(data); return; } if (collectionId.isEmpty() && createItems) { collectionId = data->parent()->d->m_sourceRegistry->defaultCollection().id().toString(); } EClient *client = data->parent()->d->m_sourceRegistry->client(collectionId); if (!client) { Q_FOREACH(const QOrganizerItem &i, items) { data->appendResult(i, QOrganizerManager::InvalidCollectionError); } saveItemsAsyncStart(data); return; } Q_ASSERT(client); data->setClient(client); g_object_unref(client); bool hasRecurrence = false; GSList *comps = parseItems(data->client(), items, &hasRecurrence); if (comps) { data->setWorkingItems(items); if (createItems) { e_cal_client_create_objects(data->client(), comps, data->cancellable(), (GAsyncReadyCallback) QOrganizerEDSEngine::saveItemsAsyncCreated, data); } else { //WORKAROUND: There is no api to say what kind of update we want in case of update recurrence // items (E_CAL_OBJ_MOD_ALL, E_CAL_OBJ_MOD_THIS, E_CAL_OBJ_MOD_THISNADPRIOR, E_CAL_OBJ_MOD_THIS_AND_FUTURE) // as temporary solution the user can use "update-mode" property in QOrganizerItemSaveRequest object, // if not was specified, we will try to guess based on the event list. // If the event list does not cotain any recurrence event we will use E_CAL_OBJ_MOD_ALL // If the event list cotains any recurrence event we will use E_CAL_OBJ_MOD_THIS // all other cases should be explicitly specified using "update-mode" property int updateMode = data->updateMode(); if (updateMode == -1) { updateMode = hasRecurrence ? E_CAL_OBJ_MOD_THIS : E_CAL_OBJ_MOD_ALL; } e_cal_client_modify_objects(data->client(), comps, static_cast(updateMode), data->cancellable(), (GAsyncReadyCallback) QOrganizerEDSEngine::saveItemsAsyncModified, data); } g_slist_free_full(comps, (GDestroyNotify) icalcomponent_free); } else { qWarning() << "Fail to translate items"; } } } void QOrganizerEDSEngine::saveItemsAsyncModified(GObject *source_object, GAsyncResult *res, SaveRequestData *data) { Q_UNUSED(source_object); GError *gError = 0; e_cal_client_modify_objects_finish(E_CAL_CLIENT(data->client()), res, &gError); if (gError) { qWarning() << "Fail to modify items" << gError->message; g_error_free(gError); gError = 0; if (data->isLive()) { Q_FOREACH(const QOrganizerItem &i, data->workingItems()) { data->appendResult(i, QOrganizerManager::UnspecifiedError); } } } else if (data->isLive()) { data->appendResults(data->workingItems()); } if (data->isLive()) { saveItemsAsyncStart(data); } else { releaseRequestData(data); } } void QOrganizerEDSEngine::saveItemsAsyncCreated(GObject *source_object, GAsyncResult *res, SaveRequestData *data) { Q_UNUSED(source_object); GError *gError = 0; GSList *uids = 0; e_cal_client_create_objects_finish(E_CAL_CLIENT(data->client()), res, &uids, &gError); if (gError) { qWarning() << "Fail to create items:" << (void*) data << gError->message; g_error_free(gError); gError = 0; if (data->isLive()) { Q_FOREACH(const QOrganizerItem &i, data->workingItems()) { data->appendResult(i, QOrganizerManager::UnspecifiedError); } } } else if (data->isLive()) { QString currentCollectionId = data->currentCollection(); if (currentCollectionId.isEmpty()) { currentCollectionId = data->parent()->defaultCollection(0).id().toString(); } QList items = data->workingItems(); for(uint i=0, iMax=g_slist_length(uids); i < iMax; i++) { QOrganizerItem &item = items[i]; const gchar *uid = static_cast(g_slist_nth_data(uids, i)); QOrganizerEDSEngineId *eid = new QOrganizerEDSEngineId(currentCollectionId, QString::fromUtf8(uid)); item.setId(QOrganizerItemId(eid)); item.setGuid(QString("%1/%2") .arg(eid->m_collectionId) .arg(eid->m_itemId)); QOrganizerEDSCollectionEngineId *edsCollectionId = new QOrganizerEDSCollectionEngineId(currentCollectionId); item.setCollectionId(QOrganizerCollectionId(edsCollectionId)); } g_slist_free_full(uids, g_free); data->appendResults(items); } // check if request was destroyed by the caller if (data->isLive()) { saveItemsAsyncStart(data); } else { releaseRequestData(data); } } bool QOrganizerEDSEngine::saveItems(QList *items, const QList &detailMask, QMap *errorMap, QtOrganizer::QOrganizerManager::Error *error) { QOrganizerItemSaveRequest *req = new QOrganizerItemSaveRequest(this); req->setItems(*items); req->setDetailMask(detailMask); startRequest(req); waitForRequestFinished(req, 0); *errorMap = req->errorMap(); *error = req->error(); *items = req->items(); return (*error == QOrganizerManager::NoError); } void QOrganizerEDSEngine::removeItemsByIdAsync(QOrganizerItemRemoveByIdRequest *req) { if (req->itemIds().count() == 0) { QOrganizerManagerEngine::updateItemRemoveByIdRequest(req, QOrganizerManager::NoError, QMap(), QOrganizerAbstractRequest::FinishedState); return; } RemoveByIdRequestData *data = new RemoveByIdRequestData(this, req); removeItemsByIdAsyncStart(data); } void QOrganizerEDSEngine::removeItemsByIdAsyncStart(RemoveByIdRequestData *data) { // check if request was destroyed by the caller if (!data->isLive()) { releaseRequestData(data); return; } QString collectionId = data->next(); for(; !collectionId.isNull(); collectionId = data->next()) { EClient *client = data->parent()->d->m_sourceRegistry->client(collectionId); data->setClient(client); g_object_unref(client); GSList *ids = data->compIds(); GError *gError = 0; e_cal_client_remove_objects_sync(data->client(), ids, E_CAL_OBJ_MOD_THIS, 0, 0); if (gError) { qWarning() << "Fail to remove Items" << gError->message; g_error_free(gError); gError = 0; } data->commit(); } data->finish(); } void QOrganizerEDSEngine::removeItemsAsync(QOrganizerItemRemoveRequest *req) { if (req->items().count() == 0) { QOrganizerManagerEngine::updateItemRemoveRequest(req, QOrganizerManager::NoError, QMap(), QOrganizerAbstractRequest::FinishedState); return; } RemoveRequestData *data = new RemoveRequestData(this, req); removeItemsAsyncStart(data); } void QOrganizerEDSEngine::removeItemsAsyncStart(RemoveRequestData *data) { // check if request was destroyed by the caller if (!data->isLive()) { releaseRequestData(data); return; } QOrganizerCollectionId collection = data->next(); for(; !collection.isNull(); collection = data->next()) { EClient *client = data->parent()->d->m_sourceRegistry->client(collection.toString()); data->setClient(client); g_object_unref(client); GSList *ids = data->compIds(); GError *gError = 0; e_cal_client_remove_objects_sync(data->client(), ids, E_CAL_OBJ_MOD_THIS, 0, 0); if (gError) { qWarning() << "Fail to remove Items" << gError->message; g_error_free(gError); gError = 0; } data->commit(); } data->finish(); } bool QOrganizerEDSEngine::removeItems(const QList &itemIds, QMap *errorMap, QOrganizerManager::Error *error) { QOrganizerItemRemoveByIdRequest *req = new QOrganizerItemRemoveByIdRequest(this); req->setItemIds(itemIds); startRequest(req); waitForRequestFinished(req, 0); if (errorMap) { *errorMap = req->errorMap(); } if (error) { *error = req->error(); } return (*error == QOrganizerManager::NoError); } QOrganizerCollection QOrganizerEDSEngine::defaultCollection(QOrganizerManager::Error* error) { if (error) { *error = QOrganizerManager::NoError; } return d->m_sourceRegistry->defaultCollection(); } QOrganizerCollection QOrganizerEDSEngine::collection(const QOrganizerCollectionId& collectionId, QOrganizerManager::Error* error) { QOrganizerCollection collection = d->m_sourceRegistry->collection(collectionId.toString()); if (collection.id().isNull() && error) { *error = QOrganizerManager::DoesNotExistError; } return collection; } QList QOrganizerEDSEngine::collections(QOrganizerManager::Error* error) { QOrganizerCollectionFetchRequest *req = new QOrganizerCollectionFetchRequest(this); startRequest(req); waitForRequestFinished(req, 0); if (error) { *error = req->error(); } if (req->error() == QOrganizerManager::NoError) { return req->collections(); } else { return QList(); } } bool QOrganizerEDSEngine::saveCollection(QOrganizerCollection* collection, QOrganizerManager::Error* error) { QOrganizerCollectionSaveRequest *req = new QOrganizerCollectionSaveRequest(this); req->setCollection(*collection); startRequest(req); waitForRequestFinished(req, 0); *error = req->error(); if ((*error == QOrganizerManager::NoError) && (req->collections().count())) { *collection = req->collections()[0]; return true; } else { return false; } } void QOrganizerEDSEngine::saveCollectionAsync(QOrganizerCollectionSaveRequest *req) { if (req->collections().count() == 0) { QOrganizerManagerEngine::updateCollectionSaveRequest(req, QList(), QOrganizerManager::NoError, QMap(), QOrganizerAbstractRequest::FinishedState); return; } ESourceRegistry *registry = d->m_sourceRegistry->object(); SaveCollectionRequestData *requestData = new SaveCollectionRequestData(this, req); requestData->setRegistry(registry); if (requestData->prepareToCreate()) { e_source_registry_create_sources(registry, requestData->sourcesToCreate(), requestData->cancellable(), (GAsyncReadyCallback) QOrganizerEDSEngine::saveCollectionAsyncCommited, requestData); } else { requestData->prepareToUpdate(); g_idle_add((GSourceFunc) saveCollectionUpdateAsyncStart, requestData); } } void QOrganizerEDSEngine::saveCollectionAsyncCommited(ESourceRegistry *registry, GAsyncResult *res, SaveCollectionRequestData *data) { GError *gError = 0; e_source_registry_create_sources_finish(registry, res, &gError); if (gError) { qWarning() << "Fail to create sources:" << gError->message; g_error_free(gError); if (data->isLive()) { data->finish(QOrganizerManager::InvalidCollectionError); return; } } else if (data->isLive()) { data->commitSourceCreated(); data->prepareToUpdate(); g_idle_add((GSourceFunc) saveCollectionUpdateAsyncStart, data); } } gboolean QOrganizerEDSEngine::saveCollectionUpdateAsyncStart(SaveCollectionRequestData *data) { // check if request was destroyed by the caller if (!data->isLive()) { releaseRequestData(data); return FALSE; } ESource *source = data->nextSourceToUpdate(); if (source) { e_source_write(source, data->cancellable(), (GAsyncReadyCallback) QOrganizerEDSEngine::saveCollectionUpdateAsynCommited, data); } else { data->finish(); } return FALSE; } void QOrganizerEDSEngine::saveCollectionUpdateAsynCommited(ESource *source, GAsyncResult *res, SaveCollectionRequestData *data) { GError *gError = 0; e_source_write_finish(source, res, &gError); if (gError) { qWarning() << "Fail to update collection" << gError->message; g_error_free(gError); if (data->isLive()) { data->commitSourceUpdated(source, QOrganizerManager::InvalidCollectionError); } } else if (data->isLive()) { data->commitSourceUpdated(source); } if (data->isLive()) { g_idle_add((GSourceFunc) saveCollectionUpdateAsyncStart, data); } else { releaseRequestData(data); } } bool QOrganizerEDSEngine::removeCollection(const QOrganizerCollectionId& collectionId, QOrganizerManager::Error* error) { QOrganizerCollectionRemoveRequest *req = new QOrganizerCollectionRemoveRequest(this); req->setCollectionId(collectionId); startRequest(req); waitForRequestFinished(req, 0); if (error) { *error = req->error(); } return(req->error() == QOrganizerManager::NoError); } void QOrganizerEDSEngine::removeCollectionAsync(QtOrganizer::QOrganizerCollectionRemoveRequest *req) { if (req->collectionIds().count() == 0) { QOrganizerManagerEngine::updateCollectionRemoveRequest(req, QOrganizerManager::NoError, QMap(), QOrganizerAbstractRequest::FinishedState); return; } RemoveCollectionRequestData *requestData = new RemoveCollectionRequestData(this, req); removeCollectionAsyncStart(0, 0, requestData); } void QOrganizerEDSEngine::removeCollectionAsyncStart(GObject *sourceObject, GAsyncResult *res, RemoveCollectionRequestData *data) { // check if request was destroyed by the caller if (!data->isLive()) { releaseRequestData(data); return; } if (sourceObject && res) { GError *gError = 0; if (data->remoteDeletable()) { e_source_remote_delete_finish(E_SOURCE(sourceObject), res, &gError); } else { e_source_remove_finish(E_SOURCE(sourceObject), res, &gError); } if (gError) { qWarning() << "Fail to remove collection" << gError->message; g_error_free(gError); data->commit(QOrganizerManager::InvalidCollectionError); } else { data->commit(); } } ESource *source = data->begin(); if (source) { ESourceRegistry *registry = NULL; gboolean accountRemovable = e_source_get_removable(source); gboolean remoteDeletable = e_source_get_remote_deletable(source); if ((accountRemovable == FALSE) && (remoteDeletable == FALSE)) { qWarning() << "Account not removable will refetch source"; // WORKAROUND: Sometimes EDS take longer to make a account removable with this we // force EDS to update sources infomation registry = e_source_registry_new_sync(NULL, NULL); source = e_source_registry_ref_source(registry, e_source_get_uid(source)); accountRemovable = e_source_get_removable(source); remoteDeletable = e_source_get_remote_deletable(source); } if (remoteDeletable == TRUE) { data->setRemoteDeletable(true); e_source_remote_delete(source, data->cancellable(), (GAsyncReadyCallback) QOrganizerEDSEngine::removeCollectionAsyncStart, data); } else if (accountRemovable == TRUE) { e_source_remove(source, data->cancellable(), (GAsyncReadyCallback) QOrganizerEDSEngine::removeCollectionAsyncStart, data); } else { qWarning() << "Source not removable" << e_source_get_uid(source); data->commit(QOrganizerManager::InvalidCollectionError); removeCollectionAsyncStart(0, 0, data); } if (registry) { g_object_unref(source); g_object_unref(registry); } } else { data->finish(); } } void QOrganizerEDSEngine::releaseRequestData(RequestData *data) { data->deleteLater(); } void QOrganizerEDSEngine::requestDestroyed(QOrganizerAbstractRequest* req) { RequestData *data = m_runningRequests.take(req); if (data) { data->cancel(); } } bool QOrganizerEDSEngine::startRequest(QOrganizerAbstractRequest* req) { if (!req) return false; switch (req->type()) { case QOrganizerAbstractRequest::ItemFetchRequest: itemsAsync(qobject_cast(req)); break; case QOrganizerAbstractRequest::ItemFetchByIdRequest: itemsByIdAsync(qobject_cast(req)); break; case QOrganizerAbstractRequest::ItemOccurrenceFetchRequest: itemOcurrenceAsync(qobject_cast(req)); break; case QOrganizerAbstractRequest::CollectionFetchRequest: QOrganizerManagerEngine::updateCollectionFetchRequest(qobject_cast(req), d->m_sourceRegistry->collections(), QOrganizerManager::NoError, QOrganizerAbstractRequest::FinishedState); break; case QOrganizerAbstractRequest::ItemSaveRequest: saveItemsAsync(qobject_cast(req)); break; case QOrganizerAbstractRequest::ItemRemoveRequest: removeItemsAsync(qobject_cast(req)); break; case QOrganizerAbstractRequest::ItemRemoveByIdRequest: removeItemsByIdAsync(qobject_cast(req)); break; case QOrganizerAbstractRequest::CollectionSaveRequest: saveCollectionAsync(qobject_cast(req)); break; case QOrganizerAbstractRequest::CollectionRemoveRequest: removeCollectionAsync(qobject_cast(req)); break; default: updateRequestState(req, QOrganizerAbstractRequest::FinishedState); qWarning() << "No implemented request" << req->type(); break; } return true; } bool QOrganizerEDSEngine::cancelRequest(QOrganizerAbstractRequest* req) { RequestData *data = m_runningRequests.value(req); if (data) { data->cancel(); return true; } qWarning() << "Request is not running" << (void*) req; return false; } bool QOrganizerEDSEngine::waitForRequestFinished(QOrganizerAbstractRequest* req, int msecs) { Q_ASSERT(req); RequestData *data = m_runningRequests.value(req); if (data) { data->wait(msecs); // We can delete the operation already finished data->deleteLater(); } return true; } QList QOrganizerEDSEngine::supportedItemDetails(QOrganizerItemType::ItemType itemType) const { QList supportedDetails; supportedDetails << QOrganizerItemDetail::TypeItemType << QOrganizerItemDetail::TypeGuid << QOrganizerItemDetail::TypeTimestamp << QOrganizerItemDetail::TypeDisplayLabel << QOrganizerItemDetail::TypeDescription << QOrganizerItemDetail::TypeComment << QOrganizerItemDetail::TypeTag << QOrganizerItemDetail::TypeClassification << QOrganizerItemDetail::TypeExtendedDetail; if (itemType == QOrganizerItemType::TypeEvent) { supportedDetails << QOrganizerItemDetail::TypeRecurrence << QOrganizerItemDetail::TypeEventTime << QOrganizerItemDetail::TypePriority << QOrganizerItemDetail::TypeLocation << QOrganizerItemDetail::TypeReminder << QOrganizerItemDetail::TypeAudibleReminder << QOrganizerItemDetail::TypeEmailReminder << QOrganizerItemDetail::TypeVisualReminder; } else if (itemType == QOrganizerItemType::TypeTodo) { supportedDetails << QOrganizerItemDetail::TypeRecurrence << QOrganizerItemDetail::TypeTodoTime << QOrganizerItemDetail::TypePriority << QOrganizerItemDetail::TypeTodoProgress << QOrganizerItemDetail::TypeReminder << QOrganizerItemDetail::TypeAudibleReminder << QOrganizerItemDetail::TypeEmailReminder << QOrganizerItemDetail::TypeVisualReminder; } else if (itemType == QOrganizerItemType::TypeEventOccurrence) { supportedDetails << QOrganizerItemDetail::TypeParent << QOrganizerItemDetail::TypeEventTime << QOrganizerItemDetail::TypePriority << QOrganizerItemDetail::TypeLocation << QOrganizerItemDetail::TypeReminder << QOrganizerItemDetail::TypeAudibleReminder << QOrganizerItemDetail::TypeEmailReminder << QOrganizerItemDetail::TypeVisualReminder; } else if (itemType == QOrganizerItemType::TypeTodoOccurrence) { supportedDetails << QOrganizerItemDetail::TypeParent << QOrganizerItemDetail::TypeTodoTime << QOrganizerItemDetail::TypePriority << QOrganizerItemDetail::TypeTodoProgress << QOrganizerItemDetail::TypeReminder << QOrganizerItemDetail::TypeAudibleReminder << QOrganizerItemDetail::TypeEmailReminder << QOrganizerItemDetail::TypeVisualReminder; } else if (itemType == QOrganizerItemType::TypeJournal) { supportedDetails << QOrganizerItemDetail::TypeJournalTime; } else if (itemType == QOrganizerItemType::TypeNote) { // nothing ;) } else { supportedDetails.clear(); } return supportedDetails; } QList QOrganizerEDSEngine::supportedFilters() const { QList supported; supported << QOrganizerItemFilter::InvalidFilter << QOrganizerItemFilter::DetailFilter << QOrganizerItemFilter::DetailFieldFilter << QOrganizerItemFilter::DetailRangeFilter << QOrganizerItemFilter::IntersectionFilter << QOrganizerItemFilter::UnionFilter << QOrganizerItemFilter::IdFilter << QOrganizerItemFilter::CollectionFilter << QOrganizerItemFilter::DefaultFilter; return supported; } QList QOrganizerEDSEngine::supportedItemTypes() const { return QList() << QOrganizerItemType::TypeEvent << QOrganizerItemType::TypeEventOccurrence << QOrganizerItemType::TypeJournal << QOrganizerItemType::TypeNote << QOrganizerItemType::TypeTodo << QOrganizerItemType::TypeTodoOccurrence; } int QOrganizerEDSEngine::runningRequestCount() const { return m_runningRequests.count(); } void QOrganizerEDSEngine::onSourceAdded(const QString &collectionId) { d->watch(collectionId); Q_EMIT collectionsAdded(QList() << QOrganizerCollectionId::fromString(collectionId)); } void QOrganizerEDSEngine::onSourceRemoved(const QString &collectionId) { d->unWatch(collectionId); Q_EMIT collectionsRemoved(QList() << QOrganizerCollectionId::fromString(collectionId)); } void QOrganizerEDSEngine::onSourceUpdated(const QString &collectionId) { Q_EMIT collectionsChanged(QList() << QOrganizerCollectionId::fromString(collectionId)); } void QOrganizerEDSEngine::onViewChanged(QOrganizerItemChangeSet *change) { change->emitSignals(this); } QDateTime QOrganizerEDSEngine::fromIcalTime(struct icaltimetype value, const char *tzId) { uint tmTime; bool allDayEvent = icaltime_is_date(value); // check if ialtimetype contais a time and timezone if (!allDayEvent && tzId) { QByteArray tzLocationName; icaltimezone *timezone = icaltimezone_get_builtin_timezone_from_tzid(tzId); if (icaltime_is_utc(value)) { tzLocationName = "UTC"; } else { // fallback: sometimes the tzId contains the location name if (!timezone) { timezone = icaltimezone_get_builtin_timezone(tzId); } tzLocationName = QByteArray(icaltimezone_get_location(timezone)); } tmTime = icaltime_as_timet_with_zone(value, timezone); QTimeZone qTz(tzLocationName); return QDateTime::fromTime_t(tmTime, qTz); } else { tmTime = icaltime_as_timet(value); QDateTime t = QDateTime::fromTime_t(tmTime).toUTC(); // all day or floating time events will be saved with invalid timezone return QDateTime(t.date(), // if the event is all day event save with emtpy time (allDayEvent ? QTime() : t.time()), QTimeZone()); } } icaltimetype QOrganizerEDSEngine::fromQDateTime(const QDateTime &dateTime, bool allDay, QByteArray *tzId) { QDateTime finalDate(dateTime); QTimeZone tz; if (!allDay) { switch (finalDate.timeSpec()) { case Qt::UTC: case Qt::OffsetFromUTC: // convert date to UTC timezone tz = QTimeZone("UTC"); finalDate = finalDate.toTimeZone(tz); break; case Qt::TimeZone: tz = finalDate.timeZone(); if (!tz.isValid()) { // floating time finalDate = QDateTime(finalDate.date(), finalDate.time(), Qt::UTC); } break; case Qt::LocalTime: tz = QTimeZone(QTimeZone::systemTimeZoneId()); finalDate = finalDate.toTimeZone(tz); break; default: break; } } if (tz.isValid()) { icaltimezone *timezone = 0; timezone = icaltimezone_get_builtin_timezone(tz.id().constData()); *tzId = QByteArray(icaltimezone_get_tzid(timezone)); return icaltime_from_timet_with_zone(finalDate.toTime_t(), allDay, timezone); } else { if (!finalDate.isValid()) { finalDate = QDateTime(finalDate.date(), allDay || !finalDate.time().isValid() ? QTime(0, 0, 0) : finalDate.time()); } *tzId = ""; return icaltime_from_timet(finalDate.toTime_t(), allDay); } } void QOrganizerEDSEngine::parseStartTime(ECalComponent *comp, QOrganizerItem *item) { ECalComponentDateTime *dt = g_new0(ECalComponentDateTime, 1); e_cal_component_get_dtstart(comp, dt); if (dt->value) { QOrganizerEventTime etr = item->detail(QOrganizerItemDetail::TypeEventTime); etr.setStartDateTime(fromIcalTime(*dt->value, dt->tzid)); if (icaltime_is_date(*dt->value) != etr.isAllDay()) { etr.setAllDay(icaltime_is_date(*dt->value)); } item->saveDetail(&etr); } e_cal_component_free_datetime(dt); } void QOrganizerEDSEngine::parseTodoStartTime(ECalComponent *comp, QOrganizerItem *item) { ECalComponentDateTime *dt = g_new0(ECalComponentDateTime, 1); e_cal_component_get_dtstart(comp, dt); if (dt->value) { QOrganizerTodoTime etr = item->detail(QOrganizerItemDetail::TypeTodoTime); etr.setStartDateTime(fromIcalTime(*dt->value, dt->tzid)); if (icaltime_is_date(*dt->value) != etr.isAllDay()) { etr.setAllDay(icaltime_is_date(*dt->value)); } item->saveDetail(&etr); } e_cal_component_free_datetime(dt); } void QOrganizerEDSEngine::parseEndTime(ECalComponent *comp, QOrganizerItem *item) { ECalComponentDateTime *dt = g_new0(ECalComponentDateTime, 1); e_cal_component_get_dtend(comp, dt); if (dt->value) { QOrganizerEventTime etr = item->detail(QOrganizerItemDetail::TypeEventTime); etr.setEndDateTime(fromIcalTime(*dt->value, dt->tzid)); if (icaltime_is_date(*dt->value) != etr.isAllDay()) { etr.setAllDay(icaltime_is_date(*dt->value)); } item->saveDetail(&etr); } e_cal_component_free_datetime(dt); } void QOrganizerEDSEngine::parseWeekRecurrence(struct icalrecurrencetype *rule, QtOrganizer::QOrganizerRecurrenceRule *qRule) { static QMap daysOfWeekMap; if (daysOfWeekMap.isEmpty()) { daysOfWeekMap.insert(ICAL_MONDAY_WEEKDAY, Qt::Monday); daysOfWeekMap.insert(ICAL_THURSDAY_WEEKDAY, Qt::Thursday); daysOfWeekMap.insert(ICAL_WEDNESDAY_WEEKDAY, Qt::Wednesday); daysOfWeekMap.insert(ICAL_TUESDAY_WEEKDAY, Qt::Tuesday); daysOfWeekMap.insert(ICAL_FRIDAY_WEEKDAY, Qt::Friday); daysOfWeekMap.insert(ICAL_SATURDAY_WEEKDAY, Qt::Saturday); daysOfWeekMap.insert(ICAL_SUNDAY_WEEKDAY, Qt::Sunday); } qRule->setFrequency(QOrganizerRecurrenceRule::Weekly); QSet daysOfWeek; for (int d=0; d <= Qt::Sunday; d++) { short day = rule->by_day[d]; if (day != ICAL_RECURRENCE_ARRAY_MAX) { daysOfWeek.insert(daysOfWeekMap[icalrecurrencetype_day_day_of_week(rule->by_day[d])]); } } qRule->setDaysOfWeek(daysOfWeek); } void QOrganizerEDSEngine::parseMonthRecurrence(struct icalrecurrencetype *rule, QtOrganizer::QOrganizerRecurrenceRule *qRule) { qRule->setFrequency(QOrganizerRecurrenceRule::Monthly); QSet daysOfMonth; for (int d=0; d < ICAL_BY_MONTHDAY_SIZE; d++) { short day = rule->by_month_day[d]; if (day != ICAL_RECURRENCE_ARRAY_MAX) { daysOfMonth.insert(day); } } qRule->setDaysOfMonth(daysOfMonth); } void QOrganizerEDSEngine::parseYearRecurrence(struct icalrecurrencetype *rule, QtOrganizer::QOrganizerRecurrenceRule *qRule) { qRule->setFrequency(QOrganizerRecurrenceRule::Yearly); QSet daysOfYear; for (int d=0; d < ICAL_BY_YEARDAY_SIZE; d++) { short day = rule->by_year_day[d]; if (day != ICAL_RECURRENCE_ARRAY_MAX) { daysOfYear.insert(day); } } qRule->setDaysOfYear(daysOfYear); QSet monthOfYear; for (int d=0; d < ICAL_BY_MONTH_SIZE; d++) { short month = rule->by_month[d]; if (month != ICAL_RECURRENCE_ARRAY_MAX) { monthOfYear.insert(static_cast(month)); } } qRule->setMonthsOfYear(monthOfYear); } void QOrganizerEDSEngine::parseRecurrence(ECalComponent *comp, QOrganizerItem *item) { // recurence if (e_cal_component_has_rdates(comp)) { QSet dates; GSList *periodList = 0; e_cal_component_get_rdate_list(comp, &periodList); for(GSList *i = periodList; i != 0; i = i->next) { ECalComponentPeriod *period = (ECalComponentPeriod*) i->data; //TODO: get timezone info QDateTime dt = fromIcalTime(period->start, 0); dates.insert(dt.date()); //TODO: period.end, period.duration } e_cal_component_free_period_list(periodList); QOrganizerItemRecurrence rec = item->detail(QOrganizerItemDetail::TypeRecurrence); rec.setRecurrenceDates(dates); item->saveDetail(&rec); } if (e_cal_component_has_exdates(comp)) { QSet dates; GSList *exdateList = 0; e_cal_component_get_exdate_list(comp, &exdateList); for(GSList *i = exdateList; i != 0; i = i->next) { ECalComponentDateTime* dateTime = (ECalComponentDateTime*) i->data; QDateTime dt = fromIcalTime(*dateTime->value, dateTime->tzid); dates.insert(dt.date()); } e_cal_component_free_exdate_list(exdateList); QOrganizerItemRecurrence irec = item->detail(QOrganizerItemDetail::TypeRecurrence); irec.setExceptionDates(dates); item->saveDetail(&irec); } // rules GSList *ruleList = 0; e_cal_component_get_rrule_list(comp, &ruleList); if (ruleList) { QSet qRules; for(GSList *i = ruleList; i != 0; i = i->next) { struct icalrecurrencetype *rule = (struct icalrecurrencetype*) i->data; QOrganizerRecurrenceRule qRule; switch (rule->freq) { case ICAL_SECONDLY_RECURRENCE: case ICAL_MINUTELY_RECURRENCE: case ICAL_HOURLY_RECURRENCE: qWarning() << "Recurrence frequency not supported"; break; case ICAL_DAILY_RECURRENCE: qRule.setFrequency(QOrganizerRecurrenceRule::Daily); break; case ICAL_WEEKLY_RECURRENCE: parseWeekRecurrence(rule, &qRule); break; case ICAL_MONTHLY_RECURRENCE: parseMonthRecurrence(rule, &qRule); break; case ICAL_YEARLY_RECURRENCE: parseYearRecurrence(rule, &qRule); break; case ICAL_NO_RECURRENCE: break; } if (icaltime_is_date(rule->until)) { QDate dt = QDate::fromString(icaltime_as_ical_string(rule->until), "yyyyMMdd"); if (dt.isValid()) { qRule.setLimit(dt); } } else if (rule->count > 0) { qRule.setLimit(rule->count); } qRule.setInterval(rule->interval); QSet positions; for (int d=0; d < ICAL_BY_SETPOS_SIZE; d++) { short day = rule->by_set_pos[d]; if (day != ICAL_RECURRENCE_ARRAY_MAX) { positions.insert(day); } } qRule.setPositions(positions); qRules << qRule; } if (!qRules.isEmpty()) { QOrganizerItemRecurrence irec = item->detail(QOrganizerItemDetail::TypeRecurrence); irec.setRecurrenceRules(qRules); item->saveDetail(&irec); } e_cal_component_free_recur_list(ruleList); } // TODO: exeptions rules } void QOrganizerEDSEngine::parsePriority(ECalComponent *comp, QOrganizerItem *item) { gint *priority = 0; e_cal_component_get_priority(comp, &priority); if (priority) { QOrganizerItemPriority iPriority = item->detail(QOrganizerItemDetail::TypePriority); if ((*priority >= QOrganizerItemPriority::UnknownPriority) && (*priority <= QOrganizerItemPriority::LowPriority)) { iPriority.setPriority((QOrganizerItemPriority::Priority) *priority); } else { iPriority.setPriority(QOrganizerItemPriority::UnknownPriority); } e_cal_component_free_priority(priority); item->saveDetail(&iPriority); } } void QOrganizerEDSEngine::parseLocation(ECalComponent *comp, QOrganizerItem *item) { const gchar *location; e_cal_component_get_location(comp, &location); if (location) { QOrganizerItemLocation ld = item->detail(QOrganizerItemDetail::TypeLocation); ld.setLabel(QString::fromUtf8(location)); item->saveDetail(&ld); } } void QOrganizerEDSEngine::parseDueDate(ECalComponent *comp, QOrganizerItem *item) { ECalComponentDateTime due; e_cal_component_get_due(comp, &due); if (due.value) { QOrganizerTodoTime ttr = item->detail(QOrganizerItemDetail::TypeTodoTime); ttr.setDueDateTime(fromIcalTime(*due.value, due.tzid)); if (icaltime_is_date(*due.value) != ttr.isAllDay()) { ttr.setAllDay(icaltime_is_date(*due.value)); } item->saveDetail(&ttr); } e_cal_component_free_datetime(&due); } void QOrganizerEDSEngine::parseProgress(ECalComponent *comp, QOrganizerItem *item) { gint percentage = e_cal_component_get_percent_as_int(comp); if (percentage > 0 && percentage <= 100) { QOrganizerTodoProgress tp = item->detail(QOrganizerItemDetail::TypeTodoProgress); tp.setPercentageComplete(percentage); item->saveDetail(&tp); } } void QOrganizerEDSEngine::parseStatus(ECalComponent *comp, QOrganizerItem *item) { icalproperty_status status; e_cal_component_get_status(comp, &status); QOrganizerTodoProgress tp; switch(status) { case ICAL_STATUS_NONE: tp.setStatus(QOrganizerTodoProgress::StatusNotStarted); break; case ICAL_STATUS_INPROCESS: tp.setStatus(QOrganizerTodoProgress::StatusInProgress); break; case ICAL_STATUS_COMPLETED: tp.setStatus(QOrganizerTodoProgress::StatusComplete); break; case ICAL_STATUS_CANCELLED: default: //TODO: not supported break; } item->saveDetail(&tp); } void QOrganizerEDSEngine::parseAttendeeList(ECalComponent *comp, QOrganizerItem *item) { GSList *attendeeList = 0; e_cal_component_get_attendee_list(comp, &attendeeList); for (GSList *attendeeIter=attendeeList; attendeeIter != 0; attendeeIter = attendeeIter->next) { ECalComponentAttendee *attendee = static_cast(attendeeIter->data); QOrganizerEventAttendee qAttendee; qAttendee.setAttendeeId(QString::fromUtf8(attendee->member)); qAttendee.setName(QString::fromUtf8(attendee->cn)); qAttendee.setEmailAddress(QString::fromUtf8(attendee->value)); switch(attendee->role) { case ICAL_ROLE_REQPARTICIPANT: qAttendee.setParticipationRole(QOrganizerEventAttendee::RoleRequiredParticipant); break; case ICAL_ROLE_OPTPARTICIPANT: qAttendee.setParticipationRole(QOrganizerEventAttendee::RoleOptionalParticipant); break; case ICAL_ROLE_CHAIR: qAttendee.setParticipationRole(QOrganizerEventAttendee::RoleChairperson); break; case ICAL_ROLE_X: qAttendee.setParticipationRole(QOrganizerEventAttendee::RoleHost); break; case ICAL_ROLE_NONE: default: qAttendee.setParticipationRole(QOrganizerEventAttendee::RoleNonParticipant); break; } switch(attendee->status) { case ICAL_PARTSTAT_ACCEPTED: qAttendee.setParticipationStatus(QOrganizerEventAttendee::StatusAccepted); break; case ICAL_PARTSTAT_DECLINED: qAttendee.setParticipationStatus(QOrganizerEventAttendee::StatusDeclined); break; case ICAL_PARTSTAT_TENTATIVE: qAttendee.setParticipationStatus(QOrganizerEventAttendee::StatusTentative); break; case ICAL_PARTSTAT_DELEGATED: qAttendee.setParticipationStatus(QOrganizerEventAttendee::StatusDelegated); break; case ICAL_PARTSTAT_COMPLETED: qAttendee.setParticipationStatus(QOrganizerEventAttendee::StatusCompleted); break; case ICAL_PARTSTAT_INPROCESS: qAttendee.setParticipationStatus(QOrganizerEventAttendee::StatusInProcess); break; case ICAL_PARTSTAT_NEEDSACTION: case ICAL_PARTSTAT_NONE: default: qAttendee.setParticipationStatus(QOrganizerEventAttendee::StatusUnknown); break; } item->saveDetail(&qAttendee); } e_cal_component_free_attendee_list(attendeeList); } void QOrganizerEDSEngine::parseExtendedDetails(ECalComponent *comp, QOrganizerItem *item) { icalcomponent *icalcomp = e_cal_component_get_icalcomponent(comp); for (icalproperty *prop = icalcomponent_get_first_property(icalcomp, ICAL_X_PROPERTY); prop != NULL; prop = icalcomponent_get_next_property (icalcomp, ICAL_X_PROPERTY)) { QOrganizerItemExtendedDetail ex; ex.setName(QString::fromUtf8(icalproperty_get_x_name(prop))); ex.setData(QByteArray(icalproperty_get_x(prop))); item->saveDetail(&ex); } } QOrganizerItem *QOrganizerEDSEngine::parseEvent(ECalComponent *comp, QList detailsHint) { QOrganizerItem *event; if (hasRecurrence(comp)) { event = new QOrganizerEventOccurrence(); } else { event = new QOrganizerEvent(); } if (detailsHint.isEmpty() || detailsHint.contains(QOrganizerItemDetail::TypeEventTime)) { parseStartTime(comp, event); parseEndTime(comp, event); } if (detailsHint.isEmpty() || detailsHint.contains(QOrganizerItemDetail::TypeRecurrence)) { parseRecurrence(comp, event); } if (detailsHint.isEmpty() || detailsHint.contains(QOrganizerItemDetail::TypePriority)) { parsePriority(comp, event); } if (detailsHint.isEmpty() || detailsHint.contains(QOrganizerItemDetail::TypeLocation)) { parseLocation(comp, event); } return event; } QOrganizerItem *QOrganizerEDSEngine::parseToDo(ECalComponent *comp, QList detailsHint) { QOrganizerItem *todo; if (hasRecurrence(comp)) { todo = new QOrganizerTodoOccurrence(); } else { todo = new QOrganizerTodo(); } if (detailsHint.isEmpty() || detailsHint.contains(QOrganizerItemDetail::TypeTodoTime)) { parseTodoStartTime(comp, todo); parseDueDate(comp, todo); } if (detailsHint.isEmpty() || detailsHint.contains(QOrganizerItemDetail::TypeRecurrence)) { parseRecurrence(comp, todo); } if (detailsHint.isEmpty() || detailsHint.contains(QOrganizerItemDetail::TypePriority)) { parsePriority(comp, todo); } if (detailsHint.isEmpty() || detailsHint.contains(QOrganizerItemDetail::TypeTodoProgress)) { parseProgress(comp, todo); parseStatus(comp, todo); } return todo; } QOrganizerItem *QOrganizerEDSEngine::parseJournal(ECalComponent *comp, QList detailsHint) { QOrganizerJournal *journal = new QOrganizerJournal(); if (detailsHint.isEmpty() || detailsHint.contains(QOrganizerItemDetail::TypeJournalTime)) { ECalComponentDateTime dt; e_cal_component_get_dtstart(comp, &dt); if (dt.value) { QOrganizerJournalTime jtime; jtime.setEntryDateTime(fromIcalTime(*dt.value, dt.tzid)); journal->saveDetail(&jtime); } e_cal_component_free_datetime(&dt); } return journal; } void QOrganizerEDSEngine::parseSummary(ECalComponent *comp, QtOrganizer::QOrganizerItem *item) { ECalComponentText summary; e_cal_component_get_summary(comp, &summary); if (summary.value) { item->setDisplayLabel(QString::fromUtf8(summary.value)); } } void QOrganizerEDSEngine::parseDescription(ECalComponent *comp, QtOrganizer::QOrganizerItem *item) { GSList *descriptions = 0; e_cal_component_get_description_list(comp, &descriptions); QStringList itemDescription; for(GSList *descList = descriptions; descList != 0; descList = descList->next) { ECalComponentText *description = static_cast(descList->data); if (description && description->value) { itemDescription.append(QString::fromUtf8(description->value)); } } item->setDescription(itemDescription.join("\n")); e_cal_component_free_text_list(descriptions); } void QOrganizerEDSEngine::parseComments(ECalComponent *comp, QtOrganizer::QOrganizerItem *item) { GSList *comments = 0; e_cal_component_get_comment_list(comp, &comments); for(int ci=0, ciMax=g_slist_length(comments); ci < ciMax; ci++) { ECalComponentText *txt = static_cast(g_slist_nth_data(comments, ci)); item->addComment(QString::fromUtf8(txt->value)); } e_cal_component_free_text_list(comments); } void QOrganizerEDSEngine::parseTags(ECalComponent *comp, QtOrganizer::QOrganizerItem *item) { GSList *categories = 0; e_cal_component_get_categories_list(comp, &categories); for(GSList *tag=categories; tag != 0; tag = tag->next) { item->addTag(QString::fromUtf8(static_cast(tag->data))); } e_cal_component_free_categories_list(categories); } QUrl QOrganizerEDSEngine::dencodeAttachment(ECalComponentAlarm *alarm) { QUrl attachment; icalattach *attach = 0; e_cal_component_alarm_get_attach(alarm, &attach); if (attach) { if (icalattach_get_is_url(attach)) { const gchar *url = icalattach_get_url(attach); attachment = QUrl(QString::fromUtf8(url)); } icalattach_unref(attach); } return attachment; } void QOrganizerEDSEngine::parseVisualReminderAttachment(ECalComponentAlarm *alarm, QOrganizerItemReminder *aDetail) { QUrl attach = dencodeAttachment(alarm); if (attach.isValid()) { aDetail->setValue(QOrganizerItemVisualReminder::FieldDataUrl, attach); } ECalComponentText txt; e_cal_component_alarm_get_description(alarm, &txt); aDetail->setValue(QOrganizerItemVisualReminder::FieldMessage, QString::fromUtf8(txt.value)); } void QOrganizerEDSEngine::parseAudibleReminderAttachment(ECalComponentAlarm *alarm, QOrganizerItemReminder *aDetail) { QUrl attach = dencodeAttachment(alarm); if (attach.isValid()) { aDetail->setValue(QOrganizerItemAudibleReminder::FieldDataUrl, attach); } } void QOrganizerEDSEngine::parseReminders(ECalComponent *comp, QtOrganizer::QOrganizerItem *item, QList detailsHint) { GList *alarms = e_cal_component_get_alarm_uids(comp); for(GList *a = alarms; a != 0; a = a->next) { QOrganizerItemReminder *aDetail = 0; QSharedPointer alarm(e_cal_component_get_alarm(comp, static_cast(a->data)), e_cal_component_alarm_free); if (!alarm) { continue; } ECalComponentAlarmAction aAction; e_cal_component_alarm_get_action(alarm.data(), &aAction); switch(aAction) { case E_CAL_COMPONENT_ALARM_DISPLAY: if (!detailsHint.isEmpty() && !detailsHint.contains(QOrganizerItemDetail::TypeReminder) && !detailsHint.contains(QOrganizerItemDetail::TypeVisualReminder)) { continue; } aDetail = new QOrganizerItemVisualReminder(); parseVisualReminderAttachment(alarm.data(), aDetail); break; case E_CAL_COMPONENT_ALARM_AUDIO: if (!detailsHint.isEmpty() && !detailsHint.contains(QOrganizerItemDetail::TypeReminder) && !detailsHint.contains(QOrganizerItemDetail::TypeAudibleReminder)) { continue; } // use audio as fallback default: aDetail = new QOrganizerItemAudibleReminder(); parseAudibleReminderAttachment(alarm.data(), aDetail); break; } ECalComponentAlarmTrigger trigger; e_cal_component_alarm_get_trigger(alarm.data(), &trigger); int relSecs = 0; if (trigger.type == E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START) { relSecs = - icaldurationtype_as_int(trigger.u.rel_duration); if (relSecs < 0) { relSecs = 0; qWarning() << "QOrganizer does not support triggers after event start"; } } else if (trigger.type != E_CAL_COMPONENT_ALARM_TRIGGER_NONE) { qWarning() << "QOrganizer only supports triggers relative to event start."; } aDetail->setSecondsBeforeStart(relSecs); ECalComponentAlarmRepeat aRepeat; e_cal_component_alarm_get_repeat(alarm.data(), &aRepeat); aDetail->setRepetition(aRepeat.repetitions, icaldurationtype_as_int(aRepeat.duration)); item->saveDetail(aDetail); delete aDetail; } } void QOrganizerEDSEngine::parseEventsAsync(const QMap &events, bool isIcalEvents, QList detailsHint, QObject *source, const QByteArray &slot) { QMap request; Q_FOREACH(const QString &collectionId, events.keys()) { QOrganizerEDSCollectionEngineId *collection = d->m_sourceRegistry->collectionEngineId(collectionId); request.insert(collection, events.value(collectionId)); } // the thread will destroy itself when done QOrganizerParseEventThread *thread = new QOrganizerParseEventThread(source, slot); thread->start(request, isIcalEvents, detailsHint); } QList QOrganizerEDSEngine::parseEvents(QOrganizerEDSCollectionEngineId *collectionId, GSList *events, bool isIcalEvents, QList detailsHint) { QList items; for (GSList *l = events; l; l = l->next) { QOrganizerItem *item; ECalComponent *comp; if (isIcalEvents) { icalcomponent *clone = icalcomponent_new_clone(static_cast(l->data)); if (clone && icalcomponent_is_valid(clone)) { comp = e_cal_component_new_from_icalcomponent(clone); } else { qWarning() << "Fail to parse event"; continue; } } else { comp = E_CAL_COMPONENT(l->data); } //type ECalComponentVType vType = e_cal_component_get_vtype(comp); switch(vType) { case E_CAL_COMPONENT_EVENT: item = parseEvent(comp, detailsHint); break; case E_CAL_COMPONENT_TODO: item = parseToDo(comp, detailsHint); break; case E_CAL_COMPONENT_JOURNAL: item = parseJournal(comp, detailsHint); break; case E_CAL_COMPONENT_FREEBUSY: qWarning() << "Component FREEBUSY not supported;"; continue; case E_CAL_COMPONENT_TIMEZONE: qWarning() << "Component TIMEZONE not supported;"; case E_CAL_COMPONENT_NO_TYPE: continue; } // id is mandatory parseId(comp, item, collectionId); if (detailsHint.isEmpty() || detailsHint.contains(QOrganizerItemDetail::TypeDescription)) { parseDescription(comp, item); } if (detailsHint.isEmpty() || detailsHint.contains(QOrganizerItemDetail::TypeDisplayLabel)) { parseSummary(comp, item); } if (detailsHint.isEmpty() || detailsHint.contains(QOrganizerItemDetail::TypeComment)) { parseComments(comp, item); } if (detailsHint.isEmpty() || detailsHint.contains(QOrganizerItemDetail::TypeTag)) { parseTags(comp, item); } if (detailsHint.isEmpty() || detailsHint.contains(QOrganizerItemDetail::TypeReminder) || detailsHint.contains(QOrganizerItemDetail::TypeVisualReminder) || detailsHint.contains(QOrganizerItemDetail::TypeAudibleReminder) || detailsHint.contains(QOrganizerItemDetail::TypeEmailReminder)) { parseReminders(comp, item, detailsHint); } if (detailsHint.isEmpty() || detailsHint.contains(QOrganizerItemDetail::TypeEventAttendee)) { parseAttendeeList(comp, item); } if (detailsHint.isEmpty() || detailsHint.contains(QOrganizerItemDetail::TypeExtendedDetail)) { parseExtendedDetails(comp, item); } items << *item; delete item; if (isIcalEvents) { g_object_unref(comp); } } return items; } QList QOrganizerEDSEngine::parseEvents(const QString &collectionId, GSList *events, bool isIcalEvents, QList detailsHint) { QOrganizerEDSCollectionEngineId *collection = d->m_sourceRegistry->collectionEngineId(collectionId); return parseEvents(collection, events, isIcalEvents, detailsHint); } void QOrganizerEDSEngine::parseStartTime(const QOrganizerItem &item, ECalComponent *comp) { QOrganizerEventTime etr = item.detail(QOrganizerItemDetail::TypeEventTime); if (!etr.isEmpty()) { QByteArray tzId; struct icaltimetype ict = fromQDateTime(etr.startDateTime(), etr.isAllDay(), &tzId); ECalComponentDateTime dt; dt.tzid = tzId.isEmpty() ? NULL : tzId.constData(); dt.value = &ict; e_cal_component_set_dtstart(comp, &dt); } } void QOrganizerEDSEngine::parseEndTime(const QOrganizerItem &item, ECalComponent *comp) { QOrganizerEventTime etr = item.detail(QOrganizerItemDetail::TypeEventTime); if (!etr.isEmpty()) { QDateTime eventEndDateTime = etr.endDateTime(); if (etr.startDateTime() > eventEndDateTime) { eventEndDateTime = etr.startDateTime(); } if (etr.isAllDay() && (eventEndDateTime.date() == etr.startDateTime().date())) { eventEndDateTime = etr.startDateTime().addDays(1); } QByteArray tzId; struct icaltimetype ict = fromQDateTime(eventEndDateTime, etr.isAllDay(), &tzId); ECalComponentDateTime dt; dt.tzid = tzId.isEmpty() ? NULL : tzId.constData(); dt.value = &ict; e_cal_component_set_dtend(comp, &dt); } } void QOrganizerEDSEngine::parseTodoStartTime(const QOrganizerItem &item, ECalComponent *comp) { QOrganizerTodoTime etr = item.detail(QOrganizerItemDetail::TypeTodoTime); if (!etr.isEmpty() && !etr.startDateTime().isNull()) { QByteArray tzId; struct icaltimetype ict = fromQDateTime(etr.startDateTime(), etr.isAllDay(), &tzId); ECalComponentDateTime dt; dt.tzid = tzId.isEmpty() ? NULL : tzId.constData(); dt.value = &ict; e_cal_component_set_dtstart(comp, &dt); } } void QOrganizerEDSEngine::parseWeekRecurrence(const QOrganizerRecurrenceRule &qRule, struct icalrecurrencetype *rule) { static QMap daysOfWeekMap; if (daysOfWeekMap.isEmpty()) { daysOfWeekMap.insert(Qt::Monday, ICAL_MONDAY_WEEKDAY); daysOfWeekMap.insert(Qt::Thursday, ICAL_THURSDAY_WEEKDAY); daysOfWeekMap.insert(Qt::Wednesday, ICAL_WEDNESDAY_WEEKDAY); daysOfWeekMap.insert(Qt::Tuesday, ICAL_TUESDAY_WEEKDAY); daysOfWeekMap.insert(Qt::Friday, ICAL_FRIDAY_WEEKDAY); daysOfWeekMap.insert(Qt::Saturday, ICAL_SATURDAY_WEEKDAY); daysOfWeekMap.insert(Qt::Sunday, ICAL_SUNDAY_WEEKDAY); } QList daysOfWeek = qRule.daysOfWeek().toList(); int c = 0; rule->freq = ICAL_WEEKLY_RECURRENCE; for(int d=Qt::Monday; d <= Qt::Sunday; d++) { if (daysOfWeek.contains(static_cast(d))) { rule->by_day[c++] = daysOfWeekMap[static_cast(d)]; } } for (int d = c; d < ICAL_BY_DAY_SIZE; d++) { rule->by_day[d] = ICAL_RECURRENCE_ARRAY_MAX; } } void QOrganizerEDSEngine::parseMonthRecurrence(const QOrganizerRecurrenceRule &qRule, struct icalrecurrencetype *rule) { rule->freq = ICAL_MONTHLY_RECURRENCE; int c = 0; Q_FOREACH(int daysOfMonth, qRule.daysOfMonth()) { rule->by_month_day[c++] = daysOfMonth; } for (int d = c; d < ICAL_BY_MONTHDAY_SIZE; d++) { rule->by_month_day[d] = ICAL_RECURRENCE_ARRAY_MAX; } } void QOrganizerEDSEngine::parseYearRecurrence(const QOrganizerRecurrenceRule &qRule, struct icalrecurrencetype *rule) { rule->freq = ICAL_YEARLY_RECURRENCE; QList daysOfYear = qRule.daysOfYear().toList(); int c = 0; for (int d=1; d < ICAL_BY_YEARDAY_SIZE; d++) { if (daysOfYear.contains(d)) { rule->by_year_day[c++] = d; } } for (int d = c; d < ICAL_BY_YEARDAY_SIZE; d++) { rule->by_year_day[d] = ICAL_RECURRENCE_ARRAY_MAX; } c = 0; QList monthOfYear = qRule.monthsOfYear().toList(); for (int d=1; d < ICAL_BY_MONTH_SIZE; d++) { if (monthOfYear.contains(static_cast(d))) { rule->by_month[c++] = d; } } for (int d = c; d < ICAL_BY_YEARDAY_SIZE; d++) { rule->by_month[d] = ICAL_RECURRENCE_ARRAY_MAX; } } void QOrganizerEDSEngine::parseRecurrence(const QOrganizerItem &item, ECalComponent *comp) { QOrganizerItemRecurrence rec = item.detail(QOrganizerItemDetail::TypeRecurrence); if (!rec.isEmpty()) { GSList *periodList = 0; Q_FOREACH(const QDate &dt, rec.recurrenceDates()) { ECalComponentPeriod *period = g_new0(ECalComponentPeriod, 1); period->start = icaltime_from_timet(QDateTime(dt).toTime_t(), FALSE); periodList = g_slist_append(periodList, period); //TODO: period.end, period.duration } e_cal_component_set_rdate_list(comp, periodList); e_cal_component_free_period_list(periodList); GSList *exdateList = 0; Q_FOREACH(const QDate &dt, rec.exceptionDates()) { ECalComponentDateTime *dateTime = g_new0(ECalComponentDateTime, 1); struct icaltimetype *itt = g_new0(struct icaltimetype, 1); *itt = icaltime_from_timet(QDateTime(dt).toTime_t(), FALSE); dateTime->value = itt; exdateList = g_slist_append(exdateList, dateTime); } e_cal_component_set_exdate_list(comp, exdateList); e_cal_component_free_exdate_list(exdateList); GSList *ruleList = 0; Q_FOREACH(const QOrganizerRecurrenceRule &qRule, rec.recurrenceRules()) { struct icalrecurrencetype *rule = g_new0(struct icalrecurrencetype, 1); icalrecurrencetype_clear(rule); switch(qRule.frequency()) { case QOrganizerRecurrenceRule::Daily: rule->freq = ICAL_DAILY_RECURRENCE; break; case QOrganizerRecurrenceRule::Weekly: parseWeekRecurrence(qRule, rule); break; case QOrganizerRecurrenceRule::Monthly: parseMonthRecurrence(qRule, rule); break; case QOrganizerRecurrenceRule::Yearly: parseYearRecurrence(qRule, rule); break; case QOrganizerRecurrenceRule::Invalid: rule->freq = ICAL_NO_RECURRENCE; break; } switch (qRule.limitType()) { case QOrganizerRecurrenceRule::DateLimit: if (qRule.limitDate().isValid()) { rule->until = icaltime_from_timet(QDateTime(qRule.limitDate()).toTime_t(), TRUE); } break; case QOrganizerRecurrenceRule::CountLimit: if (qRule.limitCount() > 0) { rule->count = qRule.limitCount(); } break; case QOrganizerRecurrenceRule::NoLimit: default: rule->count = 0; } QSet positions = qRule.positions(); for (int d=1; d < ICAL_BY_SETPOS_SIZE; d++) { if (positions.contains(d)) { rule->by_set_pos[d] = d; } else { rule->by_set_pos[d] = ICAL_RECURRENCE_ARRAY_MAX; } } rule->interval = qRule.interval(); ruleList = g_slist_append(ruleList, rule); } e_cal_component_set_rrule_list(comp, ruleList); g_slist_free_full(ruleList, g_free); } } void QOrganizerEDSEngine::parsePriority(const QOrganizerItem &item, ECalComponent *comp) { QOrganizerItemPriority priority = item.detail(QOrganizerItemDetail::TypePriority); if (!priority.isEmpty()) { gint iPriority = (gint) priority.priority(); e_cal_component_set_priority(comp, &iPriority); } } void QOrganizerEDSEngine::parseLocation(const QOrganizerItem &item, ECalComponent *comp) { QOrganizerItemLocation ld = item.detail(QOrganizerItemDetail::TypeLocation); if (!ld.isEmpty()) { e_cal_component_set_location(comp, ld.label().toUtf8().data()); } } void QOrganizerEDSEngine::parseDueDate(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp) { QOrganizerTodoTime ttr = item.detail(QOrganizerItemDetail::TypeTodoTime); if (!ttr.isEmpty() && !ttr.dueDateTime().isNull()) { QDateTime dueDateTime = ttr.dueDateTime(); if (ttr.startDateTime() > dueDateTime) { dueDateTime = ttr.startDateTime(); } if (ttr.isAllDay() && (dueDateTime.date() == ttr.startDateTime().date())) { dueDateTime = ttr.startDateTime().addDays(1); } QByteArray tzId; struct icaltimetype ict = fromQDateTime(dueDateTime, ttr.isAllDay(), &tzId); ECalComponentDateTime dt; dt.tzid = tzId.isEmpty() ? NULL : tzId.constData(); dt.value = &ict; e_cal_component_set_due(comp, &dt);; } } void QOrganizerEDSEngine::parseProgress(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp) { QOrganizerTodoProgress tp = item.detail(QOrganizerItemDetail::TypeTodoProgress); if (!tp.isEmpty() && (tp.percentageComplete() > 0)) { e_cal_component_set_percent_as_int(comp, tp.percentageComplete()); } } void QOrganizerEDSEngine::parseStatus(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp) { QOrganizerTodoProgress tp = item.detail(QOrganizerItemDetail::TypeTodoProgress); if (!tp.isEmpty()) { switch(tp.status()) { case QOrganizerTodoProgress::StatusNotStarted: e_cal_component_set_status(comp, ICAL_STATUS_NONE); break; case QOrganizerTodoProgress::StatusInProgress: e_cal_component_set_status(comp, ICAL_STATUS_INPROCESS); break; case QOrganizerTodoProgress::StatusComplete: e_cal_component_set_status(comp, ICAL_STATUS_COMPLETED); break; default: e_cal_component_set_status(comp, ICAL_STATUS_CANCELLED); break; } } } void QOrganizerEDSEngine::parseAttendeeList(const QOrganizerItem &item, ECalComponent *comp) { GSList *attendeeList = 0; Q_FOREACH(const QOrganizerEventAttendee &attendee, item.details(QOrganizerItemDetail::TypeEventAttendee)) { ECalComponentAttendee *calAttendee = g_new0(ECalComponentAttendee, 1); calAttendee->member = g_strdup(attendee.attendeeId().toUtf8().constData()); calAttendee->cn = g_strdup(attendee.name().toUtf8().constData()); calAttendee->value = g_strdup(attendee.emailAddress().toUtf8().constData()); switch(attendee.participationRole()) { case QOrganizerEventAttendee::RoleRequiredParticipant: calAttendee->role = ICAL_ROLE_REQPARTICIPANT; break; case QOrganizerEventAttendee::RoleOptionalParticipant: calAttendee->role = ICAL_ROLE_OPTPARTICIPANT; break; case QOrganizerEventAttendee::RoleChairperson: calAttendee->role = ICAL_ROLE_CHAIR; break; case QOrganizerEventAttendee::RoleHost: calAttendee->role = ICAL_ROLE_X; break; default: calAttendee->role = ICAL_ROLE_NONE; } switch(attendee.participationStatus()) { case QOrganizerEventAttendee::StatusAccepted: calAttendee->status = ICAL_PARTSTAT_ACCEPTED; break; case QOrganizerEventAttendee::StatusDeclined: calAttendee->status = ICAL_PARTSTAT_DECLINED; break; case QOrganizerEventAttendee::StatusTentative: calAttendee->status = ICAL_PARTSTAT_TENTATIVE; break; case QOrganizerEventAttendee::StatusDelegated: calAttendee->status = ICAL_PARTSTAT_DELEGATED; break; case QOrganizerEventAttendee::StatusInProcess: calAttendee->status = ICAL_PARTSTAT_INPROCESS; break; case QOrganizerEventAttendee::StatusCompleted: calAttendee->status = ICAL_PARTSTAT_COMPLETED; break; case QOrganizerEventAttendee::StatusUnknown: default: calAttendee->status = ICAL_PARTSTAT_NONE; break; } attendeeList = g_slist_append(attendeeList, calAttendee); } e_cal_component_set_attendee_list(comp, attendeeList); e_cal_component_free_attendee_list(attendeeList); } void QOrganizerEDSEngine::parseExtendedDetails(const QOrganizerItem &item, ECalComponent *comp) { icalcomponent *icalcomp = e_cal_component_get_icalcomponent(comp); Q_FOREACH(const QOrganizerItemExtendedDetail &ex, item.details(QOrganizerItemDetail::TypeExtendedDetail)) { // We only support QByteArray. // We could use QStream serialization but it will make it impossible to read it from glib side, for example indicators. QByteArray data = ex.data().toByteArray(); if (data.isEmpty()) { qWarning() << "Invalid value for property" << ex.name() <<". EDS only supports QByteArray values for extended properties"; continue; } icalproperty *xProp = icalproperty_new_x(data.constData()); icalproperty_set_x_name(xProp, ex.name().toUtf8().constData()); icalcomponent_add_property(icalcomp, xProp); } } bool QOrganizerEDSEngine::hasRecurrence(ECalComponent *comp) { char *rid = e_cal_component_get_recurid_as_string(comp); bool result = (rid && strcmp(rid, "0")); if (rid) { free(rid); } return result; } void QOrganizerEDSEngine::parseId(ECalComponent *comp, QOrganizerItem *item, QOrganizerEDSCollectionEngineId *edsCollectionId) { ECalComponentId *id = e_cal_component_get_id(comp); QOrganizerEDSEngineId *edsParentId = 0; QOrganizerEDSEngineId *edsId; if (!edsCollectionId) { qWarning() << "Parse Id with null collection"; return; } edsId = QOrganizerEDSEngineId::fromComponentId(edsCollectionId->m_collectionId, id, &edsParentId); item->setId(QOrganizerItemId(edsId)); item->setGuid(QString("%1/%2") .arg(edsCollectionId->m_collectionId) .arg(edsId->m_itemId)); if (edsParentId) { QOrganizerItemParent itemParent = item->detail(QOrganizerItemDetail::TypeParent); itemParent.setParentId(QOrganizerItemId(edsParentId)); item->saveDetail(&itemParent); } QOrganizerCollectionId cId = QOrganizerCollectionId(edsCollectionId); item->setCollectionId(cId); e_cal_component_free_id(id); } ECalComponent *QOrganizerEDSEngine::createDefaultComponent(ECalClient *client, icalcomponent_kind iKind, ECalComponentVType eType) { ECalComponent *comp; icalcomponent *icalcomp = 0; if (client && !e_cal_client_get_default_object_sync(client, &icalcomp, NULL, NULL)) { icalcomp = icalcomponent_new(iKind); } comp = e_cal_component_new(); if (icalcomp && !e_cal_component_set_icalcomponent(comp, icalcomp)) { icalcomponent_free(icalcomp); } e_cal_component_set_new_vtype(comp, eType); return comp; } ECalComponent *QOrganizerEDSEngine::parseEventItem(ECalClient *client, const QOrganizerItem &item) { ECalComponent *comp = createDefaultComponent(client, ICAL_VEVENT_COMPONENT, E_CAL_COMPONENT_EVENT); parseStartTime(item, comp); parseEndTime(item, comp); parseRecurrence(item, comp); parsePriority(item, comp); parseLocation(item, comp); return comp; } ECalComponent *QOrganizerEDSEngine::parseTodoItem(ECalClient *client, const QOrganizerItem &item) { ECalComponent *comp = createDefaultComponent(client, ICAL_VTODO_COMPONENT, E_CAL_COMPONENT_TODO); parseTodoStartTime(item, comp); parseDueDate(item, comp); parseRecurrence(item, comp); parsePriority(item, comp); parseProgress(item, comp); parseStatus(item, comp); return comp; } ECalComponent *QOrganizerEDSEngine::parseJournalItem(ECalClient *client, const QOrganizerItem &item) { ECalComponent *comp = createDefaultComponent(client, ICAL_VJOURNAL_COMPONENT, E_CAL_COMPONENT_JOURNAL); QOrganizerJournalTime jtime = item.detail(QOrganizerItemDetail::TypeJournalTime); if (!jtime.isEmpty()) { QByteArray tzId; struct icaltimetype ict = fromQDateTime(jtime.entryDateTime(), false, &tzId); ECalComponentDateTime dt; dt.tzid = tzId.isEmpty() ? NULL : tzId.constData(); dt.value = &ict; e_cal_component_set_dtstart(comp, &dt); } return comp; } void QOrganizerEDSEngine::parseSummary(const QOrganizerItem &item, ECalComponent *comp) { //summary if (!item.displayLabel().isEmpty()) { ECalComponentText txt; QByteArray str = item.displayLabel().toUtf8(); txt.altrep = 0; txt.value = str.constData(); e_cal_component_set_summary(comp, &txt); } } void QOrganizerEDSEngine::parseDescription(const QOrganizerItem &item, ECalComponent *comp) { //description if (!item.description().isEmpty()) { GSList *descriptions = 0; QList descList; Q_FOREACH(const QString &desc, item.description().split("\n")) { QByteArray str = desc.toUtf8(); ECalComponentText *txt = g_new0(ECalComponentText, 1); txt->value = str.constData(); descriptions = g_slist_append(descriptions, txt); // keep str alive until the property gets updated descList << str; } e_cal_component_set_description_list(comp, descriptions); e_cal_component_free_text_list(descriptions); } } void QOrganizerEDSEngine::parseComments(const QOrganizerItem &item, ECalComponent *comp) { //comments GSList *comments = 0; QList commentList; Q_FOREACH(const QString &comment, item.comments()) { QByteArray str = comment.toUtf8(); ECalComponentText *txt = g_new0(ECalComponentText, 1); txt->value = str.constData(); comments = g_slist_append(comments, txt); // keep str alive until the property gets updated commentList << str; } if (comments) { e_cal_component_set_comment_list(comp, comments); e_cal_component_free_text_list(comments); } } void QOrganizerEDSEngine::parseTags(const QOrganizerItem &item, ECalComponent *comp) { //tags GSList *categories = 0; QList tagList; Q_FOREACH(const QString &tag, item.tags()) { QByteArray str = tag.toUtf8(); categories = g_slist_append(categories, str.data()); // keep str alive until the property gets updated tagList << str; } if (categories) { e_cal_component_set_categories_list(comp, categories); g_slist_free(categories); } } void QOrganizerEDSEngine::encodeAttachment(const QUrl &url, ECalComponentAlarm *alarm) { if (!url.isEmpty()) { icalattach *attach = icalattach_new_from_url(url.toString().toUtf8()); e_cal_component_alarm_set_attach(alarm, attach); icalattach_unref(attach); } } void QOrganizerEDSEngine::parseVisualReminderAttachment(const QOrganizerItemDetail &detail, ECalComponentAlarm *alarm) { ECalComponentText txt; QByteArray str = detail.value(QOrganizerItemVisualReminder::FieldMessage).toString().toUtf8(); if (!str.isEmpty()) { txt.altrep = 0; txt.value = str.constData(); e_cal_component_alarm_set_description(alarm, &txt); } encodeAttachment(detail.value(QOrganizerItemVisualReminder::FieldDataUrl).toUrl(), alarm); } void QOrganizerEDSEngine::parseAudibleReminderAttachment(const QOrganizerItemDetail &detail, ECalComponentAlarm *alarm) { encodeAttachment(detail.value(QOrganizerItemAudibleReminder::FieldDataUrl).toUrl(), alarm); } void QOrganizerEDSEngine::parseReminders(const QOrganizerItem &item, ECalComponent *comp) { //reminders QList reminders = item.details(QOrganizerItemDetail::TypeAudibleReminder); reminders += item.details(QOrganizerItemDetail::TypeVisualReminder); Q_FOREACH(const QOrganizerItemDetail &detail, reminders) { const QOrganizerItemReminder *reminder = static_cast(&detail); ECalComponentAlarm *alarm = e_cal_component_alarm_new(); switch(reminder->type()) { case QOrganizerItemReminder::TypeVisualReminder: e_cal_component_alarm_set_action(alarm, E_CAL_COMPONENT_ALARM_DISPLAY); parseVisualReminderAttachment(detail, alarm); break; case QOrganizerItemReminder::TypeAudibleReminder: default: // use audio as fallback e_cal_component_alarm_set_action(alarm, E_CAL_COMPONENT_ALARM_AUDIO); parseAudibleReminderAttachment(detail, alarm); break; } ECalComponentAlarmTrigger trigger; trigger.type = E_CAL_COMPONENT_ALARM_TRIGGER_RELATIVE_START; trigger.u.rel_duration = icaldurationtype_from_int(- reminder->secondsBeforeStart()); e_cal_component_alarm_set_trigger(alarm, trigger); ECalComponentAlarmRepeat aRepeat; // TODO: check if this is really necessary aRepeat.repetitions = reminder->repetitionCount(); //qMax(reminder->repetitionCount(), 1); aRepeat.duration = icaldurationtype_from_int(reminder->repetitionDelay()); e_cal_component_alarm_set_repeat(alarm, aRepeat); e_cal_component_add_alarm(comp, alarm); e_cal_component_alarm_free(alarm); } } GSList *QOrganizerEDSEngine::parseItems(ECalClient *client, QList items, bool *hasRecurrence) { GSList *comps = 0; Q_FOREACH(const QOrganizerItem &item, items) { ECalComponent *comp = 0; *hasRecurrence = ((item.type() == QOrganizerItemType::TypeTodoOccurrence) || (item.type() == QOrganizerItemType::TypeEventOccurrence)); switch(item.type()) { case QOrganizerItemType::TypeEvent: case QOrganizerItemType::TypeEventOccurrence: comp = parseEventItem(client, item); break; case QOrganizerItemType::TypeTodo: case QOrganizerItemType::TypeTodoOccurrence: comp = parseTodoItem(client, item); break; case QOrganizerItemType::TypeJournal: comp = parseJournalItem(client, item); break; case QOrganizerItemType::TypeNote: qWarning() << "Component TypeNote not supported;"; case QOrganizerItemType::TypeUndefined: continue; } parseId(item, comp); parseSummary(item, comp); parseDescription(item, comp); parseComments(item, comp); parseTags(item, comp); parseReminders(item, comp); parseAttendeeList(item, comp); parseExtendedDetails(item, comp); if (!item.id().isNull()) { e_cal_component_commit_sequence(comp); } else { e_cal_component_abort_sequence(comp); } comps = g_slist_append(comps, icalcomponent_new_clone(e_cal_component_get_icalcomponent(comp))); g_object_unref(comp); } return comps; } void QOrganizerEDSEngine::parseId(const QOrganizerItem &item, ECalComponent *comp) { QOrganizerItemId itemId = item.id(); if (!itemId.isNull()) { QString rId; QString cId = QOrganizerEDSEngineId::toComponentId(itemId, &rId); e_cal_component_set_uid(comp, cId.toUtf8().data()); if (!rId.isEmpty()) { ECalComponentRange recur_id; struct icaltimetype tt = icaltime_from_string(rId.toUtf8().data()); recur_id.type = E_CAL_COMPONENT_RANGE_SINGLE; recur_id.datetime.value = &tt; e_cal_component_set_recurid(comp, &recur_id); } } } qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-fetchocurrencedata.cpp0000644000015600001650000000613412672562647030572 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "qorganizer-eds-fetchocurrencedata.h" #include #include #include using namespace QtOrganizer; FetchOcurrenceData::FetchOcurrenceData(QOrganizerEDSEngine *engine, QOrganizerAbstractRequest *req) : RequestData(engine, req), m_components(0) { } FetchOcurrenceData::~FetchOcurrenceData() { if (m_components) { g_slist_free_full(m_components, (GDestroyNotify)icalcomponent_free); m_components = 0; } } time_t FetchOcurrenceData::startDate() const { QDateTime startDate = request()->startDate(); if (!startDate.isValid()) { startDate = QDateTime::fromTime_t(0); qWarning() << "Start date is invalide using " << startDate; } return startDate.toTime_t(); } time_t FetchOcurrenceData::endDate() const { QDateTime endDate = request()->endDate(); if (!endDate.isValid()) { QDate currentDate = QDate::currentDate(); endDate.setTime(QTime(0, 0, 0)); endDate.setDate(QDate(currentDate.year()+1, 1, 1)); qWarning() << "End date is invalid using " << endDate; } return endDate.toTime_t(); } void FetchOcurrenceData::finish(QOrganizerManager::Error error, QtOrganizer::QOrganizerAbstractRequest::State state) { QList results; if (m_components) { QOrganizerItemOccurrenceFetchRequest *req = request(); QString collectionId = req->parentItem().collectionId().toString(); results = parent()->parseEvents(collectionId, m_components, true, req->fetchHint().detailTypesHint()); g_slist_free_full(m_components, (GDestroyNotify)icalcomponent_free); m_components = 0; } QOrganizerManagerEngine::updateItemOccurrenceFetchRequest(request(), results, error, state); RequestData::finish(error, state); } void FetchOcurrenceData::appendResult(icalcomponent *comp) { m_components = g_slist_append(m_components, comp); } qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-saverequestdata.h0000644000015600001650000000423412672562647027606 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __QORGANIZER_EDS_SAVEREQUESTDATA_H__ #define __QORGANIZER_EDS_SAVEREQUESTDATA_H__ #include "qorganizer-eds-requestdata.h" #include "qorganizer-eds-engine.h" class SaveRequestData : public RequestData { public: SaveRequestData(QOrganizerEDSEngine *engine, QtOrganizer::QOrganizerAbstractRequest *req); ~SaveRequestData(); void finish(QtOrganizer::QOrganizerManager::Error error = QtOrganizer::QOrganizerManager::NoError, QtOrganizer::QOrganizerAbstractRequest::State state = QtOrganizer::QOrganizerAbstractRequest::FinishedState); QString nextCollection(); QString currentCollection() const; QList takeItemsToCreate(); QList takeItemsToUpdate(); bool end() const; void setWorkingItems(QList items); QList workingItems() const; int updateMode() const; void appendResults(QList results); void appendResult(const QtOrganizer::QOrganizerItem &item, QtOrganizer::QOrganizerManager::Error error = QtOrganizer::QOrganizerManager::NoError); private: QList m_result; QMap m_erros; QMap > m_items; QList m_currentItems; QList m_workingItems; QString m_currentCollection; }; #endif qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-fetchbyidrequestdata.cpp0000644000015600001650000000515612672562647031150 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "qorganizer-eds-fetchbyidrequestdata.h" #include using namespace QtOrganizer; FetchByIdRequestData::FetchByIdRequestData(QOrganizerEDSEngine *engine, QOrganizerAbstractRequest *req) : RequestData(engine, req), m_current(-1) { } FetchByIdRequestData::~FetchByIdRequestData() { } QString FetchByIdRequestData::nextId() { QString id; QList ids = request()->ids(); m_current++; if (m_current < ids.count()) { id = ids[m_current].toString(); } return id; } QString FetchByIdRequestData::currentId() const { return request()->ids()[m_current].toString(); } QString FetchByIdRequestData::currentCollectionId() const { QString itemId = currentId(); if (!itemId.isEmpty()) { return itemId.contains("/") ? itemId.split("/").first() : QString(); } return QString(); } bool FetchByIdRequestData::end() const { QList ids = request()->ids(); return (m_current >= ids.count()); } void FetchByIdRequestData::finish(QOrganizerManager::Error error, QOrganizerAbstractRequest::State state) { QOrganizerManagerEngine::updateItemFetchByIdRequest(request(), m_results, error, m_errors, state); RequestData::finish(error, state); } int FetchByIdRequestData::appendResult(const QOrganizerItem &result) { if (result.id().isNull()) { m_errors.insert(m_current, QOrganizerManager::DoesNotExistError); } else { m_results << result; } return m_results.length(); } qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-factory.cpp0000644000015600001650000000172212672562647026406 0ustar pbuserpbgroup00000000000000#include "qorganizer-eds-factory.h" #include "qorganizer-eds-collection-engineid.h" #include "qorganizer-eds-engineid.h" #include "qorganizer-eds-engine.h" #include using namespace QtOrganizer; QOrganizerManagerEngine* QOrganizerEDSFactory::engine(const QMap& parameters, QOrganizerManager::Error* error) { Q_UNUSED(error); return QOrganizerEDSEngine::createEDSEngine(parameters); } QOrganizerItemEngineId* QOrganizerEDSFactory::createItemEngineId(const QMap& parameters, const QString& idString) const { Q_UNUSED(parameters); return new QOrganizerEDSEngineId(idString); } QOrganizerCollectionEngineId* QOrganizerEDSFactory::createCollectionEngineId(const QMap& parameters, const QString& idString) const { Q_UNUSED(parameters); return new QOrganizerEDSCollectionEngineId(idString); } QString QOrganizerEDSFactory::managerName() const { return QString::fromLatin1("eds"); } qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-removerequestdata.cpp0000644000015600001650000001035112672562647030475 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "qorganizer-eds-removerequestdata.h" #include "qorganizer-eds-engineid.h" #include "qorganizer-eds-enginedata.h" #include #include using namespace QtOrganizer; RemoveRequestData::RemoveRequestData(QOrganizerEDSEngine *engine, QtOrganizer::QOrganizerAbstractRequest *req) :RequestData(engine, req), m_sessionStaterd(0), m_currentCompIds(0) { m_pendingItems = request()->items(); Q_FOREACH(const QOrganizerItem &item, m_pendingItems) { m_pendingCollections.insert(item.collectionId()); } } RemoveRequestData::~RemoveRequestData() { } QList RemoveRequestData::pendingCollections() const { return m_pendingCollections.toList(); } GSList *RemoveRequestData::takeItemsIds(QOrganizerCollectionId collectionId) { GSList *ids = 0; QList items = m_pendingItems; Q_FOREACH(const QOrganizerItem &item, items) { if (item.collectionId() == collectionId) { m_currentIds.append(item.id()); ECalComponentId *id = QOrganizerEDSEngineId::toComponentIdObject(item.id()); if (id) { ids = g_slist_append(ids, id); } m_pendingItems.removeAll(item); } } return ids; } void RemoveRequestData::finish(QOrganizerManager::Error error, QOrganizerAbstractRequest::State state) { e_client_refresh_sync(m_client, 0, 0); QOrganizerManagerEngine::updateItemRemoveRequest(request(), error, QMap(), state); //The signal will be fired by the view watcher. Check ViewWatcher::onObjectsRemoved //emitChangeset(&m_changeSet); RequestData::finish(error, state); } GSList *RemoveRequestData::compIds() const { return m_currentCompIds; } void RemoveRequestData::commit() { Q_ASSERT(m_sessionStaterd); QOrganizerManagerEngine::updateItemRemoveRequest(request(), QtOrganizer::QOrganizerManager::NoError, QMap(), QOrganizerAbstractRequest::ActiveState); reset(); } QOrganizerCollectionId RemoveRequestData::next() { Q_ASSERT(!m_sessionStaterd); if (m_pendingCollections.count() > 0) { m_sessionStaterd = true; QSet::const_iterator i = m_pendingCollections.constBegin(); m_pendingCollections.remove(*i); m_currentCollectionId = *i; m_currentCompIds = takeItemsIds(m_currentCollectionId); return m_currentCollectionId; } return QOrganizerCollectionId(); } void RemoveRequestData::cancel() { Q_ASSERT(m_sessionStaterd); RequestData::cancel(); clear(); } void RemoveRequestData::reset() { m_currentCollectionId = QOrganizerCollectionId(); m_currentIds.clear(); if (m_currentCompIds) { g_slist_free_full(m_currentCompIds, (GDestroyNotify)e_cal_component_free_id); m_currentCompIds = 0; } m_sessionStaterd = false; } void RemoveRequestData::clear() { reset(); setClient(0); } QOrganizerCollectionId RemoveRequestData::collectionId() const { return m_currentCollectionId; } qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-source-registry.h0000644000015600001650000001053712672562654027554 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __QORGANIZER_EDS_SOURCEREGISTRY_H__ #define __QORGANIZER_EDS_SOURCEREGISTRY_H__ #include #include #include #include #include #include "qorganizer-eds-collection-engineid.h" #define COLLECTION_CALLENDAR_TYPE_METADATA "collection-type" #define COLLECTION_SELECTED_METADATA "collection-selected" #define COLLECTION_READONLY_METADATA "collection-readonly" #define COLLECTION_DEFAULT_METADATA "collection-default" class SourceRegistry : public QObject { Q_OBJECT public: SourceRegistry(QObject *parent=0); ~SourceRegistry(); ESourceRegistry *object() const; void load(); QtOrganizer::QOrganizerCollection defaultCollection() const; void setDefaultCollection(QtOrganizer::QOrganizerCollection &collection); QtOrganizer::QOrganizerCollection collection(const QString &collectionId) const; QList collections() const; QStringList collectionsIds() const; QList collectionsEngineIds() const; ESource *source(const QString &collectionId) const; QOrganizerEDSCollectionEngineId* collectionEngineId(const QString &collectionId) const; QtOrganizer::QOrganizerCollection collection(ESource *source) const; QtOrganizer::QOrganizerCollection insert(ESource *source); void remove(ESource *source); void remove(const QString &collectionId); EClient *client(const QString &collectionId); void clear(); static QtOrganizer::QOrganizerCollection parseSource(ESource *source, bool isDefault, QOrganizerEDSCollectionEngineId **edsId); Q_SIGNALS: void sourceAdded(const QString &collectionId); void sourceRemoved(const QString &collectionId); void sourceUpdated(const QString &collectionId); private: QSettings m_settings; ESourceRegistry *m_sourceRegistry; QtOrganizer::QOrganizerCollection m_defaultCollection; QMap m_clients; QMap m_sources; QMap m_collections; QMap m_collectionsMap; // handler id int m_sourceAddedId; int m_sourceRemovedId; int m_sourceChangedId; int m_sourceEnabledId; int m_sourceDisabledId; int m_defaultSourceChangedId; QByteArray defaultCollectionId() const; QString findCollection(ESource *source) const; QtOrganizer::QOrganizerCollection registerSource(ESource *source, bool isDefault = false); void updateDefaultCollection(QtOrganizer::QOrganizerCollection *collection); static void updateCollection(QtOrganizer::QOrganizerCollection *collection, bool isDefault, ESource *source, EClient *client = 0); // glib callback static void onSourceAdded(ESourceRegistry *registry, ESource *source, SourceRegistry *self); static void onSourceChanged(ESourceRegistry *registry, ESource *source, SourceRegistry *self); static void onSourceRemoved(ESourceRegistry *registry, ESource *source, SourceRegistry *self); static void onDefaultCalendarChanged(ESourceRegistry *registry, GParamSpec *pspec, SourceRegistry *self); }; #endif qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-factory.h0000644000015600001650000000306212672562647026052 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of contact-service-app. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __QORGANIZER_EDS_FACTORY_H__ #define __QORGANIZER_EDS_FACTORY_H__ #include #include #include #include class QOrganizerEDSFactory : public QtOrganizer::QOrganizerManagerEngineFactory { Q_OBJECT Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QOrganizerManagerEngineFactoryInterface" FILE "eds.json") public: QtOrganizer::QOrganizerManagerEngine* engine(const QMap& parameters, QtOrganizer::QOrganizerManager::Error*); QtOrganizer::QOrganizerItemEngineId* createItemEngineId(const QMap& parameters, const QString& idString) const; QtOrganizer::QOrganizerCollectionEngineId* createCollectionEngineId(const QMap& parameters, const QString& idString) const; QString managerName() const; }; #endif qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-viewwatcher.cpp0000644000015600001650000001334212672562647027270 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "qorganizer-eds-enginedata.h" #include "qorganizer-eds-viewwatcher.h" #include "qorganizer-eds-fetchrequestdata.h" #include "qorganizer-eds-engineid.h" #include #include #include #include #include using namespace QtOrganizer; ViewWatcher::ViewWatcher(const QString &collectionId, QOrganizerEDSEngineData *data, EClient *client) : m_collectionId(collectionId), m_engineData(data), m_eClient(E_CAL_CLIENT(client)), m_eView(0), m_eventLoop(0) { g_object_ref(m_eClient); m_cancellable = g_cancellable_new(); e_cal_client_get_view(m_eClient, QStringLiteral("#t").toUtf8().constData(), // match all, m_cancellable, (GAsyncReadyCallback) ViewWatcher::viewReady, this); wait(); } ViewWatcher::~ViewWatcher() { clear(); } void ViewWatcher::viewReady(GObject *sourceObject, GAsyncResult *res, ViewWatcher *self) { Q_UNUSED(sourceObject); GError *gError = 0; ECalClientView *view = 0; e_cal_client_get_view_finish(self->m_eClient, res, &view, &gError); if (gError) { qWarning() << "Fail to open view (" << self->m_collectionId << "):" << gError->message; g_error_free(gError); gError = 0; } else { self->m_eView = view; g_signal_connect(view, "objects-added", (GCallback) ViewWatcher::onObjectsAdded, self); g_signal_connect(view, "objects-removed", (GCallback) ViewWatcher::onObjectsRemoved, self); g_signal_connect(view, "objects-modified", (GCallback) ViewWatcher::onObjectsModified, self); e_cal_client_view_set_flags(view, E_CAL_CLIENT_VIEW_FLAGS_NONE, NULL); e_cal_client_view_start(view, &gError); if (gError) { qWarning() << "Fail to start view (" << self->m_collectionId << "):" << gError->message; g_error_free(gError); gError = 0; } } g_clear_object(&self->m_cancellable); if (self->m_eventLoop) { self->m_eventLoop->quit(); } } void ViewWatcher::clear() { if (m_cancellable) { g_cancellable_cancel(m_cancellable); wait(); Q_ASSERT(m_cancellable == 0); } if (m_eView) { e_cal_client_view_stop(m_eView, 0); g_clear_object(&m_eView); } if (m_eClient) { g_clear_object(&m_eClient); } } void ViewWatcher::wait() { if (m_cancellable) { QEventLoop eventLoop; m_eventLoop = &eventLoop; eventLoop.exec(); m_eventLoop = 0; } } QList ViewWatcher::parseItemIds(GSList *objects) { QList result; for (GSList *l = objects; l; l = l->next) { const gchar *uid = 0; icalcomponent *icalcomp = static_cast(l->data); icalproperty *prop = icalcomponent_get_first_property(icalcomp, ICAL_UID_PROPERTY); if (prop) { uid = icalproperty_get_uid(prop); } else { qWarning() << "Fail to parse component ID"; } QOrganizerEDSEngineId *itemId = new QOrganizerEDSEngineId(m_collectionId, QString::fromUtf8(uid)); result << QOrganizerItemId(itemId); } return result; } void ViewWatcher::onObjectsAdded(ECalClientView *view, GSList *objects, ViewWatcher *self) { Q_UNUSED(view); QOrganizerItemChangeSet changeSet; changeSet.insertAddedItems(self->parseItemIds(objects)); self->m_engineData->emitSharedSignals(&changeSet); } void ViewWatcher::onObjectsRemoved(ECalClientView *view, GSList *objects, ViewWatcher *self) { Q_UNUSED(view); QOrganizerItemChangeSet changeSet; for (GSList *l = objects; l; l = l->next) { ECalComponentId *id = static_cast(l->data); QOrganizerEDSEngineId *itemId = new QOrganizerEDSEngineId(self->m_collectionId, QString::fromUtf8(id->uid)); changeSet.insertRemovedItem(QOrganizerItemId(itemId)); } self->m_engineData->emitSharedSignals(&changeSet); } void ViewWatcher::onObjectsModified(ECalClientView *view, GSList *objects, ViewWatcher *self) { Q_UNUSED(view); QOrganizerItemChangeSet changeSet; changeSet.insertChangedItems(self->parseItemIds(objects)); self->m_engineData->emitSharedSignals(&changeSet); } qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-requestdata.h0000644000015600001650000000427712672562647026736 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __QORGANIZER_EDS_REQUESTDATA_H__ #define __QORGANIZER_EDS_REQUESTDATA_H__ #include "qorganizer-eds-engine.h" #include "qorganizer-eds-enginedata.h" #include #include #include #include #include #include class RequestData { public: RequestData(QOrganizerEDSEngine *engine, QtOrganizer::QOrganizerAbstractRequest *req); GCancellable* cancellable() const; bool isLive() const; void setClient(EClient *client); ECalClient *client() const; QOrganizerEDSEngine *parent() const; virtual void cancel(); void deleteLater(); virtual void finish(QtOrganizer::QOrganizerManager::Error error, QtOrganizer::QOrganizerAbstractRequest::State state); void wait(int msec = 0); bool isWaiting(); template T* request() const { return qobject_cast(m_req.data()); } template void emitChangeset(T *cs) { if (!m_parent.isNull()) { m_parent->d->emitSharedSignals(cs); } } // debug static int instanceCount(); protected: QPointer m_parent; EClient *m_client; QtOrganizer::QOrganizerItemChangeSet m_changeSet; QMutex m_waiting; bool m_finished; virtual ~RequestData(); private: QPointer m_req; GCancellable *m_cancellable; static int m_instanceCount; }; #endif qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-viewwatcher.h0000644000015600001650000000362112672562647026734 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __QORGANIZER_EDS_VIEWWATCHER_H__ #define __QORGANIZER_EDS_VIEWWATCHER_H__ #include "qorganizer-eds-engine.h" #include #include #include #include class QOrganizerEDSEngineData; class ViewWatcher : public QObject { Q_OBJECT public: ViewWatcher(const QString &collectionId, QOrganizerEDSEngineData *data, EClient *client); virtual ~ViewWatcher(); void clear(); void wait(); private: QString m_collectionId; QOrganizerEDSEngineData *m_engineData; GCancellable *m_cancellable; ECalClient *m_eClient; ECalClientView *m_eView; QEventLoop *m_eventLoop; QList parseItemIds(GSList *objects); static void clientConnected(GObject *sourceObject, GAsyncResult *res, ViewWatcher *self); static void viewReady(GObject *sourceObject, GAsyncResult *res, ViewWatcher *self); static void onObjectsAdded(ECalClientView *view, GSList *objects, ViewWatcher *self); static void onObjectsRemoved(ECalClientView *view, GSList *objects, ViewWatcher *self); static void onObjectsModified(ECalClientView *view, GSList *objects, ViewWatcher *self); }; #endif qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-fetchrequestdata.h0000644000015600001650000000571612672562647027747 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __QORGANIZER_EDS_FETCHREQUESTDATA_H__ #define __QORGANIZER_EDS_FETCHREQUESTDATA_H__ #include "qorganizer-eds-requestdata.h" #include class FetchRequestDataParseListener; class FetchRequestData : public RequestData { public: FetchRequestData(QOrganizerEDSEngine *engine, QStringList collections, QtOrganizer::QOrganizerAbstractRequest *req); ~FetchRequestData(); QString nextCollection(); QString nextParentId(); QString collection() const; time_t startDate() const; time_t endDate() const; bool hasDateInterval() const; bool filterIsValid() const; void cancel(); void compileCurrentIds(); void finish(QtOrganizer::QOrganizerManager::Error error = QtOrganizer::QOrganizerManager::NoError, QtOrganizer::QOrganizerAbstractRequest::State state = QtOrganizer::QOrganizerAbstractRequest::FinishedState); void appendResult(icalcomponent *comp); void appendDeatachedResult(icalcomponent *comp); int appendResults(QList results); QString dateFilter(); private: FetchRequestDataParseListener *m_parseListener; QMap m_components; QStringList m_collections; QSet m_currentParentIds; QStringList m_deatachedIds; QString m_current; GSList* m_currentComponents; QList m_results; QStringList filterCollections(const QStringList &collections) const; QStringList collectionsFromFilter(const QtOrganizer::QOrganizerItemFilter &f) const; void finishContinue(QtOrganizer::QOrganizerManager::Error error, QtOrganizer::QOrganizerAbstractRequest::State state); friend class FetchRequestDataParseListener; }; class FetchRequestDataParseListener : public QObject { Q_OBJECT public: FetchRequestDataParseListener(FetchRequestData *data, QtOrganizer::QOrganizerManager::Error error, QtOrganizer::QOrganizerAbstractRequest::State state); private Q_SLOTS: void onParseDone(QList results); private: FetchRequestData *m_data; QtOrganizer::QOrganizerManager::Error m_error; QtOrganizer::QOrganizerAbstractRequest::State m_state; }; #endif qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-fetchbyidrequestdata.h0000644000015600001650000000310712672562647030607 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __QORGANIZER_EDS_FETCHBYIDREQUESTDATA_H__ #define __QORGANIZER_EDS_FETCHBYIDREQUESTDATA_H__ #include "qorganizer-eds-requestdata.h" class FetchByIdRequestData : public RequestData { public: FetchByIdRequestData(QOrganizerEDSEngine *engine, QtOrganizer::QOrganizerAbstractRequest *req); ~FetchByIdRequestData(); QString nextId(); QString currentId() const; QString currentCollectionId() const; bool end() const; void finish(QtOrganizer::QOrganizerManager::Error error = QtOrganizer::QOrganizerManager::NoError, QtOrganizer::QOrganizerAbstractRequest::State state = QtOrganizer::QOrganizerAbstractRequest::FinishedState); int appendResult(const QtOrganizer::QOrganizerItem &result); private: int m_current; QList m_results; QMap m_errors; }; #endif qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-saverequestdata.cpp0000644000015600001650000001040712672562647030140 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "qorganizer-eds-saverequestdata.h" #include "qorganizer-eds-enginedata.h" #include #include #define UPDATE_MODE_PROPRETY "update-mode" using namespace QtOrganizer; SaveRequestData::SaveRequestData(QOrganizerEDSEngine *engine, QtOrganizer::QOrganizerAbstractRequest *req) : RequestData(engine, req) { // map items by collection Q_FOREACH(const QOrganizerItem &i, request()->items()) { QString collectionId = i.collectionId().toString(); if (collectionId == QStringLiteral("qtorganizer:::")) { collectionId = QStringLiteral(""); } QList li = m_items[collectionId]; li << i; m_items.insert(collectionId, li); } } SaveRequestData::~SaveRequestData() { } void SaveRequestData::finish(QtOrganizer::QOrganizerManager::Error error, QtOrganizer::QOrganizerAbstractRequest::State state) { e_client_refresh_sync(m_client, 0, 0); QOrganizerManagerEngine::updateItemSaveRequest(request(), m_result, error, m_erros, state); // Change will be fired by the viewwatcher RequestData::finish(error, state); } void SaveRequestData::appendResults(QList result) { m_result += result; } QString SaveRequestData::nextCollection() { if (m_items.isEmpty()) { m_currentCollection = QString(QString::null); m_currentItems.clear(); } else { m_currentCollection = m_items.keys().first(); m_currentItems = m_items.take(m_currentCollection); } m_workingItems.clear(); return m_currentCollection; } QString SaveRequestData::currentCollection() const { return m_currentCollection; } QList SaveRequestData::takeItemsToCreate() { QList result; Q_FOREACH(const QOrganizerItem &i, m_currentItems) { if (i.id().isNull()) { result << i; m_currentItems.removeAll(i); } } return result; } QList SaveRequestData::takeItemsToUpdate() { QList result; Q_FOREACH(const QOrganizerItem &i, m_currentItems) { if (!i.id().isNull()) { result << i; m_currentItems.removeAll(i); } } return result; } bool SaveRequestData::end() const { return m_items.isEmpty(); } void SaveRequestData::appendResult(const QOrganizerItem &item, QOrganizerManager::Error error) { if (error != QOrganizerManager::NoError) { int index = request()->items().indexOf(item); if (index != -1) { m_erros.insert(index, error); } } else { m_result << item; } } void SaveRequestData::setWorkingItems(QList items) { m_workingItems = items; } QList SaveRequestData::workingItems() const { return m_workingItems; } int SaveRequestData::updateMode() const { // due the lack of API we will use the QObject proprety "update-mode" to allow specify wich kind of // update the developer want QOrganizerItemSaveRequest *req = request(); QVariant updateMode = req->property(UPDATE_MODE_PROPRETY); if (updateMode.isValid()) { return updateMode.toInt(); } else { return -1; } } qtorganizer5-eds-0.1.1+16.04.20160317/organizer/CMakeLists.txt0000644000015600001650000000447412672562647024052 0ustar pbuserpbgroup00000000000000project(qorganizer-eds-src) set(QORGANIZER_BACKEND qtorganizer_eds) set(QORGANIZER_BACKEND_SRCS qorganizer-eds-collection-engineid.cpp qorganizer-eds-fetchrequestdata.cpp qorganizer-eds-fetchbyidrequestdata.cpp qorganizer-eds-fetchocurrencedata.cpp qorganizer-eds-engine.cpp qorganizer-eds-enginedata.cpp qorganizer-eds-engineid.cpp qorganizer-eds-parseeventthread.cpp qorganizer-eds-removecollectionrequestdata.cpp qorganizer-eds-removerequestdata.cpp qorganizer-eds-removebyidrequestdata.cpp qorganizer-eds-requestdata.cpp qorganizer-eds-savecollectionrequestdata.cpp qorganizer-eds-saverequestdata.cpp qorganizer-eds-viewwatcher.cpp qorganizer-eds-source-registry.cpp ) set(QORGANIZER_BACKEND_HDRS qorganizer-eds-collection-engineid.h qorganizer-eds-fetchrequestdata.h qorganizer-eds-fetchbyidrequestdata.h qorganizer-eds-fetchocurrencedata.h qorganizer-eds-engine.h qorganizer-eds-enginedata.h qorganizer-eds-engineid.h qorganizer-eds-parseeventthread.h qorganizer-eds-removecollectionrequestdata.h qorganizer-eds-removerequestdata.h qorganizer-eds-removebyidrequestdata.h qorganizer-eds-requestdata.h qorganizer-eds-savecollectionrequestdata.h qorganizer-eds-saverequestdata.h qorganizer-eds-source-registry.h qorganizer-eds-viewwatcher.h ) add_library(${QORGANIZER_BACKEND}-lib STATIC ${QORGANIZER_BACKEND_SRCS} ${QORGANIZER_BACKEND_HDRS} ) add_library(${QORGANIZER_BACKEND} MODULE qorganizer-eds-factory.cpp qorganizer-eds-factory.h ) include_directories( ${CMAKE_BINARY_DIR} ${GLIB_INCLUDE_DIRS} ${GIO_INCLUDE_DIRS} ${ECAL_INCLUDE_DIRS} ${EDATASERVER_INCLUDE_DIRS} ) target_link_libraries(${QORGANIZER_BACKEND}-lib ${GLIB_LIBRARIES} ${ECAL_LIBRARIES} ${EDATASERVER_LIBRARIES} ) target_link_libraries(${QORGANIZER_BACKEND} ${QORGANIZER_BACKEND}-lib ${GLIB_LIBRARIES} ${ECAL_LIBRARIES} ${EDATASERVER_LIBRARIES} ) qt5_use_modules(${QORGANIZER_BACKEND}-lib Core Organizer) qt5_use_modules(${QORGANIZER_BACKEND} Core Organizer) execute_process( COMMAND qmake -query QT_INSTALL_PLUGINS OUTPUT_VARIABLE QT_INSTALL_PLUGINS OUTPUT_STRIP_TRAILING_WHITESPACE ) install(TARGETS ${QORGANIZER_BACKEND} LIBRARY DESTINATION ${QT_INSTALL_PLUGINS}/organizer) qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-parseeventthread.cpp0000644000015600001650000000307712672562647030310 0ustar pbuserpbgroup00000000000000#include "qorganizer-eds-parseeventthread.h" #include "qorganizer-eds-collection-engineid.h" #include "qorganizer-eds-engine.h" #include QOrganizerParseEventThread::QOrganizerParseEventThread(QObject *source, const QByteArray &slot, QObject *parent) : QThread(parent), m_source(source) { qRegisterMetaType >(); int slotIndex = source->metaObject()->indexOfSlot(slot.mid(1)); if (slotIndex == -1) { qWarning() << "Invalid slot:" << slot << "for object" << m_source; } else { m_slot = source->metaObject()->method(slotIndex); } connect(this, SIGNAL(finished()), SLOT(deleteLater())); } void QOrganizerParseEventThread::start(QMap events, bool isIcalEvents, QList detailsHint) { m_events = events; m_isIcalEvents = isIcalEvents; m_detailsHint = detailsHint; QThread::start(); } void QOrganizerParseEventThread::run() { QList result; Q_FOREACH(QOrganizerEDSCollectionEngineId *id, m_events.keys()) { if (!m_source) { break; } result += QOrganizerEDSEngine::parseEvents(id, m_events.value(id), m_isIcalEvents, m_detailsHint); } if (m_source && m_slot.isValid()) { m_slot.invoke(m_source, Qt::QueuedConnection, Q_ARG(QList, result)); } } qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-parseeventthread.h0000644000015600001650000000331612672562647027751 0ustar pbuserpbgroup00000000000000/* * Copyright 2015 Canonical Ltd. * * This file is part of canonical-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef QORGANIZER_PARSE_EVENT_THREAD_H #define QORGANIZER_PARSE_EVENT_THREAD_H #include #include #include #include #include #include #include #include #include class QOrganizerEDSCollectionEngineId; class QOrganizerParseEventThread : public QThread { Q_OBJECT public: QOrganizerParseEventThread(QObject *source, const QByteArray &slot, QObject *parent = 0); void start(QMap events, bool isIcalEvents, QList detailsHint); private: QPointer m_source; QMetaMethod m_slot; // parse data QMap m_events; bool m_isIcalEvents; QList m_detailsHint; // virtual void run(); }; #endif qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-engine.h0000644000015600001650000004053212672562647025653 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of canonical-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef QORGANIZER_EDS_ENGINE_H #define QORGANIZER_EDS_ENGINE_H #include "qorganizer-eds-collection-engineid.h" #include #include #include #include #include #include #include #include #include #include #include #include class RequestData; class FetchRequestData; class FetchByIdRequestData; class FetchOcurrenceData; class SaveRequestData; class RemoveRequestData; class RemoveByIdRequestData; class SaveCollectionRequestData; class RemoveCollectionRequestData; class ViewWatcher; class QOrganizerEDSEngineData; class QOrganizerEDSCollectionEngineId; class QOrganizerEDSEngine : public QtOrganizer::QOrganizerManagerEngine { Q_OBJECT public: static QOrganizerEDSEngine *createEDSEngine(const QMap& parameters); ~QOrganizerEDSEngine(); // URI reporting QString managerName() const; QMap managerParameters() const; // items QList items(const QList &itemIds, const QtOrganizer::QOrganizerItemFetchHint &fetchHint, QMap *errorMap, QtOrganizer::QOrganizerManager::Error *error); QList items(const QtOrganizer::QOrganizerItemFilter &filter, const QDateTime &startDateTime, const QDateTime &endDateTime, int maxCount, const QList &sortOrders, const QtOrganizer::QOrganizerItemFetchHint &fetchHint, QtOrganizer::QOrganizerManager::Error *error); QList itemIds(const QtOrganizer::QOrganizerItemFilter &filter, const QDateTime &startDateTime, const QDateTime &endDateTime, const QList &sortOrders, QtOrganizer::QOrganizerManager::Error *error); QList itemOccurrences(const QtOrganizer::QOrganizerItem &parentItem, const QDateTime &startDateTime, const QDateTime &endDateTime, int maxCount, const QtOrganizer::QOrganizerItemFetchHint &fetchHint, QtOrganizer::QOrganizerManager::Error *error); QList itemsForExport(const QDateTime &startDateTime, const QDateTime &endDateTime, const QtOrganizer::QOrganizerItemFilter &filter, const QList &sortOrders, const QtOrganizer::QOrganizerItemFetchHint &fetchHint, QtOrganizer::QOrganizerManager::Error *error); bool saveItems(QList *items, const QList &detailMask, QMap *errorMap, QtOrganizer::QOrganizerManager::Error *error); bool removeItems(const QList &itemIds, QMap *errorMap, QtOrganizer::QOrganizerManager::Error *error); // collections QtOrganizer::QOrganizerCollection defaultCollection(QtOrganizer::QOrganizerManager::Error* error); QtOrganizer::QOrganizerCollection collection(const QtOrganizer::QOrganizerCollectionId &collectionId, QtOrganizer::QOrganizerManager::Error *error); QList collections(QtOrganizer::QOrganizerManager::Error* error); bool saveCollection(QtOrganizer::QOrganizerCollection* collection, QtOrganizer::QOrganizerManager::Error* error); bool removeCollection(const QtOrganizer::QOrganizerCollectionId& collectionId, QtOrganizer::QOrganizerManager::Error* error); // Asynchronous Request Support virtual void requestDestroyed(QtOrganizer::QOrganizerAbstractRequest* req); virtual bool startRequest(QtOrganizer::QOrganizerAbstractRequest* req); virtual bool cancelRequest(QtOrganizer::QOrganizerAbstractRequest* req); virtual bool waitForRequestFinished(QtOrganizer::QOrganizerAbstractRequest* req, int msecs); // Capabilities reporting virtual QList supportedFilters() const; virtual QList supportedItemDetails(QtOrganizer::QOrganizerItemType::ItemType itemType) const; virtual QList supportedItemTypes() const; // debug int runningRequestCount() const; protected Q_SLOTS: void onSourceAdded(const QString &collectionId); void onSourceRemoved(const QString &collectionId); void onSourceUpdated(const QString &collectionId); void onViewChanged(QtOrganizer::QOrganizerItemChangeSet *change); protected: QOrganizerEDSEngine(QOrganizerEDSEngineData *data); private: static QOrganizerEDSEngineData *m_globalData; QOrganizerEDSEngineData *d; QMap m_runningRequests; QList parseEvents(const QString &collectionId, GSList *events, bool isIcalEvents, QList detailsHint); void parseEventsAsync(const QMap &events, bool isIcalEvents, QList detailsHint, QObject *source, const QByteArray &slot); static QList parseEvents(QOrganizerEDSCollectionEngineId *collectionId, GSList *events, bool isIcalEvents, QList detailsHint); static GSList *parseItems(ECalClient *client, QList items, bool *hasRecurrence); // QOrganizerItem -> ECalComponent static void parseId(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); static void parseSummary(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); static void parseDescription(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); static void parseComments(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); static void parseTags(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); static void parseReminders(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); static void encodeAttachment(const QUrl &url, ECalComponentAlarm *alarm); static void parseVisualReminderAttachment(const QtOrganizer::QOrganizerItemDetail &detail, ECalComponentAlarm *alarm); static void parseAudibleReminderAttachment(const QtOrganizer::QOrganizerItemDetail &detail, ECalComponentAlarm *alarm); static void parseStartTime(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); static void parseEndTime(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); static void parseTodoStartTime(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); static void parseRecurrence(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); static void parseWeekRecurrence(const QtOrganizer::QOrganizerRecurrenceRule &qRule, struct icalrecurrencetype *rule); static void parseMonthRecurrence(const QtOrganizer::QOrganizerRecurrenceRule &qRule, struct icalrecurrencetype *rule); static void parseYearRecurrence(const QtOrganizer::QOrganizerRecurrenceRule &qRule, struct icalrecurrencetype *rule); static void parsePriority(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); static void parseLocation(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); static void parseDueDate(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); static void parseProgress(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); static void parseStatus(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); static void parseAttendeeList(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); static void parseExtendedDetails(const QtOrganizer::QOrganizerItem &item, ECalComponent *comp); // ECalComponent -> QOrganizerItem static bool hasRecurrence(ECalComponent *comp); static void parseId(ECalComponent *comp, QtOrganizer::QOrganizerItem *item, QOrganizerEDSCollectionEngineId *edsCollectionId); static void parseSummary(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); static void parseDescription(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); static void parseComments(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); static void parseTags(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); static void parseReminders(ECalComponent *comp, QtOrganizer::QOrganizerItem *item, QList detailsHint = QList()); static QUrl dencodeAttachment(ECalComponentAlarm *alarm); static void parseAudibleReminderAttachment(ECalComponentAlarm *alarm, QtOrganizer::QOrganizerItemReminder *aDetail); static void parseVisualReminderAttachment(ECalComponentAlarm *alarm, QtOrganizer::QOrganizerItemReminder *aDetail); static void parseStartTime(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); static void parseTodoStartTime(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); static void parseEndTime(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); static void parseRecurrence(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); static void parseWeekRecurrence(struct icalrecurrencetype *rule, QtOrganizer::QOrganizerRecurrenceRule *qRule); static void parseMonthRecurrence(struct icalrecurrencetype *rule, QtOrganizer::QOrganizerRecurrenceRule *qRule); static void parseYearRecurrence(struct icalrecurrencetype *rule, QtOrganizer::QOrganizerRecurrenceRule *qRule); static void parsePriority(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); static void parseLocation(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); static void parseDueDate(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); static void parseProgress(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); static void parseStatus(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); static void parseAttendeeList(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); static void parseExtendedDetails(ECalComponent *comp, QtOrganizer::QOrganizerItem *item); static QDateTime fromIcalTime(struct icaltimetype value, const char *tzId); static icaltimetype fromQDateTime(const QDateTime &dateTime, bool allDay, QByteArray *tzId); static QtOrganizer::QOrganizerItem *parseEvent(ECalComponent *comp, QList detailsHint); static QtOrganizer::QOrganizerItem *parseToDo(ECalComponent *comp, QList detailsHint); static QtOrganizer::QOrganizerItem *parseJournal(ECalComponent *comp, QList detailsHint); static ECalComponent *createDefaultComponent(ECalClient *client, icalcomponent_kind iKind, ECalComponentVType eType); static ECalComponent *parseEventItem(ECalClient *client, const QtOrganizer::QOrganizerItem &item); static ECalComponent *parseTodoItem(ECalClient *client, const QtOrganizer::QOrganizerItem &item); static ECalComponent *parseJournalItem(ECalClient *client, const QtOrganizer::QOrganizerItem &item); // glib callback void itemsAsync(QtOrganizer::QOrganizerItemFetchRequest *req); static void itemsAsyncStart(FetchRequestData *data); static gboolean itemsAsyncListed(ECalComponent *comp, time_t instanceStart, time_t instanceEnd, FetchRequestData *data); static void itemsAsyncDone(FetchRequestData *data); static void itemsAsyncListedAsComps(GObject *source, GAsyncResult *res, FetchRequestData *data); static void itemsAsyncFetchDeatachedItems(FetchRequestData *data); static void itemsAsyncListByIdListed(GObject *source, GAsyncResult *res, FetchRequestData *data); void itemsByIdAsync(QtOrganizer::QOrganizerItemFetchByIdRequest *req); static void itemsByIdAsyncStart(FetchByIdRequestData *data); static void itemsByIdAsyncListed(GObject *client, GAsyncResult *res, FetchByIdRequestData *data); void itemOcurrenceAsync(QtOrganizer::QOrganizerItemOccurrenceFetchRequest *req); static void itemOcurrenceAsyncGetObjectDone(GObject *source, GAsyncResult *res, FetchOcurrenceData *data); static void itemOcurrenceAsyncListed(ECalComponent *comp, time_t instanceStart, time_t instanceEnd, FetchOcurrenceData *data); static void itemOcurrenceAsyncDone(FetchOcurrenceData *data); void saveItemsAsync(QtOrganizer::QOrganizerItemSaveRequest *req); static void saveItemsAsyncStart(SaveRequestData *data); static void saveItemsAsyncCreated(GObject *source_object, GAsyncResult *res, SaveRequestData *data); static void saveItemsAsyncModified(GObject *source_object, GAsyncResult *res, SaveRequestData *data); void removeItemsByIdAsync(QtOrganizer::QOrganizerItemRemoveByIdRequest *req); static void removeItemsByIdAsyncStart(RemoveByIdRequestData *data); void removeItemsAsync(QtOrganizer::QOrganizerItemRemoveRequest *req); static void removeItemsAsyncStart(RemoveRequestData *data); void saveCollectionAsync(QtOrganizer::QOrganizerCollectionSaveRequest *req); static gboolean saveCollectionUpdateAsyncStart(SaveCollectionRequestData *data); static void saveCollectionAsyncCommited(ESourceRegistry *registry, GAsyncResult *res, SaveCollectionRequestData *data); static void saveCollectionUpdateAsynCommited(ESource *source, GAsyncResult *res, SaveCollectionRequestData *data); void removeCollectionAsync(QtOrganizer::QOrganizerCollectionRemoveRequest *req); static void removeCollectionAsyncStart(GObject *sourceObject, GAsyncResult *res, RemoveCollectionRequestData *data); static void releaseRequestData(RequestData *data); friend class RequestData; friend class SaveCollectionRequestData; friend class RemoveCollectionRequestData; friend class ViewWatcher; friend class FetchRequestData; friend class FetchOcurrenceData; friend class QOrganizerParseEventThread; }; //FIXME: Do we really need this, this looks wrong using namespace QtOrganizer; Q_DECLARE_METATYPE(QList) Q_DECLARE_METATYPE(QList) Q_DECLARE_METATYPE(QList) #endif qtorganizer5-eds-0.1.1+16.04.20160317/organizer/qorganizer-eds-removerequestdata.h0000644000015600001650000000362612672562647030151 0ustar pbuserpbgroup00000000000000/* * Copyright 2013 Canonical Ltd. * * This file is part of ubuntu-pim-service. * * contact-service-app is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 3. * * contact-service-app is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #ifndef __QORGANIZER_EDS_REMOVEQUESTDATA_H__ #define __QORGANIZER_EDS_REMOVEQUESTDATA_H__ #include "qorganizer-eds-requestdata.h" #include class RemoveRequestData : public RequestData { public: RemoveRequestData(QOrganizerEDSEngine *engine, QtOrganizer::QOrganizerAbstractRequest *req); ~RemoveRequestData(); QList pendingCollections() const; QtOrganizer::QOrganizerCollectionId collectionId() const; void finish(QtOrganizer::QOrganizerManager::Error error = QtOrganizer::QOrganizerManager::NoError, QtOrganizer::QOrganizerAbstractRequest::State state = QtOrganizer::QOrganizerAbstractRequest::FinishedState); GSList *compIds() const; QtOrganizer::QOrganizerCollectionId next(); void commit(); virtual void cancel(); private: QSet m_pendingCollections; QList m_pendingItems; bool m_sessionStaterd; GSList *m_currentCompIds; QList m_currentIds; QtOrganizer::QOrganizerCollectionId m_currentCollectionId; void clear(); void reset(); GSList* takeItemsIds(QtOrganizer::QOrganizerCollectionId collectionId); }; #endif qtorganizer5-eds-0.1.1+16.04.20160317/CMakeLists.txt0000644000015600001650000000641412672562647022046 0ustar pbuserpbgroup00000000000000project(qorganizer-eds) cmake_minimum_required(VERSION 2.8.9) include(FindPkgConfig) # Standard install paths include(GNUInstallDirs) find_package(Qt5Core REQUIRED) add_definitions(-DQT_NO_KEYWORDS) add_definitions(-std=c++11) pkg_check_modules(GLIB REQUIRED glib-2.0>=2.32) pkg_check_modules(GIO REQUIRED gio-2.0>=2.32) pkg_check_modules(EDATASERVER REQUIRED libedataserver-1.2>=3.8) pkg_check_modules(ECAL REQUIRED REQUIRED libecal-1.2>=3.8) set(CMAKE_INCLUDE_CURRENT_DIR ON) set(CMAKE_AUTOMOC ON) add_definitions(-std=c++11) # Coverage tools OPTION(ENABLE_COVERAGE "Build with coverage analysis support" OFF) if(ENABLE_COVERAGE) message(STATUS "Using coverage flags") find_program(COVERAGE_COMMAND gcov) if(NOT COVERAGE_COMMAND) message(FATAL_ERROR "gcov command not found") endif() SET(CMAKE_C_FLAGS "-g -O0 -Wall -fprofile-arcs -ftest-coverage") SET(CMAKE_CXX_FLAGS "-g -O0 -Wall -fprofile-arcs -ftest-coverage") SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -lgcov") include(${CMAKE_SOURCE_DIR}/cmake/lcov.cmake) endif() # Address Sanitizer OPTION(ENABLE_ADDRSANITIZER "Build with address sanitizer support" OFF) if(ENABLE_ADDRSANITIZER) message(STATUS "Using address sanitizer flags") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer") SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address") endif() configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") #Temporary dir used by tests execute_process(COMMAND mktemp -d -t qorganizer_eds_test.XXX OUTPUT_VARIABLE TMP_DIR OUTPUT_STRIP_TRAILING_WHITESPACE) #Create the directories file(MAKE_DIRECTORY ${TMP_DIR}/.cache) file(MAKE_DIRECTORY ${TMP_DIR}/.config) file(MAKE_DIRECTORY ${TMP_DIR}/.local/share) find_program(DBUS_RUNNER dbus-test-runner) find_program(EVOLUTION_CALENDAR_FACTORY evolution-calendar-factory PATHS /usr/lib/evolution/) find_program(EVOLUTION_SOURCE_REGISTRY evolution-source-registry PATHS /usr/lib/evolution/) find_program(GVFSD gvfsd PATHS /usr/lib/gvfs/) if(EDATASERVER_VERSION VERSION_LESS "3.16") set(EVOLUTION_API_3_17 "0") set(EVOLUTION_SOURCE_SERVICE_NAME "org.gnome.evolution.dataserver.Sources3") set(EVOLUTION_CALENDAR_SERVICE_NAME "org.gnome.evolution.dataserver.Calendar4") else() set(EVOLUTION_API_3_17 "1") set(EVOLUTION_SOURCE_SERVICE_NAME "org.gnome.evolution.dataserver.Sources4") set(EVOLUTION_CALENDAR_SERVICE_NAME "org.gnome.evolution.dataserver.Calendar7") endif() configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) add_subdirectory(organizer) if(DBUS_RUNNER) if(EVOLUTION_CALENDAR_FACTORY) enable_testing() add_subdirectory(tests) else(EVOLUTION_CALENDAR_FACTORY) message(WARNING "evolution-calendar-factory binary not found tests will be disabled") endif(EVOLUTION_CALENDAR_FACTORY) else(DBUS_RUNNER) message(WARNING "dbus-test-runner binary not found tests will be disabled") endif(DBUS_RUNNER)