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 <tdeapplication.h>
00029 #include <kdebug.h>
00030 #include <tdeversion.h>
00031 #include <tdelocale.h>
00032 #include <kiconloader.h>
00033 #include <tdeconfig.h>
00034 #include <kurl.h>
00035 #include <kstandarddirs.h>
00036 #include <dcopclient.h>
00037 #include <tdepopupmenu.h>
00038 #include <tdemessagebox.h>
00039 #include <tdeaction.h>
00040 #include <kstdaction.h>
00041
00042 #include <tqtooltip.h>
00043 #include <tqfile.h>
00044
00045 #include <stdlib.h>
00046
00047 AlarmDockWindow::AlarmDockWindow( const char *name )
00048 : KSystemTray( 0, name )
00049 {
00050
00051 TDEConfig *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 TDEGlobal::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, TQT_SLOT( slotSuspendAll() ) );
00068 mDismissAll = contextMenu()->insertItem( i18n("Dismiss All"), this, TQT_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 TQT_SLOT( toggleAlarmsEnabled() ) );
00075 mAutostartId = contextMenu()->insertItem( i18n("Start Reminder Daemon at Login"), this,
00076 TQT_SLOT( toggleAutostart() ) );
00077 contextMenu()->setItemChecked( mAutostartId, autostart );
00078 contextMenu()->setItemChecked( mAlarmsEnabledId, alarmsEnabled );
00079
00080
00081
00082 TDEActionCollection *ac = actionCollection();
00083 const char *quitName = KStdAction::name( KStdAction::Quit );
00084 TDEAction *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( TQT_SIGNAL( activated() ), this,
00090 TQT_SLOT( maybeQuit() ) );
00091 connect( quit, TQT_SIGNAL( activated() ), TQT_SLOT( slotQuit() ) );
00092 }
00093 #else //FIXME: remove for KDE 4.0
00094 quit->disconnect( TQT_SIGNAL( activated() ), tqApp,
00095 TQT_SLOT( closeAllWindows() ) );
00096 }
00097 connect( this, TQT_SIGNAL( quitSelected() ), TQT_SLOT( slotQuit() ) );
00098 #endif
00099
00100 TQToolTip::add(this, mName );
00101 }
00102
00103 AlarmDockWindow::~AlarmDockWindow()
00104 {
00105 }
00106
00107 void AlarmDockWindow::resizeTrayIcon ()
00108 {
00109
00110 mPixmapEnabled = loadSizedIcon( "korgac", width() );
00111 mPixmapDisabled = loadSizedIcon( "korgac_disabled", width() );
00112
00113 TDEConfig *config = kapp->config();
00114 bool alarmsEnabled = config->readBoolEntry( "Enabled", true );
00115 setPixmap( alarmsEnabled ? mPixmapEnabled : mPixmapDisabled );
00116 }
00117
00118 void AlarmDockWindow::resizeEvent ( TQResizeEvent * )
00119 {
00120 resizeTrayIcon();
00121 }
00122
00123 void AlarmDockWindow::showEvent ( TQShowEvent *se )
00124 {
00125 resizeTrayIcon();
00126 KSystemTray::showEvent(se);
00127 }
00128
00129 void AlarmDockWindow::slotUpdate( int reminders )
00130 {
00131 TQToolTip::remove( this );
00132 if ( reminders > 0 )
00133 {
00134 TQToolTip::add( this, i18n( "There is 1 active reminder.",
00135 "There are %n active reminders.", reminders ) );
00136 contextMenu()->setItemEnabled( mSuspendAll, true );
00137 contextMenu()->setItemEnabled( mDismissAll, true );
00138 }
00139 else
00140 {
00141 TQToolTip::add( this, mName );
00142 contextMenu()->setItemEnabled( mSuspendAll, false );
00143 contextMenu()->setItemEnabled( mDismissAll, false );
00144 }
00145 }
00146
00147 void AlarmDockWindow::toggleAlarmsEnabled()
00148 {
00149 kdDebug(5890) << "AlarmDockWindow::toggleAlarmsEnabled()" << endl;
00150
00151 TDEConfig *config = kapp->config();
00152 config->setGroup( "General" );
00153
00154 bool enabled = !contextMenu()->isItemChecked( mAlarmsEnabledId );
00155 contextMenu()->setItemChecked( mAlarmsEnabledId, enabled );
00156 setPixmap( enabled ? mPixmapEnabled : mPixmapDisabled );
00157
00158 config->writeEntry( "Enabled", enabled );
00159 config->sync();
00160 }
00161
00162 void AlarmDockWindow::toggleAutostart()
00163 {
00164 bool autostart = !contextMenu()->isItemChecked( mAutostartId );
00165
00166 enableAutostart( autostart );
00167 }
00168
00169 void AlarmDockWindow::slotSuspendAll()
00170 {
00171 emit suspendAllSignal();
00172 }
00173
00174 void AlarmDockWindow::slotDismissAll()
00175 {
00176 emit dismissAllSignal();
00177 }
00178
00179 void AlarmDockWindow::enableAutostart( bool enable )
00180 {
00181 TDEConfig *config = kapp->config();
00182 config->setGroup( "General" );
00183 config->writeEntry( "Autostart", enable );
00184 config->sync();
00185
00186 contextMenu()->setItemChecked( mAutostartId, enable );
00187 }
00188
00189 void AlarmDockWindow::mousePressEvent( TQMouseEvent *e )
00190 {
00191 if ( e->button() == Qt::LeftButton ) {
00192 kapp->startServiceByDesktopName( "korganizer", TQString() );
00193 } else {
00194 KSystemTray::mousePressEvent( e );
00195 }
00196 }
00197
00198
00199 void AlarmDockWindow::slotQuit()
00200 {
00201 int result = KMessageBox::questionYesNoCancel( this,
00202 i18n("Do you want to start the KOrganizer reminder daemon at login "
00203 "(note that you will not get reminders whilst the daemon is not running)?"),
00204 i18n("Close KOrganizer Reminder Daemon"),
00205 i18n("Start"), i18n("Do Not Start"),
00206 TQString::fromLatin1("AskForStartAtLogin")
00207 );
00208
00209 bool autostart = true;
00210 if ( result == KMessageBox::No ) autostart = false;
00211 enableAutostart( autostart );
00212
00213 if ( result != KMessageBox::Cancel )
00214 emit quitSignal();
00215 }
00216
00217 #include "alarmdockwindow.moc"