individualmaildialog.cpp 4.38 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
#include <KLocalizedString>

12
13
#include <QComboBox>
#include <QDialogButtonBox>
14
15
#include <QGridLayout>
#include <QLabel>
Volker Krause's avatar
Volker Krause committed
16
#include <QPushButton>
17
18
19

using namespace IncidenceEditorNG;

Laurent Montel's avatar
Laurent Montel committed
20
21
22
23
24
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
25
    : QDialog(parent)
26
{
Volker Krause's avatar
Volker Krause committed
27
28
    setWindowTitle(i18nc("@title:window", "Group Scheduling Email"));
    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();
Laurent Montel's avatar
Laurent Montel committed
34
35
36
37
38
        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."));
39
        mAttendeeDecision.push_back(std::make_pair(attendee, options));
40

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

    QWidget *mW = new QLabel(question);

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

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

    topLayout->addWidget(m_buttons);
79
80
81
82
83
84
}

IndividualMailDialog::~IndividualMailDialog()
{
}

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

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

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