KIO

kremoteencoding.h
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 kremoteencoding.h <KRemoteEncoding>
21 *
22 * Allows encoding and decoding properly remote filenames into Unicode.
23 *
24 * Certain protocols do not specify an appropriate encoding for decoding
25 * their 8-bit data into proper Unicode forms. Therefore, KIO workers should
26 * use this class in order to convert those forms into QStrings before
27 * creating the respective KIO::UDSEntry. The same is true for decoding
28 * URLs to its components.
29 *
30 * Each KIO::WorkerBase has one object of this kind, even if it is not necessary.
31 * It can be accessed through KIO::WorkerBase::remoteEncoding.
32 *
33 * @short A class for handling remote filenames
34 * @author Thiago Macieira <thiago.macieira@kdemail.net>
35 */
36class KIOCORE_EXPORT KRemoteEncoding
37{
38public:
39 /**
40 * Constructor.
41 *
42 * Constructs this object to use the given encoding name.
43 * If @p name is a null pointer, the standard encoding will be used.
44 */
45 explicit KRemoteEncoding(const char *name = nullptr);
46
47 /**
48 * Destructor
49 */
51
52 /**
53 * Converts the given full pathname or filename to Unicode.
54 * This function is supposed to work for dirnames, filenames
55 * or a full pathname.
56 */
57 QString decode(const QByteArray &name) const;
58
59 /**
60 * Converts the given name from Unicode.
61 * This function is supposed to work for dirnames, filenames
62 * or a full pathname.
63 */
64 QByteArray encode(const QString &name) const;
65
66 /**
67 * Converts the given URL into its 8-bit components
68 */
69 QByteArray encode(const QUrl &url) const;
70
71 /**
72 * Converts the given URL into 8-bit form and separate the
73 * dirname from the filename. This is useful for worker functions
74 * like stat or get.
75 *
76 * The dirname is returned with the final slash always stripped
77 */
78 QByteArray directory(const QUrl &url, bool ignore_trailing_slash = true) const;
79
80 /**
81 * Converts the given URL into 8-bit form and retrieve the filename.
82 */
83 QByteArray fileName(const QUrl &url) const;
84
85 /**
86 * Returns the encoding being used.
87 */
88 const char *encoding() const;
89
90 /**
91 * Sets the encoding being used.
92 * This function does not change the global configuration.
93 *
94 * Pass a null pointer in @p name to revert to the standard
95 * encoding.
96 */
97 void setEncoding(const char *name);
98
99protected:
100 virtual void virtual_hook(int id, void *data);
101
102private:
103 std::unique_ptr<KRemoteEncodingPrivate> const d;
104
105 Q_DISABLE_COPY(KRemoteEncoding)
106};
107
108#endif
Allows encoding and decoding properly remote filenames into Unicode.
virtual ~KRemoteEncoding()
Destructor.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.