Commit 35a7fa09 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

improve agent

parent c92af71c
......@@ -63,7 +63,7 @@ void FollowUpReminderInfo::setId(Akonadi::Item::Id value)
bool FollowUpReminderInfo::isValid() const
{
return (mId != -1 && !mMessageId.isEmpty() && mFollowUpReminderDate.isValid());
return (mId != -1 && !mMessageId.isEmpty() && mFollowUpReminderDate.isValid() && !mTo.isEmpty());
}
QString FollowUpReminderInfo::messageId() const
......@@ -76,6 +76,16 @@ void FollowUpReminderInfo::setMessageId(const QString &messageId)
mMessageId = messageId;
}
void FollowUpReminderInfo::setTo(const QString &to)
{
mTo = to;
}
QString FollowUpReminderInfo::to() const
{
return mTo;
}
QDateTime FollowUpReminderInfo::followUpReminderDate() const
{
return mFollowUpReminderDate;
......
......@@ -35,6 +35,9 @@ public:
QString messageId() const;
void setMessageId(const QString &messageId);
void setTo(const QString &to);
QString to() const;
QDateTime followUpReminderDate() const;
void setFollowUpReminderDate(const QDateTime &followUpReminderDate);
......@@ -45,6 +48,7 @@ private:
Akonadi::Item::Id mId;
QString mMessageId;
QDateTime mFollowUpReminderDate;
QString mTo;
};
#endif // FOLLOWUPREMINDERINFO_H
......@@ -17,6 +17,14 @@
#include "followupreminderjob.h"
#include <Akonadi/ItemFetchJob>
#include <Akonadi/ItemFetchScope>
#include <Akonadi/KMime/MessageParts>
#include <KMime/Message>
#include <KDebug>
FollowUpReminderJob::FollowUpReminderJob(QObject *parent)
: QObject(parent)
{
......@@ -29,10 +37,52 @@ FollowUpReminderJob::~FollowUpReminderJob()
void FollowUpReminderJob::start()
{
if (!mItem.isValid()) {
deleteLater();
return;
}
Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob(mItem);
job->fetchScope().fetchPayloadPart( Akonadi::MessagePart::Envelope, true );
job->fetchScope().setAncestorRetrieval( Akonadi::ItemFetchScope::Parent );
connect( job, SIGNAL(result(KJob*)), SLOT(slotItemFetchJobDone(KJob*)) );
}
void FollowUpReminderJob::setItem(const Akonadi::Item &item)
{
mItem = item;
}
void FollowUpReminderJob::slotItemFetchJobDone(KJob* job)
{
if ( job->error() ) {
kError() << "Error while fetching item. " << job->error() << job->errorString();
deleteLater();
return;
}
const Akonadi::ItemFetchJob *fetchJob = qobject_cast<Akonadi::ItemFetchJob*>( job );
const Akonadi::Item::List items = fetchJob->items();
if ( items.isEmpty() ) {
kError() << "Error while fetching item: item not found";
deleteLater();
return;
}
if ( !items.at(0).hasPayload<KMime::Message::Ptr>() ) {
kError() << "Item has not payload";
deleteLater();
return;
}
const KMime::Message::Ptr msg = items.at(0).payload<KMime::Message::Ptr>();
if (msg) {
KMime::Headers::MessageID *msgID = msg->messageID(false);
if (msgID) {
//FIXME It's not the messageID to look at!
const QString messageIdStr = msgID->asUnicodeString();
qDebug()<<" messageIdStr"<<messageIdStr;
Q_EMIT finished(messageIdStr);
}
}
deleteLater();
}
......@@ -36,6 +36,9 @@ public:
Q_SIGNALS:
void finished(const QString &messageId);
private slots:
void slotItemFetchJobDone(KJob *job);
private:
Akonadi::Item mItem;
};
......
......@@ -23,6 +23,8 @@
#include <KGlobal>
#include <KConfigGroup>
#include <KConfig>
#include <knotification.h>
#include <KLocalizedString>
FollowUpReminderManager::FollowUpReminderManager(QObject *parent)
: QObject(parent)
......@@ -75,9 +77,27 @@ void FollowUpReminderManager::checkFollowUp(const Akonadi::Item &item, const Ako
void FollowUpReminderManager::slotCheckFollowUpFinished(const QString &messageId)
{
Q_FOREACH(FollowUpReminderInfo* info, mFollowUpReminderInfoList) {
if (info->messageId() == messageId) {
answerReceived(info->to());
//TODO inform that we have a response!
}
}
//TODO
}
void FollowUpReminderManager::answerReceived(const QString &from)
{
const QPixmap pixmap = KIcon( QLatin1String("kmail") ).pixmap( KIconLoader::SizeSmall, KIconLoader::SizeSmall );
KNotification::event( QLatin1String("mailreceived"),
i18n("Answer from %1 received", from),
pixmap,
0,
KNotification::CloseOnTimeout,
KGlobal::mainComponent());
}
#include "followupremindermanager.moc"
......@@ -38,6 +38,7 @@ private slots:
void slotCheckFollowUpFinished(const QString &messageId);
private:
void answerReceived(const QString &from);
KSharedConfig::Ptr mConfig;
QList<FollowUpReminderInfo*> mFollowUpReminderInfoList;
QPointer<FollowUpReminderNoAnswerDialog> mNoAnswerDialog;
......
......@@ -29,19 +29,24 @@ void FollowUpReminderInfoTest::shouldHaveDefaultValue()
QCOMPARE(info.id(), Akonadi::Item::Id(-1));
QCOMPARE(info.messageId(), QString());
QCOMPARE(info.isValid(), false);
QCOMPARE(info.to(), QString());
}
void FollowUpReminderInfoTest::shoudBeNotValid()
{
FollowUpReminderInfo info;
//We need a Akonadi::Id valid and a messageId not empty and a valid date
//We need a Akonadi::Id valid and a messageId not empty and a valid date and a "To" not empty
info.setMessageId(QLatin1String("foo"));
QCOMPARE(info.isValid(), false);
QDate date(2014,1,1);
const QDate date(2014,1,1);
info.setFollowUpReminderDate(QDateTime(date));
QCOMPARE(info.isValid(), false);
const QString to = QLatin1String("kde.org");
info.setTo(to);
QCOMPARE(info.isValid(), false);
info.setId(Akonadi::Item::Id(42));
QCOMPARE(info.isValid(), true);
}
......
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