Let users know the default hotkey is Super+space with libnotify.
authorfujiwarat <takao.fujiwara1@gmail.com>
Fri, 17 May 2013 03:12:54 +0000 (12:12 +0900)
committerfujiwarat <takao.fujiwara1@gmail.com>
Fri, 17 May 2013 03:12:54 +0000 (12:12 +0900)
Review URL: https://codereview.appspot.com/9407043

configure.ac
data/ibus.schemas.in
ui/gtk3/Makefile.am
ui/gtk3/panel.vala

index 3036792..781bbf5 100644 (file)
@@ -2,8 +2,8 @@
 #
 # ibus - The Input Bus
 #
-# Copyright (c) 2007-2010 Peng Huang <shawn.p.huang@gmail.com>
-# Copyright (c) 2007-2010 Red Hat, Inc.
+# Copyright (c) 2007-2013 Peng Huang <shawn.p.huang@gmail.com>
+# Copyright (c) 2007-2013 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
@@ -498,6 +498,21 @@ if test x"$enable_engine" = x"yes"; then
     enable_engine="yes (enabled, use --disable-engine to disable)"
 fi
 
+# --disable-libnotify
+AC_ARG_ENABLE(libnotify,
+    AS_HELP_STRING([--disable-libnotify],
+                   [Disable to link libnotify]),
+    [enable_libnotify=$enableval],
+    [enable_libnotify=yes]
+)
+AM_CONDITIONAL([ENABLE_LIBNOTIFY], [test x"$enable_libnotify" = x"yes"])
+if test x"$enable_libnotify" = x"yes"; then
+    PKG_CHECK_MODULES(LIBNOTIFY, [
+        libnotify >= 0.7
+    ])
+    enable_libnotify="yes (enabled, use --disable-libnotify to disable)"
+fi
+
 # Check iso-codes.
 PKG_CHECK_MODULES(ISOCODES, [
     iso-codes
@@ -574,6 +589,7 @@ Build options:
   No snooper regexes        "$NO_SNOOPER_APPS"
   Panel icon                "$IBUS_ICON_KEYBOARD"
   Enable surrounding-text   $enable_surrounding_text
+  Enable libnotify          $enable_libnotify
   Run test cases            $enable_tests
 ])
 
index 9263adc..9cfe83b 100644 (file)
       </locale>
     </schema>
     <schema>
+      <key>/schemas/desktop/ibus/general/version</key>
+      <applyto>/desktop/ibus/general/version</applyto>
+      <owner>ibus</owner>
+      <type>string</type>
+      <default></default>
+      <locale name="C">
+        <short>Saved version number</short>
+            <long>The saved version number will be used to check the
+                  difference between the version of the previous installed
+                  ibus and one of the current ibus.
+            </long>
+      </locale>
+    </schema>
+    <schema>
       <key>/schemas/desktop/ibus/general/hotkey/trigger</key>
       <applyto>/desktop/ibus/general/hotkey/trigger</applyto>
       <owner>ibus</owner>
index 43454bc..2038814 100644 (file)
@@ -2,8 +2,8 @@
 #
 # ibus - The Input Bus
 #
-# Copyright (c) 2007-2010 Peng Huang <shawn.p.huang@gmail.com>
-# Copyright (c) 2007-2010 Red Hat, Inc.
+# Copyright (c) 2007-2013 Peng Huang <shawn.p.huang@gmail.com>
+# Copyright (c) 2007-2013 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
@@ -83,6 +83,21 @@ AM_VALAFLAGS = \
        --pkg=xi \
        $(NULL)
 
+if ENABLE_LIBNOTIFY
+AM_CFLAGS += \
+       @LIBNOTIFY_CFLAGS@ \
+       $(NULL)
+
+AM_LDADD += \
+       @LIBNOTIFY_LIBS@ \
+       $(NULL)
+
+AM_VALAFLAGS += \
+       --pkg=libnotify \
+       -D ENABLE_LIBNOTIFY \
+       $(NULL)
+endif
+
 libexec_PROGRAMS = ibus-ui-gtk3
 
 ibus_ui_gtk3_SOURCES = \
index 0c793f4..39aca08 100644 (file)
@@ -298,6 +298,95 @@ class Panel : IBus.PanelService {
                                 var_embed_preedit);
     }
 
+    private int compare_versions(string version1, string version2) {
+        string[] version1_list = version1.split(".");
+        string[] version2_list = version2.split(".");
+        int major1, minor1, micro1, major2, minor2, micro2;
+
+        if (version1 == version2) {
+            return 0;
+        }
+
+        // The initial dconf value of "version" is "".
+        if (version1 == "") {
+            return -1;
+        }
+        if (version2 == "") {
+            return 1;
+        }
+
+        assert(version1_list.length >= 3);
+        assert(version2_list.length >= 3);
+
+        major1 = int.parse(version1_list[0]);
+        minor1 = int.parse(version1_list[1]);
+        micro1 = int.parse(version1_list[2]);
+
+        major2 = int.parse(version2_list[0]);
+        minor2 = int.parse(version2_list[1]);
+        micro2 = int.parse(version2_list[2]);
+
+        if (major1 == minor1 && minor1 == minor2 && micro1 == micro2) {
+            return 0;
+        }
+        if ((major1 > major2) ||
+            (major1 == major2 && minor1 > minor2) ||
+            (major1 == major2 && minor1 == minor2 &&
+             micro1 > micro2)) {
+            return 1;
+        }
+        return -1;
+    }
+
+    private void update_version_1_5_3() {
+#if ENABLE_LIBNOTIFY
+        if (!Notify.is_initted()) {
+            Notify.init ("ibus");
+        }
+
+        var notification = new Notify.Notification(
+                _("IBus Update"),
+                _("Super+space is now the default hotkey."),
+                "ibus");
+        notification.set_timeout(30 * 1000);
+        notification.set_category("hotkey");
+
+        try {
+            notification.show();
+        } catch (GLib.Error e){
+            warning ("Notification is failed for IBus 1.5.3: %s", e.message);
+        }
+#else
+        warning(_("Super+space is now the default hotkey."));
+#endif
+    }
+
+    private void set_version() {
+        Variant var_prev_version = m_config.get_value("general", "version");
+        Variant var_current_version = null;
+        string prev_version = "".dup();
+        string current_version = null;
+
+        if (var_prev_version != null) {
+            prev_version = var_prev_version.dup_string();
+        }
+
+        if (compare_versions(prev_version, "1.5.3") < 0) {
+            update_version_1_5_3();
+        }
+
+        current_version = "%d.%d.%d".printf(IBus.MAJOR_VERSION,
+                                            IBus.MINOR_VERSION,
+                                            IBus.MICRO_VERSION);
+
+        if (prev_version == current_version) {
+            return;
+        }
+
+        var_current_version = new Variant.string(current_version);
+        m_config.set_value("general", "version", var_current_version);
+    }
+
     public void set_config(IBus.Config config) {
         if (m_config != null) {
             m_config.value_changed.disconnect(config_value_changed_cb);
@@ -325,11 +414,12 @@ class Panel : IBus.PanelService {
             bind_switch_shortcut(null);
             set_switcher_delay_time(null);
             set_embed_preedit_text(null);
+            set_custom_font();
+
+            set_version();
         } else {
             update_engines(null, null);
         }
-
-        set_custom_font();
     }
 
     private void exec_setxkbmap(IBus.EngineDesc engine) {