63b857f
From 735a4d98ac057ded317dae9b85777ce56d8af0fd Mon Sep 17 00:00:00 2001
48fb145
From: fujiwarat <takao.fujiwara1@gmail.com>
63b857f
Date: Mon, 20 Jun 2011 19:04:51 +0900
692f6ca
Subject: [PATCH] Enable ibus-setup to show the frequently used languages
692f6ca
 only in IME list.
48fb145
48fb145
---
48fb145
 data/ibus.schemas.in    |  168 +++++++++++++++++++++++++++++++++++++++++++++++
48fb145
 setup/enginecombobox.py |  153 ++++++++++++++++++++++++++++++++++++------
48fb145
 setup/main.py           |    1 +
48fb145
 3 files changed, 300 insertions(+), 22 deletions(-)
48fb145
63b857f
diff --git a/data/ibus.schemas.in.in b/data/ibus.schemas.in.in
63b857f
index d4334e1..5ef2ac2 100644
63b857f
--- a/data/ibus.schemas.in.in
63b857f
+++ b/data/ibus.schemas.in.in
48fb145
@@ -239,6 +239,174 @@
48fb145
       </locale>
48fb145
     </schema>
48fb145
     <schema>
48fb145
+      <key>/schemas/desktop/ibus/general/xkblayoutconfig/system/group_list</key>
48fb145
+      <applyto>/desktop/ibus/general/xkblayoutconfig/system/group_list</applyto>
48fb145
+      <owner>ibus</owner>
48fb145
+      <type>list</type>
48fb145
+      <list_type>string</list_type>
48fb145
+      <default>[west_europe,south_europe,east_europe,north_europe,west_asia,center_asia,east_asia,india,australia]</default>
48fb145
+      <locale name="C">
48fb145
+        <short>List of system keyboard layout groups on ibus-setup</short>
48fb145
+	    <long>The group list is used not to show all the system
48fb145
+                  keyboard layouts by default. The list item will be
48fb145
+                  appended at the end of gconf key. e.g.
48fb145
+                  .../xkblayoutconfig/system/item1</long>
48fb145
+      </locale>
48fb145
+    </schema>
48fb145
+    <schema>
48fb145
+      <key>/schemas/desktop/ibus/general/xkblayoutconfig/system/west_europe</key>
48fb145
+      <applyto>/desktop/ibus/general/xkblayoutconfig/system/west_europe</applyto>
48fb145
+      <owner>ibus</owner>
48fb145
+      <type>list</type>
48fb145
+      <list_type>string</list_type>
48fb145
+      
48fb145
+      <default>[ad,be,br,de,ca,ch,cz,es,fr,gn,hu,ie,ie(CloGaelach),it,latam,nl,pt,si,sk]</default>
48fb145
+      -->
48fb145
+      <default>[ca,cs,de,en,es,fr,gd,hu,it,nl,pt,sk,sl]</default>
48fb145
+      <locale name="C">
48fb145
+        <short>List of European languages on ibus-setup</short>
48fb145
+	    <long>ibus-setup shows the languages only in input method list
48fb145
+                  when you run ibus-setup on one of the languages.
48fb145
+                  Other languages are hidden under an extended button.</long>
48fb145
+      </locale>
48fb145
+    </schema>
48fb145
+    <schema>
48fb145
+      <key>/schemas/desktop/ibus/general/xkblayoutconfig/system/south_europe</key>
48fb145
+      <applyto>/desktop/ibus/general/xkblayoutconfig/system/south_europe</applyto>
48fb145
+      <owner>ibus</owner>
48fb145
+      <type>list</type>
48fb145
+      <list_type>string</list_type>
48fb145
+      
48fb145
+      <default>[al,ba,bg,gr,me,mk,mt,ro,rs]</default>
48fb145
+      -->
48fb145
+      <default>[bg,bs,el,mk,mt,ro,sq,sr]</default>
48fb145
+      <locale name="C">
48fb145
+        <short>List of European languages on ibus-setup</short>
48fb145
+	    <long>ibus-setup shows the languages only in input method list
48fb145
+                  when you run ibus-setup on one of the languages.
48fb145
+                  Other languages are hidden under an extended button.</long>
48fb145
+      </locale>
48fb145
+    </schema>
48fb145
+    <schema>
48fb145
+      <key>/schemas/desktop/ibus/general/xkblayoutconfig/system/east_europe</key>
48fb145
+      <applyto>/desktop/ibus/general/xkblayoutconfig/system/east_europe</applyto>
48fb145
+      <owner>ibus</owner>
48fb145
+      <type>list</type>
48fb145
+      <list_type>string</list_type>
48fb145
+      
48fb145
+      <default>[by,ee,epo,ge,ge(dsb),ge(ru),ge(os),hr,kg,kz,lt,lv,pl,pl(csb),ru,ru(cv),ru(kom),ru(sah),ru(tt),ru(xal),ua,uz]</default>
48fb145
+      -->
48fb145
+      <default>[be,csb,cv,et,ka,kk,ky,lt,lv,pl,ru,tt,uk,uz]</default>
48fb145
+      <locale name="C">
48fb145
+        <short>List of European languages on ibus-setup</short>
48fb145
+	    <long>ibus-setup shows the languages only in input method list
48fb145
+                  when you run ibus-setup on one of the languages.
48fb145
+                  Other languages are hidden under an extended button.</long>
48fb145
+      </locale>
48fb145
+    </schema>
48fb145
+    <schema>
48fb145
+      <key>/schemas/desktop/ibus/general/xkblayoutconfig/system/north_europe</key>
48fb145
+      <applyto>/desktop/ibus/general/xkblayoutconfig/system/north_europe</applyto>
48fb145
+      <owner>ibus</owner>
48fb145
+      <type>list</type>
48fb145
+      <list_type>string</list_type>
48fb145
+      
48fb145
+      <default>[dk,fi,fo,is,no,no(smi),se]</default>
48fb145
+      -->
48fb145
+      <default>[da,fi,fo,is,no,se,sv]</default>
48fb145
+      <locale name="C">
48fb145
+        <short>List of European languages on ibus-setup</short>
48fb145
+	    <long>ibus-setup shows the languages only in input method list
48fb145
+                  when you run ibus-setup on one of the languages.
48fb145
+                  Other languages are hidden under an extended button.</long>
48fb145
+      </locale>
48fb145
+    </schema>
48fb145
+    <schema>
48fb145
+      <key>/schemas/desktop/ibus/general/xkblayoutconfig/system/west_asia</key>
48fb145
+      <applyto>/desktop/ibus/general/xkblayoutconfig/system/west_asia</applyto>
48fb145
+      <owner>ibus</owner>
48fb145
+      <type>list</type>
48fb145
+      <list_type>string</list_type>
48fb145
+      
48fb145
+      <default>[am,ara,az,et,gh,gh(akan),gh(ewe),gh(fula),gh(ga),gh(hausa),il,iq,iq(ku),ir,ir(ku),ma,ma(tifinagh),ng,ng(hausa),ng,ng(igbo),ng(yoruba),sy,sy(ku),tj,tr]</default>
48fb145
+      -->
48fb145
+      <default>[am,ar,az,ber,fa,ha,he,hy,ig,ku,tg,tr,yo]</default>
48fb145
+      <locale name="C">
48fb145
+        <short>List of Asian languages on ibus-setup</short>
48fb145
+	    <long>ibus-setup shows the languages only in input method list
48fb145
+                  when you run ibus-setup on one of the languages.
48fb145
+                  Other languages are hidden under an extended button.</long>
48fb145
+      </locale>
48fb145
+    </schema>
48fb145
+    <schema>
48fb145
+      <key>/schemas/desktop/ibus/general/xkblayoutconfig/system/center_asia</key>
48fb145
+      <applyto>/desktop/ibus/general/xkblayoutconfig/system/center_asia</applyto>
48fb145
+      <owner>ibus</owner>
48fb145
+      <type>list</type>
48fb145
+      <list_type>string</list_type>
48fb145
+      
48fb145
+      <default>[cn(tib)]</default>
48fb145
+      -->
48fb145
+      <default>[bo,zh]</default>
48fb145
+      <locale name="C">
48fb145
+        <short>List of Asian languages on ibus-setup</short>
48fb145
+	    <long>ibus-setup shows the languages only in input method list
48fb145
+                  when you run ibus-setup on one of the languages.
48fb145
+                  Other languages are hidden under an extended button.</long>
48fb145
+      </locale>
48fb145
+    </schema>
48fb145
+    <schema>
48fb145
+      <key>/schemas/desktop/ibus/general/xkblayoutconfig/system/east_asia</key>
48fb145
+      <applyto>/desktop/ibus/general/xkblayoutconfig/system/east_asia</applyto>
48fb145
+      <owner>ibus</owner>
48fb145
+      <type>list</type>
48fb145
+      <list_type>string</list_type>
48fb145
+      
48fb145
+      <default>[bt,kh,la,mal,mm,th,vn]</default>
48fb145
+      -->
48fb145
+      <default>[dz,km,lo,my,th,vi]</default>
48fb145
+      <locale name="C">
48fb145
+        <short>List of Asian languages on ibus-setup</short>
48fb145
+	    <long>ibus-setup shows the languages only in input method list
48fb145
+                  when you run ibus-setup on one of the languages.
48fb145
+                  Other languages are hidden under an extended button.</long>
48fb145
+      </locale>
48fb145
+    </schema>
48fb145
+    <schema>
48fb145
+      <key>/schemas/desktop/ibus/general/xkblayoutconfig/system/india</key>
48fb145
+      <applyto>/desktop/ibus/general/xkblayoutconfig/system/india</applyto>
48fb145
+      <owner>ibus</owner>
48fb145
+      <type>list</type>
48fb145
+      <list_type>string</list_type>
48fb145
+      
48fb145
+      <default>[bd,in,in(ben),in(guj),in(guru),in(jhelum),in(kan),in(mal),in(ori),in(tam),in(tel),in(urd-phonetic),in(bolnagri),lk,lk(tam_unicode),mv,np,pk]</default>
48fb145
+      -->
48fb145
+      <default>[bn,dv,gu,hi,kn,ml,ne,or,pa,si,ta,te,ur]</default>
48fb145
+      <locale name="C">
48fb145
+        <short>List of Asian languages on ibus-setup</short>
48fb145
+	    <long>ibus-setup shows the languages only in input method list
48fb145
+                  when you run ibus-setup on one of the languages.
48fb145
+                  Other languages are hidden under an extended button.</long>
48fb145
+      </locale>
48fb145
+    </schema>
48fb145
+    <schema>
48fb145
+      <key>/schemas/desktop/ibus/general/xkblayoutconfig/system/australia</key>
48fb145
+      <applyto>/desktop/ibus/general/xkblayoutconfig/system/australia</applyto>
48fb145
+      <owner>ibus</owner>
48fb145
+      <type>list</type>
48fb145
+      <list_type>string</list_type>
48fb145
+      
48fb145
+      <default>[mao]</default>
48fb145
+      -->
48fb145
+      <default>[mi]</default>
48fb145
+      <locale name="C">
48fb145
+        <short>List of Asian languages on ibus-setup</short>
48fb145
+	    <long>ibus-setup shows the languages only in input method list
48fb145
+                  when you run ibus-setup on one of the languages.
48fb145
+                  Other languages are hidden under an extended button.</long>
48fb145
+      </locale>
48fb145
+    </schema>
48fb145
+    <schema>
48fb145
       <key>/schemas/desktop/ibus/panel/use_custom_font</key>
48fb145
       <applyto>/desktop/ibus/panel/use_custom_font</applyto>
48fb145
       <owner>ibus</owner>
48fb145
diff --git a/setup/enginecombobox.py b/setup/enginecombobox.py
692f6ca
index 7383177..bff2407 100644
48fb145
--- a/setup/enginecombobox.py
48fb145
+++ b/setup/enginecombobox.py
48fb145
@@ -43,7 +43,10 @@ class EngineComboBox(gtk.ComboBox):
48fb145
         self.connect("notify::active", self.__notify_active_cb)
48fb145
 
48fb145
         self.__model = None
48fb145
+        self.__all_model = None
48fb145
+        self.__config = None
48fb145
         self.__title = _("Select an input method")
48fb145
+        self.__show_sub_lang = False
48fb145
 
48fb145
         renderer = gtk.CellRendererPixbuf()
48fb145
         renderer.set_property("xalign", 0)
47affbc
@@ -57,21 +60,51 @@ class EngineComboBox(gtk.ComboBox):
48fb145
         self.pack_start(renderer, True)
48fb145
         self.set_cell_data_func(renderer, self.__name_cell_data_cb)
48fb145
 
48fb145
-    def set_engines(self, engines):
48fb145
-        self.__model = gtk.TreeStore(gobject.TYPE_PYOBJECT)
47affbc
-
47affbc
-        iter1 = self.__model.append(None)
47affbc
-        self.__model.set(iter1, 0, 0)
47affbc
-        lang = {}
47affbc
-        for e in engines:
47affbc
-            if ibus.use_bridge_hotkey() and \
47affbc
-               e.name == ibus.DEFAULT_BRIDGE_ENGINE_NAME:
47affbc
-                continue
47affbc
-            l = ibus.get_language_name(e.language)
47affbc
-            if l not in lang:
47affbc
-                lang[l] = []
47affbc
-            lang[l].append(e)
48fb145
+    def __gconf_get_lang_list_from_locale(self):
48fb145
+        common_list = ['en', 'Other']
48fb145
+        if  self.__config == None:
48fb145
+            return None
48fb145
+        loc = None
48fb145
+        try:
48fb145
+            loc = locale.setlocale (locale.LC_ALL)
48fb145
+        except:
48fb145
+            pass
48fb145
+        if loc == None:
48fb145
+            return common_list
48fb145
+        current_lang = ibus.get_language_name(loc)
48fb145
+        if current_lang == None:
48fb145
+            return common_list
48fb145
+        group_list = self.__config.get_value("general/xkblayoutconfig/system",
48fb145
+                                             "group_list", None)
48fb145
+        if group_list == None:
48fb145
+            return [loc] + common_list
48fb145
+        group_list = list(group_list)
48fb145
+        lang_list = None
48fb145
+        for group in group_list:
48fb145
+            group = str(group)
48fb145
+            langs = self.__config.get_value("general/xkblayoutconfig/system",
48fb145
+                                            group, [])
48fb145
+            for lang in langs:
48fb145
+                lang = str(lang)
48fb145
+                if current_lang == ibus.get_language_name(lang):
48fb145
+                    lang_list = langs
48fb145
+                    break
48fb145
+            if lang_list != None:
48fb145
+                break
48fb145
+        if lang_list == None:
48fb145
+            return [loc] + common_list
48fb145
+        return lang_list + common_list
47affbc
+
48fb145
+    def __has_engine_in_lang_list(self, engine, lang_list):
48fb145
+        retval = False
48fb145
+        for lang in lang_list:
48fb145
+            if ibus.get_language_name(lang) == \
48fb145
+                ibus.get_language_name(engine.language):
48fb145
+                retval = True
48fb145
+                break
48fb145
+        return retval
48fb145
 
48fb145
+    def __model_append_langs(self, model, lang, visible):
48fb145
         keys = lang.keys()
48fb145
         keys.sort(locale.strcoll)
48fb145
         #add "Others" to the end of the combo box
47affbc
@@ -79,29 +112,89 @@ class EngineComboBox(gtk.ComboBox):
48fb145
             keys.remove(ibus.get_language_name("Other"))
48fb145
             keys += [ibus.get_language_name("Other")]
48fb145
         for l in keys:
48fb145
-            iter1 = self.__model.append(None)
48fb145
-            self.__model.set(iter1, 0, l)
48fb145
+            iter1 = model.append(None)
48fb145
+            model.set(iter1, 0, l)
48fb145
             def cmp_engine(a, b):
48fb145
                 if a.rank == b.rank:
48fb145
                     return locale.strcoll(a.longname, b.longname)
48fb145
                 return int(b.rank - a.rank)
48fb145
             lang[l].sort(cmp_engine)
48fb145
             for e in lang[l]:
48fb145
-                iter2 = self.__model.append(iter1)
48fb145
-                self.__model.set(iter2, 0, e)
48fb145
+                iter2 = model.append(iter1)
48fb145
+                model.set(iter2, 0, e)
48fb145
+
48fb145
+    def set_engines(self, engines):
48fb145
+        self.__model = gtk.TreeStore(gobject.TYPE_PYOBJECT)
47affbc
 
47affbc
-        self.set_model(self.__model)
48fb145
+        iter1 = self.__model.append(None)
48fb145
+        self.__model.set(iter1, 0, 0)
48fb145
+        lang_list = self.__gconf_get_lang_list_from_locale()
48fb145
+        lang = {}
48fb145
+        sub_lang = {}
48fb145
+        for e in engines:
47affbc
+            if ibus.use_bridge_hotkey() and \
47affbc
+               e.name == ibus.DEFAULT_BRIDGE_ENGINE_NAME:
47affbc
+                continue
48fb145
+            l = ibus.get_language_name(e.language)
48fb145
+            if lang_list == None or \
48fb145
+                self.__has_engine_in_lang_list(e, lang_list):
48fb145
+                if l not in lang:
48fb145
+                    lang[l] = []
48fb145
+                lang[l].append(e)
48fb145
+            else:
48fb145
+                if l not in sub_lang:
48fb145
+                    sub_lang[l] = []
48fb145
+                sub_lang[l].append(e)
48fb145
+
48fb145
+        self.__model_append_langs(self.__model, lang, True)
48fb145
+        iter1 = self.__model.append(None)
48fb145
+        self.__model.set(iter1, 0, -1)
48fb145
+
48fb145
+        self.__all_model = gtk.TreeStore(gobject.TYPE_PYOBJECT)
48fb145
+        iter1 = self.__all_model.append(None)
48fb145
+        self.__all_model.set(iter1, 0, 0)
48fb145
+        self.__model_append_langs(self.__all_model, lang, False)
48fb145
+        iter1 = self.__all_model.append(None)
48fb145
+        self.__all_model.set(iter1, 0, -1)
48fb145
+        self.__model_append_langs(self.__all_model, sub_lang, False)
48fb145
+
48fb145
+        self.__toggle_sub_lang()
47affbc
+
48fb145
+    def __toggle_sub_lang(self):
48fb145
+        self.set_model(None)
48fb145
+        if self.__show_sub_lang:
48fb145
+            self.set_model(self.__all_model)
48fb145
+        else:
48fb145
+            self.set_model(self.__model)
48fb145
         self.set_active(0)
48fb145
 
48fb145
     def __icon_cell_data_cb(self, celllayout, renderer, model, iter):
48fb145
-        engine = self.__model.get_value(iter, 0)
48fb145
+        model = self.get_model()
48fb145
+        engine = model.get_value(iter, 0)
48fb145
 
48fb145
         if isinstance(engine, str) or isinstance (engine, unicode):
48fb145
             renderer.set_property("visible", False)
48fb145
             renderer.set_property("sensitive", False)
48fb145
         elif isinstance(engine, int):
48fb145
-            renderer.set_property("visible", False)
48fb145
-            renderer.set_property("sensitive", False)
48fb145
+            if engine == 0:
48fb145
+                renderer.set_property("visible", False)
48fb145
+                renderer.set_property("sensitive", False)
48fb145
+                renderer.set_property("pixbuf", None)
48fb145
+            elif engine < 0:
48fb145
+                if not self.__show_sub_lang:
48fb145
+                    pixbuf = load_icon("list-add", gtk.ICON_SIZE_LARGE_TOOLBAR)
48fb145
+                else:
48fb145
+                    pixbuf = load_icon("list-remove", gtk.ICON_SIZE_LARGE_TOOLBAR)
48fb145
+                if pixbuf == None:
48fb145
+                    pixbuf = load_icon("gtk-missing-image",
48fb145
+                                       gtk.ICON_SIZE_LARGE_TOOLBAR)
48fb145
+                if pixbuf == None:
48fb145
+                    renderer.set_property("visible", False)
48fb145
+                    renderer.set_property("sensitive", False)
48fb145
+                    return
48fb145
+                renderer.set_property("visible", True)
48fb145
+                renderer.set_property("sensitive", True)
48fb145
+                renderer.set_property("pixbuf", pixbuf)
48fb145
         else:
