2026-08-22 22:43:53 +05:30
|
|
|
#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;
|
|
|
|
|
void printData();
|
2026-08-24 15:23:46 +05:30
|
|
|
void writeData(std::string file_path);
|
|
|
|
|
void readFromData(std::string file_path);
|
2026-08-22 22:43:53 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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 = "";
|
|
|
|
|
public:
|
|
|
|
|
explicit MainScreen(std::string search_term = "", QObject *parent = nullptr);
|
|
|
|
|
signals:
|
|
|
|
|
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
|