KCoreAddons

kfileutils.h
1/*
2 This file is part of the KDE libraries
3
4 SPDX-FileCopyrightText: 2000-2005 David Faure <faure@kde.org>
5 SPDX-FileCopyrightText: 2021 Alexander Lohnau <alexander.lohnau@gmx.de>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9#ifndef KFILEUTILS_H
10#define KFILEUTILS_H
11
12#include "kcoreaddons_export.h"
13
14#include <QString>
15#include <QUrl>
16
17/**
18 * @short A namespace for KFileUtils globals
19 *
20 */
21namespace KFileUtils
22{
23/**
24 * Given a directory path and a string representing a file or directory
25 * (which usually exist already), this function returns a suggested name
26 * for a file/directory that doesn't exist in @p baseURL.
27 *
28 * The suggested file name is of the form "foo (1)", "foo (2)" etc.
29 *
30 * For local URLs, this function will check if there is already a file/directory
31 * with the new suggested name and will keep incrementing the number in the above
32 * format until it finds one that doesn't exist. Note that this function uses a
33 * blocking I/O call (using QFileInfo) to check the existence of the file/directory,
34 * this could be problematic for network mounts (e.g. SMB, NFS) as these are treated
35 * as local files by the upstream QFile code. An alternative is to use makeSuggestedName()
36 * and use KIO to stat the new file/directory in an asynchronous way.
37 *
38 * @since 5.61
39 */
40KCOREADDONS_EXPORT QString suggestName(const QUrl &baseURL, const QString &oldName);
41
42/**
43 * Given a string, "foo", representing a file/directory (which usually exists already),
44 * this function returns a suggested name for a file/directory in the form "foo (1)",
45 * "foo (2)" etc.
46 *
47 * Unlike the suggestName() method, this function doesn't check if there is a file/directory
48 * with the newly suggested name; the idea being that this responsibility falls on
49 * the caller, e.g. one can use KIO::stat() to check asynchronously whether the new
50 * name already exists (in its parent directory) or not.
51 *
52 * @since 5.76
53 */
54KCOREADDONS_EXPORT QString makeSuggestedName(const QString &oldName);
55
56/**
57 * Locates all files matching the @p nameFilters in the given @p dirs
58 * The returned list does not contain duplicate file names.
59 * In case there are multiple files the one which comes first in the dirs list is returned.
60 * For example:
61 * @code
62 QStringList dirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("krunner/dbusplugins"), QStandardPaths::LocateDirectory);
63 KFileUtils::findAllUniqueFiles(dirs, QStringList{QStringLiteral("*.desktop")});
64 * @endcode
65 * @param location standard location for the dir
66 * @param dir directory in which the files are located
67 * @param nameFilters filters that get passed to the QDirIterator that is used internally to
68 * iterate over the files in each dir in the list
69 * @return list of absolute file paths
70 * @since 5.85
71 */
72KCOREADDONS_EXPORT QStringList findAllUniqueFiles(const QStringList &dirs, const QStringList &nameFilters = {});
73}
74#endif
A namespace for KFileUtils globals.
Definition kfileutils.h:22
KCOREADDONS_EXPORT QString suggestName(const QUrl &baseURL, const QString &oldName)
Given a directory path and a string representing a file or directory (which usually exist already),...
KCOREADDONS_EXPORT QStringList findAllUniqueFiles(const QStringList &dirs, const QStringList &nameFilters={})
Locates all files matching the nameFilters in the given dirs The returned list does not contain dupli...
KCOREADDONS_EXPORT QString makeSuggestedName(const QString &oldName)
Given a string, "foo", representing a file/directory (which usually exists already),...
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 7 2024 12:01:00 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.