Subversion Repositories Scribus

Rev

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