summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--migrationutility/googlesourceaccount.cpp155
-rw-r--r--migrationutility/googlesourceaccount.h52
2 files changed, 81 insertions, 126 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)
diff --git a/migrationutility/googlesourceaccount.h b/migrationutility/googlesourceaccount.h
index 52c76d1..2085873 100644
--- a/migrationutility/googlesourceaccount.h
+++ b/migrationutility/googlesourceaccount.h
@@ -25,6 +25,7 @@
namespace KGAPI2 {
class Job;
+class FetchJob;
}
class GoogleSourceAccount: public SourceAccount
@@ -86,18 +87,33 @@ private:
QHash<QString, QString> mTasklists;
};
-class FetchContactObjectsJob : public FetchObjectsJob
+class GoogleFetchObjectsJob : public FetchObjectsJob
{
Q_OBJECT
public:
- explicit FetchContactObjectsJob(const KGAPI2::AccountPtr &account, QObject* parent = 0);
+ explicit GoogleFetchObjectsJob(const QString &folder, const KGAPI2::AccountPtr &account, QObject* parent = 0);
virtual void start();
+protected:
+ virtual Object getObject(const KGAPI2::ObjectPtr &) = 0;
+ virtual KGAPI2::FetchJob *getFetchJob(const KGAPI2::AccountPtr &, const QString &folder) = 0;
+
private slots:
void slotFetchJobFinished(KGAPI2::Job *job);
private:
- KGAPI2::AccountPtr mAccount;
+ const KGAPI2::AccountPtr mAccount;
+ const QString mCurrentFolder;
+};
+
+class FetchContactObjectsJob : public GoogleFetchObjectsJob
+{
+public:
+ explicit FetchContactObjectsJob(const KGAPI2::AccountPtr &account, QObject* parent = 0);
+
+protected:
+ virtual KGAPI2::FetchJob* getFetchJob(const KGAPI2::AccountPtr &account, const QString& folder);
+ virtual Object getObject(const KGAPI2::ObjectPtr &object);
};
class LoginJob : public KJob
@@ -114,24 +130,15 @@ private:
KGAPI2::AccountPtr mAccount;
};
-/*
- * TODO
- * All fetch jobs could be consolidated into one, but we need multiple inheritance
- */
-
-class FetchCalendarObjectsJob : public FetchObjectsJob
+class FetchCalendarObjectsJob : public GoogleFetchObjectsJob
{
Q_OBJECT
public:
explicit FetchCalendarObjectsJob(const QString &mCalendarId, const KGAPI2::AccountPtr &account, QObject* parent = 0);
- virtual void start();
-private slots:
- void slotFetchJobFinished(KGAPI2::Job *job);
-
-private:
- KGAPI2::AccountPtr mAccount;
- QString mCalendarId;
+protected:
+ virtual KGAPI2::FetchJob* getFetchJob(const KGAPI2::AccountPtr& , const QString& folder);
+ virtual Object getObject(const KGAPI2::ObjectPtr& );
};
class FetchCalendarFoldersJob : public FetchFoldersJob
@@ -149,19 +156,14 @@ private:
KGAPI2::AccountPtr mAccount;
};
-class FetchTaskObjectsJob : public FetchObjectsJob
+class FetchTaskObjectsJob : public GoogleFetchObjectsJob
{
- Q_OBJECT
public:
explicit FetchTaskObjectsJob(const QString &mTasklistId, const KGAPI2::AccountPtr &account, QObject* parent = 0);
- virtual void start();
-
-private slots:
- void slotFetchJobFinished(KGAPI2::Job *job);
-private:
- KGAPI2::AccountPtr mAccount;
- QString mTasklistId;
+protected:
+ virtual KGAPI2::FetchJob* getFetchJob(const KGAPI2::AccountPtr& , const QString& folder);
+ virtual Object getObject(const KGAPI2::ObjectPtr& );
};
class FetchTaskListsJob : public FetchFoldersJob