2
# -*- coding: utf-8 -*-
5
# J Phani Mahesh <phanimahesh@gmail.com>
6
# Barneedhar (jokerdino) <barneedhar@ubuntu.com>
7
# Amith KK <amithkumaran@gmail.com>
8
# Georgi Karavasilev <motorslav@gmail.com>
9
# Sam Tran <samvtran@gmail.com>
10
# Sam Hewitt <hewittsamuel@gmail.com>
11
# Angel Araya <al.arayaq@gmail.com>
14
# A One-stop configuration tool for Unity.
18
# This file is a part of Unity Tweak Tool
20
# Unity Tweak Tool is free software; you can redistribute it and/or modify it under
21
# the terms of the GNU General Public License as published by the Free Software
22
# Foundation; version 3.
24
# Unity Tweak Tool is distributed in the hope that it will be useful, but WITHOUT
25
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
26
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
29
# You should have received a copy of the GNU General Public License along with
30
# this program; if not, see <https://www.gnu.org/licenses/gpl-3.0.txt>
34
from gi.repository import Gtk, Gdk
36
from UnityTweakTool.config.ui import ui
37
from . import unitytweakconfig
38
from . import gsettings
39
from .values import values
41
class Unitysettings ():
42
def __init__(self, builder):
45
self.ui['sc_reveal_sensitivity'].add_mark(2.0, Gtk.PositionType.BOTTOM, None)
46
self.ui['sc_launcher_transparency'].add_mark(.666, Gtk.PositionType.BOTTOM, None)
47
self.ui['sc_panel_transparency'].add_mark(.67, Gtk.PositionType.BOTTOM, None)
49
if Gdk.Screen.get_default().get_n_monitors() == 1:
50
dependants = ['l_launcher_visibility',
51
'radio_launcher_visibility_all',
52
'radio_launcher_visibility_primary',
54
'radio_active_monitor',
56
self.ui.unsensitize(dependants)
58
#=====================================================================#
60
#=====================================================================#
62
'''Reads the current config and refreshes the displayed values'''
64
color = gsettings.unityshell.get_string('background-color')
65
if color.endswith('00'):
66
self.ui['radio_launcher_color_cham'].set_active(True)
67
self.ui.unsensitize(['color_launcher_color_cus'])
69
self.ui['radio_launcher_color_cus'].set_active(True)
70
self.ui.sensitize(['color_launcher_color_cus'])
71
valid, gdkcolor = Gdk.Color.parse(color[:-2])
73
self.ui['color_launcher_color_cus'].set_color(gdkcolor)
74
del color, valid, gdkcolor
77
self.ui['sw_show_desktop'].set_active(True if 'unity://desktop-icon' in gsettings.launcher.get_strv('favorites') else False)
79
# ====== Dash Helpers ===== #
81
dependants = ['b_clear_run_history']
82
if gsettings.runner.get_strv('history') == '[]':
83
self.ui.unsensitize(dependants)
84
self.ui['b_clear_run_history'].set_active(False)
86
self.ui.sensitize(dependants)
90
# ====== Panel Helpers ====== #
91
self.ui['sc_panel_transparency'].set_value(gsettings.unityshell.get_double('panel-opacity'))
93
interested_players = gsettings.sound.get_strv('interested-media-players')
94
preferred_players = gsettings.sound.get_strv('preferred-media-players')
96
for player in interested_players:
97
self.ui['cbox_default_player'].append_text(player.capitalize())
98
if preferred_players[0] in interested_players:
99
self.ui['cbox_default_player'].set_active(interested_players.index(preferred_players[0]))
101
# ====== Unity Switcher helpers ====== #
102
# Window Switcher accelerators
103
model = self.ui['list_unity_switcher_windows_accelerators']
105
alt_tab_forward = gsettings.unityshell.get_string('alt-tab-forward')
106
iter_alt_tab_forward = model.get_iter_first()
107
model.set_value(iter_alt_tab_forward, 1, alt_tab_forward)
109
alt_tab_prev = gsettings.unityshell.get_string('alt-tab-prev')
110
iter_alt_tab_prev = model.iter_next(iter_alt_tab_forward)
111
model.set_value(iter_alt_tab_prev, 1, alt_tab_prev)
113
alt_tab_forward_all = gsettings.unityshell.get_string('alt-tab-forward-all')
114
iter_alt_tab_forward_all = model.iter_next(iter_alt_tab_prev)
115
model.set_value(iter_alt_tab_forward_all, 1, alt_tab_forward_all)
117
alt_tab_prev_all = gsettings.unityshell.get_string('alt-tab-prev-all')
118
iter_alt_tab_prev_all = model.iter_next(iter_alt_tab_forward_all)
119
model.set_value(iter_alt_tab_prev_all, 1, alt_tab_prev_all)
121
alt_tab_right = gsettings.unityshell.get_string('alt-tab-right')
122
iter_alt_tab_right = model.iter_next(iter_alt_tab_prev_all)
123
model.set_value(iter_alt_tab_right, 1, alt_tab_right)
125
alt_tab_left = gsettings.unityshell.get_string('alt-tab-left')
126
iter_alt_tab_left = model.iter_next(iter_alt_tab_right)
127
model.set_value(iter_alt_tab_left, 1, alt_tab_left)
129
alt_tab_detail_start = gsettings.unityshell.get_string('alt-tab-detail-start')
130
iter_alt_tab_detail_start = model.iter_next(iter_alt_tab_left)
131
model.set_value(iter_alt_tab_detail_start, 1, alt_tab_detail_start)
133
alt_tab_detail_stop = gsettings.unityshell.get_string('alt-tab-detail-stop')
134
iter_alt_tab_detail_stop = model.iter_next(iter_alt_tab_detail_start)
135
model.set_value(iter_alt_tab_detail_stop, 1, alt_tab_detail_stop)
137
alt_tab_next_window = gsettings.unityshell.get_string('alt-tab-next-window')
138
iter_alt_tab_next_window = model.iter_next(iter_alt_tab_detail_stop)
139
model.set_value(iter_alt_tab_next_window, 1, alt_tab_next_window)
141
alt_tab_prev_window = gsettings.unityshell.get_string('alt-tab-prev-window')
143
iter_alt_tab_prev_window = model.iter_next(iter_alt_tab_next_window)
144
model.set_value(iter_alt_tab_prev_window, 1, alt_tab_prev_window)
148
# Launcher switcher accelerators
149
model = self.ui['list_unity_switcher_launcher_accelerators']
151
launcher_switcher_forward = gsettings.unityshell.get_string('launcher-switcher-forward')
152
iter_launcher_switcher_forward = model.get_iter_first()
153
model.set_value(iter_launcher_switcher_forward, 1, launcher_switcher_forward)
155
launcher_switcher_prev = gsettings.unityshell.get_string('launcher-switcher-prev')
156
iter_launcher_switcher_prev = model.iter_next(iter_launcher_switcher_forward)
157
model.set_value(iter_launcher_switcher_prev, 1, launcher_switcher_prev)
159
del model, launcher_switcher_forward, iter_launcher_switcher_forward, launcher_switcher_prev, iter_launcher_switcher_prev
162
# ====== Unity Webapps helpers ===== #
163
# Preauthorized domains
164
self.ui['check_preauthorized_amazon'].set_active(True if 'amazon.ca' in gsettings.webapps.get_strv('preauthorized-domains') else False)
165
self.ui['check_preauthorized_ubuntuone'].set_active(True if 'one.ubuntu.com' in gsettings.webapps.get_strv('preauthorized-domains') else False)
167
# ====== Unity additional helpers ======= #
168
model = self.ui['list_unity_additional_accelerators']
170
show_hud = gsettings.unityshell.get_string('show-hud')
171
iter_show_hud = model.get_iter_first()
172
model.set_value(iter_show_hud, 1, show_hud)
174
show_launcher = gsettings.unityshell.get_string('show-launcher')
175
iter_show_launcher = model.iter_next(iter_show_hud)
176
model.set_value(iter_show_launcher, 1, show_launcher)
178
execute_command = gsettings.unityshell.get_string('execute-command')
179
iter_execute_command = model.iter_next(iter_show_launcher)
180
model.set_value(iter_execute_command, 1, execute_command)
182
keyboard_focus = gsettings.unityshell.get_string('keyboard-focus')
183
iter_keyboard_focus = model.iter_next(iter_execute_command)
184
model.set_value(iter_keyboard_focus, 1, keyboard_focus)
186
panel_first_menu = gsettings.unityshell.get_string('panel-first-menu')
187
iter_panel_first_menu = model.iter_next(iter_keyboard_focus)
188
model.set_value(iter_panel_first_menu, 1, panel_first_menu)
190
del model, show_hud, iter_show_hud, show_launcher, iter_show_launcher, execute_command, iter_execute_command, keyboard_focus, iter_keyboard_focus, panel_first_menu, iter_panel_first_menu
193
# ===== BEGIN: Unity settings =====
194
# ----- BEGIN: Launcher -----
196
def on_sc_reveal_sensitivity_value_changed(self, widget, udata = None):
197
value = self.ui['sc_reveal_sensitivity'].get_value()
198
gsettings.unityshell.set_double('edge-responsiveness', value)
200
def on_sc_launcher_transparency_value_changed(self, widget, udata = None):
201
opacity = self.ui['sc_launcher_transparency'].get_value()
202
gsettings.unityshell.set_double('launcher-opacity', opacity)
203
def on_radio_launcher_color_cus_toggled(self, widget, udata = None):
204
dependants = ['color_launcher_color_cus']
205
color = self.ui['color_launcher_color_cus'].get_color()
206
colorhash = gsettings.color_to_hash(color)
207
if self.ui['radio_launcher_color_cus'].get_active():
208
self.ui.sensitize(dependants)
209
gsettings.unityshell.set_string('background-color', colorhash)
211
self.ui.unsensitize(dependants)
212
gsettings.unityshell.set_string('background-color', colorhash[:-2]+'00')
215
def on_sw_show_desktop_active_notify(self, widget, udata = None):
216
fav = gsettings.launcher.get_strv('favorites')
217
desktop = 'unity://desktop-icon'
218
if self.ui['sw_show_desktop'].get_active():
219
if desktop not in fav:
221
gsettings.launcher.set_strv('favorites', fav)
225
gsettings.launcher.set_strv('favorites', fav)
228
def on_b_unity_launcher_reset_clicked(self, widget):
229
gsettings.unityshell.reset('background-color')
230
gsettings.unityshell.reset('panel-opacity')
233
fav = gsettings.launcher.get_strv('favorites')
234
desktop = 'unity://desktop-icon'
237
gsettings.launcher.set_strv('favorites', fav)
243
# ----- END: Launcher -----
245
# ----- BEGIN: Dash -----
246
def on_b_clear_run_history_clicked(self, widget):
247
gsettings.runner.reset('history')
248
#----- END: Dash -------
250
#----- BEGIN: Panel -----
251
def on_sc_panel_transparency_value_changed(self, widget, udata = None):
252
panel_transparency = widget.get_value()
253
gsettings.unityshell.set_double('panel-opacity', panel_transparency)
254
def on_cbox_default_player_changed(self, widget, udata = None):
255
combobox_text = self.ui['cbox_default_player'].get_active_text()
256
gsettings.sound.set_strv('preferred-media-players', [combobox_text.lower()])
258
def on_b_unity_panel_reset_clicked(self, widget):
259
gsettings.sound.reset('preferred-media-players')
263
#----- END: Panel -----
265
#----- BEGIN: Switcher -----
266
# keyboard widgets in unity-windows-switcher
268
def on_craccel_unity_switcher_windows_accel_edited(self, craccel, path, key, mods, hwcode, model = None):
269
model = self.ui['list_unity_switcher_windows_accelerators']
270
accel = Gtk.accelerator_name(key, mods)
271
titer = model.get_iter(path)
272
model.set_value(titer, 1, accel)
273
# Python has no switch statement, right?
276
gsettings.unityshell.set_string('alt-tab-forward', accel)
278
gsettings.unityshell.set_string('alt-tab-prev', accel)
280
gsettings.unityshell.set_string('alt-tab-forward-all', accel)
282
gsettings.unityshell.set_string('alt-tab-prev-all', accel)
284
gsettings.unityshell.set_string('alt-tab-right', accel)
286
gsettings.unityshell.set_string('alt-tab-left', accel)
288
gsettings.unityshell.set_string('alt-tab-detail-start', accel)
290
gsettings.unityshell.set_string('alt-tab-detail-stop', accel)
292
gsettings.unityshell.set_string('alt-tab-next-window', accel)
294
gsettings.unityshell.set_string('alt-tab-prev-window', accel)
296
def on_craccel_unity_switcher_windows_accel_cleared(self, craccel, path, model = None):
297
model = self.ui['list_unity_switcher_windows_accelerators']
298
titer = model.get_iter(path)
299
model.set_value(titer, 1, 'Disabled')
301
gsettings.unityshell.set_string('alt-tab-forward', 'Disabled')
303
gsettings.unityshell.set_string('alt-tab-prev', 'Disabled')
305
gsettings.unityshell.set_string('alt-tab-forward-all', 'Disabled')
307
gsettings.unityshell.set_string('alt-tab-prev-all', 'Disabled')
309
gsettings.unityshell.set_string('alt-tab-right', 'Disabled')
311
gsettings.unityshell.set_string('alt-tab-left', 'Disabled')
313
gsettings.unityshell.set_string('alt-tab-detail-start', 'Disabled')
315
gsettings.unityshell.set_string('alt-tab-detail-stop', 'Disabled')
317
gsettings.unityshell.set_string('alt-tab-next-window', 'Disabled')
319
gsettings.unityshell.set_string('alt-tab-prev-window', 'Disabled')
321
# keyboard widgets in unity-launcher-switcher
323
def on_craccel_unity_switcher_launcher_accel_edited(self, craccel, path, key, mods, hwcode, model = None):
324
model = self.ui['list_unity_switcher_launcher_accelerators']
325
accel = Gtk.accelerator_name(key, mods)
326
titer = model.get_iter(path)
327
model.set_value(titer, 1, accel)
328
# Python has no switch statement, right?
331
gsettings.unityshell.set_string('launcher-switcher-forward', accel)
333
gsettings.unityshell.set_string('launcher-switcher-prev', accel)
335
def on_craccel_unity_switcher_launcher_accel_cleared(self, craccel, path, model = None):
336
model = self.ui['list_unity_switcher_launcher_accelerators']
337
titer = model.get_iter(path)
338
model.set_value(titer, 1, 'Disabled')
340
gsettings.unityshell.set_string('launcher-switcher-forward', 'Disabled')
342
gsettings.unityshell.set_string('launcher-switcher-prev', 'Disabled')
344
def on_b_unity_switcher_reset_clicked(self, widget):
345
gsettings.unityshell.reset('alt-tab-forward')
346
gsettings.unityshell.reset('alt-tab-prev')
347
gsettings.unityshell.reset('alt-tab-forward-all')
348
gsettings.unityshell.reset('alt-tab-prev-all')
349
gsettings.unityshell.reset('alt-tab-right')
350
gsettings.unityshell.reset('alt-tab-left')
351
gsettings.unityshell.reset('alt-tab-detail-start')
352
gsettings.unityshell.reset('alt-tab-detail-stop')
353
gsettings.unityshell.reset('alt-tab-next-window')
354
gsettings.unityshell.reset('alt-tab-prev-window')
355
gsettings.unityshell.reset('launcher-switcher-forward')
356
gsettings.unityshell.reset('launcher-switcher-prev')
359
#----- END: Switch -----
361
#----- BEGIN: Webapps -----
362
# Preauthorized domains - Amazon
363
def on_check_preauthorized_amazon_toggled(self, widget):
364
if self.ui['check_preauthorized_amazon'].get_active() == False:
365
preauthorized = gsettings.webapps.get_strv('preauthorized-domains')
366
amazonca = 'amazon.ca'
367
if amazonca in preauthorized:
368
amazonlist = ['amazon.ca', 'amazon.cn', 'amazon.com', 'amazon.co.uk', 'amazon.de', 'amazon.es', 'amazon.fr', 'amazon.it', 'www.amazon.ca', 'www.amazon.cn', 'www.amazon.com', 'www.amazon.co.uk', 'www.amazon.de', 'www.amazon.es', 'www.amazon.fr', 'www.amazon.it']
369
for amazon in amazonlist:
370
preauthorized.remove(amazon)
371
gsettings.webapps.set_strv('preauthorized-domains', preauthorized)
372
elif amazonca not in preauthorized:
375
preauthorized = gsettings.webapps.get_strv('preauthorized-domains')
376
amazonca = 'amazon.ca'
377
if amazonca not in preauthorized:
378
amazonlist = ['amazon.ca', 'amazon.cn', 'amazon.com', 'amazon.co.uk', 'amazon.de', 'amazon.es', 'amazon.fr', 'amazon.it', 'www.amazon.ca', 'www.amazon.cn', 'www.amazon.com', 'www.amazon.co.uk', 'www.amazon.de', 'www.amazon.es', 'www.amazon.fr', 'www.amazon.it']
379
for amazon in amazonlist:
380
preauthorized.append(amazon)
381
gsettings.webapps.set_strv('preauthorized-domains', preauthorized)
382
elif amazonca in preauthorized:
385
# Preauthorized domains - Ubuntu One
386
def on_check_preauthorized_ubuntuone_toggled(self, widget):
387
if self.ui['check_preauthorized_ubuntuone'].get_active() == False:
388
preauthorized = gsettings.webapps.get_strv('preauthorized-domains')
389
ubuntuone = 'one.ubuntu.com'
390
if ubuntuone in preauthorized:
391
preauthorized.remove(ubuntuone)
392
gsettings.webapps.set_strv('preauthorized-domains', preauthorized)
393
elif ubuntuone not in preauthorized:
396
preauthorized = gsettings.webapps.get_strv('preauthorized-domains')
397
ubuntuone = 'one.ubuntu.com'
398
if ubuntuone not in preauthorized:
399
preauthorized.append(ubuntuone)
400
gsettings.webapps.set_strv('preauthorized-domains', preauthorized)
401
elif ubuntuone in preauthorized:
405
def on_b_unity_webapps_reset_clicked(self, widget):
406
gsettings.webapps.reset('preauthorized-domains')
409
#----- END: Webapps -----
411
#----- BEGIN: Additional -----
412
# keyboard widgets in unity-additional
414
def on_craccel_unity_additional_accel_edited(self, craccel, path, key, mods, hwcode, model = None):
415
# Glade has a habit of swapping arguments. beware.
416
model = self.ui['list_unity_additional_accelerators']
417
accel = Gtk.accelerator_name(key, mods)
418
titer = model.get_iter(path)
419
model.set_value(titer, 1, accel)
421
# Python has no switch statement, right?
423
# You are right, jokerdino. Python has no switch statement.
424
# That is against OOP principles. -jpm
427
gsettings.unityshell.set_string('show-hud', accel)
429
gsettings.unityshell.set_string('show-launcher', accel)
431
gsettings.unityshell.set_string('execute-command', accel)
433
gsettings.unityshell.set_string('keyboard-focus', accel)
435
gsettings.unityshell.set_string('panel-first-menu', accel)
437
def on_craccel_unity_additional_accel_cleared(self, craccel, path, model = None):
438
model = self.ui['list_unity_additional_accelerators']
439
titer = model.get_iter(path)
440
model.set_value(titer, 1, 'Disabled')
442
gsettings.unityshell.set_string('show-hud', 'Disabled')
444
gsettings.unityshell.set_string('show-launcher', 'Disabled')
446
gsettings.unityshell.set_string('execute-command', 'Disabled')
448
gsettings.unityshell.set_string('keyboard-focus', 'Disabled')
450
gsettings.unityshell.set_string('panel-first-menu', 'Disabled')
452
def on_b_unity_additional_reset_clicked(self, widget):
453
gsettings.unityshell.reset('shortcut-overlay')
454
gsettings.unityshell.reset('show-hud')
455
gsettings.unityshell.reset('show-launcher')
456
gsettings.unityshell.reset('execute-command')
457
gsettings.unityshell.reset('keyboard-focus')
458
gsettings.unityshell.reset('panel-first-menu')
461
#----- END: Additional -----