File indexing completed on 2024-11-17 04:54:27

0001 /*
0002  * SPDX-FileCopyrightText: 2014 Kevin Ottens <ervin@kde.org>
0003  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004  */
0005 
0006 
0007 #include "task.h"
0008 
0009 #include "utils/datetime.h"
0010 
0011 using namespace Domain;
0012 
0013 Task::Task(QObject *parent)
0014     : QObject(parent),
0015       m_running(false),
0016       m_done(false),
0017       m_recurrence(NoRecurrence)
0018 {
0019 }
0020 
0021 Task::~Task()
0022 {
0023 }
0024 
0025 QString Task::text() const
0026 {
0027     return m_text;
0028 }
0029 
0030 QString Task::title() const
0031 {
0032     return m_title;
0033 }
0034 
0035 bool Task::isRunning() const
0036 {
0037     return m_running;
0038 }
0039 
0040 bool Task::isDone() const
0041 {
0042     return m_done;
0043 }
0044 
0045 void Task::setDone(bool done)
0046 {
0047     if (m_done == done)
0048         return;
0049 
0050     const QDate doneDate = done ? Utils::DateTime::currentDate() : QDate();
0051 
0052     m_done = done;
0053     m_doneDate = doneDate;
0054 
0055     emit doneChanged(done);
0056     emit doneDateChanged(doneDate);
0057 }
0058 
0059 void Task::setDoneDate(const QDate &doneDate)
0060 {
0061     if (m_doneDate == doneDate)
0062         return;
0063 
0064     m_doneDate = doneDate;
0065     emit doneDateChanged(doneDate);
0066 }
0067 
0068 QDate Task::startDate() const
0069 {
0070     return m_startDate;
0071 }
0072 
0073 void Task::setStartDate(const QDate &startDate)
0074 {
0075     if (m_startDate == startDate)
0076         return;
0077 
0078     m_startDate = startDate;
0079     emit startDateChanged(startDate);
0080 }
0081 
0082 QDate Task::dueDate() const
0083 {
0084     return m_dueDate;
0085 }
0086 
0087 QDate Task::doneDate() const
0088 {
0089     return m_doneDate;
0090 }
0091 
0092 Task::Recurrence Task::recurrence() const
0093 {
0094     return m_recurrence;
0095 }
0096 
0097 Task::Attachments Task::attachments() const
0098 {
0099     return m_attachments;
0100 }
0101 
0102 void Task::setText(const QString &text)
0103 {
0104     if (m_text == text)
0105         return;
0106 
0107     m_text = text;
0108     emit textChanged(text);
0109 }
0110 
0111 void Task::setTitle(const QString &title)
0112 {
0113     if (m_title == title)
0114         return;
0115 
0116     m_title = title;
0117     emit titleChanged(title);
0118 }
0119 
0120 void Task::setRunning(bool running)
0121 {
0122     if (m_running == running)
0123         return;
0124     m_running = running;
0125     emit runningChanged(running);
0126 }
0127 
0128 void Task::setDueDate(const QDate &dueDate)
0129 {
0130     if (m_dueDate == dueDate)
0131         return;
0132 
0133     m_dueDate = dueDate;
0134     emit dueDateChanged(dueDate);
0135 }
0136 
0137 void Task::setRecurrence(Task::Recurrence recurrence)
0138 {
0139     if (m_recurrence == recurrence)
0140         return;
0141 
0142     m_recurrence = recurrence;
0143     emit recurrenceChanged(recurrence);
0144 }
0145 
0146 void Task::setAttachments(const Task::Attachments &attachments)
0147 {
0148     if (m_attachments == attachments)
0149         return;
0150 
0151     m_attachments = attachments;
0152     emit attachmentsChanged(attachments);
0153 }
0154 
0155 
0156 Task::Attachment::Attachment()
0157 {
0158 }
0159 
0160 Task::Attachment::Attachment(const QByteArray &data)
0161 {
0162     setData(data);
0163 }
0164 
0165 Task::Attachment::Attachment(const QUrl &uri)
0166 {
0167     setUri(uri);
0168 }
0169 
0170 Task::Attachment::Attachment(const Task::Attachment &other)
0171     : m_uri(other.m_uri),
0172       m_data(other.m_data),
0173       m_label(other.m_label),
0174       m_mimeType(other.m_mimeType),
0175       m_iconName(other.m_iconName)
0176 {
0177 }
0178 
0179 Task::Attachment::~Attachment()
0180 {
0181 }
0182 
0183 Task::Attachment &Task::Attachment::operator=(const Task::Attachment &other)
0184 {
0185     Attachment copy(other);
0186     std::swap(m_uri, copy.m_uri);
0187     std::swap(m_data, copy.m_data);
0188     std::swap(m_label, copy.m_label);
0189     std::swap(m_mimeType, copy.m_mimeType);
0190     std::swap(m_iconName, copy.m_iconName);
0191     return *this;
0192 }
0193 
0194 bool Task::Attachment::operator==(const Task::Attachment &other) const
0195 {
0196     return m_uri == other.m_uri
0197         && m_data == other.m_data
0198         && m_label == other.m_label
0199         && m_mimeType == other.m_mimeType
0200             && m_iconName == other.m_iconName;
0201 }
0202 
0203 bool Task::Attachment::isValid() const
0204 {
0205     return m_uri.isValid() || !m_data.isEmpty();
0206 }
0207 
0208 bool Task::Attachment::isUri() const
0209 {
0210     return m_uri.isValid();
0211 }
0212 
0213 QUrl Task::Attachment::uri() const
0214 {
0215     return m_uri;
0216 }
0217 
0218 void Task::Attachment::setUri(const QUrl &uri)
0219 {
0220     m_uri = uri;
0221     m_data.clear();
0222 }
0223 
0224 QByteArray Task::Attachment::data() const
0225 {
0226     return m_data;
0227 }
0228 
0229 void Task::Attachment::setData(const QByteArray &data)
0230 {
0231     m_data = data;
0232     m_uri.clear();
0233 }
0234 
0235 QString Task::Attachment::label() const
0236 {
0237     return m_label;
0238 }
0239 
0240 void Task::Attachment::setLabel(const QString &label)
0241 {
0242     m_label = label;
0243 }
0244 
0245 QString Task::Attachment::mimeType() const
0246 {
0247     return m_mimeType;
0248 }
0249 
0250 void Task::Attachment::setMimeType(const QString &mimeType)
0251 {
0252     m_mimeType = mimeType;
0253 }
0254 
0255 QString Task::Attachment::iconName() const
0256 {
0257     return m_iconName;
0258 }
0259 
0260 void Task::Attachment::setIconName(const QString &iconName)
0261 {
0262     m_iconName = iconName;
0263 }
0264 
0265 #include "moc_task.cpp"