@@ -18,12 +18,14 @@ import QtQuick 2.4
1818import QtQuick.Window 2.2
1919import Ubuntu.Settings.Menus 0.1 as Menus
2020import Ubuntu.Settings.Components 0.1
21+import AccountsService 0.1
2122import QMenuModel 0.1
2223import Utils 0.1 as Utils
2324import Ubuntu.Components.ListItems 1.3 as ListItems
2425import Ubuntu.Components 1.3
2526import Unity.Session 0.1
2627import Unity.Platform 1.0
28+import Unity.Application 0.1
2729
2830Item {
2931 id: menuFactory
@@ -985,6 +987,55 @@ Item {
985987 }
986988 }
987989
990+ Component {
991+ id: keymapMenu;
992+
993+ Menus.CheckableMenu {
994+ id: checkItem
995+ objectName: "keymapMenu"
996+ property QtObject menuData: null
997+ property int menuIndex: -1
998+ property bool serverChecked: menuData && menuData.isToggled || false
999+
1000+ text: menuData && menuData.label || ""
1001+ enabled: menuData && menuData.sensitive || false
1002+ checked: serverChecked
1003+ highlightWhenPressed: false
1004+
1005+ ServerPropertySynchroniser {
1006+ objectName: "sync"
1007+ syncTimeout: Utils.Constants.indicatorValueTimeout
1008+
1009+ serverTarget: checkItem
1010+ serverProperty: "serverChecked"
1011+ userTarget: checkItem
1012+ userProperty: "checked"
1013+
1014+ onSyncTriggered: {
1015+ menuModel.activate(checkItem.menuIndex);
1016+
1017+ print("!!! Keymap", checkItem.menuIndex, "triggered")
1018+ print("!!! Active action state:", actionGroup.activeAction.state)
1019+ if (MirFocusController.focusedSurface) {
1020+ print("!!! Switching keymap to:", AccountsService.keymaps[checkItem.menuIndex])
1021+ MirFocusController.focusedSurface.keymap = AccountsService.keymaps[checkItem.menuIndex];
1022+ }
1023+ }
1024+ }
1025+
1026+ QDBusActionGroup {
1027+ id: actionGroup
1028+ busType: DBus.SessionBus
1029+ busName: "com.canonical.indicator.keyboard"
1030+ objectPath: "/com/canonical/indicator/keyboard"
1031+
1032+ property variant activeAction: action("active")
1033+
1034+ Component.onCompleted: actionGroup.start()
1035+ }
1036+ }
1037+ }
1038+
9881039 function load(modelData, context) {
9891040 // tweak indicator-session items
9901041 if (context === "indicator-session") {
@@ -995,6 +1046,11 @@ Item {
9951046 }
9961047 }
9971048
1049+ // specialize for indicator-keyboard
1050+ if (context === "indicator-keyboard" && modelData.isRadio) {
1051+ return keymapMenu;
1052+ }
1053+
9981054 if (modelData.type !== undefined && modelData.type !== "") {
9991055 var component = undefined;
10001056