From 1cb9d1cc920b75b36f4fa828ae6994d8485662a9 Mon Sep 17 00:00:00 2001 From: William Hua Date: Wed, 19 Mar 2014 16:32:18 +1300 Subject: Use private IBus implementation. --- lib/Makefile.am | 1 + lib/ibus-panel.vala | 26 ++++++++++++++++++++++++++ lib/main.vala | 48 ++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 65 insertions(+), 10 deletions(-) create mode 100644 lib/ibus-panel.vala diff --git a/lib/Makefile.am b/lib/Makefile.am index 7432d15c..b99073e1 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -10,6 +10,7 @@ indicator_keyboard_service_SOURCES = main.vala \ source.vala \ common.vala \ ibus-menu.vala \ + ibus-panel.vala \ window-stack.vala \ unity-greeter.vala indicator_keyboard_service_VALAFLAGS = $(AM_VALAFLAGS) \ diff --git a/lib/ibus-panel.vala b/lib/ibus-panel.vala new file mode 100644 index 00000000..460b1eac --- /dev/null +++ b/lib/ibus-panel.vala @@ -0,0 +1,26 @@ +/* + * Copyright 2014 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3 of the License. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authors: William Hua + */ + +[DBus (name="com.canonical.IBus.Panel.Private")] +public interface IBusPanel : Object { + + public abstract void activate_property (string name, uint state) throws IOError; + + public signal void properties_registered (Variant variant); + public signal void property_updated (Variant variant); +} diff --git a/lib/main.vala b/lib/main.vala index f012ecb0..4367e9ae 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -37,7 +37,7 @@ public class Indicator.Keyboard.Service : Object { private uint focused_window_id; private IBus.Bus? ibus; - private IBus.PanelService? panel_service; + private IBusPanel? ibus_panel; private uint panel_timeout; private Source[]? sources; @@ -576,11 +576,35 @@ public class Indicator.Keyboard.Service : Object { } } - if (panel_service == null && sources[i].is_ibus) { - if (get_ibus ().request_name (IBus.SERVICE_PANEL, IBus.BusNameFlag.REPLACE_EXISTING) > 0) { - panel_service = new IBus.PanelService (get_ibus ().get_connection ()); - ((!) panel_service).register_properties.connect (handle_registered_properties); - ((!) panel_service).update_property.connect (handle_updated_property); + if (ibus_panel == null && sources[i].is_ibus) { + var connection = get_ibus ().get_connection (); + var name = "org.freedesktop.IBus.Panel"; + var path = "/org/freedesktop/IBus/Panel"; + + try { + ibus_panel = connection.get_proxy_sync (name, path); + + ((!) ibus_panel).properties_registered.connect ((variant) => { + var properties = new IBus.PropList (); + properties.deserialize (variant); + + if (properties is IBus.PropList) { + handle_properties_registered ((!) (properties as IBus.PropList)); + } + }); + ((!) ibus_panel).property_updated.connect ((variant) => { + var type = IBus.PropType.NORMAL; + var state = IBus.PropState.INCONSISTENT; + var text = new IBus.Text.from_static_string (""); + var property = new IBus.Property ("", type, text, null, text, false, false, state, null); + property.deserialize (variant); + + if (property is IBus.Property) { + handle_property_updated ((!) (property as IBus.Property)); + } + }); + } catch (IOError error) { + warning ("error: %s", error.message); } } } @@ -590,7 +614,7 @@ public class Indicator.Keyboard.Service : Object { } [DBus (visible = false)] - private void handle_registered_properties (IBus.PropList list) { + private void handle_properties_registered (IBus.PropList list) { if (panel_timeout > 0) { GLib.Source.remove (panel_timeout); panel_timeout = 0; @@ -604,7 +628,7 @@ public class Indicator.Keyboard.Service : Object { } [DBus (visible = false)] - private void handle_updated_property (IBus.Property property) { + private void handle_property_updated (IBus.Property property) { get_ibus_menu ().update_property (property); } @@ -747,8 +771,12 @@ public class Indicator.Keyboard.Service : Object { if (ibus_menu == null) { ibus_menu = new IBusMenu (get_action_group ()); ((!) ibus_menu).activate.connect ((property, state) => { - if (panel_service != null) { - ((!) panel_service).property_activate (property.key, state); + if (ibus_panel != null) { + try { + ((!) ibus_panel).activate_property (property.key, state); + } catch (IOError error) { + warning ("error: %s", error.message); + } } }); } -- cgit v1.2.3 From e5772b006395eb5587be7cf88367a42e702582c7 Mon Sep 17 00:00:00 2001 From: William Hua Date: Wed, 19 Mar 2014 17:28:51 +1300 Subject: Breaks IBus << 1.5.5-1ubuntu3. --- debian/control | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/control b/debian/control index 4148227e..585af9c5 100644 --- a/debian/control +++ b/debian/control @@ -30,6 +30,7 @@ Package: indicator-keyboard Architecture: any Depends: ${misc:Depends}, ${shlibs:Depends}, +Breaks: ibus (<< 1.5.5-1ubuntu3), Description: Keyboard indicator This package contains the keyboard indicator, which should show as an icon in the top panel when using the Unity environment. It can be used to switch -- cgit v1.2.3 From be945fee7825c4852f558d6e2e77a196c184f9c5 Mon Sep 17 00:00:00 2001 From: William Hua Date: Wed, 19 Mar 2014 18:06:54 +1300 Subject: Check if IBus is connected before checking engine properties. --- lib/main.vala | 59 +++++++++++++++++++++++++---------------------- po/indicator-keyboard.pot | 10 ++++---- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/lib/main.vala b/lib/main.vala index 4367e9ae..9e74ee84 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -577,34 +577,37 @@ public class Indicator.Keyboard.Service : Object { } if (ibus_panel == null && sources[i].is_ibus) { - var connection = get_ibus ().get_connection (); - var name = "org.freedesktop.IBus.Panel"; - var path = "/org/freedesktop/IBus/Panel"; - - try { - ibus_panel = connection.get_proxy_sync (name, path); - - ((!) ibus_panel).properties_registered.connect ((variant) => { - var properties = new IBus.PropList (); - properties.deserialize (variant); - - if (properties is IBus.PropList) { - handle_properties_registered ((!) (properties as IBus.PropList)); - } - }); - ((!) ibus_panel).property_updated.connect ((variant) => { - var type = IBus.PropType.NORMAL; - var state = IBus.PropState.INCONSISTENT; - var text = new IBus.Text.from_static_string (""); - var property = new IBus.Property ("", type, text, null, text, false, false, state, null); - property.deserialize (variant); - - if (property is IBus.Property) { - handle_property_updated ((!) (property as IBus.Property)); - } - }); - } catch (IOError error) { - warning ("error: %s", error.message); + DBusConnection? connection = get_ibus ().get_connection (); + + if (connection != null) { + var name = "org.freedesktop.IBus.Panel"; + var path = "/org/freedesktop/IBus/Panel"; + + try { + ibus_panel = ((!) connection).get_proxy_sync (name, path); + + ((!) ibus_panel).properties_registered.connect ((variant) => { + var properties = new IBus.PropList (); + properties.deserialize (variant); + + if (properties is IBus.PropList) { + handle_properties_registered ((!) (properties as IBus.PropList)); + } + }); + ((!) ibus_panel).property_updated.connect ((variant) => { + var type = IBus.PropType.NORMAL; + var state = IBus.PropState.INCONSISTENT; + var text = new IBus.Text.from_static_string (""); + var property = new IBus.Property ("", type, text, null, text, false, false, state, null); + property.deserialize (variant); + + if (property is IBus.Property) { + handle_property_updated ((!) (property as IBus.Property)); + } + }); + } catch (IOError error) { + warning ("error: %s", error.message); + } } } } diff --git a/po/indicator-keyboard.pot b/po/indicator-keyboard.pot index 34931572..090c84a3 100644 --- a/po/indicator-keyboard.pot +++ b/po/indicator-keyboard.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2013-09-27 16:28+0200\n" +"POT-Creation-Date: 2014-03-19 18:04+1300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,19 +17,19 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: ../lib/main.vala:427 +#: ../lib/main.vala:655 #, c-format msgid "%s input source" msgstr "" -#: ../lib/main.vala:525 +#: ../lib/main.vala:801 msgid "Character Map" msgstr "" -#: ../lib/main.vala:526 +#: ../lib/main.vala:802 msgid "Keyboard Layout Chart" msgstr "" -#: ../lib/main.vala:527 +#: ../lib/main.vala:803 msgid "Text Entry Settings..." msgstr "" -- cgit v1.2.3 From a08ab0c4f8f80366eb7c08795e9d5407aef8ecff Mon Sep 17 00:00:00 2001 From: William Hua Date: Thu, 20 Mar 2014 12:25:34 +1300 Subject: IBus panel is only available while IBus is running. --- lib/main.vala | 82 +++++++++++++++++++++++++++-------------------- po/indicator-keyboard.pot | 10 +++--- 2 files changed, 53 insertions(+), 39 deletions(-) diff --git a/lib/main.vala b/lib/main.vala index 9e74ee84..55c46b02 100644 --- a/lib/main.vala +++ b/lib/main.vala @@ -38,6 +38,7 @@ public class Indicator.Keyboard.Service : Object { private IBus.Bus? ibus; private IBusPanel? ibus_panel; + private ulong ibus_connected_id; private uint panel_timeout; private Source[]? sources; @@ -131,6 +132,43 @@ public class Indicator.Keyboard.Service : Object { return (!) ibus; } + [DBus (visible = false)] + private IBusPanel? get_ibus_panel () { + if (ibus_panel == null && get_ibus ().is_connected ()) { + var connection = get_ibus ().get_connection (); + var name = "org.freedesktop.IBus.Panel"; + var path = "/org/freedesktop/IBus/Panel"; + + try { + ibus_panel = connection.get_proxy_sync (name, path); + + ((!) ibus_panel).properties_registered.connect ((variant) => { + var properties = new IBus.PropList (); + properties.deserialize (variant); + + if (properties is IBus.PropList) { + handle_properties_registered ((!) (properties as IBus.PropList)); + } + }); + ((!) ibus_panel).property_updated.connect ((variant) => { + var type = IBus.PropType.NORMAL; + var state = IBus.PropState.INCONSISTENT; + var text = new IBus.Text.from_static_string (""); + var property = new IBus.Property ("", type, text, null, text, false, false, state, null); + property.deserialize (variant); + + if (property is IBus.Property) { + handle_property_updated ((!) (property as IBus.Property)); + } + }); + } catch (IOError error) { + warning ("error: %s", error.message); + } + } + + return ibus_panel; + } + [DBus (visible = false)] public void up () { if (loop == null) { @@ -576,38 +614,12 @@ public class Indicator.Keyboard.Service : Object { } } - if (ibus_panel == null && sources[i].is_ibus) { - DBusConnection? connection = get_ibus ().get_connection (); - - if (connection != null) { - var name = "org.freedesktop.IBus.Panel"; - var path = "/org/freedesktop/IBus/Panel"; - - try { - ibus_panel = ((!) connection).get_proxy_sync (name, path); - - ((!) ibus_panel).properties_registered.connect ((variant) => { - var properties = new IBus.PropList (); - properties.deserialize (variant); - - if (properties is IBus.PropList) { - handle_properties_registered ((!) (properties as IBus.PropList)); - } - }); - ((!) ibus_panel).property_updated.connect ((variant) => { - var type = IBus.PropType.NORMAL; - var state = IBus.PropState.INCONSISTENT; - var text = new IBus.Text.from_static_string (""); - var property = new IBus.Property ("", type, text, null, text, false, false, state, null); - property.deserialize (variant); - - if (property is IBus.Property) { - handle_property_updated ((!) (property as IBus.Property)); - } - }); - } catch (IOError error) { - warning ("error: %s", error.message); - } + if (ibus_connected_id == 0 && sources[i].is_ibus) { + ibus_connected_id = get_ibus ().connected.connect (() => { get_ibus_panel (); }); + get_ibus ().disconnected.connect (() => { ibus_panel = null; }); + + if (get_ibus ().is_connected ()) { + get_ibus_panel (); } } } @@ -774,9 +786,11 @@ public class Indicator.Keyboard.Service : Object { if (ibus_menu == null) { ibus_menu = new IBusMenu (get_action_group ()); ((!) ibus_menu).activate.connect ((property, state) => { - if (ibus_panel != null) { + var panel = get_ibus_panel (); + + if (panel != null) { try { - ((!) ibus_panel).activate_property (property.key, state); + ((!) panel).activate_property (property.key, state); } catch (IOError error) { warning ("error: %s", error.message); } diff --git a/po/indicator-keyboard.pot b/po/indicator-keyboard.pot index 090c84a3..5647f938 100644 --- a/po/indicator-keyboard.pot +++ b/po/indicator-keyboard.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2014-03-19 18:04+1300\n" +"POT-Creation-Date: 2014-03-20 12:25+1300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,19 +17,19 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: ../lib/main.vala:655 +#: ../lib/main.vala:667 #, c-format msgid "%s input source" msgstr "" -#: ../lib/main.vala:801 +#: ../lib/main.vala:815 msgid "Character Map" msgstr "" -#: ../lib/main.vala:802 +#: ../lib/main.vala:816 msgid "Keyboard Layout Chart" msgstr "" -#: ../lib/main.vala:803 +#: ../lib/main.vala:817 msgid "Text Entry Settings..." msgstr "" -- cgit v1.2.3