clutterxp 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- clutterxp/__init__.py +4 -0
- clutterxp/cli/__init__.py +7 -0
- clutterxp/cli/app.py +251 -0
- clutterxp/cli/cmd_config.py +250 -0
- clutterxp/cli/cmd_doctor.py +449 -0
- clutterxp/cli/cmd_duplicates.py +253 -0
- clutterxp/cli/cmd_gui.py +22 -0
- clutterxp/cli/cmd_history.py +233 -0
- clutterxp/cli/cmd_init.py +76 -0
- clutterxp/cli/cmd_organize.py +226 -0
- clutterxp/cli/cmd_rules.py +540 -0
- clutterxp/cli/cmd_scan.py +109 -0
- clutterxp/cli/cmd_service.py +130 -0
- clutterxp/cli/cmd_undo.py +180 -0
- clutterxp/cli/cmd_watch.py +147 -0
- clutterxp/cli/errors.py +166 -0
- clutterxp/cli/render.py +390 -0
- clutterxp/config/__init__.py +40 -0
- clutterxp/config/jsonschema.py +12 -0
- clutterxp/config/loader.py +212 -0
- clutterxp/config/placeholders.py +79 -0
- clutterxp/config/runtime.py +30 -0
- clutterxp/config/schema.py +166 -0
- clutterxp/config/validate.py +226 -0
- clutterxp/config/writer.py +248 -0
- clutterxp/config.example.yaml +76 -0
- clutterxp/duplicates/__init__.py +22 -0
- clutterxp/duplicates/detector.py +438 -0
- clutterxp/duplicates/hashcache.py +149 -0
- clutterxp/duplicates/namenorm.py +45 -0
- clutterxp/duplicates/quarantine.py +196 -0
- clutterxp/duplicates/report.py +110 -0
- clutterxp/gui/__init__.py +1 -0
- clutterxp/gui/api.py +494 -0
- clutterxp/gui/app.py +205 -0
- clutterxp/gui/models_qt.py +544 -0
- clutterxp/gui/views/__init__.py +21 -0
- clutterxp/gui/views/dashboard.py +253 -0
- clutterxp/gui/views/duplicates.py +404 -0
- clutterxp/gui/views/folders.py +354 -0
- clutterxp/gui/views/history.py +281 -0
- clutterxp/gui/views/preview.py +277 -0
- clutterxp/gui/views/rules.py +527 -0
- clutterxp/gui/views/settings.py +172 -0
- clutterxp/gui/workers.py +147 -0
- clutterxp/history/__init__.py +23 -0
- clutterxp/history/db.py +174 -0
- clutterxp/history/pathcodec.py +42 -0
- clutterxp/history/recovery.py +318 -0
- clutterxp/history/schema.sql +43 -0
- clutterxp/history/service.py +493 -0
- clutterxp/history/undo.py +373 -0
- clutterxp/interfaces.py +164 -0
- clutterxp/locking.py +113 -0
- clutterxp/logging_setup.py +73 -0
- clutterxp/models.py +266 -0
- clutterxp/mover/__init__.py +26 -0
- clutterxp/mover/collision.py +46 -0
- clutterxp/mover/fsops.py +191 -0
- clutterxp/mover/safe_move.py +741 -0
- clutterxp/organizer.py +388 -0
- clutterxp/packaging/clutterxp.service +15 -0
- clutterxp/paths.py +112 -0
- clutterxp/planner.py +339 -0
- clutterxp/py.typed +0 -0
- clutterxp/rules/__init__.py +16 -0
- clutterxp/rules/engine.py +374 -0
- clutterxp/rules/matcher.py +222 -0
- clutterxp/rules/template.py +171 -0
- clutterxp/rules/tokenizer.py +118 -0
- clutterxp/safety.py +111 -0
- clutterxp/scanner.py +196 -0
- clutterxp/service_install.py +208 -0
- clutterxp/units.py +59 -0
- clutterxp/watch/__init__.py +37 -0
- clutterxp/watch/debounce.py +84 -0
- clutterxp/watch/events.py +259 -0
- clutterxp/watch/ignore.py +77 -0
- clutterxp/watch/service.py +662 -0
- clutterxp/watch/settle.py +170 -0
- clutterxp-1.1.0.dist-info/METADATA +149 -0
- clutterxp-1.1.0.dist-info/RECORD +84 -0
- clutterxp-1.1.0.dist-info/WHEEL +4 -0
- clutterxp-1.1.0.dist-info/entry_points.txt +6 -0
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"""Dashboard view for ClutterXP GUI.
|
|
2
|
+
|
|
3
|
+
Displays watcher state, quick summary statistics, last 5 operations,
|
|
4
|
+
and quick actions (Scan, Organize, Undo Last Batch).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from PySide6.QtCore import Qt, Signal
|
|
12
|
+
from PySide6.QtWidgets import (
|
|
13
|
+
QFrame,
|
|
14
|
+
QGridLayout,
|
|
15
|
+
QGroupBox,
|
|
16
|
+
QHBoxLayout,
|
|
17
|
+
QHeaderView,
|
|
18
|
+
QLabel,
|
|
19
|
+
QMessageBox,
|
|
20
|
+
QPushButton,
|
|
21
|
+
QTableView,
|
|
22
|
+
QVBoxLayout,
|
|
23
|
+
QWidget,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
from clutterxp.gui.api import GuiApi
|
|
27
|
+
from clutterxp.gui.models_qt import HistoryTableModel
|
|
28
|
+
from clutterxp.gui.workers import run_in_worker
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class DashboardView(QWidget):
|
|
32
|
+
"""Main dashboard overview."""
|
|
33
|
+
|
|
34
|
+
navigate_requested = Signal(str) # "preview", "folders", "rules", "history", etc.
|
|
35
|
+
|
|
36
|
+
def __init__(self, api: GuiApi, parent: QWidget | None = None) -> None:
|
|
37
|
+
super().__init__(parent)
|
|
38
|
+
self.api = api
|
|
39
|
+
self._history_model = HistoryTableModel()
|
|
40
|
+
self._init_ui()
|
|
41
|
+
self.refresh()
|
|
42
|
+
|
|
43
|
+
def _init_ui(self) -> None:
|
|
44
|
+
main_layout = QVBoxLayout(self)
|
|
45
|
+
main_layout.setContentsMargins(16, 16, 16, 16)
|
|
46
|
+
main_layout.setSpacing(16)
|
|
47
|
+
|
|
48
|
+
# Title
|
|
49
|
+
title_label = QLabel("ClutterXP Dashboard")
|
|
50
|
+
title_font = title_label.font()
|
|
51
|
+
title_font.setPointSize(16)
|
|
52
|
+
title_font.setBold(True)
|
|
53
|
+
title_label.setFont(title_font)
|
|
54
|
+
main_layout.addWidget(title_label)
|
|
55
|
+
|
|
56
|
+
# Top row: Watcher Card & Stats Grid
|
|
57
|
+
top_row = QHBoxLayout()
|
|
58
|
+
top_row.setSpacing(16)
|
|
59
|
+
|
|
60
|
+
# Watcher State Card
|
|
61
|
+
self.watcher_group = QGroupBox("Watcher Daemon")
|
|
62
|
+
watcher_layout = QVBoxLayout(self.watcher_group)
|
|
63
|
+
watcher_layout.setSpacing(8)
|
|
64
|
+
|
|
65
|
+
self.watcher_status_label = QLabel("Status: Checking...")
|
|
66
|
+
status_font = self.watcher_status_label.font()
|
|
67
|
+
status_font.setBold(True)
|
|
68
|
+
self.watcher_status_label.setFont(status_font)
|
|
69
|
+
watcher_layout.addWidget(self.watcher_status_label)
|
|
70
|
+
|
|
71
|
+
self.watcher_folders_label = QLabel("Watched Folders: None")
|
|
72
|
+
self.watcher_folders_label.setWordWrap(True)
|
|
73
|
+
watcher_layout.addWidget(self.watcher_folders_label)
|
|
74
|
+
|
|
75
|
+
self.watcher_toggle_btn = QPushButton("Toggle Watcher")
|
|
76
|
+
self.watcher_toggle_btn.clicked.connect(self._on_toggle_watcher)
|
|
77
|
+
watcher_layout.addWidget(self.watcher_toggle_btn)
|
|
78
|
+
watcher_layout.addStretch()
|
|
79
|
+
|
|
80
|
+
top_row.addWidget(self.watcher_group, stretch=1)
|
|
81
|
+
|
|
82
|
+
# Quick Stats Card
|
|
83
|
+
stats_group = QGroupBox("Quick Stats")
|
|
84
|
+
stats_layout = QGridLayout(stats_group)
|
|
85
|
+
stats_layout.setSpacing(12)
|
|
86
|
+
|
|
87
|
+
stats_layout.addWidget(QLabel("Configured Folders:"), 0, 0)
|
|
88
|
+
self.folders_count_label = QLabel("0")
|
|
89
|
+
self.folders_count_label.setAlignment(Qt.AlignmentFlag.AlignRight)
|
|
90
|
+
stats_layout.addWidget(self.folders_count_label, 0, 1)
|
|
91
|
+
|
|
92
|
+
stats_layout.addWidget(QLabel("Today's Moves:"), 1, 0)
|
|
93
|
+
self.today_moves_label = QLabel("0")
|
|
94
|
+
self.today_moves_label.setAlignment(Qt.AlignmentFlag.AlignRight)
|
|
95
|
+
stats_layout.addWidget(self.today_moves_label, 1, 1)
|
|
96
|
+
|
|
97
|
+
stats_layout.addWidget(QLabel("Active Rules:"), 2, 0)
|
|
98
|
+
self.rules_count_label = QLabel("0")
|
|
99
|
+
self.rules_count_label.setAlignment(Qt.AlignmentFlag.AlignRight)
|
|
100
|
+
stats_layout.addWidget(self.rules_count_label, 2, 1)
|
|
101
|
+
|
|
102
|
+
stats_group.setLayout(stats_layout)
|
|
103
|
+
top_row.addWidget(stats_group, stretch=1)
|
|
104
|
+
|
|
105
|
+
# Quick Actions Card
|
|
106
|
+
actions_group = QGroupBox("Quick Actions")
|
|
107
|
+
actions_layout = QVBoxLayout(actions_group)
|
|
108
|
+
actions_layout.setSpacing(8)
|
|
109
|
+
|
|
110
|
+
self.scan_btn = QPushButton("Scan Folders")
|
|
111
|
+
self.scan_btn.clicked.connect(lambda: self.navigate_requested.emit("preview"))
|
|
112
|
+
actions_layout.addWidget(self.scan_btn)
|
|
113
|
+
|
|
114
|
+
self.organize_btn = QPushButton("Organize (Preview)")
|
|
115
|
+
self.organize_btn.clicked.connect(lambda: self.navigate_requested.emit("preview"))
|
|
116
|
+
actions_layout.addWidget(self.organize_btn)
|
|
117
|
+
|
|
118
|
+
self.undo_last_btn = QPushButton("Undo Last Batch")
|
|
119
|
+
self.undo_last_btn.clicked.connect(self._on_undo_last_batch)
|
|
120
|
+
actions_layout.addWidget(self.undo_last_btn)
|
|
121
|
+
|
|
122
|
+
actions_layout.addStretch()
|
|
123
|
+
top_row.addWidget(actions_group, stretch=1)
|
|
124
|
+
|
|
125
|
+
main_layout.addLayout(top_row)
|
|
126
|
+
|
|
127
|
+
# Separator line
|
|
128
|
+
line = QFrame()
|
|
129
|
+
line.setFrameShape(QFrame.Shape.HLine)
|
|
130
|
+
line.setFrameShadow(QFrame.Shadow.Sunken)
|
|
131
|
+
main_layout.addWidget(line)
|
|
132
|
+
|
|
133
|
+
# Bottom section: Recent Operations
|
|
134
|
+
recent_group = QGroupBox("Recent Operations (Last 5)")
|
|
135
|
+
recent_layout = QVBoxLayout(recent_group)
|
|
136
|
+
|
|
137
|
+
self.recent_table = QTableView()
|
|
138
|
+
self.recent_table.setModel(self._history_model)
|
|
139
|
+
self.recent_table.setSelectionBehavior(QTableView.SelectionBehavior.SelectRows)
|
|
140
|
+
self.recent_table.setSelectionMode(QTableView.SelectionMode.SingleSelection)
|
|
141
|
+
self.recent_table.horizontalHeader().setSectionResizeMode(
|
|
142
|
+
QHeaderView.ResizeMode.ResizeToContents
|
|
143
|
+
)
|
|
144
|
+
self.recent_table.horizontalHeader().setStretchLastSection(True)
|
|
145
|
+
recent_layout.addWidget(self.recent_table)
|
|
146
|
+
|
|
147
|
+
btn_row = QHBoxLayout()
|
|
148
|
+
btn_row.addStretch()
|
|
149
|
+
self.view_history_btn = QPushButton("View Full History")
|
|
150
|
+
self.view_history_btn.clicked.connect(lambda: self.navigate_requested.emit("history"))
|
|
151
|
+
btn_row.addWidget(self.view_history_btn)
|
|
152
|
+
recent_layout.addLayout(btn_row)
|
|
153
|
+
|
|
154
|
+
main_layout.addWidget(recent_group, stretch=1)
|
|
155
|
+
|
|
156
|
+
def refresh(self) -> None:
|
|
157
|
+
"""Fetch dashboard state in background worker."""
|
|
158
|
+
|
|
159
|
+
def _fetch() -> dict[str, Any]:
|
|
160
|
+
status = self.api.watcher_status()
|
|
161
|
+
cfg = self.api.get_runtime_config()
|
|
162
|
+
today_moves = self.api.get_today_move_count()
|
|
163
|
+
recent_ops = self.api.history_list(limit=5)
|
|
164
|
+
return {
|
|
165
|
+
"watcher_status": status,
|
|
166
|
+
"config": cfg,
|
|
167
|
+
"today_moves": today_moves,
|
|
168
|
+
"recent_ops": recent_ops,
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
run_in_worker(
|
|
172
|
+
_fetch,
|
|
173
|
+
on_result=self._apply_dashboard_data,
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
def _apply_dashboard_data(self, data: dict[str, Any]) -> None:
|
|
177
|
+
"""Update UI with fetched data on main thread."""
|
|
178
|
+
status = data["watcher_status"]
|
|
179
|
+
cfg = data["config"]
|
|
180
|
+
today_moves = data["today_moves"]
|
|
181
|
+
recent_ops = data["recent_ops"]
|
|
182
|
+
|
|
183
|
+
# Watcher State
|
|
184
|
+
if status == "running":
|
|
185
|
+
self.watcher_status_label.setText("Status: RUNNING")
|
|
186
|
+
self.watcher_toggle_btn.setText("Stop Watcher")
|
|
187
|
+
else:
|
|
188
|
+
self.watcher_status_label.setText("Status: STOPPED")
|
|
189
|
+
self.watcher_toggle_btn.setText("Start Watcher")
|
|
190
|
+
|
|
191
|
+
watch_paths = [w.path for w in cfg.watch_entries]
|
|
192
|
+
if watch_paths:
|
|
193
|
+
self.watcher_folders_label.setText(
|
|
194
|
+
f"Watching {len(watch_paths)} folder(s): {', '.join(watch_paths)}"
|
|
195
|
+
)
|
|
196
|
+
else:
|
|
197
|
+
self.watcher_folders_label.setText("Watched Folders: None configured")
|
|
198
|
+
|
|
199
|
+
# Stats
|
|
200
|
+
self.folders_count_label.setText(str(len(cfg.watch_entries)))
|
|
201
|
+
self.today_moves_label.setText(str(today_moves))
|
|
202
|
+
self.rules_count_label.setText(str(len(cfg.rules)))
|
|
203
|
+
|
|
204
|
+
# Recent Operations Table
|
|
205
|
+
self._history_model.set_records(recent_ops)
|
|
206
|
+
|
|
207
|
+
def _on_toggle_watcher(self) -> None:
|
|
208
|
+
current_status = self.api.watcher_status()
|
|
209
|
+
if current_status == "running":
|
|
210
|
+
self.api.watcher_stop()
|
|
211
|
+
else:
|
|
212
|
+
self.api.watcher_start()
|
|
213
|
+
self.refresh()
|
|
214
|
+
|
|
215
|
+
def _on_undo_last_batch(self) -> None:
|
|
216
|
+
reply = QMessageBox.question(
|
|
217
|
+
self,
|
|
218
|
+
"Confirm Undo",
|
|
219
|
+
"Are you sure you want to undo the last batch of file moves?",
|
|
220
|
+
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
|
|
221
|
+
)
|
|
222
|
+
if reply == QMessageBox.StandardButton.Yes:
|
|
223
|
+
|
|
224
|
+
def _do_undo() -> Any:
|
|
225
|
+
return self.api.undo_last_batch()
|
|
226
|
+
|
|
227
|
+
def _on_done(outcomes: Any) -> None:
|
|
228
|
+
if not outcomes:
|
|
229
|
+
QMessageBox.information(self, "Undo", "No previous batches to undo.")
|
|
230
|
+
else:
|
|
231
|
+
succeeded = sum(1 for o in outcomes if o.ok)
|
|
232
|
+
failed = len(outcomes) - succeeded
|
|
233
|
+
if failed > 0:
|
|
234
|
+
reasons = "\n".join(
|
|
235
|
+
f"- {o.message or o.code.value}" for o in outcomes if not o.ok
|
|
236
|
+
)
|
|
237
|
+
QMessageBox.warning(
|
|
238
|
+
self,
|
|
239
|
+
"Undo Completed with Refusals",
|
|
240
|
+
f"Restored {succeeded} files.\n{failed} files refused:\n{reasons}",
|
|
241
|
+
)
|
|
242
|
+
else:
|
|
243
|
+
QMessageBox.information(
|
|
244
|
+
self,
|
|
245
|
+
"Undo Successful",
|
|
246
|
+
f"Successfully restored {succeeded} file(s).",
|
|
247
|
+
)
|
|
248
|
+
self.refresh()
|
|
249
|
+
|
|
250
|
+
run_in_worker(_do_undo, on_result=_on_done)
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
__all__ = ["DashboardView"]
|
|
@@ -0,0 +1,404 @@
|
|
|
1
|
+
"""Duplicates view for multi-stage scanning, progress, cancellation, and quarantine.
|
|
2
|
+
|
|
3
|
+
Implements acceptance criteria A87 (live progress & clean cancellation) and
|
|
4
|
+
A88 (quarantine preview, confirm, moves without deleting, undoable, exact groups only).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
from PySide6.QtCore import Qt, QUrl
|
|
13
|
+
from PySide6.QtGui import QDesktopServices
|
|
14
|
+
from PySide6.QtWidgets import (
|
|
15
|
+
QCheckBox,
|
|
16
|
+
QComboBox,
|
|
17
|
+
QDialog,
|
|
18
|
+
QDialogButtonBox,
|
|
19
|
+
QFileDialog,
|
|
20
|
+
QFormLayout,
|
|
21
|
+
QGroupBox,
|
|
22
|
+
QHBoxLayout,
|
|
23
|
+
QHeaderView,
|
|
24
|
+
QLabel,
|
|
25
|
+
QLineEdit,
|
|
26
|
+
QListWidget,
|
|
27
|
+
QListWidgetItem,
|
|
28
|
+
QMessageBox,
|
|
29
|
+
QProgressBar,
|
|
30
|
+
QPushButton,
|
|
31
|
+
QSplitter,
|
|
32
|
+
QTableView,
|
|
33
|
+
QVBoxLayout,
|
|
34
|
+
QWidget,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
from clutterxp import paths
|
|
38
|
+
from clutterxp.duplicates.quarantine import QuarantinePlan
|
|
39
|
+
from clutterxp.gui.api import GuiApi
|
|
40
|
+
from clutterxp.gui.models_qt import DuplicatesTableModel, format_bytes
|
|
41
|
+
from clutterxp.gui.workers import CancellationToken, run_in_worker
|
|
42
|
+
from clutterxp.models import BatchResult, DuplicateGroup, FileInfo
|
|
43
|
+
from clutterxp.units import parse_size
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class QuarantinePreviewDialog(QDialog):
|
|
47
|
+
"""Dialog previewing files to be quarantined and confirming execution."""
|
|
48
|
+
|
|
49
|
+
def __init__(
|
|
50
|
+
self,
|
|
51
|
+
plan: QuarantinePlan,
|
|
52
|
+
parent: QWidget | None = None,
|
|
53
|
+
) -> None:
|
|
54
|
+
super().__init__(parent)
|
|
55
|
+
self.setWindowTitle("Preview Quarantine")
|
|
56
|
+
self.resize(580, 420)
|
|
57
|
+
self.plan = plan
|
|
58
|
+
|
|
59
|
+
layout = QVBoxLayout(self)
|
|
60
|
+
|
|
61
|
+
info_box = QGroupBox("Quarantine Summary")
|
|
62
|
+
info_layout = QFormLayout(info_box)
|
|
63
|
+
info_layout.addRow("Quarantine Directory:", QLabel(str(plan.quarantine_dir)))
|
|
64
|
+
info_layout.addRow("Keep Strategy:", QLabel(plan.keep_strategy))
|
|
65
|
+
info_layout.addRow("Files to Move:", QLabel(str(plan.total_moves)))
|
|
66
|
+
info_layout.addRow("Wasted Bytes Reclaimed:", QLabel(format_bytes(plan.total_bytes)))
|
|
67
|
+
layout.addWidget(info_box)
|
|
68
|
+
|
|
69
|
+
# Kept files preview
|
|
70
|
+
layout.addWidget(QLabel("Files being kept in place (original locations):"))
|
|
71
|
+
kept_list = QListWidget()
|
|
72
|
+
for f in plan.kept_files:
|
|
73
|
+
kept_list.addItem(f"KEEP: {f.path}")
|
|
74
|
+
layout.addWidget(kept_list)
|
|
75
|
+
|
|
76
|
+
# Quarantined files preview
|
|
77
|
+
layout.addWidget(QLabel("Files to move into quarantine directory (undoable):"))
|
|
78
|
+
move_list = QListWidget()
|
|
79
|
+
for act in plan.actions:
|
|
80
|
+
move_list.addItem(f"MOVE: {act.file.path} -> {act.target_dir / act.target_name}")
|
|
81
|
+
layout.addWidget(move_list)
|
|
82
|
+
|
|
83
|
+
btn_box = QDialogButtonBox(
|
|
84
|
+
QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
|
|
85
|
+
)
|
|
86
|
+
btn_box.button(QDialogButtonBox.StandardButton.Ok).setText("Confirm Quarantine")
|
|
87
|
+
btn_box.accepted.connect(self.accept)
|
|
88
|
+
btn_box.rejected.connect(self.reject)
|
|
89
|
+
layout.addWidget(btn_box)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class DuplicatesView(QWidget):
|
|
93
|
+
"""View to detect duplicates and quarantine exact groups."""
|
|
94
|
+
|
|
95
|
+
def __init__(self, api: GuiApi, parent: QWidget | None = None) -> None:
|
|
96
|
+
super().__init__(parent)
|
|
97
|
+
self.api = api
|
|
98
|
+
self._model = DuplicatesTableModel()
|
|
99
|
+
self._current_groups: list[DuplicateGroup] = []
|
|
100
|
+
self._cancel_token = CancellationToken()
|
|
101
|
+
self._init_ui()
|
|
102
|
+
|
|
103
|
+
def _init_ui(self) -> None:
|
|
104
|
+
main_layout = QVBoxLayout(self)
|
|
105
|
+
main_layout.setContentsMargins(16, 16, 16, 16)
|
|
106
|
+
main_layout.setSpacing(12)
|
|
107
|
+
|
|
108
|
+
# Header
|
|
109
|
+
title_label = QLabel("Duplicate File Finder & Quarantine")
|
|
110
|
+
title_font = title_label.font()
|
|
111
|
+
title_font.setPointSize(16)
|
|
112
|
+
title_font.setBold(True)
|
|
113
|
+
title_label.setFont(title_font)
|
|
114
|
+
main_layout.addWidget(title_label)
|
|
115
|
+
|
|
116
|
+
# Folder Picker & Scan Controls Box
|
|
117
|
+
scan_box = QGroupBox("Scan Targets & Parameters")
|
|
118
|
+
scan_layout = QVBoxLayout(scan_box)
|
|
119
|
+
|
|
120
|
+
folders_row = QHBoxLayout()
|
|
121
|
+
self.folders_list = QListWidget()
|
|
122
|
+
self.folders_list.setMaximumHeight(80)
|
|
123
|
+
# Default target folder from config if present
|
|
124
|
+
cfg = self.api.get_runtime_config()
|
|
125
|
+
for w in cfg.watch_entries:
|
|
126
|
+
self.folders_list.addItem(w.path)
|
|
127
|
+
folders_row.addWidget(self.folders_list, stretch=1)
|
|
128
|
+
|
|
129
|
+
f_btns = QVBoxLayout()
|
|
130
|
+
self.add_folder_btn = QPushButton("Add Folder...")
|
|
131
|
+
self.add_folder_btn.clicked.connect(self._on_add_folder)
|
|
132
|
+
f_btns.addWidget(self.add_folder_btn)
|
|
133
|
+
|
|
134
|
+
self.remove_folder_btn = QPushButton("Remove Folder")
|
|
135
|
+
self.remove_folder_btn.clicked.connect(self._on_remove_folder)
|
|
136
|
+
f_btns.addWidget(self.remove_folder_btn)
|
|
137
|
+
f_btns.addStretch()
|
|
138
|
+
folders_row.addLayout(f_btns)
|
|
139
|
+
|
|
140
|
+
scan_layout.addLayout(folders_row)
|
|
141
|
+
|
|
142
|
+
options_row = QHBoxLayout()
|
|
143
|
+
self.recursive_cb = QCheckBox("Recursive")
|
|
144
|
+
self.recursive_cb.setChecked(True)
|
|
145
|
+
options_row.addWidget(self.recursive_cb)
|
|
146
|
+
|
|
147
|
+
self.potential_cb = QCheckBox("Detect Potential Duplicates")
|
|
148
|
+
self.potential_cb.setChecked(True)
|
|
149
|
+
options_row.addWidget(self.potential_cb)
|
|
150
|
+
|
|
151
|
+
options_row.addWidget(QLabel("Min Size:"))
|
|
152
|
+
self.min_size_edit = QLineEdit("1B")
|
|
153
|
+
self.min_size_edit.setMaximumWidth(80)
|
|
154
|
+
options_row.addWidget(self.min_size_edit)
|
|
155
|
+
|
|
156
|
+
options_row.addStretch()
|
|
157
|
+
|
|
158
|
+
self.scan_btn = QPushButton("Start Scan")
|
|
159
|
+
self.scan_btn.setStyleSheet("font-weight: bold; padding: 6px 14px;")
|
|
160
|
+
self.scan_btn.clicked.connect(self.start_scan)
|
|
161
|
+
options_row.addWidget(self.scan_btn)
|
|
162
|
+
|
|
163
|
+
self.cancel_btn = QPushButton("Cancel")
|
|
164
|
+
self.cancel_btn.setEnabled(False)
|
|
165
|
+
self.cancel_btn.clicked.connect(self.cancel_scan)
|
|
166
|
+
options_row.addWidget(self.cancel_btn)
|
|
167
|
+
|
|
168
|
+
scan_layout.addLayout(options_row)
|
|
169
|
+
main_layout.addWidget(scan_box)
|
|
170
|
+
|
|
171
|
+
# Progress bar
|
|
172
|
+
self.progress_bar = QProgressBar()
|
|
173
|
+
self.progress_bar.setVisible(False)
|
|
174
|
+
main_layout.addWidget(self.progress_bar)
|
|
175
|
+
|
|
176
|
+
# Center area: Filter + Groups Table + Selected Files
|
|
177
|
+
center_splitter = QSplitter(Qt.Orientation.Vertical)
|
|
178
|
+
|
|
179
|
+
groups_container = QWidget()
|
|
180
|
+
groups_layout = QVBoxLayout(groups_container)
|
|
181
|
+
groups_layout.setContentsMargins(0, 0, 0, 0)
|
|
182
|
+
|
|
183
|
+
filter_row = QHBoxLayout()
|
|
184
|
+
filter_row.addWidget(QLabel("Show Groups:"))
|
|
185
|
+
self.kind_combo = QComboBox()
|
|
186
|
+
self.kind_combo.addItem("All Duplicate Groups", "all")
|
|
187
|
+
self.kind_combo.addItem("Exact Duplicates Only", "exact")
|
|
188
|
+
self.kind_combo.addItem("Potential Duplicates", "potential")
|
|
189
|
+
self.kind_combo.addItem("Hardlinks Only", "hardlink")
|
|
190
|
+
self.kind_combo.currentIndexChanged.connect(self._on_filter_changed)
|
|
191
|
+
filter_row.addWidget(self.kind_combo)
|
|
192
|
+
filter_row.addStretch()
|
|
193
|
+
groups_layout.addLayout(filter_row)
|
|
194
|
+
|
|
195
|
+
self.table = QTableView()
|
|
196
|
+
self.table.setModel(self._model)
|
|
197
|
+
self.table.setSelectionBehavior(QTableView.SelectionBehavior.SelectRows)
|
|
198
|
+
self.table.setSelectionMode(QTableView.SelectionMode.SingleSelection)
|
|
199
|
+
self.table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.ResizeToContents)
|
|
200
|
+
self.table.horizontalHeader().setStretchLastSection(True)
|
|
201
|
+
self.table.selectionModel().selectionChanged.connect(self._on_group_selected)
|
|
202
|
+
groups_layout.addWidget(self.table)
|
|
203
|
+
center_splitter.addWidget(groups_container)
|
|
204
|
+
|
|
205
|
+
# Details of files in selected group
|
|
206
|
+
details_box = QGroupBox("Files in Selected Duplicate Group")
|
|
207
|
+
details_layout = QVBoxLayout(details_box)
|
|
208
|
+
|
|
209
|
+
self.files_list = QListWidget()
|
|
210
|
+
details_layout.addWidget(self.files_list)
|
|
211
|
+
|
|
212
|
+
file_btns = QHBoxLayout()
|
|
213
|
+
self.open_fm_btn = QPushButton("Open in File Manager")
|
|
214
|
+
self.open_fm_btn.setEnabled(False)
|
|
215
|
+
self.open_fm_btn.clicked.connect(self._on_open_file_manager)
|
|
216
|
+
file_btns.addWidget(self.open_fm_btn)
|
|
217
|
+
|
|
218
|
+
file_btns.addStretch()
|
|
219
|
+
|
|
220
|
+
self.quarantine_btn = QPushButton("Quarantine Duplicates...")
|
|
221
|
+
self.quarantine_btn.setStyleSheet("font-weight: bold;")
|
|
222
|
+
self.quarantine_btn.clicked.connect(self._on_quarantine_clicked)
|
|
223
|
+
file_btns.addWidget(self.quarantine_btn)
|
|
224
|
+
|
|
225
|
+
details_layout.addLayout(file_btns)
|
|
226
|
+
center_splitter.addWidget(details_box)
|
|
227
|
+
|
|
228
|
+
main_layout.addWidget(center_splitter, stretch=1)
|
|
229
|
+
|
|
230
|
+
@property
|
|
231
|
+
def model(self) -> DuplicatesTableModel:
|
|
232
|
+
return self._model
|
|
233
|
+
|
|
234
|
+
def set_groups(self, groups: list[DuplicateGroup]) -> None:
|
|
235
|
+
"""Set groups directly for testing and sync updates."""
|
|
236
|
+
self._current_groups = list(groups)
|
|
237
|
+
self._model.set_groups(groups)
|
|
238
|
+
self._on_group_selected()
|
|
239
|
+
|
|
240
|
+
def start_scan(self) -> None:
|
|
241
|
+
"""Start duplicate detector scan in background worker."""
|
|
242
|
+
folders = [
|
|
243
|
+
Path(self.folders_list.item(i).text()).expanduser()
|
|
244
|
+
for i in range(self.folders_list.count())
|
|
245
|
+
]
|
|
246
|
+
if not folders:
|
|
247
|
+
QMessageBox.information(self, "No Folders", "Please add at least one folder to scan.")
|
|
248
|
+
return
|
|
249
|
+
|
|
250
|
+
try:
|
|
251
|
+
min_size_bytes = parse_size(self.min_size_edit.text().strip() or "1B")
|
|
252
|
+
except Exception:
|
|
253
|
+
QMessageBox.warning(self, "Invalid Size", "Please specify a valid minimum file size.")
|
|
254
|
+
return
|
|
255
|
+
|
|
256
|
+
self._cancel_token.reset()
|
|
257
|
+
self.scan_btn.setEnabled(False)
|
|
258
|
+
self.cancel_btn.setEnabled(True)
|
|
259
|
+
self.progress_bar.setVisible(True)
|
|
260
|
+
self.progress_bar.setValue(0)
|
|
261
|
+
self.progress_bar.setMaximum(100)
|
|
262
|
+
|
|
263
|
+
def _do_scan(
|
|
264
|
+
*args: Any,
|
|
265
|
+
cancel: Any = None,
|
|
266
|
+
progress: Any = None,
|
|
267
|
+
**kwargs: Any,
|
|
268
|
+
) -> list[DuplicateGroup]:
|
|
269
|
+
cancel_ev = cancel if cancel is not None else self._cancel_token.event
|
|
270
|
+
return list(
|
|
271
|
+
self.api.duplicates_scan(
|
|
272
|
+
folders,
|
|
273
|
+
recursive=self.recursive_cb.isChecked(),
|
|
274
|
+
min_size=min_size_bytes,
|
|
275
|
+
potential=self.potential_cb.isChecked(),
|
|
276
|
+
cancel=cancel_ev,
|
|
277
|
+
progress=progress,
|
|
278
|
+
)
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
def _on_done(groups: list[DuplicateGroup]) -> None:
|
|
282
|
+
self.scan_btn.setEnabled(True)
|
|
283
|
+
self.cancel_btn.setEnabled(False)
|
|
284
|
+
self.progress_bar.setVisible(False)
|
|
285
|
+
self.set_groups(groups)
|
|
286
|
+
|
|
287
|
+
def _on_err(exc: Exception) -> None:
|
|
288
|
+
self.scan_btn.setEnabled(True)
|
|
289
|
+
self.cancel_btn.setEnabled(False)
|
|
290
|
+
self.progress_bar.setVisible(False)
|
|
291
|
+
if not self._cancel_token.is_cancelled:
|
|
292
|
+
QMessageBox.critical(self, "Duplicate Scan Failed", str(exc))
|
|
293
|
+
|
|
294
|
+
run_in_worker(
|
|
295
|
+
_do_scan,
|
|
296
|
+
cancel_token=self._cancel_token,
|
|
297
|
+
with_progress=True,
|
|
298
|
+
on_progress=lambda cur, tot: self.progress_bar.setValue(int(cur * 100 / max(tot, 1))),
|
|
299
|
+
on_result=_on_done,
|
|
300
|
+
on_error=_on_err,
|
|
301
|
+
)
|
|
302
|
+
|
|
303
|
+
def cancel_scan(self) -> None:
|
|
304
|
+
"""Cancel ongoing duplicate scan."""
|
|
305
|
+
self._cancel_token.cancel()
|
|
306
|
+
self.cancel_btn.setEnabled(False)
|
|
307
|
+
self.scan_btn.setEnabled(True)
|
|
308
|
+
self.progress_bar.setVisible(False)
|
|
309
|
+
|
|
310
|
+
def _on_add_folder(self) -> None:
|
|
311
|
+
chosen = QFileDialog.getExistingDirectory(self, "Select Directory to Scan")
|
|
312
|
+
if chosen:
|
|
313
|
+
self.folders_list.addItem(chosen)
|
|
314
|
+
|
|
315
|
+
def _on_remove_folder(self) -> None:
|
|
316
|
+
cur_row = self.folders_list.currentRow()
|
|
317
|
+
if cur_row >= 0:
|
|
318
|
+
self.folders_list.takeItem(cur_row)
|
|
319
|
+
|
|
320
|
+
def _on_filter_changed(self) -> None:
|
|
321
|
+
self._model.set_filter(self.kind_combo.currentData())
|
|
322
|
+
self._on_group_selected()
|
|
323
|
+
|
|
324
|
+
def _on_group_selected(self) -> None:
|
|
325
|
+
self.files_list.clear()
|
|
326
|
+
selected_indexes = self.table.selectionModel().selectedRows()
|
|
327
|
+
if not selected_indexes:
|
|
328
|
+
self.open_fm_btn.setEnabled(False)
|
|
329
|
+
return
|
|
330
|
+
|
|
331
|
+
group = self._model.get_group(selected_indexes[0].row())
|
|
332
|
+
if group is None:
|
|
333
|
+
self.open_fm_btn.setEnabled(False)
|
|
334
|
+
return
|
|
335
|
+
|
|
336
|
+
self.open_fm_btn.setEnabled(True)
|
|
337
|
+
for f in group.files:
|
|
338
|
+
item = QListWidgetItem(f"{f.path} ({format_bytes(f.size)})")
|
|
339
|
+
item.setData(Qt.ItemDataRole.UserRole, f)
|
|
340
|
+
self.files_list.addItem(item)
|
|
341
|
+
|
|
342
|
+
def _on_open_file_manager(self) -> None:
|
|
343
|
+
selected_items = self.files_list.selectedItems()
|
|
344
|
+
target_path: Path | None = None
|
|
345
|
+
if selected_items:
|
|
346
|
+
f_info: FileInfo = selected_items[0].data(Qt.ItemDataRole.UserRole)
|
|
347
|
+
target_path = f_info.path
|
|
348
|
+
else:
|
|
349
|
+
selected_indexes = self.table.selectionModel().selectedRows()
|
|
350
|
+
if selected_indexes:
|
|
351
|
+
group = self._model.get_group(selected_indexes[0].row())
|
|
352
|
+
if group and group.files:
|
|
353
|
+
target_path = group.files[0].path
|
|
354
|
+
|
|
355
|
+
if target_path and target_path.exists():
|
|
356
|
+
folder_url = QUrl.fromLocalFile(str(target_path.parent))
|
|
357
|
+
QDesktopServices.openUrl(folder_url)
|
|
358
|
+
|
|
359
|
+
def _on_quarantine_clicked(self) -> None:
|
|
360
|
+
# Acceptance A88: Quarantine operates strictly on EXACT duplicate groups
|
|
361
|
+
exact_groups = [g for g in self._current_groups if g.kind == "exact" and len(g.files) >= 2]
|
|
362
|
+
if not exact_groups:
|
|
363
|
+
QMessageBox.warning(
|
|
364
|
+
self,
|
|
365
|
+
"Quarantine Not Available",
|
|
366
|
+
"Quarantine requires at least one exact duplicate group with 2 or more files.\n"
|
|
367
|
+
"Potential duplicates and hardlinks cannot be quarantined.",
|
|
368
|
+
)
|
|
369
|
+
return
|
|
370
|
+
|
|
371
|
+
quarantine_dir = paths.state_dir() / "quarantine"
|
|
372
|
+
plan = self.api.duplicates_plan_quarantine(exact_groups, quarantine_dir=quarantine_dir)
|
|
373
|
+
|
|
374
|
+
if plan.total_moves == 0:
|
|
375
|
+
QMessageBox.information(
|
|
376
|
+
self, "Quarantine", "No files eligible for quarantine in detected groups."
|
|
377
|
+
)
|
|
378
|
+
return
|
|
379
|
+
|
|
380
|
+
dialog = QuarantinePreviewDialog(plan, self)
|
|
381
|
+
if dialog.exec() == QDialog.DialogCode.Accepted:
|
|
382
|
+
|
|
383
|
+
def _do_quarantine() -> BatchResult:
|
|
384
|
+
return self.api.duplicates_quarantine(plan)
|
|
385
|
+
|
|
386
|
+
def _on_done(res: BatchResult) -> None:
|
|
387
|
+
QMessageBox.information(
|
|
388
|
+
self,
|
|
389
|
+
"Quarantine Completed",
|
|
390
|
+
f"Successfully quarantined {res.moved} duplicate file(s) into:\n"
|
|
391
|
+
f"{plan.quarantine_dir}\n\n"
|
|
392
|
+
f"Batch #{res.batch_id} recorded in journal.\n"
|
|
393
|
+
"This operation can be completely undone from the History view.",
|
|
394
|
+
)
|
|
395
|
+
# Re-run scan to update list
|
|
396
|
+
self.start_scan()
|
|
397
|
+
|
|
398
|
+
def _on_err(exc: Exception) -> None:
|
|
399
|
+
QMessageBox.critical(self, "Quarantine Failed", str(exc))
|
|
400
|
+
|
|
401
|
+
run_in_worker(_do_quarantine, on_result=_on_done, on_error=_on_err)
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
__all__ = ["DuplicatesView", "QuarantinePreviewDialog"]
|