1/*
2 This file is part of the KDE project
3
4 SPDX-FileCopyrightText: 2010 Jacopo De Simoi <wilderkde@gmail.com>
5 SPDX-FileCopyrightText: 2014 Lukáš Tinkl <ltinkl@redhat.com>
6 SPDX-FileCopyrightText: 2016 Kai Uwe Broulik <kde\arivat.broulik.de>
7 SPDX-FileCopyrightText: 2019 David Hallas <david@davidhallas.dk>
8
9 SPDX-License-Identifier: LGPL-2.0-only
10*/
11
12#ifndef KLISTOPENFILESJOB_H
13#define KLISTOPENFILESJOB_H
14
15#include <QObject>
16#include <QString>
17#include <kcoreaddons_export.h>
18#include <kjob.h>
19#include <kprocesslist.h>
20
21#include <memory>
22
23class KListOpenFilesJobPrivate;
24
25/*!
26 * \class KListOpenFilesJob
27 * \inmodule KCoreAddons
28 * \brief Provides information about processes that have open files in a given path or subdirectory of path.
29 *
30 * When start() is invoked it starts to collect information about processes that have any files open in path or a
31 * subdirectory of path. When it is done the KJob::result signal is emitted and the result can be retrieved with the
32 * processInfoList function.
33 *
34 * On Unix like systems the lsof utility is used to get the list of processes.
35 * On Windows the listing always fails with error code NotSupported.
36 *
37 * \since 5.63
38 */
39class KCOREADDONS_EXPORT KListOpenFilesJob : public KJob
40{
41 Q_OBJECT
42public:
43 /*!
44 *
45 */
46 explicit KListOpenFilesJob(const QString &path);
47 ~KListOpenFilesJob() override;
48 void start() override;
49 /*!
50 * \brief Returns the list of processes with open files for the requested path
51 *
52 * Returns The list of processes with open files for the requested path
53 */
54 KProcessList::KProcessInfoList processInfoList() const;
55
56public:
57 /*!
58 * \brief Special error codes emitted by KListOpenFilesJob
59 *
60 * The KListOpenFilesJob uses the error codes defined here besides the standard error codes defined by KJob
61 *
62 * \value NotSupported Indicates that the platform doesn't support listing open files by processes
63 * \value InternalError Internal error has ocurred
64 * \value DoesNotExist The specified path does not exist
65 */
66 enum class Error {
67 NotSupported = KJob::UserDefinedError + 1,
68 InternalError = KJob::UserDefinedError + 2,
69 DoesNotExist = KJob::UserDefinedError + 11,
70 };
71
72private:
73 friend class KListOpenFilesJobPrivate;
74 std::unique_ptr<KListOpenFilesJobPrivate> const d;
75};
76
77#endif // KLISTOPENFILESJOB_H
78

source code of kcoreaddons/src/lib/util/klistopenfilesjob.h