~ubuntu-branches/ubuntu/lucid/kdepim/lucid-updates

« back to all changes in this revision

Viewing changes to debian/patches/kubuntu_02_kalarm_kstatusnotifieritem.diff

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-03-04 19:25:28 UTC
  • mfrom: (1.1.53 upstream)
  • Revision ID: james.westby@ubuntu.com-20100304192528-wjajj487qzpuu76v
Tags: 4:4.4.1a-0ubuntu1
* Use 4.4.1a version to enable upgrades from the backports PPA
* Convert kalarm to use kstatusnotifieritem
 - Add kubuntu_02_kalarm_kstatusnotifieritem.diff from Aurelien Gateau
 - Add icons in debian/kalarm-icons
 - Add debian/rules to install
 - Add build-dep on sharutils

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
diff --git a/kalarm/kalarmapp.cpp b/kalarm/kalarmapp.cpp
 
2
index 8d6b898..f4d3bda 100644
 
3
--- a/kalarm/kalarmapp.cpp
 
4
+++ b/kalarm/kalarmapp.cpp
 
5
@@ -56,6 +56,7 @@
 
6
 #include <netwm.h>
 
7
 #include <kdebug.h>
 
8
 #include <kshell.h>
 
9
+#include <ksystemtrayicon.h>
 
10
 
 
11
 #include <QObject>
 
12
 #include <QTimer>
 
13
@@ -762,7 +763,6 @@ bool KAlarmApp::displayTrayIcon(bool show, MainWindow* parent)
 
14
                        }
 
15
                        mTrayWindow = new TrayWindow(parent ? parent : MainWindow::firstWindow());
 
16
                        connect(mTrayWindow, SIGNAL(deleted()), SIGNAL(trayIconToggled()));
 
17
-                       mTrayWindow->show();
 
18
                        emit trayIconToggled();
 
19
 
 
20
                        if (!checkSystemTray())
 
21
diff --git a/kalarm/kalarmconfig.kcfg b/kalarm/kalarmconfig.kcfg
 
22
index 3bef849..55f9a91 100644
 
23
--- a/kalarm/kalarmconfig.kcfg
 
24
+++ b/kalarm/kalarmconfig.kcfg
 
25
@@ -47,6 +47,8 @@
 
26
   <signal name="feb29TypeChanged">
 
27
     <argument type="Enum">DefaultFeb29Type</argument>
 
28
   </signal>
 
29
+  <signal name="tooltipPreferencesChanged">
 
30
+  </signal>
 
31
 
 
32
   <group name="General">
 
33
     <entry name="Version" type="String" hidden="true">
 
34
@@ -125,21 +127,25 @@
 
35
       </whatsthis>
 
36
       <default>5</default>
 
37
       <min>-1</min>
 
38
+      <emit signal="tooltipPreferencesChanged"/>
 
39
     </entry>
 
40
     <entry name="ShowTooltipAlarmTime" type="Bool">
 
41
       <label context="@label">Show alarm times in system tray tooltip</label>
 
42
       <whatsthis context="@info:whatsthis">Specify whether to show in the system tray tooltip, the time at which each alarm is due.</whatsthis>
 
43
       <default>true</default>
 
44
+      <emit signal="tooltipPreferencesChanged"/>
 
45
     </entry>
 
46
     <entry name="ShowTooltipTimeToAlarm" type="Bool">
 
47
       <label context="@label">Show time to alarms in system tray tooltip</label>
 
48
       <whatsthis context="@info:whatsthis">Specify whether to show in the system tray tooltip, how long until each alarm is due.</whatsthis>
 
49
       <default>true</default>
 
50
+      <emit signal="tooltipPreferencesChanged"/>
 
51
     </entry>
 
52
     <entry name="TooltipTimeToPrefix" type="String">
 
53
       <label context="@label">Time-to-alarm prefix in system tray tooltip</label>
 
54
       <whatsthis context="@info:whatsthis">Enter the text to be displayed in front of the time until the alarm, in the system tray tooltip.</whatsthis>
 
55
       <default code="true">QLatin1String("+")</default>
 
56
+      <emit signal="tooltipPreferencesChanged"/>
 
57
     </entry>
 
58
     <entry name="EmailClient" key="EmailClient" type="Enum">
 
59
       <label context="@label">Email client</label>
 
60
diff --git a/kalarm/mainwindow.cpp b/kalarm/mainwindow.cpp
 
61
index 9ad679b..3355e97 100644
 
62
--- a/kalarm/mainwindow.cpp
 
63
+++ b/kalarm/mainwindow.cpp
 
64
@@ -60,6 +60,7 @@
 
