From bd48b1f5c71ab849e1d2c78fd069a92d37426dc3 Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Thu, 1 Sep 2011 18:48:41 +0900 Subject: [PATCH 2/6] Refactor setup.c. --- src/ibus-m17n-preferences.ui | 3 +- src/setup.c | 663 +++++++++++++++++++++++------------------- 2 files changed, 362 insertions(+), 304 deletions(-) diff --git a/src/ibus-m17n-preferences.ui b/src/ibus-m17n-preferences.ui index 6f6ace7..a46ab49 100644 --- a/src/ibus-m17n-preferences.ui +++ b/src/ibus-m17n-preferences.ui @@ -263,9 +263,10 @@ automatic automatic - + True True + True both diff --git a/src/setup.c b/src/setup.c index aba0e92..30386df 100644 --- a/src/setup.c +++ b/src/setup.c @@ -17,19 +17,24 @@ enum { NUM_COLS }; -struct _ConfigContext { - IBusConfig *config; - MSymbol language; - MSymbol name; - GtkListStore *store; - gchar *section; +struct _SetupDialog { + GtkWidget *dialog; + GtkWidget *combobox_underline; + GtkWidget *combobox_orientation; + GtkWidget *checkbutton_foreground; GtkWidget *colorbutton_foreground; + GtkWidget *checkbutton_background; GtkWidget *colorbutton_background; + GtkWidget *treeview; + GtkListStore *store; -}; -typedef struct _ConfigContext ConfigContext; + gchar *lang; + gchar *name; -static IBusConfig *config = NULL; + IBusConfig *config; + gchar *section; +}; +typedef struct _SetupDialog SetupDialog; static gchar *opt_name = NULL; static const GOptionEntry options[] = { @@ -38,17 +43,8 @@ static const GOptionEntry options[] = { {NULL} }; -void -ibus_m17n_init (IBusBus *bus) -{ - config = ibus_bus_get_config (bus); - if (config) - g_object_ref_sink (config); - ibus_m17n_init_common (); -} - static gchar * -format_value (MPlist *plist) +format_m17n_value (MPlist *plist) { if (mplist_key (plist) == Msymbol) return g_strdup (msymbol_name ((MSymbol) mplist_value (plist))); @@ -64,7 +60,7 @@ format_value (MPlist *plist) } static MPlist * -parse_value (MPlist *plist, gchar *text) +parse_m17n_value (MPlist *plist, gchar *text) { MPlist *value; @@ -100,7 +96,7 @@ parse_value (MPlist *plist, gchar *text) } static void -insert_items (GtkListStore *store, MSymbol language, MSymbol name) +insert_m17n_items (GtkListStore *store, MSymbol language, MSymbol name) { MPlist *plist; @@ -109,8 +105,8 @@ insert_items (GtkListStore *store, MSymbol language, MSymbol name) for (; plist && mplist_key (plist) == Mplist; plist = mplist_next (plist)) { GtkTreeIter iter; MSymbol key; - MPlist *p, *value; - gchar *description; + MPlist *p, *mvalue; + gchar *description, *value; p = mplist_value (plist); key = mplist_value (p); /* name */ @@ -118,15 +114,17 @@ insert_items (GtkListStore *store, MSymbol language, MSymbol name) p = mplist_next (p); /* description */ description = ibus_m17n_mtext_to_utf8 ((MText *) mplist_value (p)); p = mplist_next (p); /* status */ - value = mplist_next (p); + mvalue = mplist_next (p); + value = format_m17n_value (mvalue); gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, COLUMN_KEY, msymbol_name (key), COLUMN_DESCRIPTION, description, - COLUMN_VALUE, format_value (value), + COLUMN_VALUE, value, -1); g_free (description); + g_free (value); } } @@ -163,95 +161,238 @@ on_edited (GtkCellRendererText *cell, gchar *new_text, gpointer data) { - ConfigContext *context = data; - GtkTreeModel *model = GTK_TREE_MODEL (context->store); + SetupDialog *dialog = data; + GtkTreeModel *model = GTK_TREE_MODEL (dialog->store); GtkTreeIter iter; GtkTreePath *path = gtk_tree_path_new_from_string (path_string); - MPlist *plist, *p, *value; - gchar *key; gtk_tree_model_get_iter (model, &iter, path); - gtk_tree_model_get (model, &iter, COLUMN_KEY, &key, -1); - plist = minput_get_variable (context->language, context->name, - msymbol (key)); - if (!plist) - goto fail; + gtk_list_store_set (dialog->store, &iter, + COLUMN_VALUE, new_text, + -1); + gtk_tree_path_free (path); +} - p = mplist_next (mplist_next (mplist_next (mplist_value (plist)))); - if (!p) - goto fail; +static void +toggle_colorbutton_sensitive (GtkToggleButton *togglebutton, + GtkWidget *colorbutton) +{ + if (gtk_toggle_button_get_active (togglebutton)) + gtk_widget_set_sensitive (colorbutton, TRUE); + else + gtk_widget_set_sensitive (colorbutton, FALSE); +} - value = parse_value (p, new_text); - if (!value) - goto fail; +static void +on_foreground_toggled (GtkToggleButton *togglebutton, + gpointer user_data) +{ + SetupDialog *dialog = user_data; + toggle_colorbutton_sensitive (togglebutton, dialog->colorbutton_foreground); +} - if (minput_config_variable (context->language, context->name, - msymbol (key), value) != 0) - goto fail; +static void +on_background_toggled (GtkToggleButton *togglebutton, + gpointer user_data) +{ + SetupDialog *dialog = user_data; + toggle_colorbutton_sensitive (togglebutton, dialog->colorbutton_background); +} - if (minput_save_config () != 1) - goto fail; +static gint +get_combo_box_index_by_value (GtkComboBox *combobox, gint value) +{ + GtkTreeModel *model; + GtkTreeIter iter; + gint index; - gtk_list_store_set (context->store, &iter, - COLUMN_VALUE, new_text, - -1); + index = 0; + model = gtk_combo_box_get_model (combobox); + if (!gtk_tree_model_get_iter_first (model, &iter)) + return -1; - fail: - gtk_tree_path_free (path); + do { + gint _value; + gtk_tree_model_get (model, &iter, COLUMN_VALUE, &_value, -1); + if (_value == value) + return index; + index++; + } while (gtk_tree_model_iter_next (model, &iter)); + return -1; } static void -color_to_gdk (guint color, GdkColor *color_gdk) +_gdk_color_from_uint (guint color, GdkColor *color_gdk) { - memset (color_gdk, 0, sizeof *color_gdk); + color_gdk->pixel = 0; color_gdk->red = (color >> 8) & 0xFF00; color_gdk->green = color & 0xFF00; color_gdk->blue = (color & 0xFF) << 8; } static void -set_color (ConfigContext *context, const gchar *name, GdkColor *color) +setup_dialog_load_config (SetupDialog *dialog) { - gchar buf[8]; + gchar *color; + gboolean bvalue; + gint ivalue; + GdkColor cvalue; + GtkCellRenderer *renderer; + gint index; - if (color) - sprintf (buf, "#%02X%02X%02X", - (color->red & 0xFF00) >> 8, - (color->green & 0xFF00) >> 8, - (color->blue & 0xFF00) >> 8); - else - strcpy (buf, "none"); - ibus_m17n_config_set_string (config, context->section, name, buf); + /* General -> Pre-edit Appearance */ + /* foreground color of pre-edit buffer */ + bvalue = FALSE; + _gdk_color_from_uint (PREEDIT_FOREGROUND, &cvalue); + if (ibus_m17n_config_get_string (dialog->config, + dialog->section, + "preedit_foreground", + &color)) { + if (g_strcmp0 (color, "none") != 0 && gdk_color_parse (color, &cvalue)) + bvalue = TRUE; + g_free (color); + } + + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(dialog->checkbutton_foreground), + bvalue); + g_signal_connect (dialog->checkbutton_foreground, "toggled", + G_CALLBACK(on_foreground_toggled), + dialog); + gtk_widget_set_sensitive (dialog->colorbutton_foreground, + bvalue); + gtk_color_button_set_color (GTK_COLOR_BUTTON(dialog->colorbutton_foreground), + &cvalue); + + /* background color of pre-edit buffer */ + bvalue = FALSE; + _gdk_color_from_uint (PREEDIT_BACKGROUND, &cvalue); + if (ibus_m17n_config_get_string (dialog->config, + dialog->section, + "preedit_background", + &color)) { + if (g_strcmp0 (color, "none") != 0 && gdk_color_parse (color, &cvalue)) + bvalue = TRUE; + g_free (color); + } + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(dialog->checkbutton_background), + bvalue); + g_signal_connect (dialog->checkbutton_background, "toggled", + G_CALLBACK(on_background_toggled), + dialog); + gtk_widget_set_sensitive (dialog->colorbutton_background, + bvalue); + gtk_color_button_set_color (GTK_COLOR_BUTTON(dialog->colorbutton_background), + &cvalue); + + /* underline of pre-edit buffer */ + renderer = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT(dialog->combobox_underline), + renderer, TRUE); + gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT(dialog->combobox_underline), + renderer, "text", 0, NULL); + if (!ibus_m17n_config_get_int (dialog->config, + dialog->section, + "preedit_underline", + &ivalue)) + ivalue = IBUS_ATTR_UNDERLINE_NONE; + + index = get_combo_box_index_by_value + (GTK_COMBO_BOX(dialog->combobox_underline), + ivalue); + gtk_combo_box_set_active (GTK_COMBO_BOX(dialog->combobox_underline), + index); + + /* General -> Other */ + renderer = gtk_cell_renderer_text_new (); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT(dialog->combobox_orientation), + renderer, TRUE); + gtk_cell_layout_set_attributes + (GTK_CELL_LAYOUT(dialog->combobox_orientation), + renderer, "text", 0, NULL); + if (!ibus_m17n_config_get_int (dialog->config, + dialog->section, + "lookup_table_orientation", + &ivalue)) + ivalue = IBUS_ORIENTATION_SYSTEM; + + index = get_combo_box_index_by_value + (GTK_COMBO_BOX(dialog->combobox_orientation), + ivalue); + gtk_combo_box_set_active (GTK_COMBO_BOX(dialog->combobox_orientation), + index); + + /* Advanced -> m17n-lib configuration */ + dialog->store = gtk_list_store_new (NUM_COLS, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING); + insert_m17n_items (dialog->store, + msymbol (dialog->lang), + msymbol (dialog->name)); + + gtk_tree_view_set_model (GTK_TREE_VIEW(dialog->treeview), + GTK_TREE_MODEL (dialog->store)); + + renderer = gtk_cell_renderer_text_new (); + gtk_tree_view_insert_column_with_attributes + (GTK_TREE_VIEW (dialog->treeview), -1, + "Key", + renderer, + "text", COLUMN_KEY, + NULL); + renderer = gtk_cell_renderer_text_new (); + gtk_tree_view_insert_column_with_attributes + (GTK_TREE_VIEW (dialog->treeview), -1, + "Value", + renderer, + "text", COLUMN_VALUE, + NULL); + g_object_set (renderer, "editable", TRUE, NULL); + g_signal_connect (renderer, "edited", G_CALLBACK(on_edited), dialog); + + g_signal_connect (dialog->treeview, "query-tooltip", + G_CALLBACK(on_query_tooltip), NULL); } -static void -on_foreground_color_set (GtkColorButton *widget, - gpointer user_data) +static gchar * +_gdk_color_to_string (GdkColor *color) { - ConfigContext *context = user_data; - GdkColor color; - - gtk_color_button_get_color (GTK_COLOR_BUTTON(widget), &color); - set_color (context, "preedit_foreground", &color); + g_strdup_printf ("#%02X%02X%02X", + (color->red & 0xFF00) >> 8, + (color->green & 0xFF00) >> 8, + (color->blue & 0xFF00) >> 8); } static void -on_background_color_set (GtkColorButton *widget, - gpointer user_data) +save_color (SetupDialog *dialog, + GtkToggleButton *togglebutton, + GtkColorButton *colorbutton, + const gchar *name) { - ConfigContext *context = user_data; - GdkColor color; - - gtk_color_button_get_color (GTK_COLOR_BUTTON(widget), &color); - set_color (context, "preedit_background", &color); + if (gtk_toggle_button_get_active (togglebutton)) { + GdkColor color; + gchar *svalue; + + gtk_color_button_get_color (colorbutton, &color); + svalue = _gdk_color_to_string (&color); + ibus_m17n_config_set_string (dialog->config, + dialog->section, + name, + svalue); + g_free (svalue); + } else + ibus_m17n_config_set_string (dialog->config, + dialog->section, + name, + "none"); } static void -on_underline_changed (GtkComboBox *combo, - gpointer user_data) +save_choice (SetupDialog *dialog, + GtkComboBox *combo, + const gchar *name) { - ConfigContext *context = user_data; GtkTreeModel *model; GtkTreeIter iter; gint active; @@ -260,123 +401,164 @@ on_underline_changed (GtkComboBox *combo, gtk_combo_box_get_active_iter (combo, &iter); gtk_tree_model_get (model, &iter, COLUMN_VALUE, &active, -1); - ibus_m17n_config_set_int (config, - context->section, - "preedit_underline", - active); + ibus_m17n_config_set_int (dialog->config, dialog->section, name, active); } -static void -on_orientation_changed (GtkComboBox *combo, - gpointer user_data) +static gboolean +save_m17n_options (SetupDialog *dialog) { - ConfigContext *context = user_data; - GtkTreeModel *model; + GtkTreeModel *model = GTK_TREE_MODEL (dialog->store); GtkTreeIter iter; - gint active; + MPlist *plist, *p, *mvalue = NULL; + MSymbol lang, name; + gchar *key = NULL, *value = NULL; + gboolean retval = TRUE; - model = gtk_combo_box_get_model (combo); - gtk_combo_box_get_active_iter (combo, &iter); - gtk_tree_model_get (model, &iter, COLUMN_VALUE, &active, -1); + if (!gtk_tree_model_get_iter_first (model, &iter)) + return; - ibus_m17n_config_set_int (config, - context->section, - "lookup_table_orientation", - active); -} + lang = msymbol (dialog->lang); + name = msymbol (dialog->name); -static void -toggle_color (ConfigContext *context, - GtkToggleButton *togglebutton, - GtkWidget *colorbutton, - const gchar *name) -{ - GdkColor color; + do { + gtk_tree_model_get (model, &iter, + COLUMN_KEY, &key, + COLUMN_VALUE, &value, + -1); - if (gtk_toggle_button_get_active (togglebutton)) { - gtk_widget_set_sensitive (colorbutton, TRUE); - gtk_color_button_get_color (GTK_COLOR_BUTTON(colorbutton), &color); - set_color (context, name, &color); - } else { - gtk_widget_set_sensitive (colorbutton, FALSE); - gtk_color_button_get_color (GTK_COLOR_BUTTON(colorbutton), &color); - set_color (context, name, NULL); - } + plist = minput_get_variable (lang, name, msymbol (key)); + if (!plist) { + retval = FALSE; + break; + } + + p = mplist_next (mplist_next (mplist_next (mplist_value (plist)))); + if (!p) { + retval = FALSE; + break; + } + + mvalue = parse_m17n_value (p, value); + if (!mvalue) { + retval = FALSE; + break; + } + + if (minput_config_variable (lang, name, msymbol (key), mvalue) != 0) { + retval = FALSE; + break; + } + + if (mvalue) + m17n_object_unref (mvalue); + g_free (key); + g_free (value); + mvalue = NULL; + key = NULL; + value = NULL; + } while (gtk_tree_model_iter_next (model, &iter)); + + if (retval && minput_save_config () != 1) + retval = FALSE; + + if (mvalue) + m17n_object_unref (mvalue); + g_free (key); + g_free (value); + + return retval; } static void -on_foreground_toggled (GtkToggleButton *togglebutton, - gpointer user_data) +setup_dialog_save_config (SetupDialog *dialog) { - ConfigContext *context = user_data; - - toggle_color (context, - togglebutton, - context->colorbutton_foreground, - "preedit_foreground"); + save_color (dialog, + GTK_TOGGLE_BUTTON(dialog->checkbutton_foreground), + GTK_COLOR_BUTTON(dialog->colorbutton_foreground), + "preedit_foreground"); + save_color (dialog, + GTK_TOGGLE_BUTTON(dialog->checkbutton_background), + GTK_COLOR_BUTTON(dialog->colorbutton_background), + "preedit_background"); + save_choice (dialog, + GTK_COMBO_BOX(dialog->combobox_underline), + "preedit_underline"); + save_choice (dialog, + GTK_COMBO_BOX(dialog->combobox_orientation), + "lookup_table_orientation"); + save_m17n_options (dialog); } -static void -on_background_toggled (GtkToggleButton *togglebutton, - gpointer user_data) +static SetupDialog * +setup_dialog_new (IBusConfig *config, + const gchar *lang, + const gchar *name) { - ConfigContext *context = user_data; + GtkBuilder *builder; + SetupDialog *dialog; + GObject *object; + GError *error; + + dialog = g_slice_new0 (SetupDialog); + dialog->config = g_object_ref_sink (config); + dialog->lang = g_strdup (lang); + dialog->name = g_strdup (name); + dialog->section = g_strdup_printf ("engine/M17N/%s/%s", lang, name); + + builder = gtk_builder_new (); + gtk_builder_set_translation_domain (builder, "ibus-m17n"); + + error = NULL; + gtk_builder_add_from_file (builder, + SETUPDIR "/ibus-m17n-preferences.ui", + &error); + g_assert_no_error (error); + + object = gtk_builder_get_object (builder, "dialog"); + dialog->dialog = GTK_WIDGET(object); + object = gtk_builder_get_object (builder, "checkbutton_foreground"); + dialog->checkbutton_foreground = GTK_WIDGET(object); + object = gtk_builder_get_object (builder, "colorbutton_foreground"); + dialog->colorbutton_foreground = GTK_WIDGET(object); + object = gtk_builder_get_object (builder, "checkbutton_background"); + dialog->checkbutton_background = GTK_WIDGET(object); + object = gtk_builder_get_object (builder, "colorbutton_background"); + dialog->colorbutton_background = GTK_WIDGET(object); + object = gtk_builder_get_object (builder, "combobox_underline"); + dialog->combobox_underline = GTK_WIDGET(object); + object = gtk_builder_get_object (builder, "combobox_orientation"); + dialog->combobox_orientation = GTK_WIDGET(object); + object = gtk_builder_get_object (builder, "treeview_mim_config"); + dialog->treeview = GTK_WIDGET(object); - toggle_color (context, - togglebutton, - context->colorbutton_background, - "preedit_background"); + return dialog; } -static gint -get_combo_box_index_by_value (GtkComboBox *combobox, gint value) +static void +setup_dialog_free (SetupDialog *dialog) { - GtkTreeModel *model; - GtkTreeIter iter; - gint index; + gtk_widget_destroy (dialog->dialog); - index = 0; - model = gtk_combo_box_get_model (combobox); - if (!gtk_tree_model_get_iter_first (model, &iter)) - return -1; + g_free (dialog->lang); + g_free (dialog->name); - do { - gint _value; - gtk_tree_model_get (model, &iter, COLUMN_VALUE, &_value, -1); - if (_value == value) - return index; - index++; - } while (gtk_tree_model_iter_next (model, &iter)); - return -1; + g_free (dialog->section); + g_object_unref (dialog->store); + g_slice_free (SetupDialog, dialog); } static void start (const gchar *engine_name) { IBusBus *bus; - gchar **strv, *lang, *name; - GtkBuilder *builder; - GtkWidget *dialog; - GtkWidget *combobox_underline, *combobox_orientation; - GtkWidget *checkbutton_foreground, *checkbutton_background; - GtkWidget *treeview; - GtkListStore *store; + IBusConfig *config; + gchar **strv, *lang, *name, *section; + SetupDialog *dialog; GObject *object; GError *error = NULL; - GtkCellRenderer *renderer; - ConfigContext context; - gchar *color; - gboolean is_foreground_set, is_background_set; - GdkColor foreground, background; - gint underline; - gint orientation; - gint index; ibus_init (); - - bus = ibus_bus_new (); - //g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL); - ibus_m17n_init (bus); + ibus_m17n_init_common (); strv = g_strsplit (engine_name, ":", 3); @@ -386,150 +568,25 @@ start (const gchar *engine_name) lang = strv[1]; name = strv[2]; - config = ibus_bus_get_config (bus); - context.section = g_strdup_printf ("engine/M17N/%s/%s", lang, name); - - builder = gtk_builder_new (); - gtk_builder_set_translation_domain (builder, "ibus-m17n"); - gtk_builder_add_from_file (builder, - SETUPDIR "/ibus-m17n-preferences.ui", - &error); - object = gtk_builder_get_object (builder, "dialog"); - dialog = GTK_WIDGET(object); - object = gtk_builder_get_object (builder, "checkbutton_foreground"); - checkbutton_foreground = GTK_WIDGET(object); - object = gtk_builder_get_object (builder, "colorbutton_foreground"); - context.colorbutton_foreground = GTK_WIDGET(object); - object = gtk_builder_get_object (builder, "checkbutton_background"); - checkbutton_background = GTK_WIDGET(object); - object = gtk_builder_get_object (builder, "colorbutton_background"); - context.colorbutton_background = GTK_WIDGET(object); - object = gtk_builder_get_object (builder, "combobox_underline"); - combobox_underline = GTK_WIDGET(object); - object = gtk_builder_get_object (builder, "combobox_orientation"); - combobox_orientation = GTK_WIDGET(object); - object = gtk_builder_get_object (builder, "treeviewMimConfig"); - treeview = GTK_WIDGET(object); - - /* General -> Pre-edit Appearance */ - /* foreground color of pre-edit buffer */ - is_foreground_set = FALSE; - color_to_gdk (PREEDIT_FOREGROUND, &foreground); - if (ibus_m17n_config_get_string (config, - context.section, - "preedit_foreground", - &color)) { - if (g_strcmp0 (color, "none") != 0 && - gdk_color_parse (color, &foreground)) - is_foreground_set = TRUE; - g_free (color); - } + bus = ibus_bus_new (); + //g_signal_connect (bus, "disconnected", G_CALLBACK (ibus_disconnected_cb), NULL); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkbutton_foreground), - is_foreground_set); - g_signal_connect (checkbutton_foreground, "toggled", - G_CALLBACK(on_foreground_toggled), - &context); - gtk_widget_set_sensitive (context.colorbutton_foreground, - is_foreground_set); - gtk_color_button_set_color - (GTK_COLOR_BUTTON(context.colorbutton_foreground), - &foreground); - g_signal_connect (context.colorbutton_foreground, "color-set", - G_CALLBACK(on_foreground_color_set), &context); + config = ibus_bus_get_config (bus); + dialog = setup_dialog_new (config, lang, name); - - /* background color of pre-edit buffer */ - is_background_set = FALSE; - color_to_gdk (PREEDIT_BACKGROUND, &background); - if (ibus_m17n_config_get_string (config, - context.section, - "preedit_background", - &color)) { - if (g_strcmp0 (color, "none") != 0 && - gdk_color_parse (color, &background)) - is_background_set = TRUE; - g_debug ("preedit_background %d", is_background_set); - g_free (color); - } - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkbutton_background), - is_background_set); - g_signal_connect (checkbutton_background, "toggled", - G_CALLBACK(on_background_toggled), - &context); - gtk_widget_set_sensitive (context.colorbutton_background, - is_background_set); - gtk_color_button_set_color - (GTK_COLOR_BUTTON(context.colorbutton_background), - &background); - g_signal_connect (context.colorbutton_background, "color-set", - G_CALLBACK(on_background_color_set), &context); + g_strfreev (strv); - /* underline of pre-edit buffer */ - renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT(combobox_underline), - renderer, TRUE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT(combobox_underline), - renderer, "text", 0, NULL); - if (!ibus_m17n_config_get_int (config, - context.section, - "preedit_underline", - &underline)) - underline = IBUS_ATTR_UNDERLINE_NONE; + setup_dialog_load_config (dialog); - index = get_combo_box_index_by_value (GTK_COMBO_BOX(combobox_underline), - underline); - gtk_combo_box_set_active (GTK_COMBO_BOX(combobox_underline), index); - g_signal_connect (combobox_underline, "changed", - G_CALLBACK(on_underline_changed), &context); + gtk_widget_show_all (dialog->dialog); + gtk_dialog_run (GTK_DIALOG(dialog->dialog)); - /* General -> Other */ - renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT(combobox_orientation), - renderer, TRUE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT(combobox_orientation), - renderer, "text", 0, NULL); - if (!ibus_m17n_config_get_int (config, - context.section, - "lookup_table_orientation", - &orientation)) - orientation = IBUS_ORIENTATION_SYSTEM; - - index = get_combo_box_index_by_value (GTK_COMBO_BOX(combobox_orientation), - orientation); - gtk_combo_box_set_active (GTK_COMBO_BOX(combobox_orientation), index); - g_signal_connect (combobox_orientation, "changed", - G_CALLBACK(on_orientation_changed), &context); + setup_dialog_save_config (dialog); + setup_dialog_free (dialog); - /* Advanced -> m17n-lib configuration */ - store = gtk_list_store_new (NUM_COLS, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING); - insert_items (store, msymbol (lang), msymbol (name)); - - gtk_tree_view_set_model (GTK_TREE_VIEW(treeview), GTK_TREE_MODEL (store)); - gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1, - "Key", - gtk_cell_renderer_text_new (), - "text", COLUMN_KEY, NULL); - g_object_set (treeview, "has-tooltip", TRUE, NULL); - g_signal_connect (treeview, "query-tooltip", G_CALLBACK(on_query_tooltip), - NULL); - - context.language = msymbol (lang); - context.name = msymbol (name); - context.store = store; - renderer = gtk_cell_renderer_text_new (); - gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1, - "Value", - renderer, - "text", COLUMN_VALUE, NULL); - g_object_set (renderer, "editable", TRUE, NULL); - g_signal_connect (renderer, "edited", G_CALLBACK(on_edited), &context); + g_object_unref (bus); - gtk_widget_show_all (dialog); - gtk_dialog_run (GTK_DIALOG(dialog)); + M17N_FINI (); } int -- 1.7.6.1