1
0
mirror of https://github.com/QRouland/UTPass.git synced 2025-02-24 20:24:56 +00:00

150 lines
5.0 KiB
C
Raw Normal View History

2025-01-10 13:48:38 +01:00
#ifndef GIT_H
#define GIT_H
2025-01-17 10:40:54 +01:00
#include "jobs/gitjob.h"
2025-02-21 15:50:27 +01:00
#include "qdebug.h"
2025-01-10 13:48:38 +01:00
#include <QUrl>
#include <QObject>
2025-01-17 10:40:54 +01:00
#include <QSemaphore>
#include <QtCore/QDir>
2025-01-10 13:48:38 +01:00
2025-01-14 08:15:03 +01:00
/**
2025-01-17 10:40:54 +01:00
* @class Git
* @brief A class that provides Git functionality for cloning and updating repositories.
*
* The `Git` class provides a set of methods to do Git operation on remote URLs.
2025-01-14 08:15:03 +01:00
*/
2025-01-10 13:48:38 +01:00
class Git : public QObject
{
Q_OBJECT
2025-02-21 15:50:27 +01:00
Q_PROPERTY(QString privKey READ pubKeyPath)
Q_PROPERTY(QString pubKey READ privKeyPath)
2025-01-10 13:48:38 +01:00
2025-01-17 10:40:54 +01:00
private slots:
/**
* @brief Slot that handles the result of a cloning operation.
*
* This slot is connected to the result of the cloning operation and is triggered when the cloning
* process finishes. It emits the appropriate signal based on whether the clone operation succeeded
* or failed.
*
* @param err A boolean indicating whether an error occurred during cloning. `true` if the clone failed,
* `false` if it succeeded.
*/
void cloneResult(const bool err);
signals:
/**
* @brief Signal emitted when the cloning operation succeeds.
*
* This signal is emitted when the Git repository is successfully cloned.
*/
void cloneSucceed();
/**
* @brief Signal emitted when the cloning operation fails.
*
* This signal is emitted when an error occurs during the cloning operation.
*/
void cloneFailed();
private:
2025-01-17 10:40:54 +01:00
std::unique_ptr<QSemaphore> m_sem; /**< Semaphore for managing concurrent operations. */
2025-02-21 15:50:27 +01:00
QDir m_ssh_homedir; /**< Directory that contains the SSH keys (public and private). */
2025-01-17 10:40:54 +01:00
/**
* @brief Clones a repository from a specified URL.
*
* This private method initiates the cloning job. It sets up the repository cloning process based on
* the specified URL, destination path, and cloning mode (HTTP or SSH).
*
* @param url The URL of the Git repository to clone.
* @param path The destination path for the cloned repository.
* @param mode The cloning mode, such as HTTP or SSH (represented as `cred_type`).
* @return `true` if the cloning process was successful, `false` otherwise.
*/
bool clone(QString url, QString path, cred_type mode);
2025-02-21 15:50:27 +01:00
protected:
/**
* @brief Get the path to the public keyring.
*
* @return The file path to the public key.
*/
QString pubKeyPath()
{
return this->m_ssh_homedir.filePath("id_rsa.pub");
}
/**
* @brief Get the path to the secret keyring.
*
* @return The file path to the private key.
*/
QString privKeyPath()
{
return this->m_ssh_homedir.filePath("id_rsa");
}
2025-01-10 13:48:38 +01:00
public:
2025-01-17 10:40:54 +01:00
/**
* @brief Constructor for the Git class.
*
* Initializes the `Git` class, setting up necessary resources such as the semaphore for concurrent operation management.
*/
Git();
2025-01-10 13:48:38 +01:00
2025-01-17 10:40:54 +01:00
/**
* @brief Destructor for the Git class.
*
* Cleans up any resources used by the `Git` class, ensuring that no ongoing operations or resources are left hanging.
*/
~Git() override;
2025-02-21 15:50:27 +01:00
Q_INVOKABLE bool importSshKey(QUrl source_path, bool is_private);
2025-01-17 10:40:54 +01:00
/**
* @brief Clones a repository over HTTP.
*
* This method clones a Git repository from the specified HTTP URL and saves it to the given destination path.
* It is a wrapper around the private `clone()` method, specifying the HTTP cloning mode.
*
* @param url The HTTP URL of the Git repository to clone.
* @param path The destination path for the cloned repository.
* @return `true` if the clone operation was successful, `false` otherwise.
*/
2025-01-14 08:15:03 +01:00
Q_INVOKABLE bool cloneHttp(QString url, QString path);
2025-01-17 10:40:54 +01:00
/**
* @brief Clones a repository over HTTP with a password for authentication.
*
* This method clones a Git repository from the specified HTTP URL using the provided password for authentication,
* and saves it to the given destination path.
*
* @param url The HTTP URL of the Git repository to clone.
* @param path The destination path for the cloned repository.
* @param pass The password used for HTTP authentication.
2025-02-21 15:50:27 +01:00
* @return `true` if the clone job operation was successfully started, `false` otherwise.
2025-01-17 10:40:54 +01:00
*/
2025-01-14 08:15:03 +01:00
Q_INVOKABLE bool cloneHttpPass(QString url, QString path, QString pass);
2025-01-17 10:40:54 +01:00
2025-02-21 15:50:27 +01:00
/**
* @brief Clones a repository over SSH with a key for authentication.
*
* This method clones a Git repository from the specified ssh URL using the provided password for authentication,
* and saves it to the given destination path.
*
* @param url The HTTP URL of the Git repository to clone.
* @param path The destination path for the cloned repository.
* @param passphrase The passphrase used for SSH authentication.
* @return `true` if the clone job operation was successfully started, `false` otherwise.
*/
Q_INVOKABLE bool cloneSshKey(QString url, QString path, QString passphrase);
2025-01-17 10:40:54 +01:00
2025-01-10 13:48:38 +01:00
// Q_INVOKABLE bool update(QUrl url, QString path);
2025-01-17 10:40:54 +01:00
// ....
2025-01-10 13:48:38 +01:00
};
#endif