1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 /***************************************************************************
8 *   Copyright (C) 2005 by Craig Bradney                                   *
9 *   cbradney@zip.com.au                                                   *
10 *                                                                         *
11 *   This program is free software; you can redistribute it and/or modify  *
12 *   it under the terms of the GNU General Public License as published by  *
13 *   the Free Software Foundation; either version 2 of the License, or     *
14 *   (at your option) any later version.                                   *
15 *                                                                         *
16 *   This program is distributed in the hope that it will be useful,       *
17 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
18 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
19 *   GNU General Public License for more details.                          *
20 *                                                                         *
21 *   You should have received a copy of the GNU General Public License     *
22 *   along with this program; if not, write to the                         *
23 *   Free Software Foundation, Inc.,                                       *
24 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
25 ***************************************************************************/
26 
27 #ifndef MULTIPROGRESSDIALOG_H
28 #define MULTIPROGRESSDIALOG_H
29 
30 #include "scribusapi.h"
31 #include "ui_multiprogressdialog.h"
32 
33 #include <QProgressBar>
34 #include <QDialog>
35 #include <QLabel>
36 #include <QLayout>
37 #include <QMap>
38 #include <QPushButton>
39 #include <QStringList>
40 #include <QString>
41 #include <QList>
42 
43 
44 class SCRIBUS_API MultiProgressDialog : public QDialog, Ui::MultiProgressDialog
45 {
46 	Q_OBJECT
47 
48 	public:
49 		MultiProgressDialog(QWidget* parent=nullptr);
50 		/**
51 		 * Create a multi progress bar dialog for long operations with multiple steps. The dialog includes
52 		 * one standard progress bar, typically for the overall progress and others may be added easily.
53 		 * @param titleText Title of the dialog
54 		 * @param cancelButtonText Text of the cancel button.. Cancel, Close, @sa CommontStrings::
55 		 * @param parent Parent widget for the dialog, commonly ScribusMainWindow
56 		 * @param f Qt GUI flags
57 		 */
58 		MultiProgressDialog(const QString& titleText, const QString& cancelButtonText, QWidget* parent=nullptr);
59 		~MultiProgressDialog() = default;
60 
61 		/**
62 		 * Remove all progress bars other than the main one
63 		 */
64 		void removeExtraProgressBars();
65 		/**
66 		 * Add a list of progress bars, where barsList contains a list of references and barTexts
67 		 * contains the labels for the bars. Set the bools in barsNumerical to true to get a "X of Y" indicator
68 		 * Eg:
69 		 * "MYBAR1" -> "My Bar 1:"
70 		 * "MYBAR2" -> "My Bar 2:"
71 		 * @param barsList
72 		 * @param barsTexts
73 		 * @param barsNumerical
74 		 * @return Success
75 		 */
76 		bool addExtraProgressBars(const QStringList &barsList, const QStringList &barsTexts, const QList<bool>& barsNumerical);
77 		/**
78 		 * Get the overall progress for the dialog
79 		 * @return overall progress
80 		 */
81 		int overallProgress() const;
82 		/**
83 		 * Get the progress for a user defined progress bar
84 		 * @param barName
85 		 * @return progress for specified user bar
86 		 */
87 		int progress(const QString& barName) const;
88 		/**
89 		 * Set a new label for a user defined progress bar
90 		 * @param barName Progress bar name
91 		 * @param newLabel New label
92 		 * @return Success
93 		 */
94 		bool setLabel(const QString& barName, const QString& newLabel);
95 		/**
96 		 * Sets a user defined progress bar to a busy bar
97 		 * @param barName
98 		 * @return Success
99 		 */
100 		bool setBusyIndicator(const QString& barName);
101 		/**
102 		 * Set the total steps for a user defined progress bar
103 		 * @param barName
104 		 * @param totalSteps
105 		 * @return Success
106 		 */
107 		bool setTotalSteps(const QString& barName, int totalSteps);
108 		/**
109 		 * Set the progress for a user defined progress bar
110 		 * @param barName
111 		 * @param progress
112 		 * @return
113 		 */
114 		bool setProgress(const QString& barName, int progress);
115 		/**
116 		 * Set the prgress and total steps for a user defined progress bar
117 		 * @param barName
118 		 * @param progress
119 		 * @param totalSteps
120 		 * @return
121 		 */
122 		bool setProgress(const QString& barName, int progress, int totalSteps);
123 		/**
124 		 * Set the overall total steps for the dialog
125 		 * @param totalSteps
126 		 */
127 		void setOverallTotalSteps(int totalSteps);
128 		/**
129 		 * Set the overall progress for the dialog
130 		 * @param progress
131 		 */
132 		void setOverallProgress(int progress);
133 		/**
134 		 * Set the overall progress and total steps for the dialog
135 		 * @param progress
136 		 * @param totalSteps
137 		 */
138 		void setOverallProgress(int progress, int totalSteps);
139 		/**
140 		 * Create a new progress bar in one step
141 		 * @param barName
142 		 * @param barText
143 		 * @param progress
144 		 * @param totalSteps
145 		 * @return
146 		 */
147 		bool setupBar(const QString&barName, const QString&barText, int progress, int totalSteps);
148 		/**
149 		 * Set the cancel button text
150 		 * @param cancelButtonText
151 		 */
152 		void setCancelButtonText(const QString& cancelButtonText);
153 
154 	signals:
155 		void canceled();
156 
157 	protected:
158 		QStringList progressBarTitles;
159 		QMap<QString, QProgressBar*> progressBars;
160 		QMap<QString, QLabel*> progressLabels;
161 
162 	private slots:
163 		void emitCancel();
164 };
165 
166 #endif
167