summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Mollekopf <mollekopf@kolabsys.com>2013-11-11 13:03:28 (GMT)
committerChristian Mollekopf <mollekopf@kolabsys.com>2013-11-11 13:03:28 (GMT)
commit5cc21d084a89f871e009df2f5696040b32c379ac (patch)
tree1127ab30e7078a7dfa18ee82776c20f2537253e2
parentee2b3d7dd1824a62da2dcd41b91f5fbd07396784 (diff)
downloadkolab-utils-5cc21d084a89f871e009df2f5696040b32c379ac.tar.gz
Set private and shared annotations. Moved folder creation to separate job to reuse in kolabaccount.
-rw-r--r--lib/CMakeLists.txt1
-rw-r--r--lib/jobs/CMakeLists.txt1
-rw-r--r--lib/jobs/createkolabfolderjob.cpp109
-rw-r--r--lib/jobs/createkolabfolderjob.h54
-rw-r--r--lib/jobs/setupkolabfoldersjob.cpp75
-rw-r--r--lib/jobs/setupkolabfoldersjob.h6
-rw-r--r--lib/kolabaccount.cpp24
7 files changed, 201 insertions, 69 deletions
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index dd03d7e..4fb4ffc 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -14,6 +14,7 @@ QT4_WRAP_CPP(JOB_MOC
${CMAKE_CURRENT_SOURCE_DIR}/jobs/fetchmessagesjob.h
${CMAKE_CURRENT_SOURCE_DIR}/jobs/setupkolabfoldersjob.h
${CMAKE_CURRENT_SOURCE_DIR}/jobs/getuserlistjob.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/jobs/createkolabfolderjob.h
)
set( JOBS_SRCS ${JOBS_SRCS} ${JOB_MOC} )
diff --git a/lib/jobs/CMakeLists.txt b/lib/jobs/CMakeLists.txt
index c1fa4e5..8667abb 100644
--- a/lib/jobs/CMakeLists.txt
+++ b/lib/jobs/CMakeLists.txt
@@ -7,5 +7,6 @@ set (JOBS_SRCS
${CMAKE_CURRENT_SOURCE_DIR}/fetchmessagesjob.cpp
${CMAKE_CURRENT_SOURCE_DIR}/setupkolabfoldersjob.cpp
${CMAKE_CURRENT_SOURCE_DIR}/getuserlistjob.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/createkolabfolderjob.cpp
PARENT_SCOPE)
diff --git a/lib/jobs/createkolabfolderjob.cpp b/lib/jobs/createkolabfolderjob.cpp
new file mode 100644
index 0000000..51f67bb
--- /dev/null
+++ b/lib/jobs/createkolabfolderjob.cpp
@@ -0,0 +1,109 @@
+/*
+ * 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/>.
+ */
+
+#include "createkolabfolderjob.h"
+
+#include <kimap/createjob.h>
+#include <kimap/setmetadatajob.h>
+#include <QStringList>
+
+#include <errorhandler.h>
+#include <kolabdefinitions.h>
+
+CreateKolabFolderJob::CreateKolabFolderJob(const QString& name, const QByteArray& sharedAnnotation, const QByteArray& privateAnnotation, CreateKolabFolderJob::MetadataCapability cap, KIMAP::Session* session, QObject* parent)
+: KJob(parent),
+ m_session(session),
+ m_name(name),
+ m_sharedAnnotation(sharedAnnotation),
+ m_privateAnnotation(privateAnnotation),
+ m_metadataCapability(cap)
+{
+
+}
+
+void CreateKolabFolderJob::start()
+{
+ KIMAP::CreateJob *createJob = new KIMAP::CreateJob(m_session);
+ createJob->setMailBox(m_name);
+ connect(createJob, SIGNAL(result(KJob*)), this, SLOT(onCreateDone(KJob*)));
+ createJob->start();
+}
+
+CreateKolabFolderJob::MetadataCapability CreateKolabFolderJob::capablitiesFromString(const QString &cap)
+{
+ if (cap.contains(QLatin1String("ANNOTATEMORE"))) {
+ return Annotatemore;
+ }
+ return Metadata;
+}
+
+CreateKolabFolderJob::MetadataCapability CreateKolabFolderJob::capablitiesFromString(const QStringList &cap)
+{
+ if (cap.contains(QLatin1String("ANNOTATEMORE"))) {
+ return Annotatemore;
+ }
+ return Metadata;
+}
+
+void CreateKolabFolderJob::onCreateDone(KJob *job)
+{
+ if (job->error()) {
+ Warning() << job->errorString() << "Trying to fix the metadata";
+ } else {
+ KIMAP::CreateJob *createJob = static_cast<KIMAP::CreateJob*>(job);
+ Debug() << "Created folder " << createJob->mailBox();
+ }
+
+ KIMAP::SetMetaDataJob *setMetadataJob = new KIMAP::SetMetaDataJob(m_session);
+ setMetadataJob->setMailBox(m_name);
+ if ( m_metadataCapability == Metadata ) {
+ setMetadataJob->setServerCapability( KIMAP::MetaDataJobBase::Metadata );
+ if (!m_sharedAnnotation.isEmpty()) {
+ setMetadataJob->addMetaData("/shared" KOLAB_FOLDER_TYPE_ANNOTATION, m_sharedAnnotation);
+ }
+ if (!m_privateAnnotation.isEmpty()) {
+ setMetadataJob->addMetaData("/private" KOLAB_FOLDER_TYPE_ANNOTATION, m_privateAnnotation);
+ }
+ } else {
+ setMetadataJob->setServerCapability( KIMAP::MetaDataJobBase::Annotatemore );
+ setMetadataJob->setEntry( KOLAB_FOLDER_TYPE_ANNOTATION );
+ if (!m_sharedAnnotation.isEmpty()) {
+ setMetadataJob->addMetaData("value.shared", m_sharedAnnotation);
+ }
+ if (!m_privateAnnotation.isEmpty()) {
+ setMetadataJob->addMetaData("value.priv", m_privateAnnotation);
+ }
+ }
+ connect(setMetadataJob, SIGNAL(result(KJob*)), this, SLOT(onMetadataSetDone(KJob*)));
+ setMetadataJob->start();
+}
+
+void CreateKolabFolderJob::onMetadataSetDone(KJob *job)
+{
+ if ( job->error() ) {
+ Warning() << job->errorString();
+ setErrorText("Failed to create folder: " + m_name);
+ setError(KJob::UserDefinedError);
+ }
+ emitResult();
+}
+
+QString CreateKolabFolderJob::folder() const
+{
+ return m_name;
+}
+
diff --git a/lib/jobs/createkolabfolderjob.h b/lib/jobs/createkolabfolderjob.h
new file mode 100644
index 0000000..b293e35
--- /dev/null
+++ b/lib/jobs/createkolabfolderjob.h
@@ -0,0 +1,54 @@
+/*
+ * 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 CREATEKOLABFOLDERJOB_H
+#define CREATEKOLABFOLDERJOB_H
+
+#include <kjob.h>
+
+namespace KIMAP {
+class Session;
+}
+
+class CreateKolabFolderJob : public KJob
+{
+ Q_OBJECT
+public:
+ enum MetadataCapability {
+ Metadata,
+ Annotatemore
+ };
+ explicit CreateKolabFolderJob(const QString &name, const QByteArray &sharedAnnotation, const QByteArray &privateAnnotation, MetadataCapability cap, KIMAP::Session *session, QObject* parent = 0);
+ virtual void start();
+
+ QString folder() const;
+
+ static MetadataCapability capablitiesFromString(const QString &);
+ static MetadataCapability capablitiesFromString(const QStringList &);
+
+private slots:
+ void onCreateDone(KJob*);
+ void onMetadataSetDone(KJob*);
+private:
+ KIMAP::Session *m_session;
+ QString m_name;
+ QByteArray m_sharedAnnotation;
+ QByteArray m_privateAnnotation;
+ MetadataCapability m_metadataCapability;
+};
+
+#endif
diff --git a/lib/jobs/setupkolabfoldersjob.cpp b/lib/jobs/setupkolabfoldersjob.cpp
index c30b43e..79bfb71 100644
--- a/lib/jobs/setupkolabfoldersjob.cpp
+++ b/lib/jobs/setupkolabfoldersjob.cpp
@@ -16,16 +16,16 @@
*/
#include "setupkolabfoldersjob.h"
+
#include <kimap/session.h>
-#include <kimap/createjob.h>
#include <kimap/selectjob.h>
-#include <kimap/setmetadatajob.h>
-#include <QStringList>
#include <errorhandler.h>
#include <kolabdefinitions.h>
#include <formathelpers.h>
+#include "createkolabfolderjob.h"
+
SetupKolabFoldersJob::SetupKolabFoldersJob(const QStringList &serverCapabilities, QString rootFolder, KIMAP::Session* session, QObject* parent)
: KJob(parent),
m_session(session),
@@ -53,7 +53,7 @@ void SetupKolabFoldersJob::start()
connect(selectJob, SIGNAL(result(KJob*)), this, SLOT(onSelectDone(KJob*)));
selectJob->start();
} else {
- createMailbox();
+ createNext();
}
}
@@ -65,7 +65,7 @@ void SetupKolabFoldersJob::onSelectDone(KJob *job)
emitResult();
return;
}
- createMailbox();
+ createNext();
}
static QString getFolderName(Kolab::FolderType type)
@@ -78,68 +78,53 @@ static Kolab::FolderType getFolderType(const QString &typeString)
return Kolab::folderTypeFromString(typeString.toStdString());
}
-void SetupKolabFoldersJob::createMailbox()
+void SetupKolabFoldersJob::createNext()
{
if (m_folderTypes.isEmpty()) {
emitResult();
return;
}
- m_currentFolderType = m_folderTypes.takeFirst();
- Kolab::FolderType folderType = getFolderType(m_currentFolderType);
+ createMailbox(m_folderTypes.takeFirst());
+}
+
+void SetupKolabFoldersJob::createMailbox(const QString &currentFolderType)
+{
+ const Kolab::FolderType folderType = getFolderType(currentFolderType);
if (folderType == Kolab::MailType) {
- Warning() << "unknown kolab type: " << m_currentFolderType;
+ Warning() << "unknown kolab type: " << currentFolderType;
setError(KJob::UserDefinedError);
emitResult();
return;
}
- KIMAP::CreateJob *createJob = new KIMAP::CreateJob(m_session);
- createJob->setMailBox(getFolderName(folderType));
+ const QString name = getFolderName(folderType);
+ const QByteArray privateAnnotation = QString::fromStdString(Kolab::folderAnnotation(folderType, true)).toLatin1();
+ const QByteArray sharedAnnotation = QString::fromStdString(Kolab::folderAnnotation(folderType, false)).toLatin1();
+
+ m_createdFolders.insert(currentFolderType, name);
+
+ CreateKolabFolderJob *createJob = new CreateKolabFolderJob(name,
+ sharedAnnotation,
+ privateAnnotation,
+ CreateKolabFolderJob::capablitiesFromString(m_serverCapabilities),
+ m_session,
+ this
+ );
connect(createJob, SIGNAL(result(KJob*)), this, SLOT(onCreateDone(KJob*)));
createJob->start();
}
void SetupKolabFoldersJob::onCreateDone(KJob *job)
{
- QString mailbox;
if (job->error()) {
- Warning() << job->errorString() << "Trying to fix the metadata";
- mailbox = getFolderName(getFolderType(m_currentFolderType));
+ Warning() << job->errorString() << "Failed to create folder";
} else {
- KIMAP::CreateJob *createJob = static_cast<KIMAP::CreateJob*>(job);
- mailbox = createJob->mailBox();
- Debug() << "Created folder " << m_rootFolder << createJob->mailBox();
+ CreateKolabFolderJob *createJob = static_cast<CreateKolabFolderJob*>(job);
+ Debug() << "Created folder " << m_rootFolder << createJob->folder();
}
- m_createdFolders.insert(m_currentFolderType, mailbox);
-
- KIMAP::SetMetaDataJob *setMetadataJob = new KIMAP::SetMetaDataJob(m_session);
- setMetadataJob->setMailBox(mailbox);
- Kolab::FolderType folderType = Kolab::folderTypeFromString(m_currentFolderType.toStdString());
- if ( m_serverCapabilities.contains( "METADATA" ) ) {
- setMetadataJob->setServerCapability( KIMAP::MetaDataJobBase::Metadata );
- setMetadataJob->addMetaData("/shared" KOLAB_FOLDER_TYPE_ANNOTATION, QString::fromStdString(Kolab::folderAnnotation(folderType, false)).toLatin1() );
- } else {
- setMetadataJob->setServerCapability( KIMAP::MetaDataJobBase::Annotatemore );
- setMetadataJob->setEntry( KOLAB_FOLDER_TYPE_ANNOTATION );
- setMetadataJob->addMetaData( "value.shared", QString::fromStdString(Kolab::folderAnnotation(folderType, false)).toLatin1() );
- }
- //TODO also set the private annotation with the .default suffix
- connect(setMetadataJob, SIGNAL(result(KJob*)), this, SLOT(onMetadataSetDone(KJob*)));
- setMetadataJob->start();
-}
-
-void SetupKolabFoldersJob::onMetadataSetDone(KJob *job)
-{
- if ( job->error() ) {
- Warning() << job->errorString();
- setErrorText("Failed to create the folder for type: " + m_currentFolderType);
- setError(KJob::UserDefinedError);
- }
- createMailbox();
+ createNext();
}
QMap< QString, QString > SetupKolabFoldersJob::createdFolders() const
{
return m_createdFolders;
}
-
-
diff --git a/lib/jobs/setupkolabfoldersjob.h b/lib/jobs/setupkolabfoldersjob.h
index 2062d38..8dfd3d3 100644
--- a/lib/jobs/setupkolabfoldersjob.h
+++ b/lib/jobs/setupkolabfoldersjob.h
@@ -42,12 +42,12 @@ public:
private slots:
void onSelectDone(KJob*);
void onCreateDone(KJob*);
- void onMetadataSetDone(KJob*);
+
private:
- void createMailbox();
+ void createNext();
+ void createMailbox(const QString &folderType);
KIMAP::Session *m_session;
QStringList m_folderTypes;
- QString m_currentFolderType;
QString m_rootFolder;
QStringList m_serverCapabilities;
QMap<QString, QString> m_createdFolders;
diff --git a/lib/kolabaccount.cpp b/lib/kolabaccount.cpp
index 29cb6d0..a0b616c 100644
--- a/lib/kolabaccount.cpp
+++ b/lib/kolabaccount.cpp
@@ -19,6 +19,7 @@
#include "sessionfactory.h"
#include "jobs/setupkolabfoldersjob.h"
#include "jobs/fetchmessagesjob.h"
+#include "jobs/createkolabfolderjob.h"
#include <kimap/session.h>
#include <kimap/logoutjob.h>
#include <kimap/appendjob.h>
@@ -325,31 +326,13 @@ void KolabAccount::createFolder(const QString &name, const QByteArray &annotatio
Debug() << "creating folder: " << name << annotation;
return;
}
-
- KIMAP::CreateJob *createJob = new KIMAP::CreateJob(mSession);
- createJob->setMailBox(name);
+ CreateKolabFolderJob *createJob = new CreateKolabFolderJob(name, annotation, QByteArray(), CreateKolabFolderJob::capablitiesFromString(mCapabilities), mSession, this);
createJob->exec();
- Debug() << "created folder: " << name;
if (createJob->error()) {
Error() << createJob->errorString();
return;
}
-
- KIMAP::SetMetaDataJob *setMetadataJob = new KIMAP::SetMetaDataJob(mSession);
- setMetadataJob->setMailBox(createJob->mailBox());
- if ( mCapabilities.contains( "METADATA" ) ) {
- setMetadataJob->setServerCapability( KIMAP::MetaDataJobBase::Metadata );
- setMetadataJob->addMetaData( "/shared" KOLAB_FOLDER_TYPE_ANNOTATION, annotation );
- } else {
- setMetadataJob->setServerCapability( KIMAP::MetaDataJobBase::Annotatemore );
- setMetadataJob->setEntry( KOLAB_FOLDER_TYPE_ANNOTATION );
- setMetadataJob->addMetaData( "value.shared", annotation );
- }
- setMetadataJob->exec();
- if (setMetadataJob->error()) {
- Error() << setMetadataJob->errorString();
- }
-
+ Debug() << "created folder: " << name;
mFolders.append(name);
}
@@ -378,7 +361,6 @@ void KolabAccount::setupFolders()
KIMAP::SelectJob *selectJob = new KIMAP::SelectJob(mSession);
selectJob->setMailBox(QString());
//TODO internationalize folder names
- //TODO make part of setupkolabfoldersjob after adding types to folderTypeFromString in formathelpers.cpp
//TODO the suffixes should go in the private namespace
createFolder("Drafts", KOLAB_FOLDER_TYPE_MAIL KOLAB_FOLDER_TYPE_DRAFT_SUFFIX);
createFolder("Sent", KOLAB_FOLDER_TYPE_MAIL KOLAB_FOLDER_TYPE_SENT_SUFFIX);