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 mCalendar->readConfig();
00062 mCalendar->load();
00063
00064 connect( &mCheckTimer, SIGNAL( timeout() ), SLOT( checkAlarms() ) );
00065
00066 KConfig *cfg = KGlobal::config();
00067 cfg->setGroup(
"Alarms" );
00068
int interval = cfg->readNumEntry(
"Interval", 60 );
00069 kdDebug(5890) <<
"KOAlarmClient check interval: " << interval <<
" seconds."
00070 << endl;
00071
00072 mCheckTimer.start( 1000 * interval );
00073 }
00074
00075 KOAlarmClient::~KOAlarmClient()
00076 {
00077
delete mCalendar;
00078
delete mDocker;
00079 }
00080
00081
void KOAlarmClient::checkAlarms()
00082 {
00083 KConfig *cfg = KGlobal::config();
00084
00085 cfg->setGroup(
"General" );
00086
if ( !cfg->readBoolEntry(
"Enabled",
true ) )
return;
00087
00088 cfg->setGroup(
"Alarms" );
00089
QDateTime lastChecked = cfg->readDateTimeEntry(
"CalendarsLastChecked" );
00090
QDateTime from = lastChecked.addSecs( 1 );
00091
QDateTime to = QDateTime::currentDateTime();
00092
00093 kdDebug(5891) <<
"Check: " << from.toString() <<
" - " << to.toString() << endl;
00094
00095
QValueList<Alarm *> alarms = mCalendar->alarms( from, to );
00096
00097
bool newEvents =
false;
00098
QValueList<Alarm *>::ConstIterator it;
00099
for( it = alarms.begin(); it != alarms.end(); ++it ) {
00100 kdDebug(5891) <<
"ALARM: " << (*it)->parent()->summary() << endl;
00101 Incidence *incidence = mCalendar->incidence( (*it)->parent()->uid() );
00102
if ( incidence->type() ==
"Event" ) {
00103 mAlarmDialog->appendEvent( static_cast<Event *>(incidence) );
00104 newEvents =
true;
00105 }
else if ( incidence->type() ==
"Todo" ) {
00106 mAlarmDialog->appendTodo( static_cast<Todo *>(incidence) );
00107 newEvents =
true;
00108 }
00109 }
00110
if ( newEvents ) {
00111 showAlarmDialog();
00112 }
00113
00114 cfg->writeEntry(
"CalendarsLastChecked", to );
00115
00116 cfg->sync();
00117 }
00118
00119
void KOAlarmClient::suspend(
int seconds )
00120 {
00121
00122 connect( &mSuspendTimer, SIGNAL( timeout() ), SLOT( showAlarmDialog() ) );
00123 mSuspendTimer.start( 1000 * seconds,
true );
00124 }
00125
00126
void KOAlarmClient::showAlarmDialog()
00127 {
00128 mAlarmDialog->show();
00129 mAlarmDialog->raise();
00130 KWin::forceActiveWindow( mAlarmDialog->winId() );
00131 mAlarmDialog->actionButton( KDialogBase::Ok )->setFocus();
00132 mAlarmDialog->eventNotification();
00133 }
00134
00135
void KOAlarmClient::quit()
00136 {
00137 kdDebug(5890) <<
"KOAlarmClient::quit()" << endl;
00138 kapp->quit();
00139 }
00140
00141
void KOAlarmClient::forceAlarmCheck()
00142 {
00143 checkAlarms();
00144 }
00145
00146
void KOAlarmClient::dumpDebug()
00147 {
00148 KConfig *cfg = KGlobal::config();
00149
00150 cfg->setGroup(
"Alarms" );
00151
QDateTime lastChecked = cfg->readDateTimeEntry(
"CalendarsLastChecked" );
00152
00153 kdDebug(5890) <<
"Last Check: " << lastChecked << endl;
00154 }
00155
00156
QStringList KOAlarmClient::dumpAlarms()
00157 {
00158
QDateTime start =
QDateTime( QDateTime::currentDateTime().date(),
00159
QTime( 0, 0 ) );
00160
QDateTime end = start.addDays( 1 ).addSecs( -1 );
00161
00162
QStringList lst;
00163
00164 lst <<
QString(
"AlarmDeamon::dumpAlarms() from ") + start.toString()+
" to " +
00165 end.toString();
00166
00167
QValueList<Alarm*> alarms = mCalendar->alarms( start, end );
00168
QValueList<Alarm*>::ConstIterator it;
00169
for( it = alarms.begin(); it != alarms.end(); ++it ) {
00170 Alarm *a = *it;
00171 lst <<
QString(
" ") + a->parent()->summary() +
" ("
00172 + a->time().toString() +
")";
00173 }
00174
00175
return lst;
00176 }
00177
00178
void KOAlarmClient::debugShowDialog()
00179 {
00180 showAlarmDialog();
00181 }
00182
00183
#include "koalarmclient.moc"