mirror of
https://github.com/KeksPirates/SoftwareManager.git
synced 2026-08-04 01:49:42 +02:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bf20625832 | |||
| 8d218443bf | |||
| a55a049583 | |||
| 4e7e08c136 |
+72
-23
@@ -488,10 +488,19 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
|
|
||||||
def setEditorData(self, editor, index):
|
def setEditorData(self, editor, index):
|
||||||
button = editor.findChild(QtWidgets.QPushButton)
|
button = editor.findChild(QtWidgets.QPushButton)
|
||||||
magnet_link = list(state.active_downloads.keys())[index.row()]
|
if not button:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
with state.downloads_lock:
|
||||||
|
keys = list(state.active_downloads.keys())
|
||||||
|
if index.row() >= len(keys):
|
||||||
|
return
|
||||||
|
magnet_link = keys[index.row()]
|
||||||
magnetdl = state.active_downloads[magnet_link]
|
magnetdl = state.active_downloads[magnet_link]
|
||||||
status = magnetdl.status()
|
status = magnetdl.status()
|
||||||
if button:
|
except (RuntimeError, IndexError, KeyError):
|
||||||
|
return
|
||||||
|
|
||||||
if status.state == lt.torrent_status.seeding:
|
if status.state == lt.torrent_status.seeding:
|
||||||
button.setIcon(svg_icon(SVG_FOLDER, 18))
|
button.setIcon(svg_icon(SVG_FOLDER, 18))
|
||||||
button.setText("")
|
button.setText("")
|
||||||
@@ -500,10 +509,19 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
button.setIcon(svg_icon(SVG_PLAY if is_user_paused else SVG_PAUSE, 18))
|
button.setIcon(svg_icon(SVG_PLAY if is_user_paused else SVG_PAUSE, 18))
|
||||||
button.setText("")
|
button.setText("")
|
||||||
|
|
||||||
|
|
||||||
def createEditor(self, parent, option, index):
|
def createEditor(self, parent, option, index):
|
||||||
magnet_link = list(state.active_downloads.keys())[index.row()]
|
try:
|
||||||
|
with state.downloads_lock:
|
||||||
|
keys = list(state.active_downloads.keys())
|
||||||
|
if index.row() >= len(keys):
|
||||||
|
return QWidget(parent)
|
||||||
|
magnet_link = keys[index.row()]
|
||||||
magnetdl = state.active_downloads[magnet_link]
|
magnetdl = state.active_downloads[magnet_link]
|
||||||
status = magnetdl.status()
|
status = magnetdl.status()
|
||||||
|
except (RuntimeError, IndexError, KeyError):
|
||||||
|
return QWidget(parent)
|
||||||
|
|
||||||
widget = QWidget(parent)
|
widget = QWidget(parent)
|
||||||
widget.setStyleSheet("border: none; background: transparent;")
|
widget.setStyleSheet("border: none; background: transparent;")
|
||||||
layout = QHBoxLayout(widget)
|
layout = QHBoxLayout(widget)
|
||||||
@@ -526,6 +544,7 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
widget.setLayout(layout)
|
widget.setLayout(layout)
|
||||||
return widget
|
return widget
|
||||||
|
|
||||||
|
|
||||||
def editorEvent(self, event, model, option, index):
|
def editorEvent(self, event, model, option, index):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -846,10 +865,14 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
if idx.isValid():
|
if idx.isValid():
|
||||||
editor = self.downloadList.indexWidget(idx)
|
editor = self.downloadList.indexWidget(idx)
|
||||||
if editor and delegate:
|
if editor and delegate:
|
||||||
|
try:
|
||||||
delegate.setEditorData(editor, idx)
|
delegate.setEditorData(editor, idx)
|
||||||
|
except RuntimeError:
|
||||||
|
pass
|
||||||
|
|
||||||
self._update_speed_label()
|
self._update_speed_label()
|
||||||
|
|
||||||
|
|
||||||
def _update_speed_label(self):
|
def _update_speed_label(self):
|
||||||
total_down = 0
|
total_down = 0
|
||||||
total_up = 0
|
total_up = 0
|
||||||
@@ -991,60 +1014,86 @@ class MainWindow(QtWidgets.QMainWindow, QWidget):
|
|||||||
if not hasattr(self, '_context_menu_row'):
|
if not hasattr(self, '_context_menu_row'):
|
||||||
return
|
return
|
||||||
row = self._context_menu_row
|
row = self._context_menu_row
|
||||||
|
with state.downloads_lock:
|
||||||
if row < 0 or row >= len(state.active_downloads):
|
if row < 0 or row >= len(state.active_downloads):
|
||||||
return
|
return
|
||||||
magnet_link = list(state.active_downloads.keys())[row]
|
magnet_link = list(state.active_downloads.keys())[row]
|
||||||
magnetdl = state.active_downloads[magnet_link]
|
magnetdl = state.active_downloads[magnet_link]
|
||||||
confirm = QMessageBox.question(self, "Cancel Download", f"Are you sure you want to cancel the download of '{magnetdl.status().name}'?", QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
|
|
||||||
|
# Cache the name BEFORE removing from session
|
||||||
|
try:
|
||||||
|
torrent_name = magnetdl.status().name
|
||||||
|
except RuntimeError:
|
||||||
|
torrent_name = "Unknown"
|
||||||
|
|
||||||
|
confirm = QMessageBox.question(
|
||||||
|
self, "Cancel Download",
|
||||||
|
f"Are you sure you want to cancel the download of '{torrent_name}'?",
|
||||||
|
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
|
||||||
|
)
|
||||||
if confirm == QMessageBox.StandardButton.Yes:
|
if confirm == QMessageBox.StandardButton.Yes:
|
||||||
if hasattr(magnetdl, 'stop'):
|
with state.downloads_lock:
|
||||||
magnetdl.stop()
|
state.active_downloads.pop(magnet_link, None)
|
||||||
elif state.dl_session:
|
remove_download_log(magnet_link)
|
||||||
|
|
||||||
|
if state.dl_session:
|
||||||
try:
|
try:
|
||||||
state.dl_session.remove_torrent(magnetdl)
|
state.dl_session.remove_torrent(magnetdl)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
del state.active_downloads[magnet_link]
|
|
||||||
remove_download_log(magnet_link)
|
consoleLog(f"Cancelled download: {torrent_name}", True)
|
||||||
consoleLog(f"Cancelled download: {magnetdl.status().name}", True)
|
|
||||||
|
|
||||||
def deleteFileAction(self):
|
def deleteFileAction(self):
|
||||||
if not hasattr(self, '_context_menu_row'):
|
if not hasattr(self, '_context_menu_row'):
|
||||||
return
|
return
|
||||||
row = self._context_menu_row
|
row = self._context_menu_row
|
||||||
|
with state.downloads_lock:
|
||||||
if row < 0 or row >= len(state.active_downloads):
|
if row < 0 or row >= len(state.active_downloads):
|
||||||
return
|
return
|
||||||
magnet_link = list(state.active_downloads.keys())[row]
|
magnet_link = list(state.active_downloads.keys())[row]
|
||||||
magnetdl = state.active_downloads[magnet_link]
|
magnetdl = state.active_downloads[magnet_link]
|
||||||
|
|
||||||
|
try:
|
||||||
status = magnetdl.status()
|
status = magnetdl.status()
|
||||||
save_path = status.save_path
|
save_path = status.save_path
|
||||||
torrent_name = status.name
|
torrent_name = status.name
|
||||||
|
except RuntimeError:
|
||||||
|
consoleLog("Error: torrent handle already invalid", True)
|
||||||
|
with state.downloads_lock:
|
||||||
|
state.active_downloads.pop(magnet_link, None)
|
||||||
|
remove_download_log(magnet_link)
|
||||||
|
return
|
||||||
|
|
||||||
download_path = os.path.join(save_path, torrent_name)
|
download_path = os.path.join(save_path, torrent_name)
|
||||||
confirm = QMessageBox.question(self, "Delete Files", f"Are you sure you want to delete the downloaded files of '{magnetdl.status().name}'? This action cannot be undone.", QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
|
|
||||||
|
confirm = QMessageBox.question(
|
||||||
|
self, "Delete Files",
|
||||||
|
f"Are you sure you want to delete the downloaded files of '{torrent_name}'? This action cannot be undone.",
|
||||||
|
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
|
||||||
|
)
|
||||||
if confirm == QMessageBox.StandardButton.Yes:
|
if confirm == QMessageBox.StandardButton.Yes:
|
||||||
if hasattr(magnetdl, 'stop'):
|
with state.downloads_lock:
|
||||||
magnetdl.stop()
|
state.active_downloads.pop(magnet_link, None)
|
||||||
elif state.dl_session:
|
remove_download_log(magnet_link)
|
||||||
|
|
||||||
|
if state.dl_session:
|
||||||
try:
|
try:
|
||||||
state.dl_session.remove_torrent(magnetdl)
|
state.dl_session.remove_torrent(magnetdl)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if download_path and os.path.exists(download_path):
|
if download_path and os.path.exists(download_path):
|
||||||
try:
|
try:
|
||||||
if os.path.isfile(download_path):
|
if os.path.isfile(download_path):
|
||||||
remove_download_log(magnet_link)
|
|
||||||
os.remove(download_path)
|
os.remove(download_path)
|
||||||
del state.active_downloads[magnet_link]
|
consoleLog(f"Deleted files for: {torrent_name}", True)
|
||||||
consoleLog(f"Deleted files for: {magnetdl.status().name}", True)
|
|
||||||
else:
|
else:
|
||||||
import shutil
|
import shutil
|
||||||
remove_download_log(magnet_link)
|
|
||||||
shutil.rmtree(download_path)
|
shutil.rmtree(download_path)
|
||||||
del state.active_downloads[magnet_link]
|
consoleLog(f"Deleted files for: {torrent_name}", True)
|
||||||
consoleLog(f"Deleted files for: {magnetdl.status().name}", True)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
consoleLog(f"Error deleting files: {e}", True)
|
consoleLog(f"Error deleting files: {e}", True)
|
||||||
else:
|
else:
|
||||||
del state.active_downloads[magnet_link]
|
consoleLog(f"Removed entry (files not found): {torrent_name}", True)
|
||||||
remove_download_log(magnet_link)
|
|
||||||
consoleLog(f"Removed entry (files not found): {magnetdl.status().name}", True)
|
|
||||||
|
|||||||
@@ -213,11 +213,11 @@ class DirectDownloadHandle:
|
|||||||
self._status.mark_completed()
|
self._status.mark_completed()
|
||||||
update_download_completed(self.url, True)
|
update_download_completed(self.url, True)
|
||||||
self._clear_state()
|
self._clear_state()
|
||||||
consoleLog(f"✓ Finished downloading {self._name}")
|
consoleLog(f"Finished downloading {self._name}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._status.mark_error(str(e))
|
self._status.mark_error(str(e))
|
||||||
consoleLog(f"✗ Download failed for {self._name}: {e}")
|
consoleLog(f"Download failed for {self._name}: {e}")
|
||||||
finally:
|
finally:
|
||||||
if self._session:
|
if self._session:
|
||||||
self._session.close()
|
self._session.close()
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ def init_session():
|
|||||||
consoleLog("Initialized Session")
|
consoleLog("Initialized Session")
|
||||||
|
|
||||||
|
|
||||||
def add_download(magnet_uri, dl_path=state.download_path):
|
def add_download(magnet_uri):
|
||||||
|
|
||||||
if state.active_downloads is None:
|
if state.active_downloads is None:
|
||||||
state.active_downloads = {}
|
state.active_downloads = {}
|
||||||
@@ -89,7 +89,7 @@ def add_download(magnet_uri, dl_path=state.download_path):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
params = lt.parse_magnet_uri(magnet_uri)
|
params = lt.parse_magnet_uri(magnet_uri)
|
||||||
params.save_path = "."
|
params.save_path = state.download_path
|
||||||
|
|
||||||
handle = state.dl_session.add_torrent(params)
|
handle = state.dl_session.add_torrent(params)
|
||||||
|
|
||||||
@@ -100,7 +100,7 @@ def add_download(magnet_uri, dl_path=state.download_path):
|
|||||||
|
|
||||||
if free_space > total_size:
|
if free_space > total_size:
|
||||||
magnetdl = lt.parse_magnet_uri(magnet_uri)
|
magnetdl = lt.parse_magnet_uri(magnet_uri)
|
||||||
magnetdl.save_path = dl_path
|
magnetdl.save_path = state.download_path
|
||||||
download = state.dl_session.add_torrent(magnetdl)
|
download = state.dl_session.add_torrent(magnetdl)
|
||||||
else:
|
else:
|
||||||
download = None
|
download = None
|
||||||
|
|||||||
@@ -1,11 +1,8 @@
|
|||||||
from core.utils.logging.logs import consoleLog
|
from core.utils.logging.logs import consoleLog
|
||||||
from core.network.libtorrent_int import add_download
|
from core.network.libtorrent_int import add_download
|
||||||
|
|
||||||
def add_magnet(uri, dl_path=None):
|
def add_magnet(uri):
|
||||||
if uri is not None and uri.startswith("magnet:?"):
|
if uri is not None and uri.startswith("magnet:?"):
|
||||||
if dl_path:
|
|
||||||
add_download(uri, dl_path)
|
|
||||||
else:
|
|
||||||
add_download(uri)
|
add_download(uri)
|
||||||
consoleLog("Magnet URI added to LibTorrent")
|
consoleLog("Magnet URI added to LibTorrent")
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import os
|
|
||||||
import platform
|
|
||||||
import configparser
|
|
||||||
from core.utils.data.state import state
|
from core.utils.data.state import state
|
||||||
|
import configparser
|
||||||
|
import platform
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
def create_config():
|
def create_config():
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
@@ -15,7 +16,7 @@ def create_config():
|
|||||||
|
|
||||||
config["Network"] = {
|
config["Network"] = {
|
||||||
"api_url": f"{state.api_url}",
|
"api_url": f"{state.api_url}",
|
||||||
"download_path": f"{state.download_path}",
|
"bound_interface": f"{state.bound_interface}" if state.bound_interface is not None else "None",
|
||||||
"download_speed_limit": f"{state.down_speed_limit}",
|
"download_speed_limit": f"{state.down_speed_limit}",
|
||||||
"upload_speed_limit": f"{state.up_speed_limit}",
|
"upload_speed_limit": f"{state.up_speed_limit}",
|
||||||
"max_connections": f"{state.max_connections}",
|
"max_connections": f"{state.max_connections}",
|
||||||
@@ -23,7 +24,7 @@ def create_config():
|
|||||||
}
|
}
|
||||||
|
|
||||||
config["Paths"] = {
|
config["Paths"] = {
|
||||||
"bound_interface": f"{state.bound_interface}" if state.bound_interface is not None else "None",
|
"download_path": f"{state.download_path}",
|
||||||
"image_path": f"{state.image_path}"
|
"image_path": f"{state.image_path}"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,16 +65,16 @@ def read_config():
|
|||||||
|
|
||||||
# Network
|
# Network
|
||||||
state.api_url = config.get("Network", "api_url", fallback=state.api_url)
|
state.api_url = config.get("Network", "api_url", fallback=state.api_url)
|
||||||
state.download_path = config.get("Network", "download_path", fallback=state.download_path)
|
state.bound_interface = config.get("Network", "bound_interface", fallback=state.bound_interface)
|
||||||
|
if state.bound_interface == "None":
|
||||||
|
state.bound_interface = None
|
||||||
state.down_speed_limit = config.getint("Network", "download_speed_limit", fallback=state.down_speed_limit)
|
state.down_speed_limit = config.getint("Network", "download_speed_limit", fallback=state.down_speed_limit)
|
||||||
state.up_speed_limit = config.getint("Network", "upload_speed_limit", fallback=state.up_speed_limit)
|
state.up_speed_limit = config.getint("Network", "upload_speed_limit", fallback=state.up_speed_limit)
|
||||||
state.max_connections = config.getint("Network", "max_connections", fallback=state.max_connections)
|
state.max_connections = config.getint("Network", "max_connections", fallback=state.max_connections)
|
||||||
state.max_downloads = config.getint("Network", "max_downloads", fallback=state.max_downloads)
|
state.max_downloads = config.getint("Network", "max_downloads", fallback=state.max_downloads)
|
||||||
|
|
||||||
# Paths
|
# Paths
|
||||||
state.bound_interface = config.get("Paths", "bound_interface", fallback=state.bound_interface)
|
state.download_path = config.get("Paths", "download_path", fallback=state.download_path)
|
||||||
if state.bound_interface == "None":
|
|
||||||
state.bound_interface = None
|
|
||||||
state.image_path = config.get("Paths", "image_path", fallback=state.image_path)
|
state.image_path = config.get("Paths", "image_path", fallback=state.image_path)
|
||||||
|
|
||||||
create_config()
|
create_config()
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ def save_settings(close=lambda: None, apiurl=None, download_path=None, down_spee
|
|||||||
if bound_interface is not None:
|
if bound_interface is not None:
|
||||||
state.bound_interface = None if bound_interface == "None" else bound_interface
|
state.bound_interface = None if bound_interface == "None" else bound_interface
|
||||||
|
|
||||||
|
|
||||||
update_settings()
|
update_settings()
|
||||||
consoleLog("Saved Settings")
|
consoleLog("Saved Settings")
|
||||||
create_config()
|
create_config()
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class AppState(QObject):
|
|||||||
|
|
||||||
self.currenttracker: str = "rutracker"
|
self.currenttracker: str = "rutracker"
|
||||||
self.trackertable: QTableWidget
|
self.trackertable: QTableWidget
|
||||||
self.trackers: Dict[str,Dict[str,Any]] = {}# each tracker should add itself here
|
self.trackers: Dict[str,Dict[str,Any]] = {} # each tracker should add itself here
|
||||||
'''
|
'''
|
||||||
an example:
|
an example:
|
||||||
"rutracker" : {
|
"rutracker" : {
|
||||||
@@ -41,7 +41,6 @@ class AppState(QObject):
|
|||||||
self.interfaces: List = []
|
self.interfaces: List = []
|
||||||
self.active_interfaces: List = []
|
self.active_interfaces: List = []
|
||||||
self.bound_interface: Any = None
|
self.bound_interface: Any = None
|
||||||
|
|
||||||
self.log_buffer: List[str] = []
|
self.log_buffer: List[str] = []
|
||||||
self.downloads_lock = threading.RLock()
|
self.downloads_lock = threading.RLock()
|
||||||
self.main_window: Any = None
|
self.main_window: Any = None
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
from core.utils.logging.logs import consoleLog, remove_download_log
|
from core.utils.logging.logs import consoleLog, remove_download_log
|
||||||
from core.utils.network.download import run_download_direct, seed_magnet
|
from core.utils.network.download import run_download_direct, seed_magnet
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
def split_data(data):
|
def split_data(data):
|
||||||
|
|||||||
@@ -135,9 +135,7 @@ def _update_download_completed_inner(magnet_uri, completed) -> DownloadList:
|
|||||||
try:
|
try:
|
||||||
stored_magnet = (getattr(download, 'magnet_uri', None) or "").strip()
|
stored_magnet = (getattr(download, 'magnet_uri', None) or "").strip()
|
||||||
stored_url = (getattr(download, 'url', None) or "").strip()
|
stored_url = (getattr(download, 'url', None) or "").strip()
|
||||||
consoleLog(f"Comparing with magnet: {stored_magnet[:50] if stored_magnet else 'None'}...")
|
|
||||||
if identifier and (stored_magnet == identifier or stored_url == identifier):
|
if identifier and (stored_magnet == identifier or stored_url == identifier):
|
||||||
consoleLog(f"Match found! Setting completed={completed}")
|
|
||||||
download.completed = completed
|
download.completed = completed
|
||||||
found = True
|
found = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ def run_download(post):
|
|||||||
|
|
||||||
def run_download_direct(magnet_uri, dl_path=None, title="Direct Download"):
|
def run_download_direct(magnet_uri, dl_path=None, title="Direct Download"):
|
||||||
consoleLog(f"Magnet: {title}")
|
consoleLog(f"Magnet: {title}")
|
||||||
add_magnet(magnet_uri, dl_path)
|
add_magnet(magnet_uri)
|
||||||
add_download_log(title, "", magnet_uri, False)
|
add_download_log(title, "", magnet_uri, False)
|
||||||
|
|
||||||
def seed_magnet(magnet_uri, file_path):
|
def seed_magnet(magnet_uri, file_path):
|
||||||
|
|||||||
Reference in New Issue
Block a user