kalarmd Library API Documentation

alarmdockwindow.cpp

00001 /*
00002     KDE Panel docking window for KDE Alarm Daemon GUI.
00003 
00004     This file is part of the GUI interface for the KDE alarm daemon.
00005     Copyright (c) 2001 David Jarvie <software@astrojar.org.uk>
00006     Based on the original, (c) 1998, 1999 Preston Brown
00007 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with this program; if not, write to the Free Software
00020     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00021 
00022     As a special exception, permission is given to link this program
00023     with any edition of Qt, and distribute the resulting executable,
00024     without including the source code for Qt in the source distribution.
00025 */
00026 
00027 #include <stdlib.h>
00028 
00029 #include <qtooltip.h>
00030 #include <qfile.h>
00031 
00032 #include <kapplication.h>
00033 #include <kdebug.h>
00034 #include <klocale.h>
00035 #include <kiconloader.h>
00036 #include <kprocess.h>
00037 #include <kconfig.h>
00038 #include <kmessagebox.h>
00039 #include <kurl.h>
00040 #include <kstandarddirs.h>
00041 #include <dcopclient.h>
00042 
00043 #include "koalarmclient.h"
00044 #include "alarmdaemoniface_stub.h"
00045 
00046 #include "alarmdockwindow.h"
00047 #include "alarmdockwindow.moc"
00048 
00049 
00050 AlarmDockWindow::AlarmDockWindow(KOAlarmClient *client, QWidget *parent,
00051                                  const char *name)
00052   : KSystemTray(parent, name),
00053     mAlarmGui(client)
00054 {
00055   // Read the GUI autostart status from the config file
00056   KConfig* config = kapp->config();
00057   config->setGroup("General");
00058   bool autostartGui = config->readBoolEntry( "Autostart", true );
00059   bool alarmsEnabled = config->readBoolEntry( "Enabled", true );
00060 
00061   // Set up GUI icons
00062   KGlobal::iconLoader()->addAppDir( "kalarmdgui" );
00063   mPixmapEnabled  = BarIcon( "kalarmdgui" );
00064   mPixmapDisabled = BarIcon( "kalarmdgui_disabled" );
00065 
00066   setPixmap( alarmsEnabled ? mPixmapEnabled : mPixmapDisabled );
00067 
00068   // Set up the context menu
00069   mAlarmsEnabledId = contextMenu()->insertItem(i18n("Alarms Enabled"),
00070                                               this, SLOT(toggleAlarmsEnabled()));
00071   mAutostartGuiId = contextMenu()->insertItem(i18n("Start Alarm Client at Login"),
00072                                               this, SLOT(toggleGuiAutostart()));
00073   contextMenu()->insertItem( i18n("Configure Alarm Client..."), this,
00074                              SLOT( configureAlarmDaemon() ) );
00075   
00076   contextMenu()->setItemChecked(mAutostartGuiId, autostartGui);
00077   contextMenu()->setItemChecked(mAlarmsEnabledId, alarmsEnabled);
00078 }
00079 
00080 AlarmDockWindow::~AlarmDockWindow()
00081 {
00082 }
00083 
00084 
00085 /*
00086  * Called when the Alarms Enabled context menu item is selected.
00087  */
00088 void AlarmDockWindow::toggleAlarmsEnabled()
00089 {
00090   kdDebug() << "AlarmDockWindow::toggleAlarmsEnabled()" << endl;
00091 
00092   KConfig* config = kapp->config();
00093   config->setGroup("General");
00094 
00095   bool enabled = !contextMenu()->isItemChecked( mAlarmsEnabledId );
00096   contextMenu()->setItemChecked( mAlarmsEnabledId, enabled );
00097   setPixmap( enabled ? mPixmapEnabled : mPixmapDisabled );
00098 
00099   config->writeEntry( "Enabled", enabled );  
00100   config->sync();
00101 }
00102 
00103 
00104 /*
00105  * Set GUI autostart at login on or off, and set the context menu accordingly.
00106  */
00107 void AlarmDockWindow::setGuiAutostart(bool on)
00108 {
00109   kdDebug() << "setGuiAutostart()=" << int(on) << endl;
00110 
00111   KConfig* config = kapp->config();
00112   config->setGroup("General");
00113   config->writeEntry("Autostart", on);
00114   config->sync();
00115 
00116   contextMenu()->setItemChecked(mAutostartGuiId, on);
00117 }
00118 
00119 
00120 /*
00121  * Called when the mouse is clicked over the panel icon.
00122  */
00123 void AlarmDockWindow::mousePressEvent(QMouseEvent* e)
00124 {
00125   if ( e->button() == LeftButton ) {
00126     kapp->startServiceByDesktopName( "korganizer", QString::null );
00127   } else {
00128     KSystemTray::mousePressEvent( e );
00129   }
00130 }
00131 
00132 
00133 void AlarmDockWindow::closeEvent(QCloseEvent*)
00134 {
00135   kapp->quit();
00136 }
00137 
00138 void AlarmDockWindow::configureAlarmDaemon()
00139 {
00140   kapp->startServiceByDesktopName( "kcmkded", QString::null );
00141 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sat Oct 18 02:47:21 2003 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001