[uim-commit] r2473 - trunk/emacs

ekato at freedesktop.org ekato at freedesktop.org
Thu Dec 8 21:07:40 PST 2005


Author: ekato
Date: 2005-12-08 21:07:32 -0800 (Thu, 08 Dec 2005)
New Revision: 2473

Modified:
   trunk/emacs/callback.c
   trunk/emacs/callback.h
   trunk/emacs/context.c
   trunk/emacs/context.h
   trunk/emacs/encoding.c
   trunk/emacs/encoding.h
   trunk/emacs/prop.c
Log:
* emacs/callback.h
* emacs/callback.c
* emacs/encoding.h
* emacs/encoding.c
* emacs/context.h
* emacs/context.c
* emmacs/prop.c
  - Handle configuration_changed_cb().  Bug #5284. comment #3.


Modified: trunk/emacs/callback.c
===================================================================
--- trunk/emacs/callback.c	2005-12-09 05:02:23 UTC (rev 2472)
+++ trunk/emacs/callback.c	2005-12-09 05:07:32 UTC (rev 2473)
@@ -150,3 +150,17 @@
   update_prop_label(ua->prop, str);
 }
 
+
+void
+configuration_changed_cb(void *ptr)
+{
+
+  uim_agent_context *ua = (uim_agent_context *)ptr;
+
+  /* configuration of context has changed at uim side */
+  debug_printf(DEBUG_NOTE, "configuration_changed_cb\n");
+
+  update_context_configuration(ua);
+  
+}
+

Modified: trunk/emacs/callback.h
===================================================================
--- trunk/emacs/callback.h	2005-12-09 05:02:23 UTC (rev 2472)
+++ trunk/emacs/callback.h	2005-12-09 05:07:32 UTC (rev 2473)
@@ -65,7 +65,9 @@
 void candidate_shift_page_cb(void *ptr, int direction);
 void candidate_deactivate_cb(void *ptr);
 
-void prop_list_update_cb(void *ptr , const char *str);
-void prop_label_update_cb(void *ptr , const char *str);
+void prop_list_update_cb(void *ptr, const char *str);
+void prop_label_update_cb(void *ptr, const char *str);
 
+void configuration_changed_cb(void *ptr);
+
 #endif

Modified: trunk/emacs/context.c
===================================================================
--- trunk/emacs/context.c	2005-12-09 05:02:23 UTC (rev 2472)
+++ trunk/emacs/context.c	2005-12-09 05:07:32 UTC (rev 2473)
@@ -42,6 +42,39 @@
 uim_agent_context_list *agent_context_list_head = NULL;
 uim_agent_context_list *agent_context_list_tail = NULL;
 
+static void
+update_context_im(uim_agent_context *ua)
+{
+  debug_printf(DEBUG_NOTE, "update_context_im\n");
+
+  uim_switch_im(ua->context, ua->im);
+
+  if (ua->im && strcmp(ua->im, uim_get_current_im_name(ua->context)) != 0) {
+	debug_printf(DEBUG_ERROR,
+				 "update_context_im: failed to switch IM to %s\n", ua->im);
+	free(ua->im);
+	ua->im = strdup(uim_get_current_im_name(ua->context));
+  }
+}
+
+static void
+update_context_encoding(uim_agent_context *ua)
+{
+
+  debug_printf(DEBUG_NOTE, "update_context_encoding\n");
+
+  /* discard current context */
+  clear_candidate(ua->pe->cand);
+  clear_preedit(ua->pe);
+  uim_release_context(ua->context);
+  
+  ua->context = create_context(ua->encoding, ua);
+
+  update_context_im(ua);
+  
+}
+
+
 /* search context */
 uim_agent_context *
 get_uim_agent_context(int id)
@@ -71,57 +104,47 @@
 	return ua;
   }
 
+  if (ua->im) free(ua->im);
+
+  if (im)
+	ua->im = strdup(im);
+  else
+	ua->im = NULL;
+
   if (strcmp(ua->encoding, encoding) == 0) {
 	/* encodings are same */
 
 	debug_printf(DEBUG_NOTE,
 				 "same encoding %s %s\n", ua->im, im);
 
-	if (ua->im) free(ua->im);
+	update_context_im(ua);
 
-	if (im)
-	  ua->im = strdup(im);
-	else
-	  ua->im = NULL;
-
-	uim_switch_im(ua->context, im);  
-
 	uim_prop_label_update(ua->context);
 	uim_prop_list_update(ua->context);
 
-	return ua;
-
   } else {
 	/* encodings are different */
 
 	debug_printf(DEBUG_NOTE, 
 				 "different encoding %s %s\n", ua->encoding, encoding);
 
-	/* discard current context */
-	clear_candidate(ua->pe->cand);
-	clear_preedit(ua->pe);
-	uim_release_context(ua->context);
+	if (ua->encoding) free(ua->encoding);
+	ua->encoding = strdup(encoding);
 
-	ua->context = create_context(encoding, ua);
+	update_context_encoding(ua);
 
-	uim_switch_im(ua->context, im);
+  }
 
