KUrlCompletion Class

Header: #include <KUrlCompletion>
CMake: find_package(Qt6 REQUIRED COMPONENTS KIOWidgets)
target_link_libraries(mytarget PRIVATE Qt6::KIOWidgets)
Inherited By:

KShellCompletion

Public Types

enum Mode { ExeCompletion, FileCompletion, DirCompletion }

Public Functions

KUrlCompletion()
KUrlCompletion(KUrlCompletion::Mode)
virtual ~KUrlCompletion() override
virtual QUrl dir() const
virtual bool isRunning() const
QStringList mimeTypeFilters() const
virtual KUrlCompletion::Mode mode() const
virtual bool replaceEnv() const
virtual bool replaceHome() const
QString replacedPath(const QString &text) const
virtual void setDir(const QUrl &dir)
void setMimeTypeFilters(const QStringList &mimeTypes)
virtual void setMode(KUrlCompletion::Mode mode)
virtual void setReplaceEnv(bool replace)
virtual void setReplaceHome(bool replace)
virtual void stop()

Reimplemented Public Functions

virtual QString makeCompletion(const QString &text) override

Static Public Members

QString replacedPath(const QString &text, bool replaceHome, bool replaceEnv = true)

Detailed Description

@class KUrlCompletion kurlcompletion.h <KUrlCompletion>

This class does completion of URLs including user directories (~user) and environment variables. Remote URLs are passed to KIO.

@short Completion of a single URL @author David Smith <dsmith@algonet.se>

Member Type Documentation

enum KUrlCompletion::Mode

Determines how completion is done. @li ExeCompletion - executables in $PATH or with full path. @li FileCompletion - all files with full path or in dir(), URLs are listed using KIO. @li DirCompletion - Same as FileCompletion but only returns directories.

Member Function Documentation

KUrlCompletion::KUrlCompletion()

Constructs a KUrlCompletion object in FileCompletion mode.

KUrlCompletion::KUrlCompletion(KUrlCompletion::Mode)

This overloaded constructor allows you to set the Mode to ExeCompletion or FileCompletion without using setMode. Default is FileCompletion.

[override virtual noexcept] KUrlCompletion::~KUrlCompletion()

Destructs the KUrlCompletion object.

[virtual] QUrl KUrlCompletion::dir() const

Returns the current directory, as it was given in setDir @return the current directory, as a URL (use QUrl::toLocalFile for local paths)

See also setDir().

[virtual] bool KUrlCompletion::isRunning() const

Check whether asynchronous completion is in progress. @return true if asynchronous completion is in progress

[override virtual] QString KUrlCompletion::makeCompletion(const QString &text)

Finds completions to the given text.

Remote URLs are listed with KIO. For performance reasons, local files are listed with KIO only if KURLCOMPLETION_LOCAL_KIO is set. The completion is done asynchronously if KIO is used.

Returns the first match for user, environment, and local dir completion and QString() for asynchronous completion (KIO or threaded).

@param text the text to complete @return the first match, or QString() if not found

QStringList KUrlCompletion::mimeTypeFilters() const

Returns the MIME type filters for the file dialog. @see QFileDialog::mimeTypeFilters() @since 5.38

See also setMimeTypeFilters().

[virtual] KUrlCompletion::Mode KUrlCompletion::mode() const

Returns the completion mode: exe or file completion (default FileCompletion). @return the completion mode

See also setMode().

[virtual] bool KUrlCompletion::replaceEnv() const

Checks whether environment variables are completed and whether they are replaced internally while finding completions. Default is enabled. @return true if environment variables will be replaced

See also setReplaceEnv().

[virtual] bool KUrlCompletion::replaceHome() const

Returns whether ~username is completed and whether ~username is replaced internally with the user's home directory while finding completions. Default is enabled. @return true to replace tilde with the home directory

See also setReplaceHome().

QString KUrlCompletion::replacedPath(const QString &text) const

Replaces username and/or environment variables, depending on the current settings and returns the filtered url. Only works with local files, i.e. returns back the original string for non-local urls. @param text the text to process @return the path or URL resulting from this operation. If you want to convert it to a QUrl, use QUrl::fromUserInput.

[static] QString KUrlCompletion::replacedPath(const QString &text, bool replaceHome, bool replaceEnv = true)

@internal I'll let ossi add a real one to KShell :)

[virtual] void KUrlCompletion::setDir(const QUrl &dir)

Sets the current directory (used as base for completion). Default = $HOME. @param dir the current directory, as a URL (use QUrl::fromLocalFile for local paths)

See also dir().

void KUrlCompletion::setMimeTypeFilters(const QStringList &mimeTypes)

Sets the MIME type filters for the file dialog. @see QFileDialog::setMimeTypeFilters() @since 5.38

See also mimeTypeFilters().

[virtual] void KUrlCompletion::setMode(KUrlCompletion::Mode mode)

Changes the completion mode: exe or file completion @param mode the new completion mode

See also mode().

[virtual] void KUrlCompletion::setReplaceEnv(bool replace)

Enables/disables completion and replacement (internally) of environment variables in URLs. Default is enabled. @param replace true to replace environment variables

See also replaceEnv().

[virtual] void KUrlCompletion::setReplaceHome(bool replace)

Enables/disables completion of ~username and replacement (internally) of ~username with the user's home directory. Default is enabled. @param replace true to replace tilde with the home directory

See also replaceHome().

[virtual] void KUrlCompletion::stop()

Stops asynchronous completion.