KIO

kprotocolmanager.h
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 1999 Torben Weis <weis@kde.org>
4 SPDX-FileCopyrightText: 2000 Waldo Bastain <bastain@kde.org>
5 SPDX-FileCopyrightText: 2000 Dawit Alemayehu <adawit@kde.org>
6 SPDX-FileCopyrightText: 2008 Jarosław Staniek <staniek@kde.org>
7 SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org>
8
9 SPDX-License-Identifier: LGPL-2.0-only
10*/
11
12#ifndef KPROTOCOLMANAGER_H
13#define KPROTOCOLMANAGER_H
14
15#include <QStringList>
16
17#include "kio/global.h" // KIO::CacheControl
18#include "kiocore_export.h"
19#include "kprotocolinfo.h"
20
21class KSharedConfig;
22template<class T>
24typedef QExplicitlySharedDataPointer<KSharedConfig> KSharedConfigPtr;
25namespace KIO
26{
27class WorkerConfigPrivate;
28} // namespace KIO
29
30/**
31 * @class KProtocolManager kprotocolmanager.h <KProtocolManager>
32 *
33 * Provides information about I/O (Internet, etc.) settings chosen/set
34 * by the end user.
35 *
36 * KProtocolManager has a heap of static functions that allows only read
37 * access to KDE's IO related settings. These include proxy, cache, file
38 * transfer resumption, timeout and user-agent related settings.
39 *
40 * The information provided by this class is generic enough to be applicable
41 * to any application that makes use of KDE's IO sub-system. Note that this
42 * mean the proxy, timeout etc. settings are saved in a separate user-specific
43 * config file and not in the config file of the application.
44 *
45 * Original author:
46 * @author Torben Weis <weis@kde.org>
47 *
48 * Revised by:
49 * @author Waldo Bastain <bastain@kde.org>
50 * @author Dawit Alemayehu <adawit@kde.org>
51 * @see KPAC
52 */
53class KIOCORE_EXPORT KProtocolManager
54{
55public:
56 /*=========================== TIMEOUT CONFIG ================================*/
57
58#if KIOCORE_ENABLE_DEPRECATED_SINCE(6, 11)
59 /**
60 * Returns the preferred timeout value for reading from
61 * remote connections in seconds.
62 *
63 * @return timeout value for remote connection in secs.
64 *
65 * @deprecated since 6.11, not used.
66 */
67 KIOCORE_DEPRECATED_VERSION(6, 11, "Not used")
68 static int readTimeout();
69#endif
70
71#if KIOCORE_ENABLE_DEPRECATED_SINCE(6, 11)
72 /**
73 * Returns the preferred timeout value for remote connections
74 * in seconds.
75 *
76 * @return timeout value for remote connection in secs.
77 *
78 * @deprecated since 6.11, not used.
79 */
80 KIOCORE_DEPRECATED_VERSION(6, 11, "Not used")
81 static int connectTimeout();
82#endif
83
84#if KIOCORE_ENABLE_DEPRECATED_SINCE(6, 11)
85 /**
86 * Returns the preferred timeout value for proxy connections
87 * in seconds.
88 *
89 * @return timeout value for proxy connection in secs.
90 *
91 * @deprecated since 6.11, not used.
92 */
93 KIOCORE_DEPRECATED_VERSION(6, 11, "Not used")
94 static int proxyConnectTimeout();
95#endif
96
97#if KIOCORE_ENABLE_DEPRECATED_SINCE(6, 11)
98 /**
99 * Returns the preferred response timeout value for
100 * remote connecting in seconds.
101 *
102 * @return timeout value for remote connection in seconds.
103 *
104 * @deprecated since 6.11, not used.
105 */
106 KIOCORE_DEPRECATED_VERSION(6, 11, "Not used")
107 static int responseTimeout();
108#endif
109
110 /*============================ DOWNLOAD CONFIG ==============================*/
111
112 /**
113 * Returns true if partial downloads should be
114 * automatically resumed.
115 * @return true to resume partial downloads
116 */
117 static bool autoResume();
118
119 /**
120 * Returns true if partial downloads should be marked
121 * with a ".part" extension.
122 * @return true if partial downloads should get an ".part" extension
123 */
124 static bool markPartial();
125
126 /**
127 * Returns the minimum file size for keeping aborted
128 * downloads.
129 *
130 * Any data downloaded that does not meet this minimum
131 * requirement will simply be discarded. The default size
132 * is 5 KB.
133 *
134 * @return the minimum keep size for aborted downloads in bytes
135 */
136 static int minimumKeepSize();
137
138 /*===================== PROTOCOL CAPABILITIES ===============================*/
139
140 /**
141 * Returns whether the protocol can list files/objects.
142 * If a protocol supports listing it can be browsed in e.g. file-dialogs
143 * and konqueror.
144 *
145 * Whether a protocol supports listing is determined by the "listing="
146 * field in the protocol description file.
147 * If the protocol support listing it should list the fields it provides in
148 * this field. If the protocol does not support listing this field should
149 * remain empty (default.)
150 *
151 * @param url the url to check
152 * @return true if the protocol support listing
153 * @see listing()
154 */
155 static bool supportsListing(const QUrl &url);
156
157 /**
158 * Returns whether the protocol can retrieve data from URLs.
159 *
160 * This corresponds to the "reading=" field in the protocol description file.
161 * Valid values for this field are "true" or "false" (default).
162 *
163 * @param url the url to check
164 * @return true if it is possible to read from the URL
165 */
166 static bool supportsReading(const QUrl &url);
167
168 /**
169 * Returns whether the protocol can store data to URLs.
170 *
171 * This corresponds to the "writing=" field in the protocol description file.
172 * Valid values for this field are "true" or "false" (default).
173 *
174 * @param url the url to check
175 * @return true if the protocol supports writing
176 */
177 static bool supportsWriting(const QUrl &url);
178
179 /**
180 * Returns whether the protocol can create directories/folders.
181 *
182 * This corresponds to the "makedir=" field in the protocol description file.
183 * Valid values for this field are "true" or "false" (default).
184 *
185 * @param url the url to check
186 * @return true if the protocol can create directories
187 */
188 static bool supportsMakeDir(const QUrl &url);
189
190 /**
191 * Returns whether the protocol can delete files/objects.
192 *
193 * This corresponds to the "deleting=" field in the protocol description file.
194 * Valid values for this field are "true" or "false" (default).
195 *
196 * @param url the url to check
197 * @return true if the protocol supports deleting
198 */
199 static bool supportsDeleting(const QUrl &url);
200
201 /**
202 * Returns whether the protocol can create links between files/objects.
203 *
204 * This corresponds to the "linking=" field in the protocol description file.
205 * Valid values for this field are "true" or "false" (default).
206 *
207 * @param url the url to check
208 * @return true if the protocol supports linking
209 */
210 static bool supportsLinking(const QUrl &url);
211
212 /**
213 * Returns whether the protocol can move files/objects between different
214 * locations.
215 *
216 * This corresponds to the "moving=" field in the protocol description file.
217 * Valid values for this field are "true" or "false" (default).
218 *
219 * @param url the url to check
220 * @return true if the protocol supports moving
221 */
222 static bool supportsMoving(const QUrl &url);
223
224 /**
225 * Returns whether the protocol can be opened using KIO::open(const QUrl&).
226 *
227 * This corresponds to the "opening=" field in the protocol description file.
228 * Valid values for this field are "true" or "false" (default).
229 *
230 * @param url the url to check
231 * @return true if the protocol supports opening
232 */
233 static bool supportsOpening(const QUrl &url);
234
235 /**
236 * Returns whether the protocol can be truncated with FileJob::truncate(KIO::filesize_t length).
237 *
238 * This corresponds to the "truncating=" field in the protocol description file.
239 * Valid values for this field are "true" or "false" (default).
240 *
241 * @param url the url to check
242 * @return true if the protocol supports truncating
243 * @since 5.66
244 */
245 static bool supportsTruncating(const QUrl &url);
246
247 /**
248 * Returns whether the protocol can copy files/objects directly from the
249 * filesystem itself. If not, the application will read files from the
250 * filesystem using the file-protocol and pass the data on to the destination
251 * protocol.
252 *
253 * This corresponds to the "copyFromFile=" field in the protocol description file.
254 * Valid values for this field are "true" or "false" (default).
255 *
256 * @param url the url to check
257 * @return true if the protocol can copy files from the local file system
258 */
259 static bool canCopyFromFile(const QUrl &url);
260
261 /**
262 * Returns whether the protocol can copy files/objects directly to the
263 * filesystem itself. If not, the application will receive the data from
264 * the source protocol and store it in the filesystem using the
265 * file-protocol.
266 *
267 * This corresponds to the "copyToFile=" field in the protocol description file.
268 * Valid values for this field are "true" or "false" (default).
269 *
270 * @param url the url to check
271 * @return true if the protocol can copy files to the local file system
272 */
273 static bool canCopyToFile(const QUrl &url);
274
275 /**
276 * Returns whether the protocol can rename (i.e. move fast) files/objects
277 * directly from the filesystem itself. If not, the application will read
278 * files from the filesystem using the file-protocol and pass the data on
279 * to the destination protocol.
280 *
281 * This corresponds to the "renameFromFile=" field in the protocol description file.
282 * Valid values for this field are "true" or "false" (default).
283 *
284 * @param url the url to check
285 * @return true if the protocol can rename/move files from the local file system
286 */
287 static bool canRenameFromFile(const QUrl &url);
288
289 /**
290 * Returns whether the protocol can rename (i.e. move fast) files/objects
291 * directly to the filesystem itself. If not, the application will receive
292 * the data from the source protocol and store it in the filesystem using the
293 * file-protocol.
294 *
295 * This corresponds to the "renameToFile=" field in the protocol description file.
296 * Valid values for this field are "true" or "false" (default).
297 *
298 * @param url the url to check
299 * @return true if the protocol can rename files to the local file system
300 */
301 static bool canRenameToFile(const QUrl &url);
302
303 /**
304 * Returns whether the protocol can recursively delete directories by itself.
305 * If not (the usual case) then KIO will list the directory and delete files
306 * and empty directories one by one.
307 *
308 * This corresponds to the "deleteRecursive=" field in the protocol description file.
309 * Valid values for this field are "true" or "false" (default).
310 *
311 * @param url the url to check
312 * @return true if the protocol can delete non-empty directories by itself.
313 */
314 static bool canDeleteRecursive(const QUrl &url);
315
316 /**
317 * This setting defines the strategy to use for generating a filename, when
318 * copying a file or directory to another directory. By default the destination
319 * filename is made out of the filename in the source URL. However if the
320 * KIO worker displays names that are different from the filename of the URL
321 * (e.g. kio_fonts shows Arial for arial.ttf, or kio_trash shows foo.txt and
322 * uses some internal URL), using Name means that the display name (UDS_NAME)
323 * will be used to as the filename in the destination directory.
324 *
325 * This corresponds to the "fileNameUsedForCopying=" field in the protocol description file.
326 * Valid values for this field are "Name" or "FromURL" (default).
327 *
328 * @param url the url to check
329 * @return how to generate the filename in the destination directory when copying/moving
330 */
331 static KProtocolInfo::FileNameUsedForCopying fileNameUsedForCopying(const QUrl &url);
332
333 /**
334 * Returns default MIME type for this URL based on the protocol.
335 *
336 * This corresponds to the "defaultMimetype=" field in the protocol description file.
337 *
338 * @param url the url to check
339 * @return the default MIME type of the protocol, or an empty string if unknown
340 */
341 static QString defaultMimetype(const QUrl &url);
342
343 /**
344 * Returns whether the protocol should be treated as a filesystem
345 * or as a stream when reading from it.
346 *
347 * This corresponds to the "input=" field in the protocol description file.
348 * Valid values for this field are "filesystem", "stream" or "none" (default).
349 *
350 * @param url the url to check
351 * @return the input type of the given @p url
352 */
353 static KProtocolInfo::Type inputType(const QUrl &url);
354
355 /**
356 * Returns whether the protocol should be treated as a filesystem
357 * or as a stream when writing to it.
358 *
359 * This corresponds to the "output=" field in the protocol description file.
360 * Valid values for this field are "filesystem", "stream" or "none" (default).
361 *
362 * @param url the url to check
363 * @return the output type of the given @p url
364 */
365 static KProtocolInfo::Type outputType(const QUrl &url);
366
367 /**
368 * Returns the list of fields this protocol returns when listing
369 * The current possibilities are
370 * Name, Type, Size, Date, AccessDate, Access, Owner, Group, Link, URL, MimeType
371 * as well as Extra1, Extra2 etc. for extra fields (see extraFields).
372 *
373 * This corresponds to the "listing=" field in the protocol description file.
374 * The supported fields should be separated with ',' in the protocol description file.
375 *
376 * @param url the url to check
377 * @return a list of field names
378 */
379 static QStringList listing(const QUrl &url);
380
381 /**
382 * Returns whether the protocol can act as a source protocol.
383 *
384 * A source protocol retrieves data from or stores data to the
385 * location specified by a URL.
386 * A source protocol is the opposite of a filter protocol.
387 *
388 * The "source=" field in the protocol description file determines
389 * whether a protocol is a source protocol or a filter protocol.
390 * @param url the url to check
391 * @return true if the protocol is a source of data (e.g. http), false if the
392 * protocol is a filter (e.g. gzip)
393 */
394 static bool isSourceProtocol(const QUrl &url);
395
396 /**
397 * Returns which protocol handles this MIME type, if it's an archive MIME type.
398 * For instance zip:/ handles application/x-zip.
399 *
400 * This is defined in the protocol description file using an entry like
401 * "archiveMimetype=application/x-zip"
402 *
403 * @param mimeType the MIME type to check
404 * @return the protocol that can handle this archive MIME type, for instance "zip".
405 */
406 static QString protocolForArchiveMimetype(const QString &mimeType);
407
408 /*=============================== OTHERS ====================================*/
409
410 /**
411 * Force a reload of the general config file of
412 * KIO workers ( kioslaverc).
413 */
414 static void reparseConfiguration();
415
416 /**
417 * Returns the charset to use for the specified @ref url.
418 *
419 */
420 static QString charsetFor(const QUrl &url);
421
422 /**
423 * @brief Returns whether the protocol suppports KIO/POSIX permissions handling.
424 *
425 * When this is false the Permissions properties tab may be hidden, for example. The protocol may still support
426 * permission control through other means, specific to the individual KIO worker.
427 *
428 * @param url the url to check
429 * @return whether the protocol supports permissions
430 * @since 5.98
431 */
432 static bool supportsPermissions(const QUrl &url);
433
434private:
435 friend class KIO::WorkerConfigPrivate;
436
437 /**
438 * @internal
439 * (Shared with WorkerConfig)
440 */
441 KIOCORE_NO_EXPORT static QMap<QString, QString> entryMap(const QString &group);
442};
443#endif
Type
Describes the type of a protocol.
Provides information about I/O (Internet, etc.) settings chosen/set by the end user.
static int proxyConnectTimeout()
Returns the preferred timeout value for proxy connections in seconds.
static bool supportsOpening(const QUrl &url)
Returns whether the protocol can be opened using KIO::open(const QUrl&).
static KProtocolInfo::Type outputType(const QUrl &url)
Returns whether the protocol should be treated as a filesystem or as a stream when writing to it.
static bool supportsPermissions(const QUrl &url)
Returns whether the protocol suppports KIO/POSIX permissions handling.
static QString charsetFor(const QUrl &url)
Returns the charset to use for the specified url.
static QStringList listing(const QUrl &url)
Returns the list of fields this protocol returns when listing The current possibilities are Name,...
static bool canRenameToFile(const QUrl &url)
Returns whether the protocol can rename (i.e.
static bool supportsReading(const QUrl &url)
Returns whether the protocol can retrieve data from URLs.
static bool canCopyFromFile(const QUrl &url)
Returns whether the protocol can copy files/objects directly from the filesystem itself.
static QString defaultMimetype(const QUrl &url)
Returns default MIME type for this URL based on the protocol.
static bool canRenameFromFile(const QUrl &url)
Returns whether the protocol can rename (i.e.
static KProtocolInfo::Type inputType(const QUrl &url)
Returns whether the protocol should be treated as a filesystem or as a stream when reading from it.
static bool supportsListing(const QUrl &url)
Returns whether the protocol can list files/objects.
static bool supportsDeleting(const QUrl &url)
Returns whether the protocol can delete files/objects.
static bool supportsLinking(const QUrl &url)
Returns whether the protocol can create links between files/objects.
static KProtocolInfo::FileNameUsedForCopying fileNameUsedForCopying(const QUrl &url)
This setting defines the strategy to use for generating a filename, when copying a file or directory ...
static QString protocolForArchiveMimetype(const QString &mimeType)
Returns which protocol handles this MIME type, if it's an archive MIME type.
static bool supportsTruncating(const QUrl &url)
Returns whether the protocol can be truncated with FileJob::truncate(KIO::filesize_t length).
static int connectTimeout()
Returns the preferred timeout value for remote connections in seconds.
static bool autoResume()
Returns true if partial downloads should be automatically resumed.
static bool markPartial()
Returns true if partial downloads should be marked with a ".part" extension.
static bool isSourceProtocol(const QUrl &url)
Returns whether the protocol can act as a source protocol.
static bool supportsMoving(const QUrl &url)
Returns whether the protocol can move files/objects between different locations.
static bool canCopyToFile(const QUrl &url)
Returns whether the protocol can copy files/objects directly to the filesystem itself.
static int minimumKeepSize()
Returns the minimum file size for keeping aborted downloads.
static bool supportsMakeDir(const QUrl &url)
Returns whether the protocol can create directories/folders.
static bool canDeleteRecursive(const QUrl &url)
Returns whether the protocol can recursively delete directories by itself.
static void reparseConfiguration()
Force a reload of the general config file of KIO workers ( kioslaverc).
static bool supportsWriting(const QUrl &url)
Returns whether the protocol can store data to URLs.
static int responseTimeout()
Returns the preferred response timeout value for remote connecting in seconds.
static int readTimeout()
Returns the preferred timeout value for reading from remote connections in seconds.
A namespace for KIO globals.
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:49:36 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.