Krita Source Code Documentation
Loading...
Searching...
No Matches
KoDocumentInfo Class Reference

The class containing all meta information about a document. More...

#include <KoDocumentInfo.h>

+ Inheritance diagram for KoDocumentInfo:

Signals

void infoUpdated (const QString &info, const QString &data)
 

Public Member Functions

QString aboutInfo (const QString &info) const
 
QStringList authorContactInfo () const
 authorContactInfo
 
QString authorInfo (const QString &info) const
 
 KoDocumentInfo (const KoDocumentInfo &rhs, QObject *parent=0)
 
 KoDocumentInfo (QObject *parent=0)
 
bool load (const QDomDocument &doc)
 
QString originalGenerator () const
 
void resetMetaData ()
 
QDomDocument save (QDomDocument &doc)
 
void setAboutInfo (const QString &info, const QString &data)
 
void setAuthorInfo (const QString &info, const QString &data)
 
void setOriginalGenerator (const QString &generator)
 
void updateParameters ()
 
 ~KoDocumentInfo () override
 

Private Member Functions

bool loadAboutInfo (const QDomElement &e)
 
bool loadAuthorInfo (const QDomElement &e)
 
QDomElement saveAboutInfo (QDomDocument &doc)
 
QDomElement saveAuthorInfo (QDomDocument &doc)
 
void setActiveAuthorInfo (const QString &info, const QString &data)
 
void updateParametersAndBumpNumCycles ()
 Bumps the editing cycles count and save date, and then calls updateParameters.
 

Private Attributes

QMap< QString, QString > m_aboutInfo
 
QStringList m_aboutTags
 
QMap< QString, QString > m_authorInfo
 
QMap< QString, QString > m_authorInfoOverride
 
QStringList m_authorTags
 
QMap< QString, QString > m_contact
 
QStringList m_contactTags
 
QString m_generator
 

Detailed Description

The class containing all meta information about a document.

Author
Torben Weis weis@.nosp@m.kde..nosp@m.org
David Faure faure.nosp@m.@kde.nosp@m..org
Martin Pfeiffer hubip.nosp@m.ete@.nosp@m.gmx.n.nosp@m.et
See also
KoDocumentInfoDlg

This class contains the meta information for a document. They are stored in two QMap and can be accessed through aboutInfo() and authorInfo(). The about info can be changed with setAboutInfo() and setAuthorInfo()

Definition at line 36 of file KoDocumentInfo.h.

Constructor & Destructor Documentation

◆ KoDocumentInfo() [1/2]

KoDocumentInfo::KoDocumentInfo ( QObject * parent = 0)
explicit

The constructor

Parameters
parenta pointer to the parent object

Definition at line 27 of file KoDocumentInfo.cpp.

27 : QObject(parent)
28{
29 m_aboutTags << "title" << "description" << "subject" << "abstract"
30 << "keyword" << "initial-creator" << "editing-cycles" << "editing-time"
31 << "date" << "creation-date" << "language" << "license";
32
33 m_authorTags << "creator" << "creator-first-name" << "creator-last-name" << "initial" << "author-title" << "position" << "company";
34 m_contactTags << "email" << "telephone" << "telephone-work" << "fax" << "country" << "postal-code" << "city" << "street";
35 setAboutInfo("editing-cycles", "0");
36 setAboutInfo("time-elapsed", "0");
37 setAboutInfo("initial-creator", i18n("Unknown"));
38 setAboutInfo("creation-date", QDateTime::currentDateTime()
39 .toString(Qt::ISODate));
40}
QStringList m_contactTags
QStringList m_authorTags
QStringList m_aboutTags
void setAboutInfo(const QString &info, const QString &data)
QString toString(const QString &value)

References m_aboutTags, m_authorTags, m_contactTags, and setAboutInfo().

◆ KoDocumentInfo() [2/2]

KoDocumentInfo::KoDocumentInfo ( const KoDocumentInfo & rhs,
QObject * parent = 0 )
explicit

Definition at line 42 of file KoDocumentInfo.cpp.

