[uim-commit] r3110 - in trunk: doc helper scm

yamaken at freedesktop.org yamaken at freedesktop.org
Fri Feb 17 09:14:01 PST 2006


Author: yamaken
Date: 2006-02-17 09:13:54 -0800 (Fri, 17 Feb 2006)
New Revision: 3110

Modified:
   trunk/doc/COMPATIBILITY
   trunk/doc/HELPER-PROTOCOL
   trunk/helper/toolbar-common-gtk.c
   trunk/scm/action.scm
Log:
* This commit make helper protocol incompatible with former
  ones. Helper program developers, please read doc/HELPER-PROTOCOL and
  follow the changes

* doc/HELPER-PROTOCOL
  - Revise 'prop_label_update' and 'prop_list_update'
* doc/COMPATIBILITY
  - Add new section "Add icon support to helper protocol"
* scm/action.scm
  - (indication-compose-label, indication-compose-leaf): Add
    indication-id into the message
* helper/toolbar-common-gtk.c
  - (command_entry_len): Change type to guint
  - (helper_toolbar_check_custom, right_click_menu_create): Follow the
    type change of command_entry_len
  - (has_n_strs): New static function
  - (helper_toolbar_prop_list_update):
    * Follow the protocol change
    * Make protocol interpretation meaningful
    * Fix crash on invalid message
  - (helper_toolbar_prop_label_update):
    * Follow the protocol change
    * Make protocol interpretation meaningful


Modified: trunk/doc/COMPATIBILITY
===================================================================
--- trunk/doc/COMPATIBILITY	2006-02-15 18:22:13 UTC (rev 3109)
+++ trunk/doc/COMPATIBILITY	2006-02-17 17:13:54 UTC (rev 3110)
@@ -57,6 +57,26 @@
 
 The changes are described below in most recently updated order.
 ------------------------------------------------------------------------------
+Summary: Add icon support to helper protocol
+Affects: Helper program developers
+Updates: Helper protocol
+Version: 1.1.0
+Revision: ac3110
+Date: 2006-02-18
+Modifier: YamaKen
+Related:
+URL:
+  http://lists.freedesktop.org/archives/uim/2006-February/001434.html
+Changes:
+  (update) "prop_label_update"
+  (update) "prop_list_update"
+Description:
+  Add 'indication_id' attribute to the two messages to support icons on
+  toolbars. And a special indication_id "separator" is also defined.
+  
+  The message formats have been incompatible with former ones. Helper program
+  developers, please read doc/HELPER-PROTOCOL and follow the changes.
+------------------------------------------------------------------------------
 Summary: Rename is-set-ugid? to follow the Scheme naming convention
 Affects: IM developers, uim developers
 Updates: Scheme API

Modified: trunk/doc/HELPER-PROTOCOL
===================================================================
--- trunk/doc/HELPER-PROTOCOL	2006-02-15 18:22:13 UTC (rev 3109)
+++ trunk/doc/HELPER-PROTOCOL	2006-02-17 17:13:54 UTC (rev 3110)
@@ -99,6 +99,7 @@
   charset = "UTF-8" | "EUC-JP" | "GB18030" |
             <or any name that can be specified as iconv_open(3) argument>
   str = str <any characters except for '\0', '\t' or '\n'> | ""
+  identifier = [_a-zA-Z][_a-zA-Z0-9]*
 
 * Focus notification messages
 
@@ -166,6 +167,11 @@
     designed to reduce message passing overhead by replacing prop_list_update
     by this.
 
+    indication_id is an identifier that specifies visual appearance of the
+    item. The ID roughly considerable as "icon name", and so the message
+    receiver can use it to form filename for the corresponding icon
+    (e.g. "anthy" -> "/path/to/somewhere/32x32/anthy.png").
+
     iconic_label is a very short string typically 1 character to be used as
     icon. For example, "a" means 'direct input'.
 
@@ -177,8 +183,9 @@
 
     prop_label_update = "prop_label_update\n" charset_specifier labels
     labels = labels label | label
-    label = iconic_label "\t" buttontooltip_string "\n"
+    label = indication_id "\t" iconic_label "\t" buttontooltip_string "\n"
 
+    indication_id = identifier
     iconic_label = str
     buttontooltip_string = str
 
@@ -207,6 +214,12 @@
     iconic_label is a very short string typically 1 character to be used as
     icon. For example, "a" means 'direct input'.
 
+    indication_id is an identifier. This element has same meaning as in
+    prop_label_update except for the special ID "separator". If the ID is
+    "separator", message receivers should display the leaf as toolkit-native
+    separator. But it is not necessary since the "separator" appears as dummy
+    item with no action if the receiver is not aware of it.
+
     buttontooltip_string is a string for tooltip of the button.
 
     menulabel_string is a short string to be shown in the menu.
@@ -227,10 +240,11 @@
     prop_list_update = "prop_list_update\n" charset_specifier parts
     parts = parts part | part
     part = branch leaves
-    branch = "branch\t" iconic_label "\t" buttontooltip_string "\n"
+    branch = "branch\t" indication_id "\t" iconic_label "\t" buttontooltip_string "\n"
     leaves = leaves leaf | leaf
-    leaf = "leaf\t" iconic_label "\t" menulabel_string "\t" menutooltip_string "\t" menucommand_name "\t" flag "\n"
+    leaf = "leaf\t" indication_id "\t" iconic_label "\t" menulabel_string "\t" menutooltip_string "\t" menucommand_name "\t" flag "\n"
 
+    indication_id = identifier | "separator"
     iconic_label = str
     buttontooltip_string = str
     menulabel_string = str

Modified: trunk/helper/toolbar-common-gtk.c
===================================================================
--- trunk/helper/toolbar-common-gtk.c	2006-02-15 18:22:13 UTC (rev 3109)
+++ trunk/helper/toolbar-common-gtk.c	2006-02-17 17:13:54 UTC (rev 3110)
@@ -136,7 +136,7 @@
   }
 };
 
-static gint command_entry_len = sizeof(command_entry) / sizeof(struct _CommandEntry);
+static guint command_entry_len = sizeof(command_entry) / sizeof(struct _CommandEntry);
 
 static GtkWidget *im_menu;
 static GtkWidget *prop_menu;
@@ -144,6 +144,24 @@
 static unsigned int read_tag;
 static int uim_fd;
 
+static gboolean has_n_strs(gchar **str_list, guint n);
+
+static gboolean
+has_n_strs(gchar **str_list, guint n)
+{
+  guint i;
+
+  if (!str_list)
+    return FALSE;
+
+  for (i = 0; i < n; i++) {
+    if (!str_list[i])
+      return FALSE;
+  }
+
+  return TRUE;
+}
+
 static void
 calc_menu_position(GtkMenu *menu, gint *x, gint *y, gboolean *push_in,
 		   GtkWidget *button)
@@ -573,9 +591,11 @@
 helper_toolbar_prop_list_update(GtkWidget *widget, gchar **lines)
 {
   GtkWidget *button = NULL;
-  int i;
+  guint i;
   gchar **cols;
-  gchar *charset = NULL;
+  gchar *charset;
+  gchar *indication_id, *iconic_label, *label, *tooltip_str;
+  gchar *action_id, *is_selected;
   GList *prop_buttons, *tool_buttons;
   GtkSizeGroup *sg;
 
@@ -596,8 +616,7 @@
     g_object_set_data(G_OBJECT(widget), OBJECT_DATA_TOOL_BUTTONS, NULL);
   }
 
