Subversion Repositories Scribus

Rev

Rev 3693 | Rev 4024 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3487 craig 1
#include "loadsaveplugin.h"
2
 
3686 craig 3
QValueList<LoadSavePlugin::FormatSupport> LoadSavePlugin::formats;
4
 
3487 craig 5
LoadSavePlugin::LoadSavePlugin()
3696 craig 6
        : ScPlugin()
3487 craig 7
{
8
}
9
 
10
LoadSavePlugin::~LoadSavePlugin()
11
{
12
}
3686 craig 13
 
3693 craig 14
// STATIC method - return a list of all existing formats
15
const QValueList<LoadSavePlugin::FormatSupport> & LoadSavePlugin::supportedFormats()
16
{
17
        return formats;
18
}
19
 
3696 craig 20
const QStringList LoadSavePlugin::fileDialogLoadFilter()
21
{
22
        return getDialogFilter(true);
23
}
24
 
25
const QStringList LoadSavePlugin::fileDialogSaveFilter()
26
{
27
        return getDialogFilter(false);
28
}
29
 
30
const QStringList LoadSavePlugin::getDialogFilter(bool forLoad)
31
{
32
        QValueList<LoadSavePlugin::FormatSupport>::const_iterator it(formats.constBegin());
33
        QValueList<LoadSavePlugin::FormatSupport>::const_iterator itEnd(formats.constEnd());
34
        QStringList filterList;
35
        // We know the list is sorted by id, then priority, so we can just take the
36
        // highest priority entry for each ID, and we can start with the first entry
37
        // in the list.
38
        filterList.append((*it).filter);
39
        unsigned int lastID = (*it).formatId;
40
        ++it;
41
        for ( ; it != itEnd ; ++it )
42
                // Find the next load/save (as appropriate) plugin for the next format type
43
                if ( (forLoad ? (*it).load : (*it).save) && ((*it).formatId > lastID) )
44
                {
45
                        // And add it to the filter list, since we know it's 
46
                        // the highest priority because of the sort order.
47
                        filterList.append((*it).filter);
48
                        lastID = (*it).formatId;
49
                }
50
        filterList.append(tr("All Files (*)"));
51
        return filterList;
52
}
53
 
3686 craig 54
bool LoadSavePlugin::saveFile(const QString & /* fileName */,
55
                                                          const LoadSavePlugin::FormatSupport & /* fmt */)
56
{
57
        return false;
58
}
59
 
60
bool LoadSavePlugin::loadFile(const QString & /* fileName */,
61
                                                          const LoadSavePlugin::FormatSupport & /* fmt */)
62
{
63
        return false;
64
}
65
 
66
void LoadSavePlugin::registerFormat(const LoadSavePlugin::FormatSupport & fmt)
67
{
3696 craig 68
        // We insert the format in a very specific location so that the formats
69
        // list is sorted by ascending id, then descending priority.
70
        // We first look for entries with equal or greater ID, then equal or
71
        // lesser priority, and insert before the first item that is of either:
72
        //     - Equal ID and lesser or equal priority; or
73
        //     - Greater ID
74
        // If we don't find one, we insert before the end iterator, ie append.
75
        QValueList<LoadSavePlugin::FormatSupport>::iterator it(formats.begin());
76
        QValueList<LoadSavePlugin::FormatSupport>::iterator itEnd(formats.end());
77
        while (it != itEnd)
78
        {
79
                if ( ( ((*it).formatId == fmt.formatId) && ((*it).priority <= fmt.priority) ) ||
80
                         ((*it).formatId > fmt.formatId))
81
                                break;
82
                ++it;
83
        }
84
        formats.insert(it, fmt);
85
        //printFormatList(); // DEBUG
3686 craig 86
}
87
 
3696 craig 88
// static debugging function - prints the human readable format list
89
void LoadSavePlugin::printFormatList()
3686 craig 90
{
3696 craig 91
        qDebug("Current format list:");
92
        QValueList<LoadSavePlugin::FormatSupport>::const_iterator it(formats.constBegin());
93
        QValueList<LoadSavePlugin::FormatSupport>::const_iterator itEnd(formats.constEnd());
94
        for ( ; it != itEnd ; ++it )
95
        {
96
                qDebug("    Format: Id: %3u, Prio: %3hu, Name: %s",
97
                                (*it).formatId, (*it).priority, (*it).trName.local8Bit().data() );
98
        }
99
        qDebug("Done");
100
}
101
 
102
void LoadSavePlugin::unregisterFormat(unsigned int id)
103
{
104
        QValueList<LoadSavePlugin::FormatSupport>::iterator it(findFormat(id, this));
3686 craig 105
        Q_ASSERT(it != formats.end());
106
        formats.remove(it);
107
}
108
 
109
void LoadSavePlugin::unregisterAll()
110
{
111
        QValueList<LoadSavePlugin::FormatSupport>::iterator it(formats.begin());
112
        QValueList<LoadSavePlugin::FormatSupport>::iterator itEnd(formats.end());
3693 craig 113
        while (it != itEnd)
3686 craig 114
        {
115
                if ((*it).plug == this)
3693 craig 116
                        it = formats.remove(it);
117
                else
118
                        ++it;
3686 craig 119
        }
120
}
121
 
122
QValueList<LoadSavePlugin::FormatSupport>::iterator
3696 craig 123
LoadSavePlugin::findFormat(unsigned int id,
3686 craig 124
                                                   LoadSavePlugin* plug,
125
                                                   QValueList<LoadSavePlugin::FormatSupport>::iterator it)
126
{
127
        QValueList<LoadSavePlugin::FormatSupport>::iterator itEnd(formats.end());
128
        for ( ; it != itEnd ; ++it )
129
        {
3696 craig 130
                if (
131
                                ((*it).formatId == id) &&
132
                                ((plug == 0) || (plug == (*it).plug))
133
                        )
3686 craig 134
                        return it;
135
        }
136
        return itEnd;
137
}