Scribus
Open source desktop publishing at your fingertips
collection.h
1 /*****************************************************************
2 * Copyright (C) 2009 Pierre Marchand
3 
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 *
17 ******************************************************************/
18 
19 #ifndef COLLECTION_H
20 #define COLLECTION_H
21 
22 #include <QList>
23 #include <QString>
24 #include <QStringList>
25 #include <QThread>
26 #include <QXmlStreamReader>
27 #include <QXmlStreamWriter>
28 
30 {
31  public:
32  //creates collection object setting name and file
34 
35  //name of the collection
36  QString name;
37  //path to the collectionfile
38  QString file;
39  //paths to the images in the collection
40  QStringList imageFiles;
41  //tags to each image;
42  QList<QStringList> tags;
43 
44 };
45 
46 
47 //manages a set of collections
49 {
50  public:
51  //sets name
52  collections ( QString collectionsName );
53 
54  //contains name of the collections
55  QString name;
56 
57  QStringList collectionNames;
58  QStringList collectionFiles;
59 };
60 
61 
62 //a thread to read collectionfiles
63 class collectionReaderThread : public QXmlStreamReader, public QThread
64 {
65  public:
66  //set file to read
67  collectionReaderThread ( QString &xmlFile2, bool importCollection );
68 
69  //starts reading the file
70  void readFile();
71 
72  //is executed after starting the thread
73  void run();
74  //restarts the thread
75  void restart();
76 
77  //true if thread should restart
78  volatile bool restartThread;
79 
80  //hierarchy for collectionsbrowser qtreewidget
81  QList<collections *> collectionsSet;
82  //contains the images read from the file
83  imageCollection *collection;
84 
85  //tells which filetype it was, 0 for collectionsset, 1 for collection
86  int type;
87  //if it is an import
88  bool import;
89  //the file to read from
90  QString xmlFile;
91  QStringList addImages;
92 
93  private:
94  //reads collectionsdatabase
95  void readCollectionsDb();
96  //reads a collectionfile
97  void readCollectionFile();
98 
99  //reads the category of a collectionsdb
100  void readCategory();
101  //reads a collection from a collectionsdb
102  void readCollection();
103 
104  //reads an image from a collectionfile
105  void readImage();
106 
107  //called when an unknown element is encountered
108  void readUnknownElement();
109 
110  //tells how many categories the collectionsdb contained
111  int categoriesCount;
112 };
113 
114 
115 class collectionListReaderThread : public QThread
116 {
117  Q_OBJECT
118 
119  public:
120  //set files to read
121  collectionListReaderThread ( QStringList &xmlFiles2 );
122 
123  //is executed after starting the thread
124  void run();
125  //restarts the thread
126  void restart();
127 
128  //true if thread should restart
129  volatile bool restartThread;
130 
131  QString xmlFile;
132  QStringList xmlFiles;
133 
134  QList<imageCollection *> readCollections;
135 
136  private slots:
137  void collectionReaderThreadFinished();
138 
139  private:
141 };
142 
143 
144 //thread to write a collectionssetfile
145 class collectionsWriterThread : public QXmlStreamWriter, public QThread
146 {
147  public:
148  //sets initial values
149  //parameters:
150  //QString &xmlFile2: the file to write
151  //int fileType: the type of file, 0 for collectionfile, 1 for collectionsdb
152  //QList<collections *> saveCollections2: the collectionsset to write to the file
153  collectionsWriterThread ( QString &xmlFile2, QList<collections *> saveCollections2 );
154  //starts writing to the file
155  void writeFile();
156 
157  //called after the thread has been started
158  void run();
159  //restarts the thread
160  void restart();
161 
162  //true if thread should restart
163  volatile bool restartThread;
164 
165  private:
166  //writes a category into a collectionssetfile
167  void writeCategory ( const collections *category );
168  //writes a collection into a collectionssetfile
169  void writeCollection ( const QString &collectionName, const QString &collectionFile );
170 
171  //contains the path to the output file
172  QString xmlFile;
173  //the collection to write into a collectionfile
174  QList<collections *> saveCollections;
175 };
176 
177 
178 //thread to write a collectionfile
179 class collectionWriterThread : public QXmlStreamWriter, public QThread
180 {
181  public:
182  //sets initial values
183  //parameters:
184  //QString &xmlFile2: the file to write
185  //imageCollection *saveCollection2: the collection to write to the file
186  collectionWriterThread ( QString &xmlFile2, imageCollection &saveCollection2 );
187  //starts writing to the file
188  void writeFile();
189 
190  //called after the thread has been started
191  void run();
192 
193  private:
194  //writes an image into a collectionfile
195  void writeImage ( const QString &imageFile, const QStringList &tags );
196  void writeTags ( const QStringList &tags );
197 
198  //contains the path to the output file
199  QString xmlFile;
200  //the collection to write into a collectionfile
201  imageCollection saveCollection;
202 };
203 
204 #endif // COLLECTION_H
Definition: collection.h:63
Definition: collection.h:145
Definition: collection.h:48
Definition: collection.h:29
Definition: collection.h:179
Definition: collection.h:115