Subversion Repositories Scribus

Rev

Rev 8668 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 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
*/
3487 craig 7
#include "loadsaveplugin.h"
5076 cbradney 8
#include "loadsaveplugin.moc"
3487 craig 9
 
4024 craig 10
QValueList<FileFormat> LoadSavePlugin::formats;
3686 craig 11
 
3487 craig 12
LoadSavePlugin::LoadSavePlugin()
5642 cbradney 13
        : ScPlugin(),
14
        m_Doc(0),
15
        m_View(0),
5781 cbradney 16
        m_ScMW(0),
5642 cbradney 17
        m_mwProgressBar(0),
18
        m_AvailableFonts(0)
3487 craig 19
{
20
}
21
 
22
LoadSavePlugin::~LoadSavePlugin()
23
{
24
}
3686 craig 25
 
3693 craig 26
// STATIC method - return a list of all existing formats
4024 craig 27
const QValueList<FileFormat> & LoadSavePlugin::supportedFormats()
3693 craig 28
{
29
        return formats;
30
}
31
 
4024 craig 32
const FileFormat * LoadSavePlugin::getFormatById(const int id)
33
{
34
        QValueList<FileFormat>::iterator it(findFormat(id));
35
        if (it == formats.end())
36
                return 0;
37
        else
38
                return &(*it);
39
}
40
 
3696 craig 41
const QStringList LoadSavePlugin::fileDialogLoadFilter()
42
{
43
        return getDialogFilter(true);
44
}
45
 
46
const QStringList LoadSavePlugin::fileDialogSaveFilter()
47
{
48
        return getDialogFilter(false);
49
}
50
 
51
const QStringList LoadSavePlugin::getDialogFilter(bool forLoad)
52
{
4024 craig 53
        QValueList<FileFormat>::const_iterator it(formats.constBegin());
54
        QValueList<FileFormat>::const_iterator itEnd(formats.constEnd());
3696 craig 55
        QStringList filterList;
56
        // We know the list is sorted by id, then priority, so we can just take the
57
        // highest priority entry for each ID, and we can start with the first entry
58
        // in the list.
8668 cbradney 59
        //First, check if we even have any plugins to load with.. 
60
        if (it!=itEnd)
61
        {
62
                filterList.append((*it).filter);
63
                unsigned int lastID = (*it).formatId;
64
                ++it;
65
                for ( ; it != itEnd ; ++it )
3696 craig 66
                {
8668 cbradney 67
                        // Find the next load/save (as appropriate) plugin for the next format type
68
                        if ( (forLoad ? (*it).load : (*it).save) && ((*it).formatId > lastID) )
69
                        {
70
                                // And add it to the filter list, since we know it's 
71
                                // the highest priority because of the sort order.
72
                                filterList.append((*it).filter);
73
                                lastID = (*it).formatId;
74
                        }
3696 craig 75
                }
8668 cbradney 76
        }
77
        else
8751 cbradney 78
//              qDebug("%s", tr("No File Loader Plugins Found"));
79
                qDebug("%s", tr("No File Loader Plugins Found").local8Bit().data());
6260 fschmid 80
        filterList.append( tr("All Files (*)"));
3696 craig 81
        return filterList;
82
}
83
 
3686 craig 84
bool LoadSavePlugin::saveFile(const QString & /* fileName */,
4024 craig 85
                                                          const FileFormat & /* fmt */)
3686 craig 86
{
87
        return false;
88
}
89
 
90
bool LoadSavePlugin::loadFile(const QString & /* fileName */,
5540 mrdocs 91
                                                          const FileFormat & /* fmt */,
92
                                                          int /* flags */,
93
                                                          int /* index */)
3686 craig 94
{
95
        return false;
96
}
97
 
5540 mrdocs 98
bool LoadSavePlugin::checkFlags(int flags)
99
{
100
        int numFlags = 0;
101
        // Only one of the following flags must be set:
102
        // lfCreateDoc, lfUseCurrentPage, lfInsertPage
103
        if( flags & lfCreateDoc )
104
                numFlags++;
105
        if( flags & lfUseCurrentPage )
106
                numFlags++;
107
        if( flags & lfInsertPage )
108
                numFlags++;
109
        if( numFlags > 1 )
110
                return false;
111
        return true;
112
}
113
 
