Commit 3a609ac1 authored by Laurent Montel's avatar Laurent Montel 😁

Don't recreate mDefaultPixmap all the time.

parent 9ebefc55
......@@ -53,6 +53,8 @@
#include <KConfigGroup>
#include <KLocalizedString>
#include <KWindowSystem>
#include <KToolInvocation>
using namespace Akonadi;
......@@ -65,6 +67,7 @@ NewMailNotifierAgent::NewMailNotifierAgent( const QString &id )
mIdentityManager = new KPIMIdentities::IdentityManager( false, this );
connect(mIdentityManager, SIGNAL(changed()), SLOT(slotIdentitiesChanged()));
slotIdentitiesChanged();
mDefaultPixmap = KIcon( QLatin1String("kmail") ).pixmap( KIconLoader::SizeMedium, KIconLoader::SizeMedium );
DBusConnectionPool::threadConnection().registerObject( QLatin1String( "/NewMailNotifierAgent" ),
this, QDBusConnection::ExportAdaptors );
......@@ -91,9 +94,19 @@ NewMailNotifierAgent::NewMailNotifierAgent( const QString &id )
mTimer.setInterval( 5 * 1000 );
connect( &mTimer, SIGNAL(timeout()), SLOT(slotShowNotifications()) );
if (NewMailNotifierAgentSettings::textToSpeakEnabled())
Util::testJovieService();
if (NewMailNotifierAgentSettings::textToSpeakEnabled()) {
if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String("org.kde.kttsd"))) {
QString error;
if (KToolInvocation::startServiceByDesktopName(QLatin1String("kttsd"), QStringList(), &error)) {
KNotification::event( QLatin1String("text-to-speak-not-found"),
i18n("Starting Jovie Text-to-Speech Service Failed %1", error),
mDefaultPixmap,
0,
KNotification::CloseOnTimeout,
KGlobal::mainComponent());
}
}
}
if (isActive()) {
mTimer.setSingleShot( true );
}
......@@ -460,6 +473,7 @@ void NewMailNotifierAgent::slotShowNotifications()
}
if (hasUniqMessage) {
SpecialNotifierJob *job = new SpecialNotifierJob(mListEmails, currentPath, item, this);
job->setDefaultPixmap(mDefaultPixmap);
connect(job, SIGNAL(displayNotification(QPixmap,QString)), SLOT(slotDisplayNotification(QPixmap,QString)));
mNewMails.clear();
return;
......@@ -472,7 +486,7 @@ void NewMailNotifierAgent::slotShowNotifications()
kDebug() << message;
slotDisplayNotification(Util::defaultPixmap(), message);
slotDisplayNotification(mDefaultPixmap, message);
mNewMails.clear();
}
......
......@@ -27,7 +27,7 @@
#include <QTimer>
#include <QStringList>
#include <QPixmap>
namespace Akonadi {
class AgentInstance;
}
......@@ -102,6 +102,7 @@ private:
bool isActive() const;
void clearAll();
bool excludeSpecialCollection(const Akonadi::Collection &collection) const;
QPixmap mDefaultPixmap;
QStringList mListEmails;
QHash<Akonadi::Collection, QList<Akonadi::Item::Id> > mNewMails;
QHash<QString, QString> mCacheResourceName;
......
......@@ -55,6 +55,11 @@ SpecialNotifierJob::~SpecialNotifierJob()
}
void SpecialNotifierJob::setDefaultPixmap(const QPixmap &pixmap)
{
mDefaultPixmap = pixmap;
}
void SpecialNotifierJob::slotItemFetchJobDone(KJob *job)
{
if ( job->error() ) {
......@@ -81,7 +86,7 @@ void SpecialNotifierJob::slotItemFetchJobDone(KJob *job)
job->setQuery( Akonadi::ContactSearchJob::Email, KPIMUtils::firstEmailAddress(mFrom).toLower(), Akonadi::ContactSearchJob::ExactMatch );
connect( job, SIGNAL(result(KJob*)), SLOT(slotSearchJobFinished(KJob*)) );
} else {
emitNotification(Util::defaultPixmap());
emitNotification(mDefaultPixmap);
deleteLater();
}
} else {
......@@ -96,7 +101,7 @@ void SpecialNotifierJob::slotSearchJobFinished( KJob *job )
const Akonadi::ContactSearchJob *searchJob = qobject_cast<Akonadi::ContactSearchJob*>( job );
if ( searchJob->error() ) {
kWarning() << "Unable to fetch contact:" << searchJob->errorText();
emitNotification(Util::defaultPixmap());
emitNotification(mDefaultPixmap);
return;
}
if (!searchJob->contacts().isEmpty()) {
......@@ -104,12 +109,12 @@ void SpecialNotifierJob::slotSearchJobFinished( KJob *job )
const KABC::Picture photo = addressee.photo();
const QImage image = photo.data();
if (image.isNull()) {
emitNotification(Util::defaultPixmap());
emitNotification(mDefaultPixmap);
} else {
emitNotification(QPixmap::fromImage(image));
}
} else {
emitNotification(Util::defaultPixmap());
emitNotification(mDefaultPixmap);
}
}
......
......@@ -22,6 +22,7 @@
#include <QObject>
#include <Akonadi/Item>
#include <QStringList>
#include <QPixmap>
class KJob;
class SpecialNotifierJob : public QObject
......@@ -31,6 +32,8 @@ public:
explicit SpecialNotifierJob(const QStringList &listEmails, const QString &path, Akonadi::Item::Id id, QObject *parent = 0);
~SpecialNotifierJob();
void setDefaultPixmap(const QPixmap &pixmap);
Q_SIGNALS:
void displayNotification(const QPixmap &pixmap, const QString &message);
......@@ -40,6 +43,7 @@ private Q_SLOTS:
void slotOpenMail();
private:
void emitNotification(const QPixmap &pixmap);
QPixmap mDefaultPixmap;
QStringList mListEmails;
QString mSubject;
QString mFrom;
......
......@@ -20,33 +20,11 @@
#include <KNotification>
#include <KLocalizedString>
#include <KGlobal>
#include <KIcon>
#include <KIconLoader>
#include <KToolInvocation>
#include <Akonadi/AgentInstance>
#include <Akonadi/AgentType>
#include <KMime/Message>
#include <QDBusInterface>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
void Util::testJovieService()
{
if (!QDBusConnection::sessionBus().interface()->isServiceRegistered(QLatin1String("org.kde.kttsd"))) {
QString error;
if (KToolInvocation::startServiceByDesktopName(QLatin1String("kttsd"), QStringList(), &error)) {
KNotification::event( QLatin1String("text-to-speak-not-found"),
i18n("Starting Jovie Text-to-Speech Service Failed %1", error),
Util::defaultPixmap(),
0,
KNotification::CloseOnTimeout,
KGlobal::mainComponent());
}
}
}
void Util::showNotification(const QPixmap &pixmap, const QString &message)
{
......@@ -58,12 +36,6 @@ void Util::showNotification(const QPixmap &pixmap, const QString &message)
KGlobal::mainComponent());
}
QPixmap Util::defaultPixmap()
{
const QPixmap pixmap = KIcon( QLatin1String("kmail") ).pixmap( KIconLoader::SizeMedium, KIconLoader::SizeMedium );
return pixmap;
}
bool Util::excludeAgentType(const Akonadi::AgentInstance &instance)
{
if ( instance.type().mimeTypes().contains( KMime::Message::mimeType() ) ) {
......
......@@ -27,9 +27,7 @@ class AgentInstance;
namespace Util {
void showNotification(const QPixmap &pixmap, const QString &message);
QPixmap defaultPixmap();
bool excludeAgentType(const Akonadi::AgentInstance &instance);
void testJovieService();
}
#endif // UTIL_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