43 : QObject(parent),
51{
52}
QMap< QString, QString > m_authorInfo
QMap< QString, QString > m_aboutInfo
QMap< QString, QString > m_authorInfoOverride
QMap< QString, QString > m_contact

◆ ~KoDocumentInfo()

KoDocumentInfo::~KoDocumentInfo ( )
override

The destructor

Definition at line 54 of file KoDocumentInfo.cpp.

55{
56}

Member Function Documentation

◆ aboutInfo()

QString KoDocumentInfo::aboutInfo ( const QString & info) const

Obtain information about the document

Parameters
infothe kind of information to obtain
Returns
a QString with the information

Definition at line 135 of file KoDocumentInfo.cpp.

136{
137 if (!m_aboutTags.contains(info)) {
138 return QString();
139 }
140
141 return m_aboutInfo[info];
142}

References m_aboutInfo, and m_aboutTags.

◆ authorContactInfo()

QStringList KoDocumentInfo::authorContactInfo ( ) const

authorContactInfo

Returns
returns list of contact info for author.

Definition at line 121 of file KoDocumentInfo.cpp.

122{
123 return m_contact.keys();
124}

References m_contact.

◆ authorInfo()

QString KoDocumentInfo::authorInfo ( const QString & info) const

Obtain information about the author

Parameters
infothe kind of information to obtain
Returns
a QString with the information

Definition at line 113 of file KoDocumentInfo.cpp.

114{
115 if (!m_authorTags.contains(info) && !m_contactTags.contains(info) && !info.contains("contact-mode-"))
116 return QString();
117
118 return m_authorInfo[ info ];
119}

References m_authorInfo, m_authorTags, and m_contactTags.

◆ infoUpdated

void KoDocumentInfo::infoUpdated ( const QString & info,
const QString & data )
signal

◆ load()

bool KoDocumentInfo::load ( const QDomDocument & doc)

Load the KoDocumentInfo from an Calligra-1.3 DomDocument

Parameters
docthe QDomDocument to load from
Returns
true if success

Definition at line 58 of file KoDocumentInfo.cpp.

59{
60 m_authorInfo.clear();
61
62 if (!loadAboutInfo(doc.documentElement()))
63 return false;
64
65 if (!loadAuthorInfo(doc.documentElement()))
66 return false;
67
68 return true;
69}
bool loadAuthorInfo(const QDomElement &e)
bool loadAboutInfo(const QDomElement &e)

References loadAboutInfo(), loadAuthorInfo(), and m_authorInfo.

◆ loadAboutInfo()

bool KoDocumentInfo::loadAboutInfo ( const QDomElement & e)
private

Load the information about the document from a Calligra-1.3 file

Parameters
ethe element to load from
Returns
true if success

Definition at line 196 of file KoDocumentInfo.cpp.

197{
198 QDomElement e = root.firstChildElement("about");
199 if(e.isNull()) {
200 return false;
201 }
202
203 for (e = e.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) {
204 setAboutInfo(e.tagName(), e.text());
205 }
206
207 return true;
208}

References setAboutInfo().

◆ loadAuthorInfo()

bool KoDocumentInfo::loadAuthorInfo ( const QDomElement & e)
private

Load the information about the document from a Calligra-1.3 file

Parameters
ethe element to load from
Returns
true if success

Definition at line 145 of file KoDocumentInfo.cpp.

146{
147 m_contact.clear();
148
149 QDomElement e = root.firstChildElement("author");
150 if(e.isNull()) {
151 return false;
152 }
153
154 for (e = e.firstChildElement(); !e.isNull(); e = e.nextSiblingElement()) {
155 QString field = e.tagName();
156 QString value = e.text();
157
158 if (field == "full-name") {
159 setActiveAuthorInfo("creator", value.trimmed());
160 } else if (field == "contact") {
161 m_contact.insert(value, e.attribute("type"));
162 } else {
163 setActiveAuthorInfo(field, value.trimmed());
164 }
165 }
166
167 return true;
168}
float value(const T *src, size_t ch)
void setActiveAuthorInfo(const QString &info, const QString &data)

References m_contact, setActiveAuthorInfo(), and value().

