GUI: Show authors list and license in simple text file view dialog.

Add "Authors" and "License" items to the Help-menu. When selected, these items open simple text file viewer dialog. The AUTHORS and COPYING files are embedded to the executable and shown in the dialog.
This commit is contained in:
Kimmo Varis 2009-06-14 12:57:43 +03:00
parent 4286fdbabb
commit 801a241e0b
6 changed files with 203 additions and 3 deletions

96
gui/fileviewdialog.cpp Normal file
View File

@ -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 <http://www.gnu.org/licenses/
*/
#include <QDialog>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QTextEdit>
#include <QPushButton>
#include <QFile>
#include <QByteArray>
#include <QMessageBox>
#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;
}

58
gui/fileviewdialog.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/
*/
#ifndef _FILEVIEW_DIALOG_H_
#define _FILEVIEW_DIALOG_H_
#include <QDialog>
#include <QString>
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_

View File

@ -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 \

View File

@ -12,5 +12,8 @@
<file>images/process-stop.png</file>
<file>images/text-x-generic.png</file>
<file>images/view-refresh.png</file>
<file alias="COPYING">../COPYING</file>
<file alias="AUTHORS">../AUTHORS</file>
</qresource>
</RCC>

View File

@ -26,6 +26,7 @@
#include <QToolBar>
#include <QKeySequence>
#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()
{

View File

@ -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
*