Cppcheck
applicationdialog.cpp
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2023 Cppcheck team.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "applicationdialog.h"
20 
21 #include "application.h"
22 #include "common.h"
23 
24 #include "ui_applicationdialog.h"
25 
26 #include <QDialogButtonBox>
27 #include <QDir>
28 #include <QFileDialog>
29 #include <QLineEdit>
30 #include <QMessageBox>
31 #include <QPushButton>
32 
33 
35  Application &app,
36  QWidget *parent) :
37  QDialog(parent),
38  mUI(new Ui::ApplicationDialog),
39  mApplication(app)
40 {
41  mUI->setupUi(this);
42 
43  connect(mUI->mButtonBrowse, &QPushButton::clicked, this, &ApplicationDialog::browse);
44  connect(mUI->mButtons, &QDialogButtonBox::accepted, this, &ApplicationDialog::ok);
45  connect(mUI->mButtons, &QDialogButtonBox::rejected, this, &ApplicationDialog::reject);
46  mUI->mPath->setText(app.getPath());
47  mUI->mName->setText(app.getName());
48  mUI->mParameters->setText(app.getParameters());
49  setWindowTitle(title);
50  adjustSize();
51 }
52 
53 
55 {
56  delete mUI;
57 }
58 
60 {
61  QString filter;
62 #ifdef Q_OS_WIN
63  // In Windows (almost) all executables have .exe extension
64  // so it does not make sense to show everything.
65  filter += tr("Executable files (*.exe);;All files(*.*)");
66 #endif // Q_OS_WIN
67  QString selectedFile = QFileDialog::getOpenFileName(this,
68  tr("Select viewer application"),
70  filter);
71 
72  if (!selectedFile.isEmpty()) {
73  setPath(SETTINGS_LAST_APP_PATH, selectedFile);
74  QString path(QDir::toNativeSeparators(selectedFile));
75  mUI->mPath->setText(path);
76  }
77 }
78 
80 {
81  if (mUI->mName->text().isEmpty() || mUI->mPath->text().isEmpty()) {
82  QMessageBox msg(QMessageBox::Warning,
83  tr("Cppcheck"),
84  tr("You must specify a name, a path and optionally parameters for the application!"),
85  QMessageBox::Ok,
86  this);
87 
88  msg.exec();
89 
90  reject();
91  } else {
92  // Convert possible native (Windows) path to internal presentation format
93  mApplication.setName(mUI->mName->text());
94  mApplication.setPath(QDir::fromNativeSeparators(mUI->mPath->text()));
95  mApplication.setParameters(mUI->mParameters->text());
96 
97  accept();
98  }
99 }
Dialog to edit a startable application.
Ui::ApplicationDialog * mUI
UI from the Qt designer.
ApplicationDialog(const QString &title, Application &app, QWidget *parent=nullptr)
Constructor.
void browse()
Slot to browse for an application.
~ApplicationDialog() override
Application & mApplication
Underlying Application.
A class containing information of the application to execute.
Definition: application.h:43
const QString & getParameters() const
Get application command line parameters.
Definition: application.h:68
void setPath(const QString &path)
Set application path.
Definition: application.h:84
void setName(const QString &name)
Set application name.
Definition: application.h:76
void setParameters(const QString &parameters)
Set application command line parameters.
Definition: application.h:92
const QString & getPath() const
Get application path.
Definition: application.h:60
const QString & getName() const
Get application name.
Definition: application.h:52
QString getPath(const QString &type)
Obtains the path of specified type Returns the path of specified type if not empty.
Definition: common.cpp:32
#define SETTINGS_LAST_APP_PATH
Definition: common.h:102
void setPath(const QString &type, const QString &value)
Stores last used path of specified type Stores provided path as last used path for specified type.
Definition: common.cpp:46
Definition: aboutdialog.h:27