Fix toolbar button text hiding opt

Review Request #130047 - Created March 24, 2017 and updated

Alexander Trufanov

There is a bug with toolbar button's text. If you open toolbar's context menu you'll be able to hide button caption for each button separately. You can disable all of them which is very convinient if you enabled a lot of plugins that add new buttons to toolbar.

But when KTorrent is relaunched it forgets this setting for very first subpanel (by default it contains 2 buttons: torrents & plugins). All other buttons keep their text hidden.

This fix allows KT to save and load these buttons state properly.

Implementation notes:
The list of actions usually save\restore its state (Priority property) automatically if created from *ui.rc file. But these actions are added dynamically into it. And it looks like their state isn't automatically saved even if I fill in objectName property for them (objectName is used as key for configuration file). So I've added required code.

I'm using icon-id+"wght"+weight as objectNamefor dynamically created actions (default objectName is empty) because their name property is i18n()'ed just before Action object constructed. Ideally I would change Action constructor and require additional non-internationalized string parameter as objectName, but this breaks plugin's binary compatibility which is unwanted. I could also move i18n() inside Action's constructor and copy name before localization. Or I could add setObjectName() after Action and its derived objects creation in each plugin's code. But this would not be obvious for other plugins developers and require some warnings in documentation.
So <icon-id, weight> pair is used. Currently all plugins have different icons and weights (weights are hardcoded), but in theory they could match. So pair is used for more robustness.

Alexander Trufanov
Alexander Trufanov
Alexander Trufanov
Alexander Trufanov
Review request changed

Change Summary:

adding new reviewer


Andrius Štikonas

Looks good to me. Although, I would use C++11 ranged based for for this...