[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdepim/akonadi/libakonadi
From: Volker Krause <vkrause () kde ! org>
Date: 2008-02-26 22:22:11
Message-ID: 1204064531.345485.1658.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 779756 by vkrause:
Add plural handling for actions that can operate on multiple objects.
M +33 -7 standardactionmanager.cpp
M +20 -2 standardactionmanager.h
--- trunk/KDE/kdepim/akonadi/libakonadi/standardactionmanager.cpp #779755:779756
@@ -50,11 +50,11 @@
const char* slot;
} actionData[] = {
{ "akonadi_collection_create", I18N_NOOP("&New Folder..."), "folder-new", 0, \
SLOT(slotCreateCollection()) },
- { "akonadi_collection_copy", I18N_NOOP("&Copy Folder(s)"), "edit-copy", 0, \
SLOT(slotCopyCollections()) }, + { "akonadi_collection_copy", 0, "edit-copy", 0, \
SLOT(slotCopyCollections()) }, { "akonadi_collection_delete", I18N_NOOP("&Delete \
Folder"), "edit-delete", 0, SLOT(slotDeleteCollection()) }, { \
"akonadi_collection_sync", I18N_NOOP("&Synchronize Folder"), "view-refresh", \
Qt::Key_F5, SLOT(slotSynchronizeCollection()) }, { "akonadi_collection_properties", \
I18N_NOOP("Folder &Properties..."), "configure", 0, SLOT(slotCollectionProperties()) \
},
- { "akonadi_item_copy", I18N_NOOP("&Copy Item(s)"), "edit-copy", 0, \
SLOT(slotCopyItems()) }, + { "akonadi_item_copy", 0, "edit-copy", 0, \
SLOT(slotCopyItems()) }, { "akonadi_manage_local_subscriptions", I18N_NOOP("Manage \
Local &Subscriptions..."), 0, 0, SLOT(slotLocalSubscription()) } };
static const int numActionData = sizeof actionData / sizeof *actionData;
@@ -71,6 +71,9 @@
{
actions.fill( 0, StandardActionManager::LastType );
agentManager = new AgentManager( parent );
+
+ pluralLabels.insert( StandardActionManager::CopyCollections, ki18np( "&Copy \
Folder", "&Copy %1 Folders" ) ); + pluralLabels.insert( \
StandardActionManager::CopyItems, ki18np( "&Copy Item", "&Copy %1 Items" ) ); }
void enableAction( StandardActionManager::Type type, bool enable )
@@ -80,6 +83,14 @@
actions[type]->setEnabled( enable );
}
+ void updatePluralLabel( StandardActionManager::Type type, int count )
+ {
+ Q_ASSERT( type >= 0 && type < StandardActionManager::LastType );
+ if ( actions[type] && pluralLabels.contains( type ) && !pluralLabels.value( \
type ).isEmpty() ) { + actions[type]->setText( pluralLabels.value( type \
).subs( qMax( count, 1 ) ).toString() ); + }
+ }
+
void copy( QItemSelectionModel* selModel )
{
Q_ASSERT( selModel );
@@ -93,11 +104,12 @@
{
bool singleColSelected = false;
bool multiColSelected = false;
+ int colCount = 0;
QModelIndex selectedIndex;
if ( collectionSelectionModel ) {
- const int count = collectionSelectionModel->selectedRows().count();
- singleColSelected = count == 1;
- multiColSelected = count > 0;
+ colCount = collectionSelectionModel->selectedRows().count();
+ singleColSelected = colCount == 1;
+ multiColSelected = colCount > 0;
if ( singleColSelected )
selectedIndex = collectionSelectionModel->selectedRows().first();
}
@@ -117,12 +129,17 @@
}
bool multiItemSelected = false;
+ int itemCount = 0;
if ( itemSelectionModel ) {
- multiItemSelected = itemSelectionModel->selectedRows().count() > 0;
+ itemCount = itemSelectionModel->selectedRows().count();
+ multiItemSelected = itemCount > 0;
}
enableAction( CopyItems, multiItemSelected );
+ updatePluralLabel( CopyCollections, colCount );
+ updatePluralLabel( CopyItems, itemCount );
+
emit q->actionStateUpdated();
}
@@ -224,6 +241,7 @@
QItemSelectionModel *itemSelectionModel;
QVector<KAction*> actions;
AgentManager *agentManager;
+ QHash<StandardActionManager::Type, KLocalizedString> pluralLabels;
};
StandardActionManager::StandardActionManager( KActionCollection * actionCollection,
@@ -261,7 +279,9 @@
if ( d->actions[type] )
return d->actions[type];
KAction *action = new KAction( d->parentWidget );
- if ( actionData[type].label )
+ if ( d->pluralLabels.contains( type ) && !d->pluralLabels.value( type ).isEmpty() \
) + action->setText( d->pluralLabels.value( type ).subs( 1 ).toString() );
+ else if ( actionData[type].label )
action->setText( i18n( actionData[type].label ) );
if ( actionData[type].icon )
action->setIcon( KIcon( QString::fromLatin1( actionData[type].icon ) ) );
@@ -286,4 +306,10 @@
return d->actions[type];
}
+void StandardActionManager::setActionText(Type type, const KLocalizedString & text)
+{
+ Q_ASSERT( type >= 0 && type < LastType );
+ d->pluralLabels.insert( type, text );
+}
+
#include "standardactionmanager.moc"
--- trunk/KDE/kdepim/akonadi/libakonadi/standardactionmanager.h #779755:779756
@@ -22,6 +22,7 @@
#include "libakonadi_export.h"
+#include <KLocalizedString>
#include <QtCore/QObject>
class KAction;
@@ -44,7 +45,10 @@
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.
+ 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.
@@ -93,7 +97,7 @@
@param actionCollection The action collection to operate on.
@param parent The parent widget.
*/
- StandardActionManager( KActionCollection *actionCollection, QWidget *parent = 0 \
); + explicit StandardActionManager( KActionCollection *actionCollection, QWidget \
*parent = 0 );
/**
Destructor.
@@ -131,6 +135,20 @@
*/
KAction* action( Type type ) const;
+ /**
+ Sets the label of the action @p type to @p 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.
+
+ Example:
+ @verbatim
+ acctMgr->setActionText( Akonadi::StandardActionManager::CopyItems,
+ ki18np( "Copy Mail", "Copy %1 Mails" ) );
+ @endverbatim
+ */
+ void setActionText( Type type, const KLocalizedString &text );
+
Q_SIGNALS:
/**
Emitted when the action state has been updated.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic