72 lines
1.6 KiB
C++
72 lines
1.6 KiB
C++
#ifndef TORRENTSESSION_H
|
|
#define TORRENTSESSION_H
|
|
|
|
#include <QObject>
|
|
#include <QThread>
|
|
#include <QLocalServer>
|
|
#include <QLocalSocket>
|
|
#include <QCoreApplication>
|
|
#include <QProcess>
|
|
#include <filesystem>
|
|
#include <QTimer>
|
|
#include <unistd.h>
|
|
|
|
|
|
struct SearchItem;
|
|
|
|
class SocketManager: public QObject {
|
|
Q_OBJECT
|
|
QLocalServer *server = nullptr;
|
|
QLocalSocket *socket = nullptr;
|
|
public:
|
|
SocketManager(QObject *parent = nullptr);
|
|
signals:
|
|
void status();
|
|
void resume();
|
|
void pause();
|
|
void remove();
|
|
|
|
public slots:
|
|
void start();
|
|
void statusSignalFromTorrentSession(QByteArray data);
|
|
|
|
private slots:
|
|
void addConnection();
|
|
void commandFromClient();
|
|
private:
|
|
void sendSignalToTorrentSession(QString command);
|
|
std::filesystem::path testDir(std::string dir_name, std::string file_format);
|
|
std::string numToStr(int num);
|
|
};
|
|
|
|
class TorrentSession : public QObject
|
|
{
|
|
Q_OBJECT
|
|
SearchItem *item = nullptr;
|
|
std::filesystem::path download_path;
|
|
enum class Status {
|
|
Downloading,
|
|
Paused,
|
|
Finished,
|
|
Seeding,
|
|
};
|
|
SocketManager *manager = nullptr;
|
|
QThread *socket_manager_thread = nullptr;
|
|
QTimer start_timer;
|
|
public:
|
|
explicit TorrentSession(SearchItem it, std::filesystem::path download_path, QObject *parent = nullptr);
|
|
int start();
|
|
signals:
|
|
void startSocketManager();
|
|
void sendStatusSignalToSocketManager(QByteArray data);
|
|
public slots:
|
|
void sendStatus();
|
|
void pause();
|
|
void resume();
|
|
void remove();
|
|
private slots:
|
|
void launchSession();
|
|
signals:
|
|
};
|
|
|
|
#endif // TORRENTSESSION_H
|