Skip to content

Commit

Permalink
Reload preload engines until users customize the list.
Browse files Browse the repository at this point in the history
The idea is, if users don't customize the preload_engines with ibus-setup,
users would prefer to load the system default engines again by login.
The gconf value 'preload_engine_mode' is
IBUS_PRELOAD_ENGINE_MODE_USER by default but set
IBUS_PRELOAD_ENGINE_MODE_LANG_RELATIVE for the initial login.
If preload_engine_mode is IBUS_PRELOAD_ENGINE_MODE_LANG_RELATIVE,
ibus-daemon loads the system preload engines by langs.
If preload_engine_mode is IBUS_PRELOAD_ENGINE_MODE_USER,
ibus-daemon do not update the gconf value preload_engines.
On the other hand, if users enable the customized engine checkbutton
on ibus-setup, ibus-setup sets 'preload_engine_mode' as
IBUS_PRELOAD_ENGINE_MODE_USER and users can customize the value
'preload_engines'.
  • Loading branch information
fujiwarat committed Jan 31, 2013
1 parent a72989e commit f07be51
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 11 deletions.
24 changes: 24 additions & 0 deletions data/ibus-xkb.schemas.in
@@ -1,6 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<gconfschemafile>
<schemalist>
<schema>
<key>/schemas/desktop/ibus/general/preload_engine_mode</key>
<applyto>/desktop/ibus/general/preload_engine_mode</applyto>
<owner>ibus</owner>
<type>int</type>
<default>0</default>
<locale name="C">
<short>Preload engine mode</short>
<long>Preload engines are loaded with this mode.
0 = user customized engines.
1 = language related engines.</long>
</locale>
</schema>
<schema>
<key>/schemas/desktop/ibus/general/preload_engines_inited</key>
<applyto>/desktop/ibus/general/preload_engines_inited</applyto>
<owner>ibus</owner>
<type>bool</type>
<default>false</default>
<locale name="C">
<short>The key preload_engines is initialized</short>
<long>The key preload_engines is initialized</long>
</locale>
</schema>
<schema>
<key>/schemas/desktop/ibus/general/use_xmodmap</key>
<applyto>/desktop/ibus/general/use_xmodmap</applyto>
Expand Down
74 changes: 66 additions & 8 deletions setup/main.py
Expand Up @@ -29,6 +29,7 @@
from gi.repository import GLib
from gi.repository import Gtk
from gi.repository import IBus
from gi.repository import IBusXKB
from os import path
from xdg import BaseDirectory

Expand Down Expand Up @@ -191,16 +192,27 @@ def __init_general(self):
self.__checkbutton_use_global_engine.connect("toggled",
self.__checkbutton_use_global_engine_toggled_cb)

# set preload mode
preload_engine_mode = IBusXKB.PreloadEngineMode.USER
variant = self.__config.get_value("general", "preload_engine_mode")
if variant != None:
preload_engine_mode = variant.get_int32()
button = self.__builder.get_object("checkbutton_preload_engine_mode")
if preload_engine_mode == IBusXKB.PreloadEngineMode.USER:
button.set_active(True)
self.__builder.get_object("hbox_customize_active_input_methods").set_sensitive(True)
else:
button.set_active(False)
self.__builder.get_object("hbox_customize_active_input_methods").set_sensitive(False)
button.connect("toggled", self.__checkbutton_preload_engine_mode_toggled_cb)

# init engine page
self.__engines = self.__bus.list_engines()
self.__combobox = self.__builder.get_object("combobox_engines")
self.__combobox.set_engines(self.__engines)

tmp_dict = {}
for e in self.__engines:
tmp_dict[e.get_name()] = e
engine_names = values.get("preload_engines", [])
engines = [tmp_dict[name] for name in engine_names if name in tmp_dict]
engines = self.__get_engine_descs_from_names(engine_names)

self.__treeview = self.__builder.get_object("treeview_engines")
self.__treeview.set_engines(engines)
Expand Down Expand Up @@ -244,6 +256,7 @@ def __init_ui(self):
self.__checkbutton_auto_start_toggled_cb)

self.__config = self.__bus.get_config()
self.__config.connect("value-changed", self.__config_value_changed_cb)

self.__init_hotkey()
self.__init_panel()
Expand All @@ -252,8 +265,8 @@ def __init_ui(self):
def __combobox_notify_active_engine_cb(self, combobox, property):
engine = self.__combobox.get_active_engine()
button = self.__builder.get_object("button_engine_add")
button.set_sensitive(
engine != None and engine not in self.__treeview.get_engines())
button.set_sensitive(engine != None and \
engine.get_name() not in map(lambda e: e.get_name(), self.__treeview.get_engines()))

def __get_engine_setup_exec_args(self, engine):
args = []
Expand All @@ -273,6 +286,13 @@ def __get_engine_setup_exec_args(self, engine):
args.append(path.basename(setup_path))
return args

