summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2013-11-08 10:19:11 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2013-11-08 10:19:11 (GMT)
commitee2b3d7dd1824a62da2dcd41b91f5fbd07396784 (patch)
treeb5e8c38224b6e666b29b9791b33a3f1750b63696
parent431653a26a3596e955e0fb99ce8afe6550cdfc7b (diff)
downloadkolab-utils-ee2b3d7dd1824a62da2dcd41b91f5fbd07396784.tar.gz
Use common baseclass for google folder fetch jobs too.
-rw-r--r--migrationutility/googlesourceaccount.cpp163
-rw-r--r--migrationutility/googlesourceaccount.h46
2 files changed, 96 insertions, 113 deletions
diff --git a/migrationutility/googlesourceaccount.cpp b/migrationutility/googlesourceaccount.cpp
index e425281..a920719 100644
--- a/migrationutility/googlesourceaccount.cpp
+++ b/migrationutility/googlesourceaccount.cpp
@@ -49,7 +49,6 @@ void GoogleFetchObjectsJob::start()
emitResult();
return;
}
- Debug() << "fetching contacts";
KGAPI2::FetchJob *fetchJob = getFetchJob(mAccount, mCurrentFolder);
connect(fetchJob, SIGNAL(finished(KGAPI2::Job*)), this, SLOT(slotFetchJobFinished(KGAPI2::Job*)));
@@ -71,16 +70,59 @@ void GoogleFetchObjectsJob::slotFetchJobFinished(KGAPI2::Job* job)
}
QList<Object> objects;
- /* Get all items the job has retrieved */
- const KGAPI2::ObjectsList items = fetchJob->items();
- foreach (const KGAPI2::ObjectPtr &i, items) {
+ foreach (const KGAPI2::ObjectPtr &i, fetchJob->items()) {
objects << getObject(i);
-
}
emit objectsReceived(mCurrentFolder, objects);
emitResult();
}
+GoogleFetchFoldersJob::GoogleFetchFoldersJob(const KGAPI2::AccountPtr& account, QObject* parent)
+: FetchFoldersJob(parent),
+ mAccount(account)
+{
+
+}
+
+void GoogleFetchFoldersJob::start()
+{
+ if (mAccount.isNull()) {
+ Error() << "Error: Please authenticate first";
+ setError(KJob::UserDefinedError);
+ setErrorText("Error: Please authenticate first");
+ emitResult();
+ return;
+ }
+
+ KGAPI2::FetchJob *fetchJob = getFetchJob(mAccount);
+ connect(fetchJob, SIGNAL(finished(KGAPI2::Job*)), this, SLOT(slotFetchJobFinished(KGAPI2::Job*)));
+}
+
+
+void GoogleFetchFoldersJob::slotFetchJobFinished(KGAPI2::Job* job)
+{
+ 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;
+ }
+
+ QStringList folders;
+ foreach (const KGAPI2::ObjectPtr &i, fetchJob->items()) {
+ const QPair<QString, QString> folder = getFolder(i);
+ folders << folder.first;
+ mNames.insert(folder.first, folder.second);
+ }
+ emit foldersReceived(folders);
+ emitResult();
+}
+
FetchContactObjectsJob::FetchContactObjectsJob(const KGAPI2::AccountPtr &account, QObject* parent)
@@ -127,56 +169,24 @@ Object FetchCalendarObjectsJob::getObject(const KGAPI2::ObjectPtr &object)
FetchCalendarFoldersJob::FetchCalendarFoldersJob(const KGAPI2::AccountPtr& account, QObject* parent)
-: FetchFoldersJob(parent),
- mAccount(account)
+: GoogleFetchFoldersJob(account, parent)
{
}
-void FetchCalendarFoldersJob::start()
+KGAPI2::FetchJob* FetchCalendarFoldersJob::getFetchJob(const KGAPI2::AccountPtr& account)
{
- if (mAccount.isNull()) {
- Error() << "Error: Please authenticate first";
- setError(KJob::UserDefinedError);
- setErrorText("Error: Please authenticate first");
- emitResult();
- return;
- }
- Debug() << "fetch calendars";
- KGAPI2::CalendarFetchJob *fetchJob = new KGAPI2::CalendarFetchJob(mAccount, this);
- connect(fetchJob, SIGNAL(finished(KGAPI2::Job*)), this, SLOT(slotFetchJobFinished(KGAPI2::Job*)));
+ return new KGAPI2::CalendarFetchJob(account, this);
}
-void FetchCalendarFoldersJob::slotFetchJobFinished(KGAPI2::Job* job)
+QPair<QString, QString> FetchCalendarFoldersJob::getFolder(const KGAPI2::ObjectPtr& object)
{
- KGAPI2::CalendarFetchJob *fetchJob = qobject_cast<KGAPI2::CalendarFetchJob*>(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 objects = fetchJob->items();
-
- QStringList folders;
- Debug() << "Fetched " << objects.size() << " calendars";
- Q_FOREACH (const KGAPI2::ObjectPtr &c, objects) {
- const KGAPI2::Calendar &calendar = *c.dynamicCast<KGAPI2::Calendar>();
- //TODO prefix with Calendar/
- QString name = calendar.title();
- //normalize so it works as imap mailbox name
- name.replace(QLatin1String("@"), QLatin1String("at"));
- Debug() << "calendar: " << name;
- mNames.insert(calendar.uid(), name);
- folders << calendar.uid();
- }
- emit foldersReceived(folders);
- emitResult();
+ const KGAPI2::Calendar &calendar = *object.dynamicCast<KGAPI2::Calendar>();
+ //TODO prefix with Calendar/
+ QString name = calendar.title();
+ //normalize so it works as imap mailbox name
+ name.replace(QLatin1String("@"), QLatin1String("at"));
+ Debug() << "calendar: " << name;
+ return qMakePair<QString, QString>(calendar.uid(), name);
}
FetchTaskObjectsJob::FetchTaskObjectsJob(const QString &tasklistId, const KGAPI2::AccountPtr& account, QObject* parent)
@@ -199,61 +209,26 @@ Object FetchTaskObjectsJob::getObject(const KGAPI2::ObjectPtr &object)
}
FetchTaskListsJob::FetchTaskListsJob(const KGAPI2::AccountPtr& account, QObject* parent)
-: FetchFoldersJob(parent),
- mAccount(account)
+: GoogleFetchFoldersJob(account, parent)
{
}
-void FetchTaskListsJob::start()
+KGAPI2::FetchJob* FetchTaskListsJob::getFetchJob(const KGAPI2::AccountPtr& account)
{
- if (mAccount.isNull()) {
- Error() << "Error: Please authenticate first";
- setError(KJob::UserDefinedError);
- setErrorText("Error: Please authenticate first");
- emitResult();
- return;
- }
- Debug() << "fetch tasks";
- KGAPI2::TaskListFetchJob *fetchJob = new KGAPI2::TaskListFetchJob(mAccount, this);
- connect(fetchJob, SIGNAL(finished(KGAPI2::Job*)), this, SLOT(slotFetchJobFinished(KGAPI2::Job*)));
+ return new KGAPI2::TaskListFetchJob(account, this);
}
-//TODO somehow share this with the other fetchjobs
-//multiple inheritance? need to figure out how to use virtual inheritance for this
-void FetchTaskListsJob::slotFetchJobFinished(KGAPI2::Job* job)
+QPair<QString, QString> FetchTaskListsJob::getFolder(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 objects = fetchJob->items();
-
- QStringList folders;
- Debug() << "Fetched " << objects.size() << " tasklists";
- Q_FOREACH (const KGAPI2::ObjectPtr &c, objects) {
- const KGAPI2::TaskList &list = *c.dynamicCast<KGAPI2::TaskList>();
- //TODO prefix with Task/
- QString name = list.title();
- //normalize so it works as imap mailbox name
- name.replace(QLatin1String("@"), QLatin1String("at"));
- Debug() << "calendar: " << name;
- mNames.insert(list.uid(), name);
- folders << list.uid();
- }
- emit foldersReceived(folders);
- emitResult();
+ const KGAPI2::TaskList &list = *object.dynamicCast<KGAPI2::TaskList>();
+ //TODO prefix with Task/
+ QString name = list.title();
+ //normalize so it works as imap mailbox name
+ name.replace(QLatin1String("@"), QLatin1String("at"));
+ Debug() << "calendar: " << name;
+ return qMakePair<QString, QString>(list.uid(), name);
}
-
LoginJob::LoginJob(const KGAPI2::AccountPtr &account, QObject* parent)
: KJob(parent),
mAccount(account)
diff --git a/migrationutility/googlesourceaccount.h b/migrationutility/googlesourceaccount.h
index 2085873..e1c1bf7 100644
--- a/migrationutility/googlesourceaccount.h
+++ b/migrationutility/googlesourceaccount.h
@@ -106,6 +106,25 @@ private:
const QString mCurrentFolder;
};
+class GoogleFetchFoldersJob : public FetchFoldersJob
+{
+ Q_OBJECT
+public:
+ explicit GoogleFetchFoldersJob(const KGAPI2::AccountPtr &account, QObject* parent = 0);
+ virtual void start();
+ QHash<QString, QString> mNames;
+
+protected:
+ virtual QPair<QString, QString> getFolder(const KGAPI2::ObjectPtr &object) = 0;
+ virtual KGAPI2::FetchJob *getFetchJob(const KGAPI2::AccountPtr &account) = 0;
+
+private slots:
+ void slotFetchJobFinished(KGAPI2::Job *job);
+
+private:
+ const KGAPI2::AccountPtr mAccount;
+};
+
class FetchContactObjectsJob : public GoogleFetchObjectsJob
{
public:
@@ -132,7 +151,6 @@ private:
class FetchCalendarObjectsJob : public GoogleFetchObjectsJob
{
- Q_OBJECT
public:
explicit FetchCalendarObjectsJob(const QString &mCalendarId, const KGAPI2::AccountPtr &account, QObject* parent = 0);
@@ -141,19 +159,14 @@ protected:
virtual Object getObject(const KGAPI2::ObjectPtr& );
};
-class FetchCalendarFoldersJob : public FetchFoldersJob
+class FetchCalendarFoldersJob : public GoogleFetchFoldersJob
{
- Q_OBJECT
public:
explicit FetchCalendarFoldersJob(const KGAPI2::AccountPtr &account, QObject* parent = 0);
- virtual void start();
- QHash<QString, QString> mNames;
-
-private slots:
- void slotFetchJobFinished(KGAPI2::Job *job);
-private:
- KGAPI2::AccountPtr mAccount;
+protected:
+ virtual KGAPI2::FetchJob* getFetchJob(const KGAPI2::AccountPtr& account);
+ virtual QPair<QString, QString> getFolder(const KGAPI2::ObjectPtr& object);
};
class FetchTaskObjectsJob : public GoogleFetchObjectsJob
@@ -166,19 +179,14 @@ protected:
virtual Object getObject(const KGAPI2::ObjectPtr& );
};
-class FetchTaskListsJob : public FetchFoldersJob
+class FetchTaskListsJob : public GoogleFetchFoldersJob
{
- Q_OBJECT
public:
explicit FetchTaskListsJob(const KGAPI2::AccountPtr &account, QObject* parent = 0);
- virtual void start();
- QHash<QString, QString> mNames;
-
-private slots:
- void slotFetchJobFinished(KGAPI2::Job *job);
-private:
- KGAPI2::AccountPtr mAccount;
+protected:
+ virtual KGAPI2::FetchJob* getFetchJob(const KGAPI2::AccountPtr& account);
+ virtual QPair< QString, QString > getFolder(const KGAPI2::ObjectPtr& object);
};
#endif \ No newline at end of file