• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdepimlibs-4.9.4 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 <klocale.h>
30 
31 #include "resourcecalendar.moc"
32 
33 using namespace KCal;
34 
35 //@cond PRIVATE
36 class ResourceCalendar::Private
37 {
38  public:
39  Private()
40  : mResolveConflict( false ),
41  mNoReadOnlyOnLoad( false ),
42  mInhibitSave( false )
43  {}
44  bool mResolveConflict;
45  bool mNoReadOnlyOnLoad;
46  bool mInhibitSave; // true to prevent saves
47  bool mReceivedLoadError;
48  bool mReceivedSaveError;
49  QString mLastError;
50 };
51 //@endcond
52 
53 ResourceCalendar::ResourceCalendar()
54  : KRES::Resource(), d( new Private )
55 {
56 }
57 
58 ResourceCalendar::ResourceCalendar( const KConfigGroup &group )
59  : KRES::Resource( group ),
60  d( new Private )
61 {
62 }
63 
64 ResourceCalendar::~ResourceCalendar()
65 {
66  delete d;
67 }
68 
69 bool ResourceCalendar::isResolveConflictSet() const
70 {
71  return d->mResolveConflict;
72 }
73 
74 void ResourceCalendar::setResolveConflict( bool b )
75 {
76  d->mResolveConflict = b;
77 }
78 
79 QString ResourceCalendar::infoText() const
80 {
81  QString txt;
82 
83  txt += "<b>" + resourceName() + "</b>";
84  txt += "<br>";
85 
86  KRES::Factory *factory = KRES::Factory::self( "calendar" );
87  QString t = factory->typeName( type() );
88  txt += i18n( "Type: %1", t );
89 
90  addInfoText( txt );
91 
92  return txt;
93 }
94 
95 void ResourceCalendar::writeConfig( KConfigGroup &group )
96 {
97  KRES::Resource::writeConfig( group );
98 }
99 
100 Incidence *ResourceCalendar::incidence( const QString &uid )
101 {
102  Incidence *i = event( uid );
103  if ( i ) {
104  return i;
105  }
106 
107  i = todo( uid );
108  if ( i ) {
109  return i;
110  }
111 
112  i = journal( uid );
113  return i;
114 }
115 
116 bool ResourceCalendar::addIncidence( Incidence *incidence )
117 {
118  Incidence::AddVisitor<ResourceCalendar> v( this );
119  return incidence->accept( v );
120 }
121 
122 bool ResourceCalendar::deleteIncidence( Incidence *incidence )
123 {
124  Incidence::DeleteVisitor<ResourceCalendar> v( this );
125  return incidence->accept( v );
126 }
127 
128 Incidence::List ResourceCalendar::rawIncidences()
129 {
130  return Calendar::mergeIncidenceList( rawEvents(), rawTodos(), rawJournals() );
131 }
132 
133 void ResourceCalendar::setSubresourceActive( const QString &, bool )
134 {
135 }
136 
137 bool ResourceCalendar::removeSubresource( const QString &resource )
138 {
139  Q_UNUSED( resource )
140  return true;
141 }
142 
143 bool ResourceCalendar::addSubresource( const QString &resource, const QString &parent )
144 {
145  Q_UNUSED( resource )
146  Q_UNUSED( parent )
147  return true;
148 }
149 
150 QString ResourceCalendar::subresourceType( const QString &resource )
151 {
152  Q_UNUSED( resource )
153  return QString();
154 }
155 
156 bool ResourceCalendar::load()
157 {
158  kDebug() << resourceName();
159 
160  d->mReceivedLoadError = false;
161 
162  bool success = true;
163  if ( !isOpen() ) {
164  success = open(); //krazy:exclude=syscalls open is a class method
165  }
166  if ( success ) {
167  success = doLoad( false );
168  }
169  if ( !success && !d->mReceivedLoadError ) {
170  loadError();
171  }
172 
173  // If the resource is read-only, we need to set its incidences to read-only,
174  // too. This can't be done at a lower-level, since the read-only setting
175  // happens at this level
176  if ( !d->mNoReadOnlyOnLoad && readOnly() ) {
177  Incidence::List incidences( rawIncidences() );
178  Incidence::List::Iterator it;
179  for ( it = incidences.begin(); it != incidences.end(); ++it ) {
180  (*it)->setReadOnly( true );
181  }
182  }
183 
184  kDebug() << "Done loading resource" << resourceName();
185 
186  return success;
187 }
188 
189 void ResourceCalendar::loadError( const QString &err )
190 {
191  kDebug() << "Error loading resource:" << err;
192 
193  d->mReceivedLoadError = true;
194 
195  QString msg = i18n( "Error while loading %1.\n", resourceName() );
196  if ( !err.isEmpty() ) {
197  msg += err;
198  }
199  emit resourceLoadError( this, msg );
200 }
201 
202 bool ResourceCalendar::receivedLoadError() const
203 {
204  return d->mReceivedLoadError;
205 }
206 
207 void ResourceCalendar::setReceivedLoadError( bool b )
208 {
209  d->mReceivedLoadError = b;
210 }
211 
212 bool ResourceCalendar::save( Incidence *incidence )
213 {
214  if ( d->mInhibitSave ) {
215  return true;
216  }
217 
218  if ( !readOnly() ) {
219  kDebug() << resourceName();
220 
221  d->mReceivedSaveError = false;
222 
223  if ( !isOpen() ) {
224  kDebug() << "Trying to save into a closed resource" << resourceName();
225  return true;
226  }
227  bool success = incidence ? doSave( false, incidence ) : doSave( false );
228  if ( !success && !d->mReceivedSaveError ) {
229  saveError();
230  }
231  return success;
232  } else {
233  // Read-only, just don't save...
234  kDebug() << "Don't save read-only resource" << resourceName();
235  return true;
236  }
237 }
238 
239 bool ResourceCalendar::save( QString &err, Incidence *incidence )
240 {
241  d->mLastError.clear();
242  bool ret = save( incidence ); // a new mLastError may be set in here
243  err = d->mLastError;
244  return ret;
245 }
246 
247 bool ResourceCalendar::isSaving()
248 {
249  return false;
250 }
251 
252 bool ResourceCalendar::doSave( bool syncCache, Incidence *incidence )
253 {
254  Q_UNUSED( incidence );
255  return doSave( syncCache );
256 }
257 
258 void ResourceCalendar::saveError( const QString &err )
259 {
260  kDebug() << "Error saving resource:" << err;
261 
262  d->mReceivedSaveError = true;
263  QString msg = i18n( "Error while saving %1.\n", resourceName() );
264  if ( !err.isEmpty() ) {
265  msg += err;
266  }
267  d->mLastError = err;
268  emit resourceSaveError( this, msg );
269 }
270 
271 QStringList ResourceCalendar::subresources() const
272 {
273  return QStringList();
274 }
275 
276 bool ResourceCalendar::canHaveSubresources() const
277 {
278  return false;
279 }
280 
281 bool ResourceCalendar::subresourceActive( const QString &resource ) const
282 {
283  Q_UNUSED( resource );
284  return true;
285 }
286 
287 QString ResourceCalendar::labelForSubresource( const QString &resource ) const
288 {
289  // the resource identifier is a sane fallback
290  return resource;
291 }
292 
293 QString ResourceCalendar::subresourceIdentifier( Incidence *incidence )
294 {
295  Q_UNUSED( incidence );
296  return QString();
297 }
298 
299 bool ResourceCalendar::receivedSaveError() const
300 {
301  return d->mReceivedSaveError;
302 }
303 
304 void ResourceCalendar::setReceivedSaveError( bool b )
305 {
306  d->mReceivedSaveError = b;
307 }
308 
309 void ResourceCalendar::setInhibitSave( bool inhibit )
310 {
311  d->mInhibitSave = inhibit;
312 }
313 
314 bool ResourceCalendar::saveInhibited() const
315 {
316  return d->mInhibitSave;
317 }
318 
319 bool ResourceCalendar::setValue( const QString &key, const QString &value )
320 {
321  Q_UNUSED( key );
322  Q_UNUSED( value );
323  return false;
324 }
325 
326 void ResourceCalendar::setNoReadOnlyOnLoad( bool noReadOnly )
327 {
328  d->mNoReadOnlyOnLoad = noReadOnly;
329 }
330 
331 bool ResourceCalendar::noReadOnlyOnLoad() const
332 {
333  return d->mNoReadOnlyOnLoad;
334 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Mon Dec 10 2012 13:48:47 by doxygen 1.8.1.2 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
  • Related Pages

kdepimlibs-4.9.4 API Reference

Skip menu "kdepimlibs-4.9.4 API Reference"
  • akonadi
  •   contact
  •   kmime
  • kabc
  • kalarmcal
  • kblog
  • kcal
  • kcalcore
  • kcalutils
  • kholidays
  • kimap
  • kioslave
  •   imap4
  •   mbox
  •   nntp
  • kldap
  • kmbox
  • kmime
  • kontactinterface
  • kpimidentities
  • kpimtextedit
  •   richtextbuilders
  • 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