00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "alarmdockwindow.h"
00027 #include "koalarmclient.h"
00028
00029 #include <kactioncollection.h>
00030 #include <kdebug.h>
00031 #include <kdeversion.h>
00032 #include <klocale.h>
00033 #include <kiconloader.h>
00034 #include <kiconeffect.h>
00035 #include <kconfig.h>
00036 #include <kconfiggroup.h>
00037 #include <kurl.h>
00038 #include <kstandarddirs.h>
00039 #include <kmenu.h>
00040 #include <kmessagebox.h>
00041 #include <kaction.h>
00042 #include <kstandardaction.h>
00043 #include <ktoolinvocation.h>
00044 #include <kglobal.h>
00045
00046 #include <QFile>
00047 #include <QMouseEvent>
00048
00049 #include <stdlib.h>
00050
00051 AlarmDockWindow::AlarmDockWindow()
00052 : KSystemTrayIcon( 0 )
00053 {
00054
00055 KConfigGroup config( KGlobal::config(), "General" );
00056 bool autostartSet = config.hasKey( "Autostart" );
00057 bool autostart = config.readEntry( "Autostart", true );
00058 bool alarmsEnabled = config.readEntry( "Enabled", true );
00059
00060 mName = i18nc( "@title:window", "KOrganizer Reminder Daemon" );
00061 setToolTip( mName );
00062
00063
00064 KIconLoader::global()->addAppDir( "korgac" );
00065 KIconLoader::global()->addAppDir( "kdepim" );
00066 QString iconPath = KIconLoader::global()->iconPath( "korgac", KIconLoader::Panel );
00067 mIconEnabled = loadIcon( iconPath );
00068 if ( mIconEnabled.isNull() ) {
00069 KMessageBox::sorry( parentWidget(),
00070 i18nc( "@info", "Cannot load system tray icon." ) );
00071 } else {
00072 KIconLoader loader;
00073 QImage iconDisabled =
00074 mIconEnabled.pixmap( loader.currentSize( KIconLoader::Panel ) ).toImage();
00075 KIconEffect::toGray( iconDisabled, 1.0 );
00076 mIconDisabled = QIcon( QPixmap::fromImage( iconDisabled ) );
00077 }
00078
00079 setIcon( alarmsEnabled ? mIconEnabled : mIconDisabled );
00080
00081
00082 mSuspendAll =
00083 contextMenu()->addAction( i18nc( "@action:inmenu", "Suspend All Reminders" ), this,
00084 SLOT(slotSuspendAll()) );
00085 mDismissAll =
00086 contextMenu()->addAction( i18nc( "@action:inmenu", "Dismiss All Reminders" ), this,
00087 SLOT(slotDismissAll()) );
00088 mSuspendAll->setEnabled( false );
00089 mDismissAll->setEnabled( false );
00090
00091 contextMenu()->addSeparator();
00092 mAlarmsEnabled =
00093 contextMenu()->addAction( i18nc( "@action:inmenu", "Enable Reminders" ) );
00094 connect( mAlarmsEnabled, SIGNAL(toggled(bool)), SLOT(toggleAlarmsEnabled(bool)) );
00095 mAlarmsEnabled->setCheckable( true );
00096
00097 mAutostart =
00098 contextMenu()->addAction( i18nc( "@action:inmenu", "Start Reminder Daemon at Login" ) );
00099 connect( mAutostart, SIGNAL(toggled(bool )), SLOT(toggleAutostart(bool)) );
00100 mAutostart->setCheckable( true );
00101
00102 mAlarmsEnabled->setChecked( alarmsEnabled );
00103 mAutostart->setChecked( autostart );
00104
00105
00106
00107 KActionCollection *ac = actionCollection();
00108 const char *quitName = KStandardAction::name( KStandardAction::Quit );
00109 QAction *quit = ac->action( quitName );
00110 if ( !quit ) {
00111 kDebug() << "No Quit standard action.";
00112 } else {
00113 quit->disconnect( SIGNAL(triggered(bool)), this, SLOT(maybeQuit()) );
00114 connect( quit, SIGNAL(activated()), SLOT(slotQuit()) );
00115 }
00116
00117 connect( this, SIGNAL(activated( QSystemTrayIcon::ActivationReason )),
00118 SLOT(slotActivated( QSystemTrayIcon::ActivationReason )) );
00119
00120 setToolTip( mName );
00121 mAutostartSet = autostartSet;
00122 }
00123
00124 AlarmDockWindow::~AlarmDockWindow()
00125 {
00126 }
00127
00128 void AlarmDockWindow::slotUpdate( int reminders )
00129 {
00130 mSuspendAll->setEnabled( reminders > 0 );
00131 mDismissAll->setEnabled( reminders > 0 );
00132 if ( reminders > 0 ) {
00133 setToolTip( i18ncp( "@info:tooltip",
00134 "There is 1 active reminder.",
00135 "There are %1 active reminders.", reminders ) );
00136 } else {
00137 setToolTip( i18nc( "@info:tooltip", "No active reminders." ) );
00138 }
00139 }
00140
00141 void AlarmDockWindow::toggleAlarmsEnabled( bool checked )
00142 {
00143 kDebug();
00144
00145 setIcon( checked ? mIconEnabled : mIconDisabled );
00146
00147 KConfigGroup config( KGlobal::config(), "General" );
00148 config.writeEntry( "Enabled", checked );
00149 config.sync();
00150 }
00151
00152 void AlarmDockWindow::toggleAutostart( bool checked )
00153 {
00154 kDebug();
00155 mAutostartSet = true;
00156 enableAutostart( checked );
00157 }
00158
00159 void AlarmDockWindow::slotSuspendAll()
00160 {
00161 emit suspendAllSignal();
00162 }
00163
00164 void AlarmDockWindow::slotDismissAll()
00165 {
00166 emit dismissAllSignal();
00167 }
00168
00169 void AlarmDockWindow::enableAutostart( bool enable )
00170 {
00171 KConfigGroup config( KGlobal::config(), "General" );
00172 config.writeEntry( "Autostart", enable );
00173 config.sync();
00174 }
00175
00176 void AlarmDockWindow::slotActivated( QSystemTrayIcon::ActivationReason reason )
00177 {
00178 if ( reason == QSystemTrayIcon::Trigger ) {
00179 KToolInvocation::startServiceByDesktopName( "korganizer", QString() );
00180 }
00181 }
00182
00183 void AlarmDockWindow::slotQuit()
00184 {
00185 if ( mAutostartSet == true ) {
00186 int result = KMessageBox::questionYesNo(
00187 parentWidget(),
00188 i18nc( "@info", "Do you want to quit the KOrganizer reminder daemon "
00189 "(note that you will not get reminders whilst the daemon is not running)?" ),
00190 i18nc( "@title:window", "Close KOrganizer Reminder Daemon" ) );
00191
00192 if ( result == KMessageBox::Yes ) {
00193 emit quitSignal();
00194 }
00195 } else {
00196 int result = KMessageBox::questionYesNoCancel(
00197 parentWidget(),
00198 i18nc( "@info", "Do you want to start the KOrganizer reminder daemon at login "
00199 "(note that you will not get reminders whilst the daemon is not running)?" ),
00200 i18nc( "@title:window", "Close KOrganizer Reminder Daemon" ),
00201 KGuiItem( i18nc( "@action:button start the reminder daemon", "Start" ) ),
00202 KGuiItem( i18nc( "@action:button do not start the reminder daemon", "Do Not Start" ) ),
00203 KStandardGuiItem::cancel(),
00204 QString::fromLatin1( "AskForStartAtLogin" ) );
00205
00206 bool autostart = true;
00207 if ( result == KMessageBox::No ) {
00208 autostart = false;
00209 }
00210 enableAutostart( autostart );
00211
00212 if ( result != KMessageBox::Cancel ) {
00213 emit quitSignal();
00214 }
00215 }
00216 }
00217
00218 #include "alarmdockwindow.moc"