rpms/scim-pinyin/devel scim-pinyin-helper.patch,NONE,1.1
fedora-cvs-commits at redhat.com
fedora-cvs-commits at redhat.com
Tue Jun 27 02:55:07 UTC 2006
Author: qshen
Update of /cvs/dist/rpms/scim-pinyin/devel
In directory cvs.devel.redhat.com:/tmp/cvs-serv16437
Added Files:
scim-pinyin-helper.patch
Log Message:
qshen: add scim-pinyin-helper.patch
scim-pinyin-helper.patch:
configure.ac | 9
po/POTFILES.in | 1
po/zh_CN.po | 135 +++
src/Makefile.am | 19
src/scim_pinyin_helper.cpp | 1130 +++++++++++++++++++++++++++++++++
src/scim_pinyin_helper.h | 56 +
src/scim_pinyin_imengine.cpp | 307 ++++++++
src/scim_pinyin_imengine.h | 8
src/scim_pinyin_imengine_config_keys.h | 3
src/scim_pinyin_imengine_setup.cpp | 31
src/scim_pinyin_phrase.h | 6
11 files changed, 1694 insertions(+), 11 deletions(-)
--- NEW FILE scim-pinyin-helper.patch ---
diff -Naur scim-pinyin-0.5.91.bak/configure.ac scim-pinyin-0.5.91/configure.ac
--- scim-pinyin-0.5.91.bak/configure.ac 2006-06-23 16:15:55.000000000 +0800
+++ scim-pinyin-0.5.91/configure.ac 2006-06-27 09:51:26.000000000 +0800
@@ -46,10 +46,17 @@
else
SCIM_BUILD_SETUP=0
fi
-
AM_CONDITIONAL(SCIM_BUILD_SETUP, [test "$SCIM_HAS_GTKUTILS" = "yes"])
AC_SUBST(SCIM_BUILD_SETUP)
+if test "$SCIM_HAS_GTKUTILS" = "yes"; then
+ SCIM_BUILD_HELPER=1
+else
+ SCIM_BUILD_HELPER=0
+fi
+
+AM_CONDITIONAL(SCIM_BUILD_HELPER, [test "$SCIM_HAS_GTKUTILS" = "yes"])
+AC_SUBST(SCIM_BUILD_HELPER)
# Checks for header files.
AC_HEADER_STDC
diff -Naur scim-pinyin-0.5.91.bak/po/POTFILES.in scim-pinyin-0.5.91/po/POTFILES.in
--- scim-pinyin-0.5.91.bak/po/POTFILES.in 2006-06-23 16:15:55.000000000 +0800
+++ scim-pinyin-0.5.91/po/POTFILES.in 2006-06-27 09:51:39.000000000 +0800
@@ -1,2 +1,3 @@
src/scim_pinyin_imengine.cpp
src/scim_pinyin_imengine_setup.cpp
+src/scim_pinyin_helper.cpp
diff -Naur scim-pinyin-0.5.91.bak/po/zh_CN.po scim-pinyin-0.5.91/po/zh_CN.po
--- scim-pinyin-0.5.91.bak/po/zh_CN.po 2006-06-23 16:15:55.000000000 +0800
+++ scim-pinyin-0.5.91/po/zh_CN.po 2006-06-27 09:51:49.000000000 +0800
@@ -480,3 +480,138 @@
#~ msgstr ""
#~ "è¿ä¸ªæ¨¡ååºè¯¥æ¯æçè¯è¨ç¯å¢(locale). å¤ä¸ªè¯è¨ç¯å¢å¯ä»¥ç¨éå·åå¼. 设为 "
#~ "\"default\" 以使ç¨å
建ç缺çå¼."
+
+#: src/scim_pinyin_helper.cpp:55
+msgid "Smart pinyin helper"
+msgstr "æºè½æ¼é³è¾
å©ç¨åº"
+
+#: src/scim_pinyin_helper.cpp:57
+msgid "A helper module for Smart Pinyin IMEngine."
+msgstr "æºè½æ¼é³è¾å
¥æ³å¼æçè¾
å©æ¨¡å"
+
+#: src/scim_pinyin_helper.cpp:270
+msgid "please select a directory."
+msgstr "请éæ©ä¸ä¸ªç®å½"
+
+#: src/scim_pinyin_helper.cpp:270
+msgid "please select the directory that contains the user phrase library."
+msgstr "请éæ©å
å«ç¨æ·è¯åºçç®å½"
+
+#: src/scim_pinyin_helper.cpp:337
+msgid "Invalid phrase libraries in this directory!"
+msgstr "æ¬ç®å½ä¸çè¯åºæ¯æ æçï¼"
+
+#: src/scim_pinyin_helper.cpp:529
+msgid "The phrase length exeed the MAX_USER_PHRASE_LENGTH!"
+msgstr "çè¯é¿åº¦è¶
è¿æ大é¿åº¦ï¼"
+
+#: src/scim_pinyin_helper.cpp:589
+msgid "Invalid pinyin key in the input pinyin sequence."
+msgstr "è¾å
¥çæ¼é³åºåä¸åå¨æ æå¼ã"
+
+#: src/scim_pinyin_helper.cpp:642
+msgid "Pinyin keys number is not equal to the phrase charachater number."
+msgstr "æ¼é³é³èæ°ä¸çè¯åç¬¦æ° ä¸ä¸è´ã"
+
+#: src/scim_pinyin_helper.cpp:780
+msgid "Success to save the user phrase library."
+msgstr "æåä¿åç¨æ·è¯åºã"
+
+#: src/scim_pinyin_helper.cpp:794
+msgid "Failed to save the user phrase library."
+msgstr "ä¿åç¨æ·è¯åºå¤±è´¥ã"
+
+#: src/scim_pinyin_helper.cpp:808
+msgid "Success to import the user phrase library."
+msgstr "æå导å
¥ç¨æ·è¯åºã"
+
+#: src/scim_pinyin_helper.cpp:829
+msgid "Failed to import the user phrase library."
+msgstr "导å
¥ç¨æ·è¯åºå¤±è´¥ã"
+
+#: src/scim_pinyin_helper.cpp:854
+msgid "Success to add the new phrases into the user phrase library."
+msgstr "æåå°è¯¥è¯ç»å å
¥ç¨æ·è¯åºã"
+
+#: src/scim_pinyin_helper.cpp:924
+msgid "ID"
+msgstr "ç¼å·"
+
+#: src/scim_pinyin_helper.cpp:924
+msgid "PHRASE"
+msgstr "è¯ç»"
+
+#: src/scim_pinyin_helper.cpp:924
+msgid "PINYIN"
+msgstr "æ¼é³"
+
+#: src/scim_pinyin_helper.cpp:989
+msgid "SCIM Pinyin - Add New Phrase"
+msgstr "SCIM æºè½æ¼é³ï¼ é
ç½®ç¨æ·è¯åº"
+
+#: src/scim_pinyin_helper.cpp:999
+msgid "_Options"
+msgstr "é项(_O)"
+
+#: src/scim_pinyin_helper.cpp:1015
+msgid "_Actions"
+msgstr "æä½(_A)"
+
+#: src/scim_pinyin_helper.cpp:1027
+msgid "_List User Phrase Library"
+msgstr "æ¾ç¤ºç¨æ·è¯åº(_L)"
+
+#: src/scim_pinyin_helper.cpp:1031
+msgid "_Save User Phrase Library"
+msgstr "ä¿åç¨æ·è¯åº(_S)"
+
+#: src/scim_pinyin_helper.cpp:1035
+msgid "_Import User Phrase Library"
+msgstr "导å
¥ç¨æ·è¯åº(_I)"
+
+#: src/scim_pinyin_helper.cpp:1039
+msgid "_Add New Phrases"
+msgstr "æ·»å æ°è¯ç»(_A)"
+
+#: src/scim_pinyin_helper.cpp:1043
+msgid "_Delete Phrase"
+msgstr "å é¤è¯ç»(_D)"
+
+#: src/scim_pinyin_helper.cpp:1048
+msgid "_Help"
+msgstr "帮å©(_H)"
+
+#: src/scim_pinyin_helper.cpp:1055
+msgid "_About"
+msgstr "å
³äº(_A)"
+
+#: src/scim_pinyin_helper.cpp:1086
+msgid "Quit"
+msgstr "éåº"
+
+#: src/scim_pinyin_helper.cpp:1081
+msgid "Submit"
+msgstr "æ交"
+
+#: src/scim_pinyin_helper.cpp:1092
+msgid "Add"
+msgstr "æ·»å "
+
+#: src/scim_pinyin_helper.cpp:1098
+msgid "Delete"
+msgstr "å é¤"
+
+#: src/scim_pinyin_imengine_setup.cpp:611
+msgid "Show pinyin helper property in the tool bar"
+msgstr "å¨å·¥å
·æ¡ä¸æ¾ç¤ºæ¼é³è¾
å©ç¨åºå¼å
³(_H)"
+
+#: src/scim_pinyin_imengine_setup.cpp:854
+msgid ""
+"If this option is checked, "
+"the tool bar will show the pinyin_helper property. "
+msgstr ""
+"å¦æéä¸æ¬é项ï¼å°ä¼å¨å·¥å
·æ¡ä¸æ¾ç¤ºæ¼é³è¾
å©ç¨åºçå¼å
³."
+
+#: src/scim_pinyin_imengine_setup.cpp:611
+msgid "The switch to invoke pinyin helper. Click to invoke it."
+msgstr "è°ç¨æ¼é³è¾
å©ç¨åºçå¼å
³, ç¹å»å¯ä»¥æå¼è¯¥è¾
å©ç¨åº."
diff -Naur scim-pinyin-0.5.91.bak/src/Makefile.am scim-pinyin-0.5.91/src/Makefile.am
--- scim-pinyin-0.5.91.bak/src/Makefile.am 2006-06-23 16:15:55.000000000 +0800
+++ scim-pinyin-0.5.91/src/Makefile.am 2006-06-27 09:52:06.000000000 +0800
@@ -36,7 +36,8 @@
scim_pinyin_phrase.h \
scim_native_lookup_table.h \
scim_pinyin_smart_match.h \
- scim_special_table.h
+ scim_special_table.h \
+ scim_pinyin_helper.h
noinst_LTLIBRARIES = libpinyin.la
@@ -90,6 +91,22 @@
@SCIM_GTKUTILS_LIBS@ \
@LTLIBINTL@
+HELPER_MODULE = pinyin-imengine-helper.la
+
+helpermoduledir = @SCIM_MODULEDIR@/Helper
+helpermodule_LTLIBRARIES= $(HELPER_MODULE)
+
+pinyin_imengine_helper_la_SOURCES = scim_pinyin_helper.cpp
+pinyin_imengine_helper_la_CFLAGS = @SCIM_GTKUTILS_CFLAGS@ @SCIM_CFLAGS@
+pinyin_imengine_helper_la_CXXFLAGS = @SCIM_GTKUTILS_CFLAGS@ @SCIM_CFLAGS@
+pinyin_imengine_helper_la_LDFLAGS = -avoid-version \
+ -rpath $(helpermoduledir) \
+ -module \
+ @LIBTOOL_EXPORT_OPTIONS@ \
+ @SCIM_LIBS@ \
+ @SCIM_GTKUTILS_LIBS@ \
+ @LTLIBINTL@
+
if ENABLE_TOOLS
TOOLS = make-pinyin make-phrase make-pinyin-phrase
endif
diff -Naur scim-pinyin-0.5.91.bak/src/scim_pinyin_helper.cpp scim-pinyin-0.5.91/src/scim_pinyin_helper.cpp
--- scim-pinyin-0.5.91.bak/src/scim_pinyin_helper.cpp 1970-01-01 08:00:00.000000000 +0800
+++ scim-pinyin-0.5.91/src/scim_pinyin_helper.cpp 2006-06-27 09:52:06.000000000 +0800
@@ -0,0 +1,1130 @@
+/*
+ * Copyright (C) 2006 Qian Shen <qshen at redhat.com>
+ *
+ * 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; either version 2, or (at your option)
+ * any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#define Uses_SCIM_HELPER
+#define Uses_SCIM_CONFIG_BASE
+#include <map>
+#include <scim.h>
+#include <gtk/gtk.h>
+#include "scim_pinyin_helper.h"
+
+using namespace scim;
+
+#define scim_module_init pinyin_imengine_helper_LTX_scim_module_init
+#define scim_module_exit pinyin_imengine_helper_LTX_scim_module_exit
+#define scim_helper_module_number_of_helpers pinyin_imengine_helper_LTX_scim_helper_module_number_of_helpers
+#define scim_helper_module_get_helper_info pinyin_imengine_helper_LTX_scim_helper_module_get_helper_info
+#define scim_helper_module_run_helper pinyin_imengine_helper_LTX_scim_helper_module_run_helper
+
+static void run (const String &display,
+ const ConfigPointer &config);
+
+HelperAgent helper_agent;
+
+HelperInfo helper_info (SCIM_PINYIN_HELPER_UUID, // uuid
+ "", // name
+ "", // icon
+ "",
+ SCIM_HELPER_NEED_SCREEN_INFO|SCIM_HELPER_NEED_SCREEN_INFO);
+
+//Module Interface
+extern "C" {
+ void scim_module_init (void)
+ {
+ bindtextdomain (GETTEXT_PACKAGE, SCIM_PINYIN_LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+
+ helper_info.name = String (_("Smart pinyin helper"));
+ helper_info.description = String (
+ _("A helper module for Smart Pinyin IMEngine."));
+ }
+
+ void scim_module_exit (void)
+ {
+ }
+
+ unsigned int scim_helper_module_number_of_helpers (void)
+ {
+ return 1;
+ }
+
+ bool scim_helper_module_get_helper_info (unsigned int idx, HelperInfo &info)
+ {
+ if (idx == 0) {
+ info = helper_info;
+ return true;
+ }
+ return false;
+ }
+
+ void scim_helper_module_run_helper (const String &uuid,
+ const ConfigPointer &config,
+ const String &display)
+ {
+ SCIM_DEBUG_MAIN(1) << "scim_pinyin_imengine_helper_LTX_scim_helper_module_run_helper ()\n";
+
+ if (uuid == String (SCIM_PINYIN_HELPER_UUID)) {
+ run (display, config);
+ }
+
+ SCIM_DEBUG_MAIN(1) << "exit scim_pinyin_imengine_helper_LTX_scim_helper_module_run_helper ()\n";
+ }
+}
+
+//Global Variables
+static int cur_ic = -1;
+static String cur_uuid;
+
+GtkWidget * BaseWindow;
+GtkListStore * list_store;
+GtkTreeModel * tree_model;
+GtkTreeView * tree_view;
+GtkTreeIter cur_iter;
+GtkCellRenderer * renderer_num, *renderer_phrase, *renderer_pinyin;
+GtkWidget * submit_button, *disable_button, *add_button;
+GtkWidget * add_phrase_row, *disable_phrase_row;
+
+uint32 max_user_phrase_length = 8;
+
+bool ok_to_add_new_row = false;
+guint row_count = 0;
+
+int list_cur_num = -1;
+
+static gboolean
+helper_agent_input_handler (GIOChannel *source,
+ GIOCondition condition,
+ gpointer user_data)
+{
+ if (condition == G_IO_IN) {
+ HelperAgent *agent = static_cast<HelperAgent*> (user_data);
+ if (agent && agent->has_pending_event ())
+ agent->filter_event ();
+ } else if (condition == G_IO_ERR || condition == G_IO_HUP) {
+ gtk_main_quit ();
+ }
+ return TRUE;
+}
+
+static void
+slot_exit (const HelperAgent *agent, int ic, const String &uuid)
+{
+ gtk_main_quit ();
+}
+
+static void slot_attach_input_context (const HelperAgent *agent, int ic, const String &uuid)
+{
+ std::cout << "slot_attach_input_context (" << ic << ", " << uuid << ")\n";
+
+ cur_ic = ic;
+ cur_uuid = uuid;
+
+ // Inform the scim-pinyin imengine that scim-pinyin-helper started successfully
+ Transaction trans;
+ trans.put_command (SCIM_TRANS_CMD_REQUEST);
+ trans.put_command (SCIM_TRANS_CMD_START_HELPER);
+ agent->send_imengine_event (ic, uuid, trans);
+}
+
+static void slot_detach_input_context (const HelperAgent *agent, int ic, const String &uuid)
+{
+ std::cout << "slot_detach_input_context (" << ic << ", " << uuid << ")\n";
+}
+
+static void slot_update_screen (const HelperAgent *, int ic, const String &uuid, int screen)
+{
+ std::cout << "slot_update_screen (" << ic << ", " << uuid << ", " << screen << ")\n";
+}
+
+static void slot_update_spot_location (const HelperAgent *, int ic, const String &uuid, int x, int y)
+{
+ std::cout << "slot_update_spot_location (" << ic << ", " << uuid << ", " << x << ", " << y << ")\n";
+
+ //gtk_window_move (GTK_WINDOW (main_window), x + 16, y + 16);
+}
+
+void
+on_button_quit_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ gtk_main_quit ();
+}
+
+void
+on_quit_activate (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ gtk_main_quit ();
+}
+
+void
+on_about1_activate (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+}
+
+void
+on_new_row_activate (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ std::cout << "in on_new_column_activate()" <<endl;
+
+ if( !ok_to_add_new_row )
+ return;
+
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ GtkTreeViewColumn* column;
+
+ gtk_list_store_append (list_store, &iter);
+
+ row_count ++;
+
+ gtk_list_store_set (list_store, &iter,
+ NUM_COLUMN, row_count,
+ PHRASE_COLUMN, "",
+ PINYIN_COLUMN, "",
+ -1);
+
+ path = gtk_tree_model_get_path ( tree_model, &iter );
+
+ column = gtk_tree_view_get_column ( tree_view, 1 );
+
+ gtk_tree_view_set_cursor ( tree_view,
+ path,
+ column,
+ TRUE);
+ // bug? - if use this api to grab focus, scim will crash!
+ //gtk_widget_grab_focus ( (GtkWidget*)tree_view);
+
+ ok_to_add_new_row = false;
+}
+
+void
+on_list_user_phrase_library (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ gtk_widget_hide (submit_button);
+ gtk_widget_show (disable_button);
+ gtk_widget_show (add_button);
+ gtk_widget_show (add_phrase_row);
+ gtk_widget_show (disable_phrase_row);
+
+ g_object_set ( renderer_phrase, "editable", false, NULL);
+ g_object_set ( renderer_pinyin, "editable", false, NULL);
+
+ Transaction send;
+ send.put_command (SCIM_TRANS_CMD_REQUEST);
+ send.put_command (SCIM_PINYIN_TRANS_CMD_SHOW_USER_LIB);
+ helper_agent.send_imengine_event (cur_ic, cur_uuid, send);
+
+ std::cout << "in on_list_user_phrase_library(), send : SCIM_PINYIN_TRANS_CMD_SHOW_USER_LIB\n";
+}
+
+void
+on_dir_select_ok (GtkWidget *widget,
+ gpointer user_data)
+{
+ GtkWidget *dir_selector = GTK_WIDGET (user_data);
+ const gchar *selected_dirname;
+ String string_dirname;
+
+ selected_dirname = gtk_file_selection_get_filename (GTK_FILE_SELECTION (dir_selector));
+ string_dirname = String( selected_dirname );
+
+ if( g_file_test( selected_dirname , G_FILE_TEST_IS_DIR ) )
+ gtk_widget_destroy( GTK_WIDGET(dir_selector) );
+ else
+ return;
+
+ Transaction send;
+ send.put_command (SCIM_TRANS_CMD_REQUEST);
+ send.put_command (SCIM_PINYIN_TRANS_CMD_SAVE_USER_LIB);
+ send.put_data ( string_dirname );
+ helper_agent.send_imengine_event (cur_ic, cur_uuid, send);
+
+ std::cout << "in on_dir_select_ok(), send : SCIM_PINYIN_TRANS_CMD_SAVE_USER_LIB"<< endl;
+}
+
+void
+on_save_user_phrase_library (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ GtkWidget *dir_selector;
+
+ dir_selector = gtk_file_selection_new (_("please select a directory."));
+
+ g_signal_connect (GTK_FILE_SELECTION (dir_selector)->ok_button,
+ "clicked",
+ G_CALLBACK (on_dir_select_ok),
+ dir_selector);
+
+ g_signal_connect_swapped (GTK_FILE_SELECTION (dir_selector)->cancel_button,
+ "clicked",
+ G_CALLBACK (gtk_widget_destroy),
+ dir_selector);
+
+ gtk_widget_show (dir_selector);
+}
+
+void
+on_lib_select_ok (GtkWidget *widget,
+ gpointer user_data)
+{
+ GtkWidget *lib_selector = GTK_WIDGET (user_data);
+ const gchar *selected_dirname;
+ String string_dirname;
+
+ String pinyin_lib_bakname("/phrase_lib.bak");
+ String pinyin_phrase_lib_bakname("/pinyin_phrase_lib.bak");
+ String pinyin_phrase_index_bakname("/pinyin_phrase_index.bak");
+
+ selected_dirname = gtk_file_selection_get_filename (GTK_FILE_SELECTION (lib_selector));
+ string_dirname = String( selected_dirname );
+
+
+ /* test the libraries --by name */
+ if( g_file_test( selected_dirname , G_FILE_TEST_IS_DIR ) )
+ {
+ std::cout << "in on_lib_select_ok(), send : selected_dirname=" << selected_dirname << endl;
+
+ if( g_file_test( (string_dirname + pinyin_lib_bakname).c_str() , G_FILE_TEST_EXISTS) &&
+ g_file_test( (string_dirname + pinyin_phrase_lib_bakname).c_str() , G_FILE_TEST_EXISTS) &&
+ g_file_test( (string_dirname + pinyin_phrase_index_bakname).c_str() , G_FILE_TEST_EXISTS) )
+ {
+ gtk_widget_destroy( GTK_WIDGET(lib_selector) );
+ }
+ else
+ {
+ GtkWidget *dialog;
+ dialog = gtk_message_dialog_new( GTK_WINDOW(lib_selector),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _("Invalid phrase libraries in this directory!") );
+ gtk_dialog_run( GTK_DIALOG(dialog) );
+ gtk_widget_destroy(dialog);
+
+ return;
+ }
+ }
+ else
+ return;
+
+ Transaction send;
+ send.put_command (SCIM_TRANS_CMD_REQUEST);
+ send.put_command (SCIM_PINYIN_TRANS_CMD_IMPORT_USER_LIB);
+ send.put_data ( string_dirname );
+ helper_agent.send_imengine_event (cur_ic, cur_uuid, send);
+
+ std::cout << "in on_dir_select_ok(), send : SCIM_PINYIN_TRANS_CMD_IMPORT_USER_LIB"<< endl;
+}
+
+void
+on_import_user_phrase_library (GtkMenuItem *menuitem,
+ gpointer user_data)
+{
+ GtkWidget *lib_selector;
+
+ lib_selector = gtk_file_selection_new (_("please select the directory that contains the user phrase library."));
+
+ g_signal_connect (GTK_FILE_SELECTION (lib_selector)->ok_button,
+ "clicked",
+ G_CALLBACK (on_lib_select_ok),
+ lib_selector);
+
+ g_signal_connect_swapped (GTK_FILE_SELECTION (lib_selector)->cancel_button,
+ "clicked",
+ G_CALLBACK (gtk_widget_destroy),
+ lib_selector);
+
+ gtk_widget_show (lib_selector);
+}
+
+void
+on_button_submit_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ std::cout << "PinyinHelper: on_button_submit_clicked() - begin" <<endl;
+
+ GtkTreeIter iter;
+ gchar *phrase, *pinyin;
+ WideString w_phrase, w_pinyin;
+ std::vector<WideString> phrase_vec;
+ std::vector<WideString> pinyin_vec;
+
+ if (!gtk_tree_model_get_iter_first (tree_model, &iter))
+ return;
+
+ do {
+ gtk_tree_model_get(tree_model, &iter, PHRASE_COLUMN, &phrase, -1);
+ gtk_tree_model_get(tree_model, &iter, PINYIN_COLUMN, &pinyin, -1);
+
+
+ w_phrase = utf8_mbstowcs( phrase );
+ w_pinyin = utf8_mbstowcs( pinyin );
+
+ phrase_vec.push_back( w_phrase );
+ pinyin_vec.push_back( w_pinyin );
+
+ } while (gtk_tree_model_iter_next (tree_model, &iter));
+
+ if( phrase_vec.size() == 1 || pinyin_vec.size() == 1 )
+ return;
+
+ Transaction send;
+ send.put_command (SCIM_TRANS_CMD_REQUEST);
+ send.put_command (SCIM_PINYIN_TRANS_CMD_COMMIT_NEW_PHRASE);
+ send.put_data ( phrase_vec );
+ send.put_data ( pinyin_vec );
+ helper_agent.send_imengine_event (cur_ic, cur_uuid, send);
+
+ std::cout << "on_button_submit_clicked() : send : SCIM_PINYIN_TRANS_CMD_COMMIT_NEW_PHRASE"<< endl;
+
+}
+
+void
+on_button_add_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ GtkTreeViewColumn* column;
+
+ gtk_widget_show (submit_button);
+ gtk_widget_hide (disable_button);
+ gtk_widget_hide (add_button);
+ gtk_widget_hide (add_phrase_row);
+ gtk_widget_hide (disable_phrase_row);
+
+ g_object_set ( renderer_phrase, "editable", true, NULL);
+ g_object_set ( renderer_pinyin, "editable", true, NULL);
+
+ gtk_list_store_clear ( list_store );
+
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter,
+ NUM_COLUMN, 1,
+ PHRASE_COLUMN, "",
+ PINYIN_COLUMN, "",
+ -1);
+
+ row_count = 1;
+
+ // set cursor to the first phrase cell
+ //gtk_tree_model_get_iter_first ( tree_model, &iter);
+ path = gtk_tree_model_get_path ( tree_model, &iter );
+ column = gtk_tree_view_get_column ( tree_view, 1 );
+ gtk_tree_view_set_cursor ( tree_view,
+ path,
+ column,
+ TRUE);
+
+ Transaction send;
+ send.put_command (SCIM_TRANS_CMD_REQUEST);
+ send.put_command (SCIM_PINYIN_TRANS_CMD_GET_MAX_USER_PHRASE_LENGTH);
+ helper_agent.send_imengine_event (cur_ic, cur_uuid, send);
+
+ std::cout << "on_button_add_clicked() - send : SCIM_PINYIN_TRANS_CMD_GET_MAX_USER_PHRASE_LENGTH"<< endl;
+}
+
+void
+on_button_disable_clicked (GtkButton *button,
+ gpointer user_data)
+{
+ GtkTreeIter iter;
+ GtkTreeModel *model;
+ GtkTreeSelection* selection;
+ gchar *phrase;
+ WideString w_phrase;
+ gboolean rc;
+
+ selection = gtk_tree_view_get_selection( tree_view);
+
+ rc = gtk_tree_selection_get_selected (selection, &model, &iter);
+ if( !rc )
+ return;
+
+ gtk_tree_model_get(model, &iter, PHRASE_COLUMN, &phrase, -1);
+ gtk_tree_model_get(model, &iter, NUM_COLUMN, &list_cur_num, -1);
+
+ w_phrase = utf8_mbstowcs( phrase );
+
+ Transaction send;
+ send.put_command (SCIM_TRANS_CMD_REQUEST);
+ send.put_command (SCIM_PINYIN_TRANS_CMD_DISABLE_PHRASE);
+ send.put_data ( w_phrase );
+ helper_agent.send_imengine_event (cur_ic, cur_uuid, send);
+
+ std::cout << "in on_button_disable_clicked(), send : SCIM_PINYIN_TRANS_CMD_DISABLE_PHRASE"<< endl;
+}
+
+void
+on_phrase_cell_edited (GtkCellRendererText *renderer,
+ gchar *path,
+ gchar *new_text,
+ gpointer data)
+{
+/*
+ gunichar uni_new_text = g_utf8_get_char ( new_text );
+ PangoScript s = pango_script_for_unichar (uni_new_text);
+*/
+ if( strlen(new_text) == 0 )
+ return;
+
+ if( g_utf8_strlen (new_text, -1) > max_user_phrase_length ){
+ GtkWidget *dialog;
+ dialog = gtk_message_dialog_new( GTK_WINDOW(BaseWindow),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _("The phrase length exeed the MAX_USER_PHRASE_LENGTH!") );
+ gtk_dialog_run( GTK_DIALOG(dialog) );
+ gtk_widget_destroy(dialog);
+
+ GtkTreePath *_path = gtk_tree_path_new_from_string (path);
+ GtkTreeViewColumn *column = gtk_tree_view_get_column ( tree_view, 1 );
+ gtk_tree_view_set_cursor ( tree_view,
+ _path,
+ column,
+ TRUE);
+ return;
+ }
+
+ WideString w_new_text;
+
+ w_new_text = utf8_mbstowcs( new_text );
+
+ gtk_tree_model_get_iter_from_string( tree_model, &cur_iter, path);
+
+ gtk_list_store_set(list_store, &cur_iter,
+ PHRASE_COLUMN, new_text,
+ -1);
+
+ Transaction send;
+ send.put_command (SCIM_TRANS_CMD_REQUEST);
+ send.put_command (SCIM_PINYIN_TRANS_CMD_GET_PINYIN);
+ send.put_data ( w_new_text );
+ helper_agent.send_imengine_event (cur_ic, cur_uuid, send);
+
+ std::cout << "in on_phrase_cell_edited(), send : SCIM_PINYIN_TRANS_CMD_GET_PINYIN"<< endl;
+}
+
+void
+on_pinyin_cell_edited (GtkCellRendererText *renderer,
+ gchar *path,
+ gchar *new_text,
+ gpointer data)
+{
+ std::cout << "in on_pinyin_cell_edited() " << new_text <<" path="<< path <<endl ;
+
+ int key_nums;
+ gchar *phrase;
+ String new_text_str;
+ String::iterator iter;
+ WideString w_phrase;
+
+
+ for(int i = 0; new_text[i]!='\0'; i++){
+
+ if( !islower( new_text[i] ) && new_text[i] != ' '){
+ GtkWidget *dialog;
+ dialog = gtk_message_dialog_new( GTK_WINDOW(BaseWindow),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _("Invalid pinyin key in the input pinyin sequence.") );
+ gtk_dialog_run( GTK_DIALOG(dialog) );
+ gtk_widget_destroy(dialog);
+
+ return;
+ }
+
+ if( new_text[i] == ' ' && new_text[i+1] == ' ')
+ continue;
+
+ if( new_text[i] == ' ' && new_text[i+1] == '\0')
+ continue;
+
+ new_text_str.push_back( new_text[i] );
+ }
+
+ iter = new_text_str.begin();
+ key_nums = 0;
+ while( iter != new_text_str.end() ){
+ if( *iter == ' ')
+ key_nums++;
+ iter++;
+ }
+ if( key_nums == 0 ){
+ if( new_text_str.size() > 0 )
+ key_nums++;
+ } else {
+ key_nums++; }
+
+ gtk_tree_model_get_iter_from_string( tree_model, &cur_iter, path);
+
+ gtk_tree_model_get(tree_model, &cur_iter, PHRASE_COLUMN, &phrase, -1);
+
+ w_phrase = utf8_mbstowcs( phrase );
+
+ //std::cout << "in on_pinyin_cell_edited() w_phrase.size=" << w_phrase.size() <<endl ;
+ //std::cout << "in on_pinyin_cell_edited() key_nums =" << key_nums <<endl ;
+
+ if( w_phrase.size() == 0){
+ gtk_list_store_set(list_store, &cur_iter,
+ PINYIN_COLUMN, "",
+ -1);
+ return;
+ }
+
+ if( w_phrase.size() != key_nums ){
+ GtkWidget *dialog;
+ dialog = gtk_message_dialog_new( GTK_WINDOW(BaseWindow),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ _("Pinyin keys number is not equal to the phrase charachater number.") );
+ gtk_dialog_run( GTK_DIALOG(dialog) );
+ gtk_widget_destroy(dialog);
+
+ return;
+ }
+
+ gtk_list_store_set(list_store, &cur_iter,
+ PINYIN_COLUMN, new_text_str.c_str(),
+ -1);
+
+}
+
+static void
+slot_process_imengine_event (const HelperAgent *agent, int ic,
+ const String &uuid, const Transaction &recv)
+{
+ if (uuid == "05235cfc-43ce-490c-b1b1-c5a2185276ae") {
+
+ int cmd;
+ TransactionReader reader (recv);
+ std::vector<String> pinyin_strings;
+
+ std::vector <String> phrase_pinyin_vec;
+ std::vector <WideString> phrase_string_vec;
+
+ if (reader.get_command (cmd) && cmd == SCIM_TRANS_CMD_REQUEST) {
+ while (reader.get_command (cmd)) {
+ switch (cmd) {
+ case SCIM_PINYIN_TRANS_CMD_SEND_PINYIN:
+ {
+ std::cout << "process_imengine_event():get command- SCIM_PINYIN_TRANS_CMD_SEND_PINYIN \n";
+
+ if (reader.get_data (pinyin_strings)) {
+
+ gtk_list_store_set(list_store, &cur_iter,
+ PINYIN_COLUMN, pinyin_strings[0].c_str(),
+ -1);
+ }
+
+ guint num;
+ gtk_tree_model_get ( tree_model, &cur_iter, 0, &num, -1 );
+
+ if ( num == row_count ) {
+ ok_to_add_new_row = true;
+ on_new_row_activate ( NULL,NULL );
+ }
+
+ break;
+ }
+ case SCIM_PINYIN_TRANS_CMD_SEND_PINYIN_FAILED:
+ {
+ std::cout << "process_imengine_event():get command- SCIM_PINYIN_TRANS_CMD_SEND_PINYIN_FAILED \n";
+
+ GtkTreePath *path;
+ GtkTreeViewColumn *column;
+
+ gtk_list_store_set(list_store, &cur_iter,
+ PHRASE_COLUMN,"",
+ -1);
+ path = gtk_tree_model_get_path ( tree_model, &cur_iter );
+
+ column = gtk_tree_view_get_column ( tree_view, 1 );
+
+ gtk_tree_view_set_cursor ( tree_view,
+ path,
+ column,
+ TRUE);
+ break;
+ }
+ case SCIM_PINYIN_TRANS_CMD_SEND_USER_LIB:
+ {
+ std::cout << "process_imengine_event():get command- SCIM_PINYIN_TRANS_CMD_SEND_USER_LIB \n";
+
+ GtkTreeIter iter, focus_iter;
+ GtkTreePath *path;
+ int i;
+
+ /* for multi selection use
+ GtkTreeSelection* selection;
+ selection = gtk_tree_view_get_selection( tree_view);
+ gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE);
+ */
+
+ if (reader.get_data (phrase_string_vec) && reader.get_data (phrase_pinyin_vec) ) {
+
+ gtk_list_store_clear ( list_store );
+
+ for( i=0 ; i < phrase_string_vec.size(); i++){
+
+ gtk_list_store_append (list_store, &iter);
+ gtk_list_store_set (list_store, &iter,
+ NUM_COLUMN, i+1,
+ PHRASE_COLUMN, utf8_wcstombs(phrase_string_vec[i]).c_str(),
+ PINYIN_COLUMN, phrase_pinyin_vec[i].c_str(),
+ -1);
+
+ if( list_cur_num == i+1 )
+ focus_iter = iter;
+ }
+
+ // if disable one row, select the next row
+ if( list_cur_num > 0 ){
+ if( list_cur_num < i+1 )
+ path = gtk_tree_model_get_path ( tree_model, &focus_iter );
+ else
+ path = gtk_tree_model_get_path ( tree_model, &iter );
+ gtk_tree_view_set_cursor ( tree_view, path, NULL, false);
+ list_cur_num = -1;
+ }
+ }
+ break;
+ }
+ case SCIM_PINYIN_TRANS_CMD_SAVE_USER_LIB_OK:
+ {
+ std::cout << "process_imengine_event():get command- SCIM_PINYIN_TRANS_CMD_SAVE_USER_LIB_OK \n";
+
+ GtkWidget *dialog;
+ dialog = gtk_message_dialog_new( GTK_WINDOW(BaseWindow),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_OK,
+ _("Success to save the user phrase library.") );
+ gtk_dialog_run( GTK_DIALOG(dialog) );
+ gtk_widget_destroy(dialog);
+
+ break;
+ }
+ case SCIM_PINYIN_TRANS_CMD_SAVE_USER_LIB_FAIL:
+ {
+ std::cout << "process_imengine_event():get command- SCIM_PINYIN_TRANS_CMD_SAVE_USER_LIB_FAIL \n";
+
+ GtkWidget *dialog;
+ dialog = gtk_message_dialog_new( GTK_WINDOW(BaseWindow),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_OK,
+ _("Failed to save the user phrase library.") );
+ gtk_dialog_run( GTK_DIALOG(dialog) );
+ gtk_widget_destroy(dialog);
+
+ break;
+ }
+ case SCIM_PINYIN_TRANS_CMD_IMPORT_USER_LIB_OK:
+ {
+ std::cout << "process_imengine_event():get command- SCIM_PINYIN_TRANS_CMD_IMPORT_USER_LIB_OK \n";
+
+ GtkWidget *dialog;
+ dialog = gtk_message_dialog_new( GTK_WINDOW(BaseWindow),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_OK,
+ _("Success to import the user phrase library.") );
+ gtk_dialog_run( GTK_DIALOG(dialog) );
+ gtk_widget_destroy(dialog);
+
+ Transaction send;
+ send.put_command (SCIM_TRANS_CMD_REQUEST);
+ send.put_command (SCIM_PINYIN_TRANS_CMD_SHOW_USER_LIB);
+ helper_agent.send_imengine_event (cur_ic, cur_uuid, send);
+
+ std::cout << "send : SCIM_PINYIN_TRANS_CMD_SHOW_USER_LIB"<< endl;
+
+ break;
+ }
+ case SCIM_PINYIN_TRANS_CMD_IMPORT_USER_LIB_FAIL:
+ {
+ std::cout << "process_imengine_event():get command- SCIM_PINYIN_TRANS_CMD_IMPORT_USER_LIB_FAIL \n";
+
+ GtkWidget *dialog;
+ dialog = gtk_message_dialog_new( GTK_WINDOW(BaseWindow),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_OK,
+ _("Failed to import the user phrase library.") );
+ gtk_dialog_run( GTK_DIALOG(dialog) );
+ gtk_widget_destroy(dialog);
+
+ break;
+ }
+ case SCIM_PINYIN_TRANS_CMD_DISABLE_PHRASE_OK:
+ {
+ Transaction send;
+ send.put_command (SCIM_TRANS_CMD_REQUEST);
+ send.put_command (SCIM_PINYIN_TRANS_CMD_SHOW_USER_LIB);
+ helper_agent.send_imengine_event (cur_ic, cur_uuid, send);
+
+ std::cout << "send : SCIM_PINYIN_TRANS_CMD_SHOW_USER_LIB"<< endl;
+
+ break;
+ }
+ case SCIM_PINYIN_TRANS_CMD_COMMIT_NEW_PHRASE_OK:
+ {
+ std::cout << "process_imengine_event():get command - SCIM_PINYIN_TRANS_CMD_COMMIT_NEW_PHRASE_OK \n";
+
+ GtkWidget *dialog;
+ dialog = gtk_message_dialog_new( GTK_WINDOW(BaseWindow),
+ GTK_DIALOG_MODAL,
+ GTK_MESSAGE_INFO,
+ GTK_BUTTONS_OK,
+ _("Success to add the new phrases into the user phrase library.") );
+ gtk_dialog_run( GTK_DIALOG(dialog) );
+ gtk_widget_destroy(dialog);
+
+ on_list_user_phrase_library( NULL, NULL);
+
+ break;
+ }
+ case SCIM_PINYIN_TRANS_CMD_SEND_MAX_USER_PHRASE_LENGTH:
+ {
+ std::cout << "process_imengine_event():get command - SCIM_PINYIN_TRANS_CMD_SEND_MAX_USER_PHRASE_LENGTH \n";
+
+ uint32 length;
+ if (reader.get_data (length) )
+ max_user_phrase_length = length;
+
+ break;
+ }
+ default:
+ {
+ std::cout << "process_imengine_event():get command- default\n";
+ break;
+ }
+ }
+ }
+ }
+ }
+}
+
+/* create the treeview model*/
+static GtkTreeModel * create_model (void)
+{
+ GtkListStore *store;
+
+ store = gtk_list_store_new (N_COLUMNS,
+ G_TYPE_UINT,
+ G_TYPE_STRING,
+ G_TYPE_STRING);
+
+ list_store = store;
+ return GTK_TREE_MODEL (store);
+}
+
+/* add columns to the treeview */
+static void add_columns (GtkTreeView *treeview)
+{
+ GtkTreeViewColumn *column;
+
+ renderer_num = gtk_cell_renderer_text_new ();
+ g_object_set ( renderer_num, "xalign", 0.5, NULL);
+ column = gtk_tree_view_column_new_with_attributes (_("ID"),
+ renderer_num,
+ "text",NUM_COLUMN,
+ NULL);
+ g_object_set ( renderer_num, "alignment", 0.5, NULL);
+ gtk_tree_view_append_column (treeview, column);
+
+ renderer_phrase = gtk_cell_renderer_text_new ();
+ g_object_set ( renderer_phrase, "editable", FALSE, NULL);
+ g_signal_connect(renderer_phrase, "edited", (GCallback) on_phrase_cell_edited, NULL);
+ column = gtk_tree_view_column_new_with_attributes (_("PHRASE"),
+ renderer_phrase,
+ "text",PHRASE_COLUMN,
+ NULL);
+ gtk_tree_view_append_column (treeview, column);
+
+ renderer_pinyin = gtk_cell_renderer_text_new ();
+ g_object_set ( renderer_pinyin, "editable", FALSE, NULL);
+ g_signal_connect(renderer_pinyin, "edited", (GCallback) on_pinyin_cell_edited, NULL);
+ column = gtk_tree_view_column_new_with_attributes (_("PINYIN"),
+ renderer_pinyin,
+ "text",
+ PINYIN_COLUMN,
+ NULL);
+ gtk_tree_view_append_column (treeview, column);
+}
+
+GtkWidget*
+create_BaseWindow (void)
+{
+ GtkWidget *window1;
+ GtkWidget *vbox1;
+ GtkWidget *menubar1;
+ GtkWidget *menuitem1;
+ GtkWidget *menuitem1_menu;
+ GtkWidget *separatormenuitem1;
+ GtkWidget *quit;
+ GtkWidget *menuitem2;
+ GtkWidget *menuitem4;
+ GtkWidget *menuitem2_menu;
+ GtkWidget *menuitem4_menu;
+ GtkWidget *about1;
+ GtkWidget *new_row;
+ GtkWidget *scrolledwindow1;
+ GtkWidget *treeview_phrase;
+ GtkWidget *hbox1;
+ GtkWidget *button_quit;
+ GtkWidget *button_submit;
+ GtkAccelGroup *accel_group;
+
+/* code by hand */
+ GtkTreeModel *model;
+ GtkWidget *list_lib_row;
+ GtkWidget *save_lib_row;
+ GtkWidget *import_lib_row;
+ GtkWidget *button_disable;
+ GtkWidget *button_add;
+/* end */
+
+ accel_group = gtk_accel_group_new ();
+
+ window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_widget_set_size_request (window1, 400, 300);
+ gtk_window_set_title (GTK_WINDOW (window1), _("SCIM Pinyin - Add New Phrase"));
+
+ vbox1 = gtk_vbox_new (FALSE, 0);
+ gtk_widget_show (vbox1);
+ gtk_container_add (GTK_CONTAINER (window1), vbox1);
+
+ menubar1 = gtk_menu_bar_new ();
+ gtk_widget_show (menubar1);
+ gtk_box_pack_start (GTK_BOX (vbox1), menubar1, FALSE, FALSE, 0);
+
+ menuitem1 = gtk_menu_item_new_with_mnemonic (_("_Options"));
+ gtk_widget_show (menuitem1);
+ gtk_container_add (GTK_CONTAINER (menubar1), menuitem1);
+
+ menuitem1_menu = gtk_menu_new ();
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem1), menuitem1_menu);
+
+ separatormenuitem1 = gtk_separator_menu_item_new ();
+ gtk_widget_show (separatormenuitem1);
+ gtk_container_add (GTK_CONTAINER (menuitem1_menu), separatormenuitem1);
+ gtk_widget_set_sensitive (separatormenuitem1, FALSE);
+
+ quit = gtk_image_menu_item_new_from_stock ("gtk-quit", accel_group);
+ gtk_widget_show (quit);
+ gtk_container_add (GTK_CONTAINER (menuitem1_menu), quit);
+
+ menuitem2 = gtk_menu_item_new_with_mnemonic (_("_Actions"));
+ gtk_widget_show (menuitem2);
+ gtk_container_add (GTK_CONTAINER (menubar1), menuitem2);
+
+/* qshen add by hand */
+ menuitem2_menu = gtk_menu_new ();
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem2), menuitem2_menu);
+
+ list_lib_row = gtk_menu_item_new_with_mnemonic (_("_List User Phrase Library"));
+ gtk_widget_show (list_lib_row);
+ gtk_container_add (GTK_CONTAINER (menuitem2_menu), list_lib_row);
+
+ save_lib_row = gtk_menu_item_new_with_mnemonic (_("_Save User Phrase Library"));
+ gtk_widget_show (save_lib_row);
+ gtk_container_add (GTK_CONTAINER (menuitem2_menu), save_lib_row);
+
+ import_lib_row = gtk_menu_item_new_with_mnemonic (_("_Import User Phrase Library"));
+ gtk_widget_show (import_lib_row);
+ gtk_container_add (GTK_CONTAINER (menuitem2_menu), import_lib_row);
+
+ add_phrase_row = gtk_menu_item_new_with_mnemonic (_("_Add New Phrases"));
+ gtk_widget_show (add_phrase_row);
+ gtk_container_add (GTK_CONTAINER (menuitem2_menu), add_phrase_row);
+
+ disable_phrase_row = gtk_menu_item_new_with_mnemonic (_("_Delete Phrase"));
+ gtk_widget_show (disable_phrase_row);
+ gtk_container_add (GTK_CONTAINER (menuitem2_menu), disable_phrase_row);
+/* qshen end */
+
+ menuitem4 = gtk_menu_item_new_with_mnemonic (_("_Help"));
+ gtk_widget_show (menuitem4);
+ gtk_container_add (GTK_CONTAINER (menubar1), menuitem4);
+
+ menuitem4_menu = gtk_menu_new ();
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem4), menuitem4_menu);
+
+ about1 = gtk_menu_item_new_with_mnemonic (_("_About"));
+ gtk_widget_show (about1);
+ gtk_container_add (GTK_CONTAINER (menuitem4_menu), about1);
+
+ scrolledwindow1 = gtk_scrolled_window_new (NULL, NULL);
+ gtk_widget_show (scrolledwindow1);
+ gtk_box_pack_start (GTK_BOX (vbox1), scrolledwindow1, TRUE, TRUE, 0);
+ gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolledwindow1), GTK_SHADOW_IN);
+
+ treeview_phrase = gtk_tree_view_new ();
+ gtk_widget_show (treeview_phrase);
+ gtk_container_add (GTK_CONTAINER (scrolledwindow1), treeview_phrase);
+
+/* code by hand */
+ tree_view = GTK_TREE_VIEW(treeview_phrase);
+ model = create_model ();
+ gtk_tree_view_set_model(GTK_TREE_VIEW(treeview_phrase),model);
+ g_object_unref (model);
+ add_columns (GTK_TREE_VIEW (treeview_phrase));
+ tree_model = model;
+/* end */
+
+ hbox1 = gtk_hbox_new (TRUE, 0);
+ gtk_widget_show (hbox1);
+ gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, FALSE, 0);
+
+ button_quit = gtk_button_new_with_mnemonic (_("Quit"));
+ gtk_widget_show (button_quit);
+ gtk_box_pack_start (GTK_BOX (hbox1), button_quit, FALSE, FALSE, 0);
+ gtk_widget_set_size_request (button_quit, 80, -1);
+
+ button_submit = gtk_button_new_with_mnemonic (_("Submit"));
+ //gtk_widget_show (button_submit);
+ gtk_box_pack_start (GTK_BOX (hbox1), button_submit, FALSE, FALSE, 0);
+ gtk_widget_set_size_request (button_submit, 80, -1);
+ submit_button = button_submit;
+
+ button_add = gtk_button_new_with_mnemonic (_("Add"));
+ gtk_widget_show (button_add);
+ gtk_box_pack_start (GTK_BOX (hbox1), button_add, FALSE, FALSE, 0);
+ gtk_widget_set_size_request (button_add, 80, -1);
+ add_button = button_add; //qshen add
+
+ button_disable = gtk_button_new_with_mnemonic (_("Delete"));
+ gtk_widget_show (button_disable);
+ gtk_box_pack_start (GTK_BOX (hbox1), button_disable, FALSE, FALSE, 0);
+ gtk_widget_set_size_request (button_disable, 80, -1);
+ disable_button = button_disable;//qshen add
+
+ g_signal_connect ((gpointer) quit, "activate",
+ G_CALLBACK (on_quit_activate),
+ NULL);
+ g_signal_connect ((gpointer) list_lib_row, "activate",
+ G_CALLBACK (on_list_user_phrase_library),
+ NULL);
+ g_signal_connect ((gpointer) save_lib_row, "activate",
+ G_CALLBACK (on_save_user_phrase_library),
+ NULL);
+ g_signal_connect ((gpointer) import_lib_row, "activate",
+ G_CALLBACK (on_import_user_phrase_library),
+ NULL);
+ g_signal_connect ((gpointer) add_phrase_row, "activate",
+ G_CALLBACK (on_button_add_clicked),
+ NULL);
+ g_signal_connect ((gpointer) disable_phrase_row, "activate",
+ G_CALLBACK (on_button_disable_clicked),
+ NULL);
+ g_signal_connect ((gpointer) about1, "activate",
+ G_CALLBACK (on_about1_activate),
+ NULL);
+ g_signal_connect ((gpointer) button_quit, "clicked",
+ G_CALLBACK (on_button_quit_clicked),
+ NULL);
+ g_signal_connect ((gpointer) button_submit, "clicked",
+ G_CALLBACK (on_button_submit_clicked),
+ NULL);
+/* code by hand */
+ g_signal_connect (G_OBJECT(window1), "destroy",
+ G_CALLBACK (gtk_main_quit),
+ NULL);
+ g_signal_connect ((gpointer) button_disable, "clicked",
+ G_CALLBACK (on_button_disable_clicked),
+ NULL);
+ g_signal_connect ((gpointer) button_add, "clicked",
+ G_CALLBACK (on_button_add_clicked),
+ NULL);
+/* end */
+ gtk_window_add_accel_group (GTK_WINDOW (window1), accel_group);
+
+
+ return window1;
+}
+
+
+
+static void
+run (const String &display, const ConfigPointer &config)
+{
+ char **argv = new char * [4];
+ int argc = 3;
+
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ GtkTreeViewColumn* column;
+
+ argv [0] = "smart-pinyin-imengine-helper";
+ argv [1] = "--display";
+ argv [2] = const_cast<char *> (display.c_str ());
+ argv [3] = 0;
+
+ std::cout << "in run()" <<endl;
+
+ setenv ("DISPLAY", display.c_str (), 1);
+
+ gtk_init (&argc, &argv);
+
+ helper_agent.signal_connect_exit (slot (slot_exit));
+ helper_agent.signal_connect_attach_input_context (slot (slot_attach_input_context));
+ helper_agent.signal_connect_detach_input_context (slot (slot_detach_input_context));
+ helper_agent.signal_connect_update_screen (slot (slot_update_screen));
+ helper_agent.signal_connect_update_spot_location (slot (slot_update_spot_location));
+ helper_agent.signal_connect_process_imengine_event (slot (slot_process_imengine_event));
+
+
+ BaseWindow = create_BaseWindow ();
+ gtk_widget_show (BaseWindow);
+
+ // open connection
+ int fd = helper_agent.open_connection (helper_info, display);
+ GIOChannel *ch = g_io_channel_unix_new (fd);
+
+ if (fd >= 0 && ch) {
+ g_io_add_watch (ch, G_IO_IN,
+ helper_agent_input_handler,
+ (gpointer) &helper_agent);
+ g_io_add_watch (ch, G_IO_ERR,
+ helper_agent_input_handler,
+ (gpointer) &helper_agent);
+ g_io_add_watch (ch, G_IO_HUP,
+ helper_agent_input_handler,
+ (gpointer) &helper_agent);
+ }
+
+ Transaction send;
+ send.put_command (SCIM_TRANS_CMD_REQUEST);
+ send.put_command (SCIM_PINYIN_TRANS_CMD_SHOW_USER_LIB);
+ helper_agent.send_imengine_event (cur_ic, cur_uuid, send);
+
+ gtk_main ();
+
+ // close connection
+ helper_agent.close_connection ();
+ fd = -1;
+}
diff -Naur scim-pinyin-0.5.91.bak/src/scim_pinyin_helper.h scim-pinyin-0.5.91/src/scim_pinyin_helper.h
--- scim-pinyin-0.5.91.bak/src/scim_pinyin_helper.h 1970-01-01 08:00:00.000000000 +0800
+++ scim-pinyin-0.5.91/src/scim_pinyin_helper.h 2006-06-27 09:52:06.000000000 +0800
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2006 Qian Shen <qshen at redhat.com>
+ *
+ * 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; either version 2, or (at your option)
+ * any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __SCIM_PINYIN_HELPER_H__
+#define __SCIM_PINYIN_HELPER_H__
+
+#include <fstream.h>
+#include <iostream.h>
+#include <scim_trans_commands.h>
+#include "scim_pinyin_private.h"
+
+#define SCIM_PINYIN_HELPER_UUID "85e45f24-0a86-4507-a357-906c6cceea4b"
+
+#define SCIM_PINYIN_TRANS_CMD_COMMIT_NEW_PHRASE SCIM_TRANS_CMD_USER_DEFINED + 100
+#define SCIM_PINYIN_TRANS_CMD_GET_PINYIN SCIM_TRANS_CMD_USER_DEFINED + 101
+#define SCIM_PINYIN_TRANS_CMD_SEND_PINYIN SCIM_TRANS_CMD_USER_DEFINED + 102
+#define SCIM_PINYIN_TRANS_CMD_SEND_PINYIN_FAILED SCIM_TRANS_CMD_USER_DEFINED + 103
+#define SCIM_PINYIN_TRANS_CMD_SHOW_USER_LIB SCIM_TRANS_CMD_USER_DEFINED + 104
+#define SCIM_PINYIN_TRANS_CMD_SEND_USER_LIB SCIM_TRANS_CMD_USER_DEFINED + 105
+#define SCIM_PINYIN_TRANS_CMD_SAVE_USER_LIB SCIM_TRANS_CMD_USER_DEFINED + 106
+#define SCIM_PINYIN_TRANS_CMD_SAVE_USER_LIB_OK SCIM_TRANS_CMD_USER_DEFINED + 107
+#define SCIM_PINYIN_TRANS_CMD_SAVE_USER_LIB_FAIL SCIM_TRANS_CMD_USER_DEFINED + 108
+#define SCIM_PINYIN_TRANS_CMD_IMPORT_USER_LIB SCIM_TRANS_CMD_USER_DEFINED + 109
+#define SCIM_PINYIN_TRANS_CMD_IMPORT_USER_LIB_OK SCIM_TRANS_CMD_USER_DEFINED + 110
+#define SCIM_PINYIN_TRANS_CMD_IMPORT_USER_LIB_FAIL SCIM_TRANS_CMD_USER_DEFINED + 111
+#define SCIM_PINYIN_TRANS_CMD_DISABLE_PHRASE SCIM_TRANS_CMD_USER_DEFINED + 112
+#define SCIM_PINYIN_TRANS_CMD_DISABLE_PHRASE_OK SCIM_TRANS_CMD_USER_DEFINED + 113
+#define SCIM_PINYIN_TRANS_CMD_DISABLE_PHRASE_FAIL SCIM_TRANS_CMD_USER_DEFINED + 114
+#define SCIM_PINYIN_TRANS_CMD_COMMIT_NEW_PHRASE_OK SCIM_TRANS_CMD_USER_DEFINED + 115
+#define SCIM_PINYIN_TRANS_CMD_GET_MAX_USER_PHRASE_LENGTH SCIM_TRANS_CMD_USER_DEFINED + 116
+#define SCIM_PINYIN_TRANS_CMD_SEND_MAX_USER_PHRASE_LENGTH SCIM_TRANS_CMD_USER_DEFINED + 117
+
+enum
+{
+ NUM_COLUMN,
+ PHRASE_COLUMN,
+ PINYIN_COLUMN,
+ N_COLUMNS
+};
+
+#endif /* __SCIM_PINYIN_HELPER_H__ */
diff -Naur scim-pinyin-0.5.91.bak/src/scim_pinyin_imengine_config_keys.h scim-pinyin-0.5.91/src/scim_pinyin_imengine_config_keys.h
--- scim-pinyin-0.5.91.bak/src/scim_pinyin_imengine_config_keys.h 2006-06-23 16:15:55.000000000 +0800
+++ scim-pinyin-0.5.91/src/scim_pinyin_imengine_config_keys.h 2006-06-27 09:52:06.000000000 +0800
@@ -63,6 +63,9 @@
#define SCIM_CONFIG_IMENGINE_PINYIN_SHUANG_PIN "/IMEngine/Pinyin/ShuangPin"
#define SCIM_CONFIG_IMENGINE_PINYIN_SHUANG_PIN_SCHEME "/IMEngine/Pinyin/ShuangPinScheme"
+
+#define SCIM_CONFIG_IMENGINE_PINYIN_SHOW_WORD_PROPERTY "/IMEngine/Pinyin/ShowWordProperty" //qshen
+
#endif
/*
vi:expandtab:ts=4:nowrap:ai
diff -Naur scim-pinyin-0.5.91.bak/src/scim_pinyin_imengine.cpp scim-pinyin-0.5.91/src/scim_pinyin_imengine.cpp
--- scim-pinyin-0.5.91.bak/src/scim_pinyin_imengine.cpp 2006-06-23 16:15:55.000000000 +0800
+++ scim-pinyin-0.5.91/src/scim_pinyin_imengine.cpp 2006-06-27 09:52:07.000000000 +0800
@@ -44,6 +44,7 @@
#include "scim_pinyin_imengine.h"
#include "scim_pinyin_smart_match.h"
#include "scim_pinyin_imengine_config_keys.h"
+#include "scim_pinyin_helper.h"
#define scim_module_init pinyin_LTX_scim_module_init
#define scim_module_exit pinyin_LTX_scim_module_exit
@@ -54,6 +55,7 @@
#define SCIM_PROP_STATUS "/IMEngine/Pinyin/Status"
#define SCIM_PROP_LETTER "/IMEngine/Pinyin/Letter"
#define SCIM_PROP_PUNCT "/IMEngine/Pinyin/Punct"
+#define SCIM_PROP_WORD "/IMEngine/Pinyin/Word" //qshen
#define SCIM_PROP_PINYIN_SCHEME "/IMEngine/Pinyin/PinyinScheme"
#define SCIM_PROP_PINYIN_SCHEME_QUAN_PIN "/IMEngine/Pinyin/PinyinScheme/QuanPin"
@@ -92,6 +94,7 @@
static Property _status_property (SCIM_PROP_STATUS, "");
static Property _letter_property (SCIM_PROP_LETTER, "");
static Property _punct_property (SCIM_PROP_PUNCT, "");
+static Property _word_property (SCIM_PROP_WORD, ""); //qshen 0217
static Property _pinyin_scheme_property (SCIM_PROP_PINYIN_SCHEME, "å
¨");
static Property _pinyin_quan_pin_property (SCIM_PROP_PINYIN_SCHEME_QUAN_PIN, "å
¨æ¼");
@@ -126,6 +129,8 @@
_status_property.set_label ("è±");
_letter_property.set_icon (SCIM_HALF_LETTER_ICON);
_punct_property.set_icon (SCIM_HALF_PUNCT_ICON);
+ _word_property.set_tip (_("The switch to invoke pinyin helper. Click to invoke it.")); //qshen
+ _word_property.set_label ("è¯"); //qshen
_scim_config = config;
return 1;
@@ -153,7 +158,8 @@
m_auto_combine_phrase (false),
m_auto_fill_preedit (false),
m_always_show_lookup (false),
- m_show_all_keys (true),
+ m_show_all_keys (false),
+ m_show_word_property (false), //qshen
m_user_data_binary (true),
m_valid (false),
m_shuang_pin (false),
@@ -204,6 +210,7 @@
bool tone = false;
bool dynamic_adjust = true;
bool incomplete = true;
+ bool show_word_property = false;
bool ambiguities [SCIM_PINYIN_AmbLast + 2] =
{ false, false, false, false,
@@ -269,7 +276,12 @@
true);
m_show_all_keys =
m_config->read (String (SCIM_CONFIG_IMENGINE_PINYIN_SHOW_ALL_KEYS),
- true);
+ false);
+
+ m_show_word_property = //qshen
+ m_config->read (String (SCIM_CONFIG_IMENGINE_PINYIN_SHOW_WORD_PROPERTY),
+ false);
+
m_user_data_binary =
m_config->read (String (SCIM_CONFIG_IMENGINE_PINYIN_USER_DATA_BINARY),
true);
@@ -692,6 +704,7 @@
m_traditional (true),
m_lookup_table_def_page_size (9),
m_keys_caret (0),
+ m_helper_started (false), //qshen
m_lookup_caret (0),
m_iconv (encoding)
{
@@ -890,6 +903,280 @@
return false;
}
+//qshen add
+class __PinyinPhraseHelperFunc {
+
+ std::vector <String> &m_phrase_pinyin_vec;
+ std::vector <WideString> &m_phrase_string_vec;
+
+public:
+ __PinyinPhraseHelperFunc ( std::vector <String> &pinyin_vec, std::vector <WideString> &string_vec) :
+ m_phrase_pinyin_vec( pinyin_vec),
+ m_phrase_string_vec( string_vec ) {}
+
+ void operator () (const PinyinPhrase & phrase) {
+
+ String tmp_string;
+
+ if (phrase.is_enable () && phrase.length()>= 2) {
+ tmp_string.clear();
+
+ for (int i=0; i<phrase.length (); i++){
+ tmp_string += phrase.get_key (i).get_key_string() + " ";
+ }
+
+ m_phrase_pinyin_vec.push_back( tmp_string );
+ m_phrase_string_vec.push_back( phrase.get_phrase().get_content () );
+ }
+ }
+};
+
+
+//qshen add
+void
+PinyinInstance::process_helper_event (const String &helper_uuid, const Transaction &trans)
+{
+ SCIM_DEBUG_IMENGINE (2) << "PinyinInstance : process_helper_event ()\n";
+
+ TransactionReader reader (trans);
+ Transaction send_trans;
+
+ int cmd, num;
+ bool first_black_space = false;
+ String phrase, tmp_string, selected_dirname;
+ WideString new_phrase, disable_phrase;
+ WideString::iterator iter1, iter2;
+
+ std::vector <String> pinyin_strings;
+ std::vector <WideString> phrase_received, pinyin_received;
+ std::vector <PinyinKeyVector> keys_vector;
+
+ PinyinKey key;
+ PinyinParsedKey pkey;
+ PinyinParsedKeyVector pkey_vec;
+ std::vector <PinyinParsedKeyVector> pkey_vec_vec;
+
+ std::vector <String> phrase_pinyin_vec;
+ std::vector <WideString> phrase_string_vec;
+
+ String pinyin_lib_bakname("/phrase_lib.bak");
+ String pinyin_phrase_lib_bakname("/pinyin_phrase_lib.bak");
+ String pinyin_phrase_index_bakname("/pinyin_phrase_index.bak");
+
+ if (helper_uuid != SCIM_PINYIN_HELPER_UUID)
+ return;
+
+ if (reader.get_command (cmd) && cmd == SCIM_TRANS_CMD_REQUEST &&
+ reader.get_command (cmd)) {
+ if (cmd == SCIM_TRANS_CMD_START_HELPER) {
+ SCIM_DEBUG_IMENGINE (2) << "PinyinInstance : process_helper_event () - received SCIM_TRANS_CMD_START_HELPER\n";
+ m_helper_started = true;
+
+ if (m_focused) {
+ send_trans.clear ();
+ send_trans.put_command (SCIM_TRANS_CMD_REQUEST);
+ send_trans.put_command (SCIM_TRANS_CMD_FOCUS_IN);
+ send_helper_event (SCIM_PINYIN_HELPER_UUID, send_trans);
+ SCIM_DEBUG_IMENGINE (2) << "PinyinInstance : process_helper_event () - send SCIM_TRANS_CMD_FOCUS_IN\n";
+ }
+ }
+ if (cmd == SCIM_PINYIN_TRANS_CMD_SHOW_USER_LIB) {
+ SCIM_DEBUG_IMENGINE (2) << "PinyinInstance : process_helper_event () - received SCIM_PINYIN_TRANS_CMD_SHOW_USER_LIB\n";
+
+ phrase_pinyin_vec.clear();
+ phrase_string_vec.clear();
+ __PinyinPhraseHelperFunc func( phrase_pinyin_vec, phrase_string_vec );
+
+ m_user_phrase_lib->for_each_phrase( func );
+
+ //SCIM_DEBUG_IMENGINE (2) << "phrase_string_vec.size()=" << phrase_string_vec.size() << " phrase_pinyin_vec.size()=" << phrase_pinyin_vec.size() <<endl;
+ //for (int i=0 ; i < phrase_string_vec.size(); i++)
+ // SCIM_DEBUG_IMENGINE (2) << "phrase_string_vec["<<i<<"]="<< utf8_wcstombs(phrase_string_vec[i]) << " phrase_pinyin_vec["<<i<<"]="<<phrase_pinyin_vec[i] <<endl;
+
+ send_trans.clear ();
+ send_trans.put_command (SCIM_TRANS_CMD_REQUEST);
+ send_trans.put_command (SCIM_PINYIN_TRANS_CMD_SEND_USER_LIB);
+ send_trans.put_data ( phrase_string_vec );
+ send_trans.put_data ( phrase_pinyin_vec );
+ send_helper_event (SCIM_PINYIN_HELPER_UUID, send_trans);
+ SCIM_DEBUG_IMENGINE (2) << "PinyinInstance : process_helper_event () - send SCIM_PINYIN_TRANS_CMD_SEND_USER_LIB\n";
+ }
+ if (cmd == SCIM_PINYIN_TRANS_CMD_DISABLE_PHRASE) {
+ SCIM_DEBUG_IMENGINE (2) << "PinyinInstance : process_helper_event () - received SCIM_PINYIN_TRANS_CMD_DISABLE_PHRASE\n";
+
+ if (reader.get_data (disable_phrase) ) {
+ if (disable_phrase.length () >= 2) {
+ Phrase phrase = m_user_phrase_lib->find (disable_phrase);
+ if (phrase.valid () && phrase.is_enable ()) {
+ phrase.disable ();
+
+ send_trans.clear ();
+ send_trans.put_command (SCIM_TRANS_CMD_REQUEST);
+ send_trans.put_command (SCIM_PINYIN_TRANS_CMD_DISABLE_PHRASE_OK);
+ send_helper_event (SCIM_PINYIN_HELPER_UUID, send_trans);
+ SCIM_DEBUG_IMENGINE (2) << "PinyinInstance : process_helper_event () - send SCIM_PINYIN_TRANS_CMD_DISABLE_PHRASE_OK\n";
+ }
+ }
+ }
+ }
+ if (cmd == SCIM_PINYIN_TRANS_CMD_SAVE_USER_LIB) {
+ SCIM_DEBUG_IMENGINE (2) << "PinyinInstance : process_helper_event () - received SCIM_PINYIN_TRANS_CMD_SAVE_USER_LIB\n";
+
+ if (reader.get_data (selected_dirname) ) {
+ if ( m_pinyin_global->save_user_phrase_lib( (selected_dirname+pinyin_lib_bakname).c_str(),
+ (selected_dirname+pinyin_phrase_lib_bakname).c_str(),
+ (selected_dirname+pinyin_phrase_index_bakname).c_str(),
+ true) ) {
+ send_trans.clear ();
+ send_trans.put_command (SCIM_TRANS_CMD_REQUEST);
+ send_trans.put_command (SCIM_PINYIN_TRANS_CMD_SAVE_USER_LIB_OK);
+ send_helper_event (SCIM_PINYIN_HELPER_UUID, send_trans);
+ SCIM_DEBUG_IMENGINE (2) << "PinyinInstance : process_helper_event () - send SCIM_PINYIN_TRANS_CMD_SAVE_USER_LIB_OK\n";
+ } else {
+ send_trans.clear ();
+ send_trans.put_command (SCIM_TRANS_CMD_REQUEST);
+ send_trans.put_command (SCIM_PINYIN_TRANS_CMD_SAVE_USER_LIB_FAIL);
+ send_helper_event (SCIM_PINYIN_HELPER_UUID, send_trans);
+ SCIM_DEBUG_IMENGINE (2) << "PinyinInstance : process_helper_event () - send SCIM_PINYIN_TRANS_CMD_SAVE_USER_LIB_FAIL\n";
+ }
+ }
+ }
+ if (cmd == SCIM_PINYIN_TRANS_CMD_IMPORT_USER_LIB) {
+ SCIM_DEBUG_IMENGINE (2) << "PinyinInstance : process_helper_event () - received SCIM_PINYIN_TRANS_CMD_IMPORT_USER_LIB\n";
+
+ if (reader.get_data (selected_dirname) ) {
+ if (m_pinyin_global->load_user_phrase_lib ( (selected_dirname + pinyin_lib_bakname).c_str (),
+ (selected_dirname + pinyin_phrase_lib_bakname).c_str (),
+ (selected_dirname + pinyin_phrase_index_bakname) .c_str ())) {
+
+ send_trans.clear ();
+ send_trans.put_command (SCIM_TRANS_CMD_REQUEST);
+ send_trans.put_command (SCIM_PINYIN_TRANS_CMD_IMPORT_USER_LIB_OK);
+ send_helper_event (SCIM_PINYIN_HELPER_UUID, send_trans);
+ SCIM_DEBUG_IMENGINE (2) << "PinyinInstance : process_helper_event () - send SCIM_PINYIN_TRANS_CMD_IMPORT_USER_LIB_OK\n";
+ } else {
+ send_trans.clear ();
+ send_trans.put_command (SCIM_TRANS_CMD_REQUEST);
+ send_trans.put_command (SCIM_PINYIN_TRANS_CMD_IMPORT_USER_LIB_FAIL);
+ send_helper_event (SCIM_PINYIN_HELPER_UUID, send_trans);
+ SCIM_DEBUG_IMENGINE (2) << "PinyinInstance : process_helper_event () - send SCIM_PINYIN_TRANS_CMD_IMPORT_USER_LIB_FAIL\n";
+ }
+ }
+ }
+ if (cmd == SCIM_PINYIN_TRANS_CMD_COMMIT_NEW_PHRASE) {
+ SCIM_DEBUG_IMENGINE (2) << "PinyinInstance : process_helper_event () - received SCIM_PINYIN_TRANS_CMD_COMMIT_NEW_PHRASE\n";
+
+ if (reader.get_data (phrase_received) && reader.get_data (pinyin_received) ) {
+
+ if( phrase_received.size() != pinyin_received.size() ) {
+ SCIM_DEBUG_IMENGINE (2) << "PinyinInstance : process_helper_event () - phrase.size() != pinyin.size()\n";
+ return;
+ }
+
+ pkey_vec_vec.clear();
+
+ for (int i=0 ; i < pinyin_received.size(); i++){
+
+ first_black_space = false;
+ pkey_vec.clear();
+
+ iter1 = pinyin_received[i].begin();
+ iter2 = pinyin_received[i].begin();
+
+ while(iter2 != pinyin_received[i].end()) {
+ if( (*iter2) == ' ') {
+ if( !first_black_space ) {
+ first_black_space = true;
+
+ tmp_string.clear();
+
+ for(; iter1 != iter2; ++iter1 )
+ tmp_string.push_back(*iter1);
+
+ key = PinyinKey ( m_pinyin_global->get_pinyin_validator (),
+ tmp_string.c_str() );
+
+ pkey = PinyinParsedKey( key );
+
+ pkey_vec.push_back( pkey );
+
+ } else {
+ ++iter1;
+ }
+ } else {
+ if( first_black_space ) {
+ first_black_space = false;
+ ++iter1;
+ }
+ }
+ ++iter2;
+ }
+ pkey_vec_vec.push_back( pkey_vec );
+ }
+
+ for (int i=0 ; i < pkey_vec_vec.size(); i++){
+ if( pkey_vec_vec[i].size() <= 0 )
+ continue;
+
+ add_new_phrase (phrase_received[i], pkey_vec_vec[i]);
+ }
+
+ send_trans.clear ();
+ send_trans.put_command (SCIM_TRANS_CMD_REQUEST);
+ send_trans.put_command (SCIM_PINYIN_TRANS_CMD_COMMIT_NEW_PHRASE_OK);
+ send_helper_event (SCIM_PINYIN_HELPER_UUID, send_trans);
+ SCIM_DEBUG_IMENGINE (2) << "PinyinInstance : process_helper_event () - send SCIM_PINYIN_TRANS_CMD_COMMIT_NEW_PHRASE_OK\n";
+ }
+ }
+ if (cmd == SCIM_PINYIN_TRANS_CMD_GET_PINYIN) {
+ SCIM_DEBUG_IMENGINE (2) << "PinyinInstance : process_helper_event () - received SCIM_PINYIN_TRANS_CMD_GET_PINYIN\n";
+
+ if (reader.get_data (new_phrase)) {
+
+ if( new_phrase.length() == 0 )
+ return;
+
+ num = m_pinyin_table->find_key_strings ( keys_vector, new_phrase );
+ if( num == 0 ) { // it means the new_phrase is not a right Chinese string.
+ send_trans.clear ();
+ send_trans.put_command (SCIM_TRANS_CMD_REQUEST);
+ send_trans.put_command (SCIM_PINYIN_TRANS_CMD_SEND_PINYIN_FAILED);
+ send_helper_event (SCIM_PINYIN_HELPER_UUID, send_trans);
+ SCIM_DEBUG_IMENGINE (2) << "PinyinInstance : process_helper_event () - send SCIM_PINYIN_TRANS_CMD_SEND_PINYIN_FAILED\n";
+ return;
+ }
+
+ tmp_string.clear();
+ for (int i=0 ; i < keys_vector.size(); i++){
+
+ for (int j=0; j < keys_vector[i].size(); j++)
+ tmp_string += keys_vector[i][j].get_key_string() + " ";
+
+ pinyin_strings.push_back( tmp_string );
+ tmp_string.clear();
+ }
+
+ send_trans.clear ();
+ send_trans.put_command (SCIM_TRANS_CMD_REQUEST);
+ send_trans.put_command (SCIM_PINYIN_TRANS_CMD_SEND_PINYIN);
+ send_trans.put_data ( pinyin_strings );
+ send_helper_event (SCIM_PINYIN_HELPER_UUID, send_trans);
+ SCIM_DEBUG_IMENGINE (2) << "PinyinInstance : process_helper_event () - send SCIM_PINYIN_TRANS_CMD_SEND_PINYIN\n";
+ }
+ }
+ if (cmd == SCIM_PINYIN_TRANS_CMD_GET_MAX_USER_PHRASE_LENGTH) {
+ SCIM_DEBUG_IMENGINE (2) << "PinyinInstance : process_helper_event () - received SCIM_PINYIN_TRANS_CMD_GET_MAX_USER_PHRASE_LENGTH\n";
+
+ send_trans.clear ();
+ send_trans.put_command (SCIM_TRANS_CMD_REQUEST);
+ send_trans.put_command (SCIM_PINYIN_TRANS_CMD_SEND_MAX_USER_PHRASE_LENGTH);
+ send_trans.put_data ( m_factory->m_max_user_phrase_length );
+ send_helper_event (SCIM_PINYIN_HELPER_UUID, send_trans);
+ SCIM_DEBUG_IMENGINE (2) << "PinyinInstance : process_helper_event () - send SCIM_PINYIN_TRANS_CMD_SEND_MAX_USER_PHRASE_LENGTH\n";
+ }
+ }
+}//qshen end
+
void
PinyinInstance::select_candidate (unsigned int item)
{
@@ -1039,6 +1326,8 @@
m_full_width_punctuation [which] = !m_full_width_punctuation [which];
refresh_punct_property ();
+ } else if (property == SCIM_PROP_WORD) { //qshen
+ refresh_word_property (); //qshen
} else if (property == SCIM_PROP_PINYIN_SCHEME_QUAN_PIN) {
m_factory->m_shuang_pin = false;
update_pinyin_scheme = true;
@@ -1142,13 +1431,16 @@
proplist.push_back (_pinyin_quan_pin_property);
proplist.push_back (_pinyin_sp_stone_property);
proplist.push_back (_pinyin_sp_zrm_property);
- //proplist.push_back (_pinyin_sp_ms_property);
- //proplist.push_back (_pinyin_sp_ziguang_property);
+ proplist.push_back (_pinyin_sp_ms_property);
+ proplist.push_back (_pinyin_sp_ziguang_property);
proplist.push_back (_pinyin_sp_abc_property);
proplist.push_back (_pinyin_sp_liushi_property);
proplist.push_back (_status_property);
proplist.push_back (_letter_property);
proplist.push_back (_punct_property);
+
+ if( m_factory->m_show_word_property )
+ proplist.push_back (_word_property); //qshen
register_properties (proplist);
refresh_all_properties ();
@@ -1196,6 +1488,13 @@
update_property (_punct_property);
}
+//qshen add
+void
+PinyinInstance::refresh_word_property ()
+{
+ start_helper( SCIM_PINYIN_HELPER_UUID );
+}
+
void
PinyinInstance::refresh_pinyin_scheme_property ()
{
diff -Naur scim-pinyin-0.5.91.bak/src/scim_pinyin_imengine.h scim-pinyin-0.5.91/src/scim_pinyin_imengine.h
--- scim-pinyin-0.5.91.bak/src/scim_pinyin_imengine.h 2006-06-23 16:15:55.000000000 +0800
+++ scim-pinyin-0.5.91/src/scim_pinyin_imengine.h 2006-06-27 09:52:07.000000000 +0800
@@ -46,7 +46,9 @@
bool m_auto_fill_preedit;
bool m_always_show_lookup;
bool m_show_all_keys;
-
+
+ bool m_show_word_property; //qshen
+
bool m_user_data_binary;
bool m_valid;
@@ -127,6 +129,8 @@
WideString m_auto_combined_string;
KeyEvent m_prev_key;
+
+ bool m_helper_started; //qshen
NativeLookupTable m_lookup_table;
@@ -156,6 +160,7 @@
virtual ~PinyinInstance ();
virtual bool process_key_event (const KeyEvent& key);
+ virtual void process_helper_event (const String &helper_uuid, const Transaction &trans); //qshen add
virtual void move_preedit_caret (unsigned int pos);
virtual void select_candidate (unsigned int item);
virtual void update_lookup_table_page_size (unsigned int page_size);
@@ -201,6 +206,7 @@
void refresh_status_property ();
void refresh_letter_property ();
void refresh_punct_property ();
+ void refresh_word_property (); //qshen
void refresh_pinyin_scheme_property ();
void calc_parsed_keys ();
diff -Naur scim-pinyin-0.5.91.bak/src/scim_pinyin_imengine_setup.cpp scim-pinyin-0.5.91/src/scim_pinyin_imengine_setup.cpp
--- scim-pinyin-0.5.91.bak/src/scim_pinyin_imengine_setup.cpp 2006-06-23 16:15:55.000000000 +0800
+++ scim-pinyin-0.5.91/src/scim_pinyin_imengine_setup.cpp 2006-06-27 09:52:08.000000000 +0800
@@ -102,12 +102,13 @@
// Internal data declaration.
static bool __config_user_data_binary = false;
+static bool __config_pinyin_helper = false; //qshen
static bool __config_auto_combine_phrase = true;
static bool __config_auto_fill_preedit = true;
static bool __config_match_longer_phrase = false;
static bool __config_always_show_lookup = true;
-static bool __config_show_all_keys = true;
+static bool __config_show_all_keys = false;
static bool __config_dynamic_adjust = true;
static int __config_max_user_phrase_length = 8;
@@ -301,6 +302,7 @@
};
static GtkWidget * __widget_user_data_binary = 0;
+static GtkWidget * __widget_pinyin_helper = 0; //qshen
static GtkWidget * __widget_auto_combine_phrase = 0;
static GtkWidget * __widget_auto_fill_preedit = 0;
@@ -605,6 +607,12 @@
gtk_widget_show (separator);
gtk_box_pack_start (GTK_BOX (vbox), separator, FALSE, FALSE, 4);
+ // Pinyin helper -- qshen
+ __widget_pinyin_helper = gtk_check_button_new_with_mnemonic (_("Show pinyin helper property in the tool bar"));
+ gtk_widget_show (__widget_pinyin_helper);
+ gtk_box_pack_start (GTK_BOX (vbox), __widget_pinyin_helper, FALSE, FALSE, 4);
+ gtk_container_set_border_width (GTK_CONTAINER (__widget_pinyin_helper), 2);
+
// Create the pinyin configurations page
vbox = gtk_vbox_new (FALSE, 0);
gtk_widget_show (vbox);
@@ -746,6 +754,11 @@
g_signal_connect ((gpointer) __widget_user_data_binary, "toggled",
G_CALLBACK (__on_default_toggle_button_toggled),
&__config_user_data_binary);
+ //qshen
+ g_signal_connect ((gpointer) __widget_pinyin_helper, "toggled",
+ G_CALLBACK (__on_default_toggle_button_toggled),
+ &__config_pinyin_helper);
+
g_signal_connect ((gpointer) __widget_tone, "toggled",
G_CALLBACK (__on_default_toggle_button_toggled),
@@ -777,6 +790,11 @@
"the user pinyin and phrase data will be stored "
"in binary format. "
"This will increase the loading speed."), NULL);
+ //qshen add
+ gtk_tooltips_set_tip (__widget_tooltips, __widget_pinyin_helper,
+ _("If this option is checked, "
+ "the tool bar will show the pinyin_helper property. "),
+ NULL);
gtk_tooltips_set_tip (__widget_tooltips, __widget_auto_combine_phrase,
_("If this option is checked, "
@@ -980,6 +998,12 @@
GTK_TOGGLE_BUTTON (__widget_user_data_binary),
__config_user_data_binary);
}
+ //qshen
+ if (__widget_pinyin_helper) {
+ gtk_toggle_button_set_active (
+ GTK_TOGGLE_BUTTON (__widget_pinyin_helper),
+ __config_pinyin_helper);
+ }
for (i = 0; __config_keyboards [i].key; ++ i) {
if (__config_keyboards [i].entry) {
@@ -1044,6 +1068,9 @@
__config_user_data_binary=
config->read (String (SCIM_CONFIG_IMENGINE_PINYIN_USER_DATA_BINARY),
__config_user_data_binary);
+ __config_pinyin_helper= //qshen
+ config->read (String (SCIM_CONFIG_IMENGINE_PINYIN_SHOW_WORD_PROPERTY),
+ __config_pinyin_helper);
__config_max_user_phrase_length =
config->read (String (SCIM_CONFIG_IMENGINE_PINYIN_MAX_USER_PHRASE_LENGTH),
__config_max_user_phrase_length);
@@ -1107,6 +1134,8 @@
__config_dynamic_adjust);
config->write (String (SCIM_CONFIG_IMENGINE_PINYIN_USER_DATA_BINARY),
__config_user_data_binary);
+ config->write (String (SCIM_CONFIG_IMENGINE_PINYIN_SHOW_WORD_PROPERTY), //qshen
+ __config_pinyin_helper);
config->write (String (SCIM_CONFIG_IMENGINE_PINYIN_MAX_USER_PHRASE_LENGTH),
__config_max_user_phrase_length);
config->write (String (SCIM_CONFIG_IMENGINE_PINYIN_MAX_PREEDIT_LENGTH),
diff -Naur scim-pinyin-0.5.91.bak/src/scim_pinyin_phrase.h scim-pinyin-0.5.91/src/scim_pinyin_phrase.h
--- scim-pinyin-0.5.91.bak/src/scim_pinyin_phrase.h 2006-06-23 16:15:55.000000000 +0800
+++ scim-pinyin-0.5.91/src/scim_pinyin_phrase.h 2006-06-27 09:52:08.000000000 +0800
@@ -371,6 +371,9 @@
}
void optimize_phrase_frequencies (uint32 max_freq = (SCIM_PHRASE_MAX_FREQUENCY >> 1));
+
+ template<class T>
+ void for_each_phrase (T &op);
private:
Phrase get_phrase (uint32 phrase_offset) {
@@ -409,9 +412,6 @@
bool insert_phrase_into_index (const Phrase &phrase, const PinyinKeyVector &keys);
template<class T>
- void for_each_phrase (T &op);
-
- template<class T>
void for_each_phrase_level_one (uint32 len, T &op);
template<class T>
More information about the fedora-cvs-commits
mailing list