~ubuntu-branches/ubuntu/karmic/kdepim/karmic-backports

« back to all changes in this revision

Viewing changes to akonadi/resources/kolabproxy/event.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christian Mangold
  • Date: 2009-07-10 06:34:50 UTC
  • mfrom: (1.1.40 upstream)
  • Revision ID: james.westby@ubuntu.com-20090710063450-neojgew2fh0n3y0u
Tags: 4:4.2.96-0ubuntu1
* New upstream release
* Bump kde build-deps to 4.2.96

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    This file is part of the kolab resource - the implementation of the
3
 
    Kolab storage format. See www.kolab.org for documentation on this.
4
 
 
5
 
    Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
6
 
 
7
 
    This library is free software; you can redistribute it and/or
8
 
    modify it under the terms of the GNU Library General Public
9
 
    License as published by the Free Software Foundation; either
10
 
    version 2 of the License, or (at your option) any later version.
11
 
 
12
 
    This library is distributed in the hope that it will be useful,
13
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
    Library General Public License for more details.
16
 
 
17
 
    You should have received a copy of the GNU Library General Public License
18
 
    along with this library; see the file COPYING.LIB.  If not, write to
19
 
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20
 
    Boston, MA 02110-1301, USA.
21
 
 
22
 
    In addition, as a special exception, the copyright holders give
23
 
    permission to link the code of this program with any edition of
24
 
    the Qt library by Trolltech AS, Norway (or with modified versions
25
 
    of Qt that use the same license as Qt), and distribute linked
26
 
    combinations including the two.  You must obey the GNU General
27
 
    Public License in all respects for all of the code used other than
28
 
    Qt.  If you modify this file, you may extend this exception to
29
 
    your version of the file, but you are not obligated to do so.  If
30
 
    you do not wish to do so, delete this exception statement from
31
 
    your version.
32
 
*/
33
 
 
34
 
#include "event.h"
35
 
 
36
 
#include <kcal/event.h>
37
 
#include <kdebug.h>
38
 
 
39
 
using namespace Kolab;
40
 
 
41
 
 
42
 
KCal::Event* Event::xmlToEvent( const QString& xml, const QString& tz)
43
 
{
44
 
  Event event( tz );
45
 
  event.load( xml );
46
 
  KCal::Event* kcalEvent = new KCal::Event();
47
 
  event.saveTo( kcalEvent );
48
 
  return kcalEvent;
49
 
}
50
 
 
51
 
QString Event::eventToXML( KCal::Event* kcalEvent, const QString& tz  )
52
 
{
53
 
  Event event( tz, kcalEvent );
54
 
  return event.saveXML();
55
 
}
56
 
 
57
 
Event::Event( const QString& tz, KCal::Event* event )
58
 
  : Incidence( tz, event ),
59
 
  mShowTimeAs( KCal::Event::Opaque ), mHasEndDate( false )
60
 
{
61
 
  if ( event )
62
 
    setFields( event );
63
 
}
64
 
 
65
 
Event::~Event()
66
 
{
67
 
}
68
 
 
69
 
void Event::setTransparency( KCal::Event::Transparency transparency )
70
 
{
71
 
  mShowTimeAs = transparency;
72
 
}
73
 
 
74
 
KCal::Event::Transparency Event::transparency() const
75
 
{
76
 
  return mShowTimeAs;
77
 
}
78
 
 
79
 
void Event::setEndDate( const KDateTime& date )
80
 
{
81
 
  mEndDate = date;
82
 
  mHasEndDate = true;
83
 
  if ( mFloatingStatus == AllDay )
84
 
    kDebug() <<"ERROR: Time on end date but no time on the event";
85
 
  mFloatingStatus = HasTime;
86
 
}
87
 
 
88
 
void Event::setEndDate( const QDate& date )
89
 
{
90
 
  mEndDate = KDateTime( date );
91
 
  mHasEndDate = true;
92
 
  if ( mFloatingStatus == HasTime )
93
 
    kDebug() <<"ERROR: No time on end date but time on the event";
94
 
  mFloatingStatus = AllDay;
95
 
}
96
 
 
97
 
void Event::setEndDate( const QString& endDate )
98
 
