global_settings.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. #!/usr/bin/python3
  2. #
  3. # The Qubes OS Project, http://www.qubes-os.org
  4. #
  5. # Copyright (C) 2012 Agnieszka Kostrzewa <agnieszka.kostrzewa@gmail.com>
  6. # Copyright (C) 2012 Marek Marczykowski <marmarek@mimuw.edu.pl>
  7. #
  8. # This program is free software; you can redistribute it and/or
  9. # modify it under the terms of the GNU General Public License
  10. # as published by the Free Software Foundation; either version 2
  11. # of the License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Lesser General Public License along
  19. # with this program; if not, see <http://www.gnu.org/licenses/>.
  20. #
  21. #
  22. import os
  23. import subprocess
  24. from PyQt5 import QtWidgets, QtCore, QtGui # pylint: disable=import-error
  25. from qubesadmin.utils import parse_size
  26. from qubesadmin import exc
  27. from . import ui_globalsettingsdlg # pylint: disable=no-name-in-module
  28. from . import utils
  29. from configparser import ConfigParser
  30. qmemman_config_path = '/etc/qubes/qmemman.conf'
  31. def _run_qrexec_repo(service, arg=''):
  32. # Set default locale to C in order to prevent error msg
  33. # in subprocess call related to falling back to C locale
  34. env = os.environ.copy()
  35. env['LC_ALL'] = 'C'
  36. # Fake up a "qrexec call" to dom0 because dom0 can't qrexec to itself yet
  37. cmd = '/etc/qubes-rpc/' + service
  38. p = subprocess.run(
  39. ['sudo', cmd, arg],
  40. stdout=subprocess.PIPE,
  41. stderr=subprocess.PIPE,
  42. check=False,
  43. env=env
  44. )
  45. if p.stderr:
  46. raise exc.QubesException(
  47. QtCore.QCoreApplication.translate(
  48. "GlobalSettings", 'qrexec call stderr was not empty'),
  49. {'stderr': p.stderr.decode('utf-8')})
  50. if p.returncode != 0:
  51. raise exc.QubesException(
  52. QtCore.QCoreApplication.translate(
  53. "GlobalSettings",
  54. 'qrexec call exited with non-zero return code'),
  55. {'returncode': p.returncode})
  56. return p.stdout.decode('utf-8')
  57. class GlobalSettingsWindow(ui_globalsettingsdlg.Ui_GlobalSettings,
  58. QtWidgets.QDialog):
  59. def __init__(self, app, qubes_app, parent=None):
  60. super().__init__(parent)
  61. self.app = app
  62. self.qubes_app = qubes_app
  63. self.vm = self.qubes_app.domains[self.qubes_app.local_name]
  64. self.setupUi(self)
  65. self.buttonBox.accepted.connect(self.save_and_apply)
  66. self.buttonBox.rejected.connect(self.reject)
  67. self.__init_system_defaults__()
  68. self.__init_kernel_defaults__()
  69. self.__init_mem_defaults__()
  70. self.__init_updates__()
  71. self.__init_gui_defaults()
  72. self.errors = []
  73. def setup_application(self):
  74. self.app.setApplicationName(self.tr("Qubes Global Settings"))
  75. self.app.setWindowIcon(QtGui.QIcon.fromTheme("qubes-manager"))
  76. def setup_widget_with_vms(self, widget, filter_function,
  77. allow_none, holder, property_name):
  78. try:
  79. utils.initialize_widget_with_vms(
  80. widget=widget,
  81. qubes_app=self.qubes_app,
  82. filter_function=filter_function,
  83. allow_none=allow_none,
  84. holder=holder,
  85. property_name=property_name
  86. )
  87. except exc.QubesDaemonAccessError:
  88. widget.clear()
  89. widget.setCurrentText("unavailable")
  90. widget.setEnabled(False)
  91. def __init_system_defaults__(self):
  92. # set up updatevm choice
  93. self.setup_widget_with_vms(
  94. widget=self.update_vm_combo,
  95. filter_function=(lambda vm: vm.klass != 'TemplateVM'),
  96. allow_none=True,
  97. holder=self.qubes_app,
  98. property_name="updatevm")
  99. # set up clockvm choice
  100. self.setup_widget_with_vms(
  101. widget=self.clock_vm_combo,
  102. filter_function=(lambda vm: vm.klass != 'TemplateVM'),
  103. allow_none=True,
  104. holder=self.qubes_app,
  105. property_name="clockvm")
  106. # set up default netvm
  107. self.setup_widget_with_vms(
  108. widget=self.default_netvm_combo,
  109. filter_function=(lambda vm: getattr(
  110. vm, 'provides_network', False)),
  111. allow_none=True,
  112. holder=self.qubes_app,
  113. property_name="default_netvm")
  114. # default template
  115. self.setup_widget_with_vms(
  116. widget=self.default_template_combo,
  117. filter_function=(lambda vm: vm.klass == 'TemplateVM'),
  118. allow_none=True,
  119. holder=self.qubes_app,
  120. property_name="default_template"
  121. )
  122. # default dispvm
  123. self.setup_widget_with_vms(
  124. widget=self.default_dispvm_combo,
  125. filter_function=(lambda vm: getattr(
  126. vm, 'template_for_dispvms', False)),
  127. allow_none=True,
  128. holder=self.qubes_app,
  129. property_name="default_dispvm"
  130. )
  131. def __apply_system_defaults__(self):
  132. # updatevm
  133. if utils.did_widget_selection_change(self.update_vm_combo):
  134. try:
  135. self.qubes_app.updatevm = self.update_vm_combo.currentData()
  136. except exc.QubesException as ex:
  137. self.errors.append(
  138. "Failed to set UpdateVM due to {}".format(str(ex)))
  139. # clockvm
  140. if utils.did_widget_selection_change(self.clock_vm_combo):
  141. try:
  142. self.qubes_app.clockvm = self.clock_vm_combo.currentData()
  143. except exc.QubesException as ex:
  144. self.errors.append(
  145. "Failed to set ClockVM due to {}".format(str(ex)))
  146. # default netvm
  147. if utils.did_widget_selection_change(self.default_netvm_combo):
  148. try:
  149. self.qubes_app.default_netvm = \
  150. self.default_netvm_combo.currentData()
  151. except exc.QubesException as ex:
  152. self.errors.append(
  153. "Failed to set Default NetVM due to {}".format(str(ex)))
  154. # default template
  155. if utils.did_widget_selection_change(self.default_template_combo):
  156. try:
  157. self.qubes_app.default_template = \
  158. self.default_template_combo.currentData()
  159. except exc.QubesException as ex:
  160. self.errors.append(
  161. "Failed to set Default Template due to {}".format(str(ex)))
  162. # default_dispvm
  163. if utils.did_widget_selection_change(self.default_dispvm_combo):
  164. try:
  165. self.qubes_app.default_dispvm = \
  166. self.default_dispvm_combo.currentData()
  167. except exc.QubesException as ex:
  168. self.errors.append(
  169. "Failed to set Default DispVM due to {}".format(str(ex)))
  170. def __init_kernel_defaults__(self):
  171. try:
  172. utils.initialize_widget_with_kernels(
  173. widget=self.default_kernel_combo,
  174. qubes_app=self.qubes_app,
  175. allow_none=True,
  176. holder=self.qubes_app,
  177. property_name='default_kernel')
  178. except exc.QubesDaemonAccessError:
  179. self.default_kernel_combo.clear()
  180. self.default_kernel_combo.setCurrentText("unavailable")
  181. self.default_kernel_combo.setEnabled(False)
  182. def __apply_kernel_defaults__(self):
  183. if utils.did_widget_selection_change(self.default_kernel_combo):
  184. try:
  185. self.qubes_app.default_kernel = \
  186. self.default_kernel_combo.currentData()
  187. except exc.QubesException as ex:
  188. self.errors.append(
  189. "Failed to set Default Kernel due to {}".format(str(ex)))
  190. def __init_gui_defaults(self):
  191. utils.initialize_widget(
  192. widget=self.allow_fullscreen,
  193. choices=[
  194. ('default (disallow)', None),
  195. ('allow', True),
  196. ('disallow', False)
  197. ],
  198. selected_value=utils.get_boolean_feature(
  199. self.vm,
  200. 'gui-default-allow-fullscreen'))
  201. utils.initialize_widget(
  202. widget=self.allow_utf8,
  203. choices=[
  204. ('default (disallow)', None),
  205. ('allow', True),
  206. ('disallow', False)
  207. ],
  208. selected_value=utils.get_boolean_feature(
  209. self.vm,
  210. 'gui-default-allow-utf8-titles'))
  211. utils.initialize_widget(
  212. widget=self.trayicon,
  213. choices=[
  214. ('default (thin border)', None),
  215. ('full background', 'bg'),
  216. ('thin border', 'border1'),
  217. ('thick border', 'border2'),
  218. ('tinted icon', 'tint'),
  219. ('tinted icon with modified white', 'tint+whitehack'),
  220. ('tinted icon with 50% saturation', 'tint+saturation50')
  221. ],
  222. selected_value=utils.get_feature(
  223. self.vm, 'gui-default-trayicon-mode', None))
  224. utils.initialize_widget(
  225. widget=self.securecopy,
  226. choices=[
  227. ('default (Ctrl+Shift+C)', None),
  228. ('Ctrl+Shift+C', 'Ctrl-Shift-c'),
  229. ('Ctrl+Win+C', 'Ctrl-Mod4-c'),
  230. ],
  231. selected_value=utils.get_feature(
  232. self.vm, 'gui-default-secure-copy-sequence', None))
  233. utils.initialize_widget(
  234. widget=self.securepaste,
  235. choices=[
  236. ('default (Ctrl+Shift+V)', None),
  237. ('Ctrl+Shift+V', 'Ctrl-Shift-V'),
  238. ('Ctrl+Win+V', 'Ctrl-Mod4-v'),
  239. ('Ctrl+Insert', 'Ctrl-Ins'),
  240. ],
  241. selected_value=utils.get_feature(
  242. self.vm, 'gui-default-secure-paste-sequence', None))
  243. def __apply_feature_change(self, widget, feature):
  244. if utils.did_widget_selection_change(widget):
  245. if widget.currentData() is None:
  246. try:
  247. del self.vm.features[feature]
  248. except exc.QubesDaemonAccessError:
  249. self.errors.append(
  250. "Failed to set {} due to insufficient "
  251. "permissions".format(feature))
  252. else:
  253. try:
  254. self.vm.features[feature] = widget.currentData()
  255. except exc.QubesDaemonAccessError:
  256. self.errors.append(
  257. "Failed to set {} due to insufficient "
  258. "permissions".format(feature))
  259. def __apply_gui_defaults(self):
  260. self.__apply_feature_change(widget=self.allow_fullscreen,
  261. feature='gui-default-allow-fullscreen')
  262. self.__apply_feature_change(widget=self.allow_utf8,
  263. feature='gui-default-allow-utf8-titles')
  264. self.__apply_feature_change(widget=self.trayicon,
  265. feature='gui-default-trayicon-mode')
  266. self.__apply_feature_change(widget=self.securecopy,
  267. feature='gui-default-secure-copy-sequence')
  268. self.__apply_feature_change(widget=self.securepaste,
  269. feature='gui-default-secure-paste-sequence')
  270. def __init_mem_defaults__(self):
  271. # qmemman settings
  272. try:
  273. self.qmemman_config = ConfigParser()
  274. self.vm_min_mem_val = '200MiB' # str(qmemman_algo.MIN_PREFMEM)
  275. # str(qmemman_algo.DOM0_MEM_BOOST)
  276. self.dom0_mem_boost_val = '350MiB'
  277. self.qmemman_config.read(qmemman_config_path)
  278. if self.qmemman_config.has_section('global'):
  279. self.vm_min_mem_val = \
  280. self.qmemman_config.get('global', 'vm-min-mem')
  281. self.dom0_mem_boost_val = \
  282. self.qmemman_config.get('global', 'dom0-mem-boost')
  283. self.vm_min_mem_val = parse_size(self.vm_min_mem_val)
  284. self.dom0_mem_boost_val = parse_size(self.dom0_mem_boost_val)
  285. self.min_vm_mem.setValue(
  286. int(self.vm_min_mem_val / 1024 / 1024))
  287. self.dom0_mem_boost.setValue(
  288. int(self.dom0_mem_boost_val / 1024 / 1024))
  289. except exc.QubesException:
  290. self.min_vm_mem.setEnabled(False)
  291. self.dom0_mem_boost.setEnabled(False)
  292. def __apply_mem_defaults__(self):
  293. if not self.min_vm_mem.isEnabled() or \
  294. not self.dom0_mem_boost.isEnabled():
  295. return
  296. # qmemman settings
  297. current_min_vm_mem = self.min_vm_mem.value()
  298. current_dom0_mem_boost = self.dom0_mem_boost.value()
  299. if current_min_vm_mem * 1024 * 1024 != self.vm_min_mem_val or \
  300. current_dom0_mem_boost * 1024 * 1024 != self.dom0_mem_boost_val:
  301. current_min_vm_mem = str(current_min_vm_mem) + 'MiB'
  302. current_dom0_mem_boost = str(current_dom0_mem_boost) + 'MiB'
  303. if not self.qmemman_config.has_section('global'):
  304. # add the whole section
  305. self.qmemman_config.add_section('global')
  306. self.qmemman_config.set(
  307. 'global', 'vm-min-mem', current_min_vm_mem)
  308. self.qmemman_config.set(
  309. 'global', 'dom0-mem-boost', current_dom0_mem_boost)
  310. self.qmemman_config.set(
  311. 'global', 'cache-margin-factor', str(1.3))
  312. # removed qmemman_algo.CACHE_FACTOR
  313. try:
  314. qmemman_config_file = open(qmemman_config_path, 'a')
  315. self.qmemman_config.write(qmemman_config_file)
  316. qmemman_config_file.close()
  317. except Exception as ex: # pylint: disable=broad-except
  318. self.errors.append(
  319. "Failed to set memory settings due to {}".format(
  320. str(ex)))
  321. else:
  322. # If there already is a 'global' section, we don't use
  323. # SafeConfigParser.write() - it would get rid of
  324. # all the comments...
  325. lines_to_add = {}
  326. lines_to_add['vm-min-mem'] = \
  327. "vm-min-mem = " + current_min_vm_mem + "\n"
  328. lines_to_add['dom0-mem-boost'] = \
  329. "dom0-mem-boost = " + current_dom0_mem_boost + "\n"
  330. config_lines = []
  331. try:
  332. qmemman_config_file = open(qmemman_config_path, 'r')
  333. except Exception as ex: # pylint: disable=broad-except
  334. self.errors.append(
  335. "Failed to set memory settings due to {}".format(
  336. str(ex)))
  337. return
  338. for line in qmemman_config_file:
  339. if line.strip().startswith('vm-min-mem'):
  340. config_lines.append(lines_to_add['vm-min-mem'])
  341. del lines_to_add['vm-min-mem']
  342. elif line.strip().startswith('dom0-mem-boost'):
  343. config_lines.append(lines_to_add['dom0-mem-boost'])
  344. del lines_to_add['dom0-mem-boost']
  345. else:
  346. config_lines.append(line)
  347. qmemman_config_file.close()
  348. for line in lines_to_add:
  349. config_lines.append(line)
  350. try:
  351. qmemman_config_file = open(qmemman_config_path, 'w')
  352. qmemman_config_file.writelines(config_lines)
  353. qmemman_config_file.close()
  354. except Exception as ex: # pylint: disable=broad-except
  355. self.errors.append(
  356. "Failed to set memory settings due to {}".format(
  357. str(ex)))
  358. return
  359. def __init_updates__(self):
  360. self.updates_dom0_val = bool(
  361. utils.get_feature(self.qubes_app.domains['dom0'],
  362. 'service.qubes-update-check',
  363. True))
  364. self.updates_dom0.setChecked(self.updates_dom0_val)
  365. try:
  366. self.updates_vm.setChecked(self.qubes_app.check_updates_vm)
  367. except exc.QubesDaemonAccessError:
  368. self.updates_vm.isEnabled(False)
  369. self.enable_updates_all.clicked.connect(self.__enable_updates_all)
  370. self.disable_updates_all.clicked.connect(self.__disable_updates_all)
  371. self.repos = repos = dict()
  372. try:
  373. for i in _run_qrexec_repo('qubes.repos.List').split('\n'):
  374. lst = i.split('\0')
  375. # Keyed by repo name
  376. dct = repos[lst[0]] = dict()
  377. dct['prettyname'] = lst[1]
  378. dct['enabled'] = lst[2] == 'enabled'
  379. except exc.QubesException:
  380. self.dom0_updates_repo.setEnabled(False)
  381. self.itl_tmpl_updates_repo.setEnabled(False)
  382. self.comm_tmpl_updates_repo.setEnabled(False)
  383. if repos['qubes-dom0-unstable']['enabled']:
  384. self.dom0_updates_repo.setCurrentIndex(3)
  385. elif repos['qubes-dom0-current-testing']['enabled']:
  386. self.dom0_updates_repo.setCurrentIndex(2)
  387. elif repos['qubes-dom0-security-testing']['enabled']:
  388. self.dom0_updates_repo.setCurrentIndex(1)
  389. elif repos['qubes-dom0-current']['enabled']:
  390. self.dom0_updates_repo.setCurrentIndex(0)
  391. else:
  392. raise Exception(
  393. self.tr('Cannot detect enabled dom0 update repositories'))
  394. if repos['qubes-templates-itl-testing']['enabled']:
  395. self.itl_tmpl_updates_repo.setCurrentIndex(1)
  396. elif repos['qubes-templates-itl']['enabled']:
  397. self.itl_tmpl_updates_repo.setCurrentIndex(0)
  398. else:
  399. raise Exception(self.tr('Cannot detect enabled ITL template update '
  400. 'repositories'))
  401. if repos['qubes-templates-community-testing']['enabled']:
  402. self.comm_tmpl_updates_repo.setCurrentIndex(2)
  403. elif repos['qubes-templates-community']['enabled']:
  404. self.comm_tmpl_updates_repo.setCurrentIndex(1)
  405. else:
  406. self.comm_tmpl_updates_repo.setCurrentIndex(0)
  407. def __enable_updates_all(self):
  408. reply = QtWidgets.QMessageBox.question(
  409. self, self.tr("Change state of all qubes"),
  410. self.tr("Are you sure you want to set all qubes to check "
  411. "for updates?"),
  412. QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.Cancel)
  413. if reply == QtWidgets.QMessageBox.Cancel:
  414. return
  415. self.__set_updates_all(True)
  416. def __disable_updates_all(self):
  417. reply = QtWidgets.QMessageBox.question(
  418. self, self.tr("Change state of all qubes"),
  419. self.tr("Are you sure you want to set all qubes to not check "
  420. "for updates?"),
  421. QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.Cancel)
  422. if reply == QtWidgets.QMessageBox.Cancel:
  423. return
  424. self.__set_updates_all(False)
  425. def __set_updates_all(self, state):
  426. errors = []
  427. for vm in self.qubes_app.domains:
  428. if vm.klass != "AdminVM":
  429. try:
  430. vm.features['service.qubes-update-check'] = state
  431. except exc.QubesDaemonAccessError:
  432. errors.append(vm.name)
  433. if errors:
  434. QtWidgets.QMessageBox.warning(
  435. self, "Error!",
  436. "Failed to set state for some qubes: {}".format(
  437. ", ".join(errors)))
  438. def __apply_updates__(self):
  439. if self.updates_dom0.isEnabled() and \
  440. self.updates_dom0.isChecked() != self.updates_dom0_val:
  441. try:
  442. self.qubes_app.domains['dom0'].features[
  443. 'service.qubes-update-check'] = \
  444. self.updates_dom0.isChecked()
  445. except exc.QubesDaemonAccessError:
  446. self.errors.append("Failed to change dom0 update value due "
  447. "to insufficient permissions.")
  448. if self.updates_vm.isEnabled() and \
  449. self.qubes_app.check_updates_vm != self.updates_vm.isChecked():
  450. try:
  451. self.qubes_app.check_updates_vm = self.updates_vm.isChecked()
  452. except exc.QubesDaemonAccessError:
  453. self.errors.append("Failed to set qube update checking due "
  454. "to insufficient permissions.")
  455. def _manage_repos(self, repolist, action):
  456. for name in repolist:
  457. if self.repos[name]['enabled'] and action == 'Enable' or \
  458. not self.repos[name]['enabled'] and action == 'Disable':
  459. continue
  460. try:
  461. result = _run_qrexec_repo('qubes.repos.' + action, name)
  462. if result != 'ok\n':
  463. raise RuntimeError(
  464. self.tr('qrexec call stdout did not contain "ok"'
  465. ' as expected'),
  466. {'stdout': result})
  467. except RuntimeError as ex:
  468. msg = '{desc}; {args}'.format(desc=ex.args[0], args=', '.join(
  469. # This is kind of hard to mentally parse but really all
  470. # it does is pretty-print args[1], which is a dictionary
  471. ['{key}: {val}'.format(key=i[0], val=i[1]) for i in
  472. ex.args[1].items()]
  473. ))
  474. QtWidgets.QMessageBox.warning(
  475. None,
  476. self.tr("ERROR!"),
  477. self.tr("Error managing {repo} repository settings:"
  478. " {msg}".format(repo=name, msg=msg)))
  479. def _handle_dom0_updates_combobox(self, idx):
  480. idx += 1
  481. repolist = ['qubes-dom0-current', 'qubes-dom0-security-testing',
  482. 'qubes-dom0-current-testing', 'qubes-dom0-unstable']
  483. enable = repolist[:idx]
  484. disable = repolist[idx:]
  485. self._manage_repos(enable, 'Enable')
  486. self._manage_repos(disable, 'Disable')
  487. # pylint: disable=invalid-name
  488. def _handle_itl_tmpl_updates_combobox(self, idx):
  489. idx += 1
  490. repolist = ['qubes-templates-itl', 'qubes-templates-itl-testing']
  491. enable = repolist[:idx]
  492. disable = repolist[idx:]
  493. self._manage_repos(enable, 'Enable')
  494. self._manage_repos(disable, 'Disable')
  495. # pylint: disable=invalid-name
  496. def _handle_comm_tmpl_updates_combobox(self, idx):
  497. # We don't increment idx by 1 because this is the only combobox that
  498. # has an explicit "disable this repository entirely" option
  499. repolist = ['qubes-templates-community',
  500. 'qubes-templates-community-testing']
  501. enable = repolist[:idx]
  502. disable = repolist[idx:]
  503. self._manage_repos(enable, 'Enable')
  504. self._manage_repos(disable, 'Disable')
  505. def __apply_repos__(self):
  506. if self.dom0_updates_repo.isEnabled():
  507. self._handle_dom0_updates_combobox(
  508. self.dom0_updates_repo.currentIndex())
  509. if self.itl_tmpl_updates_repo.isEnabled():
  510. self._handle_itl_tmpl_updates_combobox(
  511. self.itl_tmpl_updates_repo.currentIndex())
  512. if self.comm_tmpl_updates_repo.isEnabled():
  513. self._handle_comm_tmpl_updates_combobox(
  514. self.comm_tmpl_updates_repo.currentIndex())
  515. def reject(self):
  516. self.done(0)
  517. def save_and_apply(self):
  518. self.errors = []
  519. self.__apply_system_defaults__()
  520. self.__apply_kernel_defaults__()
  521. self.__apply_mem_defaults__()
  522. self.__apply_updates__()
  523. self.__apply_repos__()
  524. self.__apply_gui_defaults()
  525. if self.errors:
  526. err_msg = "Failed to apply some settings:\n" + "\n".join(
  527. self.errors)
  528. QtWidgets.QMessageBox.warning(self, "Error", err_msg)
  529. def main():
  530. utils.run_synchronous(GlobalSettingsWindow)
  531. if __name__ == "__main__":
  532. main()