48fb145
             renderer.set_property("visible", True)
48fb145
             renderer.set_property("sensitive", True)
47affbc
@@ -113,7 +206,8 @@ class EngineComboBox(gtk.ComboBox):
48fb145
             renderer.set_property("pixbuf", pixbuf)
48fb145
 
48fb145
     def __name_cell_data_cb(self, celllayout, renderer, model, iter):
48fb145
-        engine = self.__model.get_value(iter, 0)
48fb145
+        model = self.get_model()
48fb145
+        engine = model.get_value(iter, 0)
48fb145
 
48fb145
         if isinstance (engine, str) or isinstance (engine, unicode):
48fb145
             renderer.set_property("sensitive", False)
47affbc
@@ -121,8 +215,15 @@ class EngineComboBox(gtk.ComboBox):
48fb145
             renderer.set_property("weight", pango.WEIGHT_NORMAL)
48fb145
         elif isinstance(engine, int):
48fb145
             renderer.set_property("sensitive", True)
48fb145
-            renderer.set_property("text", self.__title)
48fb145
-            renderer.set_property("weight", pango.WEIGHT_NORMAL)
48fb145
+            if engine == 0:
48fb145
+                renderer.set_property("text", self.__title)
48fb145
+                renderer.set_property("weight", pango.WEIGHT_NORMAL)
48fb145
+            elif engine < 0:
48fb145
+                if not self.__show_sub_lang:
692f6ca
+                    renderer.set_property("text", _("Show all input methods"))
48fb145
+                else:
692f6ca
+                    renderer.set_property("text", _("Show only input methods for your region"))
48fb145
+                renderer.set_property("weight", pango.WEIGHT_BOLD)
48fb145
         else:
48fb145
             renderer.set_property("sensitive", True)
48fb145
             renderer.set_property("text", engine.longname)
47affbc
@@ -137,13 +238,21 @@ class EngineComboBox(gtk.ComboBox):
48fb145
             if i == 0 or i == -1:
48fb145
                 return None
48fb145
             iter = self.get_active_iter()
48fb145
-            return self.get_model()[iter][0]
48fb145
+            model = self.get_model()
48fb145
+            if model[iter][0] == -1:
48fb145
+                self.__show_sub_lang = not self.__show_sub_lang
48fb145
+                self.__toggle_sub_lang()
48fb145
+                return None
48fb145
+            return model[iter][0]
48fb145
         else:
48fb145
             raise AttributeError, 'unknown property %s' % property.name
48fb145
 
48fb145
     def get_active_engine(self):
48fb145
         return self.get_property("active-engine")
48fb145
 
48fb145
+    def set_config(self, config):
48fb145
+        self.__config = config
48fb145
+
48fb145
     def get_title(self):
48fb145
         return self.__title
48fb145
 
48fb145
diff --git a/setup/main.py b/setup/main.py
63b857f
index 192fb88..5a0170d 100644
48fb145
--- a/setup/main.py
48fb145
+++ b/setup/main.py
63b857f
@@ -227,6 +227,7 @@ class Setup(object):
48fb145
         button.connect("toggled", self.__checkbutton_preload_engine_mode_toggled_cb)
48fb145
         self.__engines = self.__bus.list_engines()
48fb145
         self.__combobox = self.__builder.get_object("combobox_engines")
48fb145
+        self.__combobox.set_config(self.__config)
48fb145
         self.__combobox.set_engines(self.__engines)
48fb145
 
48fb145
         engines = self.__bus.list_active_engines()
48fb145
-- 
692f6ca
1.7.4.4
48fb145