libkcal

resourcecalendar.cpp
1 /*
2  This file is part of libkcal.
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 <tdeconfig.h>
26 #include <kdebug.h>
27 #include <tdelocale.h>
28 
29 #include "calendar.h"
30 
31 #include "resourcecalendar.h"
32 
33 using namespace KCal;
34 
35 ResourceCalendar::ResourceCalendar( const TDEConfig *config )
36  : KRES::Resource( config ), mResolveConflict( false )
37 {
38  mException = 0;
39 }
40 
41 ResourceCalendar::~ResourceCalendar()
42 {
43  delete mException;
44 }
45 
47 {
48  delete mException;
49  mException = 0;
50 }
51 
53 {
54  delete mException;
55  mException = exception;
56 }
57 
59 {
60  return mException;
61 }
62 
63 void ResourceCalendar::setResolveConflict( bool b)
64 {
65  mResolveConflict = b;
66 }
67 
69 {
70  TQString txt;
71 
72  txt += "<b>" + resourceName() + "</b>";
73  txt += "<br>";
74 
75  KRES::Factory *factory = KRES::Factory::self( "calendar" );
76  TQString t = factory->typeName( type() );
77  txt += i18n("Type: %1").arg( t );
78 
79  addInfoText( txt );
80 
81  return txt;
82 }
83 
84 void ResourceCalendar::writeConfig( TDEConfig* config )
85 {
86 // kdDebug(5800) << "ResourceCalendar::writeConfig()" << endl;
87 
88  KRES::Resource::writeConfig( config );
89 }
90 
91 Incidence *ResourceCalendar::incidence( const TQString &uid )
92 {
93  Incidence *i = event( uid );
94  if ( i ) return i;
95  i = todo( uid );
96  if ( i ) return i;
97  i = journal( uid );
98  return i;
99 }
100 
102 {
104  return incidence->accept( v );
105 }
106 
107 bool ResourceCalendar::addIncidence( Incidence *incidence, const TQString &subresource )
108 {
110  return incidence->accept( v );
111 }
112 
114 {
116  return incidence->accept( v );
117 }
118 
120 {
122 }
123 
124 void ResourceCalendar::setSubresourceActive( const TQString &, bool )
125 {
126 }
127 
128 bool ResourceCalendar::addSubresource( const TQString &, const TQString & )
129 {
130  return true;
131 }
132 
133 bool ResourceCalendar::removeSubresource( const TQString & )
134 {
135  return true;
136 }
137 
139 {
140  kdDebug(5800) << "Loading resource " + resourceName() << endl;
141 
142  mReceivedLoadError = false;
143 
144  bool success = true;
145  if ( !isOpen() )
146  success = open();
147  if ( success )
148  success = doLoad();
149 
150  if ( !success && !mReceivedLoadError )
151  loadError();
152 
153  // If the resource is read-only, we need to set its incidences to read-only,
154  // too. This can't be done at a lower-level, since the read-only setting
155  // happens at this level
156  if ( readOnly() ) {
157  Incidence::List incidences( rawIncidences() );
158  Incidence::List::Iterator it;
159  for ( it = incidences.begin(); it != incidences.end(); ++it ) {
160  (*it)->setReadOnly( true );
161  }
162  }
163 
164  kdDebug(5800) << "Done loading resource " + resourceName() << endl;
165 
166  return success;
167 }
168 
169 void ResourceCalendar::loadError( const TQString &err )
170 {
171  kdDebug(5800) << "Error loading resource: " << err << endl;
172 
173  mReceivedLoadError = true;
174 
175  TQString msg = i18n("Error while loading %1.\n") .arg( resourceName() );
176  if ( !err.isEmpty() ) {
177  msg += err;
178  }
179  emit resourceLoadError( this, msg );
180 }
181 
183 {
184  if ( !readOnly() ) {
185  kdDebug(5800) << "Save resource " + resourceName() << endl;
186 
187  mReceivedSaveError = false;
188 
189  if ( !isOpen() ) return true;
190  bool success = incidence ? doSave(incidence) : doSave();
191  if ( !success && !mReceivedSaveError ) saveError();
192 
193  return success;
194  } else {
195  // Read-only, just don't save...
196  kdDebug(5800) << "Don't save read-only resource " + resourceName() << endl;
197  return true;
198  }
199 }
200 
202 {
203  return doSave();
204 }
205 
206 void ResourceCalendar::saveError( const TQString &err )
207 {
208  kdDebug(5800) << "Error saving resource: " << err << endl;
209 
210  mReceivedSaveError = true;
211 
212  TQString msg = i18n("Error while saving %1.\n") .arg( resourceName() );
213  if ( !err.isEmpty() ) {
214  msg += err;
215  }
216  emit resourceSaveError( this, msg );
217 }
218 
219 bool ResourceCalendar::setValue( const TQString &key, const TQString &value )
220 {
221  Q_UNUSED( key );
222  Q_UNUSED( value );
223  return false;
224 }
225 
226 TQString ResourceCalendar::subresourceType( const TQString &resource )
227 {
228  Q_UNUSED( resource );
229  return TQString();
230 }
231 
232 bool ResourceCalendar::subresourceWritable( const TQString &resource ) const
233 {
234  if ( resource.isEmpty() ) {
235  return !readOnly();
236  } else {
237  return false;
238  }
239 }
240 
242 {
243 }
244 
246 {
247 }
248 
249 #include "resourcecalendar.moc"