File indexing completed on 2024-11-24 04:44:16

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 "incidence.h"
0013 
0014 #include <KCalendarCore/Incidence>
0015 #include <KCalendarCore/Todo>
0016 
0017 class QDomElement;
0018 
0019 namespace KCal
0020 {
0021 class ResourceKolab;
0022 }
0023 
0024 namespace KolabV2
0025 {
0026 /**
0027  * This class represents a task, and knows how to load/save it
0028  * from/to XML, and from/to a KCalendarCore::Todo.
0029  * The instances of this class are temporary, only used to convert
0030  * one to the other.
0031  */
0032 class Task : public Incidence
0033 {
0034 public:
0035     /// Use this to parse an xml string to a task entry
0036     /// The caller is responsible for deleting the returned task
0037     static KCalendarCore::Todo::Ptr fromXml(const QDomDocument &xmlDoc, const QString &tz /*, KCalendarCore::ResourceKolab *res = 0,
0038                                 const QString& subResource = QString(), quint32 sernum = 0 */);
0039 
0040     /// Use this to get an xml string describing this task entry
0041     static QString taskToXML(const KCalendarCore::Todo::Ptr &, const QString &tz);
0042 
0043     explicit Task(/*KCalendarCore::ResourceKolab *res, const QString& subResource, quint32 sernum,*/
0044                   const QString &tz,
0045                   const KCalendarCore::Todo::Ptr &todo = KCalendarCore::Todo::Ptr());
0046     ~Task() override;
0047 
0048     QString type() const override
0049     {
0050         return QStringLiteral("Task");
0051     }
0052 
0053     void saveTo(const KCalendarCore::Todo::Ptr &todo);
0054 
0055     virtual void setPercentCompleted(int percent);
0056     virtual int percentCompleted() const;
0057 
0058     virtual void setStatus(KCalendarCore::Incidence::Status status);
0059     virtual KCalendarCore::Incidence::Status status() const;
0060 
0061     virtual void setParent(const QString &parentUid);
0062     virtual QString parent() const;
0063 
0064     virtual void setHasStartDate(bool);
0065     virtual bool hasStartDate() const;
0066 
0067     virtual void setDueDate(const QDateTime &date);
0068     virtual void setDueDate(const QString &date);
0069     virtual void setDueDate(const QDate &date);
0070     virtual QDateTime dueDate() const;
0071     virtual bool hasDueDate() const;
0072 
0073     virtual void setCompletedDate(const QDateTime &date);
0074     virtual QDateTime completedDate() const;
0075     virtual bool hasCompletedDate() const;
0076 
0077     // Load the attributes of this class
0078     bool loadAttribute(QDomElement &) override;
0079 
0080     // Save the attributes of this class
0081     bool saveAttributes(QDomElement &) const override;
0082 
0083     // Load this task by reading the XML file
0084     bool loadXML(const QDomDocument &xml) override;
0085 
0086     // Serialize this task to an XML string
0087     QString saveXML() const override;
0088 
0089 protected:
0090     // Read all known fields from this ical todo
0091     void setFields(const KCalendarCore::Todo::Ptr &);
0092 
0093     int mPercentCompleted;
0094     KCalendarCore::Incidence::Status mStatus;
0095     QString mParent;
0096 
0097     bool mHasStartDate = false;
0098 
0099     bool mHasDueDate = false;
0100     QDateTime mDueDate;
0101 
0102     bool mHasCompletedDate = false;
0103     QDateTime mCompletedDate;
0104 };
0105 }