Akonadi Calendar

publishdialog.cpp
1 /*
2  SPDX-FileCopyrightText: 2001 Cornelius Schumacher <[email protected]>
3  SPDX-FileCopyrightText: 2009 Allen Winter <[email protected]>
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"
13 
14 #include <KCalendarCore/Person>
15 
16 #include <KCodecs/KEmailAddress>
17 
18 #include <KLocalizedString>
19 #include <KMessageBox>
20 
21 #include <QDesktopServices>
22 #include <QDialogButtonBox>
23 #include <QPushButton>
24 #include <QUrl>
25 
26 using namespace KCalendarCore;
27 using namespace Akonadi;
28 
29 PublishDialog::PublishDialog(QWidget *parent)
30  : QDialog(parent)
31  , d(new Private(this))
32 {
33  setWindowTitle(i18nc("@title:window", "Select Addresses"));
34  auto layout = new QVBoxLayout(this);
35  auto widget = new QWidget(this);
36  widget->setObjectName(QStringLiteral("PublishFreeBusy"));
37  d->mUI.setupUi(widget);
38  layout->addWidget(widget);
39  d->mUI.mListWidget->setSelectionMode(QAbstractItemView::SingleSelection);
40  d->mUI.mNameLineEdit->setEnabled(false);
41  d->mUI.mEmailLineEdit->setEnabled(false);
42 
43  d->mUI.mNew->setIcon(QIcon::fromTheme(QStringLiteral("list-add")));
44  d->mUI.mRemove->setIcon(QIcon::fromTheme(QStringLiteral("list-remove")));
45  d->mUI.mRemove->setEnabled(false);
46  d->mUI.mSelectAddressee->setIcon(QIcon::fromTheme(QStringLiteral("view-pim-contacts")));
47  connect(d->mUI.mListWidget, &QListWidget::itemSelectionChanged, d, &Private::updateInput);
48  connect(d->mUI.mNew, &QAbstractButton::clicked, d, &Private::addItem);
49  connect(d->mUI.mRemove, &QAbstractButton::clicked, d, &Private::removeItem);
50  connect(d->mUI.mSelectAddressee, &QAbstractButton::clicked, d, &Private::openAddressbook);
51  connect(d->mUI.mNameLineEdit, &QLineEdit::textChanged, d, &Private::updateItem);
52  connect(d->mUI.mEmailLineEdit, &QLineEdit::textChanged, d, &Private::updateItem);
53 
55  QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
56  okButton->setDefault(true);
57  okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
58  layout->addWidget(buttonBox);
59 
60  okButton->setToolTip(i18n("Send email to these recipients"));
61  okButton->setWhatsThis(
62  i18n("Clicking the <b>Ok</b> button will cause "
63  "an email to be sent to the recipients you "
64  "have entered."));
65 
66  QPushButton *cancelButton = buttonBox->button(QDialogButtonBox::Cancel);
67  cancelButton->setToolTip(i18n("Cancel recipient selection and the email"));
68  cancelButton->setWhatsThis(
69  i18n("Clicking the <b>Cancel</b> button will "
70  "cause the email operation to be terminated."));
71 
72  QPushButton *helpButton = buttonBox->button(QDialogButtonBox::Help);
73  helpButton->setWhatsThis(
74  i18n("Click the <b>Help</b> button to read "
75  "more information about Group Scheduling."));
76 
77  connect(buttonBox, &QDialogButtonBox::accepted, this, &PublishDialog::accept);
78  connect(buttonBox, &QDialogButtonBox::rejected, this, &PublishDialog::reject);
79  connect(buttonBox->button(QDialogButtonBox::Help), &QPushButton::clicked, this, &PublishDialog::slotHelp);
80 }
81 
82 PublishDialog::~PublishDialog()
83 {
84  delete d;
85 }
86 
87 void PublishDialog::slotHelp()
88 {
89  const QUrl url = QUrl(QStringLiteral("help:/")).resolved(QUrl(QStringLiteral("korganizer/group-scheduling.html")));
90  // launch khelpcenter, or a browser for URIs not handled by khelpcenter
92 }
93 
94 void PublishDialog::addAttendee(const Attendee &attendee)
95 {
96  d->mUI.mNameLineEdit->setEnabled(true);
97  d->mUI.mEmailLineEdit->setEnabled(true);
98  auto item = new QListWidgetItem(d->mUI.mListWidget);
99  Person person(attendee.name(), attendee.email());
100  item->setText(person.fullName());
101  d->mUI.mListWidget->addItem(item);
102  d->mUI.mRemove->setEnabled(!d->mUI.mListWidget->selectedItems().isEmpty());
103 }
104 
105 QString PublishDialog::addresses() const
106 {
107  QStringList toList;
108  const int count = d->mUI.mListWidget->count();
109  for (int i = 0; i < count; ++i) {
110  QListWidgetItem *item = d->mUI.mListWidget->item(i);
111  if (!item->text().isEmpty()) {
112  toList << item->text();
113  }
114  }
115 
116  return toList.join(QLatin1Char(','));
117 }
118 
119 void PublishDialog::accept()
120 {
121  QString badAddress;
122  const KEmailAddress::EmailParseResult addressOk = KEmailAddress::isValidAddressList(addresses(), badAddress);
123  if (addressOk != KEmailAddress::AddressOk) {
124  KMessageBox::sorry(this,
125  i18n("Unable to publish the calendar incidence due to an "
126  "invalid recipients string. %1",
127  emailParseResultToString(addressOk)),
128  i18n("Publishing Error"));
129  } else {
130  QDialog::accept();
131  }
132 }
void textChanged(const QString &text)
QString join(const QString &separator) const const
QString i18nc(const char *context, const char *text, const TYPE &arg...)
bool isEmpty() const const
void clicked(bool checked)
KCODECS_EXPORT EmailParseResult isValidAddressList(const QString &aStr, QString &badAddr)
KCODECS_EXPORT QString emailParseResultToString(EmailParseResult errorCode)
void setShortcut(const QKeySequence &key)
QString email() const
virtual void accept()
QString i18n(const char *text, const TYPE &arg...)
void setWhatsThis(const QString &)
FreeBusyManager::Singleton.
QUrl resolved(const QUrl &relative) const const
QIcon fromTheme(const QString &name)
void itemSelectionChanged()
void setToolTip(const QString &)
bool openUrl(const QUrl &url)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setDefault(bool)
QString name() const
Key_Return
QString text() const const
void sorry(QWidget *parent, const QString &text, const QString &caption=QString(), Options options=Notify)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Jun 19 2021 23:12:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.