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 
18 using namespace MessageViewer;
19 
20 class MessageViewer::ConfigureWidgetPrivate
21 {
22 public:
23  ConfigureWidgetPrivate() = default;
24 
25  ~ConfigureWidgetPrivate()
26  {
27  delete mSettingsUi;
28  mSettingsUi = nullptr;
29  }
30 
31  Ui_Settings *mSettingsUi = nullptr;
32 };
33 
34 ConfigureWidget::ConfigureWidget(QWidget *parent)
35  : QWidget(parent)
36  , d(new MessageViewer::ConfigureWidgetPrivate)
37 {
38  d->mSettingsUi = new Ui_Settings;
39  d->mSettingsUi->setupUi(this);
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 
53 ConfigureWidget::~ConfigureWidget() = default;
54 
55 void ConfigureWidget::readConfig()
56 {
57  readCurrentOverrideCodec();
58  d->mSettingsUi->kcfg_CollapseQuoteLevelSpin->setEnabled(MessageViewer::MessageViewerSettings::self()->showExpandQuotesMark());
59 }
60 
61 void 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 
69 void 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"));
78  QStringList::ConstIterator it(encodings.constBegin());
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"
static QStringList supportedEncodings(bool usAscii)
Return a list of the supported encodings.
QLayout * layout() 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)
int size() const const
void prepend(const T &value)
QString i18n(const char *text, const TYPE &arg...)
bool isEmpty() const const
static QString encodingForName(const QString &descriptiveName)
Drop-in replacement for KCharsets::encodingForName().
typedef ConstIterator
QList::const_iterator constEnd() const const
void currentIndexChanged(int index)
void setContentsMargins(int left, int top, int right, int bottom)
const QList< QKeySequence > & end()
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Thu Feb 15 2024 03:55:19 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.