Akonadi Contacts

messageformattingwidget.cpp
1/*
2 This file is part of Contact Editor.
3
4 SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org>
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>
17using namespace Akonadi;
18
19MessageFormattingWidget::MessageFormattingWidget(QWidget *parent)
20 : QWidget(parent)
21 , mMailPreferFormatting(new QComboBox(this))
22 , mAllowRemoteContent(new QCheckBox(i18nc("@option:check", "Allow remote content in received HTML messages"), this))
23{
24 auto topLayout = new QVBoxLayout(this);
25 topLayout->setContentsMargins({});
26 auto label = new QLabel(i18nc("@label:textbox", "Show messages received from this contact as:"), this);
27 label->setObjectName(QLatin1StringView("label"));
28 topLayout->addWidget(label);
29
30 mMailPreferFormatting->setObjectName(QLatin1StringView("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(QLatin1StringView("mAllowRemoteContent"));
37 topLayout->addWidget(mAllowRemoteContent);
38}
39
40MessageFormattingWidget::~MessageFormattingWidget() = default;
41
42void MessageFormattingWidget::loadContact(const KContacts::Addressee &contact)
43{
44 const QString mailAllowToRemoteContent = Akonadi::Utils::loadCustom(contact, QStringLiteral("MailAllowToRemoteContent"));
45 mAllowRemoteContent->setChecked(mailAllowToRemoteContent == QLatin1StringView("TRUE"));
46
47 const QString mailPreferedFormatting = Akonadi::Utils::loadCustom(contact, QStringLiteral("MailPreferedFormatting"));
48 if (mailPreferedFormatting.isEmpty()) {
49 mMailPreferFormatting->setCurrentIndex(0);
50 } else if (mailPreferedFormatting == QLatin1StringView("TEXT")) {
51 mMailPreferFormatting->setCurrentIndex(1);
52 } else if (mailPreferedFormatting == QLatin1StringView("HTML")) {
53 mMailPreferFormatting->setCurrentIndex(2);
54 } else {
55 mMailPreferFormatting->setCurrentIndex(0);
56 }
57}
58
59void 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 Akonadi::Utils::storeCustom(contact, QStringLiteral("MailPreferedFormatting"), mailPreferedFormatting);
71
72 QString mailAllowToRemoteContent;
73 if (mAllowRemoteContent->isChecked()) {
74 mailAllowToRemoteContent = QStringLiteral("TRUE");
75 }
76 Akonadi::Utils::storeCustom(contact, QStringLiteral("MailAllowToRemoteContent"), mailAllowToRemoteContent);
77}
78
79void MessageFormattingWidget::setReadOnly(bool readOnly)
80{
81 mMailPreferFormatting->setEnabled(!readOnly);
82 mAllowRemoteContent->setEnabled(!readOnly);
83}
84
85#include "moc_messageformattingwidget.cpp"
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
A widget for editing the display name of a contact.
QString label(StandardShortcut id)
void setChecked(bool)
void setCurrentIndex(int index)
bool isEmpty() const const
void setEnabled(bool)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:05:47 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.