• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.14.10 API Reference
  • KDE Home
  • Contact Us
 

KCal Library

  • kcal
resourcecalendar.cpp
1/*
2 This file is part of the kcal library.
3
4 Copyright (c) 1998 Preston Brown <pbrown@kde.org>
5 Copyright (c) 2001-2004 Cornelius Schumacher <schumacher@kde.org>
6 Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
7 Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Library General Public
11 License as published by the Free Software Foundation; either
12 version 2 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Library General Public License for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with this library; see the file COPYING.LIB. If not, write to
21 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA.
23*/
24
25#include "resourcecalendar.h"
26
27#include <kconfig.h>
28#include <kdebug.h>
29#include <klocalizedstring.h>
30
31
32using namespace KCal;
33
34//@cond PRIVATE
35class ResourceCalendar::Private
36{
37 public:
38 Private()
39 : mResolveConflict( false ),
40 mNoReadOnlyOnLoad( false ),
41 mInhibitSave( false )
42 {}
43 bool mResolveConflict;
44 bool mNoReadOnlyOnLoad;
45 bool mInhibitSave; // true to prevent saves
46 bool mReceivedLoadError;
47 bool mReceivedSaveError;
48 QString mLastError;
49};
50//@endcond
51
52ResourceCalendar::ResourceCalendar()
53 : KRES::Resource(), d( new Private )
54{
55}
56
57ResourceCalendar::ResourceCalendar( const KConfigGroup &group )
58 : KRES::Resource( group ),
59 d( new Private )
60{
61}
62
63ResourceCalendar::~ResourceCalendar()
64{
65 delete d;
66}
67
68bool ResourceCalendar::isResolveConflictSet() const
69{
70 return d->mResolveConflict;
71}
72
73void ResourceCalendar::setResolveConflict( bool b )
74{
75 d->mResolveConflict = b;
76}
77
78QString ResourceCalendar::infoText() const
79{
80 QString txt;
81
82 txt += "<b>" + resourceName() + "</b>";
83 txt += "<br>";
84
85 KRES::Factory *factory = KRES::Factory::self( "calendar" );
86 QString t = factory->typeName( type() );
87 txt += i18n( "Type: %1", t );
88
89 addInfoText( txt );
90
91 return txt;
92}
93
94void ResourceCalendar::writeConfig( KConfigGroup &group )
95{
96 KRES::Resource::writeConfig( group );
97}
98
99Incidence *ResourceCalendar::incidence( const QString &uid )
100{
101 Incidence *i = event( uid );
102 if ( i ) {
103 return i;
104 }
105
106 i = todo( uid );
107 if ( i ) {
108 return i;
109 }
110
111 i = journal( uid );
112 return i;
113}
114
115bool ResourceCalendar::addIncidence( Incidence *incidence )
116{
117 Incidence::AddVisitor<ResourceCalendar> v( this );
118 return incidence->accept( v );
119}
120
121bool ResourceCalendar::deleteIncidence( Incidence *incidence )
122{
123 Incidence::DeleteVisitor<ResourceCalendar> v( this );
124 return incidence->accept( v );
125}
126
127Incidence::List ResourceCalendar::rawIncidences()
128{
129 return Calendar::mergeIncidenceList( rawEvents(), rawTodos(), rawJournals() );
130}
131
132void ResourceCalendar::setSubresourceActive( const QString &, bool )
133{
134}
135
136bool ResourceCalendar::removeSubresource( const QString &resource )
137{
138 Q_UNUSED( resource )
139 return true;
140}
141
142bool ResourceCalendar::addSubresource( const QString &resource, const QString &parent )
143{
144 Q_UNUSED( resource )
145 Q_UNUSED( parent )
146 return true;
147}
148
149QString ResourceCalendar::subresourceType( const QString &resource )
150{
151 Q_UNUSED( resource )
152 return QString();
153}
154
155bool ResourceCalendar::load()
156{
157 kDebug() << resourceName();
158
159 d->mReceivedLoadError = false;
160
161 bool success = true;
162 if ( !isOpen() ) {
163 success = open(); //krazy:exclude=syscalls open is a class method
164 }
165 if ( success ) {
166 success = doLoad( false );
167 }
168 if ( !success && !d->mReceivedLoadError ) {
169 loadError();
170 }
171
172 // If the resource is read-only, we need to set its incidences to read-only,
173 // too. This can't be done at a lower-level, since the read-only setting
174 // happens at this level
175 if ( !d->mNoReadOnlyOnLoad && readOnly() ) {
176 Incidence::List incidences( rawIncidences() );
177 Incidence::List::Iterator it;
178 for ( it = incidences.begin(); it != incidences.end(); ++it ) {
179 (*it)->setReadOnly( true );
180 }
181 }
182
183 kDebug() << "Done loading resource" << resourceName();
184
185 return success;
186}
187
188void ResourceCalendar::loadError( const QString &err )
189{
190 kDebug() << "Error loading resource:" << err;
191
192 d->mReceivedLoadError = true;
193
194 QString msg = i18n( "Error while loading %1.\n", resourceName() );
195 if ( !err.isEmpty() ) {
196 msg += err;
197 }
198 emit resourceLoadError( this, msg );
199}
200
201bool ResourceCalendar::receivedLoadError() const
202{
203 return d->mReceivedLoadError;
204}
205
206void ResourceCalendar::setReceivedLoadError( bool b )
207{
208 d->mReceivedLoadError = b;
209}
210
211bool ResourceCalendar::save( Incidence *incidence )
212{
213 if ( d->mInhibitSave ) {
214 return true;
215 }
216
217 if ( !readOnly() ) {
218 kDebug() << resourceName();
219
220 d->mReceivedSaveError = false;
221
222 if ( !isOpen() ) {
223 kDebug() << "Trying to save into a closed resource" << resourceName();
224 return true;
225 }
226 bool success = incidence ? doSave( false, incidence ) : doSave( false );
227 if ( !success && !d->mReceivedSaveError ) {
228 saveError();
229 }
230 return success;
231 } else {
232 // Read-only, just don't save...
233 kDebug() << "Don't save read-only resource" << resourceName();
234 return true;
235 }
236}
237
238bool ResourceCalendar::save( QString &err, Incidence *incidence )
239{
240 d->mLastError.clear();
241 bool ret = save( incidence ); // a new mLastError may be set in here
242 err = d->mLastError;
243 return ret;
244}
245
246bool ResourceCalendar::isSaving()
247{
248 return false;
249}
250
251bool ResourceCalendar::doSave( bool syncCache, Incidence *incidence )
252{
253 Q_UNUSED( incidence );
254 return doSave( syncCache );
255}
256
257void ResourceCalendar::saveError( const QString &err )
258{
259 kDebug() << "Error saving resource:" << err;
260
261 d->mReceivedSaveError = true;
262 QString msg = i18n( "Error while saving %1.\n", resourceName() );
263 if ( !err.isEmpty() ) {
264 msg += err;
265 }
266 d->mLastError = err;
267 emit resourceSaveError( this, msg );
268}
269
270QStringList ResourceCalendar::subresources() const
271{
272 return QStringList();
273}
274
275bool ResourceCalendar::canHaveSubresources() const
276{
277 return false;
278}
279
280bool ResourceCalendar::subresourceActive( const QString &resource ) const
281{
282 Q_UNUSED( resource );
283 return true;
284}
285
286QString ResourceCalendar::labelForSubresource( const QString &resource ) const
287{
288 // the resource identifier is a sane fallback
289 return resource;
290}
291
292QString ResourceCalendar::subresourceIdentifier( Incidence *incidence )
293{
294 Q_UNUSED( incidence );
295 return QString();
296}
297
298bool ResourceCalendar::receivedSaveError() const
299{
300 return d->mReceivedSaveError;
301}
302
303void ResourceCalendar::setReceivedSaveError( bool b )
304{
305 d->mReceivedSaveError = b;
306}
307
308void ResourceCalendar::setInhibitSave( bool inhibit )
309{
310 d->mInhibitSave = inhibit;
311}
312
313bool ResourceCalendar::saveInhibited() const
314{
315 return d->mInhibitSave;
316}
317
318bool ResourceCalendar::setValue( const QString &key, const QString &value )
319{
320 Q_UNUSED( key );
321 Q_UNUSED( value );
322 return false;
323}
324
325void ResourceCalendar::setNoReadOnlyOnLoad( bool noReadOnly )
326{
327 d->mNoReadOnlyOnLoad = noReadOnly;
328}
329
330bool ResourceCalendar::noReadOnlyOnLoad() const
331{
332 return d->mNoReadOnlyOnLoad;
333}
KCal::Calendar::mergeIncidenceList
static Incidence::List mergeIncidenceList(const Event::List &events, const Todo::List &todos, const Journal::List &journals)
Create a merged list of Events, Todos, and Journals.
Definition calendar.cpp:1207
KCal::IncidenceBase::accept
virtual bool accept(Visitor &v)
Accept IncidenceVisitor.
Definition incidencebase.h:228
KCal::Incidence
Provides the abstract base class common to non-FreeBusy (Events, To-dos, Journals) calendar component...
Definition incidence.h:70
KCal::ListBase
This class provides a template for lists of pointers.
Definition listbase.h:45
KCal::ResourceCalendar::setInhibitSave
void setInhibitSave(bool inhibit)
Inhibit or allow saves, overriding the save policy set by setSavePolicy().
Definition resourcecalendar.cpp:308
KCal::ResourceCalendar::resourceSaveError
void resourceSaveError(ResourceCalendar *, const QString &error)
This signal is emitted when an error occurs during saving.
KCal::ResourceCalendar::saveInhibited
bool saveInhibited() const
Return whether saves have been inhibited by setInhibitSave().
Definition resourcecalendar.cpp:313
KCal::ResourceCalendar::subresources
virtual QStringList subresources() const
If this resource has subresources, return a QStringList of them.
Definition resourcecalendar.cpp:270
KCal::ResourceCalendar::setNoReadOnlyOnLoad
void setNoReadOnlyOnLoad(bool noReadOnly)
Specify whether individual incidences should be set read-only when a read-only resource is loaded.
Definition resourcecalendar.cpp:325
KCal::ResourceCalendar::doLoad
virtual bool doLoad(bool syncCache)=0
Do the actual loading of the resource data.
KCal::ResourceCalendar::setSubresourceActive
virtual void setSubresourceActive(const QString &resource, bool active)
(De-)activate a subresource.
Definition resourcecalendar.cpp:132
KCal::ResourceCalendar::labelForSubresource
virtual QString labelForSubresource(const QString &resource) const
What is the label for this subresource?
Definition resourcecalendar.cpp:286
KCal::ResourceCalendar::subresourceIdentifier
virtual QString subresourceIdentifier(Incidence *incidence)
Get the identifier of the subresource associated with a specified incidence.
Definition resourcecalendar.cpp:292
KCal::ResourceCalendar::infoText
virtual QString infoText() const
Return rich text with info about the resource.
Definition resourcecalendar.cpp:78
KCal::ResourceCalendar::resourceLoadError
void resourceLoadError(ResourceCalendar *, const QString &error)
This signal is emitted when an error occurs during loading.
KCal::ResourceCalendar::save
bool save(Incidence *incidence=0)
Save resource data.
Definition resourcecalendar.cpp:211
KCal::ResourceCalendar::rawEvents
virtual Event::List rawEvents(EventSortField sortField=EventSortUnsorted, SortDirection sortDirection=SortDirectionAscending)=0
Return unfiltered list of all events in calendar.
KCal::ResourceCalendar::journal
virtual Journal * journal(const QString &uid)=0
Return Journal with given unique id.
KCal::ResourceCalendar::load
virtual bool load()
Load resource data.
Definition resourcecalendar.cpp:155
KCal::ResourceCalendar::addIncidence
virtual bool addIncidence(Incidence *)
Add incidence to resource.
Definition resourcecalendar.cpp:115
KCal::ResourceCalendar::removeSubresource
virtual bool removeSubresource(const QString &resource)
Remove a subresource with the id.
Definition resourcecalendar.cpp:136
KCal::ResourceCalendar::incidence
Incidence * incidence(const QString &uid)
Return incidence with given unique id.
Definition resourcecalendar.cpp:99
KCal::ResourceCalendar::addInfoText
virtual void addInfoText(QString &) const
Add info text for concrete resources.
Definition resourcecalendar.h:506
KCal::ResourceCalendar::subresourceType
virtual QString subresourceType(const QString &resource)
Returns the type of the subresource: "event", "todo", or "journal", QString if unknown/mixed.
Definition resourcecalendar.cpp:149
KCal::ResourceCalendar::rawTodos
virtual Todo::List rawTodos(TodoSortField sortField=TodoSortUnsorted, SortDirection sortDirection=SortDirectionAscending)=0
Return list of all todos.
KCal::ResourceCalendar::canHaveSubresources
virtual bool canHaveSubresources() const
Is this resource capable of having subresources or not?
Definition resourcecalendar.cpp:275
KCal::ResourceCalendar::todo
virtual Todo * todo(const QString &uid)=0
Searches todolist for an event with this unique id.
KCal::ResourceCalendar::rawJournals
virtual Journal::List rawJournals(JournalSortField sortField=JournalSortUnsorted, SortDirection sortDirection=SortDirectionAscending)=0
Return list of all journals.
KCal::ResourceCalendar::deleteIncidence
virtual bool deleteIncidence(Incidence *)
Delete incidence from resource.
Definition resourcecalendar.cpp:121
KCal::ResourceCalendar::loadError
void loadError(const QString &errorMessage=QString())
A resource should call this function if a load error happens.
Definition resourcecalendar.cpp:188
KCal::ResourceCalendar::subresourceActive
virtual bool subresourceActive(const QString &resource) const
Is this subresource active or not?
Definition resourcecalendar.cpp:280
KCal::ResourceCalendar::addSubresource
virtual bool addSubresource(const QString &resource, const QString &parent)
Add a subresource with the id.
Definition resourcecalendar.cpp:142
KCal::ResourceCalendar::noReadOnlyOnLoad
bool noReadOnlyOnLoad() const
Return whether individual incidences are inhibited from being set read-only when a read-only resource...
Definition resourcecalendar.cpp:330
KCal::ResourceCalendar::setValue
virtual bool setValue(const QString &key, const QString &value)
Sets a particular value of the resource's configuration.
Definition resourcecalendar.cpp:318
KCal::ResourceCalendar::doSave
virtual bool doSave(bool syncCache)=0
Do the actual saving of the resource data.
KCal::ResourceCalendar::event
virtual Event * event(const QString &uid)=0
Retrieves an event on the basis of the unique string ID.
KCal::ResourceCalendar::saveError
void saveError(const QString &errorMessage=QString())
A resource should call this function if a save error happens.
Definition resourcecalendar.cpp:257
KCal::ResourceCalendar::isSaving
virtual bool isSaving()
Return true if a save operation is still in progress, otherwise return false.
Definition resourcecalendar.cpp:246
KCal::ResourceCalendar::rawIncidences
Incidence::List rawIncidences()
Returns a list of all incideces.
Definition resourcecalendar.cpp:127
KRES::Factory
KRES::Factory::self
static Factory * self(const QString &resourceFamily)
KRES::Resource::open
bool open()
KRES::Resource::isOpen
bool isOpen() const
KRES::Resource::resourceName
virtual QString resourceName() const
KRES::Resource::type
QString type() const
KRES::Resource::writeConfig
virtual void writeConfig(KConfigGroup &group)
KRES::Resource::readOnly
virtual bool readOnly() const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Wed Jan 24 2024 00:00:00 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KCal Library

Skip menu "KCal Library"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepimlibs-4.14.10 API Reference

Skip menu "kdepimlibs-4.14.10 API Reference"
  • akonadi
  •   contact
  •   kmime
  •   socialutils
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  • kpimutils
  • kresources
  • ktnef
  • kxmlrpcclient
  • mailtransport
  • microblog
  • qgpgme
  • syndication
  •   atom
  •   rdf
  •   rss2
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal