Commit 358db854 authored by Shashwat Jolly's avatar Shashwat Jolly
Browse files

Switch to new collection type and list API

The etebase API changed to allow fetching collection by types.
The resource now fetches only Contacts, Calendar and Task collections.
parent cf6363c9
......@@ -62,8 +62,8 @@ void EntriesFetchJob::fetchEntries()
return;
}
EtebaseCollectionMetadataPtr metaData(etebase_collection_get_meta(mEtesyncCollection.get()));
const QString type = QString::fromUtf8(etebase_collection_metadata_get_collection_type(metaData.get()));
EtebaseItemMetadataPtr metaData(etebase_collection_get_meta(mEtesyncCollection.get()));
const QString type = QString::fromUtf8(etebase_collection_get_collection_type(mEtesyncCollection.get()));
qCDebug(ETESYNC_LOG) << "Type:" << type;
QString sToken = mCollection.remoteRevision();
......@@ -141,6 +141,7 @@ void EntriesFetchJob::setupItem(const EtebaseItem *etesyncItem, const QString &t
etebase_item_get_content(etesyncItem, content.data(), len);
}
item.setPayloadFromData(content);
// qCDebug(ETESYNC_LOG) << item.payloadData()<<endl;
if (etebase_item_is_deleted(etesyncItem)) {
mRemovedItems.push_back(item);
......
......@@ -32,19 +32,24 @@ void etebase_fetch_options_set_stoken(EtebaseFetchOptions *fetch_options, const
etebase_fetch_options_set_stoken(fetch_options, charArrFromQString(stoken));
}
EtebaseCollectionMetadataPtr etebase_collection_metadata_new(const QString &type, const QString &name)
void etebase_item_metadata_set_item_type(EtebaseItemMetadata *meta_data, const QString &item_type)
{
return EtebaseCollectionMetadataPtr(etebase_collection_metadata_new(charArrFromQString(type), charArrFromQString(name)));
etebase_item_metadata_set_item_type(meta_data, charArrFromQString(item_type));
}
void etebase_collection_metadata_set_color(EtebaseCollectionMetadata *meta_data, const QString &color)
void etebase_item_metadata_set_color(EtebaseItemMetadata *meta_data, const QString &color)
{
etebase_collection_metadata_set_color(meta_data, charArrFromQString(color));
etebase_item_metadata_set_color(meta_data, charArrFromQString(color));
}
void etebase_collection_metadata_set_name(EtebaseCollectionMetadata *meta_data, const QString &name)
void etebase_item_metadata_set_name(EtebaseItemMetadata *meta_data, const QString &name)
{
etebase_collection_metadata_set_name(meta_data, charArrFromQString(name));
etebase_item_metadata_set_name(meta_data, charArrFromQString(name));
}
EtebaseCollectionPtr etebase_collection_manager_create(const EtebaseCollectionManager *col_mgr, const QString &collection_type, const EtebaseItemMetadata *meta, const void *content, uintptr_t content_size)
{
return EtebaseCollectionPtr(etebase_collection_manager_create(col_mgr, charArrFromQString(collection_type), meta, content, content_size));
}
EtebaseFileSystemCachePtr etebase_fs_cache_new(const QString &path, const QString &username)
......
......@@ -20,6 +20,9 @@
#define ETESYNC_DEFAULT_COLLECTION_COLOR QStringLiteral("#8BC34A")
static const char *ETESYNC_COLLECTION_TYPES[] = { "etebase.vevent", "etebase.vcard", "etebase.vtodo" };
static const int ETESYNC_COLLECTION_TYPES_SIZE = ETEBASE_UTILS_C_ARRAY_LEN(ETESYNC_COLLECTION_TYPES);
struct EtebaseDeleter
{
void operator()(EtebaseClient *ptr)
......@@ -52,11 +55,6 @@ struct EtebaseDeleter
etebase_collection_destroy(ptr);
}
void operator()(EtebaseCollectionMetadata *ptr)
{
etebase_collection_metadata_destroy(ptr);
}
void operator()(EtebaseItemManager *ptr)
{
etebase_item_manager_destroy(ptr);
......@@ -96,7 +94,6 @@ using EtebaseFetchOptionsPtr = std::unique_ptr<EtebaseFetchOptions, EtebaseDelet
using EtebaseCollectionListResponsePtr = std::unique_ptr<EtebaseCollectionListResponse, EtebaseDeleter>;
using EtebaseCollectionManagerPtr = std::unique_ptr<EtebaseCollectionManager, EtebaseDeleter>;
using EtebaseCollectionPtr = std::unique_ptr<EtebaseCollection, EtebaseDeleter>;
using EtebaseCollectionMetadataPtr = std::unique_ptr<EtebaseCollectionMetadata, EtebaseDeleter>;
using EtebaseItemManagerPtr = std::unique_ptr<EtebaseItemManager, EtebaseDeleter>;
using EtebaseItemListResponsePtr = std::unique_ptr<EtebaseItemListResponse, EtebaseDeleter>;
using EtebaseItemMetadataPtr = std::unique_ptr<EtebaseItemMetadata, EtebaseDeleter>;
......@@ -113,11 +110,13 @@ EtebaseAccountPtr etebase_account_login(const EtebaseClient *client, const QStri
void etebase_fetch_options_set_stoken(EtebaseFetchOptions *fetch_options, const QString &stoken);
EtebaseCollectionMetadataPtr etebase_collection_metadata_new(const QString &type, const QString &name);
void etebase_item_metadata_set_item_type(EtebaseItemMetadata *meta_data, const QString &item_type);
void etebase_item_metadata_set_color(EtebaseItemMetadata *meta_data, const QString &color);
void etebase_collection_metadata_set_color(EtebaseCollectionMetadata *meta_data, const QString &color);
void etebase_item_metadata_set_name(EtebaseItemMetadata *meta_data, const QString &name);
void etebase_collection_metadata_set_name(EtebaseCollectionMetadata *meta_data, const QString &name);
EtebaseCollectionPtr etebase_collection_manager_create(const EtebaseCollectionManager *col_mgr, const QString &collection_type, const EtebaseItemMetadata *meta, const void *content, uintptr_t content_size);
EtebaseFileSystemCachePtr etebase_fs_cache_new(const QString &path, const QString &username);
......
......@@ -112,7 +112,7 @@ bool EteSyncClientState::accountStatus()
etebase_fetch_options_set_limit(fetchOptions.get(), 1);
etebase_fetch_options_set_prefetch(fetchOptions.get(), ETEBASE_PREFETCH_OPTION_MEDIUM);
EtebaseCollectionListResponsePtr collectionList(etebase_collection_manager_list(collectionManager.get(), fetchOptions.get()));
EtebaseCollectionListResponsePtr collectionList(etebase_collection_manager_list_multi(collectionManager.get(), ETESYNC_COLLECTION_TYPES, ETESYNC_COLLECTION_TYPES_SIZE, fetchOptions.get()));
if (!collectionList) {
qCDebug(ETESYNC_LOG) << "Could not fetch collection list with limit 1";
qCDebug(ETESYNC_LOG) << "Etebase error" << etebase_error_get_message();
......
......@@ -384,8 +384,7 @@ void EteSyncResource::itemAdded(const Akonadi::Item &item, const Akonadi::Collec
cancelTask(i18n("Could not get etesyncCollection from cache '%1'", collection.remoteId()));
return;
}
EtebaseCollectionMetadataPtr collectionMetadata(etebase_collection_get_meta(etesyncCollection.get()));
const QString type = QString::fromUtf8(etebase_collection_metadata_get_collection_type(collectionMetadata.get()));
const QString type = QString::fromUtf8(etebase_collection_get_collection_type(etesyncCollection.get()));
// Create metadata
int64_t modificationTimeSinceEpoch = QDateTime::currentMSecsSinceEpoch();
......@@ -572,14 +571,16 @@ void EteSyncResource::collectionAdded(const Akonadi::Collection &collection, con
// Create metadata
int64_t modificationTimeSinceEpoch = QDateTime::currentMSecsSinceEpoch();
const QString type = getEtebaseTypeForCollection(collection);
EtebaseCollectionMetadataPtr collectionMetaData(etebase_collection_metadata_new(type, collection.displayName()));
etebase_collection_metadata_set_color(collectionMetaData.get(), ETESYNC_DEFAULT_COLLECTION_COLOR);
etebase_collection_metadata_set_mtime(collectionMetaData.get(), &modificationTimeSinceEpoch);
EtebaseItemMetadataPtr collectionMetaData(etebase_item_metadata_new());
etebase_item_metadata_set_item_type(collectionMetaData.get(), type);
etebase_item_metadata_set_name(collectionMetaData.get(), collection.displayName());
etebase_item_metadata_set_color(collectionMetaData.get(), ETESYNC_DEFAULT_COLLECTION_COLOR);
etebase_item_metadata_set_mtime(collectionMetaData.get(), &modificationTimeSinceEpoch);
qCDebug(ETESYNC_LOG) << "Created metadata";
// Create EteSync collection
EtebaseCollectionPtr etesyncCollection(etebase_collection_manager_create(collectionManager.get(), collectionMetaData.get(), nullptr, 0));
EtebaseCollectionPtr etesyncCollection(etebase_collection_manager_create(collectionManager.get(), type, collectionMetaData.get(), nullptr, 0));
if (!etesyncCollection) {
qCDebug(ETESYNC_LOG) << "Could not create new etesyncCollection";
qCDebug(ETESYNC_LOG) << "Etebase error;" << etebase_error_get_message();
......@@ -648,14 +649,14 @@ void EteSyncResource::collectionChanged(const Akonadi::Collection &collection)
}
// Update metadata
EtebaseCollectionMetadataPtr collectionMetaData(etebase_collection_get_meta(etesyncCollection.get()));
EtebaseItemMetadataPtr collectionMetaData(etebase_collection_get_meta(etesyncCollection.get()));
// mtime
int64_t modificationTimeSinceEpoch = QDateTime::currentMSecsSinceEpoch();
etebase_collection_metadata_set_mtime(collectionMetaData.get(), &modificationTimeSinceEpoch);
etebase_item_metadata_set_mtime(collectionMetaData.get(), &modificationTimeSinceEpoch);
// Name
etebase_collection_metadata_set_name(collectionMetaData.get(), collection.displayName());
etebase_item_metadata_set_name(collectionMetaData.get(), collection.displayName());
// Color
auto journalColor = ETESYNC_DEFAULT_COLLECTION_COLOR;
......@@ -665,7 +666,7 @@ void EteSyncResource::collectionChanged(const Akonadi::Collection &collection)
journalColor = colorAttr->color().name();
}
}
etebase_collection_metadata_set_color(collectionMetaData.get(), journalColor);
etebase_item_metadata_set_color(collectionMetaData.get(), journalColor);
// Set metadata
etebase_collection_set_meta(etesyncCollection.get(), collectionMetaData.get());
......@@ -706,11 +707,11 @@ void EteSyncResource::collectionRemoved(const Akonadi::Collection &collection)
}
// Update metadata
EtebaseCollectionMetadataPtr collectionMetaData(etebase_collection_get_meta(etesyncCollection.get()));
EtebaseItemMetadataPtr collectionMetaData(etebase_collection_get_meta(etesyncCollection.get()));
// mtime
int64_t modificationTimeSinceEpoch = QDateTime::currentMSecsSinceEpoch();
etebase_collection_metadata_set_mtime(collectionMetaData.get(), &modificationTimeSinceEpoch);
etebase_item_metadata_set_mtime(collectionMetaData.get(), &modificationTimeSinceEpoch);
// Set collection deleted
etebase_collection_delete(etesyncCollection.get());
......
......@@ -73,7 +73,7 @@ void JournalsFetchJob::fetchJournals()
etebase_fetch_options_set_limit(fetchOptions.get(), COLLECTIONS_FETCH_BATCH_SIZE);
etebase_fetch_options_set_prefetch(fetchOptions.get(), ETEBASE_PREFETCH_OPTION_MEDIUM);
EtebaseCollectionListResponsePtr collectionList(etebase_collection_manager_list(collectionManager.get(), fetchOptions.get()));
EtebaseCollectionListResponsePtr collectionList(etebase_collection_manager_list_multi(collectionManager.get(), ETESYNC_COLLECTION_TYPES, ETEBASE_UTILS_C_ARRAY_LEN(ETESYNC_COLLECTION_TYPES), fetchOptions.get()));
if (!collectionList) {
setError(int(etebase_error_get_code()));
const char *err = etebase_error_get_message();
......@@ -137,9 +137,10 @@ void JournalsFetchJob::setupCollection(const EtebaseCollection *etesyncCollectio
qCDebug(ETESYNC_LOG) << "Setting up collection" << etebase_collection_get_uid(etesyncCollection);
EtebaseCollectionMetadataPtr metaData(etebase_collection_get_meta(etesyncCollection));
EtebaseItemMetadataPtr metaData(etebase_collection_get_meta(etesyncCollection));
const QString type = QString::fromUtf8(etebase_collection_metadata_get_collection_type(metaData.get()));
const QString type = QString::fromUtf8(etebase_collection_get_collection_type(etesyncCollection));
qCDebug(ETESYNC_LOG) << ETEBASE_COLLECTION_TYPE_CALENDAR;
qCDebug(ETESYNC_LOG) << "Type" << type;
......@@ -149,7 +150,7 @@ void JournalsFetchJob::setupCollection(const EtebaseCollection *etesyncCollectio
auto attr = collection.attribute<EntityDisplayAttribute>(Collection::AddIfMissing);
const QString displayName = QString::fromUtf8(etebase_collection_metadata_get_name(metaData.get()));
const QString displayName = QString::fromUtf8(etebase_item_metadata_get_name(metaData.get()));
qCDebug(ETESYNC_LOG) << "Name:" << displayName;
......@@ -175,7 +176,7 @@ void JournalsFetchJob::setupCollection(const EtebaseCollection *etesyncCollectio
}
const QString journalUid = QString::fromUtf8(etebase_collection_get_uid(etesyncCollection));
auto collectionColor = QString::fromUtf8(etebase_collection_metadata_get_color(metaData.get()));
auto collectionColor = QString::fromUtf8(etebase_item_metadata_get_color(metaData.get()));
auto colorAttr = collection.attribute<Akonadi::CollectionColorAttribute>(Collection::AddIfMissing);
if (collectionColor.isEmpty()) {
collectionColor = ETESYNC_DEFAULT_COLLECTION_COLOR;
......@@ -211,14 +212,16 @@ void JournalsFetchJob::createDefaultCollection(const QString &collectionType, co
// Create metadata
int64_t modificationTimeSinceEpoch = QDateTime::currentMSecsSinceEpoch();
EtebaseCollectionMetadataPtr collectionMetaData(etebase_collection_metadata_new(collectionType, collectionName));
etebase_collection_metadata_set_color(collectionMetaData.get(), ETESYNC_DEFAULT_COLLECTION_COLOR);
etebase_collection_metadata_set_mtime(collectionMetaData.get(), &modificationTimeSinceEpoch);
EtebaseItemMetadataPtr collectionMetaData(etebase_item_metadata_new());
etebase_item_metadata_set_item_type(collectionMetaData.get(), collectionType);
etebase_item_metadata_set_name(collectionMetaData.get(), collectionName);
etebase_item_metadata_set_color(collectionMetaData.get(), ETESYNC_DEFAULT_COLLECTION_COLOR);
etebase_item_metadata_set_mtime(collectionMetaData.get(), &modificationTimeSinceEpoch);
qCDebug(ETESYNC_LOG) << "Created metadata";
// Create EteSync collection
EtebaseCollectionPtr etesyncCollection(etebase_collection_manager_create(collectionManager.get(), collectionMetaData.get(), nullptr, 0));
EtebaseCollectionPtr etesyncCollection(etebase_collection_manager_create(collectionManager.get(), collectionType, collectionMetaData.get(), nullptr, 0));
if (!etesyncCollection) {
qCDebug(ETESYNC_LOG) << "Could not create new etesyncCollection";
qCDebug(ETESYNC_LOG) << "Etebase error;" << etebase_error_get_message();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment