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 | #ifndef KREMOTEENCODING_H |
20 | #define KREMOTEENCODING_H |
21 | |
22 | #include <kio/kio_export.h> |
23 | #include <kurl.h> |
24 | #include <QtCore/QString> |
25 | #include <QtCore/QByteArray> |
26 | #include <QtCore/QTextCodec> |
27 | |
28 | class KRemoteEncodingPrivate; |
29 | /** |
30 | * Allows encoding and decoding properly remote filenames into Unicode. |
31 | * |
32 | * Certain protocols do not specify an appropriate encoding for decoding |
33 | * their 8-bit data into proper Unicode forms. Therefore, ioslaves should |
34 | * use this class in order to convert those forms into QStrings before |
35 | * creating the respective KIO::UDSEntry. The same is true for decoding |
36 | * URLs to its components. |
37 | * |
38 | * Each KIO::SlaveBase has one object of this kind, even if it is not necessary. |
39 | * It can be accessed through KIO::SlaveBase::remoteEncoding. |
40 | * |
41 | * @short A class for handling remote filenames |
42 | * @author Thiago Macieira <thiago.macieira@kdemail.net> |
43 | */ |
44 | class KIO_EXPORT KRemoteEncoding |
45 | { |
46 | public: |
47 | /** |
48 | * Constructor. |
49 | * |
50 | * Constructs this object to use the given encoding name. |
51 | * If @p name is a null pointer, the standard encoding will be used. |
52 | */ |
53 | explicit KRemoteEncoding(const char *name = 0); |
54 | |
55 | /** |
56 | * Destructor |
57 | */ |
58 | virtual ~KRemoteEncoding(); |
59 | |
60 | /** |
61 | * Converts the given full pathname or filename to Unicode. |
62 | * This function is supposed to work for dirnames, filenames |
63 | * or a full pathname. |
64 | */ |
65 | QString decode(const QByteArray& name) const; |
66 | |
67 | /** |
68 | * Converts the given name from Unicode. |
69 | * This function is supposed to work for dirnames, filenames |
70 | * or a full pathname. |
71 | */ |
72 | QByteArray encode(const QString& name) const; |
73 | |
74 | /** |
75 | * Converts the given URL into its 8-bit components |
76 | */ |
77 | QByteArray encode(const KUrl& url) const; |
78 | |
79 | /** |
80 | * Converts the given URL into 8-bit form and separate the |
81 | * dirname from the filename. This is useful for slave functions |
82 | * like stat or get. |
83 | * |
84 | * The dirname is returned with the final slash always stripped |
85 | */ |
86 | QByteArray directory(const KUrl& url, bool ignore_trailing_slash = true) const; |
87 | |
88 | /** |
89 | * Converts the given URL into 8-bit form and retrieve the filename. |
90 | */ |
91 | QByteArray fileName(const KUrl& url) const; |
92 | |
93 | /** |
94 | * Returns the encoding being used. |
95 | */ |
96 | const char *encoding() const; |
97 | |
98 | /** |
99 | * Returns the MIB for the codec being used. |
100 | */ |
101 | int encodingMib() const; |
102 | |
103 | /** |
104 | * Sets the encoding being used. |
105 | * This function does not change the global configuration. |
106 | * |
107 | * Pass a null pointer in @p name to revert to the standard |
108 | * encoding. |
109 | */ |
110 | void setEncoding(const char* name); |
111 | |
112 | protected: |
113 | virtual void virtual_hook(int id, void* data); |
114 | |
115 | private: |
116 | KRemoteEncodingPrivate* const d; |
117 | |
118 | Q_DISABLE_COPY(KRemoteEncoding) |
119 | }; |
120 | |
121 | #endif |
122 | |