2009-05-23 12:37:30 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2014-02-15 07:45:39 +01:00
|
|
|
* Copyright (C) 2007-2014 Daniel Marjamäki and 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
|
|
|
*/
|
|
|
|
|
2010-10-31 12:16:55 +01:00
|
|
|
#include <QString>
|
2010-07-17 21:34:07 +02:00
|
|
|
#include <QWidget>
|
2010-10-31 12:16:55 +01:00
|
|
|
#include <QDialog>
|
2009-05-23 12:37:30 +02:00
|
|
|
#include <QFileDialog>
|
2009-05-24 10:53:29 +02:00
|
|
|
#include <QMessageBox>
|
2010-07-17 21:34:07 +02:00
|
|
|
#include "applicationdialog.h"
|
2011-04-02 15:30:09 +02:00
|
|
|
#include "application.h"
|
2013-02-08 16:18:05 +01:00
|
|
|
#include "common.h"
|
2009-05-23 12:37:30 +02:00
|
|
|
|
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),
|
|
|
|
mApplication(app)
|
2009-05-23 12:37:30 +02:00
|
|
|
{
|
2009-07-02 18:14:12 +02:00
|
|
|
mUI.setupUi(this);
|
|
|
|
|
|
|
|
connect(mUI.mButtonBrowse, SIGNAL(clicked()), this, SLOT(Browse()));
|
2012-11-30 12:38:41 +01:00
|
|
|
connect(mUI.mButtons, SIGNAL(accepted()), this, SLOT(Ok()));
|
2009-07-02 18:14:12 +02:00
|
|
|
connect(mUI.mButtons, SIGNAL(rejected()), this, SLOT(reject()));
|
2011-04-02 15:30:09 +02:00
|
|
|
mUI.mPath->setText(app.getPath());
|
2011-04-04 09:23:43 +02:00
|
|
|
mUI.mName->setText(app.getName());
|
2011-04-02 15:30:09 +02:00
|
|
|
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()
|
|
|
|
{
|
|
|
|
//dtor
|
|
|
|
}
|
|
|
|
|
|
|
|
void ApplicationDialog::Browse()
|
|
|
|
{
|
2009-06-17 23:54:39 +02:00
|
|
|
QString filter;
|
|
|
|
#ifdef Q_WS_WIN
|
|
|
|
// In Windows (almost) all executables have .exe extension
|
|
|
|
// so it does not make sense to show everything.
|
|
|
|
filter += tr("Executable files (*.exe);;All files(*.*)");
|
|
|
|
#endif // Q_WS_WIN
|
|
|
|
QString selectedFile = QFileDialog::getOpenFileName(this,
|
|
|
|
tr("Select viewer application"),
|
2013-02-08 16:18:05 +01:00
|
|
|
GetPath(SETTINGS_LAST_APP_PATH),
|
2009-06-17 23:54:39 +02:00
|
|
|
filter);
|
2009-05-23 12:37:30 +02:00
|
|
|
|
2011-10-13 20:53:06 +02:00
|
|
|
if (!selectedFile.isEmpty()) {
|
2013-02-17 19:59:16 +01:00
|
|
|
SetPath(SETTINGS_LAST_APP_PATH, selectedFile);
|
2009-06-17 23:54:39 +02:00
|
|
|
QString path(QDir::toNativeSeparators(selectedFile));
|
2009-07-02 18:14:12 +02:00
|
|
|
mUI.mPath->setText(path);
|
2009-05-23 12:37:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-24 10:53:29 +02:00
|
|
|
void ApplicationDialog::Ok()
|
|
|
|
{
|
2012-11-30 12:38:41 +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
|
2012-10-27 11:35:00 +02: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
|
|
|
}
|
|
|
|
}
|