• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdepim
  • Sitemap
  • Contact Us
 

korganizer/korgac

alarmdockwindow.cpp

Go to the documentation of this file.
00001 /*
00002   This file is part of KOrganizer.
00003 
00004   Copyright (c) 2003 Cornelius Schumacher <schumacher@kde.org>
00005   Copyright (c) 2008 Allen Winter <winter@kde.org>
00006 
00007   This program is free software; you can redistribute it and/or modify
00008   it under the terms of the GNU General Public License as published by
00009   the Free Software Foundation; either version 2 of the License, or
00010   (at your option) any later version.
00011 
00012   This program is distributed in the hope that it will be useful,
00013   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00015   GNU General Public License for more details.
00016 
00017   You should have received a copy of the GNU General Public License along
00018   with this program; if not, write to the Free Software Foundation, Inc.,
00019   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020 
00021   As a special exception, permission is given to link this program
00022   with any edition of Qt, and distribute the resulting executable,
00023   without including the source code for Qt in the source distribution.
00024 */
00025 
00026 #include "alarmdockwindow.h"
00027 #include "koalarmclient.h"
00028 
00029 #include <kactioncollection.h>
00030 #include <kdebug.h>
00031 #include <kdeversion.h>
00032 #include <klocale.h>
00033 #include <kiconloader.h>
00034 #include <kiconeffect.h>
00035 #include <kconfig.h>
00036 #include <kconfiggroup.h>
00037 #include <kurl.h>
00038 #include <kstandarddirs.h>
00039 #include <kmenu.h>
00040 #include <kmessagebox.h>
00041 #include <kaction.h>
00042 #include <kstandardaction.h>
00043 #include <ktoolinvocation.h>
00044 #include <kglobal.h>
00045 
00046 #include <QFile>
00047 #include <QMouseEvent>
00048 
00049 #include <stdlib.h>
00050 
00051 AlarmDockWindow::AlarmDockWindow()
00052   : KSystemTrayIcon( 0 )
00053 {
00054   // Read the autostart status from the config file
00055   KConfigGroup config( KGlobal::config(), "General" );
00056   bool autostartSet = config.hasKey( "Autostart" );
00057   bool autostart = config.readEntry( "Autostart", true );
00058   bool alarmsEnabled = config.readEntry( "Enabled", true );
00059 
00060   mName = i18nc( "@title:window", "KOrganizer Reminder Daemon" );
00061   setToolTip( mName );
00062 
00063   // Set up icons
00064   KIconLoader::global()->addAppDir( "korgac" );
00065   KIconLoader::global()->addAppDir( "kdepim" );
00066   QString iconPath = KIconLoader::global()->iconPath( "korgac", KIconLoader::Panel );
00067   mIconEnabled  = loadIcon( iconPath );
00068   if ( mIconEnabled.isNull() ) {
00069     KMessageBox::sorry( parentWidget(),
00070                         i18nc( "@info", "Cannot load system tray icon." ) );
00071   } else {
00072     KIconLoader loader;
00073     QImage iconDisabled =
00074       mIconEnabled.pixmap( loader.currentSize( KIconLoader::Panel ) ).toImage();
00075     KIconEffect::toGray( iconDisabled, 1.0 );
00076     mIconDisabled = QIcon( QPixmap::fromImage( iconDisabled ) );
00077   }
00078 
00079   setIcon( alarmsEnabled ? mIconEnabled : mIconDisabled );
00080 
00081   // Set up the context menu
00082   mSuspendAll =
00083     contextMenu()->addAction( i18nc( "@action:inmenu", "Suspend All Reminders" ), this,
00084                               SLOT(slotSuspendAll()) );
00085   mDismissAll =
00086     contextMenu()->addAction( i18nc( "@action:inmenu", "Dismiss All Reminders" ), this,
00087                               SLOT(slotDismissAll()) );
00088   mSuspendAll->setEnabled( false );
00089   mDismissAll->setEnabled( false );
00090 
00091   contextMenu()->addSeparator();
00092   mAlarmsEnabled =
00093     contextMenu()->addAction( i18nc( "@action:inmenu", "Enable Reminders" ) );
00094   connect( mAlarmsEnabled, SIGNAL(toggled(bool)), SLOT(toggleAlarmsEnabled(bool)) );
00095   mAlarmsEnabled->setCheckable( true );
00096 
00097   mAutostart =
00098     contextMenu()->addAction( i18nc( "@action:inmenu", "Start Reminder Daemon at Login" ) );
00099   connect( mAutostart, SIGNAL(toggled(bool )), SLOT(toggleAutostart(bool)) );
00100   mAutostart->setCheckable( true );
00101 
00102   mAlarmsEnabled->setChecked( alarmsEnabled );
00103   mAutostart->setChecked( autostart );
00104 
00105   // Disable standard quit behaviour. We have to intercept the quit even,
00106   // if the main window is hidden.
00107   KActionCollection *ac = actionCollection();
00108   const char *quitName = KStandardAction::name( KStandardAction::Quit );
00109   QAction *quit = ac->action( quitName );
00110   if ( !quit ) {
00111     kDebug() << "No Quit standard action.";
00112   } else {
00113     quit->disconnect( SIGNAL(triggered(bool)), this, SLOT(maybeQuit()) );
00114     connect( quit, SIGNAL(activated()), SLOT(slotQuit()) );
00115   }
00116 
00117   connect( this, SIGNAL(activated( QSystemTrayIcon::ActivationReason )),
00118            SLOT(slotActivated( QSystemTrayIcon::ActivationReason )) );
00119 
00120   setToolTip( mName );
00121   mAutostartSet = autostartSet;
00122 }
00123 
00124 AlarmDockWindow::~AlarmDockWindow()
00125 {
00126 }
00127 
00128 void AlarmDockWindow::slotUpdate( int reminders )
00129 {
00130   mSuspendAll->setEnabled( reminders > 0 );
00131   mDismissAll->setEnabled( reminders > 0 );
00132   if ( reminders > 0 ) {
00133     setToolTip( i18ncp( "@info:tooltip",
00134                         "There is 1 active reminder.",
00135                         "There are %1 active reminders.", reminders ) );
00136   } else {
00137     setToolTip( i18nc( "@info:tooltip", "No active reminders." ) );
00138   }
00139 }
00140 
00141 void AlarmDockWindow::toggleAlarmsEnabled( bool checked )
00142 {
00143   kDebug();
00144 
00145   setIcon( checked ? mIconEnabled : mIconDisabled );
00146 
00147   KConfigGroup config( KGlobal::config(), "General" );
00148   config.writeEntry( "Enabled", checked );
00149   config.sync();
00150 }
00151 
00152 void AlarmDockWindow::toggleAutostart( bool checked )
00153 {
00154   kDebug();
00155   mAutostartSet = true;
00156   enableAutostart( checked );
00157 }
00158 
00159 void AlarmDockWindow::slotSuspendAll()
00160 {
00161   emit suspendAllSignal();
00162 }
00163 
00164 void AlarmDockWindow::slotDismissAll()
00165 {
00166   emit dismissAllSignal();
00167 }
00168 
00169 void AlarmDockWindow::enableAutostart( bool enable )
00170 {
00171   KConfigGroup config( KGlobal::config(), "General" );
00172   config.writeEntry( "Autostart", enable );
00173   config.sync();
00174 }
00175 
00176 void AlarmDockWindow::slotActivated( QSystemTrayIcon::ActivationReason reason )
00177 {
00178   if ( reason == QSystemTrayIcon::Trigger ) {
00179     KToolInvocation::startServiceByDesktopName( "korganizer", QString() );
00180   }
00181 }
00182 
00183 void AlarmDockWindow::slotQuit()
00184 {
00185   if ( mAutostartSet == true ) {
00186     int result = KMessageBox::questionYesNo(
00187       parentWidget(),
00188       i18nc( "@info", "Do you want to quit the KOrganizer reminder daemon "
00189              "(note that you will not get reminders whilst the daemon is not running)?" ),
00190       i18nc( "@title:window", "Close KOrganizer Reminder Daemon" ) );
00191 
00192     if ( result == KMessageBox::Yes ) {
00193       emit quitSignal();
00194     }
00195   } else {
00196     int result = KMessageBox::questionYesNoCancel(
00197       parentWidget(),
00198       i18nc( "@info", "Do you want to start the KOrganizer reminder daemon at login "
00199              "(note that you will not get reminders whilst the daemon is not running)?" ),
00200       i18nc( "@title:window", "Close KOrganizer Reminder Daemon" ),
00201       KGuiItem( i18nc( "@action:button start the reminder daemon", "Start" ) ),
00202       KGuiItem( i18nc( "@action:button do not start the reminder daemon", "Do Not Start" ) ),
00203       KStandardGuiItem::cancel(),
00204       QString::fromLatin1( "AskForStartAtLogin" ) );
00205 
00206     bool autostart = true;
00207     if ( result == KMessageBox::No ) {
00208       autostart = false;
00209     }
00210     enableAutostart( autostart );
00211 
00212     if ( result != KMessageBox::Cancel ) {
00213       emit quitSignal();
00214     }
00215   }
00216 }
00217 
00218 #include "alarmdockwindow.moc"

korganizer/korgac

Skip menu "korganizer/korgac"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  •   doc
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal