Commit 805428e9 authored by segfault's avatar segfault

Greeter: Split locale setting file into multiple files (refs: #17136)

This is a preparation for loading the settings in the Greeter when
persistence is unlocked.
parent 463ba28a
......@@ -35,7 +35,16 @@ system_locale_dir = '/usr/share/locale/'
# Directory where the Greeter settings are stored
settings_dir = '/var/lib/gdm3/settings'
# File where session locale settings are stored
# File where the session language setting is stored
language_setting_path = os.path.join(settings_dir, 'tails.language')
# File where the session formats setting is stored
formats_setting_path = os.path.join(settings_dir, 'tails.formats')
# File where the session keyboard setting is stored
keyboard_setting_path = os.path.join(settings_dir, 'tails.keyboard')
# File where the above locale related settings are stored concatenated
locale_setting_path = os.path.join(settings_dir, 'tails.locale')
# File where the session sudo password is stored
......
import logging
import gi
import logging
import os
import tailsgreeter.config
from tailsgreeter.settings.localization import LocalizationSetting, language_from_locale, country_from_locale
from tailsgreeter.settings.utils import write_settings
gi.require_version('GObject', '2.0')
gi.require_version('GnomeDesktop', '3.0')
......@@ -16,6 +18,13 @@ class FormatsSetting(LocalizationSetting):
self.value = 'en_US'
self.locales_per_country = self._make_locales_per_country_dict(language_codes)
def apply_to_upcoming_session(self):
settings_file = tailsgreeter.config.formats_setting_path
write_settings(settings_file, {
'TAILS_FORMATS': self.get_value(),
'IS_DEFAULT': (not self.value_changed_by_user),
})
def get_tree(self) -> Gtk.TreeStore:
treestore = Gtk.TreeStore(GObject.TYPE_STRING, # id
GObject.TYPE_STRING) # name
......
import logging
import gi
import logging
import tailsgreeter.config
from tailsgreeter.settings.localization import LocalizationSetting, ln_iso639_tri, \
ln_iso639_2_T_to_B, language_from_locale, country_from_locale
from tailsgreeter.settings.utils import write_settings
gi.require_version('Gio', '2.0')
gi.require_version('GLib', '2.0')
......@@ -19,6 +21,22 @@ class KeyboardSetting(LocalizationSetting):
self.xkbinfo = GnomeDesktop.XkbInfo()
self.value = 'us'
def apply_to_upcoming_session(self):
try:
layout, variant = self.get_value().split('+')
except ValueError:
layout = self.get_value()
variant = ''
settings_file = tailsgreeter.config.keyboard_setting_path
write_settings(settings_file, {
# The default value from /etc/default/keyboard
'TAILS_XKBMODEL': 'pc105',
'TAILS_XKBLAYOUT': layout,
'TAILS_XKBVARIANT': variant,
'IS_DEFAULT': (not self.value_changed_by_user),
})
def get_tree(self, layout_codes=None) -> Gtk.TreeStore:
if not layout_codes:
layout_codes = self.get_all()
......
......@@ -23,8 +23,10 @@ import logging
import locale
from typing import Callable
import tailsgreeter.config
from tailsgreeter.settings.localization import LocalizationSetting, \
language_from_locale, country_from_locale
from tailsgreeter.settings.utils import write_settings
gi.require_version('GLib', '2.0')
gi.require_version('GObject', '2.0')
......@@ -46,6 +48,13 @@ class LanguageSetting(LocalizationSetting):
self.locales_per_language = self._make_language_to_locale_dict(locales)
self.language_names_per_language = self._make_language_to_language_name_dict(self.lang_codes)
def apply_to_upcoming_session(self):
settings_file = tailsgreeter.config.language_setting_path
write_settings(settings_file, {
'TAILS_LOCALE_NAME': self.get_value(),
'IS_DEFAULT': (not self.value_changed_by_user),
})
def get_tree(self) -> Gtk.TreeStore:
treestore = Gtk.TreeStore(GObject.TYPE_STRING, # id
GObject.TYPE_STRING) # name
......
......@@ -53,18 +53,13 @@ class LocalisationSettings(object):
self._usermanager_loaded_cb()
def apply_to_upcoming_session(self):
with open(tailsgreeter.config.locale_setting_path, 'w') as f:
os.chmod(tailsgreeter.config.locale_setting_path, 0o600)
f.write('TAILS_LOCALE_NAME=%s\n' % self.language.get_value())
f.write('TAILS_FORMATS=%s\n' % self.formats.get_value())
try:
layout, variant = self.keyboard.get_value().split('+')
except ValueError:
layout = self.keyboard.get_value()
variant = ''
# XXX: use default value from /etc/default/keyboard
f.write('TAILS_XKBMODEL=%s\n' % 'pc105')
f.write('TAILS_XKBLAYOUT=%s\n' % layout)
f.write('TAILS_XKBVARIANT=%s\n' % variant)
self.language.apply_to_upcoming_session()
self.formats.apply_to_upcoming_session()
self.keyboard.apply_to_upcoming_session()
with open(tailsgreeter.config.locale_setting_path, 'w') as outfile:
for path in (tailsgreeter.config.language_setting_path,
tailsgreeter.config.formats_setting_path,
tailsgreeter.config.keyboard_setting_path):
with open(path) as infile:
outfile.write(infile.read())
import os
def write_settings(filename: str, settings: dict):
with open(filename, 'w') as f:
os.chmod(filename, 0o600)
for key, value in settings.items():
f.write('%s=%s\n' % (key, value))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment