1
From 9e5f8fbf72684fb823b7868601e76f7a7df23ae7 Mon Sep 17 00:00:00 2001
2
From: Aurelien Gateau <aurelien.gateau@canonical.com>
3
Date: Thu, 13 Aug 2009 17:07:24 +0200
4
Subject: [PATCH 5/5] Support for icon in indicators.
6
This feature required duplicating code from FolderViewItem.
7
I have been told this will go away when KMail switches to Akonadi, so
8
there is no point in refactoring the existing icon code.
10
kmail/kmfolder.cpp | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++--
11
kmail/kmfolder.h | 1 +
12
2 files changed, 139 insertions(+), 4 deletions(-)
14
diff --git a/kmail/kmfolder.cpp b/kmail/kmfolder.cpp
15
index 5c5d11f..6d1406f 100644
16
--- a/kmail/kmfolder.cpp
17
+++ b/kmail/kmfolder.cpp
18
@@ -940,11 +940,10 @@ void KMFolder::setIgnoreNewMail( bool b )
19
SLOT( slotIndicatorClicked() ) );
20
connect( mStorage, SIGNAL( numUnreadMsgsChanged( KMFolder* ) ),
21
SLOT( updateIndicator() ) );
22
- QImage image( mUnreadIconPath );
23
- if ( !image.isNull() ) {
24
- mIndicator->setProperty( "icon", image );
26
+ connect( this, SIGNAL( iconsChanged() ),
27
+ SLOT( updateIndicatorIcon() ) );
29
+ updateIndicatorIcon();
33
@@ -976,6 +975,141 @@ void KMFolder::updateIndicator()
38
+// This is ugly: we can't get the real icon from KMFolder because it does not
39
+// return the appropriate icons for special cases like inbox, outbox, sent.
40
+// This is done at view level by FolderView and FolderViewItem.
41
+// The following code reuse FolderViewItem code as much as possible, but
42
+// duplicates quite a bit of FolderViewItem::normalIcon() and
43
+// FolderViewItem::unreadIcon()
44
+#include <folderview.h>
46
+static QString normalIcon( KMFolder *folder )
50
+ KPIM::FolderTreeWidgetItem::FolderType ftwiFolderType = KMail::FolderViewItem::folderTypeByFolder( folder );
52
+ if ( ftwiFolderType == KPIM::FolderTreeWidgetItem::Root )
54
+ switch ( folder->folderType() )
56
+ case KMFolderTypeImap:
57
+ case KMFolderTypeCachedImap:
58
+ icon = "network-server";
60
+ case KMFolderTypeSearch:
61
+ icon = "system-search";
69
+ switch ( ftwiFolderType )
71
+ case KPIM::FolderTreeWidgetItem::Inbox:
72
+ icon = "mail-folder-inbox";
74
+ case KPIM::FolderTreeWidgetItem::Outbox:
75
+ icon = "mail-folder-outbox";
77
+ case KPIM::FolderTreeWidgetItem::SentMail:
78
+ icon = "mail-folder-sent";
80
+ case KPIM::FolderTreeWidgetItem::Trash:
81
+ icon = "user-trash";
83
+ case KPIM::FolderTreeWidgetItem::Drafts:
84
+ icon = "document-properties";
86
+ case KPIM::FolderTreeWidgetItem::Templates:
87
+ icon = "document-new";
91
+ //If not a resource folder don't try to use icalIface folder pixmap
92
+ if ( kmkernel->iCalIface().isResourceFolder( folder ) ) {
93
+ icon = kmkernel->iCalIface().folderPixmap( ftwiFolderType );
99
+ // non-root search folders
100
+ if ( folder->folderType() == KMFolderTypeSearch )
101
+ icon = "edit-find-mail";
103
+ // empty folders with no associated content
104
+ if ( folder->noContent() )
105
+ icon = "folder-grey";
108
+ // allow icon customization by the folder itself
109
+ if ( folder->useCustomIcons() )
110
+ icon = folder->normalIconPath();
113
+ if ( icon.isEmpty() )
119
+static QString unreadIcon( KMFolder *folder )
122
+ KPIM::FolderTreeWidgetItem::FolderType ftwiFolderType = KMail::FolderViewItem::folderTypeByFolder( folder );
125
+ ftwiFolderType == KPIM::FolderTreeWidgetItem::Root || folder->isSystemFolder() ||
126
+ kmkernel->folderIsTrash( folder ) || kmkernel->folderIsTemplates( folder ) ||
127
+ kmkernel->folderIsDraftOrOutbox( folder )
129
+ icon = normalIcon( folder );
131
+ if ( folder->useCustomIcons() )
133
+ icon = folder->unreadIconPath();
134
+ if ( icon.isEmpty() )
135
+ icon = folder->normalIconPath();
138
+ if ( icon.isEmpty() )
140
+ if ( folder->noContent() )
141
+ icon = "folder-grey";
143
+ //If not a resource folder don't try to use icalIface folder pixmap
144
+ if( kmkernel->iCalIface().isResourceFolder( folder ) ) {
145
+ icon = kmkernel->iCalIface().folderPixmap( ftwiFolderType );
147
+ if ( icon.isEmpty() ) {
148
+ icon = "folder-open";
157
+void KMFolder::updateIndicatorIcon()
159
+ if ( !mIndicator ) {
163
+ QString icon = unreadIcon( this );
164
+ QPixmap pix = SmallIcon(icon);
165
+ if ( pix.isNull() ) {
166
+ kWarning() << "Could not read image from" << icon;
168
+ mIndicator->setProperty( "icon", pix.toImage() );
172
void KMFolder::slotIndicatorClicked()
174
kmkernel->activateMainWin();
175
diff --git a/kmail/kmfolder.h b/kmail/kmfolder.h
176
index 1c2cb80..a5c8c68 100644
177
--- a/kmail/kmfolder.h
178
+++ b/kmail/kmfolder.h
179
@@ -681,6 +681,7 @@ private slots:
180
void slotIdentitiesChanged();
182
void updateIndicator();
183
+ void updateIndicatorIcon();
185
void slotIndicatorClicked();