File indexing completed on 2024-05-12 05:22:12

0001 /*
0002  * This file is part of LibKGAPI library
0003  *
0004  * SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007  */
0008 
0009 #include "calendar.h"
0010 #include "debug.h"
0011 #include "reminder.h"
0012 
0013 using namespace KGAPI2;
0014 
0015 class Q_DECL_HIDDEN Calendar::Private
0016 {
0017 public:
0018     Private() = default;
0019     Private(const Private &other) = default;
0020 
0021     QString uid;
0022     QString title;
0023     QString details;
0024     QString timezone;
0025     QString location;
0026     bool editable = false;
0027     QColor backgroundColor;
0028     QColor foregroundColor;
0029 
0030     RemindersList reminders;
0031 };
0032 
0033 Calendar::Calendar()
0034     : Object()
0035     , d(new Private)
0036 {
0037 }
0038 
0039 Calendar::Calendar(const Calendar &other)
0040     : Object(other)
0041     , d(new Private(*(other.d.get())))
0042 {
0043 }
0044 
0045 Calendar::~Calendar() = default;
0046 
0047 bool Calendar::operator==(const Calendar &other) const
0048 {
0049     if (d->uid != other.d->uid) {
0050         qCDebug(KGAPIDebug) << "UIDs don't match";
0051         return false;
0052     }
0053     if (d->title != other.d->title) {
0054         qCDebug(KGAPIDebug) << "Titles don't match";
0055         return false;
0056     }
0057     if (d->details != other.d->details) {
0058         qCDebug(KGAPIDebug) << "Details don't match";
0059         return false;
0060     }
0061     if (d->timezone != other.d->timezone) {
0062         qCDebug(KGAPIDebug) << "Timezones don't match";
0063         return false;
0064     }
0065     if (d->location != other.d->location) {
0066         qCDebug(KGAPIDebug) << "Locations don't match";
0067         return false;
0068     }
0069     if (d->editable != other.d->editable) {
0070         qCDebug(KGAPIDebug) << "Editable doesn't match";
0071         return false;
0072     }
0073     if (d->backgroundColor != other.d->backgroundColor) {
0074         qCDebug(KGAPIDebug) << "BackgroundColors don't match";
0075         return false;
0076     }
0077     if (d->foregroundColor != other.d->foregroundColor) {
0078         qCDebug(KGAPIDebug) << "ForegroundColors don't match";
0079         return false;
0080     }
0081 
0082     for (const auto &reminder : std::as_const(d->reminders)) {
0083         if (std::find_if(other.d->reminders.cbegin(),
0084                          other.d->reminders.cend(),
0085                          [reminder](const ReminderPtr &otherReminder) {
0086                              return *reminder == *otherReminder;
0087                          })
0088             == other.d->reminders.cend()) {
0089             qCDebug(KGAPIDebug) << "Reminders don't match";
0090             return false;
0091         }
0092     }
0093 
0094     return true;
0095 }
0096 
0097 void Calendar::setUid(const QString &uid)
0098 {
0099     d->uid = uid;
0100 }
0101 
0102 QString Calendar::uid() const
0103 {
0104     return d->uid;
0105 }
0106 
0107 QString Calendar::title() const
0108 {
0109     return d->title;
0110 }
0111 
0112 void Calendar::setTitle(const QString &title)
0113 {
0114     d->title = title;
0115 }
0116 
0117 QString Calendar::details() const
0118 {
0119     return d->details;
0120 }
0121 
0122 void Calendar::setDetails(const QString &details)
0123 {
0124     d->details = details;
0125 }
0126 
0127 QString Calendar::location() const
0128 {
0129     return d->location;
0130 }
0131 
0132 void Calendar::setLocation(const QString &location)
0133 {
0134     d->location = location;
0135 }
0136 
0137 QString Calendar::timezone() const
0138 {
0139     return d->timezone;
0140 }
0141 
0142 void Calendar::setTimezone(const QString &timezone)
0143 {
0144     d->timezone = timezone;
0145 }
0146 
0147 bool Calendar::editable() const
0148 {
0149     return d->editable;
0150 }
0151 
0152 void Calendar::setEditable(const bool editable)
0153 {
0154     d->editable = editable;
0155 }
0156 
0157 void Calendar::setDefaultReminders(const RemindersList &reminders)
0158 {
0159     d->reminders = reminders;
0160 }
0161 
0162 void Calendar::addDefaultReminer(const ReminderPtr &reminder)
0163 {
0164     d->reminders.append(reminder);
0165 }
0166 
0167 RemindersList Calendar::defaultReminders() const
0168 {
0169     return d->reminders;
0170 }
0171 
0172 QColor Calendar::backgroundColor() const
0173 {
0174     return d->backgroundColor;
0175 }
0176 
0177 void Calendar::setBackgroundColor(const QColor &color)
0178 {
0179     d->backgroundColor = color;
0180 }
0181 
0182 QColor Calendar::foregroundColor() const
0183 {
0184     return d->foregroundColor;
0185 }
0186 
0187 void Calendar::setForegroundColor(const QColor &color)
0188 {
0189     d->foregroundColor = color;
0190 }