Skip to content

Commit 1459208

Browse files
committed
Export the launcher dialog as a shared library
1 parent 3d68695 commit 1459208

11 files changed

+202
-5
lines changed

launcher/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,5 +119,6 @@ endif()
119119
# UI launcher
120120
if(HAVE_QT_CONCURRENT AND GAMMARAY_BUILD_UI)
121121
add_subdirectory(ui)
122+
gammaray_install_headers(${CMAKE_CURRENT_BINARY_DIR}/ui/gammaray_launcher_dialog_export.h ui/launcherdialog.h)
122123
endif()
123124
endif()

launcher/launchoptions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
#include <QHash>
3535
#include <QSharedDataPointer>
36+
#include <QUrl>
3637

3738
QT_BEGIN_NAMESPACE
3839
class QStringList;
@@ -65,6 +66,8 @@ class GAMMARAY_LAUNCHER_EXPORT LaunchOptions
6566
/** Returns @c true if we are supposed to attach rather than start a new process. */
6667
bool isAttach() const;
6768

69+
bool isConnect() const;
70+
6871
/** Returns @c true if no valid launch arguments or process id are set. */
6972
bool isValid() const;
7073

@@ -84,6 +87,9 @@ class GAMMARAY_LAUNCHER_EXPORT LaunchOptions
8487
void setPid(int pid);
8588
int pid() const;
8689

90+
void setUrl(const QUrl &url);
91+
QUrl url() const;
92+
8793
/** UI mode. */
8894
UiMode uiMode() const;
8995
void setUiMode(UiMode mode);

launcher/ui/CMakeLists.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ target_link_libraries(gammaray_launcher_ui_internal
3838
gammaray_ui
3939
)
4040

41+
install(TARGETS gammaray_launcher_ui_internal EXPORT GammaRayTargets ${INSTALL_TARGETS_DEFAULT_ARGS})
42+
4143
set(gammaray_launcher_ui_srcs main.cpp)
4244
# TODO we don't need all the class icons here, so split the qrc file accordingly
4345
qt4_add_resources(gammaray_launcher_ui_srcs ${CMAKE_SOURCE_DIR}/resources/gammaray.qrc)
@@ -55,5 +57,25 @@ set_target_properties(gammaray-launcher PROPERTIES
5557
RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/${LIBEXEC_INSTALL_DIR}"
5658
)
5759

60+
set(gammaray_launcher_dialog_srcs launcherdialog.cpp)
61+
add_library(gammaray_launcher_dialog SHARED ${gammaray_launcher_dialog_srcs})
62+
target_link_libraries(gammaray_launcher_dialog
63+
${QT_QTGUI_LIBRARIES}
64+
gammaray_common
65+
gammaray_launcher_ui_internal
66+
)
67+
68+
install(TARGETS gammaray_launcher_dialog EXPORT GammaRayTargets ${INSTALL_TARGETS_DEFAULT_ARGS})
69+
generate_export_header(gammaray_launcher_dialog)
70+
71+
ecm_generate_pri_file(BASE_NAME GammaRayLauncherDialog
72+
LIB_NAME gammaray_launcher_dialog
73+
DEPS "core gui GammaRayCommon GammaRayLauncher"
74+
FILENAME_VAR PRI_FILENAME
75+
INCLUDE_INSTALL_DIR ${INCLUDE_INSTALL_DIR})
76+
77+
install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR})
78+
79+
5880
install(TARGETS gammaray-launcher DESTINATION ${LIBEXEC_INSTALL_DIR})
5981

launcher/ui/attachdialog.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ int AttachDialog::pid() const
141141
return ui.view->currentIndex().data(ProcessModel::PIDRole).toInt();
142142
}
143143

144+
QString AttachDialog::name() const
145+
{
146+
return ui.view->currentIndex().data(ProcessModel::NameRole).toString();
147+
}
148+
144149
void AttachDialog::updateProcesses()
145150
{
146151
QFutureWatcher<ProcDataList> *watcher = new QFutureWatcher<ProcDataList>(this);

launcher/ui/attachdialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class AttachDialog : public QWidget
4949

5050
LaunchOptions launchOptions() const;
5151
int pid() const;
52+
QString name() const;
5253

5354
/// Returns @c true if a valid process is selected.
5455
bool isValid() const;

launcher/ui/connectpage.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,18 @@ bool ConnectPage::isValid() const
6868
return !ui->host->text().isEmpty();
6969
}
7070

71-
void ConnectPage::launchClient()
71+
QUrl ConnectPage::url() const
7272
{
7373
QUrl url;
7474
url.setScheme(QStringLiteral("tcp"));
7575
url.setHost(ui->host->text());
7676
url.setPort(ui->port->value());
77-
ClientLauncher::launchDetached(url);
77+
return url;
78+
}
79+
80+
void ConnectPage::launchClient()
81+
{
82+
ClientLauncher::launchDetached(url());
7883
}
7984

8085
void ConnectPage::writeSettings()

launcher/ui/connectpage.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class ConnectPage : public QWidget
4646

4747
bool isValid() const;
4848
void writeSettings();
49+
QUrl url() const;
4950

5051
public slots:
5152
void launchClient();

