Back to index

scribus-ng  1.3.4.dfsg+svn20071115
loadsaveplugin.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include "loadsaveplugin.h"
00008 #include "loadsaveplugin.moc"
00009 
00010 QValueList<FileFormat> LoadSavePlugin::formats;
00011 
00012 LoadSavePlugin::LoadSavePlugin()
00013        : ScPlugin(),
00014        m_Doc(0),
00015        m_View(0),
00016        m_ScMW(0),
00017        m_mwProgressBar(0),
00018        m_AvailableFonts(0)
00019 {
00020 }
00021 
00022 LoadSavePlugin::~LoadSavePlugin()
00023 {
00024 }
00025 
00026 // STATIC method - return a list of all existing formats
00027 const QValueList<FileFormat> & LoadSavePlugin::supportedFormats()
00028 {
00029        return formats;
00030 }
00031 
00032 const FileFormat * LoadSavePlugin::getFormatById(const int id)
00033 {
00034        QValueList<FileFormat>::iterator it(findFormat(id));
00035        if (it == formats.end())
00036               return 0;
00037        else
00038               return &(*it);
00039 }
00040 
00041 const QStringList LoadSavePlugin::fileDialogLoadFilter()
00042 {
00043        return getDialogFilter(true);
00044 }
00045 
00046 const QStringList LoadSavePlugin::fileDialogSaveFilter()
00047 {
00048        return getDialogFilter(false);
00049 }
00050 
00051 const QStringList LoadSavePlugin::getDialogFilter(bool forLoad)
00052 {
00053        QValueList<FileFormat>::const_iterator it(formats.constBegin());
00054        QValueList<FileFormat>::const_iterator itEnd(formats.constEnd());
00055        QStringList filterList;
00056        // We know the list is sorted by id, then priority, so we can just take the
00057        // highest priority entry for each ID, and we can start with the first entry
00058        // in the list.
00059        //First, check if we even have any plugins to load with.. 
00060        if (it!=itEnd)
00061        {
00062               filterList.append((*it).filter);
00063               unsigned int lastID = (*it).formatId;
00064               ++it;
00065               for ( ; it != itEnd ; ++it )
00066               {
00067                      // Find the next load/save (as appropriate) plugin for the next format type
00068                      if ( (forLoad ? (*it).load : (*it).save) && ((*it).formatId > lastID) )
00069                      {
00070                             // And add it to the filter list, since we know it's 
00071                             // the highest priority because of the sort order.
00072                             filterList.append((*it).filter);
00073                             lastID = (*it).formatId;
00074                      }
00075               }
00076        }
00077        else
00078 //            qDebug("%s", tr("No File Loader Plugins Found"));
00079               qDebug("%s", tr("No File Loader Plugins Found").local8Bit().data());
00080        filterList.append( tr("All Files (*)"));
00081        return filterList;
00082 }
00083 
00084 bool LoadSavePlugin::saveFile(const QString & /* fileName */,
00085                                                    const FileFormat & /* fmt */)
00086 {
00087        return false;
00088 }
00089 
00090 bool LoadSavePlugin::loadFile(const QString & /* fileName */,
00091                                                    const FileFormat & /* fmt */,
00092                                                    int /* flags */,
00093                                                    int /* index */)
00094 {
00095        return false;
00096 }
00097 
00098 bool LoadSavePlugin::checkFlags(int flags)
00099 {
00100        int numFlags = 0;
00101        // Only one of the following flags must be set:
00102        // lfCreateDoc, lfUseCurrentPage, lfInsertPage
00103        if( flags & lfCreateDoc ) 
00104               numFlags++;
00105        if( flags & lfUseCurrentPage ) 
00106               numFlags++;
00107        if( flags & lfInsertPage ) 
00108               numFlags++;
00109        if( numFlags > 1 )
00110               return false;
00111        return true;
00112 }
00113 
00114 void LoadSavePlugin::registerFormat(const FileFormat & fmt)
00115 {
00116        // We insert the format in a very specific location so that the formats
00117        // list is sorted by ascending id, then descending priority.
00118        // We first look for entries with equal or greater ID, then equal or
00119        // lesser priority, and insert before the first item that is of either:
00120        //     - Equal ID and lesser or equal priority; or
00121        //     - Greater ID
00122        // If we don't find one, we insert before the end iterator, ie append.
00123        QValueList<FileFormat>::iterator it(formats.begin());
00124        QValueList<FileFormat>::iterator itEnd(formats.end());
00125        while (it != itEnd)
00126        {
00127               if ( ( ((*it).formatId == fmt.formatId) && ((*it).priority <= fmt.priority) ) ||
00128                       ((*it).formatId > fmt.formatId)) 
00129                             break;
00130               ++it;
00131        }
00132        formats.insert(it, fmt);
00133        //printFormatList(); // DEBUG
00134 }
00135 
00136 // static debugging function - prints the human readable format list
00137 void LoadSavePlugin::printFormatList()
00138 {
00139        qDebug("Current format list:");
00140        QValueList<FileFormat>::const_iterator it(formats.constBegin());
00141        QValueList<FileFormat>::const_iterator itEnd(formats.constEnd());
00142        for ( ; it != itEnd ; ++it )
00143        {
00144               qDebug("    Format: Id: %3u, Prio: %3hu, Name: %s",
00145                             (*it).formatId, (*it).priority, (*it).trName.local8Bit().data() );
00146        }
00147        qDebug("Done");
00148 }
00149 
00150 void LoadSavePlugin::unregisterFormat(unsigned int id)
00151 {
00152        QValueList<FileFormat>::iterator it(findFormat(id, this));
00153        Q_ASSERT(it != formats.end());
00154        formats.remove(it);
00155 }
00156 
00157 void LoadSavePlugin::unregisterAll()
00158 {
00159        QValueList<FileFormat>::iterator it(formats.begin());
00160        QValueList<FileFormat>::iterator itEnd(formats.end());
00161        while (it != itEnd)
00162        {
00163               if ((*it).plug == this)
00164                      it = formats.remove(it);
00165               else
00166                      ++it;
00167        }
00168 }
00169 
00170 QValueList<FileFormat>::iterator
00171 LoadSavePlugin::findFormat(unsigned int id,
00172                                              LoadSavePlugin* plug,
00173                                              QValueList<FileFormat>::iterator it)
00174 {
00175        QValueList<FileFormat>::iterator itEnd(formats.end());
00176        for ( ; it != itEnd ; ++it )
00177        {
00178               if (
00179                             ((*it).formatId == id) &&
00180                             ((plug == 0) || (plug == (*it).plug))
00181                      )
00182                      return it;
00183        }
00184        return itEnd;
00185 }
00186 
00187 QValueList<FileFormat>::iterator
00188 LoadSavePlugin::findFormat(const QString& extension,
00189                                              LoadSavePlugin* plug,
00190                                              QValueList<FileFormat>::iterator it)
00191 {
00192        QValueList<FileFormat>::iterator itEnd(formats.end());
00193        for ( ; it != itEnd ; ++it )
00194        {
00195               if (
00196                             ((*it).nameMatch.search(extension)) &&
00197                             ((plug == 0) || (plug == (*it).plug))
00198                      )
00199                      return it;
00200        }
00201        return itEnd;
00202 }
00203 
00204 
00205 void LoadSavePlugin::setupTargets(ScribusDoc *targetDoc, ScribusView* targetView, ScribusMainWindow* targetMW, QProgressBar* targetMWPRogressBar, SCFonts* targetAvailableFonts)
00206 {
00207        m_Doc=targetDoc;
00208        m_View=targetView;
00209        m_ScMW=targetMW;
00210        m_mwProgressBar=targetMWPRogressBar;
00211        m_AvailableFonts=targetAvailableFonts;
00212 }
00213 
00214 void LoadSavePlugin::getReplacedFontData(bool & /*getNewReplacement*/, QMap<QString,QString> &/*getReplacedFonts*/, QValueList<ScFace> &/*getDummyScFaces*/)
00215 {
00216 }
00217 
00218 bool LoadSavePlugin::loadPage(const QString & /*fileName*/, int /*pageNumber*/, bool /*Mpage*/, QString /*renamedPageName*/)
00219 {
00220        return false;
00221 }
00222 
00223 bool LoadSavePlugin::readStyles(const QString& /*fileName*/, ScribusDoc* /*doc*/, StyleSet<ParagraphStyle> &/*docParagraphStyles*/)
00224 {
00225        return false;
00226 }
00227 
00228 bool LoadSavePlugin::readCharStyles(const QString& /*fileName*/, ScribusDoc* /*doc*/, StyleSet<CharStyle> &/*docCharStyles*/)
00229 {
00230        return false;
00231 }
00232 
00233 bool LoadSavePlugin::readLineStyles(const QString& /*fileName*/, QMap<QString,multiLine>* /*Sty*/)
00234 {
00235        return false;
00236 }
00237 
00238 bool LoadSavePlugin::readColors(const QString& /*fileName*/, ColorList & /*colors*/)
00239 {
00240        return false;
00241 }
00242 
00243 bool LoadSavePlugin::readPageCount(const QString& /*fileName*/, int* /*num1*/, int* /*num2*/, QStringList & /*masterPageNames*/)
00244 {
00245        return false;
00246 }
00247 
00248 bool FileFormat::loadFile(const QString & fileName, int flags, int index) const
00249 {
00250        return (plug && load) ? plug->loadFile(fileName, *this, flags, index) : false;
00251 }
00252 
00253 bool FileFormat::saveFile(const QString & fileName) const
00254 {
00255        return (plug && save) ? plug->saveFile(fileName, *this) : false;
00256 }
00257 
00258 void FileFormat::setupTargets(ScribusDoc *targetDoc, ScribusView* targetView, ScribusMainWindow* targetMW, QProgressBar* targetMWPRogressBar, SCFonts* targetAvailableFonts) const
00259 {
00260        if (plug)
00261               plug->setupTargets(targetDoc, targetView, targetMW, targetMWPRogressBar, targetAvailableFonts);
00262 }
00263 
00264 void FileFormat::getReplacedFontData(bool & getNewReplacement, QMap<QString,QString> &getReplacedFonts, QValueList<ScFace> &getDummyScFaces) const
00265 {
00266        if (plug)
00267               plug->getReplacedFontData(getNewReplacement, getReplacedFonts, getDummyScFaces);
00268 }
00269 
00270 bool FileFormat::loadPage(const QString & fileName, int pageNumber, bool Mpage, QString renamedPageName) const
00271 {
00272        return (plug && load) ? plug->loadPage(fileName, pageNumber, Mpage, renamedPageName) : false;
00273 }
00274 
00275 bool FileFormat::readStyles(const QString& fileName, ScribusDoc* doc, StyleSet<ParagraphStyle> &docParagraphStyles) const
00276 {
00277        return (plug && load) ? plug->readStyles(fileName, doc, docParagraphStyles) : false;
00278 }
00279 
00280 bool FileFormat::readCharStyles(const QString& fileName, ScribusDoc* doc, StyleSet<CharStyle> &docCharStyles) const
00281 {
00282        return (plug && load) ? plug->readCharStyles(fileName, doc, docCharStyles) : false;
00283 }
00284 
00285 bool FileFormat::readLineStyles(const QString& fileName, QMap<QString,multiLine> *Sty) const
00286 {
00287        return (plug && load) ? plug->readLineStyles(fileName, Sty) : false;
00288 }
00289 
00290 bool FileFormat::readColors(const QString& fileName, ColorList & colors) const
00291 {
00292        return (plug && load) ? plug->readColors(fileName, colors) : false;
00293 }
00294 
00295 bool FileFormat::readPageCount(const QString& fileName, int *num1, int *num2, QStringList & masterPageNames) const
00296 {
00297        return (plug && load) ? plug->readPageCount(fileName, num1, num2, masterPageNames) : false;
00298 }
00299