From b1009a800f4e64b17e19e578deedaf0c9bd18902 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 4 Jun 2013 15:42:16 -0400 Subject: Add qml example for UnityMenuModel --- examples/exportmenu.py | 6 +++++- examples/unityqmlmenumodel.qml | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 examples/unityqmlmenumodel.qml (limited to 'examples') diff --git a/examples/exportmenu.py b/examples/exportmenu.py index 4be3deb..767d8b9 100755 --- a/examples/exportmenu.py +++ b/examples/exportmenu.py @@ -54,7 +54,7 @@ if __name__ == '__main__': GLib.Variant.new_string('lorem ipsum')) foo.set_attribute_value('x-enabled', GLib.Variant.new_boolean(True)) menu.append_item(foo) - bar = Gio.MenuItem.new('bar', 'app.bar') + bar = Gio.MenuItem.new('bar', 'bar') bar.set_attribute_value('x-defaultvalue', GLib.Variant.new_string('Hello World!')) bar.set_attribute_value('x-canonical-currentvalue', @@ -74,5 +74,9 @@ if __name__ == '__main__': menu.append('baz', 'app.baz') bus.export_menu_model(BUS_OBJECT_PATH, menu) + actions = Gio.SimpleActionGroup.new() + actions.add_action(Gio.SimpleAction.new("bar", None)) + bus.export_action_group(BUS_OBJECT_PATH, actions) + GLib.MainLoop().run() diff --git a/examples/unityqmlmenumodel.qml b/examples/unityqmlmenumodel.qml new file mode 100644 index 0000000..257866d --- /dev/null +++ b/examples/unityqmlmenumodel.qml @@ -0,0 +1,34 @@ + +import QtQuick 2.0 +import QMenuModel 0.1 + +Item { + width: 400; + height: 500; + + UnityMenuModel { + id: menu + busName: "com.canonical.testmenu" + actionObjectPath: "/com/canonical/testmenu" + menuObjectPath: "/com/canonical/testmenu" + } + + ListView { + anchors.fill: parent + anchors.margins: 10 + spacing: 3 + model: menu + delegate: Rectangle { + width: parent.width + height: 40 + color: "#ddd" + Text { + anchors.fill: parent + anchors.margins: 5 + verticalAlignment: Text.AlignVCenter + color: sensitive ? "black" : "#aaa"; + text: label + } + } + } +} -- cgit v1.2.3 From 2a01b1cba8af5891bac632683286951e2c3f95f0 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 4 Jun 2013 20:23:22 -0400 Subject: examples/exportmenu.py: use g_bus_own_name to avoid race This avoids the common d-bus race where a name is owned but objects aren't exported on it yet. --- examples/exportmenu.py | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'examples') diff --git a/examples/exportmenu.py b/examples/exportmenu.py index 767d8b9..b7c37b1 100755 --- a/examples/exportmenu.py +++ b/examples/exportmenu.py @@ -32,22 +32,7 @@ from gi.repository import GLib BUS_NAME = 'com.canonical.testmenu' BUS_OBJECT_PATH = '/com/canonical/testmenu' - -if __name__ == '__main__': - bus = Gio.bus_get_sync(Gio.BusType.SESSION, None) - # Claim well-known bus name and ensure only one instance of self is running - # at any given time. - # http://dbus.freedesktop.org/doc/dbus-specification.html#message-bus-names - proxy = Gio.DBusProxy.new_sync(bus, 0, None, - 'org.freedesktop.DBus', - '/org/freedesktop/DBus', - 'org.freedesktop.DBus', None) - result = proxy.RequestName('(su)', BUS_NAME, 0x4) - if result != 1 : - print >> sys.stderr, ("Name '%s' is already owned on the session bus." - "Aborting.") % BUS_NAME - sys.exit(1) - +def bus_acquired(bus, name): menu = Gio.Menu() foo = Gio.MenuItem.new('foo', 'app.foo') foo.set_attribute_value('x-additionaltext', @@ -78,5 +63,6 @@ if __name__ == '__main__': actions.add_action(Gio.SimpleAction.new("bar", None)) bus.export_action_group(BUS_OBJECT_PATH, actions) +if __name__ == '__main__': + Gio.bus_own_name(Gio.BusType.SESSION, BUS_NAME, 0, bus_acquired, None, None) GLib.MainLoop().run() - -- cgit v1.2.3 From 00885c1ddd04819c44d6a0ca2c7f2af8a1298a97 Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Tue, 4 Jun 2013 21:05:40 -0400 Subject: unitymenumodel: expose isSeparator --- examples/unityqmlmenumodel.qml | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'examples') diff --git a/examples/unityqmlmenumodel.qml b/examples/unityqmlmenumodel.qml index 257866d..d38d6e5 100644 --- a/examples/unityqmlmenumodel.qml +++ b/examples/unityqmlmenumodel.qml @@ -18,16 +18,33 @@ Item { anchors.margins: 10 spacing: 3 model: menu - delegate: Rectangle { - width: parent.width - height: 40 - color: "#ddd" - Text { - anchors.fill: parent - anchors.margins: 5 - verticalAlignment: Text.AlignVCenter - color: sensitive ? "black" : "#aaa"; - text: label + + delegate: Loader { + sourceComponent: isSeparator ? separator : menuitem; + + Component { + id: separator + Rectangle { + width: parent.width + height: 4 + color: "blue" + } + } + + Component { + id: menuitem + Rectangle { + width: parent.width + height: 40 + color: "#ddd" + Text { + anchors.fill: parent + anchors.margins: 5 + verticalAlignment: Text.AlignVCenter + color: sensitive ? "black" : "#aaa"; + text: label + } + } } } } -- cgit v1.2.3 From e735d95e613e2ee6170799002183e0770d34590e Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Wed, 5 Jun 2013 13:50:12 -0400 Subject: unitymenumodel: add activate() --- examples/unityqmlmenumodel.qml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'examples') diff --git a/examples/unityqmlmenumodel.qml b/examples/unityqmlmenumodel.qml index d38d6e5..a66ba8e 100644 --- a/examples/unityqmlmenumodel.qml +++ b/examples/unityqmlmenumodel.qml @@ -14,6 +14,7 @@ Item { } ListView { + id: listview anchors.fill: parent anchors.margins: 10 spacing: 3 @@ -25,7 +26,7 @@ Item { Component { id: separator Rectangle { - width: parent.width + width: listview.width height: 4 color: "blue" } @@ -34,7 +35,7 @@ Item { Component { id: menuitem Rectangle { - width: parent.width + width: listview.width height: 40 color: "#ddd" Text { @@ -44,6 +45,10 @@ Item { color: sensitive ? "black" : "#aaa"; text: label } + MouseArea { + anchors.fill: parent + onClicked: listview.model.activate(index); + } } } } -- cgit v1.2.3 From 192e9c85e6d7441a6115d1ead859b8449cfb07ec Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 25 Jul 2013 06:28:54 +0200 Subject: examples/unitymenumodel.qml: update to newest API --- examples/unityqmlmenumodel.qml | 55 +++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 9 deletions(-) (limited to 'examples') diff --git a/examples/unityqmlmenumodel.qml b/examples/unityqmlmenumodel.qml index a66ba8e..5dcb1ff 100644 --- a/examples/unityqmlmenumodel.qml +++ b/examples/unityqmlmenumodel.qml @@ -8,9 +8,9 @@ Item { UnityMenuModel { id: menu - busName: "com.canonical.testmenu" - actionObjectPath: "/com/canonical/testmenu" - menuObjectPath: "/com/canonical/testmenu" + busName: "com.canonical.indicator.sound" + actions: { "indicator": "/com/canonical/indicator/sound" } + menuObjectPath: "/com/canonical/indicator/sound/desktop" } ListView { @@ -21,7 +21,19 @@ Item { model: menu delegate: Loader { - sourceComponent: isSeparator ? separator : menuitem; + sourceComponent: { + if (isSeparator) { + return separator; + } + else if (type == "com.canonical.unity.slider") { + listview.model.loadExtendedAttributes(index, {'min-icon': 'icon', + 'max-icon': 'icon'}); + return slider; + } + else { + return menuitem; + } + } Component { id: separator @@ -32,22 +44,47 @@ Item { } } + Component { + id: slider + Row { + anchors.fill: parent + Image { + source: ext.minIcon + } + Image { + source: ext.maxIcon + } + } + } + Component { id: menuitem Rectangle { width: listview.width height: 40 color: "#ddd" - Text { + Row { anchors.fill: parent anchors.margins: 5 - verticalAlignment: Text.AlignVCenter - color: sensitive ? "black" : "#aaa"; - text: label + Image { + source: icon + } + Text { + height: parent.height + verticalAlignment: Text.AlignVCenter + color: sensitive ? "black" : "#aaa"; + text: label + } } MouseArea { anchors.fill: parent - onClicked: listview.model.activate(index); + onClicked: { + var submenu = listview.model.submenu(index); + if (submenu) + listview.model = submenu; + else + listview.model.activate(index); + } } } } -- cgit v1.2.3 From 57f5b0730a9f001201458d2759797bba17cabaef Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Thu, 25 Jul 2013 10:18:31 +0200 Subject: examples/unityqmlmenumodel.qml: add license header --- examples/unityqmlmenumodel.qml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'examples') diff --git a/examples/unityqmlmenumodel.qml b/examples/unityqmlmenumodel.qml index 5dcb1ff..8028674 100644 --- a/examples/unityqmlmenumodel.qml +++ b/examples/unityqmlmenumodel.qml @@ -1,3 +1,20 @@ +/* + * Copyright 2013 Canonical Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Authors: Lars Uebernickel + */ import QtQuick 2.0 import QMenuModel 0.1 -- cgit v1.2.3 From d57caa61f787c4bd7cb0823eadbbc5d84f542f0a Mon Sep 17 00:00:00 2001 From: Lars Uebernickel Date: Fri, 26 Jul 2013 15:04:50 +0200 Subject: Expose the state of a menu item's action in model.actionState --- examples/unityqmlmenumodel.qml | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'examples') diff --git a/examples/unityqmlmenumodel.qml b/examples/unityqmlmenumodel.qml index 8028674..e1de3c8 100644 --- a/examples/unityqmlmenumodel.qml +++ b/examples/unityqmlmenumodel.qml @@ -63,13 +63,21 @@ Item { Component { id: slider - Row { - anchors.fill: parent - Image { - source: ext.minIcon - } - Image { - source: ext.maxIcon + Rectangle { + width: listview.width + color: "#ddd" + height: 40 + Row { + anchors.fill: parent + Image { + source: ext.minIcon + } + Text { + text: model.actionState + } + Image { + source: ext.maxIcon + } } } } -- cgit v1.2.3 From 2bbdf4e2347ec566280b9d878a12b7b1e732f632 Mon Sep 17 00:00:00 2001 From: Nick Dedekind Date: Fri, 9 Aug 2013 10:50:12 +0100 Subject: glib callbacks pass events through qt. --- examples/unityqmlmenumodel.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples') diff --git a/examples/unityqmlmenumodel.qml b/examples/unityqmlmenumodel.qml index e1de3c8..c0e5adc 100644 --- a/examples/unityqmlmenumodel.qml +++ b/examples/unityqmlmenumodel.qml @@ -108,7 +108,7 @@ Item { if (submenu) listview.model = submenu; else - listview.model.activate(index); + action.activate(); } } } -- cgit v1.2.3