File indexing completed on 2024-11-24 04:44:10
0001 /* 0002 * SPDX-FileCopyrightText: 2012 Christian Mollekopf <mollekopf@kolabsys.com> 0003 * 0004 * SPDX-License-Identifier: LGPL-3.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "kolab_export.h" 0010 0011 #include <KCalendarCore/Event> 0012 #include <KCalendarCore/MemoryCalendar> 0013 #include <kolabevent.h> 0014 #include <memory> 0015 0016 namespace Kolab 0017 { 0018 namespace Calendaring 0019 { 0020 /** 0021 * Returns true if the events conflict (overlap) 0022 * Start and end date/time is inclusive. 0023 * 0024 * Does not take recurrences into account. 0025 */ 0026 KOLAB_EXPORT bool conflicts(const Kolab::Event &, const Kolab::Event &); 0027 0028 /** 0029 * Returns sets of the events which are directly conflicting with each other. 0030 * The same event may appear in multiple sets. 0031 * Non-conflicting events are not returned. 0032 * conflicts() is used for conflict detection. 0033 * 0034 * If the second list is given, each event from the first list is additionally checked against each event of the second set. 0035 * Conflicts within the second list are not detected. 0036 * 0037 * The checked event from the first list comes always first in the returned set. 0038 */ 0039 KOLAB_EXPORT std::vector<std::vector<Kolab::Event>> getConflictingSets(const std::vector<Kolab::Event> &, 0040 const std::vector<Kolab::Event> & = std::vector<Kolab::Event>()); 0041 0042 /** 0043 * Returns the dates in which the event recurs within the specified timespan. 0044 */ 0045 KOLAB_EXPORT std::vector<Kolab::cDateTime> timeInInterval(const Kolab::Event &, const Kolab::cDateTime &start, const Kolab::cDateTime &end); 0046 0047 /** 0048 * In-Memory Calendar Cache 0049 */ 0050 class KOLAB_EXPORT Calendar 0051 { 0052 public: 0053 explicit Calendar(); 0054 /** 0055 * Add an event to the in-memory calendar. 0056 */ 0057 void addEvent(const Kolab::Event &); 0058 /** 0059 * Returns all events within the specified interval (start and end inclusive). 0060 * 0061 * @param sort controls if the resulting event set is sorted in ascending order according to the start date 0062 */ 0063 std::vector<Kolab::Event> getEvents(const Kolab::cDateTime &start, const Kolab::cDateTime &end, bool sort); 0064 0065 private: 0066 Calendar(const Calendar &) = delete; 0067 void operator=(const Calendar &) = delete; 0068 std::unique_ptr<KCalendarCore::MemoryCalendar> mCalendar; 0069 }; 0070 } // Namespace 0071 } // Namespace