Commit 06f5807f authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Show notifier when all check is done

parent 5a9bda68
......@@ -49,7 +49,9 @@
using namespace Akonadi;
NewMailNotifierAgent::NewMailNotifierAgent( const QString &id )
: AgentBase( id ), mNotifierEnabled(true)
: AgentBase( id ),
mNotifierEnabled(true),
mCheckMailInProgress(false)
{
KGlobal::locale()->insertCatalog( "newmailnotifieragent" );
Akonadi::AttributeFactory::registerAttribute<NewMailNotifierAttribute>();
......@@ -94,11 +96,17 @@ void NewMailNotifierAgent::setEnableNotifier(bool b)
KConfigGroup group( KGlobal::config(), "General" );
group.writeEntry( "enabled", mNotifierEnabled);
if (!mNotifierEnabled) {
mNewMails.clear();
clearAll();
}
}
}
void NewMailNotifierAgent::clearAll()
{
mNewMails.clear();
mCheckMailInProgress = false;
mInstanceNameInProgress.clear();
}
bool NewMailNotifierAgent::enabledNotifier() const
{
......@@ -188,6 +196,13 @@ void NewMailNotifierAgent::showNotifications()
if (!mNotifierEnabled)
return;
if (mCheckMailInProgress) {
//Restart timer until all is done.
mTimer.start();
return;
}
QStringList texts;
QHash< Akonadi::Collection, QList<Akonadi::Item::Id> >::const_iterator end(mNewMails.constEnd());
for ( QHash< Akonadi::Collection, QList<Akonadi::Item::Id> >::const_iterator it = mNewMails.constBegin(); it != end; ++it ) {
......@@ -214,11 +229,30 @@ void NewMailNotifierAgent::showNotifications()
void NewMailNotifierAgent::slotInstanceStatusChanged(const Akonadi::AgentInstance &instance)
{
if (!mNotifierEnabled)
return;
const QString identifier(instance.identifier());
switch(instance.status()) {
case Akonadi::AgentInstance::Broken:
case Akonadi::AgentInstance::Idle:
{
if (mInstanceNameInProgress.contains(identifier)) {
mInstanceNameInProgress.removeAll(identifier);
if (mInstanceNameInProgress.isEmpty()) {
mCheckMailInProgress = false;
}
}
break;
}
case Akonadi::AgentInstance::Running:
case Akonadi::AgentInstance::Broken:
{
if (!mInstanceNameInProgress.contains(identifier)) {
mInstanceNameInProgress.append(identifier);
mCheckMailInProgress = true;
}
break;
}
case Akonadi::AgentInstance::NotConfigured:
break;
}
......@@ -226,7 +260,16 @@ void NewMailNotifierAgent::slotInstanceStatusChanged(const Akonadi::AgentInstanc
void NewMailNotifierAgent::slotInstanceRemoved(const Akonadi::AgentInstance &instance)
{
//TODO
if (!mNotifierEnabled)
return;
const QString identifier(instance.identifier());
if (mInstanceNameInProgress.contains(identifier)) {
mInstanceNameInProgress.removeAll(identifier);
if (mInstanceNameInProgress.isEmpty()) {
mCheckMailInProgress = false;
}
}
}
AKONADI_AGENT_MAIN( NewMailNotifierAgent )
......
......@@ -25,7 +25,8 @@
#include <akonadi/collection.h> // make sure this is included before QHash, otherwise it wont find the correct qHash implementation for some reason
#include <akonadi/agentbase.h>
#include <QtCore/QTimer>
#include <QTimer>
#include <QStringList>
namespace Akonadi {
class AgentInstance;
......@@ -53,10 +54,13 @@ private slots:
void slotInstanceRemoved(const Akonadi::AgentInstance &instance);
private:
void clearAll();
bool excludeSpecialCollection(const Akonadi::Collection &collection) const;
QHash<Akonadi::Collection, QList<Akonadi::Item::Id> > mNewMails;
QTimer mTimer;
QStringList mInstanceNameInProgress;
bool mNotifierEnabled;
bool mCheckMailInProgress;
};
#endif
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