global_settings.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  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 RuntimeError(
  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 RuntimeError(
  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(GlobalSettingsWindow, self).__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 as ex:
  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. self.dom0_mem_boost_val = '350MiB' # str(qmemman_algo.DOM0_MEM_BOOST)
  276. self.qmemman_config.read(qmemman_config_path)
  277. if self.qmemman_config.has_section('global'):
  278. self.vm_min_mem_val = \
  279. self.qmemman_config.get('global', 'vm-min-mem')
  280. self.dom0_mem_boost_val = \
  281. self.qmemman_config.get('global', 'dom0-mem-boost')
  282. self.vm_min_mem_val = parse_size(self.vm_min_mem_val)
  283. self.dom0_mem_boost_val = parse_size(self.dom0_mem_boost_val)
  284. self.min_vm_mem.setValue(
  285. int(self.vm_min_mem_val / 1024 / 1024))
  286. self.dom0_mem_boost.setValue(
  287. int(self.dom0_mem_boost_val / 1024 / 1024))
  288. except exc.QubesException:
  289. self.min_vm_mem.setEnabled(False)
  290. self.dom0_mem_boost.setEnabled(False)
  291. def __apply_mem_defaults__(self):
  292. if not self.min_vm_mem.isEnabled() or \
  293. not self.dom0_mem_boost.isEnabled():
  294. return
  295. # qmemman settings
  296. current_min_vm_mem = self.min_vm_mem.value()
  297. current_dom0_mem_boost = self.dom0_mem_boost.value()
  298. if current_min_vm_mem * 1024 * 1024 != self.vm_min_mem_val or \
  299. current_dom0_mem_boost * 1024 * 1024 != self.dom0_mem_boost_val:
  300. current_min_vm_mem = str(current_min_vm_mem) + 'MiB'
  301. current_dom0_mem_boost = str(current_dom0_mem_boost) + 'MiB'
  302. if not self.qmemman_config.has_section('global'):
  303. # add the whole section
  304. self.qmemman_config.add_section('global')
  305. self.qmemman_config.set(
  306. 'global', 'vm-min-mem', current_min_vm_mem)
  307. self.qmemman_config.set(
  308. 'global', 'dom0-mem-boost', current_dom0_mem_boost)
  309. self.qmemman_config.set(
  310. 'global', 'cache-margin-factor', str(1.3))
  311. # removed qmemman_algo.CACHE_FACTOR
  312. try:
  313. qmemman_config_file = open(qmemman_config_path, 'a')
  314. self.qmemman_config.write(qmemman_config_file)
  315. qmemman_config_file.close()
  316. except Exception as ex:
  317. self.errors.append(
  318. "Failed to set memory settings due to {}".format(
  319. str(ex)))
  320. else:
  321. # If there already is a 'global' section, we don't use
  322. # SafeConfigParser.write() - it would get rid of
  323. # all the comments...
  324. lines_to_add = {}
  325. lines_to_add['vm-min-mem'] = \
  326. "vm-min-mem = " + current_min_vm_mem + "\n"
  327. lines_to_add['dom0-mem-boost'] = \
  328. "dom0-mem-boost = " + current_dom0_mem_boost + "\n"
  329. config_lines = []
  330. try:
  331. qmemman_config_file = open(qmemman_config_path, 'r')
  332. except Exception as ex:
  333. self.errors.append(
  334. "Failed to set memory settings due to {}".format(
  335. str(ex)))
  336. return
  337. for line in qmemman_config_file:
  338. if line.strip().startswith('vm-min-mem'):
  339. config_lines.append(lines_to_add['vm-min-mem'])
  340. del lines_to_add['vm-min-mem']
  341. elif line.strip().startswith('dom0-mem-boost'):
  342. config_lines.append(lines_to_add['dom0-mem-boost'])
  343. del lines_to_add['dom0-mem-boost']
  344. else:
  345. config_lines.append(line)
  346. qmemman_config_file.close()
  347. for line in lines_to_add:
  348. config_lines.append(line)
  349. try:
  350. qmemman_config_file = open(qmemman_config_path, 'w')
  351. qmemman_config_file.writelines(config_lines)
  352. qmemman_config_file.close()
  353. except Exception as ex:
  354. self.errors.append(
  355. "Failed to set memory settings due to {}".format(
  356. str(ex)))
  357. return
  358. def __init_updates__(self):
  359. self.updates_dom0_val = bool(
  360. utils.get_feature(self.qubes_app.domains['dom0'],
  361. 'service.qubes-update-check',
  362. True))
  363. self.updates_dom0.setChecked(self.updates_dom0_val)
  364. try:
  365. self.updates_vm.setChecked(self.qubes_app.check_updates_vm)
  366. except exc.QubesDaemonAccessError:
  367. self.updates_vm.isEnabled(False)
  368. self.enable_updates_all.clicked.connect(self.__enable_updates_all)
  369. self.disable_updates_all.clicked.connect(self.__disable_updates_all)
  370. self.repos = repos = dict()
  371. try:
  372. for i in _run_qrexec_repo('qubes.repos.List').split('\n'):
  373. lst = i.split('\0')
  374. # Keyed by repo name
  375. dct = repos[lst[0]] = dict()
  376. dct['prettyname'] = lst[1]
  377. dct['enabled'] = lst[2] == 'enabled'
  378. except Exception as ex:
  379. self.dom0_updates_repo.setEnabled(False)
  380. self.itl_tmpl_updates_repo.setEnabled(False)
  381. self.comm_tmpl_updates_repo.setEnabled(False)
  382. if repos['qubes-dom0-unstable']['enabled']:
  383. self.dom0_updates_repo.setCurrentIndex(3)
  384. elif repos['qubes-dom0-current-testing']['enabled']:
  385. self.dom0_updates_repo.setCurrentIndex(2)
  386. elif repos['qubes-dom0-security-testing']['enabled']:
  387. self.dom0_updates_repo.setCurrentIndex(1)
  388. elif repos['qubes-dom0-current']['enabled']:
  389. self.dom0_updates_repo.setCurrentIndex(0)
  390. else:
  391. raise Exception(
  392. self.tr('Cannot detect enabled dom0 update repositories'))
  393. if repos['qubes-templates-itl-testing']['enabled']:
  394. self.itl_tmpl_updates_repo.setCurrentIndex(1)
  395. elif repos['qubes-templates-itl']['enabled']:
  396. self.itl_tmpl_updates_repo.setCurrentIndex(0)
  397. else:
  398. raise Exception(self.tr('Cannot detect enabled ITL template update '
  399. 'repositories'))
  400. if repos['qubes-templates-community-testing']['enabled']:
  401. self.comm_tmpl_updates_repo.setCurrentIndex(2)
  402. elif repos['qubes-templates-community']['enabled']:
  403. self.comm_tmpl_updates_repo.setCurrentIndex(1)
  404. else:
  405. self.comm_tmpl_updates_repo.setCurrentIndex(0)
  406. def __enable_updates_all(self):
  407. reply = QtWidgets.QMessageBox.question(
  408. self, self.tr("Change state of all qubes"),
  409. self.tr("Are you sure you want to set all qubes to check "
  410. "for updates?"),
  411. QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.Cancel)
  412. if reply == QtWidgets.QMessageBox.Cancel:
  413. return
  414. self.__set_updates_all(True)
  415. def __disable_updates_all(self):
  416. reply = QtWidgets.QMessageBox.question(
  417. self, self.tr("Change state of all qubes"),
  418. self.tr("Are you sure you want to set all qubes to not check "
  419. "for updates?"),
  420. QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.Cancel)
  421. if reply == QtWidgets.QMessageBox.Cancel:
  422. return
  423. self.__set_updates_all(False)
  424. def __set_updates_all(self, state):
  425. errors = []
  426. for vm in self.qubes_app.domains:
  427. if vm.klass != "AdminVM":
  428. try:
  429. vm.features['service.qubes-update-check'] = state
  430. except exc.QubesDaemonAccessError:
  431. errors.append(vm.name)
  432. if errors:
  433. QtWidgets.QMessageBox.warning(
  434. self, "Error!",
  435. "Failed to set state for some qubes: {}".format(
  436. ", ".join(errors)))
  437. def __apply_updates__(self):
  438. if self.updates_dom0.isEnabled() and \
  439. self.updates_dom0.isChecked() != self.updates_dom0_val:
  440. try:
  441. self.qubes_app.domains['dom0'].features[
  442. 'service.qubes-update-check'] = \
  443. self.updates_dom0.isChecked()
  444. except exc.QubesDaemonAccessError:
  445. self.errors.append("Failed to change dom0 update value due "
  446. "to insufficient permissions.")
  447. if self.updates_vm.isEnabled() and \
  448. self.qubes_app.check_updates_vm != self.updates_vm.isChecked():
  449. try:
  450. self.qubes_app.check_updates_vm = self.updates_vm.isChecked()
  451. except exc.QubesDaemonAccessError:
  452. self.errors.append("Failed to set qube update checking due "
  453. "to insufficient permissions.")
  454. def _manage_repos(self, repolist, action):
  455. for name in repolist:
  456. if self.repos[name]['enabled'] and action == 'Enable' or \
  457. not self.repos[name]['enabled'] and action == 'Disable':
  458. continue
  459. try:
  460. result = _run_qrexec_repo('qubes.repos.' + action, name)
  461. if result != 'ok\n':
  462. raise RuntimeError(
  463. self.tr('qrexec call stdout did not contain "ok"'
  464. ' as expected'),
  465. {'stdout': result})
  466. except RuntimeError as ex:
  467. msg = '{desc}; {args}'.format(desc=ex.args[0], args=', '.join(
  468. # This is kind of hard to mentally parse but really all
  469. # it does is pretty-print args[1], which is a dictionary
  470. ['{key}: {val}'.format(key=i[0], val=i[1]) for i in
  471. ex.args[1].items()]
  472. ))
  473. QtWidgets.QMessageBox.warning(
  474. None,
  475. self.tr("ERROR!"),
  476. self.tr("Error managing {repo} repository settings:"
  477. " {msg}".format(repo=name, msg=msg)))
  478. def _handle_dom0_updates_combobox(self, idx):
  479. idx += 1
  480. repolist = ['qubes-dom0-current', 'qubes-dom0-security-testing',
  481. 'qubes-dom0-current-testing', 'qubes-dom0-unstable']
  482. enable = repolist[:idx]
  483. disable = repolist[idx:]
  484. self._manage_repos(enable, 'Enable')
  485. self._manage_repos(disable, 'Disable')
  486. # pylint: disable=invalid-name
  487. def _handle_itl_tmpl_updates_combobox(self, idx):
  488. idx += 1
  489. repolist = ['qubes-templates-itl', 'qubes-templates-itl-testing']
  490. enable = repolist[:idx]
  491. disable = repolist[idx:]
  492. self._manage_repos(enable, 'Enable')
  493. self._manage_repos(disable, 'Disable')
  494. # pylint: disable=invalid-name
  495. def _handle_comm_tmpl_updates_combobox(self, idx):
  496. # We don't increment idx by 1 because this is the only combobox that
  497. # has an explicit "disable this repository entirely" option
  498. repolist = ['qubes-templates-community',
  499. 'qubes-templates-community-testing']
  500. enable = repolist[:idx]
  501. disable = repolist[idx:]
  502. self._manage_repos(enable, 'Enable')
  503. self._manage_repos(disable, 'Disable')
  504. def __apply_repos__(self):
  505. if self.dom0_updates_repo.isEnabled():
  506. self._handle_dom0_updates_combobox(
  507. self.dom0_updates_repo.currentIndex())
  508. if self.itl_tmpl_updates_repo.isEnabled():
  509. self._handle_itl_tmpl_updates_combobox(
  510. self.itl_tmpl_updates_repo.currentIndex())
  511. if self.comm_tmpl_updates_repo.isEnabled():
  512. self._handle_comm_tmpl_updates_combobox(
  513. self.comm_tmpl_updates_repo.currentIndex())
  514. def reject(self):
  515. self.done(0)
  516. def save_and_apply(self):
  517. self.errors = []
  518. self.__apply_system_defaults__()
  519. self.__apply_kernel_defaults__()
  520. self.__apply_mem_defaults__()
  521. self.__apply_updates__()
  522. self.__apply_repos__()
  523. self.__apply_gui_defaults()
  524. if self.errors:
  525. err_msg = "Failed to apply some settings:\n" + "\n".join(
  526. self.errors)
  527. QtWidgets.QMessageBox.warning(self, "Error", err_msg)
  528. def main():
  529. utils.run_synchronous(GlobalSettingsWindow)
  530. if __name__ == "__main__":
  531. main()