File indexing completed on 2024-05-12 16:01:59

0001 /* This file is part of the KDE project
0002    SPDX-FileCopyrightText: 1998, 1999, 2000 Torben Weis <weis@kde.org>
0003    SPDX-FileCopyrightText: 2004 David Faure <faure@kde.org>
0004    SPDX-FileCopyrightText: 2006 Martin Pfeiffer <hubipete@gmx.net>
0005 
0006    SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef KO_DOCUMENT_INFO_H
0010 #define KO_DOCUMENT_INFO_H
0011 
0012 #include <QObject>
0013 #include <QMap>
0014 #include <QString>
0015 #include <QStringList>
0016 
0017 #include "kritaui_export.h"
0018 #include <QDomDocument>
0019 
0020 class QDomDocument;
0021 class QDomElement;
0022 class KoStore;
0023 
0024 /**
0025  * @short The class containing all meta information about a document
0026  *
0027  * @author Torben Weis <weis@kde.org>
0028  * @author David Faure <faure@kde.org>
0029  * @author Martin Pfeiffer <hubipete@gmx.net>
0030  * @see KoDocumentInfoDlg
0031  *
0032  * This class contains the meta information for a document. They are
0033  * stored in two QMap and can be accessed through aboutInfo() and authorInfo().
0034  * The about info can be changed with setAboutInfo() and setAuthorInfo()
0035  */
0036 class KRITAUI_EXPORT KoDocumentInfo : public QObject
0037 {
0038     Q_OBJECT
0039 
0040 public:
0041     /**
0042      * The constructor
0043      * @param parent a pointer to the parent object
0044      */
0045     explicit KoDocumentInfo(QObject *parent = 0);
0046     explicit KoDocumentInfo(const KoDocumentInfo &rhs, QObject *parent = 0);
0047 
0048     /** The destructor */
0049     ~KoDocumentInfo() override;
0050     /**
0051      * Load the KoDocumentInfo from an Calligra-1.3 DomDocument
0052      * @param doc the QDomDocument to load from
0053      * @return true if success
0054      */
0055     bool load(const QDomDocument& doc);
0056 
0057     /**
0058      * Save the KoDocumentInfo to an Calligra-1.3 DomDocument
0059      * @return the QDomDocument to which was saved
0060      */
0061     QDomDocument save(QDomDocument &doc);
0062 
0063     /**
0064      * Set information about the author.
0065      * This will override any information retrieved from the author profile
0066      * But it does not change the author profile
0067      * Note: authorInfo() will not return the new value until the document has been
0068      * saved by the user.(autosave doesn't count)
0069      * @param info the kind of information to set
0070      * @param data the data to set for this information
0071      */
0072     void setAuthorInfo(const QString& info, const QString& data);
0073 
0074     /**
0075      * Obtain information about the author
0076      * @param info the kind of information to obtain
0077      * @return a QString with the information
0078      */
0079     QString authorInfo(const QString& info) const;
0080 
0081     /**
0082      * @brief authorContactInfo
0083      * @return returns list of contact info for author.
0084      */
0085     QStringList authorContactInfo() const;
0086 
0087     /**
0088      * Set information about the document
0089      * @param info the kind of information to set
0090      * @param data the data to set for this information
0091      */
0092     void setAboutInfo(const QString& info, const QString& data);
0093 
0094     /**
0095      * Obtain information about the document
0096      * @param info the kind of information to obtain
0097      * @return a QString with the information
0098      */
0099     QString aboutInfo(const QString& info) const;
0100 
0101     /**
0102      * Obtain the generator of the document, as it was loaded from the document
0103      */
0104     QString originalGenerator() const;
0105 
0106     /**
0107      * Sets the original generator of the document. This does not affect what gets
0108      * saved to a document in the meta:generator field, it only changes what
0109      * originalGenerator() will return.
0110      */
0111     void setOriginalGenerator(const QString& generator);
0112 
0113     /** Resets part of the meta data */
0114     void resetMetaData();
0115 
0116     /** Takes care of updating the document info from configuration correctly */
0117     void updateParameters();
0118 
0119 private:
0120     /// Bumps the editing cycles count and save date, and then calls updateParameters
0121     void updateParametersAndBumpNumCycles();
0122 
0123     /**
0124      * Set information about the author
0125      * This sets what is actually saved to file. The public method setAuthorInfo() can be used to set
0126      * values that override what is fetched from the author profile. During saveParameters() author
0127      * profile and any overrides is combined resulting in calls to this method.
0128      * @param info the kind of information to set
0129      * @param data the data to set for this information
0130      */
0131     void setActiveAuthorInfo(const QString& info, const QString& data);
0132 
0133     /**
0134      * Load the information about the document from a Calligra-1.3 file
0135      * @param e the element to load from
0136      * @return true if success
0137      */
0138     bool loadAboutInfo(const QDomElement& e);
0139 
0140     /**
0141      * Save the information about the document to a Calligra-1.3 file
0142      * @param doc the QDomDocument to save in
0143      * @return the QDomElement to which was saved
0144      */
0145     QDomElement saveAboutInfo(QDomDocument& doc);
0146 
0147     /**
0148      * Load the information about the document from a Calligra-1.3 file
0149      * @param e the element to load from
0150      * @return true if success
0151      */
0152     bool loadAuthorInfo(const QDomElement& e);
0153 
0154     /**
0155      * Save the information about the author to a Calligra-1.3 file
0156      * @param doc the QDomDocument to save in
0157      * @return the QDomElement to which was saved
0158      */
0159     QDomElement saveAuthorInfo(QDomDocument& doc);
0160 
0161     /** A QStringList containing all tags for the document information */
0162     QStringList m_aboutTags;
0163     /** A QStringList containing all tags for the author information */
0164     QStringList m_authorTags;
0165     /** A QStringList containing all valid contact tags */
0166     QStringList m_contactTags;
0167     /** A QMap with the contact modes and their type in the second string */
0168     QMap <QString, QString> m_contact;
0169     /** The map containing information about the author */
0170     QMap<QString, QString> m_authorInfo;
0171     /** The map containing information about the author set programmatically*/
0172     QMap<QString, QString> m_authorInfoOverride;
0173     /** The map containing information about the document */
0174     QMap<QString, QString> m_aboutInfo;
0175     /** The original meta:generator of the document */
0176     QString m_generator;
0177 
0178 Q_SIGNALS:
0179     void infoUpdated(const QString &info, const QString &data);
0180 };
0181 
0182 #endif