diff --git a/gui/fileviewdialog.cpp b/gui/fileviewdialog.cpp new file mode 100644 index 000000000..610637280 --- /dev/null +++ b/gui/fileviewdialog.cpp @@ -0,0 +1,96 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2009 Daniel Marjamäki 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 "fileviewdialog.h" + +FileViewDialog::FileViewDialog(const QString &file, QWidget *parent) + : QDialog(parent) +{ + QString title = FormatTitle(file); + setWindowTitle(title); + + QVBoxLayout *mainLayout = new QVBoxLayout(); + QHBoxLayout *btnLayout = new QHBoxLayout(); + QPushButton *quit = new QPushButton(tr("Close")); + QTextEdit *edit = new QTextEdit(); + edit->setReadOnly(true); + + mainLayout->addWidget(edit); + mainLayout->addLayout(btnLayout); + btnLayout->addStretch(); + btnLayout->addWidget(quit); + setLayout(mainLayout); + + connect(quit, SIGNAL(clicked()), this, SLOT(close())); + + LoadTextFile(file, edit); +} + +void FileViewDialog::LoadTextFile(const QString &filename, QTextEdit *edit) +{ + QFile file(filename); + if (!file.exists()) + { + QString msg(tr("Could not find the file:\n")); + msg += filename; + QMessageBox msgbox(QMessageBox::Critical, + tr("Cppcheck"), + msg, + QMessageBox::Ok, + this); + msgbox.exec(); + return; + } + + file.open(QIODevice::ReadOnly | QIODevice::Text); + if (!file.isReadable()) + { + QString msg(tr("Could not read the file:\n")); + msg += filename; + QMessageBox msgbox(QMessageBox::Critical, + tr("Cppcheck"), + msg, + QMessageBox::Ok, + this); + msgbox.exec(); + return; + } + QByteArray filedata = file.readAll(); + file.close(); + + QString filestringdata(filedata); + edit->setPlainText(filestringdata); +} + +QString FileViewDialog::FormatTitle(const QString &filename) +{ + QString title(filename); + if (title.startsWith(":")) + { + title.remove(0, 1); + } + return title; +} diff --git a/gui/fileviewdialog.h b/gui/fileviewdialog.h new file mode 100644 index 000000000..6c11ad02f --- /dev/null +++ b/gui/fileviewdialog.h @@ -0,0 +1,58 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2009 Daniel Marjamäki 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 + +class QWidget; +class QTextEdit; + +/** +* @brief File view -dialog. +* This dialog shows text files. It is used for showing the license file and +* the authors list. +* +*/ +class FileViewDialog : public QDialog +{ + Q_OBJECT +public: + FileViewDialog(const QString &file, QWidget *parent = 0); + +protected: + + /** + * @brief Load text file contents to edit control. + * + * @param filename File to load. + * @param edit Control where to load the file contents. + */ + void LoadTextFile(const QString &filename, QTextEdit *edit); + + /** + * @brief Format dialog title from filename. + * + * @param filename File to load. + */ + QString FormatTitle(const QString &filename); +}; + +#endif // _FILEVIEW_DIALOG_H_ diff --git a/gui/gui.pro b/gui/gui.pro index bfa42d9fb..8864232c7 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -26,6 +26,7 @@ HEADERS += mainwindow.h \ applicationdialog.h \ aboutdialog.h \ common.h \ + fileviewdialog.h \ ../src/checkautovariables.h \ ../src/checkdangerousfunctions.h \ ../src/checkheaders.h \ @@ -60,6 +61,7 @@ SOURCES += main.cpp \ applicationlist.cpp \ applicationdialog.cpp \ aboutdialog.cpp \ + fileviewdialog.cpp \ ../src/checkautovariables.cpp \ ../src/checkdangerousfunctions.cpp \ ../src/checkmemoryleak.cpp \ diff --git a/gui/gui.qrc b/gui/gui.qrc index 9ce1b7f2c..9140ddbdd 100644 --- a/gui/gui.qrc +++ b/gui/gui.qrc @@ -12,5 +12,8 @@ images/process-stop.png images/text-x-generic.png images/view-refresh.png + + ../COPYING + ../AUTHORS diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index d2895922a..8a921d4b0 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -26,6 +26,7 @@ #include #include #include "aboutdialog.h" +#include "fileviewdialog.h" #include "../src/filelister.h" #include "../src/cppcheckexecutor.h" @@ -47,6 +48,8 @@ MainWindow::MainWindow() : mActionShowCollapseAll(tr("Collapse all"), this), mActionShowExpandAll(tr("Expand all"), this), mActionAbout(tr("About"), this), + mActionShowLicense(tr("License..."), this), + mActionShowAuthors(tr("Authors..."), this), mActionStop(tr("Stop checking"), this), mActionSave(tr("Save results to a file"), this), mResults(mSettings, mApplications) @@ -84,6 +87,9 @@ MainWindow::MainWindow() : menuprogram->addAction(&mActionSettings); QMenu *menuHelp = menuBar()->addMenu(tr("&Help")); + menuHelp->addAction(&mActionShowLicense); + menuHelp->addAction(&mActionShowAuthors); + menuHelp->addSeparator(); menuHelp->addAction(&mActionAbout); setCentralWidget(&mResults); @@ -110,6 +116,8 @@ MainWindow::MainWindow() : connect(&mActionSave, SIGNAL(triggered()), this, SLOT(Save())); connect(&mActionAbout, SIGNAL(triggered()), this, SLOT(About())); + connect(&mActionShowLicense, SIGNAL(triggered()), this, SLOT(ShowLicense())); + connect(&mActionShowAuthors, SIGNAL(triggered()), this, SLOT(ShowAuthors())); connect(&mThread, SIGNAL(Done()), this, SLOT(CheckDone())); connect(&mResults, SIGNAL(GotResults()), this, SLOT(ResultsAdded())); @@ -434,9 +442,20 @@ void MainWindow::About() version.replace("Cppcheck ", ""); AboutDialog *dlg = new AboutDialog(version, this); - dlg->show(); + dlg->exec(); } +void MainWindow::ShowLicense() +{ + FileViewDialog *dlg = new FileViewDialog(":COPYING", this); + dlg->exec(); +} + +void MainWindow::ShowAuthors() +{ + FileViewDialog *dlg = new FileViewDialog(":AUTHORS", this); + dlg->exec(); +} void MainWindow::Save() { diff --git a/gui/mainwindow.h b/gui/mainwindow.h index d79e66eb1..d5fdc82e2 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -119,6 +119,17 @@ public slots: */ void About(); + /** + * @brief Slot to to show license text + * + */ + void ShowLicense(); + + /** + * @brief Slot to to show authors list + * + */ + void ShowAuthors(); /** * @brief Slot to stop processing files @@ -230,7 +241,6 @@ protected: */ QAction mActionReCheck; - /** * @brief Menu action to check a directory * @@ -298,11 +308,23 @@ protected: QAction mActionShowExpandAll; /** - * @brief Action show about dialog + * @brief Action to show about dialog * */ QAction mActionAbout; + /** + * @brief Action to show license text + * + */ + QAction mActionShowLicense; + + /** + * @brief Action to show authors list + * + */ + QAction mActionShowAuthors; + /** * @brief Action stop checking files *