4024 craig 114
void LoadSavePlugin::registerFormat(const FileFormat & fmt)
3686 craig 115
{
3696 craig 116
        // We insert the format in a very specific location so that the formats
117
        // list is sorted by ascending id, then descending priority.
118
        // We first look for entries with equal or greater ID, then equal or
119
        // lesser priority, and insert before the first item that is of either:
120
        //     - Equal ID and lesser or equal priority; or
121
        //     - Greater ID
122
        // If we don't find one, we insert before the end iterator, ie append.
4024 craig 123
        QValueList<FileFormat>::iterator it(formats.begin());
124
        QValueList<FileFormat>::iterator itEnd(formats.end());
3696 craig 125
        while (it != itEnd)
126
        {
127
                if ( ( ((*it).formatId == fmt.formatId) && ((*it).priority <= fmt.priority) ) ||
128
                         ((*it).formatId > fmt.formatId))
129
                                break;
130
                ++it;
131
        }
132
        formats.insert(it, fmt);
133
        //printFormatList(); // DEBUG
3686 craig 134
}
135
 
3696 craig 136
// static debugging function - prints the human readable format list
137
void LoadSavePlugin::printFormatList()
3686 craig 138
{
3696 craig 139
        qDebug("Current format list:");
4024 craig 140
        QValueList<FileFormat>::const_iterator it(formats.constBegin());
141
        QValueList<FileFormat>::const_iterator itEnd(formats.constEnd());
3696 craig 142
        for ( ; it != itEnd ; ++it )
143
        {
144
                qDebug("    Format: Id: %3u, Prio: %3hu, Name: %s",
145
                                (*it).formatId, (*it).priority, (*it).trName.local8Bit().data() );
146
        }
147
        qDebug("Done");
148
}
149
 
150
void LoadSavePlugin::unregisterFormat(unsigned int id)
151
{
4024 craig 152
        QValueList<FileFormat>::iterator it(findFormat(id, this));
3686 craig 153
        Q_ASSERT(it != formats.end());
154
        formats.remove(it);
155
}
156
 
157
void LoadSavePlugin::unregisterAll()
158
{
4024 craig 159
        QValueList<FileFormat>::iterator it(formats.begin());
160
        QValueList<FileFormat>::iterator itEnd(formats.end());
3693 craig 161
        while (it != itEnd)
3686 craig 162
        {
163
                if ((*it).plug == this)
3693 craig 164
                        it = formats.remove(it);
165
                else
166
                        ++it;
3686 craig 167
        }
168
}
169
 
4024 craig 170
QValueList<FileFormat>::iterator
3696 craig 171
LoadSavePlugin::findFormat(unsigned int id,
3686 craig 172
                                                   LoadSavePlugin* plug,
4024 craig 173
                                                   QValueList<FileFormat>::iterator it)
3686 craig 174
{
4024 craig 175
        QValueList<FileFormat>::iterator itEnd(formats.end());
3686 craig 176
        for ( ; it != itEnd ; ++it )
177
        {
3696 craig 178
                if (
179
                                ((*it).formatId == id) &&
180
                                ((plug == 0) || (plug == (*it).plug))
181
                        )
3686 craig 182
                        return it;
183
        }
184
        return itEnd;
185
}
4024 craig 186
 
5642 cbradney 187
QValueList<FileFormat>::iterator
188
LoadSavePlugin::findFormat(const QString& extension,
189
                                                   LoadSavePlugin* plug,
190
                                                   QValueList<FileFormat>::iterator it)
191
{
192
        QValueList<FileFormat>::iterator itEnd(formats.end());
193
        for ( ; it != itEnd ; ++it )
194
        {
195
                if (
196
                                ((*it).nameMatch.search(extension)) &&
197
                                ((plug == 0) || (plug == (*it).plug))
198
                        )
199
                        return it;
200
        }
201
        return itEnd;
202
}
4024 craig 203
 
204
 
5781 cbradney 205
void LoadSavePlugin::setupTargets(ScribusDoc *targetDoc, ScribusView* targetView, ScribusMainWindow* targetMW, QProgressBar* targetMWPRogressBar, SCFonts* targetAvailableFonts)
5642 cbradney 206
{
207
        m_Doc=targetDoc;
208
        m_View=targetView;
5781 cbradney 209
        m_ScMW=targetMW;
5642 cbradney 210
        m_mwProgressBar=targetMWPRogressBar;
211
        m_AvailableFonts=targetAvailableFonts;
212
}
213
 
