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 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 //void AlarmDockWindow::closeEvent( QCloseEvent * ) 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"
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:12 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003