Commit 4af112b9 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Remove duplicate code

parent ad2b984f
...@@ -260,7 +260,8 @@ void NewMailNotifierAgent::showNotifications() ...@@ -260,7 +260,8 @@ void NewMailNotifierAgent::showNotifications()
} }
} }
if (numberOfEmail == 1) { if (numberOfEmail == 1) {
new SpecialNotifierJob(item, this); SpecialNotifierJob *job = new SpecialNotifierJob(item, this);
connect(job, SIGNAL(displayNotification(QPixmap,QString)), SLOT(slotDisplayNotification(QPixmap,QString)));
mNewMails.clear(); mNewMails.clear();
return; return;
} else { } else {
...@@ -272,16 +273,20 @@ void NewMailNotifierAgent::showNotifications() ...@@ -272,16 +273,20 @@ void NewMailNotifierAgent::showNotifications()
kDebug() << message; kDebug() << message;
Util::showNotification(Util::defaultPixmap(), message); slotDisplayNotification(Util::defaultPixmap(), message);
if ( mBeepOnNewMails ) {
KNotification::beep();
}
mNewMails.clear(); mNewMails.clear();
} }
void NewMailNotifierAgent::slotDisplayNotification(const QPixmap &pixmap, const QString &message)
{
Util::showNotification(pixmap, message);
if ( mBeepOnNewMails ) {
KNotification::beep();
}
}
void NewMailNotifierAgent::slotInstanceStatusChanged(const Akonadi::AgentInstance &instance) void NewMailNotifierAgent::slotInstanceStatusChanged(const Akonadi::AgentInstance &instance)
{ {
......
...@@ -60,6 +60,7 @@ private slots: ...@@ -60,6 +60,7 @@ private slots:
void configure(WId windowId); void configure(WId windowId);
void slotInstanceStatusChanged(const Akonadi::AgentInstance &instance); void slotInstanceStatusChanged(const Akonadi::AgentInstance &instance);
void slotInstanceRemoved(const Akonadi::AgentInstance &instance); void slotInstanceRemoved(const Akonadi::AgentInstance &instance);
void slotDisplayNotification(const QPixmap &pixmap, const QString &message);
private: private:
void clearAll(); void clearAll();
......
...@@ -53,7 +53,7 @@ void SpecialNotifierJob::slotItemFetchJobDone(KJob *job) ...@@ -53,7 +53,7 @@ void SpecialNotifierJob::slotItemFetchJobDone(KJob *job)
return; return;
} }
Akonadi::Item::List lst = qobject_cast<Akonadi::ItemFetchJob*>( job )->items(); const Akonadi::Item::List lst = qobject_cast<Akonadi::ItemFetchJob*>( job )->items();
if (lst.count() == 1) { if (lst.count() == 1) {
Akonadi::Item item = lst.first(); Akonadi::Item item = lst.first();
if ( !item.hasPayload<KMime::Message::Ptr>() ) { if ( !item.hasPayload<KMime::Message::Ptr>() ) {
...@@ -79,7 +79,7 @@ void SpecialNotifierJob::slotSearchJobFinished( KJob *job ) ...@@ -79,7 +79,7 @@ void SpecialNotifierJob::slotSearchJobFinished( KJob *job )
const Akonadi::ContactSearchJob *searchJob = qobject_cast<Akonadi::ContactSearchJob*>( job ); const Akonadi::ContactSearchJob *searchJob = qobject_cast<Akonadi::ContactSearchJob*>( job );
if ( searchJob->error() ) { if ( searchJob->error() ) {
kWarning() << "Unable to fetch contact:" << searchJob->errorText(); kWarning() << "Unable to fetch contact:" << searchJob->errorText();
Util::showNotification(Util::defaultPixmap(), i18n("from: %1 \nSubject: %2",mFrom, mSubject)); emit displayNotification(Util::defaultPixmap(), i18n("from: %1 \nSubject: %2",mFrom, mSubject));
deleteLater(); deleteLater();
return; return;
} }
...@@ -87,9 +87,9 @@ void SpecialNotifierJob::slotSearchJobFinished( KJob *job ) ...@@ -87,9 +87,9 @@ void SpecialNotifierJob::slotSearchJobFinished( KJob *job )
const KABC::Addressee addressee = searchJob->contacts().first(); const KABC::Addressee addressee = searchJob->contacts().first();
const KABC::Picture photo = addressee.photo(); const KABC::Picture photo = addressee.photo();
const QImage image = photo.data(); const QImage image = photo.data();
Util::showNotification(QPixmap::fromImage(image), i18n("from: %1 \nSubject: %2",mFrom, mSubject)); emit displayNotification(QPixmap::fromImage(image), i18n("from: %1 \nSubject: %2",mFrom, mSubject));
} else { } else {
Util::showNotification(Util::defaultPixmap(), i18n("from: %1 \nSubject: %2",mFrom, mSubject)); emit displayNotification(Util::defaultPixmap(), i18n("from: %1 \nSubject: %2",mFrom, mSubject));
} }
deleteLater(); deleteLater();
} }
......
...@@ -30,6 +30,9 @@ public: ...@@ -30,6 +30,9 @@ public:
explicit SpecialNotifierJob(Akonadi::Item::Id id, QObject *parent = 0); explicit SpecialNotifierJob(Akonadi::Item::Id id, QObject *parent = 0);
~SpecialNotifierJob(); ~SpecialNotifierJob();
Q_SIGNALS:
void displayNotification(const QPixmap &pixmap, const QString &message);
private Q_SLOTS: private Q_SLOTS:
void slotSearchJobFinished( KJob *job ); void slotSearchJobFinished( KJob *job );
void slotItemFetchJobDone(KJob*); void slotItemFetchJobDone(KJob*);
......
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