KIO

global.h
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2000-2005 David Faure <faure@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-only
6*/
7#ifndef KIO_GLOBAL_H
8#define KIO_GLOBAL_H
9
10#include "kiocore_export.h"
11
12#include <QFile> // for QFile::Permissions
13#include <QString>
14
15#include <KJob>
16
17class QUrl;
18class QTime;
19
20#if defined(Q_OS_WIN) && defined(Q_CC_MSVC)
21// on windows ssize_t is not defined, only SSIZE_T exists
22#include <basetsd.h>
23typedef SSIZE_T ssize_t;
24#endif
25
26/**
27 * @short A namespace for KIO globals
28 *
29 */
30namespace KIO
31{
32/// 64-bit file offset
33typedef qlonglong fileoffset_t;
34/// 64-bit file size
35typedef qulonglong filesize_t;
36
37/**
38 * Converts @p size from bytes to the string representation.
39 *
40 * @param size size in bytes
41 * @return converted size as a string - e.g. 123.4 KiB , 12.0 MiB
42 */
43KIOCORE_EXPORT QString convertSize(KIO::filesize_t size);
44
45/**
46 * Converts a size to a string representation
47 * Not unlike QString::number(...)
48 *
49 * @param size size in bytes
50 * @return converted size as a string - e.g. 123456789
51 */
52KIOCORE_EXPORT QString number(KIO::filesize_t size);
53
54/**
55 * Converts size from kibi-bytes (2^10) to the string representation.
56 *
57 * @param kibSize size in kibi-bytes (2^10)
58 * @return converted size as a string - e.g. 123.4 KiB , 12.0 MiB
59 */
60KIOCORE_EXPORT QString convertSizeFromKiB(KIO::filesize_t kibSize);
61
62/**
63 * Calculates remaining time in seconds from total size, processed size and speed.
64 *
65 * @param totalSize total size in bytes
66 * @param processedSize processed size in bytes
67 * @param speed speed in bytes per second
68 * @return calculated remaining time in seconds
69 */
70KIOCORE_EXPORT unsigned int calculateRemainingSeconds(KIO::filesize_t totalSize, KIO::filesize_t processedSize, KIO::filesize_t speed);
71
72/**
73 * Convert @p seconds to a string representing number of days, hours, minutes and seconds
74 *
75 * @param seconds number of seconds to convert
76 * @return string representation in a locale depending format
77 */
78KIOCORE_EXPORT QString convertSeconds(unsigned int seconds);
79
80/**
81 * Helper for showing information about a set of files and directories
82 * @param items the number of items (= @p files + @p dirs + number of symlinks :)
83 * @param files the number of files
84 * @param dirs the number of dirs
85 * @param size the sum of the size of the @p files
86 * @param showSize whether to show the size in the result
87 * @return the summary string
88 */
89KIOCORE_EXPORT QString itemsSummaryString(uint items, uint files, uint dirs, KIO::filesize_t size, bool showSize);
90
91/**
92 * Encodes (from the text displayed to the real filename)
93 * This translates '/' into a "unicode fraction slash", QChar(0x2044).
94 * Used by KIO::link, for instance.
95 * @param str the file name to encode
96 * @return the encoded file name
97 */
98KIOCORE_EXPORT QString encodeFileName(const QString &str);
99/**
100 * Decodes (from the filename to the text displayed)
101 * This doesn't do anything anymore, it used to do the opposite of encodeFileName
102 * when encodeFileName was using %2F for '/'.
103 * @param str the file name to decode
104 * @return the decoded file name
105 */
106KIOCORE_EXPORT QString decodeFileName(const QString &str);
107
108/**
109 * Error codes that can be emitted by KIO.
110 */
111enum Error {
112 ERR_CANNOT_OPEN_FOR_READING = KJob::UserDefinedError + 1,
113 ERR_CANNOT_OPEN_FOR_WRITING = KJob::UserDefinedError + 2,
114 ERR_CANNOT_LAUNCH_PROCESS = KJob::UserDefinedError + 3,
115 ERR_INTERNAL = KJob::UserDefinedError + 4,
116 ERR_MALFORMED_URL = KJob::UserDefinedError + 5,
117 ERR_UNSUPPORTED_PROTOCOL = KJob::UserDefinedError + 6,
118 ERR_NO_SOURCE_PROTOCOL = KJob::UserDefinedError + 7,
119 ERR_UNSUPPORTED_ACTION = KJob::UserDefinedError + 8,
120 ERR_IS_DIRECTORY = KJob::UserDefinedError + 9, ///< ... where a file was expected
121 ERR_IS_FILE = KJob::UserDefinedError + 10, ///< ... where a directory was expected (e.g.\ listing)
122 ERR_DOES_NOT_EXIST = KJob::UserDefinedError + 11,
123 ERR_FILE_ALREADY_EXIST = KJob::UserDefinedError + 12,
124 ERR_DIR_ALREADY_EXIST = KJob::UserDefinedError + 13,
125 ERR_UNKNOWN_HOST = KJob::UserDefinedError + 14,
126 ERR_ACCESS_DENIED = KJob::UserDefinedError + 15,
127 ERR_WRITE_ACCESS_DENIED = KJob::UserDefinedError + 16,
128 ERR_CANNOT_ENTER_DIRECTORY = KJob::UserDefinedError + 17,
129 ERR_PROTOCOL_IS_NOT_A_FILESYSTEM = KJob::UserDefinedError + 18,
130 ERR_CYCLIC_LINK = KJob::UserDefinedError + 19,
131 ERR_USER_CANCELED = KJob::KilledJobError,
132 ERR_CYCLIC_COPY = KJob::UserDefinedError + 21,
133 ERR_CANNOT_CREATE_SOCKET = KJob::UserDefinedError + 22,
134 ERR_CANNOT_CONNECT = KJob::UserDefinedError + 23,
135 ERR_CONNECTION_BROKEN = KJob::UserDefinedError + 24,
136 ERR_NOT_FILTER_PROTOCOL = KJob::UserDefinedError + 25,
137 ERR_CANNOT_MOUNT = KJob::UserDefinedError + 26,
138 ERR_CANNOT_UNMOUNT = KJob::UserDefinedError + 27,
139 ERR_CANNOT_READ = KJob::UserDefinedError + 28,
140 ERR_CANNOT_WRITE = KJob::UserDefinedError + 29,
141 ERR_CANNOT_BIND = KJob::UserDefinedError + 30,
142 ERR_CANNOT_LISTEN = KJob::UserDefinedError + 31,
143 ERR_CANNOT_ACCEPT = KJob::UserDefinedError + 32,
144 ERR_CANNOT_LOGIN = KJob::UserDefinedError + 33,
145 ERR_CANNOT_STAT = KJob::UserDefinedError + 34,
146 ERR_CANNOT_CLOSEDIR = KJob::UserDefinedError + 35,
147 ERR_CANNOT_MKDIR = KJob::UserDefinedError + 37,
148 ERR_CANNOT_RMDIR = KJob::UserDefinedError + 38,
149 ERR_CANNOT_RESUME = KJob::UserDefinedError + 39,
150 ERR_CANNOT_RENAME = KJob::UserDefinedError + 40,
151 ERR_CANNOT_CHMOD = KJob::UserDefinedError + 41,
152 ERR_CANNOT_DELETE = KJob::UserDefinedError + 42,
153 // The text argument is the protocol that the dead worker supported.
154 // This means for example: file, ftp, http, ...
155 ERR_WORKER_DIED = KJob::UserDefinedError + 43, ///< @since 5.96
156 ERR_OUT_OF_MEMORY = KJob::UserDefinedError + 44,
157 ERR_UNKNOWN_PROXY_HOST = KJob::UserDefinedError + 45,
158 ERR_CANNOT_AUTHENTICATE = KJob::UserDefinedError + 46,
159 ERR_ABORTED = KJob::UserDefinedError + 47, ///< Action got aborted from application side
160 ERR_INTERNAL_SERVER = KJob::UserDefinedError + 48,
161 ERR_SERVER_TIMEOUT = KJob::UserDefinedError + 49,
162 ERR_SERVICE_NOT_AVAILABLE = KJob::UserDefinedError + 50,
163 ERR_UNKNOWN = KJob::UserDefinedError + 51,
164 // (was a warning) ERR_CHECKSUM_MISMATCH = 52,
165 ERR_UNKNOWN_INTERRUPT = KJob::UserDefinedError + 53,
166 ERR_CANNOT_DELETE_ORIGINAL = KJob::UserDefinedError + 54,
167 ERR_CANNOT_DELETE_PARTIAL = KJob::UserDefinedError + 55,
168 ERR_CANNOT_RENAME_ORIGINAL = KJob::UserDefinedError + 56,
169 ERR_CANNOT_RENAME_PARTIAL = KJob::UserDefinedError + 57,
170 ERR_NEED_PASSWD = KJob::UserDefinedError + 58,
171 ERR_CANNOT_SYMLINK = KJob::UserDefinedError + 59,
172 ERR_NO_CONTENT = KJob::UserDefinedError + 60, ///< Action succeeded but no content will follow.
173 ERR_DISK_FULL = KJob::UserDefinedError + 61,
174 ERR_IDENTICAL_FILES = KJob::UserDefinedError + 62, ///< src==dest when moving/copying
175 /**
176 * For worker specified errors that can be
177 * rich text. Email links will be handled
178 * by the standard email app and all hrefs
179 * will be handled by the standard browser.
180 * <a href="exec:/khelpcenter ?" will be
181 * forked.
182 * @since 5.96
183 */
184 ERR_WORKER_DEFINED = KJob::UserDefinedError + 63,
185 ERR_UPGRADE_REQUIRED = KJob::UserDefinedError + 64, ///< A transport upgrade is required to access this
186 ///< object. For instance, TLS is demanded by
187 ///< the server in order to continue.
188 ERR_POST_DENIED = KJob::UserDefinedError + 65, ///< Issued when trying to POST data to a certain Ports
189 // see job.cpp
190 ERR_CANNOT_SEEK = KJob::UserDefinedError + 66,
191 ERR_CANNOT_SETTIME = KJob::UserDefinedError + 67, ///< Emitted by setModificationTime
192 ERR_CANNOT_CHOWN = KJob::UserDefinedError + 68,
193 ERR_POST_NO_SIZE = KJob::UserDefinedError + 69,
194 ERR_DROP_ON_ITSELF = KJob::UserDefinedError + 70, ///< from KIO::DropJob, @since 5.6
195 ERR_CANNOT_MOVE_INTO_ITSELF = KJob::UserDefinedError + 71, ///< emitted by KIO::move, @since 5.18
196 ERR_PASSWD_SERVER = KJob::UserDefinedError + 72, ///< returned by WorkerBase::openPasswordDialog, @since 5.24
197 ERR_CANNOT_CREATE_WORKER = KJob::UserDefinedError + 73, ///< used by Worker::createWorker, @since 5.96
198 ERR_FILE_TOO_LARGE_FOR_FAT32 = KJob::UserDefinedError + 74, ///< @since 5.54
199 ERR_OWNER_DIED ///< Value used between kuiserver and views when the job owner disappears unexpectedly. It should not be emitted by workers. @since 5.54
200 = KJob::UserDefinedError + 75,
201 ERR_PRIVILEGE_NOT_REQUIRED = KJob::UserDefinedError + 76, ///< used by file ioworker, @since 5.60
202 ERR_CANNOT_TRUNCATE = KJob::UserDefinedError + 77, // used by FileJob::truncate, @since 5.66
203 /**
204 * Indicates failure to create a symlink due to the underlying filesystem (FAT/ExFAT)
205 * not supporting them. Used by e.g. CopyJob.
206 * @since 5.88
207 */
208 ERR_SYMLINKS_NOT_SUPPORTED = KJob::UserDefinedError + 78,
209
210 /**
211 * Moving files/dirs to the Trash failed due to size constraints.
212 *
213 * @since 5.100
214 */
215 ERR_TRASH_FILE_TOO_LARGE = KJob::UserDefinedError + 79,
216};
217
218#if KIOCORE_ENABLE_DEPRECATED_SINCE(6, 6)
219/**
220 * Specifies how to use the cache.
221 * @see parseCacheControl()
222 * @see getCacheControlString()
223 * @deprecated since 6.6, not used
224 */
225KIOCORE_DEPRECATED_VERSION(6, 6, "Not used")
227 CC_CacheOnly, ///< Fail request if not in cache
228 CC_Cache, ///< Use cached entry if available
229 CC_Verify, ///< Validate cached entry with remote site if expired
230 CC_Refresh, ///< Always validate cached entry with remote site
231 CC_Reload, ///< Always fetch from remote site.
232};
233#endif
234
235/**
236 * Specifies privilege file operation status.
237 * @since 5.43
238 */
240 OperationAllowed = 1,
241 OperationCanceled,
242 OperationNotAllowed,
243};
244
245/**
246 * Describes the fields that a stat command will retrieve
247 * @see UDSEntry
248 * @see StatDetails
249 * @since 5.69
250 */
252 /// No field returned, useful to check if a file exists
254 /// Filename, access, type, size, linkdest
256 /// uid, gid
257 StatUser = 0x2,
258 /// atime, mtime, btime
259 StatTime = 0x4,
260 /// Resolve symlinks
262 /// ACL data
263 StatAcl = 0x10,
264 /// dev, inode
265 StatInode = 0x20,
266 /// Recursive size
267 /// @since 5.70
269 /// MIME type
270 /// @since 5.82
272
273 /// Default StatDetail flag when creating a @c StatJob.
274 /// Equivalent to setting <tt>StatBasic | StatUser | StatTime | StatAcl | StatResolveSymlink</tt>
276};
277/**
278 * Stores a combination of #StatDetail values.
279 */
280Q_DECLARE_FLAGS(StatDetails, StatDetail)
281
282Q_DECLARE_OPERATORS_FOR_FLAGS(KIO::StatDetails)
283
284#if KIOCORE_ENABLE_DEPRECATED_SINCE(6, 6)
285/**
286 * Parses the string representation of the cache control option.
287 *
288 * @param cacheControl the string representation
289 * @return the cache control value
290 * @see getCacheControlString()
291 * @deprecated since 6.6, not used
292 */
293
294KIOCORE_EXPORT KIO::CacheControl parseCacheControl(const QString &cacheControl);
295#endif
296
297#if KIOCORE_ENABLE_DEPRECATED_SINCE(6, 6)
298/**
299 * Returns a string representation of the given cache control method.
300 *
301 * @param cacheControl the cache control method
302 * @return the string representation
303 * @see parseCacheControl()
304 * @deprecated since 6.6, not used
305 */
306KIOCORE_DEPRECATED_VERSION(6, 6, "Not used")
307KIOCORE_EXPORT QString getCacheControlString(KIO::CacheControl cacheControl);
308#endif
309
310/**
311 * Return the "favicon" (see http://www.favicon.com) for the given @p url,
312 * if available. Does NOT attempt to download the favicon, it only returns
313 * one that is already available.
314 *
315 * If unavailable, returns QString().
316 * Use KIO::FavIconRequestJob instead of this method if you can wait
317 * for the favicon to be downloaded.
318 *
319 * @param url the URL of the favicon
320 * @return the path to the icon (to be passed to QIcon()), or QString()
321 *
322 * @since 5.0
323 */
324KIOCORE_EXPORT QString favIconForUrl(const QUrl &url);
325
326/**
327 * Converts KIO file permissions from mode_t to QFile::Permissions format.
328 *
329 * This is a convenience function for converting KIO permissions parameter from
330 * mode_t to QFile::Permissions.
331 *
332 * @param permissions KIO file permissions.
333 *
334 * @return -1 if @p permissions is -1, otherwise its OR'ed QFile::Permission equivalent.
335 */
336KIOCORE_EXPORT QFile::Permissions convertPermissions(int permissions);
337
338/**
339 * Return the icon name for a URL.
340 * Most of the time this returns the MIME type icon,
341 * but also has fallback to favicon and protocol-specific icon.
342 *
343 * Pass this to QIcon::fromTheme().
344 *
345 * @since 5.0
346 */
347KIOCORE_EXPORT QString iconNameForUrl(const QUrl &url);
348
349/**
350 * This function is useful to implement the "Up" button in a file manager for example.
351 *
352 * @return a URL that is a level higher
353 *
354 * @since 5.0
355 */
356KIOCORE_EXPORT QUrl upUrl(const QUrl &url);
357
358}
359#endif
A namespace for KIO globals.
KIOCORE_EXPORT QString convertSizeFromKiB(KIO::filesize_t kibSize)
Converts size from kibi-bytes (2^10) to the string representation.
Definition global.cpp:50
KIOCORE_EXPORT QString iconNameForUrl(const QUrl &url)
Return the icon name for a URL.
Definition global.cpp:188
KIOCORE_EXPORT QString convertSeconds(unsigned int seconds)
Convert seconds to a string representing number of days, hours, minutes and seconds.
Definition global.cpp:69
KIOCORE_EXPORT QString number(KIO::filesize_t size)
Converts a size to a string representation Not unlike QString::number(...)
Definition global.cpp:55
KIOCORE_EXPORT QString getCacheControlString(KIO::CacheControl cacheControl)
Returns a string representation of the given cache control method.
Definition global.cpp:157
PrivilegeOperationStatus
Specifies privilege file operation status.
Definition global.h:239
KIOCORE_EXPORT QString convertSize(KIO::filesize_t size)
Converts size from bytes to the string representation.
Definition global.cpp:43
KIOCORE_EXPORT unsigned int calculateRemainingSeconds(KIO::filesize_t totalSize, KIO::filesize_t processedSize, KIO::filesize_t speed)
Calculates remaining time in seconds from total size, processed size and speed.
Definition global.cpp:60
KIOCORE_EXPORT QUrl upUrl(const QUrl &url)
This function is useful to implement the "Up" button in a file manager for example.
Definition global.cpp:238
KIOCORE_EXPORT QFile::Permissions convertPermissions(int permissions)
Converts KIO file permissions from mode_t to QFile::Permissions format.
KIOCORE_EXPORT QString favIconForUrl(const QUrl &url)
Return the "favicon" (see http://www.favicon.com) for the given url, if available.
Definition global.cpp:179
CacheControl
Specifies how to use the cache.
Definition global.h:226
@ CC_Cache
Use cached entry if available.
Definition global.h:228
@ CC_Verify
Validate cached entry with remote site if expired.
Definition global.h:229
@ CC_Reload
Always fetch from remote site.
Definition global.h:231
@ CC_CacheOnly
Fail request if not in cache.
Definition global.h:227
@ CC_Refresh
Always validate cached entry with remote site.
Definition global.h:230
qlonglong fileoffset_t
64-bit file offset
Definition global.h:33
qulonglong filesize_t
64-bit file size
Definition global.h:35
StatDetail
Describes the fields that a stat command will retrieve.
Definition global.h:251
@ StatBasic
Filename, access, type, size, linkdest.
Definition global.h:255
@ StatDefaultDetails
Default StatDetail flag when creating a StatJob.
Definition global.h:275
@ StatTime
atime, mtime, btime
Definition global.h:259
@ StatUser
uid, gid
Definition global.h:257
@ StatResolveSymlink
Resolve symlinks.
Definition global.h:261
@ StatNoDetails
No field returned, useful to check if a file exists.
Definition global.h:253
@ StatAcl
ACL data.
Definition global.h:263
@ StatRecursiveSize
Recursive size.
Definition global.h:268
@ StatMimeType
MIME type.
Definition global.h:271
@ StatInode
dev, inode
Definition global.h:265
Error
Error codes that can be emitted by KIO.
Definition global.h:111
@ ERR_OWNER_DIED
Value used between kuiserver and views when the job owner disappears unexpectedly....
Definition global.h:199
@ ERR_CANNOT_MOVE_INTO_ITSELF
emitted by KIO::move,
Definition global.h:195
@ ERR_NO_CONTENT
Action succeeded but no content will follow.
Definition global.h:172
@ ERR_WORKER_DEFINED
For worker specified errors that can be rich text.
Definition global.h:184
@ ERR_IDENTICAL_FILES
src==dest when moving/copying
Definition global.h:174
@ ERR_DROP_ON_ITSELF
from KIO::DropJob,
Definition global.h:194
@ ERR_POST_DENIED
Issued when trying to POST data to a certain Ports.
Definition global.h:188
@ ERR_ABORTED
Action got aborted from application side.
Definition global.h:159
@ ERR_CANNOT_CREATE_WORKER
used by Worker::createWorker,
Definition global.h:197
@ ERR_PASSWD_SERVER
returned by WorkerBase::openPasswordDialog,
Definition global.h:196
@ ERR_FILE_TOO_LARGE_FOR_FAT32
Definition global.h:198
@ ERR_UPGRADE_REQUIRED
A transport upgrade is required to access this.
Definition global.h:185
@ ERR_IS_FILE
... where a directory was expected (e.g. listing)
Definition global.h:121
@ ERR_WORKER_DIED
Definition global.h:155
@ ERR_IS_DIRECTORY
... where a file was expected
Definition global.h:120
@ ERR_SYMLINKS_NOT_SUPPORTED
Indicates failure to create a symlink due to the underlying filesystem (FAT/ExFAT) not supporting the...
Definition global.h:208
@ ERR_PRIVILEGE_NOT_REQUIRED
used by file ioworker,
Definition global.h:201
@ ERR_TRASH_FILE_TOO_LARGE
Moving files/dirs to the Trash failed due to size constraints.
Definition global.h:215
@ ERR_CANNOT_SETTIME
Emitted by setModificationTime.
Definition global.h:191
KIOCORE_EXPORT QString decodeFileName(const QString &str)
Decodes (from the filename to the text displayed) This doesn't do anything anymore,...
Definition global.cpp:118
KIOCORE_EXPORT QString itemsSummaryString(uint items, uint files, uint dirs, KIO::filesize_t size, bool showSize)
Helper for showing information about a set of files and directories.
Definition global.cpp:85
KIOCORE_EXPORT QString encodeFileName(const QString &str)
Encodes (from the text displayed to the real filename) This translates '/' into a "unicode fraction s...
Definition global.cpp:111
KIOCORE_EXPORT KIO::CacheControl parseCacheControl(const QString &cacheControl)
Parses the string representation of the cache control option.
Definition global.cpp:131
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.