Support enable/disable hotkeys that enable or disable ibus unconditionally (i.e....
authorYusuke Sato <yusukes@chromium.org>
Fri, 11 Feb 2011 14:48:42 +0000 (23:48 +0900)
committerYusuke Sato <yusukes@chromium.org>
Fri, 11 Feb 2011 14:48:42 +0000 (23:48 +0900)
I'll update ibus/po/*po files if the change looks good to you.

BUG=http://code.google.com/p/ibus/issues/detail?id=1173
TEST=manually

Review URL: http://codereview.appspot.com/3807047

bus/ibusimpl.c
ibus/common.py
setup/main.py
setup/setup.ui

index cbcf7f426dc4b2603f87e514e8131fc3b9769489..79dbf2762b02fe60fe7e971894d453dda4e479c2 100644 (file)
@@ -319,6 +319,32 @@ bus_ibus_impl_set_trigger (BusIBusImpl *ibus,
 #endif
 }
 
+/**
+ * bus_ibus_impl_set_enable_unconditional:
+ *
+ * A function to be called when "enable_unconditional" config is updated.
+ */
+static void
+bus_ibus_impl_set_enable_unconditional (BusIBusImpl *ibus,
+                                        GVariant    *value)
+{
+    GQuark hotkey = g_quark_from_static_string ("enable-unconditional");
+    bus_ibus_impl_set_hotkey (ibus, hotkey, value);
+}
+
+/**
+ * bus_ibus_impl_set_disable_unconditional:
+ *
+ * A function to be called when "disable_unconditional" config is updated.
+ */
+static void
+bus_ibus_impl_set_disable_unconditional (BusIBusImpl *ibus,
+                                         GVariant    *value)
+{
+    GQuark hotkey = g_quark_from_static_string ("disable-unconditional");
+    bus_ibus_impl_set_hotkey (ibus, hotkey, value);
+}
+
 /**
  * bus_ibus_impl_set_next_engine_in_menu:
  *
@@ -544,14 +570,16 @@ const static struct {
     gchar *key;
     void (*func) (BusIBusImpl *, GVariant *);
 } bus_ibus_impl_config_items [] = {
-    { "general/hotkey", "trigger",              bus_ibus_impl_set_trigger },
-    { "general/hotkey", "next_engine_in_menu",  bus_ibus_impl_set_next_engine_in_menu },
-    { "general/hotkey", "previous_engine",      bus_ibus_impl_set_previous_engine },
-    { "general", "preload_engines",             bus_ibus_impl_set_preload_engines },
-    { "general", "use_system_keyboard_layout",  bus_ibus_impl_set_use_sys_layout },
-    { "general", "use_global_engine",           bus_ibus_impl_set_use_global_engine },
-    { "general", "embed_preedit_text",          bus_ibus_impl_set_embed_preedit_text },
-    { "general", "enable_by_default",           bus_ibus_impl_set_enable_by_default },
+    { "general/hotkey", "trigger",               bus_ibus_impl_set_trigger },
+    { "general/hotkey", "enable_unconditional",  bus_ibus_impl_set_enable_unconditional },
+    { "general/hotkey", "disable_unconditional", bus_ibus_impl_set_disable_unconditional },
+    { "general/hotkey", "next_engine_in_menu",   bus_ibus_impl_set_next_engine_in_menu },
+    { "general/hotkey", "previous_engine",       bus_ibus_impl_set_previous_engine },
+    { "general", "preload_engines",              bus_ibus_impl_set_preload_engines },
+    { "general", "use_system_keyboard_layout",   bus_ibus_impl_set_use_sys_layout },
+    { "general", "use_global_engine",            bus_ibus_impl_set_use_global_engine },
+    { "general", "embed_preedit_text",           bus_ibus_impl_set_embed_preedit_text },
+    { "general", "enable_by_default",            bus_ibus_impl_set_enable_by_default },
 };
 
 /**
@@ -1900,6 +1928,8 @@ bus_ibus_impl_filter_keyboard_shortcuts (BusIBusImpl     *ibus,
                                          guint           prev_modifiers)
 {
     static GQuark trigger = 0;
+    static GQuark enable_unconditional = 0;
+    static GQuark disable_unconditional = 0;
     static GQuark next = 0;
     static GQuark previous = 0;
 
@@ -1908,6 +1938,8 @@ bus_ibus_impl_filter_keyboard_shortcuts (BusIBusImpl     *ibus,
 
     if (trigger == 0) {
         trigger = g_quark_from_static_string ("trigger");
+        enable_unconditional = g_quark_from_static_string ("enable-unconditional");
+        disable_unconditional = g_quark_from_static_string ("disable-unconditional");
         next = g_quark_from_static_string ("next-engine-in-menu");
         previous = g_quark_from_static_string ("previous-engine");
     }
@@ -1930,6 +1962,20 @@ bus_ibus_impl_filter_keyboard_shortcuts (BusIBusImpl     *ibus,
         }
         return (enabled != bus_input_context_is_enabled (context));
     }
+    if (event == enable_unconditional) {
+        gboolean enabled = bus_input_context_is_enabled (context);
+        if (!enabled) {
+            bus_input_context_enable (context);
+        }
+        return bus_input_context_is_enabled (context);
+    }
+    if (event == disable_unconditional) {
+        gboolean enabled = bus_input_context_is_enabled (context);
+        if (enabled) {
+            bus_input_context_disable (context);
+        }
+        return !bus_input_context_is_enabled (context);
+    }
     if (event == next) {
         if (bus_input_context_is_enabled (context)) {
             bus_ibus_impl_context_request_next_engine_in_menu (ibus, context);
index 763ed1c999339518a75b7107613e9c2ccbfed9ae..e105f1809d180afb66bb8c6c1a5e8510ed55be25 100644 (file)
@@ -36,10 +36,9 @@ __all__ = (
         "default_reply_handler",
         "default_error_handler",
         "DEFAULT_ASYNC_HANDLERS",
-        "CONFIG_GENERAL_SHORTCUT_TRIGGER",
-        "CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE",
-        "CONFIG_GENERAL_SHORTCUT_PREV_ENGINE",
         "CONFIG_GENERAL_SHORTCUT_TRIGGER_DEFAULT",
+        "CONFIG_GENERAL_SHORTCUT_ENABLE_DEFAULT",
+        "CONFIG_GENERAL_SHORTCUT_DISABLE_DEFAULT",
         "CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE_DEFAULT",
         "CONFIG_GENERAL_SHORTCUT_PREV_ENGINE_DEFAULT",
         "main",
@@ -144,14 +143,13 @@ DEFAULT_ASYNC_HANDLERS = {
     "error_handler" : default_error_handler
 }
 
-CONFIG_GENERAL_SHORTCUT_TRIGGER     = "/general/keyboard_shortcut_trigger"
 CONFIG_GENERAL_SHORTCUT_TRIGGER_DEFAULT = [
     "Control+space",
     "Zenkaku_Hankaku",
     "Hangul"]
-CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE = "/general/keyboard_shortcut_next_engine"
+CONFIG_GENERAL_SHORTCUT_ENABLE_DEFAULT = []
+CONFIG_GENERAL_SHORTCUT_DISABLE_DEFAULT = []
 CONFIG_GENERAL_SHORTCUT_NEXT_ENGINE_DEFAULT = []
-CONFIG_GENERAL_SHORTCUT_PREV_ENGINE = "/general/keyboard_shortcut_prev_engine"
 CONFIG_GENERAL_SHORTCUT_PREV_ENGINE_DEFAULT = []
 
 __mainloop = None
index 96e94568ec7763faef80e718f4c8c01f3e87fd34..a22bb0c3ef87464044e329aed3af415087ce4b6b 100644 (file)
@@ -101,6 +101,28 @@ class Setup(object):
         button.connect("clicked", self.__shortcut_button_clicked_cb,
                     N_("trigger"), "general/hotkey", "trigger", entry)
 
+        # enable (unconditional)
+        shortcuts = self.__config.get_value(
+                        "general/hotkey", "enable_unconditional",
+                        ibus.CONFIG_GENERAL_SHORTCUT_ENABLE_DEFAULT)
+        button = self.__builder.get_object("button_enable")
+        entry = self.__builder.get_object("entry_enable")
+        entry.set_text("; ".join(shortcuts))
+        entry.set_tooltip_text("\n".join(shortcuts))
+        button.connect("clicked", self.__shortcut_button_clicked_cb,
+                    N_("enable"), "general/hotkey", "enable_unconditional", entry)
+
+        # disable (unconditional)
+        shortcuts = self.__config.get_value(
+                        "general/hotkey", "disable_unconditional",
+                        ibus.CONFIG_GENERAL_SHORTCUT_DISABLE_DEFAULT)
+        button = self.__builder.get_object("button_disable")
+        entry = self.__builder.get_object("entry_disable")
+        entry.set_text("; ".join(shortcuts))
+        entry.set_tooltip_text("\n".join(shortcuts))
+        button.connect("clicked", self.__shortcut_button_clicked_cb,
+                    N_("disable"), "general/hotkey", "disable_unconditional", entry)
+
         # next engine
         shortcuts = self.__config.get_value(
                         "general/hotkey", "next_engine_in_menu",
index 0e31a78f3ec320abe4ca3ae60b6da6b7bde7b35e..0a69df8c1e093786de434709feb49eeeab18a34c 100644 (file)
                             <child>
                               <object class="GtkTable" id="table1">
                                 <property name="visible">True</property>
-                                <property name="n_rows">3</property>
+                                <property name="n_rows">5</property>
                                 <property name="n_columns">2</property>
                                 <property name="column_spacing">12</property>
                                 <property name="row_spacing">6</property>
-                                <child>
-                                  <object class="GtkLabel" id="label7">
-                                    <property name="visible">True</property>
-                                    <property name="tooltip_text" translatable="yes">The shortcut keys for turning input method on or off</property>
-                                    <property name="xalign">0</property>
-                                    <property name="label" translatable="yes">Enable or disable:</property>
-                                  </object>
-                                  <packing>
-                                    <property name="x_options">GTK_FILL</property>
-                                    <property name="y_options">GTK_FILL</property>
-                                  </packing>
-                                </child>
                                 <child>
                                   <object class="GtkLabel" id="label8">
                                     <property name="visible">True</property>
                                     <property name="label" translatable="yes">Next input method:</property>
                                   </object>
                                   <packing>
-                                    <property name="top_attach">1</property>
-                                    <property name="bottom_attach">2</property>
+                                    <property name="top_attach">3</property>
+                                    <property name="bottom_attach">4</property>
                                     <property name="x_options">GTK_FILL</property>
                                     <property name="y_options">GTK_FILL</property>
                                   </packing>
                                     <property name="label" translatable="yes">Previous input method:</property>
                                   </object>
                                   <packing>
-                                    <property name="top_attach">2</property>
-                                    <property name="bottom_attach">3</property>
+                                    <property name="top_attach">4</property>
+                                    <property name="bottom_attach">5</property>
                                     <property name="x_options">GTK_FILL</property>
                                     <property name="y_options">GTK_FILL</property>
                                   </packing>
                                   <packing>
                                     <property name="left_attach">1</property>
                                     <property name="right_attach">2</property>
-                                    <property name="top_attach">1</property>
-                                    <property name="bottom_attach">2</property>
+                                    <property name="top_attach">3</property>
+                                    <property name="bottom_attach">4</property>
                                   </packing>
                                 </child>
                                 <child>
                                       </packing>
                                     </child>
                                   </object>
+                                  <packing>
+                                    <property name="left_attach">1</property>
+                                    <property name="right_attach">2</property>
+                                    <property name="top_attach">4</property>
+                                    <property name="bottom_attach">5</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel" id="label7">
+                                    <property name="visible">True</property>
+                                    <property name="tooltip_text" translatable="yes">The shortcut keys for turning input method on or off</property>
+                                    <property name="xalign">0</property>
+                                    <property name="label" translatable="yes">Enable or disable:</property>
+                                  </object>
+                                  <packing>
+                                    <property name="x_options">GTK_FILL</property>
+                                    <property name="y_options">GTK_FILL</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel" id="label18">
+                                    <property name="visible">True</property>
+                                    <property name="xalign">0</property>
+                                    <property name="label" translatable="yes">Enable:</property>
+                                  </object>
+                                  <packing>
+                                    <property name="top_attach">1</property>
+                                    <property name="bottom_attach">2</property>
+                                    <property name="x_options">GTK_FILL</property>
+                                    <property name="y_options">GTK_FILL</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkHBox" id="hbox2">
+                                    <property name="visible">True</property>
+                                    <property name="spacing">6</property>
+                                    <child>
+                                      <object class="GtkEntry" id="entry_enable">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="editable">False</property>
+                                      </object>
+                                      <packing>
+                                        <property name="position">0</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkButton" id="button_enable">
+                                        <property name="label" translatable="yes">...</property>
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="receives_default">True</property>
+                                        <property name="use_underline">True</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="position">1</property>
+                                      </packing>
+                                    </child>
+                                  </object>
+                                  <packing>
+                                    <property name="left_attach">1</property>
+                                    <property name="right_attach">2</property>
+                                    <property name="top_attach">1</property>
+                                    <property name="bottom_attach">2</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkLabel" id="label19">
+                                    <property name="visible">True</property>
+                                    <property name="xalign">0</property>
+                                    <property name="label" translatable="yes">Disable:</property>
+                                  </object>
+                                  <packing>
+                                    <property name="top_attach">2</property>
+                                    <property name="bottom_attach">3</property>
+                                    <property name="x_options">GTK_FILL</property>
+                                    <property name="y_options">GTK_FILL</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <object class="GtkHBox" id="hbox3">
+                                    <property name="visible">True</property>
+                                    <property name="spacing">6</property>
+                                    <child>
+                                      <object class="GtkEntry" id="entry_disable">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="editable">False</property>
+                                      </object>
+                                      <packing>
+                                        <property name="position">0</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkButton" id="button_disable">
+                                        <property name="label" translatable="yes">...</property>
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">True</property>
+                                        <property name="receives_default">True</property>
+                                        <property name="use_underline">True</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="position">1</property>
+                                      </packing>
+                                    </child>
+                                  </object>
                                   <packing>
                                     <property name="left_attach">1</property>
                                     <property name="right_attach">2</property>