File indexing completed on 2024-04-28 05:26:49
0001 /******************************************************************* 0002 * reportinterface.h 0003 * SPDX-FileCopyrightText: 2009, 2011 Dario Andres Rodriguez <andresbajotierra@gmail.com> 0004 * SPDX-FileCopyrightText: 2009 George Kiagiadakis <gkiagia@users.sourceforge.net> 0005 * SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org> 0006 * 0007 * SPDX-License-Identifier: GPL-2.0-or-later 0008 * 0009 ******************************************************************/ 0010 0011 #ifndef REPORTINTERFACE__H 0012 #define REPORTINTERFACE__H 0013 0014 #include <QObject> 0015 #include <QStringList> 0016 #include <QTimer> 0017 0018 #include "sentrypostbox.h" 0019 0020 namespace Bugzilla 0021 { 0022 class NewBug; 0023 } // namespace Bugzilla 0024 0025 class BugzillaManager; 0026 class ProductMapping; 0027 0028 class ReportInterface : public QObject 0029 { 0030 Q_OBJECT 0031 Q_PROPERTY(BugzillaManager *bugzilla READ bugzillaManager CONSTANT) 0032 Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged) 0033 Q_PROPERTY(QString detailText MEMBER m_reportDetailText WRITE setDetailText NOTIFY detailTextChanged) 0034 Q_PROPERTY(bool userRememberCrashSitutation MEMBER m_userRememberCrashSituation NOTIFY awarenessChanged) 0035 Q_PROPERTY(Reproducible reproducible MEMBER m_reproducible NOTIFY awarenessChanged) 0036 Q_PROPERTY(bool provideActionsApplicationDesktop MEMBER m_provideActionsApplicationDesktop NOTIFY awarenessChanged) 0037 0038 Q_PROPERTY(bool provideUnusualBehavior MEMBER m_provideUnusualBehavior NOTIFY provideUnusualBehaviorChanged) 0039 Q_PROPERTY(bool provideApplicationConfigurationDetails MEMBER m_provideApplicationConfigurationDetails NOTIFY awarenessChanged) 0040 Q_PROPERTY(QString backtrace READ backtrace WRITE setBacktrace NOTIFY backtraceChanged) 0041 0042 Q_PROPERTY(bool isBugAwarenessPageDataUseful READ isBugAwarenessPageDataUseful NOTIFY awarenessChanged) 0043 0044 Q_PROPERTY(uint attachToBugNumber READ attachToBugNumber WRITE setAttachToBugNumber NOTIFY attachToBugNumberChanged) 0045 0046 Q_PROPERTY(uint sentReport MEMBER m_sentReport NOTIFY done) 0047 Q_PROPERTY(bool crashEventSent READ hasCrashEventSent NOTIFY crashEventSent) 0048 public: 0049 enum Reproducible { 0050 ReproducibleUnsure, 0051 ReproducibleNever, 0052 ReproducibleSometimes, 0053 ReproducibleEverytime, 0054 }; 0055 Q_ENUM(Reproducible) 0056 0057 enum class Backtrace { 0058 Complete, 0059 Reduced, 0060 Exclude, 0061 }; 0062 Q_ENUM(Backtrace) 0063 0064 enum class DrKonqiStamp { 0065 Include, 0066 Exclude, 0067 }; 0068 Q_ENUM(DrKonqiStamp) 0069 0070 static ReportInterface *self(); 0071 0072 Q_SIGNAL void awarenessChanged(); 0073 0074 Q_INVOKABLE void setBugAwarenessPageData(bool, ReportInterface::Reproducible, bool, bool, bool); 0075 bool isBugAwarenessPageDataUseful() const; 0076 0077 Q_INVOKABLE int selectedOptionsRating() const; 0078 0079 QString backtrace() const; 0080 void setBacktrace(const QString &backtrace); 0081 Q_SIGNAL void backtraceChanged(); 0082 0083 QString title() const; 0084 void setTitle(const QString &text); 0085 Q_SIGNAL void titleChanged(); 0086 0087 void setDetailText(const QString &text); 0088 Q_SIGNAL void detailTextChanged(); 0089 0090 Q_INVOKABLE QString generateReportFullText(ReportInterface::DrKonqiStamp stamp, ReportInterface::Backtrace inlineBacktrace) const; 0091 0092 Bugzilla::NewBug newBugReportTemplate() const; 0093 0094 Q_INVOKABLE QStringList relatedBugzillaProducts() const; 0095 0096 bool isWorthReporting() const; 0097 0098 // Zero means creating a new bug report 0099 void setAttachToBugNumber(uint); 0100 uint attachToBugNumber() const; 0101 Q_SIGNAL void attachToBugNumberChanged(); 0102 0103 BugzillaManager *bugzillaManager() const; 0104 ProductMapping *productMapping() const; 0105 0106 bool userCanProvideActionsAppDesktop() const 0107 { 0108 return m_provideActionsApplicationDesktop; 0109 } 0110 0111 bool userCanProvideUnusualBehavior() const 0112 { 0113 return m_provideUnusualBehavior; 0114 } 0115 0116 bool userCanProvideApplicationConfigDetails() const 0117 { 0118 return m_provideApplicationConfigurationDetails; 0119 } 0120 0121 bool isCrashEventSendingEnabled() const; 0122 bool hasCrashEventSent() const; 0123 [[nodiscard]] QString sentryEventId() const; 0124 0125 public Q_SLOTS: 0126 void prepareCrashEvent(); 0127 void prepareCrashComment(); 0128 void createCrashMessage(const QString &message); 0129 void sendBugReport(); 0130 void sendSentryReport(); 0131 void setSendWhenReady(bool send); 0132 0133 private Q_SLOTS: 0134 void sendUsingDefaultProduct() const; 0135 // Attach backtrace to bug and use collected report as comment. 0136 void attachBacktraceWithReport(); 0137 void attachSent(int); 0138 0139 Q_SIGNALS: 0140 void done(); 0141 void sendReportError(const QString &); 0142 void provideUnusualBehaviorChanged(); 0143 void crashEventSent(); 0144 0145 private: 0146 explicit ReportInterface(QObject *parent = nullptr); 0147 // Attach backtrace to bug. Only used internally when the comment isn't 0148 // meant to be the full report. 0149 void attachBacktrace(const QString &comment); 0150 void sendToSentry(); 0151 void maybeDone(); 0152 void maybePickUpPostbox(); 0153 void trySentry(); 0154 void prepareEventPayload(); 0155 0156 QString generateAttachmentComment() const; 0157 0158 // Information the user can provide 0159 bool m_userRememberCrashSituation; 0160 Reproducible m_reproducible; 0161 bool m_provideActionsApplicationDesktop; 0162 bool m_provideUnusualBehavior; 0163 bool m_provideApplicationConfigurationDetails; 0164 0165 QString m_backtrace; 0166 0167 QString m_reportTitle; 0168 QString m_reportDetailText; 0169 0170 uint m_attachToBugNumber; 0171 0172 ProductMapping *m_productMapping = nullptr; 0173 BugzillaManager *m_bugzillaManager = nullptr; 0174 0175 bool m_skipSentry = false; 0176 bool m_forceSentry = false; 0177 QTimer m_sentryStartTimer; 0178 bool m_tryingSentry = false; 0179 SentryPostbox m_sentryPostbox; 0180 uint m_sentReport = 0; 0181 bool m_sendWhenReady = false; 0182 }; 0183 0184 #endif