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 QToolTip::add(
this, i18n(
"KOrganizer reminder daemon (korgac)") );
00085
00086
00087 connect(
this, SIGNAL( quitSelected() ), SLOT( slotQuit() ) );
00088 }
00089
00090 AlarmDockWindow::~AlarmDockWindow()
00091 {
00092 }
00093
00094
00095
void AlarmDockWindow::toggleAlarmsEnabled()
00096 {
00097 kdDebug(5890) <<
"AlarmDockWindow::toggleAlarmsEnabled()" << endl;
00098
00099 KConfig *config = kapp->config();
00100 config->setGroup(
"General" );
00101
00102
bool enabled = !contextMenu()->isItemChecked( mAlarmsEnabledId );
00103 contextMenu()->setItemChecked( mAlarmsEnabledId, enabled );
00104 setPixmap( enabled ? mPixmapEnabled : mPixmapDisabled );
00105
00106 config->writeEntry(
"Enabled", enabled );
00107 config->sync();
00108 }
00109
00110
void AlarmDockWindow::toggleAutostart()
00111 {
00112
bool autostart = !contextMenu()->isItemChecked( mAutostartId );
00113
00114 enableAutostart( autostart );
00115 }
00116
00117
00118
void AlarmDockWindow::enableAutostart(
bool enable )
00119 {
00120 KConfig *config = kapp->config();
00121 config->setGroup(
"General" );
00122 config->writeEntry(
"Autostart", enable );
00123 config->sync();
00124
00125 contextMenu()->setItemChecked( mAutostartId, enable );
00126 }
00127
00128
void AlarmDockWindow::mousePressEvent(
QMouseEvent *e )
00129 {
00130
if ( e->button() == LeftButton ) {
00131 kapp->startServiceByDesktopName(
"korganizer", QString::null );
00132 }
else {
00133 KSystemTray::mousePressEvent( e );
00134 }
00135 }
00136
00137
00138
void AlarmDockWindow::slotQuit()
00139 {
00140
int result = KMessageBox::questionYesNoCancel(
this,
00141 i18n(
"Do you want to start the KOrganizer alarm daemon at login "
00142
"(note that you will not get alarms whilst the daemon is not running)?"),
00143 i18n(
"Close KOrganizer Alarm Daemon"),
00144 KStdGuiItem::yes(), KStdGuiItem::no(),
00145 QString::fromLatin1(
"AskForStartAtLogin")
00146 );
00147
00148
bool autostart =
true;
00149
if ( result == KMessageBox::No ) autostart =
false;
00150 enableAutostart( autostart );
00151
00152
if ( result != KMessageBox::Cancel ) kapp->quit();
00153 }
00154
00155
#include "alarmdockwindow.moc"