nekodl/mainscreen.h

103 lines
2.8 KiB
C
Raw Normal View History

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;
2026-08-25 17:26:04 +05:30
std::filesystem::path download_path;
2026-08-22 22:43:53 +05:30
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
};
2026-08-25 17:26:04 +05:30
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();
};
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 = "";
2026-08-25 17:26:04 +05:30
Socket *socket = nullptr;
QThread *socket_thread = nullptr;
2026-08-22 22:43:53 +05:30
public:
explicit MainScreen(std::string search_term = "", QObject *parent = nullptr);
signals:
2026-08-25 17:26:04 +05:30
void startSocket();
public slots:
void resumeOldTorrentSession(SearchItem it);
void statusFromSocket(Status st);
2026-08-22 22:43:53 +05:30
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