File indexing completed on 2024-04-28 05:46:31

0001 /*
0002     SPDX-FileCopyrightText: 2010 Volker Lanz <vl@fidra.de>
0003     SPDX-FileCopyrightText: 2014-2020 Andrius Štikonas <andrius@stikonas.eu>
0004 
0005     SPDX-License-Identifier: GPL-3.0-or-later
0006 */
0007 
0008 #ifndef APPLYPROGRESSDIALOG_H
0009 #define APPLYPROGRESSDIALOG_H
0010 
0011 #include <QDialog>
0012 #include <QString>
0013 #include <QElapsedTimer>
0014 #include <QTimer>
0015 
0016 class OperationRunner;
0017 class Operation;
0018 class Job;
0019 class ApplyProgressDialogWidget;
0020 class ApplyProgressDetailsWidget;
0021 class Report;
0022 
0023 class QDialogButtonBox;
0024 class QTreeWidgetItem;
0025 class QCloseEvent;
0026 class QKeyEvent;
0027 
0028 /** Show progress.
0029 
0030     The progress dialog telling the user about the progress of the Operations that are being applied.
0031 
0032     @author Volker Lanz <vl@fidra.de>
0033 */
0034 class ApplyProgressDialog : public QDialog
0035 {
0036     Q_DISABLE_COPY(ApplyProgressDialog)
0037 
0038 public:
0039     ApplyProgressDialog(QWidget* parent, OperationRunner& orunner);
0040     ~ApplyProgressDialog();
0041 
0042 public:
0043     void show();
0044 
0045     Report& report() {
0046         Q_ASSERT(m_Report);    /**< @return the Report object for this dialog */
0047         return *m_Report;
0048     }
0049     const Report& report() const {
0050         Q_ASSERT(m_Report);    /**< @return the Report object for this dialog */
0051         return *m_Report;
0052     }
0053 
0054 protected:
0055     void onAllOpsFinished();
0056     void onAllOpsCancelled();
0057     void onAllOpsError();
0058     void onCancelButton();
0059     void onDetailsButton();
0060     void onOkButton();
0061     void onOpStarted(int num, Operation* op);
0062     void onOpFinished(int num, Operation* op);
0063     void onSecondElapsed();
0064     void saveReport();
0065     void browserReport();
0066     void updateReportUnforced();
0067     void updateReport(bool force = false);
0068 
0069     void onJobStarted(Job* job, Operation* op);
0070     void onJobFinished(Job* job, Operation* op);
0071     void toggleDetails();
0072 
0073     void closeEvent(QCloseEvent* e) override;
0074     void keyPressEvent(QKeyEvent* e) override;
0075 
0076     void setupConnections();
0077 
0078     const OperationRunner& operationRunner() const {
0079         return m_OperationRunner;
0080     }
0081 
0082     ApplyProgressDialogWidget
0083     & dialogWidget() {
0084         Q_ASSERT(m_ProgressDialogWidget);
0085         return *m_ProgressDialogWidget;
0086     }
0087     const ApplyProgressDialogWidget
0088     & dialogWidget() const {
0089         Q_ASSERT(m_ProgressDialogWidget);
0090         return *m_ProgressDialogWidget;
0091     }
0092 
0093     ApplyProgressDetailsWidget
0094     & detailsWidget() {
0095         Q_ASSERT(m_ProgressDetailsWidget);
0096         return *m_ProgressDetailsWidget;
0097     }
0098     const ApplyProgressDetailsWidget
0099     & detailsWidget() const {
0100         Q_ASSERT(m_ProgressDetailsWidget);
0101         return *m_ProgressDetailsWidget;
0102     }
0103 
0104     void setStatus(const QString& s);
0105 
0106     void setParentTitle(const QString& s);
0107 
0108     void addTaskOutput(int num, const Operation& op);
0109 
0110     QString opDesc(int num, const Operation& op) const;
0111 
0112     void resetReport();
0113 
0114     void allOpsDone(const QString& msg);
0115 
0116     QElapsedTimer& time() {
0117         return m_ElapsedTimer;
0118     }
0119 
0120     QTimer& timer() {
0121         return m_Timer;
0122     }
0123     const QTimer& timer() const {
0124         return m_Timer;
0125     }
0126 
0127     const QString& savedParentTitle() const {
0128         return m_SavedParentTitle;
0129     }
0130 
0131     void setCurrentOpItem(QTreeWidgetItem* item) {
0132         m_CurrentOpItem = item;
0133     }
0134     QTreeWidgetItem* currentOpItem() {
0135         return m_CurrentOpItem;
0136     }
0137 
0138     void setCurrentJobItem(QTreeWidgetItem* item) {
0139         m_CurrentJobItem = item;
0140     }
0141     QTreeWidgetItem* currentJobItem() {
0142         return m_CurrentJobItem;
0143     }
0144 
0145     int lastReportUpdate() const {
0146         return m_LastReportUpdate;
0147     }
0148     void setLastReportUpdate(int t) {
0149         m_LastReportUpdate = t;
0150     }
0151 
0152     static const QString& timeFormat() {
0153         return m_TimeFormat;
0154     }
0155 
0156 private:
0157     ApplyProgressDialogWidget* m_ProgressDialogWidget;
0158     ApplyProgressDetailsWidget* m_ProgressDetailsWidget;
0159     const OperationRunner& m_OperationRunner;
0160     Report* m_Report;
0161     QString m_SavedParentTitle;
0162     QTimer m_Timer;
0163     QElapsedTimer m_ElapsedTimer;
0164     QTreeWidgetItem* m_CurrentOpItem;
0165     QTreeWidgetItem* m_CurrentJobItem;
0166     int m_LastReportUpdate;
0167 
0168     QDialogButtonBox* dialogButtonBox;
0169     QPushButton* okButton;
0170     QPushButton* cancelButton;
0171     QPushButton* detailsButton;
0172 
0173     static const QString m_TimeFormat;
0174 };
0175 
0176 #endif