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.
5
Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
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.
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.
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.
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
36
#include <kcal/event.h>
39
using namespace Kolab;
42
KCal::Event* Event::xmlToEvent( const QString& xml, const QString& tz)
46
KCal::Event* kcalEvent = new KCal::Event();
47
event.saveTo( kcalEvent );
51
QString Event::eventToXML( KCal::Event* kcalEvent, const QString& tz )
53
Event event( tz, kcalEvent );
54
return event.saveXML();
57
Event::Event( const QString& tz, KCal::Event* event )
58
: Incidence( tz, event ),
59
mShowTimeAs( KCal::Event::Opaque ), mHasEndDate( false )
69
void Event::setTransparency( KCal::Event::Transparency transparency )
71
mShowTimeAs = transparency;
74
KCal::Event::Transparency Event::transparency() const
79
void Event::setEndDate( const KDateTime& date )
83
if ( mFloatingStatus == AllDay )
84
kDebug() <<"ERROR: Time on end date but no time on the event";
85
mFloatingStatus = HasTime;
88
void Event::setEndDate( const QDate& date )
90
mEndDate = KDateTime( date );
92
if ( mFloatingStatus == HasTime )
93
kDebug() <<"ERROR: No time on end date but time on the event";
94
mFloatingStatus = AllDay;
97
void Event::setEndDate( const QString& endDate )
99
if ( endDate.length() > 10 )
100
// This is a date + time
101
setEndDate( stringToDateTime( endDate ) );
103
// This is only a date
104
setEndDate( stringToDate( endDate ) );
107
KDateTime Event::endDate() const
112
bool Event::loadAttribute( QDomElement& element )
114
// This method doesn't handle the color-label tag yet
115
QString tagName = element.tagName();
117
if ( tagName == "show-time-as" ) {
118
// TODO: Support tentative and outofoffice
119
if ( element.text() == "free" )
120
setTransparency( KCal::Event::Transparent );
122
setTransparency( KCal::Event::Opaque );
123
} else if ( tagName == "end-date" )
124
setEndDate( element.text() );
126
return Incidence::loadAttribute( element );
132
bool Event::saveAttributes( QDomElement& element ) const
134
// Save the base class elements
135
Incidence::saveAttributes( element );
137
// TODO: Support tentative and outofoffice
138
if ( transparency() == KCal::Event::Transparent )
139
writeString( element, "show-time-as", "free" );
141
writeString( element, "show-time-as", "busy" );
143
if ( mFloatingStatus == HasTime )
144
writeString( element, "end-date", dateTimeToString( endDate() ) );
146
writeString( element, "end-date", dateToString( endDate().date() ) );
153
bool Event::loadXML( const QDomDocument& document )
155
QDomElement top = document.documentElement();
157
if ( top.tagName() != "event" ) {
158
qWarning( "XML error: Top tag was %s instead of the expected event",
159
top.tagName().toAscii().data() );
163
for ( QDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) {
166
if ( n.isElement() ) {
167
QDomElement e = n.toElement();
170
kDebug() <<"Node is not a comment or an element???";
176
QString Event::saveXML() const
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();
186
void Event::setFields( const KCal::Event* event )
188
Incidence::setFields( event );
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() );
196
mFloatingStatus = HasTime;
197
setEndDate( localToUTC( event->dtEnd() ) );
201
setTransparency( event->transparency() );
204
void Event::saveTo( KCal::Event* event )
206
Incidence::saveTo( event );
208
event->setHasEndDate( mHasEndDate );
210
if ( mFloatingStatus == AllDay )
211
// This is an all-day event. Don't timezone move this one
212
event->setDtEnd( endDate() );
214
event->setDtEnd( utcToLocal( endDate() ) );
216
event->setTransparency( transparency() );