r14798 by cbradney - #8848: Multi progress bar for collect for output
scribus-commit
scribus-commit at lists.scribus.net
Tue Feb 23 22:00:32 CET 2010
Revision: 14798
Author: cbradney
Date: 2010-02-23T20:50:25.363260Z
Commit message: #8848: Multi progress bar for collect for output
Changeset:
M /trunk/Scribus/scribus/collect4output.cpp
M /trunk/Scribus/scribus/scribus.cpp
M /trunk/Scribus/scribus/CMakeLists.txt
A /trunk/Scribus/scribus/ui/collectforoutput_ui.h
M /trunk/Scribus/scribus/collect4output.h
A /trunk/Scribus/scribus/ui/collectforoutput_ui.cpp
Diffs:
Index: scribus/collect4output.cpp
===================================================================
--- scribus/collect4output.cpp (revision 14797)
+++ scribus/collect4output.cpp (revision 14798)
@@ -28,17 +28,32 @@
#include <QMap>
#include <QDir>
-CollectForOutput::CollectForOutput(ScribusDoc* doc, bool withFontsA, bool withProfilesA, bool compressDocA)
+CollectForOutput::CollectForOutput(ScribusDoc* doc, QString outputDirectory, bool withFonts, bool withProfiles, bool compressDoc)
: QObject(ScCore),
- m_Doc(0)
+ m_Doc(0),
+ m_outputDirectory(QString::null),
+ profileCount(0),
+ itemCount(0),
+ fontCount(0),
+ patternCount(0),
+ uiCollect(false)
{
m_Doc=doc;
- outputDirectory = QString();
- compressDoc = compressDocA;
- withFonts = withFontsA;
- withProfiles = withProfilesA;
+ if (outputDirectory!=QString::null)
+ m_outputDirectory=outputDirectory;
+ m_compressDoc = compressDoc;
+ m_withFonts = withFonts;
+ m_withProfiles = withProfiles;
dirs = PrefsManager::instance()->prefsFile->getContext("dirs");
collectedFiles.clear();
+
+ if (m_withProfiles)
+ m_Doc->getUsedProfiles(docProfiles);
+ if (m_withFonts)
+ fontCount=m_Doc->UsedFonts.count();
+ itemCount=m_Doc->MasterItems.count()+m_Doc->DocItems.count()+m_Doc->FrameItems.count();
+ patterns = m_Doc->getUsedPatterns();
+ patternCount=patterns.count();
}
bool CollectForOutput::newDirDialog()
@@ -52,20 +67,20 @@
wdir = dirs->get("collect", prefsDocDir);
else
wdir = dirs->get("collect", ".");
- outputDirectory = ScCore->primaryMainWindow()->CFileDialog(wdir, tr("Choose a Directory"), "", "", fdDirectoriesOnly, &compressDoc, &withFonts, &withProfiles);
+ m_outputDirectory = ScCore->primaryMainWindow()->CFileDialog(wdir, tr("Choose a Directory"), "", "", fdDirectoriesOnly, &m_compressDoc, &m_withFonts, &m_withProfiles);
}
- if (outputDirectory.isEmpty())
+ if (m_outputDirectory.isEmpty())
return false;
- if (!outputDirectory.endsWith("/"))
- outputDirectory += "/";
- QDir dir(outputDirectory);
+ if (!m_outputDirectory.endsWith("/"))
+ m_outputDirectory += "/";
+ QDir dir(m_outputDirectory);
if (!dir.exists())
{
- bool created = dir.mkpath(outputDirectory);
+ bool created = dir.mkpath(m_outputDirectory);
if (!created)
{
QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning,
- "<qt>" + tr("Cannot create directory:\n%1").arg(outputDirectory) + "</qt>",
+ "<qt>" + tr("Cannot create directory:\n%1").arg(m_outputDirectory) + "</qt>",
CommonStrings::tr_OK);
return false;
}
@@ -73,37 +88,38 @@
return true;
}
-QString CollectForOutput::collect()
+QString CollectForOutput::collect(QString &newFileName)
{
if (!newDirDialog())
- return "";
+ return "Collect cancelled or unable to create collect destination directory";
ScCore->fileWatcher->forceScan();
ScCore->fileWatcher->stop();
- dirs->set("collect", outputDirectory.left(outputDirectory.lastIndexOf("/",-2)));
+ dirs->set("collect", m_outputDirectory.left(m_outputDirectory.lastIndexOf("/",-2)));
ScCore->primaryMainWindow()->setStatusBarInfoText( tr("Collecting..."));
if (!collectItems())
{
+ QString errorMsg( tr("Cannot collect all files for output for file:\n%1").arg(newName) );
QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning,
- "<qt>" + tr("Cannot collect all files for output for file:\n%1").arg(newName) + "</qt>",
+ "<qt>" + errorMsg + "</qt>",
CommonStrings::tr_OK);
- return "";
+ return errorMsg;
}
- if (withFonts)
+ if (m_withFonts)
collectFonts();
- if (withProfiles)
+ if (m_withProfiles)
collectProfiles();
- /* collect document must go last because of image paths changes
- in collectItems() */
+ /* collect document must go last because of image paths changes in collectItems() */
if (!collectDocument())
{
- QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning, "<qt>" + tr("Cannot collect the file: \n%1").arg(newName) + "</qt>", CommonStrings::tr_OK);
- return "";
+ QString errorMsg( tr("Cannot collect the file: \n%1").arg(newName) );
+ QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning, "<qt>" + errorMsg + "</qt>", CommonStrings::tr_OK);
+ return errorMsg;
}
- QDir::setCurrent(outputDirectory);
+ QDir::setCurrent(m_outputDirectory);
ScCore->primaryMainWindow()->updateActiveWindowCaption(newName);
UndoManager::instance()->renameStack(newName);
ScCore->primaryMainWindow()->scrActions["fileSave"]->setEnabled(false);
@@ -113,13 +129,14 @@
ScCore->primaryMainWindow()->mainWindowProgressBar->reset();
ScCore->fileWatcher->start();
collectedFiles.clear();
- return newName;
+ newFileName=newName;
+ return QString::null;
}
bool CollectForOutput::collectDocument()
{
- QFileInfo fi = QFileInfo(outputDirectory);
- newName = outputDirectory;
+ QFileInfo fi = QFileInfo(m_outputDirectory);
+ newName = m_outputDirectory;
if (!fi.exists())
return false;
if (!fi.isDir() || !fi.isWritable())
@@ -134,7 +151,7 @@
newName += m_Doc->DocName+".sla";
m_Doc->hasName = true;
- if (compressDoc)
+ if (m_compressDoc)
{
if (!newName.endsWith(".gz"))
newName += ".gz";
@@ -155,6 +172,7 @@
bool CollectForOutput::collectItems()
{
uint counter = 0;
+ int c=0;
for (uint lc = 0; lc < 3; ++lc)
{
PageItem* ite = NULL;
@@ -185,9 +203,10 @@
break;
}
processItem(ite);
+ if (uiCollect)
+ emit itemsCollected(c++);
}
}
- QStringList patterns = m_Doc->getUsedPatterns();
for (int c = 0; c < patterns.count(); ++c)
{
ScPattern pa = m_Doc->docPatterns[patterns[c]];
@@ -195,6 +214,8 @@
{
processItem(pa.items.at(o));
}
+ if (uiCollect)
+ emit patternsCollected(c);
}
return true;
}
@@ -281,10 +302,11 @@
PrefsManager *prefsManager = PrefsManager::instance();
QMap<QString,int>::Iterator it3;
QMap<QString,int>::Iterator it3end = m_Doc->UsedFonts.end();
+ int c=0;
for (it3 = m_Doc->UsedFonts.begin(); it3 != it3end; ++it3)
{
- QFileInfo itf = QFileInfo(prefsManager->appPrefs.fontPrefs.AvailFonts[it3.key()].fontFilePath());
- copyFileAtomic(prefsManager->appPrefs.fontPrefs.AvailFonts[it3.key()].fontFilePath(), outputDirectory + itf.fileName());
+ QFileInfo itf(prefsManager->appPrefs.fontPrefs.AvailFonts[it3.key()].fontFilePath());
+ copyFileAtomic(prefsManager->appPrefs.fontPrefs.AvailFonts[it3.key()].fontFilePath(), m_outputDirectory + itf.fileName());
if (prefsManager->appPrefs.fontPrefs.AvailFonts[it3.key()].type() == ScFace::TYPE1)
{
QStringList metrics;
@@ -307,9 +329,11 @@
{
QString origAFM = metrics[a];
QFileInfo fi(origAFM);
- copyFileAtomic(origAFM, outputDirectory + fi.fileName());
+ copyFileAtomic(origAFM, m_outputDirectory + fi.fileName());
}
}
+ if (uiCollect)
+ emit fontsCollected(c++);
}
return true;
}
@@ -356,14 +380,15 @@
bool CollectForOutput::collectProfiles()
{
- ProfilesL docProfiles;
- m_Doc->getUsedProfiles(docProfiles);
ProfilesL::Iterator itend = docProfiles.end();
+ int c=0;
for (ProfilesL::Iterator it = docProfiles.begin(); it != itend; ++it)
{
QString profileName(it.key());
QString profilePath(it.value());
- copyFileAtomic(profilePath, outputDirectory + QFileInfo(profilePath).fileName());
+ copyFileAtomic(profilePath, m_outputDirectory + QFileInfo(profilePath).fileName());
+ if (uiCollect)
+ emit profilesCollected(c++);
}
return true;
}
@@ -387,7 +412,7 @@
++cnt;
}
if (copy)
- copyFileAtomic(oldFile, outputDirectory + newFile);
+ copyFileAtomic(oldFile, m_outputDirectory + newFile);
collectedFiles[newFile] = oldFile;
- return outputDirectory + newFile;
+ return m_outputDirectory + newFile;
}
Index: scribus/collect4output.h
===================================================================
--- scribus/collect4output.h (revision 14797)
+++ scribus/collect4output.h (revision 14798)
@@ -10,6 +10,8 @@
#include <QObject>
#include <QMap>
+#include "scribusstructs.h"
+
class QString;
class ScribusDoc;
class PrefsContext;
@@ -26,70 +28,83 @@
{
Q_OBJECT
-public:
- /*! \brief Setup the attributes
- \param doc a Scribus doecument reference
- \param withFontsA collect/move fonts into output directory too
- \param withProfilesA collect/move CMS profiles into output directory too
- \param compressDocA use gzipped document
- */
- CollectForOutput(ScribusDoc* doc, bool withFontsA=false, bool withProfilesA=false, bool compressDocA=false);
- ~CollectForOutput(){};
+ public:
+ /*! \brief Setup the attributes
+ \param doc a Scribus doecument reference
+ \param withFonts collect/move fonts into output directory too
+ \param withProfiles collect/move CMS profiles into output directory too
+ \param compressDoc use gzipped document
+ */
+ CollectForOutput(ScribusDoc* doc, QString outputDirectory=QString::null, bool withFonts=false, bool withProfiles=false, bool compressDoc=false);
+ ~CollectForOutput(){};
- /*! \brief Main method doing everything.
- It calls all related methods
- */
- QString collect();
+ /*! \brief Main method doing everything.
+ It calls all related methods
+ */
+ virtual QString collect(QString &newFileName);
-private:
- /*! Doc to collect */
- ScribusDoc* m_Doc;
- /*! Use compressed document. See the constructor */
- bool compressDoc;
- /*! Collect fonts too. See the constructor */
- bool withFonts;
- /*! Collect icc profiles too. See the constructor */
- bool withProfiles;
- /*! User defined directory via GUI */
- QString outputDirectory;
- /*! Name of the moved file with the new directory path */
- QString newName;
- /*! \brief Remember already collected files to collect the same files only once.
- It's QMap - newFile, oldFile.*/
- QMap<QString, QString> collectedFiles;
- /*! Reference to the preferences */
- PrefsContext* dirs;
+ protected:
+ /*! Doc to collect */
+ ScribusDoc* m_Doc;
+ /*! Use compressed document. See the constructor */
+ bool m_compressDoc;
+ /*! Collect fonts too. See the constructor */
+ bool m_withFonts;
+ /*! Collect icc profiles too. See the constructor */
+ bool m_withProfiles;
+ /*! User defined directory via GUI */
+ QString m_outputDirectory;
+ /*! Name of the moved file with the new directory path */
+ QString newName;
+ /*! \brief Remember already collected files to collect the same files only once.
+ It's QMap - newFile, oldFile.*/
+ QMap<QString, QString> collectedFiles;
+ /*! Reference to the preferences */
+ PrefsContext* dirs;
- /*! Ask user for output directory via GUI.
- \retval true on success */
- bool newDirDialog();
- /*! Check permissions and export document itself.
- \retval true on success */
- bool collectDocument();
- /*! Collect all related items, esp. images.
- \retval true on success */
- bool collectItems();
- /*! Processes the item, helper function for collectItems() */
- void processItem(PageItem *ite);
- /*! Collect used fonts if requested.
- \retval true on success */
- bool collectFonts();
- /*! Helper function for collectFonts() */
- QStringList findFontMetrics(const QString& baseDir, const QString& baseName) const;
- /*! Collect used profiles if requested.
- \retval true on success */
- bool collectProfiles();
- /*! \brief Copy used file into new location with magic checks.
- It looks into collectedFiles map. If there is newFile (key) already
- found - it will construct new filename to prevent overwriting.
- E.g. newFile.png can be newFile_0.png.
- It checks already collected files not to collect one item 2 times.
- \param oldFile full path of the original file
- \param newFile suggested fullpath of the collected file
- \retval QString really used fullpath of the new file
- */
- QString collectFile(QString oldFile, QString newFile);
+ /*! Ask user for output directory via GUI.
+ \retval true on success */
+ bool newDirDialog();
+ /*! Check permissions and export document itself.
+ \retval true on success */
+ bool collectDocument();
+ /*! Collect all related items, esp. images.
+ \retval true on success */
+ bool collectItems();
+ /*! Processes the item, helper function for collectItems() */
+ void processItem(PageItem *ite);
+ /*! Collect used fonts if requested.
+ \retval true on success */
+ bool collectFonts();
+ /*! Helper function for collectFonts() */
+ QStringList findFontMetrics(const QString& baseDir, const QString& baseName) const;
+ /*! Collect used profiles if requested.
+ \retval true on success */
+ bool collectProfiles();
+ /*! \brief Copy used file into new location with magic checks.
+ It looks into collectedFiles map. If there is newFile (key) already
+ found - it will construct new filename to prevent overwriting.
+ E.g. newFile.png can be newFile_0.png.
+ It checks already collected files not to collect one item 2 times.
+ \param oldFile full path of the original file
+ \param newFile suggested fullpath of the collected file
+ \retval QString really used fullpath of the new file
+ */
+ QString collectFile(QString oldFile, QString newFile);
+ ProfilesL docProfiles;
+ QStringList patterns;
+ int profileCount;
+ int itemCount;
+ int fontCount;
+ int patternCount;
+ bool uiCollect;
+
+ signals:
+ void fontsCollected(int);
+ void patternsCollected(int);
+ void profilesCollected(int);
+ void itemsCollected(int);
};
#endif
Index: scribus/ui/collectforoutput_ui.cpp
===================================================================
--- scribus/ui/collectforoutput_ui.cpp (revision 0)
+++ scribus/ui/collectforoutput_ui.cpp (revision 14798)
@@ -0,0 +1,155 @@
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+
+#include "collectforoutput_ui.h"
+
+#include "commonstrings.h"
+#include "undomanager.h"
+#include "filewatcher.h"
+#include "prefscontext.h"
+#include "scribuscore.h"
+#include "scraction.h"
+#include "scribusapp.h"
+
+CollectForOutput_UI::CollectForOutput_UI(QWidget* parent, ScribusDoc* doc, QString outputDirectory, bool withFonts, bool withProfiles, bool compressDoc) :
+ CollectForOutput(doc, outputDirectory, withFonts, withProfiles, compressDoc)
+{
+ uiCollect=true;
+ connect(this, SIGNAL(fontsCollected(int)), this, SLOT(collectedFonts(int)));
+ connect(this, SIGNAL(itemsCollected(int)), this, SLOT(collectedItems(int)));
+ connect(this, SIGNAL(patternsCollected(int)), this, SLOT(collectedPatterns(int)));
+ connect(this, SIGNAL(profilesCollected(int)), this, SLOT(collectedProfiles(int)));
+}
+
+QString CollectForOutput_UI::collect(QString &newFileName)
+{
+ if (!newDirDialog())
+ return "Collect cancelled or unable to create collect destination directory";
+
+ progressDialog=new MultiProgressDialog("Collect for Output", "Cancel");
+ QStringList barNames, barTexts;
+ QList<bool> barsNumeric;
+ barNames << "items";
+ barTexts << tr("Collecting Items:");
+ barsNumeric << true;
+ barNames << "patterns";
+ barTexts << tr("Collecting Patterns:");
+ barsNumeric << true;
+
+ if (m_withFonts)
+ {
+ barNames << "fonts";
+ barTexts << tr("Collecting Fonts:");
+ barsNumeric << true;
+ }
+ if (m_withProfiles)
+ {
+ barNames << "profiles";
+ barTexts << tr("Collecting Profiles:");
+ barsNumeric << true;
+ }
+
+ progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric);
+ progressDialog->setOverallTotalSteps(profileCount+itemCount+fontCount+patternCount);
+ progressDialog->setTotalSteps("items", itemCount);
+ progressDialog->setTotalSteps("patterns", patternCount);
+ progressDialog->setProgress("items", 0);
+ progressDialog->setProgress("patterns", 0);
+ if (m_withFonts)
+ {
+ progressDialog->setTotalSteps("fonts", fontCount);
+ progressDialog->setProgress("fonts", 0);
+ }
+ if (m_withProfiles)
+ {
+ progressDialog->setTotalSteps("profiles", profileCount);
+ progressDialog->setProgress("profiles", 0);
+ }
+ progressDialog->setOverallProgress(0);
+
+
+
+ ScCore->fileWatcher->forceScan();
+ ScCore->fileWatcher->stop();
+
+
+ progressDialog->show();
+// connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelRequested()));
+ ScQApp->processEvents();
+
+ dirs->set("collect", m_outputDirectory.left(m_outputDirectory.lastIndexOf("/",-2)));
+ ScCore->primaryMainWindow()->setStatusBarInfoText( tr("Collecting..."));
+
+ if (!collectItems())
+ {
+ QString errorMsg( tr("Cannot collect all files for output for file:\n%1").arg(newName) );
+ QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning,
+ "<qt>" + errorMsg + "</qt>",
+ CommonStrings::tr_OK);
+ return errorMsg;
+ }
+ progressDialog->setOverallProgress(itemCount+patternCount);
+
+ if (m_withFonts)
+ {
+ collectFonts();
+ progressDialog->setProgress("fonts", fontCount);
+ progressDialog->setOverallProgress(itemCount+patternCount+fontCount);
+ }
+ if (m_withProfiles)
+ {
+ collectProfiles();
+ progressDialog->setProgress("profiles", profileCount);
+ progressDialog->setOverallProgress(itemCount+patternCount+fontCount+profileCount);
+ }
+ /* collect document must go last because of image paths changes in collectItems() */
+ if (!collectDocument())
+ {
+ QString errorMsg( tr("Cannot collect the file: \n%1").arg(newName) );
+ QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning, "<qt>" + errorMsg + "</qt>", CommonStrings::tr_OK);
+ return errorMsg;
+ }
+
+ QDir::setCurrent(m_outputDirectory);
+ ScCore->primaryMainWindow()->updateActiveWindowCaption(newName);
+ UndoManager::instance()->renameStack(newName);
+ ScCore->primaryMainWindow()->scrActions["fileSave"]->setEnabled(false);
+ ScCore->primaryMainWindow()->scrActions["fileRevert"]->setEnabled(false);
+ ScCore->primaryMainWindow()->updateRecent(newName);
+ ScCore->primaryMainWindow()->setStatusBarInfoText("");
+ ScCore->primaryMainWindow()->mainWindowProgressBar->reset();
+ ScCore->fileWatcher->start();
+ collectedFiles.clear();
+ newFileName=newName;
+ progressDialog->close();
+ delete progressDialog;
+ return QString::null;
+}
+
+void CollectForOutput_UI::collectedFonts(int c)
+{
+ progressDialog->setProgress("fonts", c);
+ ScQApp->processEvents();
+}
+
+void CollectForOutput_UI::collectedItems(int c)
+{
+ progressDialog->setProgress("items", c);
+ ScQApp->processEvents();
+}
+
+void CollectForOutput_UI::collectedPatterns(int c)
+{
+ progressDialog->setProgress("patterns", c);
+ ScQApp->processEvents();
+}
+
+void CollectForOutput_UI::collectedProfiles(int c)
+{
+ progressDialog->setProgress("profiles", c);
+ ScQApp->processEvents();
+}
Property changes on: scribus/ui/collectforoutput_ui.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Index: scribus/ui/collectforoutput_ui.h
===================================================================
--- scribus/ui/collectforoutput_ui.h (revision 0)
+++ scribus/ui/collectforoutput_ui.h (revision 14798)
@@ -0,0 +1,32 @@
+/*
+For general Scribus (>=1.3.2) copyright and licensing information please refer
+to the COPYING file provided with the program. Following this notice may exist
+a copyright and/or license notice that predates the release of Scribus 1.3.2
+for which a new license (GPL+exception) is in place.
+*/
+
+#ifndef COLLECTFOROUTPUT_UI_H
+#define COLLECTFOROUTPUT_UI_H
+
+#include "collect4output.h"
+#include "multiprogressdialog.h"
+
+class CollectForOutput_UI : public CollectForOutput
+{
+ Q_OBJECT
+ public:
+ CollectForOutput_UI(QWidget *parent, ScribusDoc* doc, QString outputDirectory=QString::null, bool withFonts=false, bool withProfiles=false, bool compressDoc=false);
+ virtual QString collect(QString &newFileName);
+ signals:
+
+ protected slots:
+ void collectedFonts(int);
+ void collectedItems(int);
+ void collectedPatterns(int);
+ void collectedProfiles(int);
+
+ protected:
+ MultiProgressDialog* progressDialog;
+};
+
+#endif // COLLECTFOROUTPUT_UI_H
Property changes on: scribus/ui/collectforoutput_ui.h
___________________________________________________________________
Added: svn:eol-style
+ native
Index: scribus/scribus.cpp
===================================================================
--- scribus/scribus.cpp (revision 14797)
+++ scribus/scribus.cpp (revision 14798)
@@ -89,7 +89,7 @@
#include "ui/charselect.h"
#include "ui/checkDocument.h"
#include "ui/cmsprefs.h"
-#include "collect4output.h"
+#include "ui/collectforoutput_ui.h"
#include "ui/colorcombo.h"
#include "ui/colorm.h"
#include "commonstrings.h"
@@ -8973,8 +8973,10 @@
QString ScribusMainWindow::Collect(bool compress, bool withFonts, const bool withProfiles, const QString& )
{
- CollectForOutput c(doc, withFonts, withProfiles, compress);
- return c.collect();
+ CollectForOutput_UI c(this, doc, QString::null, withFonts, withProfiles, compress);
+ QString newFileName;
+ QString errorMsg=c.collect(newFileName);
+ return newFileName;
}
void ScribusMainWindow::docCheckToggle(bool visible)
Index: scribus/CMakeLists.txt
===================================================================
--- scribus/CMakeLists.txt (revision 14797)
+++ scribus/CMakeLists.txt (revision 14798)
@@ -183,6 +183,7 @@
ui/cmsprefs.h
ui/cmykfw.h
collect4output.h
+ ui/collectforoutput_ui.h
colorblind.h
ui/colorchart.h
ui/colorcombo.h
@@ -466,6 +467,7 @@
ui/cmsprefs.cpp
ui/cmykfw.cpp
collect4output.cpp
+ ui/collectforoutput_ui.cpp
colorblind.cpp
ui/colorchart.cpp
ui/colorcombo.cpp
More information about the scribus-commit
mailing list