1
0
mirror of https://github.com/QRouland/UTPass.git synced 2025-02-11 15:07:16 +00:00
UTPass/plugins/Utils/utils.h

86 lines
2.2 KiB
C
Raw Normal View History

2019-09-20 21:29:39 +02:00
#ifndef UTILS_H
#define UTILS_H
#include <QObject>
#include <QUrl>
#include <QQuickWindow>
2025-01-20 15:46:57 +01:00
#include <memory>
#include <QSemaphore>
2019-09-20 21:29:39 +02:00
2025-01-17 10:40:54 +01:00
/**
* @class Utils
* @brief A utility class that provides helper functions for file and directory operations.
*
* The `Utils` class contains various helper methods such as for managing files and directories, including unzipping files
* and removing files or directories.
*/
2019-09-20 21:29:39 +02:00
class Utils : public QObject
{
Q_OBJECT
2025-01-20 15:46:57 +01:00
private slots:
/**
* @brief Slot to handle the result of a unzip operation.
* @param err True if an error occurred during the operation.
*/
void unzipResult(bool err);
signals:
2025-01-17 10:40:54 +01:00
/**
2025-01-20 15:46:57 +01:00
* @brief Emitted when the archive is successfully extracted.
2025-01-17 10:40:54 +01:00
*/
2025-01-20 15:46:57 +01:00
void unzipSucceed();
2025-01-17 10:40:54 +01:00
/**
2025-01-20 15:46:57 +01:00
* @brief Emitted when the unzipping operation fails.
*/
void unzipFailed();
2025-01-20 15:46:57 +01:00
private:
std::unique_ptr<QSemaphore> m_sem; /**< Semaphore for managing concurrent operations. */
public:
/**
* @brief Constructor for the Utils class.
2025-01-17 10:40:54 +01:00
*/
2025-01-20 15:46:57 +01:00
Utils();
2019-09-20 21:29:39 +02:00
2025-01-17 10:40:54 +01:00
/**
* @brief Start a job to unzips a ZIP file to the specified output directory.
2025-01-17 10:40:54 +01:00
*
* @param zip_url The URL of the ZIP file to unzip.
* @param dir_out The output directory where the contents of the ZIP file should be extracted.
* @return `true` if the unzipping job is started successfullly, `false` otherwise.
2025-01-17 10:40:54 +01:00
*/
2019-09-20 21:29:39 +02:00
Q_INVOKABLE bool unzip(QUrl zip_url, QString dir_out);
2025-01-17 10:40:54 +01:00
/**
* @brief Retrieves the path to the manifest data.
*
* This function returns the full path to the manifest file used by the application.
*
* @return A QString containing the manifest file path.
*/
Q_INVOKABLE QString manifestPath();
/**
* @brief Removes a file located at the specified URL.
*
* @param file_url The URL of the file to remove.
* @return `true` if the file was successfully removed; `false` otherwise.
*/
Q_INVOKABLE bool rmFile(QUrl file_url);
/**
* @brief Removes a directory located at the specified URL.
*
* @param dir_url The URL of the directory to remove.
* @return `true` if the directory was successfully removed; `false` otherwise.
*/
Q_INVOKABLE bool rmDir(QUrl dir_url);
2019-09-20 21:29:39 +02:00
};
#endif