2
KOrganizer Alarm Daemon Client.
4
This file is part of KOrganizer.
2
This file is part of the KDE reminder agent.
6
4
Copyright (c) 2002,2003 Cornelius Schumacher <schumacher@kde.org>
26
24
//krazy:excludeall=kdebug because we use the korgac(check) debug area in here
28
26
#include "koalarmclient.h"
29
#ifndef KORGAC_AKONADI_AGENT
27
#if !defined(KORGAC_AKONADI_AGENT)
30
28
#include "alarmdialog.h"
31
29
#include "alarmdockwindow.h"
35
33
#include "korgacadaptor.h"
35
#include <calendarsupport/calendar.h>
36
#include <calendarsupport/calendarmodel.h>
37
#include <calendarsupport/utils.h>
37
39
#include <Akonadi/Item>
38
40
#include <Akonadi/ChangeRecorder>
39
41
#include <Akonadi/Session>
42
#include <Akonadi/Collection>
40
43
#include <Akonadi/ItemFetchScope>
41
#include <akonadi/dbusconnectionpool.h>
43
#include <calendarsupport/calendar.h>
44
#include <calendarsupport/calendarmodel.h>
45
#include <calendarsupport/utils.h>
47
#include <kcalcore/calendar.h>
44
#include <akonadi/dbusconnectionpool.h> // fix when forwarding header is there
46
#include <KCalCore/Calendar>
49
48
#include <KApplication>
67
66
Akonadi::DBusConnectionPool::threadConnection().registerObject( "/ac", this );
70
#ifndef KORGAC_AKONADI_AGENT
69
#if !defined(KORGAC_AKONADI_AGENT)
71
70
if ( dockerEnabled() ) {
72
71
mDocker = new AlarmDockWindow;
73
72
connect( this, SIGNAL(reminderCount(int)), mDocker, SLOT(slotUpdate(int)) );
82
81
monitor->itemFetchScope().fetchFullPayload( true );
83
82
monitor->setCollectionMonitored( Akonadi::Collection::root() );
84
83
monitor->fetchCollection( true );
85
monitor->setMimeTypeMonitored( "text/calendar", true ); // FIXME: this one should not be needed, in fact it might cause the inclusion of free/busy, notes or other unwanted stuff
84
monitor->setMimeTypeMonitored( "text/calendar", true ); // FIXME: this one should not be needed,
85
// in fact it might cause the inclusion of
86
// free/busy, notes or other unwanted junk
86
87
monitor->setMimeTypeMonitored( KCalCore::Event::eventMimeType(), true );
87
88
monitor->setMimeTypeMonitored( KCalCore::Todo::todoMimeType(), true );
88
89
monitor->setMimeTypeMonitored( KCalCore::Journal::journalMimeType(), true );
89
CalendarSupport::CalendarModel *calendarModel = new CalendarSupport::CalendarModel( monitor, this );
90
mCalendarModel = new CalendarSupport::CalendarModel( monitor, this );
90
91
//mCalendarModel->setItemPopulationStrategy( EntityTreeModel::LazyPopulation );
92
93
KDescendantsProxyModel *flattener = new KDescendantsProxyModel(this);
93
flattener->setSourceModel( calendarModel );
94
flattener->setSourceModel( mCalendarModel );
95
mCalendar = new CalendarSupport::Calendar( calendarModel, flattener,
96
zone.isValid() ? KDateTime::Spec( zone ) : KDateTime::ClockTime );
97
new CalendarSupport::Calendar( mCalendarModel, flattener,
99
KDateTime::Spec( zone ) :
100
KDateTime::ClockTime );
98
102
mCalendar->setObjectName( "KOrgac's calendar" );
100
104
connect( &mCheckTimer, SIGNAL(timeout()), SLOT(checkAlarms()) );
105
connect( mCalendarModel, SIGNAL(collectionPopulated(Akonadi::Collection::Id)),
106
SLOT(checkAlarms()) );
107
connect( mCalendarModel, SIGNAL(collectionTreeFetched(Akonadi::Collection::List)),
108
SLOT(checkAlarms()) );
102
110
KConfigGroup alarmGroup( KGlobal::config(), "Alarms" );
103
111
const int interval = alarmGroup.readEntry( "Interval", 60 );
126
134
if ( akonadiItemId >= 0 ) {
127
135
const QDateTime dt = incGroup.readEntry( "RemindAt", QDateTime() );
128
136
Akonadi::Item i = mCalendar->incidence( Akonadi::Item::fromUrl( url ).id() );
129
if ( CalendarSupport::hasIncidence( i ) && !CalendarSupport::incidence( i )->alarms().isEmpty() ) {
137
if ( CalendarSupport::hasIncidence( i ) &&
138
!CalendarSupport::incidence( i )->alarms().isEmpty() ) {
130
139
createReminder( mCalendar, i, dt, QString() );
176
// We do not want to miss any reminders, so don't perform check unless
177
// the list of collections is available.
178
if ( !mCalendarModel->isCollectionTreeFetched() ) {
179
kDebug(5891) << "CollectionTree has not been fetched yet; aborting check.";
183
// Collections also need to be populated if we want to be sure not to miss any reminders.
184
const int rowCount = mCalendarModel->rowCount();
185
for ( int row = 0; row < rowCount; ++row ) {
186
static const int column = 0;
187
const QModelIndex index = mCalendarModel->index( row, column );
189
mCalendarModel->data( index, CalendarSupport::CalendarModel::IsPopulatedRole ).toBool();
191
kDebug(5891) << "Collections have not been populated yet; aborting check.";
167
196
QDateTime from = mLastChecked.addSecs( 1 );
168
197
mLastChecked = QDateTime::currentDateTime();
172
201
const Alarm::List alarms = mCalendar->alarms( KDateTime( from, KDateTime::LocalZone ),
173
202
KDateTime( mLastChecked, KDateTime::LocalZone ),
174
true /* exclude blocked alarms */ );
203
true /* exclude blocked alarms */);
176
205
foreach ( const Alarm::Ptr &alarm, alarms ) {
177
206
const QString uid = alarm->parentUid();
194
#if !defined(Q_WS_MAEMO_5) && !defined(_WIN32_WCE) && !defined(KORGAC_AKONADI_AGENT)
223
#if !defined(Q_WS_MAEMO_5) && !defined(Q_WS_WINCE) && !defined(KORGAC_AKONADI_AGENT)
195
224
if ( !mDialog ) {
196
225
mDialog = new AlarmDialog( calendar );
197
226
connect( this, SIGNAL(saveAllSignal()), mDialog, SLOT(slotSave()) );
216
245
#if defined(Q_WS_MAEMO_5)
217
246
QMaemo5InformationBox::information( 0, incidence->summary(), QMaemo5InformationBox::NoTimeout );
219
KNotification *notify = new KNotification( "reminder", 0L, KNotification::Persistent );
248
KNotification *notify = new KNotification( "reminder", 0, KNotification::Persistent );
220
249
notify->setText( incidence->summary() );
221
250
notify->sendEvent();
283
312
Alarm::List alarms = mCalendar->alarms( start, end );
284
foreach( Alarm::Ptr a, alarms ) {
313
foreach ( Alarm::Ptr a, alarms ) {
285
314
const Akonadi::Item::Id itemId = mCalendar->itemIdForIncidenceUid( a->parentUid() );
286
const Incidence::Ptr parentIncidence = CalendarSupport::incidence( mCalendar->incidence( itemId ) );
315
const Incidence::Ptr parentIncidence =
316
CalendarSupport::incidence( mCalendar->incidence( itemId ) );
287
317
lst << QString( " " ) + parentIncidence->summary() + " (" + a->time().toString() + ')';