Akonadi Contacts

messageformattingwidget.cpp
1 /*
2  This file is part of Contact Editor.
3 
4  SPDX-FileCopyrightText: 2017-2023 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  , mMailPreferFormatting(new QComboBox(this))
22  , mAllowRemoteContent(new QCheckBox(i18n("Allow remote content in received HTML messages"), this))
23 {
24  auto topLayout = new QVBoxLayout(this);
25  topLayout->setContentsMargins({});
26  auto label = new QLabel(i18n("Show messages received from this contact as:"), this);
27  label->setObjectName(QStringLiteral("label"));
28  topLayout->addWidget(label);
29 
30  mMailPreferFormatting->setObjectName(QStringLiteral("mMailPreferFormatting"));
31  topLayout->addWidget(mMailPreferFormatting);
32  label->setBuddy(mMailPreferFormatting);
33  const QStringList listFormat{i18n("Default"), i18n("Plain Text"), i18n("HTML")};
34  mMailPreferFormatting->addItems(listFormat);
35 
36  mAllowRemoteContent->setObjectName(QStringLiteral("mAllowRemoteContent"));
37  topLayout->addWidget(mAllowRemoteContent);
38 }
39 
40 MessageFormattingWidget::~MessageFormattingWidget() = default;
41 
42 void MessageFormattingWidget::loadContact(const KContacts::Addressee &contact)
43 {
44  const QString mailAllowToRemoteContent = ContactEditor::Utils::loadCustom(contact, QStringLiteral("MailAllowToRemoteContent"));
45  mAllowRemoteContent->setChecked(mailAllowToRemoteContent == QLatin1String("TRUE"));
46 
47  const QString mailPreferedFormatting = ContactEditor::Utils::loadCustom(contact, QStringLiteral("MailPreferedFormatting"));
48  if (mailPreferedFormatting.isEmpty()) {
49  mMailPreferFormatting->setCurrentIndex(0);
50  } else if (mailPreferedFormatting == QLatin1String("TEXT")) {
51  mMailPreferFormatting->setCurrentIndex(1);
52  } else if (mailPreferedFormatting == QLatin1String("HTML")) {
53  mMailPreferFormatting->setCurrentIndex(2);
54  } else {
55  mMailPreferFormatting->setCurrentIndex(0);
56  }
57 }
58 
59 void MessageFormattingWidget::storeContact(KContacts::Addressee &contact) const
60 {
61  QString mailPreferedFormatting;
62  const int index = mMailPreferFormatting->currentIndex();
63  if (index == 0) {
64  // Nothing => remove custom variable
65  } else if (index == 1) {
66  mailPreferedFormatting = QStringLiteral("TEXT");
67  } else if (index == 2) {
68  mailPreferedFormatting = QStringLiteral("HTML");
69  }
70  ContactEditor::Utils::storeCustom(contact, QStringLiteral("MailPreferedFormatting"), mailPreferedFormatting);
71 
72  QString mailAllowToRemoteContent;
73  if (mAllowRemoteContent->isChecked()) {
74  mailAllowToRemoteContent = QStringLiteral("TRUE");
75  }
76  ContactEditor::Utils::storeCustom(contact, QStringLiteral("MailAllowToRemoteContent"), mailAllowToRemoteContent);
77 }
78 
79 void MessageFormattingWidget::setReadOnly(bool readOnly)
80 {
81  mMailPreferFormatting->setEnabled(!readOnly);
82  mAllowRemoteContent->setEnabled(!readOnly);
83 }
QString i18n(const char *text, const TYPE &arg...)
bool isEmpty() const const
QString label(StandardShortcut id)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Apr 1 2023 04:09:05 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.