2
Copyright (c) 2000,2001,2004 Cornelius Schumacher <schumacher@kde.org>
3
Copyright (c) 2010 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
4
Copyright (c) 2010 Andras Mantia <andras@kdab.com>
5
Copyright (C) 2010 Casey Link <casey@kdab.com>
7
This library is free software; you can redistribute it and/or modify it
8
under the terms of the GNU Library General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or (at your
10
option) any later version.
12
This library is distributed in the hope that it will be useful, but WITHOUT
13
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
15
License for more details.
17
You should have received a copy of the GNU Library General Public License
18
along with this library; see the file COPYING.LIB. If not, write to the
19
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23
#ifndef INCIDENCEEDITOR_CONFLICTRESOLVER_H
24
#define INCIDENCEEDITOR_CONFLICTRESOLVER_H
26
#include "incidenceeditors-ng_export.h"
27
#include "freebusyitem.h"
33
namespace IncidenceEditorNG {
35
class FreeBusyItemModel;
38
* Takes a list of attendees and event info (e.g., min time start, max time end)
39
* fetches their freebusy information, then identifies conflicts and periods of non-conflict.
41
* It exposes these periods so another class can display them to the user and allow
42
* them to choose a correct time.
45
class INCIDENCEEDITORS_NG_EXPORT ConflictResolver : public QObject
50
* @param parentWidget is passed to Akonadi when fetching free/busy data.
52
explicit ConflictResolver( QWidget *parentWidget, QObject *parent = 0 );
56
* The attendees free busy info will be fetched
57
* and integrated into the resolver.
59
void insertAttendee( const KCalCore::Attendee::Ptr &attendee );
61
void insertAttendee( const FreeBusyItem::Ptr &freebusy );
64
* The attendee will no longer be considered when
68
void removeAttendee( const KCalCore::Attendee::Ptr &attendee );
73
void clearAttendees();
76
* Returns whether the resolver contains the attendee
78
bool containsAttendee( const KCalCore::Attendee::Ptr &attendee );
81
* Constrain the free time slot search to the weekdays
82
* identified by their KCalendarSystem integer representation
83
* Default is Monday - Friday
84
* @param weekdays a 7 bit array indicating the allowed days (bit 0=Monday, value 1=allowed).
85
* @see KCalendarSystem
87
void setAllowedWeekdays( const QBitArray &weekdays );
90
* Constrain the free time slot search to the set participant roles.
91
* Mandatory roles are considered the minimum required to attend
92
* the meeting, so only those attendees with the mandatory roles will
93
* be considered in the search.
94
* Default is all roles are mandatory.
95
* @param roles the set of mandatory participant roles
97
void setMandatoryRoles( const QSet<KCalCore::Attendee::Role> &roles );
100
* Returns a list of date time ranges that conform to the
101
* search constraints.
102
* @see setMandatoryRoles
103
* @see setAllowedWeekdays
105
KCalCore::Period::List availableSlots() const;
108
Finds a free slot in the future which has at least the same size as
111
bool findFreeSlot( const KCalCore::Period &dateTimeRange );
113
QList<FreeBusyItem::Ptr> freeBusyItems() const;
115
FreeBusyItemModel *model() const;
119
* Emitted when the user changes the start and end dateTimes
122
void dateTimesChanged( const KDateTime & newStart, const KDateTime & newEnd );
125
* Emitted when there are conflicts
126
* @param number the number of conflicts
128
void conflictsDetected( int number );
131
* Emitted when the resolver locates new free slots.
133
void freeSlotsAvailable( const KCalCore::Period::List & );
137
* Set the timeframe constraints
139
* These control the timeframe for which conflicts are to be resolved.
141
void setEarliestDate( const QDate &newDate );
142
void setEarliestTime( const QTime &newTime );
143
void setLatestDate( const QDate &newDate );
144
void setLatestTime( const QTime &newTime );
146
void setEarliestDateTime( const KDateTime &newDateTime );
147
void setLatestDateTime( const KDateTime &newDateTime );
149
void freebusyDataChanged();
151
void findAllFreeSlots();
153
void setResolution( int seconds );
157
Checks whether the slot specified by (tryFrom, tryTo) matches the
158
search constraints. If yes, return true. The return value is the
159
number of conflicts that were detected, and (tryFrom, tryTo) contain the next free slot for
160
that participant. In other words, the returned slot does not have to
161
be free for everybody else.
163
int tryDate( KDateTime &tryFrom, KDateTime &tryTo );
166
Checks whether the slot specified by (tryFrom, tryTo) is available
167
for the participant with specified fb. If yes, return true. If
168
not, return false and change (tryFrom, tryTo) to contain the next
169
possible slot for this participant (not necessarily a slot that is
170
available for all participants).
172
bool tryDate( const KCalCore::FreeBusy::Ptr &fb, KDateTime &tryFrom, KDateTime &tryTo );
175
* Checks whether the supplied attendee passes the
176
* current mandatory role constraint.
177
* @return true if the attendee is of one of the mandatory roles, false if not
179
bool matchesRoleConstraint( const KCalCore::Attendee::Ptr &attendee );
181
void calculateConflicts();
183
KCalCore::Period mTimeframeConstraint; //!< the datetime range for outside of which
184
//free slots won't be searched.
185
KCalCore::Period::List mAvailableSlots;
187
QTimer mCalculateTimer; //!< A timer is used control the calculation of conflicts
188
// to prevent the process from being repeated many times
189
// after a series of quick parameter changes.
192
FreeBusyItemModel *mFBModel;
193
QWidget *mParentWidget;
195
QSet<KCalCore::Attendee::Role> mMandatoryRoles;
196
QBitArray mWeekdays; //!< a 7 bit array indicating the allowed days
197
//(bit 0 = Monday, value 1 = allowed).
199
int mSlotResolutionSeconds;