[PATCH] Don't loose shortcuts when closing global shortcut kcm

Aurélien Gâteau aurelien.gateau at free.fr
Sun Jan 20 01:15:54 GMT 2008

Kevin Ottens wrote:

> Le samedi 19 janvier 2008, Aurélien Gâteau a écrit :
>> When one close the "global shortcut" kcm (kcmshell4 keys), all global
>> shortcuts are gone. Include kwin shortcuts, so there is no more alt+tab
>> or alt+f4. Attached patch fix this. Ok to commit and backport?
> Hm, from your patch, doesn't it mean we'll leak memory instead?

Hm, yes. It's the first time I introduce a leak on purpose :/. The goal is
to avoid having the KAction destructor called, as it would remove the
global shortcut.
It's not a serious leak: the allocated memory used to be freed when the kcm
was destroyed, which happened when you quit the kcm host process. It's
still freed at this time now.

The problem comes from the fact that we need to create KAction instances for
the shortcuts so that we can use KShortcutsEditor, but those KAction are
not the real ones, we just fake them.

An alternative solution could be adding a flag to KAction to instruct it not
to remove the global shortcut, but it would clutter the API for a very
marginal use IMHO.

We could also move the shortcut removal code from ~KAction to a virtual
removeShortcuts() method, like this:

KAction::~KAction() {

void KAction::removeShortcuts() {
        /* real shortcut removal code */

Then in the KCM we would create a FakeAction class, inheriting from KAction
and reimplementing removeShortcuts() to be an empty method. Don't know
which one is the best.

> Also, what's the aim for this part of the patch:
> +        KAction *action = col->addAction(actionname);
> +        action->setText(actionlist.at(1));

To avoid having the action deleted, it must not be a child of "this", so I
figured it would be nicer to make it a child of the action collection,
rather than setting its parent pointer to 0.


More information about the kde-core-devel mailing list