aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-09-12 14:47:26 -0300
committerRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-09-12 14:47:26 -0300
commita3aa532c698c5eab037b17870275d8e27e77a498 (patch)
tree01e918b9adc2557a0e67f05221e2c36f4e65ee29 /tests
parent638bcc947afe2b941d934fc3f87513f0c8565f7f (diff)
downloadqmenumodel-a3aa532c698c5eab037b17870275d8e27e77a498.tar.gz
qmenumodel-a3aa532c698c5eab037b17870275d8e27e77a498.tar.bz2
qmenumodel-a3aa532c698c5eab037b17870275d8e27e77a498.zip
Added QML documentation.
Diffstat (limited to 'tests')
-rw-r--r--tests/client/CMakeLists.txt1
-rw-r--r--tests/script/dbusmenuscript.cpp13
-rw-r--r--tests/script/dbusmenuscript.h2
-rw-r--r--tests/script/menuscript.py53
4 files changed, 62 insertions, 7 deletions
diff --git a/tests/client/CMakeLists.txt b/tests/client/CMakeLists.txt
index bf77461..473ebcd 100644
--- a/tests/client/CMakeLists.txt
+++ b/tests/client/CMakeLists.txt
@@ -44,3 +44,4 @@ endif()
declare_test(servicetest)
declare_test(menuchangestest)
declare_test(modeltest)
+declare_test(actiongrouptest)
diff --git a/tests/script/dbusmenuscript.cpp b/tests/script/dbusmenuscript.cpp
index baf5ac2..b190d5b 100644
--- a/tests/script/dbusmenuscript.cpp
+++ b/tests/script/dbusmenuscript.cpp
@@ -91,3 +91,16 @@ void DBusMenuScript::run()
QTest::qWait(WAIT_TIMEOUT);
}
}
+
+QString DBusMenuScript::popActivatedAction()
+{
+ if (m_script) {
+ QDBusMessage reply = m_script->call("popActivatedAction");
+ if (reply.arguments().count() > 0) {
+ return reply.arguments()[0].toString();
+ }
+ }
+
+ return QString();
+}
+
diff --git a/tests/script/dbusmenuscript.h b/tests/script/dbusmenuscript.h
index 6e9532b..8a93e83 100644
--- a/tests/script/dbusmenuscript.h
+++ b/tests/script/dbusmenuscript.h
@@ -47,6 +47,8 @@ public:
void publishMenu();
void unpublishMenu();
+ QString popActivatedAction();
+
private:
QDBusInterface *m_script;
};
diff --git a/tests/script/menuscript.py b/tests/script/menuscript.py
index 05e226c..f50aacd 100644
--- a/tests/script/menuscript.py
+++ b/tests/script/menuscript.py
@@ -53,6 +53,11 @@ class Script(dbus.service.Object):
self._list.walk()
steps -= 1
+ @dbus.service.method(dbus_interface=INTERFACE_NAME,
+ in_signature='', out_signature='s')
+ def popActivatedAction(self):
+ return self._list._activatedActions.pop(0)
+
@staticmethod
def create(aList):
global bus
@@ -87,6 +92,12 @@ class Action(object):
item = Gio.MenuItem.new(self._kargs['label'], self._kargs['actionName'])
self.setProperties(item, self._kargs['properties'])
parent.append_item(item)
+
+ # Action
+ act = Gio.SimpleAction.new(self._kargs['actionName'], None)
+ act.connect('activate', self._list._onActionActivated)
+ self._list._rootAction.insert(act)
+
elif self._kargs['link'] == 'section':
section = Gio.Menu()
parent.append_section(self._kargs['label'], section)
@@ -99,6 +110,9 @@ class Action(object):
(menu, mId) = self._list.getMenu(menuId)
if mId != -1:
menu.remove(mId)
+ if self._kargs['actionName']:
+ # Remove action
+ self._list._rootAction.remove(self._kargs['actionName'])
else:
print "Remove menu item"
@@ -111,11 +125,15 @@ class Action(object):
class ActionList(object):
def __init__(self, objectPath):
self._actions = []
+ self._actions_bk = []
self._objectPath = objectPath
self._bux = None
- self._exportID = None
+ self._exportMenuID = None
+ self._exportActionID = None
self._ownNameID = None
self._root = None
+ self._rootAction = None
+ self._activatedActions = []
def appendItem(self, label, actionName, link=None, parentId=None, properties=None):
self._actions.append(Action(self, 'append',
@@ -125,9 +143,20 @@ class ActionList(object):
link=link,
properties=properties))
- def removeItem(self, menuId):
+ def removeItem(self, menuId, actionName=None):
self._actions.append(Action(self, 'remove',
- menuId=menuId))
+ menuId=menuId,
+ actionName=actionName))
+
+ def _save(self):
+ self._actions_bk = []
+ self._actions_bk.extend(self._actions)
+
+
+ def _restore(self):
+ if len(self._actions_bk):
+ self._actions = []
+ self._actions.extend(self._actions_bk)
def _findMenu(self, root, ids):
if len(ids) == 0:
@@ -155,18 +184,28 @@ class ActionList(object):
def _exportService(self, connection, name):
self._root = Gio.Menu()
+ self._rootAction = Gio.SimpleActionGroup()
self._bus = connection
- self._exportID = connection.export_menu_model(MENU_OBJECT_PATH, self._root)
+ self._exportMenuID = connection.export_menu_model(MENU_OBJECT_PATH, self._root)
+ self._exportActionID = connection.export_action_group(MENU_OBJECT_PATH, self._rootAction)
def start(self):
+ self._save()
self._ownNameID = Gio.bus_own_name(2, MENU_SERVICE_NAME, 0, self._exportService, None, None)
def stop(self):
- if self._exportID:
- self._bus.unexport_menu_model(self._exportID)
- self._exportID = None
+ if self._exportMenuID:
+ self._bus.unexport_menu_model(self._exportMenuID)
+ self._exportMenuID = None
+
+ if self._exportActionID:
+ self._bus.unexport_action_group(self._exportActionID)
+ self._exportActionID = None
if self._ownNameID:
Gio.bus_unown_name(self._ownNameID)
self._ownNameID = None
+ self._restore()
+ def _onActionActivated(self, action, parameter):
+ self._activatedActions.append(action.get_name())