File indexing completed on 2024-05-12 03:54:59
0001 /* 0002 This file is part of the KDE project 0003 0004 SPDX-FileCopyrightText: 2010 Jacopo De Simoi <wilderkde@gmail.com> 0005 SPDX-FileCopyrightText: 2014 Lukáš Tinkl <ltinkl@redhat.com> 0006 SPDX-FileCopyrightText: 2016 Kai Uwe Broulik <kde@privat.broulik.de> 0007 SPDX-FileCopyrightText: 2019 David Hallas <david@davidhallas.dk> 0008 0009 SPDX-License-Identifier: LGPL-2.0-only 0010 */ 0011 0012 #ifndef KLISTOPENFILESJOB_H 0013 #define KLISTOPENFILESJOB_H 0014 0015 #include <QObject> 0016 #include <QString> 0017 #include <kcoreaddons_export.h> 0018 #include <kjob.h> 0019 #include <kprocesslist.h> 0020 0021 #include <memory> 0022 0023 class KListOpenFilesJobPrivate; 0024 0025 /** 0026 * @brief Provides information about processes that have open files in a given path or subdirectory of path. 0027 * 0028 * When start() is invoked it starts to collect information about processes that have any files open in path or a 0029 * subdirectory of path. When it is done the KJob::result signal is emitted and the result can be retrieved with the 0030 * processInfoList function. 0031 * 0032 * On Unix like systems the lsof utility is used to get the list of processes. 0033 * On Windows the listing always fails with error code NotSupported. 0034 * 0035 * @since 5.63 0036 */ 0037 class KCOREADDONS_EXPORT KListOpenFilesJob : public KJob 0038 { 0039 Q_OBJECT 0040 public: 0041 explicit KListOpenFilesJob(const QString &path); 0042 ~KListOpenFilesJob() override; 0043 void start() override; 0044 /** 0045 * @brief Returns the list of processes with open files for the requested path 0046 * @return The list of processes with open files for the requested path 0047 */ 0048 KProcessList::KProcessInfoList processInfoList() const; 0049 0050 public: 0051 /** 0052 * @brief Special error codes emitted by KListOpenFilesJob 0053 * 0054 * The KListOpenFilesJob uses the error codes defined here besides the standard error codes defined by KJob 0055 */ 0056 enum class Error { 0057 /*** Indicates that the platform doesn't support listing open files by processes */ 0058 NotSupported = KJob::UserDefinedError + 1, 0059 /*** Internal error has ocurred */ 0060 InternalError = KJob::UserDefinedError + 2, 0061 /*** The specified path does not exist */ 0062 DoesNotExist = KJob::UserDefinedError + 11, 0063 }; 0064 0065 private: 0066 friend class KListOpenFilesJobPrivate; 0067 std::unique_ptr<KListOpenFilesJobPrivate> const d; 0068 }; 0069 0070 #endif // KLISTOPENFILESJOB_H