diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index d6ebe0e699..6433bd7155 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -119,5 +119,6 @@ endif() # UI launcher if(HAVE_QT_CONCURRENT AND GAMMARAY_BUILD_UI) add_subdirectory(ui) + gammaray_install_headers(${CMAKE_CURRENT_BINARY_DIR}/ui/gammaray_launcher_dialog_export.h ui/launcherdialog.h) endif() endif() diff --git a/launcher/launchoptions.h b/launcher/launchoptions.h index fe8462d2cd..f8a877f87b 100644 --- a/launcher/launchoptions.h +++ b/launcher/launchoptions.h @@ -33,6 +33,7 @@ #include #include +#include QT_BEGIN_NAMESPACE class QStringList; @@ -65,6 +66,8 @@ class GAMMARAY_LAUNCHER_EXPORT LaunchOptions /** Returns @c true if we are supposed to attach rather than start a new process. */ bool isAttach() const; + bool isConnect() const; + /** Returns @c true if no valid launch arguments or process id are set. */ bool isValid() const; @@ -84,6 +87,9 @@ class GAMMARAY_LAUNCHER_EXPORT LaunchOptions void setPid(int pid); int pid() const; + void setUrl(const QUrl &url); + QUrl url() const; + /** UI mode. */ UiMode uiMode() const; void setUiMode(UiMode mode); diff --git a/launcher/ui/CMakeLists.txt b/launcher/ui/CMakeLists.txt index 31df78b03f..82b0f27883 100644 --- a/launcher/ui/CMakeLists.txt +++ b/launcher/ui/CMakeLists.txt @@ -38,6 +38,8 @@ target_link_libraries(gammaray_launcher_ui_internal gammaray_ui ) +install(TARGETS gammaray_launcher_ui_internal EXPORT GammaRayTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) + set(gammaray_launcher_ui_srcs main.cpp) # TODO we don't need all the class icons here, so split the qrc file accordingly qt4_add_resources(gammaray_launcher_ui_srcs ${CMAKE_SOURCE_DIR}/resources/gammaray.qrc) @@ -55,5 +57,25 @@ set_target_properties(gammaray-launcher PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${LIBEXEC_INSTALL_DIR}" ) +set(gammaray_launcher_dialog_srcs launcherdialog.cpp) +add_library(gammaray_launcher_dialog SHARED ${gammaray_launcher_dialog_srcs}) +target_link_libraries(gammaray_launcher_dialog + ${QT_QTGUI_LIBRARIES} + gammaray_common + gammaray_launcher_ui_internal +) + +install(TARGETS gammaray_launcher_dialog EXPORT GammaRayTargets ${INSTALL_TARGETS_DEFAULT_ARGS}) +generate_export_header(gammaray_launcher_dialog) + +ecm_generate_pri_file(BASE_NAME GammaRayLauncherDialog + LIB_NAME gammaray_launcher_dialog + DEPS "core gui GammaRayCommon GammaRayLauncher" + FILENAME_VAR PRI_FILENAME + INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_DIR}) + +install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR}) + + install(TARGETS gammaray-launcher DESTINATION ${LIBEXEC_INSTALL_DIR}) diff --git a/launcher/ui/attachdialog.cpp b/launcher/ui/attachdialog.cpp index 779e357f6d..5c1642d8a4 100644 --- a/launcher/ui/attachdialog.cpp +++ b/launcher/ui/attachdialog.cpp @@ -141,6 +141,11 @@ int AttachDialog::pid() const return ui.view->currentIndex().data(ProcessModel::PIDRole).toInt(); } +QString AttachDialog::name() const +{ + return ui.view->currentIndex().data(ProcessModel::NameRole).toString(); +} + void AttachDialog::updateProcesses() { QFutureWatcher *watcher = new QFutureWatcher(this); diff --git a/launcher/ui/attachdialog.h b/launcher/ui/attachdialog.h index ce5c87e301..f6e81e984a 100644 --- a/launcher/ui/attachdialog.h +++ b/launcher/ui/attachdialog.h @@ -49,6 +49,7 @@ class AttachDialog : public QWidget LaunchOptions launchOptions() const; int pid() const; + QString name() const; /// Returns @c true if a valid process is selected. bool isValid() const; diff --git a/launcher/ui/connectpage.cpp b/launcher/ui/connectpage.cpp index 499b158830..05bd8ae8e3 100644 --- a/launcher/ui/connectpage.cpp +++ b/launcher/ui/connectpage.cpp @@ -68,13 +68,18 @@ bool ConnectPage::isValid() const return !ui->host->text().isEmpty(); } -void ConnectPage::launchClient() +QUrl ConnectPage::url() const { QUrl url; url.setScheme(QStringLiteral("tcp")); url.setHost(ui->host->text()); url.setPort(ui->port->value()); - ClientLauncher::launchDetached(url); + return url; +} + +void ConnectPage::launchClient() +{ + ClientLauncher::launchDetached(url()); } void ConnectPage::writeSettings() diff --git a/launcher/ui/connectpage.h b/launcher/ui/connectpage.h index e1e2927936..d9e63f67a9 100644 --- a/launcher/ui/connectpage.h +++ b/launcher/ui/connectpage.h @@ -46,6 +46,7 @@ class ConnectPage : public QWidget bool isValid() const; void writeSettings(); + QUrl url() const; public slots: void launchClient(); diff --git a/launcher/ui/launcherdialog.cpp b/launcher/ui/launcherdialog.cpp new file mode 100644 index 0000000000..b5aaf78727 --- /dev/null +++ b/launcher/ui/launcherdialog.cpp @@ -0,0 +1,79 @@ +/* + launcherdialog.cpp + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Giulio Camuffo + + Licensees holding valid commercial KDAB GammaRay licenses may use this file in + accordance with GammaRay Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + 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 2 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 . +*/ + +#include + +#include "launcherdialog.h" +#include "launcherwindow.h" +#include "ui_launcherwindow.h" + +namespace GammaRay { + +LauncherDialog::Result LauncherDialog::exec(Mode mode) +{ + LauncherWindow launcher(false); + launcher.ui->tabWidget->removeTab(launcher.ui->tabWidget->indexOf(launcher.ui->launchPage)); + + switch (mode) { + case Mode::Connect: + launcher.ui->tabWidget->setCurrentWidget(launcher.ui->connectPage); + break; + case Mode::Attach: + launcher.ui->tabWidget->setCurrentWidget(launcher.ui->attachPage); + break; + } + + int ret = launcher.exec(); + Result result; + result.m_valid = ret == QDialog::Accepted; + + QWidget *current = launcher.ui->tabWidget->currentWidget(); + if (current == launcher.ui->connectPage) { + result.m_mode = Mode::Connect; + } else if (current == launcher.ui->attachPage) { + result.m_mode = Mode::Attach; + } else { + result.m_valid = false; + return result; + } + + switch (result.m_mode) { + case Mode::Connect: + result.m_url = launcher.ui->connectPage->url(); + break; + case Mode::Attach: + result.m_procPid = launcher.ui->attachPage->pid(); + result.m_procExe = launcher.ui->attachPage->name(); + break; + } + + + return result; +} + +} diff --git a/launcher/ui/launcherdialog.h b/launcher/ui/launcherdialog.h new file mode 100644 index 0000000000..d921b4eaf9 --- /dev/null +++ b/launcher/ui/launcherdialog.h @@ -0,0 +1,73 @@ +/* + launcherdialog.h + + This file is part of GammaRay, the Qt application inspection and + manipulation tool. + + Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com + Author: Giulio Camuffo + + Licensees holding valid commercial KDAB GammaRay licenses may use this file in + accordance with GammaRay Commercial License Agreement provided with the Software. + + Contact info@kdab.com if any conditions of this licensing are not clear to you. + + 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 2 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 . +*/ + +#ifndef GAMMARAY_LAUNCHERDIALOG_H +#define GAMMARAY_LAUNCHERDIALOG_H + +#include +#include + +#include "gammaray_launcher_dialog_export.h" + +namespace GammaRay { + +class GAMMARAY_LAUNCHER_DIALOG_EXPORT LauncherDialog : public QObject +{ +public: + enum class Mode { + Connect, + Attach, + }; + + class Result + { + public: + operator bool() const { return m_valid; } + + Mode mode() const { return m_mode; } + + QUrl url() const { return m_url; } + + QString processExe() const { return m_procExe; } + qint64 processPid() const { return m_procPid; } + + private: + bool m_valid; + Mode m_mode; + QUrl m_url; + QString m_procExe; + qint64 m_procPid; + friend class LauncherDialog; + }; + + Result exec(Mode mode); +}; + +} + +#endif diff --git a/launcher/ui/launcherwindow.cpp b/launcher/ui/launcherwindow.cpp index 91bc04c0c7..f7f516cef7 100644 --- a/launcher/ui/launcherwindow.cpp +++ b/launcher/ui/launcherwindow.cpp @@ -38,9 +38,10 @@ using namespace GammaRay; -LauncherWindow::LauncherWindow(QWidget *parent) +LauncherWindow::LauncherWindow(bool launchClient, QWidget *parent) : QDialog(parent) , ui(new Ui::LauncherWindow) + , m_launchClient(launchClient) { ui->setupUi(this); ui->aboutLabel->setText(AboutData::aboutText()); @@ -101,7 +102,7 @@ void LauncherWindow::accept() ui->attachPage->writeSettings(); ui->connectPage->writeSettings(); - if (ui->tabWidget->currentWidget() == ui->connectPage) + if (ui->tabWidget->currentWidget() == ui->connectPage && m_launchClient) ui->connectPage->launchClient(); QDialog::accept(); diff --git a/launcher/ui/launcherwindow.h b/launcher/ui/launcherwindow.h index a468f026eb..e0215e4a15 100644 --- a/launcher/ui/launcherwindow.h +++ b/launcher/ui/launcherwindow.h @@ -41,7 +41,7 @@ class LauncherWindow : public QDialog { Q_OBJECT public: - explicit LauncherWindow(QWidget *parent = nullptr); + explicit LauncherWindow(bool launchClient = true, QWidget *parent = nullptr); ~LauncherWindow(); /// returns all information required to perform the launch/attach @@ -55,6 +55,9 @@ private slots: private: Ui::LauncherWindow *ui; + bool m_launchClient; + + friend class LauncherDialog; }; }