Commit e4cf8473 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Exclude notification when emails is send by receiver

parent fd59a7e2
......@@ -35,6 +35,7 @@ target_link_libraries( akonadi_newmailnotifier_agent
${KDEPIMLIBS_KABC_LIBS}
${KDEPIMLIBS_KPIMUTILS_LIBS}
${KDEPIMLIBS_AKONADI_CONTACT_LIBS}
${KDEPIMLIBS_KPIMIDENTITIES_LIBS}
)
......
......@@ -2,4 +2,3 @@ for 4.12:
---------
- Look at https://github.com/shellscape/Gmail-Notifier-Plus/tree/master/Promotional for idea
- Show if we can display full collection path (for the moment we can't)
- suggestion: don't notify if the "from" is us
......@@ -29,6 +29,8 @@
#include "newmailnotifieragentsettings.h"
#include "newmailnotifiersettingsdialog.h"
#include <KPIMIdentities/IdentityManager>
#include <akonadi/dbusconnectionpool.h>
#include <akonadi/agentfactory.h>
......@@ -60,6 +62,10 @@ NewMailNotifierAgent::NewMailNotifierAgent( const QString &id )
Akonadi::AttributeFactory::registerAttribute<NewMailNotifierAttribute>();
new NewMailNotifierAdaptor( this );
mIdentityManager = new KPIMIdentities::IdentityManager( false, this );
connect(mIdentityManager, SIGNAL(changed()), SLOT(slotIdentitiesChanged()));
slotIdentitiesChanged();
DBusConnectionPool::threadConnection().registerObject( QLatin1String( "/NewMailNotifierAgent" ),
this, QDBusConnection::ExportAdaptors );
DBusConnectionPool::threadConnection().registerService( QLatin1String( "org.freedesktop.Akonadi.NewMailNotifierAgent" ) );
......@@ -86,6 +92,11 @@ NewMailNotifierAgent::NewMailNotifierAgent( const QString &id )
}
}
void NewMailNotifierAgent::slotIdentitiesChanged()
{
mListEmails = mIdentityManager->allEmails();
}
void NewMailNotifierAgent::doSetOnline(bool online)
{
if (!online) {
......@@ -355,7 +366,7 @@ void NewMailNotifierAgent::slotShowNotifications()
texts.append( i18np( "One new email in %2", "%1 new emails in %2", it.value().count(), displayName ) );
}
if (hasUniqMessage) {
SpecialNotifierJob *job = new SpecialNotifierJob(currentPath, item, this);
SpecialNotifierJob *job = new SpecialNotifierJob(mListEmails, currentPath, item, this);
connect(job, SIGNAL(displayNotification(QPixmap,QString)), SLOT(slotDisplayNotification(QPixmap,QString)));
mNewMails.clear();
return;
......
......@@ -32,6 +32,10 @@ namespace Akonadi {
class AgentInstance;
}
namespace KPIMIdentities {
class IdentityManager;
}
class NewMailNotifierAgent : public Akonadi::AgentBase, public Akonadi::AgentBase::ObserverV2
{
Q_OBJECT
......@@ -81,14 +85,17 @@ private slots:
void slotInstanceStatusChanged(const Akonadi::AgentInstance &instance);
void slotInstanceRemoved(const Akonadi::AgentInstance &instance);
void slotDisplayNotification(const QPixmap &pixmap, const QString &message);
void slotIdentitiesChanged();
private:
bool isActive() const;
void clearAll();
bool excludeSpecialCollection(const Akonadi::Collection &collection) const;
QStringList mListEmails;
QHash<Akonadi::Collection, QList<Akonadi::Item::Id> > mNewMails;
QTimer mTimer;
QStringList mInstanceNameInProgress;
KPIMIdentities::IdentityManager *mIdentityManager;
};
#endif
......@@ -33,8 +33,9 @@
#include <QTextDocument>
SpecialNotifierJob::SpecialNotifierJob(const QString &path, Akonadi::Item::Id id, QObject *parent)
SpecialNotifierJob::SpecialNotifierJob(const QStringList &listEmails, const QString &path, Akonadi::Item::Id id, QObject *parent)
: QObject(parent),
mListEmails(listEmails),
mPath(path)
{
Akonadi::Item item(id);
......@@ -111,6 +112,15 @@ void SpecialNotifierJob::slotSearchJobFinished( KJob *job )
void SpecialNotifierJob::emitNotification(const QPixmap &pixmap)
{
if (NewMailNotifierAgentSettings::excludeEmailsFromMe()) {
Q_FOREACH( const QString &email, mListEmails) {
if (mFrom.contains(email)) {
//Exclude this notification
return;
}
}
}
QStringList result;
if (NewMailNotifierAgentSettings::showFrom()) {
result << i18n("From: %1", Qt::escape(mFrom));
......
......@@ -21,13 +21,14 @@
#include <QObject>
#include <Akonadi/Item>
#include <QStringList>
class KJob;
class SpecialNotifierJob : public QObject
{
Q_OBJECT
public:
explicit SpecialNotifierJob(const QString &path, Akonadi::Item::Id id, QObject *parent = 0);
explicit SpecialNotifierJob(const QStringList &listEmails, const QString &path, Akonadi::Item::Id id, QObject *parent = 0);
~SpecialNotifierJob();
Q_SIGNALS:
......@@ -39,6 +40,7 @@ private Q_SLOTS:
private:
void emitNotification(const QPixmap &pixmap);
QStringList mListEmails;
QString mSubject;
QString mFrom;
QString mPath;
......
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