diff --git a/gui/application.ui b/gui/application.ui index 06ef4a358..190712a16 100644 --- a/gui/application.ui +++ b/gui/application.ui @@ -1,155 +1,169 @@ - - - ApplicationDialog - - - Qt::WindowModal - - - - 0 - 0 - 569 - 300 - - - - Add an application - - - - - - 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) - - - Qt::AutoText - - - - - - - - - - - Application's name: - - - mName - - - - - - - Command to execute: - - - mPath - - - - - - - - - - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Browse - - - - - - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - mName - mPath - mButtonBrowse - mButtons - - - - - mButtons - accepted() - ApplicationDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - mButtons - rejected() - ApplicationDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - - + + + ApplicationDialog + + + Qt::WindowModal + + + + 0 + 0 + 569 + 303 + + + + Add an application + + + + + + 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) + + + Qt::AutoText + + + + + + + + + + + Application's name: + + + mName + + + + + + + Executable: + + + mPath + + + + + + + Parameters: + + + mParameters + + + + + + + + + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Browse + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + mName + mPath + mParameters + mButtons + mButtonBrowse + + + + + mButtons + accepted() + ApplicationDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + mButtons + rejected() + ApplicationDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/gui/applicationdialog.cpp b/gui/applicationdialog.cpp index ecaeb9691..b84b1e294 100644 --- a/gui/applicationdialog.cpp +++ b/gui/applicationdialog.cpp @@ -27,6 +27,7 @@ ApplicationDialog::ApplicationDialog(const QString &name, const QString &path, + const QString ¶ms, 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); diff --git a/gui/applicationdialog.h b/gui/applicationdialog.h index 0cb697fa8..7aca8a967 100644 --- a/gui/applicationdialog.h +++ b/gui/applicationdialog.h @@ -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 ¶ms, 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(); diff --git a/gui/applicationlist.cpp b/gui/applicationlist.cpp index 7dada872b..beb0f6761 100644 --- a/gui/applicationlist.cpp +++ b/gui/applicationlist.cpp @@ -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 ¶meters) { 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 ¶meters) { 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; diff --git a/gui/applicationlist.h b/gui/applicationlist.h index 9bad886a8..be395ca52 100644 --- a/gui/applicationlist.h +++ b/gui/applicationlist.h @@ -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 ¶meters); /** * @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 ¶meters); /** * @brief Remove an application from the list diff --git a/gui/common.h b/gui/common.h index 6d9383ad2..bbe2f4821 100644 --- a/gui/common.h +++ b/gui/common.h @@ -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" diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 6c44b0407..168dbb71c 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -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() diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 90e785d04..1c9ad31af 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -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"); diff --git a/gui/settingsdialog.cpp b/gui/settingsdialog.cpp index ca78c1d9d..e9b229fbb 100644 --- a/gui/settingsdialog.cpp +++ b/gui/settingsdialog.cpp @@ -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()); } }