summaryrefslogtreecommitdiffstats
path: root/lib/kofficecore/KoPictureCollection.h
blob: 8d96761c3c96c5ecee04f4a99c234092af6f7d65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/* This file is part of the KDE project
   Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
   Copyright (c) 2001 David Faure <faure@kde.org>
   Copyright (C) 2002 Nicolas GOUTTE <goutte@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef koPictureCollection_h
#define koPictureCollection_h

#include <tqmap.h>
#include <tqdom.h>
#include <tqvaluelist.h>

#include "KoPicture.h"

class KURL;

class KoStore;
class KoXmlWriter;

/**
 * A collection of pictures (a key and the picture itself).
 *
 */
class KOFFICECORE_EXPORT KoPictureCollection : public TQMap<KoPictureKey, KoPicture>
{
public:
    enum Type {
        /// collection with mixed pictures
        CollectionPicture=0,
        /// collection with images only
        CollectionImage,
        /// collection with cliparts only
        CollectionClipart
    };

    /**
     * Looks for a clipart in the collection, returns a new KoPicture with that key if not found.
     */
    KoPicture findPicture( const KoPictureKey &key ) const;

    /**
     * Inserts a picture into the collection, if not already there
     */
    KoPicture insertPicture( const KoPictureKey& key, const KoPicture& picture );

    /**
     * Inserts a picture into the collection, if not already there
     * Same as above, but takes the key from the @p picture
     */
    KoPicture insertPicture( const KoPicture& picture );

    /**
     * @brief Download a possibly remote file
     *
     * If this file is really remote, it is always downloaded.
     * If the file is local, it acts as @ref #loadPicture.
     * @param url the URL to download from
     * @param window the parent window for the download. You can pass NULL (0)
     *               if you absolutely cannot find anything to use.
     */
    KoPicture downloadPicture(const KURL& url, TQWidget *window);

    /**
     * @brief Load a clipart from a file (and insert into the collection).
     *
     * The modification date of the file is checked, to create the key
     * for this clipart. If this key maps to an existing clipart in the
     * collection, then this picture is returned, otherwise the file is loaded.
     */
    KoPicture loadPicture( const TQString &fileName );

    /**
     * Save the used picturess from the collection into the store
     * Usually called from completeSaving().
     *
     * @param pictureType type for the stored picture
     * @param store the store in which to save the pictures
     * @param keys the list of keys corresponding to the pictures to save
     * @return true on success, false on failure (e.g. disk full)
     *
     * @todo Reduce lameness of dox for pictureType.
     */
    bool saveToStore(const Type pictureType, KoStore * store, const TQValueList<KoPictureKey>& keys );

    /**
     * Generate the &lt;PICTURES&gt;, &lt;PIXMAPS> or &lt;CLIPARTS> tag, that saves the key and the related
     * relative path in the store (e.g. pictures/picture1.png) for each picture.
     *
     * @param pictureType the type of the collection
     * @param doc the DOM document in which the tags are to be generated
     * @param keys the list of keys
     */
    TQDomElement saveXML(const Type pictureType, TQDomDocument &doc,
        TQValueList<KoPictureKey> keys );

    bool saveOasisToStore( KoStore *store, TQValueList<KoPictureKey> keys, KoXmlWriter* manifestWriter );


    typedef TQMap<KoPictureKey, TQString> StoreMap;
    /**
     * Read the &lt;PICTURES&gt;, &lt;PIXMAPS> or &lt;CLIPARTS> tag, and save the result (key<->store-filename associations)
     * into the TQMap. You may want to 'new' a TQMap in loadXML, and to use and then delete
     * it in completeLoading (to save memory).
     *
     * @param pixmapsElem the &lt;PICTURES&gt;, &lt;PIXMAPS> or &lt;CLIPARTS> element
     */
    StoreMap readXML( TQDomElement &pixmapsElem );

    /**
     * Helper method for @ref #readFromStore
     */
    void readXML( TQDomElement& pixmapsElem, TQMap <KoPictureKey, TQString>& map );

    /**
     * Read all pictures from the store, into this collection
     * The map comes from @ref #readXML, and is used to find which pictures
     * to load, and which key to associate them.
     */
    void readFromStore( KoStore * store, const StoreMap & storeMap );

    /**
     * @deprecated
     * KPresenter needs to use the same code for loading images from a collection and
     * for loading images from disk.
     *
     * @param fileName the name of the file to read from disk if needed
     * @param dateTime the date and time
     *
     * Formerly, an invalid date/time meant to read the file from disk. This is not the case anymore.
     */
    KoPicture findOrLoad(const TQString& fileName, const TQDateTime& dateTime);

    /**
     * Return filename as url for picture
     *
     */
    TQString getOasisFileName(const KoPicture& picture) const;

    /**
     * Call it before to save Oasis file
     */
    void assignUniqueIds();


private:
    /**
     * @internal
     */
    TQString getFileName(const Type pictureType, KoPicture& picture, int& counter);

    class Private;
    Private* d;
};

#endif /* __koPictureCollection_h_- */