korganizer Library API Documentation

koalarmclient.cpp

00001 /* 00002 KOrganizer Alarm Daemon Client. 00003 00004 This file is part of KOrganizer. 00005 00006 Copyright (c) 2002,2003 Cornelius Schumacher 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 "koalarmclient.h" 00028 00029 #include "alarmdockwindow.h" 00030 #include "alarmdialog.h" 00031 00032 #include <libkcal/calendarresources.h> 00033 00034 #include <kstandarddirs.h> 00035 #include <kdebug.h> 00036 #include <klocale.h> 00037 #include <kapplication.h> 00038 #include <kwin.h> 00039 00040 #include <qpushbutton.h> 00041 00042 KOAlarmClient::KOAlarmClient( QObject *parent, const char *name ) 00043 : DCOPObject( "ac" ), QObject( parent, name ), 00044 mSuspendTimer( this ) 00045 { 00046 kdDebug(5890) << "KOAlarmClient::KOAlarmClient()" << endl; 00047 00048 mDocker = new AlarmDockWindow; 00049 mDocker->show(); 00050 00051 mAlarmDialog = new AlarmDialog; 00052 connect( mAlarmDialog, SIGNAL( suspendSignal( int ) ), 00053 SLOT( suspend( int ) ) ); 00054 00055 KConfig c( locate( "config", "korganizerrc" ) ); 00056 c.setGroup( "Time & Date" ); 00057 QString tz = c.readEntry( "TimeZoneId" ); 00058 kdDebug(5890) << "TimeZone: " << tz << endl; 00059 00060 mCalendar = new CalendarResources( tz ); 00061 00062 connect( &mCheckTimer, SIGNAL( timeout() ), SLOT( checkAlarms() ) ); 00063 00064 KConfig *cfg = KGlobal::config(); 00065 cfg->setGroup( "Alarms" ); 00066 int interval = cfg->readNumEntry( "Interval", 60 ); 00067 kdDebug(5890) << "KOAlarmClient check interval: " << interval << " seconds." 00068 << endl; 00069 00070 mCheckTimer.start( 1000 * interval ); // interval in seconds 00071 } 00072 00073 KOAlarmClient::~KOAlarmClient() 00074 { 00075 delete mCalendar; 00076 delete mDocker; 00077 } 00078 00079 void KOAlarmClient::checkAlarms() 00080 { 00081 KConfig *cfg = KGlobal::config(); 00082 00083 cfg->setGroup( "General" ); 00084 if ( !cfg->readBoolEntry( "Enabled", true ) ) return; 00085 00086 cfg->setGroup( "Alarms" ); 00087 QDateTime lastChecked = cfg->readDateTimeEntry( "CalendarsLastChecked" ); 00088 QDateTime from = lastChecked.addSecs( 1 ); 00089 QDateTime to = QDateTime::currentDateTime(); 00090 00091 kdDebug(5891) << "Check: " << from.toString() << " - " << to.toString() << endl; 00092 00093 QValueList<Alarm *> alarms = mCalendar->alarms( from, to ); 00094 00095 bool newEvents = false; 00096 QValueList<Alarm *>::ConstIterator it; 00097 for( it = alarms.begin(); it != alarms.end(); ++it ) { 00098 kdDebug(5891) << "ALARM: " << (*it)->parent()->summary() << endl; 00099 Event *event = mCalendar->event( (*it)->parent()->uid() ); 00100 if ( event ) { 00101 mAlarmDialog->appendEvent( event ); 00102 newEvents = true; 00103 } 00104 } 00105 if ( newEvents ) { 00106 showAlarmDialog(); 00107 } 00108 00109 cfg->writeEntry( "CalendarsLastChecked", to ); 00110 00111 cfg->sync(); 00112 } 00113 00114 void KOAlarmClient::suspend( int minutes ) 00115 { 00116 // kdDebug(5890) << "KOAlarmClient::suspend() " << minutes << " minutes" << endl; 00117 connect( &mSuspendTimer, SIGNAL( timeout() ), SLOT( showAlarmDialog() ) ); 00118 mSuspendTimer.start( 1000 * 60 * minutes, true ); 00119 } 00120 00121 void KOAlarmClient::showAlarmDialog() 00122 { 00123 mAlarmDialog->show(); 00124 mAlarmDialog->raise(); 00125 KWin::setActiveWindow( mAlarmDialog->winId() ); 00126 mAlarmDialog->actionButton( KDialogBase::User2 )->setFocus(); 00127 mAlarmDialog->eventNotification(); 00128 } 00129 00130 void KOAlarmClient::quit() 00131 { 00132 kdDebug(5890) << "KOAlarmClient::quit()" << endl; 00133 kapp->quit(); 00134 } 00135 00136 void KOAlarmClient::forceAlarmCheck() 00137 { 00138 checkAlarms(); 00139 } 00140 00141 void KOAlarmClient::dumpDebug() 00142 { 00143 KConfig *cfg = KGlobal::config(); 00144 00145 cfg->setGroup( "Alarms" ); 00146 QDateTime lastChecked = cfg->readDateTimeEntry( "CalendarsLastChecked" ); 00147 00148 kdDebug(5890) << "Last Check: " << lastChecked << endl; 00149 } 00150 00151 QStringList KOAlarmClient::dumpAlarms() 00152 { 00153 QDateTime start = QDateTime( QDateTime::currentDateTime().date(), 00154 QTime( 0, 0 ) ); 00155 QDateTime end = start.addDays( 1 ).addSecs( -1 ); 00156 00157 QStringList lst; 00158 // Don't translate, this is for debugging purposes. 00159 lst << QString("AlarmDeamon::dumpAlarms() from ") + start.toString()+ " to " + 00160 end.toString(); 00161 00162 QValueList<Alarm*> alarms = mCalendar->alarms( start, end ); 00163 QValueList<Alarm*>::ConstIterator it; 00164 for( it = alarms.begin(); it != alarms.end(); ++it ) { 00165 Alarm *a = *it; 00166 lst << QString(" ") + a->parent()->summary() + " (" 00167 + a->time().toString() + ")"; 00168 } 00169 00170 return lst; 00171 } 00172 00173 void KOAlarmClient::debugShowDialog() 00174 { 00175 showAlarmDialog(); 00176 } 00177 00178 #include "koalarmclient.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:13 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003