6bf917
From d3ce0467bb7825cc97da9646254bc09f58119fda Mon Sep 17 00:00:00 2001
48fb14
From: fujiwarat <takao.fujiwara1@gmail.com>
6bf917
Date: Tue, 27 Nov 2012 15:53:34 +0900
ca2220
Subject: [PATCH] Enable ibus-setup to show the frequently used languages
ca2220
 only in IME list.
48fb14
48fb14
---
a208e6
 data/ibus.schemas.in    | 168 ++++++++++++++++++++++++++++++++++++++++++++++++
a208e6
 setup/enginecombobox.py | 155 +++++++++++++++++++++++++++++++++++++-------
a208e6
 setup/main.py           |   1 +
db31e5
 3 files changed, 300 insertions(+), 24 deletions(-)
48fb14
db6c98
diff --git a/data/ibus.schemas.in b/data/ibus.schemas.in
a208e6
index 64f6f33..23739af 100644
db6c98
--- a/data/ibus.schemas.in
db6c98
+++ b/data/ibus.schemas.in
a208e6
@@ -348,6 +348,174 @@ se,si,sk,sy,sy(ku),th,tj,tr,ua,uz,vn
48fb14
       </locale>
48fb14
     </schema>
48fb14
     <schema>
db6c98
+      <key>/schemas/desktop/ibus/general/xkblayoutconfig/group_list</key>
db6c98
+      <applyto>/desktop/ibus/general/xkblayoutconfig/group_list</applyto>
48fb14
+      <owner>ibus</owner>
48fb14
+      <type>list</type>
48fb14
+      <list_type>string</list_type>
48fb14
+      <default>[west_europe,south_europe,east_europe,north_europe,west_asia,center_asia,east_asia,india,australia]</default>
48fb14
+      <locale name="C">
48fb14
+        <short>List of system keyboard layout groups on ibus-setup</short>
db6c98
+           <long>The group list is used not to show all the system
48fb14
+                  keyboard layouts by default. The list item will be
48fb14
+                  appended at the end of gconf key. e.g.
db6c98
+                  .../xkblayoutconfig/item1</long>
48fb14
+      </locale>
48fb14
+    </schema>
48fb14
+    <schema>
db6c98
+      <key>/schemas/desktop/ibus/general/xkblayoutconfig/west_europe</key>
db6c98
+      <applyto>/desktop/ibus/general/xkblayoutconfig/west_europe</applyto>
48fb14
+      <owner>ibus</owner>
48fb14
+      <type>list</type>
48fb14
+      <list_type>string</list_type>
48fb14
+      
48fb14
+      <default>[ad,be,br,de,ca,ch,cz,es,fr,gn,hu,ie,ie(CloGaelach),it,latam,nl,pt,si,sk]</default>
48fb14
+      -->
48fb14
+      <default>[ca,cs,de,en,es,fr,gd,hu,it,nl,pt,sk,sl]</default>
48fb14
+      <locale name="C">
48fb14
+        <short>List of European languages on ibus-setup</short>
db6c98
+           <long>ibus-setup shows the languages only in input method list
48fb14
+                  when you run ibus-setup on one of the languages.
48fb14
+                  Other languages are hidden under an extended button.</long>
48fb14
+      </locale>
48fb14
+    </schema>
48fb14
+    <schema>
db6c98
+      <key>/schemas/desktop/ibus/general/xkblayoutconfig/south_europe</key>
db6c98
+      <applyto>/desktop/ibus/general/xkblayoutconfig/south_europe</applyto>
48fb14
+      <owner>ibus</owner>
48fb14
+      <type>list</type>
48fb14
+      <list_type>string</list_type>
48fb14
+      
48fb14
+      <default>[al,ba,bg,gr,me,mk,mt,ro,rs]</default>
48fb14
+      -->
48fb14
+      <default>[bg,bs,el,mk,mt,ro,sq,sr]</default>
48fb14
+      <locale name="C">
48fb14
+        <short>List of European languages on ibus-setup</short>
db6c98
+           <long>ibus-setup shows the languages only in input method list
48fb14
+                  when you run ibus-setup on one of the languages.
48fb14
+                  Other languages are hidden under an extended button.</long>
48fb14
+      </locale>
48fb14
+    </schema>
48fb14
+    <schema>
db6c98
+      <key>/schemas/desktop/ibus/general/xkblayoutconfig/east_europe</key>
db6c98
+      <applyto>/desktop/ibus/general/xkblayoutconfig/east_europe</applyto>
48fb14
+      <owner>ibus</owner>
48fb14
+      <type>list</type>
48fb14
+      <list_type>string</list_type>
48fb14
+      
48fb14
+      <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>
48fb14
+      -->
48fb14
+      <default>[be,csb,cv,et,ka,kk,ky,lt,lv,pl,ru,tt,uk,uz]</default>
48fb14
+      <locale name="C">
48fb14
+        <short>List of European languages on ibus-setup</short>
db6c98
+           <long>ibus-setup shows the languages only in input method list
48fb14
+                  when you run ibus-setup on one of the languages.
48fb14
+                  Other languages are hidden under an extended button.</long>
48fb14
+      </locale>
48fb14
+    </schema>
48fb14
+    <schema>
db6c98
+      <key>/schemas/desktop/ibus/general/xkblayoutconfig/north_europe</key>
db6c98
+      <applyto>/desktop/ibus/general/xkblayoutconfig/north_europe</applyto>
48fb14
+      <owner>ibus</owner>
48fb14
+      <type>list</type>
48fb14
+      <list_type>string</list_type>
48fb14
+      
48fb14
+      <default>[dk,fi,fo,is,no,no(smi),se]</default>
48fb14
+      -->
48fb14
+      <default>[da,fi,fo,is,no,se,sv]</default>
48fb14
+      <locale name="C">
48fb14
+        <short>List of European languages on ibus-setup</short>
db6c98
+           <long>ibus-setup shows the languages only in input method list
48fb14
+                  when you run ibus-setup on one of the languages.
48fb14
+                  Other languages are hidden under an extended button.</long>
48fb14
+      </locale>
48fb14
+    </schema>
48fb14
+    <schema>
db6c98
+      <key>/schemas/desktop/ibus/general/xkblayoutconfig/west_asia</key>
db6c98
+      <applyto>/desktop/ibus/general/xkblayoutconfig/west_asia</applyto>
48fb14
+      <owner>ibus</owner>
48fb14
+      <type>list</type>
48fb14
+      <list_type>string</list_type>
48fb14
+      
48fb14
+      <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>
48fb14
+      -->
48fb14
+      <default>[am,ar,az,ber,fa,ha,he,hy,ig,ku,tg,tr,yo]</default>
48fb14
+      <locale name="C">
48fb14
+        <short>List of Asian languages on ibus-setup</short>
db6c98
+           <long>ibus-setup shows the languages only in input method list
48fb14
+                  when you run ibus-setup on one of the languages.
48fb14
+                  Other languages are hidden under an extended button.</long>
48fb14
+      </locale>
48fb14
+    </schema>
48fb14
+    <schema>
db6c98
+      <key>/schemas/desktop/ibus/general/xkblayoutconfig/center_asia</key>
db6c98
+      <applyto>/desktop/ibus/general/xkblayoutconfig/center_asia</applyto>
48fb14
+      <owner>ibus</owner>
48fb14
+      <type>list</type>
48fb14
+      <list_type>string</list_type>
48fb14
+      
48fb14
+      <default>[cn(tib)]</default>
48fb14
+      -->
48fb14
+      <default>[bo,zh]</default>
48fb14
+      <locale name="C">
48fb14
+        <short>List of Asian languages on ibus-setup</short>
db6c98
+           <long>ibus-setup shows the languages only in input method list
48fb14
+                  when you run ibus-setup on one of the languages.
48fb14
+                  Other languages are hidden under an extended button.</long>
48fb14
+      </locale>
48fb14
+    </schema>
48fb14
+    <schema>
db6c98
+      <key>/schemas/desktop/ibus/general/xkblayoutconfig/east_asia</key>
db6c98
+      <applyto>/desktop/ibus/general/xkblayoutconfig/east_asia</applyto>
48fb14
+      <owner>ibus</owner>
48fb14
+      <type>list</type>
48fb14
+      <list_type>string</list_type>
48fb14
+      
48fb14
+      <default>[bt,kh,la,mal,mm,th,vn]</default>
48fb14
+      -->
48fb14
+      <default>[dz,km,lo,my,th,vi]</default>
48fb14
+      <locale name="C">
48fb14
+        <short>List of Asian languages on ibus-setup</short>
db6c98
+           <long>ibus-setup shows the languages only in input method list
48fb14
+                  when you run ibus-setup on one of the languages.
48fb14
+                  Other languages are hidden under an extended button.</long>
48fb14
+      </locale>
48fb14
+    </schema>
48fb14
+    <schema>
db6c98
+      <key>/schemas/desktop/ibus/general/xkblayoutconfig/india</key>
db6c98
+      <applyto>/desktop/ibus/general/xkblayoutconfig/india</applyto>
48fb14
+      <owner>ibus</owner>
48fb14
+      <type>list</type>
48fb14
+      <list_type>string</list_type>
48fb14
+      
48fb14
+      <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>
48fb14
+      -->
48fb14
+      <default>[bn,dv,gu,hi,kn,ml,ne,or,pa,si,ta,te,ur]</default>
48fb14
+      <locale name="C">
48fb14
+        <short>List of Asian languages on ibus-setup</short>
db6c98
+           <long>ibus-setup shows the languages only in input method list
48fb14
+                  when you run ibus-setup on one of the languages.
48fb14
+                  Other languages are hidden under an extended button.</long>
48fb14
+      </locale>
48fb14
+    </schema>
48fb14
+    <schema>
db6c98
+      <key>/schemas/desktop/ibus/general/xkblayoutconfig/australia</key>
db6c98
+      <applyto>/desktop/ibus/general/xkblayoutconfig/australia</applyto>
48fb14
+      <owner>ibus</owner>
48fb14
+      <type>list</type>
48fb14
+      <list_type>string</list_type>
48fb14
+      
48fb14
+      <default>[mao]</default>
48fb14
+      -->
48fb14
+      <default>[mi]</default>
48fb14
+      <locale name="C">
48fb14
+        <short>List of Asian languages on ibus-setup</short>
db6c98
+           <long>ibus-setup shows the languages only in input method list
48fb14
+                  when you run ibus-setup on one of the languages.
48fb14
+                  Other languages are hidden under an extended button.</long>
48fb14
+      </locale>
48fb14
+    </schema>
48fb14
+    <schema>
db6c98
       <key>/schemas/desktop/ibus/panel/custom_font</key>
db6c98
       <applyto>/desktop/ibus/panel/custom_font</applyto>
48fb14
       <owner>ibus</owner>
48fb14
diff --git a/setup/enginecombobox.py b/setup/enginecombobox.py
db31e5
index f80b164..578098c 100644
48fb14
--- a/setup/enginecombobox.py
48fb14
+++ b/setup/enginecombobox.py
db6c98
@@ -45,6 +45,9 @@ class EngineComboBox(Gtk.ComboBox):
48fb14
         self.connect("notify::active", self.__notify_active_cb)
48fb14
 
48fb14
         self.__model = None
48fb14
+        self.__all_model = None
48fb14
+        self.__config = None
48fb14
+        self.__show_sub_lang = False
48fb14
 
db6c98
         renderer = Gtk.CellRendererPixbuf()
48fb14
         renderer.set_property("xalign", 0)
db31e5
@@ -58,20 +61,51 @@ class EngineComboBox(Gtk.ComboBox):
48fb14
         self.pack_start(renderer, True)
db6c98
         self.set_cell_data_func(renderer, self.__name_cell_data_cb, None)
48fb14
 
48fb14
-    def set_engines(self, engines):
db6c98
-        self.__model = Gtk.TreeStore(object)
48fb14
+    def __gconf_get_lang_list_from_locale(self):
48fb14
+        common_list = ['en', 'Other']
48fb14
+        if  self.__config == None:
48fb14
+            return None
48fb14
+        loc = None
48fb14
+        try:
db6c98
+           loc = locale.setlocale (locale.LC_ALL)
48fb14
+        except:
48fb14
+            pass
48fb14
+        if loc == None:
48fb14
+            return common_list
db6c98
+        current_lang = IBus.get_language_name(loc)
48fb14
+        if current_lang == None:
48fb14
+            return common_list
db6c98
+        group_list = self.__config.get_value("general/xkblayoutconfig",
db6c98
+                                             "group_list")
48fb14
+        if group_list == None:
48fb14
+            return [loc] + common_list
48fb14
+        group_list = list(group_list)
48fb14
+        lang_list = None
48fb14
+        for group in group_list:
48fb14
+            group = str(group)
db6c98
+            langs = list(self.__config.get_value("general/xkblayoutconfig",
db6c98
+                                                  group))
48fb14
+            for lang in langs:
48fb14
+                lang = str(lang)
db6c98
+                if current_lang == IBus.get_language_name(lang):
48fb14
+                    lang_list = langs
48fb14
+                    break
48fb14
+            if lang_list != None:
48fb14
+                break
48fb14
+        if lang_list == None:
48fb14
+            return [loc] + common_list
48fb14
+        return lang_list + common_list
095f9c
 
