GUI: Have separate setting for editor app path and params.

Currently combined editor application path + params is a bit
problematic (at least in Windows). We really don't know where the app
path ends and parameters start. So proper quoting is not always
possible.

And application path and command line parameters are clearly
different settings anyway. So make them separate settings. It has
bunch of other positive sides too. Like one can now browse new path
for the application without loosing the parameters.

When starting Cppcheck version with these new settings user is warned
that loading settings had problems and asked to check and fix the
settings.
This commit is contained in:
Kimmo Varis 2011-04-02 00:53:26 +03:00
parent f34e9e6623
commit 1f7d9145b0
9 changed files with 289 additions and 185 deletions

View File

@ -1,155 +1,169 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ApplicationDialog</class>
<widget class="QDialog" name="ApplicationDialog">
<property name="windowModality">
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>569</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Add an application</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Here you can add applications that can open error files.
Specify a name for the application and the application to execute.
The following texts are replaced with appropriate values when application is executed:
(file) - Filename containing the error
(line) - Line number containing the error
(message) - Error message
(severity) - Error severity
Example opening a file with Kate and make Kate scroll to the correct line:
kate -l(line) (file)</string>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Application's name:</string>
</property>
<property name="buddy">
<cstring>mName</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Command to execute:</string>
</property>
<property name="buddy">
<cstring>mPath</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLineEdit" name="mName"/>
</item>
<item>
<widget class="QLineEdit" name="mPath"/>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="mButtonBrowse">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="mButtons">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>mName</tabstop>
<tabstop>mPath</tabstop>
<tabstop>mButtonBrowse</tabstop>
<tabstop>mButtons</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>mButtons</sender>
<signal>accepted()</signal>
<receiver>ApplicationDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>mButtons</sender>
<signal>rejected()</signal>
<receiver>ApplicationDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ApplicationDialog</class>
<widget class="QDialog" name="ApplicationDialog">
<property name="windowModality">
<enum>Qt::WindowModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>569</width>
<height>303</height>
</rect>
</property>
<property name="windowTitle">
<string>Add an application</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Here you can add applications that can open error files.
Specify a name for the application and the application to execute.
The following texts are replaced with appropriate values when application is executed:
(file) - Filename containing the error
(line) - Line number containing the error
(message) - Error message
(severity) - Error severity
Example opening a file with Kate and make Kate scroll to the correct line:
kate -l(line) (file)</string>
</property>
<property name="textFormat">
<enum>Qt::AutoText</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Application's name:</string>
</property>
<property name="buddy">
<cstring>mName</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Executable:</string>
</property>
<property name="buddy">
<cstring>mPath</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Parameters:</string>
</property>
<property name="buddy">
<cstring>mParameters</cstring>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLineEdit" name="mName"/>
</item>
<item>
<widget class="QLineEdit" name="mPath"/>
</item>
<item>
<widget class="QLineEdit" name="mParameters"/>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="mButtonBrowse">
<property name="text">
<string>Browse</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="mButtons">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<tabstops>
<tabstop>mName</tabstop>
<tabstop>mPath</tabstop>
<tabstop>mParameters</tabstop>
<tabstop>mButtons</tabstop>
<tabstop>mButtonBrowse</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>mButtons</sender>
<signal>accepted()</signal>
<receiver>ApplicationDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>mButtons</sender>
<signal>rejected()</signal>
<receiver>ApplicationDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -27,6 +27,7 @@
ApplicationDialog::ApplicationDialog(const QString &name,
const QString &path,
const QString &params,
const QString &title,
QWidget *parent) :
QDialog(parent)
@ -38,6 +39,7 @@ ApplicationDialog::ApplicationDialog(const QString &name,
connect(mUI.mButtons, SIGNAL(rejected()), this, SLOT(reject()));
mUI.mPath->setText(path);
mUI.mName->setText(name);
mUI.mParameters->setText(params);
setWindowTitle(title);
}
@ -88,13 +90,19 @@ QString ApplicationDialog::GetPath()
return mUI.mPath->text();
}
QString ApplicationDialog::GetParams()
{
return mUI.mParameters->text();
}
void ApplicationDialog::Ok()
{
if (mUI.mName->text().isEmpty() || mUI.mPath->text().isEmpty())
if (mUI.mName->text().isEmpty() || mUI.mPath->text().isEmpty() ||
mUI.mParameters->text().isEmpty())
{
QMessageBox msg(QMessageBox::Warning,
tr("Cppcheck"),
tr("You must specify a name and a path for the application!"),
tr("You must specify a name, a path and parameters for the application!"),
QMessageBox::Ok,
this);

View File

@ -44,11 +44,13 @@ public:
*
* @param name Default name for the application to start
* @param path Path for the application
* @param params Params for the application
* @param title Title for the dialog
* @param parent Parent widget
*/
ApplicationDialog(const QString &name,
const QString &path,
const QString &params,
const QString &title,
QWidget *parent = 0);
virtual ~ApplicationDialog();
@ -64,10 +66,18 @@ public:
/**
* @brief Get modified path
* This also contains all parameters user wants to specify.
* This contains the full path to the application executable.
* @return Modified path
*/
QString GetPath();
/**
* @brief Get modified parameters
* This contains the parameters given to the application.
* @return Modified path
*/
QString GetParams();
protected slots:
void Ok();

View File

@ -38,28 +38,39 @@ ApplicationList::~ApplicationList()
Clear();
}
void ApplicationList::LoadSettings(QSettings *programSettings)
bool ApplicationList::LoadSettings(QSettings *programSettings)
{
QStringList names = programSettings->value(SETTINGS_APPLICATION_NAMES, QStringList()).toStringList();
QStringList paths = programSettings->value(SETTINGS_APPLICATION_PATHS, QStringList()).toStringList();
QStringList params = programSettings->value(SETTINGS_APPLICATION_PARAMS, QStringList()).toStringList();
int defapp = programSettings->value(SETTINGS_APPLICATION_DEFAULT, -1).toInt();
if (names.empty() && paths.empty())
// Params will be empty first time starting with the new setting.
// Return false and inform user about problem with application settings.
bool succeeded = true;
if (params.empty())
{
for (int i = 0; i < paths.length(); i++)
params << "";
succeeded = false;
}
if (names.empty() && paths.empty() && params.empty())
{
do
{
// use as default for gnome environments
if (QFileInfo("/usr/bin/gedit").isExecutable())
{
AddApplication("gedit", "/usr/bin/gedit +(line) (file)");
AddApplication("gedit", "/usr/bin/gedit", "+(line) (file)");
defapp = 0;
break;
}
// use as default for kde environments
if (QFileInfo("/usr/bin/kate").isExecutable())
{
AddApplication("kate", "/usr/bin/kate -l(line) (file)");
AddApplication("kate", "/usr/bin/kate", "-l(line) (file)");
defapp = 0;
break;
}
@ -75,7 +86,7 @@ void ApplicationList::LoadSettings(QSettings *programSettings)
if (names.size() > 0 && (names.size() == paths.size()))
{
for (int i = 0; i < names.size(); i++)
AddApplication(names[i], paths[i]);
AddApplication(names[i], paths[i], params[i]);
if (defapp == -1)
mDefaultApplicationIndex = 0;
@ -84,21 +95,25 @@ void ApplicationList::LoadSettings(QSettings *programSettings)
else
mDefaultApplicationIndex = 0;
}
return succeeded;
}
void ApplicationList::SaveSettings(QSettings *programSettings)
{
QStringList names;
QStringList paths;
QStringList params;
for (int i = 0; i < GetApplicationCount(); i++)
{
names << GetApplicationName(i);
paths << GetApplicationPath(i);
params << GetApplicationParameters(i);
}
programSettings->setValue(SETTINGS_APPLICATION_NAMES, names);
programSettings->setValue(SETTINGS_APPLICATION_PATHS, paths);
programSettings->setValue(SETTINGS_APPLICATION_PARAMS, params);
programSettings->setValue(SETTINGS_APPLICATION_DEFAULT, mDefaultApplicationIndex);
}
@ -126,21 +141,34 @@ QString ApplicationList::GetApplicationPath(const int index) const
}
return QString();
}
QString ApplicationList::GetApplicationParameters(const int index) const
{
if (index >= 0 && index < mApplications.size())
{
return mApplications[index].Parameters;
}
return QString();
}
void ApplicationList::SetApplication(const int index,
const QString &name,
const QString &path)
const QString &path,
const QString &parameters)
{
if (index >= 0 && index < mApplications.size())
{
mApplications[index].Name = name;
mApplications[index].Path = path;
mApplications[index].Parameters = parameters;
}
}
void ApplicationList::AddApplication(const QString &name, const QString &path)
void ApplicationList::AddApplication(const QString &name,
const QString &path,
const QString &parameters)
{
if (name.isEmpty() || path.isEmpty())
{
@ -150,6 +178,7 @@ void ApplicationList::AddApplication(const QString &name, const QString &path)
ApplicationType type;
type.Name = name;
type.Path = path;
type.Parameters = parameters;
mApplications << type;
}
@ -176,7 +205,8 @@ void ApplicationList::Copy(const ApplicationList *list)
Clear();
for (int i = 0; i < list->GetApplicationCount(); i++)
{
AddApplication(list->GetApplicationName(i), list->GetApplicationPath(i));
AddApplication(list->GetApplicationName(i), list->GetApplicationPath(i),
list->GetApplicationParameters(i));
}
mDefaultApplicationIndex = list->GetDefaultApplication();
}
@ -193,7 +223,7 @@ bool ApplicationList::FindDefaultWindowsEditor()
const QString notepadppPath = appPath + "\\Notepad++\\notepad++.exe";
if (QFileInfo(notepadppPath).isExecutable())
{
AddApplication("Notepad++", "\"" + notepadppPath + "\" -n(line) (file)");
AddApplication("Notepad++", "\"" + notepadppPath + "\"", "-n(line) (file)");
return true;
}
@ -201,7 +231,7 @@ bool ApplicationList::FindDefaultWindowsEditor()
const QString notepadPath = windowsPath + "\\system32\\notepad.exe";
if (QFileInfo(notepadPath).isExecutable())
{
AddApplication("Notepad", notepadPath + " (file)");
AddApplication("Notepad", notepadPath, "(file)");
return true;
}
return false;

View File

@ -62,10 +62,16 @@ public:
QString Name;
/**
* @brief Application's path and commandline arguments
* @brief Application's path
*
*/
QString Path;
/**
* @brief Application's parameters
*
*/
QString Parameters;
} ApplicationType;
ApplicationList(QObject *parent = 0);
@ -75,8 +81,11 @@ public:
* @brief Load all applications
*
* @param programSettings QSettings to load application list from
* @return true if loading succeeded, false if there is problem with
* application list. Most probably because of older version settings need
* to be upgraded.
*/
void LoadSettings(QSettings *programSettings);
bool LoadSettings(QSettings *programSettings);
/**
* @brief Save all applications
@ -106,6 +115,14 @@ public:
*/
QString GetApplicationPath(const int index) const;
/**
* @brief Get Application's parameters
*
* @param index of the application whose parameters to get
* @return Application's parameters
*/
QString GetApplicationParameters(const int index) const;
/**
* @brief Return the default application.
* @return Index of the default application.
@ -121,17 +138,20 @@ public:
* @param index Index of the application to modify
* @param name New name for the application
* @param path New path for the application
* @param parameters New parameters for the application
*/
void SetApplication(const int index, const QString &name,
const QString &path);
const QString &path, const QString &parameters);
/**
* @brief Add a new application
*
* @param name Name of the application
* @param path Path to the application
* @param parameters Parameters for the application
*/
void AddApplication(const QString &name, const QString &path);
void AddApplication(const QString &name, const QString &path,
const QString &parameters);
/**
* @brief Remove an application from the list

View File

@ -77,6 +77,7 @@ ShowTypes;
#define SETTINGS_SAVE_FULL_PATH "Save full path"
#define SETTINGS_APPLICATION_NAMES "Application names"
#define SETTINGS_APPLICATION_PATHS "Application paths"
#define SETTINGS_APPLICATION_PARAMS "Application parameters"
#define SETTINGS_APPLICATION_DEFAULT "Default Application"
#define SETTINGS_LANGUAGE "Application language"
#define SETTINGS_GLOBAL_INCLUDE_PATHS "Global include paths"

View File

@ -153,9 +153,24 @@ void MainWindow::LoadSettings()
mUI.mToolBarMain->setVisible(mSettings->value(SETTINGS_TOOLBARS_MAIN_SHOW, true).toBool());
mUI.mToolBarView->setVisible(mSettings->value(SETTINGS_TOOLBARS_VIEW_SHOW, true).toBool());
mApplications->LoadSettings(mSettings);
SetLanguage(mSettings->value(SETTINGS_LANGUAGE, mTranslation->SuggestLanguage()).toString());
bool succeeded = mApplications->LoadSettings(mSettings);
if (!succeeded)
{
QString msg = tr("There was a problem with loading the editor application settings.\n\n"
"This is probably because the settings were changed between the Cppcheck versions. "
"Please check (and fix) the editor application settings, otherwise the editor "
"program might not start correctly.");
QMessageBox msgBox(QMessageBox::Warning,
tr("Cppcheck"),
msg,
QMessageBox::Ok,
this);
msgBox.exec();
}
}
void MainWindow::SaveSettings()

View File

@ -659,7 +659,7 @@ void ResultsTree::StartApplication(QStandardItem *target, int application)
QVariantMap data = target->data().toMap();
QString program = mApplications->GetApplicationPath(application);
QString params = mApplications->GetApplicationParameters(application);
//Replace (file) with filename
QString file = data["file"].toString();
@ -697,19 +697,21 @@ void ResultsTree::StartApplication(QStandardItem *target, int application)
file.append("\"");
}
program.replace("(file)", file, Qt::CaseInsensitive);
params.replace("(file)", file, Qt::CaseInsensitive);
QVariant line = data["line"];
program.replace("(line)", QString("%1").arg(line.toInt()), Qt::CaseInsensitive);
params.replace("(line)", QString("%1").arg(line.toInt()), Qt::CaseInsensitive);
program.replace("(message)", data["message"].toString(), Qt::CaseInsensitive);
program.replace("(severity)", data["severity"].toString(), Qt::CaseInsensitive);
params.replace("(message)", data["message"].toString(), Qt::CaseInsensitive);
params.replace("(severity)", data["severity"].toString(), Qt::CaseInsensitive);
bool success = QProcess::startDetached(program);
const QString program = mApplications->GetApplicationPath(application);
const QString cmdLine = QString("%1 %2").arg(program).arg(params);
bool success = QProcess::startDetached(cmdLine);
if (!success)
{
QString app = mApplications->GetApplicationName(application);
QString text = tr("Could not start %1\n\nPlease check the application path and parameters are correct.").arg(app);
QString text = tr("Could not start %1\n\nPlease check the application path and parameters are correct.").arg(program);
QMessageBox msgbox(this);
msgbox.setWindowTitle("Cppcheck");

View File

@ -198,11 +198,12 @@ void SettingsDialog::SaveCheckboxValue(QCheckBox *box, const QString &name)
void SettingsDialog::AddApplication()
{
ApplicationDialog dialog("", "", tr("Add a new application"), this);
ApplicationDialog dialog("", "", "", tr("Add a new application"), this);
if (dialog.exec() == QDialog::Accepted)
{
mTempApplications->AddApplication(dialog.GetName(), dialog.GetPath());
mTempApplications->AddApplication(dialog.GetName(), dialog.GetPath(),
dialog.GetParams());
mUI.mListWidget->addItem(dialog.GetName());
}
}
@ -236,11 +237,14 @@ void SettingsDialog::EditApplication()
ApplicationDialog dialog(mTempApplications->GetApplicationName(row),
mTempApplications->GetApplicationPath(row),
mTempApplications->GetApplicationParameters(row),
tr("Modify an application"), this);
if (dialog.exec() == QDialog::Accepted)
{
mTempApplications->SetApplication(row, dialog.GetName(), dialog.GetPath());
mTempApplications->SetApplication(row, dialog.GetName(),
dialog.GetPath(),
dialog.GetParams());
item->setText(dialog.GetName());
}
}