[Ktutorial-commits] SF.net SVN: ktutorial:[231] trunk/ktutorial/ktutorial-editor
Status: Alpha
Brought to you by:
danxuliu
From: <dan...@us...> - 2010-04-13 20:30:23
|
Revision: 231 http://ktutorial.svn.sourceforge.net/ktutorial/?rev=231&view=rev Author: danxuliu Date: 2010-04-13 20:30:16 +0000 (Tue, 13 Apr 2010) Log Message: ----------- -Add RemoteObjectChooser (and related classes) to select a remote object from a running application. Use it in WaitForEvent and WaitForWidget. -Add a helper class to execute dialogs that do not finish when they are hidden (required by RemoteObjectChooser to safely hide all the windows and dialogs except itself). Modified Paths: -------------- trunk/ktutorial/ktutorial-editor/src/EditActions.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.h trunk/ktutorial/ktutorial-editor/src/view/WaitForEventWidget.ui trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.cpp trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.h trunk/ktutorial/ktutorial-editor/src/view/WaitForSignalWidget.ui trunk/ktutorial/ktutorial-editor/src/view/WaitForWidget.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/CMakeLists.txt Added Paths: ----------- trunk/ktutorial/ktutorial-editor/src/view/DialogRunner.cpp trunk/ktutorial/ktutorial-editor/src/view/DialogRunner.h trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.cpp trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.h trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.ui trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItem.cpp trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItem.h trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItemUpdater.cpp trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItemUpdater.h trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeSelectionManager.cpp trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeSelectionManager.h trunk/ktutorial/ktutorial-editor/src/view/TargetApplicationView.cpp trunk/ktutorial/ktutorial-editor/src/view/TargetApplicationView.h trunk/ktutorial/ktutorial-editor/tests/unit/view/DialogRunnerTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/RemoteObjectChooserTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/RemoteObjectTreeItemTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/RemoteObjectTreeItemUpdaterTest.cpp trunk/ktutorial/ktutorial-editor/tests/unit/view/RemoteObjectTreeSelectionManagerTest.cpp Modified: trunk/ktutorial/ktutorial-editor/src/EditActions.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/EditActions.cpp 2010-04-13 20:11:06 UTC (rev 230) +++ trunk/ktutorial/ktutorial-editor/src/EditActions.cpp 2010-04-13 20:30:16 UTC (rev 231) @@ -28,6 +28,7 @@ #include "commands/TutorialCommands.h" #include "data/Reaction.h" #include "data/Step.h" +#include "view/DialogRunner.h" #include "view/EditionDialog.h" #include "view/LicenseWidget.h" #include "view/ReactionWidget.h" @@ -213,10 +214,7 @@ EditionDialog* dialog = new EditionDialog(commandWidget, mTutorialEditor); dialog->setObjectName("editionDialog"); - int dialogCode = dialog->exec(); - dialog->deleteLater(); - - return dialogCode; + return DialogRunner(dialog).exec(); } //private slots: Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-04-13 20:11:06 UTC (rev 230) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.cpp 2010-04-13 20:30:16 UTC (rev 231) @@ -35,6 +35,10 @@ #include "view/TutorialTreeItem.h" #include "view/TutorialTreeSelectionManager.h" +#ifdef QT_QTDBUS_FOUND +#include "targetapplication/TargetApplication.h" +#endif + //public: KTutorialEditor::KTutorialEditor(): KXmlGuiWindow(0), @@ -63,6 +67,12 @@ setupGUI(); } +KTutorialEditor::~KTutorialEditor() { +#ifdef QT_QTDBUS_FOUND + delete TargetApplication::self(); +#endif +} + Tutorial* KTutorialEditor::tutorial() { return mTutorial; } @@ -136,6 +146,10 @@ delete mTutorial; mTutorial = tutorial; + +#ifdef QT_QTDBUS_FOUND + TargetApplication::self()->setTargetApplicationFilePath(""); +#endif } void KTutorialEditor::setupDocks() { Modified: trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-04-13 20:11:06 UTC (rev 230) +++ trunk/ktutorial/ktutorial-editor/src/KTutorialEditor.h 2010-04-13 20:30:16 UTC (rev 231) @@ -41,6 +41,12 @@ KTutorialEditor(); /** + * Destroys this KTutorialEditor. + * The target application is also killed if it is running. + */ + virtual ~KTutorialEditor(); + + /** * Returns the tutorial being edited. * * @return The tutorial being edited. Modified: trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-04-13 20:11:06 UTC (rev 230) +++ trunk/ktutorial/ktutorial-editor/src/view/CMakeLists.txt 2010-04-13 20:30:16 UTC (rev 231) @@ -2,6 +2,7 @@ ActionListWidget.cpp AutoExpandableTreeView.cpp CommandWidget.cpp + DialogRunner.cpp EditionDialog.cpp EditionWidget.cpp LicenseWidget.cpp @@ -29,6 +30,18 @@ WaitForWidget.cpp ) +if (QT_QTDBUS_FOUND) + add_definitions(-DQT_QTDBUS_FOUND) + set(ktutorial_editor_view_SRCS + ${ktutorial_editor_view_SRCS} + RemoteObjectChooser.cpp + RemoteObjectTreeItem.cpp + RemoteObjectTreeItemUpdater.cpp + RemoteObjectTreeSelectionManager.cpp + TargetApplicationView.cpp + ) +endif (QT_QTDBUS_FOUND) + kde4_add_ui_files(ktutorial_editor_view_SRCS CustomCodeWidget.ui LicenseWidget.ui @@ -41,10 +54,23 @@ WaitForWidget.ui ) +if (QT_QTDBUS_FOUND) + kde4_add_ui_files(ktutorial_editor_view_SRCS + RemoteObjectChooser.ui + ) +endif (QT_QTDBUS_FOUND) + kde4_add_library(ktutorial_editor_view ${ktutorial_editor_view_SRCS}) target_link_libraries(ktutorial_editor_view ktutorial_editor_commands ktutorial_editor_data ${KDE4_KDEUI_LIBS} + ${KDE4_KIO_LIBS} ) + +if (QT_QTDBUS_FOUND) + target_link_libraries(ktutorial_editor_view + ktutorial_editor_targetapplication + ) +endif (QT_QTDBUS_FOUND) Added: trunk/ktutorial/ktutorial-editor/src/view/DialogRunner.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/DialogRunner.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/DialogRunner.cpp 2010-04-13 20:30:16 UTC (rev 231) @@ -0,0 +1,59 @@ +/*************************************************************************** + * 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 "DialogRunner.h" + +#include <QDialog> +#include <QEventLoop> + +//public: + +DialogRunner::DialogRunner(QDialog* dialog, QObject* parent): + QObject(parent), + mDialog(dialog) { + Q_ASSERT(dialog); +} + +int DialogRunner::exec() { + Q_ASSERT(mDialog); + + mDialog->setModal(true); + mDialog->show(); + + connect(mDialog, SIGNAL(finished(int)), this, SLOT(exitEventLoop())); + connect(mDialog, SIGNAL(destroyed(QObject*)), this, SLOT(exitEventLoop())); + + mEventLoop = new QEventLoop(); + mEventLoop->exec(QEventLoop::DialogExec); + delete mEventLoop; + + if (!mDialog) { + return QDialog::Rejected; + } + + int result = mDialog->result(); + mDialog->deleteLater(); + + return result; +} + +//private slots: + +void DialogRunner::exitEventLoop() { + mEventLoop->exit(); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/DialogRunner.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/DialogRunner.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/DialogRunner.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/DialogRunner.h 2010-04-13 20:30:16 UTC (rev 231) @@ -0,0 +1,79 @@ +/*************************************************************************** + * 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 DIALOGRUNNER_H +#define DIALOGRUNNER_H + +#include <QObject> +#include <QPointer> + +class QDialog; +class QEventLoop; + +/** + * Convenience class to execute modal dialogs that can be hidden without ending + * their execution. + * DialogRunner just shows the given dialog as a modal dialog and executes an + * event loop to block in the exec() method until the user closes the dialog or + * the dialog is destroyed. The dialog can be hidden and shown again without + * causing the exec method to return (in contrast with QDialog::exec() that + * returns when the dialog is hidden). + * + * Once the event loop ends, the dialog is scheduled for deletion. + */ +class DialogRunner: public QObject { +Q_OBJECT +public: + + /** + * Creates a new DialogRunner for the given dialog and with the given + * parent. + * + * @param dialog The dialog to execute. + * @param parent The parent object of this DialogRunner. + */ + explicit DialogRunner(QDialog* dialog, QObject* parent = 0); + + /** + * Shows the dialog as a modal dialog, blocking until the user closes it. + */ + int exec(); + +private: + + /** + * The dialog to execute. + */ + QPointer<QDialog> mDialog; + + /** + * The event loop to block exec method in. + */ + QEventLoop* mEventLoop; + +private Q_SLOTS: + + /** + * Exits the event loop. + * When the event loop exits, exec method is no longer blocked and returns. + */ + void exitEventLoop(); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/DialogRunner.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.cpp 2010-04-13 20:30:16 UTC (rev 231) @@ -0,0 +1,204 @@ +/*************************************************************************** + * 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 "RemoteObjectChooser.h" +#include "ui_RemoteObjectChooser.h" + +#include <QPushButton> + +#include <KDebug> +#include <KDialogButtonBox> +#include <KMessageBox> + +#include "RemoteObjectTreeItem.h" +#include "RemoteObjectTreeItemUpdater.h" +#include "RemoteObjectTreeSelectionManager.h" +#include "TreeModel.h" +#include "TargetApplicationView.h" +#include "../targetapplication/RemoteEditorSupport.h" +#include "../targetapplication/RemoteEventSpy.h" +#include "../targetapplication/RemoteObject.h" +#include "../targetapplication/TargetApplication.h" + +//public: + +RemoteObjectChooser::RemoteObjectChooser(QWidget* parent): + QWidget(parent), + mCurrentRemoteObject(0), + mSuccessfullyStarted(false) { + setWindowFlags(Qt::Window); + Q_ASSERT(parent); + + ui = new Ui::RemoteObjectChooser(); + ui->setupUi(this); + + QPushButton* button = ui->dialogButtonBox->button(QDialogButtonBox::Ok); + button->setObjectName("okButton"); + button->setEnabled(false); + connect(button, SIGNAL(clicked(bool)), this, SLOT(accept())); + + button = ui->dialogButtonBox->button(QDialogButtonBox::Cancel); + button->setObjectName("cancelButton"); + connect(button, SIGNAL(clicked(bool)), this, SLOT(cancel())); + + connect(TargetApplication::self(), SIGNAL(started()), + this, SLOT(handleTargetApplicationStarted())); + connect(TargetApplication::self(), + SIGNAL(startFailed(TargetApplication::Error)), + this, SLOT(cancel())); + connect(TargetApplication::self(), SIGNAL(finished()), + this, SLOT(handleTargetApplicationFinished())); + + if (TargetApplication::self()->remoteEditorSupport()) { + handleTargetApplicationStarted(); + } else { + TargetApplicationView* targetApplicationView = + new TargetApplicationView(TargetApplication::self(), this); + targetApplicationView->start(); + } +} + +RemoteObjectChooser::~RemoteObjectChooser() { + if (mCurrentRemoteObject && + TargetApplication::self()->remoteEditorSupport()) { + TargetApplication::self()->remoteEditorSupport()-> + stopHighlighting(mCurrentRemoteObject); + } + + delete ui; +} + +//protected: + +void RemoteObjectChooser::closeEvent(QCloseEvent* event) { + QWidget::closeEvent(event); + showParentWindows(this); + deleteLater(); +} + +//private: + +void RemoteObjectChooser::hideParentWindows(QWidget* widget) { + if (!widget || !widget->parentWidget()) { + return; + } + + if (widget->parentWidget()->windowFlags() & (Qt::Window | Qt::Dialog)) { + widget->parentWidget()->hide(); + } + + hideParentWindows(widget->parentWidget()); +} + +void RemoteObjectChooser::showParentWindows(QWidget* widget) { + if (!widget || !widget->parentWidget()) { + return; + } + + //Show them in inverse order, because showing first a dialog and then its + //parent window would create an entry for the dialog and another entry for + //the window in the task bar + showParentWindows(widget->parentWidget()); + + if (widget->parentWidget()->windowFlags() & (Qt::Window | Qt::Dialog)) { + widget->parentWidget()->show(); + } +} + +//private slots: + +void RemoteObjectChooser::handleTargetApplicationStarted() { + hideParentWindows(this); + + RemoteEditorSupport* remoteEditorSupport = + TargetApplication::self()->remoteEditorSupport(); + + RemoteObject* mainWindow = remoteEditorSupport->mainWindow(); + RemoteObjectTreeItem* rootItem = new RemoteObjectTreeItem(mainWindow); + TreeModel* treeModel = new TreeModel(rootItem, this); + ui->remoteObjectsTreeView->setModel(treeModel); + + RemoteObjectTreeItemUpdater* updater = + new RemoteObjectTreeItemUpdater(this); + rootItem->setUpdater(updater); + + try { + updater->setRemoteEventSpy(remoteEditorSupport->enableEventSpy()); + } catch (DBusException e) { + kWarning() << "Remote event spy could not be enabled in the target " + << "application. Children objects will not be added and " + << "removed automatically in the list to reflect the " + << "changes in the remote objects (" << e.message() << ")."; + } + + //Parent object is set to the selection model, so the manager is also + //deleted when the selection model it watches is deleted + QItemSelectionModel* selectionModel = + ui->remoteObjectsTreeView->selectionModel(); + RemoteObjectTreeSelectionManager* selectionManager = + new RemoteObjectTreeSelectionManager(selectionModel, selectionModel); + connect(selectionManager, SIGNAL(remoteObjectSelected(RemoteObject*)), + this, SLOT(setCurrentRemoteObject(RemoteObject*))); + + mSuccessfullyStarted = true; +} + +void RemoteObjectChooser::handleTargetApplicationFinished() { + //If the application is running but it was not successfully started (the + //application does not have the KTutorial editor support module) + //this RemoteObjectChooser is just closed. The TargetApplicationView takes + //care of notifying the user about the problem. + if (!mSuccessfullyStarted) { + return; + } + + QString text = i18nc("@label", "The target application has been closed, " +"but it must be running to be able to choose the objects."); + QString caption = i18nc("@title:window", "Target application closed"); + KMessageBox::sorry(this, text, caption); + + close(); +} + +void RemoteObjectChooser::setCurrentRemoteObject(RemoteObject* remoteObject) { + if (mCurrentRemoteObject && mCurrentRemoteObject != remoteObject) { + TargetApplication::self()->remoteEditorSupport()-> + stopHighlighting(mCurrentRemoteObject); + } + + mCurrentRemoteObject = remoteObject; + + if (mCurrentRemoteObject) { + TargetApplication::self()->remoteEditorSupport()-> + highlight(mCurrentRemoteObject); + ui->dialogButtonBox->button(QDialogButtonBox::Ok)->setEnabled(true); + } else { + ui->dialogButtonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + } +} + +void RemoteObjectChooser::accept() { + Q_ASSERT(mCurrentRemoteObject); + + emit remoteObjectChosen(mCurrentRemoteObject); + close(); +} + +void RemoteObjectChooser::cancel() { + close(); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.h 2010-04-13 20:30:16 UTC (rev 231) @@ -0,0 +1,171 @@ +/*************************************************************************** + * 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 REMOTEOBJECTCHOOSER_H +#define REMOTEOBJECTCHOOSER_H + +#include <QWidget> + +class RemoteObject; + +namespace Ui { +class RemoteObjectChooser; +} + +/** + * Widget to choose a remote object from all the available remote objects in the + * target application. + * The RemoteObjectChooser shows a window with a list containing all the objects + * that can be accesed by KTutorial in the target application. The target + * application must be running, so it is started when the RemoteObjectChooser is + * created. If the target application is closed, the RemoteObjectChooser is also + * closed (after notifying the user). + * + * When the target application is successfully started, the RemoteObjectChooser + * hides all its parent dialogs and windows. Only the RemoteObjectChooser itself + * is kept shown to avoid the rest of windows of KTutorial editor to get in the + * way of the user when he interacts with the target application. + * + * When the user selects a remote object in the list and that object represents + * a widget, the widget is highlighted in the target application. + * + * The window contains an "Ok" and a "Cancel" button, like the ones found in + * dialogs. A window is used instead of a dialog to be shown in the task bar (as + * after hidding the rest of KTutorial editor windows no entry would be shown if + * this were a dialog). When there is a remote object selected and the "Ok" + * button is clicked, signal remoteObjectChosen(RemoteObject*) is emitted. + * + * The RemoteObjectChooser deletes itself once it has been closed, no matter the + * reason why. + */ +class RemoteObjectChooser: public QWidget { +Q_OBJECT +public: + + /** + * Creates a new RemoteObjectChooser with the given parent. + * The target application is started. + * + * @param parent The parent QWidget. + */ + explicit RemoteObjectChooser(QWidget* parent = 0); + + /** + * Destroys this RemoteObjectChooser. + * The highlighting in the current remote object is stopped, if any. + */ + virtual ~RemoteObjectChooser(); + +Q_SIGNALS: + + /** + * Emitted when the user chooses a RemoteObject. + * + * @param remoteObject The chosen RemoteObject. + */ + void remoteObjectChosen(RemoteObject* remoteObject); + +protected: + + /** + * Executes KDialog handler, shows again the parent windows and schedules + * this RemoteObjectChooser for deletion. + * close() can't be redefined to restore the parent windows, as it doesn't + * get a close triggered by the window manager (like using ALT+F4) (and it + * is not even a virtual method). Moreover, close() itself sends a + * QCloseEvent, which is handled by this method. + * Likely, Qt::WA_DeleteOnClose isn't used as it will delete this + * RemoteObjectChooser only through close(), but not through a QCloseEvent. + * Instead, this RemoteObjectChooser is scheduled for deletion after + * receiving a QCloseEvent. + * + * @param event The QCloseEvent. + */ + virtual void closeEvent(QCloseEvent* event); + +private: + + /** + * The Ui Designer generated class. + */ + Ui::RemoteObjectChooser* ui; + + /** + * The RemoteObject currently selected in the list. + */ + RemoteObject* mCurrentRemoteObject; + + /** + * True if the target application has been successfully started, false + * otherwise. + */ + bool mSuccessfullyStarted; + + /** + * Hide all the parent widgets of the given widget that are windows or + * dialogs. + * + * @param widget The widget to hide its parents. + */ + void hideParentWindows(QWidget* widget); + + /** + * Shows all the parent widgets of the given widget that are windows or + * dialogs. + * + * @param widget The widget to show its parents. + */ + void showParentWindows(QWidget* widget); + +private Q_SLOTS: + + /** + * Hides the parent windows and dialogs and sets up the models for the tree + * view. + */ + void handleTargetApplicationStarted(); + + /** + * If the target application was finished after starting successfully, a + * warning is shown to the user and this RemoteObjectChooser is closed. + */ + void handleTargetApplicationFinished(); + + /** + * Sets the current remote object. + * The current remote object is highlighted, and the highlighting in the + * previous one is stopped. + * + * @param remoteObject The current remote object to set. + */ + void setCurrentRemoteObject(RemoteObject* remoteObject); + + /** + * Emits remoteObjectChosen(RemoteObject*) and closes this + * RemoteObjectChooser. + */ + void accept(); + + /** + * Closes this RemoteObjectChooser. + */ + void cancel(); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.ui =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.ui (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectChooser.ui 2010-04-13 20:30:16 UTC (rev 231) @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>RemoteObjectChooser</class> + <widget class="QWidget" name="RemoteObjectChooser"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>400</width> + <height>300</height> + </rect> + </property> + <property name="windowTitle"> + <string comment="@title:window">Target application objects</string> + </property> + <property name="whatsThis"> + <string comment="@info:whatsthis"><p>Chooser for objects in the target application.</p> +<p>The objects shown in the list are all the objects accessible through KTutorial. They are shown in a tree structure to represent the parent and child relationships the objects have.</p> +<p>Note, however, that not all the objects have a name set in the target application. KTutorial needs to know the name of the object to find it, so if an object does not have a name KTutorial will not be able to use it.</p></string> + </property> + <layout class="QVBoxLayout" name="remoteObjectChooserVerticalLayout"> + <item> + <widget class="AutoExpandableTreeView" name="remoteObjectsTreeView"/> + </item> + <item> + <widget class="KDialogButtonBox" name="dialogButtonBox"> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <customwidgets> + <customwidget> + <class>KDialogButtonBox</class> + <extends>QDialogButtonBox</extends> + <header>kdialogbuttonbox.h</header> + </customwidget> + <customwidget> + <class>AutoExpandableTreeView</class> + <extends>QTreeView</extends> + <header>AutoExpandableTreeView.h</header> + </customwidget> + </customwidgets> + <resources/> + <connections/> +</ui> Added: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItem.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItem.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItem.cpp 2010-04-13 20:30:16 UTC (rev 231) @@ -0,0 +1,138 @@ +/*************************************************************************** + * 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 "RemoteObjectTreeItem.h" + +#include <KDebug> +#include <KLocalizedString> + +#include "RemoteObjectTreeItemUpdater.h" +#include "../targetapplication/RemoteObject.h" + +//public: + +RemoteObjectTreeItem::RemoteObjectTreeItem(RemoteObject* remoteObject, + TreeItem* parent): + TreeItem(parent), + mRemoteObject(remoteObject), + mUpdater(0) { + Q_ASSERT(remoteObject); + + try { + mName = remoteObject->name(); + mClassName = remoteObject->className(); + } catch (DBusException e) { + mName = i18nc("@item", "D-Bus Error!"); + mClassName = i18nc("@item", "D-Bus Error!"); + } + + if (mName.isEmpty()) { + mName = i18nc("@item", "Object without name!"); + } + + if (mClassName.isEmpty()) { + mClassName = i18nc("@item", "No class name!"); + } + + updateChildren(); +} + +QString RemoteObjectTreeItem::text() const { + return i18nc("@item Object name (Class name)", "%1 (%2)", mName, + mClassName); +} + +RemoteObject* RemoteObjectTreeItem::remoteObject() const { + return mRemoteObject; +} + +void RemoteObjectTreeItem::setUpdater(RemoteObjectTreeItemUpdater* updater) { + Q_ASSERT(updater); + + mUpdater = updater; + + updater->registerRemoteObjectTreeItem(this); + + foreach (RemoteObjectTreeItem* child, mChildRemoteObjectTreeItems) { + child->setUpdater(updater); + } +} + +void RemoteObjectTreeItem::updateChildren() { + QList<RemoteObject*> children; + try { + children = mRemoteObject->children(); + } catch (DBusException e) { + kWarning() << "The children for the remote object with id " + << mRemoteObject->objectId() << " could not be updated (" + << e.message() << ")."; + return; + } + + int i=0; + while (i < mChildRemoteObjectTreeItems.count()) { + if (i >= children.count() || + mChildRemoteObjectTreeItems[i]->remoteObject() != children[i]) { + removeChildRemoteObject( + mChildRemoteObjectTreeItems[i]->remoteObject()); + } else { + i++; + } + } + + while (i < children.count()) { + addChildRemoteObject(children[i]); + i++; + } +} + +//private: + +RemoteObjectTreeItem* RemoteObjectTreeItem::remoteObjectTreeItemForRemoteObject( + RemoteObject* child) const { + foreach (RemoteObjectTreeItem* remoteObjectTreeItem, + mChildRemoteObjectTreeItems) { + if (remoteObjectTreeItem->remoteObject() == child) { + return remoteObjectTreeItem; + } + } + + return 0; +} + +//private slots: + +void RemoteObjectTreeItem::addChildRemoteObject(RemoteObject* child) { + RemoteObjectTreeItem* remoteObjectTreeItem = + new RemoteObjectTreeItem(child, this); + appendChild(remoteObjectTreeItem); + mChildRemoteObjectTreeItems.append(remoteObjectTreeItem); + + if (mUpdater) { + remoteObjectTreeItem->setUpdater(mUpdater); + } +} + +void RemoteObjectTreeItem::removeChildRemoteObject(RemoteObject* child) { + RemoteObjectTreeItem* remoteObjectTreeItem = + remoteObjectTreeItemForRemoteObject(child); + + removeChild(remoteObjectTreeItem); + mChildRemoteObjectTreeItems.removeOne(remoteObjectTreeItem); + delete remoteObjectTreeItem; +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItem.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItem.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItem.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItem.h 2010-04-13 20:30:16 UTC (rev 231) @@ -0,0 +1,149 @@ +/*************************************************************************** + * 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 REMOTEOBJECTTREEITEM_H +#define REMOTEOBJECTTREEITEM_H + +#include "TreeItem.h" + +class RemoteObject; +class RemoteObjectTreeItemUpdater; + +/** + * A TreeItem that represents a RemoteObject. + * The tree representation of a RemoteObject is: + * The object name (The class name) + * |-The child 1 name (The child 1 class name) + * | ... + * |-The child 2 name (The child 2 class name) + * | ... + * ... + * + * If the RemoteObject returns an empty object name or an empty class name + * (for example, because the id is wrong), a placeholder is used instead. Name + * placeholder is "Object without name!", and the class name placeholder is + * "No class name!". + * + * If a D-Bus error happens, the placeholder for each element is "D-Bus Error!". + * No children are shown if a D-Bus error happened. + * + * RemoteObjects does not provide information about changes in their children. A + * helper class, RemoteObjectTreeItemUpdater, is used for this. + * RemoteObjectTreeItem can work without an updater, but changes in the children + * will not be shown if updateChildren() is not called explicitly. + * + * @see RemoteObjectTreeItemUpdater + */ +class RemoteObjectTreeItem: public TreeItem { +Q_OBJECT +public: + + /** + * Creates a new RemoteObjectTreeItem for the given RemoteObject and with + * the given parent. + * + * @param remoteObject The RemoteObject to represent. + * @param parent The parent TreeItem. + */ + explicit RemoteObjectTreeItem(RemoteObject* remoteObject, + TreeItem* parent = 0); + + /** + * Returns "The class name (The class name)", or a placeholder if the names + * are empty or can not be got. + * + * @return The text for this TreeItem. + */ + virtual QString text() const; + + /** + * Returns the RemoteObject. + * + * @return The RemoteObject. + */ + RemoteObject* remoteObject() const; + + /** + * Sets the updater to register the children tree items in. + * + * @param updater The updater to register the children tree items in. + */ + void setUpdater(RemoteObjectTreeItemUpdater* updater); + + /** + * Updates the children tree items based on the current children of the + * remote object, adding or removing them as necessary. + */ + void updateChildren(); + +private: + + /** + * The RemoteObject. + */ + RemoteObject* mRemoteObject; + + /** + * The updater for this RemoteObjectTreeItem and all its children. + */ + RemoteObjectTreeItemUpdater* mUpdater; + + /** + * The name of the RemoteObject. + */ + QString mName; + + /** + * The class name of the RemoteObject. + */ + QString mClassName; + + /** + * The RemoteObjectTreeItems for each child RemoteObject in the + * RemoteObject. + */ + QList<RemoteObjectTreeItem*> mChildRemoteObjectTreeItems; + + /** + * Returns the RemoteObjectTreeItem for the given child RemoteObject. + * + * @param child The child RemoteObject to get its RemoteObjectTreeItem. + * @return The RemoteObjectTreeItem. + */ + RemoteObjectTreeItem* remoteObjectTreeItemForRemoteObject( + RemoteObject* child) const; + + /** + * Adds a new RemoteObjectTreeItem when a child RemoteObject is added in the + * RemoteObject. + * + * @param child The child RemoteObject added in the RemoteObject. + */ + void addChildRemoteObject(RemoteObject* child); + + /** + * Removes the RemoteObjectTreeItem for the child RemoteObject removed in + * the RemoteObject. + * + * @param child The child RemoteObject removed in the RemoteObject. + */ + void removeChildRemoteObject(RemoteObject* child); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItem.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItemUpdater.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItemUpdater.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItemUpdater.cpp 2010-04-13 20:30:16 UTC (rev 231) @@ -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 "RemoteObjectTreeItemUpdater.h" +#include "RemoteObjectTreeItem.h" +#include "../targetapplication/RemoteEventSpy.h" + +//public: + +RemoteObjectTreeItemUpdater::RemoteObjectTreeItemUpdater(QObject* parent): + QObject(parent) { +} + +void RemoteObjectTreeItemUpdater::setRemoteEventSpy( + RemoteEventSpy* remoteEventSpy) { + connect(remoteEventSpy, SIGNAL(eventReceived(RemoteObject*, QString)), + this, SLOT(handleEventReceived(RemoteObject*, QString))); +} + +void RemoteObjectTreeItemUpdater::registerRemoteObjectTreeItem( + RemoteObjectTreeItem* item) { + mRemoteObjectTreeItems.insert(item->remoteObject(), item); +} + +//private slots: + +void RemoteObjectTreeItemUpdater::handleEventReceived( + RemoteObject* remoteObject, + const QString& eventType) { + if (!mRemoteObjectTreeItems.contains(remoteObject)) { + return; + } + + if (!mRemoteObjectTreeItems.value(remoteObject)) { + //The tree item was deleted, so an entry is no longer needed for it + mRemoteObjectTreeItems.remove(remoteObject); + return; + } + + if (eventType != "ChildAdded" && eventType != "ChildRemoved") { + return; + } + + mRemoteObjectTreeItems.value(remoteObject)->updateChildren(); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItemUpdater.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItemUpdater.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItemUpdater.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItemUpdater.h 2010-04-13 20:30:16 UTC (rev 231) @@ -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 REMOTEOBJECTTREEITEMUPDATER_H +#define REMOTEOBJECTTREEITEMUPDATER_H + +#include <QHash> +#include <QObject> +#include <QPointer> + +class RemoteEventSpy; +class RemoteObject; +class RemoteObjectTreeItem; + +/** + * Helper class for RemoteObjectTreeItem to notify when it should update its + * children tree items. + * RemoteObjectTreeItems can not update their list of children tree items by + * themselves, as RemoteObject does not provide that information. The + * RemoteEventSpy has to be used to watch events in all the RemoteObjects and + * update the tree items when a ChildAdded or a ChildRemoved event is received. + * + * RemoteObjectTreeItems should not be registered directly with the updater. The + * updater must be set in the root RemoteObjectTreeItem to update. The tree item + * will take care of registering its children with the updater when necessary. + * Thus, the whole tree is updated, instead of only the registered item. + * + * @see RemoteObjectTreeItem + */ +class RemoteObjectTreeItemUpdater: public QObject { +Q_OBJECT +public: + + /** + * Creates a new RemoteObjectTreeItemUpdater. + * + * @param parent The parent object. + */ + explicit RemoteObjectTreeItemUpdater(QObject* parent = 0); + + /** + * Sets the RemoteEventSpy to check its events. + * + * @param remoteEventSpy The RemoteEventSpy. + */ + void setRemoteEventSpy(RemoteEventSpy* remoteEventSpy); + + /** + * Registers a new RemoteObjectTreeItem to be updated. + * + * @param remoteObjectTreeItem The RemoteObjectTreeItem to register. + */ + void registerRemoteObjectTreeItem( + RemoteObjectTreeItem* remoteObjectTreeItem); + +private: + + /** + * The RemoteObjectTreeItems to update, identified by their RemoteObject. + */ + QHash<RemoteObject*, QPointer<RemoteObjectTreeItem> > + mRemoteObjectTreeItems; + +private Q_SLOTS: + + /** + * If the event is a ChildAdded or a ChildRemoved, the RemoteObjectTreeItem + * that represents the remoteObject is told to update its children. + * + * @param remoteObject The RemoteObject to update. + * @param eventType The type of the event received. + */ + void handleEventReceived(RemoteObject* remoteObject, + const QString& eventType); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeItemUpdater.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeSelectionManager.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeSelectionManager.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeSelectionManager.cpp 2010-04-13 20:30:16 UTC (rev 231) @@ -0,0 +1,95 @@ +/*************************************************************************** + * 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 "RemoteObjectTreeSelectionManager.h" + +#include "RemoteObjectTreeItem.h" + +//public: + +RemoteObjectTreeSelectionManager::RemoteObjectTreeSelectionManager( + QItemSelectionModel* itemSelectionModel, + QObject* parent): QObject(parent) { + connect(itemSelectionModel, + SIGNAL(selectionChanged(QItemSelection, QItemSelection)), + this, + SLOT(handleSelectionChanged(QItemSelection, QItemSelection))); +} + +//private: + +void RemoteObjectTreeSelectionManager::updateRemoteObjectSelection( + TreeItem* selected, + TreeItem* deselected) { + RemoteObject* selectedRemoteObject = getRemoteObjectForTreeItem(selected); + RemoteObject* deselectedRemoteObject = getRemoteObjectForTreeItem( + deselected); + + if (selectedRemoteObject && + selectedRemoteObject != deselectedRemoteObject) { + emit remoteObjectSelected(selectedRemoteObject); + return; + } + + if (!selectedRemoteObject && deselectedRemoteObject) { + emit remoteObjectSelected(0); + return; + } +} + +RemoteObject* RemoteObjectTreeSelectionManager::getRemoteObjectForTreeItem( + TreeItem* item) { + if (qobject_cast<RemoteObjectTreeItem*>(item)) { + return static_cast<RemoteObjectTreeItem*>(item)->remoteObject(); + } + + if (item == 0 || item->parent() == 0) { + return 0; + } + + return getRemoteObjectForTreeItem(item->parent()); +} + +//private slots: + +void RemoteObjectTreeSelectionManager::handleSelectionChanged( + const QItemSelection& selected, + const QItemSelection& deselected) { + //Only single selections are supported + Q_ASSERT(selected.count() <= 1); + Q_ASSERT(deselected.count() <= 1); + + TreeItem* selectedItem = 0; + TreeItem* deselectedItem = 0; + + if (selected.count() == 1) { + Q_ASSERT(selected.at(0).indexes().count() == 1); + + QModelIndex index = selected.at(0).indexes().at(0); + selectedItem = static_cast<TreeItem*>(index.internalPointer()); + } + + if (deselected.count() == 1) { + Q_ASSERT(deselected.at(0).indexes().count() == 1); + + QModelIndex index = deselected.at(0).indexes().at(0); + deselectedItem = static_cast<TreeItem*>(index.internalPointer()); + } + + updateRemoteObjectSelection(selectedItem, deselectedItem); +} Property changes on: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeSelectionManager.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeSelectionManager.h =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeSelectionManager.h (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeSelectionManager.h 2010-04-13 20:30:16 UTC (rev 231) @@ -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 REMOTEOBJECTTREESELECTIONMANAGER_H +#define REMOTEOBJECTTREESELECTIONMANAGER_H + +#include <QItemSelectionModel> +#include <QObject> + +class RemoteObject; +class TreeItem; + +/** + * Watches the QItemSelectionModel of a TreeModel composed by + * RemoteObjectTreeItems for changes in the selection. + * When an item is selected in the TreeModel, + * remoteObjectSelected(RemoteObject*) signal is emitted with the RemoteObject + * represented by the selected item. + * + * Only single item selections are supported. + */ +class RemoteObjectTreeSelectionManager: public QObject { +Q_OBJECT +public: + + /** + * Creates a new RemoteObjectTreeSelectionManager that watchs the given + * selection model. + * + * @param itemSelectionModel The selection model to watch for changes in the + * selection. + * @param parent The parent object. + */ + explicit RemoteObjectTreeSelectionManager( + QItemSelectionModel* itemSelectionModel, QObject* parent = 0); + +Q_SIGNALS: + + /** + * Emitted when a RemoteObject is selected. + * If the RemoteObject is deselected and the new selected item isn't a + * RemoteObject, the signal is emitted with a null pointer. + * + * @param remoteObject The selected RemoteObject, or null if it was + * deselected. + */ + void remoteObjectSelected(RemoteObject* remoteObject); + +private: + + /** + * Emits remoteObjectSelected(RemoteObject*) signal based on the selected + * and deselected items. + * + * @param selected The selected item, if any. + * @param deselected The deselected item, if any. + */ + void updateRemoteObjectSelection(TreeItem* selected, TreeItem* deselected); + + /** + * Returns the RemoteObject represented by the given item. + * If the item doesn't represent a RemoteObject or there is no item, a null + * pointer is returned. + * + * @param item The item to get its represented RemoteObject. + * @return The RemoteObject. + */ + RemoteObject* getRemoteObjectForTreeItem(TreeItem* item); + +private Q_SLOTS: + + /** + * Handles a change in the selection in the watched selection model. + * Signals are emitted as needed based on the selected and deselected items. + * + * @param selected The item selection of selected items. + * @param selected The item selection of deselected items. + */ + void handleSelectionChanged(const QItemSelection& selected, + const QItemSelection& deselected); + +}; + +#endif Property changes on: trunk/ktutorial/ktutorial-editor/src/view/RemoteObjectTreeSelectionManager.h ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/ktutorial/ktutorial-editor/src/view/TargetApplicationView.cpp =================================================================== --- trunk/ktutorial/ktutorial-editor/src/view/TargetApplicationView.cpp (rev 0) +++ trunk/ktutorial/ktutorial-editor/src/view/TargetApplicationView.cpp 2010-04-13 20:30:16 UTC (rev 231) @@ -0,0 +1,109 @@ +/*************************************************************************** + * 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 "TargetApplicationView.h" + +#include <QApplication> +#include <QScopedPointer> + +#include <KFileDialog> +#include <KFileFilterCombo> +#include <KLocalizedString> +#include <KMessageBox> + +//public: + +TargetApplicationView::TargetApplicationView( + TargetApplication* targetApplication, QWidget* parent): + QObject(parent), + mTargetApplication(targetApplication), + mParent(parent) { +} + +void TargetApplicationView::start() { + if (mTargetApplication->remoteEditorSupport()) { + return; + } + + if (mTargetApplication->targetApplicationFilePath().isEmpty()) { + QString path = askApplicationFilePath(); + + if (path.isEmpty()) { + return; + } + + ... [truncated message content] |