File indexing completed on 2024-04-28 05:45:58
0001 /* 0002 SPDX-FileCopyrightText: 2008-2010 Volker Lanz <vl@fidra.de> 0003 SPDX-FileCopyrightText: 2008 Laurent Montel <montel@kde.org> 0004 SPDX-FileCopyrightText: 2015 Chris Campbell <c.j.campbell@ed.ac.uk> 0005 SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org> 0006 SPDX-FileCopyrightText: 2016 Andrius Štikonas <andrius@stikonas.eu> 0007 0008 SPDX-License-Identifier: GPL-3.0-or-later 0009 */ 0010 0011 #ifndef KPMCORE_REPORT_H 0012 #define KPMCORE_REPORT_H 0013 0014 #include "util/libpartitionmanagerexport.h" 0015 0016 #include <QObject> 0017 #include <QList> 0018 #include <QString> 0019 #include <QtGlobal> 0020 0021 class ReportLine; 0022 0023 /** Report details about running Operations and Jobs. 0024 0025 Gather information for the report shown in the ProgressDialog's detail view. 0026 0027 @author Volker Lanz <vl@fidra.de> 0028 */ 0029 class LIBKPMCORE_EXPORT Report : public QObject 0030 { 0031 Q_OBJECT 0032 Q_DISABLE_COPY(Report) 0033 0034 friend Report& operator<<(Report& report, const QString& s); 0035 friend Report& operator<<(Report& report, qint64 i); 0036 0037 public: 0038 explicit Report(Report* p, const QString& cmd = QString()); 0039 ~Report() override; 0040 0041 Q_SIGNALS: 0042 void outputChanged(); 0043 0044 public: 0045 Report* newChild(const QString& cmd = QString()); 0046 0047 const QList<Report*>& children() const { 0048 return m_Children; /**< @return the list of this Report's children */ 0049 } 0050 0051 Report* parent() { 0052 return m_Parent; /**< @return pointer to this Reports parent. May be nullptr if this is the root Report */ 0053 } 0054 const Report* parent() const { 0055 return m_Parent; /**< @return pointer to this Reports parent. May be nullptr if this is the root Report */ 0056 } 0057 0058 Report* root(); 0059 const Report* root() const; 0060 0061 const QString& command() const { 0062 return m_Command; /**< @return the command */ 0063 } 0064 const QString& output() const { 0065 return m_Output; /**< @return the output */ 0066 } 0067 const QString& status() const { 0068 return m_Status; /**< @return the status line */ 0069 } 0070 0071 void setCommand(const QString& s) { 0072 m_Command = s; /**< @param s the new command */ 0073 } 0074 void setStatus(const QString& s) { 0075 m_Status = s; /**< @param s the new status */ 0076 } 0077 void addOutput(const QString& s); 0078 0079 QString toHtml() const; 0080 QString toText() const; 0081 0082 ReportLine line(); 0083 0084 static QString htmlHeader(); 0085 static QString htmlFooter(); 0086 0087 protected: 0088 void emitOutputChanged(); 0089 0090 private: 0091 Report* m_Parent; 0092 QList<Report*> m_Children; 0093 QString m_Command; 0094 QString m_Output; 0095 QString m_Status; 0096 }; 0097 0098 inline Report& operator<<(Report& report, const QString& s) 0099 { 0100 report.addOutput(s); 0101 return report; 0102 } 0103 0104 inline Report& operator<<(Report& report, qint64 i) 0105 { 0106 report.addOutput(QString::number(i)); 0107 return report; 0108 } 0109 0110 class ReportLine 0111 { 0112 friend ReportLine operator<<(ReportLine reportLine, const QString& s); 0113 friend ReportLine operator<<(ReportLine reportLine, qint64 i); 0114 friend class Report; 0115 0116 protected: 0117 ReportLine(Report& r) : ref(1), report(r.newChild()) {} 0118 0119 public: 0120 ~ReportLine() { 0121 if (--ref == 0) *report << QStringLiteral("\n"); 0122 } 0123 ReportLine(const ReportLine& other) : ref(other.ref + 1), report(other.report) {} 0124 0125 private: 0126 ReportLine& operator=(const ReportLine&); 0127 0128 private: 0129 qint32 ref; 0130 Report* report; 0131 }; 0132 0133 inline ReportLine operator<<(ReportLine reportLine, const QString& s) 0134 { 0135 *reportLine.report << s; 0136 return reportLine; 0137 } 0138 0139 inline ReportLine operator<<(ReportLine reportLine, qint64 i) 0140 { 0141 *reportLine.report << i; 0142 return reportLine; 0143 } 0144 0145 #endif