individualmaildialog.cpp 4.34 KB
Newer Older
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
8
 */

#include "individualmaildialog.h"

Volker Krause's avatar
Volker Krause committed
9
#include <KGuiItem>
10
11
12
13
#include <KLocalizedString>

#include <QGridLayout>
#include <QLabel>
Volker Krause's avatar
Volker Krause committed
14
#include <QPushButton>
15
16
17

using namespace IncidenceEditorNG;

Laurent Montel's avatar
Laurent Montel committed
18
19
20
21
22
IndividualMailDialog::IndividualMailDialog(const QString &question,
                                           const KCalendarCore::Attendee::List &attendees,
                                           const KGuiItem &buttonYes,
                                           const KGuiItem &buttonNo,
                                           QWidget *parent)
Volker Krause's avatar
Volker Krause committed
23
    : QDialog(parent)
24
{
Volker Krause's avatar
Volker Krause committed
25
26
    setWindowTitle(i18nc("@title:window", "Group Scheduling Email"));
    m_detailsWidget = new QWidget();
Laurent Montel's avatar
Laurent Montel committed
27
    auto *layout = new QGridLayout(m_detailsWidget);
28
    mAttendeeDecision.reserve(attendees.size());
29
    int row = 0;
30
    for (const KCalendarCore::Attendee &attendee : attendees) {
Laurent Montel's avatar
Laurent Montel committed
31
        auto *options = new QComboBox();
Laurent Montel's avatar
Laurent Montel committed
32
33
34
35
36
        options->addItem(i18nc("@item:inlistbox ITIP Messages for one attendee", "Send update"), QVariant(Update));
        options->addItem(i18nc("@item:inlistbox ITIP Messages for one attendee", "Send no update"), QVariant(NoUpdate));
        options->addItem(i18nc("@item:inlistbox ITIP Messages for one attendee", "Edit mail"), QVariant(Edit));
        options->setWhatsThis(i18nc("@info:whatsthis", "Options for this particular attendee."));
        options->setToolTip(i18nc("@info:tooltip", "Choose an option for this attendee."));
37
        mAttendeeDecision.push_back(std::make_pair(attendee, options));
38

39
        layout->addWidget(new QLabel(attendee.fullName()), row, 0);
40
41
42
        layout->addWidget(options, row, 1);
        ++row;
    }
Volker Krause's avatar
Volker Krause committed
43
    QSizePolicy sizePolicy = m_detailsWidget->sizePolicy();
44
45
    sizePolicy.setHorizontalStretch(1);
    sizePolicy.setVerticalStretch(1);
Volker Krause's avatar
Volker Krause committed
46
    m_detailsWidget->setSizePolicy(sizePolicy);
47
48
49

    QWidget *mW = new QLabel(question);

Volker Krause's avatar
Volker Krause committed
50
51
52
53
    auto topLayout = new QVBoxLayout(this);
    topLayout->addWidget(mW);
    topLayout->addWidget(m_detailsWidget);

Laurent Montel's avatar
Laurent Montel committed
54
    m_buttons = new QDialogButtonBox(this);
Laurent Montel's avatar
Laurent Montel committed
55
    m_buttons->setStandardButtons(QDialogButtonBox::Yes | QDialogButtonBox::No | QDialogButtonBox::Help);
Volker Krause's avatar
Volker Krause committed
56
57
    auto yesButton = m_buttons->button(QDialogButtonBox::Yes);
    yesButton->setText(buttonYes.text());
Laurent Montel's avatar
Laurent Montel committed
58
59
60
    connect(yesButton, &QPushButton::clicked, this, [this]() {
        done(QDialogButtonBox::Yes);
    });
Volker Krause's avatar
Volker Krause committed
61
62
    auto noButton = m_buttons->button(QDialogButtonBox::No);
    noButton->setText(buttonNo.text());
Laurent Montel's avatar
Laurent Montel committed
63
64
65
    connect(noButton, &QPushButton::clicked, this, [this]() {
        done(QDialogButtonBox::No);
    });
Volker Krause's avatar
Volker Krause committed
66
    auto detailsButton = m_buttons->button(QDialogButtonBox::Help);
Laurent Montel's avatar
Laurent Montel committed
67
    detailsButton->setIcon(QIcon::fromTheme(QStringLiteral("help-about")));
Volker Krause's avatar
Volker Krause committed
68
69
70
71
72
73
74
75
76
    connect(detailsButton, &QPushButton::clicked, this, [this]() {
        m_detailsWidget->setVisible(!m_detailsWidget->isVisible());
        updateButtonState();
        adjustSize();
    });
    m_detailsWidget->setVisible(false);
    updateButtonState();

    topLayout->addWidget(m_buttons);
77
78
79
80
81
82
}

IndividualMailDialog::~IndividualMailDialog()
{
}

83
KCalendarCore::Attendee::List IndividualMailDialog::editAttendees() const
84
{
85
    KCalendarCore::Attendee::List edit;
86
    for (auto it = mAttendeeDecision.cbegin(), end = mAttendeeDecision.cend(); it != end; ++it) {
87
88
89
        const int index = (*it).second->currentIndex();
        if ((*it).second->itemData(index, Qt::UserRole) == Edit) {
            edit.append((*it).first);
90
91
92
93
94
        }
    }
    return edit;
}

95
KCalendarCore::Attendee::List IndividualMailDialog::updateAttendees() const
96
{
97
    KCalendarCore::Attendee::List update;
98
    for (auto it = mAttendeeDecision.cbegin(), end = mAttendeeDecision.cend(); it != end; ++it) {
99
100
101
        const int index = (*it).second->currentIndex();
        if ((*it).second->itemData(index, Qt::UserRole) == Update) {
            update.append((*it).first);
102
103
104
105
        }
    }
    return update;
}
Volker Krause's avatar
Volker Krause committed
106
107
108
109

void IndividualMailDialog::updateButtonState()
{
    auto detailsButton = m_buttons->button(QDialogButtonBox::Help);
Laurent Montel's avatar
Laurent Montel committed
110
    if (m_detailsWidget->isVisible()) {
Laurent Montel's avatar
Laurent Montel committed
111
        detailsButton->setText(i18nc("@action:button show list of attendees", "Individual mailsettings <<"));
Laurent Montel's avatar
Laurent Montel committed
112
    } else {
Laurent Montel's avatar
Laurent Montel committed
113
        detailsButton->setText(i18nc("@action:button show list of attendees", "Individual mailsettings >>"));
Laurent Montel's avatar
Laurent Montel committed
114
    }
Volker Krause's avatar
Volker Krause committed
115
}