65
 #include <kaction.h>
 
66
 #include <kactioncollection.h>
 
67
 #include <kinputdialog.h>
 
68
+#include <ksystemtrayicon.h>
 
69
 
 
70
 #include <kstandardaction.h>
 
71
 #include <kiconloader.h>
 
72
diff --git a/kalarm/pixmaps/ox22-emblems-partdisabled.png b/kalarm/pixmaps/ox22-emblems-partdisabled.png
 
73
deleted file mode 100644
 
74
index 6e40203..0000000
 
75
Binary files a/kalarm/pixmaps/ox22-emblems-partdisabled.png and /dev/null differ
 
76
diff --git a/kalarm/pixmaps/ox8-emblems-disabled.png b/kalarm/pixmaps/ox8-emblems-disabled.png
 
77
new file mode 100644
 
78
index 0000000..ed3ec7c
 
79
Binary files /dev/null and b/kalarm/pixmaps/ox8-emblems-disabled.png differ
 
80
diff --git a/kalarm/pixmaps/ox8-emblems-partdisabled.png b/kalarm/pixmaps/ox8-emblems-partdisabled.png
 
81
new file mode 100644
 
82
index 0000000..5f2c1a9
 
83
Binary files /dev/null and b/kalarm/pixmaps/ox8-emblems-partdisabled.png differ
 
84
diff --git a/kalarm/traywindow.cpp b/kalarm/traywindow.cpp
 
85
index df2790d..347edc7 100644
 
86
--- a/kalarm/traywindow.cpp
 
87
+++ b/kalarm/traywindow.cpp
 
88
@@ -32,6 +32,7 @@
 
89
 #include "newalarmaction.h"
 
90
 #include "prefdlg.h"
 
91
 #include "preferences.h"
 
92
+#include "synchtimer.h"
 
93
 #include "templatemenuaction.h"
 
94
 
 
95
 #include <stdlib.h>
 
96
@@ -69,34 +70,14 @@ struct TipItem
 
97
 =============================================================================*/
 
98
 
 
99
 TrayWindow::TrayWindow(MainWindow* parent)
 
100
-       : KSystemTrayIcon(parent),
 
101
+       : KStatusNotifierItem(parent),
 
102
          mAssocMainWindow(parent),
 
103
          mHaveDisabledAlarms(false)
 
104
 {
 
105
        kDebug();
 
106
-       // Set up GUI icons
 
107
-       mIconEnabled  = loadIcon("kalarm");
 
108
-       if (mIconEnabled.isNull())
 
109
-               KMessageBox::sorry(parent, i18nc("@info", "Cannot load system tray icon."));
 
110
-       else
 
111
-       {
 
112
-               // Create the all alarms disabled icon, by converting the normal icon to grey
 
113
-               KIconLoader* loader = KIconLoader::global();
 
114
-               QImage icon = mIconEnabled.pixmap(loader->currentSize(KIconLoader::Panel)).toImage();
 
115
-               QImage iconDisabled = icon;
 
116
-               KIconEffect::toGray(iconDisabled, 1.0);
 
117
-               mIconDisabled = QIcon(QPixmap::fromImage(iconDisabled));
 
118
-
 
119
-               // Create the partially disabled icon, by overlaying the normal icon
 
120
-               // with a disabled indication
 
121
-               QImage disabled = loader->loadIcon("partdisabled", KIconLoader::Panel, icon.width(), KIconLoader::DefaultState, QStringList("emblems")).toImage();
 
122
-               KIconEffect::overlay(icon, disabled);
 
123
-               mIconSomeDisabled = QIcon(QPixmap::fromImage(icon));
 
124
-       }
 
125
-#ifdef __GNUC__
 
126
-#warning How to implement drag-and-drop?
 
127
-#endif
 
128
-       //setAcceptDrops(true);         // allow drag-and-drop onto this window
 
129
+       setToolTipIconByName("kalarm");
 
130
+       setToolTipTitle(KGlobal::mainComponent().aboutData()->programName());
 
131
+       setIconByName("kalarm");
 
132
 
 
133
        // Set up the context menu
 
134
        KActionCollection* actions = actionCollection();
 
135
@@ -135,14 +116,40 @@ TrayWindow::TrayWindow(MainWindow* parent)
 
136
        a = KStandardAction::quit(0, 0, actions);
 
137
        connect(a, SIGNAL(triggered(bool)), SLOT(slotQuit()), Qt::QueuedConnection);
 
138
 
 
139
-       // Set icon to correspond with the alarms enabled menu status
 
140
-       setEnabledStatus(theApp()->alarmsEnabled());
 
141
-
 
142
        connect(AlarmResources::instance(), SIGNAL(resourceStatusChanged(AlarmResource*, AlarmResources::Change)), SLOT(slotResourceStatusChanged()));
 
143
        connect(AlarmCalendar::resources(), SIGNAL(haveDisabledAlarmsChanged(bool)), SLOT(slotHaveDisabledAlarms(bool)));
 
144
-       connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), SLOT(slotActivated(QSystemTrayIcon::ActivationReason)));
 
