summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2013-11-04 21:50:44 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2013-11-04 21:50:44 (GMT)
commitfc4896670ccff5dcbd3dce97cb33e6c172e16ef1 (patch)
tree0ce30ca718c4e727094daa312d971ea81314ec7d
parent8827b110b4367f52d3efb25537f77ae9f01cffa0 (diff)
downloadkolab-utils-fc4896670ccff5dcbd3dce97cb33e6c172e16ef1.tar.gz
Separated ProbeIMAPServer from ProbeKolabServer. Moved folder setup to kolab job.
-rw-r--r--fbdaemon/fbaggregatorjob.cpp6
-rw-r--r--fbdaemon/fbaggregatorjob.h2
-rw-r--r--fbdaemon/fbgeneratorjob.cpp8
-rw-r--r--fbdaemon/fbgeneratorjob.h2
-rw-r--r--fbdaemon/kolabjob.cpp34
-rw-r--r--fbdaemon/kolabjob.h7
-rw-r--r--lib/CMakeLists.txt1
-rw-r--r--lib/jobs/CMakeLists.txt1
-rw-r--r--lib/jobs/probeimapserverjob.cpp93
-rw-r--r--lib/jobs/probeimapserverjob.h53
-rw-r--r--lib/jobs/probekolabserverjob.cpp82
-rw-r--r--lib/jobs/probekolabserverjob.h10
-rw-r--r--migrationutility/imapsourceaccount.cpp4
13 files changed, 206 insertions, 97 deletions
diff --git a/fbdaemon/fbaggregatorjob.cpp b/fbdaemon/fbaggregatorjob.cpp
index 4531336..47a283a 100644
--- a/fbdaemon/fbaggregatorjob.cpp
+++ b/fbdaemon/fbaggregatorjob.cpp
@@ -39,16 +39,16 @@ QStringList FBAggregatorJob::requiredFolders()
return QStringList() << KOLAB_FOLDER_TYPE_FREEBUSY;
}
-void FBAggregatorJob::startWork(ProbeKolabServerJob* capabilitiesJob)
+void FBAggregatorJob::startWork()
{
Debug() << "starting aggregator job for " << mSessionSettings.userName;
- if (capabilitiesJob->kolabFolders().values(KOLAB_FOLDER_TYPE_FREEBUSY).isEmpty()) {
+ if (mKolabFolders.values(KOLAB_FOLDER_TYPE_FREEBUSY).isEmpty()) {
kWarning() << "no freebusy folder found";
setError(KJob::UserDefinedError);
logout();
return;
}
- mFreebusyFolder = capabilitiesJob->kolabFolders().values(KOLAB_FOLDER_TYPE_FREEBUSY).first();
+ mFreebusyFolder = mKolabFolders.values(KOLAB_FOLDER_TYPE_FREEBUSY).first();
FetchMessagesJob *fetchJob = new FetchMessagesJob(mFreebusyFolder, mSession, this);
connect( fetchJob, SIGNAL(result(KJob*)), this, SLOT(onFetchFBDone(KJob*)) );
diff --git a/fbdaemon/fbaggregatorjob.h b/fbdaemon/fbaggregatorjob.h
index 0b4c270..24c45ee 100644
--- a/fbdaemon/fbaggregatorjob.h
+++ b/fbdaemon/fbaggregatorjob.h
@@ -40,7 +40,7 @@ private Q_SLOTS:
// void onGenerateFBDone(KJob*);
// void onModDone(KJob*);
private:
- virtual void startWork(ProbeKolabServerJob* job);
+ virtual void startWork();
QString mFreebusyFolder;
QString mGeneratedFile;
diff --git a/fbdaemon/fbgeneratorjob.cpp b/fbdaemon/fbgeneratorjob.cpp
index 3617637..25afbe6 100644
--- a/fbdaemon/fbgeneratorjob.cpp
+++ b/fbdaemon/fbgeneratorjob.cpp
@@ -49,16 +49,16 @@ QStringList FBGeneratorJob::requiredFolders()
}
-void FBGeneratorJob::startWork(ProbeKolabServerJob* capabilitiesJob)
+void FBGeneratorJob::startWork()
{
- if (capabilitiesJob->kolabFolders().values(KOLAB_FOLDER_TYPE_FREEBUSY).isEmpty()) {
+ if (mKolabFolders.values(KOLAB_FOLDER_TYPE_FREEBUSY).isEmpty()) {
kWarning() << "no freebusy folder found";
setError(KJob::UserDefinedError);
logout();
return;
}
- mFreebusyFolder = capabilitiesJob->kolabFolders().values(KOLAB_FOLDER_TYPE_FREEBUSY).first();
- mEventFolders = capabilitiesJob->kolabFolders().values(KOLAB_FOLDER_TYPE_EVENT);
+ mFreebusyFolder = mKolabFolders.values(KOLAB_FOLDER_TYPE_FREEBUSY).first();
+ mEventFolders = mKolabFolders.values(KOLAB_FOLDER_TYPE_EVENT);
if (mEventFolders.isEmpty()) {
kWarning() << "no event folders available";
logout();
diff --git a/fbdaemon/fbgeneratorjob.h b/fbdaemon/fbgeneratorjob.h
index bdfc5a6..47ee128 100644
--- a/fbdaemon/fbgeneratorjob.h
+++ b/fbdaemon/fbgeneratorjob.h
@@ -35,7 +35,7 @@ private Q_SLOTS:
protected:
virtual QStringList requiredFolders();
private:
- virtual void startWork(ProbeKolabServerJob* job);
+ virtual void startWork();
QString mFreebusyFolder;
QStringList mEventFolders;
diff --git a/fbdaemon/kolabjob.cpp b/fbdaemon/kolabjob.cpp
index 373b08b..be50a90 100644
--- a/fbdaemon/kolabjob.cpp
+++ b/fbdaemon/kolabjob.cpp
@@ -24,6 +24,7 @@
#include "uiproxy.h"
#include "authenticationjob.h"
#include "jobs/probekolabserverjob.h"
+#include <jobs/setupkolabfoldersjob.h>
#include <sessionsettings.h>
KolabJob::KolabJob(const SessionSettings &sessionSettings, QObject* parent)
@@ -72,7 +73,6 @@ void KolabJob::onAuthDone(KJob *job)
}
// Debug() << "login successful";
ProbeKolabServerJob *probeJob = new ProbeKolabServerJob(mSession, this);
- probeJob->createDefaultsIfMissing(requiredFolders());
QObject::connect(probeJob, SIGNAL(result(KJob*)), this, SLOT(onProbeDone(KJob*)));
probeJob->start();
}
@@ -85,9 +85,35 @@ void KolabJob::onProbeDone(KJob* job)
emitResult();
return;
}
- ProbeKolabServerJob *capabilitiesJob = qobject_cast<ProbeKolabServerJob*>( job );
- Q_ASSERT(capabilitiesJob);
- startWork(capabilitiesJob);
+ ProbeKolabServerJob *probeJob = static_cast<ProbeKolabServerJob*>(job);
+ mKolabFolders = probeJob->kolabFolders();
+
+ QString rootFolder;
+ QStringList toCreate;
+ foreach (const QString &folderType, requiredFolders()) {
+ if (!mKolabFolders.contains(folderType)) {
+ toCreate << folderType;
+ }
+ }
+ if (toCreate.isEmpty()) {
+ startWork();
+ } else {
+ SetupKolabFoldersJob *setupJob = new SetupKolabFoldersJob(probeJob->capabilities(), rootFolder, mSession, this);
+ setupJob->setKolabFolders(toCreate);
+ connect(setupJob, SIGNAL(result(KJob*)), this, SLOT(onSetupDone(KJob*)));
+ setupJob->start();
+ }
+}
+
+void KolabJob::onSetupDone(KJob *job)
+{
+ if ( job->error() ) {
+ Warning() << job->errorString();
+ setError(KJob::UserDefinedError);
+ emitResult();
+ return;
+ }
+ startWork();
}
void KolabJob::logout()
diff --git a/fbdaemon/kolabjob.h b/fbdaemon/kolabjob.h
index 8a1749e..30595b1 100644
--- a/fbdaemon/kolabjob.h
+++ b/fbdaemon/kolabjob.h
@@ -19,6 +19,8 @@
#define KOLABJOB_H
#include <kimap/session.h>
#include <QStringList>
+#include <QHash>
+#include <kimap/listjob.h>
#include <sessionsettings.h>
#define X_ORIGIN_HEADER "X-Freebusy-Origin"
@@ -36,17 +38,18 @@ private Q_SLOTS:
void onAuthDone(KJob*);
void onProbeDone(KJob* job);
void onLogoutDone(KJob*);
+ void onSetupDone(KJob*);
protected:
virtual QStringList requiredFolders();
- virtual void startWork(ProbeKolabServerJob *job) = 0;
+ virtual void startWork() = 0;
void logout();
SessionSettings mSessionSettings;
QString mFreebusyFolder;
KIMAP::Session *mSession;
-
+ QMultiHash<QString, QString> mKolabFolders;
};
#endif // KOLABJOB_H
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index ebcca44..dd03d7e 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -7,6 +7,7 @@ set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default" )
add_subdirectory(jobs)
QT4_WRAP_CPP(JOB_MOC
${CMAKE_CURRENT_SOURCE_DIR}/jobs/findkolabfoldersjob.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/jobs/probeimapserverjob.h
${CMAKE_CURRENT_SOURCE_DIR}/jobs/probekolabserverjob.h
${CMAKE_CURRENT_SOURCE_DIR}/jobs/sequentialcompositejob.h
${CMAKE_CURRENT_SOURCE_DIR}/jobs/messagemodifyjob.h
diff --git a/lib/jobs/CMakeLists.txt b/lib/jobs/CMakeLists.txt
index a9796ef..c1fa4e5 100644
--- a/lib/jobs/CMakeLists.txt
+++ b/lib/jobs/CMakeLists.txt
@@ -1,5 +1,6 @@
set (JOBS_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/findkolabfoldersjob.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/probeimapserverjob.cpp
${CMAKE_CURRENT_SOURCE_DIR}/probekolabserverjob.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sequentialcompositejob.cpp
${CMAKE_CURRENT_SOURCE_DIR}/messagemodifyjob.cpp
diff --git a/lib/jobs/probeimapserverjob.cpp b/lib/jobs/probeimapserverjob.cpp
new file mode 100644
index 0000000..512a77e
--- /dev/null
+++ b/lib/jobs/probeimapserverjob.cpp
@@ -0,0 +1,93 @@
+
+/*
+ * Copyright (C) 2012 Christian Mollekopf <mollekopf@kolabsys.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "probeimapserverjob.h"
+#include <kimap/capabilitiesjob.h>
+#include <kimap/namespacejob.h>
+#include <errorhandler.h>
+
+ProbeIMAPServerJob::ProbeIMAPServerJob(KIMAP::Session *session, QObject* parent)
+: KJob(parent),
+ mSession(session)
+{
+
+}
+
+ProbeIMAPServerJob::~ProbeIMAPServerJob()
+{
+
+}
+
+void ProbeIMAPServerJob::start()
+{
+ KIMAP::CapabilitiesJob *capabilities = new KIMAP::CapabilitiesJob(mSession);
+ connect(capabilities, SIGNAL(result(KJob*)), this, SLOT(onCapabilitiesTestDone(KJob*)));
+ capabilities->start();
+}
+
+void ProbeIMAPServerJob::onCapabilitiesTestDone(KJob* job)
+{
+ if ( job->error() ) {
+ Warning() << job->errorString();
+ setError(KJob::UserDefinedError);
+ emitResult();
+ return;
+ }
+ KIMAP::CapabilitiesJob *capabilitiesJob = qobject_cast<KIMAP::CapabilitiesJob*>( job );
+ Q_ASSERT(capabilitiesJob);
+ mCapabilities = capabilitiesJob->capabilities();
+ if ( mCapabilities.contains( "NAMESPACE" ) ) {
+ KIMAP::NamespaceJob *nsJob = new KIMAP::NamespaceJob( mSession );
+ QObject::connect( nsJob, SIGNAL(result(KJob*)), SLOT(onNamespacesTestDone(KJob*)) );
+ nsJob->start();
+ return;
+ } else {
+ emitResult();
+ }
+}
+
+void ProbeIMAPServerJob::onNamespacesTestDone( KJob *job )
+{
+ if ( job->error() ) {
+ Warning() << job->errorString();
+ setError(KJob::UserDefinedError);
+ emitResult();
+ return;
+ }
+ KIMAP::NamespaceJob *nsJob = qobject_cast<KIMAP::NamespaceJob*>( job );
+ Q_ASSERT(nsJob);
+ mPersonalNamespace = nsJob->personalNamespaces();
+ mExcludedNamespace = nsJob->userNamespaces()+nsJob->sharedNamespaces();
+
+ emitResult();
+}
+
+QStringList ProbeIMAPServerJob::capabilities() const
+{
+ return mCapabilities;
+}
+
+QList< KIMAP::MailBoxDescriptor > ProbeIMAPServerJob::personalNamespace() const
+{
+ return mPersonalNamespace;
+}
+
+QList< KIMAP::MailBoxDescriptor > ProbeIMAPServerJob::excludedNamespaces() const
+{
+ return mExcludedNamespace;
+}
diff --git a/lib/jobs/probeimapserverjob.h b/lib/jobs/probeimapserverjob.h
new file mode 100644
index 0000000..6cf0197
--- /dev/null
+++ b/lib/jobs/probeimapserverjob.h
@@ -0,0 +1,53 @@
+
+/*
+ * Copyright (C) 2013 Christian Mollekopf <mollekopf@kolabsys.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef PROBEIMAPSERVERJOB_H
+#define PROBEIMAPSERVERJOB_H
+#include <kcompositejob.h>
+#include <QStringList>
+#include <QHash>
+#include <kimap/session.h>
+#include <kimap/listjob.h>
+
+/**
+ * Probeserver for supported IMAP features
+ */
+class ProbeIMAPServerJob: public KJob
+{
+ Q_OBJECT
+public:
+ explicit ProbeIMAPServerJob(KIMAP::Session *, QObject* parent = 0);
+ virtual ~ProbeIMAPServerJob();
+ virtual void start();
+
+ QList<KIMAP::MailBoxDescriptor> personalNamespace() const;
+ QList<KIMAP::MailBoxDescriptor> excludedNamespaces() const;
+ QStringList capabilities() const;
+
+protected Q_SLOTS:
+ void onCapabilitiesTestDone(KJob *);
+ void onNamespacesTestDone(KJob *);
+
+private:
+ KIMAP::Session *mSession;
+ QStringList mCapabilities;
+ QList<KIMAP::MailBoxDescriptor> mPersonalNamespace;
+ QList<KIMAP::MailBoxDescriptor> mExcludedNamespace;
+};
+
+#endif
diff --git a/lib/jobs/probekolabserverjob.cpp b/lib/jobs/probekolabserverjob.cpp
index 60cd89e..324e989 100644
--- a/lib/jobs/probekolabserverjob.cpp
+++ b/lib/jobs/probekolabserverjob.cpp
@@ -18,8 +18,7 @@
#include "probekolabserverjob.h"
#include "findkolabfoldersjob.h"
#include "setupkolabfoldersjob.h"
-#include <kimap/capabilitiesjob.h>
-#include <kimap/namespacejob.h>
+#include "probeimapserverjob.h"
#include <errorhandler.h>
ProbeKolabServerJob::ProbeKolabServerJob(KIMAP::Session *session, QObject* parent)
@@ -36,53 +35,23 @@ ProbeKolabServerJob::~ProbeKolabServerJob()
void ProbeKolabServerJob::start()
{
- KIMAP::CapabilitiesJob *capabilities = new KIMAP::CapabilitiesJob(mSession);
- connect(capabilities, SIGNAL(result(KJob*)), this, SLOT(onCapabilitiesTestDone(KJob*)));
- capabilities->start();
+ ProbeIMAPServerJob *probeJob = new ProbeIMAPServerJob(mSession, this);
+ connect(probeJob, SIGNAL(result(KJob*)), this, SLOT(onProbeJobDone(KJob*)));
+ probeJob->start();
}
-void ProbeKolabServerJob::createDefaultsIfMissing(const QStringList &folders)
+void ProbeKolabServerJob::onProbeJobDone(KJob* job)
{
- mFoldersToCreate = folders;
-}
-
-void ProbeKolabServerJob::onCapabilitiesTestDone(KJob* job)
-{
- if ( job->error() ) {
- Warning() << job->errorString();
- setError(KJob::UserDefinedError);
- emitResult();
- return;
- }
- KIMAP::CapabilitiesJob *capabilitiesJob = qobject_cast<KIMAP::CapabilitiesJob*>( job );
- Q_ASSERT(capabilitiesJob);
- mCapabilities = capabilitiesJob->capabilities();
- if ( mCapabilities.contains( "NAMESPACE" ) ) {
- KIMAP::NamespaceJob *nsJob = new KIMAP::NamespaceJob( mSession );
- QObject::connect( nsJob, SIGNAL(result(KJob*)), SLOT(onNamespacesTestDone(KJob*)) );
- nsJob->start();
- return;
- } else {
- FindKolabFoldersJob *findJob = new FindKolabFoldersJob(mCapabilities, mPersonalNamespace, mExcludedNamespace, mSession, this);
- connect(findJob, SIGNAL(result(KJob*)), this, SLOT(findKolabFoldersDone(KJob*)));
- findJob->start();
- }
-}
-
-
-void ProbeKolabServerJob::onNamespacesTestDone( KJob *job )
-{
- if ( job->error() ) {
+ if (job->error()) {
Warning() << job->errorString();
setError(KJob::UserDefinedError);
emitResult();
return;
}
- KIMAP::NamespaceJob *nsJob = qobject_cast<KIMAP::NamespaceJob*>( job );
- Q_ASSERT(nsJob);
- mPersonalNamespace = nsJob->personalNamespaces();
- mExcludedNamespace = nsJob->userNamespaces()+nsJob->sharedNamespaces();
-
+ ProbeIMAPServerJob *probeJob = static_cast<ProbeIMAPServerJob*>(job);
+ mCapabilities = probeJob->capabilities();
+ mPersonalNamespace = probeJob->personalNamespace();
+ mExcludedNamespace = probeJob->excludedNamespaces();
FindKolabFoldersJob *findJob = new FindKolabFoldersJob(mCapabilities, mPersonalNamespace, mExcludedNamespace, mSession, this);
connect(findJob, SIGNAL(result(KJob*)), this, SLOT(findKolabFoldersDone(KJob*)));
findJob->start();
@@ -99,40 +68,9 @@ void ProbeKolabServerJob::findKolabFoldersDone(KJob *job)
FindKolabFoldersJob *findJob = static_cast<FindKolabFoldersJob*>(job);
// qDebug() << "Found kolab folders: " << findJob->getKolabFolders();
mKolabFolders = findJob->getKolabFolders();
-
- //TODO Setting up the missing folders shouldn't be part of the ProbeJob, and it's probably only used in one place in here => separate
- QString rootFolder;
- QStringList toCreate;
- foreach (const QString &folderType, mFoldersToCreate) {
- if (!mKolabFolders.contains(folderType)) {
- toCreate << folderType;
- }
- }
- if (toCreate.isEmpty()) {
- emitResult();
- return;
- }
- SetupKolabFoldersJob *setupJob = new SetupKolabFoldersJob(mCapabilities, rootFolder, mSession, this);
- setupJob->setKolabFolders(toCreate);
- connect(setupJob, SIGNAL(result(KJob*)), this, SLOT(onSetupDone(KJob*)));
- setupJob->start();
-}
-
-void ProbeKolabServerJob::onSetupDone(KJob *job)
-{
- if (job->error()) {
- Warning() << job->errorString();
- setError(KJob::UserDefinedError);
- }
- SetupKolabFoldersJob *setupJob = static_cast<SetupKolabFoldersJob*>(job);
- const QMap<QString, QString> createdFolders = setupJob->createdFolders();
- foreach (const QString &folderType, createdFolders.keys()) {
- mKolabFolders.insert(folderType, createdFolders.value(folderType));
- }
emitResult();
}
-
QMultiHash<QString, QString> ProbeKolabServerJob::kolabFolders() const
{
return mKolabFolders;
diff --git a/lib/jobs/probekolabserverjob.h b/lib/jobs/probekolabserverjob.h
index eff69e9..16e2e92 100644
--- a/lib/jobs/probekolabserverjob.h
+++ b/lib/jobs/probekolabserverjob.h
@@ -17,7 +17,6 @@
#ifndef PROBEKOLABSERVERJOB_H
#define PROBEKOLABSERVERJOB_H
-#include <kcompositejob.h>
#include <QStringList>
#include <QHash>
#include <kimap/session.h>
@@ -34,26 +33,21 @@ public:
virtual ~ProbeKolabServerJob();
virtual void start();
- void createDefaultsIfMissing(const QStringList &);
-
QList<KIMAP::MailBoxDescriptor> personalNamespace() const;
QList<KIMAP::MailBoxDescriptor> excludedNamespaces() const;
QStringList capabilities() const;
QMultiHash<QString, QString> kolabFolders() const;
protected Q_SLOTS:
- void onCapabilitiesTestDone( KJob *job );
- void onNamespacesTestDone( KJob *job );
+ void onProbeJobDone(KJob *job);
void findKolabFoldersDone(KJob*);
+
private:
KIMAP::Session *mSession;
QStringList mCapabilities;
QList<KIMAP::MailBoxDescriptor> mPersonalNamespace;
QList<KIMAP::MailBoxDescriptor> mExcludedNamespace;
QMultiHash<QString, QString> mKolabFolders;
- QStringList mFoldersToCreate;
-public slots:
- void onSetupDone(KJob*);
};
#endif // PROBEKOLABSERVERJOB_H
diff --git a/migrationutility/imapsourceaccount.cpp b/migrationutility/imapsourceaccount.cpp
index 32e921e..91a4e2b 100644
--- a/migrationutility/imapsourceaccount.cpp
+++ b/migrationutility/imapsourceaccount.cpp
@@ -18,7 +18,7 @@
#include "imapsourceaccount.h"
#include <jobs/fetchmessagesjob.h>
-#include <jobs/probekolabserverjob.h>
+#include <jobs/probeimapserverjob.h>
#include <sessionfactory.h>
#include <kimap/session.h>
#include <kimap/listjob.h>
@@ -72,7 +72,7 @@ QPair<Kolab::FolderType, QString> IMAPSourceAccount::translateFolder(const QStri
void IMAPSourceAccount::init()
{
- ProbeKolabServerJob *probeJob = new ProbeKolabServerJob(mSession, this);
+ ProbeIMAPServerJob *probeJob = new ProbeIMAPServerJob(mSession, this);
probeJob->exec();
mPersonalNamespaces = probeJob->personalNamespace();
}