summaryrefslogtreecommitdiffstats
path: root/libkcal/resourcecalendar.cpp
blob: 36a0932b0dac0f2c26dd2658f07112f2a019e2d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
    This file is part of libkcal.

    Copyright (c) 1998 Preston Brown <pbrown@kde.org>
    Copyright (c) 2001-2004 Cornelius Schumacher <schumacher@kde.org>
    Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
    Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Library General Public
    License as published by the Free Software Foundation; either
    version 2 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Library General Public License for more details.

    You should have received a copy of the GNU Library General Public License
    along with this library; see the file COPYING.LIB.  If not, write to
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA 02110-1301, USA.
*/

#include <kconfig.h>
#include <kdebug.h>
#include <klocale.h>

#include "calendar.h"

#include "resourcecalendar.h"

using namespace KCal;

ResourceCalendar::ResourceCalendar( const TDEConfig *config )
  : KRES::Resource( config ), mResolveConflict( false )
{
  mException = 0;
}

ResourceCalendar::~ResourceCalendar()
{
  delete mException;
}

void ResourceCalendar::clearException()
{
  delete mException;
  mException = 0;
}

void ResourceCalendar::setException( ErrorFormat *exception )
{
  delete mException;
  mException = exception;
}

ErrorFormat *ResourceCalendar::exception()
{
  return mException;
}

void ResourceCalendar::setResolveConflict( bool b)
{
 mResolveConflict = b;
}

TQString ResourceCalendar::infoText() const
{
  TQString txt;

  txt += "<b>" + resourceName() + "</b>";
  txt += "<br>";

  KRES::Factory *factory = KRES::Factory::self( "calendar" );
  TQString t = factory->typeName( type() );
  txt += i18n("Type: %1").arg( t );

  addInfoText( txt );

  return txt;
}

void ResourceCalendar::writeConfig( TDEConfig* config )
{
//  kdDebug(5800) << "ResourceCalendar::writeConfig()" << endl;

  KRES::Resource::writeConfig( config );
}

Incidence *ResourceCalendar::incidence( const TQString &uid )
{
  Incidence *i = event( uid );
  if ( i ) return i;
  i = todo( uid );
  if ( i ) return i;
  i = journal( uid );
  return i;
}

bool ResourceCalendar::addIncidence( Incidence *incidence )
{
  Incidence::AddVisitor<ResourceCalendar> v( this );
  return incidence->accept( v );
}

bool ResourceCalendar::addIncidence( Incidence *incidence, const TQString &subresource )
{
  Incidence::AddSubResourceVisitor<ResourceCalendar> v( this, subresource );
  return incidence->accept( v );
}

bool ResourceCalendar::deleteIncidence( Incidence *incidence )
{
  Incidence::DeleteVisitor<ResourceCalendar> v( this );
  return incidence->accept( v );
}

Incidence::List ResourceCalendar::rawIncidences()
{
  return Calendar::mergeIncidenceList( rawEvents(), rawTodos(), rawJournals() );
}

void ResourceCalendar::setSubresourceActive( const TQString &, bool )
{
}

bool ResourceCalendar::addSubresource( const TQString &, const TQString & )
{
  return true;
}

bool ResourceCalendar::removeSubresource( const TQString & )
{
  return true;
}

bool ResourceCalendar::load()
{
  kdDebug(5800) << "Loading resource " + resourceName() << endl;

  mReceivedLoadError = false;

  bool success = true;
  if ( !isOpen() )
    success = open();
  if ( success )
    success = doLoad();

  if ( !success && !mReceivedLoadError )
    loadError();

  // If the resource is read-only, we need to set its incidences to read-only,
  // too. This can't be done at a lower-level, since the read-only setting
  // happens at this level
  if ( readOnly() ) {
    Incidence::List incidences( rawIncidences() );
    Incidence::List::Iterator it;
    for ( it = incidences.begin(); it != incidences.end(); ++it ) {
      (*it)->setReadOnly( true );
    }
  }

  kdDebug(5800) << "Done loading resource " + resourceName() << endl;

  return success;
}

void ResourceCalendar::loadError( const TQString &err )
{
  kdDebug(5800) << "Error loading resource: " << err << endl;

  mReceivedLoadError = true;

  TQString msg = i18n("Error while loading %1.\n") .arg( resourceName() );
  if ( !err.isEmpty() ) {
    msg += err;
  }
  emit resourceLoadError( this, msg );
}

bool ResourceCalendar::save( Incidence *incidence )
{
  if ( !readOnly() ) {
    kdDebug(5800) << "Save resource " + resourceName() << endl;

    mReceivedSaveError = false;

    if ( !isOpen() ) return true;
    bool success = incidence ? doSave(incidence) : doSave();
    if ( !success && !mReceivedSaveError ) saveError();

    return success;
  } else {
    // Read-only, just don't save...
    kdDebug(5800) << "Don't save read-only resource " + resourceName() << endl;
    return true;
  }
}

bool ResourceCalendar::doSave( Incidence * )
{
  return doSave();
}

void ResourceCalendar::saveError( const TQString &err )
{
  kdDebug(5800) << "Error saving resource: " << err << endl;

  mReceivedSaveError = true;

  TQString msg = i18n("Error while saving %1.\n") .arg( resourceName() );
  if ( !err.isEmpty() ) {
    msg += err;
  }
  emit resourceSaveError( this, msg );
}

bool ResourceCalendar::setValue( const TQString &key, const TQString &value )
{
  Q_UNUSED( key );
  Q_UNUSED( value );
  return false;
}

TQString ResourceCalendar::subresourceType( const TQString &resource )
{
  Q_UNUSED( resource );
  return TQString();
}

bool ResourceCalendar::subresourceWritable( const TQString &resource ) const
{
  if ( resource.isEmpty() ) {
    return !readOnly();
  } else {
    return false;
  }
}

void ResourceCalendar::beginAddingIncidences()
{
}

void ResourceCalendar::endAddingIncidences()
{
}

#include "resourcecalendar.moc"