add a first version of a html report class
svn path=/trunk/extragear/sysadmin/partitionmanager/; revision=1120179
This commit is contained in:
parent
3d8eaf6e48
commit
ce6f2c08d4
|
@ -29,6 +29,7 @@
|
|||
#include "jobs/job.h"
|
||||
|
||||
#include "util/report.h"
|
||||
#include "util/htmlreport.h"
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QTime>
|
||||
|
@ -392,9 +393,9 @@ void ApplyProgressDialog::saveReport()
|
|||
|
||||
if (tempFile.open())
|
||||
{
|
||||
tempFile.write(Report::htmlHeader().toUtf8());
|
||||
tempFile.write(HtmlReport::header().toUtf8());
|
||||
tempFile.write(report().toHtml().toUtf8());
|
||||
tempFile.write(Report::htmlFooter().toUtf8());
|
||||
tempFile.write(HtmlReport::footer().toUtf8());
|
||||
|
||||
tempFile.close();
|
||||
|
||||
|
@ -417,9 +418,9 @@ void ApplyProgressDialog::browserReport()
|
|||
|
||||
if (file.open())
|
||||
{
|
||||
file.write(Report::htmlHeader().toUtf8());
|
||||
file.write(HtmlReport::header().toUtf8());
|
||||
file.write(report().toHtml().toUtf8());
|
||||
file.write(Report::htmlFooter().toUtf8());
|
||||
file.write(HtmlReport::footer().toUtf8());
|
||||
|
||||
// set the temp file's permission for everyone to read it.
|
||||
file.setPermissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ReadGroup | QFile::ReadOther);
|
||||
|
|
|
@ -24,27 +24,23 @@
|
|||
#include "core/smartstatus.h"
|
||||
#include "core/smartattribute.h"
|
||||
|
||||
#include "backend/corebackend.h"
|
||||
#include "backend/corebackendmanager.h"
|
||||
|
||||
#include "util/helpers.h"
|
||||
#include "util/htmlreport.h"
|
||||
|
||||
#include <kdebug.h>
|
||||
#include <kpushbutton.h>
|
||||
#include <kiconloader.h>
|
||||
#include <klocale.h>
|
||||
#include <kglobal.h>
|
||||
#include <kglobalsettings.h>
|
||||
#include <kdatetime.h>
|
||||
#include <kcomponentdata.h>
|
||||
#include <kfiledialog.h>
|
||||
#include <kio/copyjob.h>
|
||||
#include <kio/netaccess.h>
|
||||
#include <kio/jobuidelegate.h>
|
||||
#include <kmessagebox.h>
|
||||
#include <ktemporaryfile.h>
|
||||
#include <kaboutdata.h>
|
||||
#include <kicon.h>
|
||||
#include <kglobalsettings.h>
|
||||
#include <kglobal.h>
|
||||
#include <klocale.h>
|
||||
|
||||
#include <QTreeWidgetItem>
|
||||
#include <QTextStream>
|
||||
|
@ -151,23 +147,32 @@ void SmartDialog::setupConnections()
|
|||
connect(this, SIGNAL(user1Clicked()), SLOT(saveSmartReport()));
|
||||
}
|
||||
|
||||
static QString tableLine(const QString& label, const QString contents)
|
||||
{
|
||||
QString s;
|
||||
|
||||
s += "<tr>\n";
|
||||
s += QString("<td style='font-weight:bold;padding-right:20px;'>%1</td>\n").arg(Qt::escape(label));
|
||||
s += QString("<td>%1</td>\n").arg(Qt::escape(contents));
|
||||
s += "</tr>\n";
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
QString SmartDialog::toHtml() const
|
||||
{
|
||||
QString rval;
|
||||
QTextStream s(&rval);
|
||||
|
||||
if (device().smartStatus().status())
|
||||
s << HtmlReport::tableLine(i18n("SMART status:"), i18nc("@label SMART disk status", "good"));
|
||||
else
|
||||
s << HtmlReport::tableLine(i18n("SMART status:"), i18nc("@label SMART disk status", "BAD"));
|
||||
|
||||
const QString badSectors = device().smartStatus().badSectors() > 0
|
||||
? KGlobal::locale()->formatNumber(device().smartStatus().badSectors(), 0)
|
||||
: i18nc("@label SMART number of bad sectors", "none");
|
||||
|
||||
s << HtmlReport::tableLine(i18n("Model:"), device().smartStatus().modelName())
|
||||
<< HtmlReport::tableLine(i18n("Serial number:"), device().smartStatus().serial())
|
||||
<< HtmlReport::tableLine(i18n("Firmware revision:"), device().smartStatus().firmware())
|
||||
<< HtmlReport::tableLine(i18n("Temperature:"), SmartStatus::tempToString(device().smartStatus().temp()))
|
||||
<< HtmlReport::tableLine(i18n("Bad sectors:"), badSectors)
|
||||
<< HtmlReport::tableLine(i18n("Powered on for:"), KGlobal::locale()->formatDuration(device().smartStatus().poweredOn()))
|
||||
<< HtmlReport::tableLine(i18n("Power cycles:"), KGlobal::locale()->formatNumber(device().smartStatus().powerCycles(), 0))
|
||||
<< HtmlReport::tableLine(i18n("Self tests:"), SmartStatus::selfTestStatusToString(device().smartStatus().selfTestStatus()))
|
||||
<< HtmlReport::tableLine(i18n("Overall assessment:"), SmartStatus::overallAssessmentToString(device().smartStatus().overall()));
|
||||
|
||||
s << "</table><br/>";
|
||||
|
||||
if (device().smartStatus().isValid())
|
||||
{
|
||||
|
||||
|
@ -206,71 +211,6 @@ QString SmartDialog::toHtml() const
|
|||
return rval;
|
||||
}
|
||||
|
||||
QString SmartDialog::htmlHeader() const
|
||||
{
|
||||
QString rval;
|
||||
QTextStream s(&rval);
|
||||
|
||||
s <<
|
||||
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
|
||||
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
|
||||
"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n"
|
||||
"<head>\n"
|
||||
" <title>"
|
||||
<< i18n("%1: SMART Status Report", Qt::escape(KGlobal::mainComponent().aboutData()->programName()))
|
||||
<< "</title>\n"
|
||||
" <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>\n"
|
||||
"</head>\n\n"
|
||||
"<body>\n";
|
||||
|
||||
s << "<h1>"
|
||||
<< i18n("%1: SMART Status Report", Qt::escape(KGlobal::mainComponent().aboutData()->programName()))
|
||||
<< "</h1>\n\n";
|
||||
|
||||
struct utsname info;
|
||||
uname(&info);
|
||||
const QString unameString = QString(info.sysname) + ' ' + info.nodename + ' ' + info.release + ' ' + info.version + ' ' + info.machine;
|
||||
|
||||
s << "<table>\n"
|
||||
<< tableLine(i18n("Date:"), KGlobal::locale()->formatDateTime(KDateTime::currentLocalDateTime()))
|
||||
<< tableLine(i18n("Program version:"), KGlobal::mainComponent().aboutData()->version())
|
||||
<< tableLine(i18n("Backend:"), QString("%1 (%2)").arg(CoreBackendManager::self()->backend()->about().programName()).arg(CoreBackendManager::self()->backend()->about().version()))
|
||||
<< tableLine(i18n("KDE version:"), KDE_VERSION_STRING)
|
||||
<< tableLine(i18n("Machine:"), unameString)
|
||||
<< "</table>\n<br/>\n";
|
||||
|
||||
s << "<table>\n";
|
||||
if (device().smartStatus().status())
|
||||
s << tableLine(i18n("SMART status:"), i18nc("@label SMART disk status", "good"));
|
||||
else
|
||||
s << tableLine(i18n("SMART status:"), i18nc("@label SMART disk status", "BAD"));
|
||||
|
||||
const QString badSectors = device().smartStatus().badSectors() > 0
|
||||
? KGlobal::locale()->formatNumber(device().smartStatus().badSectors(), 0)
|
||||
: i18nc("@label SMART number of bad sectors", "none");
|
||||
|
||||
s << tableLine(i18n("Model:"), device().smartStatus().modelName())
|
||||
<< tableLine(i18n("Serial number:"), device().smartStatus().serial())
|
||||
<< tableLine(i18n("Firmware revision:"), device().smartStatus().firmware())
|
||||
<< tableLine(i18n("Temperature:"), SmartStatus::tempToString(device().smartStatus().temp()))
|
||||
<< tableLine(i18n("Bad sectors:"), badSectors)
|
||||
<< tableLine(i18n("Powered on for:"), KGlobal::locale()->formatDuration(device().smartStatus().poweredOn()))
|
||||
<< tableLine(i18n("Power cycles:"), KGlobal::locale()->formatNumber(device().smartStatus().powerCycles(), 0))
|
||||
<< tableLine(i18n("Self tests:"), SmartStatus::selfTestStatusToString(device().smartStatus().selfTestStatus()))
|
||||
<< tableLine(i18n("Overall assessment:"), SmartStatus::overallAssessmentToString(device().smartStatus().overall()));
|
||||
|
||||
s << "</table><br/>";
|
||||
|
||||
s.flush();
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
QString SmartDialog::htmlFooter() const
|
||||
{
|
||||
return "\n\n</body>\n</html>\n";
|
||||
}
|
||||
|
||||
void SmartDialog::saveSmartReport()
|
||||
{
|
||||
const KUrl url = KFileDialog::getSaveUrl(KUrl("kfiledialog://saveSMARTReport"));
|
||||
|
@ -282,9 +222,11 @@ void SmartDialog::saveSmartReport()
|
|||
|
||||
if (tempFile.open())
|
||||
{
|
||||
tempFile.write(htmlHeader().toUtf8());
|
||||
tempFile.write(toHtml().toUtf8());
|
||||
tempFile.write(htmlFooter().toUtf8());
|
||||
QTextStream s(&tempFile);
|
||||
|
||||
s << HtmlReport::header().toUtf8()
|
||||
<< toHtml().toUtf8()
|
||||
<< HtmlReport::footer().toUtf8();
|
||||
|
||||
tempFile.close();
|
||||
|
||||
|
|
|
@ -59,8 +59,6 @@ class SmartDialog : public KDialog
|
|||
const SmartDialogWidget& dialogWidget() const { Q_ASSERT(m_DialogWidget); return *m_DialogWidget; }
|
||||
|
||||
QString toHtml() const;
|
||||
QString htmlHeader() const;
|
||||
QString htmlFooter() const;
|
||||
|
||||
private:
|
||||
Device& m_Device;
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2010 by Volker Lanz <vl@fidra.de> *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#include "util/htmlreport.h"
|
||||
|
||||
#include "backend/corebackend.h"
|
||||
#include "backend/corebackendmanager.h"
|
||||
|
||||
#include <kglobal.h>
|
||||
#include <kaboutdata.h>
|
||||
#include <kdatetime.h>
|
||||
#include <klocale.h>
|
||||
#include <kglobalsettings.h>
|
||||
#include <kcomponentdata.h>
|
||||
|
||||
#include <QString>
|
||||
#include <QTextStream>
|
||||
#include <QTextDocument>
|
||||
|
||||
#include <sys/utsname.h>
|
||||
#include <unistd.h>
|
||||
|
||||
QString HtmlReport::tableLine(const QString& label, const QString contents)
|
||||
{
|
||||
QString rval;
|
||||
QTextStream s(&rval);
|
||||
|
||||
s << "<tr>\n"
|
||||
<< QString("<td style='font-weight:bold;padding-right:20px;'>%1</td>\n").arg(Qt::escape(label))
|
||||
<< QString("<td>%1</td>\n").arg(Qt::escape(contents))
|
||||
<< "</tr>\n";
|
||||
|
||||
s.flush();
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
QString HtmlReport::header()
|
||||
{
|
||||
QString rval;
|
||||
QTextStream s(&rval);
|
||||
|
||||
s <<
|
||||
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
|
||||
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
|
||||
"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n"
|
||||
"<head>\n"
|
||||
" <title>"
|
||||
<< i18n("%1: SMART Status Report", Qt::escape(KGlobal::mainComponent().aboutData()->programName()))
|
||||
<< "</title>\n"
|
||||
" <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>\n"
|
||||
"</head>\n\n"
|
||||
"<body>\n";
|
||||
|
||||
s << "<h1>"
|
||||
<< i18n("%1: SMART Status Report", Qt::escape(KGlobal::mainComponent().aboutData()->programName()))
|
||||
<< "</h1>\n\n";
|
||||
|
||||
struct utsname info;
|
||||
uname(&info);
|
||||
const QString unameString = QString(info.sysname) + ' ' + info.nodename + ' ' + info.release + ' ' + info.version + ' ' + info.machine;
|
||||
|
||||
s << "<table>\n"
|
||||
<< tableLine(i18n("Date:"), KGlobal::locale()->formatDateTime(KDateTime::currentLocalDateTime()))
|
||||
<< tableLine(i18n("Program version:"), KGlobal::mainComponent().aboutData()->version())
|
||||
<< tableLine(i18n("Backend:"), QString("%1 (%2)").arg(CoreBackendManager::self()->backend()->about().programName()).arg(CoreBackendManager::self()->backend()->about().version()))
|
||||
<< tableLine(i18n("KDE version:"), KDE_VERSION_STRING)
|
||||
<< tableLine(i18n("Machine:"), unameString)
|
||||
<< "</table>\n<br/>\n";
|
||||
|
||||
s << "<table>\n";
|
||||
|
||||
s.flush();
|
||||
|
||||
return rval;
|
||||
}
|
||||
|
||||
QString HtmlReport::footer()
|
||||
{
|
||||
return "\n\n</body>\n</html>\n";
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2010 by Volker Lanz <vl@fidra.de> *
|
||||
* *
|
||||
* 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 2 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, write to the *
|
||||
* Free Software Foundation, Inc., *
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#if !defined(HTMLREPORT__H)
|
||||
|
||||
#define HTMLREPORT__H
|
||||
|
||||
class QString;
|
||||
|
||||
class HtmlReport
|
||||
{
|
||||
public:
|
||||
HtmlReport();
|
||||
|
||||
public:
|
||||
static QString tableLine(const QString& label, const QString contents);
|
||||
static QString header();
|
||||
static QString footer();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -18,6 +18,7 @@
|
|||
***************************************************************************/
|
||||
|
||||
#include "util/report.h"
|
||||
#include "util/htmlreport.h"
|
||||
|
||||
#include "backend/corebackend.h"
|
||||
#include "backend/corebackendmanager.h"
|
||||
|
@ -65,58 +66,6 @@ Report* Report::newChild(const QString& cmd)
|
|||
return r;
|
||||
}
|
||||
|
||||
static QString tableLine(const QString& label, const QString contents)
|
||||
{
|
||||
QString s;
|
||||
|
||||
s += "<tr>\n";
|
||||
s += QString("<td style='font-weight:bold;padding-right:20px;'>%1</td>\n").arg(Qt::escape(label));
|
||||
s += QString("<td>%1</td>\n").arg(Qt::escape(contents));
|
||||
s += "</tr>\n";
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
QString Report::htmlHeader()
|
||||
{
|
||||
QString s = QString(
|
||||
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n"
|
||||
"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
|
||||
"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n"
|
||||
"<head>\n"
|
||||
" <title>%1</title>\n"
|
||||
" <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/>\n"
|
||||
"</head>\n\n"
|
||||
"<body>\n"
|
||||
).arg(i18n("%1: Operation Report", Qt::escape(KGlobal::mainComponent().aboutData()->programName())));
|
||||
|
||||
s += QString("<h1>%1</h1>\n\n").arg(i18n("%1: Operation Report", Qt::escape(KGlobal::mainComponent().aboutData()->programName())));
|
||||
|
||||
struct utsname info;
|
||||
uname(&info);
|
||||
const QString unameString = QString(info.sysname) + ' ' + info.nodename + ' ' + info.release + ' ' + info.version + ' ' + info.machine;
|
||||
|
||||
s += "<table>\n";
|
||||
s += tableLine(i18n("Date:"), KGlobal::locale()->formatDateTime(KDateTime::currentLocalDateTime()));
|
||||
s += tableLine(i18n("Program version:"), KGlobal::mainComponent().aboutData()->version());
|
||||
s += tableLine(i18n("Backend:"), QString("%1 (%2)").arg(CoreBackendManager::self()->backend()->about().programName()).arg(CoreBackendManager::self()->backend()->about().version()));
|
||||
s += tableLine(i18n("KDE version:"), KDE_VERSION_STRING);
|
||||
s += tableLine(i18n("Machine:"), unameString);
|
||||
s += tableLine(i18n("User ID:"), QString::number(geteuid()));
|
||||
s += "</table>\n<br/>\n";
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
QString Report::htmlFooter()
|
||||
{
|
||||
QString s;
|
||||
|
||||
s += "\n\n</body>\n</html>\n";
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
@return the Report converted to HTML
|
||||
@see toText()
|
||||
|
|
Loading…
Reference in New Issue