/** * @RDE_HEADER@ * Advanced file copy manager with progress dialog * $Id: tpm_exported_scripts_dialog.cpp 53111 2021-03-22 08:21:29Z wille_m $ * $HeadURL: svn://slssvn/TDS/branches/product/iterations/21_03_salted_caramel/Lts/Plugins/TakeHomePackageManager/tpm_exported_scripts_dialog.cpp $ * $Author: wille_m $ * * Created by Mike Wille, SLTE, 2024-02-09 */ #pragma once #include #include #include #include namespace TakeHomePackageManager { class ProcessOverlay; struct THP2COMMON_EXPORT CopyInfo // :'( we need this to cut the srcPath from the file path, to have the same folder structure in the destionation folder { QString srcPath; QString dstPath; QFileInfo fileInfo; }; using CopyInfoList = QList; THP2COMMON_EXPORT CopyInfoList getFilesFromFolder(const QString &srcPath, const QString &dstPath, const QStringList &excludes = {}) noexcept(false); THP2COMMON_EXPORT void copyFiles(const CopyInfoList &fileList, LtsWidgets::LtsDialog *dialog) noexcept(false); // TODO: mv to LtsCommon class AsyncFileCopy : public QObject { Q_OBJECT public: static const int s_chunkSize = 1 * 1024 * 1024; // 1MB static AsyncFileCopy *createAsyncFileCopy(const CopyInfoList &fileList) // to prevent the user from thinking having to delete the class (which it does itself) { return new AsyncFileCopy(fileList); } ~AsyncFileCopy() = default; private: AsyncFileCopy(const CopyInfoList &fileList); private: bool copy(const CopyInfoList &fileList); bool m_wasCanceled { false }; public slots: void slotCancel() { m_wasCanceled = true; } signals: void newAction(const QString &newAction); void status(const QString &status); void started(int fileCount, qint64 bytesTotalAll); void newFile(int currentFile, qint64 bytesTotalFile, const QString &filename); void progress(qint64 bytesCopiedFile, qint64 bytesCopiedAll); void finished(bool success); }; class THP2COMMON_EXPORT CopyProcess : public QObject { Q_OBJECT public: CopyProcess(const CopyInfoList &fileList, QObject *parent = nullptr); ~CopyProcess(); QWidget *process(); signals: void signalCancel(); void finished(bool success); private: ProcessOverlay *m_process; bool m_wasCanceled { false }; QString m_currentAction; }; } // namespace TakeHomePackageManager