2009-05-23 12:37:30 +02:00
|
|
|
/*
|
|
|
|
* Cppcheck - A tool for static C/C++ code analysis
|
2010-04-13 21:23:17 +02:00
|
|
|
* Copyright (C) 2007-2010 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
|
|
|
*/
|
|
|
|
|
|
|
|
#include "applicationdialog.h"
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QFileDialog>
|
|
|
|
#include <QDebug>
|
2009-05-24 10:53:29 +02:00
|
|
|
#include <QMessageBox>
|
2009-05-23 12:37:30 +02:00
|
|
|
|
2009-05-23 18:29:24 +02:00
|
|
|
|
2009-05-23 12:37:30 +02:00
|
|
|
ApplicationDialog::ApplicationDialog(const QString &name,
|
2009-05-23 13:26:04 +02:00
|
|
|
const QString &path,
|
2009-06-06 11:57:16 +02:00
|
|
|
const QString &title,
|
|
|
|
QWidget *parent) :
|
2010-04-02 07:30:58 +02:00
|
|
|
QDialog(parent)
|
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()));
|
|
|
|
connect(mUI.mButtons, SIGNAL(accepted()), this, SLOT(accept()));
|
|
|
|
connect(mUI.mButtons, SIGNAL(rejected()), this, SLOT(reject()));
|
|
|
|
mUI.mPath->setText(path);
|
|
|
|
mUI.mName->setText(name);
|
2009-05-23 12:37:30 +02:00
|
|
|
setWindowTitle(title);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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"),
|
|
|
|
QString(),
|
|
|
|
filter);
|
2009-05-23 12:37:30 +02:00
|
|
|
|
2010-04-02 07:30:58 +02:00
|
|
|
if (!selectedFile.isEmpty())
|
2009-05-23 12:37:30 +02:00
|
|
|
{
|
2009-06-17 23:54:39 +02:00
|
|
|
QString path(QDir::toNativeSeparators(selectedFile));
|
2009-06-08 15:22:12 +02:00
|
|
|
|
2009-06-17 23:54:39 +02:00
|
|
|
// In Windows we must surround paths including spaces with quotation marks.
|
2009-06-08 15:22:12 +02:00
|
|
|
#ifdef Q_WS_WIN
|
2010-04-02 07:30:58 +02:00
|
|
|
if (path.indexOf(" ") > -1)
|
2009-06-17 23:54:39 +02:00
|
|
|
{
|
|
|
|
path.insert(0, "\"");
|
|
|
|
path.append("\"");
|
|
|
|
}
|
2009-06-08 15:22:12 +02:00
|
|
|
#endif // Q_WS_WIN
|
|
|
|
|
2009-07-02 18:14:12 +02:00
|
|
|
mUI.mPath->setText(path);
|
2009-05-23 12:37:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ApplicationDialog::GetName()
|
|
|
|
{
|
2009-07-02 18:14:12 +02:00
|
|
|
return mUI.mName->text();
|
2009-05-23 12:37:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString ApplicationDialog::GetPath()
|
|
|
|
{
|
2009-07-02 18:14:12 +02:00
|
|
|
return mUI.mPath->text();
|
2009-05-23 12:37:30 +02:00
|
|
|
}
|
2009-05-24 10:53:29 +02:00
|
|
|
|
|
|
|
void ApplicationDialog::Ok()
|
|
|
|
{
|
2010-04-02 07:30:58 +02:00
|
|
|
if (mUI.mName->text().isEmpty() || mUI.mPath->text().isEmpty())
|
2009-05-24 10:55:54 +02:00
|
|
|
{
|
2009-06-09 09:51:27 +02:00
|
|
|
QMessageBox msg(QMessageBox::Warning,
|
|
|
|
tr("Cppcheck"),
|
|
|
|
tr("You must specify a name and a path for the application!"),
|
|
|
|
QMessageBox::Ok,
|
|
|
|
this);
|
|
|
|
|
|
|
|
msg.exec();
|
|
|
|
|
2009-05-24 10:55:54 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-06 11:49:59 +02:00
|
|
|
// Convert possible native (Windows) path to internal presentation format
|
2009-07-02 18:14:12 +02:00
|
|
|
mUI.mPath->setText(QDir::fromNativeSeparators(mUI.mPath->text()));
|
2009-06-06 11:49:59 +02:00
|
|
|
accept();
|
2009-05-24 10:53:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|