-  i = 0;
-  while (lines[i] && strcmp("", lines[i])) {
+  for (i = 0; lines[i] && strcmp("", lines[i]); i++) {
     gchar *utf8_str = convert_charset(charset, lines[i]);
 
     if (utf8_str != NULL) {
@@ -608,15 +627,24 @@
     }
     
     if (cols && cols[0]) {
-      if (!strcmp("branch", cols[0])) {
-	button = prop_button_create(widget, cols[1], cols[2]);
+      if (!strcmp("branch", cols[0]) && has_n_strs(cols, 4)) {
+	indication_id = cols[1];
+	iconic_label  = cols[2];
+	tooltip_str   = cols[3];
+	button = prop_button_create(widget, iconic_label, tooltip_str);
 	append_prop_button(widget, button);
-      } else if (!strcmp("leaf", cols[0])) {
-	prop_button_append_menu(button, cols[2], cols[3], cols[4], cols[5]);
+      } else if (!strcmp("leaf", cols[0]) && has_n_strs(cols, 7)) {
+	indication_id = cols[1];
+	iconic_label  = cols[2];
+	label         = cols[3];
+	tooltip_str   = cols[4];
+	action_id     = cols[5];
+	is_selected   = cols[6];
+	prop_button_append_menu(button,
+				label, tooltip_str, action_id, is_selected);
       }
       g_strfreev(cols);
     }
-    i++;
   }
   
   /* create tool buttons */
@@ -665,14 +693,13 @@
 helper_toolbar_prop_label_update(GtkWidget *widget, gchar **lines)
 {
   GtkWidget *button;
-  unsigned int i;
-  gchar **pair;
-  gchar *charset = NULL;
+  guint i;
+  gchar **cols;
+  gchar *charset, *indication_id, *iconic_label, *tooltip_str;
   GList *prop_buttons;
 
-  i = 0;
-  while (lines[i] && strcmp("", lines[i]))
-    i++;
+  for (i = 0; lines[i] && strcmp("", lines[i]); i++)
+    continue;
 
   prop_buttons = g_object_get_data(G_OBJECT(widget), OBJECT_DATA_PROP_BUTTONS);
   if (!prop_buttons || (i - 2) != g_list_length(prop_buttons)) {
@@ -682,8 +709,7 @@
   
   charset = get_charset(lines[1]);
 
-  i = 2;
-  while (lines[i] && strcmp("", lines[i])) {
+  for (i = 2; lines[i] && strcmp("", lines[i]); i++) {
     if (charset) {
       gchar *utf8_str;
       utf8_str = g_convert(lines[i], strlen(lines[i]),
@@ -691,18 +717,20 @@
 			   NULL, /* gsize *bytes_read */
 			   NULL, /*size *bytes_written */
 			   NULL); /* GError **error*/
-      pair = g_strsplit(utf8_str, "\t", 0);
+      cols = g_strsplit(utf8_str, "\t", 0);
       g_free(utf8_str);
     } else {
-      pair = g_strsplit(lines[i], "\t", 0);
+      cols = g_strsplit(lines[i], "\t", 0);
     }
     
-    if (pair && pair[0] && pair[1]) {
+    if (has_n_strs(cols, 3)) {
+      indication_id = cols[0];
+      iconic_label  = cols[1];
+      tooltip_str   = cols[2];
       button = g_list_nth_data(prop_buttons, i - 2);
-      gtk_button_set_label(GTK_BUTTON(button), pair[0]);
+      gtk_button_set_label(GTK_BUTTON(button), iconic_label);
     }
-    g_strfreev(pair);
-    i++;
+    g_strfreev(cols);
   }
 
   g_free(charset);
@@ -777,7 +805,7 @@
 static void
 helper_toolbar_check_custom()
 {
-  int i;
+  guint i;
 
   for (i = 0; i < command_entry_len; i++)
     command_entry[i].show_button =
@@ -858,7 +886,7 @@
   GtkWidget *menu;
   GtkWidget *menu_item;
   GtkWidget *img;
-  gint i;
+  guint i;
 
   menu = gtk_menu_new();
 

Modified: trunk/scm/action.scm
===================================================================
--- trunk/scm/action.scm	2006-02-15 18:22:13 UTC (rev 3109)
+++ trunk/scm/action.scm	2006-02-17 17:13:54 UTC (rev 3110)
@@ -261,7 +261,8 @@
 
 (define indication-compose-label
   (lambda (indication)
-    (string-append (indication-iconic-label indication) "\t"
+    (string-append (symbol->string (indication-id indication)) "\t"
+		   (indication-iconic-label indication) "\t"
 		   (indication-label indication) "\n")))
 
 (define indication-compose-branch
@@ -272,6 +273,7 @@
 (define indication-compose-leaf
   (lambda (indication act-id active?)
     (string-append "leaf\t"
+		   (symbol->string (indication-id indication)) "\t"
 		   (indication-iconic-label indication) "\t"
 		   (indication-label indication) "\t"
 		   (indication-short-desc indication) "\t"



More information about the uim-commit mailing list