summaryrefslogtreecommitdiffstats
path: root/kaddressbook
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
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')
-rw-r--r--kaddressbook/features/resourceselection.cpp87
-rw-r--r--kaddressbook/features/resourceselection.h4
-rw-r--r--kaddressbook/kabcore.cpp49
-rw-r--r--kaddressbook/views/contactlistview.cpp7
4 files changed, 111 insertions, 36 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;
diff --git a/kaddressbook/kabcore.cpp b/kaddressbook/kabcore.cpp
index 0702ce04e..449357d16 100644
--- a/kaddressbook/kabcore.cpp
+++ b/kaddressbook/kabcore.cpp
@@ -226,7 +226,7 @@ void KABCore::restoreSettings()
mDetailsSplitter->setSizes( splitterSize );
const QValueList<int> leftSplitterSizes = KABPrefs::instance()->leftSplitter();
- if ( !leftSplitterSizes.isEmpty() )
+ if ( !leftSplitterSizes.isEmpty() )
mLeftSplitter->setSizes( leftSplitterSizes );
}
@@ -236,7 +236,7 @@ void KABCore::saveSettings()
KABPrefs::instance()->setDetailsPageVisible( mActionDetails->isChecked() );
KABPrefs::instance()->setDetailsSplitter( mDetailsSplitter->sizes() );
KABPrefs::instance()->setLeftSplitter( mLeftSplitter->sizes() );
-
+
mExtensionManager->saveSettings();
mViewManager->saveSettings();
@@ -295,10 +295,11 @@ QWidget *KABCore::widget() const
KAboutData *KABCore::createAboutData()
{
KAboutData *about = new KAboutData( "kaddressbook", I18N_NOOP( "KAddressBook" ),
- "3.5.10", I18N_NOOP( "The KDE Address Book" ),
+ "3.5.11", I18N_NOOP( "The KDE Address Book" ),
KAboutData::License_GPL_V2,
- I18N_NOOP( "(c) 1997-2005, The KDE PIM Team" ) );
- about->addAuthor( "Tobias Koenig", I18N_NOOP( "Current maintainer" ), "tokoe@kde.org" );
+ I18N_NOOP( "(c) 2008-2010, The Trinity Team\n(c) 1997-2005, The KDE PIM Team" ) );
+ about->addAuthor( "Timothy Pearson", I18N_NOOP( "Current maintainer" ), "kb9vqf@pearsoncomputing.net" );
+ about->addAuthor( "Tobias Koenig", I18N_NOOP( "Previous maintainer" ), "tokoe@kde.org" );
about->addAuthor( "Don Sanders", I18N_NOOP( "Original author" ) );
about->addAuthor( "Cornelius Schumacher",
I18N_NOOP( "Co-maintainer, libkabc port, CSV import/export" ),
@@ -327,10 +328,15 @@ KStatusBar *KABCore::statusBar() const
void KABCore::setContactSelected( const QString &uid )
{
+ // Avoid crash on exit
+ if ( !mAddressBook ) {
+ return;
+ }
+
KABC::Addressee addr = mAddressBook->findByUid( uid );
if ( !mDetailsViewer->isHidden() )
mDetailsViewer->setAddressee( addr );
-#ifdef KDEPIM_NEW_DISTRLISTS
+#ifdef KDEPIM_NEW_DISTRLISTS
if ( !mSelectedDistributionList.isNull() && mDistListEntryView->isShown() ) {
showDistributionListEntry( uid );
}
@@ -470,10 +476,10 @@ void KABCore::deleteDistributionLists( const QStringList & names )
QStringList uids;
for ( QStringList::ConstIterator it = names.begin(); it != names.end(); ++it ) {
- uids.append( KPIM::DistributionList::findByName( mAddressBook, *it ).uid() );
+ uids.append( KPIM::DistributionList::findByName( mAddressBook, *it ).uid() );
}
DeleteCommand *command = new DeleteCommand( mAddressBook, uids );
- mCommandHistory->addCommand( command );
+ mCommandHistory->addCommand( command );
setModified( true );
}
@@ -667,7 +673,7 @@ void KABCore::newDistributionList()
bool foundUnused = false;
int i = 1;
while ( !foundUnused ) {
- name = i18n( "New Distribution List (%1)" ).arg( i++ );
+ name = i18n( "New Distribution List (%1)" ).arg( i++ );
foundUnused = KPIM::DistributionList::findByName( addressBook(), name ).isEmpty();
}
}
@@ -1158,14 +1164,14 @@ void KABCore::initGUI()
topLayout->addWidget( searchTB );
topLayout->addWidget( mDetailsSplitter );
-
+
mDetailsStack = new QWidgetStack( mDetailsSplitter );
mExtensionManager = new ExtensionManager( new QWidget( mLeftSplitter ), mDetailsStack, this, this );
- connect( mExtensionManager, SIGNAL( detailsWidgetDeactivated( QWidget* ) ),
+ connect( mExtensionManager, SIGNAL( detailsWidgetDeactivated( QWidget* ) ),
this, SLOT( deactivateDetailsWidget( QWidget* ) ) );
- connect( mExtensionManager, SIGNAL( detailsWidgetActivated( QWidget* ) ),
+ connect( mExtensionManager, SIGNAL( detailsWidgetActivated( QWidget* ) ),
this, SLOT( activateDetailsWidget( QWidget* ) ) );
-
+
QWidget *viewWidget = new QWidget( mLeftSplitter );
if ( KABPrefs::instance()->contactListAboveExtensions() )
mLeftSplitter->moveToFirst( viewWidget );
@@ -1187,7 +1193,7 @@ void KABCore::initGUI()
KPushButton *addDistListButton = new KPushButton( mDistListButtonWidget );
addDistListButton->setText( i18n( "Add" ) );
- connect( addDistListButton, SIGNAL( clicked() ),
+ connect( addDistListButton, SIGNAL( clicked() ),
this, SLOT( editSelectedDistributionList() ) );
buttonLayout->addWidget( addDistListButton );
mDistListButtonWidget->setShown( false );
@@ -1195,7 +1201,7 @@ void KABCore::initGUI()
KPushButton *removeDistListButton = new KPushButton( mDistListButtonWidget );
removeDistListButton->setText( i18n( "Remove" ) );
- connect( removeDistListButton, SIGNAL( clicked() ),
+ connect( removeDistListButton, SIGNAL( clicked() ),
this, SLOT( removeSelectedContactsFromDistList() ) );
buttonLayout->addWidget( removeDistListButton );
#endif
@@ -1404,6 +1410,11 @@ QStringList KABCore::allCategories() const
QStringList categories, allCategories;
QStringList::ConstIterator catIt;
+ // Avoid crash on exit
+ if ( !mAddressBook ) {
+ return allCategories;
+ }
+
KABC::AddressBook::ConstIterator it;
const KABC::AddressBook::ConstIterator endIt( mAddressBook->end() );
for ( it = mAddressBook->begin(); it != endIt; ++it ) {
@@ -1559,12 +1570,12 @@ void KABCore::sendMailToDistributionList( const QString &name )
KPIM::DistributionList dist = KPIM::DistributionList::findByName( addressBook(), name );
if ( dist.isEmpty() )
return;
- typedef KPIM::DistributionList::Entry::List EntryList;
+ typedef KPIM::DistributionList::Entry::List EntryList;
QStringList mails;
const EntryList entries = dist.entries( addressBook() );
for ( EntryList::ConstIterator it = entries.begin(); it != entries.end(); ++it )
mails += (*it).addressee.fullEmail( (*it).email );
- sendMail( mails.join( ", " ) );
+ sendMail( mails.join( ", " ) );
#endif
}
@@ -1590,8 +1601,8 @@ void KABCore::showDistributionListEntry( const QString& uid )
KPIM::DistributionList dist = KPIM::DistributionList::findByName( addressBook(), mSelectedDistributionList );
if ( !dist.isEmpty() ) {
mDistListEntryView->clear();
- typedef KPIM::DistributionList::Entry::List EntryList;
- const EntryList entries = dist.entries( addressBook() );
+ typedef KPIM::DistributionList::Entry::List EntryList;
+ const EntryList entries = dist.entries( addressBook() );
for (EntryList::ConstIterator it = entries.begin(); it != entries.end(); ++it ) {
if ( (*it).addressee.uid() == uid ) {
mDistListEntryView->setEntry( dist, *it );
diff --git a/kaddressbook/views/contactlistview.cpp b/kaddressbook/views/contactlistview.cpp
index 1deadc190..90941ff56 100644
--- a/kaddressbook/views/contactlistview.cpp
+++ b/kaddressbook/views/contactlistview.cpp
@@ -216,7 +216,12 @@ ContactListView *ContactListViewItem::parent()
void ContactListViewItem::refresh()
{
- // Update our addressee, since it may have changed else were
+ // Avoid crash on exit
+ if ( !mDocument ) {
+ return;
+ }
+
+ // Update our addressee, since it may have changed elsewhere
mAddressee = mDocument->findByUid(mAddressee.uid());
if (mAddressee.isEmpty())
return;