1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2003 Thiago Macieira <thiago.macieira@kdemail.net>
4
5 SPDX-License-Identifier: LGPL-2.0-only
6*/
7
8#ifndef KREMOTEENCODING_H
9#define KREMOTEENCODING_H
10
11#include "kiocore_export.h"
12#include <QByteArray>
13#include <QString>
14
15#include <memory>
16
17class QUrl;
18class KRemoteEncodingPrivate;
19/*!
20 * \class KRemoteEncoding
21 * \inmodule KIOCore
22 *
23 * \brief Allows encoding and decoding properly remote filenames into Unicode.
24 *
25 * Certain protocols do not specify an appropriate encoding for decoding
26 * their 8-bit data into proper Unicode forms. Therefore, KIO workers should
27 * use this class in order to convert those forms into QStrings before
28 * creating the respective KIO::UDSEntry. The same is true for decoding
29 * URLs to its components.
30 *
31 * Each KIO::WorkerBase has one object of this kind, even if it is not necessary.
32 * It can be accessed through KIO::WorkerBase::remoteEncoding.
33 */
34class KIOCORE_EXPORT KRemoteEncoding
35{
36public:
37 /*!
38 * Constructor.
39 *
40 * Constructs this object to use the given encoding name.
41 * If \a name is a null pointer, the standard encoding will be used.
42 */
43 explicit KRemoteEncoding(const char *name = nullptr);
44
45 virtual ~KRemoteEncoding();
46
47 /*!
48 * Converts the given full pathname or filename to Unicode.
49 * This function is supposed to work for dirnames, filenames
50 * or a full pathname.
51 */
52 QString decode(const QByteArray &name) const;
53
54 /*!
55 * Converts the given \a name from Unicode.
56 * This function is supposed to work for dirnames, filenames
57 * or a full pathname.
58 */
59 QByteArray encode(const QString &name) const;
60
61 /*!
62 * Converts the given URL into its 8-bit components
63 */
64 QByteArray encode(const QUrl &url) const;
65
66 /*!
67 * Converts the given URL into 8-bit form and separate the
68 * dirname from the filename. This is useful for worker functions
69 * like stat or get.
70 *
71 * The dirname is returned with the final slash always stripped
72 */
73 QByteArray directory(const QUrl &url, bool ignore_trailing_slash = true) const;
74
75 /*!
76 * Converts the given URL into 8-bit form and retrieve the filename.
77 */
78 QByteArray fileName(const QUrl &url) const;
79
80 /*!
81 * Returns the encoding being used.
82 */
83 const char *encoding() const;
84
85 /*!
86 * Sets the encoding being used.
87 * This function does not change the global configuration.
88 *
89 * Pass a null pointer in \a name to revert to the standard
90 * encoding.
91 */
92 void setEncoding(const char *name);
93
94protected:
95 virtual void virtual_hook(int id, void *data);
96
97private:
98 std::unique_ptr<KRemoteEncodingPrivate> const d;
99
100 Q_DISABLE_COPY(KRemoteEncoding)
101};
102
103#endif
104

source code of kio/src/core/kremoteencoding.h