Subversion Repositories Scribus

Rev

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