145
+       connect(this, SIGNAL(activateRequested(bool, const QPoint&)), SLOT(slotActivateRequested()));
 
146
+       connect(this, SIGNAL(secondaryActivateRequested(const QPoint&)), SLOT(slotSecondaryActivateRequested()));
 
147
        slotResourceStatusChanged();   // initialise action states
 
148
        slotHaveDisabledAlarms(AlarmCalendar::resources()->haveDisabledAlarms());
 
149
+
 
150
+       // Hack: KSNI does not let us know when it is about to show the tooltip,
 
151
+       // so we need to update it whenever something change in it.
 
152
+
 
153
+       // This timer ensure updateToolTip() is not called several times in a row
 
154
+       mToolTipUpdateTimer = new QTimer(this);
 
155
+       mToolTipUpdateTimer->setInterval(0);
 
156
+       mToolTipUpdateTimer->setSingleShot(true);
 
157
+       connect(mToolTipUpdateTimer, SIGNAL(timeout()), SLOT(updateToolTip()));
 
158
+
 
159
+       // Update every minute to show accurate deadlines
 
160
+       MinuteTimer::connect(mToolTipUpdateTimer, SLOT(start()));
 
161
+
 
162
+       // Update when alarms are modified
 
163
+       connect(EventListModel::alarms(), SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
 
164
+               mToolTipUpdateTimer, SLOT(start()));
 
165
+       connect(EventListModel::alarms(), SIGNAL(rowsInserted(const QModelIndex&, int, int)),
 
166
+               mToolTipUpdateTimer, SLOT(start()));
 
167
+       connect(EventListModel::alarms(), SIGNAL(rowsMoved(const QModelIndex&, int, int, const QModelIndex&, int)),
 
168
+               mToolTipUpdateTimer, SLOT(start()));
 
169
+       connect(EventListModel::alarms(), SIGNAL(rowsRemoved(const QModelIndex&, int, int)),
 
170
+               mToolTipUpdateTimer, SLOT(start()));
 
171
+       connect(EventListModel::alarms(), SIGNAL(modelReset()),
 
172
+               mToolTipUpdateTimer, SLOT(start()));
 
173
+
 
174
+       // Update when tooltip preferences are modified
 
175
+       Preferences::connect(SIGNAL(tooltipPreferencesChanged()),
 
176
+               mToolTipUpdateTimer, SLOT(start()));
 
177
 }
 
178
 
 
179
 TrayWindow::~TrayWindow()
 
180
@@ -196,7 +203,8 @@ void TrayWindow::slotPreferences()
 
181
 */
 
182
 void TrayWindow::slotQuit()
 
183
 {
 
184
-       theApp()->doQuit(parentWidget());
 
185
+       // FIXME: Do we really need a slotQuit()?
 
186
+       theApp()->doQuit(static_cast<QWidget*>(parent()));
 
187
 }
 
188
 
 
189
 /******************************************************************************
 
190
@@ -206,7 +214,8 @@ void TrayWindow::slotQuit()
 
191
 void TrayWindow::setEnabledStatus(bool status)
 
192
 {
 
193
        kDebug() << (int)status;
 
194
-       setIcon(status ? (mHaveDisabledAlarms ? mIconSomeDisabled : mIconEnabled) : mIconDisabled);
 
195
+       updateIcon();
 
196
+       updateToolTip();
 
197
 }
 
198
 
 
199
 /******************************************************************************
 
200
@@ -217,75 +226,74 @@ void TrayWindow::slotHaveDisabledAlarms(bool haveDisabled)
 
201
 {
 
202
        kDebug() << haveDisabled;
 
203
        mHaveDisabledAlarms = haveDisabled;
 
204
-       if (mActionEnabled->isChecked())
 
205
-               setIcon(haveDisabled ? mIconSomeDisabled : mIconEnabled);
 
206
+       updateIcon();
 
207
+       updateToolTip();
 
208
 }
 
209
 
 
210
 /******************************************************************************
 
211
-*  Called when the mouse is clicked over the panel icon.
 
212
 *  A left click displays the KAlarm main window.
 
213
-*  A middle button click displays the New Alarm window.
 
214
 */
 
