27 #include "koalarmclient.h"
29 #include "alarmdockwindow.h"
30 #include "alarmdialog.h"
34 #include <kstandarddirs.h>
36 #include <tdelocale.h>
37 #include <tdeapplication.h>
40 #include <tqpushbutton.h>
42 KOAlarmClient::KOAlarmClient( TQObject *parent,
const char *name )
43 : DCOPObject(
"ac" ), TQObject( parent, name ), mDialog( 0 )
45 kdDebug(5890) <<
"KOAlarmClient::KOAlarmClient()" << endl;
47 mDocker =
new AlarmDockWindow;
49 connect(
this, TQ_SIGNAL( reminderCount(
int ) ), mDocker, TQ_SLOT( slotUpdate(
int ) ) );
50 connect( mDocker, TQ_SIGNAL( quitSignal() ), TQ_SLOT( slotQuit() ) );
52 TDEConfig c( locate(
"config",
"korganizerrc" ) );
53 c.setGroup(
"Time & Date" );
54 TQString tz = c.readEntry(
"TimeZoneId" );
55 kdDebug(5890) <<
"TimeZone: " << tz << endl;
58 mCalendar->readConfig();
61 connect( &mCheckTimer, TQ_SIGNAL( timeout() ), TQ_SLOT( checkAlarms() ) );
63 TDEConfig *config = kapp->config();
64 config->setGroup(
"Alarms" );
65 int interval = config->readNumEntry(
"Interval", 60 );
66 kdDebug(5890) <<
"KOAlarmClient check interval: " << interval <<
" seconds."
68 mLastChecked = config->readDateTimeEntry(
"CalendarsLastChecked" );
71 config->setGroup(
"General" );
72 int numReminders = config->readNumEntry(
"Reminders", 0 );
73 for (
int i = 1; i <= numReminders; ++i ) {
74 TQString group( TQString(
"Incidence-%1" ).arg( i ) );
75 config->setGroup( group );
76 TQString uid = config->readEntry(
"UID" );
77 TQDateTime dt = config->readDateTimeEntry(
"RemindAt" );
78 if ( !uid.isEmpty() ) {
79 Incidence *i = mCalendar->incidence( uid );
80 if ( i && !i->
alarms().isEmpty() ) {
81 createReminder( mCalendar, i, dt, TQString() );
84 config->deleteGroup( group );
86 config->setGroup(
"General" );
88 config->writeEntry(
"Reminders", 0 );
93 mCheckTimer.start( 1000 * interval );
96 KOAlarmClient::~KOAlarmClient()
103 void KOAlarmClient::checkAlarms()
105 TDEConfig *cfg = kapp->config();
107 cfg->setGroup(
"General" );
108 if ( !cfg->readBoolEntry(
"Enabled",
true ) )
return;
110 TQDateTime from = mLastChecked.addSecs( 1 );
111 mLastChecked = TQDateTime::currentDateTime();
113 kdDebug(5891) <<
"Check: " << from.toString() <<
" - " << mLastChecked.toString() << endl;
115 TQValueList<Alarm *> alarms = mCalendar->alarms( from, mLastChecked );
117 TQValueList<Alarm *>::ConstIterator it;
118 for( it = alarms.begin(); it != alarms.end(); ++it ) {
119 kdDebug(5891) <<
"REMINDER: " << (*it)->parent()->summary() << endl;
120 Incidence *incidence = mCalendar->incidence( (*it)->parent()->uid() );
121 createReminder( mCalendar, incidence, from, (*it)->text() );
127 const TQDateTime &dt,
128 const TQString &displayText )
134 mDialog =
new AlarmDialog( calendar );
135 connect( mDialog, TQ_SIGNAL(reminderCount(
int)), mDocker, TQ_SLOT(slotUpdate(
int)) );
136 connect( mDocker, TQ_SIGNAL(suspendAllSignal()), mDialog, TQ_SLOT(suspendAll()) );
137 connect( mDocker, TQ_SIGNAL(dismissAllSignal()), mDialog, TQ_SLOT(dismissAll()) );
138 connect(
this, TQ_SIGNAL( saveAllSignal() ), mDialog, TQ_SLOT( slotSave() ) );
141 mDialog->addIncidence( incidence, dt, displayText );
146 void KOAlarmClient::slotQuit()
148 emit saveAllSignal();
153 void KOAlarmClient::saveLastCheckTime()
155 TDEConfigGroup cg( TDEGlobal::config(),
"Alarms");
156 cg.writeEntry(
"CalendarsLastChecked", mLastChecked );
157 TDEGlobal::config()->sync();
160 void KOAlarmClient::quit()
162 kdDebug(5890) <<
"KOAlarmClient::quit()" << endl;
166 bool KOAlarmClient::commitData( TQSessionManager& )
168 emit saveAllSignal();
173 void KOAlarmClient::forceAlarmCheck()
179 void KOAlarmClient::dumpDebug()
181 TDEConfig *cfg = kapp->config();
183 cfg->setGroup(
"Alarms" );
184 TQDateTime lastChecked = cfg->readDateTimeEntry(
"CalendarsLastChecked" );
186 kdDebug(5890) <<
"Last Check: " << lastChecked << endl;
189 TQStringList KOAlarmClient::dumpAlarms()
191 TQDateTime start = TQDateTime( TQDateTime::currentDateTime().date(),
193 TQDateTime end = start.addDays( 1 ).addSecs( -1 );
197 lst << TQString(
"AlarmDeamon::dumpAlarms() from ") + start.toString()+
" to " +
200 TQValueList<Alarm*> alarms = mCalendar->alarms( start, end );
201 TQValueList<Alarm*>::ConstIterator it;
202 for( it = alarms.begin(); it != alarms.end(); ++it ) {
205 + a->
time().toString() +
")";
211 void KOAlarmClient::debugShowDialog()
216 #include "koalarmclient.moc"
Incidence * parent() const
const Alarm::List & alarms() const