095f9c
-        iter1 = self.__model.append(None)
095f9c
-        self.__model.set(iter1, 0, 0)
db6c98
-        langs = {}
095f9c
-        for e in engines:
db6c98
-            l = IBus.get_language_name(e.get_language())
db6c98
-            if l == None:
db6c98
-                l = ""
db6c98
-            if l not in langs:
db6c98
-                langs[l] = []
db6c98
-            langs[l].append(e)
48fb14
+    def __has_engine_in_lang_list(self, engine, lang_list):
48fb14
+        retval = False
48fb14
+        for lang in lang_list:
db6c98
+            if IBus.get_language_name(lang) == \
db6c98
+                IBus.get_language_name(engine.props.language):
48fb14
+                retval = True
48fb14
+                break
48fb14
+        return retval
48fb14
 
db6c98
+    def __model_append_langs(self, model, langs, visible):
db6c98
         keys = langs.keys()
48fb14
         keys.sort(locale.strcoll)
7bcb69
         loc = locale.getlocale()[0]
db31e5
@@ -89,29 +123,86 @@ class EngineComboBox(Gtk.ComboBox):
db6c98
             keys.remove(IBus.get_language_name("Other"))
db6c98
             keys += [IBus.get_language_name("Other")]
48fb14
         for l in keys:
