summaryrefslogtreecommitdiffstats
path: root/lib/kofficecore/KoPictureKey.h
blob: 09cf63207cb4ee0e85e69f632a96f7d0dc34a552 (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
/* This file is part of the KDE project
   Copyright (c) 2001 Simon Hausmann <hausmann@kde.org>
   Copyright (C) 2002, 2004 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 __koPictureKey_h__
#define __koPictureKey_h__

#include <tqstring.h>
#include <tqdatetime.h>
#include <koffice_export.h>
/**
 * \file koPictureKey.h
 * \todo correct documentation (for example: sed "s/image/picture/g")
 */

class TQDomElement;

namespace KoPictureType
{
    /**
     * TQPicture version used by KoPictureClipart
     *
     * Possible values:
     * \li 3 for TQt 2.1.x and later TQt 2.x
     * \li 4 for TQt 3.0
     * \li 5 for TQt 3.1 and later TQt 3.x
     * \li -1 for current TQt
     */
    const int formatVersionTQPicture=-1;

    enum Type
    {
        TypeUnknown = 0,    ///< Unknown or not-an-image @see KoPictureBase
        TypeImage,          ///< Image, TQImage-based @see KoPictureImage
        TypeEps,            ///< Encapsulated Postscript @see KoPictureEps
        TypeClipart,        ///< Clipart, TQPicture-based @see KoPictureClipart
        TypeWmf             ///< WMF (Windows Meta File) @see KoPictureWmf
    };
}

/**
 * KoPictureKey is the structure describing a picture in a unique way.
 * It currently includes the original path to the picture and the modification
 * date.
 *
 * @short Structure describing a picture on disk
 *
 * @note We use the *nix epoch (1970-01-01) as a time base because it is a valid date.
 * That way we do not depend on a behaviour of the current TQDateTime that might change in future versions of TQt
 * and we are also nice to non-TQt programs wanting to read KOffice's files.
 *
 * @note This behaviour is also needed for re-saving KWord files having \<FORMAT id="2"\>. When saving again,
 * these files get a \<KEY\> element as child of \<PIXMAPS\> but not one as child of \<FORMAT\> and \<IMAGE\>.
 * Therefore we need to be careful that the key remains compatible to default values 
 * (another good reason for the *NIX epoch)
 *
 * @note In case of a remote path, the "original path" is the name of the temporary file that was
 *  used to download the file.
 */
class KOFFICEUI_EXPORT KoPictureKey
{
public:
    /**
     * Default constructor. Creates a null key
     */
    KoPictureKey();

    /**
     * @brief Constructs a key, from a filename and a modification date
     *
     * Storing the modification date as part of the key allows the user
     * to update the file and import it into the application again, without
     * the application reusing the old copy from the collection.
     */
    KoPictureKey( const TQString &fn, const TQDateTime &mod );

    /**
     * Constructs a key from a filename 
     * @note The modification date is set to 1970-01-01
     */
    KoPictureKey( const TQString &fn );

    /**
     * Copy constructor
     */
    KoPictureKey( const KoPictureKey &key );

    /**
     * Assignment operator
     */
    KoPictureKey &operator=( const KoPictureKey &key );

    /**
     * Comparison operator
     */
    bool operator==( const KoPictureKey &key ) const;

    /**
     * Comparison operator 
     * @note Used for sorting in the collection's map
     */
    bool operator<( const KoPictureKey &key ) const;

    /**
     * Convert this key into a string representation of it
     */
    TQString toString() const;

    /**
     * Save this key in XML (as %KOffice 1.3)
     */
    void saveAttributes( TQDomElement &elem ) const;

    /**
     * Load this key from XML (as %KOffice 1.3)
     */
    void loadAttributes( const TQDomElement &elem );

    /**
     * First part of the key: the filename
     */
    TQString filename() const { return m_filename; }

    /**
     * Second part of the key: the modification date
     */
    TQDateTime lastModified() const { return m_lastModified; }

    /**
     * Sets the key according to @p filename, including modification time
     */
    void setKeyFromFile (const TQString& filename);

protected:
    TQString m_filename;
    TQDateTime m_lastModified;
};

#endif /* __koPictureKey_h__ */