◆ originalGenerator()

QString KoDocumentInfo::originalGenerator ( ) const

Obtain the generator of the document, as it was loaded from the document

Definition at line 329 of file KoDocumentInfo.cpp.

330{
331 return m_generator;
332}

References m_generator.

◆ resetMetaData()

void KoDocumentInfo::resetMetaData ( )

Resets part of the meta data

Definition at line 321 of file KoDocumentInfo.cpp.

322{
323 setAboutInfo("editing-cycles", QString::number(0));
324 setAboutInfo("initial-creator", authorInfo("creator"));
325 setAboutInfo("creation-date", QDateTime::currentDateTime().toString(Qt::ISODate));
326 setAboutInfo("editing-time", QString::number(0));
327}
QString authorInfo(const QString &info) const

References authorInfo(), and setAboutInfo().

◆ save()

QDomDocument KoDocumentInfo::save ( QDomDocument & doc)

Save the KoDocumentInfo to an Calligra-1.3 DomDocument

Returns
the QDomDocument to which was saved

Definition at line 72 of file KoDocumentInfo.cpp.

73{
75
76 QDomElement s = saveAboutInfo(doc);
77 if (!s.isNull())
78 doc.documentElement().appendChild(s);
79
80 s = saveAuthorInfo(doc);
81 if (!s.isNull())
82 doc.documentElement().appendChild(s);
83
84
85 if (doc.documentElement().isNull())
86 return QDomDocument();
87
88 return doc;
89}
void updateParametersAndBumpNumCycles()
Bumps the editing cycles count and save date, and then calls updateParameters.
QDomElement saveAuthorInfo(QDomDocument &doc)
QDomElement saveAboutInfo(QDomDocument &doc)

References saveAboutInfo(), saveAuthorInfo(), and updateParametersAndBumpNumCycles().

◆ saveAboutInfo()

QDomElement KoDocumentInfo::saveAboutInfo ( QDomDocument & doc)
private

Save the information about the document to a Calligra-1.3 file

Parameters
docthe QDomDocument to save in
Returns
the QDomElement to which was saved

Definition at line 210 of file KoDocumentInfo.cpp.

211{
212 QDomElement e = doc.createElement("about");
213 QDomElement t;
214
215 Q_FOREACH (const QString &tag, m_aboutTags) {
216 if (tag == "abstract") {
217 t = doc.createElement("abstract");
218 e.appendChild(t);
219 t.appendChild(doc.createCDATASection(aboutInfo(tag)));
220 } else {
221 t = doc.createElement(tag);
222 e.appendChild(t);
223 t.appendChild(doc.createTextNode(aboutInfo(tag)));
224 }
225 }
226
227 return e;
228}
QString aboutInfo(const QString &info) const

References aboutInfo(), and m_aboutTags.

◆ saveAuthorInfo()

QDomElement KoDocumentInfo::saveAuthorInfo ( QDomDocument & doc)
private

Save the information about the author to a Calligra-1.3 file

Parameters
docthe QDomDocument to save in
Returns
the QDomElement to which was saved

Definition at line 170 of file KoDocumentInfo.cpp.

171{
172 QDomElement e = doc.createElement("author");
173 QDomElement t;
174
175 Q_FOREACH (const QString &tag, m_authorTags) {
176 if (tag == "creator")
177 t = doc.createElement("full-name");
178 else
179 t = doc.createElement(tag);
180
181 e.appendChild(t);
182 t.appendChild(doc.createTextNode(authorInfo(tag)));
183 }
184 for (int i=0; i<m_contact.keys().size(); i++) {
185 t = doc.createElement("contact");
186 e.appendChild(t);
187 QString key = m_contact.keys().at(i);
188 t.setAttribute("type", m_contact[key]);
189 t.appendChild(doc.createTextNode(key));
190 }
191
192 return e;
193}
int size(const Forest< T > &forest)
Definition KisForest.h:1232

References authorInfo(), m_authorTags, and m_contact.

◆ setAboutInfo()

void KoDocumentInfo::setAboutInfo ( const QString & info,
const QString & data )

