2009-05-23 12:37:30 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2023-06-21 16:41:22 +02:00
|
|
|
* Copyright (C) 2007-2023 Cppcheck team.
|
2009-05-23 12:37:30 +02:00
|
|
|
*
|
|
|
|
* 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
|
2009-09-27 17:08:31 +02:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-05-23 12:37:30 +02:00
|
|
|
*/
|
|
|
|
|
2021-04-03 21:30:50 +02:00
|
|
|
#include "applicationdialog.h"
|
|
|
|
|
2022-02-02 16:17:28 +01:00
|
|
|
#include "application.h"
|
|
|
|
#include "common.h"
|
|
|
|
|
2022-03-19 19:54:20 +01:00
|
|
|
#include "ui_applicationdialog.h"
|
|
|
|
|
2021-04-03 21:30:50 +02:00
|
|
|
#include <QDialogButtonBox>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QDir>
|
2009-05-23 12:37:30 +02:00
|
|
|
#include <QFileDialog>
|
2023-04-08 16:08:47 +02:00
|
|
|
#include <QLineEdit>
|
2009-05-24 10:53:29 +02:00
|
|
|
#include <QMessageBox>
|
2021-04-03 21:30:50 +02:00
|
|
|
#include <QPushButton>
|
|
|
|
|
2009-05-23 18:29:24 +02:00
|
|
|
|
2011-04-02 15:30:09 +02:00
|
|
|
ApplicationDialog::ApplicationDialog(const QString &title,
|
2012-10-27 11:35:00 +02:00
|
|
|
Application &app,
|
2009-06-06 11:57:16 +02:00
|
|
|
QWidget *parent) :
|
2012-10-27 11:35:00 +02:00
|
|
|
QDialog(parent),
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI(new Ui::ApplicationDialog),
|
2012-10-27 11:35:00 +02:00
|
|
|
mApplication(app)
|
2009-05-23 12:37:30 +02:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->setupUi(this);
|
2009-07-02 18:14:12 +02:00
|
|
|
|
2022-03-19 19:54:20 +01:00
|
|
|
connect(mUI->mButtonBrowse, &QPushButton::clicked, this, &ApplicationDialog::browse);
|
|
|
|
connect(mUI->mButtons, &QDialogButtonBox::accepted, this, &ApplicationDialog::ok);
|
|
|
|
connect(mUI->mButtons, &QDialogButtonBox::rejected, this, &ApplicationDialog::reject);
|
|
|
|
mUI->mPath->setText(app.getPath());
|
|
|
|
mUI->mName->setText(app.getName());
|
|
|
|
mUI->mParameters->setText(app.getParameters());
|
2009-05-23 12:37:30 +02:00
|
|
|
setWindowTitle(title);
|
2011-04-04 10:00:09 +02:00
|
|
|
adjustSize();
|
2009-05-23 12:37:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ApplicationDialog::~ApplicationDialog()
|
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
delete mUI;
|
2009-05-23 12:37:30 +02:00
|
|
|
}
|
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
void ApplicationDialog::browse()
|
2009-05-23 12:37:30 +02:00
|
|
|
{
|
2009-06-17 23:54:39 +02:00
|
|
|
QString filter;
|
2015-10-05 21:39:46 +02:00
|
|
|
#ifdef Q_OS_WIN
|
2009-06-17 23:54:39 +02:00
|
|
|
// In Windows (almost) all executables have .exe extension
|
|
|
|
// so it does not make sense to show everything.
|
|
|
|
filter += tr("Executable files (*.exe);;All files(*.*)");
|
2015-10-05 21:39:46 +02:00
|
|
|
#endif // Q_OS_WIN
|
2009-06-17 23:54:39 +02:00
|
|
|
QString selectedFile = QFileDialog::getOpenFileName(this,
|
2021-08-07 20:51:18 +02:00
|
|
|
tr("Select viewer application"),
|
|
|
|
getPath(SETTINGS_LAST_APP_PATH),
|
|
|
|
filter);
|
2009-05-23 12:37:30 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!selectedFile.isEmpty()) {
|
2017-07-28 11:20:35 +02:00
|
|
|
setPath(SETTINGS_LAST_APP_PATH, selectedFile);
|
2009-06-17 23:54:39 +02:00
|
|
|
QString path(QDir::toNativeSeparators(selectedFile));
|
2022-03-19 19:54:20 +01:00
|
|
|
mUI->mPath->setText(path);
|
2009-05-23 12:37:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-28 13:43:49 +02:00
|
|
|
void ApplicationDialog::ok()
|
2009-05-24 10:53:29 +02:00
|
|
|
{
|
2022-03-19 19:54:20 +01:00
|
|
|
if (mUI->mName->text().isEmpty() || mUI->mPath->text().isEmpty()) {
|
2009-06-09 09:51:27 +02:00
|
|
|
QMessageBox msg(QMessageBox::Warning,
|
|
|
|
tr("Cppcheck"),
|
2012-11-30 12:38:41 +01:00
|
|
|
tr("You must specify a name, a path and optionally parameters for the application!"),
|
2009-06-09 09:51:27 +02:00
|
|
|
QMessageBox::Ok,
|
|
|
|
this);
|
|
|
|
|
|
|
|
msg.exec();
|
|
|
|
|
2012-11-30 12:38:41 +01:00
|
|
|
reject();
|
2011-10-13 20:53:06 +02:00
|
|
|
} else {
|
2009-06-06 11:49:59 +02:00
|
|
|
// Convert possible native (Windows) path to internal presentation format
|
2022-03-19 19:54:20 +01:00
|
|
|
mApplication.setName(mUI->mName->text());
|
|
|
|
mApplication.setPath(QDir::fromNativeSeparators(mUI->mPath->text()));
|
|
|
|
mApplication.setParameters(mUI->mParameters->text());
|
2012-11-30 12:38:41 +01:00
|
|
|
|
2009-06-06 11:49:59 +02:00
|
|
|
accept();
|
2009-05-24 10:53:29 +02:00
|
|
|
}
|
|
|
|
}
|