{
99
 
  if ( endDate.length() > 10 )
100
 
    // This is a date + time
101
 
    setEndDate( stringToDateTime( endDate ) );
102
 
  else
103
 
    // This is only a date
104
 
    setEndDate( stringToDate( endDate ) );
105
 
}
106
 
 
107
 
KDateTime Event::endDate() const
108
 
{
109
 
  return mEndDate;
110
 
}
111
 
 
112
 
bool Event::loadAttribute( QDomElement& element )
113
 
{
114
 
  // This method doesn't handle the color-label tag yet
115
 
  QString tagName = element.tagName();
116
 
 
117
 
  if ( tagName == "show-time-as" ) {
118
 
    // TODO: Support tentative and outofoffice
119
 
    if ( element.text() == "free" )
120
 
      setTransparency( KCal::Event::Transparent );
121
 
    else
122
 
      setTransparency( KCal::Event::Opaque );
123
 
  } else if ( tagName == "end-date" )
124
 
    setEndDate( element.text() );
125
 
  else
126
 
    return Incidence::loadAttribute( element );
127
 
 
128
 
  // We handled this
129
 
  return true;
130
 
}
131
 
 
132
 
bool Event::saveAttributes( QDomElement& element ) const
133
 
{
134
 
  // Save the base class elements
135
 
  Incidence::saveAttributes( element );
136
 
 
137
 
  // TODO: Support tentative and outofoffice
138
 
  if ( transparency() == KCal::Event::Transparent )
139
 
    writeString( element, "show-time-as", "free" );
140
 
  else
141
 
    writeString( element, "show-time-as", "busy" );
142
 
  if ( mHasEndDate ) {
143
 
    if ( mFloatingStatus == HasTime )
144
 
      writeString( element, "end-date", dateTimeToString( endDate() ) );
145
 
    else
146
 
      writeString( element, "end-date", dateToString( endDate().date() ) );
147
 
  }
148
 
 
149
 
  return true;
150
 
}
151
 
 
152
 
 
153
 
bool Event::loadXML( const QDomDocument& document )
154
 
{
155
 
  QDomElement top = document.documentElement();
156
 
 
157
 
  if ( top.tagName() != "event" ) {
158
 
    qWarning( "XML error: Top tag was %s instead of the expected event",
159
 
              top.tagName().toAscii().data() );
160
 
    return false;
161
 
  }
162
 
 
163
 
  for ( QDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) {
164
 
    if ( n.isComment() )
165
 
      continue;
166
 
    if ( n.isElement() ) {
167
 
      QDomElement e = n.toElement();
168
 
      loadAttribute( e );
169
 
    } else
170
 
      kDebug() <<"Node is not a comment or an element???";
171
 
  }
172
 
 
173
 
  return true;
174
 
}
175
 
 
176
 
QString Event::saveXML() const
177
 
{
178
 
  QDomDocument document = domTree();
179
 
  QDomElement element = document.createElement( "event" );
180
 
  element.setAttribute( "version", "1.0" );
181
 
  saveAttributes( element );
182
 
  document.appendChild( element );
183
 
  return document.toString();
184
 
}
185
 
 
186
 
void Event::setFields( const KCal::Event* event )
187
 
{
188
 
  Incidence::setFields( event );
189
 
 
190
 
  if ( event->hasEndDate() ) {
191
 
    if ( event->allDay() ) {
192
 
      // This is an all-day event. Don't timezone move this one
193
 
      mFloatingStatus = AllDay;
194
 
      setEndDate( event->dtEnd().date() );
195
 
    } else {
196
 
      mFloatingStatus = HasTime;
197
 
      setEndDate( localToUTC( event->dtEnd() ) );
198
 
    }
199
 
  } else
200
 
    mHasEndDate = false;
201
 
  setTransparency( event->transparency() );
202
 
}
203
 
 
204
 
void Event::saveTo( KCal::Event* event )
205
 
{
206
 
  Incidence::saveTo( event );
207
 
 
208
 
  event->setHasEndDate( mHasEndDate );
209
 
  if ( mHasEndDate ) {
210
 
    if ( mFloatingStatus == AllDay )
211
 
      // This is an all-day event. Don't timezone move this one
212
 
      event->setDtEnd( endDate() );
213
 
    else
214
 
      event->setDtEnd( utcToLocal( endDate() ) );
215
 
  }
216
 
  event->setTransparency( transparency() );
217
 
}