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

messageviewer

  • sources
  • kde-4.12
  • 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 
22 #include "ui_settings.h"
23 #include "utils/util.h"
24 #include "settings/globalsettings.h"
25 #include "viewer/nodehelper.h"
26 
27 #include "header/customheadersettingwidget.h"
28 
29 #include "messagecore/settings/globalsettings.h"
30 
31 #include <KConfigDialogManager>
32 #include <KDialog>
33 
34 using namespace MessageViewer;
35 
36 ConfigureWidget::ConfigureWidget( QWidget *parent )
37  : QWidget( parent )
38 {
39  mSettingsUi = new Ui_Settings;
40  mSettingsUi->setupUi( this );
41  layout()->setContentsMargins( 0, 0, 0, 0 );
42 
43  QStringList encodings = NodeHelper::supportedEncodings( false );
44  mSettingsUi->fallbackCharacterEncoding->addItems( encodings );
45  encodings.prepend( i18n( "Auto" ) );
46  mSettingsUi->overrideCharacterEncoding->addItems( encodings );
47  mSettingsUi->overrideCharacterEncoding->setCurrentIndex( 0 );
48 
49  mSettingsUi->fallbackCharacterEncoding->setWhatsThis(
50  MessageCore::GlobalSettings::self()->fallbackCharacterEncodingItem()->whatsThis() );
51  mSettingsUi->overrideCharacterEncoding->setWhatsThis(
52  MessageCore::GlobalSettings::self()->overrideCharacterEncodingItem()->whatsThis() );
53  mSettingsUi->kcfg_ShowEmoticons->setWhatsThis(
54  GlobalSettings::self()->showEmoticonsItem()->whatsThis() );
55  mSettingsUi->kcfg_ShrinkQuotes->setWhatsThis(
56  GlobalSettings::self()->shrinkQuotesItem()->whatsThis() );
57  mSettingsUi->kcfg_ShowExpandQuotesMark->setWhatsThis(
58  GlobalSettings::self()->showExpandQuotesMarkItem()->whatsThis() );
59 
60  connect( mSettingsUi->fallbackCharacterEncoding, SIGNAL(currentIndexChanged(int)),
61  this, SIGNAL(settingsChanged()) );
62  connect( mSettingsUi->overrideCharacterEncoding, SIGNAL(currentIndexChanged(int)),
63  this, SIGNAL(settingsChanged()) );
64 
65  connect( mSettingsUi->configureCustomHeadersButton, SIGNAL(clicked()),
66  this, SLOT(showCustomHeadersDialog()) );
67 }
68 
69 ConfigureWidget::~ConfigureWidget()
70 {
71  delete mSettingsUi;
72  mSettingsUi = 0;
73 }
74 
75 void ConfigureWidget::readConfig()
76 {
77  readCurrentFallbackCodec();
78  readCurrentOverrideCodec();
79  mSettingsUi->kcfg_CollapseQuoteLevelSpin->setEnabled(
80  GlobalSettings::self()->showExpandQuotesMark() );
81 }
82 
83 void ConfigureWidget::writeConfig()
84 {
85  MessageCore::GlobalSettings::self()->setFallbackCharacterEncoding(
86  NodeHelper::encodingForName( mSettingsUi->fallbackCharacterEncoding->currentText() ) );
87  MessageCore::GlobalSettings::self()->setOverrideCharacterEncoding(
88  mSettingsUi->overrideCharacterEncoding->currentIndex() == 0 ?
89  QString() :
90  NodeHelper::encodingForName( mSettingsUi->overrideCharacterEncoding->currentText() ) );
91 
92  KMime::setFallbackCharEncoding( NodeHelper::encodingForName( mSettingsUi->fallbackCharacterEncoding->currentText() ) );
93 
94 }
95 
96 void ConfigureWidget::readCurrentFallbackCodec()
97 {
98  const QStringList encodings = NodeHelper::supportedEncodings( false );
99  QStringList::ConstIterator it( encodings.constBegin() );
100  const QStringList::ConstIterator end( encodings.constEnd() );
101  const QString currentEncoding = MessageCore::GlobalSettings::self()->fallbackCharacterEncoding();
102  uint i = 0;
103  int indexOfLatin9 = 0;
104  bool found = false;
105  for( ; it != end; ++it ) {
106  const QString encoding = NodeHelper::encodingForName( *it );
107  if ( encoding == QLatin1String("ISO-8859-15") )
108  indexOfLatin9 = i;
109  if( encoding == currentEncoding ) {
110  mSettingsUi->fallbackCharacterEncoding->setCurrentIndex( i );
111  found = true;
112  break;
113  }
114  ++i;
115  }
116  if ( !found ) // nothing matched, use latin9
117  mSettingsUi->fallbackCharacterEncoding->setCurrentIndex( indexOfLatin9 );
118 }
119 
120 void ConfigureWidget::readCurrentOverrideCodec()
121 {
122  const QString &currentOverrideEncoding = MessageCore::GlobalSettings::self()->overrideCharacterEncoding();
123  if ( currentOverrideEncoding.isEmpty() ) {
124  mSettingsUi->overrideCharacterEncoding->setCurrentIndex( 0 );
125  return;
126  }
127  QStringList encodings = NodeHelper::supportedEncodings( false );
128  encodings.prepend( i18n( "Auto" ) );
129  QStringList::ConstIterator it( encodings.constBegin() );
130  const QStringList::ConstIterator end( encodings.constEnd() );
131  int i = 0;
132  for( ; it != end; ++it ) {
133  if( NodeHelper::encodingForName(*it) == currentOverrideEncoding ) {
134  mSettingsUi->overrideCharacterEncoding->setCurrentIndex( i );
135  break;
136  }
137  ++i;
138  }
139  if ( i == encodings.size() ) {
140  // the current value of overrideCharacterEncoding is an unknown encoding => reset to Auto
141  kWarning() << "Unknown override character encoding" << currentOverrideEncoding
142  << ". Resetting to Auto.";
143  mSettingsUi->overrideCharacterEncoding->setCurrentIndex( 0 );
144  MessageCore::GlobalSettings::self()->setOverrideCharacterEncoding( QString() );
145  }
146 }
147 
148 void ConfigureWidget::showCustomHeadersDialog()
149 {
150  KDialog dialog( this );
151  dialog.setButtons( KDialog::Default | KDialog::Ok | KDialog::Cancel );
152  dialog.resize(500,250);
153  CustomHeaderSettingWidget *widget = new CustomHeaderSettingWidget();
154  connect( &dialog, SIGNAL(defaultClicked()), widget, SLOT(resetToDefault()) );
155  widget->readConfig();
156  dialog.setMainWidget( widget );
157  if ( dialog.exec() == QDialog::Accepted ) {
158  widget->writeConfig();
159  settingsChanged();
160  }
161 }
162 
163 #include "configurewidget.moc"
globalsettings.h
MessageViewer::CustomHeaderSettingWidget
Definition: customheadersettingwidget.h:33
MessageViewer::NodeHelper::supportedEncodings
static QStringList supportedEncodings(bool usAscii)
Return a list of the supported encodings.
Definition: nodehelper.cpp:708
MessageViewer::ConfigureWidget::readConfig
void readConfig()
Definition: configurewidget.cpp:75
QWidget
MessageViewer::CustomHeaderSettingWidget::readConfig
void readConfig()
Definition: customheadersettingwidget.cpp:77
KDialog
nodehelper.h
customheadersettingwidget.h
MessageViewer::ConfigureWidget::settingsChanged
void settingsChanged()
Emitted when the user changes the setting in some widget.
MessageViewer::ConfigureWidget::~ConfigureWidget
~ConfigureWidget()
Definition: configurewidget.cpp:69
configurewidget.h
MessageViewer::GlobalSettings::self
static GlobalSettings * self()
Definition: globalsettings.cpp:34
util.h
MessageViewer::NodeHelper::encodingForName
static QString encodingForName(const QString &descriptiveName)
Drop-in replacement for KCharsets::encodingForName().
Definition: nodehelper.cpp:702
MessageViewer::CustomHeaderSettingWidget::writeConfig
void writeConfig()
Definition: customheadersettingwidget.cpp:94
MessageViewer::ConfigureWidget::ConfigureWidget
ConfigureWidget(QWidget *parent=0)
Definition: configurewidget.cpp:36
MessageViewer::ConfigureWidget::writeConfig
void writeConfig()
Definition: configurewidget.cpp:83
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:57 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

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