48fb14
-            iter1 = self.__model.append(None)
48fb14
-            self.__model.set(iter1, 0, l)
48fb14
+            iter1 = model.append(None)
48fb14
+            model.set(iter1, 0, l)
48fb14
             def cmp_engine(a, b):
db6c98
                 if a.get_rank() == b.get_rank():
db6c98
                     return locale.strcoll(a.get_longname(), b.get_longname())
db6c98
                 return int(b.get_rank() - a.get_rank())
db6c98
             langs[l].sort(cmp_engine)
db6c98
             for e in langs[l]:
48fb14
-                iter2 = self.__model.append(iter1)
48fb14
-                self.__model.set(iter2, 0, e)
48fb14
+                iter2 = model.append(iter1)
48fb14
+                model.set(iter2, 0, e)
48fb14
+
48fb14
+    def set_engines(self, engines):
db6c98
+        self.__model = Gtk.TreeStore(object)
095f9c
+
48fb14
+        iter1 = self.__model.append(None)
48fb14
+        self.__model.set(iter1, 0, 0)
48fb14
+        lang_list = self.__gconf_get_lang_list_from_locale()
48fb14
+        lang = {}
48fb14
+        sub_lang = {}
48fb14
+        for e in engines:
db6c98
+            l = IBus.get_language_name(e.props.language)
48fb14
+            if lang_list == None or \
48fb14
+                self.__has_engine_in_lang_list(e, lang_list):
48fb14
+                if l not in lang:
48fb14
+                    lang[l] = []
48fb14
+                lang[l].append(e)
48fb14
+            else:
48fb14
+                if l not in sub_lang:
48fb14
+                    sub_lang[l] = []
48fb14
+                sub_lang[l].append(e)
48fb14
+
48fb14
+        self.__model_append_langs(self.__model, lang, True)
48fb14
+        iter1 = self.__model.append(None)
48fb14
+        self.__model.set(iter1, 0, -1)
7bcb69
+
db6c98
+        self.__all_model = Gtk.TreeStore(object)
48fb14
+        iter1 = self.__all_model.append(None)
48fb14
+        self.__all_model.set(iter1, 0, 0)
48fb14
+        self.__model_append_langs(self.__all_model, lang, False)
48fb14
+        iter1 = self.__all_model.append(None)
48fb14
+        self.__all_model.set(iter1, 0, -1)
48fb14
+        self.__model_append_langs(self.__all_model, sub_lang, False)
48fb14
+
48fb14
+        self.__toggle_sub_lang()
7bcb69
 
7bcb69
-        self.set_model(self.__model)
48fb14
+    def __toggle_sub_lang(self):
48fb14
+        self.set_model(None)
48fb14
+        if self.__show_sub_lang:
48fb14
+            self.set_model(self.__all_model)
48fb14
+        else:
48fb14
+            self.set_model(self.__model)
48fb14
         self.set_active(0)
48fb14
 
db6c98
     def __icon_cell_data_cb(self, celllayout, renderer, model, iter, data):
48fb14
-        engine = self.__model.get_value(iter, 0)
48fb14
+        model = self.get_model()
48fb14
+        engine = model.get_value(iter, 0)
48fb14
 
48fb14
         if isinstance(engine, str) or isinstance (engine, unicode):
48fb14
             renderer.set_property("visible", False)
48fb14
             renderer.set_property("sensitive", False)
48fb14
         elif isinstance(engine, int):
