• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 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
27class KRemoteEncodingPrivate
28{
29 public:
30 KRemoteEncodingPrivate()
31 : m_codec(0)
32 {
33 }
34
35 QTextCodec *m_codec;
36};
37
38KRemoteEncoding::KRemoteEncoding(const char *name)
39 : d(new KRemoteEncodingPrivate)
40{
41 setEncoding(name);
42}
43
44KRemoteEncoding::~KRemoteEncoding()
45{
46 delete d;
47}
48
49QString 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
64QByteArray 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
73QByteArray KRemoteEncoding::encode(const KUrl& url) const
74{
75 return encode(url.path());
76}
77
78QByteArray 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
85QByteArray KRemoteEncoding::fileName(const KUrl& url) const
86{
87 return encode(url.fileName());
88}
89
90const char *KRemoteEncoding::encoding() const
91{
92 return d->m_codec->name();
93}
94
95int KRemoteEncoding::encodingMib() const
96{
97 return d->m_codec->mibEnum();
98}
99
100void 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
119void KRemoteEncoding::virtual_hook(int, void*)
120{
121}
KRemoteEncoding::decode
QString decode(const QByteArray &name) const
Converts the given full pathname or filename to Unicode.
Definition: kremoteencoding.cpp:49
KRemoteEncoding::setEncoding
void setEncoding(const char *name)
Sets the encoding being used.
Definition: kremoteencoding.cpp:100
KRemoteEncoding::KRemoteEncoding
KRemoteEncoding(const char *name=0)
Constructor.
Definition: kremoteencoding.cpp:38
KRemoteEncoding::~KRemoteEncoding
virtual ~KRemoteEncoding()
Destructor.
Definition: kremoteencoding.cpp:44
KRemoteEncoding::encode
QByteArray encode(const QString &name) const
Converts the given name from Unicode.
Definition: kremoteencoding.cpp:64
KRemoteEncoding::encodingMib
int encodingMib() const
Returns the MIB for the codec being used.
Definition: kremoteencoding.cpp:95
KRemoteEncoding::encoding
const char * encoding() const
Returns the encoding being used.
Definition: kremoteencoding.cpp:90
KRemoteEncoding::directory
QByteArray directory(const KUrl &url, bool ignore_trailing_slash=true) const
Converts the given URL into 8-bit form and separate the dirname from the filename.
Definition: kremoteencoding.cpp:78
KRemoteEncoding::virtual_hook
virtual void virtual_hook(int id, void *data)
Definition: kremoteencoding.cpp:119
KRemoteEncoding::fileName
QByteArray fileName(const KUrl &url) const
Converts the given URL into 8-bit form and retrieve the filename.
Definition: kremoteencoding.cpp:85
KUrl
KUrl::ObeyTrailingSlash
ObeyTrailingSlash
KUrl::IgnoreTrailingSlash
IgnoreTrailingSlash
KUrl::path
QString path(AdjustPathOption trailing=LeaveTrailingSlash) const
KUrl::directory
QString directory(const DirectoryOptions &options=IgnoreTrailingSlash) const
KUrl::fileName
QString fileName(const DirectoryOptions &options=IgnoreTrailingSlash) const
kDebug
#define kDebug
kdebug.h
kremoteencoding.h
kstringhandler.h
name
const char * name(StandardAction id)
KStringHandler::isUtf8
bool isUtf8(const char *str)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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.14.38 API Reference

Skip menu "kdelibs-4.14.38 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