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

List:       kde-commits
Subject:    branches/work/akonadi-ports/kdepim/korganizer
From:       Sebastian Sauer <mail () dipe ! org>
Date:       2009-07-06 19:02:31
Message-ID: 1246906951.955395.8418.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 992400 by sebsauer:

made import+export work better. we assert now rather then crash if import does \
delete+add to modify what was working ok with synchronous actions but does not work \
well with akonadi asynchronous actions.

 M  +22 -61    akonadicalendar.cpp  
 M  +38 -19    akonadicalendar_p.h  


--- branches/work/akonadi-ports/kdepim/korganizer/akonadicalendar.cpp #992399:992400
@@ -19,7 +19,6 @@
 
 #include <akonadi/collection.h>
 #include <akonadi/collectionview.h>
-#include <akonadi/collectiondialog.h>
 #include <akonadi/collectionfilterproxymodel.h>
 #include <akonadi/collectionmodel.h>
 #include <akonadi/itemfetchjob.h>
@@ -84,6 +83,7 @@
   Q_ASSERT( d->m_collectionMap.contains( collection.id() ) );
   d->m_monitor->setCollectionMonitored( collection, false );
   AkonadiCalendarCollection *c = d->m_collectionMap.take( collection.id() );
+  delete c;
 
   //d->clear();
   //d->m_session->clear();
@@ -141,11 +141,9 @@
 #if 0
   setObserversEnabled( false );
   d->mFileName.clear();
-
   deleteAllEvents();
   deleteAllTodos();
   deleteAllJournals();
-
   d->mDeletedIncidences.clearAll();
 #endif
   setModified( false );
@@ -157,51 +155,15 @@
 bool AkonadiCalendar::addIncidence( Incidence *incidence )
 {
   kDebug();
-
-  // first dispatch to addEvent/addTodo/addJournal
-  if ( ! Calendar::addIncidence( incidence ) ) {
-    return false;
-  }
-
-  // show the user a dialog to select in what collection we
-  // should save the new incidence.
-  Akonadi::CollectionDialog dlg( 0 );
-  dlg.setMimeTypeFilter( QStringList() << QString::fromLatin1( "text/calendar" ) );
-  if ( ! dlg.exec() ) {
-    return false;
-  }
-  const Akonadi::Collection collection = dlg.selectedCollection();
-  Q_ASSERT( collection.isValid() );
-  Q_ASSERT( d->m_collectionMap.contains( collection.id() ) );
-
-  // then try to add the incidence
-  Akonadi::Item item;
-  //the sub-mimetype of text/calendar as defined at \
                kdepim/akonadi/kcal/kcalmimetypevisitor.cpp
-  item.setMimeType( \
QString("application/x-vnd.akonadi.calendar.%1").arg(QString(incidence->type().lower())) \
                );
-  KCal::Incidence::Ptr incidencePtr( incidence ); //no clone() needed
-  item.setPayload<KCal::Incidence::Ptr>( incidencePtr );
-  Akonadi::ItemCreateJob *job = new Akonadi::ItemCreateJob( item, collection );
-  connect( job, SIGNAL( result( KJob* ) ), d, SLOT( createDone( KJob* ) ) );
-  return true;
+  // dispatch to addEvent/addTodo/addJournal
+  return Calendar::addIncidence( incidence );
 }
 
 bool AkonadiCalendar::deleteIncidence( Incidence *incidence )
 {
   kDebug();
-
-  // first dispatch to deleteEvent/deleteTodo/deleteJournal
-  if ( ! Calendar::deleteIncidence( incidence ) ) {
-    return false;
-  }
-
-  // then try to delete the incidence
-  Q_ASSERT( d->m_itemMap.contains( incidence->uid() ) );
-  Akonadi::Item item = d->m_itemMap[ incidence->uid() ]->m_item;
-  Q_ASSERT( item.isValid() );
-  Q_ASSERT( item.hasPayload() );
-  Akonadi::ItemDeleteJob *job = new Akonadi::ItemDeleteJob( item, d->m_session );
-  connect( job, SIGNAL( result( KJob* ) ), d, SLOT( deleteDone( KJob* ) ) );
-  return true;
+  // dispatch to deleteEvent/deleteTodo/deleteJournal
+  return Calendar::deleteIncidence( incidence );
 }
 
 void AkonadiCalendar::incidenceUpdated( IncidenceBase *incidence )
@@ -254,7 +216,6 @@
 bool AkonadiCalendar::addEvent( Event *event )
 {
   kDebug();
-  //Q_ASSERT( ! d->mEvents.contains( event->uid() ) );
   /*
   d->mEvents.insert( uid, event );
   if ( !event->recurs() && !event->isMultiDay() ) {
@@ -264,13 +225,15 @@
   setModified( true );
   notifyIncidenceAdded( event );
   */
-  return true;
+  return d->addIncidence(event);
 }
 
