-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
232 lines (182 loc) · 8.52 KB
/
Copy pathconfig.py
File metadata and controls
232 lines (182 loc) · 8.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Configuration dialog for the Link Farm plugin.
"""
from qt.core import (QWidget, QVBoxLayout, QHBoxLayout, QLabel, QPushButton,
QListWidget, QListWidgetItem, QGroupBox, QRadioButton,
QCheckBox, QLineEdit, QFormLayout, QMessageBox)
from calibre.utils.config import JSONConfig
from calibre_plugins.linkfarm.profile_manager import ProfileManager, prefs
class ConfigWidget(QWidget):
"""Configuration widget for Link Farm plugin."""
def __init__(self):
QWidget.__init__(self)
self.layout = QVBoxLayout(self)
self.setLayout(self.layout)
# Profile management section
self.setup_profile_section()
# General settings section
self.setup_general_settings()
# Load current settings
self.load_settings()
def setup_profile_section(self):
"""Setup the profile management section."""
profile_group = QGroupBox('Sync Profiles')
profile_layout = QVBoxLayout()
# Profile list
self.profile_list = QListWidget()
self.profile_list.itemSelectionChanged.connect(self.on_profile_selected)
profile_layout.addWidget(self.profile_list)
# Buttons for profile management
button_layout = QHBoxLayout()
self.new_profile_btn = QPushButton('New Profile')
self.new_profile_btn.clicked.connect(self.new_profile)
button_layout.addWidget(self.new_profile_btn)
self.edit_profile_btn = QPushButton('Edit Profile')
self.edit_profile_btn.clicked.connect(self.edit_profile)
self.edit_profile_btn.setEnabled(False)
button_layout.addWidget(self.edit_profile_btn)
self.delete_profile_btn = QPushButton('Delete Profile')
self.delete_profile_btn.clicked.connect(self.delete_profile)
self.delete_profile_btn.setEnabled(False)
button_layout.addWidget(self.delete_profile_btn)
button_layout.addStretch()
profile_layout.addLayout(button_layout)
profile_group.setLayout(profile_layout)
self.layout.addWidget(profile_group)
def setup_general_settings(self):
"""Setup general settings section."""
settings_group = QGroupBox('General Settings')
settings_layout = QFormLayout()
# Selection method
self.custom_column_radio = QRadioButton('Custom Column')
self.tags_radio = QRadioButton('Tags')
self.custom_column_radio.setChecked(True)
selection_layout = QVBoxLayout()
selection_layout.addWidget(self.custom_column_radio)
self.custom_column_name = QLineEdit()
self.custom_column_name.setPlaceholderText('e.g., #sync_profiles')
custom_column_layout = QHBoxLayout()
custom_column_layout.addSpacing(20)
custom_column_layout.addWidget(QLabel('Column name:'))
custom_column_layout.addWidget(self.custom_column_name)
selection_layout.addLayout(custom_column_layout)
selection_layout.addWidget(self.tags_radio)
self.tag_prefix = QLineEdit()
self.tag_prefix.setPlaceholderText('e.g., sync:')
tag_layout = QHBoxLayout()
tag_layout.addSpacing(20)
tag_layout.addWidget(QLabel('Tag prefix:'))
tag_layout.addWidget(self.tag_prefix)
selection_layout.addLayout(tag_layout)
settings_layout.addRow('Book Selection Method:', selection_layout)
# Visual indicators
self.show_status_icons = QCheckBox('Show sync status icons in library view')
settings_layout.addRow('', self.show_status_icons)
# Symlink behavior
self.use_relative_symlinks = QCheckBox('Use relative symlinks (when possible)')
settings_layout.addRow('Symlink Behavior:', self.use_relative_symlinks)
self.confirm_deletions = QCheckBox('Confirm before deleting symlinks')
settings_layout.addRow('', self.confirm_deletions)
settings_group.setLayout(settings_layout)
self.layout.addWidget(settings_group)
def load_settings(self):
"""Load current settings from preferences."""
# Load profiles
self.refresh_profile_list()
# Load general settings
if prefs['selection_method'] == 'custom_column':
self.custom_column_radio.setChecked(True)
else:
self.tags_radio.setChecked(True)
self.custom_column_name.setText(prefs['custom_column_name'])
self.tag_prefix.setText(prefs['tag_prefix'])
self.show_status_icons.setChecked(prefs['show_status_icons'])
self.use_relative_symlinks.setChecked(prefs['use_relative_symlinks'])
self.confirm_deletions.setChecked(prefs['confirm_deletions'])
def refresh_profile_list(self):
"""Refresh the profile list."""
self.profile_list.clear()
profiles = ProfileManager.get_all_profiles()
for profile_id, profile in profiles.items():
status = "✓" if profile.active else "✗"
structure = "Structured" if profile.preserve_structure else "Flat"
formats = ", ".join(profile.format_priority[:3])
if len(profile.format_priority) > 3:
formats += "..."
item_text = f"{status} {profile.name} - {profile.target_directory} ({structure}, {formats})"
item = QListWidgetItem(item_text)
item.setData(32, profile_id) # Qt.UserRole
self.profile_list.addItem(item)
def on_profile_selected(self):
"""Handle profile selection."""
has_selection = len(self.profile_list.selectedItems()) > 0
self.edit_profile_btn.setEnabled(has_selection)
self.delete_profile_btn.setEnabled(has_selection)
def new_profile(self):
"""Create a new profile."""
from calibre_plugins.linkfarm.dialogs import ProfileEditorDialog
dialog = ProfileEditorDialog(self)
if dialog.exec():
self.refresh_profile_list()
def edit_profile(self):
"""Edit selected profile."""
selected_items = self.profile_list.selectedItems()
if not selected_items:
return
profile_id = selected_items[0].data(32) # Qt.UserRole
profile = ProfileManager.get_profile(profile_id)
if profile:
from calibre_plugins.linkfarm.dialogs import ProfileEditorDialog
dialog = ProfileEditorDialog(self, profile)
if dialog.exec():
self.refresh_profile_list()
def delete_profile(self):
"""Delete selected profile."""
selected_items = self.profile_list.selectedItems()
if not selected_items:
return
profile_id = selected_items[0].data(32) # Qt.UserRole
profile = ProfileManager.get_profile(profile_id)
if profile:
reply = QMessageBox.question(
self, 'Delete Profile',
f'Are you sure you want to delete the profile "{profile.name}"?\n\n'
f'This will remove all sync state for books in this profile.',
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
)
if reply == QMessageBox.StandardButton.Yes:
ProfileManager.delete_profile(profile_id)
self.refresh_profile_list()
def save_settings(self):
"""Save settings to preferences."""
# Save selection method
if self.custom_column_radio.isChecked():
prefs['selection_method'] = 'custom_column'
else:
prefs['selection_method'] = 'tags'
prefs['custom_column_name'] = self.custom_column_name.text().strip()
prefs['tag_prefix'] = self.tag_prefix.text().strip()
prefs['show_status_icons'] = self.show_status_icons.isChecked()
prefs['use_relative_symlinks'] = self.use_relative_symlinks.isChecked()
prefs['confirm_deletions'] = self.confirm_deletions.isChecked()
def validate(self):
"""Validate settings before saving."""
if self.custom_column_radio.isChecked():
column_name = self.custom_column_name.text().strip()
if not column_name:
QMessageBox.warning(
self, 'Validation Error',
'Please enter a custom column name.'
)
return False
if self.tags_radio.isChecked():
tag_prefix = self.tag_prefix.text().strip()
if not tag_prefix:
QMessageBox.warning(
self, 'Validation Error',
'Please enter a tag prefix.'
)
return False
return True