Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

ibus-1.4.2-user-modifiable-shortcut.patch

By: a guest on Sep 4th, 2012  |  syntax: C  |  size: 11.32 KB  |  views: 44  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. diff -Naur ibus-1.4.2/bus/ibusimpl.c my-ibus/bus/ibusimpl.c
  2. --- ibus-1.4.2/bus/ibusimpl.c   2012-08-22 14:16:51.000000000 +0000
  3. +++ my-ibus/bus/ibusimpl.c      2012-09-04 09:42:47.349180087 +0000
  4. @@ -77,6 +77,7 @@
  5.      gchar *global_previous_engine_name;
  6.  
  7.      /* engine-specific hotkeys */
  8. +    GVariant        *saved_dynamic_hotkeys;
  9.      IBusHotkeyProfile *engines_hotkey_profile;
  10.      GHashTable      *hotkey_to_engines_map;
  11.  };
  12. @@ -139,6 +140,9 @@
  13.  static void     bus_ibus_impl_set_previous_engine
  14.                                                  (BusIBusImpl        *ibus,
  15.                                                   GVariant           *value);
  16. +static void     bus_ibus_impl_set_dynamic_engine
  17. +                                                (BusIBusImpl        *ibus,
  18. +                                                 GVariant           *value);
  19.  static void     bus_ibus_impl_set_preload_engines
  20.                                                  (BusIBusImpl        *ibus,
  21.                                                   GVariant           *value);
  22. @@ -384,6 +388,22 @@
  23.  }
  24.  
  25.  /**
  26. + * bus_ibus_impl_set_dynamic_engine:
  27. + *
  28. + * A function to be called when "dynamic_engine" config is updated.
  29. + */
  30. +static void
  31. +bus_ibus_impl_set_dynamic_engine (BusIBusImpl *ibus,
  32. +                                   GVariant    *value)
  33. +{
  34. +    if (value != NULL && g_variant_classify (value) == G_VARIANT_CLASS_ARRAY) {
  35. +        g_variant_ref (value);
  36. +        ibus->saved_dynamic_hotkeys = value;
  37. +        bus_ibus_impl_update_engines_hotkey_profile (ibus);
  38. +    }
  39. +}
  40. +
  41. +/**
  42.   * bus_ibus_impl_set_preload_engines:
  43.   *
  44.   * A function to be called when "preload_engines" config is updated.
  45. @@ -598,6 +618,7 @@
  46.      { "general/hotkey", "disable_unconditional", bus_ibus_impl_set_disable_unconditional },
  47.      { "general/hotkey", "next_engine_in_menu",   bus_ibus_impl_set_next_engine_in_menu },
  48.      { "general/hotkey", "previous_engine",       bus_ibus_impl_set_previous_engine },
  49. +    { "general/hotkey", "dynamic_engine",       bus_ibus_impl_set_dynamic_engine },
  50.      { "general", "preload_engines",              bus_ibus_impl_set_preload_engines },
  51.      { "general", "use_system_keyboard_layout",   bus_ibus_impl_set_use_sys_layout },
  52.      { "general", "use_global_engine",            bus_ibus_impl_set_use_global_engine },
  53. @@ -2337,6 +2358,39 @@
  54.  static void
  55.  bus_ibus_impl_update_engines_hotkey_profile (BusIBusImpl *ibus)
  56.  {
  57. +    GVariantIter iter;
  58. +    g_variant_iter_init (&iter, ibus->saved_dynamic_hotkeys);
  59. +    const gchar *dynamic_string = NULL;
  60. +    gchar **dynamic_string_list;
  61. +
  62. +    while (g_variant_iter_loop (&iter, "&s", &dynamic_string)) {
  63. +        GList *eng;
  64. +        const gchar *engine_to_change_name, *hotkeys;
  65. +
  66. +        dynamic_string_list = g_strsplit_set (dynamic_string, "=", 2);
  67. +        //Checks for illegal strings
  68. +        if ((! dynamic_string_list[0]) || (! dynamic_string_list[1])) {
  69. +            g_strfreev (dynamic_string_list);
  70. +            continue;
  71. +        }
  72. +
  73. +        engine_to_change_name = g_strstrip (dynamic_string_list[0]);
  74. +        hotkeys = g_strstrip (dynamic_string_list[1]);
  75. +
  76. +        for (eng = ibus->engine_list; eng; eng = eng->next) {
  77. +            IBusEngineDesc *engine;
  78. +            const gchar *engine_name;
  79. +
  80. +            engine = eng->data;
  81. +            engine_name = ibus_engine_desc_get_name(engine);
  82. +            if (g_strcmp0 (engine_to_change_name, engine_name) == 0) {
  83. +                g_object_set (G_OBJECT (engine), "hotkeys", hotkeys);
  84. +            }
  85. +        }
  86. +
  87. +        g_strfreev (dynamic_string_list);
  88. +    }
  89. +
  90.      if (ibus->engines_hotkey_profile) {
  91.          g_object_unref (ibus->engines_hotkey_profile);
  92.      }
  93. diff -Naur ibus-1.4.2/data/ibus.schemas.in my-ibus/data/ibus.schemas.in
  94. --- ibus-1.4.2/data/ibus.schemas.in     2012-08-22 14:16:51.000000000 +0000
  95. +++ my-ibus/data/ibus.schemas.in        2012-09-04 08:34:53.449056392 +0000
  96. @@ -102,6 +102,20 @@
  97.             <long>The shortcut keys for switching to the previous input method</long>
  98.        </locale>
  99.      </schema>
  100. +
  101. +    <schema>
  102. +      <key>/schemas/desktop/ibus/general/hotkey/dynamic_engine</key>
  103. +      <applyto>/desktop/ibus/general/hotkey/dynamic_engine</applyto>
  104. +      <owner>ibus</owner>
  105. +      <type>list</type>
  106. +      <list_type>string</list_type>
  107. +      <default>[]</default>
  108. +      <locale name="C">
  109. +        <short>Dynamic engine shortcut keys</short>
  110. +           <long>The shortcut keys of individual IMEs, of format "IME name = shortcut; shortcut..."</long>
  111. +      </locale>
  112. +    </schema>
  113. +
  114.      <schema>
  115.        <key>/schemas/desktop/ibus/panel/show</key>
  116.        <applyto>/desktop/ibus/panel/show</applyto>
  117. diff -Naur ibus-1.4.2/setup/enginetreeview.py my-ibus/setup/enginetreeview.py
  118. --- ibus-1.4.2/setup/enginetreeview.py  2012-08-22 14:16:51.000000000 +0000
  119. +++ my-ibus/setup/enginetreeview.py     2012-09-03 18:04:56.898908273 +0000
  120. @@ -127,7 +127,10 @@
  121.          engine = self.__model.get_value(iter, 0)
  122.          renderer.set_property("sensitive", True)
  123.          language = ibus.get_language_name(engine.language)
  124. -        renderer.set_property("text", "%s - %s" % (language, engine.longname))
  125. +        if (engine.hotkeys):
  126. +            renderer.set_property("text", "%s - %s (%s)" % (language, engine.longname, engine.hotkeys))
  127. +        else:
  128. +            renderer.set_property("text", "%s - %s" % (language, engine.longname))
  129.          if self.__model.get_path(iter)[0] == 0:
  130.              # default engine
  131.              renderer.set_property("weight", pango.WEIGHT_BOLD)
  132. diff -Naur ibus-1.4.2/setup/main.py my-ibus/setup/main.py
  133. --- ibus-1.4.2/setup/main.py    2012-08-22 14:16:51.000000000 +0000
  134. +++ my-ibus/setup/main.py       2012-09-04 08:58:07.962432065 +0000
  135. @@ -238,6 +238,9 @@
  136.          button = self.__builder.get_object("button_engine_about")
  137.          button.connect("clicked", self.__button_engine_about_cb)
  138.  
  139. +        button = self.__builder.get_object("button_engine_hotkeys")
  140. +        button.connect("clicked", self.__button_engine_hotkeys_cb)
  141. +
  142.          self.__engine_setup_exec_list = {}
  143.          button = self.__builder.get_object("button_engine_preferences")
  144.          button.connect("clicked", self.__button_engine_preferences_cb)
  145. @@ -277,6 +280,7 @@
  146.  
  147.          self.__builder.get_object("button_engine_remove").set_sensitive(engine != None)
  148.          self.__builder.get_object("button_engine_about").set_sensitive(engine != None)
  149. +        self.__builder.get_object("button_engine_hotkeys").set_sensitive(engine != None)
  150.          self.__builder.get_object("button_engine_up").set_sensitive(engine not in engines[:1])
  151.          self.__builder.get_object("button_engine_down").set_sensitive(engine not in engines[-1:])
  152.  
  153. @@ -301,6 +305,45 @@
  154.              about.run()
  155.              about.destroy()
  156.  
  157. +    def __button_engine_hotkeys_cb(self, button):
  158. +        engine = self.__treeview.get_active_engine()
  159. +        buttons = (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OK, gtk.RESPONSE_OK)
  160. +        title = _("Select keyboard shortcut for %s") %  _(engine.name)
  161. +        dialog = keyboardshortcut.KeyboardShortcutSelectionDialog(buttons = buttons, title = title)
  162. +        text = engine.hotkeys
  163. +        if text:
  164. +            shortcuts = text.split("; ")
  165. +        else:
  166. +            shortcuts = None
  167. +        dialog.set_shortcuts(shortcuts)
  168. +        id = dialog.run()
  169. +        shortcuts = dialog.get_shortcuts()
  170. +        dialog.destroy()
  171. +        if id != gtk.RESPONSE_OK:
  172. +            return
  173. +        text = "; ".join(shortcuts)
  174. +
  175. +        existing = self.__config.get_value(
  176. +                "general/hotkey", "dynamic_engine",
  177. +                [])
  178. +
  179. +        existing_dict = {}
  180. +        for item in existing:
  181. +            l = item.split('=', 1)
  182. +            if len(l) == 1: # illegal format
  183. +                continue
  184. +            name = l[0].strip()
  185. +            hot = l[1].strip()
  186. +            existing_dict[name] = hot
  187. +
  188. +        existing_dict[engine.name] = text
  189. +
  190. +        new = []
  191. +        for name, hot in existing_dict.items():
  192. +            new.append(name + " = " + hot)
  193. +
  194. +        self.__config.set_list("general/hotkey", "dynamic_engine", new, "s")
  195. +
  196.      def __button_engine_preferences_cb(self, button):
  197.          engine = self.__treeview.get_active_engine()
  198.          args = self.__get_engine_setup_exec_args(engine)
  199. diff -Naur ibus-1.4.2/setup/setup.ui my-ibus/setup/setup.ui
  200. --- ibus-1.4.2/setup/setup.ui   2012-08-22 14:16:51.000000000 +0000
  201. +++ my-ibus/setup/setup.ui      2012-09-03 19:53:40.669106347 +0000
  202. @@ -727,6 +727,22 @@
  203.                                    </packing>
  204.                                  </child>
  205.                                  <child>
  206. +                                  <object class="GtkButton" id="button_engine_hotkeys">
  207. +                                    <property name="label">Hotkeys</property>
  208. +                                    <property name="visible">True</property>
  209. +                                    <property name="sensitive">False</property>
  210. +                                    <property name="can_focus">True</property>
  211. +                                    <property name="receives_default">True</property>
  212. +                                    <property name="tooltip_text" translatable="yes">Show information of the selected input method</property>
  213. +                                    <property name="use_stock">True</property>
  214. +                                  </object>
  215. +                                  <packing>
  216. +                                    <property name="expand">False</property>
  217. +                                    <property name="fill">False</property>
  218. +                                    <property name="position">5</property>
  219. +                                  </packing>
  220. +                                </child>
  221. +                                <child>
  222.                                    <object class="GtkButton" id="button_engine_preferences">
  223.                                      <property name="label">gtk-preferences</property>
  224.                                      <property name="visible">True</property>
  225. @@ -739,7 +755,7 @@
  226.                                    <packing>
  227.                                      <property name="expand">False</property>
  228.                                      <property name="fill">False</property>
  229. -                                    <property name="position">5</property>
  230. +                                    <property name="position">6</property>
  231.                                    </packing>
  232.                                  </child>
  233.                                </object>
  234. diff -Naur ibus-1.4.2/src/ibusenginedesc.c my-ibus/src/ibusenginedesc.c
  235. --- ibus-1.4.2/src/ibusenginedesc.c     2012-03-06 15:34:36.000000000 +0000
  236. +++ my-ibus/src/ibusenginedesc.c        2012-09-04 09:37:35.392503948 +0000
  237. @@ -235,7 +235,7 @@
  238.                          "description hotkeys",
  239.                          "The hotkeys of engine description",
  240.                          "",
  241. -                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
  242. +                        G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
  243.  
  244.      /**
  245.       * IBusEngineDesc:symbol:
  246. @@ -344,7 +344,6 @@
  247.          desc->priv->rank = g_value_get_uint (value);
  248.          break;
  249.      case PROP_HOTKEYS:
  250. -        g_assert (desc->priv->hotkeys == NULL);
  251.          desc->priv->hotkeys = g_value_dup_string (value);
  252.          break;
  253.      case PROP_SYMBOL: