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

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • kasten
  • controllers
  • view
  • charsetconversion
charsetconversionview.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Kasten module, made within the KDE community.
3 
4  Copyright 2011 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "charsetconversionview.h"
24 
25 // tool
26 #include "charsetconversiontool.h"
27 // Okteta Kasten gui
28 #include <bytearraycombobox.h>
29 // Okteta core
30 #include <charcodec.h>
31 // KDE
32 #include <KMessageBox>
33 #include <KPushButton>
34 #include <KComboBox>
35 #include <KGuiItem>
36 #include <KLocale>
37 // Qt
38 #include <QtGui/QFormLayout>
39 #include <QtGui/QLayout>
40 #include <QtGui/QCheckBox>
41 #include <QtGui/QLabel>
42 #include <QtGui/QGroupBox>
43 
44 #include <KDebug>
45 
46 namespace Kasten2
47 {
48 
49 CharsetConversionView::CharsetConversionView( CharsetConversionTool* tool, QWidget* parent )
50  : QWidget( parent ),
51  mTool( tool )
52 {
53  QVBoxLayout* baseLayout = new QVBoxLayout( this );
54  baseLayout->setMargin( 0 );
55 
56  // source/target charset
57  QHBoxLayout* directionCharsetLayout = new QHBoxLayout();
58 
59  mDirectionComboBox = new KComboBox( this );
60  const QStringList directionList = QStringList()
61  << i18nc("@item:inmenu Is converted _from_ charset (selected in combobox next to this)",
62  "From")
63  << i18nc("@item:inmenu Is converted _to_ charset (selected in combobox next to this)",
64  "To");
65  mDirectionComboBox->addItems( directionList );
66  mDirectionComboBox->setCurrentIndex( mTool->conversionDirection() );
67 
68  const QString directionToolTip =
69  i18nc( "@info:tooltip",
70  "The direction the bytes are converted, to or from the selected charset." );
71  mDirectionComboBox->setToolTip( directionToolTip );
72  const QString directionWhatsThis =
73  i18nc( "@info:whatsthis",
74  "Select the direction the bytes are converted, to or from the selected charset." );
75  mDirectionComboBox->setWhatsThis( directionWhatsThis );
76  connect( mDirectionComboBox, SIGNAL(activated(int)),
77  mTool, SLOT(setConversionDirection(int)) );
78 
79  directionCharsetLayout->addWidget( mDirectionComboBox );
80 
81  mOtherCharSetComboBox = new KComboBox( this );
82  const QStringList charCodecNames = Okteta::CharCodec::codecNames();
83  const int indexOfCurrentCharCodec = charCodecNames.indexOf( mTool->otherCharCodecName() );
84  mOtherCharSetComboBox->addItems( charCodecNames );
85  mOtherCharSetComboBox->setCurrentIndex( indexOfCurrentCharCodec );
86 
87  const QString targetCharsetToolTip =
88  i18nc( "@info:tooltip",
89  "The charset the bytes are converted to." );
90  mOtherCharSetComboBox->setToolTip( targetCharsetToolTip );
91  const QString targetCharsetWhatsThis =
92  i18nc( "@info:whatsthis",
93  "Select the charset the bytes are converted to." );
94  mOtherCharSetComboBox->setWhatsThis( targetCharsetWhatsThis );
95  connect( mOtherCharSetComboBox, SIGNAL(activated(QString)),
96  mTool, SLOT(setOtherCharCodecName(QString)) );
97 
98  directionCharsetLayout->addWidget( mOtherCharSetComboBox, 10 );
99  baseLayout->addLayout( directionCharsetLayout );
100 
101  // settings
102  QGroupBox* settingsBox = new QGroupBox( i18nc("@title:group","Parameters"), this );
103 
104  QFormLayout* settingsLayout = new QFormLayout();
105 
106  const QString substituteMissingCharLabelText =
107  i18nc( "@option:check substitute bytes whose char is not part of the target charset",
108  "Substitute missing:" );
109  mSubstituteMissingCharCheckBox = new QCheckBox( this );
110  mSubstituteMissingCharCheckBox->setChecked( mTool->isSubstitutingMissingChars() );
111  const QString substituteMissingCharToolTip =
112  i18nc( "@info:tooltip",
113  "Selects if bytes should be substituted with a default byte "
114  "if its char in the source charset is not part of the target charset." );
115  const QString substituteMissingCharWhatsThis =
116  i18nc( "@info:whatsthis",
117  "Set to true if bytes should be substituted with a default byte "
118  "if its char in the source charset is not part of the target charset." );
119  mSubstituteMissingCharCheckBox->setToolTip( substituteMissingCharToolTip );
120  mSubstituteMissingCharCheckBox->setWhatsThis( substituteMissingCharWhatsThis );
121  connect( mSubstituteMissingCharCheckBox, SIGNAL(toggled(bool)),
122  mTool, SLOT(setSubstitutingMissingChars(bool)) );
123  settingsLayout->addRow( substituteMissingCharLabelText, mSubstituteMissingCharCheckBox );
124  // TODO: control what happens on conflicts or unmatched chars in the target set
125  // option to try only if no conflicts or unmatched chars are hit
126  // choosing substitute for unmatched and resolve conflicts (general/case-by-case)
127  // TODO: extra button to request check if all chars are matched, shows state
128  // TODO: option to switch view to target charset, once done, if "to" other charset
129 
130  // default byte
131  const QString substituteByteLabelText =
132  i18nc( "@label:textbox byte to use for chars which are not part of the target charset",
133  "Substitute byte:" );
134  mSubstituteByteEdit = new Okteta::ByteArrayComboBox( this );
135  mSubstituteByteEdit->setMinLength( 1 );
136  mSubstituteByteEdit->setMaxLength( 1 );
137  const QString substituteByteToolTip =
138  i18nc( "@info:tooltip",
139  "The byte to use for chars which are not part of the target charset." );
140  const QString substituteByteWhatsThis =
141  i18nc( "@info:whatsthis",
142  "Define the byte to use for chars which are not part of the target charset." );
143  mSubstituteByteEdit->setToolTip( substituteByteToolTip );
144  mSubstituteByteEdit->setWhatsThis( substituteByteWhatsThis );
145 // mSubstituteByteEdit->setEnabled( mTool->isSubstitutingMissingChars() );
146  mSubstituteByteEdit->setEnabled( false ); // TODO: fix char entering and enable again
147  connect( mSubstituteByteEdit, SIGNAL(byteArrayChanged(QByteArray)),
148  SLOT(onDefaultByteEditChanged(QByteArray)) );
149 // connect( mSubstituteMissingCharCheckBox, SIGNAL(toggled(bool)),
150 // mSubstituteByteEdit, SLOT(setEnabled(bool)) );
151  mSubstituteByteEdit->setByteArray( QByteArray(1, mTool->substituteByte()) );
152  settingsLayout->addRow( substituteByteLabelText, mSubstituteByteEdit );
153 
154  settingsBox->setLayout( settingsLayout );
155 
156  baseLayout->addWidget( settingsBox );
157 
158  // action
159  QHBoxLayout* actionsLayout = new QHBoxLayout();
160 
161  actionsLayout->addStretch();
162 
163  const KGuiItem convertGuiItem =
164  KGuiItem( i18n("Con&vert"),
165  QLatin1String("run-build"),
166  i18nc("@info:tooltip",
167  "Converts the bytes in the selected range."),
168  i18nc("@info:whatsthis",
169  "If you press the <interface>Convert</interface> button, "
170  "all bytes in the selected range "
171  "will be replaced by bytes which represent the same character "
172  "in the selected target charset.") );
173  mConvertButton = new KPushButton( convertGuiItem, this );
174  connect( mConvertButton, SIGNAL(clicked(bool)), SLOT(onConvertButtonClicked()) );
175  actionsLayout->addWidget( mConvertButton );
176 
177  baseLayout->addLayout( actionsLayout );
178  baseLayout->addStretch();
179 
180  connect( mTool, SIGNAL(isApplyableChanged(bool)),
181  SLOT(onApplyableChanged(bool)) );
182  connect( mTool, SIGNAL(conversionDone(bool,int,QMap<Okteta::Byte,int>)),
183  SLOT(onConversionDone(bool,int,QMap<Okteta::Byte,int>)) );
184 }
185 
186 
187 void CharsetConversionView::onApplyableChanged( bool isApplyable )
188 {
189  mConvertButton->setEnabled( isApplyable );
190 }
191 
192 void CharsetConversionView::onDefaultByteEditChanged( const QByteArray& byteArray )
193 {
194  Q_UNUSED( byteArray );
195 }
196 
197 void CharsetConversionView::onConvertButtonClicked()
198 {
199  mTool->convertChars();
200 }
201 
202 void CharsetConversionView::onConversionDone( bool success, int convertedBytesCount,
203  const QMap<Okteta::Byte, int>& failedPerByteCount )
204 {
205 
206  const QString messageBoxTitle = mTool->title();
207 
208  if( success )
209  {
210  QString conversionReport = (convertedBytesCount==0) ?
211  i18nc( "@info", "No bytes converted.") :
212  i18ncp( "@info", "1 byte converted.", "%1 bytes converted.", convertedBytesCount );
213  if( mTool->isSubstitutingMissingChars() )
214  {
215  int totalFailedByteCount = 0;
216  foreach( int failedByteCount, failedPerByteCount )
217  totalFailedByteCount += failedByteCount;
218  //TODO: show table with failed bytes and their number.
219  conversionReport += QLatin1String( "<br />" );
220  conversionReport += (totalFailedByteCount==0) ?
221  i18nc( "@info", "No bytes substituted.") :
222  i18ncp( "@info", "1 byte substituted.", "%1 bytes substituted.", totalFailedByteCount );
223  }
224  KMessageBox::information( /*mParentWidget*/0,
225  conversionReport,
226  messageBoxTitle );
227  }
228  else
229  {
230  // TODO: show/goto byte which on which conversion fails
231  KMessageBox::sorry( /*mParentWidget*/0,
232  i18nc("@info",
233  "Conversion cancelled because of chars which are not "
234  "in the target charset."),
235  messageBoxTitle );
236 
237  }
238 }
239 
240 CharsetConversionView::~CharsetConversionView() {}
241 
242 }
Kasten2::CharsetConversionTool::title
virtual QString title() const
Definition: charsetconversiontool.cpp:62
Okteta::ByteArrayComboBox::setMaxLength
void setMaxLength(int maxLength)
Definition: bytearraycombobox.cpp:54
charsetconversiontool.h
bytearraycombobox.h
Kasten2::CharsetConversionTool::isSubstitutingMissingChars
bool isSubstitutingMissingChars() const
Definition: charsetconversiontool.cpp:78
QWidget
Okteta::ByteArrayComboBox::setByteArray
void setByteArray(const QByteArray &byteArray)
Definition: bytearraycombobox.cpp:40
Okteta::ByteArrayComboBox::setMinLength
void setMinLength(int minLength)
Definition: bytearraycombobox.cpp:61
Okteta::CharCodec::codecNames
static const QStringList & codecNames()
Definition: charcodec.cpp:35
Kasten2::CharsetConversionTool::otherCharCodecName
QString otherCharCodecName() const
Definition: charsetconversiontool.cpp:68
Kasten2::CharsetConversionTool
Definition: charsetconversiontool.h:51
charcodec.h
Okteta::ByteArrayComboBox
Definition: bytearraycombobox.h:40
Kasten2::CharsetConversionTool::conversionDirection
ConversionDirection conversionDirection() const
Definition: charsetconversiontool.cpp:73
Kasten2::CharsetConversionView::~CharsetConversionView
virtual ~CharsetConversionView()
Definition: charsetconversionview.cpp:240
Kasten2::CharsetConversionView::CharsetConversionView
CharsetConversionView(CharsetConversionTool *tool, QWidget *parent=0)
Definition: charsetconversionview.cpp:49
Kasten2::CharsetConversionTool::convertChars
void convertChars()
Definition: charsetconversiontool.cpp:135
charsetconversionview.h
Kasten2::CharsetConversionTool::substituteByte
Okteta::Byte substituteByte() const
Definition: charsetconversiontool.cpp:83
QMap< Okteta::Byte, int >
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:07 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

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

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

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