koalarmclient.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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 );
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
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
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"
This file is part of the documentation for korganizer/korgac Library Version 3.2.2.