Global shortcuts are saved with their text-name and not their action-name - Bug?

Andreas Hartmetz ahartmetz at gmail.com
Mon Dec 31 13:05:20 GMT 2007


Am Sonntag 30 Dezember 2007 20:02:50 schrieb Christian Esken:
> Am Sonntag, 30. Dezember 2007 schrieb Andreas Pakulat:
> > On 30.12.07 15:29:23, Andreas Hartmetz wrote:
> > > Am Sonntag 30 Dezember 2007 13:45:18 schrieb Christian Esken:
> > > > Hello,
> > > >
> > > > global shortcuts are saved with their text set with
> > > > action->setText(), instead of their action name. This is reflected in
> > > > ~/.kde/share/config/kglobalshortcutsrc [1]. As far as I understand
> > > > it, this as a bug. Am I right here?
> > > >
> > > > This has an impact especially on KMix. For example the "increase
> > > > volume"action can be applied to arbitrary controls (e.g. CD, PCM,
> > > > Master), so the actions need to have distinct names (using a prefix
> > > > in the style of "controlID at soundcardID"):
> > > >
> > > >    QString increaseVolumeString = QString("Increase volume %1").arg(
> > > > actionSuffix );  // e.g. actionSuffic == "PCM:0 at ALSA::USB_Audio:1"
> > > > KAction *a = _mdwPopupActions->addAction( increaseVolumeString );
> > > > a->setText( i18n( "Increase Volume" ) );
> > > >
> > > > I cam across this when trying to understand why setting global
> > > > shortcuts in KMix behaves so strange and unreliable. Obviously I
> > > > don't want to present the user a label like "Increase volume
> > > > PCM:0 at ALSA::USB_Audio:1". Any ideas here?
> > >
> > > Oh yes, this is a bug. The biggest problem is that the config name
> > > changes if the language is changed which will obviously cause severe
> > > breakage. But there is no way to fix it because actions don't have any
> > > name except theire text(). There simply is no name() property except if
> > > the action is
> >
> > There's objectName() and KActionCollection sets that property when an
> > action is added, see KActionCollection::addAction(const QString&,
>
> OK, I am using another call, namely addAction(const QString&, const QObject
> *, const char *). Looking at the kactioncollection.cpp this looks fine. I
> checked it and the objectName() is set correctly, e.g. to "Increase volume
> Headphone:0 at ALSA::HDA_NVidia:1".
>
> > QAction*). There's 1 way though to have no object name (or rather an
> > empty one), which is not setting an object name when creating the action
> > and calling addAction with an empty string (see the same function). That
> > one can be changed however as there's always a generated name inside the
> > collection.
> >
> > > inside an action collection and then the name is a property of the
> > > collection. An action can be inserted into two different collections
> > > with two different names.
> >
> > An action automatically changes its name when its inserted into a second
> > collection with a different name.
>
> This sounds good.
>
> But how can we progress from here? As it is now, the shortcuts break when
> changing to another language. Is it still possible to change it for KDE4,
> or is it too dangerous?
>
> If it is not possible, I could use a human readable form for my action
> names prefixes, like "PCM HDA_NVidia 1" instead of a cryptic
> "PCM:0 at ALSA::HDA_NVidia:1".
>
As discussed on IRC with ervin and Chusslove, there is no easy fix. The least 
bad thing we came up with is to postpone translation to the last possible 
moment for all actions. That is very, very invasive though. Another option is 
to "force" all actions to have an objectName by querying it and maybe fail in 
some way (but only for global shortcuts) if they don't have one.
In fact, I maybe have a best-of-both-worlds solution.: Document that an 
objectName() is mandatory for proper global shortcuts management and use the 
text() plus emit a warning if there is none. The objectName() can come from 
inserting the action into a collection or from setting it manually, we don't 
care.
It's also the only realistic option left that I can think of.
Not to mention the only one that won't spoil my party^Wday with work :)

For the record, another option we discussed is to assign numbers to actions in 
their creation order in an application. That can lead to the wrong action 
getting triggered and it is prone to break on small app code changes.

Christian: The action names will show up in the standard shortcut config 
dialog so in any case it is a good thing to give them human-friendly names.

> > And in the case of 2 collections getting the same action without a name
> > they both create the same internal name.
> >
> > Andreas
>
>   Christian




More information about the kde-core-devel mailing list