Messagelib

configurewidget.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected]
3  SPDX-FileCopyrightText: 2009 Andras Mantia <[email protected]>
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 "utils/messageviewerutil.h"
13 #include <MimeTreeParser/NodeHelper>
14 
15 #include "MessageCore/MessageCoreSettings"
16 
17 #include <KLocalizedString>
18 
19 using namespace MessageViewer;
20 
21 class MessageViewer::ConfigureWidgetPrivate
22 {
23 public:
24  ConfigureWidgetPrivate() = default;
25 
26  ~ConfigureWidgetPrivate()
27  {
28  delete mSettingsUi;
29  mSettingsUi = nullptr;
30  }
31 
32  Ui_Settings *mSettingsUi = nullptr;
33 };
34 
35 ConfigureWidget::ConfigureWidget(QWidget *parent)
36  : QWidget(parent)
37  , d(new MessageViewer::ConfigureWidgetPrivate)
38 {
39  d->mSettingsUi = new Ui_Settings;
40  d->mSettingsUi->setupUi(this);
42 
44  encodings.prepend(i18n("Auto"));
45  d->mSettingsUi->overrideCharacterEncoding->addItems(encodings);
46  d->mSettingsUi->overrideCharacterEncoding->setCurrentIndex(0);
47 
48  d->mSettingsUi->overrideCharacterEncoding->setWhatsThis(MessageCore::MessageCoreSettings::self()->overrideCharacterEncodingItem()->whatsThis());
49  d->mSettingsUi->kcfg_ShrinkQuotes->setWhatsThis(MessageViewer::MessageViewerSettings::self()->shrinkQuotesItem()->whatsThis());
50  d->mSettingsUi->kcfg_ShowExpandQuotesMark->setWhatsThis(MessageViewer::MessageViewerSettings::self()->showExpandQuotesMarkItem()->whatsThis());
51  connect(d->mSettingsUi->overrideCharacterEncoding, qOverload<int>(&QComboBox::currentIndexChanged), this, &ConfigureWidget::settingsChanged);
52 }
53 
54 ConfigureWidget::~ConfigureWidget() = default;
55 
56 void ConfigureWidget::readConfig()
57 {
58  readCurrentOverrideCodec();
59  d->mSettingsUi->kcfg_CollapseQuoteLevelSpin->setEnabled(MessageViewer::MessageViewerSettings::self()->showExpandQuotesMark());
60 }
61 
62 void ConfigureWidget::writeConfig()
63 {
64  MessageCore::MessageCoreSettings::self()->setOverrideCharacterEncoding(
65  d->mSettingsUi->overrideCharacterEncoding->currentIndex() == 0
66  ? QString()
67  : MimeTreeParser::NodeHelper::encodingForName(d->mSettingsUi->overrideCharacterEncoding->currentText()));
68 }
69 
70 void ConfigureWidget::readCurrentOverrideCodec()
71 {
72  const QString &currentOverrideEncoding = MessageCore::MessageCoreSettings::self()->overrideCharacterEncoding();
73  if (currentOverrideEncoding.isEmpty()) {
74  d->mSettingsUi->overrideCharacterEncoding->setCurrentIndex(0);
75  return;
76  }
78  encodings.prepend(i18n("Auto"));
79  QStringList::ConstIterator it(encodings.constBegin());
80  const QStringList::ConstIterator end(encodings.constEnd());
81  int i = 0;
82  for (; it != end; ++it) {
83  if (MimeTreeParser::NodeHelper::encodingForName(*it) == currentOverrideEncoding) {
84  d->mSettingsUi->overrideCharacterEncoding->setCurrentIndex(i);
85  break;
86  }
87  ++i;
88  }
89  if (i == encodings.size()) {
90  // the current value of overrideCharacterEncoding is an unknown encoding => reset to Auto
91  qCWarning(MESSAGEVIEWER_LOG) << "Unknown override character encoding" << currentOverrideEncoding << ". Resetting to Auto.";
92  d->mSettingsUi->overrideCharacterEncoding->setCurrentIndex(0);
93  MessageCore::MessageCoreSettings::self()->setOverrideCharacterEncoding(QString());
94  }
95 }
QLayout * layout() const const
static QStringList supportedEncodings(bool usAscii)
Return a list of the supported encodings.
void setContentsMargins(int left, int top, int right, int bottom)
int size() const const
bool isEmpty() const const
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() const const
typedef ConstIterator
void prepend(const T &value)
QList::const_iterator constEnd() const const
QList::const_iterator constBegin() const const
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void currentIndexChanged(int index)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Dec 4 2021 23:12:52 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.