215
-void TrayWindow::slotActivated(QSystemTrayIcon::ActivationReason reason)
 
216
+void TrayWindow::slotActivateRequested()
 
217
 {
 
218
-       if (reason == QSystemTrayIcon::Trigger)
 
219
-       {
 
220
-               // Left click: display/hide the first main window
 
221
-               if (mAssocMainWindow  &&  mAssocMainWindow->isVisible())
 
222
-               {
 
223
-                       mAssocMainWindow->raise();
 
224
-                       mAssocMainWindow->activateWindow();
 
225
-               }
 
226
-       }
 
227
-       else if (reason == QSystemTrayIcon::MiddleClick)
 
228
+       // Left click: display/hide the first main window
 
229
+       if (mAssocMainWindow  &&  mAssocMainWindow->isVisible())
 
230
        {
 
231
-               if (mActionNew->isEnabled())
 
232
-                       mActionNew->trigger();    // display a New Alarm dialog
 
233
+               mAssocMainWindow->raise();
 
234
+               mAssocMainWindow->activateWindow();
 
235
        }
 
236
 }
 
237
 
 
238
 /******************************************************************************
 
239
-*  Called when the drag cursor enters the panel icon.
 
240
+*  A middle button click displays the New Alarm window.
 
241
 */
 
242
-void TrayWindow::dragEnterEvent(QDragEnterEvent* e)
 
243
+void TrayWindow::slotSecondaryActivateRequested()
 
244
 {
 
245
-       MainWindow::executeDragEnterEvent(e);
 
246
+       if (mActionNew->isEnabled())
 
247
+               mActionNew->trigger();    // display a New Alarm dialog
 
248
 }
 
249
 
 
250
 /******************************************************************************
 
251
-*  Called when an object is dropped on the panel icon.
 
252
-*  If the object is recognised, the edit alarm dialog is opened appropriately.
 
253
+*  Adjust tooltip according to the app state.
 
254
+*  The tooltip text shows alarms due in the next 24 hours. The limit of 24
 
255
+*  hours is because only times, not dates, are displayed.
 
256
 */
 
257
-void TrayWindow::dropEvent(QDropEvent* e)
 
258
+void TrayWindow::updateToolTip()
 
259
 {
 
260
-       MainWindow::executeDropEvent(0, e);
 
261
+       bool enabled = theApp()->alarmsEnabled();
 
262
+       QString subTitle;
 
263
+       if (enabled  &&  Preferences::tooltipAlarmCount())
 
264
+               subTitle = tooltipAlarmText();
 
265
+       if (!enabled) {
 
266
+               //text = i18nc("@info:tooltip 'KAlarm - disabled'", "%1 - disabled", KGlobal::mainComponent().aboutData()->programName());
 
267
+               subTitle = i18n("Disabled");
 
268
+       } else if (mHaveDisabledAlarms) {
 
269
+               if (!subTitle.isEmpty()) {
 
270
+                       subTitle += "<br/>";
 
271
+               }
 
272
+               #if 0
 
273
+               subTitle += i18nc("@info:tooltip Brief: some alarms are disabled", "(Some alarms disabled)");
 
274
+               #else
 
275
+               // FIXME: Hack to avoid introducing new strings
 
276
+               QString text = i18nc("@info:tooltip Brief: some alarms are disabled", "%1<nl/>(Some alarms disabled)%2", QString(), QString());
 
277
+               // i18n() turns "<nl/>" into "<br/>"
 
278
+               text = text.mid(text.indexOf("<br/>") + 5);
 
279
+               subTitle += text;
 
280
+               #endif
 
281
+       }
 
282
+       kDebug() << subTitle;
 
283
+       setToolTipSubTitle(subTitle);
 
284
 }
 
285
 
 
286
 /******************************************************************************
 
287
-*  Called when any event occurs.
 
288
-*  If it's a tooltip event, display the tooltip text showing alarms due in the
 
289
-*  next 24 hours. The limit of 24 hours is because only times, not dates, are
 
290
-*  displayed.
 
291
+*  Adjust icon according to the app state.
 
292
 */
 
293
-bool TrayWindow::event(QEvent* e)
 
294
+void TrayWindow::updateIcon()
 
