SVN_SILENT made messages (.desktop file) - always resolve ours
[kdepim.git] / korgac / alarmdockwindow.cpp
blobace75a52a5c3097eb3bf31e738283244f4c21727
1 /*
2 This file is part of KOrganizer.
3 This file is part of the KDE reminder agent.
5 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
6 Copyright (c) 2008-2009 Allen Winter <winter@kde.org>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 As a special exception, permission is given to link this program
23 with any edition of Qt, and distribute the resulting executable,
24 without including the source code for Qt in the source distribution.
27 #include "alarmdockwindow.h"
29 #include <QAction>
30 #include <KActionCollection>
31 #include <KConfigGroup>
32 #include <KIconEffect>
33 #include <KIconLoader>
34 #include <KLocalizedString>
35 #include <KMessageBox>
36 #include <KStandardAction>
37 #include <KToolInvocation>
38 #include <KSharedConfig>
40 #include <QMenu>
41 #include "koalarmclient_debug.h"
43 AlarmDockWindow::AlarmDockWindow()
44 : KStatusNotifierItem(0)
46 // Read the autostart status from the config file
47 KConfigGroup config(KSharedConfig::openConfig(), "General");
48 const bool autostartSet = config.hasKey("Autostart");
49 const bool autostart = config.readEntry("Autostart", true);
50 const bool alarmsEnabled = config.readEntry("Enabled", true);
52 mName = i18nc("@title:window", "KOrganizer Reminder Daemon");
53 setToolTipTitle(mName);
54 setToolTipIconByName(QStringLiteral("korgac"));
56 // Set up icons
57 KIconLoader::global()->addAppDir(QStringLiteral("korgac"));
58 QString iconPath = KIconLoader::global()->iconPath(QStringLiteral("korgac"), KIconLoader::Panel);
59 QIcon iconEnabled = QIcon(iconPath);
60 if (iconEnabled.isNull()) {
61 KMessageBox::sorry(associatedWidget(),
62 i18nc("@info", "Cannot load system tray icon."));
63 } else {
64 KIconLoader loader;
65 QImage iconDisabled =
66 iconEnabled.pixmap(loader.currentSize(KIconLoader::Panel)).toImage();
67 KIconEffect::toGray(iconDisabled, 1.0);
68 mIconDisabled = QIcon(QPixmap::fromImage(iconDisabled));
71 changeSystrayIcon(alarmsEnabled);
73 // Set up the context menu
74 mSuspendAll =
75 contextMenu()->addAction(i18nc("@action:inmenu", "Suspend All Reminders"), this,
76 SLOT(slotSuspendAll()));
77 mDismissAll =
78 contextMenu()->addAction(i18nc("@action:inmenu", "Dismiss All Reminders"), this,
79 SLOT(slotDismissAll()));
80 mSuspendAll->setEnabled(false);
81 mDismissAll->setEnabled(false);
83 contextMenu()->addSeparator();
84 mAlarmsEnabled =
85 contextMenu()->addAction(i18nc("@action:inmenu", "Enable Reminders"));
86 connect(mAlarmsEnabled, &QAction::toggled, this, &AlarmDockWindow::toggleAlarmsEnabled);
87 mAlarmsEnabled->setCheckable(true);
89 mAutostart =
90 contextMenu()->addAction(i18nc("@action:inmenu", "Start Reminder Daemon at Login"));
91 connect(mAutostart, &QAction::toggled, this, &AlarmDockWindow::toggleAutostart);
92 mAutostart->setCheckable(true);
94 mAlarmsEnabled->setChecked(alarmsEnabled);
95 mAutostart->setChecked(autostart);
97 // Disable standard quit behaviour. We have to intercept the quit even,
98 // if the main window is hidden.
99 QAction *act = action(QStringLiteral("quit"));
100 if (act) {
101 act->disconnect(SIGNAL(triggered(bool)), this, SLOT(maybeQuit()));
102 connect(act, &QAction::triggered, this, &AlarmDockWindow::slotQuit);
103 } else {
104 qCDebug(KOALARMCLIENT_LOG) << "No Quit standard action.";
106 mAutostartSet = autostartSet;
109 AlarmDockWindow::~AlarmDockWindow()
113 void AlarmDockWindow::slotUpdate(int reminders)
115 const bool actif = (reminders > 0);
116 mSuspendAll->setEnabled(actif);
117 mDismissAll->setEnabled(actif);
118 if (actif) {
119 setToolTip(QStringLiteral("korgac"), mName, i18ncp("@info:status",
120 "There is 1 active reminder.",
121 "There are %1 active reminders.", reminders));
122 } else {
123 setToolTip(QStringLiteral("korgac"), mName, i18nc("@info:status", "No active reminders."));
127 void AlarmDockWindow::toggleAlarmsEnabled(bool checked)
129 changeSystrayIcon(checked);
131 KConfigGroup config(KSharedConfig::openConfig(), "General");
132 config.writeEntry("Enabled", checked);
133 config.sync();
136 void AlarmDockWindow::toggleAutostart(bool checked)
138 qCDebug(KOALARMCLIENT_LOG);
139 mAutostartSet = true;
140 enableAutostart(checked);
143 void AlarmDockWindow::slotSuspendAll()
145 Q_EMIT suspendAllSignal();
148 void AlarmDockWindow::slotDismissAll()
150 Q_EMIT dismissAllSignal();
153 void AlarmDockWindow::enableAutostart(bool enable)
155 KConfigGroup config(KSharedConfig::openConfig(), "General");
156 config.writeEntry("Autostart", enable);
157 config.sync();
160 void AlarmDockWindow::activate(const QPoint &pos)
162 Q_UNUSED(pos);
163 KToolInvocation::startServiceByDesktopName(QStringLiteral("korganizer"), QString());
166 void AlarmDockWindow::slotQuit()
168 if (mAutostartSet == true) {
169 int result = KMessageBox::warningContinueCancel(
170 associatedWidget(),
171 xi18nc("@info",
172 "Do you want to quit the KOrganizer reminder daemon?<nl/>"
173 "<note> you will not get calendar reminders unless the daemon is running.</note>"),
174 i18nc("@title:window", "Close KOrganizer Reminder Daemon"),
175 KStandardGuiItem::quit());
177 if (result == KMessageBox::Continue) {
178 Q_EMIT quitSignal();
180 } else {
181 int result = KMessageBox::questionYesNoCancel(
182 associatedWidget(),
183 xi18nc("@info",
184 "Do you want to start the KOrganizer reminder daemon at login?<nl/>"
185 "<note> you will not get calendar reminders unless the daemon is running.</note>"),
186 i18nc("@title:window", "Close KOrganizer Reminder Daemon"),
187 KGuiItem(i18nc("@action:button start the reminder daemon", "Start")),
188 KGuiItem(i18nc("@action:button do not start the reminder daemon", "Do Not Start")),
189 KStandardGuiItem::cancel(),
190 QStringLiteral("AskForStartAtLogin"));
192 bool autostart = true;
193 if (result == KMessageBox::No) {
194 autostart = false;
196 enableAutostart(autostart);
198 if (result != KMessageBox::Cancel) {
199 Q_EMIT quitSignal();
204 void AlarmDockWindow::changeSystrayIcon(bool alarmsEnabled)
206 if (alarmsEnabled) {
207 setIconByName(QStringLiteral("korgac"));
208 } else {
209 setIconByPixmap(mIconDisabled.pixmap(22, 22));