alarmdockwindow.cpp
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
00027 #include <kapplication.h>
00028 #include <kdebug.h>
00029 #include <klocale.h>
00030 #include <kiconloader.h>
00031 #include <kconfig.h>
00032 #include <kurl.h>
00033 #include <kstandarddirs.h>
00034 #include <dcopclient.h>
00035 #include <kpopupmenu.h>
00036 #include <kmessagebox.h>
00037 #include <kaction.h>
00038 #include <kstdaction.h>
00039
00040 #include <qtooltip.h>
00041 #include <qfile.h>
00042
00043 #include <stdlib.h>
00044
00045 AlarmDockWindow::AlarmDockWindow( const char *name )
00046 : KSystemTray( 0, name )
00047 {
00048
00049 KConfig *config = kapp->config();
00050 config->setGroup("General");
00051 bool autostart = config->readBoolEntry( "Autostart", true );
00052 bool alarmsEnabled = config->readBoolEntry( "Enabled", true );
00053
00054
00055 KGlobal::iconLoader()->addAppDir( "korgac" );
00056 mPixmapEnabled = loadIcon( "korgac" );
00057 mPixmapDisabled = loadIcon( "korgac_disabled" );
00058
00059 setPixmap( alarmsEnabled ? mPixmapEnabled : mPixmapDisabled );
00060
00061
00062 mAlarmsEnabledId = contextMenu()->insertItem( i18n("Alarms Enabled"),
00063 this,
00064 SLOT( toggleAlarmsEnabled() ) );
00065 mAutostartId = contextMenu()->insertItem( i18n("Start Alarm Client at Login"),
00066 this,
00067 SLOT( toggleAutostart() ) );
00068
00069 contextMenu()->setItemChecked( mAutostartId, autostart );
00070 contextMenu()->setItemChecked( mAlarmsEnabledId, alarmsEnabled );
00071
00072
00073
00074 KActionCollection *ac = actionCollection();
00075 const char *quitName = KStdAction::name( KStdAction::Quit );
00076 KAction *quit = ac->action( quitName );
00077 if ( !quit ) {
00078 kdDebug(5890) << "No Quit standard action." << endl;
00079 } else {
00080 quit->disconnect( SIGNAL( activated() ), qApp,
00081 SLOT( closeAllWindows() ) );
00082 }
00083
00084 connect( this, SIGNAL( quitSelected() ), SLOT( slotQuit() ) );
00085 }
00086
00087 AlarmDockWindow::~AlarmDockWindow()
00088 {
00089 }
00090
00091
00092 void AlarmDockWindow::toggleAlarmsEnabled()
00093 {
00094 kdDebug(5890) << "AlarmDockWindow::toggleAlarmsEnabled()" << endl;
00095
00096 KConfig *config = kapp->config();
00097 config->setGroup( "General" );
00098
00099 bool enabled = !contextMenu()->isItemChecked( mAlarmsEnabledId );
00100 contextMenu()->setItemChecked( mAlarmsEnabledId, enabled );
00101 setPixmap( enabled ? mPixmapEnabled : mPixmapDisabled );
00102
00103 config->writeEntry( "Enabled", enabled );
00104 config->sync();
00105 }
00106
00107 void AlarmDockWindow::toggleAutostart()
00108 {
00109 bool autostart = !contextMenu()->isItemChecked( mAutostartId );
00110
00111 enableAutostart( autostart );
00112 }
00113
00114
00115 void AlarmDockWindow::enableAutostart( bool enable )
00116 {
00117 KConfig *config = kapp->config();
00118 config->setGroup( "General" );
00119 config->writeEntry( "Autostart", enable );
00120 config->sync();
00121
00122 contextMenu()->setItemChecked( mAutostartId, enable );
00123 }
00124
00125 void AlarmDockWindow::mousePressEvent( QMouseEvent *e )
00126 {
00127 if ( e->button() == LeftButton ) {
00128 kapp->startServiceByDesktopName( "korganizer", QString::null );
00129 } else {
00130 KSystemTray::mousePressEvent( e );
00131 }
00132 }
00133
00134
00135 void AlarmDockWindow::slotQuit()
00136 {
00137 int result = KMessageBox::questionYesNoCancel( this,
00138 i18n("Do you want to start the KOrganizer alarm daemon at login "
00139 "(Note that you won't get alarms when the daemon isn't running)?"),
00140 i18n("Close KOrganizer Alarm Daemon") );
00141
00142 bool autostart = true;
00143 if ( result == KMessageBox::No ) autostart = false;
00144 enableAutostart( autostart );
00145
00146 if ( result != KMessageBox::Cancel ) kapp->quit();
00147 }
00148
00149 #include "alarmdockwindow.moc"
This file is part of the documentation for korganizer/korgac Library Version 3.2.2.