mirror of
https://bitbucket.org/smil3y/kdelibs.git
synced 2025-02-23 10:22:48 +00:00
kio: drop KRemoteEncoding class
can be done by slaves via custom QTextConverter or whatever, the converter is using Charset metadata and the KRemoteEncoding class is not required outside the slaves Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
1a5f247e86
commit
97e7649bd3
8 changed files with 48 additions and 247 deletions
|
@ -201,7 +201,6 @@ install(
|
|||
KRecentDocument
|
||||
KRecentFilesAction
|
||||
KRecursiveFilterProxyModel
|
||||
KRemoteEncoding
|
||||
KReplace
|
||||
KReplaceDialog
|
||||
KRestrictedLine
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
#include "../kremoteencoding.h"
|
|
@ -58,7 +58,6 @@ set(kiocore_STAT_SRCS
|
|||
kio/kfilemetadata.cpp
|
||||
kio/kmimetypechooser.cpp
|
||||
kio/kprotocolmanager.cpp
|
||||
kio/kremoteencoding.cpp
|
||||
kio/krun.cpp
|
||||
kio/kurifilter.cpp
|
||||
kio/kurlcompletion.cpp
|
||||
|
@ -237,7 +236,6 @@ install(
|
|||
kio/kfilemetadata.h
|
||||
kio/kmimetypechooser.h
|
||||
kio/kprotocolmanager.h
|
||||
kio/kremoteencoding.h
|
||||
kio/krun.h
|
||||
kio/kurifilter.h
|
||||
kio/kurlcompletion.h
|
||||
|
|
|
@ -1,103 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2003 Thiago Macieira <thiago.macieira@kdemail.net>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "kremoteencoding.h"
|
||||
|
||||
#include <QTextConverter>
|
||||
#include <kdebug.h>
|
||||
|
||||
class KRemoteEncodingPrivate
|
||||
{
|
||||
public:
|
||||
KRemoteEncodingPrivate()
|
||||
: converter(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
~KRemoteEncodingPrivate()
|
||||
{
|
||||
delete converter;
|
||||
}
|
||||
|
||||
QByteArray name;
|
||||
QTextConverter* converter;
|
||||
};
|
||||
|
||||
KRemoteEncoding::KRemoteEncoding(const char *name)
|
||||
: d(new KRemoteEncodingPrivate())
|
||||
{
|
||||
setEncoding(name);
|
||||
}
|
||||
|
||||
KRemoteEncoding::~KRemoteEncoding()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
QString KRemoteEncoding::decode(const QByteArray& name) const
|
||||
{
|
||||
d->converter->reset();
|
||||
const QString result = d->converter->toUnicode(name);
|
||||
if (d->converter->hasFailure()) {
|
||||
// fallback in case of decoding failure
|
||||
return QString::fromLatin1(name.constData(), name.size());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QByteArray KRemoteEncoding::encode(const QString& name) const
|
||||
{
|
||||
d->converter->reset();
|
||||
const QByteArray result = d->converter->fromUnicode(name);
|
||||
if (d->converter->hasFailure()) {
|
||||
return name.toLatin1();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QByteArray KRemoteEncoding::encode(const KUrl &url) const
|
||||
{
|
||||
return encode(url.path());
|
||||
}
|
||||
|
||||
QByteArray KRemoteEncoding::directory(const KUrl &url, bool ignore_trailing_slash) const
|
||||
{
|
||||
return encode(url.directory(ignore_trailing_slash ? KUrl::KUrl::RemoveTrailingSlash : KUrl::LeaveTrailingSlash));
|
||||
}
|
||||
|
||||
QByteArray KRemoteEncoding::fileName(const KUrl &url) const
|
||||
{
|
||||
return encode(url.fileName());
|
||||
}
|
||||
|
||||
const char *KRemoteEncoding::encoding() const
|
||||
{
|
||||
return d->name.constData();
|
||||
}
|
||||
|
||||
void KRemoteEncoding::setEncoding(const char *name)
|
||||
{
|
||||
delete d->converter;
|
||||
d->name = name;
|
||||
if (d->name.isEmpty()) {
|
||||
d->name = "UTF-8";
|
||||
}
|
||||
d->converter = new QTextConverter(d->name);
|
||||
kDebug() << "setting encoding to" << d->name;
|
||||
}
|
||||
|
|
@ -1,109 +0,0 @@
|
|||
/* This file is part of the KDE libraries
|
||||
Copyright (C) 2003 Thiago Macieira <thiago.macieira@kdemail.net>
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License version 2 as published by the Free Software Foundation.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Library General Public License
|
||||
along with this library; see the file COPYING.LIB. If not, write to
|
||||
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#ifndef KREMOTEENCODING_H
|
||||
#define KREMOTEENCODING_H
|
||||
|
||||
#include <kio/kio_export.h>
|
||||
#include <kurl.h>
|
||||
|
||||
class KRemoteEncodingPrivate;
|
||||
/**
|
||||
* Allows encoding and decoding properly remote filenames into Unicode.
|
||||
*
|
||||
* Certain protocols do not specify an appropriate encoding for decoding
|
||||
* their 8-bit data into proper Unicode forms. Therefore, ioslaves should
|
||||
* use this class in order to convert those forms into QStrings before
|
||||
* creating the respective KIO::UDSEntry. The same is true for decoding
|
||||
* URLs to its components.
|
||||
*
|
||||
* Each KIO::SlaveBase has one object of this kind, even if it is not necessary.
|
||||
* It can be accessed through KIO::SlaveBase::remoteEncoding.
|
||||
*
|
||||
* @short A class for handling remote filenames
|
||||
* @author Thiago Macieira <thiago.macieira@kdemail.net>
|
||||
*/
|
||||
class KIO_EXPORT KRemoteEncoding
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* Constructs this object to use the given encoding name.
|
||||
* If @p name is a null pointer, the standard encoding will be used.
|
||||
*/
|
||||
explicit KRemoteEncoding(const char *name = nullptr);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*/
|
||||
virtual ~KRemoteEncoding();
|
||||
|
||||
/**
|
||||
* Converts the given full pathname or filename to Unicode.
|
||||
* This function is supposed to work for dirnames, filenames
|
||||
* or a full pathname.
|
||||
*/
|
||||
QString decode(const QByteArray &name) const;
|
||||
|
||||
/**
|
||||
* Converts the given name from Unicode.
|
||||
* This function is supposed to work for dirnames, filenames
|
||||
* or a full pathname.
|
||||
*/
|
||||
QByteArray encode(const QString &name) const;
|
||||
|
||||
/**
|
||||
* Converts the given URL into its 8-bit components
|
||||
*/
|
||||
QByteArray encode(const KUrl &url) const;
|
||||
|
||||
/**
|
||||
* Converts the given URL into 8-bit form and separate the
|
||||
* dirname from the filename. This is useful for slave functions
|
||||
* like stat or get.
|
||||
*
|
||||
* The dirname is returned with the final slash always stripped
|
||||
*/
|
||||
QByteArray directory(const KUrl &url, bool ignore_trailing_slash = true) const;
|
||||
|
||||
/**
|
||||
* Converts the given URL into 8-bit form and retrieve the filename.
|
||||
*/
|
||||
QByteArray fileName(const KUrl &url) const;
|
||||
|
||||
/**
|
||||
* Returns the encoding being used.
|
||||
*/
|
||||
const char* encoding() const;
|
||||
|
||||
/**
|
||||
* Sets the encoding being used.
|
||||
* This function does not change the global configuration.
|
||||
*
|
||||
* Pass a null pointer in @p name to revert to the standard
|
||||
* encoding.
|
||||
*/
|
||||
void setEncoding(const char* name);
|
||||
|
||||
private:
|
||||
KRemoteEncodingPrivate* const d;
|
||||
Q_DISABLE_COPY(KRemoteEncoding)
|
||||
};
|
||||
|
||||
#endif
|
|
@ -32,11 +32,12 @@
|
|||
#include <signal.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <QtCore/QBuffer>
|
||||
#include <QtCore/QFile>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QElapsedTimer>
|
||||
#include <QtCore/QCoreApplication>
|
||||
#include <QBuffer>
|
||||
#include <QFile>
|
||||
#include <QTextConverter>
|
||||
#include <QList>
|
||||
#include <QElapsedTimer>
|
||||
#include <QCoreApplication>
|
||||
|
||||
#include "kdebug.h"
|
||||
#include "kcrash.h"
|
||||
|
@ -47,7 +48,6 @@
|
|||
#include "kpassworddialog.h"
|
||||
#include "kwindowsystem.h"
|
||||
#include "kpasswdstore.h"
|
||||
#include "kremoteencoding.h"
|
||||
#include "connection_p.h"
|
||||
#include "ioslave_defaults.h"
|
||||
#include "slaveinterface_p.h"
|
||||
|
@ -144,7 +144,7 @@ public:
|
|||
|
||||
struct timeval last_tv;
|
||||
KIO::filesize_t totalSize;
|
||||
KRemoteEncoding *remotefile;
|
||||
QTextConverter *converter;
|
||||
time_t timeout;
|
||||
enum { Idle, InsideMethod, FinishedCalled, ErrorCalled } m_state;
|
||||
QByteArray timeoutData;
|
||||
|
@ -206,7 +206,7 @@ SlaveBasePrivate::SlaveBasePrivate(const QByteArray &protocol)
|
|||
config(nullptr),
|
||||
configGroup(nullptr),
|
||||
totalSize(0),
|
||||
remotefile(nullptr),
|
||||
converter(nullptr),
|
||||
timeout(0),
|
||||
m_passwdStore(nullptr),
|
||||
m_protocol(protocol)
|
||||
|
@ -283,7 +283,7 @@ SlaveBase::~SlaveBase()
|
|||
{
|
||||
delete d->configGroup;
|
||||
delete d->config;
|
||||
delete d->remotefile;
|
||||
delete d->converter;
|
||||
delete d;
|
||||
}
|
||||
|
||||
|
@ -365,13 +365,30 @@ void SlaveBase::sendMetaData()
|
|||
d->m_outgoingMetaData.clear();
|
||||
}
|
||||
|
||||
KRemoteEncoding *SlaveBase::remoteEncoding()
|
||||
QString SlaveBase::decodeName(const QByteArray &name) const
|
||||
{
|
||||
if (d->remotefile) {
|
||||
return d->remotefile;
|
||||
if (!d->converter) {
|
||||
d->converter = new QTextConverter(metaData(QLatin1String("Charset")).toLatin1());
|
||||
}
|
||||
const QByteArray charset (metaData(QLatin1String("Charset")).toLatin1());
|
||||
return (d->remotefile = new KRemoteEncoding(charset));
|
||||
d->converter->reset();
|
||||
const QString result = d->converter->toUnicode(name);
|
||||
if (d->converter->hasFailure()) {
|
||||
return QString::fromLatin1(name.constData(), name.size());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QByteArray SlaveBase::encodeName(const QString &name) const
|
||||
{
|
||||
if (!d->converter) {
|
||||
d->converter = new QTextConverter(metaData(QLatin1String("Charset")).toLatin1());
|
||||
}
|
||||
d->converter->reset();
|
||||
const QByteArray result = d->converter->fromUnicode(name);
|
||||
if (d->converter->hasFailure()) {
|
||||
return name.toLatin1();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void SlaveBase::data(const QByteArray &data)
|
||||
|
@ -631,8 +648,8 @@ void SlaveBase::chown(KUrl const &, const QString &, const QString &)
|
|||
|
||||
void SlaveBase::reparseConfiguration()
|
||||
{
|
||||
delete d->remotefile;
|
||||
d->remotefile = nullptr;
|
||||
delete d->converter;
|
||||
d->converter = nullptr;
|
||||
}
|
||||
|
||||
bool SlaveBase::openPasswordDialog(AuthInfo& info, const QString &errorMsg)
|
||||
|
@ -833,8 +850,8 @@ void SlaveBase::dispatch(int command, const QByteArray &data)
|
|||
case CMD_CONFIG: {
|
||||
stream >> d->configData;
|
||||
d->rebuildConfig();
|
||||
delete d->remotefile;
|
||||
d->remotefile = nullptr;
|
||||
delete d->converter;
|
||||
d->converter = nullptr;
|
||||
break;
|
||||
}
|
||||
case CMD_GET: {
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include <klocale.h>
|
||||
|
||||
class KConfigGroup;
|
||||
class KRemoteEncoding;
|
||||
class KUrl;
|
||||
|
||||
namespace KIO {
|
||||
|
@ -253,10 +252,14 @@ public:
|
|||
KConfigGroup* config();
|
||||
|
||||
/**
|
||||
* Returns an object that can translate remote filenames into proper
|
||||
* Unicode forms. This encoding can be set by the user.
|
||||
* Converts the given name to Unicode.
|
||||
*/
|
||||
KRemoteEncoding* remoteEncoding();
|
||||
QString decodeName(const QByteArray &name) const;
|
||||
|
||||
/**
|
||||
* Converts the given name from Unicode.
|
||||
*/
|
||||
QByteArray encodeName(const QString &name) const;
|
||||
|
||||
/**
|
||||
* get, aka read.
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "kio_curl.h"
|
||||
#include "kcomponentdata.h"
|
||||
#include "kmimetype.h"
|
||||
#include "kremoteencoding.h"
|
||||
#include "kconfiggroup.h"
|
||||
#include "kstandarddirs.h"
|
||||
#include "kmessagebox.h"
|
||||
|
@ -609,7 +608,7 @@ void CurlProtocol::put(const KUrl &url, int permissions, KIO::JobFlags flags)
|
|||
const QByteArray putpermissions = ftpPermissions(permissions);
|
||||
kDebug(7103) << "Filename" << putfilename << "permissions" << putpermissions;
|
||||
|
||||
const QByteArray putfilenamebytes = remoteEncoding()->encode(putfilename);
|
||||
const QByteArray putfilenamebytes = SlaveBase::encodeName(putfilename);
|
||||
m_curlquotes = curl_slist_append(m_curlquotes, QByteArray("SITE CHMOD ") + putpermissions + " " + putfilenamebytes);
|
||||
curlresult = curl_easy_setopt(m_curl, CURLOPT_POSTQUOTE, m_curlquotes);
|
||||
if (curlresult != CURLE_OK) {
|
||||
|
@ -659,7 +658,7 @@ void CurlProtocol::chmod(const KUrl &url, int permissions)
|
|||
return;
|
||||
}
|
||||
|
||||
const QByteArray chmodfilenamebytes = remoteEncoding()->encode(chmodfilename);
|
||||
const QByteArray chmodfilenamebytes = SlaveBase::encodeName(chmodfilename);
|
||||
m_curlquotes = curl_slist_append(m_curlquotes, QByteArray("SITE CHMOD ") + chmodpermissions + " " + chmodfilenamebytes);
|
||||
CURLcode curlresult = curl_easy_setopt(m_curl, CURLOPT_QUOTE, m_curlquotes);
|
||||
if (curlresult != CURLE_OK) {
|
||||
|
@ -708,7 +707,7 @@ void CurlProtocol::mkdir(const KUrl &url, int permissions)
|
|||
return;
|
||||
}
|
||||
|
||||
const QByteArray mkdirfilenamebytes = remoteEncoding()->encode(mkdirfilename);
|
||||
const QByteArray mkdirfilenamebytes = SlaveBase::encodeName(mkdirfilename);
|
||||
m_curlquotes = curl_slist_append(m_curlquotes, QByteArray("MKD ") + mkdirfilenamebytes);
|
||||
m_curlquotes = curl_slist_append(m_curlquotes, QByteArray("SITE CHMOD ") + mkdirpermissions + " " + mkdirfilenamebytes);
|
||||
CURLcode curlresult = curl_easy_setopt(m_curl, CURLOPT_QUOTE, m_curlquotes);
|
||||
|
@ -757,7 +756,7 @@ void CurlProtocol::del(const KUrl &url, bool isfile)
|
|||
return;
|
||||
}
|
||||
|
||||
const QByteArray delfilenamebytes = remoteEncoding()->encode(delfilename);
|
||||
const QByteArray delfilenamebytes = SlaveBase::encodeName(delfilename);
|
||||
if (isfile) {
|
||||
m_curlquotes = curl_slist_append(m_curlquotes, QByteArray("DELE ") + delfilenamebytes);
|
||||
} else {
|
||||
|
@ -1139,8 +1138,6 @@ QList<KIO::UDSEntry> CurlProtocol::udsEntries()
|
|||
{
|
||||
QList<KIO::UDSEntry> result;
|
||||
|
||||
kDebug(7103) << "Encoding" << remoteEncoding()->encoding();
|
||||
|
||||
// sample line:
|
||||
// drwxr-xr-x 1 nobody nobody 512 Mar 19 19:17 .
|
||||
static const QByteArray linkseparator = QByteArray("->");
|
||||
|
@ -1206,7 +1203,7 @@ QList<KIO::UDSEntry> CurlProtocol::udsEntries()
|
|||
KIO::UDSEntry kioudsentry;
|
||||
const mode_t stdmode = ftpModeFromString(ftpmode);
|
||||
const qlonglong ftpmodtime = ftpTimeFromString(ftpmonth, ftpday, ftphouroryear, currentdate.year());
|
||||
kioudsentry.insert(KIO::UDSEntry::UDS_NAME, remoteEncoding()->decode(ftpfilepath));
|
||||
kioudsentry.insert(KIO::UDSEntry::UDS_NAME, SlaveBase::decodeName(ftpfilepath));
|
||||
kioudsentry.insert(KIO::UDSEntry::UDS_FILE_TYPE, stdmode & S_IFMT);
|
||||
kioudsentry.insert(KIO::UDSEntry::UDS_ACCESS, stdmode & 07777);
|
||||
kioudsentry.insert(KIO::UDSEntry::UDS_SIZE, ftpsize);
|
||||
|
@ -1216,7 +1213,7 @@ QList<KIO::UDSEntry> CurlProtocol::udsEntries()
|
|||
if (!ftplinkpath.isEmpty()) {
|
||||
// link paths to current path causes KIO to do strange things
|
||||
if (ftplinkpath.at(0) != '.' && ftplinkpath.size() != 1) {
|
||||
kioudsentry.insert(KIO::UDSEntry::UDS_LINK_DEST, remoteEncoding()->decode(ftplinkpath));
|
||||
kioudsentry.insert(KIO::UDSEntry::UDS_LINK_DEST, SlaveBase::decodeName(ftplinkpath));
|
||||
}
|
||||
if (ftpsize <= 0) {
|
||||
kioudsentry.insert(KIO::UDSEntry::UDS_GUESSED_MIME_TYPE, QString::fromLatin1("application/x-zerosize"));
|
||||
|
|
Loading…
Add table
Reference in a new issue