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
9
+#include <ksystemtrayicon.h>
13
@@ -762,7 +763,6 @@ bool KAlarmApp::displayTrayIcon(bool show, MainWindow* parent)
15
mTrayWindow = new TrayWindow(parent ? parent : MainWindow::firstWindow());
16
connect(mTrayWindow, SIGNAL(deleted()), SIGNAL(trayIconToggled()));
17
- mTrayWindow->show();
18
emit trayIconToggled();
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
26
<signal name="feb29TypeChanged">
27
<argument type="Enum">DefaultFeb29Type</argument>
29
+ <signal name="tooltipPreferencesChanged">
32
<group name="General">
33
<entry name="Version" type="String" hidden="true">
38
+ <emit signal="tooltipPreferencesChanged"/>
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"/>
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"/>
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"/>
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
66
#include <kactioncollection.h>
67
#include <kinputdialog.h>
68
+#include <ksystemtrayicon.h>
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
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
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
89
#include "newalarmaction.h"
91
#include "preferences.h"
92
+#include "synchtimer.h"
93
#include "templatemenuaction.h"
96
@@ -69,34 +70,14 @@ struct TipItem
97
=============================================================================*/
99
TrayWindow::TrayWindow(MainWindow* parent)
100
- : KSystemTrayIcon(parent),
101
+ : KStatusNotifierItem(parent),
102
mAssocMainWindow(parent),
103
mHaveDisabledAlarms(false)
106
- // Set up GUI icons
107
- mIconEnabled = loadIcon("kalarm");
108
- if (mIconEnabled.isNull())
109
- KMessageBox::sorry(parent, i18nc("@info", "Cannot load system tray icon."));
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));
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));
126
-#warning How to implement drag-and-drop?
128
- //setAcceptDrops(true); // allow drag-and-drop onto this window
129
+ setToolTipIconByName("kalarm");
130
+ setToolTipTitle(KGlobal::mainComponent().aboutData()->programName());
131
+ setIconByName("kalarm");
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);
139
- // Set icon to correspond with the alarms enabled menu status
140
- setEnabledStatus(theApp()->alarmsEnabled());
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());
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.
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()));
159
+ // Update every minute to show accurate deadlines
160
+ MinuteTimer::connect(mToolTipUpdateTimer, SLOT(start()));
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()));
174
+ // Update when tooltip preferences are modified
175
+ Preferences::connect(SIGNAL(tooltipPreferencesChanged()),
176
+ mToolTipUpdateTimer, SLOT(start()));
179
TrayWindow::~TrayWindow()
180
@@ -196,7 +203,8 @@ void TrayWindow::slotPreferences()
182
void TrayWindow::slotQuit()
184
- theApp()->doQuit(parentWidget());
185
+ // FIXME: Do we really need a slotQuit()?
186
+ theApp()->doQuit(static_cast<QWidget*>(parent()));
189
/******************************************************************************
190
@@ -206,7 +214,8 @@ void TrayWindow::slotQuit()
191
void TrayWindow::setEnabledStatus(bool status)
193
kDebug() << (int)status;
194
- setIcon(status ? (mHaveDisabledAlarms ? mIconSomeDisabled : mIconEnabled) : mIconDisabled);
199
/******************************************************************************
200
@@ -217,75 +226,74 @@ void TrayWindow::slotHaveDisabledAlarms(bool haveDisabled)
202
kDebug() << haveDisabled;
203
mHaveDisabledAlarms = haveDisabled;
204
- if (mActionEnabled->isChecked())
205
- setIcon(haveDisabled ? mIconSomeDisabled : mIconEnabled);
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.
215
-void TrayWindow::slotActivated(QSystemTrayIcon::ActivationReason reason)
216
+void TrayWindow::slotActivateRequested()
218
- if (reason == QSystemTrayIcon::Trigger)
220
- // Left click: display/hide the first main window
221
- if (mAssocMainWindow && mAssocMainWindow->isVisible())
223
- mAssocMainWindow->raise();
224
- mAssocMainWindow->activateWindow();
227
- else if (reason == QSystemTrayIcon::MiddleClick)
228
+ // Left click: display/hide the first main window
229
+ if (mAssocMainWindow && mAssocMainWindow->isVisible())
231
- if (mActionNew->isEnabled())
232
- mActionNew->trigger(); // display a New Alarm dialog
233
+ mAssocMainWindow->raise();
234
+ mAssocMainWindow->activateWindow();
238
/******************************************************************************
239
-* Called when the drag cursor enters the panel icon.
240
+* A middle button click displays the New Alarm window.
242
-void TrayWindow::dragEnterEvent(QDragEnterEvent* e)
243
+void TrayWindow::slotSecondaryActivateRequested()
245
- MainWindow::executeDragEnterEvent(e);
246
+ if (mActionNew->isEnabled())
247
+ mActionNew->trigger(); // display a New Alarm dialog
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.
257
-void TrayWindow::dropEvent(QDropEvent* e)
258
+void TrayWindow::updateToolTip()
260
- MainWindow::executeDropEvent(0, e);
261
+ bool enabled = theApp()->alarmsEnabled();
263
+ if (enabled && Preferences::tooltipAlarmCount())
264
+ subTitle = tooltipAlarmText();
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/>";
273
+ subTitle += i18nc("@info:tooltip Brief: some alarms are disabled", "(Some alarms disabled)");
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);
282
+ kDebug() << subTitle;
283
+ setToolTipSubTitle(subTitle);
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
291
+* Adjust icon according to the app state.
293
-bool TrayWindow::event(QEvent* e)
294
+void TrayWindow::updateIcon()
296
- if (e->type() != QEvent::ToolTip)
297
- return KSystemTrayIcon::event(e);
298
- QHelpEvent* he = (QHelpEvent*)e;
299
- bool enabled = theApp()->alarmsEnabled();
301
- if (enabled && Preferences::tooltipAlarmCount())
302
- altext = tooltipAlarmText();
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);
309
- text = i18nc("@info:tooltip", "%1%2", KGlobal::mainComponent().aboutData()->programName(), altext);
311
- QToolTip::showText(he->globalPos(), text);
313
+ if (theApp()->alarmsEnabled()) {
314
+ setOverlayIconByName(mHaveDisabledAlarms ? "partdisabled" : QString());
316
+ setOverlayIconByName("disabled");
320
/******************************************************************************
321
@@ -353,7 +361,9 @@ QString TrayWindow::tooltipAlarmText() const
322
for (i = 0, iend = items.count(); i < iend; ++i)
324
kDebug() << "--" << (count+1) << ")" << items[i].text;
325
- text += "<br />" + items[i].text;
328
+ text += items[i].text;
329
if (++count == maxCount)
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
340
-#include <ksystemtrayicon.h>
341
+#include <kstatusnotifieritem.h>
345
@@ -35,7 +35,7 @@ class KAEvent;
347
class NewAlarmAction;
349
-class TrayWindow : public KSystemTrayIcon
350
+class TrayWindow : public KStatusNotifierItem
354
@@ -48,13 +48,9 @@ class TrayWindow : public KSystemTrayIcon
359
- virtual void dragEnterEvent(QDragEnterEvent*);
360
- virtual void dropEvent(QDropEvent*);
361
- virtual bool event(QEvent*);
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();
374
+ void updateToolTip();
377
QString tooltipAlarmText() const;
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;
391
#endif // TRAYWINDOW_H