-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings_dialog.py
More file actions
642 lines (537 loc) · 25.1 KB
/
Copy pathsettings_dialog.py
File metadata and controls
642 lines (537 loc) · 25.1 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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
"""
settings_dialog.py - Impostazioni globali PCM (GTK3)
Gtk.Dialog con Gtk.Notebook (tab).
Tab: Generale, Terminale, SSH, Scorciatoie.
"""
import os
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
import config_manager
import crypto_manager
from themes import TERMINAL_THEMES
from translations import t, AVAILABLE_LANGUAGES, set_lang
class SettingsDialog(Gtk.Dialog):
def __init__(self, parent=None):
super().__init__(
title=t("settings.title"),
transient_for=parent,
modal=True,
destroy_with_parent=True
)
self.set_default_size(580, 520)
self._settings = config_manager.load_settings()
self._init_ui()
self._popola()
self.show_all()
# ------------------------------------------------------------------
# Struttura principale
# ------------------------------------------------------------------
def _init_ui(self):
area = self.get_content_area()
area.set_spacing(8)
area.set_margin_start(12)
area.set_margin_end(12)
area.set_margin_top(12)
area.set_margin_bottom(8)
hdr = Gtk.Label(label=t("settings.header"))
hdr.get_style_context().add_class("section-header")
hdr.set_xalign(0.0)
area.pack_start(hdr, False, False, 0)
self._notebook = Gtk.Notebook()
area.pack_start(self._notebook, True, True, 0)
self._notebook.append_page(self._build_generale(), Gtk.Label(label=t("settings.tab.general")))
self._notebook.append_page(self._build_scorciatoie(), Gtk.Label(label=t("settings.tab.shortcuts")))
self._notebook.append_page(self._build_credenziali(), Gtk.Label(label=t("settings.tab.credentials")))
self._notebook.append_page(self._build_strumenti(), Gtk.Label(label=t("settings.tab.tools")))
self.add_button(t("sd.cancel"), Gtk.ResponseType.CANCEL)
ok_btn = self.add_button("OK", Gtk.ResponseType.OK)
ok_btn.get_style_context().add_class("suggested-action")
self.connect("response", self._on_response)
# ------------------------------------------------------------------
# Helper form row
# ------------------------------------------------------------------
@staticmethod
def _form_row(label_text: str, widget: Gtk.Widget, grid: Gtk.Grid, row: int):
lbl = Gtk.Label(label=label_text)
lbl.set_xalign(1.0)
lbl.set_margin_end(8)
grid.attach(lbl, 0, row, 1, 1)
grid.attach(widget, 1, row, 1, 1)
@staticmethod
def _make_grid() -> Gtk.Grid:
g = Gtk.Grid()
g.set_row_spacing(8)
g.set_column_spacing(8)
g.set_margin_start(12)
g.set_margin_end(12)
g.set_margin_top(12)
g.set_margin_bottom(12)
g.set_column_homogeneous(False)
return g
@staticmethod
def _browse_dir(entry: Gtk.Entry, title: str, parent):
dlg = Gtk.FileChooserDialog(
title=title,
parent=parent,
action=Gtk.FileChooserAction.SELECT_FOLDER
)
dlg.add_buttons(
"_Annulla", Gtk.ResponseType.CANCEL,
"_Seleziona", Gtk.ResponseType.OK
)
if dlg.run() == Gtk.ResponseType.OK:
entry.set_text(dlg.get_filename())
dlg.destroy()
# ------------------------------------------------------------------
# Tab Generale
# ------------------------------------------------------------------
def _build_generale(self) -> Gtk.Widget:
grid = self._make_grid()
row = 0
# Home dir
home_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=4)
self.entry_home = Gtk.Entry()
self.entry_home.set_hexpand(True)
btn_home = Gtk.Button(label="…")
btn_home.connect("clicked", lambda b: self._browse_dir(
self.entry_home, "Home directory", self))
home_box.pack_start(self.entry_home, True, True, 0)
home_box.pack_start(btn_home, False, False, 0)
self._form_row(t("settings.general.home_dir"), home_box, grid, row); row += 1
# Editor
self.combo_editor = Gtk.ComboBoxText.new_with_entry()
_editors = ["nano", "vim", "vi", "gedit", "kate", "code", "mousepad", "NotePadPQ"]
for ed in _editors:
self.combo_editor.append_text(ed)
self.combo_editor.set_hexpand(True)
self._form_row(t("settings.general.editor"), self.combo_editor, grid, row); row += 1
# Conferma uscita
self.chk_confirm_exit = Gtk.CheckButton(label=t("settings.general.confirm_exit"))
grid.attach(self.chk_confirm_exit, 0, row, 2, 1); row += 1
# Audit log
self.chk_audit_log = Gtk.CheckButton(label=t("settings.general.audit_log"))
grid.attach(self.chk_audit_log, 0, row, 2, 1); row += 1
# Session restore
self.chk_restore_sessions = Gtk.CheckButton(
label=t("settings.general.restore_sessions")
)
self.chk_restore_sessions.set_tooltip_text(
t("settings.general.restore_sessions_tt")
)
grid.attach(self.chk_restore_sessions, 0, row, 2, 1); row += 1
# Separatore
sep = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL)
sep.set_margin_top(4)
sep.set_margin_bottom(4)
grid.attach(sep, 0, row, 2, 1); row += 1
# Lingua
self.combo_lingua = Gtk.ComboBoxText()
self._lang_codes = []
for code, label in AVAILABLE_LANGUAGES.items():
self.combo_lingua.append_text(label)
self._lang_codes.append(code)
self._form_row("Language / Lingua:", self.combo_lingua, grid, row); row += 1
note_lbl = Gtk.Label(label=t("settings.general.language_note"))
note_lbl.set_xalign(0.0)
note_lbl.get_style_context().add_class("dim-label")
grid.attach(note_lbl, 0, row, 2, 1); row += 1
sw = Gtk.ScrolledWindow()
sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
sw.add(grid)
return sw
# ------------------------------------------------------------------
# Tab Terminale
# ------------------------------------------------------------------
def _build_terminale(self) -> Gtk.Widget:
grid = self._make_grid()
row = 0
self.combo_tema = Gtk.ComboBoxText()
for nome in TERMINAL_THEMES.keys():
self.combo_tema.append_text(nome)
self._form_row(t("settings.terminal.default_theme"), self.combo_tema, grid, row); row += 1
self.combo_font = Gtk.ComboBoxText.new_with_entry()
for f in ["Monospace", "DejaVu Sans Mono", "Hack", "JetBrains Mono",
"Fira Code", "Source Code Pro", "Inconsolata", "Terminus"]:
self.combo_font.append_text(f)
self._form_row(t("settings.terminal.default_font"), self.combo_font, grid, row); row += 1
self.spin_font_size = Gtk.SpinButton.new_with_range(6, 32, 1)
self._form_row(t("settings.terminal.font_size"), self.spin_font_size, grid, row); row += 1
# Scrollback infinito checkbox
self.chk_infinite_scrollback = Gtk.CheckButton(label=t("settings.terminal.infinite_scrollback"))
grid.attach(self.chk_infinite_scrollback, 0, row, 2, 1); row += 1
# Scrollback lines (disabilitato se infinito è attivo)
self.spin_scrollback = Gtk.SpinButton.new_with_range(100, 100000, 1000)
self._form_row(t("settings.terminal.scrollback"), self.spin_scrollback, grid, row); row += 1
# Connetti il segnale per abilitare/disabilitare lo spin button
self.chk_infinite_scrollback.connect("toggled", self._on_infinite_scrollback_toggled)
self.chk_confirm_close = Gtk.CheckButton(label=t("settings.terminal.confirm_close"))
grid.attach(self.chk_confirm_close, 0, row, 2, 1); row += 1
self.chk_warn_paste = Gtk.CheckButton(label=t("settings.terminal.warn_paste"))
grid.attach(self.chk_warn_paste, 0, row, 2, 1); row += 1
self.chk_log = Gtk.CheckButton(label=t("settings.terminal.log_output"))
grid.attach(self.chk_log, 0, row, 2, 1); row += 1
log_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=4)
self.entry_log_dir = Gtk.Entry()
self.entry_log_dir.set_hexpand(True)
btn_log = Gtk.Button(label="…")
btn_log.connect("clicked", lambda b: self._browse_dir(
self.entry_log_dir, "Log folder", self))
log_box.pack_start(self.entry_log_dir, True, True, 0)
log_box.pack_start(btn_log, False, False, 0)
self._form_row(t("settings.terminal.log_dir"), log_box, grid, row); row += 1
sw = Gtk.ScrolledWindow()
sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
sw.add(grid)
return sw
def _on_infinite_scrollback_toggled(self, checkbox):
"""Abilita/disabilita lo spin button quando il checkbox scrollback infinito viene attivato/disattivato."""
is_infinite = checkbox.get_active()
self.spin_scrollback.set_sensitive(not is_infinite)
# ------------------------------------------------------------------
# Tab SSH
# ------------------------------------------------------------------
def _build_ssh(self) -> Gtk.Widget:
grid = self._make_grid()
row = 0
self.spin_ka = Gtk.SpinButton.new_with_range(0, 3600, 1)
self._form_row(t("settings.ssh.keepalive"), self.spin_ka, grid, row); row += 1
self.chk_strict = Gtk.CheckButton(label=t("settings.ssh.strict"))
grid.attach(self.chk_strict, 0, row, 2, 1); row += 1
self.chk_sftp_auto = Gtk.CheckButton(label=t("settings.ssh.sftp_auto"))
grid.attach(self.chk_sftp_auto, 0, row, 2, 1); row += 1
return grid
# ------------------------------------------------------------------
# Tab Credenziali
# ------------------------------------------------------------------
def _build_credenziali(self):
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
box.set_margin_start(8)
box.set_margin_end(8)
box.set_margin_top(8)
box.set_margin_bottom(8)
# TreeView
self._cred_store = Gtk.ListStore(str, str, str, str) # name, user, domain, password
tv = Gtk.TreeView(model=self._cred_store)
for i, title in enumerate(["Nome", "Utente", "Dominio"]):
col = Gtk.TreeViewColumn(title, Gtk.CellRendererText(), text=i)
col.set_expand(i == 0)
tv.append_column(col)
tv.set_headers_visible(True)
tv.get_selection().set_mode(Gtk.SelectionMode.SINGLE)
self._cred_tv = tv
sw = Gtk.ScrolledWindow()
sw.set_hexpand(True)
sw.set_vexpand(True)
sw.set_min_content_height(180)
sw.add(tv)
box.pack_start(sw, True, True, 0)
# Buttons
btn_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=6)
btn_add = Gtk.Button(label=t("btn.add"))
btn_edit = Gtk.Button(label=t("btn.edit"))
btn_del = Gtk.Button(label=t("btn.delete"))
btn_add.connect("clicked", lambda _: self._cred_aggiungi())
btn_edit.connect("clicked", lambda _: self._cred_modifica())
btn_del.connect("clicked", lambda _: self._cred_elimina())
for b in (btn_add, btn_edit, btn_del):
btn_box.pack_start(b, False, False, 0)
box.pack_start(btn_box, False, False, 0)
return box
def _cred_dialogo(self, nome="", user="", domain="", password=""):
"""Show add/edit dialog. Returns (nome, user, domain, password) or None."""
dlg = Gtk.Dialog(
title=t("settings.cred.edit_title"),
transient_for=self,
modal=True,
destroy_with_parent=True,
)
dlg.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
Gtk.STOCK_OK, Gtk.ResponseType.OK)
dlg.set_default_response(Gtk.ResponseType.OK)
dlg.set_default_size(320, -1)
grid = Gtk.Grid(column_spacing=8, row_spacing=6,
margin_start=12, margin_end=12,
margin_top=12, margin_bottom=8)
entries = {}
for row_i, (key, label, vis) in enumerate([
("name", t("settings.cred.name") + ":", True),
("user", t("sd.user") + ":", True),
("domain", "Domain:", True),
("password", t("sd.password") + ":", False),
]):
lbl = Gtk.Label(label=label, xalign=1.0)
val = {"name": nome, "user": user, "domain": domain, "password": password}[key]
e = Gtk.Entry(text=val, visibility=vis)
e.set_hexpand(True)
e.set_activates_default(True)
grid.attach(lbl, 0, row_i, 1, 1)
grid.attach(e, 1, row_i, 1, 1)
entries[key] = e
dlg.get_content_area().add(grid)
dlg.show_all()
resp = dlg.run()
result = None
if resp == Gtk.ResponseType.OK:
result = (
entries["name"].get_text().strip(),
entries["user"].get_text().strip(),
entries["domain"].get_text().strip(),
entries["password"].get_text(),
)
dlg.destroy()
return result
def _cred_aggiungi(self):
result = self._cred_dialogo()
if result and result[0]:
self._cred_store.append(list(result))
def _cred_modifica(self):
model, it = self._cred_tv.get_selection().get_selected()
if not it:
return
row = list(model[it])
result = self._cred_dialogo(*row)
if result and result[0]:
for i, v in enumerate(result):
model.set_value(it, i, v)
def _cred_elimina(self):
model, it = self._cred_tv.get_selection().get_selected()
if it:
model.remove(it)
# ------------------------------------------------------------------
# Tab Strumenti personalizzati (VNC / RDP)
# ------------------------------------------------------------------
def _build_strumenti(self) -> Gtk.Widget:
outer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=12)
outer.set_margin_start(12); outer.set_margin_end(12)
outer.set_margin_top(12); outer.set_margin_bottom(12)
for category, label in [("vnc", t("settings.tools.vnc_group")),
("rdp", t("settings.tools.rdp_group"))]:
grp = Gtk.Frame()
grp_lbl = Gtk.Label(label=f"<b>{label}</b>")
grp_lbl.set_use_markup(True)
grp.set_label_widget(grp_lbl)
grp_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=4)
grp_box.set_margin_start(8); grp_box.set_margin_end(8)
grp_box.set_margin_top(4); grp_box.set_margin_bottom(8)
# TreeView: Etichetta, Percorso, Sintassi
store = Gtk.ListStore(str, str, str)
view = Gtk.TreeView(model=store)
view.set_headers_visible(True)
view.set_size_request(-1, 110)
for i, col_title in enumerate([t("settings.tools.col_label"),
t("settings.tools.col_path"),
t("settings.tools.col_syntax")]):
cell = Gtk.CellRendererText()
cell.set_property("editable", True)
cell.connect("edited", self._on_tool_cell_edited, store, i)
col = Gtk.TreeViewColumn(col_title, cell, text=i)
col.set_expand(i == 1)
col.set_resizable(True)
view.append_column(col)
scroll = Gtk.ScrolledWindow()
scroll.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
scroll.add(view)
grp_box.pack_start(scroll, True, True, 0)
# Toolbar
tb = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=4)
btn_add = Gtk.Button(label=t("settings.tools.add"))
btn_rem = Gtk.Button(label=t("settings.tools.remove"))
btn_add.connect("clicked", lambda b, s=store, c=category: self._aggiungi_tool(s, c))
btn_rem.connect("clicked", lambda b, v=view, s=store: self._rimuovi_tool(v, s))
tb.pack_start(btn_add, False, False, 0)
tb.pack_start(btn_rem, False, False, 0)
grp_box.pack_start(tb, False, False, 0)
grp.add(grp_box)
outer.pack_start(grp, False, False, 0)
# Salva riferimento store per popola/salva
if category == "vnc":
self._store_vnc = store
else:
self._store_rdp = store
nota = Gtk.Label(label=t("settings.tools.note"))
nota.set_xalign(0.0)
nota.get_style_context().add_class("dim-label")
nota.set_line_wrap(True)
outer.pack_start(nota, False, False, 0)
sw = Gtk.ScrolledWindow()
sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
sw.add(outer)
return sw
def _on_tool_cell_edited(self, cell, path, new_text, store, col):
it = store.get_iter_from_string(path)
if it is not None:
store.set_value(it, col, new_text)
def _aggiungi_tool(self, store: Gtk.ListStore, category: str):
syntaxes_vnc = ["TigerVNC", "RealVNC", "Remmina", "Generico"]
syntaxes_rdp = ["xfreerdp", "rdesktop", "Generico"]
syntaxes = syntaxes_vnc if category == "vnc" else syntaxes_rdp
title_key = "settings.tools.dlg_title_vnc" if category == "vnc" else "settings.tools.dlg_title_rdp"
dlg = Gtk.Dialog(title=t(title_key), transient_for=self, modal=True)
dlg.set_default_size(400, -1)
area = dlg.get_content_area()
area.set_spacing(8)
area.set_margin_start(12); area.set_margin_end(12)
area.set_margin_top(12); area.set_margin_bottom(8)
grid = Gtk.Grid()
grid.set_row_spacing(8)
grid.set_column_spacing(8)
def _lbl(txt):
l = Gtk.Label(label=txt)
l.set_xalign(1.0)
return l
entry_label = Gtk.Entry()
entry_label.set_hexpand(True)
entry_label.set_placeholder_text("UltraVNC, AnyDesk…")
grid.attach(_lbl(t("settings.tools.lbl_label")), 0, 0, 1, 1)
grid.attach(entry_label, 1, 0, 1, 1)
path_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=4)
entry_path = Gtk.Entry()
entry_path.set_hexpand(True)
entry_path.set_placeholder_text("/usr/bin/vncviewer")
btn_browse = Gtk.Button(label="…")
btn_browse.connect("clicked", lambda b: self._browse_exe(entry_path))
path_box.pack_start(entry_path, True, True, 0)
path_box.pack_start(btn_browse, False, False, 0)
grid.attach(_lbl(t("settings.tools.lbl_path")), 0, 1, 1, 1)
grid.attach(path_box, 1, 1, 1, 1)
combo_syntax = Gtk.ComboBoxText()
for s in syntaxes:
combo_syntax.append_text(s)
combo_syntax.set_active(0)
combo_syntax.set_hexpand(True)
grid.attach(_lbl(t("settings.tools.lbl_syntax")), 0, 2, 1, 1)
grid.attach(combo_syntax, 1, 2, 1, 1)
area.pack_start(grid, False, False, 0)
area.show_all()
dlg.add_buttons(t("sd.cancel"), Gtk.ResponseType.CANCEL, "OK", Gtk.ResponseType.OK)
if dlg.run() == Gtk.ResponseType.OK:
label = entry_label.get_text().strip()
path = entry_path.get_text().strip()
syntax = combo_syntax.get_active_text() or syntaxes[0]
if label and path:
store.append([label, path, syntax])
dlg.destroy()
def _rimuovi_tool(self, view: Gtk.TreeView, store: Gtk.ListStore):
sel = view.get_selection()
model, it = sel.get_selected()
if it:
store.remove(it)
def _browse_exe(self, entry: Gtk.Entry):
dlg = Gtk.FileChooserDialog(
title=t("settings.tools.browse"),
transient_for=self,
action=Gtk.FileChooserAction.OPEN
)
dlg.add_buttons(t("sd.cancel"), Gtk.ResponseType.CANCEL, "OK", Gtk.ResponseType.OK)
dlg.set_current_folder("/usr/bin")
if dlg.run() == Gtk.ResponseType.OK:
entry.set_text(dlg.get_filename())
dlg.destroy()
# ------------------------------------------------------------------
# Tab Scorciatoie
# ------------------------------------------------------------------
def _build_scorciatoie(self) -> Gtk.Widget:
grid = self._make_grid()
self._shortcut_entries: dict[str, Gtk.Entry] = {}
row = 0
labels = {
"new_terminal": "settings.shortcuts.new_terminal",
"close_tab": "settings.shortcuts.close_tab",
"prev_tab": "settings.shortcuts.prev_tab",
"next_tab": "settings.shortcuts.next_tab",
"new_session": "settings.shortcuts.new_session",
"toggle_sidebar": "settings.shortcuts.toggle_sidebar",
"find": "settings.shortcuts.find",
"fullscreen": "settings.shortcuts.fullscreen",
}
for key, t_key in labels.items():
entry = Gtk.Entry()
entry.set_width_chars(20)
self._shortcut_entries[key] = entry
self._form_row(f"{t(t_key)}:", entry, grid, row)
row += 1
note = Gtk.Label(label=t("settings.shortcuts.note"))
note.set_xalign(0.0)
note.get_style_context().add_class("dim-label")
grid.attach(note, 0, row, 2, 1)
sw = Gtk.ScrolledWindow()
sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
sw.add(grid)
return sw
# ------------------------------------------------------------------
# Popola / Salva
# ------------------------------------------------------------------
def _popola(self):
g = self._settings.get("general", {})
self.entry_home.set_text(g.get("home_dir", os.path.expanduser("~")))
# editor
ed = g.get("default_editor", "nano")
child = self.combo_editor.get_child()
if child:
child.set_text(ed)
self.chk_confirm_exit.set_active(g.get("confirm_on_exit", True))
self.chk_restore_sessions.set_active(g.get("restore_sessions_on_start", False))
self.chk_audit_log.set_active(g.get("audit_log_enabled", False))
lang_code = g.get("language", "it")
if lang_code in self._lang_codes:
self.combo_lingua.set_active(self._lang_codes.index(lang_code))
sc = self._settings.get("shortcuts", {})
for key, entry in self._shortcut_entries.items():
entry.set_text(sc.get(key, ""))
ct = self._settings.get("custom_tools", {"vnc": [], "rdp": []})
for store, key in [(self._store_vnc, "vnc"), (self._store_rdp, "rdp")]:
store.clear()
for e in ct.get(key, []):
store.append([e.get("label", ""), e.get("path", ""), e.get("syntax", "")])
# Credenziali
self._cred_store.clear()
for p in self._settings.get("credential_profiles", []):
self._cred_store.append([
p.get("name", ""),
p.get("user", ""),
p.get("domain", ""),
crypto_manager.decrypt_field(p.get("password", "")),
])
@staticmethod
def _set_combo_text(combo: Gtk.ComboBoxText, value: str):
model = combo.get_model()
for i, row in enumerate(model):
if row[0] == value:
combo.set_active(i)
return
def _on_response(self, dialog, response_id):
if response_id == Gtk.ResponseType.OK:
self._salva()
def _salva(self):
s = self._settings
s["general"]["home_dir"] = self.entry_home.get_text().strip()
ed_child = self.combo_editor.get_child()
s["general"]["default_editor"] = ed_child.get_text() if ed_child else "nano"
s["general"]["confirm_on_exit"] = self.chk_confirm_exit.get_active()
s["general"]["audit_log_enabled"] = self.chk_audit_log.get_active()
s["general"]["restore_sessions_on_start"] = self.chk_restore_sessions.get_active()
idx_lang = self.combo_lingua.get_active()
if 0 <= idx_lang < len(self._lang_codes):
lang = self._lang_codes[idx_lang]
s["general"]["language"] = lang
set_lang(lang)
for key, entry in self._shortcut_entries.items():
s["shortcuts"][key] = entry.get_text().strip()
s["custom_tools"] = {
"vnc": [{"label": r[0], "path": r[1], "syntax": r[2]}
for r in self._store_vnc if r[0] and r[1]],
"rdp": [{"label": r[0], "path": r[1], "syntax": r[2]}
for r in self._store_rdp if r[0] and r[1]],
}
# Credenziali
profiles = []
for row in self._cred_store:
profiles.append({
"name": row[0],
"user": row[1],
"domain": row[2],
"password": crypto_manager.encrypt_field(row[3]),
})
s["credential_profiles"] = profiles
config_manager.save_settings(s)