You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
224 lines
6.3 KiB
224 lines
6.3 KiB
15 years ago
|
/*
|
||
|
This file is part of the kolab resource - the implementation of the
|
||
|
Kolab storage format. See www.kolab.org for documentation on this.
|
||
|
|
||
|
Copyright (c) 2004 Bo Thorsen <bo@sonofthor.dk>
|
||
|
|
||
|
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.
|
||
|
|
||
|
In addition, as a special exception, the copyright holders give
|
||
|
permission to link the code of this program with any edition of
|
||
14 years ago
|
the TQt library by Trolltech AS, Norway (or with modified versions
|
||
|
of TQt that use the same license as TQt), and distribute linked
|
||
15 years ago
|
combinations including the two. You must obey the GNU General
|
||
|
Public License in all respects for all of the code used other than
|
||
14 years ago
|
TQt. If you modify this file, you may extend this exception to
|
||
15 years ago
|
your version of the file, but you are not obligated to do so. If
|
||
|
you do not wish to do so, delete this exception statement from
|
||
|
your version.
|
||
|
*/
|
||
|
|
||
|
#include "event.h"
|
||
|
|
||
|
#include <libkcal/event.h>
|
||
|
#include <kdebug.h>
|
||
|
|
||
|
using namespace Kolab;
|
||
|
|
||
|
|
||
15 years ago
|
KCal::Event* Event::xmlToEvent( const TQString& xml, const TQString& tz, KCal::ResourceKolab* res,
|
||
14 years ago
|
const TQString& subResource, TQ_UINT32 sernum )
|
||
15 years ago
|
{
|
||
|
Event event( res, subResource, sernum, tz );
|
||
|
event.load( xml );
|
||
|
KCal::Event* kcalEvent = new KCal::Event();
|
||
|
event.saveTo( kcalEvent );
|
||
|
return kcalEvent;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString Event::eventToXML( KCal::Event* kcalEvent, const TQString& tz )
|
||
15 years ago
|
{
|
||
14 years ago
|
Event event( 0, TQString(), 0, tz, kcalEvent );
|
||
15 years ago
|
return event.saveXML();
|
||
|
}
|
||
|
|
||
14 years ago
|
Event::Event( KCal::ResourceKolab *res, const TQString &subResource, TQ_UINT32 sernum,
|
||
15 years ago
|
const TQString& tz, KCal::Event* event )
|
||
15 years ago
|
: Incidence( res, subResource, sernum, tz ),
|
||
|
mShowTimeAs( KCal::Event::Opaque ), mHasEndDate( false )
|
||
|
{
|
||
|
if ( event )
|
||
|
setFields( event );
|
||
|
}
|
||
|
|
||
|
Event::~Event()
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void Event::setTransparency( KCal::Event::Transparency transparency )
|
||
|
{
|
||
|
mShowTimeAs = transparency;
|
||
|
}
|
||
|
|
||
|
KCal::Event::Transparency Event::transparency() const
|
||
|
{
|
||
|
return mShowTimeAs;
|
||
|
}
|
||
|
|
||
15 years ago
|
void Event::setEndDate( const TQDateTime& date )
|
||
15 years ago
|
{
|
||
|
mEndDate = date;
|
||
|
mHasEndDate = true;
|
||
13 years ago
|
if ( mFloatingStatus == AllDay )
|
||
15 years ago
|
kdDebug() << "ERROR: Time on end date but no time on the event\n";
|
||
13 years ago
|
mFloatingStatus = HasTime;
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void Event::setEndDate( const TQDate& date )
|
||
15 years ago
|
{
|
||
|
mEndDate = date;
|
||
|
mHasEndDate = true;
|
||
13 years ago
|
if ( mFloatingStatus == HasTime )
|
||
15 years ago
|
kdDebug() << "ERROR: No time on end date but time on the event\n";
|
||
13 years ago
|
mFloatingStatus = AllDay;
|
||
15 years ago
|
}
|
||
|
|
||
15 years ago
|
void Event::setEndDate( const TQString& endDate )
|
||
15 years ago
|
{
|
||
|
if ( endDate.length() > 10 )
|
||
|
// This is a date + time
|
||
|
setEndDate( stringToDateTime( endDate ) );
|
||
|
else
|
||
|
// This is only a date
|
||
|
setEndDate( stringToDate( endDate ) );
|
||
|
}
|
||
|
|
||
15 years ago
|
TQDateTime Event::endDate() const
|
||
15 years ago
|
{
|
||
|
return mEndDate;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool Event::loadAttribute( TQDomElement& element )
|
||
15 years ago
|
{
|
||
|
// This method doesn't handle the color-label tag yet
|
||
15 years ago
|
TQString tagName = element.tagName();
|
||
15 years ago
|
|
||
|
if ( tagName == "show-time-as" ) {
|
||
|
// TODO: Support tentative and outofoffice
|
||
|
if ( element.text() == "free" )
|
||
|
setTransparency( KCal::Event::Transparent );
|
||
|
else
|
||
|
setTransparency( KCal::Event::Opaque );
|
||
|
} else if ( tagName == "end-date" )
|
||
|
setEndDate( element.text() );
|
||
|
else
|
||
|
return Incidence::loadAttribute( element );
|
||
|
|
||
|
// We handled this
|
||
|
return true;
|
||
|
}
|
||
|
|
||
15 years ago
|
bool Event::saveAttributes( TQDomElement& element ) const
|
||
15 years ago
|
{
|
||
|
// Save the base class elements
|
||
|
Incidence::saveAttributes( element );
|
||
|
|
||
|
// TODO: Support tentative and outofoffice
|
||
|
if ( transparency() == KCal::Event::Transparent )
|
||
|
writeString( element, "show-time-as", "free" );
|
||
|
else
|
||
|
writeString( element, "show-time-as", "busy" );
|
||
|
if ( mHasEndDate ) {
|
||
13 years ago
|
if ( mFloatingStatus == HasTime )
|
||
15 years ago
|
writeString( element, "end-date", dateTimeToString( endDate() ) );
|
||
|
else
|
||
|
writeString( element, "end-date", dateToString( endDate().date() ) );
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
|
||
15 years ago
|
bool Event::loadXML( const TQDomDocument& document )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDomElement top = document.documentElement();
|
||
15 years ago
|
|
||
|
if ( top.tagName() != "event" ) {
|
||
13 years ago
|
tqWarning( "XML error: Top tag was %s instead of the expected event",
|
||
15 years ago
|
top.tagName().ascii() );
|
||
|
return false;
|
||
|
}
|
||
|
|
||
15 years ago
|
for ( TQDomNode n = top.firstChild(); !n.isNull(); n = n.nextSibling() ) {
|
||
15 years ago
|
if ( n.isComment() )
|
||
|
continue;
|
||
|
if ( n.isElement() ) {
|
||
15 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
loadAttribute( e );
|
||
|
} else
|
||
|
kdDebug() << "Node is not a comment or an element???" << endl;
|
||
|
}
|
||
|
|
||
|
loadAttachments();
|
||
|
return true;
|
||
|
}
|
||
|
|
||
15 years ago
|
TQString Event::saveXML() const
|
||
15 years ago
|
{
|
||
15 years ago
|
TQDomDocument document = domTree();
|
||
|
TQDomElement element = document.createElement( "event" );
|
||
15 years ago
|
element.setAttribute( "version", "1.0" );
|
||
|
saveAttributes( element );
|
||
|
document.appendChild( element );
|
||
|
return document.toString();
|
||
|
}
|
||
|
|
||
|
void Event::setFields( const KCal::Event* event )
|
||
|
{
|
||
|
Incidence::setFields( event );
|
||
|
|
||
14 years ago
|
// note: if hasEndDate() is false and hasDuration() is true
|
||
|
// dtEnd() returns start+duration
|
||
|
if ( event->hasEndDate() || event->hasDuration() ) {
|
||
15 years ago
|
if ( event->doesFloat() ) {
|
||
|
// This is a floating event. Don't timezone move this one
|
||
13 years ago
|
mFloatingStatus = AllDay;
|
||
15 years ago
|
setEndDate( event->dtEnd().date() );
|
||
|
} else {
|
||
13 years ago
|
mFloatingStatus = HasTime;
|
||
15 years ago
|
setEndDate( localToUTC( event->dtEnd() ) );
|
||
|
}
|
||
14 years ago
|
} else {
|
||
15 years ago
|
mHasEndDate = false;
|
||
14 years ago
|
}
|
||
15 years ago
|
setTransparency( event->transparency() );
|
||
|
}
|
||
|
|
||
|
void Event::saveTo( KCal::Event* event )
|
||
|
{
|
||
|
Incidence::saveTo( event );
|
||
|
|
||
|
event->setHasEndDate( mHasEndDate );
|
||
|
if ( mHasEndDate ) {
|
||
13 years ago
|
if ( mFloatingStatus == AllDay )
|
||
15 years ago
|
// This is a floating event. Don't timezone move this one
|
||
|
event->setDtEnd( endDate() );
|
||
|
else
|
||
|
event->setDtEnd( utcToLocal( endDate() ) );
|
||
|
}
|
||
|
event->setTransparency( transparency() );
|
||
|
}
|