Akonadi Contacts

messageformattingwidget.cpp
1 /*
2  This file is part of Contact Editor.
3 
4  SPDX-FileCopyrightText: 2017-2021 Laurent Montel <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "messageformattingwidget.h"
10 #include "editor/utils/utils.h"
11 #include <KLocalizedString>
12 
13 #include <QCheckBox>
14 #include <QComboBox>
15 #include <QLabel>
16 #include <QVBoxLayout>
17 using namespace ContactEditor;
18 
19 MessageFormattingWidget::MessageFormattingWidget(QWidget *parent)
20  : QWidget(parent)
21 {
22  auto topLayout = new QVBoxLayout(this);
23  topLayout->setContentsMargins(0, 0, 0, 0);
24  auto label = new QLabel(i18n("Show messages received from this contact as:"), this);
25  label->setObjectName(QStringLiteral("label"));
26  topLayout->addWidget(label);
27 
28  mMailPreferFormatting = new QComboBox(this);
29  mMailPreferFormatting->setObjectName(QStringLiteral("mMailPreferFormatting"));
30  topLayout->addWidget(mMailPreferFormatting);
31  label->setBuddy(mMailPreferFormatting);
32  const QStringList listFormat{i18n("Default"), i18n("Plain Text"), i18n("HTML")};
33  mMailPreferFormatting->addItems(listFormat);
34 
35  mAllowRemoteContent = new QCheckBox(i18n("Allow remote content in received HTML messages"), this);
36  mAllowRemoteContent->setObjectName(QStringLiteral("mAllowRemoteContent"));
37  topLayout->addWidget(mAllowRemoteContent);
38 }
39 
40 MessageFormattingWidget::~MessageFormattingWidget()
41 {
42 }
43 
44 void MessageFormattingWidget::loadContact(const KContacts::Addressee &contact)
45 {
46  const QString mailAllowToRemoteContent = ContactEditor::Utils::loadCustom(contact, QStringLiteral("MailAllowToRemoteContent"));
47  mAllowRemoteContent->setChecked(mailAllowToRemoteContent == QLatin1String("TRUE"));
48 
49  const QString mailPreferedFormatting = ContactEditor::Utils::loadCustom(contact, QStringLiteral("MailPreferedFormatting"));
50  if (mailPreferedFormatting.isEmpty()) {
51  mMailPreferFormatting->setCurrentIndex(0);
52  } else if (mailPreferedFormatting == QLatin1String("TEXT")) {
53  mMailPreferFormatting->setCurrentIndex(1);
54  } else if (mailPreferedFormatting == QLatin1String("HTML")) {
55  mMailPreferFormatting->setCurrentIndex(2);
56  } else {
57  mMailPreferFormatting->setCurrentIndex(0);
58  }
59 }
60 
61 void MessageFormattingWidget::storeContact(KContacts::Addressee &contact) const
62 {
63  QString mailPreferedFormatting;
64  const int index = mMailPreferFormatting->currentIndex();
65  if (index == 0) {
66  // Nothing => remove custom variable
67  } else if (index == 1) {
68  mailPreferedFormatting = QStringLiteral("TEXT");
69  } else if (index == 2) {
70  mailPreferedFormatting = QStringLiteral("HTML");
71  }
72  ContactEditor::Utils::storeCustom(contact, QStringLiteral("MailPreferedFormatting"), mailPreferedFormatting);
73 
74  QString mailAllowToRemoteContent;
75  if (mAllowRemoteContent->isChecked()) {
76  mailAllowToRemoteContent = QStringLiteral("TRUE");
77  }
78  ContactEditor::Utils::storeCustom(contact, QStringLiteral("MailAllowToRemoteContent"), mailAllowToRemoteContent);
79 }
80 
81 void MessageFormattingWidget::setReadOnly(bool readOnly)
82 {
83  mMailPreferFormatting->setEnabled(!readOnly);
84  mAllowRemoteContent->setEnabled(!readOnly);
85 }
QString label(StandardShortcut id)
bool isEmpty() const const
QString i18n(const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Wed Jun 23 2021 23:09:25 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.