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

« back to all changes in this revision

Viewing changes to incidenceeditor-ng/groupwareintegration.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:
 
1
/*
 
2
  Copyright (c) 2010 Kevin Ottens <ervin@kde.org>
 
3
 
 
4
  This program is free software; you can redistribute it and/or modify
 
5
  it under the terms of the GNU General Public License as published by
 
6
  the Free Software Foundation; either version 2 of the License, or
 
7
  (at your option) any later version.
 
8
 
 
9
  This program is distributed in the hope that it will be useful,
 
10
  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
12
  GNU General Public License for more details.
 
13
 
 
14
  You should have received a copy of the GNU General Public License along
 
15
  with this program; if not, write to the Free Software Foundation, Inc.,
 
16
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
17
*/
 
18
 
 
19
#include "groupwareintegration.h"
 
20
#include "editorconfig.h"
 
21
#include "incidencedialog.h"
 
22
#include "incidencedialogfactory.h"
 
23
#include "korganizereditorconfig.h"
 
24
 
 
25
#include <calendarsupport/calendar.h>
 
26
#include <calendarsupport/calendarmodel.h>
 
27
#include <calendarsupport/groupware.h>
 
28
#include <calendarsupport/kcalprefs.h>
 
29
#include <calendarsupport/utils.h>
 
30
 
 
31
#include <Akonadi/ChangeRecorder>
 
32
#include <Akonadi/ItemFetchScope>
 
33
#include <Akonadi/Session>
 
34
 
 
35
#include <KSystemTimeZones>
 
36
 
 
37
using namespace IncidenceEditorNG;
 
38
 
 
39
namespace IncidenceEditorNG {
 
40
 
 
41
class GroupwareUiDelegate : public QObject, public CalendarSupport::GroupwareUiDelegate
 
42
{
 
43
  public:
 
44
    GroupwareUiDelegate()
 
45
    {
 
46
    }
 
47
 
 
48
    void setCalendar( CalendarSupport::Calendar *calendar )
 
49
    {
 
50
      mCalendar = calendar;
 
51
    }
 
52
 
 
53
    void createCalendar()
 
54
    {
 
55
      Akonadi::Session *session = new Akonadi::Session( "GroupwareIntegration", this );
 
56
      Akonadi::ChangeRecorder *monitor = new Akonadi::ChangeRecorder( this );
 
57
 
 
58
      Akonadi::ItemFetchScope scope;
 
59
      scope.fetchFullPayload( true );
 
60
 
 
61
      monitor->setSession( session );
 
62
      monitor->setCollectionMonitored( Akonadi::Collection::root() );
 
63
      monitor->fetchCollection( true );
 
64
      monitor->setItemFetchScope( scope );
 
65
      monitor->setMimeTypeMonitored( "text/calendar" );
 
66
      monitor->setMimeTypeMonitored( KCalCore::Event::eventMimeType(), true );
 
67
      monitor->setMimeTypeMonitored( KCalCore::Todo::todoMimeType(), true );
 
68
      monitor->setMimeTypeMonitored( KCalCore::Journal::journalMimeType(), true );
 
69
 
 
70
      CalendarSupport::CalendarModel *calendarModel =
 
71
        new CalendarSupport::CalendarModel( monitor, this );
 
72
      calendarModel->setObjectName( "Groupware calendar model" );
 
73
 
 
74
      mCalendar = new CalendarSupport::Calendar( calendarModel, calendarModel,
 
75
                                                 KSystemTimeZones::local() );
 
76
      mCalendar->setObjectName( "Groupware calendar" );
 
77
      mCalendar->setOwner( KCalCore::Person( CalendarSupport::KCalPrefs::instance()->fullName(),
 
78
                                             CalendarSupport::KCalPrefs::instance()->email() ) );
 
79
    }
 
80
 
 
81
    void requestIncidenceEditor( const Akonadi::Item &item )
 
82
    {
 
83
#ifndef KDEPIM_MOBILE_UI
 
84
      const KCalCore::Incidence::Ptr incidence = CalendarSupport::incidence( item );
 
85
      if ( !incidence ) {
 
86
        kWarning() << "Incidence is null, won't open the editor";
 
87
        return;
 
88
      }
 
89
 
 
90
      IncidenceEditorNG::IncidenceDialog *dialog =
 
91
        IncidenceEditorNG::IncidenceDialogFactory::create( false /*needs initial saving?*/,
 
92
                                                           incidence->type() );
 
93
      dialog->setIsCounterProposal( true );
 
94
      dialog->load( item, QDate::currentDate() );
 
95
#else
 
96
      Q_UNUSED( item );
 
97
#endif
 
98
    }
 
99
 
 
100
    CalendarSupport::Calendar *mCalendar;
 
101
};
 
102
 
 
103
}
 
104
 
 
105
CalendarSupport::GroupwareUiDelegate* GroupwareIntegration::sDelegate = 0;
 
106
 
 
107
bool GroupwareIntegration::sActivated = false;
 
108
 
 
109
bool GroupwareIntegration::isActive()
 
110
{
 
111
  return sActivated;
 
112
}
 
113
 
 
114
void GroupwareIntegration::activate( CalendarSupport::Calendar *calendar )
 
115
{
 
116
  if ( !sDelegate )
 
117
    sDelegate = new GroupwareUiDelegate;
 
118
 
 
119
  EditorConfig::setEditorConfig( new KOrganizerEditorConfig );
 
120
  CalendarSupport::Groupware::create( sDelegate );
 
121
  if ( calendar ) {
 
122
    sDelegate->setCalendar( calendar );
 
123
  } else {
 
124
    sDelegate->createCalendar();
 
125
  }
 
126
  sActivated = true;
 
127
}
 
128
 
 
129
void GroupwareIntegration::setGlobalUiDelegate( CalendarSupport::GroupwareUiDelegate *delegate )
 
130
{
 
131
  delete sDelegate;
 
132
  sDelegate = delegate;
 
133
}