• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.5 API Reference
  • KDE Home
  • Contact Us
 

KIO

  • kio
  • kio
kremoteencoding.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2003 Thiago Macieira <thiago.macieira@kdemail.net>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include "kremoteencoding.h"
20 
21 #include <config.h>
22 
23 #include <kdebug.h>
24 #include <kstringhandler.h>
25 
26 
27 class KRemoteEncodingPrivate
28 {
29  public:
30  KRemoteEncodingPrivate()
31  : m_codec(0)
32  {
33  }
34 
35  QTextCodec *m_codec;
36 };
37 
38 KRemoteEncoding::KRemoteEncoding(const char *name)
39  : d(new KRemoteEncodingPrivate)
40 {
41  setEncoding(name);
42 }
43 
44 KRemoteEncoding::~KRemoteEncoding()
45 {
46  delete d;
47 }
48 
49 QString KRemoteEncoding::decode(const QByteArray& name) const
50 {
51 #ifdef CHECK_UTF8
52  if (d->m_codec->mibEnum() == 106 && !KStringHandler::isUtf8(name))
53  return QLatin1String(name);
54 #endif
55 
56  QString result = d->m_codec->toUnicode(name);
57  if (d->m_codec->fromUnicode(result) != name)
58  // fallback in case of decoding failure
59  return QLatin1String(name);
60 
61  return result;
62 }
63 
64 QByteArray KRemoteEncoding::encode(const QString& name) const
65 {
66  QByteArray result = d->m_codec->fromUnicode(name);
67  if (d->m_codec->toUnicode(result) != name)
68  return name.toLatin1();
69 
70  return result;
71 }
72 
73 QByteArray KRemoteEncoding::encode(const KUrl& url) const
74 {
75  return encode(url.path());
76 }
77 
78 QByteArray KRemoteEncoding::directory(const KUrl& url, bool ignore_trailing_slash) const
79 {
80  QString dir = url.directory(ignore_trailing_slash ? KUrl::DirectoryOptions(KUrl::IgnoreTrailingSlash) : KUrl::ObeyTrailingSlash);
81 
82  return encode(dir);
83 }
84 
85 QByteArray KRemoteEncoding::fileName(const KUrl& url) const
86 {
87  return encode(url.fileName());
88 }
89 
90 const char *KRemoteEncoding::encoding() const
91 {
92  return d->m_codec->name();
93 }
94 
95 int KRemoteEncoding::encodingMib() const
96 {
97  return d->m_codec->mibEnum();
98 }
99 
100 void KRemoteEncoding::setEncoding(const char *name)
101 {
102  // don't delete codecs
103 
104  if (name)
105  d->m_codec = QTextCodec::codecForName(name);
106 
107  if (d->m_codec == 0)
108  d->m_codec = QTextCodec::codecForMib( 106 ); // fallback to UTF-8
109 
110  if (d->m_codec == 0)
111  d->m_codec = QTextCodec::codecForMib(4 /* latin-1 */);
112 
113  Q_ASSERT(d->m_codec);
114 
115  kDebug() << "setting encoding" << d->m_codec->name()
116  << "for name=" << name;
117 }
118 
119 void KRemoteEncoding::virtual_hook(int, void*)
120 {
121 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Mon Jul 15 2013 13:06:13 by doxygen 1.8.3.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIO

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

kdelibs-4.10.5 API Reference

Skip menu "kdelibs-4.10.5 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
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