Commit fd858caf authored by Olivier Trichet's avatar Olivier Trichet Committed by Nate Graham
Browse files

Fix shortcut not working under non English locale

This change wraps calls to QAction::shortcut() done in QML files
to use the portable representation of QKeySequence.

The QKeySequence to QVariant operator return a string
representation using the native format not the portable format.
E.g., the sequence "Space", will be "Espace" under French locale.
The 'shortcut' attribute of QtQuick Action is stored as QVariant.
In qml file, when the QAction::shortcut() value (a QKeySequence)
is affected to a QtQuick Action shortcut, the previous operator is
used and the shortcut value may be bogus depending on translation.

    // A QAction* with the Qt::Key_Space shortcut
    property var playPauseAction: ElisaApplication.action("Play-Pause")
    Action {
        // - playPauseAction.shortcut returns QKeySequence(Qt::Key_Space).
        // - QKeySequence(Qt::Key_Space) is transform into a QVariant that
        //        contains native text "Espace".
        // - this QVariant is affected to shortcut: broken.
        shortcut: playPauseAction.shortcut
        onTriggered: ElisaApplication.audioControl.playPause()
    }

BUG: 424890
BUG: 410110
parent d4ba3781
......@@ -524,6 +524,12 @@ QAction * ElisaApplication::action(const QString& name)
#endif
}
const QString ElisaApplication::actionShortcut(QAction *action) const
{
return action->shortcut().toString(QKeySequence::PortableText);
}
QString ElisaApplication::iconName(const QIcon& icon)
{
return icon.name();
......
......@@ -103,6 +103,7 @@ public:
~ElisaApplication() override;
Q_INVOKABLE QAction* action(const QString& name);
Q_INVOKABLE const QString actionShortcut(QAction *action) const;
Q_INVOKABLE QString iconName(const QIcon& icon);
......
......@@ -53,7 +53,7 @@ Menu {
Action {
text: configureAction.text
shortcut: configureAction.shortcut
shortcut: ElisaApplication.actionShortcut(configureAction)
icon.name: ElisaApplication.iconName(configureAction.icon)
onTriggered: {
applicationMenu.close()
......@@ -63,7 +63,7 @@ Menu {
Action {
text: configureShortcutsAction.text
shortcut: configureShortcutsAction.shortcut
shortcut: ElisaApplication.actionShortcut(configureShortcutsAction)
icon.name: ElisaApplication.iconName(configureShortcutsAction.icon)
onTriggered: {
applicationMenu.close()
......@@ -77,7 +77,7 @@ Menu {
Action {
text: reportBugAction.text
shortcut: reportBugAction.shortcut
shortcut: ElisaApplication.actionShortcut(reportBugAction)
icon.name: ElisaApplication.iconName(reportBugAction.icon)
onTriggered: {
applicationMenu.close()
......@@ -91,7 +91,7 @@ Menu {
Action {
text: helpAction.text
shortcut: helpAction.shortcut
shortcut: ElisaApplication.actionShortcut(helpAction)
icon.name: ElisaApplication.iconName(helpAction.icon)
onTriggered: {
applicationMenu.close()
......@@ -101,7 +101,7 @@ Menu {
Action {
text: aboutAppAction.text
shortcut: aboutAppAction.shortcut
shortcut: ElisaApplication.actionShortcut(aboutAppAction)
icon.name: ElisaApplication.iconName(aboutAppAction.icon)
onTriggered: {
applicationMenu.close()
......@@ -115,7 +115,7 @@ Menu {
Action {
text: quitApplication.text
shortcut: quitApplication.shortcut
shortcut: ElisaApplication.actionShortcut(quitApplication)
icon.name: ElisaApplication.iconName(quitApplication.icon)
onTriggered: quitApplication.trigger()
}
......
......@@ -89,42 +89,42 @@ Kirigami.ApplicationWindow {
property var mediaPlayerControl: Kirigami.Settings.isMobile ? mobileFooterBarLoader.item : headerBarLoader.item
Action {
shortcut: goBackAction.shortcut
shortcut: ElisaApplication.actionShortcut(goBackAction)
onTriggered: contentView.goBack()
}
Action {
shortcut: seekAction.shortcut
shortcut: ElisaApplication.actionShortcut(seekAction)
onTriggered: ElisaApplication.audioControl.seek(mediaPlayerControl.playerControl.position + 10000)
}
Action {
shortcut: scrubAction.shortcut
shortcut: ElisaApplication.actionShortcut(scrubAction)
onTriggered: ElisaApplication.audioControl.seek(mediaPlayerControl.playerControl.position - 10000)
}
Action {
shortcut: nextTrackAction.shortcut
shortcut: ElisaApplication.actionShortcut(nextTrackAction)
onTriggered: ElisaApplication.mediaPlayListProxyModel.skipNextTrack(ElisaApplication.audioPlayer.position)
}
Action {
shortcut: previousTrackAction.shortcut
shortcut: ElisaApplication.actionShortcut(previousTrackAction)
onTriggered: ElisaApplication.mediaPlayListProxyModel.skipPreviousTrack(ElisaApplication.audioPlayer.position)
}
Action {
shortcut: playPauseAction.shortcut
shortcut: ElisaApplication.actionShortcut(playPauseAction)
onTriggered: ElisaApplication.audioControl.playPause()
}
Action {
shortcut: findAction.shortcut
shortcut: ElisaApplication.actionShortcut(findAction)
onTriggered: persistentSettings.expandedFilterView = !persistentSettings.expandedFilterView
}
Action {
shortcut: togglePartyModeAction.shortcut
shortcut: ElisaApplication.actionShortcut(togglePartyModeAction)
onTriggered: mediaPlayerControl.isMaximized = !mediaPlayerControl.isMaximized
}
......
......@@ -169,7 +169,7 @@ BasePlayerControl {
FlatButtonWithToolTip {
id: showHidePlaylistAction
action: Action {
shortcut: ElisaApplication.action("toggle_playlist").shortcut
shortcut: ElisaApplication.actionShortcut(ElisaApplication.action("toggle_playlist"))
onTriggered: contentView.showPlaylist = !contentView.showPlaylist
}
......
......@@ -13,7 +13,7 @@ MenuItem {
property var __action: ElisaApplication.action(elisaAction)
text: __action.text
shortcut: __action.shortcut
shortcut: ElisaApplication.actionShortcut(__action)
iconName: ElisaApplication.iconName(__action.icon)
onTriggered: __action.trigger()
visible: __action.text !== ""
......
......@@ -32,7 +32,7 @@ Menu {
MenuItem {
text: configureAction.text
shortcut: configureAction.shortcut
shortcut: ElisaApplication.actionShortcut(configureAction)
iconName: ElisaApplication.iconName(configureAction.icon)
onTriggered: configureAction.trigger()
visible: configureAction.text !== ""
......@@ -40,14 +40,14 @@ Menu {
MenuItem {
text: configureShortcutsAction.text
shortcut: configureShortcutsAction.shortcut
shortcut: ElisaApplication.actionShortcut(configureShortcutsAction)
iconName: ElisaApplication.iconName(configureShortcutsAction.icon)
onTriggered: configureShortcutsAction.trigger()
visible: configureShortcutsAction.text !== ""
}
MenuItem {
shortcut: togglePlaylistAction.shortcut
shortcut: ElisaApplication.actionShortcut(togglePlaylistAction)
text: i18n("Show Playlist")
iconName: "view-media-playlist"
checkable: true
......@@ -62,7 +62,7 @@ Menu {
MenuItem {
text: reportBugAction.text
shortcut: reportBugAction.shortcut
shortcut: ElisaApplication.actionShortcut(reportBugAction)
iconName: ElisaApplication.iconName(reportBugAction.icon)
onTriggered: reportBugAction.trigger()
visible: reportBugAction.text !== ""
......@@ -74,7 +74,7 @@ Menu {
MenuItem {
text: helpAction.text
shortcut: helpAction.shortcut
shortcut: ElisaApplication.actionShortcut(helpAction)
iconName: ElisaApplication.iconName(helpAction.icon)
onTriggered: helpAction.trigger()
visible: helpAction.text !== ""
......@@ -82,7 +82,7 @@ Menu {
MenuItem {
text: aboutAppAction.text
shortcut: aboutAppAction.shortcut
shortcut: ElisaApplication.actionShortcut(aboutAppAction)
iconName: ElisaApplication.iconName(aboutAppAction.icon)
onTriggered: aboutAppAction.trigger()
visible: aboutAppAction.text !== ""
......@@ -94,7 +94,7 @@ Menu {
MenuItem {
text: quitApplication.text
shortcut: quitApplication.shortcut
shortcut: ElisaApplication.actionShortcut(quitApplication)
iconName: ElisaApplication.iconName(quitApplication.icon)
onTriggered: quitApplication.trigger()
visible: quitApplication.text !== ""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment