2
Copyright (c) 2010 Kevin Ottens <ervin@kde.org>
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.
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.
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.
19
#include "groupwareintegration.h"
20
#include "editorconfig.h"
21
#include "incidencedialog.h"
22
#include "incidencedialogfactory.h"
23
#include "korganizereditorconfig.h"
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>
31
#include <Akonadi/ChangeRecorder>
32
#include <Akonadi/ItemFetchScope>
33
#include <Akonadi/Session>
35
#include <KSystemTimeZones>
37
using namespace IncidenceEditorNG;
39
namespace IncidenceEditorNG {
41
class GroupwareUiDelegate : public QObject, public CalendarSupport::GroupwareUiDelegate
48
void setCalendar( CalendarSupport::Calendar *calendar )
55
Akonadi::Session *session = new Akonadi::Session( "GroupwareIntegration", this );
56
Akonadi::ChangeRecorder *monitor = new Akonadi::ChangeRecorder( this );
58
Akonadi::ItemFetchScope scope;
59
scope.fetchFullPayload( true );
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 );
70
CalendarSupport::CalendarModel *calendarModel =
71
new CalendarSupport::CalendarModel( monitor, this );
72
calendarModel->setObjectName( "Groupware calendar model" );
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() ) );
81
void requestIncidenceEditor( const Akonadi::Item &item )
83
#ifndef KDEPIM_MOBILE_UI
84
const KCalCore::Incidence::Ptr incidence = CalendarSupport::incidence( item );
86
kWarning() << "Incidence is null, won't open the editor";
90
IncidenceEditorNG::IncidenceDialog *dialog =
91
IncidenceEditorNG::IncidenceDialogFactory::create( false /*needs initial saving?*/,
93
dialog->setIsCounterProposal( true );
94
dialog->load( item, QDate::currentDate() );
100
CalendarSupport::Calendar *mCalendar;
105
CalendarSupport::GroupwareUiDelegate* GroupwareIntegration::sDelegate = 0;
107
bool GroupwareIntegration::sActivated = false;
109
bool GroupwareIntegration::isActive()
114
void GroupwareIntegration::activate( CalendarSupport::Calendar *calendar )
117
sDelegate = new GroupwareUiDelegate;
119
EditorConfig::setEditorConfig( new KOrganizerEditorConfig );
120
CalendarSupport::Groupware::create( sDelegate );
122
sDelegate->setCalendar( calendar );
124
sDelegate->createCalendar();
129
void GroupwareIntegration::setGlobalUiDelegate( CalendarSupport::GroupwareUiDelegate *delegate )
132
sDelegate = delegate;