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 #include "multiprogressdialog.h"
28 
MultiProgressDialog(QWidget * parent)29 MultiProgressDialog::MultiProgressDialog(QWidget* parent) : QDialog(parent)
30 {
31 	setupUi(this);
32 	connect(buttonCancel, SIGNAL(clicked()), this, SLOT(emitCancel()));
33 }
34 
MultiProgressDialog(const QString & titleText,const QString & cancelButtonText,QWidget * parent)35 MultiProgressDialog::MultiProgressDialog(const QString& titleText, const QString & cancelButtonText, QWidget* parent) : QDialog(parent)
36 {
37 	setupUi(this);
38 	setWindowTitle(titleText);
39 	buttonCancel->setText(cancelButtonText);
40 	connect(buttonCancel, SIGNAL(clicked()), this, SLOT(emitCancel()));
41 }
emitCancel()42 void MultiProgressDialog::emitCancel()
43 {
44 	emit canceled();
45 }
46 
removeExtraProgressBars()47 void MultiProgressDialog::removeExtraProgressBars()
48 {
49 	progressBars.clear();
50 	progressLabels.clear();
51 }
52 
addExtraProgressBars(const QStringList & barsList,const QStringList & barsTexts,const QList<bool> & barsNumerical)53 bool MultiProgressDialog::addExtraProgressBars(const QStringList &barsList, const QStringList &barsTexts, const QList<bool>& barsNumerical)
54 {
55 	uint barCount=barsList.count();
56 	if (barCount==0)
57 		return false;
58 	int gridLayoutRow=gridLayout->rowCount();
59 	for (uint i=0; i<barCount; ++i)
60 	{
61 		QString barName(barsList[i]);
62 		if(progressBarTitles.contains(barName))
63 			continue;
64 		progressBarTitles.append(barName);
65 		progressBars.insert(barName, new QProgressBar(this));
66 		if (barsNumerical[i])
67 			progressBars[barName]->setFormat(tr("%v of %m"));
68 		progressBars[barName]->setMinimumWidth(150);
69 		progressLabels.insert(barName, new QLabel(barsTexts[i], this));
70 		gridLayout->addWidget(progressLabels[barName], gridLayoutRow, 0);
71 		gridLayout->addWidget(progressBars[barName], gridLayoutRow, 1);
72 		++gridLayoutRow;
73 	}
74 	return true;
75 }
76 
overallProgress() const77 int MultiProgressDialog::overallProgress() const
78 {
79 	return overallProgressBar->value();
80 }
81 
progress(const QString & barName) const82 int MultiProgressDialog::progress(const QString &barName) const
83 {
84 	int progress = 0;
85 	if (progressBars.contains(barName))
86 		progress = progressBars[barName]->value();
87 	return progress;
88 }
89 
setLabel(const QString & barName,const QString & newLabel)90 bool MultiProgressDialog::setLabel(const QString &barName, const QString & newLabel)
91 {
92 	if (progressLabels.contains(barName))
93 	{
94 		progressLabels[barName]->setText(newLabel);
95 		return true;
96 	}
97 	return false;
98 }
99 
setBusyIndicator(const QString & barName)100 bool MultiProgressDialog::setBusyIndicator(const QString &barName)
101 {
102 	if (progressBars.contains(barName))
103 	{
104 		progressBars[barName]->setMaximum(0);
105 		progressBars[barName]->setMinimum(0);
106 		return true;
107 	}
108 	return false;
109 }
110 
setTotalSteps(const QString & barName,int totalSteps)111 bool MultiProgressDialog::setTotalSteps(const QString &barName, int totalSteps)
112 {
113 	if (progressBars.contains(barName))
114 	{
115 		progressBars[barName]->setMaximum(totalSteps);
116 		return true;
117 	}
118 	return false;
119 }
120 
setProgress(const QString & barName,int progress)121 bool MultiProgressDialog::setProgress(const QString &barName, int progress)
122 {
123 	if (progressBars.contains(barName))
124 	{
125 		progressBars[barName]->setValue(progress);
126 		return true;
127 	}
128 	return false;
129 }
130 
setProgress(const QString & barName,int progress,int totalSteps)131 bool MultiProgressDialog::setProgress(const QString &barName, int progress, int totalSteps)
132 {
133 	if (progressBars.contains(barName))
134 	{
135 		progressBars[barName]->setMaximum(totalSteps);
136 		progressBars[barName]->setValue(progress);
137 		return true;
138 	}
139 	return false;
140 }
141 
setupBar(const QString & barName,const QString & barText,int progress,int totalSteps)142 bool MultiProgressDialog::setupBar(const QString &barName, const QString & barText, int progress, int totalSteps)
143 {
144 	if (progressLabels.contains(barName))
145 		progressLabels[barName]->setText(barText);
146 	else
147 		return false;
148 	if (progressBars.contains(barName))
149 	{
150 		progressBars[barName]->setMaximum(totalSteps);
151 		progressBars[barName]->setValue(progress);
152 		return true;
153 	}
154 	return false;
155 }
156 
157 
setCancelButtonText(const QString & cancelButtonText)158 void MultiProgressDialog::setCancelButtonText(const QString & cancelButtonText)
159 {
160 	buttonCancel->setText(cancelButtonText);
161 }
162 
setOverallTotalSteps(int totalSteps)163 void MultiProgressDialog::setOverallTotalSteps(int totalSteps)
164 {
165 	overallProgressBar->setMaximum(totalSteps);
166 }
167 
setOverallProgress(int progress)168 void MultiProgressDialog::setOverallProgress(int progress)
169 {
170 	overallProgressBar->setValue(progress);
171 }
172 
setOverallProgress(int progress,int totalSteps)173 void MultiProgressDialog::setOverallProgress(int progress, int totalSteps)
174 {
175 	overallProgressBar->setMaximum(totalSteps);
176 	overallProgressBar->setValue(progress);
177 }
178