Back to index

scribus-ng  1.3.4.dfsg+svn20071115
Public Member Functions | Private Member Functions | Private Attributes
CollectForOutput Class Reference

Performs "Collect for Output" tasks. More...

#include <collect4output.h>

List of all members.

Public Member Functions

 CollectForOutput (ScribusDoc *doc, bool withFontsA=false, bool withProfilesA=false, bool compressDocA=false)
 Setup the attributes.
 ~CollectForOutput ()
QString collect ()
 Main method doing everything.

Private Member Functions

bool newDirDialog ()
 Ask user for output directory via GUI.
bool collectDocument ()
 Check permissions and export document itself.
bool collectItems ()
 Collect all related items, esp.
void processItem (PageItem *ite)
 Processes the item, helper function for collectItems()
bool collectFonts ()
 Collect used fonts if requested.
bool collectProfiles ()
 Collect used profiles if requested.
QString collectFile (QString oldFile, QString newFile)
 Copy used file into new location with magic checks.

Private Attributes

ScribusDoc * m_Doc
 Doc to collect.
bool compressDoc
 Use compressed document.
bool withFonts
 Collect fonts too.
bool withProfiles
 Collect icc profiles too.
QString outputDirectory
 User defined directory via GUI.
QString newName
 Name of the moved file with the new directory path.
QMap< QString, QString > collectedFiles
 Remember already collected files to collect the same files only once.
PrefsContext * dirs
 Reference to the preferences.

Detailed Description

Performs "Collect for Output" tasks.

collect() method copies the document, fonts and images into user defined directory. QObject inheritance mainly due moc speedup and tr() methods.

Author:
Petr Vanek, Franz Schmid

Definition at line 25 of file collect4output.h.


Constructor & Destructor Documentation

CollectForOutput::CollectForOutput ( ScribusDoc *  doc,
bool  withFontsA = false,
bool  withProfilesA = false,
bool  compressDocA = false 
)

Setup the attributes.

Parameters:
withFontscollect/move fonts into output directory too
compressDocuse gzipped document

Definition at line 28 of file collect4output.cpp.

       : QObject(ScCore, 0),
       m_Doc(0)
{
       m_Doc=doc;
       outputDirectory = QString();
       compressDoc = compressDocA;
       withFonts = withFontsA;
       withProfiles = withProfilesA;
       dirs = PrefsManager::instance()->prefsFile->getContext("dirs");
       collectedFiles.clear();
}

Definition at line 35 of file collect4output.h.

{};

Member Function Documentation

Main method doing everything.

It calls all related methods

Definition at line 61 of file collect4output.cpp.

