~ubuntu-branches/ubuntu/vivid/kdepim/vivid

« back to all changes in this revision

Viewing changes to korganizer/korgac/koalarmclient.cpp

  • Committer: Package Import Robot
  • Author(s): Scott Kitterman, Jonathan Riddell, Rohan Garg, Scott Kitterman
  • Date: 2012-11-21 13:12:36 UTC
  • mfrom: (0.2.33)
  • Revision ID: package-import@ubuntu.com-20121121131236-32ijw9a2txrar80k
Tags: 4:4.9.80-0ubuntu1
[ Jonathan Riddell ]
* New upstream beta release

[ Rohan Garg ]
* Add nepomuk-core-dev to build-deps

[ Scott Kitterman ]
* Add new package, libpimcommon4
  - Add libpimcommon4.install
  - Add to debian/control, including kdepim-dbg and kdepim-dev depends
  - Add to kdepim-dev.install
* Remove usr/bin/backupmail and related files from kmail.install as they are
  not provided by upstream anymore
* Add usr/bin/pimsettingexporter and related files to kmail.install
* Add libnepomukwidgets-dev to build-depends

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
  KOrganizer Alarm Daemon Client.
3
 
 
4
 
  This file is part of KOrganizer.
 
2
  This file is part of the KDE reminder agent.
5
3
 
6
4
  Copyright (c) 2002,2003 Cornelius Schumacher <schumacher@kde.org>
7
5
 
26
24
//krazy:excludeall=kdebug because we use the korgac(check) debug area in here
27
25
 
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"
32
30
#else
34
32
#endif
35
33
#include "korgacadaptor.h"
36
34
 
 
35
#include <calendarsupport/calendar.h>
 
36
#include <calendarsupport/calendarmodel.h>
 
37
#include <calendarsupport/utils.h>
 
38
 
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>
42
 
 
43
 
#include <calendarsupport/calendar.h>
44
 
#include <calendarsupport/calendarmodel.h>
45
 
#include <calendarsupport/utils.h>
46
 
 
47
 
#include <kcalcore/calendar.h>
 
44
#include <akonadi/dbusconnectionpool.h> // fix when forwarding header is there
 
45
 
 
46
#include <KCalCore/Calendar>
48
47
 
49
48
#include <KApplication>
50
49
#include <KConfig>
67
66
  Akonadi::DBusConnectionPool::threadConnection().registerObject( "/ac", this );
68
67
  kDebug();
69
68
 
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 );
91
92
 
92
93
  KDescendantsProxyModel *flattener = new KDescendantsProxyModel(this);
93
 
  flattener->setSourceModel( calendarModel );
 
94
  flattener->setSourceModel( mCalendarModel );
94
95
 
95
 
  mCalendar = new CalendarSupport::Calendar( calendarModel, flattener,
96
 
                                     zone.isValid() ? KDateTime::Spec( zone ) : KDateTime::ClockTime );
 
96
  mCalendar =
 
97
    new CalendarSupport::Calendar( mCalendarModel, flattener,
 
98
                                   zone.isValid() ?
 
99
                                     KDateTime::Spec( zone ) :
 
100
                                     KDateTime::ClockTime );
97
101
 
98
102
  mCalendar->setObjectName( "KOrgac's calendar" );
99
103
 
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()) );
101
109
 
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() );
131
140
      }
132
141
    }
143
152
KOAlarmClient::~KOAlarmClient()
144
153
{
145
154
  delete mCalendar;
146
 
#ifndef KORGAC_AKONADI_AGENT
 
155
#if !defined(KORGAC_AKONADI_AGENT)
147
156
  delete mDocker;
148
157
  delete mDialog;
149
158
#endif
164
173
    return;
165
174
  }
166
175
 
 
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.";
 
180
    return;
 
181
  }
 
182
 
 
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 );
 
188
    bool haveData =
 
189
      mCalendarModel->data( index, CalendarSupport::CalendarModel::IsPopulatedRole ).toBool();
 
190
    if ( !haveData ) {
 
191
      kDebug(5891) << "Collections have not been populated yet; aborting check.";
 
192
      return;
 
193
    }
 
194
  }
 
195
 
167
196
  QDateTime from = mLastChecked.addSecs( 1 );
168
197
  mLastChecked = QDateTime::currentDateTime();
169
198
 
171
200
 
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 */);
175
204
 
176
205
  foreach ( const Alarm::Ptr &alarm, alarms ) {
177
206
    const QString uid = alarm->parentUid();
191
220
    return;
192
221
  }
193
222
 
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 );
218
247
#else
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();
222
251
#endif
242
271
void KOAlarmClient::quit()
243
272
{
244
273
  kDebug();
245
 
#ifndef KORGAC_AKONADI_AGENT
 
274
#if !defined(KORGAC_AKONADI_AGENT)
246
275
  kapp->quit();
247
276
#endif
248
277
}
249
278
 
250
 
#ifndef _WIN32_WCE
 
279
#if !defined(Q_WS_WINCE)
251
280
bool KOAlarmClient::commitData( QSessionManager & )
252
281
{
253
282
  emit saveAllSignal();
281
310
         end.toString();
282
311
 
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() + ')';
288
318
  }
289
319
 
297
327
 
298
328
void KOAlarmClient::hide()
299
329
{
300
 
#ifndef KORGAC_AKONADI_AGENT
 
330
#if !defined(KORGAC_AKONADI_AGENT)
301
331
  delete mDocker;
302
332
  mDocker = 0;
303
333
#endif
305
335
 
306
336
void KOAlarmClient::show()
307
337
{
308
 
#ifndef KORGAC_AKONADI_AGENT
 
338
#if !defined(KORGAC_AKONADI_AGENT)
309
339
  if ( !mDocker ) {
310
340
    if ( dockerEnabled() ) {
311
341
      mDocker = new AlarmDockWindow;