48fb14
-            renderer.set_property("visible", False)
48fb14
-            renderer.set_property("sensitive", False)
48fb14
+            if engine == 0:
48fb14
+                renderer.set_property("visible", False)
48fb14
+                renderer.set_property("sensitive", False)
48fb14
+                renderer.set_property("pixbuf", None)
48fb14
+            elif engine < 0:
48fb14
+                if not self.__show_sub_lang:
19c65a
+                    pixbuf = load_icon("go-bottom", Gtk.IconSize.LARGE_TOOLBAR)
48fb14
+                else:
19c65a
+                    pixbuf = load_icon("go-up", Gtk.IconSize.LARGE_TOOLBAR)
48fb14
+                if pixbuf == None:
db6c98
+                    pixbuf = load_icon(Gtk.STOCK_MISSING_IMAGE,
db6c98
+                                       Gtk.IconSize.LARGE_TOOLBAR)
48fb14
+                if pixbuf == None:
48fb14
+                    renderer.set_property("visible", False)
48fb14
+                    renderer.set_property("sensitive", False)
48fb14
+                    return
48fb14
+                renderer.set_property("visible", True)
48fb14
+                renderer.set_property("sensitive", True)
48fb14
+                renderer.set_property("pixbuf", pixbuf)
48fb14
         else:
48fb14
             renderer.set_property("visible", True)
48fb14
             renderer.set_property("sensitive", True)
db31e5
@@ -124,7 +215,8 @@ class EngineComboBox(Gtk.ComboBox):
48fb14
             renderer.set_property("pixbuf", pixbuf)
48fb14
 
db6c98
     def __name_cell_data_cb(self, celllayout, renderer, model, iter, data):
48fb14
-        engine = self.__model.get_value(iter, 0)
48fb14
+        model = self.get_model()
48fb14
+        engine = model.get_value(iter, 0)
48fb14
 
48fb14
         if isinstance (engine, str) or isinstance (engine, unicode):
48fb14
             renderer.set_property("sensitive", False)
db31e5
@@ -132,8 +224,15 @@ class EngineComboBox(Gtk.ComboBox):
db6c98
             renderer.set_property("weight", Pango.Weight.NORMAL)
48fb14
         elif isinstance(engine, int):
48fb14
             renderer.set_property("sensitive", True)
db6c98
-            renderer.set_property("text", _("Select an input method"))
db6c98
-            renderer.set_property("weight", Pango.Weight.NORMAL)
48fb14
+            if engine == 0:
db6c98
+                renderer.set_property("text", _("Select an input method"))
db6c98
+                renderer.set_property("weight", Pango.Weight.NORMAL)
48fb14
+            elif engine < 0:
48fb14
+                if not self.__show_sub_lang:
692f6c
+                    renderer.set_property("text", _("Show all input methods"))
48fb14
+                else:
692f6c
+                    renderer.set_property("text", _("Show only input methods for your region"))
db6c98
+                renderer.set_property("weight", Pango.Weight.BOLD)
48fb14
         else:
48fb14
             renderer.set_property("sensitive", True)
db6c98
             renderer.set_property("text", engine.get_longname())
db31e5
@@ -149,10 +248,18 @@ class EngineComboBox(Gtk.ComboBox):
48fb14
             if i == 0 or i == -1:
48fb14
                 return None
48fb14
             iter = self.get_active_iter()
48fb14
-            return self.get_model()[iter][0]
48fb14
+            model = self.get_model()
48fb14
+            if model[iter][0] == -1:
48fb14
+                self.__show_sub_lang = not self.__show_sub_lang
48fb14
+                self.__toggle_sub_lang()
48fb14
+                return None
48fb14
+            return model[iter][0]
48fb14
         else:
48fb14
             raise AttributeError, 'unknown property %s' % property.name
48fb14
 
48fb14
+    def set_config(self, config):
48fb14
+        self.__config = config
48fb14
+
db6c98
     def get_active_engine(self):
db6c98
         return self.get_property("active-engine")
48fb14
 
48fb14
diff --git a/setup/main.py b/setup/main.py
a208e6
index 5da6340..d6fa3ef 100644
48fb14
--- a/setup/main.py
48fb14
+++ b/setup/main.py
717e5a
@@ -224,6 +224,7 @@ class Setup(object):
2ed8a1
                 engines.append(engine)
db6c98
 
48fb14
         self.__combobox = self.__builder.get_object("combobox_engines")
48fb14
+        self.__combobox.set_config(self.__config)
19c65a
         self.__combobox.set_engines(engines)
48fb14
 
19c65a
         engine_names = values.get("preload_engines", [])
48fb14
-- 
a208e6
1.8.0
48fb14