Incidenceeditor

schedulingdialog.cpp
1/*
2 SPDX-FileCopyrightText: 2010 Casey Link <unnamedrambler@gmail.com>
3 SPDX-FileCopyrightText: 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <info@kdab.net>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "schedulingdialog.h"
9#include "conflictresolver.h"
10#include "visualfreebusywidget.h"
11#include <CalendarSupport/FreePeriodModel>
12#include <KCalUtils/Stringify>
13
14#include <KLocalizedString>
15
16#include <QDialogButtonBox>
17#include <QLocale>
18#include <QPushButton>
19#include <QVBoxLayout>
20
21using namespace IncidenceEditorNG;
22
23SchedulingDialog::SchedulingDialog(QDate startDate, QTime startTime, int duration, ConflictResolver *resolver, QWidget *parent)
24 : QDialog(parent)
25 , mResolver(resolver)
26 , mPeriodModel(new CalendarSupport::FreePeriodModel(this))
27{
28 setWindowTitle(i18nc("@title:window", "Scheduling"));
29 auto mainLayout = new QVBoxLayout(this);
30 auto w = new QWidget(this);
31 setupUi(w);
33 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
34 okButton->setDefault(true);
36 connect(buttonBox, &QDialogButtonBox::accepted, this, &SchedulingDialog::accept);
37 connect(buttonBox, &QDialogButtonBox::rejected, this, &SchedulingDialog::reject);
38
39 mainLayout->addWidget(w);
40 mainLayout->addWidget(buttonBox);
41 fillCombos();
42
43 Q_ASSERT(duration > 0);
44 mDuration = duration;
45
46 mVisualWidget = new VisualFreeBusyWidget(resolver->model(), 8);
47 auto ganttlayout = new QVBoxLayout(mGanttTab);
48
49 mGanttTab->setLayout(ganttlayout);
50 ganttlayout->addWidget(mVisualWidget);
51
53 connect(mStartTime, &KTimeComboBox::timeEdited, mResolver, &ConflictResolver::setEarliestTime);
54 connect(mEndDate, &KDateComboBox::dateEdited, mResolver, &ConflictResolver::setLatestDate);
55 connect(mEndTime, &KTimeComboBox::timeEdited, mResolver, &ConflictResolver::setLatestTime);
56
57 connect(mStartDate, &KDateComboBox::dateEdited, this, &SchedulingDialog::slotStartDateChanged);
58
59 connect(mWeekdayCombo, &IncidenceEditorNG::KWeekdayCheckCombo::checkedItemsChanged, this, &SchedulingDialog::slotWeekdaysChanged);
60 connect(mWeekdayCombo, &IncidenceEditorNG::KWeekdayCheckCombo::checkedItemsChanged, this, &SchedulingDialog::slotMandatoryRolesChanged);
61
62 connect(mResolver, &ConflictResolver::freeSlotsAvailable, mPeriodModel, &CalendarSupport::FreePeriodModel::slotNewFreePeriods);
63 connect(mMoveBeginTimeEdit, &KTimeComboBox::timeEdited, this, &SchedulingDialog::slotSetEndTimeLabel);
64
65 mTableView->setModel(mPeriodModel);
66 connect(mTableView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &SchedulingDialog::slotRowSelectionChanged);
67
68 mStartDate->setDate(startDate);
69 mEndDate->setDate(mStartDate->date().addDays(7));
70 mStartTime->setTime(startTime);
71 mEndTime->setTime(startTime);
72
73 mResolver->setEarliestDate(mStartDate->date());
74 mResolver->setEarliestTime(mStartTime->time());
75 mResolver->setLatestDate(mEndDate->date());
76 mResolver->setLatestTime(mEndTime->time());
77
78 mMoveApptGroupBox->hide();
79}
80
81SchedulingDialog::~SchedulingDialog() = default;
82
83void SchedulingDialog::slotUpdateIncidenceStartEnd(const QDateTime &startDateTime, const QDateTime &endDateTime)
84{
85 mVisualWidget->slotUpdateIncidenceStartEnd(startDateTime, endDateTime);
86}
87
88void SchedulingDialog::fillCombos()
89{
90 // Note: we depend on the following order
91 mRolesCombo->addItem(QIcon::fromTheme(QStringLiteral("meeting-participant")), KCalUtils::Stringify::attendeeRole(KCalendarCore::Attendee::ReqParticipant));
92 mRolesCombo->addItem(QIcon::fromTheme(QStringLiteral("meeting-participant-optional")),
93 KCalUtils::Stringify::attendeeRole(KCalendarCore::Attendee::OptParticipant));
94 mRolesCombo->addItem(QIcon::fromTheme(QStringLiteral("meeting-observer")), KCalUtils::Stringify::attendeeRole(KCalendarCore::Attendee::NonParticipant));
95 mRolesCombo->addItem(QIcon::fromTheme(QStringLiteral("meeting-chair")), KCalUtils::Stringify::attendeeRole(KCalendarCore::Attendee::Chair));
96
97 mRolesCombo->setWhatsThis(i18nc("@info:whatsthis", "Edits the role of the attendee."));
98
99 mRolesCombo->setItemCheckState(0, Qt::Checked);
100 mRolesCombo->setItemCheckState(1, Qt::Checked);
101 mRolesCombo->setItemCheckState(2, Qt::Checked);
102 mRolesCombo->setItemCheckState(3, Qt::Checked);
103
104 QBitArray days(7);
105 days.setBit(0); // Monday
106 days.setBit(1); // Tuesday
107 days.setBit(2); // Wednesday
108 days.setBit(3); // Thursday
109 days.setBit(4); // Friday.. surprise!
110
111 mWeekdayCombo->setDays(days);
112 mResolver->setAllowedWeekdays(days);
113}
114
115void SchedulingDialog::slotStartDateChanged(const QDate &newDate)
116{
117 QDate oldDate = mStDate;
118 mStDate = newDate;
119 if (newDate.isValid() && oldDate.isValid()) {
120 updateWeekDays(oldDate);
121 }
122}
123
124void SchedulingDialog::updateWeekDays(const QDate &oldDate)
125{
126 const int oldStartDayIndex = mWeekdayCombo->weekdayIndex(oldDate);
127 const int newStartDayIndex = mWeekdayCombo->weekdayIndex(mStDate);
128
129 mWeekdayCombo->setItemCheckState(oldStartDayIndex, Qt::Unchecked);
130 mWeekdayCombo->setItemEnabled(oldStartDayIndex, true);
131 mWeekdayCombo->setItemCheckState(newStartDayIndex, Qt::Checked);
132 mWeekdayCombo->setItemEnabled(newStartDayIndex, false);
133}
134
135void SchedulingDialog::slotWeekdaysChanged()
136{
137 // notify the resolver
138 mResolver->setAllowedWeekdays(mWeekdayCombo->days());
139}
140
141void SchedulingDialog::slotMandatoryRolesChanged()
142{
144 for (int i = 0; i < mRolesCombo->count(); ++i) {
145 if (mRolesCombo->itemCheckState(i) == Qt::Checked) {
147 }
148 }
149 mResolver->setMandatoryRoles(roles);
150}
151
152void SchedulingDialog::slotRowSelectionChanged(const QModelIndex &current, const QModelIndex &previous)
153{
154 Q_UNUSED(previous)
155 if (!current.isValid()) {
156 mMoveApptGroupBox->hide();
157 return;
158 }
159 auto period = current.data(CalendarSupport::FreePeriodModel::PeriodRole).value<KCalendarCore::Period>();
160 const QDate startDate = period.start().date();
161
162 const int dayOfWeek = startDate.dayOfWeek();
163 const QString dayLabel = ki18nc(
164 "@label Day of week followed by day of the month, then the month. "
165 "Example: Monday, 12 June",
166 "%1, %2 %3")
167 .subs(QLocale::system().dayName(dayOfWeek, QLocale::LongFormat))
168 .subs(startDate.day())
169 .subs(QLocale::system().monthName(startDate.month(), QLocale::LongFormat))
170 .toString();
171
172 mMoveDayLabel->setText(dayLabel);
173 mMoveBeginTimeEdit->setTimeRange(period.start().time(), period.end().addSecs(-mDuration).time());
174 mMoveBeginTimeEdit->setTime(period.start().time());
175 slotSetEndTimeLabel(period.start().time());
176 mMoveApptGroupBox->show();
177
178 mSelectedDate = startDate;
179}
180
181void SchedulingDialog::slotSetEndTimeLabel(const QTime &startTime)
182{
183 const QTime endTime = startTime.addSecs(mDuration);
184 const QString endTimeLabel = ki18nc(
185 "@label This is a suffix following a time selecting widget. "
186 "Example: [timeedit] to 10:00am",
187 "to %1")
188 .subs(QLocale::system().toString(endTime))
189 .toString();
190
191 mMoveEndTimeLabel->setText(endTimeLabel);
192 mSelectedTime = startTime;
193}
194
195QDate SchedulingDialog::selectedStartDate() const
196{
197 return mSelectedDate;
198}
199
200QTime SchedulingDialog::selectedStartTime() const
201{
202 return mSelectedTime;
203}
204
205#include "moc_schedulingdialog.cpp"
Takes a list of attendees and event info (e.g., min time start, max time end) fetches their freebusy ...
void setEarliestDate(QDate newDate)
Set the timeframe constraints.
void freeSlotsAvailable(const KCalendarCore::Period::List &)
Emitted when the resolver locates new free slots.
void setAllowedWeekdays(const QBitArray &weekdays)
Constrain the free time slot search to the weekdays identified by their KCalendarSystem integer repre...
void setMandatoryRoles(const QSet< KCalendarCore::Attendee::Role > &roles)
Constrain the free time slot search to the set participant roles.
void dateEdited(const QDate &date)
QString toString() const
KLocalizedString subs(const KLocalizedString &a, int fieldWidth=0, QChar fillChar=QLatin1Char(' ')) const
void checkedItemsChanged(const QStringList &items)
void timeEdited(const QTime &time)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
KLocalizedString KI18N_EXPORT ki18nc(const char *context, const char *text)
char * toString(const EngineQuery &query)
void setShortcut(const QKeySequence &key)
int dayOfWeek() const const
bool isValid(int year, int month, int day)
QIcon fromTheme(const QString &name)
void currentRowChanged(const QModelIndex &current, const QModelIndex &previous)
QLocale system()
QVariant data(int role) const const
bool isValid() const const
void setDefault(bool)
Key_Return
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QTime addSecs(int s) const const
T value() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:15 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.