Commit 2af86bd0 authored by Shashwat Jolly's avatar Shashwat Jolly

Fix error handling in entries fetch job

parent 1bda943e
......@@ -34,6 +34,7 @@ using namespace KCalendarCore;
CalendarTaskBaseHandler::CalendarTaskBaseHandler(EteSyncResource *resource) : BaseHandler(resource)
{
initialiseBaseDirectory();
AttributeFactory::registerAttribute<CollectionColorAttribute>();
}
void CalendarTaskBaseHandler::getItemListFromEntries(std::vector<EteSyncEntryPtr> &entries, Item::List &changedItems, Item::List &removedItems, Collection &collection, const QString &journalUid, QString &prevUid)
......@@ -256,4 +257,5 @@ void CalendarTaskBaseHandler::collectionRemoved(const Akonadi::Collection &colle
mResource->handleTokenError();
return;
}
mResource->changeCommitted(collection);
}
......@@ -209,7 +209,11 @@ void ContactHandler::collectionAdded(const Akonadi::Collection &collection, cons
etesync_journal_set_info(journal.get(), cryptoManager.get(), info.get());
etesync_journal_manager_create(mClientState->journalManager(), journal.get());
const auto result = etesync_journal_manager_create(mClientState->journalManager(), journal.get());
if (result) {
mResource->handleTokenError();
return;
}
Collection newCollection(collection);
mResource->setupCollection(newCollection, journal.get());
......@@ -227,7 +231,13 @@ void ContactHandler::collectionChanged(const Akonadi::Collection &collection)
etesync_journal_set_info(journal.get(), cryptoManager.get(), info.get());
etesync_journal_manager_update(mClientState->journalManager(), journal.get());
const auto result = etesync_journal_manager_update(mClientState->journalManager(), journal.get());
if (result) {
mResource->handleTokenError();
return;
}
mResource->changeCommitted(collection);
}
void ContactHandler::collectionRemoved(const Akonadi::Collection &collection)
......@@ -235,5 +245,10 @@ void ContactHandler::collectionRemoved(const Akonadi::Collection &collection)
const QString journalUid = collection.remoteId();
const EteSyncJournalPtr &journal = mResource->getJournal(journalUid);
etesync_journal_manager_delete(mClientState->journalManager(), journal.get());
const auto result = etesync_journal_manager_delete(mClientState->journalManager(), journal.get());
if (result) {
mResource->handleTokenError();
return;
}
mResource->changeCommitted(collection);
}
......@@ -42,26 +42,29 @@ void EntriesFetchJob::fetchEntries()
mPrevUid = mLastUid = mCollection.remoteRevision();
mEntryManager = etesync_entry_manager_new(mClient, journalUid);
while (fetchNextBatch()) {
}
EntriesFetchJob::Status status;
do {
status = fetchNextBatch();
} while (status != ERROR && status != ALL_ENTRIES_FETCHED);
if (etesync_get_error_code() != EteSyncErrorCode::ETESYNC_ERROR_CODE_NO_ERROR) {
if (status == ERROR) {
setError(UserDefinedError);
CharPtr err(etesync_get_error_message());
setErrorText(QStringFromCharPtr(err));
emitResult();
return;
}
emitResult();
}
bool EntriesFetchJob::fetchNextBatch()
EntriesFetchJob::Status EntriesFetchJob::fetchNextBatch()
{
std::vector<EteSyncEntryPtr> entries = etesync_entry_manager_list(mEntryManager.get(), mLastUid, 50);
if (entries.empty()) {
return false;
std::pair<std::vector<EteSyncEntryPtr>, bool> entries = etesync_entry_manager_list(mEntryManager.get(), mLastUid, 50);
if (entries.second) {
return ERROR;
}
if (entries.first.empty()) {
return ALL_ENTRIES_FETCHED;
}
mEntries.insert(mEntries.end(), std::make_move_iterator(entries.begin()), std::make_move_iterator(entries.end()));
mEntries.insert(mEntries.end(), std::make_move_iterator(entries.first.begin()), std::make_move_iterator(entries.first.end()));
mLastUid = QStringFromCharPtr(CharPtr(etesync_entry_get_uid(mEntries[mEntries.size() - 1].get())));
return true;
return FETCH_OK;
}
......@@ -49,8 +49,14 @@ namespace EteSyncAPI {
}
protected:
enum Status
{
FETCH_OK,
ERROR,
ALL_ENTRIES_FETCHED
};
void fetchEntries();
bool fetchNextBatch();
Status fetchNextBatch();
private:
const EteSync *mClient = nullptr;
......
......@@ -77,16 +77,20 @@ qint32 etesync_entry_manager_create(const EteSyncEntryManager *entry_manager,
return etesync_entry_manager_create(entry_manager, entries, charArrFromQString(prev_uid));
}
std::vector<EteSyncEntryPtr> etesync_entry_manager_list(const EteSyncEntryManager *entry_manager,
const QString &prev_uid, uintptr_t limit)
std::pair<std::vector<EteSyncEntryPtr>, bool> etesync_entry_manager_list(const EteSyncEntryManager *entry_manager,
const QString &prev_uid, uintptr_t limit)
{
bool err = false;
auto entries = etesync_entry_manager_list(entry_manager, charArrFromQString(prev_uid), limit);
if (!entries) {
err = true;
}
std::vector<EteSyncEntryPtr> rv;
while (*entries) {
rv.emplace_back(EteSyncEntryPtr{*entries});
++entries;
}
return rv;
return make_pair(std::move(rv), err);
}
EteSyncEntryManagerPtr etesync_entry_manager_new(const EteSync *etesync,
......
......@@ -119,8 +119,8 @@ qint32 etesync_entry_manager_create(const EteSyncEntryManager *entry_manager,
const EteSyncEntry *const *entries,
const QString &prev_uid);
std::vector<EteSyncEntryPtr> etesync_entry_manager_list(const EteSyncEntryManager *entry_manager,
const QString &prev_uid, uintptr_t limit);
std::pair<std::vector<EteSyncEntryPtr>, bool> etesync_entry_manager_list(const EteSyncEntryManager *entry_manager,
const QString &prev_uid, uintptr_t limit);
EteSyncEntryManagerPtr etesync_entry_manager_new(const EteSync *etesync,
const QString &journal_uid);
......
......@@ -140,8 +140,6 @@ Collection EteSyncResource::createRootCollection()
attr->setDisplayName(mClientState->username());
attr->setIconName(QStringLiteral("akonadi-etesync"));
collectionsRetrieved({rootCollection});
return rootCollection;
}
......@@ -154,9 +152,10 @@ void EteSyncResource::slotCollectionsRetrieved(KJob *job)
return;
}
qCDebug(ETESYNC_LOG) << "Retrieving collections";
const Collection &rootCollection = createRootCollection();
EteSyncJournal **journals = qobject_cast<JournalsFetchJob *>(job)->journals();
Collection::List list;
const Collection &rootCollection = createRootCollection();
list.push_back(rootCollection);
for (EteSyncJournal **iter = journals; *iter; iter++) {
Collection collection;
collection.setParentCollection(rootCollection);
......
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