File indexing completed on 2024-12-01 04:47:51

0001 /*
0002     This file is part of the kolab resource - the implementation of the
0003     Kolab storage format. See www.kolab.org for documentation on this.
0004 
0005     SPDX-FileCopyrightText: 2004 Bo Thorsen <bo@sonofthor.dk>
0006 
0007     SPDX-License-Identifier: LGPL-2.0-or-later
0008 */
0009 
0010 #pragma once
0011 
0012 #include <KCalendarCore/Incidence>
0013 
0014 #include <QColor>
0015 #include <QDateTime>
0016 #include <QTimeZone>
0017 #include <qdom.h>
0018 
0019 namespace KContacts
0020 {
0021 class Addressee;
0022 class ContactGroup;
0023 }
0024 
0025 namespace KolabV2
0026 {
0027 class KolabBase
0028 {
0029 public:
0030     struct Email {
0031     public:
0032         Email(const QString &name = QString(), const QString &email = QString())
0033             : displayName(name)
0034             , smtpAddress(email)
0035         {
0036         }
0037 
0038         QString displayName;
0039         QString smtpAddress;
0040     };
0041 
0042     enum Sensitivity {
0043         Public = 0,
0044         Private = 1,
0045         Confidential = 2,
0046     };
0047 
0048     explicit KolabBase(const QString &time_zone = QString());
0049     virtual ~KolabBase();
0050 
0051     // Return a string identifying this type
0052     virtual QString type() const = 0;
0053 
0054     virtual void setUid(const QString &uid);
0055     virtual QString uid() const;
0056 
0057     virtual void setBody(const QString &body);
0058     virtual QString body() const;
0059 
0060     virtual void setCategories(const QString &categories);
0061     virtual QString categories() const;
0062 
0063     virtual void setCreationDate(const QDateTime &date);
0064     virtual QDateTime creationDate() const;
0065 
0066     virtual void setLastModified(const QDateTime &date);
0067     virtual QDateTime lastModified() const;
0068 
0069     virtual void setSensitivity(Sensitivity sensitivity);
0070     virtual Sensitivity sensitivity() const;
0071 
0072     virtual void setPilotSyncId(unsigned long id);
0073     virtual bool hasPilotSyncId() const;
0074     virtual unsigned long pilotSyncId() const;
0075 
0076     virtual void setPilotSyncStatus(int status);
0077     virtual bool hasPilotSyncStatus() const;
0078     virtual int pilotSyncStatus() const;
0079 
0080     // String - Date conversion methods
0081     static QString dateTimeToString(const QDateTime &time);
0082     static QString dateToString(QDate date);
0083     static QDateTime stringToDateTime(const QString &time);
0084     static QDate stringToDate(const QString &date);
0085 
0086     // String - Sensitivity conversion methods
0087     static QString sensitivityToString(Sensitivity);
0088     static Sensitivity stringToSensitivity(const QString &);
0089 
0090     // String - Color conversion methods
0091     static QString colorToString(const QColor &);
0092     static QColor stringToColor(const QString &);
0093 
0094     // Load this object by reading the XML file
0095     bool load(const QString &xml);
0096     static QDomDocument loadDocument(const QString &xmlData);
0097 
0098     // Load this QDomDocument
0099     virtual bool loadXML(const QDomDocument &xml) = 0;
0100 
0101     // Serialize this object to an XML string
0102     virtual QString saveXML() const = 0;
0103 
0104 protected:
0105     /// Read all known fields from this ical incidence
0106     void setFields(const KCalendarCore::Incidence::Ptr &);
0107 
0108     /// Save all known fields into this ical incidence
0109     void saveTo(const KCalendarCore::Incidence::Ptr &) const;
0110 
0111     /// Read all known fields from this contact
0112     void setFields(const KContacts::Addressee *);
0113 
0114     /// Save all known fields into this contact
0115     void saveTo(KContacts::Addressee *) const;
0116 
0117     /// Read all known fields from this contact group
0118     void setFields(const KContacts::ContactGroup *);
0119 
0120     /// Save all known fields into this contact group
0121     void saveTo(KContacts::ContactGroup *) const;
0122 
0123     // This just makes the initial dom tree with version and doctype
0124     static QDomDocument domTree();
0125 
0126     bool loadEmailAttribute(QDomElement &element, Email &email);
0127 
0128     void saveEmailAttribute(QDomElement &element, const Email &email, const QString &tagName = QStringLiteral("email")) const;
0129 
0130     // Load the attributes of this class
0131     virtual bool loadAttribute(QDomElement &);
0132 
0133     // Save the attributes of this class
0134     virtual bool saveAttributes(QDomElement &) const;
0135 
0136     // Return the product ID
0137     virtual QString productID() const = 0;
0138 
0139     // Write a string tag
0140     static void writeString(QDomElement &, const QString &, const QString &);
0141 
0142     QDateTime localToUTC(const QDateTime &time) const;
0143     QDateTime utcToLocal(const QDateTime &time) const;
0144 
0145     QString mUid;
0146     QString mBody;
0147     QString mCategories;
0148     QDateTime mCreationDate;
0149     QDateTime mLastModified;
0150     Sensitivity mSensitivity;
0151     QTimeZone mTimeZone;
0152 
0153     // KPilot synchronization stuff
0154     bool mHasPilotSyncId = false;
0155     bool mHasPilotSyncStatus = false;
0156     unsigned long mPilotSyncId;
0157     int mPilotSyncStatus;
0158 };
0159 }