Commit 2ebf5587 authored by Laurent Montel's avatar Laurent Montel 😁

Add job to create followupreminder on existing message

parent 98d76d37
......@@ -156,6 +156,7 @@ if (KDEPIM_BUILD_DESKTOP)
job/createtaskjob.cpp
job/savedraftjob.cpp
job/removeduplicatemailjob.cpp
job/createfollowupreminderonexistingmessagejob.cpp
)
set(kmailprivate_widgets_LIB_SRCS
......
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "createfollowupreminderonexistingmessagejob.h"
#include <akonadi/itemfetchjob.h>
#include <Akonadi/ItemFetchScope>
#include <KMime/Message>
CreateFollowupReminderOnExistingMessageJob::CreateFollowupReminderOnExistingMessageJob(QObject *parent)
: QObject(parent)
{
}
CreateFollowupReminderOnExistingMessageJob::~CreateFollowupReminderOnExistingMessageJob()
{
}
void CreateFollowupReminderOnExistingMessageJob::start()
{
if (canStart()) {
doStart();
} else {
qDebug()<<" job can not started";
deleteLater();
}
}
void CreateFollowupReminderOnExistingMessageJob::doStart()
{
Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob( mMessageItem , this );
job->fetchScope().fetchFullPayload( true );
connect( job, SIGNAL(result(KJob*)), SLOT(itemFetchJobDone(KJob*)) );
}
void CreateFollowupReminderOnExistingMessageJob::itemFetchJobDone(KJob* job)
{
Akonadi::ItemFetchJob *fetchJob = qobject_cast<Akonadi::ItemFetchJob *>(job);
if ( fetchJob->items().count() == 1 ) {
mMessageItem = fetchJob->items().first();
} else {
qDebug()<<" CreateFollowupReminderOnExistingMessageJob Error during fetch: "<<job->errorString();
deleteLater();
return;
}
if ( !mMessageItem.hasPayload<KMime::Message::Ptr>() ) {
qDebug()<<" item has not payload";
deleteLater();
return;
}
KMime::Message::Ptr msg = mMessageItem.payload<KMime::Message::Ptr>();
//TODO create followupreminderjob
}
Akonadi::Collection CreateFollowupReminderOnExistingMessageJob::collection() const
{
return mCollection;
}
void CreateFollowupReminderOnExistingMessageJob::setCollection(const Akonadi::Collection &collection)
{
mCollection = collection;
}
QDate CreateFollowupReminderOnExistingMessageJob::date() const
{
return mDate;
}
void CreateFollowupReminderOnExistingMessageJob::setDate(const QDate &date)
{
mDate = date;
}
Akonadi::Item CreateFollowupReminderOnExistingMessageJob::messageItem() const
{
return mMessageItem;
}
void CreateFollowupReminderOnExistingMessageJob::setMessageItem(const Akonadi::Item &messageItem)
{
mMessageItem = messageItem;
}
bool CreateFollowupReminderOnExistingMessageJob::canStart() const
{
return mMessageItem.isValid() && mCollection.isValid() && mDate.isValid();
}
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef CREATEFOLLOWUPREMINDERONEXISTINGMESSAGEJOB_H
#define CREATEFOLLOWUPREMINDERONEXISTINGMESSAGEJOB_H
#include <QObject>
#include <Akonadi/Collection>
#include <QDate>
#include <akonadi/item.h>
class CreateFollowupReminderOnExistingMessageJob : public QObject
{
Q_OBJECT
public:
explicit CreateFollowupReminderOnExistingMessageJob(QObject *parent=0);
~CreateFollowupReminderOnExistingMessageJob();
void start();
Akonadi::Collection collection() const;
void setCollection(const Akonadi::Collection &collection);
QDate date() const;
void setDate(const QDate &date);
Akonadi::Item messageItem() const;
void setMessageItem(const Akonadi::Item &messageItem);
bool canStart() const;
private Q_SLOTS:
void itemFetchJobDone(KJob *job);
private:
void doStart();
Akonadi::Collection mCollection;
Akonadi::Item mMessageItem;
QDate mDate;
};
#endif // CREATEFOLLOWUPREMINDERONEXISTINGMESSAGEJOB_H
......@@ -32,3 +32,8 @@ set( kmail_statusbarlabeltoggledstate_source statusbarlabeltoggledstatetest.cpp
kde4_add_unit_test( statusbarlabeltoggledstatetest ${kmail_statusbarlabeltoggledstate_source})
target_link_libraries( statusbarlabeltoggledstatetest ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS})
set( kmail_createfollowupreminderonexistingmessagejobtest_source createfollowupreminderonexistingmessagejobtest.cpp ../job/createfollowupreminderonexistingmessagejob.cpp )
kde4_add_unit_test( createfollowupreminderonexistingmessagejobtest ${kmail_createfollowupreminderonexistingmessagejobtest_source})
target_link_libraries( createfollowupreminderonexistingmessagejobtest ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS} ${KDEPIMLIBS_AKONADI_LIBS})
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "createfollowupreminderonexistingmessagejobtest.h"
#include "../job/createfollowupreminderonexistingmessagejob.h"
#include <qtest_kde.h>
CreateFollowupReminderOnExistingMessageJobTest::CreateFollowupReminderOnExistingMessageJobTest(QObject *parent)
: QObject(parent)
{
}
CreateFollowupReminderOnExistingMessageJobTest::~CreateFollowupReminderOnExistingMessageJobTest()
{
}
void CreateFollowupReminderOnExistingMessageJobTest::shouldHaveDefaultValue()
{
CreateFollowupReminderOnExistingMessageJob job;
QVERIFY(!job.date().isValid());
QVERIFY(!job.messageItem().isValid());
QVERIFY(!job.collection().isValid());
}
void CreateFollowupReminderOnExistingMessageJobTest::shouldValidBeforeStartJob()
{
CreateFollowupReminderOnExistingMessageJob job;
QVERIFY(!job.canStart());
job.setDate(QDate::currentDate());
QVERIFY(!job.canStart());
Akonadi::Item item(42);
job.setMessageItem(item);
QVERIFY(!job.canStart());
Akonadi::Collection col(42);
job.setCollection(col);
QVERIFY(job.canStart());
}
QTEST_KDEMAIN(CreateFollowupReminderOnExistingMessageJobTest, NoGUI)
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
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
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef CREATEFOLLOWUPREMINDERONEXISTINGMESSAGEJOBTEST_H
#define CREATEFOLLOWUPREMINDERONEXISTINGMESSAGEJOBTEST_H
#include <QObject>
class CreateFollowupReminderOnExistingMessageJobTest : public QObject
{
Q_OBJECT
public:
explicit CreateFollowupReminderOnExistingMessageJobTest(QObject *parent=0);
~CreateFollowupReminderOnExistingMessageJobTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldValidBeforeStartJob();
};
#endif // CREATEFOLLOWUPREMINDERONEXISTINGMESSAGEJOBTEST_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment