summaryrefslogtreecommitdiffstats
path: root/kaddressbook/features
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-05-14 02:06:47 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-05-14 02:06:47 +0000
commitacc2b77512ce0d8d708dda14dec1464f3eed830c (patch)
tree7917cc141e67ba40a4d4b06c752b66ede069b3da /kaddressbook/features
parent54887c51b14c7707178d43d39413bf1bc7a17472 (diff)
downloadtdepim-acc2b77512ce0d8d708dda14dec1464f3eed830c.tar.gz
tdepim-acc2b77512ce0d8d708dda14dec1464f3eed830c.zip
Second batch of kdepim stability and functionality repairs
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdepim@1126473 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kaddressbook/features')
-rw-r--r--kaddressbook/features/resourceselection.cpp87
-rw-r--r--kaddressbook/features/resourceselection.h4
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;