Set information about the document

Parameters
infothe kind of information to set
datathe data to set for this information

Definition at line 126 of file KoDocumentInfo.cpp.

127{
128 if (!m_aboutTags.contains(info))
129 return;
130
131 m_aboutInfo.insert(info, data);
132 Q_EMIT infoUpdated(info, data);
133}
void infoUpdated(const QString &info, const QString &data)

References infoUpdated(), m_aboutInfo, and m_aboutTags.

◆ setActiveAuthorInfo()

void KoDocumentInfo::setActiveAuthorInfo ( const QString & info,
const QString & data )
private

Set information about the author This sets what is actually saved to file. The public method setAuthorInfo() can be used to set values that override what is fetched from the author profile. During saveParameters() author profile and any overrides is combined resulting in calls to this method.

Parameters
infothe kind of information to set
datathe data to set for this information

Definition at line 100 of file KoDocumentInfo.cpp.

101{
102 if (!m_authorTags.contains(info) && !m_contactTags.contains(info) && !info.contains("contact-mode-")) {
103 return;
104 }
105 if (m_contactTags.contains(info)) {
106 m_contact.insert(data, info);
107 } else {
108 m_authorInfo.insert(info, data);
109 }
110 Q_EMIT infoUpdated(info, data);
111}

References infoUpdated(), m_authorInfo, m_authorTags, m_contact, and m_contactTags.

◆ setAuthorInfo()

void KoDocumentInfo::setAuthorInfo ( const QString & info,
const QString & data )

