diff --git a/gui/cppcheck_de.ts b/gui/cppcheck_de.ts index 960f7dcff..9e28aaf2b 100644 --- a/gui/cppcheck_de.ts +++ b/gui/cppcheck_de.ts @@ -128,15 +128,15 @@ kate -l(line) (file) MainWindow - - - - + + + + Cppcheck - + Standard @@ -146,265 +146,275 @@ kate -l(line) (file) - + &View - + &Toolbars - + &Check - + &Edit - + &License... - + A&uthors... - + &About... - + &Files... - + Ctrl+F - + &Directory... - + Ctrl+D - + &Recheck files - + Ctrl+R - + &Stop - + Esc - + &Save results to file... - + Ctrl+S - + &Quit - + &Clear results - + &Preferences - + Show style errors - + Show common errors - + &Check all - + &Uncheck all - + Collapse &all - + &Expand all - + &Standard - + Standard items - + Toolbar - + &Categories - + Error categories - + &Open XML... - + + Open P&roject File... + + + + + &New Project File... + + + + &Contents - + Categories - + Open the help contents - + F1 - + &Language - + &Help - + Select files to check - + Select directory to check - + No suitable files found to check! - - Open the report file - - - - + Cannot exit while checking. Stop the checking before exiting. - + License - + Authors - + XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) - + Save the report file - - + + XML files (*.xml) - + + Open the report file + + + + Text files (*.txt) - + CSV files (*.csv) - + Cppcheck - %1 - + Failed to change the language: %1 @@ -415,6 +425,22 @@ Stop the checking before exiting. %1 + + + + Project files (*.cppcheck);;All files(*.*) + + + + + Select Project File + + + + + Select Project Filename + + Finnish @@ -451,6 +477,51 @@ Stop the checking before exiting. + + Project + + + + Cppcheck + + + + + Could not read the project file. + + + + + Could not write the project file. + + + + + ProjectFile + + + Project File + + + + + Include paths: + + + + + Defines: + + + + + ProjectFileDialog + + + Project file: %1 + + + QObject diff --git a/gui/cppcheck_en.ts b/gui/cppcheck_en.ts index a1292eba6..c42a0f1e1 100644 --- a/gui/cppcheck_en.ts +++ b/gui/cppcheck_en.ts @@ -141,15 +141,15 @@ kate -l(line) (file) MainWindow - - - - + + + + Cppcheck Cppcheck - + Standard Standard @@ -159,217 +159,222 @@ kate -l(line) (file) &File - + &View &View - + &Toolbars - + &Check &Check - + &Edit &Edit - + &License... &License... - + A&uthors... A&uthors... - + &About... &About... - + &Files... &Files... - + Ctrl+F Ctrl+F - + &Directory... &Directory... - + Ctrl+D Ctrl+D - + &Recheck files &Recheck files - + Ctrl+R Ctrl+R - + &Stop &Stop - + Esc Esc - + &Save results to file... &Save results to file... - + Ctrl+S Ctrl+S - + &Quit &Quit - + &Clear results &Clear results - + &Preferences &Preferences - + Show style errors Show style errors - + Show common errors Show common errors - + &Check all &Check all - + &Uncheck all &Uncheck all - + Collapse &all Collapse &all - + &Expand all &Expand all - + &Standard - + Standard items - + Toolbar - + &Categories - + Error categories - + &Open XML... - + + Open P&roject File... + + + + + &New Project File... + + + + &Contents - + Categories - + Open the help contents - + F1 - + &Language &Language - + &Help &Help - + Select files to check Select files to check - + Select directory to check Select directory to check - + No suitable files found to check! No suitable files found to check! - - Open the report file - - - - + Cannot exit while checking. Stop the checking before exiting. @@ -378,48 +383,53 @@ Stop the checking before exiting. Stop the checking before exiting. - + License License - + Authors Authors - + XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) - + Save the report file Save the report file - - + + XML files (*.xml) XML files (*.xml) - + + Open the report file + + + + Text files (*.txt) Text files (*.txt) - + CSV files (*.csv) - + Cppcheck - %1 Cppcheck - %1 - + Failed to change the language: %1 @@ -432,6 +442,22 @@ Stop the checking before exiting. %1 + + + + Project files (*.cppcheck);;All files(*.*) + + + + + Select Project File + + + + + Select Project Filename + + Finnish @@ -468,6 +494,51 @@ Stop the checking before exiting. Polish + + Project + + + + Cppcheck + Cppcheck + + + + Could not read the project file. + + + + + Could not write the project file. + + + + + ProjectFile + + + Project File + + + + + Include paths: + + + + + Defines: + + + + + ProjectFileDialog + + + Project file: %1 + + + QObject diff --git a/gui/cppcheck_fi.ts b/gui/cppcheck_fi.ts index d962b2729..1e45bf547 100644 --- a/gui/cppcheck_fi.ts +++ b/gui/cppcheck_fi.ts @@ -143,15 +143,15 @@ kate -l(line) (file) MainWindow - - - - + + + + Cppcheck Cppcheck - + Standard Vakio @@ -161,217 +161,222 @@ kate -l(line) (file) &Tiedosto - + &View &Näytä - + &Toolbars - + &Check &Tarkista - + &Edit &Muokkaa - + &License... &Lisenssi... - + A&uthors... &Tekijät... - + &About... &Tietoa ohjelmasta Cppcheck... - + &Files... &Tiedostot... - + Ctrl+F Ctrl+F - + &Directory... &Hakemisto... - + Ctrl+D Ctrl+D - + &Recheck files Tarkista tiedostot &uudelleen - + Ctrl+R Ctrl+R - + &Stop &Pysäytä - + Esc Esc - + &Save results to file... &Tallenna tulokset tiedostoon... - + Ctrl+S Ctrl+S - + &Quit &Lopeta - + &Clear results &Tyhjennä tulokset - + &Preferences &Asetukset - + Show style errors Näytä tyylivirheet - + Show common errors Näytä yleiset virheet - + &Check all &Valitse kaikki - + &Uncheck all &Poista kaikista valinta - + Collapse &all &Pienennä kaikki - + &Expand all &Laajenna kaikki - + &Standard - + Standard items - + Toolbar - + &Categories - + Error categories - + &Open XML... - + + Open P&roject File... + + + + + &New Project File... + + + + &Contents - + Categories - + Open the help contents - + F1 - + &Language &Kieli - + &Help &Ohje - + Select files to check Valitse tarkistettavat tiedostot - + Select directory to check Valitse tarkistettava hakemisto - + No suitable files found to check! Tarkistettavaksi sopivia tiedostoja ei löytynyt! - - Open the report file - - - - + Cannot exit while checking. Stop the checking before exiting. @@ -380,48 +385,53 @@ Stop the checking before exiting. Lopeta tarkistus ennen ohjelman sammuttamista. - + License Lisenssi - + Authors Tekijät - + XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) XML-tiedostot (*.xml);;Tekstitiedostot (*.txt);;CSV-tiedostot (*.csv) - + Save the report file Tallenna raportti - - + + XML files (*.xml) XML-tiedostot (*xml) - + + Open the report file + + + + Text files (*.txt) Tekstitiedostot (*.txt) - + CSV files (*.csv) - + Cppcheck - %1 Cppcheck - %1 - + Failed to change the language: %1 @@ -436,6 +446,22 @@ Lopeta tarkistus ennen ohjelman sammuttamista. + + + + Project files (*.cppcheck);;All files(*.*) + + + + + Select Project File + + + + + Select Project Filename + + Finnish @@ -472,6 +498,51 @@ Lopeta tarkistus ennen ohjelman sammuttamista. Puola + + Project + + + + Cppcheck + Cppcheck + + + + Could not read the project file. + + + + + Could not write the project file. + + + + + ProjectFile + + + Project File + + + + + Include paths: + + + + + Defines: + + + + + ProjectFileDialog + + + Project file: %1 + + + QObject diff --git a/gui/cppcheck_nl.ts b/gui/cppcheck_nl.ts index d52970c59..822e4ec5e 100644 --- a/gui/cppcheck_nl.ts +++ b/gui/cppcheck_nl.ts @@ -141,15 +141,15 @@ kate -l(line) (file) MainWindow - - - - + + + + Cppcheck Cppcheck - + Standard Standaard @@ -159,217 +159,222 @@ kate -l(line) (file) &Bestand - + &View &Weergave - + &Toolbars - + &Check &Controleer - + &Edit Be&werken - + &License... &Licentie... - + A&uthors... A&uteurs... - + &About... &Over... - + &Files... &Bestanden... - + Ctrl+F Ctrl+F - + &Directory... &Mappen... - + Ctrl+D Ctrl+D - + &Recheck files &Opnieuw controleren - + Ctrl+R Ctrl+R - + &Stop &Stop - + Esc Esc - + &Save results to file... &Resultaten opslaan... - + Ctrl+S Ctrl+S - + &Quit &Afsluiten - + &Clear results &Resultaten wissen - + &Preferences &Voorkeuren - + Show style errors Toon stijl fouten - + Show common errors Toon gewone fouten - + &Check all &Selecteer alles - + &Uncheck all Selecteer &niets - + Collapse &all Alles Inkl&appen - + &Expand all Alles &Uitklappen - + &Standard - + Standard items - + Toolbar - + &Categories - + Error categories - + &Open XML... - + + Open P&roject File... + + + + + &New Project File... + + + + &Contents - + Categories - + Open the help contents - + F1 - + &Language &Taal - + &Help &Help - + Select files to check Selecteer bestanden om te controleren - + Select directory to check Selecteer een map om te controleren - + No suitable files found to check! Geen geschikte bestanden gevonden om te controleren! - - Open the report file - - - - + Cannot exit while checking. Stop the checking before exiting. @@ -378,48 +383,53 @@ Stop the checking before exiting. Stop de controle alvorens te sluiten. - + License Licentie - + Authors Auteurs - + XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) XML bestanden (*.xml);;Tekst bestanden (*.txt);;CSV bestanden (*.csv) - + Save the report file Rapport opslaan - - + + XML files (*.xml) XML bestanden (*.xml) - + + Open the report file + + + + Text files (*.txt) Tekst bestanden (*.txt) - + CSV files (*.csv) - + Cppcheck - %1 Cppcheck - %1 - + Failed to change the language: %1 @@ -432,6 +442,22 @@ Stop de controle alvorens te sluiten. %1 + + + + Project files (*.cppcheck);;All files(*.*) + + + + + Select Project File + + + + + Select Project Filename + + Finnish @@ -468,6 +494,51 @@ Stop de controle alvorens te sluiten. Pools + + Project + + + + Cppcheck + Cppcheck + + + + Could not read the project file. + + + + + Could not write the project file. + + + + + ProjectFile + + + Project File + + + + + Include paths: + + + + + Defines: + + + + + ProjectFileDialog + + + Project file: %1 + + + QObject diff --git a/gui/cppcheck_pl.ts b/gui/cppcheck_pl.ts index 49c8a7820..328fbeed8 100644 --- a/gui/cppcheck_pl.ts +++ b/gui/cppcheck_pl.ts @@ -128,10 +128,10 @@ kate -l(line) (file) MainWindow - - - - + + + + Cppcheck @@ -141,270 +141,285 @@ kate -l(line) (file) - + &View - + &Toolbars - + &Language - + &Help - + &Check - + &Edit - + Standard - + &License... - + A&uthors... - + &About... - + &Files... - + Ctrl+F - + &Directory... - + Ctrl+D - + &Recheck files - + Ctrl+R - + &Stop - + Esc - + &Save results to file... - + Ctrl+S - + &Quit - + &Clear results - + &Preferences - + Show style errors - + Show common errors - + &Check all - + &Uncheck all - + Collapse &all - + &Expand all - + &Standard - + Standard items - + Toolbar - + &Categories - + Error categories - + &Open XML... - + + Open P&roject File... + + + + + &New Project File... + + + + &Contents - + Categories - + Open the help contents - + F1 - + No suitable files found to check! - + Select files to check - + Select directory to check - + Open the report file - + Cannot exit while checking. Stop the checking before exiting. - + License - + Authors - + XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) - + Save the report file - - + + Select Project Filename + + + + + XML files (*.xml) - + Text files (*.txt) - + CSV files (*.csv) - + Cppcheck - %1 - + Failed to change the language: %1 @@ -412,6 +427,17 @@ Stop the checking before exiting. + + + + Project files (*.cppcheck);;All files(*.*) + + + + + Select Project File + + English @@ -448,6 +474,51 @@ Stop the checking before exiting. + + Project + + + + Cppcheck + + + + + Could not read the project file. + + + + + Could not write the project file. + + + + + ProjectFile + + + Project File + + + + + Include paths: + + + + + Defines: + + + + + ProjectFileDialog + + + Project file: %1 + + + QObject diff --git a/gui/cppcheck_ru.ts b/gui/cppcheck_ru.ts index 73a38de0d..02c1f88c0 100644 --- a/gui/cppcheck_ru.ts +++ b/gui/cppcheck_ru.ts @@ -131,15 +131,15 @@ kate -l(line) (file) MainWindow - - - - + + + + Cppcheck Cppcheck - + Standard @@ -149,265 +149,275 @@ kate -l(line) (file) Файл - + &View Вид - + &Toolbars - + &Check Проверить - + &Edit Правка - + &License... Лицензия... - + A&uthors... Авторы... - + &About... О программе... - + &Files... Файлы... - + Ctrl+F Ctrl+F - + &Directory... Каталог... - + Ctrl+D Ctrl+D - + &Recheck files - + Ctrl+R Ctrl+R - + &Stop Остановить - + Esc Esc - + &Save results to file... Сохранить отчёт в файл... - + Ctrl+S Ctrl+S - + &Quit Выход - + &Clear results Очистить отчёт - + &Preferences Параметры - + Show style errors Показывать ошибки стиля - + Show common errors Показывать общие ошибки - + &Check all Отметить все - + &Uncheck all Сбросить все - + Collapse &all Свернуть все - + &Expand all Развернуть все - + &Standard - + Standard items - + Toolbar - + &Categories - + Error categories - + &Open XML... - + + Open P&roject File... + + + + + &New Project File... + + + + &Contents - + Categories - + Open the help contents - + F1 - + &Language Язык - + &Help Помощь - + Select files to check Выберите файлы для проверки - + Select directory to check Выберите каталог для проверки - + No suitable files found to check! - - Open the report file - - - - + Cannot exit while checking. Stop the checking before exiting. - + License Лицензия - + Authors Авторы - + XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) - + Save the report file - - + + XML files (*.xml) - + + Open the report file + + + + Text files (*.txt) Текстовые файлы (*.txt) - + CSV files (*.csv) - + Cppcheck - %1 Cppcheck - %1 - + Failed to change the language: %1 @@ -422,6 +432,22 @@ Stop the checking before exiting. + + + + Project files (*.cppcheck);;All files(*.*) + + + + + Select Project File + + + + + Select Project Filename + + Finnish @@ -458,6 +484,51 @@ Stop the checking before exiting. + + Project + + + + Cppcheck + Cppcheck + + + + Could not read the project file. + + + + + Could not write the project file. + + + + + ProjectFile + + + Project File + + + + + Include paths: + + + + + Defines: + + + + + ProjectFileDialog + + + Project file: %1 + + + QObject diff --git a/gui/cppcheck_se.ts b/gui/cppcheck_se.ts index 3a19447e8..f1e6f87e7 100644 --- a/gui/cppcheck_se.ts +++ b/gui/cppcheck_se.ts @@ -141,15 +141,15 @@ kate -l(line) (file) MainWindow - - - - + + + + Cppcheck Cppcheck - + Standard Standard @@ -159,266 +159,276 @@ kate -l(line) (file) &Arkiv - + &View &Visa - + &Toolbars Verktygsfält - + &Check &Check - + &Edit &Redigera - + &License... &Licens... - + A&uthors... &Utvecklat av... - + &About... &Om... - + &Files... &Filer... - + Ctrl+F Ctrl+F - + &Directory... &Katalog... - + Ctrl+D Ctrl+D - + &Recheck files Starta &om check - + Ctrl+R Ctrl+R - + &Stop &Stoppa - + Esc Esc - + &Save results to file... &Spara resultat till fil... - + Ctrl+S Ctrl+S - + &Quit &Avsluta - + &Clear results &Töm resultat - + &Preferences &Inställningar - + Show style errors Visa stilvarningar - + Show common errors Visa vanliga fel - + &Check all &Kryssa alla - + &Uncheck all Kryssa &ur alla - + Collapse &all Ingen bra översättning! &Fäll ihop alla - + &Expand all &Expandera alla - + &Standard &Standard - + Standard items Standard poster - + Toolbar Verktygsfält - + &Categories &Kategorier - + Error categories Fel kategorier - + &Open XML... - + + Open P&roject File... + + + + + &New Project File... + + + + &Contents &Innehåll - + Categories Kategorier - + Open the help contents Öppna hjälp - + F1 F1 - + &Language &Språk - + &Help &Hjälp - + Select files to check Välj filer att kontrollera - + Select directory to check Välj katalog som skall kontrolleras - + No suitable files found to check! Inga lämpliga filer hittades! - - Open the report file - - - - + Cannot exit while checking. Stop the checking before exiting. Kan ej avsluta medans check pågår. - + License Licens - + Authors Utvecklare - + XML files (*.xml);;Text files (*.txt);;CSV files (*.csv) XML filer (*.xml);;Text filer (*.txt);;CSV filer (*.csv) - + Save the report file Spara rapport - - + + XML files (*.xml) XML filer (*.xml) - + + Open the report file + + + + Text files (*.txt) Text filer (*.txt) - + CSV files (*.csv) CSV filer (*.csv) - + Cppcheck - %1 Cppcheck - %1 - + Failed to change the language: %1 @@ -433,6 +443,22 @@ Stop the checking before exiting. + + + + Project files (*.cppcheck);;All files(*.*) + + + + + Select Project File + + + + + Select Project Filename + + Finnish @@ -469,6 +495,51 @@ Stop the checking before exiting. Polska + + Project + + + + Cppcheck + Cppcheck + + + + Could not read the project file. + + + + + Could not write the project file. + + + + + ProjectFile + + + Project File + + + + + Include paths: + + + + + Defines: + + + + + ProjectFileDialog + + + Project file: %1 + + + QObject diff --git a/gui/gui.cppcheck b/gui/gui.cppcheck index 62d44c9d1..632b61115 100644 --- a/gui/gui.cppcheck +++ b/gui/gui.cppcheck @@ -1,9 +1,6 @@ - - - - - - - - - + + + + + + diff --git a/gui/gui.pro b/gui/gui.pro index 84265f8ea..3e1de7f02 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -25,6 +25,7 @@ FORMS = main.ui \ application.ui \ settings.ui \ file.ui \ + projectfile.ui \ about.ui TRANSLATIONS = cppcheck_fi.ts \ @@ -52,7 +53,9 @@ HEADERS += mainwindow.h \ common.h \ erroritem.h \ fileviewdialog.h \ + project.h \ projectfile.h \ + projectfiledialog.h \ report.h \ txtreport.h \ xmlreport.h \ @@ -70,7 +73,9 @@ SOURCES += main.cpp \ applicationdialog.cpp \ aboutdialog.cpp \ fileviewdialog.cpp \ + project.cpp \ projectfile.cpp \ + projectfiledialog.cpp \ erroritem.cpp \ report.cpp \ txtreport.cpp \ diff --git a/gui/main.ui b/gui/main.ui index 3317d4452..939106b55 100644 --- a/gui/main.ui +++ b/gui/main.ui @@ -74,6 +74,8 @@ &File + + @@ -353,6 +355,16 @@ &Open XML... + + + Open P&roject File... + + + + + &New Project File... + + diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 34ec7c1de..e4e15e1ef 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -31,6 +31,7 @@ #include "threadhandler.h" #include "fileviewdialog.h" #include "projectfile.h" +#include "project.h" #include "report.h" #include "../lib/filelister.h" @@ -80,6 +81,9 @@ MainWindow::MainWindow() : connect(mUI.mResults, SIGNAL(GotResults()), this, SLOT(ResultsAdded())); connect(mUI.mMenuView, SIGNAL(aboutToShow()), this, SLOT(AboutToShowViewMenu())); + connect(mUI.mActionNewProjectFile, SIGNAL(triggered()), this, SLOT(NewProjectFile())); + connect(mUI.mActionOpenProjectFile, SIGNAL(triggered()), this, SLOT(OpenProjectFile())); + #ifdef WIN32 connect(mUI.mActionHelpContents, SIGNAL(triggered()), this, SLOT(OpenHelpContents())); #else @@ -231,6 +235,8 @@ void MainWindow::DoCheckFiles(const QStringList &files) EnableCheckButtons(false); mUI.mActionSettings->setEnabled(false); mUI.mActionOpenXML->setEnabled(false); + mUI.mActionNewProjectFile->setEnabled(false); + mUI.mActionOpenProjectFile->setEnabled(false); mUI.mResults->SetCheckDirectory(absDirectory); @@ -392,6 +398,9 @@ void MainWindow::CheckDone() EnableCheckButtons(true); mUI.mActionSettings->setEnabled(true); mUI.mActionOpenXML->setEnabled(true); + mUI.mActionNewProjectFile->setEnabled(false); + mUI.mActionOpenProjectFile->setEnabled(false); + if (mUI.mResults->HasResults()) { mUI.mActionClearResults->setEnabled(true); @@ -680,3 +689,35 @@ void MainWindow::OpenHtmlHelpContents() HtmlHelp(NULL, exeFolder.utf16(), HH_DISPLAY_TOPIC, NULL); #endif // WIN32 } + +void MainWindow::OpenProjectFile() +{ + const QString filter = tr("Project files (*.cppcheck);;All files(*.*)"); + QString filepath = QFileDialog::getOpenFileName(this, + tr("Select Project File"), + QString(), + filter); + + if (!filepath.isEmpty()) + { + Project prj(filepath, this); + if (prj.Open()) + prj.Edit(); + } +} + +void MainWindow::NewProjectFile() +{ + const QString filter = tr("Project files (*.cppcheck);;All files(*.*)"); + QString filepath = QFileDialog::getSaveFileName(this, + tr("Select Project Filename"), + QString(), + filter); + + if (!filepath.isEmpty()) + { + Project prj(filepath, this); + prj.Create(); + prj.Edit(); + } +} diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 3142dccaa..1c8cae8b2 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -131,6 +131,18 @@ public slots: */ void Save(); + /** + * @brief Slot to create new project file.. + * + */ + void NewProjectFile(); + + /** + * @brief Slot to edit existing project file. + * + */ + void OpenProjectFile(); + protected slots: /** diff --git a/gui/project.cpp b/gui/project.cpp new file mode 100644 index 000000000..5d4f89661 --- /dev/null +++ b/gui/project.cpp @@ -0,0 +1,108 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2010 Daniel Marjamki and Cppcheck team. + * + * 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 + * along with this program. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include "project.h" +#include "projectfile.h" +#include "projectfiledialog.h" + +Project::Project(QWidget *parent) : + QObject(parent), + mPFile(NULL), + mParentWidget(parent) +{ +} + +Project::Project(const QString &filename, QWidget *parent) : + QObject(parent), + mFilename(filename), + mPFile(NULL), + mParentWidget(parent) +{ +} + +Project::~Project() +{ + delete mPFile; +} + +void Project::SetFilename(const QString &filename) +{ + mFilename = filename; +} + +bool Project::Open() +{ + mPFile = new ProjectFile(mFilename, this); + if (QFile::exists(mFilename)) + { + if (!mPFile->Read()) + { + QMessageBox msg(QMessageBox::Critical, + tr("Cppcheck"), + tr("Could not read the project file."), + QMessageBox::Ok, + mParentWidget); + msg.exec(); + mFilename = QString(); + mPFile->SetFilename(mFilename); + return false; + } + return true; + } + return false; +} + +void Project::Edit() +{ + ProjectFileDialog dlg(mFilename, mParentWidget); + + QStringList includes = mPFile->GetIncludeDirs(); + dlg.SetIncludepaths(includes); + QStringList defines = mPFile->GetDefines(); + dlg.SetDefines(defines); + int rv = dlg.exec(); + if (rv == QDialog::Accepted) + { + QStringList includes = dlg.GetIncludePaths(); + mPFile->SetIncludes(includes); + QStringList defines = dlg.GetDefines(); + mPFile->SetDefines(defines); + bool writeSuccess = mPFile->Write(); + if (!writeSuccess) + { + QMessageBox msg(QMessageBox::Critical, + tr("Cppcheck"), + tr("Could not write the project file."), + QMessageBox::Ok, + mParentWidget); + msg.exec(); + } + } +} + +void Project::Create() +{ + mPFile = new ProjectFile(mFilename, this); +} diff --git a/gui/project.h b/gui/project.h new file mode 100644 index 000000000..146375d88 --- /dev/null +++ b/gui/project.h @@ -0,0 +1,74 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2010 Daniel Marjamki and Cppcheck team. + * + * 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 + * along with this program. If not, see . + */ + +#ifndef PROJECT_H +#define PROJECT_H + +#include +#include + +class QWidget; +class ProjectFile; + +/// @addtogroup GUI +/// @{ + +/** +* @brief A class that contains project data and manages projects. +* Currently only project file creation and editing is implemented. +*/ +class Project : public QObject +{ + Q_OBJECT + +public: + Project(QWidget *parent = 0); + Project(const QString &filename, QWidget *parent = 0); + ~Project(); + + /** + * @brief Set filename for the project file. + * @param filename Filename. + */ + void SetFilename(const QString &filename); + + /** + * @brief Open existing project file. + */ + bool Open(); + + /** + * @brief Edit the project file. + */ + void Edit(); + + /** + * @brief Create new project file. + */ + void Create(); + +private: + + QString mFilename; + ProjectFile *mPFile; + QWidget *mParentWidget; +}; + +/// @} + +#endif // PROJECT_H diff --git a/gui/projectfile.cpp b/gui/projectfile.cpp index 4d73bccaf..9cf2cc7fb 100644 --- a/gui/projectfile.cpp +++ b/gui/projectfile.cpp @@ -19,10 +19,13 @@ #include #include #include +#include #include #include "projectfile.h" static const char ProjectElementName[] = "project"; +static const char ProjectVersionAttrib[] = "version"; +static const char ProjectFileVersion[] = "1"; static const char IncludDirElementName[] = "includedir"; static const char DirElementName[] = "dir"; static const char DirNameAttrib[] = "name"; @@ -52,13 +55,17 @@ bool ProjectFile::Read(const QString &filename) QXmlStreamReader xmlReader(&file); bool insideProject = false; + bool projectTagFound = false; while (!xmlReader.atEnd()) { switch (xmlReader.readNext()) { case QXmlStreamReader::StartElement: if (xmlReader.name() == ProjectElementName) + { insideProject = true; + projectTagFound = true; + } // Find include directory from inside project element if (insideProject && xmlReader.name() == IncludDirElementName) @@ -90,7 +97,10 @@ bool ProjectFile::Read(const QString &filename) } file.close(); - return true; + if (projectTagFound) + return true; + else + return false; } QStringList ProjectFile::GetIncludeDirs() const @@ -185,3 +195,58 @@ void ProjectFile::ReadDefines(QXmlStreamReader &reader) } while (!allRead); } + +void ProjectFile::SetIncludes(QStringList includes) +{ + mIncludeDirs = includes; +} + +void ProjectFile::SetDefines(QStringList defines) +{ + mDefines = defines; +} + +bool ProjectFile::Write(const QString &filename) +{ + if (!filename.isEmpty()) + mFilename = filename; + + QFile file(mFilename); + if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) + return false; + + QXmlStreamWriter xmlWriter(&file); + xmlWriter.setAutoFormatting(true); + xmlWriter.writeStartDocument("1.0"); + xmlWriter.writeStartElement(ProjectElementName); + xmlWriter.writeAttribute(ProjectVersionAttrib, ProjectFileVersion); + + if (!mIncludeDirs.isEmpty()) + { + xmlWriter.writeStartElement(IncludDirElementName); + QString incdir; + foreach(incdir, mIncludeDirs) + { + xmlWriter.writeStartElement(DirElementName); + xmlWriter.writeAttribute(DirNameAttrib, incdir); + xmlWriter.writeEndElement(); + } + xmlWriter.writeEndElement(); + } + + if (!mDefines.isEmpty()) + { + xmlWriter.writeStartElement(DefinesElementName); + QString define; + foreach(define, mDefines) + { + xmlWriter.writeStartElement(DefineName); + xmlWriter.writeAttribute(DefineNameAttrib, define); + xmlWriter.writeEndElement(); + } + xmlWriter.writeEndElement(); + } + xmlWriter.writeEndDocument(); + file.close(); + return true; +} diff --git a/gui/projectfile.h b/gui/projectfile.h index 09e82a9ce..afbcb8f85 100644 --- a/gui/projectfile.h +++ b/gui/projectfile.h @@ -31,7 +31,7 @@ /** * @brief A class that reads and writes (TODO) project files. * The project files contain project-specific settings for checking. For -* example a list of automatically deallocated classes. +* example a list of include paths. */ class ProjectFile : public QObject { @@ -59,6 +59,33 @@ public: */ QStringList GetDefines() const; + /** + * @brief Set list of includes. + * @param includes List of defines. + */ + void SetIncludes(QStringList includes); + + /** + * @brief Set list of defines. + * @param defines List of defines. + */ + void SetDefines(QStringList defines); + + /** + * @brief Write project file (to disk). + * @param filename Filename to use. + */ + bool Write(const QString &filename = QString()); + + /** + * @brief Set filename for the project file. + * @param filename Filename to use. + */ + void SetFilename(const QString &filename) + { + mFilename = filename; + } + protected: /** * @brief Read list of include directories from XML. diff --git a/gui/projectfile.txt b/gui/projectfile.txt index c7069e3ff..f22c49a82 100644 --- a/gui/projectfile.txt +++ b/gui/projectfile.txt @@ -4,20 +4,15 @@ Project files cppcheck GUI handles per-project settings in project files instead of global program settings. This allows customizing cppcheck for each project's needs. -Currently there is no GUI to edit the project file. The cppcheck automatically -loads a project file which has same name than selected directory and extension -".cppcheck". For example in "gui"-directory cppcheck loads "gui.cppcheck" -project file. +The cppcheck automatically loads a project file which has same name than +selected directory and extension ".cppcheck". For example in "gui"-directory +cppcheck loads "gui.cppcheck" project file. The project file is simple XML file easy to edit with your favourite editor program. The format is: - - - - diff --git a/gui/projectfile.ui b/gui/projectfile.ui new file mode 100644 index 000000000..fd005658e --- /dev/null +++ b/gui/projectfile.ui @@ -0,0 +1,111 @@ + + + ProjectFile + + + + 0 + 0 + 400 + 112 + + + + Project File + + + + + + + + Include paths: + + + mEditIncludePaths + + + + + + + + + + + + + + Defines: + + + mEditDefines + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + mButtons + accepted() + ProjectFile + accept() + + + 248 + 254 + + + 157 + 274 + + + + + mButtons + rejected() + ProjectFile + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/gui/projectfiledialog.cpp b/gui/projectfiledialog.cpp new file mode 100644 index 000000000..319505380 --- /dev/null +++ b/gui/projectfiledialog.cpp @@ -0,0 +1,94 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2010 Daniel Marjamki and Cppcheck team. + * + * 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 + * along with this program. If not, see . + */ + +#include +#include +#include "projectfiledialog.h" + +ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent) + : QDialog(parent) +{ + mUI.setupUi(this); + + QFileInfo inf(path); + QString filename = inf.fileName(); + QString title = tr("Project file: %1").arg(filename); + setWindowTitle(title); + + connect(mUI.mButtons, SIGNAL(accepted()), this, SLOT(accept())); +} + +QStringList ProjectFileDialog::GetIncludePaths() const +{ + QString include = mUI.mEditIncludePaths->text(); + QStringList includes; + if (!include.isEmpty()) + { + include = include.trimmed(); + if (include.indexOf(';') != -1) + includes = include.split(";"); + else + includes.append(include); + } + return includes; +} + +QStringList ProjectFileDialog::GetDefines() const +{ + QString define = mUI.mEditDefines->text(); + QStringList defines; + if (!define.isEmpty()) + { + define = define.trimmed(); + if (define.indexOf(';') != -1) + defines = define.split(";"); + else + defines.append(define); + } + return defines; +} + +void ProjectFileDialog::SetIncludepaths(const QStringList &includes) +{ + QString includestr; + QString dir; + foreach(dir, includes) + { + includestr += dir; + includestr += ";"; + } + // Remove ; from the end of the string + if (includestr.endsWith(';')) + includestr = includestr.left(includestr.length() - 1); + mUI.mEditIncludePaths->setText(includestr); +} + +void ProjectFileDialog::SetDefines(const QStringList &defines) +{ + QString definestr; + QString define; + foreach(define, defines) + { + definestr += define; + definestr += ";"; + } + // Remove ; from the end of the string + if (definestr.endsWith(';')) + definestr = definestr.left(definestr.length() - 1); + mUI.mEditDefines->setText(definestr); +} diff --git a/gui/projectfiledialog.h b/gui/projectfiledialog.h new file mode 100644 index 000000000..c3252fe35 --- /dev/null +++ b/gui/projectfiledialog.h @@ -0,0 +1,71 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2010 Daniel Marjamki and Cppcheck team. + * + * 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 + * along with this program. If not, see . + */ + +#ifndef PROJECTFILE_DIALOG_H +#define PROJECTFILE_DIALOG_H + +#include +#include + +#include "ui_projectfile.h" + +class ProjectFile; + +/// @addtogroup GUI +/// @{ + + +/** +* @brief A dialog for editing project file data. +*/ +class ProjectFileDialog : public QDialog +{ + Q_OBJECT +public: + ProjectFileDialog(const QString &path, QWidget *parent = 0); + + /** + * @brief Return include paths from the dialog control. + * @return List of include paths. + */ + QStringList GetIncludePaths() const; + + /** + * @brief Return define names from the dialog control. + * @return List of define names. + */ + QStringList GetDefines() const; + + /** + * @brief Set include paths to dialog control. + * @param includes List of include paths to set to dialog control. + */ + void SetIncludepaths(const QStringList &includes); + + /** + * @brief Set define names to dialog control. + * @param defines List of define names to set to dialog control. + */ + void SetDefines(const QStringList &defines); + +private: + Ui::ProjectFile mUI; +}; + +/// @} +#endif // PROJECTFILE_DIALOG_H