+// this is e.g. called by pimlibs/kcal/icalformat_p.cpp on import to replace
+// existing events with newer ones. We probably like to just update in that
+// case rather then to delete+create...
 bool AkonadiCalendar::deleteEvent( Event *event )
 {
   kDebug();
-  //Q_ASSERT( d->mEvents.contains( event->uid() ) );
   /*
   setModified( true );
   notifyIncidenceDeleted( event );
@@ -280,9 +243,10 @@
       d->mEventsForDate, event->dtStart().date().toString(), event->uid() );
   }
   */
-  return true;
+  return d->deleteIncidence(event);
 }
 
+// hmmm...
 void AkonadiCalendar::deleteAllEvents()
 {
   kDebug();
@@ -305,7 +269,8 @@
 Event *AkonadiCalendar::event( const QString &uid )
 {
   kDebug();
-  Q_ASSERT( d->m_itemMap.contains( uid ) );
+  if( ! d->m_itemMap.contains( uid ) )
+    return 0;
   AkonadiCalendarItem *aci = d->m_itemMap[ uid ];
   Event *event = dynamic_cast<Event*>( aci->incidence().get() );
   Q_ASSERT( event );
@@ -315,7 +280,6 @@
 bool AkonadiCalendar::addTodo( Todo *todo )
 {
   kDebug();
-  //Q_ASSERT( ! d->mTodos.contains( todo->uid() ) );
   /*
   d->mTodos.insert( uid, todo );
   if ( todo->hasDueDate() ) {
@@ -326,14 +290,12 @@
   setModified( true );
   notifyIncidenceAdded( todo );
   */
-  return true;
+  return d->addIncidence(todo);
 }
 
-
 bool AkonadiCalendar::deleteTodo( Todo *todo )
 {
   kDebug();
-  //Q_ASSERT( d->mTodos.contains( todo->uid() ) );
   /*
   // Handle orphaned children
   removeRelations( todo );
@@ -351,7 +313,7 @@
     return false;
   }
   */
-  return true;
+  return d->deleteIncidence(todo);
 }
 
 void AkonadiCalendar::deleteAllTodos()
@@ -376,7 +338,8 @@
 Todo *AkonadiCalendar::todo( const QString &uid )
 {
   kDebug();
-  Q_ASSERT( d->m_itemMap.contains( uid ) );
+  if( ! d->m_itemMap.contains( uid ) )
+    return 0;
   AkonadiCalendarItem *aci = d->m_itemMap[ uid ];
   Todo *todo = dynamic_cast<Todo*>( aci->incidence().get() );
   Q_ASSERT( todo );
@@ -571,8 +534,6 @@
 bool AkonadiCalendar::addJournal( Journal *journal )
 {
   kDebug();
-  QString uid = journal->uid();
-  //Q_ASSERT( ! d->mJournals.contains( uid ) );
   /*
   d->mJournals.insert( uid, journal );
   mJournalsForDate.insert( journal->dtStart().date().toString(), journal );
@@ -580,14 +541,13 @@
   setModified( true );
   notifyIncidenceAdded( journal );
   */
-  return true;
+  return d->addIncidence(journal);
 }
 
 bool AkonadiCalendar::deleteJournal( Journal *journal )
 {
   kDebug();
-  QString uid = journal->uid();
-  //Q_ASSERT( d->mJournals.contains( uid ) );
+  //Q_ASSERT( d->mJournals.contains( journal->uid() ) );
   /*
   if ( d->mJournals.remove( journal->uid() ) ) {
     setModified( true );
@@ -601,7 +561,7 @@
     return false;
   }
   */
-  return true;
+  return d->deleteIncidence(journal);
 }
 
 void AkonadiCalendar::deleteAllJournals()
@@ -626,7 +586,8 @@
 Journal *AkonadiCalendar::journal( const QString &uid )
 {
   kDebug();
-  Q_ASSERT( d->m_itemMap.contains( uid ) );
+  if( ! d->m_itemMap.contains( uid ) )
+    return 0;
   AkonadiCalendarItem *aci = d->m_itemMap[ uid ];
   Journal *journal = dynamic_cast<Journal*>( aci->incidence().get() );
   Q_ASSERT( journal );
--- branches/work/akonadi-ports/kdepim/korganizer/akonadicalendar_p.h #992399:992400
@@ -32,6 +32,7 @@
 #include <akonadi/collectionview.h>
 #include <akonadi/collectionfilterproxymodel.h>
 #include <akonadi/collectionmodel.h>
+#include <akonadi/collectiondialog.h>
 #include <akonadi/itemfetchjob.h>
 #include <akonadi/itemfetchscope.h>
 #include <akonadi/itemdeletejob.h>
@@ -135,6 +136,39 @@
       qDeleteAll(m_collectionMap);
     }
 
+    bool addIncidence( Incidence *incidence )
+    {
+      Akonadi::CollectionDialog dlg( 0 );
+      dlg.setMimeTypeFilter( QStringList() << QString::fromLatin1( "text/calendar" ) \
); +      if ( ! dlg.exec() ) {
+        return false;
+      }
+      const Akonadi::Collection collection = dlg.selectedCollection();
+      Q_ASSERT( collection.isValid() );
+      //Q_ASSERT( m_collectionMap.contains( collection.id() ) ); //we can add items \
to collections we don't show yet +      Q_ASSERT( ! m_itemMap.contains( \
incidence->uid() ) ); //but we can not have the same incidence in 2 collections +
+      Akonadi::Item item;
+      //the sub-mimetype of text/calendar as defined at \
kdepim/akonadi/kcal/kcalmimetypevisitor.cpp +      item.setMimeType( \
QString("application/x-vnd.akonadi.calendar.%1").arg(QString(incidence->type().toLower())) \
); +      KCal::Incidence::Ptr incidencePtr( incidence ); //no clone() needed
+      item.setPayload<KCal::Incidence::Ptr>( incidencePtr );
+      Akonadi::ItemCreateJob *job = new Akonadi::ItemCreateJob( item, collection );
+      connect( job, SIGNAL( result( KJob* ) ), this, SLOT( createDone( KJob* ) ) );
+      return true;
+    }
+
+    bool deleteIncidence( Incidence *incidence )
+    {
+      Q_ASSERT( m_itemMap.contains( incidence->uid() ) );
+      Akonadi::Item item = m_itemMap[ incidence->uid() ]->m_item;
+      Q_ASSERT( item.isValid() );
+      Q_ASSERT( item.hasPayload() );
+      Akonadi::ItemDeleteJob *job = new Akonadi::ItemDeleteJob( item, m_session );
+      connect( job, SIGNAL( result( KJob* ) ), this, SLOT( deleteDone( KJob* ) ) );
+      return true;
+    }
+
 /*
 #if 0
     CalFormat *mFormat;                    // calendar format
@@ -196,11 +230,11 @@
     void modifyDone( KJob *job )
     {
         kDebug();
-        if ( job->error() ) {
+        Akonadi::ItemModifyJob *modifyjob = static_cast<Akonadi::ItemModifyJob*>( \
job ); +        if ( modifyjob->error() ) {
             kWarning( 5250 ) << "Item modify failed:" << job->errorString();
             return;
         }
-        Akonadi::ItemModifyJob *modifyjob = static_cast<Akonadi::ItemModifyJob*>( \
job );  //TODO
         emit q->calendarChanged();
     }
@@ -238,26 +272,10 @@
             Q_ASSERT( item.hasPayload() );
             const KCal::Incidence::Ptr incidence = \
                item.payload<KCal::Incidence::Ptr>();
             kDebug() << "Add uid=" << incidence->uid() << "summary=" << \
                incidence->summary() << "type=" << incidence->type();
-#if 0
-            //TODO use visitor
-            if( Event *event = dynamic_cast<Event*>( incidence.get() ) )
-                mEvents.insert( incidence->uid(), event );
-            else if( Todo *todo = dynamic_cast<Todo*>( incidence.get() ) )
-                mTodos.insert( incidence->uid(), todo );
-            else if( Journal *journal = dynamic_cast<Journal*>( incidence.get() ) )
-                mJournals.insert( incidence->uid(), journal );
-            else
-                Q_ASSERT(false);
-            incidence->registerObserver(q);
-            m_map[ incidence ] = item;
-#else
+            Q_ASSERT( ! m_itemMap.contains( incidence->uid() ) ); //uh, 2 incidences \
with the same uid?  incidence->registerObserver( q );
-
-            Q_ASSERT( ! m_itemMap.contains( incidence->uid() ) );
             m_itemMap[ incidence->uid() ] = new AkonadiCalendarItem(q, item);
-#endif
         }
-
         emit q->calendarChanged();
     }
 
@@ -269,6 +287,7 @@
     }
 
     void itemsRemoved( const Akonadi::Item::List &items, const Akonadi::Collection \
&collection ) { +        Q_UNUSED(collection);
         kDebug()<<items.count();
         foreach(const Akonadi::Item& item, items) {
             Q_ASSERT( item.isValid() );


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

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