1 | /* This file is part of the KDE project |
2 | Copyright (C) 2007 Dag Andersen <danders@get2net.dk> |
3 | |
4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public |
6 | License as published by the Free Software Foundation; either |
7 | version 2 of the License, or (at your option) any later version. |
8 | |
9 | This library 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 GNU |
12 | Library General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
17 | * Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | #ifndef KPTDOCUMENTS_H |
21 | #define KPTDOCUMENTS_H |
22 | |
23 | #include "kplatokernel_export.h" |
24 | |
25 | #include "KoXmlReaderForward.h" |
26 | |
27 | #include <QList> |
28 | |
29 | #include <kurl.h> |
30 | #include <klocale.h> |
31 | |
32 | class KoStore; |
33 | |
34 | class QDomElement; |
35 | |
36 | namespace KPlato |
37 | { |
38 | |
39 | class XMLLoaderObject; |
40 | class Node; |
41 | class Documents; |
42 | |
43 | class KPLATOKERNEL_EXPORT Document |
44 | { |
45 | public: |
46 | enum Type { Type_None, Type_Product, Type_Reference }; |
47 | enum SendAs { SendAs_None, SendAs_Copy, SendAs_Reference }; |
48 | |
49 | Document(); |
50 | explicit Document( const KUrl &url, Type type = Type_Reference, SendAs sendAs = SendAs_Reference ); |
51 | ~Document(); |
52 | |
53 | bool operator==( const Document &doc ) const; |
54 | bool operator!=( const Document &doc ) const { return ! operator==( doc ); } |
55 | |
56 | QString name() const { return m_name; } |
57 | void setName( const QString &name ); |
58 | |
59 | Type type() const { return m_type; } |
60 | void setType( Type type ); |
61 | static QStringList typeList( bool trans = false ); |
62 | static QString typeToString( Type type, bool trans = false ); |
63 | |
64 | SendAs sendAs() const { return m_sendAs; } |
65 | void setSendAs( SendAs snd ); |
66 | static QStringList sendAsList( bool trans = false ); |
67 | static QString sendAsToString( SendAs snd, bool trans = false ); |
68 | |
69 | KUrl url() const { return m_url; } |
70 | void setUrl( const KUrl &url ); |
71 | bool isValid() const; |
72 | |
73 | QString status() const { return m_status; } |
74 | void setStatus( const QString &sts ); |
75 | |
76 | bool load( KoXmlElement &element, XMLLoaderObject &status ); |
77 | void save(QDomElement &element) const; |
78 | |
79 | private: |
80 | Type m_type; |
81 | KUrl m_url; |
82 | QString m_status; |
83 | SendAs m_sendAs; |
84 | QString m_name; |
85 | |
86 | friend class Documents; |
87 | Documents *parent; |
88 | }; |
89 | |
90 | class KPLATOKERNEL_EXPORT Documents |
91 | { |
92 | public: |
93 | Documents(); |
94 | explicit Documents( const Documents &docs ); |
95 | ~Documents(); |
96 | |
97 | bool operator==( const Documents &docs ) const; |
98 | bool operator!=( const Documents &docs ) const { return ! operator==( docs ); } |
99 | |
100 | void deleteAll(); |
101 | QList<Document*> documents() const { return m_docs; } |
102 | void addDocument( Document *doc ); |
103 | void addDocument( const KUrl &url, Document::Type = Document::Type_None ); |
104 | Document *takeDocument( int index ); |
105 | Document *takeDocument( Document *doc ); |
106 | Document *findDocument( const Document *doc ) const; |
107 | Document *findDocument( const KUrl &url ) const; |
108 | // Document *document( int index ) const; |
109 | |
110 | bool contains( const Document *doc ) const { return m_docs.contains( const_cast<Document*>( doc ) ); } |
111 | int indexOf( const Document *doc ) const { return m_docs.indexOf( const_cast<Document*>( doc ) ); } |
112 | int count() const { return m_docs.count(); } |
113 | const Document *at( int index ) const { return m_docs.at( index ); } |
114 | Document *value( int index ) const { return m_docs.value( index ); } |
115 | |
116 | bool load( KoXmlElement &element, XMLLoaderObject &status ); |
117 | void save(QDomElement &element) const; |
118 | |
119 | void saveToStore( KoStore *store ) const; |
120 | |
121 | void documentChanged( Document *doc ); |
122 | |
123 | protected: |
124 | QList<Document*> m_docs; |
125 | |
126 | private: |
127 | friend class Node; |
128 | Node *node; // owner node |
129 | }; |
130 | |
131 | } //namespace KPlato |
132 | |
133 | #endif |
134 | |