launcher/ui/launcherdialog.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
launcherdialog.cpp
3+
4+
This file is part of GammaRay, the Qt application inspection and
5+
manipulation tool.
6+
7+
Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
8+
Author: Giulio Camuffo <[email protected]>
9+
10+
Licensees holding valid commercial KDAB GammaRay licenses may use this file in
11+
accordance with GammaRay Commercial License Agreement provided with the Software.
12+
13+
Contact [email protected] if any conditions of this licensing are not clear to you.
14+
15+
This program is free software; you can redistribute it and/or modify
16+
it under the terms of the GNU General Public License as published by
17+
the Free Software Foundation, either version 2 of the License, or
18+
(at your option) any later version.
19+
20+
This program is distributed in the hope that it will be useful,
21+
but WITHOUT ANY WARRANTY; without even the implied warranty of
22+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23+
GNU General Public License for more details.
24+
25+
You should have received a copy of the GNU General Public License
26+
along with this program. If not, see <http://www.gnu.org/licenses/>.
27+
*/
28+
29+
#include <QDialog>
30+
31+
#include "launcherdialog.h"
32+
#include "launcherwindow.h"
33+
#include "ui_launcherwindow.h"
34+
35+
namespace GammaRay {
36+
37+
LauncherDialog::Result LauncherDialog::exec(Mode mode)
38+
{
39+
LauncherWindow launcher(false);
40+
launcher.ui->tabWidget->removeTab(launcher.ui->tabWidget->indexOf(launcher.ui->launchPage));
41+
42+
switch (mode) {
43+
case Mode::Connect:
44+
launcher.ui->tabWidget->setCurrentWidget(launcher.ui->connectPage);
45+
break;
46+
case Mode::Attach:
47+
launcher.ui->tabWidget->setCurrentWidget(launcher.ui->attachPage);
48+
break;
49+
}
50+
51+
int ret = launcher.exec();
52+
Result result;
53+
result.m_valid = ret == QDialog::Accepted;
54+
55+
QWidget *current = launcher.ui->tabWidget->currentWidget();
56+
if (current == launcher.ui->connectPage) {
57+
result.m_mode = Mode::Connect;
58+
} else if (current == launcher.ui->attachPage) {
59+
result.m_mode = Mode::Attach;
60+
} else {
61+
result.m_valid = false;
62+
return result;
63+
}
64+
65+
switch (result.m_mode) {
66+
case Mode::Connect:
67+
result.m_url = launcher.ui->connectPage->url();
68+
break;
69+
case Mode::Attach:
70+
result.m_procPid = launcher.ui->attachPage->pid();
71+
result.m_procExe = launcher.ui->attachPage->name();
72+
break;
73+
}
74+
75+
76+
return result;
77+
}
78+
79+
}

launcher/ui/launcherdialog.h

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
launcherdialog.h
3+
4+
This file is part of GammaRay, the Qt application inspection and
5+
manipulation tool.
6+
7+
Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
8+
Author: Giulio Camuffo <[email protected]>
9+
10+
Licensees holding valid commercial KDAB GammaRay licenses may use this file in
11+
accordance with GammaRay Commercial License Agreement provided with the Software.
12+
13+
Contact [email protected] if any conditions of this licensing are not clear to you.
14+
15+
This program is free software; you can redistribute it and/or modify
16+
it under the terms of the GNU General Public License as published by
17+
the Free Software Foundation, either version 2 of the License, or
18+
(at your option) any later version.
19+
20+
This program is distributed in the hope that it will be useful,
21+
but WITHOUT ANY WARRANTY; without even the implied warranty of
22+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23+
GNU General Public License for more details.
24+
25+
You should have received a copy of the GNU General Public License
26+
along with this program. If not, see <http://www.gnu.org/licenses/>.
27+
*/
28+
29+
#ifndef GAMMARAY_LAUNCHERDIALOG_H
30+
#define GAMMARAY_LAUNCHERDIALOG_H
31+
32+
#include <QObject>
33+
#include <QUrl>
34+
35+
#include "gammaray_launcher_dialog_export.h"
36+
37+
namespace GammaRay {
38+
39+
class GAMMARAY_LAUNCHER_DIALOG_EXPORT LauncherDialog : public QObject
40+
{
41+
public:
42+
enum class Mode {
43+
Connect,
44+
Attach,
45+
};
46+
47+
class Result
48+
{
49+
public:
50+
operator bool() const { return m_valid; }
51+
52+
Mode mode() const { return m_mode; }
53+
54+
QUrl url() const { return m_url; }
55+
56+
QString processExe() const { return m_procExe; }
57+
qint64 processPid() const { return m_procPid; }
58+
59+
private:
60+
bool m_valid;
61+
Mode m_mode;
62+
QUrl m_url;
63+
QString m_procExe;
64+
qint64 m_procPid;
65+
friend class LauncherDialog;
66+
};
67+
68+
Result exec(Mode mode);
69+
};
70+
71+
}
72+
73+
#endif

launcher/ui/launcherwindow.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@
3838

3939
using namespace GammaRay;
4040

41-
LauncherWindow::LauncherWindow(QWidget *parent)
41+
LauncherWindow::LauncherWindow(bool launchClient, QWidget *parent)
4242
: QDialog(parent)
4343
, ui(new Ui::LauncherWindow)
44+
, m_launchClient(launchClient)
4445
{
4546
ui->setupUi(this);
4647
ui->aboutLabel->setText(AboutData::aboutText());
@@ -101,7 +102,7 @@ void LauncherWindow::accept()
101102
ui->attachPage->writeSettings();
102103
ui->connectPage->writeSettings();
103104

104-
if (ui->tabWidget->currentWidget() == ui->connectPage)
105+
if (ui->tabWidget->currentWidget() == ui->connectPage && m_launchClient)
105106
ui->connectPage->launchClient();
106107

107108
QDialog::accept();

0 commit comments

Comments
 (0)