Messagelib

recipientseditorsidewidget.cpp
1 /*
2  SPDX-FileCopyrightText: 2010 Casey Link <[email protected]>
3  SPDX-FileCopyrightText: 2009-2010 Klaralvdalens Datakonsult AB, a KDAB Group company <[email protected]>
4 
5  Refactored from earlier code by:
6  SPDX-FileCopyrightText: 2010 Volker Krause <[email protected]>
7  SPDX-FileCopyrightText: 2004 Cornelius Schumacher <[email protected]>
8 
9  SPDX-License-Identifier: LGPL-2.0-or-later
10 */
11 
12 #include "recipientseditorsidewidget.h"
13 
14 #include "kwindowpositioner.h"
15 #include "recipientspicker.h"
16 
17 #include <KLocalizedString>
18 #include <QLabel>
19 #include <QPushButton>
20 #include <QVBoxLayout>
21 
22 using namespace MessageComposer;
23 
24 RecipientsEditorSideWidget::RecipientsEditorSideWidget(RecipientsEditor *view, QWidget *parent)
25  : QWidget(parent)
26  , mEditor(view)
27 {
28  auto topLayout = new QVBoxLayout(this);
29 
30  topLayout->setContentsMargins({});
31  topLayout->addStretch(1);
32 
33  mTotalLabel = new QLabel(this);
34  mTotalLabel->setAlignment(Qt::AlignCenter);
35  mTotalLabel->setTextFormat(Qt::PlainText);
36  topLayout->addWidget(mTotalLabel);
37  mTotalLabel->hide();
38 
39  topLayout->addStretch(1);
40 
41  mDistributionListButton = new QPushButton(i18nc("@action:button", "Save List..."), this);
42  topLayout->addWidget(mDistributionListButton);
43  mDistributionListButton->hide();
44  connect(mDistributionListButton, &QAbstractButton::clicked, this, &RecipientsEditorSideWidget::saveDistributionList);
45  mDistributionListButton->setToolTip(i18nc("@info:tooltip", "Save recipients as distribution list"));
46 
47  mSelectButton = new QPushButton(i18nc("@action:button Open recipient selection dialog.", "Se&lect..."), this);
48  topLayout->addWidget(mSelectButton);
49  connect(mSelectButton, &QPushButton::clicked, this, &RecipientsEditorSideWidget::pickRecipient);
50  mSelectButton->setToolTip(i18nc("@info:tooltip", "Select recipients from address book"));
51  updateTotalToolTip();
52 }
53 
54 RecipientsEditorSideWidget::~RecipientsEditorSideWidget() = default;
55 
56 RecipientsPicker *RecipientsEditorSideWidget::picker() const
57 {
58  if (!mRecipientPicker) {
59  // hacks to allow picker() to be const in the presence of lazy loading
60  auto non_const_this = const_cast<RecipientsEditorSideWidget *>(this);
61  mRecipientPicker = new RecipientsPicker(non_const_this);
62  connect(mRecipientPicker, &RecipientsPicker::pickedRecipient, non_const_this, &RecipientsEditorSideWidget::pickedRecipient);
63  mPickerPositioner = new KWindowPositioner(mSelectButton, mRecipientPicker);
64  }
65  return mRecipientPicker;
66 }
67 
68 void RecipientsEditorSideWidget::setFocus()
69 {
70  mSelectButton->setFocus();
71 }
72 
73 void RecipientsEditorSideWidget::setTotal(int recipients, int lines)
74 {
75  QString labelText;
76  if (recipients == 0) {
77  labelText = i18nc("@info:status No recipients selected", "No recipients");
78  } else {
79  labelText = i18ncp("@info:status Number of recipients selected", "1 recipient", "%1 recipients", recipients);
80  }
81 
82  if (lines > 3) {
83  mTotalLabel->setText(labelText);
84  mTotalLabel->show();
85  updateTotalToolTip();
86  } else {
87  mTotalLabel->hide();
88  }
89 
90  if (lines > 2) {
91  mDistributionListButton->show();
92  } else {
93  mDistributionListButton->hide();
94  }
95 }
96 
97 void RecipientsEditorSideWidget::updateTotalToolTip()
98 {
99  QString text;
100 
101  QString to;
102  QString cc;
103  QString bcc;
104  QString replyTo;
105 
106  Recipient::List recipients = mEditor->recipients();
109  for (it = recipients.constBegin(); it != end; ++it) {
110  const QString emailLine = QLatin1String("&nbsp;&nbsp;") + (*it)->email().toHtmlEscaped() + QLatin1String("<br/>");
111  switch ((*it)->type()) {
112  case Recipient::To:
113  to += emailLine;
114  break;
115  case Recipient::Cc:
116  cc += emailLine;
117  break;
118  case Recipient::Bcc:
119  bcc += emailLine;
120  break;
121  case Recipient::ReplyTo:
122  replyTo += emailLine;
123  break;
124  default:
125  break;
126  }
127  }
128 
129  text += i18nc("@info:tooltip %1 list of emails", "To:%1", to);
130  if (!cc.isEmpty()) {
131  text += i18nc("@info:tooltip %1 list of emails", "CC:%1", cc);
132  }
133  if (!bcc.isEmpty()) {
134  text += i18nc("@info:tooltip %1 list of emails", "BCC:%1", bcc);
135  }
136  if (!replyTo.isEmpty()) {
137  text += i18nc("@info:tooltip %1 list of emails", "Reply-To:%1", replyTo);
138  }
139 
140  mTotalLabel->setToolTip(QStringLiteral("<html><head><body>%1</body></head></html>").arg(text));
141 }
142 
143 void RecipientsEditorSideWidget::pickRecipient()
144 {
145  MessageComposer::RecipientsPicker *p = picker();
146  Recipient::Ptr rec = mEditor->activeRecipient();
147  if (rec) {
148  p->setDefaultType(rec->type());
149  p->setRecipients(mEditor->recipients());
150  mPickerPositioner->reposition();
151  p->show();
152  }
153 }
PlainText
AlignCenter
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
The RecipientsEditor class.
void clicked(bool checked)
QVector::const_iterator constEnd() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QString i18ncp(const char *context, const char *singular, const char *plural, const TYPE &arg...)
bool isEmpty() const const
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QVector::const_iterator constBegin() const const
typedef ConstIterator
const QList< QKeySequence > & end()
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Mar 26 2023 04:08:11 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.