[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-pim
Subject:    Re: [Kde-pim] Move KOrganizer to new resource framework
From:       Guenter Schwann <schwann () icg ! tu-graz ! ac ! at>
Date:       2003-01-14 13:48:18
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tuesday 14 January 2003 14:16, Steffen Hansen wrote:
> The fromString() method in the patch seems cool, but the existing
> ICalFormat::toString( i ); is not what I want. It omits the
> BEGIN:VCALENDAR ... and only writes the incidence. We still need the
> data to be surrounded with BEGIN::VCALENDAR and PRODID and whatnot.
>
> How would I do that?

My next proposal...
And again: THIS IS UNTESTED (I can only say, that it compiles)

Now there is
Incidence *ICalFormat::fromString( const QString &text )
and 
QString ICalFormat::toICalString( Incidence *incidence )

ciao
- -- 
Guenter Schwann
Graz University of Technology - Computer Graphics and Vision
GPG-key: http://www.sbox.tugraz.at/home/v/vogel/gpg-schwann-public-key.txt
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+JBUk43e2O3Z+/CQRAlm2AKCR81VgCE11slvMATWkKO/h492PsgCeMcfH
rFaO8JX0+q2vgObhLiHfATg=
=06rX
-----END PGP SIGNATURE-----

["tostring.diff" (text/x-diff)]

? Doxyfile
? calendarimap/resourceimap.kidl
? calendarimap/resourceimap_skel.cpp
Index: icalformat.cpp
===================================================================
RCS file: /home/kde/kdepim/libkcal/icalformat.cpp,v
retrieving revision 1.37
diff -u -3 -p -b -r1.37 icalformat.cpp
--- icalformat.cpp	13 Jan 2003 14:55:42 -0000	1.37
+++ icalformat.cpp	14 Jan 2003 13:42:49 -0000
@@ -143,6 +143,39 @@ bool ICalFormat::fromString( Calendar *c
   return success;
 }
 
+Incidence *ICalFormat::fromString( const QString &text )
+{
+  icalcomponent *calendar;
+
+  calendar = icalcomponent_new_from_string( text.local8Bit().data());
+  if (!calendar) {
+    kdDebug() << "ICalFormat::fromString(const QString) parse error" << endl;
+    setException(new ErrorFormat(ErrorFormat::ParseErrorIcal));
+    return false;
+  }
+
+  Incidence *ical=0;
+  
+  icalcomponent *c;
+  c = icalcomponent_get_first_component(calendar,ICAL_VEVENT_COMPONENT);
+  if (c) {
+    ical = mImpl->readEvent(c);
+  } else {
+    c = icalcomponent_get_first_component(calendar,ICAL_VTODO_COMPONENT);
+    if (c) {
+      ical = mImpl->readTodo(c);
+    } else {
+      c = icalcomponent_get_first_component(calendar,ICAL_VJOURNAL_COMPONENT);
+      if (c) {
+        ical = mImpl->readJournal(c);
+      }
+    }
+  }
+  
+  icalcomponent_free( calendar );
+  return ical;
+}
+
 QString ICalFormat::toString( Calendar *cal )
 {
   setTimeZone( cal->timeZoneId(), !cal->isLocalTime() );
@@ -184,6 +217,19 @@ QString ICalFormat::toString( Calendar *
                  i18n("libical error")));
     return QString::null;
   }
+
+  return QString::fromLocal8Bit( text );
+}
+
+QString ICalFormat::toICalString( Incidence *incidence )
+{
+  icalcomponent *calendar = mImpl->createCalendarComponent();
+  icalcomponent *component = mImpl->writeIncidence( incidence );
+  icalcomponent_add_component(calendar,component);
+  const char *text = icalcomponent_as_ical_string( calendar );
+
+  icalcomponent_free( component );
+  icalcomponent_free( calendar );
 
   return QString::fromLocal8Bit( text );
 }
Index: icalformat.h
===================================================================
RCS file: /home/kde/kdepim/libkcal/icalformat.h,v
retrieving revision 1.14
diff -u -3 -p -b -r1.14 icalformat.h
--- icalformat.h	5 Sep 2002 06:50:32 -0000	1.14
+++ icalformat.h	14 Jan 2003 13:42:49 -0000
@@ -65,9 +65,17 @@ class ICalFormat : public CalFormat {
     */
     bool fromString( Calendar *, const QString & );  
     /**
+      Parse string and return first ical component.
+    */
+    Incidence *fromString( const QString & );  
+    /**
       Return calendar information as string.
     */
     QString toString( Calendar * );
+    /**
+      Return incidence as full iCalendar formatted text.
+    */
+    QString toICalString( Incidence * );
     /**
       Return incidence as iCalendar formatted text.
     */

_______________________________________________
kde-pim mailing list
kde-pim@mail.kde.org
http://mail.kde.org/mailman/listinfo/kde-pim
kde-pim home page at http://pim.kde.org/

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic