• 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
charsetconversionjob.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 "charsetconversionjob.h"
24 
25 // Okteta core
26 #include <abstractbytearraymodel.h>
27 #include <charcodec.h>
28 #include <character.h>
29 // Qt
30 #include <QtGui/QApplication>
31 
32 
33 namespace Kasten2
34 {
35 
36 static const int CharsetConversionBlockSize = 100000;
37 
38 bool CharsetConversionJob::exec()
39 {
40  // reset
41  mConvertedBytesCount = 0;
42  mFailedPerByteCount.clear();
43 
44  // check
45  if( ! mByteArrayModel || ! mRange.isValid() )
46  {
47  deleteLater(); // TODO: could be reused on next operation
48 
49  return false;
50  }
51 
52  bool success = true;
53  int r = 0;
54  Okteta::Address i = mRange.start();
55  Okteta::Address blockEnd = mRange.start();
56  while( i <= mRange.end() && success )
57  {
58  blockEnd += CharsetConversionBlockSize;
59  if( blockEnd > mRange.end() )
60  blockEnd = mRange.end();
61 
62  for( ; i<=blockEnd && success; ++i )
63  {
64  Okteta::Byte convertedByte;
65  const Okteta::Byte originalByte = mByteArrayModel->byte(i);
66  const Okteta::Character decodedChar = mSourceCharCodec->decode( originalByte );
67  bool isConverted = ! decodedChar.isUndefined();
68  if( isConverted )
69  isConverted = mTargetCharCodec->encode( &convertedByte, decodedChar );
70 
71  if( ! isConverted )
72  {
73  if( ! mSubstitutingMissingChars )
74  {
75  success = false;
76  break;
77  }
78  mFailedPerByteCount[originalByte]++;
79  convertedByte = mSubstituteByte;
80  }
81 
82  // TODO: means if the default byte equals a not convertable original
83  // byte that one is not counted. okay, or should be made explicit to user?
84  if( originalByte != convertedByte )
85  mConvertedBytesCount++;
86 
87  mResult[r++] = convertedByte;
88  }
89 
90  QApplication::processEvents( QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers, 100 );
91  }
92 
93  deleteLater(); // TODO: could be reused on next operation
94 
95  return success;
96 }
97 
98 }
character.h
Okteta::Address
qint32 Address
Definition: address.h:34
abstractbytearraymodel.h
Kasten2::CharsetConversionJob::mResult
Okteta::Byte *const mResult
Definition: charsetconversionjob.h:64
KDE::Range::start
T start() const
Definition: range.h:86
charsetconversionjob.h
Okteta::Character::isUndefined
bool isUndefined() const
Definition: character.h:52
Okteta::Byte
unsigned char Byte
Definition: byte.h:29
Okteta::CharCodec::decode
virtual Character decode(Byte byte) const =0
Kasten2::CharsetConversionJob::mFailedPerByteCount
QMap< Okteta::Byte, int > mFailedPerByteCount
Definition: charsetconversionjob.h:75
Kasten2::CharsetConversionJob::mSourceCharCodec
const Okteta::CharCodec *const mSourceCharCodec
Definition: charsetconversionjob.h:68
Kasten2::CharsetConversionBlockSize
static const int CharsetConversionBlockSize
Definition: charsetconversionjob.cpp:36
KDE::Range::end
T end() const
Definition: range.h:88
Kasten2::CharsetConversionJob::mByteArrayModel
Okteta::AbstractByteArrayModel *const mByteArrayModel
Definition: charsetconversionjob.h:65
Kasten2::CharsetConversionJob::exec
bool exec()
Definition: charsetconversionjob.cpp:38
Kasten2::CharsetConversionJob::mSubstituteByte
Okteta::Byte mSubstituteByte
Definition: charsetconversionjob.h:72
Okteta::AbstractByteArrayModel::byte
virtual Byte byte(Address offset) const =0
locates working range The idea behind is to tell buffer which range will be requested in the followin...
Kasten2::CharsetConversionJob::mTargetCharCodec
const Okteta::CharCodec *const mTargetCharCodec
Definition: charsetconversionjob.h:69
charcodec.h
Okteta::CharCodec::encode
virtual bool encode(Byte *byte, const QChar &_char) const =0
Kasten2::CharsetConversionJob::mRange
const Okteta::AddressRange mRange
Definition: charsetconversionjob.h:66
Kasten2::CharsetConversionJob::mConvertedBytesCount
int mConvertedBytesCount
Definition: charsetconversionjob.h:74
KDE::Range::isValid
bool isValid() const
returns true if the range covers at least one index
Definition: range.h:122
Okteta::Character
Definition: character.h:35
Kasten2::CharsetConversionJob::mSubstitutingMissingChars
bool mSubstitutingMissingChars
Definition: charsetconversionjob.h:71
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