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

List:       kde-commits
Subject:    proko2: kdepim/kresources/kolab/shared
From:       Bo Thorsen <bo () sonofthor ! dk>
Date:       2004-08-12 12:01:34
Message-ID: 20040812120134.41352926D () office ! kde ! org
[Download RAW message or body]

CVS commit by thorsen: 

Handle creation and modification datetimes correctly in contacts


  M +33 -1     kolabbase.cpp   1.1.2.12


--- kdepim/kresources/kolab/shared/kolabbase.cpp  #1.1.2.11:1.1.2.12
@@ -86,5 +86,35 @@ void KolabBase::setFields( const KABC::A
   setBody( addressee->note() );
   setCategories( addressee->categories().join( "," ) );
-  setLastModified( addressee->revision() );
+
+  // Set creation-time and last-modification-time
+  const QString creationString = addressee->custom( "KOLAB", "CreationDate" );
+  kdDebug(5006) << "Creation time string: " << creationString << endl;
+  QDateTime creationDate;
+  if ( creationString.isEmpty() ) {
+    creationDate = QDateTime::currentDateTime();
+    kdDebug(5006) << "Creation date set to current time\n";
+  }
+  else {
+    creationDate = stringToDateTime( creationString );
+    kdDebug(5006) << "Creation date loaded\n";
+  }
+  QDateTime modified = addressee->revision();
+  if ( !modified.isValid() )
+    modified = QDateTime::currentDateTime();
+  setLastModified( modified );
+  if ( modified < creationDate ) {
+    // It's not possible that the modification date is earlier than creation
+    creationDate = modified;
+    kdDebug(5006) << "Creation date set to modification date\n";
+  }
+  setCreationDate( creationDate );
+  const QString newCreationDate = dateTimeToString( creationDate );
+  if ( creationString != newCreationDate ) {
+    // We modified the creation date, so store it for future reference
+    const_cast<KABC::Addressee*>( addressee )
+      ->insertCustom( "KOLAB", "CreationDate", newCreationDate );
+    kdDebug(5006) << "Creation date modified. New one: " << newCreationDate << endl;
+  }
+
   switch( addressee->secrecy().type() ) {
   case KABC::Secrecy::Private:
@@ -107,4 +137,6 @@ void KolabBase::saveTo( KABC::Addressee*
   addressee->setCategories( QStringList::split( ',', categories() ) );
   addressee->setRevision( lastModified() );
+  addressee->insertCustom( "KOLAB", "CreationDate",
+                           dateTimeToString( creationDate() ) );
 
   switch( sensitivity() ) {


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

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