Incidenceeditor

individualmaildialog.cpp
1/*
2 * SPDX-FileCopyrightText: 2014 Sandro Knauß <knauss@kolabsys.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later WITH Qt-Commercial-exception-1.0
5 */
6
7#include "individualmaildialog.h"
8
9#include <KGuiItem>
10#include <KLocalizedString>
11
12#include <QComboBox>
13#include <QDialogButtonBox>
14#include <QGridLayout>
15#include <QLabel>
16#include <QPushButton>
17
18using namespace IncidenceEditorNG;
19
20IndividualMailDialog::IndividualMailDialog(const QString &question,
21 const KCalendarCore::Attendee::List &attendees,
22 const KGuiItem &buttonYes,
23 const KGuiItem &buttonNo,
24 QWidget *parent)
25 : QDialog(parent)
26{
27 setWindowTitle(i18nc("@title:window", "Group Scheduling Email"));
28 m_detailsWidget = new QWidget();
29 auto layout = new QGridLayout(m_detailsWidget);
30 mAttendeeDecision.reserve(attendees.size());
31 int row = 0;
32 for (const KCalendarCore::Attendee &attendee : attendees) {
33 auto options = new QComboBox();
34 options->addItem(i18nc("@item:inlistbox ITIP Messages for one attendee", "Send update"), QVariant(Update));
35 options->addItem(i18nc("@item:inlistbox ITIP Messages for one attendee", "Send no update"), QVariant(NoUpdate));
36 options->addItem(i18nc("@item:inlistbox ITIP Messages for one attendee", "Edit mail"), QVariant(Edit));
37 options->setWhatsThis(i18nc("@info:whatsthis", "Options for this particular attendee."));
38 options->setToolTip(i18nc("@info:tooltip", "Choose an option for this attendee."));
39 mAttendeeDecision.emplace_back(attendee, options);
40
41 layout->addWidget(new QLabel(attendee.fullName()), row, 0);
42 layout->addWidget(options, row, 1);
43 ++row;
44 }
45 QSizePolicy sizePolicy = m_detailsWidget->sizePolicy();
46 sizePolicy.setHorizontalStretch(1);
47 sizePolicy.setVerticalStretch(1);
48 m_detailsWidget->setSizePolicy(sizePolicy);
49
50 QWidget *mW = new QLabel(question);
51
52 auto topLayout = new QVBoxLayout(this);
53 topLayout->addWidget(mW);
54 topLayout->addWidget(m_detailsWidget);
55
56 m_buttons = new QDialogButtonBox(this);
57 m_buttons->setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No | QDialogButtonBox::Help);
58 auto yesButton = m_buttons->button(QDialogButtonBox::Yes);
59 yesButton->setText(buttonYes.text());
60 connect(yesButton, &QPushButton::clicked, this, [this]() {
62 });
63 auto noButton = m_buttons->button(QDialogButtonBox::No);
64 noButton->setText(buttonNo.text());
65 connect(noButton, &QPushButton::clicked, this, [this]() {
67 });
68 auto detailsButton = m_buttons->button(QDialogButtonBox::Help);
69 detailsButton->setIcon(QIcon::fromTheme(QStringLiteral("help-about")));
70 connect(detailsButton, &QPushButton::clicked, this, [this]() {
71 m_detailsWidget->setVisible(!m_detailsWidget->isVisible());
72 updateButtonState();
73 adjustSize();
74 });
75 m_detailsWidget->setVisible(false);
76 updateButtonState();
77
78 topLayout->addWidget(m_buttons);
79}
80
81IndividualMailDialog::~IndividualMailDialog() = default;
82
83KCalendarCore::Attendee::List IndividualMailDialog::editAttendees() const
84{
86 for (auto it = mAttendeeDecision.cbegin(), end = mAttendeeDecision.cend(); it != end; ++it) {
87 const int index = (*it).second->currentIndex();
88 if ((*it).second->itemData(index, Qt::UserRole) == Edit) {
89 edit.append((*it).first);
90 }
91 }
92 return edit;
93}
94
95KCalendarCore::Attendee::List IndividualMailDialog::updateAttendees() const
96{
98 for (auto it = mAttendeeDecision.cbegin(), end = mAttendeeDecision.cend(); it != end; ++it) {
99 const int index = (*it).second->currentIndex();
100 if ((*it).second->itemData(index, Qt::UserRole) == Update) {
101 update.append((*it).first);
102 }
103 }
104 return update;
105}
106
107void IndividualMailDialog::updateButtonState()
108{
109 auto detailsButton = m_buttons->button(QDialogButtonBox::Help);
110 if (m_detailsWidget->isVisible()) {
111 detailsButton->setText(i18nc("@action:button show list of attendees", "Individual mailsettings <<"));
112 } else {
113 detailsButton->setText(i18nc("@action:button show list of attendees", "Individual mailsettings >>"));
114 }
115}
116
117#include "moc_individualmaildialog.cpp"
QString text() const
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void clicked(bool checked)
QPushButton * button(StandardButton which) const const
QIcon fromTheme(const QString &name)
void append(QList< T > &&value)
qsizetype size() const const
void setHorizontalStretch(int stretchFactor)
void setVerticalStretch(int stretchFactor)
UserRole
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void update()
bool isVisible() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:17:23 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.