aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-09-05 16:15:39 -0300
committerRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-09-05 16:15:39 -0300
commit0dfd3d4cd4214a732e4a5cda59fd4dfc082b8425 (patch)
treea4d1d4e876e31a1265581ee89c673eb66aaaae8d /examples
downloadqmenumodel-0dfd3d4cd4214a732e4a5cda59fd4dfc082b8425.tar.gz
qmenumodel-0dfd3d4cd4214a732e4a5cda59fd4dfc082b8425.tar.bz2
qmenumodel-0dfd3d4cd4214a732e4a5cda59fd4dfc082b8425.zip
Initial import.
Diffstat (limited to 'examples')
-rw-r--r--examples/CMakeLists.txt4
-rw-r--r--examples/Menu.qml18
-rw-r--r--examples/MenuFactory.qml33
-rw-r--r--examples/MenuSection.qml29
-rw-r--r--examples/SubMenu.qml14
-rw-r--r--examples/main.qml44
-rwxr-xr-xexamples/run-example.sh.in1
-rw-r--r--examples/simple-client.py26
-rw-r--r--examples/simple.py42
9 files changed, 211 insertions, 0 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
new file mode 100644
index 0000000..fda5683
--- /dev/null
+++ b/examples/CMakeLists.txt
@@ -0,0 +1,4 @@
+project(examples)
+
+configure_file("${CMAKE_CURRENT_SOURCE_DIR}/run-example.sh.in"
+ "${CMAKE_CURRENT_BINARY_DIR}/run-example.sh" @ONLY)
diff --git a/examples/Menu.qml b/examples/Menu.qml
new file mode 100644
index 0000000..3060edb
--- /dev/null
+++ b/examples/Menu.qml
@@ -0,0 +1,18 @@
+import QtQuick 1.1
+import Ubuntu.Components 0.1
+import Ubuntu.Components.ListItems 0.1 as ListItem
+
+
+ListItem.Standard {
+ property variant menu
+
+ width: parent.width
+ text: menu.label
+
+ onClicked: {
+ if (menu.linkSubMenu)
+ loadMainMenu(menu.linkSubMenu)
+ else
+ loadMainMenu(menu.linkSection)
+ }
+}
diff --git a/examples/MenuFactory.qml b/examples/MenuFactory.qml
new file mode 100644
index 0000000..2729268
--- /dev/null
+++ b/examples/MenuFactory.qml
@@ -0,0 +1,33 @@
+import QtQuick 1.1
+import Ubuntu.Components 0.1
+import Ubuntu.Components.ListItems 0.1 as ListItem
+
+Loader {
+ property variant menu
+ height: childrenRect.height
+
+ onMenuChanged: {
+ if (menu) {
+ if (menu.linkSection)
+ source = "MenuSection.qml"
+ else if (menu.linkSubMenu)
+ source = "SubMenu.qml"
+ else
+ source = "Menu.qml";
+ }
+
+ console.debug("Load: " + source)
+ }
+
+ onStatusChanged: {
+ if (status == Loader.Ready) {
+ if (menu.linkSection)
+ item.menu = menu
+ else if (menu.linkSubMenu)
+ item.menu = menu
+ else if (menu)
+ item.menu = menu
+ }
+ }
+}
+
diff --git a/examples/MenuSection.qml b/examples/MenuSection.qml
new file mode 100644
index 0000000..2a1b6c9
--- /dev/null
+++ b/examples/MenuSection.qml
@@ -0,0 +1,29 @@
+import QtQuick 1.1
+import Ubuntu.Components 0.1
+import Ubuntu.Components.ListItems 0.1 as ListItem
+
+
+Item {
+ property variant menu
+ width: parent.width
+ height: contents.height
+
+ Column {
+ id: contents
+ width: parent.width
+
+ ListItem.Header {
+ text: menu.label
+ }
+
+ Repeater {
+ model: menu ? menu.linkSection : undefined
+
+ MenuFactory {
+ menu: model
+ }
+ }
+
+ ListItem.Divider { }
+ }
+}
diff --git a/examples/SubMenu.qml b/examples/SubMenu.qml
new file mode 100644
index 0000000..7049c3b
--- /dev/null
+++ b/examples/SubMenu.qml
@@ -0,0 +1,14 @@
+import QtQuick 1.1
+import Ubuntu.Components 0.1
+import Ubuntu.Components.ListItems 0.1 as ListItem
+
+
+ListItem.Standard {
+ property variant menu
+
+ anchors.fill: parent
+ text: menu.label
+ progression: true
+
+ onClicked: { loadMainMenu (menu.linkSubMenu) }
+}
diff --git a/examples/main.qml b/examples/main.qml
new file mode 100644
index 0000000..857351c
--- /dev/null
+++ b/examples/main.qml
@@ -0,0 +1,44 @@
+import QtQuick 1.1
+import QMenuModel 1.0
+import Ubuntu.Components 0.1
+import Ubuntu.Components.ListItems 0.1 as ListItem
+
+Rectangle {
+ id: main
+
+ height: 800
+ width: 480
+ color: "#eeeeee"
+
+ function loadMainMenu(menu) {
+ mainMenu.model = menu
+ }
+
+ QDBusMenuModel {
+ id: menuModel
+ busType: 1
+ busName: "com.ubuntu.networksettings"
+ objectPath: "/com/ubuntu/networksettings"
+ onConnected: {
+ console.log("Menu appears ")
+ }
+ }
+
+
+ ListView {
+ id: mainMenu
+ anchors.fill: parent
+ model: menuModel
+
+ delegate: MenuFactory {
+ width: parent.width
+ menu: model
+ }
+
+ Component.onCompleted: {
+ menuModel.connect()
+ }
+ }
+}
+
+
diff --git a/examples/run-example.sh.in b/examples/run-example.sh.in
new file mode 100755
index 0000000..4843f49
--- /dev/null
+++ b/examples/run-example.sh.in
@@ -0,0 +1 @@
+gdb --args qmlviewer -I @src_BINARY_DIR@ $1
diff --git a/examples/simple-client.py b/examples/simple-client.py
new file mode 100644
index 0000000..ff7b416
--- /dev/null
+++ b/examples/simple-client.py
@@ -0,0 +1,26 @@
+# creates this menu:
+#
+# Menu Item
+# ----------------
+# One
+# Two
+# Three
+# ----------------
+# Submenu > | One
+# | Two
+# | Three
+
+from gi.repository import GLib, Gio
+
+def on_items_changed (model, position, removed, added, data):
+ print 'items changed:', position, removed, added
+
+bus = Gio.bus_get_sync (Gio.BusType.SESSION, None)
+print dir(bus)
+menu = bus.get_menu_model(':1.473', '/menu')
+#menu = Gio.dbus_menu_model_get(Gio.BusType.SESSION, ':1.473', '/menu')
+menu.connect ('items-changed', on_items_changed)
+
+loop = GLib.MainLoop ()
+loop.run ()
+
diff --git a/examples/simple.py b/examples/simple.py
new file mode 100644
index 0000000..bc2d37c
--- /dev/null
+++ b/examples/simple.py
@@ -0,0 +1,42 @@
+# creates this menu:
+#
+# Menu Item
+# ----------------
+# One
+# Two
+# Three
+# ----------------
+# Submenu > | One
+# | Two
+# | Three
+
+from gi.repository import GLib, Gio
+
+def action_activated (action, parameter):
+ print action.get_name ()
+
+actions = Gio.SimpleActionGroup ()
+for i in ['one', 'two', 'three']:
+ action = Gio.SimpleAction.new (i, None)
+ action.connect ('activate', action_activated)
+ actions.insert (action)
+
+numbers = Gio.Menu ()
+numbers.append ('One', 'one')
+numbers.append ('Two', 'two')
+numbers.append ('Three', 'three')
+
+menu = Gio.Menu ()
+menu.append ('Menu item', 'one')
+menu.append_section ('Numbers', numbers)
+menu.append_submenu ('Submenu', numbers)
+
+# export the menu and action group on d-bus
+bus = Gio.bus_get_sync (Gio.BusType.SESSION, None)
+bus.export_menu_model ('/menu', menu)
+bus.export_action_group ('/menu', actions)
+print bus.get_unique_name ()
+
+loop = GLib.MainLoop ()
+loop.run ()
+