diff --git a/libs/odf/KoDocumentInfo.cpp b/libs/odf/KoDocumentInfo.cpp index b1c6526af5..76b9753047 100644 --- a/libs/odf/KoDocumentInfo.cpp +++ b/libs/odf/KoDocumentInfo.cpp @@ -1,469 +1,467 @@ /* This file is part of the KDE project Copyright (C) 1998, 1999, 2000 Torben Weis Copyright (C) 2004 David Faure 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. */ #include "KoDocumentInfo.h" #include "KoDocumentBase.h" #include "KoOdfWriteStore.h" #include "KoXmlNS.h" #include #include #include #include #include #include #include #include #include #include #include #include #include KoDocumentInfo::KoDocumentInfo(QObject *parent) : QObject(parent) { m_aboutTags << "title" << "description" << "subject" << "abstract" << "keyword" << "initial-creator" << "editing-cycles" << "editing-time" << "date" << "creation-date" << "language" << "license"; m_authorTags << "creator" << "creator-first-name" << "creator-last-name" << "initial" << "author-title" << "position" << "company"; m_contactTags << "email" << "telephone" << "telephone-work" << "fax" << "country" << "postal-code" << "city" << "street"; setAboutInfo("editing-cycles", "0"); setAboutInfo("time-elapsed", "0"); setAboutInfo("initial-creator", i18n("Unknown")); setAboutInfo("creation-date", QDateTime::currentDateTime() .toString(Qt::ISODate)); } KoDocumentInfo::KoDocumentInfo(const KoDocumentInfo &rhs, QObject *parent) : QObject(parent), m_aboutTags(rhs.m_aboutTags), m_authorTags(rhs.m_authorTags), m_contact(rhs.m_contact), m_authorInfo(rhs.m_authorInfo), m_authorInfoOverride(rhs.m_authorInfoOverride), m_aboutInfo(rhs.m_aboutInfo), m_generator(rhs.m_generator) { } KoDocumentInfo::~KoDocumentInfo() { } bool KoDocumentInfo::load(const KoXmlDocument &doc) { m_authorInfo.clear(); if (!loadAboutInfo(doc.documentElement())) return false; if (!loadAuthorInfo(doc.documentElement())) return false; return true; } QDomDocument KoDocumentInfo::save(QDomDocument &doc) { updateParametersAndBumpNumCycles(); QDomElement s = saveAboutInfo(doc); if (!s.isNull()) doc.documentElement().appendChild(s); s = saveAuthorInfo(doc); if (!s.isNull()) doc.documentElement().appendChild(s); if (doc.documentElement().isNull()) return QDomDocument(); return doc; } void KoDocumentInfo::setAuthorInfo(const QString &info, const QString &data) { if (!m_authorTags.contains(info) && !m_contactTags.contains(info) && !info.contains("contact-mode-")) { - qDebug()< 0) { setAboutInfo("keyword", keywords.join(", ")); } return true; } bool KoDocumentInfo::loadAboutInfo(const KoXmlElement &e) { KoXmlNode n = e.namedItem("about").firstChild(); KoXmlElement tmp; for (; !n.isNull(); n = n.nextSibling()) { tmp = n.toElement(); if (tmp.isNull()) continue; if (tmp.tagName() == "abstract") setAboutInfo("abstract", tmp.text()); setAboutInfo(tmp.tagName(), tmp.text()); } return true; } QDomElement KoDocumentInfo::saveAboutInfo(QDomDocument &doc) { QDomElement e = doc.createElement("about"); QDomElement t; Q_FOREACH (const QString &tag, m_aboutTags) { if (tag == "abstract") { t = doc.createElement("abstract"); e.appendChild(t); t.appendChild(doc.createCDATASection(aboutInfo(tag))); } else { t = doc.createElement(tag); e.appendChild(t); t.appendChild(doc.createTextNode(aboutInfo(tag))); } } return e; } void KoDocumentInfo::updateParametersAndBumpNumCycles() { KoDocumentBase *doc = dynamic_cast< KoDocumentBase *>(parent()); if (doc && doc->isAutosaving()) { return; } setAboutInfo("editing-cycles", QString::number(aboutInfo("editing-cycles").toInt() + 1)); setAboutInfo("date", QDateTime::currentDateTime().toString(Qt::ISODate)); updateParameters(); } void KoDocumentInfo::updateParameters() { KoDocumentBase *doc = dynamic_cast< KoDocumentBase *>(parent()); if (doc && (!doc->isModified())) { return; } KConfig config("kritarc"); config.reparseConfiguration(); KConfigGroup appAuthorGroup(&config, "Author"); QString profile = appAuthorGroup.readEntry("active-profile", ""); QString authorInfo = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/authorinfo/"; QDir dir(authorInfo); QStringList filters = QStringList() << "*.authorinfo"; //Anon case setActiveAuthorInfo("creator", QString()); setActiveAuthorInfo("initial", ""); setActiveAuthorInfo("author-title", ""); setActiveAuthorInfo("position", ""); setActiveAuthorInfo("company", ""); if (dir.entryList(filters).contains(profile+".authorinfo")) { QFile file(dir.absoluteFilePath(profile+".authorinfo")); if (file.exists()) { file.open(QFile::ReadOnly); QByteArray ba = file.readAll(); file.close(); QDomDocument doc = QDomDocument(); doc.setContent(ba); QDomElement root = doc.firstChildElement(); QDomElement el = root.firstChildElement("nickname"); if (!el.isNull()) { setActiveAuthorInfo("creator", el.text()); } el = root.firstChildElement("givenname"); if (!el.isNull()) { setActiveAuthorInfo("creator-first-name", el.text()); } el = root.firstChildElement("middlename"); if (!el.isNull()) { setActiveAuthorInfo("initial", el.text()); } el = root.firstChildElement("familyname"); if (!el.isNull()) { setActiveAuthorInfo("creator-last-name", el.text()); } el = root.firstChildElement("title"); if (!el.isNull()) { setActiveAuthorInfo("author-title", el.text()); } el = root.firstChildElement("position"); if (!el.isNull()) { setActiveAuthorInfo("position", el.text()); } el = root.firstChildElement("company"); if (!el.isNull()) { setActiveAuthorInfo("company", el.text()); } m_contact.clear(); el = root.firstChildElement("contact"); while (!el.isNull()) { m_contact.insert(el.text(), el.attribute("type")); el = el.nextSiblingElement("contact"); } } } //allow author info set programmatically to override info from author profile Q_FOREACH (const QString &tag, m_authorTags) { if (m_authorInfoOverride.contains(tag)) { setActiveAuthorInfo(tag, m_authorInfoOverride.value(tag)); } } } void KoDocumentInfo::resetMetaData() { setAboutInfo("editing-cycles", QString::number(0)); setAboutInfo("initial-creator", authorInfo("creator")); setAboutInfo("creation-date", QDateTime::currentDateTime().toString(Qt::ISODate)); setAboutInfo("editing-time", QString::number(0)); } QString KoDocumentInfo::originalGenerator() const { return m_generator; } void KoDocumentInfo::setOriginalGenerator(const QString &generator) { m_generator = generator; }