Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
PIM
KDE PIM Runtime
Commits
3a609ac1
Commit
3a609ac1
authored
Jan 07, 2015
by
Laurent Montel
😁
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't recreate mDefaultPixmap all the time.
parent
9ebefc55
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
39 deletions
+33
-39
agents/newmailnotifier/newmailnotifieragent.cpp
agents/newmailnotifier/newmailnotifieragent.cpp
+18
-4
agents/newmailnotifier/newmailnotifieragent.h
agents/newmailnotifier/newmailnotifieragent.h
+2
-1
agents/newmailnotifier/specialnotifierjob.cpp
agents/newmailnotifier/specialnotifierjob.cpp
+9
-4
agents/newmailnotifier/specialnotifierjob.h
agents/newmailnotifier/specialnotifierjob.h
+4
-0
agents/newmailnotifier/util.cpp
agents/newmailnotifier/util.cpp
+0
-28
agents/newmailnotifier/util.h
agents/newmailnotifier/util.h
+0
-2
No files found.
agents/newmailnotifier/newmailnotifieragent.cpp
View file @
3a609ac1
...
...
@@ -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
::
d
efaultPixmap
()
,
message
);
slotDisplayNotification
(
mD
efaultPixmap
,
message
);
mNewMails
.
clear
();
}
...
...
agents/newmailnotifier/newmailnotifieragent.h
View file @
3a609ac1
...
...
@@ -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
;
...
...
agents/newmailnotifier/specialnotifierjob.cpp
View file @
3a609ac1
...
...
@@ -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
::
d
efaultPixmap
()
);
emitNotification
(
mD
efaultPixmap
);
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
::
d
efaultPixmap
()
);
emitNotification
(
mD
efaultPixmap
);
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
::
d
efaultPixmap
()
);
emitNotification
(
mD
efaultPixmap
);
}
else
{
emitNotification
(
QPixmap
::
fromImage
(
image
));
}
}
else
{
emitNotification
(
Util
::
d
efaultPixmap
()
);
emitNotification
(
mD
efaultPixmap
);
}
}
...
...
agents/newmailnotifier/specialnotifierjob.h
View file @
3a609ac1
...
...
@@ -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
;
...
...
agents/newmailnotifier/util.cpp
View file @
3a609ac1
...
...
@@ -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
()
)
)
{
...
...
agents/newmailnotifier/util.h
View file @
3a609ac1
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment