./ 0000755 0000156 0000165 00000000000 12676475617 011122 5 ustar jenkins jenkins ./doc/ 0000755 0000156 0000165 00000000000 12676475617 011667 5 ustar jenkins jenkins ./doc/qmenumodel.qdocconf.in 0000644 0000156 0000165 00000000335 12676475617 016161 0 ustar jenkins jenkins project = QMenuModel QML elements
sourcedirs = @src_SOURCE_DIR@
sources.fileextensions = "*.cpp"
outputdir = html
outputformats = HTML
version = 0.1
syntaxhighlighting = true
sourceencoding = UTF-8
outputencoding = UTF-8
./doc/CMakeLists.txt 0000644 0000156 0000165 00000000640 12676475617 014427 0 ustar jenkins jenkins set(QMENUMODEL_DOC_FILE ${CMAKE_CURRENT_BINARY_DIR}/qmenumodel.qdocconf)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/qmenumodel.qdocconf.in"
${QMENUMODEL_DOC_FILE} @ONLY)
add_custom_target(qdoc)
add_custom_command(TARGET qdoc
COMMAND ${QDOC_BIN} ${QMENUMODEL_DOC_FILE}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "QDoc running...")
./cmake/ 0000755 0000156 0000165 00000000000 12676475617 012202 5 ustar jenkins jenkins ./cmake/lcov.cmake 0000644 0000156 0000165 00000005005 12676475617 014147 0 ustar jenkins jenkins # - This module creates a new 'lcov' target which generates
# a coverage analysis html output.
# LCOV is a graphical front-end for GCC's coverage testing tool gcov. Please see
# http://ltp.sourceforge.net/coverage/lcov.php
#
# Usage: you must add an option to your CMakeLists.txt to build your application
# with coverage support. Then you need to include this file to the lcov target.
#
# Example:
# IF(BUILD_WITH_COVERAGE)
# SET(CMAKE_C_FLAGS "-g -O0 -Wall -fprofile-arcs -ftest-coverage")
# SET(CMAKE_CXX_FLAGS "-g -O0 -Wall -fprofile-arcs -ftest-coverage")
# SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-coverage -lgcov")
# include(${CMAKE_SOURCE_DIR}/cmake/lcov.cmake)
# ENDIF(BUILD_WITH_COVERAGE)
#=============================================================================
# Copyright 2010 ascolab GmbH
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distributed this file outside of CMake, substitute the full
# License text for the above reference.)
set(REMOVE_PATTERN
q*.h
*.moc
moc_*.cpp
locale_facets.h
new)
## lcov target
ADD_CUSTOM_TARGET(lcov)
ADD_CUSTOM_COMMAND(TARGET lcov
COMMAND mkdir -p coverage
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
ADD_CUSTOM_COMMAND(TARGET lcov
COMMAND lcov --directory . --zerocounters
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
ADD_CUSTOM_COMMAND(TARGET lcov
COMMAND make test
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
ADD_CUSTOM_COMMAND(TARGET lcov
COMMAND lcov --directory . --capture --output-file ./coverage/stap_all.info --no-checksum --compat-libtool
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
ADD_CUSTOM_COMMAND(TARGET lcov
COMMAND lcov --directory . -r ./coverage/stap_all.info ${REMOVE_PATTERN} --output-file ./coverage/stap.info
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
ADD_CUSTOM_COMMAND(TARGET lcov
COMMAND genhtml -o ./coverage --title "Code Coverage" --legend --show-details --demangle-cpp ./coverage/stap.info
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
ADD_CUSTOM_COMMAND(TARGET lcov
COMMAND echo "Open ${CMAKE_BINARY_DIR}/coverage/index.html to view the coverage analysis results."
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
./tests/ 0000755 0000156 0000165 00000000000 12676475617 012264 5 ustar jenkins jenkins ./tests/script/ 0000755 0000156 0000165 00000000000 12676475617 013570 5 ustar jenkins jenkins ./tests/script/dbusmenuscript.cpp 0000644 0000156 0000165 00000005142 12676475617 017345 0 ustar jenkins jenkins /*
* Copyright 2012 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:
* Renato Araujo Oliveira Filho
*/
#include "dbusmenuscript.h"
#include
#include
#include
#define WAIT_TIMEOUT 500
DBusMenuScript::DBusMenuScript()
:m_script(0)
{
}
DBusMenuScript::~DBusMenuScript()
{
quit();
}
bool DBusMenuScript::connect()
{
QTest::qWait(WAIT_TIMEOUT);
m_script = new QDBusInterface(SCRIPT_SERVICE_NAME,
SCRIPT_OBJECT_PATH,
SCRIPT_INTERFACE_NAME,
QDBusConnection::sessionBus(), 0);
if (m_script && m_script->isValid()) {
return true;
} else {
qWarning() << "DBUS ERROR:" << m_script->lastError().message();
return false;
}
}
void DBusMenuScript::publishMenu()
{
if (m_script) {
m_script->call("publishMenu");
QTest::qWait(WAIT_TIMEOUT);
}
}
void DBusMenuScript::unpublishMenu()
{
if (m_script) {
m_script->call("unpublishMenu");
QTest::qWait(WAIT_TIMEOUT);
}
}
void DBusMenuScript::quit()
{
if (m_script) {
m_script->call("quit");
QTest::qWait(WAIT_TIMEOUT);
delete m_script;
m_script = 0;
}
}
void DBusMenuScript::walk(int steps)
{
if (m_script) {
m_script->call("walk", steps);
QTest::qWait(WAIT_TIMEOUT);
}
}
void DBusMenuScript::run()
{
if (m_script) {
m_script->call("walk", -1);
QTest::qWait(WAIT_TIMEOUT);
}
}
QPair DBusMenuScript::popActivatedAction()
{
if (m_script) {
QDBusMessage reply = m_script->call("popActivatedAction");
if (reply.arguments().count() > 0) {
QVariant value;
QString name = reply.arguments()[0].toString();
if (reply.arguments().count() > 1) {
value = reply.arguments()[1];
}
return qMakePair(name, value);
}
}
return qMakePair(QString(), QVariant());
}
./tests/script/CMakeLists.txt 0000644 0000156 0000165 00000000306 12676475617 016327 0 ustar jenkins jenkins project(dbusmenuscript)
add_library(dbusmenuscript STATIC dbusmenuscript.cpp)
set_target_properties(dbusmenuscript PROPERTIES COMPILE_FLAGS -fPIC)
qt5_use_modules(dbusmenuscript Core DBus Test)
./tests/script/menuscript.py 0000644 0000156 0000165 00000017356 12676475617 016347 0 ustar jenkins jenkins # 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 .
#
import dbus
import dbus.service
from dbus import glib
from dbus.mainloop.glib import DBusGMainLoop
from gi.repository import GObject
from gi.repository import GLib
from gi.repository import Gio
SERVICE_NAME = "com.canonical.test"
INTERFACE_NAME = "com.canonical.test.menuscript"
OBJECT_PATH = "/com/canonical/test/menuscript"
MENU_SERVICE_NAME= SERVICE_NAME + ".menu"
MENU_OBJECT_PATH = OBJECT_PATH + "/menu"
bus = None
class Script(dbus.service.Object):
def __init__(self, aList, session, object_path):
dbus.service.Object.__init__(self, session, object_path)
self._list = aList
self._session = session
def run(self):
self._loop = GObject.MainLoop()
self._loop.run()
@dbus.service.method(dbus_interface=INTERFACE_NAME,
in_signature='', out_signature='',
sender_keyword='sender')
def publishMenu(self, sender=None):
self._list.start()
@dbus.service.method(dbus_interface=INTERFACE_NAME,
in_signature='', out_signature='',
sender_keyword='sender')
def unpublishMenu(self, sender=None):
self._list.stop()
@dbus.service.method(dbus_interface=INTERFACE_NAME,
in_signature='', out_signature='',
sender_keyword='sender')
def quit(self, sender=None):
self.unpublishMenu();
self._loop.quit()
@dbus.service.method(dbus_interface=INTERFACE_NAME,
in_signature='i', out_signature='',
sender_keyword='sender')
def walk(self, steps, sender=None):
if steps == -1 or steps > self._list.size():
steps = self._list.size()
while(steps > 0):
self._list.walk()
steps -= 1
""" TODO: We only support string states for now """
@dbus.service.method(dbus_interface=INTERFACE_NAME,
in_signature='', out_signature='ss')
def popActivatedAction(self):
return self._list._activatedActions.pop(0)
@staticmethod
def create(aList):
global bus
GObject.threads_init()
glib.threads_init()
dbus_loop = DBusGMainLoop()
bus = dbus.SessionBus(mainloop=dbus_loop)
bus_name = dbus.service.BusName(SERVICE_NAME, bus=bus)
return Script(aList, bus_name, OBJECT_PATH)
class Action(object):
def __init__(self, aList, action, **kwargs):
self._list = aList
self._action = action
self._kargs = kwargs
def setProperties(self, menu, props):
if props:
for key in props:
menu.set_attribute_value(key, props[key])
def appendItem(self):
parentId = self._kargs['parentId']
if parentId and len(parentId):
parent = self._list.getMenu(parentId)[0]
else:
parent = self._list._root
if self._kargs['link'] == None:
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'], self._kargs['actionStateType'])
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)
elif self._kargs['link'] == 'submenu':
submenu = Gio.Menu()
parent.append_submenu(self._kargs['label'], submenu)
def removeItem(self):
menuId = self._kargs['menuId']
(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")
def run(self):
if self._action == 'append':
self.appendItem()
elif self._action == 'remove':
self.removeItem()
class ActionList(object):
def __init__(self, objectPath):
self._actions = []
self._actions_bk = []
self._objectPath = objectPath
self._bus = 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, actionStateType=None):
self._actions.append(Action(self, 'append',
parentId=parentId,
label=label,
actionName=actionName,
link=link,
properties=properties,
actionStateType=actionStateType))
def removeItem(self, menuId, actionName=None):
self._actions.append(Action(self, 'remove',
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:
return (root, -1)
currentId = int(ids[0])
link = root.get_item_link(currentId, 'section')
if link == None:
link = root.get_item_link(currentId, 'submenu')
if link:
return self._findMenu(link, ids[1:])
else:
return (root, currentId)
def getMenu(self, menuId):
return self._findMenu(self._root, str(menuId).split('.'));
def walk(self):
item = self._actions.pop(0)
item.run()
def size(self):
return len(self._actions)
def _exportService(self, connection, name):
self._root = Gio.Menu()
self._rootAction = Gio.SimpleActionGroup()
self._bus = connection
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._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._root = None
self._rootAction = None
self._restore()
def _onActionActivated(self, action, parameter):
self._activatedActions.append((action.get_name(), parameter.get_string()))
./tests/script/dbusmenuscript.h 0000644 0000156 0000165 00000002657 12676475617 017022 0 ustar jenkins jenkins /*
* Copyright 2012 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:
* Renato Araujo Oliveira Filho
*/
#ifndef DBUSMENUSCRIPT_H
#define DBUSMENUSCRITP_H
#include
#include
#include
#define SCRIPT_SERVICE_NAME "com.canonical.test"
#define SCRIPT_OBJECT_PATH "/com/canonical/test/menuscript"
#define SCRIPT_INTERFACE_NAME "com.canonical.test.menuscript"
#define MENU_SERVICE_NAME SCRIPT_SERVICE_NAME ".menu"
#define MENU_OBJECT_PATH SCRIPT_OBJECT_PATH "/menu"
class DBusMenuScript
{
public:
DBusMenuScript();
~DBusMenuScript();
bool connect();
void quit();
void walk(int steps = 1);
void run();
void publishMenu();
void unpublishMenu();
QPair popActivatedAction();
private:
QDBusInterface *m_script;
};
#endif
./tests/CMakeLists.txt 0000644 0000156 0000165 00000000064 12676475617 015024 0 ustar jenkins jenkins add_subdirectory(script)
add_subdirectory(client)
./tests/client/ 0000755 0000156 0000165 00000000000 12676475617 013542 5 ustar jenkins jenkins ./tests/client/qmltest.cpp 0000644 0000156 0000165 00000006125 12676475617 015743 0 ustar jenkins jenkins /*
* Copyright 2012 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:
* Renato Araujo Oliveira Filho
*/
extern "C" {
#include
}
#include "qdbusmenumodel.h"
#include "dbusmenuscript.h"
#include "qmlfiles.h"
#include
#include
#include
#include
#include
#include
#include
class QMLTest : public QObject
{
Q_OBJECT
private:
DBusMenuScript m_script;
private Q_SLOTS:
void initTestCase()
{
QVERIFY(m_script.connect());
}
void cleanupTestCase()
{
m_script.quit();
}
void init()
{
}
void cleanup()
{
m_script.unpublishMenu();
}
/*
* Test if model is destroyed without crash
*/
void destroyModel()
{
m_script.publishMenu();
m_script.run();
QTest::qWait(500);
QQuickView *view = new QQuickView;
view->engine()->addImportPath(QML_BASE_DIR);
view->engine()->rootContext()->setContextProperty("resetModel", QVariant(false));
view->engine()->rootContext()->setContextProperty("globalBusType", DBusEnums::SessionBus);
view->engine()->rootContext()->setContextProperty("globalBusName", MENU_SERVICE_NAME);
view->engine()->rootContext()->setContextProperty("globalObjectPath", MENU_OBJECT_PATH);
view->setSource(QUrl::fromLocalFile(LOADMODEL_QML));
QTest::qWait(500);
view->engine()->rootContext()->setContextProperty("resetModel", true);
QTest::qWait(500);
}
/*
* Test the menu model disappearing from the bus and reappearing
* while the QML application is running.
*/
void testServiceDisappear()
{
m_script.publishMenu();
m_script.run();
QTest::qWait(500);
QQuickView *view = new QQuickView;
view->engine()->addImportPath(QML_BASE_DIR);
view->engine()->rootContext()->setContextProperty("globalBusType", DBusEnums::SessionBus);
view->engine()->rootContext()->setContextProperty("globalBusName", MENU_SERVICE_NAME);
view->engine()->rootContext()->setContextProperty("globalObjectPath", MENU_OBJECT_PATH);
view->setSource(QUrl::fromLocalFile(LOADMODEL2_QML));
QTest::qWait(500);
m_script.unpublishMenu();
QTest::qWait(500);
m_script.publishMenu();
m_script.run();
QTest::qWait(500);
delete view;
QTest::qWait(1000);
}
};
QTEST_MAIN(QMLTest)
#include "qmltest.moc"
./tests/client/modelsignalstest.cpp 0000644 0000156 0000165 00000020625 12676475617 017634 0 ustar jenkins jenkins /*
* Copyright 2012 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:
* Renato Araujo Oliveira Filho
*/
#include "qmenumodel.h"
#include
#include
#include
extern "C" {
#include
}
class MenuModelTestClass : public QMenuModel
{
Q_OBJECT
public:
MenuModelTestClass()
: QMenuModel(G_MENU_MODEL(g_menu_new())), m_step(0)
{
}
void loadModel()
{
GMenu *root = G_MENU(menuModel());
// STEP 0
m_step = 0;
GMenu *section = g_menu_new();
g_menu_append(section, "msg1", NULL);
g_menu_append_section(root, "section1", G_MENU_MODEL(section));
// STEP 1
m_step++;
GMenu *section2 = g_menu_new();
g_menu_append_section(root, "section2", G_MENU_MODEL(section2));
// STEP 2
m_step++;
g_menu_append(root, "item1", NULL);
// STEP 3
m_step++;
g_menu_insert(root, 1, "item2", NULL);
}
void clear()
{
GMenu *root = G_MENU(menuModel());
// STEP 0
m_step = 0;
g_menu_remove(root, 0);
// STEP 1
m_step++;
g_menu_remove(root, 2);
// STEP 2
m_step++;
g_menu_remove(root, 0);
// STEP 3
m_step++;
g_menu_remove(root, 0);
}
public Q_SLOTS:
void checkModelStateBeforeInsert(const QModelIndex &parent, int start, int end)
{
if (m_step == 0) {
QCOMPARE(rowCount(), 0);
QVERIFY(data(index(1), QMenuModel::Label).isNull());
} else if (m_step == 1) {
QCOMPARE(rowCount(), 1);
QCOMPARE(data(index(0), QMenuModel::Label).toString(), QString("section1"));
QVERIFY(data(index(1), QMenuModel::Label).isNull());
} else if (m_step == 2) {
QCOMPARE(rowCount(), 2);
QCOMPARE(data(index(0), QMenuModel::Label).toString(), QString("section1"));
QCOMPARE(data(index(1), QMenuModel::Label).toString(), QString("section2"));
QVERIFY(data(index(2), QMenuModel::Label).isNull());
} else if (m_step == 3) {
QCOMPARE(rowCount(), 3);
QCOMPARE(data(index(0), QMenuModel::Label).toString(), QString("section1"));
QCOMPARE(data(index(1), QMenuModel::Label).toString(), QString("section2"));
QCOMPARE(data(index(2), QMenuModel::Label).toString(), QString("item1"));
QVERIFY(data(index(3), QMenuModel::Label).isNull());
}
}
void checkModelStateAfterInsert(const QModelIndex &parent, int start, int end)
{
if (m_step == 0) {
QCOMPARE(rowCount(), 1);
QCOMPARE(data(index(0), QMenuModel::Label).toString(), QString("section1"));
QVERIFY(data(index(1), QMenuModel::Label).isNull());
} else if (m_step == 1) {
QCOMPARE(rowCount(), 2);
QCOMPARE(data(index(0), QMenuModel::Label).toString(), QString("section1"));
QCOMPARE(data(index(1), QMenuModel::Label).toString(), QString("section2"));
QVERIFY(data(index(2), QMenuModel::Label).isNull());
} else if (m_step == 2) {
QCOMPARE(rowCount(), 3);
QCOMPARE(data(index(0), QMenuModel::Label).toString(), QString("section1"));
QCOMPARE(data(index(1), QMenuModel::Label).toString(), QString("section2"));
QCOMPARE(data(index(2), QMenuModel::Label).toString(), QString("item1"));
QVERIFY(data(index(3), QMenuModel::Label).isNull());
} else if (m_step == 3) {
QCOMPARE(rowCount(), 4);
QCOMPARE(data(index(0), QMenuModel::Label).toString(), QString("section1"));
QCOMPARE(data(index(1), QMenuModel::Label).toString(), QString("item2"));
QCOMPARE(data(index(2), QMenuModel::Label).toString(), QString("section2"));
QCOMPARE(data(index(3), QMenuModel::Label).toString(), QString("item1"));
QVERIFY(data(index(4), QMenuModel::Label).isNull());
}
}
void checkModelStateBeforeRemove(const QModelIndex &parent, int start, int end)
{
if (m_step == 0) {
QCOMPARE(rowCount(), 4);
QVERIFY(data(index(0), QMenuModel::Label).isNull());
QCOMPARE(data(index(1), QMenuModel::Label).toString(), QString("item2"));
QCOMPARE(data(index(2), QMenuModel::Label).toString(), QString("section2"));
QCOMPARE(data(index(3), QMenuModel::Label).toString(), QString("item1"));
QVERIFY(data(index(4), QMenuModel::Label).isNull());
} else if (m_step == 1) {
QCOMPARE(rowCount(), 3);
QCOMPARE(data(index(0), QMenuModel::Label).toString(), QString("item2"));
QCOMPARE(data(index(1), QMenuModel::Label).toString(), QString("section2"));
QVERIFY(data(index(3), QMenuModel::Label).isNull());
QVERIFY(data(index(4), QMenuModel::Label).isNull());
} else if (m_step == 2) {
QCOMPARE(rowCount(), 2);
QVERIFY(data(index(0), QMenuModel::Label).isNull());
QCOMPARE(data(index(1), QMenuModel::Label).toString(), QString("section2"));
QVERIFY(data(index(2), QMenuModel::Label).isNull());
} else if (m_step == 3) {
QCOMPARE(rowCount(), 1);
QVERIFY(data(index(0), QMenuModel::Label).isNull());
QVERIFY(data(index(1), QMenuModel::Label).isNull());
}
}
void checkModelStateAfterRemove(const QModelIndex &parent, int start, int end)
{
if (m_step == 0) {
QCOMPARE(rowCount(), 3);
QCOMPARE(data(index(0), QMenuModel::Label).toString(), QString("item2"));
QCOMPARE(data(index(1), QMenuModel::Label).toString(), QString("section2"));
QCOMPARE(data(index(2), QMenuModel::Label).toString(), QString("item1"));
QVERIFY(data(index(3), QMenuModel::Label).isNull());
} else if (m_step == 1) {
QCOMPARE(rowCount(), 2);
QCOMPARE(data(index(0), QMenuModel::Label).toString(), QString("item2"));
QCOMPARE(data(index(1), QMenuModel::Label).toString(), QString("section2"));
QVERIFY(data(index(3), QMenuModel::Label).isNull());
} else if (m_step == 2) {
QCOMPARE(rowCount(), 1);
QCOMPARE(data(index(0), QMenuModel::Label).toString(), QString("section2"));
QVERIFY(data(index(1), QMenuModel::Label).isNull());
} else if (m_step == 3) {
QCOMPARE(rowCount(), 0);
QVERIFY(data(index(0), QMenuModel::Label).isNull());
}
}
private:
int m_step;
};
class ModelSignalsTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase()
{
g_type_init();
}
/*
* Test if the model state still correct before and after insert a new row
*/
void testSignalInsertRows()
{
MenuModelTestClass model;
QObject::connect(&model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)),
&model, SLOT(checkModelStateBeforeInsert(QModelIndex,int,int)));
QObject::connect(&model, SIGNAL(rowsInserted(QModelIndex,int,int)),
&model, SLOT(checkModelStateAfterInsert(QModelIndex,int,int)));
model.loadModel();
}
/*
* Test if the model state still correct before and after remove a row
*/
void testSignalRemoveRows()
{
MenuModelTestClass model;
model.loadModel();
QObject::connect(&model, SIGNAL(rowsAboutToBeMoved(QModelIndex,int,int,QModelIndex,int)),
&model, SLOT(checkModelStateBeforeRemove(QModelIndex,int,int)));
QObject::connect(&model, SIGNAL(rowsRemoved(QModelIndex,int,int)),
&model, SLOT(checkModelStateAfterRemove(QModelIndex,int,int)));
model.clear();
}
};
QTEST_MAIN(ModelSignalsTest)
#include "modelsignalstest.moc"
./tests/client/convertertest.cpp 0000644 0000156 0000165 00000013465 12676475617 017166 0 ustar jenkins jenkins /*
* Copyright 2012 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:
* Renato Araujo Oliveira Filho
*/
extern "C" {
#include
}
#include "converter.h"
#include
#include
#include
class ConverterTest : public QObject
{
Q_OBJECT
private:
bool compare(const QVariant &qv, const GVariantType *type)
{
bool result;
GVariant *gv = Converter::toGVariant(qv);
result = g_variant_type_equal(g_variant_get_type(gv), type);
if (!result) {
qWarning() << "types are different: QVariant:" << qv.typeName()
<< "Result:" << (const char*) g_variant_get_type(gv)
<< "Expected:"<< (const char*) type;
}
g_variant_unref(gv);
return result;
}
bool compareWithSchema(const QVariant &qv, const QString strType)
{
GVariantType* expected_type;
expected_type = g_variant_type_new(strType.toUtf8().data());
bool result;
GVariant *gv = Converter::toGVariantWithSchema(qv, strType.toUtf8().data());
result = g_variant_type_equal(g_variant_get_type(gv), expected_type);
if (!result) {
qWarning() << "types are different: QVariant:" << qv.typeName()
<< "Result:" << (const char*) g_variant_get_type(gv)
<< "Expected:"<< (const char*) expected_type;
}
g_variant_unref(gv);
return result;
}
private Q_SLOTS:
/*
* Test converter QVariant to GVariant
*/
void testToGVariant()
{
// Boolean
QVERIFY(compare(QVariant(true), G_VARIANT_TYPE_BOOLEAN));
// Byte
QVERIFY(compare(QVariant::fromValue(42), G_VARIANT_TYPE_BYTE));
// Int16
QVERIFY(compare(QVariant::fromValue(-42), G_VARIANT_TYPE_INT16));
// UInt16
QVERIFY(compare(QVariant::fromValue(-42), G_VARIANT_TYPE_UINT16));
// Int32
QVERIFY(compare(QVariant(-42), G_VARIANT_TYPE_INT32));
// UInt32
QVERIFY(compare(QVariant((uint)42), G_VARIANT_TYPE_UINT32));
// Int64
QVERIFY(compare(QVariant::fromValue(-42), G_VARIANT_TYPE_INT64));
// UInt64
QVERIFY(compare(QVariant::fromValue(42), G_VARIANT_TYPE_UINT64));
// Double
QVERIFY(compare(QVariant((double)42.42), G_VARIANT_TYPE_DOUBLE));
// String
QVERIFY(compare(QVariant(QString("42")), G_VARIANT_TYPE_STRING));
// ByteArray
QVERIFY(compare(QVariant(QByteArray("42")), G_VARIANT_TYPE_BYTESTRING));
// Map
QVERIFY(compare(QVariantMap(), G_VARIANT_TYPE_VARDICT));
}
void testTupleConversion()
{
QVariantList qTuple;
qTuple << 1 << "2" << 3.3;
GVariant *gTuple = Converter::toGVariant(qTuple);
QVERIFY(g_variant_type_is_tuple(g_variant_get_type(gTuple)));
QCOMPARE(g_variant_n_children(gTuple), (gsize)3);
GVariant *v = g_variant_get_child_value(gTuple, 0);
int v0 = g_variant_get_int32(v);
QCOMPARE(v0, 1);
g_variant_unref(v);
v = g_variant_get_child_value(gTuple, 1);
const gchar *v1 = g_variant_get_string(v, NULL);
QCOMPARE(QString(v1), QString("2"));
g_variant_unref(v);
v = g_variant_get_child_value(gTuple, 2);
gdouble v2 = g_variant_get_double(v);
QCOMPARE(v2, 3.3);
g_variant_unref(v);
g_variant_unref(gTuple);
}
void testSchemaConvert()
{
// convert to integer
compareWithSchema(QVariant::fromValue(1), "i");
compareWithSchema(QVariant::fromValue(1.1), "i");
// convert to integer
compareWithSchema(QVariant::fromValue(true), "b");
compareWithSchema(QVariant::fromValue(1), "b");
// convert to double
compareWithSchema(QVariant::fromValue(1.0), "d");
compareWithSchema(QVariant::fromValue(1), "d");
// convert to string
compareWithSchema(QVariant::fromValue(1), "s");
compareWithSchema(QVariant::fromValue(1.1), "s");
// convert to tuple
compareWithSchema(QVariantList() << QVariant::fromValue(true) << QVariant::fromValue(1) << QVariant::fromValue(1) << QVariant::fromValue("test1"), "(bdis)");
// convert to array
compareWithSchema(QVariantList() << QVariant::fromValue(1) << QVariant::fromValue(1), "ad");
compareWithSchema(QVariantList() << QVariant::fromValue("test1") << QVariant::fromValue("test2"), "as");
// convert to array of tuple
QVariantList si1(QVariantList() << QVariant::fromValue("test1") << QVariant::fromValue(1));
QVariantList si2(QVariantList() << QVariant::fromValue("test1") << QVariant::fromValue(1));
compareWithSchema(QVariantList() << QVariant::fromValue(si1) << QVariant::fromValue(si2), "a(sd)");
// convert to vardict
QVariantMap map;
map["test1"] = QVariant::fromValue(1);
map["test2"] = QVariant::fromValue(1);
compareWithSchema(map, "a{sv}");
}
};
QTEST_MAIN(ConverterTest)
#include "convertertest.moc"
./tests/client/treetest.cpp 0000644 0000156 0000165 00000007027 12676475617 016113 0 ustar jenkins jenkins /*
* Copyright 2012 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:
* Renato Araujo Oliveira Filho
* Olivier Tilloy
*/
#include "qmenumodel.h"
extern "C" {
#include
}
#include
class TestModel : public QMenuModel
{
Q_OBJECT
public:
TestModel() : QMenuModel(0)
{
GMenu *menu5 = g_menu_new();
g_menu_append(menu5, "menu6", NULL);
g_menu_append(menu5, "menu7", NULL);
GMenu *menu3 = g_menu_new();
g_menu_append(menu3, "menu4", NULL);
g_menu_append_section(menu3, "menu5", G_MENU_MODEL(menu5));
g_menu_append(menu3, "menu8", NULL);
GMenu *menu = g_menu_new();
g_menu_append(menu, "menu0", NULL);
g_menu_append(menu, "menu1", NULL);
g_menu_append(menu, "menu2", NULL);
g_menu_append_section(menu, "menu3", G_MENU_MODEL(menu3));
setMenuModel(G_MENU_MODEL(menu));
m_menus << menu << menu3 << menu5;
}
private:
QList m_menus;
};
class TreeTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase()
{
g_type_init();
}
void testMenuBuild()
{
TestModel menu;
QCOMPARE(menu.rowCount(), 4);
QModelIndex row0 = menu.index(0);
QVERIFY(row0.isValid());
QCOMPARE(menu.rowCount(row0), 0);
QModelIndex row3 = menu.index(3);
QVERIFY(row3.isValid());
QCOMPARE(menu.rowCount(row3), 3);
QCOMPARE(menu.data(row3, QMenuModel::Label).toString(), QString("menu3"));
QModelIndex row4 = row3.child(0, 0);
QVERIFY(row4.isValid());
QCOMPARE(menu.rowCount(row4), 0);
QCOMPARE(menu.data(row4, QMenuModel::Depth).toInt(), 1);
QCOMPARE(menu.data(row4, QMenuModel::Label).toString(), QString("menu4"));
QModelIndex row5 = row3.child(1, 0);
QVERIFY(row5.isValid());
QCOMPARE(menu.rowCount(row5), 2);
QCOMPARE(menu.data(row5, QMenuModel::Depth).toInt(), 1);
QCOMPARE(menu.data(row5, QMenuModel::Label).toString(), QString("menu5"));
QModelIndex row6 = row5.child(0, 0);
QVERIFY(row6.isValid());
QCOMPARE(menu.rowCount(row6), 0);
QCOMPARE(menu.data(row6, QMenuModel::Depth).toInt(), 2);
QCOMPARE(menu.data(row6, QMenuModel::Label).toString(), QString("menu6"));
QModelIndex row7 = row5.child(1, 0);
QVERIFY(row7.isValid());
QCOMPARE(menu.rowCount(row7), 0);
QCOMPARE(menu.data(row7, QMenuModel::Depth).toInt(), 2);
QCOMPARE(menu.data(row7, QMenuModel::Label).toString(), QString("menu7"));
QModelIndex parent_6 = menu.parent(row6);
QVERIFY(parent_6.isValid());
QCOMPARE(menu.rowCount(parent_6), 2);
QCOMPARE(menu.data(parent_6, QMenuModel::Depth).toInt(), 1);
QCOMPARE(menu.data(parent_6, QMenuModel::Label).toString(), QString("menu5"));
}
};
QTEST_MAIN(TreeTest)
#include "treetest.moc"
./tests/client/script_servicetest.py 0000755 0000156 0000165 00000001541 12676475617 020044 0 ustar jenkins jenkins #!/usr/bin/env python3
# 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 .
#
import time
from menuscript import Script, ActionList, MENU_OBJECT_PATH
al = ActionList(MENU_OBJECT_PATH)
al.appendItem("Menu0", "Menu0")
al.appendItem("Menu1", "Menu1")
t = Script.create(al)
t.run()
./tests/client/cachetest.cpp 0000644 0000156 0000165 00000013537 12676475617 016222 0 ustar jenkins jenkins /*
* Copyright 2012 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:
* Renato Araujo Oliveira Filho
* Olivier Tilloy
*/
#include "qmenumodel.h"
extern "C" {
#include
}
#include
class TestModel : public QMenuModel
{
Q_OBJECT
public:
TestModel() : QMenuModel(0)
{
GMenu *menu3 = g_menu_new();
g_menu_append(menu3, "menu4", NULL);
g_menu_append(menu3, "menu5", NULL);
g_menu_append(menu3, "menu6", NULL);
GMenu *menu = g_menu_new();
g_menu_append(menu, "menu0", NULL);
g_menu_append(menu, "menu1", NULL);
g_menu_append(menu, "menu2", NULL);
g_menu_append_section(menu, "menu3", G_MENU_MODEL(menu3));
setMenuModel(G_MENU_MODEL(menu));
m_menus << menu << menu3;
}
void removeItem(int section, int index)
{
GMenu *menu = m_menus[section];
g_menu_remove(menu, index);
}
void insertItem(int section, int index, const QString &label)
{
GMenu *menu = m_menus[section];
g_menu_insert(menu, index, label.toUtf8().data(), NULL);
}
QList cacheIndexes() const
{
QList indexes = cache().keys();
qSort(indexes);
return indexes;
}
private:
QList m_menus;
};
class CacheTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase()
{
g_type_init();
}
// Verify that normal menu items are not cached (only sub-menus are)
void testCacheContents()
{
TestModel menu;
QVERIFY(menu.cacheIndexes().isEmpty());
menu.data(menu.index(1), QMenuModel::Label);
QVERIFY(menu.cacheIndexes().isEmpty());
menu.data(menu.index(2), QMenuModel::Action);
QVERIFY(menu.cacheIndexes().isEmpty());
}
// Verify that the link attribute always returns the same cached menu
void testStaticMenuCache()
{
TestModel menu;
QModelIndex index = menu.index(3);
QVariant data = menu.data(index, QMenuModel::LinkSection);
QCOMPARE(menu.cacheIndexes(), QList() << 3);
QVariant data2 = menu.data(index, QMenuModel::LinkSection);
QCOMPARE(menu.cacheIndexes(), QList() << 3);
QVERIFY(data.value() == data2.value());
QMenuModel *section = qvariant_cast(data);
index = section->index(1);
data = menu.data(index, QMenuModel::LinkSection);
data2 = menu.data(index, QMenuModel::LinkSection);
QCOMPARE(menu.cacheIndexes(), QList() << 3);
QVERIFY(data.value() == data2.value());
}
// Verify that the cache is correctly updated after inserting a new item
void testInsertItems()
{
TestModel menu;
QModelIndex index = menu.index(3);
QVariant data = menu.data(index, QMenuModel::LinkSection);
QCOMPARE(menu.cacheIndexes(), QList() << 3);
menu.insertItem(0, 4, "newMenu");
QCOMPARE(menu.cacheIndexes(), QList() << 3);
menu.insertItem(0, 1, "newMenu");
QCOMPARE(menu.cacheIndexes(), QList() << 4);
index = menu.index(4);
QVariant data2 = menu.data(index, QMenuModel::LinkSection);
QCOMPARE(menu.cacheIndexes(), QList() << 4);
QVERIFY(data.value() == data2.value());
}
// Verify that the cache is correctly updated after removing an item that wasn’t cached
void testRemoveNonCachedItem()
{
TestModel menu;
QModelIndex index = menu.index(3);
QVariant data = menu.data(index, QMenuModel::LinkSection);
QCOMPARE(menu.cacheIndexes(), QList() << 3);
menu.removeItem(0, 1);
QCOMPARE(menu.cacheIndexes(), QList() << 2);
index = menu.index(2);
QVariant data2 = menu.data(index, QMenuModel::LinkSection);
QCOMPARE(menu.cacheIndexes(), QList() << 2);
QVERIFY(data.value() == data2.value());
}
// Verify that the cache is correctly updated after removing a cached item
void testRemoveCachedItem()
{
TestModel menu;
QModelIndex index = menu.index(3);
QVariant data = menu.data(index, QMenuModel::LinkSection);
QCOMPARE(menu.cacheIndexes(), QList() << 3);
menu.removeItem(0, 3);
QVERIFY(menu.cacheIndexes().isEmpty());
}
// Verify that the cache is correctly updated after multiple insertions and removals
void testMultiplesUpdates()
{
TestModel menu;
QVERIFY(menu.cacheIndexes().isEmpty());
menu.data(menu.index(3), QMenuModel::LinkSection);
QCOMPARE(menu.cacheIndexes(), QList() << 3);
menu.insertItem(0, 1, "newMenu");
menu.insertItem(0, 2, "newMenu");
menu.insertItem(0, 6, "newMenu");
menu.insertItem(0, 3, "newMenu");
menu.insertItem(0, 7, "newMenu");
QCOMPARE(menu.cacheIndexes(), QList() << 6);
menu.removeItem(0, 4);
menu.removeItem(0, 6);
menu.removeItem(0, 2);
QCOMPARE(menu.cacheIndexes(), QList() << 4);
menu.removeItem(0, 4);
QVERIFY(menu.cacheIndexes().isEmpty());
}
};
QTEST_MAIN(CacheTest)
#include "cachetest.moc"
./tests/client/servicetest.cpp 0000644 0000156 0000165 00000005520 12676475617 016610 0 ustar jenkins jenkins /*
* Copyright 2012 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:
* Renato Araujo Oliveira Filho
*/
#include "qdbusmenumodel.h"
#include "dbusmenuscript.h"
#include
#include
#include
#include
class ServiceTest : public QObject
{
Q_OBJECT
private:
DBusMenuScript m_script;
QDBusMenuModel m_model;
void setupModel(QDBusMenuModel *model)
{
model->setBusType(DBusEnums::SessionBus);
model->setBusName(MENU_SERVICE_NAME);
model->setObjectPath(MENU_OBJECT_PATH);
}
private Q_SLOTS:
void initTestCase()
{
QVERIFY(m_script.connect());
}
void cleanupTestCase()
{
m_script.quit();
}
void init()
{
m_model.stop();
m_model.setBusType(DBusEnums::SessionBus);
m_model.setBusName(MENU_SERVICE_NAME);
m_model.setObjectPath(MENU_OBJECT_PATH);
}
void cleanup()
{
m_script.unpublishMenu();
}
void testMenuStartStopWithNoService()
{
m_model.start();
QCOMPARE(m_model.status(), DBusEnums::Connecting);
m_model.stop();
QCOMPARE(m_model.status(), DBusEnums::Disconnected);
}
void testMenuStartStopWithService()
{
// Make menu available
m_script.publishMenu();
// start model
m_model.start();
// Wait for dbus sync
QTest::qWait(500);
QCOMPARE(m_model.status(), DBusEnums::Connected);
// Diconnect model
m_model.stop();
QCOMPARE(m_model.status(), DBusEnums::Disconnected);
}
void testMenuServiceAppearAndDissapear()
{
m_model.start();
QCOMPARE(m_model.status(), DBusEnums::Connecting);
QSignalSpy spy(&m_model, SIGNAL(statusChanged(DBusEnums::ConnectionStatus)));
// Make menu available
m_script.publishMenu();
// singal changed to connected
QCOMPARE(spy.count(), 1);
QCOMPARE(m_model.status(), DBusEnums::Connected);
// remove menu service
m_script.unpublishMenu();
// signal changed to connecting
QCOMPARE(spy.count(), 2);
QCOMPARE(m_model.status(), DBusEnums::Connecting);
}
};
QTEST_MAIN(ServiceTest)
#include "servicetest.moc"
./tests/client/actiongrouptest.cpp 0000644 0000156 0000165 00000012455 12676475617 017507 0 ustar jenkins jenkins /*
* Copyright 2012 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:
* Renato Araujo Oliveira Filho
*/
#include "qdbusmenumodel.h"
#include "qdbusactiongroup.h"
#include "dbusmenuscript.h"
#include "qstateaction.h"
#include
#include
#include
#include
class ActionGroupTest : public QObject
{
Q_OBJECT
private:
DBusMenuScript m_script;
QDBusMenuModel m_model;
QDBusActionGroup m_actionGroup;
private Q_SLOTS:
void initTestCase()
{
QVERIFY(m_script.connect());
}
void cleanupTestCase()
{
m_script.quit();
}
void init()
{
m_model.stop();
m_model.setBusType(DBusEnums::SessionBus);
m_model.setBusName(MENU_SERVICE_NAME);
m_model.setObjectPath(MENU_OBJECT_PATH);
m_actionGroup.stop();
m_actionGroup.setBusType(DBusEnums::SessionBus);
m_actionGroup.setBusName(MENU_SERVICE_NAME);
m_actionGroup.setObjectPath(MENU_OBJECT_PATH);
}
void cleanup()
{
m_script.unpublishMenu();
}
/*
* Test if the propety busType handle correct integer values
*/
void testBusTypeProperty()
{
m_actionGroup.setProperty("busType", 1);
QCOMPARE(m_actionGroup.busType(), DBusEnums::SessionBus);
m_actionGroup.setProperty("busType", 2);
QCOMPARE(m_actionGroup.busType(), DBusEnums::SystemBus);
m_actionGroup.setProperty("busType", 0);
QCOMPARE(m_actionGroup.busType(), DBusEnums::SystemBus);
m_actionGroup.setProperty("busType", 10);
QCOMPARE(m_actionGroup.busType(), DBusEnums::SystemBus);
}
/*
* Test if QDBusActionGroup change to correct state after DBus
* ervice appear
*/
void testServiceAppear()
{
m_model.start();
m_actionGroup.start();
QCOMPARE(m_actionGroup.status(), DBusEnums::Connecting);
// Make menu available
m_script.publishMenu();
QCOMPARE(m_actionGroup.status(), DBusEnums::Connected);
}
/*
* Test if QDBusActionGroup change to correct state after DBus
* service disappear
*/
void testServiceDisappear()
{
m_model.start();
m_actionGroup.start();
// Make menu available
m_script.publishMenu();
QCOMPARE(m_actionGroup.status(), DBusEnums::Connected);
// Append menus
m_script.walk(2);
// Remove menu from dbus
m_script.unpublishMenu();
QCOMPARE(m_actionGroup.status(), DBusEnums::Connecting);
m_actionGroup.stop();
QCOMPARE(m_actionGroup.status(), DBusEnums::Disconnected);
}
/*
* Test if Action::trigger active the action over DBus
*/
void testActiveAction()
{
// start model
m_model.start();
m_actionGroup.start();
// Make menu available
m_script.publishMenu();
m_script.walk(2);
// Get Action
QVariant action = m_model.data(m_model.index(1, 0), QMenuModel::Action);
QVERIFY(action.isValid());
QStateAction *act = m_actionGroup.action(action.toString());
QVERIFY(act);
// test action name
QCOMPARE(act->property("name").toString(), QString("Menu1Act"));
act->activate(QVariant("42"));
// wait for dbus propagation
QTest::qWait(500);
QPair result = m_script.popActivatedAction();
QCOMPARE(result.first, QString("Menu1Act"));
QCOMPARE(result.second.toString(), QString("42"));
}
/*
* Test if Action became invalid after desappear from DBus
*/
void testRemoveAction()
{
// start model
m_model.start();
m_actionGroup.start();
// Make menu available and append 2 menus
m_script.publishMenu();
m_script.walk(2);
// Get Action
QStateAction *act = m_actionGroup.action(QString("Menu1Act"));
QVERIFY(act);
QVERIFY(act->isValid());
// Remove 1 menu
m_script.walk(1);
//Check if action is invalid
QVERIFY(!act->isValid());
}
/*
* Test if Action became valid after service appears
*/
void testActionIsValid()
{
// start model
m_model.start();
m_actionGroup.start();
// Make menu available and append 2 menus
m_script.publishMenu();
// Get invalid Action
QStateAction *act = m_actionGroup.action(QString("Menu1Act"));
QVERIFY(act);
QVERIFY(!act->isValid());
QVERIFY(!act->state().isValid());
// Append menus
m_script.walk(2);
// Action appear
QVERIFY(act->isValid());
}
};
QTEST_MAIN(ActionGroupTest)
#include "actiongrouptest.moc"
./tests/client/loadmodel.qml 0000644 0000156 0000165 00000002732 12676475617 016221 0 ustar jenkins jenkins /*
* Copyright 2012 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:
* Renato Araujo Oliveira Filho
*/
import QtQuick 2.0
import QMenuModel 0.1
Item {
id: root
width: 100
height: 100
property bool reset: resetModel
onResetChanged: {
if (reset) {
// destroy the current model and check if it will not crash the QML engine
view.model.destroy();
}
}
ListView {
id: view
anchors.fill: parent
delegate: Text {
text: label
}
}
Component.onCompleted: {
// dynamically create the model to destroy it later
var model = Qt.createQmlObject("import QMenuModel 0.1; QDBusMenuModel { id: menuModel; busType: globalBusType; busName: globalBusName; objectPath: globalObjectPath; }", view, "");
model.start();
view.model = model;
}
}
./tests/client/script_qmltest.py 0000755 0000156 0000165 00000001541 12676475617 017175 0 ustar jenkins jenkins #!/usr/bin/env python3
# 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 .
#
import time
from menuscript import Script, ActionList, MENU_OBJECT_PATH
al = ActionList(MENU_OBJECT_PATH)
al.appendItem("Menu0", "Menu0")
al.appendItem("Menu1", "Menu1")
t = Script.create(al)
t.run()
./tests/client/loadmodel2.qml 0000644 0000156 0000165 00000002061 12676475617 016276 0 ustar jenkins jenkins /*
* Copyright 2012 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:
* Renato Araujo Oliveira Filho
*/
import QtQuick 2.0
import QMenuModel 0.1
Item {
width: 100
height: 100
QDBusMenuModel {
id: menuModel
busType: globalBusType
busName: globalBusName
objectPath: globalObjectPath
}
ListView {
model: menuModel
delegate: Item {}
}
Component.onCompleted: menuModel.start()
}
./tests/client/modeltest.cpp 0000644 0000156 0000165 00000014230 12676475617 016246 0 ustar jenkins jenkins /*
* Copyright 2012 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:
* Renato Araujo Oliveira Filho
*/
#include "qdbusmenumodel.h"
#include "dbusmenuscript.h"
#include
#include
#include
#include
extern "C" {
#include
}
class ModelTest : public QObject
{
Q_OBJECT
private:
DBusMenuScript m_script;
QDBusMenuModel m_model;
private Q_SLOTS:
void initTestCase()
{
QVERIFY(m_script.connect());
}
void cleanupTestCase()
{
m_script.quit();
}
void init()
{
m_model.stop();
m_model.setBusType(DBusEnums::SessionBus);
m_model.setBusName(MENU_SERVICE_NAME);
m_model.setObjectPath(MENU_OBJECT_PATH);
}
void cleanup()
{
m_script.unpublishMenu();
}
/*
* Test if parent function always return a empty QModelIndex
*/
void testParent()
{
QCOMPARE(m_model.parent(QModelIndex()), QModelIndex());
}
/*
* Test if the propety busType handle correct integer values
*/
void testBusTypeProperty()
{
m_model.setProperty("busType", 1);
QCOMPARE(m_model.busType(), DBusEnums::SessionBus);
m_model.setProperty("busType", 2);
QCOMPARE(m_model.busType(), DBusEnums::SystemBus);
m_model.setProperty("busType", 0);
QCOMPARE(m_model.busType(), DBusEnums::SystemBus);
m_model.setProperty("busType", 10);
QCOMPARE(m_model.busType(), DBusEnums::SystemBus);
}
/*
* Test if model return the correct values for standard properties
*/
void testData()
{
// Make menu available
m_script.publishMenu();
m_script.run();
// start model
m_model.start();
// Wait for dbus sync
QTest::qWait(500);
QCOMPARE(m_model.status(), DBusEnums::Connected);
QCOMPARE(m_model.rowCount(), 4);
// Label (String)
QVariant label = m_model.data(m_model.index(0, 0), QMenuModel::Label);
QVERIFY(label.isValid());
QCOMPARE(label.type(), QVariant::String);
QCOMPARE(label.toString(), QString("Menu0"));
// Action (String)
QVariant action = m_model.data(m_model.index(1, 0), QMenuModel::Action);
QVERIFY(action.isValid());
QCOMPARE(action.type(), QVariant::String);
QCOMPARE(action.toString(), QString("Menu1Act"));
// Wait for menu load (submenus are loaded async)
QTest::qWait(500);
QCOMPARE(m_model.rowCount(m_model.index(2, 0)), 2);
}
/*
* Test if the model parse correct GVariant values types
*/
void testExtraData()
{
// Make menu available
m_script.publishMenu();
m_script.run();
// start model
m_model.start();
// Wait for dbus sync
QTest::qWait(500);
QCOMPARE(m_model.status(), DBusEnums::Connected);
QCOMPARE(m_model.rowCount(), 4);
QVariant e = m_model.data(m_model.index(0, 0), QMenuModel::Extra);
QVERIFY(e.isValid());
QVariantMap extra = e.toMap();
// Boolean
QVariant v = extra["boolean"];
QCOMPARE(v.type(), QVariant::Bool);
QCOMPARE(v.toBool(), true);
// Byte
v = extra["byte"];
QCOMPARE(v.typeName(), "uchar");
QCOMPARE(v.value(), (uchar)42);
// Int16
v = extra["int16"];
QCOMPARE(v.typeName(), "short");
QCOMPARE(v.value(), (short)-42);
// UInt16
v = extra["uint16"];
QCOMPARE(v.typeName(), "ushort");
QCOMPARE(v.value(), (ushort)42);
// Int32
v = extra["int32"];
QCOMPARE(v.type(), QVariant::Int);
QCOMPARE(v.toInt(), -42);
// UInt32
v = extra["uint32"];
QCOMPARE(v.type(), QVariant::UInt);
QCOMPARE(v.toUInt(), (uint) 42);
// Int64
v = extra["int64"];
QCOMPARE(v.type(), QVariant::LongLong);
QCOMPARE(v.value(), (long) -42);
// UInt64
v = extra["uint64"];
QCOMPARE(v.type(), QVariant::ULongLong);
QCOMPARE(v.value(), (ulong) 42);
// Double
v = extra["double"];
QCOMPARE(v.type(), QVariant::Double);
QCOMPARE(v.toDouble(), 42.42);
// String
v = extra["string"];
QCOMPARE(v.type(), QVariant::String);
QCOMPARE(v.toString(), QString("42"));
// Map
v = extra["map"];
QVariantMap map;
map.insert("int64", QVariant::fromValue(-42));
map.insert("string", "42");
map.insert("double", 42.42);
QCOMPARE(v.type(), QVariant::Map);
QCOMPARE(v.toMap(), map);
// Utf8
v = extra["utf8"];
QCOMPARE(v.type(), QVariant::String);
QCOMPARE(v.toString(), QString("dança"));
// Tuple
v = extra["tuple"];
QVariantList lst;
lst << "1" << 2 << 3.3;
QCOMPARE(v.type(), QVariant::List);
QCOMPARE(v.toList(), lst);
}
/*
* Test if model is destroyed without crash
*/
void testDestroyModel()
{
// Make menu available
m_script.publishMenu();
m_script.run();
// create a new model
QDBusMenuModel *model = new QDBusMenuModel();
model->setBusType(DBusEnums::SessionBus);
model->setBusName(MENU_SERVICE_NAME);
model->setObjectPath(MENU_OBJECT_PATH);
model->start();
// Wait for dbus sync
QTest::qWait(500);
delete model;
}
};
QTEST_MAIN(ModelTest)
#include "modeltest.moc"
./tests/client/script_modeltest.py 0000755 0000156 0000165 00000004707 12676475617 017513 0 ustar jenkins jenkins #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# 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 .
#
import time
from gi.repository import GLib
from menuscript import Script, ActionList, MENU_OBJECT_PATH
al = ActionList(MENU_OBJECT_PATH)
# create map
pmap = {'int64' : GLib.Variant('x', -42),
'string': GLib.Variant('s', '42'),
'double': GLib.Variant('d', 42.42)}
al.appendItem("Menu0", "Menu0Act", None, None, {'x-boolean' : GLib.Variant('b', True),
'x-byte' : GLib.Variant('y', 42),
'x-int16' : GLib.Variant('n', -42),
'x-uint16' : GLib.Variant('q', 42),
'x-int32' : GLib.Variant('i', -42),
'x-uint32' : GLib.Variant('u', 42),
'x-int64' : GLib.Variant('x', -42),
'x-uint64' : GLib.Variant('t', 42),
'x-double' : GLib.Variant('d', 42.42),
'x-string' : GLib.Variant('s', '42'),
'x-utf8' : GLib.Variant('s', 'dança'),
'x-map' : GLib.Variant('a{sv}', pmap),
'x-tuple' : GLib.Variant('(sid)', ("1", 2, 3.3)),
})
al.appendItem("Menu1", "Menu1Act")
al.appendItem("Menu2", "Menu2Act", "section")
al.appendItem("Menu2.1", "Menu2.1Act", None, "2")
al.appendItem("Menu2.2", "Menu2.2Act", None, "2")
al.appendItem("Menu3", "Menu3Act", "submenu")
al.appendItem("Menu3.1", "Menu3.1Act", None, "3")
al.appendItem("Menu3.2", "Menu3.2Act", None, "3")
t = Script.create(al)
t.run()
./tests/client/unitymenuactiontest.cpp 0000644 0000156 0000165 00000003070 12676475617 020401 0 ustar jenkins jenkins /*
* Copyright 2014 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:
* Nick Dedekind
*/
#include "unitymenumodel.h"
#include "unitymenuaction.h"
#include
#include
class UnityMenuActionTest : public QObject
{
Q_OBJECT
private:
private Q_SLOTS:
/*
* Test if the propety busType handle correct integer values
*/
void testDestroyAfterModel()
{
UnityMenuModel* model = new UnityMenuModel;
UnityMenuAction* action = new UnityMenuAction;
action->setModel(model);
delete model;
delete action;
}
/*
* Test if the propety busType handle correct integer values
*/
void testDestroyBeforeModel()
{
UnityMenuModel* model = new UnityMenuModel;
UnityMenuAction* action = new UnityMenuAction;
action->setModel(model);
delete action;
delete model;
}
};
QTEST_MAIN(UnityMenuActionTest)
#include "unitymenuactiontest.moc"
./tests/client/script_actiongrouptest.py 0000755 0000156 0000165 00000002055 12676475617 020737 0 ustar jenkins jenkins #!/usr/bin/env python3
# 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 .
import time
from gi.repository import GLib
from menuscript import Script, ActionList, MENU_OBJECT_PATH
from gi._gi import variant_type_from_string
al = ActionList(MENU_OBJECT_PATH)
al.appendItem("Menu0", "Menu0Act", actionStateType=variant_type_from_string('s'))
al.appendItem("Menu1", "Menu1Act", actionStateType=variant_type_from_string('s'))
al.removeItem("1", "Menu1Act")
t = Script.create(al)
t.run()
./tests/client/CMakeLists.txt 0000644 0000156 0000165 00000004251 12676475617 016304 0 ustar jenkins jenkins macro(declare_test testname)
add_executable(${testname} ${testname}.cpp)
qt5_use_modules(${testname} Core DBus Widgets Test Qml Quick)
target_link_libraries(${testname}
qmenumodel
dbusmenuscript
${GLIB_LDFLAGS}
${GIO_LDFLAGS}
)
if(TEST_XML_OUTPUT)
set(TEST_ARGS -p -xunitxml -p -o -p test_${testname}.xml)
else()
set(TEST_ARGS "")
endif()
add_test(${testname}
${DBUS_RUNNER}
--task ${CMAKE_CURRENT_BINARY_DIR}/${testname} ${TEST_ARGS} --task-name Client
--task ${CMAKE_CURRENT_SOURCE_DIR}/script_${testname}.py --task-name Server
--ignore-return)
set_tests_properties(${testname} PROPERTIES
TIMEOUT ${CTEST_TESTING_TIMEOUT}
ENVIRONMENT "PYTHONPATH=${TEST_PYTHONPATH};QT_QPA_PLATFORM=minimal")
endmacro(declare_test testname)
macro(declare_simple_test testname)
add_executable(${testname} ${testname}.cpp)
qt5_use_modules(${testname} Core Test)
target_link_libraries(${testname}
qmenumodel
${GLIB_LDFLAGS}
${GIO_LDFLAGS}
)
add_test(${testname}
${CMAKE_CURRENT_BINARY_DIR}/${testname})
set_tests_properties(${testname} PROPERTIES
TIMEOUT ${CTEST_TESTING_TIMEOUT})
endmacro(declare_simple_test testname)
include_directories(${src_SOURCE_DIR}
${dbusmenuscript_SOURCE_DIR}
${GLIB_INCLUDE_DIRS}
)
add_definitions(-DTEST_SUITE)
set(TEST_PYTHONPATH ${dbusmenuscript_SOURCE_DIR})
if(NOT CTEST_TESTING_TIMEOUT)
set(CTEST_TESTING_TIMEOUT 60)
endif()
declare_test(servicetest)
declare_test(menuchangestest)
declare_test(modeltest)
declare_test(actiongrouptest)
declare_test(qmltest)
declare_test(convertertest)
declare_test(modelsignalstest)
declare_test(treetest)
declare_test(unitymenuactiontest)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/qmlfiles.h.in
${CMAKE_CURRENT_BINARY_DIR}/qmlfiles.h)
./tests/client/script_menuchangestest.py 0000755 0000156 0000165 00000001637 12676475617 020707 0 ustar jenkins jenkins #!/usr/bin/env python3
# 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 .
import time
from menuscript import Script, ActionList, MENU_OBJECT_PATH
al = ActionList(MENU_OBJECT_PATH)
al.appendItem("Menu0", "Menu0")
al.appendItem("Menu1", "Menu1")
al.removeItem(0) # remove Menu0
al.removeItem(0) # remove Menu1
t = Script.create(al)
t.run()
./tests/client/qmlfiles.h.in 0000644 0000156 0000165 00000000313 12676475617 016131 0 ustar jenkins jenkins const char* QML_BASE_DIR = "@libqmenumodel_BINARY_DIR@";
const char* LOADMODEL_QML = "@CMAKE_CURRENT_SOURCE_DIR@/loadmodel.qml";
const char* LOADMODEL2_QML = "@CMAKE_CURRENT_SOURCE_DIR@/loadmodel2.qml";
./tests/client/menuchangestest.cpp 0000644 0000156 0000165 00000003751 12676475617 017451 0 ustar jenkins jenkins /*
* Copyright 2012 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:
* Renato Araujo Oliveira Filho
*/
#include "qdbusmenumodel.h"
#include "dbusmenuscript.h"
#include
#include
#include
#include
class MenuChangesTest : public QObject
{
Q_OBJECT
private:
DBusMenuScript m_script;
QDBusMenuModel m_model;
private Q_SLOTS:
void initTestCase()
{
QVERIFY(m_script.connect());
}
void cleanupTestCase()
{
m_script.quit();
}
void init()
{
m_model.stop();
m_model.setBusType(DBusEnums::SessionBus);
m_model.setBusName(MENU_SERVICE_NAME);
m_model.setObjectPath(MENU_OBJECT_PATH);
}
void cleanup()
{
m_script.unpublishMenu();
}
/*
* Test it the model updates correct after remove or add a new menu
*/
void testMenuItemAppend()
{
m_script.publishMenu();
m_model.start();
// Create first Item
m_script.walk();
QCOMPARE(m_model.rowCount(), 1);
// Create second item
m_script.walk();
QCOMPARE(m_model.rowCount(), 2);
// Remove item0
m_script.walk();
QCOMPARE(m_model.rowCount(), 1);
// Remove item1
m_script.walk();
QCOMPARE(m_model.rowCount(), 0);
}
};
QTEST_MAIN(MenuChangesTest)
#include "menuchangestest.moc"
./README 0000644 0000156 0000165 00000002354 12676475617 012006 0 ustar jenkins jenkins QMenuModel - a Qt/QML binding for GMenuModel
(see http://developer.gnome.org/gio/unstable/GMenuModel.html)
= Building =
The build system uses cmake.
To compile, simply invoke cmake and then make, e.g.:
$ cmake .
$ make
= Running unit tests =
To run the unit tests, you will need dbus-test-runner. If it wasn’t previously
installed, install it and then re-run cmake. Then run either of these commands:
$ make test
- or -
$ ctest
= Getting code coverage information =
To run the unit tests and generate code coverage information, you need to re-run
cmake with ENABLE_COVERAGE set to ON and then invoke `make lcov`.
This requires lcov to be installed.
$ cmake -DENABLE_COVERAGE=ON .
$ make lcov
This will generate a report (coverage/index.html) which you can view in a
browser.
= API documentation =
To generate API documentation, you need to re-run cmake with GENERATE_DOC set to
ON and then invoke `make qdoc`. This requires qdoc3 to be installed.
$ cmake -DGENERATE_DOC=ON .
$ make qdoc
The documentation is generated in the HTML format under doc/html/.
= Examples =
There are examples of how to use QDBusMenuModel in QML, refer to the README file
under the examples/ directory for instructions.
./libqmenumodel/ 0000755 0000156 0000165 00000000000 12676475617 013757 5 ustar jenkins jenkins ./libqmenumodel/src/ 0000755 0000156 0000165 00000000000 12676475633 014544 5 ustar jenkins jenkins ./libqmenumodel/src/qmenumodelevents.h 0000644 0000156 0000165 00000004573 12676475617 020323 0 ustar jenkins jenkins /*
* 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:
* Nicholas Dedekind
#include
class MenuNode;
typedef struct _GDBusConnection GDBusConnection;
typedef struct _GMenuModel GMenuModel;
/* Event for a connection update for a dbus object */
class DbusObjectServiceEvent : public QEvent
{
public:
static const QEvent::Type eventType;
DbusObjectServiceEvent(GDBusConnection* connection, bool visible);
~DbusObjectServiceEvent();
GDBusConnection* connection;
bool visible;
};
/* Event for an update to the gmenumodel */
class MenuModelEvent : public QEvent
{
public:
static const QEvent::Type eventType;
MenuModelEvent(GMenuModel *model);
~MenuModelEvent();
GMenuModel *model;
};
/* Event for a GAction (base) */
class DBusActionEvent : public QEvent
{
public:
QString name;
protected:
DBusActionEvent(const QString& name, QEvent::Type type);
};
/* Event for a GAction add/remove */
class DBusActionVisiblityEvent : public DBusActionEvent
{
public:
static const QEvent::Type eventType;
DBusActionVisiblityEvent(const QString& name, bool visible);
bool visible;
};
/* Event for a GAction state value update */
class DBusActionStateEvent : public DBusActionEvent
{
public:
static const QEvent::Type eventType;
DBusActionStateEvent(const QString& name, const QVariant& state);
QVariant state;
};
/* Event for changing gmenumodel entries */
class MenuNodeItemChangeEvent : public QEvent
{
public:
static const QEvent::Type eventType;
MenuNodeItemChangeEvent(MenuNode* node, int position, int removed, int added);
MenuNode* node;
int position;
int removed;
int added;
};
#endif //QMENUMODELEVENTS_H
./libqmenumodel/src/qmenumodelevents.cpp 0000644 0000156 0000165 00000005262 12676475617 020652 0 ustar jenkins jenkins /*
* 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:
* Nicholas Dedekind
#include
}
#include "qmenumodelevents.h"
const QEvent::Type MenuNodeItemChangeEvent::eventType = static_cast(QEvent::registerEventType());
const QEvent::Type DBusActionStateEvent::eventType = static_cast(QEvent::registerEventType());
const QEvent::Type DBusActionVisiblityEvent::eventType = static_cast(QEvent::registerEventType());
const QEvent::Type MenuModelEvent::eventType = static_cast(QEvent::registerEventType());
const QEvent::Type DbusObjectServiceEvent::eventType = static_cast(QEvent::registerEventType());
MenuNodeItemChangeEvent::MenuNodeItemChangeEvent(MenuNode* _node, int _position, int _removed, int _added)
: QEvent(MenuNodeItemChangeEvent::eventType),
node(_node),
position(_position),
removed(_removed),
added(_added)
{}
DBusActionEvent::DBusActionEvent(const QString& _name, QEvent::Type type)
: QEvent(type),
name(_name)
{
}
DBusActionVisiblityEvent::DBusActionVisiblityEvent(const QString& _name, bool _visible)
: DBusActionEvent(_name, DBusActionVisiblityEvent::eventType),
visible(_visible)
{
}
DBusActionStateEvent::DBusActionStateEvent(const QString& _name, const QVariant& _state)
: DBusActionEvent(_name, DBusActionStateEvent::eventType),
state(_state)
{
}
DbusObjectServiceEvent::DbusObjectServiceEvent(GDBusConnection* _connection, bool _visible)
: QEvent(DbusObjectServiceEvent::eventType),
connection(_connection),
visible(_visible)
{
if (connection) {
g_object_ref(connection);
}
}
DbusObjectServiceEvent::~DbusObjectServiceEvent()
{
if (connection) {
g_object_unref(connection);
}
}
MenuModelEvent::MenuModelEvent(GMenuModel* _model)
: QEvent(MenuModelEvent::eventType),
model(_model)
{
if (model) {
g_object_ref(model);
}
}
MenuModelEvent::~MenuModelEvent()
{
if (model) {
g_object_unref(model);
}
}
./libqmenumodel/src/qdbusobject.cpp 0000644 0000156 0000165 00000013062 12676475617 017561 0 ustar jenkins jenkins /*
* Copyright 2012 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:
* Renato Araujo Oliveira Filho
*/
extern "C" {
#include
#include
}
#include "qdbusobject.h"
#include "qmenumodelevents.h"
#include
#include
/*!
\qmltype QDBusObject
\brief The QDBusObject is a base class
\b {This component is under heavy development.}
This is a abstracted class used by QDBusMenuModel and QDBusActionGroup
*/
/*!
\qmlproperty int QDBusObject::busType
This property holds the dbus session type which will be used during the connection.
This must be seteed before call start method
The valid values are:
\list
\li 1 - SessionBus
\li 2 - SystemBus
\endlist
*/
/*!
\qmlproperty int QDBusObject::busName
This property holds the dbus service name related with menu.
This must be seteed before call start method
*/
/*!
\qmlproperty int QDBusObject::objectPath
This property holds the dbus object path related with the menu.
This must be seteed before call start method
*/
/*!
\qmlproperty int QDBusObject::status
This property holds current dbus connection status
Te velid status are:
\list
\li 0 - Disconnected
\li 1 - Connecting
\li 2 - Connected
\endlist
*/
QDBusObject::QDBusObject(QObject* listener)
:m_listener(listener),
m_watchId(0),
m_busType(DBusEnums::None),
m_status(DBusEnums::Disconnected)
{
g_type_init();
qRegisterMetaType("DBusEnums::ConnectionStatus");
}
QDBusObject::~QDBusObject()
{
if (m_watchId != 0) {
g_bus_unwatch_name (m_watchId);
m_watchId = 0;
}
}
DBusEnums::BusType QDBusObject::busType() const
{
return m_busType;
}
void QDBusObject::setBusType(DBusEnums::BusType type)
{
if (m_busType != type) {
if (m_status != DBusEnums::Disconnected)
disconnect();
m_busType = type;
Q_EMIT busTypeChanged(m_busType);
}
}
QString QDBusObject::busName() const
{
return m_busName;
}
void QDBusObject::setBusName(const QString &busName)
{
if (m_busName != busName) {
if (m_status != DBusEnums::Disconnected)
disconnect();
m_busName = busName;
Q_EMIT busNameChanged(m_busName);
}
}
QString QDBusObject::objectPath() const
{
return m_objectPath;
}
void QDBusObject::setObjectPath(const QString &objectPath)
{
if (m_objectPath != objectPath) {
if (m_status != DBusEnums::Disconnected)
disconnect();
m_objectPath = objectPath;
Q_EMIT objectPathChanged(m_objectPath);
}
}
void QDBusObject::setStatus(DBusEnums::ConnectionStatus status)
{
if (m_status != status) {
m_status = status;
Q_EMIT statusChanged(m_status);
}
}
DBusEnums::ConnectionStatus QDBusObject::status() const
{
return m_status;
}
void QDBusObject::connect()
{
if (m_status != DBusEnums::Disconnected) {
return;
} else if ((m_busType > DBusEnums::None) && !m_objectPath.isEmpty() && !m_busName.isEmpty()) {
GBusType type = m_busType == DBusEnums::SessionBus ? G_BUS_TYPE_SESSION : G_BUS_TYPE_SYSTEM;
m_watchId = g_bus_watch_name (type,
m_busName.toUtf8().data(),
G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
QDBusObject::onServiceAppeared,
QDBusObject::onServiceVanished,
this,
NULL);
setStatus(DBusEnums::Connecting);
} else {
qWarning() << "Invalid dbus connection args";
}
}
void QDBusObject::disconnect()
{
if (m_status != DBusEnums::Disconnected) {
g_bus_unwatch_name (m_watchId);
m_watchId = 0;
setStatus(DBusEnums::Disconnected);
}
}
void QDBusObject::onServiceAppeared(GDBusConnection *connection, const gchar *, const gchar *, gpointer data)
{
QDBusObject *self = reinterpret_cast(data);
if (self->m_listener) {
DbusObjectServiceEvent dose(connection, true);
QCoreApplication::sendEvent(self->m_listener, &dose);
}
}
void QDBusObject::onServiceVanished(GDBusConnection *connection, const gchar *, gpointer data)
{
QDBusObject *self = reinterpret_cast(data);
if (self->m_listener) {
DbusObjectServiceEvent dose(connection, false);
QCoreApplication::sendEvent(self->m_listener, &dose);
}
}
bool QDBusObject::event(QEvent* e)
{
if (e->type() == DbusObjectServiceEvent::eventType) {
DbusObjectServiceEvent *dose = static_cast(e);
if (dose->visible) {
serviceAppear(dose->connection);
setStatus(DBusEnums::Connected);
} else {
setStatus(DBusEnums::Connecting);
serviceVanish(dose->connection);
}
return true;
}
return false;
}
./libqmenumodel/src/logging.h 0000644 0000156 0000165 00000001507 12676475633 016346 0 ustar jenkins jenkins /*
* Copyright (C) 2016 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 version 3, as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
* SATISFACTORY QUALITY, 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 .
*/
#ifndef QMENUMODEL_LOGGING_H
#define QMENUMODEL_LOGGING_H
#include
Q_DECLARE_LOGGING_CATEGORY(unitymenumodel)
#endif // QMENUMODEL_LOGGING_H
./libqmenumodel/src/unitymenumodelevents.cpp 0000644 0000156 0000165 00000004114 12676475617 021555 0 ustar jenkins jenkins /*
* 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:
* Nicholas Dedekind
#include
}
#include "unitymenumodelevents.h"
#include "unitymenumodel.h"
const QEvent::Type UnityMenuModelClearEvent::eventType = static_cast(QEvent::registerEventType());
const QEvent::Type UnityMenuModelAddRowEvent::eventType = static_cast(QEvent::registerEventType());
const QEvent::Type UnityMenuModelRemoveRowEvent::eventType = static_cast(QEvent::registerEventType());
const QEvent::Type UnityMenuModelDataChangeEvent::eventType = static_cast(QEvent::registerEventType());
UnityMenuModelClearEvent::UnityMenuModelClearEvent(bool _reset)
: QEvent(UnityMenuModelClearEvent::eventType),
reset(_reset)
{}
UnityMenuModelAddRowEvent::UnityMenuModelAddRowEvent(GtkMenuTrackerItem *_item, int _position)
: QEvent(UnityMenuModelAddRowEvent::eventType),
item(_item),
position(_position)
{
if (item) {
g_object_ref(item);
}
}
UnityMenuModelAddRowEvent::~UnityMenuModelAddRowEvent()
{
if (item) {
g_object_unref(item);
}
}
UnityMenuModelRemoveRowEvent::UnityMenuModelRemoveRowEvent(int _position)
: QEvent(UnityMenuModelRemoveRowEvent::eventType),
position(_position)
{}
UnityMenuModelDataChangeEvent::UnityMenuModelDataChangeEvent(int _position)
: QEvent(UnityMenuModelDataChangeEvent::eventType),
position(_position)
{}
./libqmenumodel/src/qdbusobject.h 0000644 0000156 0000165 00000004533 12676475617 017231 0 ustar jenkins jenkins /*
* Copyright 2012 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:
* Renato Araujo Oliveira Filho
*/
#ifndef QDBUSOBJECT_H
#define QDBUSOBJECT_H
#include
#include "dbus-enums.h"
typedef unsigned int guint;
typedef char gchar;
typedef void* gpointer;
typedef struct _GDBusConnection GDBusConnection;
class QDBusObject
{
public:
QDBusObject(QObject* listener);
~QDBusObject();
DBusEnums::BusType busType() const;
void setBusType(DBusEnums::BusType type);
QString busName() const;
void setBusName(const QString &busName);
QString objectPath() const;
void setObjectPath(const QString &busName);
DBusEnums::ConnectionStatus status() const;
void connect();
void disconnect();
protected:
virtual void serviceAppear(GDBusConnection *connection) = 0;
virtual void serviceVanish(GDBusConnection *connection) = 0;
// notify functions
virtual void busTypeChanged(DBusEnums::BusType type) = 0;
virtual void busNameChanged(const QString &busNameChanged) = 0;
virtual void objectPathChanged(const QString &objectPath) = 0;
virtual void statusChanged(DBusEnums::ConnectionStatus status) = 0;
// This is not a Qbject, but we are passed events from superclass qobjects.
virtual bool event(QEvent* e);
private:
QObject* m_listener;
guint m_watchId;
DBusEnums::BusType m_busType;
QString m_busName;
QString m_objectPath;
DBusEnums::ConnectionStatus m_status;
void setStatus(DBusEnums::ConnectionStatus status);
// glib slots
static void onServiceAppeared(GDBusConnection *connection, const gchar *name, const gchar *name_owner, gpointer data);
static void onServiceVanished(GDBusConnection *connection, const gchar *name, gpointer data);
};
#endif
./libqmenumodel/src/actionstateparser.h 0000644 0000156 0000165 00000002026 12676475617 020452 0 ustar jenkins jenkins /*
* 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:
* Nick Dedekind
*/
#ifndef ACTIONSTATEPARSER_H
#define ACTIONSTATEPARSER_H
#include
#include
typedef struct _GVariant GVariant;
class ActionStateParser : public QObject
{
Q_OBJECT
public:
ActionStateParser(QObject* parent = 0);
virtual QVariant toQVariant(GVariant* state) const;
};
#endif // ACTIONSTATEPARSER_H
./libqmenumodel/src/unitymenuactionevents.cpp 0000644 0000156 0000165 00000003516 12676475617 021737 0 ustar jenkins jenkins /*
* 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:
* Nicholas Dedekind (QEvent::registerEventType());
const QEvent::Type UnityMenuActionRemoveEvent::eventType = static_cast(QEvent::registerEventType());
const QEvent::Type UnityMenuActionEnabledChangedEvent::eventType = static_cast(QEvent::registerEventType());
const QEvent::Type UnityMenuActionStateChangeEvent::eventType = static_cast(QEvent::registerEventType());
UnityMenuActionAddEvent::UnityMenuActionAddEvent(bool _enabled, const QVariant& _state)
: QEvent(UnityMenuActionAddEvent::eventType),
enabled(_enabled),
state(_state)
{}
UnityMenuActionRemoveEvent::UnityMenuActionRemoveEvent()
: QEvent(UnityMenuActionRemoveEvent::eventType)
{
}
UnityMenuActionEnabledChangedEvent::UnityMenuActionEnabledChangedEvent(bool _enabled)
: QEvent(UnityMenuActionEnabledChangedEvent::eventType),
enabled(_enabled)
{}
UnityMenuActionStateChangeEvent::UnityMenuActionStateChangeEvent(const QVariant& _state)
: QEvent(UnityMenuActionStateChangeEvent::eventType),
state(_state)
{}
./libqmenumodel/src/qstateaction.cpp 0000644 0000156 0000165 00000007761 12676475617 017764 0 ustar jenkins jenkins /*
* Copyright 2012 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:
* Renato Araujo Oliveira Filho
*/
#include "qstateaction.h"
#include "qdbusactiongroup.h"
/*!
\qmltype QStateAction
\inherits QAction
\brief A QStateAction implementation to be used with \l QDBusActionGroup
\b {This component is under heavy development.}
This class can be used as a proxy for an action that is exported over D-Bus
\code
QDBusActionGroup {
id: actionGroup
busType: 1
busName: "com.ubuntu.menu"
objectPath: "com/ubuntu/menu/actions"
}
Button {
visible: actionGroup.getAction("button.bvisible").status
}
\endcode
*/
/*! \internal */
QStateAction::QStateAction(QDBusActionGroup *group, const QString &name)
: QObject(group),
m_group(group),
m_name(name)
{
// This keep the code clean
// But maybe we need move the action state control to QActionGroup to optimizations
QObject::connect(m_group, SIGNAL(actionAppear(QString)),
this, SLOT(onActionAppear(QString)));
QObject::connect(m_group, SIGNAL(actionVanish(QString)),
this, SLOT(onActionVanish(QString)));
QObject::connect(m_group, SIGNAL(actionStateChanged(QString,QVariant)),
this, SLOT(onActionStateChanged(QString,QVariant)));
m_valid = m_group->hasAction(name);
if (m_valid) {
setState(m_group->actionState(name));
}
}
/*!
\qmlproperty int QStateAction::state
This property holds the current action state
*/
QVariant QStateAction::state() const
{
return m_state;
}
/*!
\qmlproperty int QStateAction::isValid
This property return if the current Action is valid or not
A valid Action is a action which has a DBus action linked
*/
bool QStateAction::isValid() const
{
return m_valid;
}
/*!
Request for the state of action to be changed to \a paramenter.
This call merely requests a change. The action may refuse to change its state or may change its state to something other than \a paramenter.
*/
void QStateAction::updateState(const QVariant &state)
{
QVariant v = state;
if (v.convert(m_state.type()))
m_group->updateActionState(m_name, v);
}
/*!
Activates the action passing \a parameter.
\a parameter must be the correct type of parameter for the action
*/
void QStateAction::activate(const QVariant ¶meter)
{
m_group->activateAction(m_name, parameter);
}
/*! \internal */
QString QStateAction::name() const
{
return m_name;
}
/*! \internal */
void QStateAction::setValid(bool valid)
{
if (m_valid != valid) {
m_valid = valid;
Q_EMIT validChanged(m_valid);
}
}
/*! \internal */
void QStateAction::setState(const QVariant &state)
{
QVariant v = state;
if (!m_state.isValid() || (v.convert(m_state.type()) && v != m_state)) {
m_state = v;
Q_EMIT stateChanged(m_state);
}
}
/*! \internal */
void QStateAction::onActionAppear(const QString &name)
{
if (m_name == name) {
setState(m_group->actionState(name));
setValid(true);
}
}
/*! \internal */
void QStateAction::onActionVanish(const QString &name)
{
if (m_name == name) {
setState(QVariant());
setValid(false);
}
}
/*! \internal */
void QStateAction::onActionStateChanged(const QString &name, const QVariant &state)
{
if (m_name == name) {
setState(state);
}
}
./libqmenumodel/src/gtk/ 0000755 0000156 0000165 00000000000 12676475617 015333 5 ustar jenkins jenkins ./libqmenumodel/src/gtk/gtkmenutrackeritem.h 0000644 0000156 0000165 00000012320 12676475617 021407 0 ustar jenkins jenkins /*
* Copyright © 2011, 2013 Canonical Limited
*
* This library 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; either
* version 2 of the licence, or (at your option) any later version.
*
* This library 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 library. If not, see .
*
* Author: Ryan Lortie
*/
#ifndef __GTK_MENU_TRACKER_ITEM_H__
#define __GTK_MENU_TRACKER_ITEM_H__
#include "gtkactionobservable.h"
#define GTK_TYPE_MENU_TRACKER_ITEM (gtk_menu_tracker_item_get_type ())
#define GTK_MENU_TRACKER_ITEM(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), \
GTK_TYPE_MENU_TRACKER_ITEM, GtkMenuTrackerItem))
#define GTK_IS_MENU_TRACKER_ITEM(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), \
GTK_TYPE_MENU_TRACKER_ITEM))
typedef struct _GtkMenuTrackerItem GtkMenuTrackerItem;
#define GTK_TYPE_MENU_TRACKER_ITEM_ROLE (gtk_menu_tracker_item_role_get_type ())
typedef enum {
GTK_MENU_TRACKER_ITEM_ROLE_NORMAL,
GTK_MENU_TRACKER_ITEM_ROLE_CHECK,
GTK_MENU_TRACKER_ITEM_ROLE_RADIO,
} GtkMenuTrackerItemRole;
GType gtk_menu_tracker_item_get_type (void) G_GNUC_CONST;
GType gtk_menu_tracker_item_role_get_type (void) G_GNUC_CONST;
GtkMenuTrackerItem * _gtk_menu_tracker_item_new (GtkActionObservable *observable,
GMenuModel *model,
gint item_index,
const gchar *action_namespace,
gboolean is_separator);
GtkActionObservable * _gtk_menu_tracker_item_get_observable (GtkMenuTrackerItem *self);
gboolean gtk_menu_tracker_item_get_is_separator (GtkMenuTrackerItem *self);
gboolean gtk_menu_tracker_item_get_has_submenu (GtkMenuTrackerItem *self);
const gchar * gtk_menu_tracker_item_get_label (GtkMenuTrackerItem *self);
GIcon * gtk_menu_tracker_item_get_icon (GtkMenuTrackerItem *self);
gboolean gtk_menu_tracker_item_get_sensitive (GtkMenuTrackerItem *self);
gboolean gtk_menu_tracker_item_get_visible (GtkMenuTrackerItem *self);
GtkMenuTrackerItemRole gtk_menu_tracker_item_get_role (GtkMenuTrackerItem *self);
gboolean gtk_menu_tracker_item_get_toggled (GtkMenuTrackerItem *self);
const gchar * gtk_menu_tracker_item_get_accel (GtkMenuTrackerItem *self);
GMenuModel * _gtk_menu_tracker_item_get_submenu (GtkMenuTrackerItem *self);
gchar * _gtk_menu_tracker_item_get_submenu_namespace (GtkMenuTrackerItem *self);
gboolean gtk_menu_tracker_item_get_should_request_show (GtkMenuTrackerItem *self);
void gtk_menu_tracker_item_activated (GtkMenuTrackerItem *self);
void gtk_menu_tracker_item_change_state (GtkMenuTrackerItem *self,
GVariant *value);
void gtk_menu_tracker_item_request_submenu_shown (GtkMenuTrackerItem *self,
gboolean shown);
gboolean gtk_menu_tracker_item_get_submenu_shown (GtkMenuTrackerItem *self);
gchar * gtk_menu_tracker_item_get_action_name (GtkMenuTrackerItem *self);
GVariant * gtk_menu_tracker_item_get_action_state (GtkMenuTrackerItem *self);
const gchar * gtk_menu_tracker_item_get_action_namespace (GtkMenuTrackerItem *self);
gboolean gtk_menu_tracker_item_get_attribute (GtkMenuTrackerItem *self,
const gchar *attribute,
const gchar *format,
...);
GVariant * gtk_menu_tracker_item_get_attribute_value (GtkMenuTrackerItem *self,
const gchar *attribute,
const GVariantType *expected_type);
#endif
./libqmenumodel/src/gtk/gtkmenutracker.h 0000644 0000156 0000165 00000005516 12676475617 020541 0 ustar jenkins jenkins /*
* Copyright © 2013 Canonical Limited
*
* This library 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; either
* version 2 of the licence, or (at your option) any later version.
*
* This library 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 library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Author: Ryan Lortie
*/
#ifndef __GTK_MENU_TRACKER_H__
#define __GTK_MENU_TRACKER_H__
#include "gtkmenutrackeritem.h"
typedef struct _GtkMenuTracker GtkMenuTracker;
typedef void (* GtkMenuTrackerInsertFunc) (GtkMenuTrackerItem *item,
gint position,
gpointer user_data);
typedef void (* GtkMenuTrackerRemoveFunc) (gint position,
gpointer user_data);
GtkMenuTracker * gtk_menu_tracker_new (GtkActionObservable *observer,
GMenuModel *model,
gboolean with_separators,
const gchar *action_namespace,
GtkMenuTrackerInsertFunc insert_func,
GtkMenuTrackerRemoveFunc remove_func,
gpointer user_data);
GtkMenuTracker * gtk_menu_tracker_new_for_item_submenu (GtkMenuTrackerItem *item,
GtkMenuTrackerInsertFunc insert_func,
GtkMenuTrackerRemoveFunc remove_func,
gpointer user_data);
void gtk_menu_tracker_free (GtkMenuTracker *tracker);
#endif /* __GTK_MENU_TRACKER_H__ */
./libqmenumodel/src/gtk/gtksimpleactionobserver.h 0000644 0000156 0000165 00000006641 12676475617 022460 0 ustar jenkins jenkins /*
* Copyright © 2013 Canonical Limited
*
* This library 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; either version 2 of the
* licence or (at your option) any later version.
*
* This library 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 library. If not, see .
*
* Authors: Nick Dedekind