From d7d454a213b1297d68f90fc6005edd1257224b82 Mon Sep 17 00:00:00 2001 From: KeksNino Date: Fri, 10 Oct 2025 19:10:11 +0200 Subject: [PATCH] add download path setting --- core/interface/gui.py | 32 +++++++++++++++++++++++-------- core/network/aria2_integration.py | 7 ++----- core/utils/config/config.py | 4 +++- core/utils/config/settings.py | 5 ++--- core/utils/data/state.py | 4 +++- 5 files changed, 34 insertions(+), 18 deletions(-) diff --git a/core/interface/gui.py b/core/interface/gui.py index eb70eb0..1591dbc 100644 --- a/core/interface/gui.py +++ b/core/interface/gui.py @@ -133,7 +133,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget): print("Settings dialog opened") dialog = QDialog(self) dialog.setWindowTitle("Settings") - dialog.setFixedSize(400, 200) + dialog.setFixedSize(800, 400) dialog.setLayout(QVBoxLayout()) dialog.layout().addWidget(QLabel("Settings")) @@ -173,30 +173,46 @@ class MainWindow(QtWidgets.QMainWindow, QWidget): api_url_container = QWidget() api_url_layout = QHBoxLayout() - text_edit = QTextEdit() + api_url = QTextEdit() api_url_layout.addWidget(QLabel("API Server URL:")) - api_url_layout.addWidget(text_edit) + api_url_layout.addWidget(api_url) api_url_container.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) api_url_container.setLayout(api_url_layout) - text_edit.setText(state.api_url) + api_url.setText(state.api_url) dialog.layout().addWidget(api_url_container) + ################# + # DOWNLOAD PATH # + ################# - layout = QHBoxLayout() # layout for buttons + download_path_container = QWidget() + download_path_layout = QHBoxLayout() + + download_path = QTextEdit() + download_path_layout.addWidget(QLabel("Download Path:")) + download_path_layout.addWidget(download_path) + download_path_container.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) + download_path_container.setLayout(download_path_layout) + download_path.setText(state.download_path) + dialog.layout().addWidget(download_path_container) + + ############### + # SAVE/CANCEL # + ############### + + layout = QHBoxLayout() save_btn = QPushButton("Save") cancel_btn = QPushButton("Cancel") - save_btn.clicked.connect(lambda: save_settings(thread_box.value(), close_settings, text_edit.toPlainText())) + save_btn.clicked.connect(lambda: save_settings(thread_box.value(), close_settings, api_url.toPlainText(), download_path.toPlainText())) cancel_btn.clicked.connect(dialog.reject) print(thread_box.value()) layout.addWidget(cancel_btn) layout.addWidget(save_btn) - dialog.layout().addLayout(layout) - dialog.exec() diff --git a/core/network/aria2_integration.py b/core/network/aria2_integration.py index 0ad4377..a732a0f 100644 --- a/core/network/aria2_integration.py +++ b/core/network/aria2_integration.py @@ -1,5 +1,4 @@ import aria2p -import os import subprocess from core.utils.data.state import state @@ -17,10 +16,8 @@ def run_aria2p(): return aria2 - - def aria2server(): - downloads_dir = os.path.join("Library") + download_path = state.download_path cmd = [ "aria2c", @@ -28,7 +25,7 @@ def aria2server(): "--disable-ipv6", # added this since it caused problems with vpns "--rpc-listen-all", "--rpc-listen-port=6800", - f"--dir={downloads_dir}", + f"--dir={download_path}", "-x", str(state.aria2_threads), "-s", str(state.aria2_threads), ] diff --git a/core/utils/config/config.py b/core/utils/config/config.py index 1ce51a9..be356c9 100644 --- a/core/utils/config/config.py +++ b/core/utils/config/config.py @@ -7,12 +7,13 @@ from core.utils.data.state import state def create_config(): config = configparser.ConfigParser() - config["General"] = {"debug": True, "api_url": f"{state.api_url}", "aria2_threads": f"{state.aria2_threads}"} + config["General"] = {"debug": True, "api_url": f"{state.api_url}", "aria2_threads": f"{state.aria2_threads}", "download_path": f"{state.download_path}"} if platform.system() == "Windows": config_dir = os.environ.get("APPDATA", os.path.expanduser("~\\AppData\\Roaming")) else: config_dir = os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config")) + settings_path = os.path.join(config_dir, "SoftwareManager") os.makedirs(settings_path, exist_ok=True) @@ -39,4 +40,5 @@ def read_config(): state.debug = config.getboolean("General", "debug") state.api_url = config.get("General", "api_url") state.aria2_threads = config.getint("General", "aria2_threads") + state.download_path = config.get("General", "download_path") diff --git a/core/utils/config/settings.py b/core/utils/config/settings.py index e030293..24151f1 100644 --- a/core/utils/config/settings.py +++ b/core/utils/config/settings.py @@ -1,7 +1,6 @@ from core.utils.data.state import state from .config import create_config import os -import platform def restart_aria2c(): import main # had to do this because of circle import :( @@ -14,10 +13,10 @@ def restart_aria2c(): atexit.unregister(main.kill_aria2server) atexit.register(main.kill_aria2server) -def save_settings(thread_count, close, apiurl): - +def save_settings(thread_count, close, apiurl, download_path): state.aria2_threads = thread_count state.api_url = apiurl + state.download_path = download_path create_config() restart_aria2c() diff --git a/core/utils/data/state.py b/core/utils/data/state.py index 01acd41..dea94d4 100644 --- a/core/utils/data/state.py +++ b/core/utils/data/state.py @@ -1,5 +1,6 @@ from dataclasses import dataclass from typing import Optional, Any, List, Dict +from pathlib import Path @dataclass class AppState: @@ -9,7 +10,8 @@ class AppState: debug: bool = False tracker: str = "rutracker" api_url: str = "https://api.michijackson.xyz" + download_path: str = str(Path.home() / "Downloads") aria2process: Optional[Any] = None aria2_threads: int = 4 -state = AppState(posts=[], post_titles=[], post_urls=[]) \ No newline at end of file +state = AppState(posts=[], post_titles=[], post_urls=[], download_path="")