|
| 1 | +"""Unified transfer tab — sidebar of remote backends over one stack. |
| 2 | +
|
| 3 | +Collapses the six remote-backend tabs (HTTP, Google Drive, S3, Azure |
| 4 | +Blob, Dropbox, SFTP) into a single tab with a sidebar picker. The |
| 5 | +existing per-backend widgets are reused verbatim as the stack pages |
| 6 | +so feature parity is preserved. |
| 7 | +""" |
| 8 | + |
| 9 | +from __future__ import annotations |
| 10 | + |
| 11 | +from typing import NamedTuple |
| 12 | + |
| 13 | +from PySide6.QtCore import QThreadPool |
| 14 | +from PySide6.QtWidgets import ( |
| 15 | + QHBoxLayout, |
| 16 | + QListWidget, |
| 17 | + QListWidgetItem, |
| 18 | + QStackedWidget, |
| 19 | + QWidget, |
| 20 | +) |
| 21 | + |
| 22 | +from automation_file.ui.log_widget import LogPanel |
| 23 | +from automation_file.ui.tabs.azure_tab import AzureBlobTab |
| 24 | +from automation_file.ui.tabs.base import BaseTab |
| 25 | +from automation_file.ui.tabs.drive_tab import GoogleDriveTab |
| 26 | +from automation_file.ui.tabs.dropbox_tab import DropboxTab |
| 27 | +from automation_file.ui.tabs.http_tab import HTTPDownloadTab |
| 28 | +from automation_file.ui.tabs.s3_tab import S3Tab |
| 29 | +from automation_file.ui.tabs.sftp_tab import SFTPTab |
| 30 | + |
| 31 | + |
| 32 | +class _BackendEntry(NamedTuple): |
| 33 | + label: str |
| 34 | + factory: type[BaseTab] |
| 35 | + |
| 36 | + |
| 37 | +_BACKENDS: tuple[_BackendEntry, ...] = ( |
| 38 | + _BackendEntry("HTTP download", HTTPDownloadTab), |
| 39 | + _BackendEntry("Google Drive", GoogleDriveTab), |
| 40 | + _BackendEntry("Amazon S3", S3Tab), |
| 41 | + _BackendEntry("Azure Blob", AzureBlobTab), |
| 42 | + _BackendEntry("Dropbox", DropboxTab), |
| 43 | + _BackendEntry("SFTP", SFTPTab), |
| 44 | +) |
| 45 | + |
| 46 | + |
| 47 | +class TransferTab(BaseTab): |
| 48 | + """Sidebar-selectable container for every remote backend.""" |
| 49 | + |
| 50 | + def __init__(self, log: LogPanel, pool: QThreadPool) -> None: |
| 51 | + super().__init__(log, pool) |
| 52 | + self._sidebar = QListWidget() |
| 53 | + self._sidebar.setFixedWidth(180) |
| 54 | + self._stack = QStackedWidget() |
| 55 | + for entry in _BACKENDS: |
| 56 | + self._sidebar.addItem(QListWidgetItem(entry.label)) |
| 57 | + self._stack.addWidget(entry.factory(log, pool)) |
| 58 | + self._sidebar.currentRowChanged.connect(self._stack.setCurrentIndex) |
| 59 | + self._sidebar.setCurrentRow(0) |
| 60 | + |
| 61 | + root = QHBoxLayout(self) |
| 62 | + root.setContentsMargins(0, 0, 0, 0) |
| 63 | + root.addWidget(self._sidebar) |
| 64 | + root.addWidget(self._stack, 1) |
| 65 | + |
| 66 | + def current_backend(self) -> str: |
| 67 | + row = self._sidebar.currentRow() |
| 68 | + return _BACKENDS[row].label if 0 <= row < len(_BACKENDS) else "" |
| 69 | + |
| 70 | + def select_backend(self, label: str) -> bool: |
| 71 | + for index, entry in enumerate(_BACKENDS): |
| 72 | + if entry.label == label: |
| 73 | + self._sidebar.setCurrentRow(index) |
| 74 | + return True |
| 75 | + return False |
| 76 | + |
| 77 | + def inner_widget(self, label: str) -> QWidget | None: |
| 78 | + for index, entry in enumerate(_BACKENDS): |
| 79 | + if entry.label == label: |
| 80 | + return self._stack.widget(index) |
| 81 | + return None |
0 commit comments