diff options
Diffstat (limited to 'kaddressbook/features')
-rw-r--r-- | kaddressbook/features/resourceselection.cpp | 87 | ||||
-rw-r--r-- | kaddressbook/features/resourceselection.h | 4 |
2 files changed, 75 insertions, 16 deletions
diff --git a/kaddressbook/features/resourceselection.cpp b/kaddressbook/features/resourceselection.cpp index c7e89dbf5..c18d8b168 100644 --- a/kaddressbook/features/resourceselection.cpp +++ b/kaddressbook/features/resourceselection.cpp @@ -82,7 +82,10 @@ class ResourceItem : public QCheckListItem void createSubresourceItems(); - void setChecked( bool state ) { mChecked = state; } + void setChecked( bool state ) { + mChecked = state; + setOn(state); + } bool checked() const { return mChecked; } KABC::Resource *resource() const { return mResource; } QString resourceIdentifier() const { return mResourceIdentifier; } @@ -117,15 +120,6 @@ void ResourceItem::createSubresourceItems() mSubItemsCreated = true; } -// TODO: connect this to some signalResourceModified -// void ResourceItem::setGuiState() -// { -// if ( mIsSubresource ) -// setOn( mResource->subresourceActive( mResourceIdentifier ) ); -// else -// setOn( mResource->isActive() ); -// } - void ResourceItem::stateChange( bool active ) { //kdDebug(5720) << k_funcinfo << this << " " << text( 0 ) << " active=" << active << endl; @@ -216,13 +210,18 @@ void ResourceSelection::edit() if ( !item ) return; - KRES::ConfigDialog dlg( this, QString( "contact" ), item->resource() ); + // view items can change during "edit", e.g. sub resources being removed -> + // sub resource item removed + // thus keep their data rather than their pointer + KABC::Resource *resource = item->resource(); + + KRES::ConfigDialog dlg( this, QString( "contact" ), resource ); if ( dlg.exec() ) { - mManager->change( item->resource() ); - item->resource()->asyncLoad(); + mManager->change( resource ); + resource->asyncLoad(); - mLastResource = item->resource()->identifier(); + mLastResource = resource->identifier(); updateView(); } } @@ -300,7 +299,7 @@ void ResourceSelection::updateView() KRES::Manager<KABC::Resource>::Iterator it; for ( it = mManager->begin(); it != mManager->end(); ++it ) { - new ResourceItem( mListView, *it ); + ResourceItem *item = new ResourceItem( mListView, *it ); KPIM::ResourceABC* resource = dynamic_cast<KPIM::ResourceABC *>( *it ); if ( resource ) { disconnect( resource, 0, this, 0 ); @@ -313,8 +312,15 @@ void ResourceSelection::updateView() const QString &, const QString & ) ), SLOT( slotSubresourceRemoved( KPIM::ResourceABC *, const QString &, const QString & ) ) ); + + connect( resource, SIGNAL( signalSubresourceChanged( KPIM::ResourceABC *, + const QString &, const QString & ) ), + SLOT( slotSubresourceChanged( KPIM::ResourceABC *, + const QString &, const QString & ) ) ); + //connect( resource, SIGNAL( resourceSaved( KPIM::ResourceABC * ) ), // SLOT( closeResource( KPIM::ResourceABC * ) ) ); + item->createSubresourceItems(); } } @@ -345,7 +351,13 @@ void ResourceSelection::slotSubresourceAdded( KPIM::ResourceABC *resource, return; ResourceItem *item = static_cast<ResourceItem *>( i ); - (void)new ResourceItem( 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 ResourceItem( resource, item, subResource ); + } } // Remove an entry @@ -353,6 +365,30 @@ void ResourceSelection::slotSubresourceRemoved( KPIM::ResourceABC* resource, const QString& /*type*/, const QString& subResource ) { + ResourceItem *item = findSubResourceItem( resource, subResource ); + delete item; + core()->addressBook()->emitAddressBookChanged(); + updateView(); +} + +// change an entry +void ResourceSelection::slotSubresourceChanged( KPIM::ResourceABC* resource, + const QString& type, + const QString& subResource ) +{ + kdDebug(5720) << resource->resourceName() << subResource; + + ResourceItem *item = findSubResourceItem( resource, subResource ); + if ( item == 0 ) { + kdWarning(5720) << "Changed before it was added?"; + slotSubresourceAdded( resource, type, subResource ); + return; + } + + item->setText( 0, resource->subresourceLabel( subResource ) ); + item->setChecked( resource->subresourceActive( subResource ) ? true : false ); + // TODO + //emitResourcesChanged(); core()->addressBook()->emitAddressBookChanged(); updateView(); } @@ -362,6 +398,25 @@ ResourceItem* ResourceSelection::selectedItem() const return static_cast<ResourceItem*>( mListView->selectedItem() ); } +ResourceItem* ResourceSelection::findSubResourceItem( KPIM::ResourceABC *resource, + const QString &subResource ) +{ + QListViewItemIterator parentIt( mListView ); + for ( ; *parentIt; ++parentIt ) { + if ( static_cast<ResourceItem*>(*parentIt)->resource() != resource ) + continue; + + QListViewItemIterator childIt( *parentIt ); + for ( ; *childIt; ++childIt ) { + ResourceItem *item = static_cast<ResourceItem*>(*childIt); + if ( item->resourceIdentifier() == subResource ) + return item; + } + } + + return 0; +} + void ResourceSelection::initGUI() { QBoxLayout *topLayout = new QVBoxLayout( this ); diff --git a/kaddressbook/features/resourceselection.h b/kaddressbook/features/resourceselection.h index 07c458f37..6e1a56b04 100644 --- a/kaddressbook/features/resourceselection.h +++ b/kaddressbook/features/resourceselection.h @@ -62,11 +62,15 @@ class ResourceSelection : public KAB::ExtensionWidget void slotSubresourceRemoved( KPIM::ResourceABC* /*resource*/, const QString& /*type*/, const QString& subResource ); + void slotSubresourceChanged( KPIM::ResourceABC* /*resource*/, + const QString& /*type*/, + const QString& subResource ); private: void initGUI(); ResourceItem* selectedItem() const; + ResourceItem* findSubResourceItem( KPIM::ResourceABC *resource, const QString &subResource ); KListView *mListView; QPushButton *mAddButton; |