Akonadi Calendar

publishdialog.cpp
1/*
2 SPDX-FileCopyrightText: 2001 Cornelius Schumacher <schumacher@kde.org>
3 SPDX-FileCopyrightText: 2009 Allen Winter <winter@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8// TODO: validate hand-entered email addresses
9// TODO: don't allow duplicates; at least remove dupes when passing back
10// TODO: the list in PublishDialog::addresses()
11
12#include "publishdialog_p.h"
13using namespace Qt::Literals::StringLiterals;
14
15#include <KCalendarCore/Person>
16
17#include <KEmailAddress>
18
19#include <KLocalizedString>
20#include <KMessageBox>
21
22#include <QDesktopServices>
23#include <QDialogButtonBox>
24#include <QPushButton>
25#include <QUrl>
26
27using namespace KCalendarCore;
28using namespace Akonadi;
29
30PublishDialog::PublishDialog(QWidget *parent)
31 : QDialog(parent)
32 , d(new PublishDialogPrivate(this))
33{
34 setWindowTitle(i18nc("@title:window", "Select Addresses"));
35 auto layout = new QVBoxLayout(this);
36 auto widget = new QWidget(this);
37 widget->setObjectName("PublishFreeBusy"_L1);
38 d->mUI.setupUi(widget);
39 layout->addWidget(widget);
40 d->mUI.mListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
41 d->mUI.mNameLineEdit->setEnabled(false);
42 d->mUI.mEmailLineEdit->setEnabled(false);
43
44 d->mUI.mNew->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
45 d->mUI.mRemove->setIcon(QIcon::fromTheme(QStringLiteral("list-remove")));
46 d->mUI.mRemove->setEnabled(false);
47 d->mUI.mSelectAddressee->setIcon(QIcon::fromTheme(QStringLiteral("view-pim-contacts")));
48 connect(d->mUI.mListWidget, &QListWidget::itemSelectionChanged, d.get(), &PublishDialogPrivate::updateInput);
49 connect(d->mUI.mNew, &QAbstractButton::clicked, d.get(), &PublishDialogPrivate::addItem);
50 connect(d->mUI.mRemove, &QAbstractButton::clicked, d.get(), &PublishDialogPrivate::removeItem);
51 connect(d->mUI.mSelectAddressee, &QAbstractButton::clicked, d.get(), &PublishDialogPrivate::openAddressbook);
52 connect(d->mUI.mNameLineEdit, &QLineEdit::textChanged, d.get(), &PublishDialogPrivate::updateItem);
53 connect(d->mUI.mEmailLineEdit, &QLineEdit::textChanged, d.get(), &PublishDialogPrivate::updateItem);
54
56 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
57 okButton->setDefault(true);
59 layout->addWidget(buttonBox);
60
61 okButton->setToolTip(i18nc("@info:tooltip", "Send email to these recipients"));
62 okButton->setWhatsThis(
63 i18n("Clicking the <b>Ok</b> button will cause "
64 "an email to be sent to the recipients you "
65 "have entered."));
66
67 QPushButton *cancelButton = buttonBox->button(QDialogButtonBox::Cancel);
68 cancelButton->setToolTip(i18nc("@info:tooltip", "Cancel recipient selection and the email"));
69 cancelButton->setWhatsThis(
70 i18n("Clicking the <b>Cancel</b> button will "
71 "cause the email operation to be terminated."));
72
73 QPushButton *helpButton = buttonBox->button(QDialogButtonBox::Help);
74 helpButton->setWhatsThis(
75 i18n("Click the <b>Help</b> button to read "
76 "more information about Group Scheduling."));
77
78 connect(buttonBox, &QDialogButtonBox::accepted, this, &PublishDialog::accept);
79 connect(buttonBox, &QDialogButtonBox::rejected, this, &PublishDialog::reject);
80 connect(buttonBox->button(QDialogButtonBox::Help), &QPushButton::clicked, this, &PublishDialog::slotHelp);
81}
82
83PublishDialog::~PublishDialog() = default;
84
85void PublishDialog::slotHelp()
86{
87 const QUrl url = QUrl(QStringLiteral("help:/")).resolved(QUrl(QStringLiteral("korganizer/group-scheduling.html")));
88 // launch khelpcenter, or a browser for URIs not handled by khelpcenter
90}
91
92void PublishDialog::addAttendee(const Attendee &attendee)
93{
94 d->mUI.mNameLineEdit->setEnabled(true);
95 d->mUI.mEmailLineEdit->setEnabled(true);
96 auto item = new QListWidgetItem(d->mUI.mListWidget);
97 Person person(attendee.name(), attendee.email());
98 item->setText(person.fullName());
99 d->mUI.mListWidget->addItem(item);
100 d->mUI.mRemove->setEnabled(!d->mUI.mListWidget->selectedItems().isEmpty());
101}
102
103QString PublishDialog::addresses() const
104{
105 QStringList toList;
106 const int count = d->mUI.mListWidget->count();
107 for (int i = 0; i < count; ++i) {
108 QListWidgetItem *item = d->mUI.mListWidget->item(i);
109 if (!item->text().isEmpty()) {
111 }
112 }
113
114 return toList.join(QLatin1Char(','));
115}
116
117void PublishDialog::accept()
118{
119 QString badAddress;
120 const KEmailAddress::EmailParseResult addressOk = KEmailAddress::isValidAddressList(addresses(), badAddress);
121 if (addressOk != KEmailAddress::AddressOk) {
123 i18n("Unable to publish the calendar incidence due to an "
124 "invalid recipients string.\n%1",
125 emailParseResultToString(addressOk)),
126 i18nc("@title:window", "Publishing Error"));
127 } else {
129 }
130}
131
132#include "moc_publishdialog.cpp"
QString name() const
QString email() const
KCODECS_EXPORT QByteArray extractEmailAddress(const QByteArray &address)
KCODECS_EXPORT QString normalizeAddressesAndEncodeIdn(const QString &str)
KCODECS_EXPORT EmailParseResult isValidAddressList(const QString &aStr, QString &badAddr)
KCODECS_EXPORT QString emailParseResultToString(EmailParseResult errorCode)
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
FreeBusyManager::Singleton.
void error(QWidget *parent, const QString &text, const QString &title, const KGuiItem &buttonOk, Options options=Notify)
void clicked(bool checked)
void setShortcut(const QKeySequence &key)
bool openUrl(const QUrl &url)
virtual void accept()
QIcon fromTheme(const QString &name)
void textChanged(const QString &text)
qsizetype count() const const
void itemSelectionChanged()
QString text() const const
void setDefault(bool)
bool isEmpty() const const
QString join(QChar separator) const const
Key_Return
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QUrl resolved(const QUrl &relative) const const
void setToolTip(const QString &)
void setWhatsThis(const QString &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 19 2024 11:52:11 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.