-	if (ua->im) free(ua->im);
+  uim_prop_label_update(ua->context);
+  uim_prop_list_update(ua->context);
 
-	ua->im = strdup(uim_get_current_im_name(ua->context));
+  return ua;
 
-	if (ua->encoding) free(ua->encoding);
+}
 
-	ua->encoding = strdup(encoding);
 
-	uim_prop_label_update(ua->context);
-	uim_prop_list_update(ua->context);
 
-	return ua;
-  }
-}
 
-
 uim_context
 create_context(const char *encoding, uim_agent_context *ptr)
 {
@@ -150,6 +173,9 @@
 
   uim_set_prop_label_update_cb(context,
 							   prop_label_update_cb);
+
+  uim_set_configuration_changed_cb(context,
+								   configuration_changed_cb);
   
   return context;
 
@@ -285,3 +311,28 @@
   return -1;
 }
 
+
+
+/* handle configuration change */
+void
+update_context_configuration(uim_agent_context *ua)
+{
+
+  /* configuration of context has changed at uim side */
+  debug_printf(DEBUG_NOTE, "update_context_configuration\n");
+  
+  /* update IM name */
+  if (ua->im) free(ua->im);
+  ua->im = strdup(uim_get_current_im_name(ua->context));
+
+  debug_printf(DEBUG_NOTE, "ua->im %s\n", ua->im);
+
+  if (ua->encoding) free(ua->encoding);
+  ua->encoding = strdup(get_im_encoding(ua->im));
+
+  debug_printf(DEBUG_NOTE, "ua->encoding %s\n", ua->encoding);
+
+  /* switch IM again to update encoding for Emacs...orz */
+  update_context_encoding(ua);
+
+}

Modified: trunk/emacs/context.h
===================================================================
--- trunk/emacs/context.h	2005-12-09 05:02:23 UTC (rev 2472)
+++ trunk/emacs/context.h	2005-12-09 05:07:32 UTC (rev 2473)
@@ -49,6 +49,7 @@
 #include "preedit.h"
 #include "im.h"
 #include "callback.h"
+#include "encoding.h"
 
 typedef struct uim_agent_context {
   uim_context context;
@@ -78,6 +79,8 @@
 uim_agent_context *switch_context_im(uim_agent_context *ua, const char *im,
 									 const char *encoding);
 
+void update_context_configuration(uim_agent_context *ua);
+
 /* current focused context */
 extern uim_agent_context *current;
 

Modified: trunk/emacs/encoding.c
===================================================================
--- trunk/emacs/encoding.c	2005-12-09 05:02:23 UTC (rev 2472)
+++ trunk/emacs/encoding.c	2005-12-09 05:07:32 UTC (rev 2473)
@@ -38,6 +38,7 @@
 
 im_encoding *im_enc_list_head = NULL, *im_enc_list_tail = NULL;
 
+char default_encoding[] = "UTF-8";
 
 /* search encoding entry */
 im_encoding *
@@ -130,6 +131,7 @@
 	debug_printf(DEBUG_NOTE, " encoding = %s\n", im_enc->encoding);
 	return im_enc->encoding;
   } else {
-	return NULL;
+	/*return NULL;*/
+	return default_encoding;
   }
 }

Modified: trunk/emacs/encoding.h
===================================================================
--- trunk/emacs/encoding.h	2005-12-09 05:02:23 UTC (rev 2472)
+++ trunk/emacs/encoding.h	2005-12-09 05:07:32 UTC (rev 2473)
@@ -52,6 +52,8 @@
 
 extern im_encoding *im_enc_list_head, *im_enc_list_tail;
 
+extern char default_encoding[];
+
 im_encoding *search_im_encoding(const char *im);
 im_encoding *new_im_encoding(const char *im, const char *encoding);
 int set_im_encoding(const char *im, const char *encoding);

Modified: trunk/emacs/prop.c
===================================================================
--- trunk/emacs/prop.c	2005-12-09 05:02:23 UTC (rev 2472)
+++ trunk/emacs/prop.c	2005-12-09 05:07:32 UTC (rev 2473)
@@ -44,6 +44,8 @@
 
   prop->list = strdup(str);
   
+  debug_printf(DEBUG_NOTE, "prop->list: %s\n", prop->list);  
+
   prop->list_update = 1;
 
 }
@@ -55,6 +57,8 @@
 
   prop->label = strdup(str);
 
+  debug_printf(DEBUG_NOTE, "prop->label: %s\n", prop->label);  
+
   prop->label_update = 1;
 
 }



More information about the uim-commit mailing list