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

korganizer/korgac

koalarmclient.cpp

Go to the documentation of this file.
00001 /*
00002   KOrganizer Alarm Daemon Client.
00003 
00004   This file is part of KOrganizer.
00005 
00006   Copyright (c) 2002,2003 Cornelius Schumacher <schumacher@kde.org>
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 along
00019   with this program; if not, write to the Free Software Foundation, Inc.,
00020   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 //krazy:excludeall=kdebug because we use the korgac(check) debug area in here
00027 
00028 #include "koalarmclient.h"
00029 #include "korgacadaptor.h"
00030 #include "alarmdockwindow.h"
00031 #include "alarmdialog.h"
00032 
00033 #include <kcal/calendarresources.h>
00034 
00035 #include <kstandarddirs.h>
00036 #include <kdebug.h>
00037 #include <klocale.h>
00038 #include <kdatetime.h>
00039 #include <kapplication.h>
00040 #include <kwindowsystem.h>
00041 #include <kconfiggroup.h>
00042 #include <kglobal.h>
00043 
00044 #include <QPushButton>
00045 #include <QtDBus/QtDBus>
00046 
00047 KOAlarmClient::KOAlarmClient( QObject *parent )
00048   : QObject( parent ),
00049     mDialog( 0 )
00050 {
00051   new KOrgacAdaptor( this );
00052   QDBusConnection::sessionBus().registerObject( "/ac", this );
00053   kDebug();
00054 
00055   KConfig korgConfig( KStandardDirs::locate( "config", "korganizerrc" ) );
00056   KConfigGroup generalGroup( &korgConfig, "General" );
00057   bool showDock = generalGroup.readEntry( "ShowReminderDaemon", true );
00058 
00059   mDocker = new AlarmDockWindow;
00060   if ( showDock ) {
00061     mDocker->show();
00062   } else {
00063     mDocker->hide();
00064   }
00065 
00066   connect( this, SIGNAL(reminderCount(int)), mDocker, SLOT(slotUpdate(int)) );
00067   connect( mDocker, SIGNAL(quitSignal()), SLOT(slotQuit()) );
00068 
00069   KConfigGroup timedateGroup( &korgConfig, "Time & Date" );
00070   QString tz = timedateGroup.readEntry( "TimeZoneId" );
00071   kDebug() << "TimeZone:" << tz;
00072 
00073   mCalendar = new CalendarResources( tz );
00074   mCalendar->readConfig();
00075   mCalendar->load();
00076 
00077   connect( &mCheckTimer, SIGNAL(timeout()), SLOT(checkAlarms()) );
00078 
00079   KConfigGroup alarmGroup( KGlobal::config(), "Alarms" );
00080   int interval = alarmGroup.readEntry( "Interval", 60 );
00081   kDebug() << "KOAlarmClient check interval:" << interval << "seconds.";
00082   mLastChecked = alarmGroup.readEntry( "CalendarsLastChecked", QDateTime() );
00083 
00084   // load reminders that were active when quitting
00085   KConfigGroup genGroup( KGlobal::config(), "General" );
00086   int numReminders = genGroup.readEntry( "Reminders", 0 );
00087   for ( int i=1; i<=numReminders; ++i ) {
00088     QString group( QString( "Incidence-%1" ).arg( i ) );
00089     KConfigGroup *incGroup = new KConfigGroup( KGlobal::config(), group );
00090     QString uid = incGroup->readEntry( "UID" );
00091     QDateTime dt = incGroup->readEntry( "RemindAt", QDateTime() );
00092     if ( !uid.isEmpty() ) {
00093       createReminder( mCalendar->incidence( uid ), dt );
00094     }
00095     delete incGroup;
00096   }
00097   if ( numReminders ) {
00098      genGroup.writeEntry( "Reminders", 0 );
00099      genGroup.sync();
00100   }
00101 
00102   checkAlarms();
00103   mCheckTimer.start( 1000 * interval );  // interval in seconds
00104 }
00105 
00106 KOAlarmClient::~KOAlarmClient()
00107 {
00108   delete mCalendar;
00109   delete mDocker;
00110   delete mDialog;
00111 }
00112 
00113 void KOAlarmClient::checkAlarms()
00114 {
00115   KConfigGroup cfg( KGlobal::config(), "General" );
00116 
00117   if ( !cfg.readEntry( "Enabled", true ) ) {
00118     return;
00119   }
00120 
00121   QDateTime from = mLastChecked.addSecs( 1 );
00122   mLastChecked = QDateTime::currentDateTime();
00123 
00124   kDebug(5891) << "Check:" << from.toString() << " -" << mLastChecked.toString();
00125 
00126   QList<Alarm *>alarms = mCalendar->alarms( KDateTime( from, KDateTime::LocalZone ),
00127                                             KDateTime( mLastChecked, KDateTime::LocalZone ) );
00128 
00129   QList<Alarm *>::ConstIterator it;
00130   for ( it = alarms.begin(); it != alarms.end(); ++it ) {
00131     kDebug(5891) << "REMINDER:" << (*it)->parent()->summary();
00132     Incidence *incidence = mCalendar->incidence( (*it)->parent()->uid() );
00133     createReminder( incidence, QDateTime::currentDateTime() );
00134   }
00135 }
00136 
00137 void KOAlarmClient::createReminder( KCal::Incidence *incidence,
00138                                     const QDateTime &dt )
00139 {
00140   if ( !incidence ) {
00141     return;
00142   }
00143 
00144   if ( !mDialog ) {
00145     mDialog = new AlarmDialog();
00146     connect( mDialog, SIGNAL(reminderCount(int)), mDocker, SLOT(slotUpdate(int)) );
00147     connect( mDocker, SIGNAL(suspendAllSignal()), mDialog, SLOT(suspendAll()) );
00148     connect( mDocker, SIGNAL(dismissAllSignal()), mDialog, SLOT(dismissAll()) );
00149     connect( this, SIGNAL(saveAllSignal()), mDialog, SLOT(slotSave()) );
00150   }
00151 
00152   mDialog->addIncidence( incidence, dt );
00153   mDialog->wakeUp();
00154   saveLastCheckTime();
00155 }
00156 
00157 void KOAlarmClient::slotQuit()
00158 {
00159   emit saveAllSignal();
00160   saveLastCheckTime();
00161   quit();
00162 }
00163 
00164 void KOAlarmClient::saveLastCheckTime()
00165 {
00166   KConfigGroup cg( KGlobal::config(), "Alarms" );
00167   cg.writeEntry( "CalendarsLastChecked", mLastChecked );
00168   KGlobal::config()->sync();
00169 }
00170 
00171 void KOAlarmClient::quit()
00172 {
00173   kDebug();
00174   kapp->quit();
00175 }
00176 
00177 bool KOAlarmClient::commitData( QSessionManager & )
00178 {
00179   emit saveAllSignal();
00180   saveLastCheckTime();
00181   return true;
00182 }
00183 
00184 void KOAlarmClient::forceAlarmCheck()
00185 {
00186   checkAlarms();
00187   saveLastCheckTime();
00188 }
00189 
00190 void KOAlarmClient::dumpDebug()
00191 {
00192   KConfigGroup cfg( KGlobal::config(), "Alarms" );
00193 
00194   QDateTime lastChecked = cfg.readEntry( "CalendarsLastChecked", QDateTime() );
00195 
00196   kDebug() << "Last Check:" << lastChecked;
00197 }
00198 
00199 QStringList KOAlarmClient::dumpAlarms()
00200 {
00201   KDateTime start = KDateTime( QDateTime::currentDateTime().date(),
00202                                QTime( 0, 0 ), KDateTime::LocalZone );
00203   KDateTime end = start.addDays( 1 ).addSecs( -1 );
00204 
00205   QStringList lst;
00206   // Don't translate, this is for debugging purposes.
00207   lst << QString( "AlarmDeamon::dumpAlarms() from " ) + start.toString() + " to " +
00208          end.toString();
00209 
00210   QList<Alarm *> alarms = mCalendar->alarms( start, end );
00211   QList<Alarm *>::ConstIterator it;
00212   for ( it = alarms.begin(); it != alarms.end(); ++it ) {
00213     Alarm *a = *it;
00214     lst << QString( "  " ) + a->parent()->summary() + " (" + a->time().toString() + ')';
00215   }
00216 
00217   return lst;
00218 }
00219 
00220 void KOAlarmClient::debugShowDialog()
00221 {
00222 //   showAlarmDialog();
00223 }
00224 
00225 void KOAlarmClient::hide()
00226 {
00227   mDocker->hide();
00228 }
00229 
00230 void KOAlarmClient::show()
00231 {
00232   mDocker->show();
00233 }
00234 
00235 #include "koalarmclient.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