Subversion Repositories Scribus

Rev

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