View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0011040 | Scribus | General | public | 2012-08-20 17:09 | 2012-11-13 20:34 |
Reporter | pygmee | Assigned To | pygmee | ||
Priority | normal | Severity | minor | Reproducibility | have not tried |
Status | closed | Resolution | fixed | ||
Platform | x86 | OS | Ubuntu | OS Version | 12.04 |
Product Version | 1.5.0svn | ||||
Target Version | 1.5.0 | Fixed in Version | 1.5.0svn | ||
Summary | 0011040: Collect files in sub-directories | ||||
Description | actually collect4output collects all the files in one dir. It can be difficult to reuse files on large document such as magazines in which lots of pictures and fonts can be used. Having separate dirs for each collected ressources (fonts, pictures, profile) can be interesting. Adding to that a little report can be include to list ressources with their path and some other document informations to be listed (could be based on JDF or so). | ||||
Tags | No tags attached. | ||||
Patch | |||||
|
collect4output-1.0.patch (4,181 bytes)
Index: scribus/collect4output.cpp =================================================================== --- scribus/collect4output.cpp (révision 17756) +++ scribus/collect4output.cpp (copie de travail) @@ -74,10 +74,10 @@ return false; if (!m_outputDirectory.endsWith("/")) m_outputDirectory += "/"; - QDir dir(m_outputDirectory); + QDir dir(m_outputDirectory); if (!dir.exists()) { - bool created = dir.mkpath(m_outputDirectory); + bool created = dir.mkpath(m_outputDirectory); if (!created) { QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning, @@ -86,6 +86,42 @@ return false; } } + QDir dir2(m_outputDirectory+"images/"); + if (!dir2.exists()) + { + bool created = dir2.mkpath(m_outputDirectory+"images/"); + if (!created) + { + QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning, + "<qt>" + tr("Cannot create directory:\n%1").arg(m_outputDirectory+"images/") + "</qt>", + CommonStrings::tr_OK); + return false; + } + } + QDir dir3(m_outputDirectory+"fonts/"); + if (!dir3.exists()) + { + bool created = dir3.mkpath(m_outputDirectory+"fonts/"); + if (!created) + { + QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning, + "<qt>" + tr("Cannot create directory:\n%1").arg(m_outputDirectory+"fonts/") + "</qt>", + CommonStrings::tr_OK); + return false; + } + } + QDir dir4(m_outputDirectory+"profiles/"); + if (!dir4.exists()) + { + bool created = dir4.mkpath(m_outputDirectory+"profiles/"); + if (!created) + { + QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning, + "<qt>" + tr("Cannot create directory:\n%1").arg(m_outputDirectory+"profiles/") + "</qt>", + CommonStrings::tr_OK); + return false; + } + } return true; } @@ -337,8 +373,8 @@ for (it3 = m_Doc->UsedFonts.begin(); it3 != it3end; ++it3) { 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) + copyFileAtomic(prefsManager->appPrefs.fontPrefs.AvailFonts[it3.key()].fontFilePath(), m_outputDirectory + "fonts/" + itf.fileName()); + if (prefsManager->appPrefs.fontPrefs.AvailFonts[it3.key()].type() == ScFace::TYPE1) { QStringList metrics; QString fontDir = itf.absolutePath(); @@ -360,7 +396,7 @@ { QString origAFM = metrics[a]; QFileInfo fi(origAFM); - copyFileAtomic(origAFM, m_outputDirectory + fi.fileName()); + copyFileAtomic(origAFM, m_outputDirectory + "fonts/" + fi.fileName()); } } if (uiCollect) @@ -419,7 +455,7 @@ { QString profileName(it.key()); QString profilePath(it.value()); - copyFileAtomic(profilePath, m_outputDirectory + QFileInfo(profilePath).fileName()); + copyFileAtomic(profilePath, m_outputDirectory + "profiles/" + QFileInfo(profilePath).fileName()); if (uiCollect) emit profilesCollected(c++); } @@ -445,7 +481,7 @@ ++cnt; } if (copy) - copyFileAtomic(oldFile, m_outputDirectory + newFile); + copyFileAtomic(oldFile, m_outputDirectory +"images/" + newFile); collectedFiles[newFile] = oldFile; - return m_outputDirectory + newFile; + return m_outputDirectory +"images/" + newFile; } |
|
patch V1 does create subdirectories and add ressources in them. May be to directory creation could be improve with a loo on list values. That'll be my next step. Them, report creation. |
|
collect4output-1.1.patch (6,678 bytes)
Index: scribus/collect4output.cpp =================================================================== --- scribus/collect4output.cpp (révision 17759) +++ scribus/collect4output.cpp (copie de travail) @@ -28,6 +28,7 @@ #include <QString> #include <QMap> #include <QDir> +#include <QTextDocumentWriter> CollectForOutput::CollectForOutput(ScribusDoc* doc, QString outputDirectory, bool withFonts, bool withProfiles, bool compressDoc) : QObject(ScCore), @@ -74,18 +75,22 @@ return false; if (!m_outputDirectory.endsWith("/")) m_outputDirectory += "/"; - QDir dir(m_outputDirectory); - if (!dir.exists()) - { - bool created = dir.mkpath(m_outputDirectory); - if (!created) - { - QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning, - "<qt>" + tr("Cannot create directory:\n%1").arg(m_outputDirectory) + "</qt>", - CommonStrings::tr_OK); - return false; - } - } + char *directories[]={"","images/","fonts/","profiles/"}; + int Indice; + for (Indice = 0; Indice < 4; Indice++) { + QDir dir(m_outputDirectory+directories[Indice]); + if (!dir.exists()) + { + bool created = dir.mkpath(m_outputDirectory+directories[Indice]); + if (!created) + { + QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning, + "<qt>" + tr("Cannot create directory:\n%1").arg(m_outputDirectory+directories[Indice]) + "</qt>", + CommonStrings::tr_OK); + return false; + } + } + } return true; } @@ -115,29 +120,42 @@ /* 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; - } + 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(""); + 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; - return QString::null; + + QString filename = m_outputDirectory + "report.txt"; + /*QFile f(filename); + if(!f.open(QIODevice::WriteOnly)) + return false; + QString wr = ""; + wr += m_message; + QByteArray utf8wr = wr.toUtf8(); + QDataStream s(&f); + s.writeRawData(utf8wr.data(), utf8wr.length()); + f.close(); +*/ + return QString::null; } bool CollectForOutput::collectDocument() { QFileInfo fi = QFileInfo(m_outputDirectory); newName = m_outputDirectory; + m_message = "\nSOURCE DOCUMENT\n====================\n"+m_message +"\n"; if (!fi.exists()) return false; if (!fi.isDir() || !fi.isWritable()) @@ -330,6 +348,7 @@ bool CollectForOutput::collectFonts() { + //m_message = m_message + "\n\nUSED FONTS\n====================\n"; PrefsManager *prefsManager = PrefsManager::instance(); QMap<QString,int>::Iterator it3; QMap<QString,int>::Iterator it3end = m_Doc->UsedFonts.end(); @@ -337,8 +356,9 @@ for (it3 = m_Doc->UsedFonts.begin(); it3 != it3end; ++it3) { 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) + copyFileAtomic(prefsManager->appPrefs.fontPrefs.AvailFonts[it3.key()].fontFilePath(), m_outputDirectory + "fonts/" + itf.fileName()); + //m_message = m_message + "fonts/" + itf.fileName() +"\n"; + if (prefsManager->appPrefs.fontPrefs.AvailFonts[it3.key()].type() == ScFace::TYPE1) { QStringList metrics; QString fontDir = itf.absolutePath(); @@ -360,7 +380,8 @@ { QString origAFM = metrics[a]; QFileInfo fi(origAFM); - copyFileAtomic(origAFM, m_outputDirectory + fi.fileName()); + copyFileAtomic(origAFM, m_outputDirectory + "fonts/" + fi.fileName()); + //m_message = m_message + "fonts/" + fi.fileName() +"\n"; } } if (uiCollect) @@ -413,21 +434,24 @@ bool CollectForOutput::collectProfiles() { + //m_message = m_message + "\n\nUSED PROFILES\n====================\n"; 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, m_outputDirectory + QFileInfo(profilePath).fileName()); + copyFileAtomic(profilePath, m_outputDirectory + "profiles/" + QFileInfo(profilePath).fileName()) +"\n"; if (uiCollect) emit profilesCollected(c++); + //m_message = m_message + "profiles/" + QFileInfo(profilePath).fileName(); } return true; } QString CollectForOutput::collectFile(QString oldFile, QString newFile) { + //m_message = m_message + "USED IMAGES\n====================\n"; uint cnt = 1; bool copy = true; @@ -444,8 +468,10 @@ newFile = QString("%1_%2.%3").arg(basename).arg(cnt).arg(fi.completeSuffix()); ++cnt; } - if (copy) - copyFileAtomic(oldFile, m_outputDirectory + newFile); + if (copy){ + copyFileAtomic(oldFile, m_outputDirectory +"images/" + newFile); + //m_message = m_message + "images/" + newFile +"\n"; + } collectedFiles[newFile] = oldFile; - return m_outputDirectory + newFile; + return m_outputDirectory +"images/" + newFile; } |
|
V1.1 adds a more convenient way to add directories and prepares output for a report. |
|
11040_collect4output-1.2.patch (6,098 bytes)
Index: scribus/collect4output.cpp =================================================================== --- scribus/collect4output.cpp (revision 17759) +++ scribus/collect4output.cpp (working copy) @@ -23,11 +23,12 @@ #include "scpattern.h" #include "util_file.h" +#include <QDir> +#include <QMap> #include <QMessageBox> #include <QProgressBar> #include <QString> -#include <QMap> -#include <QDir> +#include <QTextDocumentWriter> CollectForOutput::CollectForOutput(ScribusDoc* doc, QString outputDirectory, bool withFonts, bool withProfiles, bool compressDoc) : QObject(ScCore), @@ -74,15 +75,26 @@ return false; if (!m_outputDirectory.endsWith("/")) m_outputDirectory += "/"; - QDir dir(m_outputDirectory); - if (!dir.exists()) + + QStringList directories; + directories.append(m_outputDirectory); + directories.append(m_outputDirectory + "images/"); + if (m_withFonts) + directories.append(m_outputDirectory + "fonts/"); + if (m_withProfiles) + directories.append(m_outputDirectory + "profiles/"); + + for (int i = 0; i < directories.count(); ++i) { - bool created = dir.mkpath(m_outputDirectory); + QDir dir(directories[i]); + if (dir.exists()) continue; + + bool created = dir.mkpath(directories[i]); if (!created) { QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning, - "<qt>" + tr("Cannot create directory:\n%1").arg(m_outputDirectory) + "</qt>", - CommonStrings::tr_OK); + "<qt>" + tr("Cannot create directory:\n%1").arg(directories[i]) + "</qt>", + CommonStrings::tr_OK); return false; } } @@ -131,6 +143,18 @@ ScCore->fileWatcher->start(); collectedFiles.clear(); newFileName=newName; + + QString filename = m_outputDirectory + "report.txt"; + /*QFile f(filename); + if(!f.open(QIODevice::WriteOnly)) + return false; + QString wr = ""; + wr += m_message; + QByteArray utf8wr = wr.toUtf8(); + QDataStream s(&f); + s.writeRawData(utf8wr.data(), utf8wr.length()); + f.close(); +*/ return QString::null; } @@ -138,6 +162,7 @@ { QFileInfo fi = QFileInfo(m_outputDirectory); newName = m_outputDirectory; + m_message = "\nSOURCE DOCUMENT\n====================\n"+m_message +"\n"; if (!fi.exists()) return false; if (!fi.isDir() || !fi.isWritable()) @@ -330,6 +355,7 @@ bool CollectForOutput::collectFonts() { + //m_message = m_message + "\n\nUSED FONTS\n====================\n"; PrefsManager *prefsManager = PrefsManager::instance(); QMap<QString,int>::Iterator it3; QMap<QString,int>::Iterator it3end = m_Doc->UsedFonts.end(); @@ -337,7 +363,8 @@ for (it3 = m_Doc->UsedFonts.begin(); it3 != it3end; ++it3) { QFileInfo itf(prefsManager->appPrefs.fontPrefs.AvailFonts[it3.key()].fontFilePath()); - copyFileAtomic(prefsManager->appPrefs.fontPrefs.AvailFonts[it3.key()].fontFilePath(), m_outputDirectory + itf.fileName()); + copyFileAtomic(prefsManager->appPrefs.fontPrefs.AvailFonts[it3.key()].fontFilePath(), m_outputDirectory + "fonts/" + itf.fileName()); + //m_message = m_message + "fonts/" + itf.fileName() +"\n"; if (prefsManager->appPrefs.fontPrefs.AvailFonts[it3.key()].type() == ScFace::TYPE1) { QStringList metrics; @@ -360,7 +387,8 @@ { QString origAFM = metrics[a]; QFileInfo fi(origAFM); - copyFileAtomic(origAFM, m_outputDirectory + fi.fileName()); + copyFileAtomic(origAFM, m_outputDirectory + "fonts/" + fi.fileName()); + //m_message = m_message + "fonts/" + fi.fileName() +"\n"; } } if (uiCollect) @@ -413,21 +441,24 @@ bool CollectForOutput::collectProfiles() { + //m_message = m_message + "\n\nUSED PROFILES\n====================\n"; 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, m_outputDirectory + QFileInfo(profilePath).fileName()); + copyFileAtomic(profilePath, m_outputDirectory + "profiles/" + QFileInfo(profilePath).fileName()); if (uiCollect) emit profilesCollected(c++); + //m_message = m_message + "profiles/" + QFileInfo(profilePath).fileName(); } return true; } QString CollectForOutput::collectFile(QString oldFile, QString newFile) { + //m_message = m_message + "USED IMAGES\n====================\n"; uint cnt = 1; bool copy = true; @@ -445,7 +476,10 @@ ++cnt; } if (copy) - copyFileAtomic(oldFile, m_outputDirectory + newFile); + { + copyFileAtomic(oldFile, m_outputDirectory +"images/" + newFile); + //m_message = m_message + "images/" + newFile +"\n"; + } collectedFiles[newFile] = oldFile; - return m_outputDirectory + newFile; + return m_outputDirectory +"images/" + newFile; } Index: scribus/collect4output.h =================================================================== --- scribus/collect4output.h (revision 17759) +++ scribus/collect4output.h (working copy) @@ -61,6 +61,8 @@ QMap<QString, QString> collectedFiles; /*! Reference to the preferences */ PrefsContext* dirs; + /*! Report text */ + QString m_message; /*! Ask user for output directory via GUI. \retval true on success */ Index: scribus/scribus.cpp =================================================================== --- scribus/scribus.cpp (revision 17759) +++ scribus/scribus.cpp (working copy) @@ -3883,9 +3883,17 @@ is12doc=true; } + QDir docProfileDir(fi.absolutePath() + "/profiles"); ScCore->getCMSProfilesDir(fi.absolutePath()+"/", false, false); + if (docProfileDir.exists()) + ScCore->getCMSProfilesDir(fi.absolutePath()+"/profiles", false, false); + + QDir docFontDir(fi.absolutePath() + "/fonts"); prefsManager->appPrefs.fontPrefs.AvailFonts.AddScalableFonts(fi.absolutePath()+"/", FName); + if (docFontDir.exists()) + prefsManager->appPrefs.fontPrefs.AvailFonts.AddScalableFonts(fi.absolutePath()+"/fonts", FName); prefsManager->appPrefs.fontPrefs.AvailFonts.updateFontMap(); + doc=new ScribusDoc(); doc->is12doc=is12doc; doc->appMode = modeNormal; |
|
Uploaded v1.2 : - fix compilation due to missing change in collect4ouput.h - create fonts and profiles directories only if user request those files to be collected - load fonts and profiles from 'doc_dir/fonts' and 'doc_dir/profiles' when collected doc is loaded |
|
great, i had just tested it another way (cf in git collectforoutput branch) but i will learn from yours :) |
|
Anything more to do related to th report? Currently that code is mostly commented out... |
|
I've committed the patch. For now i've left what relates to the report generation. For the report i would suggest to proceed as following : - refactor the code so as to list fonts, profiles and images to collect first - collect fonts, profiles and images according to the determined lists - generate the report using a single function Open a new issue when you have the report part ready. And thanks, this is a nice improvement! |
Date Modified | Username | Field | Change |
---|---|---|---|
2012-08-20 17:09 | pygmee | New Issue | |
2012-08-20 17:09 | pygmee | Status | new => assigned |
2012-08-20 17:09 | pygmee | Assigned To | => pygmee |
2012-08-20 17:10 | pygmee | File Added: collect4output-1.0.patch | |
2012-08-20 17:11 | pygmee | Note Added: 0028845 | |
2012-08-21 14:03 | pygmee | File Added: collect4output-1.1.patch | |
2012-08-21 14:03 | pygmee | Note Added: 0028851 | |
2012-08-22 21:33 | jghali | File Added: 11040_collect4output-1.2.patch | |
2012-08-22 21:39 | jghali | Note Added: 0028857 | |
2012-08-22 23:04 | pygmee | Note Added: 0028858 | |
2012-08-23 20:56 | jghali | Note Added: 0028863 | |
2012-08-26 21:54 | jghali | Note Added: 0028872 | |
2012-08-26 21:54 | jghali | Status | assigned => resolved |
2012-08-26 21:54 | jghali | Fixed in Version | => 1.5.0svn |
2012-08-26 21:54 | jghali | Resolution | open => fixed |
2012-08-26 23:24 | jghali | Target Version | 1.5.0svn => 1.5.0 |
2012-11-13 20:34 | cbradney | Status | resolved => closed |