def __get_engine_descs_from_names(self, engine_names):
tmp_dict = {}
for e in self.__engines:
tmp_dict[e.get_name()] = e
engines = [tmp_dict[name] for name in engine_names if name in tmp_dict]
return engines

def __treeview_notify_cb(self, treeview, prop):
if prop.name not in ("active-engine", "engines"):
return
Expand Down Expand Up @@ -325,6 +345,34 @@ def __button_engine_preferences_cb(self, button):
del self.__engine_setup_exec_list[name]
self.__engine_setup_exec_list[name] = os.spawnl(os.P_NOWAIT, *args)

def __checkbutton_preload_engine_mode_toggled_cb(self, button):
if button.get_active():
variant = GLib.Variant.new_int32(IBusXKB.PreloadEngineMode.USER)
self.__config.set_value("general",
"preload_engine_mode",
variant)
self.__builder.get_object("hbox_customize_active_input_methods").set_sensitive(True)
self.__treeview.notify("engines")
else:
message = _("The list of your saved input methods will be " \
"cleared immediately and the list will be " \
"configured by the login language every time. " \
"Do you agree with this?")
dlg = Gtk.MessageDialog(type = Gtk.MessageType.QUESTION,
buttons = Gtk.ButtonsType.YES_NO,
message_format = message)
id = dlg.run()
dlg.destroy()
self.__flush_gtk_events()
if id != Gtk.ResponseType.YES:
button.set_active(True)
return
variant = GLib.Variant.new_int32(IBusXKB.PreloadEngineMode.LANG_RELATIVE)
self.__config.set_value("general",
"preload_engine_mode",
variant)
self.__builder.get_object("hbox_customize_active_input_methods").set_sensitive(False)

def __init_bus(self):
self.__bus = IBus.Bus()
if self.__bus.is_connected():
Expand Down Expand Up @@ -539,8 +587,18 @@ def __checkbutton_use_global_engine_toggled_cb(self, button):
value = GLib.Variant.new_boolean(value)
self.__config.set_value("general", "use_global_engine", value)

def __config_value_changed_cb(self, bus, section, name, value):
pass
def __config_value_changed_cb(self, bus, section, name, variant):
if section == 'general' and name == 'preload_engines':
value = []
if variant != None:
value = variant.unpack()
engines = self.__get_engine_descs_from_names(value)
current_engines = self.__treeview.get_engines()
engines_csv = str.join(',', map(lambda e: e.get_name(), engines))
current_engines_csv = \
str.join(',', map(lambda e: e.get_name(), current_engines))
if engines_csv != current_engines_csv:
self.__treeview.set_engines(engines)

def __config_reloaded_cb(self, bus):
pass
Expand Down
22 changes: 19 additions & 3 deletions setup/setup.ui
Expand Up @@ -669,7 +669,23 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkHBox" id="hbox1">
<object class="GtkCheckButton" id="checkbutton_preload_engine_mode">
<property name="visible">True</property>
<property name="label" translatable="yes">Customize active input _methods</property>
<property name="use_underline">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="tooltip_text" translatable="yes">Customize active input methods</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox_customize_active_input_methods">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
Expand Down Expand Up @@ -858,7 +874,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
<property name="position">1</property>
</packing>
</child>
<child>
Expand Down Expand Up @@ -905,7 +921,7 @@ You may use up/down buttons to change it.&lt;/i&gt;&lt;/small&gt;</property>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
<property name="position">2</property>
</packing>
</child>
</object>
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.am
Expand Up @@ -51,6 +51,7 @@ ibus_xkb_common_sources = \
ibusxkbxml.c \
$(NULL)
ibus_xkb_common_headers = \
ibusxkbtypes.h \
ibusxkbxml.h \
$(NULL)
ibus_xkb_include_HEADERS = \
Expand Down
46 changes: 46 additions & 0 deletions src/ibusxkbtypes.h
@@ -0,0 +1,46 @@
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
/* vim:set et sts=4: */
/* ibus - The Input Bus
* Copyright (C) 2012 Takao Fujiwara <takao.fujiwara1@gmail.com>
* Copyright (C) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
* Copyright (C) 2008-2012 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/

/**
* SECTION: ibustypes
* @short_description: Generic types for IBus.
* @stability: Stable
*
* This section consists generic types for IBus, including shift/control key modifiers,
* and a rectangle structure.
*/
#ifndef __IBUS_XKBTYPES_H_
#define __IBUS_XKBTYPES_H_

/**
* IBusXKBPreloadEngineMode:
* @IBUS_XKB_PRELOAD_ENGINE_MODE_USER: user custimized engines
* @IBUS_XKB_PRELOAD_ENGINE_MODE_LANG_RELATIVE: language related engines.
*/
typedef enum {
IBUS_XKB_PRELOAD_ENGINE_MODE_USER = 0,
IBUS_XKB_PRELOAD_ENGINE_MODE_LANG_RELATIVE = 1,
} IBusXKBPreloadEngineMode;

#endif

0 comments on commit f07be51

Please sign in to comment.