Set information about the author. This will override any information retrieved from the author profile But it does not change the author profile Note: authorInfo() will not return the new value until the document has been saved by the user.(autosave doesn't count)

Parameters
infothe kind of information to set
datathe data to set for this information

Definition at line 91 of file KoDocumentInfo.cpp.

92{
93 if (!m_authorTags.contains(info) && !m_contactTags.contains(info) && !info.contains("contact-mode-")) {
94 return;
95 }
96
97 m_authorInfoOverride.insert(info, data);
98}

References m_authorInfoOverride, m_authorTags, and m_contactTags.

◆ setOriginalGenerator()

void KoDocumentInfo::setOriginalGenerator ( const QString & generator)

Sets the original generator of the document. This does not affect what gets saved to a document in the meta:generator field, it only changes what originalGenerator() will return.

Definition at line 334 of file KoDocumentInfo.cpp.

335{
336 m_generator = generator;
337}

References m_generator.

◆ updateParameters()

void KoDocumentInfo::updateParameters ( )

Takes care of updating the document info from configuration correctly

Definition at line 243 of file KoDocumentInfo.cpp.

244{
245 KisDocument *doc = dynamic_cast< KisDocument *>(parent());
246 if (doc && (!doc->isModified())) {
247 return;
248 }
249
250 KConfig config("kritarc");
251 config.reparseConfiguration();
252 KConfigGroup appAuthorGroup(&config, "Author");
253 QString profile = appAuthorGroup.readEntry("active-profile", "");
254
255 QString authorInfo = KoResourcePaths::getAppDataLocation() + "/authorinfo/";
256 QDir dir(authorInfo);
257 QStringList filters = QStringList() << "*.authorinfo";
258
259 //Anon case
260 setActiveAuthorInfo("creator", QString());
261 setActiveAuthorInfo("initial", "");
262 setActiveAuthorInfo("author-title", "");
263 setActiveAuthorInfo("position", "");
264 setActiveAuthorInfo("company", "");
265 if (dir.entryList(filters).contains(profile+".authorinfo")) {
266 QFile file(dir.absoluteFilePath(profile+".authorinfo"));
267 if (file.exists()) {
268 file.open(QFile::ReadOnly);
269 QByteArray ba = file.readAll();
270 file.close();
271 QDomDocument doc = QDomDocument();
272 doc.setContent(ba);
273 QDomElement root = doc.firstChildElement();
274
275 QDomElement el = root.firstChildElement("nickname");
276 if (!el.isNull()) {
277 setActiveAuthorInfo("creator", el.text());
278 }
279 el = root.firstChildElement("givenname");
280 if (!el.isNull()) {
281 setActiveAuthorInfo("creator-first-name", el.text());
282 }
283 el = root.firstChildElement("middlename");
284 if (!el.isNull()) {
285 setActiveAuthorInfo("initial", el.text());
286 }
287 el = root.firstChildElement("familyname");
288 if (!el.isNull()) {
289 setActiveAuthorInfo("creator-last-name", el.text());
290 }
291 el = root.firstChildElement("title");
292 if (!el.isNull()) {
293 setActiveAuthorInfo("author-title", el.text());
294 }
295 el = root.firstChildElement("position");
296 if (!el.isNull()) {
297 setActiveAuthorInfo("position", el.text());
298 }
299 el = root.firstChildElement("company");
300 if (!el.isNull()) {
301 setActiveAuthorInfo("company", el.text());
302 }
303
304 m_contact.clear();
305 el = root.firstChildElement("contact");
306 while (!el.isNull()) {
307 m_contact.insert(el.text(), el.attribute("type"));
308 el = el.nextSiblingElement("contact");
309 }
310 }
311 }
312
313 //allow author info set programmatically to override info from author profile
314 Q_FOREACH (const QString &tag, m_authorTags) {
315 if (m_authorInfoOverride.contains(tag)) {
317 }
318 }
319}
QList< QString > QStringList
bool isModified() const
static QString getAppDataLocation()
ChildIterator< value_type, is_const > parent(const ChildIterator< value_type, is_const > &it)
Definition KisForest.h:327

References authorInfo(), KoResourcePaths::getAppDataLocation(), KisDocument::isModified(), m_authorInfoOverride, m_authorTags, m_contact, and setActiveAuthorInfo().

◆ updateParametersAndBumpNumCycles()

void KoDocumentInfo::updateParametersAndBumpNumCycles ( )
private

Bumps the editing cycles count and save date, and then calls updateParameters.

Definition at line 230 of file KoDocumentInfo.cpp.

231{
232 KisDocument *doc = dynamic_cast< KisDocument *>(parent());
233 if (doc && doc->isAutosaving()) {
234 return;
235 }
236
237 setAboutInfo("editing-cycles", QString::number(aboutInfo("editing-cycles").toInt() + 1));
238 setAboutInfo("date", QDateTime::currentDateTime().toString(Qt::ISODate));
239
241}
int toInt(const QString &str, bool *ok=nullptr)

References aboutInfo(), KisDocument::isAutosaving, setAboutInfo(), and updateParameters().

Member Data Documentation

◆ m_aboutInfo

QMap<QString, QString> KoDocumentInfo::m_aboutInfo
private

The map containing information about the document

Definition at line 174 of file KoDocumentInfo.h.

◆ m_aboutTags

QStringList KoDocumentInfo::m_aboutTags
private

A QStringList containing all tags for the document information

Definition at line 162 of file KoDocumentInfo.h.

◆ m_authorInfo

QMap<QString, QString> KoDocumentInfo::m_authorInfo
private

The map containing information about the author

Definition at line 170 of file KoDocumentInfo.h.

◆ m_authorInfoOverride

QMap<QString, QString> KoDocumentInfo::m_authorInfoOverride
private

The map containing information about the author set programmatically

Definition at line 172 of file KoDocumentInfo.h.

◆ m_authorTags

QStringList KoDocumentInfo::m_authorTags
private

A QStringList containing all tags for the author information

Definition at line 164 of file KoDocumentInfo.h.

◆ m_contact

QMap<QString, QString> KoDocumentInfo::m_contact
private

A QMap with the contact modes and their type in the second string

Definition at line 168 of file KoDocumentInfo.h.

◆ m_contactTags

QStringList KoDocumentInfo::m_contactTags
private

A QStringList containing all valid contact tags

Definition at line 166 of file KoDocumentInfo.h.

◆ m_generator

QString KoDocumentInfo::m_generator
private

The original meta:generator of the document

Definition at line 176 of file KoDocumentInfo.h.


The documentation for this class was generated from the following files: