SVN_SILENT made messages (.desktop file)
[kdepim.git] / korgac / alarmdockwindow.cpp
blob35343beb26890fe97aa85938c4bd41a6dc7a6f89
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 <KAction>
30 #include <KActionCollection>
31 #include <KConfigGroup>
32 #include <KDebug>
33 #include <KIconEffect>
34 #include <KIconLoader>
35 #include <KLocale>
36 #include <KMessageBox>
37 #include <KMenu>
38 #include <KStandardAction>
39 #include <KToolInvocation>
41 AlarmDockWindow::AlarmDockWindow()
42 : KStatusNotifierItem( 0 )
44 // Read the autostart status from the config file
45 KConfigGroup config( KGlobal::config(), "General" );
46 bool autostartSet = config.hasKey( "Autostart" );
47 bool autostart = config.readEntry( "Autostart", true );
48 bool alarmsEnabled = config.readEntry( "Enabled", true );
50 mName = i18nc( "@title:window", "KOrganizer Reminder Daemon" );
51 setToolTipTitle( mName );
52 setToolTipIconByName( QLatin1String("korgac") );
54 // Set up icons
55 KIconLoader::global()->addAppDir( QLatin1String("korgac") );
56 KIconLoader::global()->addAppDir( QLatin1String("kdepim") );
57 QString iconPath = KIconLoader::global()->iconPath( QLatin1String("korgac"), KIconLoader::Panel );
58 QIcon iconEnabled = QIcon( iconPath );
59 if ( iconEnabled.isNull() ) {
60 KMessageBox::sorry( associatedWidget(),
61 i18nc( "@info", "Cannot load system tray icon." ) );
62 } else {
63 KIconLoader loader;
64 QImage iconDisabled =
65 iconEnabled.pixmap( loader.currentSize( KIconLoader::Panel ) ).toImage();
66 KIconEffect::toGray( iconDisabled, 1.0 );
67 mIconDisabled = QIcon( QPixmap::fromImage( iconDisabled ) );
70 changeSystrayIcon( alarmsEnabled );
72 // Set up the context menu
73 mSuspendAll =
74 contextMenu()->addAction( i18nc( "@action:inmenu", "Suspend All Reminders" ), this,
75 SLOT(slotSuspendAll()) );
76 mDismissAll =
77 contextMenu()->addAction( i18nc( "@action:inmenu", "Dismiss All Reminders" ), this,
78 SLOT(slotDismissAll()) );
79 mSuspendAll->setEnabled( false );
80 mDismissAll->setEnabled( false );
82 contextMenu()->addSeparator();
83 mAlarmsEnabled =
84 contextMenu()->addAction( i18nc( "@action:inmenu", "Enable Reminders" ) );
85 connect( mAlarmsEnabled, SIGNAL(toggled(bool)), SLOT(toggleAlarmsEnabled(bool)) );
86 mAlarmsEnabled->setCheckable( true );
88 mAutostart =
89 contextMenu()->addAction( i18nc( "@action:inmenu", "Start Reminder Daemon at Login" ) );
90 connect( mAutostart, SIGNAL(toggled(bool)), SLOT(toggleAutostart(bool)) );
91 mAutostart->setCheckable( true );
93 mAlarmsEnabled->setChecked( alarmsEnabled );
94 mAutostart->setChecked( autostart );
96 // Disable standard quit behaviour. We have to intercept the quit even,
97 // if the main window is hidden.
98 KActionCollection *ac = actionCollection();
99 const char *quitName = KStandardAction::name( KStandardAction::Quit );
100 QAction *quit = ac->action( QLatin1String(quitName) );
101 if ( !quit ) {
102 kDebug() << "No Quit standard action.";
103 } else {
104 quit->disconnect( SIGNAL(triggered(bool)), this, SLOT(maybeQuit()) );
105 connect( quit, SIGNAL(activated()), SLOT(slotQuit()) );
108 mAutostartSet = autostartSet;
111 AlarmDockWindow::~AlarmDockWindow()
115 void AlarmDockWindow::slotUpdate( int reminders )
117 bool actif = ( reminders > 0 );
118 mSuspendAll->setEnabled( actif );
119 mDismissAll->setEnabled( actif );
120 if ( actif ) {
121 setToolTip( QLatin1String("korgac"), mName, i18ncp( "@info:status",
122 "There is 1 active reminder.",
123 "There are %1 active reminders.", reminders ) );
124 } else {
125 setToolTip( QLatin1String("korgac"), mName, i18nc( "@info:status", "No active reminders." ) );
129 void AlarmDockWindow::toggleAlarmsEnabled( bool checked )
131 changeSystrayIcon( checked );
133 KConfigGroup config( KGlobal::config(), "General" );
134 config.writeEntry( "Enabled", checked );
135 config.sync();
138 void AlarmDockWindow::toggleAutostart( bool checked )
140 kDebug();
141 mAutostartSet = true;
142 enableAutostart( checked );
145 void AlarmDockWindow::slotSuspendAll()
147 emit suspendAllSignal();
150 void AlarmDockWindow::slotDismissAll()
152 emit dismissAllSignal();
155 void AlarmDockWindow::enableAutostart( bool enable )
157 KConfigGroup config( KGlobal::config(), "General" );
158 config.writeEntry( "Autostart", enable );
159 config.sync();
162 void AlarmDockWindow::activate( const QPoint &pos )
164 Q_UNUSED( pos );
165 KToolInvocation::startServiceByDesktopName( QLatin1String("korganizer"), QString() );
168 void AlarmDockWindow::slotQuit()
170 if ( mAutostartSet == true ) {
171 int result = KMessageBox::warningContinueCancel(
172 associatedWidget(),
173 i18nc( "@info",
174 "Do you want to quit the KOrganizer reminder daemon?<nl/>"
175 "<note> you will not get calendar reminders unless the daemon is running.</note>" ),
176 i18nc( "@title:window", "Close KOrganizer Reminder Daemon" ),
177 KStandardGuiItem::quit() );
179 if ( result == KMessageBox::Continue ) {
180 emit quitSignal();
182 } else {
183 int result = KMessageBox::questionYesNoCancel(
184 associatedWidget(),
185 i18nc( "@info",
186 "Do you want to start the KOrganizer reminder daemon at login?<nl/>"
187 "<note> you will not get calendar reminders unless the daemon is running.</note>" ),
188 i18nc( "@title:window", "Close KOrganizer Reminder Daemon" ),
189 KGuiItem( i18nc( "@action:button start the reminder daemon", "Start" ) ),
190 KGuiItem( i18nc( "@action:button do not start the reminder daemon", "Do Not Start" ) ),
191 KStandardGuiItem::cancel(),
192 QString::fromLatin1( "AskForStartAtLogin" ) );
194 bool autostart = true;
195 if ( result == KMessageBox::No ) {
196 autostart = false;
198 enableAutostart( autostart );
200 if ( result != KMessageBox::Cancel ) {
201 emit quitSignal();
206 void AlarmDockWindow::changeSystrayIcon( bool alarmsEnabled )
208 if ( alarmsEnabled ) {
209 setIconByName( QLatin1String("korgac") );
210 } else {
211 setIconByPixmap( mIconDisabled.pixmap( 22, 22 ) );