• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kio

kremoteencoding.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002    Copyright (C) 2003 Thiago Macieira <thiago.macieira@kdemail.net>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License version 2 as published by the Free Software Foundation.
00007 
00008    This library is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY; without even the implied warranty of
00010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011    Library General Public License for more details.
00012 
00013    You should have received a copy of the GNU Library General Public License
00014    along with this library; see the file COPYING.LIB.  If not, write to
00015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00016    Boston, MA 02110-1301, USA.
00017 */
00018 
00019 #include <config.h>
00020 
00021 #include <kdebug.h>
00022 #include <kstringhandler.h>
00023 #include "kremoteencoding.h"
00024 
00025 KRemoteEncoding::KRemoteEncoding(const char *name)
00026   : codec(0L), d(0L)
00027 {
00028   setEncoding(name);
00029 }
00030 
00031 KRemoteEncoding::~KRemoteEncoding()
00032 {
00033   // delete d;      // not necessary yet
00034 }
00035 
00036 QString KRemoteEncoding::decode(const QCString& name) const
00037 {
00038 #ifdef CHECK_UTF8
00039   if (codec->mibEnum() == 106 && !KStringHandler::isUtf8(name))
00040     return QString::fromLatin1(name);
00041 #endif
00042 
00043   QString result = codec->toUnicode(name);
00044   if (codec->fromUnicode(result) != name)
00045     // fallback in case of decoding failure
00046     return QString::fromLatin1(name);
00047 
00048   return result;
00049 }
00050 
00051 QCString KRemoteEncoding::encode(const QString& name) const
00052 {
00053   QCString result = codec->fromUnicode(name);
00054   if (codec->toUnicode(result) != name)
00055     return name.latin1();
00056  
00057   return result;
00058 }
00059 
00060 QCString KRemoteEncoding::encode(const KURL& url) const
00061 {
00062   return encode(url.path());
00063 }
00064 
00065 QCString KRemoteEncoding::directory(const KURL& url, bool ignore_trailing_slash) const
00066 {
00067   QString dir = url.directory(true, ignore_trailing_slash);
00068 
00069   return encode(dir);
00070 }
00071 
00072 QCString KRemoteEncoding::fileName(const KURL& url) const
00073 {
00074   return encode(url.fileName());
00075 }
00076 
00077 void KRemoteEncoding::setEncoding(const char *name)
00078 {
00079   // don't delete codecs
00080 
00081   if (name)
00082     codec = QTextCodec::codecForName(name);
00083 
00084   if (codec == 0L)
00085     codec = QTextCodec::codecForMib(1);
00086 
00087   kdDebug() << k_funcinfo << "setting encoding " << codec->name() 
00088         << " for name=" << name << endl;
00089 }
00090 
00091 void KRemoteEncoding::virtual_hook(int, void*)
00092 {
00093 }

kio

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

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal