Skip to content

Commit

Permalink
Export the launcher dialog as a shared library
Browse files Browse the repository at this point in the history
  • Loading branch information
giucam committed Apr 5, 2017
1 parent 3d68695 commit 1459208
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 5 deletions.
1 change: 1 addition & 0 deletions launcher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
6 changes: 6 additions & 0 deletions launcher/launchoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include <QHash>
#include <QSharedDataPointer>
#include <QUrl>

QT_BEGIN_NAMESPACE
class QStringList;
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down
22 changes: 22 additions & 0 deletions launcher/ui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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})

5 changes: 5 additions & 0 deletions launcher/ui/attachdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProcDataList> *watcher = new QFutureWatcher<ProcDataList>(this);
Expand Down
1 change: 1 addition & 0 deletions launcher/ui/attachdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions launcher/ui/connectpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions launcher/ui/connectpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class ConnectPage : public QWidget

bool isValid() const;
void writeSettings();
QUrl url() const;

public slots:
void launchClient();
Expand Down
79 changes: 79 additions & 0 deletions launcher/ui/launcherdialog.cpp
Original file line number Diff line number Diff line change
@@ -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 <giulio.camuffo@kdab.com>
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 <http://www.gnu.org/licenses/>.
*/

#include <QDialog>

#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;
}

}
73 changes: 73 additions & 0 deletions launcher/ui/launcherdialog.h
Original file line number Diff line number Diff line change
@@ -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 <giulio.camuffo@kdab.com>
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 <http://www.gnu.org/licenses/>.
*/

#ifndef GAMMARAY_LAUNCHERDIALOG_H
#define GAMMARAY_LAUNCHERDIALOG_H

#include <QObject>
#include <QUrl>

#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
5 changes: 3 additions & 2 deletions launcher/ui/launcherwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 4 additions & 1 deletion launcher/ui/launcherwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -55,6 +55,9 @@ private slots:

private:
Ui::LauncherWindow *ui;
bool m_launchClient;

friend class LauncherDialog;
};
}

Expand Down

0 comments on commit 1459208

Please sign in to comment.