295
 {
 
296
-       if (e->type() != QEvent::ToolTip)
 
297
-               return KSystemTrayIcon::event(e);
 
298
-       QHelpEvent* he = (QHelpEvent*)e;
 
299
-       bool enabled = theApp()->alarmsEnabled();
 
300
-       QString altext;
 
301
-       if (enabled  &&  Preferences::tooltipAlarmCount())
 
302
-               altext = tooltipAlarmText();
 
303
-       QString text;
 
304
-       if (!enabled)
 
305
-               text = i18nc("@info:tooltip 'KAlarm - disabled'", "%1 - disabled", KGlobal::mainComponent().aboutData()->programName());
 
306
-       else if (mHaveDisabledAlarms)
 
307
-               text = i18nc("@info:tooltip Brief: some alarms are disabled", "%1<nl/>(Some alarms disabled)%2", KGlobal::mainComponent().aboutData()->programName(), altext);
 
308
-       else
 
309
-               text = i18nc("@info:tooltip", "%1%2", KGlobal::mainComponent().aboutData()->programName(), altext);
 
310
-       kDebug() << text;
 
311
-       QToolTip::showText(he->globalPos(), text);
 
312
-       return true;
 
313
+       if (theApp()->alarmsEnabled()) {
 
314
+               setOverlayIconByName(mHaveDisabledAlarms ? "partdisabled" : QString());
 
315
+       } else {
 
316
+               setOverlayIconByName("disabled");
 
317
+       }
 
318
 }
 
319
 
 
320
 /******************************************************************************
 
321
@@ -353,7 +361,9 @@ QString TrayWindow::tooltipAlarmText() const
 
322
        for (i = 0, iend = items.count();  i < iend;  ++i)
 
323
        {
 
324
                kDebug() << "--" << (count+1) << ")" << items[i].text;
 
325
-               text += "<br />" + items[i].text;
 
326
+               if (i > 0)
 
327
+                       text += "<br />";
 
328
+               text += items[i].text;
 
329
                if (++count == maxCount)
 
330
                        break;
 
331
        }
 
332
diff --git a/kalarm/traywindow.h b/kalarm/traywindow.h
 
333
index 9d402c5..cfcdddb 100644
 
334
--- a/kalarm/traywindow.h
 
335
+++ b/kalarm/traywindow.h
 
336
@@ -23,7 +23,7 @@
 
337
 
 
338
 #include "editdlg.h"
 
339
 #include "kaevent.h"
 
340
-#include <ksystemtrayicon.h>
 
341
+#include <kstatusnotifieritem.h>
 
342
 #include <QIcon>
 
343
 
 
344
 class QEvent;
 
345
@@ -35,7 +35,7 @@ class KAEvent;
 
346
 class MainWindow;
 
347
 class NewAlarmAction;
 
348
 
 
349
-class TrayWindow : public KSystemTrayIcon
 
350
+class TrayWindow : public KStatusNotifierItem
 
351
 {
 
352
                Q_OBJECT
 
353
        public:
 
354
@@ -48,13 +48,9 @@ class TrayWindow : public KSystemTrayIcon
 
355
        signals:
 
356
                void         deleted();
 
357
 
 
358
-       protected:
 
359
-               virtual void dragEnterEvent(QDragEnterEvent*);
 
360
-               virtual void dropEvent(QDropEvent*);
 
361
-               virtual bool event(QEvent*);
 
362
-
 
363
        private slots:
 
364
-               void         slotActivated(QSystemTrayIcon::ActivationReason reason);
 
365
+               void         slotActivateRequested();
 
366
+               void         slotSecondaryActivateRequested();
 
367
                void         slotNewAlarm(EditAlarmDlg::Type);
 
368
                void         slotNewFromTemplate(const KAEvent*);
 
369
                void         slotPreferences();
 
370
@@ -62,18 +58,18 @@ class TrayWindow : public KSystemTrayIcon
 
371
                void         slotHaveDisabledAlarms(bool disabled);
 
372
                void         slotResourceStatusChanged();
 
373
                void         slotQuit();
 
374
+               void         updateToolTip();
 
375
 
 
376
        private:
 
377
                QString      tooltipAlarmText() const;
 
378
+               void         updateIcon();
 
379
 
 
380
                MainWindow*     mAssocMainWindow;     // main window associated with this, or null
 
381
-               QIcon           mIconEnabled;         // normal status icon
 
382
-               QIcon           mIconDisabled;        // icon indicating all alarms disabled
 
383
-               QIcon           mIconSomeDisabled;    // icon indicating individual alarms disabled
 
384
                KToggleAction*  mActionEnabled;
 
385
                NewAlarmAction* mActionNew;
 
386
                KAction*        mActionNewFromTemplate;
 
387
                bool            mHaveDisabledAlarms;  // some individually disabled alarms exist
 
388
+               QTimer*         mToolTipUpdateTimer;
 
389
 };
 
390
 
 
391
 #endif // TRAYWINDOW_H