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 #include "alarmdockwindow.h"
00026 #include "koalarmclient.h"
00027
00028 #include <kapplication.h>
00029 #include <kdebug.h>
00030 #include <kdeversion.h>
00031 #include <klocale.h>
00032 #include <kiconloader.h>
00033 #include <kconfig.h>
00034 #include <kurl.h>
00035 #include <kstandarddirs.h>
00036 #include <dcopclient.h>
00037 #include <kpopupmenu.h>
00038 #include <kmessagebox.h>
00039 #include <kaction.h>
00040 #include <kstdaction.h>
00041
00042 #include <qtooltip.h>
00043 #include <qfile.h>
00044
00045 #include <stdlib.h>
00046
00047 AlarmDockWindow::AlarmDockWindow( const char *name )
00048 : KSystemTray( 0, name )
00049 {
00050
00051 KConfig *config = kapp->config();
00052 config->setGroup("General");
00053 bool autostart = config->readBoolEntry( "Autostart", true );
00054 bool alarmsEnabled = config->readBoolEntry( "Enabled", true );
00055
00056 mName = i18n( "KOrganizer Reminder Daemon" );
00057 setCaption( mName );
00058
00059
00060 KGlobal::iconLoader()->addAppDir( "korgac" );
00061 mPixmapEnabled = loadIcon( "korgac" );
00062 mPixmapDisabled = loadIcon( "korgac_disabled" );
00063
00064 setPixmap( alarmsEnabled ? mPixmapEnabled : mPixmapDisabled );
00065
00066
00067 mSuspendAll = contextMenu()->insertItem( i18n("Suspend All"), this, SLOT( slotSuspendAll() ) );
00068 mDismissAll = contextMenu()->insertItem( i18n("Dismiss All"), this, SLOT( slotDismissAll() ) );
00069 contextMenu()->setItemEnabled( mSuspendAll, false );
00070 contextMenu()->setItemEnabled( mDismissAll, false );
00071
00072 contextMenu()->insertSeparator();
00073 mAlarmsEnabledId = contextMenu()->insertItem( i18n("Reminders Enabled"), this,
00074 SLOT( toggleAlarmsEnabled() ) );
00075 mAutostartId = contextMenu()->insertItem( i18n("Start Reminder Daemon at Login"), this,
00076 SLOT( toggleAutostart() ) );
00077 contextMenu()->setItemChecked( mAutostartId, autostart );
00078 contextMenu()->setItemChecked( mAlarmsEnabledId, alarmsEnabled );
00079
00080
00081
00082 KActionCollection *ac = actionCollection();
00083 const char *quitName = KStdAction::name( KStdAction::Quit );
00084 KAction *quit = ac->action( quitName );
00085 if ( !quit ) {
00086 kdDebug(5890) << "No Quit standard action." << endl;
00087 } else {
00088 #if KDE_IS_VERSION(3,3,90)
00089 quit->disconnect( SIGNAL( activated() ), this,
00090 SLOT( maybeQuit() ) );
00091 connect( quit, SIGNAL( activated() ), SLOT( slotQuit() ) );
00092 }
00093 #else //FIXME: remove for KDE 4.0
00094 quit->disconnect( SIGNAL( activated() ), qApp,
00095 SLOT( closeAllWindows() ) );
00096 }
00097 connect( this, SIGNAL( quitSelected() ), SLOT( slotQuit() ) );
00098 #endif
00099
00100 QToolTip::add(this, mName );
00101 }
00102
00103 AlarmDockWindow::~AlarmDockWindow()
00104 {
00105 }
00106
00107 void AlarmDockWindow::slotUpdate( int reminders )
00108 {
00109 QToolTip::remove( this );
00110 if ( reminders > 0 )
00111 {
00112 QToolTip::add( this, i18n( "There is 1 active reminder.",
00113 "There are %n active reminders.", reminders ) );
00114 contextMenu()->setItemEnabled( mSuspendAll, true );
00115 contextMenu()->setItemEnabled( mDismissAll, true );
00116 }
00117 else
00118 {
00119 QToolTip::add( this, mName );
00120 contextMenu()->setItemEnabled( mSuspendAll, false );
00121 contextMenu()->setItemEnabled( mDismissAll, false );
00122 }
00123 }
00124
00125 void AlarmDockWindow::toggleAlarmsEnabled()
00126 {
00127 kdDebug(5890) << "AlarmDockWindow::toggleAlarmsEnabled()" << endl;
00128
00129 KConfig *config = kapp->config();
00130 config->setGroup( "General" );
00131
00132 bool enabled = !contextMenu()->isItemChecked( mAlarmsEnabledId );
00133 contextMenu()->setItemChecked( mAlarmsEnabledId, enabled );
00134 setPixmap( enabled ? mPixmapEnabled : mPixmapDisabled );
00135
00136 config->writeEntry( "Enabled", enabled );
00137 config->sync();
00138 }
00139
00140 void AlarmDockWindow::toggleAutostart()
00141 {
00142 bool autostart = !contextMenu()->isItemChecked( mAutostartId );
00143
00144 enableAutostart( autostart );
00145 }
00146
00147 void AlarmDockWindow::slotSuspendAll()
00148 {
00149 emit suspendAllSignal();
00150 }
00151
00152 void AlarmDockWindow::slotDismissAll()
00153 {
00154 emit dismissAllSignal();
00155 }
00156
00157 void AlarmDockWindow::enableAutostart( bool enable )
00158 {
00159 KConfig *config = kapp->config();
00160 config->setGroup( "General" );
00161 config->writeEntry( "Autostart", enable );
00162 config->sync();
00163
00164 contextMenu()->setItemChecked( mAutostartId, enable );
00165 }
00166
00167 void AlarmDockWindow::mousePressEvent( QMouseEvent *e )
00168 {
00169 if ( e->button() == LeftButton ) {
00170 kapp->startServiceByDesktopName( "korganizer", QString::null );
00171 } else {
00172 KSystemTray::mousePressEvent( e );
00173 }
00174 }
00175
00176
00177 void AlarmDockWindow::slotQuit()
00178 {
00179 int result = KMessageBox::questionYesNoCancel( this,
00180 i18n("Do you want to start the KOrganizer reminder daemon at login "
00181 "(note that you will not get reminders whilst the daemon is not running)?"),
00182 i18n("Close KOrganizer Reminder Daemon"),
00183 i18n("Start"), i18n("Do Not Start"),
00184 QString::fromLatin1("AskForStartAtLogin")
00185 );
00186
00187 bool autostart = true;
00188 if ( result == KMessageBox::No ) autostart = false;
00189 enableAutostart( autostart );
00190
00191 if ( result != KMessageBox::Cancel )
00192 emit quitSignal();
00193 }
00194
00195 #include "alarmdockwindow.moc"