~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to kontact/plugins/korganizer/apptsummarywidget.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "apptsummarywidget.h"
27
27
#include "korganizerplugin.h"
28
28
#include "summaryeventinfo.h"
29
 
#include "korganizer/korganizerinterface.h"
30
 
#include "korganizer/stdcalendar.h"
31
 
 
32
 
#include <KCal/CalHelper>
33
 
 
 
29
 
 
30
#include <korganizer/korganizerinterface.h>
34
31
#include <KontactInterface/Core>
35
32
 
 
33
#include <kcalcore/calendar.h>
 
34
#include <kcalcore/event.h>
 
35
 
 
36
#include <calendarsupport/calendar.h>
 
37
#include <calendarsupport/calendaradaptor.h>
 
38
#include <calendarsupport/calendarmodel.h>
 
39
#include <calendarsupport/groupware.h>
 
40
#include <calendarsupport/incidencechanger.h>
 
41
#include <calendarsupport/utils.h>
 
42
 
 
43
#include <Akonadi/ChangeRecorder>
 
44
#include <Akonadi/Session>
 
45
#include <Akonadi/Collection>
 
46
#include <Akonadi/ItemFetchScope>
 
47
#include <Akonadi/EntityDisplayAttribute>
 
48
 
 
49
#include <KSystemTimeZones>
36
50
#include <KConfigGroup>
37
51
#include <KIconLoader>
38
52
#include <KLocale>
44
58
#include <QVBoxLayout>
45
59
 
46
60
ApptSummaryWidget::ApptSummaryWidget( KOrganizerPlugin *plugin, QWidget *parent )
47
 
  : KontactInterface::Summary( parent ), mPlugin( plugin ), mCalendar( 0 )
 
61
  : KontactInterface::Summary( parent ), mCalendar( 0 ), mPlugin( plugin )