5980 avox 214
void LoadSavePlugin::getReplacedFontData(bool & /*getNewReplacement*/, QMap<QString,QString> &/*getReplacedFonts*/, QValueList<ScFace> &/*getDummyScFaces*/)
5642 cbradney 215
{
216
}
217
 
218
bool LoadSavePlugin::loadPage(const QString & /*fileName*/, int /*pageNumber*/, bool /*Mpage*/, QString /*renamedPageName*/)
219
{
220
        return false;
221
}
222
 
5980 avox 223
bool LoadSavePlugin::readStyles(const QString& /*fileName*/, ScribusDoc* /*doc*/, StyleSet<ParagraphStyle> &/*docParagraphStyles*/)
5642 cbradney 224
{
225
        return false;
226
}
227
 
8156 avox 228
bool LoadSavePlugin::readCharStyles(const QString& /*fileName*/, ScribusDoc* /*doc*/, StyleSet<CharStyle> &/*docCharStyles*/)
229
{
230
        return false;
231
}
232
 
5753 jghali 233
bool LoadSavePlugin::readLineStyles(const QString& /*fileName*/, QMap<QString,multiLine>* /*Sty*/)
5642 cbradney 234
{
235
        return false;
236
}
237
 
238
bool LoadSavePlugin::readColors(const QString& /*fileName*/, ColorList & /*colors*/)
239
{
240
        return false;
241
}
242
 
5753 jghali 243
bool LoadSavePlugin::readPageCount(const QString& /*fileName*/, int* /*num1*/, int* /*num2*/, QStringList & /*masterPageNames*/)
5642 cbradney 244
{
245
        return false;
246
}
247
 
5540 mrdocs 248
bool FileFormat::loadFile(const QString & fileName, int flags, int index) const
4024 craig 249
{
5540 mrdocs 250
        return (plug && load) ? plug->loadFile(fileName, *this, flags, index) : false;
4024 craig 251
}
252
 
253
bool FileFormat::saveFile(const QString & fileName) const
254
{
255
        return (plug && save) ? plug->saveFile(fileName, *this) : false;
256
}
5642 cbradney 257
 
5781 cbradney 258
void FileFormat::setupTargets(ScribusDoc *targetDoc, ScribusView* targetView, ScribusMainWindow* targetMW, QProgressBar* targetMWPRogressBar, SCFonts* targetAvailableFonts) const
5642 cbradney 259
{
260
        if (plug)
5781 cbradney 261
                plug->setupTargets(targetDoc, targetView, targetMW, targetMWPRogressBar, targetAvailableFonts);
5642 cbradney 262
}
263
 
5980 avox 264
void FileFormat::getReplacedFontData(bool & getNewReplacement, QMap<QString,QString> &getReplacedFonts, QValueList<ScFace> &getDummyScFaces) const
5642 cbradney 265
{
266
        if (plug)
5980 avox 267
                plug->getReplacedFontData(getNewReplacement, getReplacedFonts, getDummyScFaces);
5642 cbradney 268
}
269
 
270
bool FileFormat::loadPage(const QString & fileName, int pageNumber, bool Mpage, QString renamedPageName) const
271
{
272
        return (plug && load) ? plug->loadPage(fileName, pageNumber, Mpage, renamedPageName) : false;
273
}
274
 
5980 avox 275
bool FileFormat::readStyles(const QString& fileName, ScribusDoc* doc, StyleSet<ParagraphStyle> &docParagraphStyles) const
5642 cbradney 276
{
277
        return (plug && load) ? plug->readStyles(fileName, doc, docParagraphStyles) : false;
278
}
279
 
8159 avox 280
bool FileFormat::readCharStyles(const QString& fileName, ScribusDoc* doc, StyleSet<CharStyle> &docCharStyles) const
281
{
282
        return (plug && load) ? plug->readCharStyles(fileName, doc, docCharStyles) : false;
283
}
284
 
5642 cbradney 285
bool FileFormat::readLineStyles(const QString& fileName, QMap<QString,multiLine> *Sty) const
286
{
287
        return (plug && load) ? plug->readLineStyles(fileName, Sty) : false;
288
}
289
 
290
bool FileFormat::readColors(const QString& fileName, ColorList & colors) const
291
{
292
        return (plug && load) ? plug->readColors(fileName, colors) : false;
293
}
294
 
295
bool FileFormat::readPageCount(const QString& fileName, int *num1, int *num2, QStringList & masterPageNames) const
296
{
297
        return (plug && load) ? plug->readPageCount(fileName, num1, num2, masterPageNames) : false;
298
}
299