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,544 @@
|
|
|
1
|
+
"""QAbstractTableModel implementations for ClutterXP GUI.
|
|
2
|
+
|
|
3
|
+
Provides reactive, typed tables backed by dataclasses from models.py:
|
|
4
|
+
- PlanTableModel: PlannedActions with checkable selection column to exclude items.
|
|
5
|
+
- RulesTableModel: Configured rules with toggleable enabled state.
|
|
6
|
+
- HistoryTableModel: Journal operations and batches.
|
|
7
|
+
- DuplicatesTableModel: Duplicate groups, wasted bytes, and file lists.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from collections.abc import Sequence
|
|
13
|
+
from typing import Any, ClassVar
|
|
14
|
+
|
|
15
|
+
from PySide6.QtCore import (
|
|
16
|
+
QAbstractTableModel,
|
|
17
|
+
QModelIndex,
|
|
18
|
+
QPersistentModelIndex,
|
|
19
|
+
Qt,
|
|
20
|
+
Signal,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
from clutterxp.config.schema import RuleSpec
|
|
24
|
+
from clutterxp.models import (
|
|
25
|
+
DuplicateGroup,
|
|
26
|
+
OperationRecord,
|
|
27
|
+
Plan,
|
|
28
|
+
PlannedAction,
|
|
29
|
+
PlanStatus,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def format_bytes(bytes_count: int) -> str:
|
|
34
|
+
"""Format bytes as human readable KiB/MiB/GiB."""
|
|
35
|
+
if bytes_count < 1024:
|
|
36
|
+
return f"{bytes_count} B"
|
|
37
|
+
num = float(bytes_count)
|
|
38
|
+
for unit in ["KiB", "MiB", "GiB", "TiB"]:
|
|
39
|
+
num /= 1024.0
|
|
40
|
+
if num < 1024.0:
|
|
41
|
+
return f"{num:.1f} {unit}"
|
|
42
|
+
return f"{num:.1f} PiB"
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
_EMPTY_INDEX = QModelIndex()
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _action_matches_filter(action: PlannedAction, filter_status: str) -> bool:
|
|
49
|
+
"""Check if action matches filter category."""
|
|
50
|
+
if filter_status == "all":
|
|
51
|
+
return True
|
|
52
|
+
if filter_status == "will_move":
|
|
53
|
+
return action.status in (PlanStatus.WILL_MOVE, PlanStatus.WILL_MOVE_RENAMED)
|
|
54
|
+
if filter_status == "ambiguous":
|
|
55
|
+
return action.status == PlanStatus.AMBIGUOUS
|
|
56
|
+
if filter_status == "blocked":
|
|
57
|
+
return action.status == PlanStatus.BLOCKED
|
|
58
|
+
if filter_status == "unmatched":
|
|
59
|
+
return action.status in (PlanStatus.NO_MATCH, PlanStatus.IGNORED)
|
|
60
|
+
return True
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class PlanTableModel(QAbstractTableModel):
|
|
64
|
+
"""Table model displaying PlannedActions with include/exclude checkboxes."""
|
|
65
|
+
|
|
66
|
+
COLUMNS: ClassVar[tuple[str, ...]] = (
|
|
67
|
+
"Include",
|
|
68
|
+
"Status",
|
|
69
|
+
"File Name",
|
|
70
|
+
"Destination",
|
|
71
|
+
"Rule",
|
|
72
|
+
"Match Reason",
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
plan_changed = Signal()
|
|
76
|
+
|
|
77
|
+
def __init__(self, plan: Plan | None = None) -> None:
|
|
78
|
+
super().__init__()
|
|
79
|
+
self._raw_actions: list[PlannedAction] = list(plan.actions) if plan is not None else []
|
|
80
|
+
self._folders = plan.folders if plan is not None else ()
|
|
81
|
+
self._filter_status: str = "all" # "all", "will_move", "ambiguous", "blocked", "unmatched"
|
|
82
|
+
self._included: dict[int, bool] = {} # id(action) -> bool
|
|
83
|
+
self._visible_indices: list[int] = []
|
|
84
|
+
self._rebuild_visibility()
|
|
85
|
+
|
|
86
|
+
def _rebuild_visibility(self) -> None:
|
|
87
|
+
indices: list[int] = []
|
|
88
|
+
for i, a in enumerate(self._raw_actions):
|
|
89
|
+
act_id = id(a)
|
|
90
|
+
if act_id not in self._included:
|
|
91
|
+
# By default, will_move and will_move_renamed are included
|
|
92
|
+
self._included[act_id] = a.status in (
|
|
93
|
+
PlanStatus.WILL_MOVE,
|
|
94
|
+
PlanStatus.WILL_MOVE_RENAMED,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
if _action_matches_filter(a, self._filter_status):
|
|
98
|
+
indices.append(i)
|
|
99
|
+
|
|
100
|
+
self._visible_indices = indices
|
|
101
|
+
|
|
102
|
+
def set_plan(self, plan: Plan) -> None:
|
|
103
|
+
"""Replace current plan and reset view."""
|
|
104
|
+
self.beginResetModel()
|
|
105
|
+
self._raw_actions = list(plan.actions)
|
|
106
|
+
self._folders = plan.folders
|
|
107
|
+
self._included.clear()
|
|
108
|
+
self._rebuild_visibility()
|
|
109
|
+
self.endResetModel()
|
|
110
|
+
self.plan_changed.emit()
|
|
111
|
+
|
|
112
|
+
def set_filter(self, filter_name: str) -> None:
|
|
113
|
+
"""Set filter: 'all', 'will_move', 'ambiguous', 'blocked', 'unmatched'."""
|
|
114
|
+
self.beginResetModel()
|
|
115
|
+
self._filter_status = filter_name.lower()
|
|
116
|
+
self._rebuild_visibility()
|
|
117
|
+
self.endResetModel()
|
|
118
|
+
|
|
119
|
+
def rowCount(self, parent: QModelIndex | QPersistentModelIndex = _EMPTY_INDEX) -> int:
|
|
120
|
+
if parent.isValid():
|
|
121
|
+
return 0
|
|
122
|
+
return len(self._visible_indices)
|
|
123
|
+
|
|
124
|
+
def columnCount(self, parent: QModelIndex | QPersistentModelIndex = _EMPTY_INDEX) -> int:
|
|
125
|
+
if parent.isValid():
|
|
126
|
+
return 0
|
|
127
|
+
return len(self.COLUMNS)
|
|
128
|
+
|
|
129
|
+
def data(
|
|
130
|
+
self,
|
|
131
|
+
index: QModelIndex | QPersistentModelIndex,
|
|
132
|
+
role: int = Qt.ItemDataRole.DisplayRole,
|
|
133
|
+
) -> Any:
|
|
134
|
+
if not index.isValid() or index.row() >= len(self._visible_indices):
|
|
135
|
+
return None
|
|
136
|
+
|
|
137
|
+
raw_idx = self._visible_indices[index.row()]
|
|
138
|
+
action = self._raw_actions[raw_idx]
|
|
139
|
+
col = index.column()
|
|
140
|
+
|
|
141
|
+
if role == Qt.ItemDataRole.CheckStateRole and col == 0:
|
|
142
|
+
is_inc = self._included.get(id(action), True)
|
|
143
|
+
return Qt.CheckState.Checked if is_inc else Qt.CheckState.Unchecked
|
|
144
|
+
|
|
145
|
+
if role == Qt.ItemDataRole.DisplayRole:
|
|
146
|
+
if col == 0:
|
|
147
|
+
return ""
|
|
148
|
+
elif col == 1:
|
|
149
|
+
return action.status.value
|
|
150
|
+
elif col == 2:
|
|
151
|
+
return action.file.name
|
|
152
|
+
elif col == 3:
|
|
153
|
+
return str(action.dest_path) if action.dest_path is not None else ""
|
|
154
|
+
elif col == 4:
|
|
155
|
+
return action.decision.hit.rule_name if action.decision.hit else ""
|
|
156
|
+
elif col == 5:
|
|
157
|
+
if action.decision.hit:
|
|
158
|
+
return action.decision.hit.matched_by
|
|
159
|
+
if action.decision.candidates:
|
|
160
|
+
cands = ", ".join(c.rule_name for c in action.decision.candidates)
|
|
161
|
+
return f"Candidates: {cands}"
|
|
162
|
+
if action.message:
|
|
163
|
+
return action.message
|
|
164
|
+
return action.decision.reason or action.code.value
|
|
165
|
+
|
|
166
|
+
return None
|
|
167
|
+
|
|
168
|
+
def setData(
|
|
169
|
+
self,
|
|
170
|
+
index: QModelIndex | QPersistentModelIndex,
|
|
171
|
+
value: Any,
|
|
172
|
+
role: int = Qt.ItemDataRole.EditRole,
|
|
173
|
+
) -> bool:
|
|
174
|
+
if index.isValid() and index.column() == 0 and role == Qt.ItemDataRole.CheckStateRole:
|
|
175
|
+
raw_idx = self._visible_indices[index.row()]
|
|
176
|
+
action = self._raw_actions[raw_idx]
|
|
177
|
+
is_checked = (
|
|
178
|
+
value == Qt.CheckState.Checked
|
|
179
|
+
or value is True
|
|
180
|
+
or value == Qt.CheckState.Checked.value
|
|
181
|
+
)
|
|
182
|
+
self._included[id(action)] = is_checked
|
|
183
|
+
self.dataChanged.emit(index, index, [Qt.ItemDataRole.CheckStateRole])
|
|
184
|
+
self.plan_changed.emit()
|
|
185
|
+
return True
|
|
186
|
+
return False
|
|
187
|
+
|
|
188
|
+
def flags(self, index: QModelIndex | QPersistentModelIndex) -> Qt.ItemFlag:
|
|
189
|
+
if not index.isValid():
|
|
190
|
+
return Qt.ItemFlag.NoItemFlags
|
|
191
|
+
base_flags = Qt.ItemFlag.ItemIsEnabled | Qt.ItemFlag.ItemIsSelectable
|
|
192
|
+
if index.column() == 0:
|
|
193
|
+
base_flags |= Qt.ItemFlag.ItemIsUserCheckable
|
|
194
|
+
return base_flags
|
|
195
|
+
|
|
196
|
+
def headerData(
|
|
197
|
+
self,
|
|
198
|
+
section: int,
|
|
199
|
+
orientation: Qt.Orientation,
|
|
200
|
+
role: int = Qt.ItemDataRole.DisplayRole,
|
|
201
|
+
) -> Any:
|
|
202
|
+
if (
|
|
203
|
+
orientation == Qt.Orientation.Horizontal
|
|
204
|
+
and role == Qt.ItemDataRole.DisplayRole
|
|
205
|
+
and 0 <= section < len(self.COLUMNS)
|
|
206
|
+
):
|
|
207
|
+
return self.COLUMNS[section]
|
|
208
|
+
return None
|
|
209
|
+
|
|
210
|
+
def get_action(self, row: int) -> PlannedAction | None:
|
|
211
|
+
"""Get the PlannedAction at visible row."""
|
|
212
|
+
if 0 <= row < len(self._visible_indices):
|
|
213
|
+
raw_idx = self._visible_indices[row]
|
|
214
|
+
return self._raw_actions[raw_idx]
|
|
215
|
+
return None
|
|
216
|
+
|
|
217
|
+
def toggle_all(self, checked: bool) -> None:
|
|
218
|
+
"""Check or uncheck all visible rows."""
|
|
219
|
+
self.beginResetModel()
|
|
220
|
+
for raw_idx in self._visible_indices:
|
|
221
|
+
action = self._raw_actions[raw_idx]
|
|
222
|
+
self._included[id(action)] = checked
|
|
223
|
+
self.endResetModel()
|
|
224
|
+
self.plan_changed.emit()
|
|
225
|
+
|
|
226
|
+
def get_included_plan(self) -> Plan:
|
|
227
|
+
"""Return a new Plan containing only actions checked for inclusion."""
|
|
228
|
+
included_actions = [
|
|
229
|
+
a
|
|
230
|
+
for a in self._raw_actions
|
|
231
|
+
if self._included.get(id(a), False)
|
|
232
|
+
and a.status in (PlanStatus.WILL_MOVE, PlanStatus.WILL_MOVE_RENAMED)
|
|
233
|
+
]
|
|
234
|
+
return Plan(folders=self._folders, actions=tuple(included_actions))
|
|
235
|
+
|
|
236
|
+
@property
|
|
237
|
+
def total_actions_count(self) -> int:
|
|
238
|
+
return len(self._raw_actions)
|
|
239
|
+
|
|
240
|
+
@property
|
|
241
|
+
def included_count(self) -> int:
|
|
242
|
+
return sum(
|
|
243
|
+
1
|
|
244
|
+
for a in self._raw_actions
|
|
245
|
+
if self._included.get(id(a), False)
|
|
246
|
+
and a.status in (PlanStatus.WILL_MOVE, PlanStatus.WILL_MOVE_RENAMED)
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
class RulesTableModel(QAbstractTableModel):
|
|
251
|
+
"""Table model displaying configured rules."""
|
|
252
|
+
|
|
253
|
+
COLUMNS: ClassVar[tuple[str, ...]] = (
|
|
254
|
+
"Enabled",
|
|
255
|
+
"Priority",
|
|
256
|
+
"Name",
|
|
257
|
+
"Keywords",
|
|
258
|
+
"Extensions",
|
|
259
|
+
"Destination",
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
rule_toggled = Signal(str, bool) # rule_name, new_enabled
|
|
263
|
+
|
|
264
|
+
def __init__(self, rules: Sequence[RuleSpec] | None = None) -> None:
|
|
265
|
+
super().__init__()
|
|
266
|
+
self._rules: list[RuleSpec] = list(rules) if rules is not None else []
|
|
267
|
+
|
|
268
|
+
def set_rules(self, rules: Sequence[RuleSpec]) -> None:
|
|
269
|
+
self.beginResetModel()
|
|
270
|
+
self._rules = list(rules)
|
|
271
|
+
self.endResetModel()
|
|
272
|
+
|
|
273
|
+
def rowCount(self, parent: QModelIndex | QPersistentModelIndex = _EMPTY_INDEX) -> int:
|
|
274
|
+
if parent.isValid():
|
|
275
|
+
return 0
|
|
276
|
+
return len(self._rules)
|
|
277
|
+
|
|
278
|
+
def columnCount(self, parent: QModelIndex | QPersistentModelIndex = _EMPTY_INDEX) -> int:
|
|
279
|
+
if parent.isValid():
|
|
280
|
+
return 0
|
|
281
|
+
return len(self.COLUMNS)
|
|
282
|
+
|
|
283
|
+
def data(
|
|
284
|
+
self,
|
|
285
|
+
index: QModelIndex | QPersistentModelIndex,
|
|
286
|
+
role: int = Qt.ItemDataRole.DisplayRole,
|
|
287
|
+
) -> Any:
|
|
288
|
+
if not index.isValid() or index.row() >= len(self._rules):
|
|
289
|
+
return None
|
|
290
|
+
|
|
291
|
+
rule = self._rules[index.row()]
|
|
292
|
+
col = index.column()
|
|
293
|
+
|
|
294
|
+
if role == Qt.ItemDataRole.CheckStateRole and col == 0:
|
|
295
|
+
return Qt.CheckState.Checked if rule.enabled else Qt.CheckState.Unchecked
|
|
296
|
+
|
|
297
|
+
if role == Qt.ItemDataRole.DisplayRole:
|
|
298
|
+
if col == 0:
|
|
299
|
+
return ""
|
|
300
|
+
elif col == 1:
|
|
301
|
+
return rule.priority
|
|
302
|
+
elif col == 2:
|
|
303
|
+
return rule.name
|
|
304
|
+
elif col == 3:
|
|
305
|
+
return ", ".join(rule.keywords)
|
|
306
|
+
elif col == 4:
|
|
307
|
+
return ", ".join(rule.extensions)
|
|
308
|
+
elif col == 5:
|
|
309
|
+
return rule.destination
|
|
310
|
+
|
|
311
|
+
return None
|
|
312
|
+
|
|
313
|
+
def setData(
|
|
314
|
+
self,
|
|
315
|
+
index: QModelIndex | QPersistentModelIndex,
|
|
316
|
+
value: Any,
|
|
317
|
+
role: int = Qt.ItemDataRole.EditRole,
|
|
318
|
+
) -> bool:
|
|
319
|
+
if index.isValid() and index.column() == 0 and role == Qt.ItemDataRole.CheckStateRole:
|
|
320
|
+
rule = self._rules[index.row()]
|
|
321
|
+
new_val = (
|
|
322
|
+
value == Qt.CheckState.Checked
|
|
323
|
+
or value is True
|
|
324
|
+
or value == Qt.CheckState.Checked.value
|
|
325
|
+
)
|
|
326
|
+
self.rule_toggled.emit(rule.name, new_val)
|
|
327
|
+
return True
|
|
328
|
+
return False
|
|
329
|
+
|
|
330
|
+
def flags(self, index: QModelIndex | QPersistentModelIndex) -> Qt.ItemFlag:
|
|
331
|
+
if not index.isValid():
|
|
332
|
+
return Qt.ItemFlag.NoItemFlags
|
|
333
|
+
base_flags = Qt.ItemFlag.ItemIsEnabled | Qt.ItemFlag.ItemIsSelectable
|
|
334
|
+
if index.column() == 0:
|
|
335
|
+
base_flags |= Qt.ItemFlag.ItemIsUserCheckable
|
|
336
|
+
return base_flags
|
|
337
|
+
|
|
338
|
+
def headerData(
|
|
339
|
+
self,
|
|
340
|
+
section: int,
|
|
341
|
+
orientation: Qt.Orientation,
|
|
342
|
+
role: int = Qt.ItemDataRole.DisplayRole,
|
|
343
|
+
) -> Any:
|
|
344
|
+
if (
|
|
345
|
+
orientation == Qt.Orientation.Horizontal
|
|
346
|
+
and role == Qt.ItemDataRole.DisplayRole
|
|
347
|
+
and 0 <= section < len(self.COLUMNS)
|
|
348
|
+
):
|
|
349
|
+
return self.COLUMNS[section]
|
|
350
|
+
return None
|
|
351
|
+
|
|
352
|
+
def get_rule(self, row: int) -> RuleSpec | None:
|
|
353
|
+
if 0 <= row < len(self._rules):
|
|
354
|
+
return self._rules[row]
|
|
355
|
+
return None
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
class HistoryTableModel(QAbstractTableModel):
|
|
359
|
+
"""Table model displaying journal operations."""
|
|
360
|
+
|
|
361
|
+
COLUMNS: ClassVar[tuple[str, ...]] = (
|
|
362
|
+
"ID",
|
|
363
|
+
"Batch",
|
|
364
|
+
"Status",
|
|
365
|
+
"Source",
|
|
366
|
+
"Destination",
|
|
367
|
+
"Rule",
|
|
368
|
+
"Time",
|
|
369
|
+
"Details",
|
|
370
|
+
)
|
|
371
|
+
|
|
372
|
+
def __init__(self, records: Sequence[OperationRecord] | None = None) -> None:
|
|
373
|
+
super().__init__()
|
|
374
|
+
self._records: list[OperationRecord] = list(records) if records is not None else []
|
|
375
|
+
|
|
376
|
+
def set_records(self, records: Sequence[OperationRecord]) -> None:
|
|
377
|
+
self.beginResetModel()
|
|
378
|
+
self._records = list(records)
|
|
379
|
+
self.endResetModel()
|
|
380
|
+
|
|
381
|
+
def rowCount(self, parent: QModelIndex | QPersistentModelIndex = _EMPTY_INDEX) -> int:
|
|
382
|
+
if parent.isValid():
|
|
383
|
+
return 0
|
|
384
|
+
return len(self._records)
|
|
385
|
+
|
|
386
|
+
def columnCount(self, parent: QModelIndex | QPersistentModelIndex = _EMPTY_INDEX) -> int:
|
|
387
|
+
if parent.isValid():
|
|
388
|
+
return 0
|
|
389
|
+
return len(self.COLUMNS)
|
|
390
|
+
|
|
391
|
+
def data(
|
|
392
|
+
self,
|
|
393
|
+
index: QModelIndex | QPersistentModelIndex,
|
|
394
|
+
role: int = Qt.ItemDataRole.DisplayRole,
|
|
395
|
+
) -> Any:
|
|
396
|
+
if not index.isValid() or index.row() >= len(self._records):
|
|
397
|
+
return None
|
|
398
|
+
|
|
399
|
+
rec = self._records[index.row()]
|
|
400
|
+
col = index.column()
|
|
401
|
+
|
|
402
|
+
if role == Qt.ItemDataRole.DisplayRole:
|
|
403
|
+
if col == 0:
|
|
404
|
+
return rec.id
|
|
405
|
+
elif col == 1:
|
|
406
|
+
return rec.batch_id
|
|
407
|
+
elif col == 2:
|
|
408
|
+
return rec.status.value
|
|
409
|
+
elif col == 3:
|
|
410
|
+
return str(rec.src_path)
|
|
411
|
+
elif col == 4:
|
|
412
|
+
return str(rec.dst_path) if rec.dst_path is not None else ""
|
|
413
|
+
elif col == 5:
|
|
414
|
+
return rec.rule_name or ""
|
|
415
|
+
elif col == 6:
|
|
416
|
+
return rec.created_at
|
|
417
|
+
elif col == 7:
|
|
418
|
+
return rec.error or ""
|
|
419
|
+
|
|
420
|
+
return None
|
|
421
|
+
|
|
422
|
+
def headerData(
|
|
423
|
+
self,
|
|
424
|
+
section: int,
|
|
425
|
+
orientation: Qt.Orientation,
|
|
426
|
+
role: int = Qt.ItemDataRole.DisplayRole,
|
|
427
|
+
) -> Any:
|
|
428
|
+
if (
|
|
429
|
+
orientation == Qt.Orientation.Horizontal
|
|
430
|
+
and role == Qt.ItemDataRole.DisplayRole
|
|
431
|
+
and 0 <= section < len(self.COLUMNS)
|
|
432
|
+
):
|
|
433
|
+
return self.COLUMNS[section]
|
|
434
|
+
return None
|
|
435
|
+
|
|
436
|
+
def get_record(self, row: int) -> OperationRecord | None:
|
|
437
|
+
if 0 <= row < len(self._records):
|
|
438
|
+
return self._records[row]
|
|
439
|
+
return None
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
class DuplicatesTableModel(QAbstractTableModel):
|
|
443
|
+
"""Table model displaying duplicate groups."""
|
|
444
|
+
|
|
445
|
+
COLUMNS: ClassVar[tuple[str, ...]] = (
|
|
446
|
+
"Kind",
|
|
447
|
+
"Files Count",
|
|
448
|
+
"Wasted Space",
|
|
449
|
+
"Hash / Note",
|
|
450
|
+
"Files",
|
|
451
|
+
)
|
|
452
|
+
|
|
453
|
+
def __init__(self, groups: Sequence[DuplicateGroup] | None = None) -> None:
|
|
454
|
+
super().__init__()
|
|
455
|
+
self._raw_groups: list[DuplicateGroup] = list(groups) if groups is not None else []
|
|
456
|
+
self._filter_kind: str = "all"
|
|
457
|
+
self._visible_groups: list[DuplicateGroup] = []
|
|
458
|
+
self._rebuild_visibility()
|
|
459
|
+
|
|
460
|
+
def _rebuild_visibility(self) -> None:
|
|
461
|
+
if self._filter_kind == "all":
|
|
462
|
+
self._visible_groups = list(self._raw_groups)
|
|
463
|
+
else:
|
|
464
|
+
self._visible_groups = [
|
|
465
|
+
g for g in self._raw_groups if g.kind.lower() == self._filter_kind
|
|
466
|
+
]
|
|
467
|
+
|
|
468
|
+
def set_groups(self, groups: Sequence[DuplicateGroup]) -> None:
|
|
469
|
+
self.beginResetModel()
|
|
470
|
+
self._raw_groups = list(groups)
|
|
471
|
+
self._rebuild_visibility()
|
|
472
|
+
self.endResetModel()
|
|
473
|
+
|
|
474
|
+
def set_filter(self, kind: str) -> None:
|
|
475
|
+
"""Filter by group kind: 'all', 'exact', 'potential', 'hardlink'."""
|
|
476
|
+
self.beginResetModel()
|
|
477
|
+
self._filter_kind = kind.lower()
|
|
478
|
+
self._rebuild_visibility()
|
|
479
|
+
self.endResetModel()
|
|
480
|
+
|
|
481
|
+
def rowCount(self, parent: QModelIndex | QPersistentModelIndex = _EMPTY_INDEX) -> int:
|
|
482
|
+
if parent.isValid():
|
|
483
|
+
return 0
|
|
484
|
+
return len(self._visible_groups)
|
|
485
|
+
|
|
486
|
+
def columnCount(self, parent: QModelIndex | QPersistentModelIndex = _EMPTY_INDEX) -> int:
|
|
487
|
+
if parent.isValid():
|
|
488
|
+
return 0
|
|
489
|
+
return len(self.COLUMNS)
|
|
490
|
+
|
|
491
|
+
def data(
|
|
492
|
+
self,
|
|
493
|
+
index: QModelIndex | QPersistentModelIndex,
|
|
494
|
+
role: int = Qt.ItemDataRole.DisplayRole,
|
|
495
|
+
) -> Any:
|
|
496
|
+
if not index.isValid() or index.row() >= len(self._visible_groups):
|
|
497
|
+
return None
|
|
498
|
+
|
|
499
|
+
group = self._visible_groups[index.row()]
|
|
500
|
+
col = index.column()
|
|
501
|
+
|
|
502
|
+
if role == Qt.ItemDataRole.DisplayRole:
|
|
503
|
+
if col == 0:
|
|
504
|
+
return group.kind
|
|
505
|
+
elif col == 1:
|
|
506
|
+
return len(group.files)
|
|
507
|
+
elif col == 2:
|
|
508
|
+
return format_bytes(group.wasted_bytes)
|
|
509
|
+
elif col == 3:
|
|
510
|
+
return group.sha256[:16] + "..." if group.sha256 else group.note
|
|
511
|
+
elif col == 4:
|
|
512
|
+
return ", ".join(f.name for f in group.files[:3]) + (
|
|
513
|
+
f" (+{len(group.files) - 3} more)" if len(group.files) > 3 else ""
|
|
514
|
+
)
|
|
515
|
+
|
|
516
|
+
return None
|
|
517
|
+
|
|
518
|
+
def headerData(
|
|
519
|
+
self,
|
|
520
|
+
section: int,
|
|
521
|
+
orientation: Qt.Orientation,
|
|
522
|
+
role: int = Qt.ItemDataRole.DisplayRole,
|
|
523
|
+
) -> Any:
|
|
524
|
+
if (
|
|
525
|
+
orientation == Qt.Orientation.Horizontal
|
|
526
|
+
and role == Qt.ItemDataRole.DisplayRole
|
|
527
|
+
and 0 <= section < len(self.COLUMNS)
|
|
528
|
+
):
|
|
529
|
+
return self.COLUMNS[section]
|
|
530
|
+
return None
|
|
531
|
+
|
|
532
|
+
def get_group(self, row: int) -> DuplicateGroup | None:
|
|
533
|
+
if 0 <= row < len(self._visible_groups):
|
|
534
|
+
return self._visible_groups[row]
|
|
535
|
+
return None
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
__all__ = [
|
|
539
|
+
"DuplicatesTableModel",
|
|
540
|
+
"HistoryTableModel",
|
|
541
|
+
"PlanTableModel",
|
|
542
|
+
"RulesTableModel",
|
|
543
|
+
"format_bytes",
|
|
544
|
+
]
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""GUI Views package for ClutterXP."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from .dashboard import DashboardView
|
|
6
|
+
from .duplicates import DuplicatesView
|
|
7
|
+
from .folders import FoldersView
|
|
8
|
+
from .history import HistoryView
|
|
9
|
+
from .preview import PreviewView
|
|
10
|
+
from .rules import RulesView
|
|
11
|
+
from .settings import SettingsView
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
"DashboardView",
|
|
15
|
+
"DuplicatesView",
|
|
16
|
+
"FoldersView",
|
|
17
|
+
"HistoryView",
|
|
18
|
+
"PreviewView",
|
|
19
|
+
"RulesView",
|
|
20
|
+
"SettingsView",
|
|
21
|
+
]
|