1 /*
2  * SPDX-FileCopyrightText: 2014 Kevin Ottens <ervin@kde.org>
3  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
4  */
5 
6 
7 
8 #ifndef DOMAIN_TASK_H
9 #define DOMAIN_TASK_H
10 
11 #include <QDate>
12 #include <QMetaType>
13 #include <QSharedPointer>
14 #include <QString>
15 #include <QUrl>
16 
17 namespace Domain {
18 
19 class Task : public QObject
20 {
21     Q_OBJECT
22     Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
23     Q_PROPERTY(QString title READ title WRITE setTitle NOTIFY titleChanged)
24     Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged)
25     Q_PROPERTY(bool done READ isDone WRITE setDone NOTIFY doneChanged)
26     Q_PROPERTY(QDate startDate READ startDate WRITE setStartDate NOTIFY startDateChanged)
27     Q_PROPERTY(QDate dueDate READ dueDate WRITE setDueDate NOTIFY dueDateChanged)
28     Q_PROPERTY(Domain::Task::Recurrence recurrence READ recurrence WRITE setRecurrence NOTIFY recurrenceChanged)
29     Q_PROPERTY(Domain::Task::Attachments attachements READ attachments WRITE setAttachments NOTIFY attachmentsChanged)
30 public:
31     typedef QSharedPointer<Task> Ptr;
32     typedef QList<Task::Ptr> List;
33 
34     enum Recurrence {
35         NoRecurrence = 0,
36         RecursDaily,
37         RecursWeekly,
38         RecursMonthly, // for now only monthly on the same day (say 11th day of the month)
39         RecursYearly,
40     };
Q_ENUM(Recurrence)41     Q_ENUM(Recurrence)
42 
43     class Attachment
44     {
45     public:
46         Attachment();
47         explicit Attachment(const QByteArray &data);
48         explicit Attachment(const QUrl &uri);
49         Attachment(const Attachment &other);
50         ~Attachment();
51 
52         Attachment &operator=(const Attachment &other);
53         bool operator==(const Attachment &other) const;
54 
55         bool isValid() const;
56         bool isUri() const;
57 
58         QUrl uri() const;
59         void setUri(const QUrl &uri);
60 
61         QByteArray data() const;
62         void setData(const QByteArray &data);
63 
64         QString label() const;
65         void setLabel(const QString &label);
66 
67         QString mimeType() const;
68         void setMimeType(const QString &mimeType);
69 
70         QString iconName() const;
71         void setIconName(const QString &iconName);
72 
73     private:
74         QUrl m_uri;
75         QByteArray m_data;
76         QString m_label;
77         QString m_mimeType;
78         QString m_iconName;
79     };
80 
81     typedef QList<Attachment> Attachments;
82 
83     explicit Task(QObject *parent = nullptr);
84     virtual ~Task();
85 
86     QString text() const;
87     QString title() const;
88     bool isRunning() const;
89     bool isDone() const;
90     QDate startDate() const;
91     QDate dueDate() const;
92     QDate doneDate() const;
93     Recurrence recurrence() const;
94     Attachments attachments() const;
95 
96 public slots:
97     void setText(const QString &text);
98     void setTitle(const QString &title);
99     void setRunning(bool running);
100     void setDone(bool done);
101     void setDoneDate(const QDate &doneDate);
102     void setStartDate(const QDate &startDate);
103     void setDueDate(const QDate &dueDate);
104     void setRecurrence(Domain::Task::Recurrence recurrence);
105     void setAttachments(const Domain::Task::Attachments &attachments);
106 
107 signals:
108     void textChanged(const QString &text);
109     void titleChanged(const QString &title);
110     void runningChanged(bool isRunning);
111     void doneChanged(bool isDone);
112     void doneDateChanged(const QDate &doneDate);
113     void startDateChanged(const QDate &startDate);
114     void dueDateChanged(const QDate &dueDate);
115     void recurrenceChanged(Domain::Task::Recurrence recurrence);
116     void attachmentsChanged(const Domain::Task::Attachments &attachments);
117 
118 private:
119     QString m_text;
120     QString m_title;
121     bool m_running;
122     bool m_done;
123     QDate m_startDate;
124     QDate m_dueDate;
125     QDate m_doneDate;
126     Recurrence m_recurrence;
127     Attachments m_attachments;
128 };
129 
130 }
131 
132 Q_DECLARE_METATYPE(Domain::Task::Ptr)
133 Q_DECLARE_METATYPE(Domain::Task::List)
134 Q_DECLARE_METATYPE(Domain::Task::Attachment)
135 Q_DECLARE_METATYPE(Domain::Task::Attachments)
136 
137 #endif // DOMAIN_TASK_H
138