"""Extract target chooser dialog.""" # This file is part of ISO Scalpel. # Copyright (C) 2025 Jeremy Anderson # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, see # or write to the Free Software Foundation, Inc., 51 Franklin Street, # Fifth Floor, Boston, MA 02110-1301 USA. from __future__ import annotations import os from PySide6.QtWidgets import ( QCheckBox, QDialog, QDialogButtonBox, QFileDialog, QHBoxLayout, QLabel, QLineEdit, QPushButton, QVBoxLayout, ) class ExtractDialog(QDialog): """Ask the user where to extract one or more entries.""" def __init__(self, items: list[tuple[str, bool]], default_dir: str, parent=None): super().__init__(parent) self.setWindowTitle("Extract") self.setMinimumWidth(480) self._items = items layout = QVBoxLayout(self) count = len(items) names = ", ".join(os.path.basename(p) for p, _ in items[:3]) if count > 3: names += f" (+{count - 3} more)" layout.addWidget(QLabel(f"Extract {count} item(s): {names}")) self.dest = QLineEdit(default_dir) browse = QPushButton("Browse…") browse.clicked.connect(self._browse) row = QHBoxLayout() row.addWidget(self.dest, 1) row.addWidget(browse) layout.addLayout(row) self.preserve = QCheckBox("Preserve directory structure") self.preserve.setChecked(True) layout.addWidget(self.preserve) buttons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) buttons.accepted.connect(self.accept) buttons.rejected.connect(self.reject) layout.addWidget(buttons) def _browse(self) -> None: d = QFileDialog.getExistingDirectory(self, "Extract to", self.dest.text()) if d: self.dest.setText(d) def destination(self) -> str: return self.dest.text().strip()