korganizer Library API Documentation

alarmdockwindow.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 00004 Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of Qt, and distribute the resulting executable, 00022 without including the source code for Qt in the source distribution. 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 // Read the autostart status from the config file 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 // Set up icons 00055 KGlobal::iconLoader()->addAppDir( "korgac" ); 00056 mPixmapEnabled = loadIcon( "korgac" ); 00057 mPixmapDisabled = loadIcon( "korgac_disabled" ); 00058 00059 setPixmap( alarmsEnabled ? mPixmapEnabled : mPixmapDisabled ); 00060 00061 // Set up the context menu 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 // Disable standard quit behaviour. We have to intercept the quit even, if the 00073 // main window is hidden. 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 //void AlarmDockWindow::closeEvent( QCloseEvent * ) 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"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Aug 27 12:53:17 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003