Commits

Akira TAGOH committed 7c06b8c

Enable the language ordering feature only when the configuration place is supportable

It now depends on $HOME/.i18n and this is a distro-specific.
without validating this, it may not works as expected.
So if it seems not being supported on the runtime env,
just hide the tab for this feature.
In other words, one can just patch it out to re-enable
this feature for your env.

  • Participants
  • Parent commits 8875133

Comments (0)

Files changed (2)

     propui = None
 
 langui_builder = FontsTweakUtil.create_builder('fonts-tweak-lang.ui')
-langui_builder.connect_signals(FontsTweakLangUI(langui_builder, dlgui))
+langui_obj = FontsTweakLangUI(langui_builder, dlgui)
+langui_builder.connect_signals(langui_obj)
 
 aliasui = aliasui_builder.get_object('fonts-alias-ui')
-langui = langui_builder.get_object('fonts-lang-order-ui')
+if langui_obj.supported == True:
+    langui = langui_builder.get_object('fonts-lang-order-ui')
+else:
+    langui = None
 
 tabs = Gtk.Notebook()
 tabs.append_page(aliasui, Gtk.Label(_('Fonts Aliases')))
 if propui is not None:
     tabs.append_page(propui, Gtk.Label(_('Fonts Properties')))
-tabs.append_page(langui, Gtk.Label(_('Language Ordering')))
+if langui is not None:
+    tabs.append_page(langui, Gtk.Label(_('Language Ordering')))
 content_area.set_border_width(2)
 content_area.add(tabs)
 

fontstweak/langui.py

         self.view = builder.get_object('treeview-lang-order-list')
         self.view.append_column(Gtk.TreeViewColumn(None, Gtk.CellRendererText(), text=0))
         self.view_list = builder.get_object('order-lang-list')
+        self.supported = True
 
         # check if current icon theme supports the symbolic icons
         add_icon = builder.get_object('add-lang-order')
             iter = None
         return iter
 
-    def __get_i18nfilename(self):
-        homedir = os.path.expanduser('~')
-        i18nfile = os.path.join(homedir, '.i18n')
+    def __get_config_filename(self):
+        if os.path.isfile('/etc/fedora-release') or os.path.isfile('/etc/redhat-release'):
+            homedir = os.path.expanduser('~')
+            return os.path.join(homedir, '.i18n')
+        else:
+            return None
 
-        return i18nfile
+    def __get_configfile_contents(self):
+        config = self.__get_config_filename()
+        if not config:
+            return None
 
-    def __get_i18nfile(self):
-        i18nfile = self.__get_i18nfilename()
         content = []
         found = False
-        if os.path.isfile(i18nfile):
-            f = open(i18nfile, 'r')
+        if os.path.isfile(config):
+            f = open(config, 'r')
             content = f.readlines()
             f.close
 
         return content
 
     def load(self):
-        content = self.__get_i18nfile()
-        l = None
-        for line in content:
-            if re.search(r'^FC_LANG=', line):
-                l = re.sub(r'^FC_LANG=(.*)$', r'\1', line).rstrip('\n')
-        model = self.view.get_model()
-        model.clear()
-        if l != None:
-            for tag in l.split(':'):
-                for lang in self.langlist.keys():
-                    if re.search(r'^%s' % tag, lang):
-                        iter = model.append()
-                        model.set_value(iter, 0, self.langlist[lang])
-                        model.set_value(iter, 1, lang)
+        content = self.__get_configfile_contents()
+        if content is None:
+            self.supported = False
+        else:
+            l = None
+            for line in content:
+                if re.search(r'^FC_LANG=', line):
+                    l = re.sub(r'^FC_LANG=(.*)$', r'\1', line).rstrip('\n')
+            model = self.view.get_model()
+            model.clear()
+            if l != None:
+                for tag in l.split(':'):
+                    for lang in self.langlist.keys():
+                        if re.search(r'^%s' % tag, lang):
+                            iter = model.append()
+                            model.set_value(iter, 0, self.langlist[lang])
+                            model.set_value(iter, 1, lang)
 
     def save(self):
         l = []