{
       if (!newDirDialog())
              return "";
       ScCore->fileWatcher->forceScan();
       ScCore->fileWatcher->stop();
       dirs->set("collect", outputDirectory.left(outputDirectory.findRev("/",-2)));
       ScCore->primaryMainWindow()->setStatusBarInfoText( tr("Collecting..."));

       if (!collectItems())
       {
              QMessageBox::warning(ScCore->primaryMainWindow(), CommonStrings::trWarning,
                                                  "<qt>" + tr("Cannot collect all files for output for file:\n%1").arg(newName) + "</qt>",
                                                  CommonStrings::tr_OK);
              return "";
       }

       if (withFonts)
              collectFonts();
       if (withProfiles)
              collectProfiles();

       /* 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 "";
       }

       QDir::setCurrent(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();
       return newName;
}

Here is the call graph for this function:

Check permissions and export document itself.

Return values:
trueon success

Definition at line 104 of file collect4output.cpp.

{
       QFileInfo fi = QFileInfo(outputDirectory);
       newName = outputDirectory;
       if (!fi.exists())
              return false;
       if (!fi.isDir() || !fi.isWritable())
              return false;

       if (m_Doc->hasName)
       {
              QFileInfo fis(m_Doc->DocName);
              newName += fis.fileName();
       }
       else
              newName += m_Doc->DocName+".sla";

       m_Doc->hasName = true;
       if (compressDoc)
       {
              if (!newName.endsWith(".gz"))
                     newName += ".gz";
              else
              {
                     if (newName.endsWith(".gz"))
                            newName = newName.remove(".gz");
              }
       }

       if (!overwrite(ScCore->primaryMainWindow(), newName))
              return false;
       if (!ScCore->primaryMainWindow()->DoFileSave(newName))
              return false;
       return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

QString CollectForOutput::collectFile ( QString  oldFile,
QString  newFile 
) [private]

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 overwritting. E.g. newFile.png can be newFile_0.png. It checks already collected files not to collect one item 2 times.

Parameters:
oldFilefull path of the original file
newFilesuggested fullpath of the collected file
Return values:
QStringreally used fullpath of the new file

Definition at line 267 of file collect4output.cpp.

{
       uint cnt = 1;
       bool copy = true;

       while (collectedFiles.contains(newFile))
       {
              // overwrite only different sources
              if (collectedFiles[newFile] == oldFile)
              {
                     copy = false;
                     break;
              }
              QFileInfo fi(newFile);
              QString basename = fi.baseName().left(fi.baseName().findRev("_"));
              newFile = QString("%1_%2.%3").arg(basename).arg(cnt).arg(fi.extension());
              ++cnt;
       }
       if (copy)
              copyFile(oldFile, outputDirectory + newFile);
       collectedFiles[newFile] = oldFile;
       return newFile;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Collect used fonts if requested.

Return values:
trueon success

Definition at line 240 of file collect4output.cpp.

{
       PrefsManager *prefsManager = PrefsManager::instance();
       QMap<QString,int>::Iterator it3;
       QMap<QString,int>::Iterator it3end = m_Doc->UsedFonts.end();
       for (it3 = m_Doc->UsedFonts.begin(); it3 != it3end; ++it3)
       {
              QFileInfo itf = QFileInfo(prefsManager->appPrefs.AvailFonts[it3.key()].fontFilePath());
              copyFile(prefsManager->appPrefs.AvailFonts[it3.key()].fontFilePath(), outputDirectory + itf.fileName());
       }
       return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Collect all related items, esp.

images.

Return values:
trueon success

Definition at line 140 of file collect4output.cpp.

{
       uint counter = 0;
       for (uint lc = 0; lc < 3; ++lc)
       {
              PageItem* ite = NULL;
              switch (lc)
              {
                     case 0:
                            counter = m_Doc->MasterItems.count();
                            break;
                     case 1:
                            counter = m_Doc->DocItems.count();
                            break;
                     case 2:
                            counter = m_Doc->FrameItems.count();
                            break;
              }
              for (uint b = 0; b < counter; ++b)
              {
                     switch (lc)
                     {
                            case 0:
                                   ite = m_Doc->MasterItems.at(b);
                                   break;
                            case 1:
                                   ite = m_Doc->DocItems.at(b);
                                   break;
                            case 2:
                                   ite = m_Doc->FrameItems.at(b);
                                   break;
                     }
                     processItem(ite);
              }
       }
       QStringList patterns = m_Doc->getUsedPatterns();
       for (uint c = 0; c < patterns.count(); ++c)
       {
              ScPattern pa = m_Doc->docPatterns[patterns[c]];
              for (uint o = 0; o < pa.items.count(); o++)
              {
                     processItem(pa.items.at(o));
              }
       }
       return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Collect used profiles if requested.

Return values:
trueon success

Definition at line 253 of file collect4output.cpp.

{
       ProfilesL docProfiles;
       m_Doc->getUsedProfiles(docProfiles);
       ProfilesL::Iterator itend = docProfiles.end();
       for (ProfilesL::Iterator it = docProfiles.begin(); it != itend; ++it)
       {
              QString profileName = it.key();
              QString profilePath = it.data();
              copyFile(profilePath, outputDirectory + QFileInfo(profilePath).fileName());
       }
       return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Ask user for output directory via GUI.

Return values:
trueon success

Definition at line 41 of file collect4output.cpp.

{
       QString curDir = QDir::currentDirPath();
       if (ScCore->usingGUI())
       {
              QString wdir = ".";
              QString prefsDocDir = PrefsManager::instance()->documentDir();
              if (!prefsDocDir.isEmpty())
                     wdir = dirs->get("collect", prefsDocDir);
              else
                     wdir = dirs->get("collect", ".");
              outputDirectory = ScCore->primaryMainWindow()->CFileDialog(wdir, tr("Choose a Directory"), "", "", fdDirectoriesOnly, &compressDoc, &withFonts, &withProfiles);
       }
       if (outputDirectory.isEmpty())
              return false;
       if (!outputDirectory.endsWith("/"))
              outputDirectory += "/";
       return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void CollectForOutput::processItem ( PageItem *  ite) [private]

Processes the item, helper function for collectItems()

Definition at line 187 of file collect4output.cpp.

{
       if (ite->asImageFrame())
       {
              /* hack for subsequent c4o "./" -> "/doc/full/path" */
              QString ofName(ite->Pfile);
              QFileInfo itf = QFileInfo(ofName);
              if (!itf.exists())
              {
                     ofName = QDir::convertSeparators(PrefsManager::instance()->documentDir() + "/" + ofName);
                     itf.setFile(ofName);
              }
              // end of hack
              if (itf.exists())
              {
                     QString oldFile = ofName;
                     ite->Pfile = collectFile(oldFile, itf.fileName());
                     ScCore->fileWatcher->removeFile(oldFile);
                     ScCore->fileWatcher->addFile(ite->Pfile);
              }
       }
       if (ite->asTextFrame())
       {
              if (ite->isAnnotation())
              {
                     QFileInfo itf;
                     if (!ite->Pfile.isEmpty())
                     {
                            itf = QFileInfo(ite->Pfile);
                            if (itf.exists())
                            {
                                   QString oldFile = ite->Pfile;
                                   ite->Pfile = collectFile(oldFile, itf.fileName());
                                   ScCore->fileWatcher->removeFile(oldFile);
                                   ScCore->fileWatcher->addFile(ite->Pfile);
                            }
                     }
                     if (!ite->Pfile2.isEmpty())
                     {
                            itf = QFileInfo(ite->Pfile2);
                            if (itf.exists())
                                   ite->Pfile2 = collectFile(ite->Pfile2, itf.fileName());
                     }
                     if (!ite->Pfile3.isEmpty())
                     {
                            itf = QFileInfo(ite->Pfile3);
                            if (itf.exists())
                                   ite->Pfile3 = collectFile(ite->Pfile3, itf.fileName());
                     }
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

QMap<QString, QString> CollectForOutput::collectedFiles [private]

Remember already collected files to collect the same files only once.

It's QMap - newFile, oldFile.

Definition at line 57 of file collect4output.h.

Use compressed document.

See the constructor

Definition at line 46 of file collect4output.h.

PrefsContext* CollectForOutput::dirs [private]

Reference to the preferences.

Definition at line 59 of file collect4output.h.

ScribusDoc* CollectForOutput::m_Doc [private]

Doc to collect.

Definition at line 44 of file collect4output.h.

QString CollectForOutput::newName [private]

Name of the moved file with the new directory path.

Definition at line 54 of file collect4output.h.

User defined directory via GUI.

Definition at line 52 of file collect4output.h.

Collect fonts too.

See the constructor

Definition at line 48 of file collect4output.h.

Collect icc profiles too.

See the constructor

Definition at line 50 of file collect4output.h.


The documentation for this class was generated from the following files: