• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

messageviewer

  • sources
  • kde-4.14
  • kdepim
  • messageviewer
  • widgets
configurewidget.cpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-file-style: "gnu" -*-
2  Copyright (C) 2009 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.net
3  Copyright (c) 2009 Andras Mantia <andras@kdab.net>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 
20 #include "configurewidget.h"
21 #include "customheadersettingdialog.h"
22 
23 #include "ui_settings.h"
24 #include "utils/util.h"
25 #include "settings/globalsettings.h"
26 #include "viewer/nodehelper.h"
27 
28 #include "messagecore/settings/globalsettings.h"
29 
30 #include <KConfigDialogManager>
31 #include <KDialog>
32 
33 using namespace MessageViewer;
34 
35 ConfigureWidget::ConfigureWidget( QWidget *parent )
36  : QWidget( parent )
37 {
38  mSettingsUi = new Ui_Settings;
39  mSettingsUi->setupUi( this );
40  layout()->setContentsMargins( 0, 0, 0, 0 );
41 
42  QStringList encodings = NodeHelper::supportedEncodings( false );
43  mSettingsUi->fallbackCharacterEncoding->addItems( encodings );
44  encodings.prepend( i18n( "Auto" ) );
45  mSettingsUi->overrideCharacterEncoding->addItems( encodings );
46  mSettingsUi->overrideCharacterEncoding->setCurrentIndex( 0 );
47 
48  mSettingsUi->fallbackCharacterEncoding->setWhatsThis(
49  MessageCore::GlobalSettings::self()->fallbackCharacterEncodingItem()->whatsThis() );
50  mSettingsUi->overrideCharacterEncoding->setWhatsThis(
51  MessageCore::GlobalSettings::self()->overrideCharacterEncodingItem()->whatsThis() );
52  mSettingsUi->kcfg_ShowEmoticons->setWhatsThis(
53  GlobalSettings::self()->showEmoticonsItem()->whatsThis() );
54  mSettingsUi->kcfg_ShrinkQuotes->setWhatsThis(
55  GlobalSettings::self()->shrinkQuotesItem()->whatsThis() );
56  mSettingsUi->kcfg_ShowExpandQuotesMark->setWhatsThis(
57  GlobalSettings::self()->showExpandQuotesMarkItem()->whatsThis() );
58 
59  connect( mSettingsUi->fallbackCharacterEncoding, SIGNAL(currentIndexChanged(int)),
60  this, SIGNAL(settingsChanged()) );
61  connect( mSettingsUi->overrideCharacterEncoding, SIGNAL(currentIndexChanged(int)),
62  this, SIGNAL(settingsChanged()) );
63 
64  connect( mSettingsUi->configureCustomHeadersButton, SIGNAL(clicked()),
65  this, SLOT(showCustomHeadersDialog()) );
66 }
67 
68 ConfigureWidget::~ConfigureWidget()
69 {
70  delete mSettingsUi;
71  mSettingsUi = 0;
72 }
73 
74 void ConfigureWidget::readConfig()
75 {
76  readCurrentFallbackCodec();
77  readCurrentOverrideCodec();
78  mSettingsUi->kcfg_CollapseQuoteLevelSpin->setEnabled(
79  GlobalSettings::self()->showExpandQuotesMark() );
80 }
81 
82 void ConfigureWidget::writeConfig()
83 {
84  MessageCore::GlobalSettings::self()->setFallbackCharacterEncoding(
85  NodeHelper::encodingForName( mSettingsUi->fallbackCharacterEncoding->currentText() ) );
86  MessageCore::GlobalSettings::self()->setOverrideCharacterEncoding(
87  mSettingsUi->overrideCharacterEncoding->currentIndex() == 0 ?
88  QString() :
89  NodeHelper::encodingForName( mSettingsUi->overrideCharacterEncoding->currentText() ) );
90 
91  KMime::setFallbackCharEncoding( NodeHelper::encodingForName( mSettingsUi->fallbackCharacterEncoding->currentText() ) );
92 
93 }
94 
95 void ConfigureWidget::readCurrentFallbackCodec()
96 {
97  const QStringList encodings = NodeHelper::supportedEncodings( false );
98  QStringList::ConstIterator it( encodings.constBegin() );
99  const QStringList::ConstIterator end( encodings.constEnd() );
100  const QString currentEncoding = MessageCore::GlobalSettings::self()->fallbackCharacterEncoding();
101  uint i = 0;
102  int indexOfLatin9 = 0;
103  bool found = false;
104  for( ; it != end; ++it ) {
105  const QString encoding = NodeHelper::encodingForName( *it );
106  if ( encoding == QLatin1String("ISO-8859-15") )
107  indexOfLatin9 = i;
108  if( encoding == currentEncoding ) {
109  mSettingsUi->fallbackCharacterEncoding->setCurrentIndex( i );
110  found = true;
111  break;
112  }
113  ++i;
114  }
115  if ( !found ) // nothing matched, use latin9
116  mSettingsUi->fallbackCharacterEncoding->setCurrentIndex( indexOfLatin9 );
117 }
118 
119 void ConfigureWidget::readCurrentOverrideCodec()
120 {
121  const QString &currentOverrideEncoding = MessageCore::GlobalSettings::self()->overrideCharacterEncoding();
122  if ( currentOverrideEncoding.isEmpty() ) {
123  mSettingsUi->overrideCharacterEncoding->setCurrentIndex( 0 );
124  return;
125  }
126  QStringList encodings = NodeHelper::supportedEncodings( false );
127  encodings.prepend( i18n( "Auto" ) );
128  QStringList::ConstIterator it( encodings.constBegin() );
129  const QStringList::ConstIterator end( encodings.constEnd() );
130  int i = 0;
131  for( ; it != end; ++it ) {
132  if( NodeHelper::encodingForName(*it) == currentOverrideEncoding ) {
133  mSettingsUi->overrideCharacterEncoding->setCurrentIndex( i );
134  break;
135  }
136  ++i;
137  }
138  if ( i == encodings.size() ) {
139  // the current value of overrideCharacterEncoding is an unknown encoding => reset to Auto
140  kWarning() << "Unknown override character encoding" << currentOverrideEncoding
141  << ". Resetting to Auto.";
142  mSettingsUi->overrideCharacterEncoding->setCurrentIndex( 0 );
143  MessageCore::GlobalSettings::self()->setOverrideCharacterEncoding( QString() );
144  }
145 }
146 
147 void ConfigureWidget::showCustomHeadersDialog()
148 {
149  QPointer<CustomHeaderSettingDialog> dlg = new CustomHeaderSettingDialog(this);
150  if ( dlg->exec() ) {
151  dlg->writeSettings();
152  settingsChanged();
153  }
154  delete dlg;
155 }
156 
QWidget::layout
QLayout * layout() const
globalsettings.h
QWidget
QLayout::setContentsMargins
void setContentsMargins(int left, int top, int right, int bottom)
MessageViewer::NodeHelper::supportedEncodings
static QStringList supportedEncodings(bool usAscii)
Return a list of the supported encodings.
Definition: nodehelper.cpp:710
MessageViewer::ConfigureWidget::readConfig
void readConfig()
Definition: configurewidget.cpp:74
QPointer
nodehelper.h
MessageViewer::CustomHeaderSettingDialog
Definition: customheadersettingdialog.h:25
QList::size
int size() const
MessageViewer::ConfigureWidget::settingsChanged
void settingsChanged()
Emitted when the user changes the setting in some widget.
MessageViewer::ConfigureWidget::~ConfigureWidget
~ConfigureWidget()
Definition: configurewidget.cpp:68
configurewidget.h
QString::isEmpty
bool isEmpty() const
MessageViewer::GlobalSettings::self
static GlobalSettings * self()
Definition: globalsettings.cpp:34
QString
util.h
QStringList
MessageViewer::NodeHelper::encodingForName
static QString encodingForName(const QString &descriptiveName)
Drop-in replacement for KCharsets::encodingForName().
Definition: nodehelper.cpp:704
customheadersettingdialog.h
QWidget::whatsThis
QString whatsThis() const
QLatin1String
QList::ConstIterator
typedef ConstIterator
QList::prepend
void prepend(const T &value)
MessageViewer::ConfigureWidget::ConfigureWidget
ConfigureWidget(QWidget *parent=0)
Definition: configurewidget.cpp:35
QList::constEnd
const_iterator constEnd() const
QList::constBegin
const_iterator constBegin() const
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
MessageViewer::ConfigureWidget::writeConfig
void writeConfig()
Definition: configurewidget.cpp:82
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:45 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

messageviewer

Skip menu "messageviewer"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal