2
Copyright (c) 2006 Till Adam <adam@kde.org>
3
Copyright (c) 2009 David Jarvie <djarvie@kde.org>
5
This library is free software; you can redistribute it and/or modify it
6
under the terms of the GNU Library General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or (at your
8
option) any later version.
10
This library is distributed in the hope that it will be useful, but WITHOUT
11
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13
License for more details.
15
You should have received a copy of the GNU Library General Public License
16
along with this library; see the file COPYING.LIB. If not, write to the
17
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21
#include "icalresourcebase.h"
22
#include "icalsettingsadaptor.h"
23
#include "singlefileresourceconfigdialog.h"
25
#include <akonadi/dbusconnectionpool.h>
27
#include <kcalcore/filestorage.h>
28
#include <kcalcore/memorycalendar.h>
29
#include <kcalcore/incidence.h>
30
#include <kcalcore/icalformat.h>
36
using namespace Akonadi;
37
using namespace KCalCore;
38
using namespace SETTINGS_NAMESPACE;
40
ICalResourceBase::ICalResourceBase( const QString &id )
41
: SingleFileResource<Settings>( id )
43
KGlobal::locale()->insertCatalog( "akonadi_ical_resource" );
46
void ICalResourceBase::initialise( const QStringList &mimeTypes, const QString &icon )
48
setSupportedMimetypes( mimeTypes, icon );
49
new ICalSettingsAdaptor( mSettings );
50
DBusConnectionPool::threadConnection().registerObject( QLatin1String( "/Settings" ),
51
mSettings, QDBusConnection::ExportAdaptors );
54
ICalResourceBase::~ICalResourceBase()
58
bool ICalResourceBase::retrieveItem( const Akonadi::Item &item,
59
const QSet<QByteArray> &parts )
61
kDebug( 5251 ) << "Item:" << item.url();
64
emit error( i18n("Calendar not loaded.") );
68
return doRetrieveItem( item, parts );
71
void ICalResourceBase::aboutToQuit()
73
if ( !mSettings->readOnly() ) {
76
mSettings->writeConfig();
79
void ICalResourceBase::customizeConfigDialog( SingleFileResourceConfigDialog<Settings> *dlg )
81
#ifndef KDEPIM_MOBILE_UI
82
dlg->setFilter( "text/calendar" );
84
dlg->setFilter( "*.ics *.vcs" );
86
dlg->setCaption( i18n("Select Calendar") );
89
bool ICalResourceBase::readFromFile( const QString &fileName )
91
mCalendar = KCalCore::MemoryCalendar::Ptr( new KCalCore::MemoryCalendar( QLatin1String( "UTC" ) ) );
92
mFileStorage = KCalCore::FileStorage::Ptr( new KCalCore::FileStorage( mCalendar, fileName,
93
new KCalCore::ICalFormat() ) );
94
const bool result = mFileStorage->load();
96
kError() << "Error loading file " << fileName;
102
void ICalResourceBase::itemRemoved( const Akonadi::Item &item )
105
kError() << "mCalendar is 0!";
106
cancelTask( i18n("Calendar not loaded.") );
110
Incidence::Ptr i = mCalendar->incidence( item.remoteId() );
112
if ( !mCalendar->deleteIncidence( i ) ) {
113
kError() << "Can't delete incidence with uid " << item.remoteId()
114
<< "; item.id() = " << item.id();
119
kError() << "Can't find incidence with uid " << item.remoteId()
120
<< "; item.id() = " << item.id();
126
void ICalResourceBase::retrieveItems( const Akonadi::Collection &col )
130
doRetrieveItems( col );
132
kError() << "mCalendar is 0!";
136
bool ICalResourceBase::writeToFile( const QString &fileName )
139
kError() << "mCalendar is 0!";
143
KCalCore::FileStorage *fileStorage = mFileStorage.data();
144
if ( fileName != mFileStorage->fileName() ) {
145
fileStorage = new KCalCore::FileStorage( mCalendar,
147
new KCalCore::ICalFormat() );
151
if ( !fileStorage->save() ) {
152
kError() << "Failed to save calendar to file " + fileName;
153
emit error( i18n("Failed to save calendar file to %1", fileName ) );
157
if ( fileStorage != mFileStorage.data() ) {
164
KCalCore::MemoryCalendar::Ptr ICalResourceBase::calendar() const
169
KCalCore::FileStorage::Ptr ICalResourceBase::fileStorage() const
175
#include "icalresourcebase.moc"