diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/CMakeLists.txt | 4 | ||||
-rw-r--r-- | examples/Menu.qml | 18 | ||||
-rw-r--r-- | examples/MenuFactory.qml | 33 | ||||
-rw-r--r-- | examples/MenuSection.qml | 29 | ||||
-rw-r--r-- | examples/SubMenu.qml | 14 | ||||
-rw-r--r-- | examples/main.qml | 44 | ||||
-rwxr-xr-x | examples/run-example.sh.in | 1 | ||||
-rw-r--r-- | examples/simple-client.py | 26 | ||||
-rw-r--r-- | examples/simple.py | 42 |
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 () + |