forked from mijorus/gearlever
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreferences.py
133 lines (100 loc) · 5.27 KB
/
preferences.py
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
import gi
import logging
from .models.Models import InternalError
from .lib.utils import get_gsettings
from .State import state
gi.require_version('Gtk', '4.0')
from gi.repository import Adw, Gtk, Gio, GLib # noqa
class Preferences(Adw.PreferencesWindow):
def __init__(self, **kwargs) :
super().__init__(**kwargs)
self.settings = get_gsettings()
# page 1
page1 = Adw.PreferencesPage()
# general group
general_preference_group = Adw.PreferencesGroup(name=_('General'))
# default_location
self.default_location_row = Adw.ActionRow(
title=_('AppImage default location'),
subtitle=self.settings.get_string('appimages-default-folder')
)
pick_default_localtion_btn = Gtk.Button(icon_name='gearlever-file-manager-symbolic', valign=Gtk.Align.CENTER)
pick_default_localtion_btn.connect('clicked', self.on_default_localtion_btn_clicked)
self.default_location_row.add_suffix(pick_default_localtion_btn)
exec_as_name_switch = self.create_boolean_settings_entry(
_('Use executable name for integrated terminal apps'),
'exec-as-name-for-terminal-apps',
_('If enabled, apps that run in the terminal are renamed as their executable.\nYou would need to add the aforementioned folder to your $PATH manually.\n\nFor example, "golang_x86_64.appimage" will be saved as "go"')
)
files_outside_folder_switch = self.create_boolean_settings_entry(
_('Show integrated AppImages outside the default folder'),
'manage-files-outside-default-folder',
_('List AppImages that have been integrated into the system menu but are located outside the default folder')
)
general_preference_group.add(self.default_location_row)
general_preference_group.add(exec_as_name_switch)
general_preference_group.add(files_outside_folder_switch)
# move appimage on integration
move_appimages_group = Adw.PreferencesGroup(name=_('File management'), title=_('File management'))
move_appimages_row = Adw.ActionRow(
title=_('Move AppImages into the destination folder'),
subtitle=(_('Reduce disk usage'))
)
copy_appimages_row = Adw.ActionRow(
title=_('Clone AppImages into the destination folder'),
subtitle=(_('Keep the original file and create a copy in the destination folder'))
)
self.move_to_destination_check = Gtk.CheckButton(
valign=Gtk.Align.CENTER,
active=self.settings.get_boolean('move-appimage-on-integration')
)
self.copy_to_destination_check = Gtk.CheckButton(
valign=Gtk.Align.CENTER,
group=self.move_to_destination_check,
active=(not self.settings.get_boolean('move-appimage-on-integration'))
)
move_appimages_row.add_prefix(self.move_to_destination_check)
copy_appimages_row.add_prefix(self.copy_to_destination_check)
move_appimages_group.add(move_appimages_row)
move_appimages_group.add(copy_appimages_row)
self.move_to_destination_check.connect('toggled', self.on_move_appimages_setting_changed)
self.copy_to_destination_check.connect('toggled', self.on_move_appimages_setting_changed)
# debugging group
debug_group = Adw.PreferencesGroup(name=_('Debugging'), title=_('Debugging'))
debug_row = self.create_boolean_settings_entry(
_('Enable debug logs'),
'debug-logs',
_('Increases log verbosity, occupying more disk space and potentially impacting performance.\nRequires a restart.')
)
debug_group.add(debug_row)
page1.add(general_preference_group)
page1.add(move_appimages_group)
page1.add(debug_group)
self.add(page1)
def on_select_default_location_response(self, dialog, result):
try:
selected_file = dialog.select_folder_finish(result)
except Exception as e:
logging.error(str(e))
return
if selected_file.query_exists() and selected_file.get_path().startswith(GLib.get_home_dir()):
self.settings.set_string('appimages-default-folder', selected_file.get_path())
self.default_location_row.set_subtitle(selected_file.get_path())
state.set__('appimages-default-folder', selected_file.get_path())
else:
raise InternalError(_('The folder must be in your home directory'))
def on_default_localtion_btn_clicked(self, widget):
dialog = Gtk.FileDialog(title=_('Select a folder'), modal=True)
dialog.select_folder(
parent=self,
cancellable=None,
callback=self.on_select_default_location_response
)
def on_move_appimages_setting_changed(self, widget):
self.settings.set_boolean('move-appimage-on-integration', self.move_to_destination_check.get_active())
def create_boolean_settings_entry(self, label: str, key: str, subtitle: str = None) -> Adw.ActionRow:
row = Adw.ActionRow(title=label, subtitle=subtitle)
switch = Gtk.Switch(valign=Gtk.Align.CENTER)
self.settings.bind(key, switch, 'active', Gio.SettingsBindFlags.DEFAULT)
row.add_suffix(switch)
return row