summaryrefslogtreecommitdiff
path: root/migrationutility/googlesourceaccount.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'migrationutility/googlesourceaccount.cpp')
-rw-r--r--migrationutility/googlesourceaccount.cpp155
1 files changed, 54 insertions, 101 deletions
diff --git a/migrationutility/googlesourceaccount.cpp b/migrationutility/googlesourceaccount.cpp
index b99f250..e425281 100644
--- a/migrationutility/googlesourceaccount.cpp
+++ b/migrationutility/googlesourceaccount.cpp
@@ -32,14 +32,15 @@
#include <errorhandler.h>
-FetchContactObjectsJob::FetchContactObjectsJob(const KGAPI2::AccountPtr &account, QObject* parent)
+GoogleFetchObjectsJob::GoogleFetchObjectsJob(const QString &currentFolder, const KGAPI2::AccountPtr& account, QObject* parent)
: FetchObjectsJob(parent),
- mAccount(account)
+ mAccount(account),
+ mCurrentFolder(currentFolder)
{
}
-void FetchContactObjectsJob::start()
+void GoogleFetchObjectsJob::start()
{
if (mAccount.isNull()) {
Error() << "Error: Please authenticate first";
@@ -50,13 +51,14 @@ void FetchContactObjectsJob::start()
}
Debug() << "fetching contacts";
- KGAPI2::ContactFetchJob *fetchJob = new KGAPI2::ContactFetchJob(mAccount, this);
+ KGAPI2::FetchJob *fetchJob = getFetchJob(mAccount, mCurrentFolder);
connect(fetchJob, SIGNAL(finished(KGAPI2::Job*)), this, SLOT(slotFetchJobFinished(KGAPI2::Job*)));
}
-void FetchContactObjectsJob::slotFetchJobFinished(KGAPI2::Job *job)
+
+void GoogleFetchObjectsJob::slotFetchJobFinished(KGAPI2::Job* job)
{
- KGAPI2::ContactFetchJob *fetchJob = qobject_cast<KGAPI2::ContactFetchJob*>(job);
+ KGAPI2::FetchJob *fetchJob = qobject_cast<KGAPI2::FetchJob*>(job);
Q_ASSERT(fetchJob);
fetchJob->deleteLater();
@@ -68,77 +70,62 @@ void FetchContactObjectsJob::slotFetchJobFinished(KGAPI2::Job *job)
return;
}
+ QList<Object> objects;
/* Get all items the job has retrieved */
- const KGAPI2::ObjectsList contacts = fetchJob->items();
+ const KGAPI2::ObjectsList items = fetchJob->items();
+ foreach (const KGAPI2::ObjectPtr &i, items) {
+ objects << getObject(i);
- QList<Object> objects;
- Debug() << "Fetched " << contacts.size() << " contacts";
- Q_FOREACH (const KGAPI2::ObjectPtr &c, contacts) {
- const KABC::Addressee contact = *c.dynamicCast<KGAPI2::Contact>();
- Debug() << "contact: " << contact.name();
- qDebug() << contact.emails();
-
- Object obj;
- obj.object = QVariant::fromValue(contact);
- objects << obj;
}
- emit objectsReceived("Contacts", objects);
+ emit objectsReceived(mCurrentFolder, objects);
emitResult();
}
-FetchCalendarObjectsJob::FetchCalendarObjectsJob(const QString &calendarId, const KGAPI2::AccountPtr& account, QObject* parent)
-: FetchObjectsJob(parent),
- mAccount(account),
- mCalendarId(calendarId)
+
+
+FetchContactObjectsJob::FetchContactObjectsJob(const KGAPI2::AccountPtr &account, QObject* parent)
+: GoogleFetchObjectsJob(QLatin1String("Contacts"), account, parent)
{
+
}
-void FetchCalendarObjectsJob::start()
+KGAPI2::FetchJob* FetchContactObjectsJob::getFetchJob(const KGAPI2::AccountPtr& account, const QString& folder)
{
- if (mAccount.isNull()) {
- Error() << "Error: Please authenticate first";
- setError(KJob::UserDefinedError);
- setErrorText("Error: Please authenticate first");
- emitResult();
- return;
- }
- Debug() << "fetching events";
-
- KGAPI2::EventFetchJob *fetchJob = new KGAPI2::EventFetchJob(mCalendarId, mAccount, this);
- connect(fetchJob, SIGNAL(finished(KGAPI2::Job*)), this, SLOT(slotFetchJobFinished(KGAPI2::Job*)));
+ Q_UNUSED(folder);
+ return new KGAPI2::ContactFetchJob(account, this);
}
-void FetchCalendarObjectsJob::slotFetchJobFinished(KGAPI2::Job* job)
+Object FetchContactObjectsJob::getObject(const KGAPI2::ObjectPtr& object)
{
- KGAPI2::EventFetchJob *fetchJob = qobject_cast<KGAPI2::EventFetchJob*>(job);
- Q_ASSERT(fetchJob);
- fetchJob->deleteLater();
+ const KABC::Addressee contact = *object.dynamicCast<KGAPI2::Contact>();
+ Debug() << "contact: " << contact.name();
+ qDebug() << contact.emails();
+ Object obj;
+ obj.object = QVariant::fromValue(contact);
+ return obj;
+}
- if (fetchJob->error() != KGAPI2::NoError) {
- Error() << fetchJob->errorString();
- setError(KJob::UserDefinedError);
- setErrorText(fetchJob->errorString());
- emitResult();
- return;
- }
+FetchCalendarObjectsJob::FetchCalendarObjectsJob(const QString &calendarId, const KGAPI2::AccountPtr& account, QObject* parent)
+: GoogleFetchObjectsJob(calendarId, account, parent)
+{
+}
- /* Get all items the job has retrieved */
- const KGAPI2::ObjectsList events = fetchJob->items();
+KGAPI2::FetchJob* FetchCalendarObjectsJob::getFetchJob(const KGAPI2::AccountPtr &account, const QString& folder)
+{
+ return new KGAPI2::EventFetchJob(folder, account, this);
+}
- QList<Object> objects;
- Debug() << "Fetched " << events.size() << " events";
- Q_FOREACH (const KGAPI2::ObjectPtr &c, events) {
- KCalCore::Incidence::Ptr event(c.dynamicCast<KGAPI2::Event>()->clone());
- Debug() << event->uid() << event->summary();
- Object obj;
- obj.object = QVariant::fromValue(event);
- objects << obj;
- }
- emit objectsReceived(mCalendarId, objects);
- emitResult();
+Object FetchCalendarObjectsJob::getObject(const KGAPI2::ObjectPtr &object)
+{
+ KCalCore::Incidence::Ptr event(object.dynamicCast<KGAPI2::Event>()->clone());
+ Debug() << event->uid() << event->summary();
+ Object obj;
+ obj.object = QVariant::fromValue(event);
+ return obj;
}
+
FetchCalendarFoldersJob::FetchCalendarFoldersJob(const KGAPI2::AccountPtr& account, QObject* parent)
: FetchFoldersJob(parent),
mAccount(account)
@@ -193,58 +180,24 @@ void FetchCalendarFoldersJob::slotFetchJobFinished(KGAPI2::Job* job)
}
FetchTaskObjectsJob::FetchTaskObjectsJob(const QString &tasklistId, const KGAPI2::AccountPtr& account, QObject* parent)
-: FetchObjectsJob(parent),
- mAccount(account),
- mTasklistId(tasklistId)
+: GoogleFetchObjectsJob(tasklistId, account, parent)
{
}
-void FetchTaskObjectsJob::start()
+KGAPI2::FetchJob* FetchTaskObjectsJob::getFetchJob(const KGAPI2::AccountPtr &account, const QString& folder)
{
- if (mAccount.isNull()) {
- Error() << "Error: Please authenticate first";
- setError(KJob::UserDefinedError);
- setErrorText("Error: Please authenticate first");
- emitResult();
- return;
- }
- Debug() << "fetching tasks";
-
- KGAPI2::TaskFetchJob *fetchJob = new KGAPI2::TaskFetchJob(mTasklistId, mAccount, this);
- connect(fetchJob, SIGNAL(finished(KGAPI2::Job*)), this, SLOT(slotFetchJobFinished(KGAPI2::Job*)));
+ return new KGAPI2::TaskFetchJob(folder, account, this);
}
-void FetchTaskObjectsJob::slotFetchJobFinished(KGAPI2::Job* job)
+Object FetchTaskObjectsJob::getObject(const KGAPI2::ObjectPtr &object)
{
- KGAPI2::FetchJob *fetchJob = qobject_cast<KGAPI2::FetchJob*>(job);
- Q_ASSERT(fetchJob);
- fetchJob->deleteLater();
-
- if (fetchJob->error() != KGAPI2::NoError) {
- Error() << fetchJob->errorString();
- setError(KJob::UserDefinedError);
- setErrorText(fetchJob->errorString());
- emitResult();
- return;
- }
-
- /* Get all items the job has retrieved */
- const KGAPI2::ObjectsList tasks = fetchJob->items();
-
- QList<Object> objects;
- Debug() << "Fetched " << tasks.size() << " tasks";
- Q_FOREACH (const KGAPI2::ObjectPtr &c, tasks) {
- KCalCore::Incidence::Ptr task(c.dynamicCast<KGAPI2::Task>()->clone());
- Debug() << task->uid() << task->summary();
- Object obj;
- obj.object = QVariant::fromValue(task);
- objects << obj;
- }
- emit objectsReceived(mTasklistId, objects);
- emitResult();
+ KCalCore::Incidence::Ptr task(object.dynamicCast<KGAPI2::Task>()->clone());
+ Debug() << task->uid() << task->summary();
+ Object obj;
+ obj.object = QVariant::fromValue(task);
+ return obj;
}
-
FetchTaskListsJob::FetchTaskListsJob(const KGAPI2::AccountPtr& account, QObject* parent)
: FetchFoldersJob(parent),
mAccount(account)