File indexing completed on 2024-05-05 03:56:08

0001 /*
0002     This file is part of the KDE project
0003     SPDX-FileCopyrightText: 2004 David Faure <faure@kde.org>
0004     SPDX-FileCopyrightText: 2009 Christian Ehrlicher <ch.ehrlicher@gmx.de>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef KIO_TRASH_H
0010 #define KIO_TRASH_H
0011 
0012 #define NOMINMAX
0013 
0014 #include <kio/workerbase.h>
0015 
0016 #include <windows.h> // Must be included before shallapi.h, otherwise it fails to build on windows
0017 
0018 #include <shellapi.h>
0019 #include <shlobj.h>
0020 
0021 #include <KConfig>
0022 
0023 namespace KIO
0024 {
0025 class Job;
0026 }
0027 
0028 class TrashProtocol : public QObject, public KIO::WorkerBase
0029 {
0030     Q_OBJECT
0031 public:
0032     TrashProtocol(const QByteArray &protocol, const QByteArray &pool, const QByteArray &app);
0033     virtual ~TrashProtocol();
0034     KIO::WorkerResult stat(const QUrl &url) override;
0035     KIO::WorkerResult listDir(const QUrl &url) override;
0036     KIO::WorkerResult get(const QUrl &url) override;
0037     KIO::WorkerResult put(const QUrl &url, int, KIO::JobFlags flags) override;
0038     KIO::WorkerResult rename(const QUrl &, const QUrl &, KIO::JobFlags) override;
0039     KIO::WorkerResult copy(const QUrl &src, const QUrl &dest, int permissions, KIO::JobFlags flags) override;
0040     // TODO (maybe) chmod( const QUrl& url, int permissions );
0041     KIO::WorkerResult del(const QUrl &url, bool isfile) override;
0042     /**
0043      * Special actions: (first int in the byte array)
0044      * 1 : empty trash
0045      * 2 : migrate old (pre-kde-3.4) trash contents
0046      * 3 : restore a file to its original location. Args: QUrl trashURL.
0047      */
0048     KIO::WorkerResult special(const QByteArray &data) override;
0049 
0050     void updateRecycleBin();
0051 
0052 private:
0053     typedef enum { Copy, Move } CopyOrMove;
0054     [[nodiscard]] KIO::WorkerResult copyOrMove(const QUrl &src, const QUrl &dest, bool overwrite, CopyOrMove action);
0055     [[nodiscard]] KIO::WorkerResult listRoot();
0056     [[nodiscard]] KIO::WorkerResult restore(const QUrl &trashURL, const QUrl &destURL);
0057     [[nodiscard]] KIO::WorkerResult clearTrash();
0058 
0059     [[nodiscard]] KIO::WorkerResult doFileOp(const QUrl &url, UINT wFunc, FILEOP_FLAGS fFlags);
0060     [[nodiscard]] KIO::WorkerResult translateError(HRESULT retValue);
0061 
0062     KConfig m_config;
0063     HWND m_notificationWindow;
0064     IShellFolder2 *m_isfTrashFolder;
0065     LPMALLOC m_pMalloc;
0066     ULONG m_hNotifyRBin;
0067 };
0068 
0069 #endif