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

List:       kde-commits
Subject:    kdepim/kresources/kolab/kcal
From:       David Faure <faure () kde ! org>
Date:       2004-09-16 23:26:54
Message-ID: 20040916232654.AB7C3B67 () office ! kde ! org
[Download RAW message or body]

CVS commit by faure: 

Save and restore unknown xml tags, as well as any custom properties.


  M +1 -3      event.cpp   1.3
  M +56 -3     incidence.cpp   1.3
  M +8 -0      incidence.h   1.3


--- kdepim/kresources/kolab/kcal/event.cpp  #1.2:1.3
@@ -165,7 +165,5 @@ bool Event::loadXML( const QDomDocument&
     if ( n.isElement() ) {
       QDomElement e = n.toElement();
-      if ( !loadAttribute( e ) )
-        // TODO: Unhandled tag - save for later storage
-        kdDebug() << "Warning: Unhandled tag " << e.tagName() << endl;
+      loadAttribute( e );
     } else
       kdDebug() << "Node is not a comment or an element???" << endl;

--- kdepim/kresources/kolab/kcal/incidence.cpp  #1.2:1.3
@@ -294,7 +294,17 @@ bool Incidence::loadAttribute( QDomEleme
     // Alarms should be minutes before. Libkcal uses event time + alarm time
     setAlarm( - element.text().toInt() );
-  else
-    return KolabBase::loadAttribute( element );
-
+  else if ( tagName == "x-custom" )
+    loadCustomAttributes( element );
+  else {
+    bool ok = KolabBase::loadAttribute( element );
+    if ( !ok ) {
+        // Unhandled tag - save for later storage
+        kdDebug() << "Saving unhandled tag " << element.tagName() << endl;
+        Custom c;
+        c.key = QCString( "X-KDE-KolabUnhandled-" ) + element.tagName().latin1();
+        c.value = element.text();
+        mCustomList.append( c );
+    }
+  }
   // We handled this
   return true;
@@ -321,7 +331,35 @@ bool Incidence::saveAttributes( QDomElem
     writeString( element, "alarm", QString::number( alarmTime ) );
   }
+  saveCustomAttributes( element );
   return true;
 }
 
+void Incidence::saveCustomAttributes( QDomElement& element ) const
+{
+  QValueList<Custom>::ConstIterator it = mCustomList.begin();
+  for ( ; it != mCustomList.end(); ++it ) {
+    QString key = (*it).key;
+    Q_ASSERT( !key.isEmpty() );
+    if ( key.startsWith( "X-KDE-KolabUnhandled-" ) ) {
+      key = key.mid( strlen( "X-KDE-KolabUnhandled-" ) );
+      writeString( element, key, (*it).value );
+    } else {
+      // Let's use attributes so that other tag-preserving-code doesn't need sub-elements
+      QDomElement e = element.ownerDocument().createElement( "x-custom" );
+      element.appendChild( e );
+      e.setAttribute( "key", key );
+      e.setAttribute( "value", (*it).value );
+    }
+  }
+}
+
+void Incidence::loadCustomAttributes( QDomElement& element )
+{
+  Custom custom;
+  custom.key = element.attribute( "key" ).latin1();
+  custom.value = element.attribute( "value" );
+  mCustomList.append( custom );
+}
+
 static KCal::Attendee::PartStat attendeeStringToStatus( const QString& s )
 {
@@ -532,4 +570,14 @@ void Incidence::setFields( const KCal::I
     mRecurrence.exclusions = incidence->exDates();
   }
+
+  // Unhandled tags and other custom properties (see libkcal/customproperties.h)
+  const QMap<QCString, QString> map = incidence->customProperties();
+  QMap<QCString, QString>::ConstIterator cit = map.begin();
+  for ( ; cit != map.end() ; ++cit ) {
+    Custom c;
+    c.key = cit.key();
+    c.value = cit.data();
+    mCustomList.append( c );
+  }
 }
 
@@ -630,4 +678,9 @@ void Incidence::saveTo( KCal::Incidence*
     incidence->setExDates( mRecurrence.exclusions );
   }
+
+  for( QValueList<Custom>::ConstIterator it = mCustomList.begin(); it != mCustomList.end(); ++it ) {
+    incidence->setNonKDECustomProperty( (*it).key, (*it).value );
+  }
+
 }
 

--- kdepim/kresources/kolab/kcal/incidence.h  #1.2:1.3
@@ -122,4 +122,6 @@ protected:
   void loadRecurrence( const QDomElement& element );
   void saveRecurrence( QDomElement& element ) const;
+  void saveCustomAttributes( QDomElement& element ) const;
+  void loadCustomAttributes( QDomElement& element );
 
   QString productID() const;
@@ -134,4 +136,10 @@ protected:
   Recurrence mRecurrence;
   QValueList<Attendee> mAttendees;
+
+  struct Custom {
+    QCString key;
+    QString value;
+  };
+  QValueList<Custom> mCustomList;
 };
 


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

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