Commit 747fac94 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Improve special notifier job

parent 8d3e467f
......@@ -25,6 +25,9 @@ target_link_libraries( akonadi_newmailnotifier_agent
${QT_QTCORE_LIBRARY}
${QT_QTDBUS_LIBRARY}
${KDE4_KNOTIFYCONFIG_LIBS}
${KDEPIMLIBS_KABC_LIBS}
${KDEPIMLIBS_KPIMUTILS_LIBS}
${KDEPIMLIBS_AKONADI_CONTACT_LIBS}
)
......
......@@ -23,6 +23,9 @@
#include <akonadi/kmime/messageparts.h>
#include <KNotification>
#include <KPIMUtils/Email>
#include <KMime/Message>
SpecialNotifierJob::SpecialNotifierJob(Akonadi::Item::Id id, QObject *parent)
: QObject(parent)
......@@ -31,7 +34,7 @@ SpecialNotifierJob::SpecialNotifierJob(Akonadi::Item::Id id, QObject *parent)
Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob( item, this );
job->fetchScope().fetchPayloadPart( Akonadi::MessagePart::Envelope, true );
connect( job, SIGNAL(result(KJob*)), SLOT(itemFetchJobDone(KJob*)) );
connect( job, SIGNAL(result(KJob*)), SLOT(slotItemFetchJobDone(KJob*)) );
}
SpecialNotifierJob::~SpecialNotifierJob()
......@@ -39,13 +42,46 @@ SpecialNotifierJob::~SpecialNotifierJob()
}
void SpecialNotifierJob::slotItemFetchJobDone(KJob*)
void SpecialNotifierJob::slotItemFetchJobDone(KJob *job)
{
//TODO
if ( job->error() ) {
kWarning() << job->errorString();
deleteLater();
return;
}
Akonadi::Item::List lst = qobject_cast<Akonadi::ItemFetchJob*>( job )->items();
if (lst.count() == 1) {
Akonadi::Item item = lst.first();
if ( !item.hasPayload<KMime::Message::Ptr>() ) {
deleteLater();
return;
}
const KMime::Message::Ptr mb = item.payload<KMime::Message::Ptr>();
mFrom = mb->from()->asUnicodeString();
mSubject = mb->subject()->asUnicodeString();
Akonadi::ContactSearchJob *job = new Akonadi::ContactSearchJob( this );
job->setLimit( 1 );
job->setQuery( Akonadi::ContactSearchJob::Email, KPIMUtils::firstEmailAddress(mFrom).toLower(), Akonadi::ContactSearchJob::ExactMatch );
connect( job, SIGNAL(result(KJob*)), SLOT(slotDelayedSelectFromAddressbook(KJob*)) );
} else {
deleteLater();
return;
}
}
void SpecialNotifierJob::slotSearchJobFinished( KJob *job )
{
const Akonadi::ContactSearchJob *searchJob = qobject_cast<Akonadi::ContactSearchJob*>( job );
if ( searchJob->error() ) {
kWarning() << "Unable to fetch contact:" << searchJob->errorText();
//TODO
return;
}
const KABC::Addressee addressee = searchJob->contacts().first();
const KABC::Picture photo = addressee.photo();
QImage image = photo.data();
//TODO
}
......
......@@ -33,6 +33,10 @@ public:
private Q_SLOTS:
void slotSearchJobFinished( KJob *job );
void slotItemFetchJobDone(KJob*);
private:
QString mSubject;
QString mFrom;
};
#endif // SPECIALNOTIFIERJOB_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