d/control: Recommend gdb
[gammaray-debian.git] / launcher / launchpage.cpp
blobf419e88f4818f2791c2841bff57feda3afececb0
1 /*
2 launchpage.cpp
4 This file is part of GammaRay, the Qt application inspection and
5 manipulation tool.
7 Copyright (C) 2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
8 Author: Volker Krause <volker.krause@kdab.com>
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "launchpage.h"
25 #include "ui_launchpage.h"
27 #include <QCompleter>
28 #include <QFileSystemModel>
29 #include <qfiledialog.h>
30 #include <qstringlistmodel.h>
31 #include <QSettings>
33 using namespace GammaRay;
35 LaunchPage::LaunchPage(QWidget *parent)
36 : QWidget(parent),
37 ui(new Ui::LaunchPage),
38 m_argsModel(new QStringListModel(this))
40 ui->setupUi(this);
41 connect(ui->progSelectButton, SIGNAL(clicked()), SLOT(showFileDialog()));
42 connect(ui->addArgButton, SIGNAL(clicked()), SLOT(addArgument()));
43 connect(ui->removeArgButton, SIGNAL(clicked()), SLOT(removeArgument()));
44 connect(ui->progEdit, SIGNAL(textChanged(QString)), SIGNAL(updateButtonState()));
46 ui->argsBox->setModel(m_argsModel);
48 QCompleter *pathCompleter = new QCompleter(this);
49 QFileSystemModel *fsModel = new QFileSystemModel(this);
50 fsModel->setRootPath(QDir::rootPath());
51 pathCompleter->setModel(fsModel);
52 ui->progEdit->setCompleter(pathCompleter);
54 QSettings settings;
55 ui->progEdit->setText(settings.value(QLatin1String("Launcher/Program")).toString());
56 m_argsModel->setStringList(settings.value(QLatin1String("Launcher/Arguments")).toStringList());
57 updateArgumentButtons();
60 LaunchPage::~LaunchPage()
62 delete ui;
65 void LaunchPage::writeSettings()
67 QSettings settings;
68 settings.setValue(QLatin1String("Launcher/Program"), ui->progEdit->text());
69 settings.setValue(QLatin1String("Launcher/Arguments"), m_argsModel->stringList());
72 QStringList LaunchPage::launchArguments() const
74 QStringList l;
75 l.push_back(ui->progEdit->text());
76 l.append(m_argsModel->stringList());
77 return l;
80 void LaunchPage::showFileDialog()
82 // TODO: add *.exe filter on Windows
83 const QString exeFilePath =
84 QFileDialog::getOpenFileName(
85 this,
86 tr("Executable to Launch"),
87 ui->progEdit->text());
89 if (exeFilePath.isEmpty()) {
90 return;
93 ui->progEdit->setText(exeFilePath);
96 void LaunchPage::addArgument()
98 m_argsModel->insertRows(m_argsModel->rowCount(), 1);
99 const QModelIndex newIndex = m_argsModel->index(m_argsModel->rowCount() - 1, 0);
100 ui->argsBox->edit(newIndex);
101 updateArgumentButtons();
104 void LaunchPage::removeArgument()
106 // TODO check if there's a selection at all and update button state accordingly
107 m_argsModel->removeRows(ui->argsBox->currentIndex().row(), 1);
108 updateArgumentButtons();
111 bool LaunchPage::isValid()
113 if (ui->progEdit->text().isEmpty()) {
114 return false;
117 const QFileInfo fi(ui->progEdit->text());
118 return fi.exists() && fi.isFile() && fi.isExecutable();
121 void LaunchPage::updateArgumentButtons()
123 ui->removeArgButton->setEnabled(m_argsModel->rowCount() > 0);
126 #include "launchpage.moc"