103 lines
2.8 KiB
C++
103 lines
2.8 KiB
C++
#ifndef MAINSCREEN_H
|
|
#define MAINSCREEN_H
|
|
|
|
#include <QObject>
|
|
#include <QNetworkAccessManager>
|
|
#include <QNetworkRequest>
|
|
#include <QNetworkReply>
|
|
#include <QJsonDocument>
|
|
#include <QJsonValue>
|
|
#include <QJsonObject>
|
|
#include <QJsonArray>
|
|
#include <QUrlQuery>
|
|
#include <ftxui/ftxui.hpp>
|
|
#include <expected>
|
|
#include <filesystem>
|
|
#include <ftxui/component/component.hpp>
|
|
#include <ftxui/component/screen_interactive.hpp>
|
|
#include <ftxui/dom/elements.hpp>
|
|
#include "torrentsession.h"
|
|
|
|
|
|
|
|
struct SearchItem {
|
|
QString title;
|
|
QUrl url;
|
|
QString size;
|
|
QString seeders;
|
|
QString leechers;
|
|
QString downloads;
|
|
QString timestamp;
|
|
QString magnet;
|
|
std::filesystem::path download_path;
|
|
void printData();
|
|
void writeData(std::string file_path);
|
|
void readFromData(std::string file_path);
|
|
};
|
|
|
|
struct Status {
|
|
SearchItem it;
|
|
int progress;
|
|
float speed;
|
|
};
|
|
|
|
class Socket: public QObject {
|
|
Q_OBJECT
|
|
std::unordered_map<std::string, QLocalSocket *> active_sockets;
|
|
QTimer *recheck = nullptr;
|
|
QTimer *timer = nullptr;
|
|
bool checked_resume_files = false;
|
|
public:
|
|
Socket(QObject *parent = nullptr);
|
|
signals:
|
|
void launchTorrentSession(SearchItem it);
|
|
void sendStatusToMainScreen(Status st);
|
|
public slots:
|
|
void start();
|
|
void startNotDownloadingSessions();
|
|
private slots:
|
|
bool isTitleInActiveSession(QString title);
|
|
void socketReadyRead();
|
|
};
|
|
|
|
class MainScreen : public QObject
|
|
{
|
|
Q_OBJECT
|
|
|
|
class Tags {
|
|
public:
|
|
Tags() = delete;
|
|
static std::string getTag(std::string file_name, std::string key);
|
|
static void setTag(std::string file_name, std::string key, std::string value);
|
|
static std::unordered_map<std::string, std::string> getAllTags(std::string file_name);
|
|
|
|
private:
|
|
static QByteArray readFile(std::string file_name);
|
|
static bool writeFile(std::string file_name, QByteArray data);
|
|
};
|
|
|
|
QNetworkAccessManager *manager = nullptr;
|
|
std::string tags_file_path = "";
|
|
Socket *socket = nullptr;
|
|
QThread *socket_thread = nullptr;
|
|
public:
|
|
explicit MainScreen(std::string search_term = "", QObject *parent = nullptr);
|
|
signals:
|
|
void startSocket();
|
|
public slots:
|
|
void resumeOldTorrentSession(SearchItem it);
|
|
void statusFromSocket(Status st);
|
|
private:
|
|
void renderSearchPage(std::string search_term);
|
|
void renderHomePage();
|
|
std::vector<SearchItem> parseSearchPage(std::string html_page);
|
|
std::vector<std::string> getStringEntries(std::vector<SearchItem> res);
|
|
int displaySearchMenu(std::vector<SearchItem> res);
|
|
int startDownloadIndex(std::vector<SearchItem> res, int index);
|
|
std::expected<std::string,int> runBasicShell(SearchItem it);
|
|
std::string stripForArgument(std::string command, int index);
|
|
private slots:
|
|
void renderSearchPage_(QNetworkReply *rep);
|
|
};
|
|
|
|
#endif // MAINSCREEN_H
|