KIO

kurlcompletion.h
1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2000 David Smith <dsmith@algonet.se>
4
5 This class was inspired by a previous KUrlCompletion by
6 SPDX-FileContributor: Henner Zeller <zeller@think.de>
7
8 SPDX-License-Identifier: LGPL-2.0-or-later
9*/
10
11#ifndef KURLCOMPLETION_H
12#define KURLCOMPLETION_H
13
14#include "kiowidgets_export.h"
15#include <kio/udsentry.h>
16
17#include <KCompletion>
18
19#include <QString>
20#include <QStringList>
21
22#include <memory>
23
24namespace KIO
25{
26class Job;
27}
28
29class KUrlCompletionPrivate;
30
31/**
32 * @class KUrlCompletion kurlcompletion.h <KUrlCompletion>
33 *
34 * This class does completion of URLs including user directories (~user)
35 * and environment variables. Remote URLs are passed to KIO.
36 *
37 * @short Completion of a single URL
38 * @author David Smith <dsmith@algonet.se>
39 */
40class KIOWIDGETS_EXPORT KUrlCompletion : public KCompletion
41{
42 Q_OBJECT
43
44public:
45 /**
46 * Determines how completion is done.
47 * @li ExeCompletion - executables in $PATH or with full path.
48 * @li FileCompletion - all files with full path or in dir(), URLs
49 * are listed using KIO.
50 * @li DirCompletion - Same as FileCompletion but only returns directories.
51 */
52 enum Mode {
53 ExeCompletion = 1,
54 FileCompletion,
55 DirCompletion
56 };
57
58 /**
59 * Constructs a KUrlCompletion object in FileCompletion mode.
60 */
62 /**
63 * This overloaded constructor allows you to set the Mode to ExeCompletion
64 * or FileCompletion without using setMode. Default is FileCompletion.
65 */
66 KUrlCompletion(Mode);
67 /**
68 * Destructs the KUrlCompletion object.
69 */
70 ~KUrlCompletion() override;
71
72 /**
73 * Finds completions to the given text.
74 *
75 * Remote URLs are listed with KIO. For performance reasons, local files
76 * are listed with KIO only if KURLCOMPLETION_LOCAL_KIO is set.
77 * The completion is done asynchronously if KIO is used.
78 *
79 * Returns the first match for user, environment, and local dir completion
80 * and QString() for asynchronous completion (KIO or threaded).
81 *
82 * @param text the text to complete
83 * @return the first match, or QString() if not found
84 */
85 QString makeCompletion(const QString &text) override;
86
87 /**
88 * Sets the current directory (used as base for completion).
89 * Default = $HOME.
90 * @param dir the current directory, as a URL (use QUrl::fromLocalFile for local paths)
91 */
92 virtual void setDir(const QUrl &dir);
93
94 /**
95 * Returns the current directory, as it was given in setDir
96 * @return the current directory, as a URL (use QUrl::toLocalFile for local paths)
97 */
98 virtual QUrl dir() const;
99
100 /**
101 * Check whether asynchronous completion is in progress.
102 * @return true if asynchronous completion is in progress
103 */
104 virtual bool isRunning() const;
105
106 /**
107 * Stops asynchronous completion.
108 */
109 virtual void stop();
110
111 /**
112 * Returns the completion mode: exe or file completion (default FileCompletion).
113 * @return the completion mode
114 */
115 virtual Mode mode() const;
116
117 /**
118 * Changes the completion mode: exe or file completion
119 * @param mode the new completion mode
120 */
121 virtual void setMode(Mode mode);
122
123 /**
124 * Checks whether environment variables are completed and
125 * whether they are replaced internally while finding completions.
126 * Default is enabled.
127 * @return true if environment variables will be replaced
128 */
129 virtual bool replaceEnv() const;
130
131 /**
132 * Enables/disables completion and replacement (internally) of
133 * environment variables in URLs. Default is enabled.
134 * @param replace true to replace environment variables
135 */
136 virtual void setReplaceEnv(bool replace);
137
138 /**
139 * Returns whether ~username is completed and whether ~username
140 * is replaced internally with the user's home directory while
141 * finding completions. Default is enabled.
142 * @return true to replace tilde with the home directory
143 */
144 virtual bool replaceHome() const;
145
146 /**
147 * Enables/disables completion of ~username and replacement
148 * (internally) of ~username with the user's home directory.
149 * Default is enabled.
150 * @param replace true to replace tilde with the home directory
151 */
152 virtual void setReplaceHome(bool replace);
153
154 /**
155 * Replaces username and/or environment variables, depending on the
156 * current settings and returns the filtered url. Only works with
157 * local files, i.e. returns back the original string for non-local
158 * urls.
159 * @param text the text to process
160 * @return the path or URL resulting from this operation. If you
161 * want to convert it to a QUrl, use QUrl::fromUserInput.
162 */
163 QString replacedPath(const QString &text) const;
164
165 /**
166 * @internal I'll let ossi add a real one to KShell :)
167 */
168 static QString replacedPath(const QString &text, bool replaceHome, bool replaceEnv = true);
169
170 /**
171 * Sets the MIME type filters for the file dialog.
172 * @see QFileDialog::setMimeTypeFilters()
173 * @since 5.38
174 */
175 void setMimeTypeFilters(const QStringList &mimeTypes);
176
177 /**
178 * Returns the MIME type filters for the file dialog.
179 * @see QFileDialog::mimeTypeFilters()
180 * @since 5.38
181 */
182 QStringList mimeTypeFilters() const;
183
184protected:
185 // Called by KCompletion, adds '/' to directories
186 void postProcessMatch(QString *match) const override;
187 void postProcessMatches(QStringList *matches) const override;
188 void postProcessMatches(KCompletionMatches *matches) const override;
189
190private:
191 std::unique_ptr<KUrlCompletionPrivate> const d;
192};
193
194#endif // KURLCOMPLETION_H
virtual QString makeCompletion(const QString &string)
virtual void postProcessMatches(KCompletionMatches *matches) const
virtual void postProcessMatch(QString *match) const
This class does completion of URLs including user directories (~user) and environment variables.
Mode
Determines how completion is done.
void stop(Ekos::AlignState mode)
A namespace for KIO globals.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 8 2024 11:56:19 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.