Messagelib

configurewidget.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net
3 SPDX-FileCopyrightText: 2009 Andras Mantia <andras@kdab.net>
4
5 SPDX-License-Identifier: GPL-2.0-or-later
6*/
7
8#include "configurewidget.h"
9#include "messageviewer_debug.h"
10#include "settings/messageviewersettings.h"
11#include "ui_settings.h"
12#include <MimeTreeParser/NodeHelper>
13
14#include "MessageCore/MessageCoreSettings"
15
16#include <KLocalizedString>
17
18using namespace MessageViewer;
19
20class MessageViewer::ConfigureWidgetPrivate
21{
22public:
23 ConfigureWidgetPrivate() = default;
24
25 ~ConfigureWidgetPrivate()
26 {
27 delete mSettingsUi;
28 mSettingsUi = nullptr;
29 }
30
31 Ui_Settings *mSettingsUi = nullptr;
32};
33
34ConfigureWidget::ConfigureWidget(QWidget *parent)
35 : QWidget(parent)
36 , d(new MessageViewer::ConfigureWidgetPrivate)
37{
38 d->mSettingsUi = new Ui_Settings;
39 d->mSettingsUi->setupUi(this);
40 layout()->setContentsMargins({});
41
43 encodings.prepend(i18n("Auto"));
44 d->mSettingsUi->overrideCharacterEncoding->addItems(encodings);
45 d->mSettingsUi->overrideCharacterEncoding->setCurrentIndex(0);
46
47 d->mSettingsUi->overrideCharacterEncoding->setWhatsThis(MessageCore::MessageCoreSettings::self()->overrideCharacterEncodingItem()->whatsThis());
48 d->mSettingsUi->kcfg_ShrinkQuotes->setWhatsThis(MessageViewer::MessageViewerSettings::self()->shrinkQuotesItem()->whatsThis());
49 d->mSettingsUi->kcfg_ShowExpandQuotesMark->setWhatsThis(MessageViewer::MessageViewerSettings::self()->showExpandQuotesMarkItem()->whatsThis());
50 connect(d->mSettingsUi->overrideCharacterEncoding, &QComboBox::currentIndexChanged, this, &ConfigureWidget::settingsChanged);
51}
52
53ConfigureWidget::~ConfigureWidget() = default;
54
55void ConfigureWidget::readConfig()
56{
57 readCurrentOverrideCodec();
58 d->mSettingsUi->kcfg_CollapseQuoteLevelSpin->setEnabled(MessageViewer::MessageViewerSettings::self()->showExpandQuotesMark());
59}
60
61void ConfigureWidget::writeConfig()
62{
63 MessageCore::MessageCoreSettings::self()->setOverrideCharacterEncoding(
64 d->mSettingsUi->overrideCharacterEncoding->currentIndex() == 0
65 ? QString()
66 : MimeTreeParser::NodeHelper::encodingForName(d->mSettingsUi->overrideCharacterEncoding->currentText()));
67}
68
69void ConfigureWidget::readCurrentOverrideCodec()
70{
71 const QString &currentOverrideEncoding = MessageCore::MessageCoreSettings::self()->overrideCharacterEncoding();
72 if (currentOverrideEncoding.isEmpty()) {
73 d->mSettingsUi->overrideCharacterEncoding->setCurrentIndex(0);
74 return;
75 }
77 encodings.prepend(i18n("Auto"));
79 const QStringList::ConstIterator end(encodings.constEnd());
80 int i = 0;
81 for (; it != end; ++it) {
82 if (MimeTreeParser::NodeHelper::encodingForName(*it) == currentOverrideEncoding) {
83 d->mSettingsUi->overrideCharacterEncoding->setCurrentIndex(i);
84 break;
85 }
86 ++i;
87 }
88 if (i == encodings.size()) {
89 // the current value of overrideCharacterEncoding is an unknown encoding => reset to Auto
90 qCWarning(MESSAGEVIEWER_LOG) << "Unknown override character encoding" << currentOverrideEncoding << ". Resetting to Auto.";
91 d->mSettingsUi->overrideCharacterEncoding->setCurrentIndex(0);
92 MessageCore::MessageCoreSettings::self()->setOverrideCharacterEncoding(QString());
93 }
94}
95
96#include "moc_configurewidget.cpp"
void settingsChanged()
Emitted when the user changes the setting in some widget.
static QStringList supportedEncodings()
Return a list of the supported encodings.
static QString encodingForName(const QString &descriptiveName)
Drop-in replacement for KCharsets::encodingForName().
QString i18n(const char *text, const TYPE &arg...)
const QList< QKeySequence > & end()
QString whatsThis(StandardShortcut id)
void currentIndexChanged(int index)
const_iterator constBegin() const const
const_iterator constEnd() const const
void prepend(parameter_type value)
qsizetype size() const const
bool isEmpty() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
void setupUi(QWidget *widget)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.