mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 17:59:43 +02:00
add download path setting
This commit is contained in:
+24
-8
@@ -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()
|
||||
|
||||
|
||||
@@ -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),
|
||||
]
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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=[])
|
||||
state = AppState(posts=[], post_titles=[], post_urls=[], download_path="")
|
||||
|
||||
Reference in New Issue
Block a user