Incidenceeditor

conflictresolver.h
1/*
2 SPDX-FileCopyrightText: 2000, 2001, 2004 Cornelius Schumacher <schumacher@kde.org>
3 SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
4 SPDX-FileCopyrightText: 2010 Andras Mantia <andras@kdab.com>
5 SPDX-FileCopyrightText: 2010 Casey Link <casey@kdab.com>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#pragma once
11
12#include "incidenceeditor_export.h"
13#include <CalendarSupport/FreeBusyItem>
14
15#include <QBitArray>
16#include <QSet>
17#include <QTimer>
18
19namespace CalendarSupport
20{
21class FreeBusyItemModel;
22}
23
24namespace IncidenceEditorNG
25{
26/**
27 * Takes a list of attendees and event info (e.g., min time start, max time end)
28 * fetches their freebusy information, then identifies conflicts and periods of non-conflict.
29 *
30 * It exposes these periods so another class can display them to the user and allow
31 * them to choose a correct time.
32 * @author Casey Link
33 */
34class INCIDENCEEDITOR_EXPORT ConflictResolver : public QObject
35{
36 Q_OBJECT
37public:
38 /**
39 * @param parentWidget is passed to Akonadi when fetching free/busy data.
40 */
41 explicit ConflictResolver(QWidget *parentWidget, QObject *parent = nullptr);
42
43 /**
44 * Add an attendee
45 * The attendees free busy info will be fetched
46 * and integrated into the resolver.
47 */
48 void insertAttendee(const KCalendarCore::Attendee &attendee);
49
50 void insertAttendee(const CalendarSupport::FreeBusyItem::Ptr &freebusy);
51 /**
52 * Removes an attendee
53 * The attendee will no longer be considered when
54 * resolving conflicts
55 */
56
57 void removeAttendee(const KCalendarCore::Attendee &attendee);
58
59 /**
60 * Clear all attendees
61 */
62 void clearAttendees();
63
64 /**
65 * Returns whether the resolver contains the attendee
66 */
67 [[nodiscard]] bool containsAttendee(const KCalendarCore::Attendee &attendee);
68
69 /**
70 * Constrain the free time slot search to the weekdays
71 * identified by their KCalendarSystem integer representation
72 * Default is Monday - Friday
73 * @param weekdays a 7 bit array indicating the allowed days (bit 0=Monday, value 1=allowed).
74 * @see KCalendarSystem
75 */
76 void setAllowedWeekdays(const QBitArray &weekdays);
77
78 /**
79 * Constrain the free time slot search to the set participant roles.
80 * Mandatory roles are considered the minimum required to attend
81 * the meeting, so only those attendees with the mandatory roles will
82 * be considered in the search.
83 * Default is all roles are mandatory.
84 * @param roles the set of mandatory participant roles
85 */
86 void setMandatoryRoles(const QSet<KCalendarCore::Attendee::Role> &roles);
87
88 /**
89 * Returns a list of date time ranges that conform to the
90 * search constraints.
91 * @see setMandatoryRoles
92 * @see setAllowedWeekdays
93 */
94 [[nodiscard]] KCalendarCore::Period::List availableSlots() const;
95
96 /**
97 Finds a free slot in the future which has at least the same size as
98 the initial slot.
99 */
100 [[nodiscard]] bool findFreeSlot(const KCalendarCore::Period &dateTimeRange);
101
102 CalendarSupport::FreeBusyItemModel *model() const;
103
104Q_SIGNALS:
105 /**
106 * Emitted when the user changes the start and end dateTimes
107 * for the incidence.
108 */
109 void dateTimesChanged(const QDateTime &newStart, const QDateTime &newEnd);
110
111 /**
112 * Emitted when there are conflicts
113 * @param number the number of conflicts
114 */
115 void conflictsDetected(int number);
116
117 /**
118 * Emitted when the resolver locates new free slots.
119 */
121
122public Q_SLOTS:
123 /**
124 * Set the timeframe constraints
125 *
126 * These control the timeframe for which conflicts are to be resolved.
127 */
128 void setEarliestDate(QDate newDate);
129 void setEarliestTime(QTime newTime);
130 void setLatestDate(QDate newDate);
131 void setLatestTime(QTime newTime);
132
133 void setEarliestDateTime(const QDateTime &newDateTime);
134 void setLatestDateTime(const QDateTime &newDateTime);
135
136 void freebusyDataChanged();
137
138 void findAllFreeSlots();
139
140 void setResolution(int seconds);
141
142private:
143 /**
144 Checks whether the slot specified by (tryFrom, tryTo) matches the
145 search constraints. If yes, return true. The return value is the
146 number of conflicts that were detected, and (tryFrom, tryTo) contain the next free slot for
147 that participant. In other words, the returned slot does not have to
148 be free for everybody else.
149 */
150 INCIDENCEEDITOR_NO_EXPORT int tryDate(QDateTime &tryFrom, QDateTime &tryTo);
151
152 /**
153 Checks whether the slot specified by (tryFrom, tryTo) is available
154 for the participant with specified fb. If yes, return true. If
155 not, return false and change (tryFrom, tryTo) to contain the next
156 possible slot for this participant (not necessarily a slot that is
157 available for all participants).
158 */
159 INCIDENCEEDITOR_NO_EXPORT bool tryDate(const KCalendarCore::FreeBusy::Ptr &fb, QDateTime &tryFrom, QDateTime &tryTo);
160
161 /**
162 * Checks whether the supplied attendee passes the
163 * current mandatory role constraint.
164 * @return true if the attendee is of one of the mandatory roles, false if not
165 */
166 INCIDENCEEDITOR_NO_EXPORT bool matchesRoleConstraint(const KCalendarCore::Attendee &attendee);
167
168 INCIDENCEEDITOR_NO_EXPORT void calculateConflicts();
169
170 KCalendarCore::Period mTimeframeConstraint; //!< the datetime range for outside of which
171 // free slots won't be searched.
172 KCalendarCore::Period::List mAvailableSlots;
173
174 QTimer mCalculateTimer; //!< A timer is used control the calculation of conflicts
175 // to prevent the process from being repeated many times
176 // after a series of quick parameter changes.
177
178 CalendarSupport::FreeBusyItemModel *const mFBModel;
179 QWidget *mParentWidget = nullptr;
180
182 QBitArray mWeekdays; //!< a 7 bit array indicating the allowed days
183 //(bit 0 = Monday, value 1 = allowed).
184
185 int mSlotResolutionSeconds;
186};
187}
Takes a list of attendees and event info (e.g., min time start, max time end) fetches their freebusy ...
void freeSlotsAvailable(const KCalendarCore::Period::List &)
Emitted when the resolver locates new free slots.
void dateTimesChanged(const QDateTime &newStart, const QDateTime &newEnd)
Emitted when the user changes the start and end dateTimes for the incidence.
void conflictsDetected(int number)
Emitted when there are conflicts.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:16:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.