aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rwxr-xr-xexamples/exportmenu.py26
-rw-r--r--examples/unityqmlmenumodel.qml118
2 files changed, 126 insertions, 18 deletions
diff --git a/examples/exportmenu.py b/examples/exportmenu.py
index 4be3deb..b7c37b1 100755
--- a/examples/exportmenu.py
+++ b/examples/exportmenu.py
@@ -32,29 +32,14 @@ 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',
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 +59,10 @@ if __name__ == '__main__':
menu.append('baz', 'app.baz')
bus.export_menu_model(BUS_OBJECT_PATH, menu)
- GLib.MainLoop().run()
+ actions = Gio.SimpleActionGroup.new()
+ 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()
diff --git a/examples/unityqmlmenumodel.qml b/examples/unityqmlmenumodel.qml
new file mode 100644
index 0000000..c0e5adc
--- /dev/null
+++ b/examples/unityqmlmenumodel.qml
@@ -0,0 +1,118 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Lars Uebernickel <lars.uebernickel@canonical.com>
+ */
+
+import QtQuick 2.0
+import QMenuModel 0.1
+
+Item {
+ width: 400;
+ height: 500;
+
+ UnityMenuModel {
+ id: menu
+ busName: "com.canonical.indicator.sound"
+ actions: { "indicator": "/com/canonical/indicator/sound" }
+ menuObjectPath: "/com/canonical/indicator/sound/desktop"
+ }
+
+ ListView {
+ id: listview
+ anchors.fill: parent
+ anchors.margins: 10
+ spacing: 3
+ model: menu
+
+ delegate: Loader {
+ 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
+ Rectangle {
+ width: listview.width
+ height: 4
+ color: "blue"
+ }
+ }
+
+ Component {
+ id: slider
+ Rectangle {
+ width: listview.width
+ color: "#ddd"
+ height: 40
+ Row {
+ anchors.fill: parent
+ Image {
+ source: ext.minIcon
+ }
+ Text {
+ text: model.actionState
+ }
+ Image {
+ source: ext.maxIcon
+ }
+ }
+ }
+ }
+
+ Component {
+ id: menuitem
+ Rectangle {
+ width: listview.width
+ height: 40
+ color: "#ddd"
+ Row {
+ anchors.fill: parent
+ anchors.margins: 5
+ Image {
+ source: icon
+ }
+ Text {
+ height: parent.height
+ verticalAlignment: Text.AlignVCenter
+ color: sensitive ? "black" : "#aaa";
+ text: label
+ }
+ }
+ MouseArea {
+ anchors.fill: parent
+ onClicked: {
+ var submenu = listview.model.submenu(index);
+ if (submenu)
+ listview.model = submenu;
+ else
+ action.activate();
+ }
+ }
+ }
+ }
+ }
+ }
+}