summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSandro Knauß <mail@sandroknauss.de>2014-05-29 16:50:48 (GMT)
committerSandro Knauß <mail@sandroknauss.de>2014-05-29 16:53:07 (GMT)
commite64fa00c29f74eb23a5f5bbfe86269759a322ad6 (patch)
tree18f37e9103dc914933e4fc04ebf360823ed2fa3f
parent8ec8758e3a2d5c59d1adae4b0f5335a1b2f838ca (diff)
downloadkolab-utils-e64fa00c29f74eb23a5f5bbfe86269759a322ad6.tar.gz
Added support for not storing fbobject at imap server.
-rw-r--r--fbdaemon/fbcoordinator.cpp4
-rw-r--r--fbdaemon/fbgeneratorjob.cpp86
-rw-r--r--fbdaemon/fbgeneratorjob.h17
3 files changed, 76 insertions, 31 deletions
diff --git a/fbdaemon/fbcoordinator.cpp b/fbdaemon/fbcoordinator.cpp
index 2da2bfa..5d4d34d 100644
--- a/fbdaemon/fbcoordinator.cpp
+++ b/fbdaemon/fbcoordinator.cpp
@@ -127,7 +127,7 @@ void FBCoordinator::generateAllForUser(const QString& user)
SequentialCompositeJob *userJob = new SequentialCompositeJob(true, this);
SessionSettings settings = Settings::instance().getSessionSettings();
settings.userName = user;
- userJob->addSubjob(new FBGeneratorJob(settings, userJob));
+ userJob->addSubjob(new FBGeneratorJob(settings, true, userJob));
userJob->addSubjob(new FBAggregatorJob(settings, userJob));
connect(userJob, SIGNAL(result(KJob*)), this, SLOT(onGeneratorDone(KJob*)));
mUserTimer.start();
@@ -140,7 +140,7 @@ void FBCoordinator::generateForUser(const QString& user)
mTimer.start();
SessionSettings settings = Settings::instance().getSessionSettings();
settings.userName = user;
- FBGeneratorJob *generator = new FBGeneratorJob(settings, this);
+ FBGeneratorJob *generator = new FBGeneratorJob(settings, true, this);
connect(generator, SIGNAL(result(KJob*)), this, SLOT(onGeneratorDone(KJob*)));
generator->start();
}
diff --git a/fbdaemon/fbgeneratorjob.cpp b/fbdaemon/fbgeneratorjob.cpp
index 25afbe6..d2f0ed5 100644
--- a/fbdaemon/fbgeneratorjob.cpp
+++ b/fbdaemon/fbgeneratorjob.cpp
@@ -35,12 +35,13 @@
#include <kimap/logoutjob.h>
#include <kimap/expungejob.h>
-
-FBGeneratorJob::FBGeneratorJob(const SessionSettings &settings, QObject* parent)
-: KolabJob(settings, parent),
- mOldImapUid(-1)
+FBGeneratorJob::FBGeneratorJob(const SessionSettings &settings, bool store, QObject* parent)
+ : KolabJob(settings, parent),
+ mOldImapUid(-1),
+ mStore(store)
{
-
+ mStartOfTimeFrame = KDateTime::currentUtcDateTime();
+ mEndOfTimeFrame = mStartOfTimeFrame.addDays(Settings::instance().getTimeframe());
}
QStringList FBGeneratorJob::requiredFolders()
@@ -48,6 +49,12 @@ QStringList FBGeneratorJob::requiredFolders()
return QStringList() << KOLAB_FOLDER_TYPE_FREEBUSY;
}
+void FBGeneratorJob::startGenerateFBJob()
+{
+ GenerateFBJob *fbJob = new GenerateFBJob(mEventFolders, mStartOfTimeFrame, mEndOfTimeFrame, mSession, this);
+ QObject::connect(fbJob, SIGNAL(result(KJob*)), this, SLOT(onGenerateFBDone(KJob*)));
+ fbJob->start();
+}
void FBGeneratorJob::startWork()
{
@@ -65,9 +72,13 @@ void FBGeneratorJob::startWork()
return;
}
- FetchMessagesJob *fetchJob = new FetchMessagesJob(mFreebusyFolder, mSession, this);
- connect( fetchJob, SIGNAL(result(KJob*)), this, SLOT(onFetchFBDone(KJob*)) );
- fetchJob->start();
+ if (mStore) {
+ FetchMessagesJob *fetchJob = new FetchMessagesJob(mFreebusyFolder, mSession, this);
+ connect(fetchJob, SIGNAL(result(KJob*)), this, SLOT(onFetchFBDone(KJob*)));
+ fetchJob->start();
+ } else {
+ startGenerateFBJob();
+ }
}
@@ -87,8 +98,6 @@ void FBGeneratorJob::onFetchFBDone(KJob *job)
kDebug() << "existing fb object " << msg->subject()->asUnicodeString();
}
- KDateTime startOfTimeFrame = KDateTime::currentUtcDateTime();
- const KDateTime endOfTimeFrame = startOfTimeFrame.addDays(Settings::instance().getTimeframe());
int threshold = Settings::instance().getThreshold();
/*
@@ -110,13 +119,13 @@ void FBGeneratorJob::onFetchFBDone(KJob *job)
const KDateTime start = Kolab::Conversion::toDate(oldFB.start());
const KDateTime end = Kolab::Conversion::toDate(oldFB.end());
- qDebug() << startOfTimeFrame << start << endOfTimeFrame << end << threshold;
- if (!(startOfTimeFrame < start || endOfTimeFrame > end.addDays(threshold))) {
+ qDebug() << mStartOfTimeFrame << start << mEndOfTimeFrame << end << threshold;
+ if (!(mStartOfTimeFrame < start || mEndOfTimeFrame > end.addDays(threshold))) {
qDebug() << "within threshold, skipping";
// upToDate = true;
continue;
}
-
+
if (mOldImapUid < 0) {
mOldImapUid = fetchJob->getImapUid(msg);
mOldFlags = fetchJob->getFlags(msg);
@@ -138,9 +147,7 @@ void FBGeneratorJob::onFetchFBDone(KJob *job)
*/
// kDebug() << mEventFolder;
- GenerateFBJob *fbJob = new GenerateFBJob(mEventFolders, startOfTimeFrame, endOfTimeFrame, mSession, this);
- QObject::connect(fbJob, SIGNAL(result(KJob*)), this, SLOT(onGenerateFBDone(KJob*)));
- fbJob->start();
+ startGenerateFBJob();
}
void FBGeneratorJob::onGenerateFBDone(KJob *job)
@@ -153,24 +160,37 @@ void FBGeneratorJob::onGenerateFBDone(KJob *job)
GenerateFBJob *fbJob = qobject_cast<GenerateFBJob*>( job );
Q_ASSERT(fbJob);
- Kolab::Freebusy fb = fbJob->getFreebusy();
- if (!fb.isValid()) {
- Debug() << "did not generate a fb object";
- //TODO generate empty fb object to mark time as free
- logout();
- return;
- }
+ mFreebusy = fbJob->getFreebusy();
+
const Kolab::ContactReference org(Kolab::ContactReference::EmailReference, Kolab::Conversion::toStdString(mSessionSettings.userName));
- fb.setOrganizer(org);
- if (!fb.organizer().isValid()) {
-// fb.setOrganizer(/*mUserName, mUserName+QLatin1Char('@')+mHostName.remove("imap.")*/);
+ mFreebusy.setOrganizer(org);
+
+ if (!mFreebusy.organizer().isValid()) {
+// mFreebusy.setOrganizer(/*mUserName, mUserName+QLatin1Char('@')+mHostName.remove("imap.")*/);
Warning() << "no valid organizer";
setError(KJob::UserDefinedError);
logout();
return;
}
- KMime::Message::Ptr message = Kolab::KolabObjectWriter::writeFreebusy(fb);
+ // We want only create the freebusy object and do not want to store it at the IMAP server
+ if (mStore) {
+ storeFBObject();
+ } else {
+ logout();
+ }
+}
+
+void FBGeneratorJob::storeFBObject()
+{
+ if (!mFreebusy.isValid()) {
+ Debug() << "did not generate a fb object";
+ //TODO generate empty fb object to mark time as free
+ logout();
+ return;
+ }
+
+ KMime::Message::Ptr message = Kolab::KolabObjectWriter::writeFreebusy(mFreebusy);
if (Kolab::ErrorHandler::instance().error() > Kolab::ErrorHandler::Debug) {
Warning() << "Error: " << Kolab::ErrorHandler::instance().errorMessage();
setError(KJob::UserDefinedError);
@@ -181,7 +201,7 @@ void FBGeneratorJob::onGenerateFBDone(KJob *job)
qint16 port;
message->appendHeader( new KMime::Headers::Generic( X_ORIGIN_HEADER, message.get(), Settings::instance().getServerUri(port).toUtf8(), "utf-8" ) );
message->assemble();
-
+
// kDebug() << message->encodedContent();
SequentialCompositeJob *seqJob = new SequentialCompositeJob(this);
seqJob->addSubjob(new MessageModifyJob(message, mFreebusyFolder, mOldFlags, mOldImapUid, mSession, this));
@@ -198,3 +218,13 @@ void FBGeneratorJob::onModDone(KJob *job)
logout();
}
+void FBGeneratorJob::setTimeFrame(const KDateTime &start, const KDateTime &end)
+{
+ mStartOfTimeFrame = start;
+ mEndOfTimeFrame = end;
+}
+
+Kolab::Freebusy FBGeneratorJob::getFreebusy()
+{
+ return mFreebusy;
+}
diff --git a/fbdaemon/fbgeneratorjob.h b/fbdaemon/fbgeneratorjob.h
index 47ee128..f730bfc 100644
--- a/fbdaemon/fbgeneratorjob.h
+++ b/fbdaemon/fbgeneratorjob.h
@@ -19,29 +19,44 @@
#ifndef FBGENERATORJOB_H
#define FBGENERATORJOB_H
#include <kjob.h>
+#include <kdatetime.h>
#include <kimap/session.h>
#include <kimap/fetchjob.h>
+#include <kolabfreebusy.h>
#include "kolabjob.h"
+class FBGeneratorTest;
+
class FBGeneratorJob: public KolabJob
{
Q_OBJECT
+ friend class FBGeneratorTest;
public:
- explicit FBGeneratorJob(const SessionSettings &settings, QObject* parent = 0);
+ explicit FBGeneratorJob(const SessionSettings &settings, bool store, QObject* parent = 0);
+
+ Kolab::Freebusy getFreebusy();
+ void setTimeFrame(const KDateTime&, const KDateTime&);
private Q_SLOTS:
void onFetchFBDone(KJob *job);
void onGenerateFBDone(KJob*);
void onModDone(KJob*);
protected:
virtual QStringList requiredFolders();
+ void startGenerateFBJob();
private:
virtual void startWork();
+ void storeFBObject();
QString mFreebusyFolder;
QStringList mEventFolders;
+ Kolab::Freebusy mFreebusy;
+ bool mStore;
qint64 mOldImapUid;
KIMAP::MessageFlags mOldFlags;
+
+ KDateTime mStartOfTimeFrame;
+ KDateTime mEndOfTimeFrame;
};
#endif // FBGENERATORJOB_H