Akonadi::StandardActionManager Class
Manages generic actions for collection and item views. More...
| Header: | #include <Akonadi/StandardActionManager> |
| CMake: | find_package(KPim6 REQUIRED COMPONENTS AkonadiWidgets)target_link_libraries(mytarget PRIVATE KPim6::AkonadiWidgets) |
Public Types
| enum | TextContext { DialogTitle, DialogText, MessageBoxTitle, MessageBoxText, MessageBoxAlternativeText, …, ErrorMessageText } |
| enum | Type { CreateCollection, CopyCollections, DeleteCollections, SynchronizeCollections, CollectionProperties, …, LastType } |
Public Functions
| StandardActionManager(KActionCollection *actionCollection, QWidget *parent = nullptr) | |
| virtual | ~StandardActionManager() override |
| QAction * | action(Akonadi::StandardActionManager::Type type) const |
| void | addRecentCollection(Akonadi::Collection::Id id) const |
| QAction * | createAction(Akonadi::StandardActionManager::Type type) |
| void | createActionFolderMenu(QMenu *menu, Akonadi::StandardActionManager::Type type) |
| void | createAllActions() |
| void | interceptAction(Akonadi::StandardActionManager::Type type, bool intercept = true) |
| Akonadi::Collection::List | selectedCollections() const |
| Akonadi::Item::List | selectedItems() const |
| void | setActionText(Akonadi::StandardActionManager::Type type, const KLocalizedString &text) |
| void | setCapabilityFilter(const QStringList &capabilities) |
| void | setCollectionPropertiesPageNames(const QStringList &names) |
| void | setCollectionSelectionModel(QItemSelectionModel *selectionModel) |
| void | setContextText(Akonadi::StandardActionManager::Type type, Akonadi::StandardActionManager::TextContext context, const KLocalizedString &text) |
| void | setFavoriteCollectionsModel(Akonadi::FavoriteCollectionsModel *favoritesModel) |
| void | setFavoriteSelectionModel(QItemSelectionModel *selectionModel) |
| void | setItemSelectionModel(QItemSelectionModel *selectionModel) |
| void | setMimeTypeFilter(const QStringList &mimeTypes) |
Signals
| void | actionStateUpdated() |
| void | selectionsChanged(const Akonadi::Collection::List &selectedCollectionsList, const Akonadi::Collection::List &selectedFavoriteCollectionsList, const Akonadi::Item::List &selectedItems) |
Detailed Description
Manages generic Akonadi actions common for all types. This covers creating of the actions with appropriate labels, icons, shortcuts etc., updating the action state depending on the current selection as well as default implementations for the actual operations.
If the default implementation is not appropriate for your application you can still use the state tracking by disconnecting the triggered() signal and re-connecting it to your implementation. The actual KAction objects can be retrieved by calling createAction() or action() for that.
If the default look and feel (labels, icons, shortcuts) of the actions is not appropriate for your application, you can access them as noted above and customize them to your needs. Additionally, you can set a KLocalizedString which should be used as a action label with correct plural handling for actions operating on multiple objects with setActionText().
Finally, if you have special needs for the action states, connect to the actionStateUpdated() signal and adjust the state accordingly.
The following actions are provided (KAction name in parenthesis): - Creation of a new collection (\ akonadi_collection_create) - Copying of selected collections (\ akonadi_collection_copy) - Deletion of selected collections (\ akonadi_collection_delete) - Synchronization of selected collections (\ akonadi_collection_sync) - Showing the collection properties dialog for the current collection (\ akonadi_collection_properties) - Copying of selected items (\ akonadi_itemcopy) - Pasting collections, items or raw data (\ akonadi_paste) - Deleting of selected items (\ akonadi_item_delete) - Managing local subscriptions (\ akonadi_manage_local_subscriptions)
The following example shows how to use standard actions in your application:
Akonadi::StandardActionManager *actMgr = new Akonadi::StandardActionManager( actionCollection(), this ); actMgr->setCollectionSelectionModel( collectionView->collectionSelectionModel() ); actMgr->createAllActions();
Additionally you have to add the actions to the KXMLGUI file of your application, using the names listed above.
If you only need a subset of the actions provided, you can call createAction() instead of createAllActions() for the action types you want.
If you want to use your own implementation of the actual action operation and not the default implementation, you can call interceptAction() on the action type you want to handle yourself and connect the slot with your own implementation to the triggered() signal of the action:
using namespace Akonadi; StandardActionManager *manager = new StandardActionManager( actionCollection(), this ); manager->setCollectionSelectionModel( collectionView->collectionSelectionModel() ); manager->createAllActions(); // disable default implementation manager->interceptAction( StandardActionManager::CopyCollections ); // connect your own implementation connect( manager->action( StandardActionManager::CopyCollections ), SIGNAL(triggered(bool)), this, SLOT(myCopyImplementation()) ); ... void MyClass::myCopyImplementation() { const Collection::List collections = manager->selectedCollections(); for ( const Collection &collection : collections ) { // copy the collection manually... } }
\todocollection deleting and sync do not support multi-selection yet
Author: Volker Krause <vkrause@kde.org>
Member Type Documentation
enum StandardActionManager::TextContext
Describes the text context that can be customized.
enum StandardActionManager::Type
Describes the supported actions.
Member Function Documentation
[explicit] StandardActionManager::StandardActionManager(KActionCollection *actionCollection, QWidget *parent = nullptr)
Creates a new standard action manager.
actionCollection The action collection to operate on. parent The parent widget.
[override virtual noexcept] StandardActionManager::~StandardActionManager()
Destroys the standard action manager.
QAction *StandardActionManager::action(Akonadi::StandardActionManager::Type type) const
Returns the action of the given type, 0 if it has not been created (yet). type action type
[signal] void StandardActionManager::actionStateUpdated()
This signal is emitted whenever the action state has been updated. In case you have special needs for changing the state of some actions, connect to this signal and adjust the action state.
void StandardActionManager::addRecentCollection(Akonadi::Collection::Id id) const
Add a collection to the global recent collection list.
id the collection ID
QAction *StandardActionManager::createAction(Akonadi::StandardActionManager::Type type)
Creates the action of the given type and adds it to the action collection specified in the constructor if it does not exist yet. The action is connected to its default implementation provided by this class.
type action to be created
void StandardActionManager::createActionFolderMenu(QMenu *menu, Akonadi::StandardActionManager::Type type)
Create a popup menu.
menu parent menu for a popup type action type
void StandardActionManager::createAllActions()
Convenience method to create all standard actions.
See also createAction().
void StandardActionManager::interceptAction(Akonadi::StandardActionManager::Type type, bool intercept = true)
Sets whether the default implementation for the given action type shall be executed when the action is triggered.
type action type intercept If \ false, the default implementation will be executed, if \ true no action is taken.
Akonadi::Collection::List StandardActionManager::selectedCollections() const
Returns the list of collections that are currently selected. The list is empty if no collection is currently selected.
Akonadi::Item::List StandardActionManager::selectedItems() const
Returns the list of items that are currently selected. The list is empty if no item is currently selected.
[signal] void StandardActionManager::selectionsChanged(const Akonadi::Collection::List &selectedCollectionsList, const Akonadi::Collection::List &selectedFavoriteCollectionsList, const Akonadi::Item::List &selectedItems)
This signal is emitted whenever one of the selections has changed (selected collections, selected favorites collections, selected items) This allows other action managers to update their actions accordingly (see e.g. StandardMailActionManager)
void StandardActionManager::setActionText(Akonadi::StandardActionManager::Type type, const KLocalizedString &text)
Sets the label of the action type to text, which is used during updating the action state and substituted according to the number of selected objects. This is mainly useful to customize the label of actions that can operate on multiple objects. type the action to set a text for text the text to display for the given action Example:
acctMgr->setActionText( Akonadi::StandardActionManager::CopyItems, ki18np( "Copy Mail", "Copy %1 Mails" ) );
void StandardActionManager::setCapabilityFilter(const QStringList &capabilities)
Sets the capability filter that will be used when creating new resources.
capabilities filter for creating new resources
void StandardActionManager::setCollectionPropertiesPageNames(const QStringList &names)
Sets the page names of the config pages that will be used by the built-in collection properties dialog.
names list of names which will be used
void StandardActionManager::setCollectionSelectionModel(QItemSelectionModel *selectionModel)
Sets the collection selection model based on which the collection related actions should operate. If none is set, all collection actions will be disabled.
selectionModel model to be set for collection
void StandardActionManager::setContextText(Akonadi::StandardActionManager::Type type, Akonadi::StandardActionManager::TextContext context, const KLocalizedString &text)
Sets the text of the action type for the given context.
type action type context context for action text content to set for the action
void StandardActionManager::setFavoriteCollectionsModel(Akonadi::FavoriteCollectionsModel *favoritesModel)
Sets the favorite collections model based on which the collection relatedactions should operate. If none is set, the "Add to Favorite Folders" action will be disabled.
favoritesModel model for the user's favorite collections
void StandardActionManager::setFavoriteSelectionModel(QItemSelectionModel *selectionModel)
Sets the favorite collection selection model based on which the favorite collection related actions should operate. If none is set, all favorite modifications actions will be disabled.
selectionModel selection model for favorite collections
void StandardActionManager::setItemSelectionModel(QItemSelectionModel *selectionModel)
Sets the item selection model based on which the item related actions should operate. If none is set, all item actions will be disabled.
selectionModel selection model for items
void StandardActionManager::setMimeTypeFilter(const QStringList &mimeTypes)
Sets the mime type filter that will be used when creating new resources.
mimeTypes filter for creating new resources