Revision: 6505
Author: ek.kato
Date: Thu Jul 15 00:21:23 2010
Log: * uim/uim-custom.h : Add new API uim_custom_save_custom().
* uim/uim-custom.c
- (uim_custom_save) : Fix indent.
- (uim_custom_save_custom) : New. Save a primary group file of
which custom variable belongs.
- (uim_custom_get_primary_group_by_custom) : New.
* helper/toolbar-common-gtk.c : Save default IM upon IM switch if
system-global coverage is set.
- (save_default_im) : New.
- (is_msg_imsw) : Ditto.
- (is_imsw_coverage_system_global) : Ditto.
- (get_imsw_im) : Ditto.
- (prop_menu_activate) : Save selected IM as a default IM when
system global coverage is set.
- (toolbar_new) : Call uim_custom_enable().
* helper/im-switcher-gtk.c : Save default IM upon IM switch if
system global coverage is selected. Add apply button.
- (save_default_im) : New.
- (change_input_method) : Save IM upon im_change_whole_desktop.
- (change_input_method_and_quit) : New.
- (create_switcher) : Add apply button.
- (main) : Call uim_init() and uim_custom_enable().
* helper/Makefile.am
- (uim_toolbar_applet_LDADD)
- (uim_toolbar_gtk_LDADD)
- (uim_toolbar_gtk_systray_LDADD)
- (uim_im_switcher_gtk_LDADD)
- Link appropriately.
http://code.google.com/p/uim/source/detail?r=6505
Modified:
/trunk/helper/Makefile.am
/trunk/helper/im-switcher-gtk.c
/trunk/helper/toolbar-common-gtk.c
/trunk/uim/uim-custom.c
/trunk/uim/uim-custom.h
=======================================
--- /trunk/helper/Makefile.am Sun Jun 13 00:29:13 2010
+++ /trunk/helper/Makefile.am Thu Jul 15 00:21:23 2010
@@ -7,7 +7,8 @@
uim_toolbar_applet_LDADD = @GTK2_LIBS@ @APPLET_GNOME_LIBS@ \
$(top_builddir)/uim/libuim-scm.la \
- $(top_builddir)/uim/libuim.la
+ $(top_builddir)/uim/libuim.la \
+ $(top_builddir)/uim/libuim-custom.la
uim_toolbar_applet_CPPFLAGS = $(helper_defs) -I$(top_srcdir)
-I$(top_builddir)
uim_toolbar_applet_CFLAGS = @GTK2_CFLAGS@ @APPLET_GNOME_CFLAGS@
if GCC
@@ -73,7 +74,8 @@
uim_toolbar_gtk_SOURCES = toolbar-standalone-gtk.c toolbar-common-gtk.c
uim_toolbar_gtk_LDADD = @GTK2_LIBS@ $(top_builddir)/uim/libuim-scm.la \
- $(top_builddir)/uim/libuim.la
+ $(top_builddir)/uim/libuim.la \
+ $(top_builddir)/uim/libuim-custom.la
uim_toolbar_gtk_CPPFLAGS = -I$(top_srcdir) -I$(top_builddir)
uim_toolbar_gtk_CFLAGS = @GTK2_CFLAGS@
@@ -82,13 +84,16 @@
uim_toolbar_gtk_systray_LDADD = @GTK2_LIBS@ \
@X11_LIBS@ \
$(top_builddir)/uim/libuim-scm.la \
- $(top_builddir)/uim/libuim.la
+ $(top_builddir)/uim/libuim.la \
+ $(top_builddir)/uim/libuim-custom.la
uim_toolbar_gtk_systray_CPPFLAGS = -I$(top_srcdir) -I$(top_builddir)
uim_toolbar_gtk_systray_CFLAGS = @GTK2_CFLAGS@
uim_im_switcher_gtk_SOURCES = im-switcher-gtk.c
uim_im_switcher_gtk_LDADD = @GTK2_LIBS@
$(top_builddir)/uim/libuim-scm.la \
- $(top_builddir)/uim/libuim.la
+ $(top_builddir)/uim/libuim-custom.la \
+ $(top_builddir)/uim/libuim-scm.la \
+ $(top_builddir)/uim/libuim.la
uim_im_switcher_gtk_CPPFLAGS = -I$(top_srcdir) -I$(top_builddir)
uim_im_switcher_gtk_CFLAGS = @GTK2_CFLAGS@
=======================================
--- /trunk/helper/im-switcher-gtk.c Thu May 6 05:31:55 2010
+++ /trunk/helper/im-switcher-gtk.c Thu Jul 15 00:21:23 2010
@@ -43,6 +43,8 @@
#include <uim/uim.h>
#include <uim/uim-helper.h>
+#include <uim/uim-custom.h>
+#include <uim/uim-scm.h>
#include "uim/gettext.h"
@@ -50,6 +52,7 @@
static int uim_fd; /* file descriptor to connect helper message bus */
static gchar *im_list_str_old; /* To compare new im_list_str */
static GtkWidget *switcher_tree_view;
+static int custom_enabled;
static gboolean
reload_im_list(GtkWindow *window, gpointer user_data);
@@ -234,6 +237,21 @@
coverage = IMSW_COVERAGE_THIS_TEXT_AREA_ONLY;
}
}
+
+static void
+save_default_im()
+{
+ if (custom_enabled) {
+ gchar *im_name = get_selected_im_name();
+
+ uim_scm_callf("custom-set-value!",
+ "yy",
+ "custom-preserved-default-im-name",
+ im_name);
+ uim_custom_save_custom("custom-preserved-default-im-name");
+ g_free(im_name);
+ }
+}
static void
change_input_method(GtkButton *button, gpointer user_data)
@@ -241,6 +259,7 @@
switch (coverage) {
case IMSW_COVERAGE_WHOLE_DESKTOP:
send_message_im_change("im_change_whole_desktop\n");
+ save_default_im();
break;
case IMSW_COVERAGE_THIS_APPLICATION_ONLY:
send_message_im_change("im_change_this_application_only\n");
@@ -249,6 +268,12 @@
send_message_im_change("im_change_this_text_area_only\n");
break;
}
+}
+
+static void
+change_input_method_and_quit(GtkButton *button, gpointer user_data)
+{
+ change_input_method(button, user_data);
gtk_main_quit();
}
@@ -385,8 +410,14 @@
gtk_button_box_set_layout(GTK_BUTTON_BOX(setting_button_box),
GTK_BUTTONBOX_END);
gtk_box_set_spacing(GTK_BOX(setting_button_box), 8);
+ /* Apply button */
+ button = gtk_button_new_from_stock(GTK_STOCK_APPLY);
+ g_signal_connect(G_OBJECT(button), "clicked",
+ G_CALLBACK(change_input_method), NULL);
+ gtk_box_pack_start(GTK_BOX(setting_button_box), button, TRUE, TRUE, 2);
+
/* Cancel button */
- button = gtk_button_new_from_stock(GTK_STOCK_CANCEL);
+ button = gtk_button_new_from_stock(GTK_STOCK_CLOSE);
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(gtk_main_quit), NULL);
gtk_box_pack_start(GTK_BOX(setting_button_box), button, TRUE, TRUE, 2);
@@ -394,7 +425,7 @@
/* OK button */
button = gtk_button_new_from_stock(GTK_STOCK_OK);
g_signal_connect(G_OBJECT(button), "clicked",
- G_CALLBACK(change_input_method), NULL);
+ G_CALLBACK(change_input_method_and_quit), NULL);
gtk_box_pack_start(GTK_BOX(setting_button_box), button, TRUE, TRUE, 2);
gtk_box_pack_start(GTK_BOX(vbox3), setting_button_box, FALSE, FALSE, 8);
@@ -559,6 +590,12 @@
gtk_init(&argc, &argv);
+ if (uim_init() < 0) {
+ fprintf(stderr, "uim_init() failed.\n");
+ exit(EXIT_FAILURE);
+ }
+ custom_enabled = uim_custom_enable();
+
result = create_switcher();
if (result == -1) {
=======================================
--- /trunk/helper/toolbar-common-gtk.c Sun Apr 4 20:35:54 2010
+++ /trunk/helper/toolbar-common-gtk.c Thu Jul 15 00:21:23 2010
@@ -41,6 +41,7 @@
#include <uim/uim.h>
#include "uim/uim-helper.h"
#include "uim/uim-scm.h"
+#include "uim/uim-custom.h"
#include "uim/gettext.h"
#define OBJECT_DATA_PROP_BUTTONS "PROP_BUTTONS"
@@ -149,6 +150,7 @@
static GtkIconFactory *uim_factory;
static GList *uim_icon_list;
static gboolean prop_menu_showing = FALSE;
+static gboolean custom_enabled;
static const char *safe_gettext(const char *msgid);
static gboolean has_n_strs(gchar **str_list, guint n);
@@ -252,17 +254,62 @@
return FALSE;
}
+
+static void
+save_default_im(const char *im)
+{
+ if (custom_enabled) {
+ uim_scm_callf("custom-set-value!",
+ "yy",
+ "custom-preserved-default-im-name",
+ im);
+ uim_custom_save_custom("custom-preserved-default-im-name");
+ }
+}
+
+static gboolean
+is_msg_imsw(const gchar *str)
+{
+ return g_str_has_prefix(str, "action_imsw_");
+}
+
+static gboolean
+is_imsw_coverage_system_global()
+{
+ char *coverage;
+ gboolean ret;
+
+ coverage = uim_scm_symbol_value_str("imsw-coverage");
+
+ ret = (gboolean)!strcmp(coverage, "system-global");
+ free(coverage);
+
+ return ret;
+}
+
+static const char*
+get_imsw_im(const gchar *str)
+{
+ /* skip "action_imsw_" */
+ return str + strlen("action_imsw_");
+}
static void
prop_menu_activate(GtkMenu *menu_item, gpointer data)
{
GString *msg;
-
- msg = g_string_new((gchar *)g_object_get_data(G_OBJECT(menu_item),
- "prop_action"));
+ const gchar *str;
+
+ str = g_object_get_data(G_OBJECT(menu_item), "prop_action");
+ msg = g_string_new(str);
g_string_prepend(msg, "prop_activate\n");
g_string_append(msg, "\n");
uim_helper_send_message(uim_fd, msg->str);
+ if (is_msg_imsw(str) && is_imsw_coverage_system_global()) {
+ const char *im = get_imsw_im(str);
+ save_default_im(im);
+ }
+
g_string_free(msg, TRUE);
}
@@ -896,6 +943,8 @@
GList *prop_buttons = NULL;
GtkSizeGroup *sg;
+ custom_enabled = (gboolean)uim_custom_enable();
+
init_icon();
/* create widgets */
=======================================
--- /trunk/uim/uim-custom.c Thu May 6 17:38:09 2010
+++ /trunk/uim/uim-custom.c Thu Jul 15 00:21:23 2010
@@ -237,6 +237,7 @@
static uim_bool for_each_primary_groups(uim_bool (*func)(const char *));
static uim_bool uim_custom_load_group(const char *group);
static uim_bool uim_custom_save_group(const char *group);
+static const char *uim_custom_get_primary_group_by_custom(const char
*custom_sym);
static const char str_list_arg[] = "uim-custom-c-str-list-arg";
static const char custom_subdir[] = "customs";
@@ -1264,12 +1265,35 @@
uim_bool
uim_custom_save(void)
{
- if(uim_helper_is_setugid() ==UIM_FALSE) {
+ if(uim_helper_is_setugid() == UIM_FALSE) {
return for_each_primary_groups(uim_custom_save_group);
} else {
return UIM_FALSE;
}
}
+
+/**
+ * Saves a per-user custom variable configuration. This function saves a
+ * primary custom group values which contains the specified custom
variable as
+ * ~/.uim.d/customs/custom-primary-group-file-containing-the-variable.scm.
The
+ * directory will be made if not exist. The saved values will be implicitly
+ * loaded at uim_init() or can explicitly be loaded by uim_custom_load().
+ *
+ * @see uim_init()
+ * @see uim_custom_load()
+ * @retval UIM_TRUE succeeded
+ * @retval UIM_FALSE failed
+ */
+uim_bool
+uim_custom_save_custom(const char *custom_sym)
+{
+ if(uim_helper_is_setugid() == UIM_FALSE) {
+ const char *group_sym =
uim_custom_get_primary_group_by_custom(custom_sym);
+ return uim_custom_save_group(group_sym);
+ } else {
+ return UIM_FALSE;
+ }
+}
/**
* Broadcasts custom variable configurations to other uim-enabled
application
@@ -1639,6 +1663,15 @@
{
uim_scm_c_list_free((void **)symbol_list,
(uim_scm_c_list_free_func)free);
}
+
+static const char *
+uim_custom_get_primary_group_by_custom(const char *custom_sym)
+{
+ uim_lisp groups;
+ groups = uim_scm_callf("custom-groups", "y", custom_sym);
+
+ return uim_scm_refer_c_str(uim_scm_car(groups));
+}
static uim_lisp
uim_custom_cb_update_cb_gate(uim_lisp cb, uim_lisp ptr, uim_lisp
custom_sym)
=======================================
--- /trunk/uim/uim-custom.h Sun Apr 4 20:35:54 2010
+++ /trunk/uim/uim-custom.h Thu Jul 15 00:21:23 2010
@@ -136,6 +136,7 @@
/* load & save */
uim_bool uim_custom_load(void);
uim_bool uim_custom_save(void);
+uim_bool uim_custom_save_custom(const char *custom_sym);
uim_bool uim_custom_broadcast(void);
uim_bool uim_custom_broadcast_reload_request(void);