~ubuntu-branches/ubuntu/oneiric/kdepim/oneiric-updates

« back to all changes in this revision

Viewing changes to incidenceeditor-ng/conflictresolver.h

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2011-06-28 19:33:24 UTC
  • mfrom: (0.2.13) (0.1.13 sid)
  • Revision ID: package-import@ubuntu.com-20110628193324-8yvjs8sdv9rdoo6c
Tags: 4:4.7.0-0ubuntu1
* New upstream release
  - update install files
  - add missing kdepim-doc package to control file
  - Fix Vcs lines
  - kontact breaks/replaces korganizer << 4:4.6.80
  - tighten the dependency of kdepim-dev on libkdepim4 to fix lintian error

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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>
 
6
 
 
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.
 
11
 
 
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.
 
16
 
 
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
 
20
  02110-1301, USA.
 
21
*/
 
22
 
 
23
#ifndef INCIDENCEEDITOR_CONFLICTRESOLVER_H
 
24
#define INCIDENCEEDITOR_CONFLICTRESOLVER_H
 
25
 
 
26
#include "incidenceeditors-ng_export.h"
 
27
#include "freebusyitem.h"
 
28
 
 
29
#include <QBitArray>
 
30
#include <QSet>
 
31
#include <QTimer>
 
32
 
 
33
namespace IncidenceEditorNG {
 
34
 
 
35
class FreeBusyItemModel;
 
36
 
 
37
/**
 
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.
 
40
 *
 
41
 * It exposes these periods so another class can display them to the user and allow
 
42
 * them to choose a correct time.
 
43
 * @author Casey Link
 
44
 */
 
45
class INCIDENCEEDITORS_NG_EXPORT ConflictResolver : public QObject
 
46
{
 
47
  Q_OBJECT
 
48
  public:
 
49
    /**
 
50
     * @param parentWidget is passed to Akonadi when fetching free/busy data.
 
51
     */
 
52
    explicit ConflictResolver( QWidget *parentWidget, QObject *parent = 0 );
 
53
 
 
54
    /**
 
55
     *  Add an attendee
 
56
     * The attendees free busy info will be fetched
 
57
     * and integrated into the resolver.
 
58
     */
 
59
    void insertAttendee( const KCalCore::Attendee::Ptr &attendee );
 
60
 
 
61
    void insertAttendee( const FreeBusyItem::Ptr &freebusy );
 
62
    /**
 
63
     * Removes an attendee
 
64
     * The attendee will no longer be considered when
 
65
     * resolving conflicts
 
66
     */
 
67
 
 
68
    void removeAttendee( const KCalCore::Attendee::Ptr &attendee );
 
69
 
 
70
    /**
 
71
     * Clear all attendees
 
72
     */
 
73
    void clearAttendees();
 
74
 
 
75
    /**
 
76
     * Returns whether the resolver contains the attendee
 
77
     */
 
78
    bool containsAttendee( const KCalCore::Attendee::Ptr &attendee );
 
79
 
 
80
    /**
 
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
 
86
     */
 
87
    void setAllowedWeekdays( const QBitArray &weekdays );
 
88
 
 
89
    /**
 
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
 
96
     */
 
97
    void setMandatoryRoles( const QSet<KCalCore::Attendee::Role> &roles );
 
98
 
 
99
    /**
 
100
     * Returns a list of date time ranges that conform to the
 
101
     * search constraints.
 
102
     * @see setMandatoryRoles
 
103
     * @see setAllowedWeekdays
 
104
     */
 
105
    KCalCore::Period::List availableSlots() const;
 
106
 
 
107
    /**
 
108
      Finds a free slot in the future which has at least the same size as
 
109
      the initial slot.
 
110
    */
 
111
    bool findFreeSlot( const KCalCore::Period &dateTimeRange );
 
112
 
 
113
    QList<FreeBusyItem::Ptr> freeBusyItems() const;
 
114
 
 
115
    FreeBusyItemModel *model() const;
 
116
 
 
117
  signals:
 
118
    /**
 
119
     * Emitted when the user changes the start and end dateTimes
 
120
     * for the incidence.
 
121
     */
 
122
    void dateTimesChanged( const KDateTime & newStart, const KDateTime & newEnd );
 
123
 
 
124
    /**
 
125
     * Emitted when there are conflicts
 
126
     * @param number the number of conflicts
 
127
     */
 
128
    void conflictsDetected( int number );
 
129
 
 
130
    /**
 
131
     * Emitted when the resolver locates new free slots.
 
132
     */
 
133
    void freeSlotsAvailable( const KCalCore::Period::List & );
 
134
 
 
135
  public slots:
 
136
    /**
 
137
     * Set the timeframe constraints
 
138
     *
 
139
     * These control the timeframe for which conflicts are to be resolved.
 
140
     */
 
141
    void setEarliestDate( const QDate &newDate );
 
142
    void setEarliestTime( const QTime &newTime );
 
143
    void setLatestDate( const QDate &newDate );
 
144
    void setLatestTime( const QTime &newTime );
 
145
 
 
146
    void setEarliestDateTime( const KDateTime &newDateTime );
 
147
    void setLatestDateTime( const KDateTime &newDateTime );
 
148
 
 
149
    void freebusyDataChanged();
 
150
 
 
151
    void findAllFreeSlots();
 
152
 
 
153
    void setResolution( int seconds );
 
154
 
 
155
  private:
 
156
    /**
 
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.
 
162
    */
 
163
    int tryDate( KDateTime &tryFrom, KDateTime &tryTo );
 
164
 
 
165
    /**
 
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).
 
171
    */
 
172
    bool tryDate( const KCalCore::FreeBusy::Ptr &fb, KDateTime &tryFrom, KDateTime &tryTo );
 
173
 
 
174
    /**
 
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
 
178
     */
 
179
    bool matchesRoleConstraint( const KCalCore::Attendee::Ptr &attendee );
 
180
 
 
181
    void calculateConflicts();
 
182
 
 
183
    KCalCore::Period mTimeframeConstraint; //!< the datetime range for outside of which
 
184
                                           //free slots won't be searched.
 
185
    KCalCore::Period::List mAvailableSlots;
 
186
 
 
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.
 
190
 
 
191
    bool mForceDownload;
 
192
    FreeBusyItemModel *mFBModel;
 
193
    QWidget *mParentWidget;
 
194
 
 
195
    QSet<KCalCore::Attendee::Role> mMandatoryRoles;
 
196
    QBitArray mWeekdays; //!< a 7 bit array indicating the allowed days
 
197
                         //(bit 0 = Monday, value 1 = allowed).
 
198
 
 
199
    int mSlotResolutionSeconds;
 
200
};
 
201
 
 
202
}
 
203
 
 
204
#endif