[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdepim/kaddressbook
From: Tobias Koenig <tokoe () kde ! org>
Date: 2010-06-20 10:22:24
Message-ID: 20100620102224.AE279AC8D9 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1140325 by tokoe:
Enabled/disable the 'New Contact' and 'New Contact Group' actions depending
on whether there exists a writable address book
BUG: 238375
M +44 -6 standardcontactactionmanager.cpp
--- trunk/KDE/kdepim/kaddressbook/standardcontactactionmanager.cpp #1140324:1140325
@@ -74,6 +74,35 @@
delete mGenericManager;
}
+ static bool hasWritableCollection( const QModelIndex &index, const QString \
&mimeType ) + {
+ const Akonadi::Collection collection = index.data( \
Akonadi::EntityTreeModel::CollectionRole ).value<Akonadi::Collection>(); + if ( \
collection.isValid() ) { + if ( collection.contentMimeTypes().contains( \
mimeType ) && (collection.rights() & Akonadi::Collection::CanCreateItem) ) + \
return true; + }
+
+ const QAbstractItemModel *model = index.model();
+ if ( !model )
+ return false;
+
+ for ( int row = 0; row < model->rowCount( index ); ++row ) {
+ if ( hasWritableCollection( model->index( row, 0, index ), mimeType ) )
+ return true;
+ }
+
+ return false;
+ }
+
+ bool hasWritableCollection( const QString &mimeType ) const
+ {
+ if ( !mCollectionSelectionModel )
+ return false;
+
+ const QAbstractItemModel *collectionModel = \
mCollectionSelectionModel->model(); + return hasWritableCollection( \
collectionModel->index( 0, 0 ), mimeType ); + }
+
void updateActions()
{
int itemCount = 0;
@@ -118,17 +147,16 @@
mActions[ StandardContactActionManager::DeleteAddressBook \
]->setEnabled( isEnabled );
if ( mActions.contains( \
StandardContactActionManager::ConfigureAddressBook ) )
mActions[ StandardContactActionManager::ConfigureAddressBook \
]->setEnabled( isEnabled );
-
- // only enable 'Create Contact Group' action if current collection \
supports contact groups
- if ( mActions.contains( \
StandardContactActionManager::CreateContactGroup ) ) {
- const bool isEnabled = collection.contentMimeTypes().contains( \
KABC::ContactGroup::mimeType() );
- mActions[ StandardContactActionManager::CreateContactGroup \
]->setEnabled( isEnabled ); }
}
}
}
- }
+ if ( mActions.contains( StandardContactActionManager::CreateContact ) )
+ mActions[ StandardContactActionManager::CreateContact ]->setEnabled( \
hasWritableCollection( KABC::Addressee::mimeType() ) ); + if ( \
mActions.contains( StandardContactActionManager::CreateContactGroup ) ) + \
mActions[ StandardContactActionManager::CreateContactGroup ]->setEnabled( \
hasWritableCollection( KABC::ContactGroup::mimeType() ) ); +
if ( mActions.contains( StandardContactActionManager::EditItem ) ) {
bool canEditItem = true;
@@ -277,8 +305,14 @@
d->mCollectionSelectionModel = selectionModel;
d->mGenericManager->setCollectionSelectionModel( selectionModel );
+ connect( selectionModel->model(), SIGNAL( rowsInserted( const QModelIndex&, int, \
int ) ), + SLOT( updateActions() ) );
+ connect( selectionModel->model(), SIGNAL( rowsRemoved( const QModelIndex&, int, \
int ) ), + SLOT( updateActions() ) );
connect( selectionModel, SIGNAL( selectionChanged( const QItemSelection&, const \
QItemSelection& ) ), SLOT( updateActions() ) );
+
+ d->updateActions();
}
void StandardContactActionManager::setItemSelectionModel( QItemSelectionModel* \
selectionModel ) @@ -288,6 +322,8 @@
connect( selectionModel, SIGNAL( selectionChanged( const QItemSelection&, const \
QItemSelection& ) ), SLOT( updateActions() ) );
+
+ d->updateActions();
}
KAction* StandardContactActionManager::createAction( Type type )
@@ -375,6 +411,8 @@
createAction( ConfigureAddressBook );
d->mGenericManager->createAllActions();
+
+ d->updateActions();
}
KAction* StandardContactActionManager::action( Type type ) const
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic