2015-06-04 01:29:22 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* Copyright (C) 2008 by Volker Lanz <vl@fidra.de> *
|
2016-03-02 19:00:31 +00:00
|
|
|
* Copyright (C) 2016 by Andrius Štikonas <andrius@stikonas.eu> *
|
2015-06-04 01:29:22 +01:00
|
|
|
* *
|
|
|
|
* 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 "util/report.h"
|
|
|
|
#include "util/htmlreport.h"
|
|
|
|
|
|
|
|
#include "backend/corebackend.h"
|
|
|
|
#include "backend/corebackendmanager.h"
|
|
|
|
|
|
|
|
#include <KLocalizedString>
|
|
|
|
|
|
|
|
#include <sys/utsname.h>
|
|
|
|
|
|
|
|
/** Creates a new Report instance.
|
2018-08-01 00:58:24 +01:00
|
|
|
@param p pointer to the parent instance. May be nullptr if this is a new root Report.
|
2015-07-13 15:16:36 +01:00
|
|
|
@param cmd the command
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
Report::Report(Report* p, const QString& cmd) :
|
2015-07-13 15:16:36 +01:00
|
|
|
QObject(),
|
|
|
|
m_Parent(p),
|
|
|
|
m_Children(),
|
|
|
|
m_Command(cmd),
|
|
|
|
m_Output(),
|
|
|
|
m_Status()
|
2015-06-04 01:29:22 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Destroys a Report instance and all its children. */
|
|
|
|
Report::~Report()
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
qDeleteAll(children());
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Creates a new child for this Report and appends it to its list of children.
|
2015-07-13 15:16:36 +01:00
|
|
|
@param cmd the command
|
|
|
|
@return pointer to a new Report child
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
Report* Report::newChild(const QString& cmd)
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
Report* r = new Report(this, cmd);
|
|
|
|
m_Children.append(r);
|
|
|
|
return r;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-07-13 15:16:36 +01:00
|
|
|
@return the Report converted to HTML
|
|
|
|
@see toText()
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
QString Report::toHtml() const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
QString s;
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
if (parent() == root())
|
|
|
|
s += QStringLiteral("<div>\n");
|
2015-07-22 14:48:03 +01:00
|
|
|
else if (parent() != nullptr)
|
2015-07-13 15:16:36 +01:00
|
|
|
s += QStringLiteral("<div style='margin-left:24px;margin-top:12px;margin-bottom:12px'>\n");
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
if (!command().isEmpty())
|
|
|
|
s += QStringLiteral("\n<b>") + command().toHtmlEscaped() + QStringLiteral("</b>\n\n");
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
if (!output().isEmpty())
|
|
|
|
s += QStringLiteral("<pre>") + output().toHtmlEscaped() + QStringLiteral("</pre>\n\n");
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
if (children().size() == 0)
|
|
|
|
s += QStringLiteral("<br/>\n");
|
|
|
|
else
|
2016-08-08 20:45:41 +01:00
|
|
|
for (const auto &child : children())
|
2016-06-01 21:00:31 +01:00
|
|
|
s += child->toHtml();
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
if (!status().isEmpty())
|
|
|
|
s += QStringLiteral("<b>") + status().toHtmlEscaped() + QStringLiteral("</b><br/>\n\n");
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-22 14:48:03 +01:00
|
|
|
if (parent() != nullptr)
|
2015-07-13 15:16:36 +01:00
|
|
|
s += QStringLiteral("</div>\n\n");
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return s;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-07-13 15:16:36 +01:00
|
|
|
@return the Report converted to plain text
|
|
|
|
@see toHtml()
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
QString Report::toText() const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
QString s;
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
if (!command().isEmpty()) {
|
|
|
|
s += QStringLiteral("==========================================================================================\n");
|
|
|
|
s += command() + QStringLiteral("\n");
|
|
|
|
s += QStringLiteral("==========================================================================================\n");
|
|
|
|
}
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
if (!output().isEmpty())
|
|
|
|
s += output() + QStringLiteral("\n");
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2016-08-08 20:45:41 +01:00
|
|
|
for (const auto &child : children())
|
2016-06-01 21:00:31 +01:00
|
|
|
s += child->toText();
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return s;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Adds a string to this Report's output.
|
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
This is usually not what you want. In most cases, you will want to create a new child Report.
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
@param s the string to add to the output
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
@see newChild()
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
void Report::addOutput(const QString& s)
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
m_Output += s;
|
|
|
|
root()->emitOutputChanged();
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Report::emitOutputChanged()
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
emit outputChanged();
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @return the root Report */
|
|
|
|
Report* Report::root()
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
Report* rval = this;
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-22 14:48:03 +01:00
|
|
|
while (rval->parent() != nullptr)
|
2015-07-13 15:16:36 +01:00
|
|
|
rval = rval->parent();
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return rval;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-07-13 15:16:36 +01:00
|
|
|
@overload
|
2015-06-04 01:29:22 +01:00
|
|
|
*/
|
|
|
|
const Report* Report::root() const
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
const Report* rval = this;
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-22 14:48:03 +01:00
|
|
|
while (rval->parent() != nullptr)
|
2015-07-13 15:16:36 +01:00
|
|
|
rval = rval->parent();
|
2015-06-04 01:29:22 +01:00
|
|
|
|
2015-07-13 15:16:36 +01:00
|
|
|
return rval;
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** @return a Report line to write to */
|
|
|
|
ReportLine Report::line()
|
|
|
|
{
|
2015-07-13 15:16:36 +01:00
|
|
|
return ReportLine(*this);
|
2015-06-04 01:29:22 +01:00
|
|
|
}
|