[Ktutorial-commits] SF.net SVN: ktutorial:[229] trunk/ktutorial/ktutorial-library
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2010-04-13 18:49:19
|
Revision: 229 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=229&view=rev Author: danxuliu Date: 2010-04-13 18:49:12 +0000 (Tue, 13 Apr 2010) Log Message: ----------- Add initial version of KTutorial editor support module to be able to introspect a running application that uses KTutorial from KTutorial editor. The purpose is ease the design of tutorials being able to know, for example, the name of the objects accessible by KTutorial in the application. Modified Paths: -------------- trunk/ktutorial/ktutorial-library/src/CMakeLists.txt trunk/ktutorial/ktutorial-library/src/KTutorial.cpp trunk/ktutorial/ktutorial-library/tests/CMakeLists.txt Added Paths: ----------- trunk/ktutorial/ktutorial-library/src/editorsupport/ trunk/ktutorial/ktutorial-library/src/editorsupport/CMakeLists.txt trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.cpp trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.h trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.cpp trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.h trunk/ktutorial/ktutorial-library/src/editorsupport/EventSpy.cpp trunk/ktutorial/ktutorial-library/src/editorsupport/EventSpy.h trunk/ktutorial/ktutorial-library/src/editorsupport/EventSpyAdaptor.cpp trunk/ktutorial/ktutorial-library/src/editorsupport/EventSpyAdaptor.h trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.cpp trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.h trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegisterAdaptor.cpp trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegisterAdaptor.h trunk/ktutorial/ktutorial-library/tests/editorsupport/ trunk/ktutorial/ktutorial-library/tests/editorsupport/CMakeLists.txt trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportAdaptorTest.cpp trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportTest.cpp trunk/ktutorial/ktutorial-library/tests/editorsupport/EventSpyAdaptorTest.cpp trunk/ktutorial/ktutorial-library/tests/editorsupport/EventSpyTest.cpp trunk/ktutorial/ktutorial-library/tests/editorsupport/ObjectRegisterAdaptorTest.cpp trunk/ktutorial/ktutorial-library/tests/editorsupport/ObjectRegisterTest.cpp Modified: trunk/ktutorial/ktutorial-library/src/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-library/src/CMakeLists.txt 2010-04-13 18:06:28 UTC (rev 228) +++ trunk/ktutorial/ktutorial-library/src/CMakeLists.txt 2010-04-13 18:49:12 UTC (rev 229) @@ -7,6 +7,11 @@ add_subdirectory(tutorials) add_subdirectory(view) +if (QT_QTDBUS_FOUND) + add_definitions(-DQT_QTDBUS_FOUND) + add_subdirectory(editorsupport) +endif (QT_QTDBUS_FOUND) + include_directories(${CMAKE_CURRENT_BINARY_DIR} ${KDE4_INCLUDES}) set(ktutorial_LIB_SRCS @@ -29,6 +34,10 @@ target_link_libraries(ktutorial ktutorial_scripting ktutorial_tutorials ktutorial_view) +if (QT_QTDBUS_FOUND) + target_link_libraries(ktutorial ktutorial_editorsupport) +endif (QT_QTDBUS_FOUND) + ####### Install the library ####### install(TARGETS ktutorial DESTINATION ${LIB_INSTALL_DIR}) Modified: trunk/ktutorial/ktutorial-library/src/KTutorial.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/KTutorial.cpp 2010-04-13 18:06:28 UTC (rev 228) +++ trunk/ktutorial/ktutorial-library/src/KTutorial.cpp 2010-04-13 18:49:12 UTC (rev 229) @@ -29,6 +29,10 @@ #include "view/StepWidget.h" #include "view/TutorialManagerDialog.h" +#ifdef QT_QTDBUS_FOUND +#include "editorsupport/EditorSupport.h" +#endif + using scripting::ScriptingModule; using scripting::ScriptManager; using view::StepWidget; @@ -72,6 +76,10 @@ registerTutorial(new UsingKTutorial()); ScriptManager().loadTutorials(mTutorialmanager); + +#ifdef QT_QTDBUS_FOUND + (new editorsupport::EditorSupport(this))->setup(window); +#endif } //private: Added: trunk/ktutorial/ktutorial-library/src/editorsupport/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-library/src/editorsupport/CMakeLists.txt (rev 0) +++ trunk/ktutorial/ktutorial-library/src/editorsupport/CMakeLists.txt 2010-04-13 18:49:12 UTC (rev 229) @@ -0,0 +1,18 @@ +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${KDE4_INCLUDES}) + +set(ktutorial_editorsupport_SRCS + EditorSupport.cpp + EditorSupportAdaptor.cpp + EventSpy.cpp + EventSpyAdaptor.cpp + ObjectRegister.cpp + ObjectRegisterAdaptor.cpp +) + +kde4_add_library(ktutorial_editorsupport ${ktutorial_editorsupport_SRCS}) + +target_link_libraries(ktutorial_editorsupport + ktutorial_extendedinformation + ${QT_QTDBUS_LIBRARY} + ${KDE4_KDECORE_LIBS} +) Property changes on: trunk/ktutorial/ktutorial-library/src/editorsupport/CMakeLists.txt ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.cpp (rev 0) +++ trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.cpp 2010-04-13 18:49:12 UTC (rev 229) @@ -0,0 +1,102 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include <QWidget> +#include <QtDBus/QtDBus> + +#include <KDebug> + +#include "EditorSupport.h" +#include "EditorSupportAdaptor.h" +#include "EventSpy.h" +#include "EventSpyAdaptor.h" +#include "ObjectRegister.h" +#include "ObjectRegisterAdaptor.h" +#include "../extendedinformation/WidgetHighlighterManager.h" + +using extendedinformation::WidgetHighlighterManager; + +namespace editorsupport { + +//public: + +EditorSupport::EditorSupport(QObject* parent /*= 0*/): QObject(parent), + mObjectRegister(0), + mEventSpy(0) { +} + +void EditorSupport::setup(QObject* window) { + if (!QDBusConnection::sessionBus().isConnected()) { + kWarning() << "Cannot connect to the D-Bus session bus!\n" + << "KTutorial editor support will not be enabled"; + return; + } + + mWindow = window; + + new EditorSupportAdaptor(this); + QDBusConnection::sessionBus().registerObject("/ktutorial", this); + + mObjectRegister = new ObjectRegister(this); + new ObjectRegisterAdaptor(mObjectRegister); + + QDBusConnection::sessionBus().registerObject("/ktutorial/ObjectRegister", + mObjectRegister); +} + +int EditorSupport::mainWindowObjectId() { + return mObjectRegister->idForObject(mWindow); +} + +void EditorSupport::highlight(int objectId) { + QObject* object = mObjectRegister->objectForId(objectId); + QWidget* widget = qobject_cast<QWidget*>(object); + if (!widget) { + return; + } + + WidgetHighlighterManager::self()->highlight(widget); +} + +void EditorSupport::stopHighlighting(int objectId) { + QObject* object = mObjectRegister->objectForId(objectId); + QWidget* widget = qobject_cast<QWidget*>(object); + if (!widget) { + return; + } + + WidgetHighlighterManager::self()->stopHighlighting(widget); +} + +void EditorSupport::enableEventSpy() { + mEventSpy = new EventSpy(this); + mEventSpy->addObjectToSpy(mWindow); + new EventSpyAdaptor(mEventSpy, mObjectRegister); + + QDBusConnection::sessionBus().registerObject("/ktutorial/EventSpy", + mEventSpy); +} + +void EditorSupport::disableEventSpy() { + QDBusConnection::sessionBus().unregisterObject("/ktutorial/EventSpy"); + + delete mEventSpy; + mEventSpy = 0; +} + +} Property changes on: trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.h (rev 0) +++ trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.h 2010-04-13 18:49:12 UTC (rev 229) @@ -0,0 +1,137 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#ifndef EDITORSUPPORT_EDITORSUPPORT_H +#define EDITORSUPPORT_EDITORSUPPORT_H + +#include <QObject> + +namespace editorsupport { +class EventSpy; +class EventSupportAdaptor; +class ObjectRegister; +} + +namespace editorsupport { + +/** + * Support module for KTutorial editor to be accessed through D-Bus. + * EditorSupport provides a way to introspect a running application from + * KTutorial editor to help the author to design a tutorial. + * + * EditorSupport is composed by three elements: the main object (this class), + * an object register and an event spy. + * + * The main object sets up the D-Bus objects and provides a way to enable and + * disable the EventSpy (as notifying all the events sent by an application + * through D-Bus is very costly, the EventSpy should be enabled only when + * needed), and highlight and stop the highlighting of widgets. + * + * The object register assigns an id to QObjects to be identified by the remote + * KTutorial editor. Using that id, KTutorial editor can request further + * information about an object to the ObjectRegister (for example, the object + * name or the class name of an object). + * + * The event spy filters all the events received by the main window and, + * recursively, all its children objects. It is used in the remote KTutorial + * editor to know, for example, that some widget got the focus, or that the + * mouse entered in some widget. Using the information provided by the EventSpy, + * the KTutorial editor can provide a way to the tutorial author to select + * widgets directly from a running application just with the mouse. + * + * The main object is registered at "/ktutorial" path, and provides the + * "org.kde.ktutorial.EditorSupport" interface. The object register is + * registered at "/ktutorial/ObjectRegister" path and provides the + * "org.kde.ktutorial.ObjectRegister" interface. Finally, when it is enabled, + * the EventSpy is registered at "/ktutorial/EVentSpy" path and provides the + * "org.kde.ktutorial.EventSpy" interface. + */ +class EditorSupport: public QObject { +Q_OBJECT +public: + + /** + * Creates a new EditorSupport with the given parent. + * + * @param parent The parent QObject. + */ + explicit EditorSupport(QObject* parent = 0); + + /** + * Exposes the editor support interfaces through DBus. + * The window and all its children will be spied when EventSpy is enabled. + * + * @param window The main window in the application. + */ + void setup(QObject* window); + + /** + * Returns the object id of the application main window. + * + * @return The object id of the application main window. + */ + int mainWindowObjectId(); + + /** + * Starts the highlighting animation for the widget associated to the given + * id. + * + * @param objectId The id of the widget to highlight. + */ + void highlight(int objectId); + + /** + * Stops the highlighting animation for the widget associated to the given + * id. + * + * @param objectId The id of the widget to stop highlighting. + */ + void stopHighlighting(int objectId); + + /** + * Enables the EventSpy. + */ + void enableEventSpy(); + + /** + * Disables the EventSpy. + */ + void disableEventSpy(); + +private: + + /** + * The object register. + */ + ObjectRegister* mObjectRegister; + + /** + * The event spy. + */ + EventSpy* mEventSpy; + + /** + * The object to spy its events and the events of its children. + */ + QObject* mWindow; + +}; + +} + +#endif Property changes on: trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupport.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.cpp (rev 0) +++ trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.cpp 2010-04-13 18:49:12 UTC (rev 229) @@ -0,0 +1,60 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include <QCoreApplication> + +#include "EditorSupportAdaptor.h" +#include "EditorSupport.h" +#include "ObjectRegister.h" + +namespace editorsupport { + +//public: + +EditorSupportAdaptor::EditorSupportAdaptor(EditorSupport* editorSupport): + QDBusAbstractAdaptor(editorSupport), + mEditorSupport(editorSupport) { +} + +//public slots: + +QString EditorSupportAdaptor::applicationFilePath() const { + return QCoreApplication::applicationFilePath(); +} + +int EditorSupportAdaptor::mainWindowObjectId() const { + return mEditorSupport->mainWindowObjectId(); +} + +void EditorSupportAdaptor::highlight(int objectId) { + mEditorSupport->highlight(objectId); +} + +void EditorSupportAdaptor::stopHighlighting(int objectId) { + mEditorSupport->stopHighlighting(objectId); +} + +void EditorSupportAdaptor::enableEventSpy() { + mEditorSupport->enableEventSpy(); +} + +void EditorSupportAdaptor::disableEventSpy() { + mEditorSupport->disableEventSpy(); +} + +} Property changes on: trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.h (rev 0) +++ trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.h 2010-04-13 18:49:12 UTC (rev 229) @@ -0,0 +1,101 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#ifndef EDITORSUPPORT_EDITORSUPPORTADAPTOR_H +#define EDITORSUPPORT_EDITORSUPPORTADAPTOR_H + +#include <QDBusAbstractAdaptor> + +namespace editorsupport { +class EditorSupport; +class ObjectRegister; +} + +namespace editorsupport { + +/** + * Adaptor to expose an EditorSupport through DBus. + * + * @see EditorSupport + */ +class EditorSupportAdaptor: public QDBusAbstractAdaptor { +Q_OBJECT +Q_CLASSINFO("D-Bus Interface", "org.kde.ktutorial.EditorSupport") +public: + + /** + * Creates a new EditorSupportAdaptor for the given EditorSupport. + * + * @param editorSupport The EditorSupport to adapt. + */ + explicit EditorSupportAdaptor(EditorSupport* editorSupport); + +public Q_SLOTS: + + /** + * Returns the path to the application file. + * + * @return The path to the application file. + */ + QString applicationFilePath() const; + + /** + * Returns the object id of the application main window. + * + * @return The object id of the application main window. + */ + int mainWindowObjectId() const; + + /** + * Starts the highlighting animation for the widget associated to the given + * id. + * + * @param objectId The id of the widget to highlight. + */ + void highlight(int objectId); + + /** + * Stops the highlighting animation for the widget associated to the given + * id. + * + * @param objectId The id of the widget to stop highlighting. + */ + void stopHighlighting(int objectId); + + /** + * Enables the EventSpy. + */ + void enableEventSpy(); + + /** + * Disables the EventSpy. + */ + void disableEventSpy(); + +private: + + /** + * The EditorSupport to adapt. + */ + EditorSupport* mEditorSupport; + +}; + +} + +#endif Property changes on: trunk/ktutorial/ktutorial-library/src/editorsupport/EditorSupportAdaptor.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-library/src/editorsupport/EventSpy.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/editorsupport/EventSpy.cpp (rev 0) +++ trunk/ktutorial/ktutorial-library/src/editorsupport/EventSpy.cpp 2010-04-13 18:49:12 UTC (rev 229) @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include <QEvent> + +#include "EventSpy.h" + +namespace editorsupport { + +//public: + +EventSpy::EventSpy(QObject* parent /*= 0*/): QObject(parent) { +} + +void EventSpy::addObjectToSpy(QObject* object) { + object->installEventFilter(this); + + foreach (QObject* child, object->children()) { + addObjectToSpy(child); + } +} + +//protected: + +bool EventSpy::eventFilter(QObject* object, QEvent* event) { + emit eventReceived(object, event); + + if (event->type() == QEvent::ChildAdded) { + addObjectToSpy(static_cast<QChildEvent*>(event)->child()); + } + + return false; +} + +} Property changes on: trunk/ktutorial/ktutorial-library/src/editorsupport/EventSpy.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-library/src/editorsupport/EventSpy.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/editorsupport/EventSpy.h (rev 0) +++ trunk/ktutorial/ktutorial-library/src/editorsupport/EventSpy.h 2010-04-13 18:49:12 UTC (rev 229) @@ -0,0 +1,77 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#ifndef EDITORSUPPORT_EVENTSPY_H +#define EDITORSUPPORT_EVENTSPY_H + +#include <QObject> + +namespace editorsupport { + +/** + * Spy to know all the events received in an object hierarchy. + * EventSpy emitts a signal whenever an event is received in any of the spied + * objects or its children (recursively). Even children added to a spied object + * after it was added are spied. + */ +class EventSpy: public QObject { +Q_OBJECT +public: + + /** + * Creates a new EventSpy with the given parent. + * + * @param parent The parent QObject. + */ + explicit EventSpy(QObject* parent = 0); + + /** + * Add object and all its children to spy. + * + * @param object The object to spy. + */ + void addObjectToSpy(QObject* object); + +Q_SIGNALS: + + /** + * Emitted when an event is received in any of the spied objects or their + * children. + * + * @param object The object that received the event. + * @param event The event received. + */ + void eventReceived(QObject* object, QEvent* event); + +protected: + + /** + * Filters the events received in the spied object hierarchies. + * A eventReceived(QObject*, QEvent*) is emitted for each event. + * + * @param object The object that received the event. + * @param event The event received. + * @return False, the let events be handled as necessary. + */ + virtual bool eventFilter(QObject* object, QEvent* event); + +}; + +} + +#endif Property changes on: trunk/ktutorial/ktutorial-library/src/editorsupport/EventSpy.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-library/src/editorsupport/EventSpyAdaptor.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/editorsupport/EventSpyAdaptor.cpp (rev 0) +++ trunk/ktutorial/ktutorial-library/src/editorsupport/EventSpyAdaptor.cpp 2010-04-13 18:49:12 UTC (rev 229) @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include <QEvent> +#include <QMetaEnum> + +#include "EventSpyAdaptor.h" +#include "EventSpy.h" +#include "ObjectRegister.h" + +namespace editorsupport { + +//public: + +EventSpyAdaptor::EventSpyAdaptor(EventSpy* eventSpy, + ObjectRegister* objectRegister): + QDBusAbstractAdaptor(eventSpy), + mObjectRegister(objectRegister) { + connect(eventSpy, SIGNAL(eventReceived(QObject*,QEvent*)), + this, SLOT(handleEventReceived(QObject*,QEvent*))); +} + +//private: + +void EventSpyAdaptor::handleEventReceived(QObject* object, QEvent* event) { + int id = mObjectRegister->idForObject(object); + + int index = QEvent::staticMetaObject.indexOfEnumerator("Type"); + QMetaEnum eventTypeEnumerator = QEvent::staticMetaObject.enumerator(index); + QString eventType = eventTypeEnumerator.valueToKey(event->type()); + + emit eventReceived(id, eventType); +} + +} Property changes on: trunk/ktutorial/ktutorial-library/src/editorsupport/EventSpyAdaptor.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-library/src/editorsupport/EventSpyAdaptor.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/editorsupport/EventSpyAdaptor.h (rev 0) +++ trunk/ktutorial/ktutorial-library/src/editorsupport/EventSpyAdaptor.h 2010-04-13 18:49:12 UTC (rev 229) @@ -0,0 +1,83 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#ifndef EDITORSUPPORT_EVENTSPYADAPTOR_H +#define EDITORSUPPORT_EVENTSPYADAPTOR_H + +#include <QDBusAbstractAdaptor> + +namespace editorsupport { +class EventSpy; +class ObjectRegister; +} + +namespace editorsupport { + +/** + * Adaptor to expose an EventSpy through DBus. + * + * @see EditorSupport + */ +class EventSpyAdaptor: public QDBusAbstractAdaptor { +Q_OBJECT +Q_CLASSINFO("D-Bus Interface", "org.kde.ktutorial.EventSpy") +public: + + /** + * Creates a new EventSpyAdaptor for the given EventSpy. + * + * @param eventSpy The EventSpy to adapt. + * @param objectRegister The object register to get the object ids from. + */ + explicit EventSpyAdaptor(EventSpy* eventSpy, + ObjectRegister* objectRegister); + +Q_SIGNALS: + + /** + * Emitted when an event is received in any of the spied objects or their + * children. + * + * @param objectId The id of the object that received the event. + * @param eventType The type of the event received. + */ + void eventReceived(int objectId, const QString& eventType); + +private: + + /** + * The register to associate objects with their id. + */ + ObjectRegister* mObjectRegister; + +private Q_SLOTS: + + /** + * Adapts the eventReceived(QObject*, QEvent*) sent by the EventSpy to be + * sent as eventReceived(int, QString). + * + * @param object The object that received the event. + * @param event The event received. + */ + void handleEventReceived(QObject* object, QEvent* event); + +}; + +} + +#endif Property changes on: trunk/ktutorial/ktutorial-library/src/editorsupport/EventSpyAdaptor.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.cpp (rev 0) +++ trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.cpp 2010-04-13 18:49:12 UTC (rev 229) @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include "ObjectRegister.h" + +namespace editorsupport { + +//public: + +ObjectRegister::ObjectRegister(QObject* parent /*= 0*/): QObject(parent), + mNextId(1) { +} + +int ObjectRegister::idForObject(QObject* object) { + int id = mRegisteredIds.value(object); + + if (!id) { + id = mNextId; + mRegisteredObjects.insert(id, object); + mRegisteredIds.insert(object, id); + connect(object, SIGNAL(destroyed(QObject*)), + this, SLOT(deregister(QObject*))); + mNextId++; + } + + return id; +} + +QObject* ObjectRegister::objectForId(int objectId) { + return mRegisteredObjects.value(objectId); +} + +void ObjectRegister::clear() { + mRegisteredIds.clear(); + mRegisteredObjects.clear(); +} + +//private slots: + +void ObjectRegister::deregister(QObject* object) { + int id = mRegisteredIds.value(object); + mRegisteredIds.remove(object); + mRegisteredObjects.remove(id); +} + +} Property changes on: trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.h (rev 0) +++ trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.h 2010-04-13 18:49:12 UTC (rev 229) @@ -0,0 +1,99 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#ifndef EDITORSUPPORT_OBJECTREGISTER_H +#define EDITORSUPPORT_OBJECTREGISTER_H + +#include <QHash> +#include <QObject> + +namespace editorsupport { + +/** + * Register to associate objects with an id. + * The id for an object is assigned after the first time the id is requested + * for that object, and are valid until the register is cleared or the object is + * destroyed (if an object is destroyed it is automatically removed from the + * register). + * + * Its purpose is assign QObjects an id to allow the remote KTutorial editor to + * refer to the objects in the target application. + */ +class ObjectRegister: public QObject { +Q_OBJECT +public: + + /** + * Creates a new ObjectRegister with the given parent. + * + * @param parent The parent QObject. + */ + explicit ObjectRegister(QObject* parent = 0); + + /** + * Returns the id assigned to the object. + * + * @param object The object to get its id. + * @return The id assigned to the object. + */ + int idForObject(QObject* object); + + /** + * Returns object associated to the id. + * + * @param objectId The id to get its associated object. + * @return The object associated to the id. + */ + QObject* objectForId(int objectId); + + /** + * Removes all the entries in this ObjectRegister. + */ + void clear(); + +private: + + /** + * The next id to assign. + */ + int mNextId; + + /** + * The registered ids mapped by associated object. + */ + QHash<QObject*, int> mRegisteredIds; + + /** + * The registered objects mapped by id. + */ + QHash<int, QObject*> mRegisteredObjects; + +private Q_SLOTS: + + /** + * Deregisters an object automatically when it is destroyed. + * + * @param object The object to deregister. + */ + void deregister(QObject* object); + +}; + +} + +#endif Property changes on: trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegister.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegisterAdaptor.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegisterAdaptor.cpp (rev 0) +++ trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegisterAdaptor.cpp 2010-04-13 18:49:12 UTC (rev 229) @@ -0,0 +1,69 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include "ObjectRegisterAdaptor.h" +#include "ObjectRegister.h" + +namespace editorsupport { + +//public: + +ObjectRegisterAdaptor::ObjectRegisterAdaptor(ObjectRegister* objectRegister): + QDBusAbstractAdaptor(objectRegister), + mObjectRegister(objectRegister) { +} + +//public slots: + +QString ObjectRegisterAdaptor::objectName(int objectId) const { + QObject* object = mObjectRegister->objectForId(objectId); + if (!object) { + return ""; + } + + return object->objectName(); +} + +QString ObjectRegisterAdaptor::className(int objectId) const { + QObject* object = mObjectRegister->objectForId(objectId); + if (!object) { + return ""; + } + + return object->metaObject()->className(); +} + +QList<int> ObjectRegisterAdaptor::childObjectIds(int objectId) const { + QObject* object = mObjectRegister->objectForId(objectId); + if (!object) { + return QList<int>(); + } + + QList<int> ids; + foreach (QObject* childObject, object->children()) { + ids.append(mObjectRegister->idForObject(childObject)); + } + + return ids; +} + +void ObjectRegisterAdaptor::clear() { + mObjectRegister->clear(); +} + +} Property changes on: trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegisterAdaptor.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegisterAdaptor.h =================================================================== --- trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegisterAdaptor.h (rev 0) +++ trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegisterAdaptor.h 2010-04-13 18:49:12 UTC (rev 229) @@ -0,0 +1,93 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#ifndef EDITORSUPPORT_OBJECTREGISTERADAPTOR_H +#define EDITORSUPPORT_OBJECTREGISTERADAPTOR_H + +#include <QDBusAbstractAdaptor> + +namespace editorsupport { +class ObjectRegister; +} + +namespace editorsupport { + +/** + * Adaptor to expose an ObjectRegister through DBus. + * + * @see EditorSupport + */ +class ObjectRegisterAdaptor: public QDBusAbstractAdaptor { +Q_OBJECT +Q_CLASSINFO("D-Bus Interface", "org.kde.ktutorial.ObjectRegister") +public: + + /** + * Creates a new ObjectRegisterAdaptor for the given ObjectRegister. + * + * @param objectRegister The ObjectRegister to adapt. + */ + explicit ObjectRegisterAdaptor(ObjectRegister* objectRegister); + +public Q_SLOTS: + + /** + * Returns the name of the object with the given id. + * If the id is not registered, an empty string is returned. + * + * @param objectId The id of the object. + * @return The name of the object. + */ + QString objectName(int objectId) const; + + /** + * Returns the class name of the object with the given id. + * If the id is not registered, an empty string is returned. + * + * @param objectId The id of the object. + * @return The class name of the object. + */ + QString className(int objectId) const; + + /** + * Returns a list with the ids of the child objects of the object with the + * given id. + * If the id is not registered, an empty list is returned. + * + * @param objectId The id of the object. + * @return The ids of the child objects. + */ + QList<int> childObjectIds(int objectId) const; + + /** + * Removes all the entries in the ObjectRegister. + */ + void clear(); + +private: + + /** + * The ObjectRegister to adapt. + */ + ObjectRegister* mObjectRegister; + +}; + +} + +#endif Property changes on: trunk/ktutorial/ktutorial-library/src/editorsupport/ObjectRegisterAdaptor.h ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/ktutorial/ktutorial-library/tests/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-library/tests/CMakeLists.txt 2010-04-13 18:06:28 UTC (rev 228) +++ trunk/ktutorial/ktutorial-library/tests/CMakeLists.txt 2010-04-13 18:49:12 UTC (rev 229) @@ -2,6 +2,10 @@ add_subdirectory(scripting) add_subdirectory(view) +if (QT_QTDBUS_FOUND) + add_subdirectory(editorsupport) +endif (QT_QTDBUS_FOUND) + # Used by kde4_add_unit_test to set the full path to test executables set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) Added: trunk/ktutorial/ktutorial-library/tests/editorsupport/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-library/tests/editorsupport/CMakeLists.txt (rev 0) +++ trunk/ktutorial/ktutorial-library/tests/editorsupport/CMakeLists.txt 2010-04-13 18:49:12 UTC (rev 229) @@ -0,0 +1,41 @@ +# Used by kde4_add_unit_test to set the full path to test executables +set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) + +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${ktutorial-library_SOURCE_DIR}/src/editorsupport ${KDE4_INCLUDES}) + +# Since Qt 4.6.0, this definition is needed for GUI testing. +# It is backwards compatible with previous Qt versions, unlike the alternative +# which is to add #include <QTestGui> in the test files. +add_definitions(-DQT_GUI_LIB) + +MACRO(UNIT_TESTS) + FOREACH(_className ${ARGN}) + set(_testName ${_className}Test) + kde4_add_unit_test(${_testName} TESTNAME ktutorial-${_testName} ${_testName}.cpp) + target_link_libraries(${_testName} ktutorial_editorsupport ${QT_QTTEST_LIBRARY}) + ENDFOREACH(_className) +ENDMACRO(UNIT_TESTS) + +unit_tests( + EditorSupport + EditorSupportAdaptor + EventSpy + EventSpyAdaptor + ObjectRegister + ObjectRegisterAdaptor +) + +MACRO(MEM_TESTS) + FOREACH(_testname ${ARGN}) + add_test(ktutorial-mem-${_testname} ${CMAKE_CURRENT_SOURCE_DIR}/../runMemcheck.py ${CMAKE_CURRENT_BINARY_DIR}/${_testname}Test ${CMAKE_CURRENT_BINARY_DIR}) + ENDFOREACH(_testname) +ENDMACRO(MEM_TESTS) + +mem_tests( + EditorSupport + EditorSupportAdaptor + EventSpy + EventSpyAdaptor + ObjectRegister + ObjectRegisterAdaptor +) Property changes on: trunk/ktutorial/ktutorial-library/tests/editorsupport/CMakeLists.txt ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportAdaptorTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportAdaptorTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportAdaptorTest.cpp 2010-04-13 18:49:12 UTC (rev 229) @@ -0,0 +1,139 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include <QtTest> + +#include <QWidget> +#include <QtDBus/QtDBus> + +#include "EditorSupportAdaptor.h" + +#include "EditorSupport.h" +#include "EventSpy.h" +#include "ObjectRegister.h" +#include "../extendedinformation/WidgetHighlighter.h" + +using extendedinformation::WidgetHighlighter; + +namespace editorsupport { + +class EditorSupportAdaptorTest: public QObject { +Q_OBJECT + +private slots: + + void testConstructor(); + + void testApplicationFilePath(); + + void testMainWindowObjectId(); + + void testHighlight(); + + void testStopHighlighting(); + + void testEnableEventSpy(); + + void testDisableEventSpy(); + +}; + +void EditorSupportAdaptorTest::testConstructor() { + EditorSupport editorSupport; + EditorSupportAdaptor* adaptor = new EditorSupportAdaptor(&editorSupport); + + QCOMPARE(adaptor->parent(), &editorSupport); +} + +void EditorSupportAdaptorTest::testApplicationFilePath() { + EditorSupport editorSupport; + EditorSupportAdaptor* adaptor = new EditorSupportAdaptor(&editorSupport); + + QCOMPARE(adaptor->applicationFilePath(), + QCoreApplication::applicationFilePath()); +} + +void EditorSupportAdaptorTest::testMainWindowObjectId() { + EditorSupport editorSupport; + QWidget window; + editorSupport.setup(&window); + EditorSupportAdaptor* adaptor = new EditorSupportAdaptor(&editorSupport); + + QCOMPARE(adaptor->mainWindowObjectId(), editorSupport.mainWindowObjectId()); +} + +void EditorSupportAdaptorTest::testHighlight() { + EditorSupport editorSupport; + QWidget window; + editorSupport.setup(&window); + EditorSupportAdaptor* adaptor = new EditorSupportAdaptor(&editorSupport); + + adaptor->highlight(adaptor->mainWindowObjectId()); + + QCOMPARE(window.findChildren<WidgetHighlighter*>().count(), 1); + QVERIFY(window.findChild<WidgetHighlighter*>()); +} + +void EditorSupportAdaptorTest::testStopHighlighting() { + EditorSupport editorSupport; + QWidget window; + editorSupport.setup(&window); + EditorSupportAdaptor* adaptor = new EditorSupportAdaptor(&editorSupport); + + adaptor->highlight(adaptor->mainWindowObjectId()); + adaptor->stopHighlighting(adaptor->mainWindowObjectId()); + + QCOMPARE(window.findChildren<WidgetHighlighter*>().count(), 0); +} + +void EditorSupportAdaptorTest::testEnableEventSpy() { + QDBusConnection bus = QDBusConnection::sessionBus(); + QVERIFY(bus.isConnected()); + + EditorSupport editorSupport; + QWidget window; + editorSupport.setup(&window); + EditorSupportAdaptor* adaptor = new EditorSupportAdaptor(&editorSupport); + + adaptor->enableEventSpy(); + + QObject* spyObject = bus.objectRegisteredAt("/ktutorial/EventSpy"); + QVERIFY(spyObject); + QVERIFY(qobject_cast<EventSpy*>(spyObject)); +} + +void EditorSupportAdaptorTest::testDisableEventSpy() { + QDBusConnection bus = QDBusConnection::sessionBus(); + QVERIFY(bus.isConnected()); + + EditorSupport editorSupport; + QWidget window; + editorSupport.setup(&window); + EditorSupportAdaptor* adaptor = new EditorSupportAdaptor(&editorSupport); + + adaptor->enableEventSpy(); + adaptor->disableEventSpy(); + + QVERIFY(!bus.objectRegisteredAt("/ktutorial/EventSpy")); +} + +} + +QTEST_MAIN(editorsupport::EditorSupportAdaptorTest) + +#include "EditorSupportAdaptorTest.moc" Property changes on: trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportAdaptorTest.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportTest.cpp =================================================================== --- trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportTest.cpp (rev 0) +++ trunk/ktutorial/ktutorial-library/tests/editorsupport/EditorSupportTest.cpp 2010-04-13 18:49:12 UTC (rev 229) @@ -0,0 +1,213 @@ +/*************************************************************************** + * Copyright (C) 2010 by Daniel Calviño Sánchez * + * dan...@gm... * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 3 of the License, or * + * (at your option) any later version. * + * * + * 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 General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; If not, see <http://www.gnu.org/licenses/>. * + ***************************************************************************/ + +#include <QtTest> + +#include <QApplication> +#include <QtDBus/QtDBus> + +#define protected public +#define private public +#include "EditorSupport.h" +#undef private +#undef protected + +#include "EventSpy.h" +#include "ObjectRegister.h" +#include "../extendedinformation/WidgetHighlighter.h" + +using extendedinformation::WidgetHighlighter; + +namespace editorsupport { + +class EditorSupportTest: public QObject { +Q_OBJECT + +public slots: + + void handleEventReceived(int objectId, const QString& eventType) { + Q_UNUSED(objectId); + mEventTypes.append(eventType); + } + +private slots: + + void init(); + + void testConstructor(); + + void testSetup(); + + void testMainWindowObjectId(); + + void testHighlight(); + + void testStopHighlighting(); + + void testEnableEventSpy(); + + void testDisableEventSpy(); + +private: + + QStringList mEventTypes; + +}; + +void EditorSupportTest::init() { + mEventTypes.clear(); +} + +void EditorSupportTest::testConstructor() { + QObject parent; + EditorSupport* editorSupport = new EditorSupport(&parent); + + QCOMPARE(editorSupport->parent(), &parent); +} + +void EditorSupportTest::testSetup() { + QDBusConnection bus = QDBusConnection::sessionBus(); + QVERIFY(bus.isConnected()); + + EditorSupport editorSupport; + QObject mainObject; + + editorSupport.setup(&mainObject); + + QObject* ktutorialObject = bus.objectRegisteredAt("/ktutorial"); + QVERIFY(ktutorialObject); + QVERIFY(qobject_cast<EditorSupport*>(ktutorialObject)); + + QObject* objectRegisterObject = + bus.objectRegisteredAt("/ktutorial/ObjectRegister"); + QVERIFY(objectRegisterObject); + QVERIFY(qobject_cast<ObjectRegister*>(objectRegisterObject)); + + QVERIFY(!bus.objectRegisteredAt("/ktutorial/EventSpy")); +} + +void EditorSupportTest::testMainWindowObjectId() { + EditorSupport editorSupport; + QWidget window; + editorSupport.setup(&window); + + int mainWindowObjectId = editorSupport.mainWindowObjectId(); + + QCOMPARE(editorSupport.mObjectRegister->idForObject(&window), + mainWindowObjectId); +} + +void EditorSupportTest::testHighlight() { + EditorSupport editorSupport; + QWidget window; + editorSupport.setup(&window); + + QWidget* widget = new QWidget(&window); + + int widgetId = editorSupport.mObjectRegister->idForObject(widget); + editorSupport.highlight(widgetId); + + QCOMPARE(widget->findChildren<WidgetHighlighter*>().count(), 1); + QVERIFY(widget->findChild<WidgetHighlighter*>()); +} + +void EditorSupportTest::testStopHighlighting() { + EditorSupport editorSupport; + QWidget window; + editorSupport.setup(&window); + + QWidget* widget = new QWidget(&window); + + int widgetId = editorSupport.mObjectRegister->idForObject(widget); + editorSupport.highlight(widgetId); + editorSupport.stopHighlighting(widgetId); + + QCOMPARE(widget->findChildren<WidgetHighlighter*>().count(), 0); +} + +void EditorSupportTest::testEnableEventSpy() { + QDBusConnection bus = QDBusConnection::sessionBus(); + QVERIFY(bus.isConnected()); + + EditorSupport editorSupport; + QObject mainObject; + editorSupport.setup(&mainObject); + editorSupport.enableEventSpy(); + + QDBusInterface* iface = new QDBusInterface(bus.baseService(), + "/ktutorial/EventSpy", "", + bus, this); + QVERIFY(iface->isValid()); + + connect(iface, SIGNAL(eventReceived(int, QString)), + this, SLOT(handleEventReceived(int, QString))); + + QObject* eventSpyObject = bus.objectRegisteredAt("/ktutorial/EventSpy"); + QVERIFY(eventSpyObject); + QVERIFY(qobject_cast<EventSpy*>(eventSpyObject)); + + //Send an event not managed by QObject to avoid messing up it... [truncated message content] |