[Kde-pim] KDE/kdepim/kaddressbook/features

Kevin Krammer kevin.krammer at gmx.at
Wed Aug 20 22:26:47 BST 2008


SVN commit 850163 by krake:

Improved handling of treewidget items for sub resources, e.g. avoid double creation, handle removeSubResource signal, etc.

Everybody using sub resource plugins please test as well

CCMAIL: kde-pim at kde.org


 M  +29 -2     resourceselection.cpp  
 M  +3 -0      resourceselection.h  


--- trunk/KDE/kdepim/kaddressbook/features/resourceselection.cpp #850162:850163
@@ -340,7 +340,13 @@
     return;
 
   KABCResourceItem *item = static_cast<KABCResourceItem *>( foundItems[0] );
-  (void)new KABCResourceItem( resource, item, subResource );
+
+  // make sure all other sub items have already been created
+  item->createSubresourceItems();
+
+  // check if we already have an item for it
+  if ( !findSubResourceItem( resource, subResource ) )
+    (void)new KABCResourceItem( resource, item, subResource );
 }
 
 // Remove an entry
@@ -349,8 +355,10 @@
                                                 const QString& subResource )
 {
   kDebug(5720) << resource->resourceName() << subResource;
+
+  KABCResourceItem *item = findSubResourceItem( resource, subResource );
+  delete item;
   // TODO
-  //delete findItemByIdentifier( resource );
   //emitResourcesChanged();
 }
 
@@ -359,6 +367,25 @@
   return static_cast<KABCResourceItem*>( mListView->currentItem() );
 }
 
+KABCResourceItem* ResourceSelection::findSubResourceItem( KABC::ResourceABC *resource,
+                                                          const QString &subResource )
+{
+  QTreeWidgetItemIterator parentIt( mListView );
+  for ( ; *parentIt; ++parentIt ) {
+    if ( static_cast<KABCResourceItem*>(*parentIt)->resource() != resource )
+      continue;
+
+    QTreeWidgetItemIterator childIt( *parentIt );
+    for ( ; *childIt; ++childIt ) {
+      KABCResourceItem *item = static_cast<KABCResourceItem*>(*childIt);
+      if ( item->resourceIdentifier() == subResource )
+        return item;
+    }
+  }
+
+  return 0;
+}
+
 void ResourceSelection::initGUI()
 {
   QBoxLayout *topLayout = new QVBoxLayout( this );
--- trunk/KDE/kdepim/kaddressbook/features/resourceselection.h #850162:850163
@@ -67,6 +67,9 @@
 
     KABCResourceItem* selectedItem() const;
 
+    KABCResourceItem* findSubResourceItem( KABC::ResourceABC *resource,
+                                           const QString &subResource );
+
     QTreeWidget *mListView;
     QAbstractButton *mAddButton;
     QAbstractButton *mEditButton;
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/



More information about the kde-pim mailing list