48
62
{
49
63
  QVBoxLayout *mainLayout = new QVBoxLayout( this );
50
64
  mainLayout->setSpacing( 3 );
59
73
  mLayout->setSpacing( 3 );
60
74
  mLayout->setRowStretch( 6, 1 );
61
75
 
62
 
  mCalendar = KOrg::StdCalendar::self();
 
76
  createCalendar();
63
77
 
64
 
  //If the kpart isn't created yet, it's created now, and mCalendar is loaded
65
 
  mPlugin->part();
 
78
  mChanger = new CalendarSupport::IncidenceChanger( mCalendar, parent );
66
79
 
67
80
  connect( mCalendar, SIGNAL(calendarChanged()), this, SLOT(updateView()) );
68
81
  connect( mPlugin->core(), SIGNAL(dayChanged(const QDate&)), this, SLOT(updateView()) );
123
136
        dt <= currentDate.addDays( mDaysAhead - 1 );
124
137
        dt = dt.addDays( 1 ) ) {
125
138
 
126
 
    SummaryEventInfo::List events =
127
 
        SummaryEventInfo::eventsForDate( dt, mCalendar );
 
139
    SummaryEventInfo::List events = SummaryEventInfo::eventsForDate( dt, mCalendarAdaptor );
128
140
 
129
141
    foreach ( SummaryEventInfo *event, events ) {
130
142
 
131
143
      // Optionally, show only my Events
132
 
      if ( mShowMineOnly && !CalHelper::isMyCalendarIncidence( mCalendar, event->ev ) ) {
 
144
/*      if ( mShowMineOnly && !KCalCore::CalHelper::isMyCalendarIncidence( mCalendarAdaptor, event->ev ) ) {
133
145
        continue;
134
146
      }
 
147
      TODO: CalHelper is deprecated, remove this?
 
148
*/
135
149
 
136
 
      Event *ev = event->ev;
 
150
      KCalCore::Event::Ptr ev = event->ev;
137
151
      // print the first of the recurring event series only
138
152
      if ( ev->recurs() ) {
139
153
        if ( uidList.contains( ev->uid() ) ) {
226
240
 
227
241
void ApptSummaryWidget::viewEvent( const QString &uid )
228
242
{
229
 
  mPlugin->core()->selectPlugin( "kontact_korganizerplugin" ); //ensure loaded
230
 
  OrgKdeKorganizerKorganizerInterface korganizer(
231
 
    "org.kde.korganizer", "/Korganizer", QDBusConnection::sessionBus() );
232
 
  korganizer.editIncidence( uid );
 
243
  Akonadi::Item::Id id = mCalendar->itemIdForIncidenceUid( uid );
 
244
 
 
245
  if ( id != -1 ) {
 
246
    mPlugin->core()->selectPlugin( "kontact_korganizerplugin" ); //ensure loaded
 
247
    OrgKdeKorganizerKorganizerInterface korganizer(
 
248
      "org.kde.korganizer", "/Korganizer", QDBusConnection::sessionBus() );
 
249
    korganizer.editIncidence( QString::number( id ) );
 
250
  }
233
251
}
234
252
 
235
 
void ApptSummaryWidget::removeEvent( const QString &uid )
 
253
void ApptSummaryWidget::removeEvent( const Akonadi::Item &item )
236
254
{
237
 
  mPlugin->core()->selectPlugin( "kontact_korganizerplugin" ); //ensure loaded
238
 
  OrgKdeKorganizerKorganizerInterface korganizer(
239
 
    "org.kde.korganizer", "/Korganizer", QDBusConnection::sessionBus() );
240
 
  korganizer.deleteIncidence( uid, false );
 
255
  mChanger->deleteIncidence( item );
241
256
}
242
257
 
243
258
void ApptSummaryWidget::popupMenu( const QString &uid )
244
259
{
245
260
  KMenu popup( this );
 
261
 
 
262
  // FIXME: Should say "Show Appointment" if we don't have rights to edit
 
263
  // Doesn't make sense to edit events from birthday resource for example
246
264
  QAction *editIt = popup.addAction( i18n( "&Edit Appointment..." ) );
 
265
 
247
266
  QAction *delIt = popup.addAction( i18n( "&Delete Appointment" ) );
248
267
  delIt->setIcon( KIconLoader::global()->
249
268
                  loadIcon( "edit-delete", KIconLoader::Small ) );
250
269
 
 
270
  Akonadi::Item::Id id = mCalendar->itemIdForIncidenceUid( uid );
 
271
  Akonadi::Item eventItem = mCalendar->event( id );
 
272
  delIt->setEnabled( mCalendar->hasDeleteRights( eventItem ) );
 
273
 
251
274
  const QAction *selectedAction = popup.exec( QCursor::pos() );
252
275
  if ( selectedAction == editIt ) {
253
276
    viewEvent( uid );
254
277
  } else if ( selectedAction == delIt ) {
255
 
    removeEvent( uid );
 
278
    removeEvent( eventItem );
256
279
  }
257
280
}
258
281
 
276
299
  return QStringList( "kcmapptsummary.desktop" );
277
300
}
278
301
 
 
302
void ApptSummaryWidget::createCalendar()
 
303
{
 
304
  Akonadi::Session *session = new Akonadi::Session( "ApptsSummaryWidget", this );
 
305
  Akonadi::ChangeRecorder *monitor = new Akonadi::ChangeRecorder( this );
 
306
 
 
307
  Akonadi::ItemFetchScope scope;
 
308
  scope.fetchFullPayload( true );
 
309
  scope.fetchAttribute<Akonadi::EntityDisplayAttribute>();
 
310
 
 
311
  monitor->setSession( session );
 
312
  monitor->setCollectionMonitored( Akonadi::Collection::root() );
 
313
  monitor->fetchCollection( true );
 
314
  monitor->setItemFetchScope( scope );
 
315
  monitor->setMimeTypeMonitored( KCalCore::Event::eventMimeType(), true );
 
316
 
 
317
  CalendarSupport::CalendarModel *calendarModel =
 
318
    new CalendarSupport::CalendarModel( monitor, this );
 
319
 
 
320
  mCalendar = new CalendarSupport::Calendar(
 
321
    calendarModel, calendarModel, KSystemTimeZones::local() );
 
322
 
 
323
  mCalendarAdaptor = CalendarSupport::CalendarAdaptor::Ptr(
 
324
    new CalendarSupport::CalendarAdaptor( mCalendar, this ) );
 
325
}
 
326
 
 
327
 
279
328
#include "apptsummarywidget.moc"