libkpimexchange Library API Documentation

utils.cpp

00001 /*
00002     This file is part of libkpimexchange
00003     Copyright (c) 2002 Jan-Pascal van Best <janpascal@vanbest.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
00019 */
00020 
00021 #include <qdatetime.h>
00022 
00023 extern "C" {
00024   #include <ical.h>
00025 }
00026 
00027 #include "utils.h"
00028 
00031 QDomElement addElement( QDomDocument& doc, QDomNode& node, const QString& ns, const QString& tag )
00032 {
00033   QDomElement el = doc.createElementNS( ns, tag );
00034   node.appendChild( el );
00035   return el;
00036 }
00037 
00042 QDomElement addElement( QDomDocument& doc, QDomNode& node, const QString& ns, const QString& tag, const QString& text )
00043 {
00044   QDomElement el = doc.createElementNS( ns, tag );
00045   QDomText textnode = doc.createTextNode( text );
00046   el.appendChild( textnode );
00047   node.appendChild( el );
00048   return el;
00049 }
00050 
00051 QDateTime utcAsZone( const QDateTime& utc, const QString& timeZoneId )
00052 {
00053   QDateTime epoch;
00054   epoch.setTime_t( 0 );
00055   time_t v = epoch.secsTo( utc );
00056   struct icaltimetype tt = icaltime_from_timet( v, 0 ); // 0: is_date=false
00057   int offset = icaltime_utc_offset( tt, timeZoneId.local8Bit() );
00058   return utc.addSecs( offset );
00059 }
00060 
00061 QDateTime zoneAsUtc( const QDateTime& zone, const QString& timeZoneId )
00062 {
00063   QDateTime epoch;
00064   epoch.setTime_t( 0 );
00065   time_t v = epoch.secsTo( zone );
00066   struct icaltimetype tt = icaltime_from_timet( v, 0 ); // 0: is_date=false
00067   int offset = icaltime_utc_offset( tt, timeZoneId.local8Bit() );
00068   return zone.addSecs( - offset );
00069 }
00070 
00071 KURL toDAV( const KURL& url ) {
00072   KURL result( url );
00073   if ( result.protocol() == "http" )
00074     result.setProtocol( "webdav" );
00075   else if ( result.protocol() == "https" )
00076     result.setProtocol( "webdavs" );
00077   return result;
00078 }
00079 
00080 KURL* toDAV( const KURL* url ) {
00081   KURL* result = new KURL( *url );
00082   if ( result->protocol() == "http" )
00083      result->setProtocol( "webdav" );
00084   else if (  result->protocol() == "https" )
00085      result->setProtocol( "webdavs" );
00086   return result;
00087 }
00088 
KDE Logo
This file is part of the documentation for libkpimexchange Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:38:10 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003