~ubuntu-branches/ubuntu/karmic/kdepim/karmic-backports

« back to all changes in this revision

Viewing changes to debian/patches/kubuntu-message-indicator/0005-Support-for-icon-in-indicators.patch

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2009-08-26 13:46:48 UTC
  • Revision ID: james.westby@ubuntu.com-20090826134648-dm4cdlj21msi6i59
Tags: 4:4.3.0-0ubuntu2
* Add message indicator 4.3 backport patches from 
  Aurelien Gateau <aurelien.gateau@canonical.com>
  in debian/patches/kubuntu-message-indicator
* Add build-dep on libindicate-qt

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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.
 
5
 
 
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.
 
9
---
 
10
 kmail/kmfolder.cpp |  142 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 
11
 kmail/kmfolder.h   |    1 +
 
12
 2 files changed, 139 insertions(+), 4 deletions(-)
 
13
 
 
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 );
 
25
-    }
 
26
+    connect( this, SIGNAL( iconsChanged() ),
 
27
+      SLOT( updateIndicatorIcon() ) );
 
28
     updateIndicator();
 
29
+    updateIndicatorIcon();
 
30
   }
 
31
 }
 
32
 
 
33
@@ -976,6 +975,141 @@ void KMFolder::updateIndicator()
 
34
   }
 
35
 }
 
36
 
 
37
+//--- UGLY ---
 
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>
 
45
+
 
46
+static QString normalIcon( KMFolder *folder )
 
47
+{
 
48
+  QString icon;
 
49
+
 
50
+  KPIM::FolderTreeWidgetItem::FolderType ftwiFolderType = KMail::FolderViewItem::folderTypeByFolder( folder );
 
51
+  // Roots
 
52
+  if ( ftwiFolderType == KPIM::FolderTreeWidgetItem::Root )
 
53
+  {
 
54
+    switch ( folder->folderType() )
 
55
+    {
 
56
+      case KMFolderTypeImap:
 
57
+      case KMFolderTypeCachedImap:
 
58
+        icon = "network-server";
 
59
+      break;
 
60
+      case KMFolderTypeSearch:
 
61
+        icon = "system-search";
 
62
+      break;
 
63
+      default:
 
64
+        icon = "folder";
 
65
+      break;
 
66
+    }
 
67
+  } else {
 
68
+    // special folders
 
69
+    switch ( ftwiFolderType )
 
70
+    {
 
71
+      case KPIM::FolderTreeWidgetItem::Inbox:
 
72
+        icon = "mail-folder-inbox";
 
73
+      break;
 
74
+      case KPIM::FolderTreeWidgetItem::Outbox:
 
75
+        icon = "mail-folder-outbox";
 
76
+      break;
 
77
+      case KPIM::FolderTreeWidgetItem::SentMail:
 
78
+        icon = "mail-folder-sent";
 
79
+      break;
 
80
+      case KPIM::FolderTreeWidgetItem::Trash:
 
81
+        icon = "user-trash";
 
82
+      break;
 
83
+      case KPIM::FolderTreeWidgetItem::Drafts:
 
84
+        icon = "document-properties";
 
85
+      break;
 
86
+      case KPIM::FolderTreeWidgetItem::Templates:
 
87
+        icon = "document-new";
 
88
+      break;
 
89
+      default:
 
90
+      {
 
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 );
 
94
+        }
 
95
+      }
 
96
+      break;
 
97
+    }
 
98
+
 
99
+    // non-root search folders
 
100
+    if ( folder->folderType() == KMFolderTypeSearch )
 
101
+      icon = "edit-find-mail";
 
102
+
 
103
+    // empty folders with no associated content
 
104
+    if ( folder->noContent() )
 
105
+      icon = "folder-grey";
 
106
+  }
 
107
+
 
108
+  // allow icon customization by the folder itself
 
109
+  if ( folder->useCustomIcons() )
 
110
+    icon = folder->normalIconPath();
 
111
+
 
112
+  // fallback
 
113
+  if ( icon.isEmpty() )
 
114
+    icon = "folder";
 
115
+
 
116
+  return icon;
 
117
+}
 
118
+
 
119
+static QString unreadIcon( KMFolder *folder )
 
120
+{
 
121
+  QString icon;
 
122
+  KPIM::FolderTreeWidgetItem::FolderType ftwiFolderType = KMail::FolderViewItem::folderTypeByFolder( folder );
 
123
+
 
124
+  if (
 
125
+      ftwiFolderType == KPIM::FolderTreeWidgetItem::Root || folder->isSystemFolder() ||
 
126
+      kmkernel->folderIsTrash( folder ) || kmkernel->folderIsTemplates( folder ) ||
 
127
+      kmkernel->folderIsDraftOrOutbox( folder )
 
128
+    )
 
129
+    icon = normalIcon( folder );
 
130
+
 
131
+  if ( folder->useCustomIcons() )
 
132
+  {
 
133
+    icon = folder->unreadIconPath();
 
134
+    if ( icon.isEmpty() )
 
135
+      icon = folder->normalIconPath();
 
136
+  }
 
137
+
 
138
+  if ( icon.isEmpty() )
 
139
+  {
 
140
+    if ( folder->noContent() )
 
141
+      icon = "folder-grey";
 
142
+    else {
 
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 );
 
146
+      }
 
147
+      if ( icon.isEmpty() ) {
 
148
+         icon = "folder-open";
 
149
+      }
 
150
+    }
 
151
+  }
 
152
+
 
153
+  return icon;
 
154
+}
 
155
+//--- /UGLY ---
 
156
+
 
157
+void KMFolder::updateIndicatorIcon()
 
158
+{
 
159
+  if ( !mIndicator ) {
 
160
+    return;
 
161
+  }
 
162
+
 
163
+  QString icon = unreadIcon( this );
 
164
+  QPixmap pix = SmallIcon(icon);
 
165
+  if ( pix.isNull() ) {
 
166
+    kWarning() << "Could not read image from" << icon;
 
167
+  } else {
 
168
+    mIndicator->setProperty( "icon", pix.toImage() );
 
169
+  }
 
170
+}
 
171
+
 
172
 void KMFolder::slotIndicatorClicked()
 
173
 {
 
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();
 
181
 
 
182
   void updateIndicator();
 
183
+  void updateIndicatorIcon();
 
184
 
 
185
   void slotIndicatorClicked();
 
186
 
 
187
-- 
 
188
1.6.3.3
 
189