-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
schedulingdialog.cpp
240 lines (201 loc) · 8.57 KB
/
schedulingdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
Copyright (C) 2010 Casey Link <unnamedrambler@gmail.com>
Copyright (C) 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "schedulingdialog.h"
#include "conflictresolver.h"
#include "freeperiodmodel.h"
#ifndef KDEPIM_MOBILE_UI
#include "visualfreebusywidget.h"
#endif
#include <KCalUtils/Stringify>
#include <KCalendarSystem>
using namespace IncidenceEditorNG;
SchedulingDialog::SchedulingDialog( const QDate &startDate, const QTime &startTime, int duration,
ConflictResolver *resolver, QWidget *parent )
: KDialog( parent ), mResolver( resolver ), mPeriodModel( new FreePeriodModel( this ) )
{
QWidget *w = new QWidget( this );
setupUi( w );
setMainWidget( w );
fillCombos();
Q_ASSERT( duration > 0 );
mDuration = duration;
#ifndef KDEPIM_MOBILE_UI
mVisualWidget = new VisualFreeBusyWidget( resolver->model(), 8, this );
QVBoxLayout *ganttlayout = new QVBoxLayout( mGanttTab );
mGanttTab->setLayout( ganttlayout );
ganttlayout->addWidget( mVisualWidget );
#endif
connect( mStartDate, SIGNAL(dateEdited(QDate)),
mResolver, SLOT(setEarliestDate(QDate)) );
connect( mStartTime, SIGNAL(timeEdited(QTime)),
mResolver, SLOT(setEarliestTime(QTime)) );
connect( mEndDate, SIGNAL(dateEdited(QDate)),
mResolver, SLOT(setLatestDate(QDate)) );
connect( mEndTime, SIGNAL(timeEdited(QTime)),
mResolver, SLOT(setLatestTime(QTime)) );
connect( mStartDate, SIGNAL(dateEdited(QDate)),
this, SLOT(slotStartDateChanged(QDate)) );
connect( mWeekdayCombo, SIGNAL(checkedItemsChanged(QStringList)),
SLOT(slotWeekdaysChanged()) );
connect( mWeekdayCombo, SIGNAL(checkedItemsChanged(QStringList)),
SLOT(slotMandatoryRolesChanged()) );
connect( mResolver, SIGNAL(freeSlotsAvailable(KCalCore::Period::List)),
mPeriodModel, SLOT(slotNewFreePeriods(KCalCore::Period::List)) );
connect( mMoveBeginTimeEdit, SIGNAL(timeEdited(QTime)),
this, SLOT(slotSetEndTimeLabel(QTime)) );
mTableView->setModel( mPeriodModel );
connect( mTableView->selectionModel(),
SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
this,
SLOT(slotRowSelectionChanged(QModelIndex,QModelIndex)) );
mStartDate->setDate( startDate );
mEndDate->setDate( mStartDate->date().addDays( 7 ) );
mStartTime->setTime( startTime );
mEndTime->setTime( startTime );
mResolver->setEarliestDate( mStartDate->date() );
mResolver->setEarliestTime( mStartTime->time() );
mResolver->setLatestDate( mEndDate->date() );
mResolver->setLatestTime( mEndTime->time() );
mMoveApptGroupBox->hide();
}
SchedulingDialog::~SchedulingDialog()
{
}
void SchedulingDialog::slotUpdateIncidenceStartEnd( const KDateTime &startDateTime,
const KDateTime &endDateTime )
{
#ifdef KDEPIM_MOBILE_UI
Q_UNUSED( startDateTime );
Q_UNUSED( endDateTime );
#else
mVisualWidget->slotUpdateIncidenceStartEnd( startDateTime, endDateTime );
#endif
}
void SchedulingDialog::fillCombos()
{
// Note: we depend on the following order
#ifdef KDEPIM_MOBILE_UI
mRolesCombo->addItem( DesktopIcon( "meeting-participant", 48 ),
KCalUtils::Stringify::attendeeRole( KCalCore::Attendee::ReqParticipant ) );
mRolesCombo->addItem( DesktopIcon( "meeting-participant-optional", 48 ),
KCalUtils::Stringify::attendeeRole( KCalCore::Attendee::OptParticipant ) );
mRolesCombo->addItem( DesktopIcon( "meeting-observer", 48 ),
KCalUtils::Stringify::attendeeRole( KCalCore::Attendee::NonParticipant ) );
mRolesCombo->addItem( DesktopIcon( "meeting-chair", 48 ),
KCalUtils::Stringify::attendeeRole( KCalCore::Attendee::Chair ) );
#else
mRolesCombo->addItem( SmallIcon( "meeting-participant" ),
KCalUtils::Stringify::attendeeRole( KCalCore::Attendee::ReqParticipant ) );
mRolesCombo->addItem( SmallIcon( "meeting-participant-optional" ),
KCalUtils::Stringify::attendeeRole( KCalCore::Attendee::OptParticipant ) );
mRolesCombo->addItem( SmallIcon( "meeting-observer" ),
KCalUtils::Stringify::attendeeRole( KCalCore::Attendee::NonParticipant ) );
mRolesCombo->addItem( SmallIcon( "meeting-chair" ),
KCalUtils::Stringify::attendeeRole( KCalCore::Attendee::Chair ) );
#endif
mRolesCombo->setWhatsThis( i18nc( "@info:whatsthis",
"Edits the role of the attendee." ) );
mRolesCombo->setItemCheckState( 0, Qt::Checked );
mRolesCombo->setItemCheckState( 1, Qt::Checked );
mRolesCombo->setItemCheckState( 2, Qt::Checked );
mRolesCombo->setItemCheckState( 3, Qt::Checked );
QBitArray days( 7 );
days.setBit( 0 ); //Monday
days.setBit( 1 ); //Tuesday
days.setBit( 2 ); //Wednesday
days.setBit( 3 ); //Thursday
days.setBit( 4 ); //Friday.. surprise!
mWeekdayCombo->setDays( days );
mResolver->setAllowedWeekdays( days );
}
void SchedulingDialog::slotStartDateChanged( const QDate &newDate )
{
QDate oldDate = mStDate;
mStDate = newDate;
if ( newDate.isValid() && oldDate.isValid() ) {
updateWeekDays( oldDate );
}
}
void SchedulingDialog::updateWeekDays( const QDate &oldDate )
{
const int oldStartDayIndex = mWeekdayCombo->weekdayIndex( oldDate );
const int newStartDayIndex = mWeekdayCombo->weekdayIndex( mStDate );
mWeekdayCombo->setItemCheckState( oldStartDayIndex, Qt::Unchecked );
mWeekdayCombo->setItemEnabled( oldStartDayIndex, true );
mWeekdayCombo->setItemCheckState( newStartDayIndex, Qt::Checked );
mWeekdayCombo->setItemEnabled( newStartDayIndex, false );
}
void SchedulingDialog::slotWeekdaysChanged()
{
// notify the resolver
mResolver->setAllowedWeekdays( mWeekdayCombo->days() );
}
void SchedulingDialog::slotMandatoryRolesChanged()
{
QSet<KCalCore::Attendee::Role> roles;
for ( int i = 0; i < mRolesCombo->count(); ++i ) {
if ( mRolesCombo->itemCheckState( i ) == Qt::Checked ) {
roles << KCalCore::Attendee::Role( i );
}
}
mResolver->setMandatoryRoles( roles );
}
void SchedulingDialog::slotRowSelectionChanged( const QModelIndex ¤t,
const QModelIndex &previous )
{
Q_UNUSED( previous );
if ( !current.isValid() ) {
mMoveApptGroupBox->hide();
return;
}
KCalCore::Period period = current.data( FreePeriodModel::PeriodRole ).value<KCalCore::Period>();
const QDate startDate = period.start().date();
const KCalendarSystem *calSys = KGlobal::locale()->calendar();
const int dayOfWeek = calSys->dayOfWeek( startDate );
const QString dayLabel =
ki18nc( "@label Day of week followed by day of the month, then the month. "
"Example: Monday, 12 June",
"%1, %2 %3" ).
subs( calSys->weekDayName( dayOfWeek, KCalendarSystem::LongDayName ) ).
subs( startDate.day() ).
subs( calSys->monthName( startDate ) ).toString();
mMoveDayLabel->setText( dayLabel );
mMoveBeginTimeEdit->setTimeRange( period.start().time(),
period.end().addSecs( -mDuration ).time() );
mMoveBeginTimeEdit->setTime( period.start().time() );
slotSetEndTimeLabel( period.start().time() );
mMoveApptGroupBox->show();
mSelectedDate = startDate;
}
void SchedulingDialog::slotSetEndTimeLabel( const QTime &startTime )
{
const QTime endTime = startTime.addSecs( mDuration );
const QString endTimeLabel =
ki18nc( "@label This is a suffix following a time selecting widget. "
"Example: [timeedit] to 10:00am",
"to %1" ).subs( KGlobal::locale()->formatTime( endTime ) ).toString();
mMoveEndTimeLabel->setText( endTimeLabel );
mSelectedTime = startTime;
}
QDate SchedulingDialog::selectedStartDate() const
{
return mSelectedDate;
}
QTime SchedulingDialog::selectedStartTime() const
{
return mSelectedTime;
}