diff --git a/scim-wnn/src/scim_wnn_imengine_setup.cpp b/scim-wnn/src/scim_wnn_imengine_setup.cpp index 1f5d2a9..36164f8 100644 --- a/scim-wnn/src/scim_wnn_imengine_setup.cpp +++ b/scim-wnn/src/scim_wnn_imengine_setup.cpp @@ -73,6 +73,7 @@ ****����Υ�꡼���Ǥ�����⥸�塼�����ܤ����ޤ���**** !!!��꡼���女���ȥ����Ȥ򳰤��ƥǥХ�!!! +*/ extern "C" { void scim_module_init (void) @@ -102,7 +103,7 @@ String scim_setup_module_get_description (void) { - return String (_("An Wnn IMEngine Module.")); + return String (_("A Wnn IMEngine Module.")); } void scim_setup_module_load_config (const ConfigPointer &config) @@ -121,7 +122,6 @@ } } // extern "C" -*/ // Internal data structure struct KeyboardConfigData @@ -135,17 +135,26 @@ GtkWidget *button; }; +struct KeyboardConfigPage +{ + const char *label; + KeyboardConfigData *data; +}; + // Internal data declaration. -static bool __config_use_kana = false; +//static bool __config_use_kana = false; +static String __config_server = SCIM_DEFAULT_WNN_SERVER; +static String __config_wnn_rc = SCIM_DEFAULT_WNN_RC; static bool __have_changed = true; -static GtkWidget * __widget_use_kana = 0; +//static GtkWidget * __widget_use_kana = 0; +static GtkWidget * __widget_server = 0; +static GtkWidget * __widget_wnn_rc = 0; static GtkTooltips * __widget_tooltips = 0; -static KeyboardConfigData __config_keyboards [] = +static KeyboardConfigData __config_keyboards_common [] = { - /* edit */ { SCIM_CONFIG_WNN_KEY_COMMIT, SCIM_DEFAULT_WNN_KEY_COMMIT, @@ -191,8 +200,19 @@ NULL, NULL, }, + { + NULL, + "", + NULL, + NULL, + NULL, + NULL, + NULL, + }, +}; - /* caret */ +static KeyboardConfigData __config_keyboards_caret [] = +{ { SCIM_CONFIG_WNN_KEY_FORWARD, SCIM_DEFAULT_WNN_KEY_FORWARD, @@ -211,8 +231,19 @@ NULL, NULL, }, + { + NULL, + "", + NULL, + NULL, + NULL, + NULL, + NULL, + }, +}; - /* segment */ +static KeyboardConfigData __config_keyboards_segment [] = +{ { SCIM_CONFIG_WNN_KEY_CONVERSION_FORWARD, SCIM_DEFAULT_WNN_KEY_CONVERSION_FORWARD, @@ -249,8 +280,19 @@ NULL, NULL, }, + { + NULL, + "", + NULL, + NULL, + NULL, + NULL, + NULL, + }, +}; - /* candidates */ +static KeyboardConfigData __config_keyboards_candidates [] = +{ { SCIM_CONFIG_WNN_KEY_CONVERSION_NEXT, SCIM_DEFAULT_WNN_KEY_CONVERSION_NEXT, @@ -287,9 +329,6 @@ NULL, NULL, }, - - /* convert */ - /* mode */ { NULL, "", @@ -300,32 +339,32 @@ NULL, }, }; -/* FIXME! */ -#if 1 -static unsigned int key_nums[] = + +static struct KeyboardConfigPage __key_conf_pages[] = { - 3,4,8, + {"Common keys", __config_keyboards_common}, + {"Preedit keys", __config_keyboards_caret}, + {"Candidates keys", __config_keyboards_candidates}, }; -static char *key_conf_page_labels[] = -{ - "Common keys","preedit keys","convert keys", -}; -static unsigned int key_conf_pages = sizeof (key_nums) / sizeof (unsigned int); -#endif +static unsigned int __key_conf_pages_num = sizeof (__key_conf_pages) / sizeof (KeyboardConfigPage); static void on_default_editable_changed (GtkEditable *editable, gpointer user_data); +/* static void on_default_toggle_button_toggled (GtkToggleButton *togglebutton, gpointer user_data); +*/ static void on_default_key_selection_clicked (GtkButton *button, gpointer user_data); -void setup_widget_value (); +static void on_default_file_selection_button (GtkButton *button, + gpointer user_data); +static void setup_widget_value (void); static GtkWidget * create_options_page () { - GtkWidget *vbox; + GtkWidget *vbox, *table, *label, *button; vbox = gtk_vbox_new (FALSE, 0); gtk_widget_show (vbox); @@ -340,6 +379,60 @@ // G_CALLBACK (on_default_toggle_button_toggled), // &__config_use_kana); + table = gtk_table_new (3, 3, FALSE); + gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0); + gtk_widget_show (table); + + /* server */ + label = gtk_label_new_with_mnemonic ("_Server: "); + gtk_widget_show (label); + gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); + gtk_misc_set_padding (GTK_MISC (label), 4, 0); + gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (GTK_FILL), 4, 4); + + __widget_server = gtk_entry_new (); + gtk_widget_show (__widget_server); + gtk_table_attach (GTK_TABLE (table), __widget_server, 1, 2, 0, 1, + (GtkAttachOptions) (GTK_FILL|GTK_EXPAND), + (GtkAttachOptions) (GTK_FILL), 4, 4); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), __widget_server); + + /* wnnenvrc */ + label = gtk_label_new_with_mnemonic ("_wnnenvrc: "); + gtk_widget_show (label); + gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); + gtk_misc_set_padding (GTK_MISC (label), 4, 0); + gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (GTK_FILL), 4, 4); + + __widget_wnn_rc = gtk_entry_new (); + gtk_widget_show (__widget_wnn_rc); + gtk_table_attach (GTK_TABLE (table), __widget_wnn_rc, 1, 2, 1, 2, + (GtkAttachOptions) (GTK_FILL|GTK_EXPAND), + (GtkAttachOptions) (GTK_FILL), 4, 4); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), __widget_wnn_rc); + + button = gtk_button_new_with_label ("..."); + gtk_widget_show (button); + gtk_table_attach (GTK_TABLE (table), button, 2, 3, 1, 2, + (GtkAttachOptions) (GTK_FILL), + (GtkAttachOptions) (GTK_FILL), 4, 4); + //gtk_label_set_mnemonic_widget (GTK_LABEL (label), button); + + /* connect all signals */ + g_signal_connect ((gpointer) __widget_server, "changed", + G_CALLBACK (on_default_editable_changed), + &__config_server); + g_signal_connect ((gpointer) __widget_wnn_rc, "changed", + G_CALLBACK (on_default_editable_changed), + &__config_wnn_rc); + g_signal_connect ((gpointer) button, "clicked", + G_CALLBACK (on_default_file_selection_button), + __widget_wnn_rc); + return vbox; } @@ -348,22 +441,19 @@ { GtkWidget *table; GtkWidget *label; - unsigned int i, start = 0, end = 0; - if (page >= key_conf_pages) + if (page >= __key_conf_pages_num) return NULL; - for (i = 0; i < page; i++) - start += key_nums[i]; - end = start + key_nums[page]; + KeyboardConfigData *data = __key_conf_pages[page].data; table = gtk_table_new (3, 3, FALSE); gtk_widget_show (table); // Create keyboard setting. - for (i = start; i < end /*__config_keyboards [i].key*/; ++ i) { + for (unsigned int i = 0; data[i].key; ++ i) { label = gtk_label_new (NULL); - gtk_label_set_text_with_mnemonic (GTK_LABEL (label), _(__config_keyboards[i].label)); + gtk_label_set_text_with_mnemonic (GTK_LABEL (label), _(data[i].label)); gtk_widget_show (label); gtk_misc_set_alignment (GTK_MISC (label), 1.0, 0.5); gtk_misc_set_padding (GTK_MISC (label), 4, 0); @@ -371,33 +461,35 @@ (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (GTK_FILL), 4, 4); - __config_keyboards [i].entry = gtk_entry_new (); - gtk_widget_show (__config_keyboards [i].entry); - gtk_table_attach (GTK_TABLE (table), __config_keyboards [i].entry, 1, 2, i, i+1, + data[i].entry = gtk_entry_new (); + gtk_widget_show (data[i].entry); + gtk_table_attach (GTK_TABLE (table), data[i].entry, 1, 2, i, i+1, (GtkAttachOptions) (GTK_FILL|GTK_EXPAND), (GtkAttachOptions) (GTK_FILL), 4, 4); - gtk_entry_set_editable (GTK_ENTRY (__config_keyboards[i].entry), FALSE); + gtk_entry_set_editable (GTK_ENTRY (data[i].entry), FALSE); - __config_keyboards[i].button = gtk_button_new_with_label ("..."); - gtk_widget_show (__config_keyboards[i].button); - gtk_table_attach (GTK_TABLE (table), __config_keyboards[i].button, 2, 3, i, i+1, + data[i].button = gtk_button_new_with_label ("..."); + gtk_widget_show (data[i].button); + gtk_table_attach (GTK_TABLE (table), data[i].button, 2, 3, i, i+1, (GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (GTK_FILL), 4, 4); - gtk_label_set_mnemonic_widget (GTK_LABEL (label), __config_keyboards[i].button); + gtk_label_set_mnemonic_widget (GTK_LABEL (label), data[i].button); } - for (i = start; i < end /*__config_keyboards [i].key*/; ++ i) { - g_signal_connect ((gpointer) __config_keyboards [i].button, "clicked", + for (unsigned int i = 0; data[i].key; ++ i) { + g_signal_connect ((gpointer) data[i].button, "clicked", G_CALLBACK (on_default_key_selection_clicked), - &(__config_keyboards [i])); - g_signal_connect ((gpointer) __config_keyboards [i].entry, "changed", + &(data[i])); + g_signal_connect ((gpointer) data[i].entry, "changed", G_CALLBACK (on_default_editable_changed), - &(__config_keyboards [i].data)); + &(data[i].data)); } - for (i = start; i < end /*__config_keyboards [i].key*/; ++ i) { - gtk_tooltips_set_tip (__widget_tooltips, __config_keyboards [i].entry, - _(__config_keyboards [i].tooltip), NULL); + if (!__widget_tooltips) + __widget_tooltips = gtk_tooltips_new(); + for (unsigned int i = 0; data[i].key; ++ i) { + gtk_tooltips_set_tip (__widget_tooltips, data[i].entry, + _(data[i].tooltip), NULL); } return table; @@ -420,12 +512,12 @@ gtk_widget_show (label); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, label); - //setup_widget_value (); + setup_widget_value (); // Create the second page. - for (unsigned int i = 0; i < key_conf_pages; i++) { + for (unsigned int i = 0; i < __key_conf_pages_num; i++) { page = create_keyboard_page (i); - label = gtk_label_new (_(key_conf_page_labels[i])); + label = gtk_label_new (_(__key_conf_pages[i].label)); gtk_widget_show (label); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, label); } @@ -436,36 +528,57 @@ return window; } -void -setup_widget_value () +static void +setup_widget_value (void) { // if (__widget_use_kana) { // gtk_toggle_button_set_active ( // GTK_TOGGLE_BUTTON (__widget_use_kana), // __config_use_kana); // } + if (__widget_server) { + gtk_entry_set_text ( + GTK_ENTRY (__widget_server), + __config_server.c_str ()); + } - for (int i = 0; __config_keyboards [i].key; ++ i) { - if (__config_keyboards [i].entry) { - gtk_entry_set_text ( - GTK_ENTRY (__config_keyboards [i].entry), - __config_keyboards [i].data.c_str ()); + if (__widget_wnn_rc) { + gtk_entry_set_text ( + GTK_ENTRY (__widget_wnn_rc), + __config_wnn_rc.c_str ()); + } + + for (unsigned int j = 0; j < __key_conf_pages_num; ++ j) { + for (unsigned int i = 0; __key_conf_pages[j].data[i].key; ++ i) { + if (__key_conf_pages[j].data[i].entry) { + gtk_entry_set_text ( + GTK_ENTRY (__key_conf_pages[j].data[i].entry), + __key_conf_pages[j].data[i].data.c_str ()); + } } } } -void +static void load_config (const ConfigPointer &config) { if (!config.null ()) { // __config_use_kana = // config->read (String (SCIM_CONFIG_IMENGINE_ANTHY_USE_KANA), // __config_use_kana); + __config_server = + config->read (String (SCIM_CONFIG_WNN_SERVER), + __config_server); + __config_wnn_rc = + config->read (String (SCIM_CONFIG_WNN_RC), + __config_wnn_rc); - for (int i = 0; __config_keyboards [i].key; ++ i) { - __config_keyboards [i].data = - config->read (String (__config_keyboards [i].key), - __config_keyboards [i].data); + for (unsigned int j = 0; j < __key_conf_pages_num; j++) { + for (unsigned int i = 0; __key_conf_pages[j].data[i].key; ++ i) { + __key_conf_pages[j].data[i].data = + config->read (String (__key_conf_pages[j].data[i].key), + __key_conf_pages[j].data[i].data); + } } setup_widget_value (); @@ -474,29 +587,36 @@ } } -void +static void save_config (const ConfigPointer &config) { if (!config.null ()) { // config->write (String (SCIM_CONFIG_IMENGINE_ANTHY_USE_KANA), // __config_use_kana); + config->write (String (SCIM_CONFIG_WNN_SERVER), + __config_server); + config->write (String (SCIM_CONFIG_WNN_RC), + __config_wnn_rc); - for (int i = 0; __config_keyboards [i].key; ++ i) { - config->write (String (__config_keyboards [i].key), - __config_keyboards [i].data); + for (unsigned j = 0; j < __key_conf_pages_num; j++) { + for (unsigned int i = 0; __key_conf_pages[j].data[i].key; ++ i) { + config->write (String (__key_conf_pages[j].data[i].key), + __key_conf_pages[j].data[i].data); + } } __have_changed = false; } } -bool +static bool query_changed () { return __have_changed; } +/* static void on_default_toggle_button_toggled (GtkToggleButton *togglebutton, gpointer user_data) @@ -508,6 +628,7 @@ __have_changed = true; } } +*/ static void on_default_editable_changed (GtkEditable *editable, @@ -550,3 +671,34 @@ gtk_widget_destroy (dialog); } } + +static void +on_ok_clicked (GtkButton *button, gpointer user_data) +{ + bool *ok = static_cast(user_data); + if (ok) + *ok = true; +} + +static void +on_default_file_selection_button (GtkButton *button, gpointer user_data) +{ + GtkEntry *entry = GTK_ENTRY (user_data); + const char *path = gtk_entry_get_text (entry); + bool ok = false; + + GtkFileSelection *sel = GTK_FILE_SELECTION (gtk_file_selection_new ("Select a file")); + gtk_file_selection_set_filename (sel, path); + g_signal_connect (G_OBJECT (sel->ok_button), "clicked", + G_CALLBACK (on_ok_clicked), + (gpointer) &ok); + gtk_window_set_transient_for ( + GTK_WINDOW (sel), + GTK_WINDOW (gtk_widget_get_toplevel(GTK_WIDGET (entry)))); + gtk_dialog_run (GTK_DIALOG (sel)); + + if (ok) + gtk_entry_set_text (entry, gtk_file_selection_get_filename (sel)); + + gtk_widget_destroy (GTK_WIDGET (sel)); +}