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"
30 #include <KActionCollection>
31 #include <KConfigGroup>
33 #include <KIconEffect>
34 #include <KIconLoader>
36 #include <KMessageBox>
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") );
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." ) );
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
74 contextMenu()->addAction( i18nc( "@action:inmenu", "Suspend All Reminders" ), this,
75 SLOT(slotSuspendAll()) );
77 contextMenu()->addAction( i18nc( "@action:inmenu", "Dismiss All Reminders" ), this,
78 SLOT(slotDismissAll()) );
79 mSuspendAll
->setEnabled( false );
80 mDismissAll
->setEnabled( false );
82 contextMenu()->addSeparator();
84 contextMenu()->addAction( i18nc( "@action:inmenu", "Enable Reminders" ) );
85 connect( mAlarmsEnabled
, SIGNAL(toggled(bool)), SLOT(toggleAlarmsEnabled(bool)) );
86 mAlarmsEnabled
->setCheckable( true );
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
) );
102 kDebug() << "No Quit standard action.";
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
);
121 setToolTip( QLatin1String("korgac"), mName
, i18ncp( "@info:status",
122 "There is 1 active reminder.",
123 "There are %1 active reminders.", reminders
) );
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
);
138 void AlarmDockWindow::toggleAutostart( bool checked
)
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
);
162 void AlarmDockWindow::activate( const QPoint
&pos
)
165 KToolInvocation::startServiceByDesktopName( QLatin1String("korganizer"), QString() );
168 void AlarmDockWindow::slotQuit()
170 if ( mAutostartSet
== true ) {
171 int result
= KMessageBox::warningContinueCancel(
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
) {
183 int result
= KMessageBox::questionYesNoCancel(
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
) {
198 enableAutostart( autostart
);
200 if ( result
!= KMessageBox::Cancel
) {
206 void AlarmDockWindow::changeSystrayIcon( bool alarmsEnabled
)
208 if ( alarmsEnabled
) {
209 setIconByName( QLatin1String("korgac") );
211 setIconByPixmap( mIconDisabled
.pixmap( 22, 22 ) );