[Tomoe-cvs 1460] CVS update: tomoe/lib

Back to archive index

Kouhei Sutou kous****@users*****
2006年 11月 30日 (木) 18:13:15 JST


Index: tomoe/lib/tomoe-char.c
diff -u tomoe/lib/tomoe-char.c:1.58 tomoe/lib/tomoe-char.c:1.59
--- tomoe/lib/tomoe-char.c:1.58	Thu Nov 30 11:53:15 2006
+++ tomoe/lib/tomoe-char.c	Thu Nov 30 18:13:15 2006
@@ -18,7 +18,7 @@
  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  *  Boston, MA  02111-1307  USA
  *
- *  $Id: tomoe-char.c,v 1.58 2006/11/30 02:53:15 kous Exp $
+ *  $Id: tomoe-char.c,v 1.59 2006/11/30 09:13:15 kous Exp $
  */
 
 #include <stdlib.h>
@@ -457,12 +457,11 @@
         TomoeReading *reading = node->data;
         gchar *xml;
 
-        if (!TOMOE_IS_READING (reading)) continue;
-
-        xml = g_markup_printf_escaped ("      <reading>%s</reading>\n",
-                                       tomoe_reading_get_reading (reading));
-        g_string_append (output, xml);
-        g_free (xml);
+        xml = tomoe_reading_to_xml (reading);
+        if (xml) {
+            g_string_append (output, xml);
+            g_free (xml);
+        }
     }
     g_string_append (output, "    </readings>\n");
 }
Index: tomoe/lib/tomoe-config.c
diff -u tomoe/lib/tomoe-config.c:1.44 tomoe/lib/tomoe-config.c:1.45
--- tomoe/lib/tomoe-config.c:1.44	Wed Nov 29 11:53:11 2006
+++ tomoe/lib/tomoe-config.c	Thu Nov 30 18:13:15 2006
@@ -17,7 +17,7 @@
  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  *  Boston, MA  02111-1307  USA
  *
- *  $Id: tomoe-config.c,v 1.44 2006/11/29 02:53:11 kous Exp $
+ *  $Id: tomoe-config.c,v 1.45 2006/11/30 09:13:15 kous Exp $
  */
 
 #ifdef HAVE_CONFIG_H
@@ -68,12 +68,15 @@
 
 static void     tomoe_config_save         (TomoeConfig *config);
 
-static gboolean _tomoe_dict_key_file_get_boolean_value (GKeyFile *key_file,
-                                                        const gchar *group,
-                                                        const gchar *key,
-                                                        gboolean default_value);
-static void     _tomoe_dict_load_system_dictionaries   (TomoeConfig *config,
-                                                        TomoeShelf *shelf);
+static gboolean _tomoe_config_key_file_get_boolean_value (GKeyFile *key_file,
+                                                          const gchar *group,
+                                                          const gchar *key,
+                                                          gboolean default_value);
+static void     _tomoe_config_load_system_dictionaries   (TomoeConfig *config,
+                                                          TomoeShelf *shelf);
+static TomoeDict *_tomoe_config_load_dictionary (GKeyFile    *key_file,
+                                                 const gchar *dict_name,
+                                                 const gchar *type);
 
 static void
 tomoe_config_class_init (TomoeConfigClass *klass)
@@ -256,49 +259,32 @@
     shelf = tomoe_shelf_new ();
     dicts = g_key_file_get_groups (key_file, &dicts_size);
     for (i = 0; i < dicts_size; i++) {
-        GError *error = NULL;
-        gchar *filename, *dict_name;
+        gchar *dict_name, *type;
         TomoeDict *dict;
 
         dict_name = dicts[i];
         if (!g_str_has_suffix (dict_name, "-dictionary"))
             continue;
 
-        filename = g_key_file_get_string (key_file, dict_name, "file", &error);
-        if (error) {
-            TOMOE_HANDLE_ERROR (error);
-            continue;
-        }
-
-        if (!_tomoe_dict_key_file_get_boolean_value (key_file, dict_name,
+        if (!_tomoe_config_key_file_get_boolean_value (key_file, dict_name,
                                                      "use", TRUE))
             continue;
 
-        if (_tomoe_dict_key_file_get_boolean_value (key_file, dict_name,
-                                                    "user", TRUE)) {
-            dict = tomoe_dict_new ("xml", "filename", filename,
-                                   "editable", TRUE, NULL);
-        } else {
-            gchar *dict_filename;
-            dict_filename = g_build_filename (TOMOEDATADIR, filename, NULL);
-            dict = tomoe_dict_new ("xml", "filename", filename,
-                                   "editable", TRUE, NULL);
-            g_free (dict_filename);
-        }
-
+        type = g_key_file_get_string (key_file, dict_name, "type", NULL);
+        dict = _tomoe_config_load_dictionary (key_file, dict_name,
+                                              type ? type : "xml");
         if (dict) {
             tomoe_shelf_add_dict (shelf, dict);
             g_object_unref (dict);
         }
-
-        g_free (filename);
+        g_free (type);
     }
 
-    if (_tomoe_dict_key_file_get_boolean_value (key_file,
+    if (_tomoe_config_key_file_get_boolean_value (key_file,
                                                 "config",
                                                 "use_system_dictionaries",
                                                 TRUE)) {
-        _tomoe_dict_load_system_dictionaries (config, shelf);
+        _tomoe_config_load_system_dictionaries (config, shelf);
     }
 
     g_strfreev(dicts);
@@ -306,7 +292,7 @@
 }
 
 static gboolean
-_tomoe_dict_key_file_get_boolean_value (GKeyFile *key_file,
+_tomoe_config_key_file_get_boolean_value (GKeyFile *key_file,
                                         const gchar *group,
                                         const gchar *key,
                                         gboolean default_value)
@@ -331,7 +317,7 @@
 }
 
 static void
-_tomoe_dict_load_system_dictionaries (TomoeConfig *config, TomoeShelf *shelf)
+_tomoe_config_load_system_dictionaries (TomoeConfig *config, TomoeShelf *shelf)
 {
     const gchar *filename;
     GDir *gdir;
@@ -361,6 +347,99 @@
     g_dir_close (gdir);
 }
 
+static TomoeDict *
+load_xml_dictionary (GKeyFile *key_file, const gchar *dict_name)
+{
+    TomoeDict *dict;
+    GError *error = NULL;
+    gchar *filename;
+    gboolean user_dict, editable;
+
+    filename = g_key_file_get_string (key_file, dict_name, "file", &error);
+    if (error) {
+        TOMOE_HANDLE_ERROR (error);
+        return NULL;
+    }
+
+    editable = _tomoe_config_key_file_get_boolean_value (key_file, dict_name,
+                                                         "editable", TRUE);
+    user_dict = _tomoe_config_key_file_get_boolean_value (key_file, dict_name,
+                                                          "user", TRUE);
+    if (!user_dict) {
+        gchar *tmp;
+        tmp = g_build_filename (TOMOEDATADIR, filename, NULL);
+        g_free (filename);
+        filename = tmp;
+    }
+
+    dict = tomoe_dict_new ("xml",
+                           "filename", filename,
+                           "editable", editable,
+                           NULL);
+
+    g_free (filename);
+
+    return dict;
+}
+
+static TomoeDict *
+load_est_dictionary (GKeyFile *key_file, const gchar *dict_name)
+{
+    TomoeDict *dict;
+    GError *error = NULL;
+    gchar *name, *database_name;
+    gboolean user_dict, editable;
+
+    name = g_key_file_get_string (key_file, dict_name, "name", &error);
+    if (error) {
+        TOMOE_HANDLE_ERROR (error);
+        return NULL;
+    }
+
+    database_name = g_key_file_get_string (key_file, dict_name,
+                                           "database", &error);
+    if (error) {
+        TOMOE_HANDLE_ERROR (error);
+        return NULL;
+    }
+
+    editable = _tomoe_config_key_file_get_boolean_value (key_file, dict_name,
+                                                         "editable", TRUE);
+    user_dict = _tomoe_config_key_file_get_boolean_value (key_file, dict_name,
+                                                          "user", TRUE);
+    if (!user_dict) {
+        gchar *tmp;
+        tmp = g_build_filename (TOMOEDATADIR, database_name, NULL);
+        g_free (database_name);
+        database_name = tmp;
+    }
+
+    dict = tomoe_dict_new ("est",
+                           "name", name,
+                           "database_name", database_name,
+                           "editable", editable,
+                           NULL);
+
+    g_free (name);
+    g_free (database_name);
+
+    return dict;
+}
+
+static TomoeDict *
+_tomoe_config_load_dictionary (GKeyFile *key_file,
+                               const gchar *dict_name,
+                               const gchar *type)
+{
+    if (strcmp (type, "xml") == 0) {
+        return load_xml_dictionary (key_file, dict_name);
+    } else if (strcmp (type, "est") == 0) {
+        return load_est_dictionary (key_file, dict_name);
+    } else {
+        return NULL;
+    }
+}
+
 /*
  * vi:ts=4:nowrap:ai:expandtab
  */
Index: tomoe/lib/tomoe-reading.c
diff -u tomoe/lib/tomoe-reading.c:1.2 tomoe/lib/tomoe-reading.c:1.3
--- tomoe/lib/tomoe-reading.c:1.2	Mon Nov 27 13:49:57 2006
+++ tomoe/lib/tomoe-reading.c	Thu Nov 30 18:13:15 2006
@@ -17,7 +17,7 @@
  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  *  Boston, MA  02111-1307  USA
  *
- *  $Id: tomoe-reading.c,v 1.2 2006/11/27 04:49:57 ikezoe Exp $
+ *  $Id: tomoe-reading.c,v 1.3 2006/11/30 09:13:15 kous Exp $
  */
 
 #include <stdlib.h>
@@ -191,6 +191,42 @@
     return priv->reading;
 }
 
+gchar *
+tomoe_reading_to_xml (TomoeReading *reading)
+{
+    TomoeReadingPrivate *priv;
+    gchar *format, *type_name;
+
+    g_return_val_if_fail (TOMOE_IS_READING (reading), NULL);
+
+    priv = TOMOE_READING_GET_PRIVATE (reading);
+
+    type_name = NULL;
+    if (priv->type == TOMOE_READING_INVALID)
+        format = "      <reading>%s</reading>\n";
+    else
+        format = "      <reading type=\"%s\">%s</reading>\n";
+
+    switch (priv->type) {
+      case TOMOE_READING_INVALID:
+        break;
+      case TOMOE_READING_UNKNOWN:
+        type_name = "unknown";
+        break;
+      case TOMOE_READING_JA_ON:
+        type_name = "ja_on";
+        break;
+      case TOMOE_READING_JA_KUN:
+        type_name = "ja_kun";
+        break;
+    }
+
+    if (type_name)
+        return g_markup_printf_escaped (format, type_name, priv->reading);
+    else
+        return g_markup_printf_escaped (format, priv->reading);
+}
+
 /*
 vi:ts=4:nowrap:ai:expandtab
 */
Index: tomoe/lib/tomoe-reading.h
diff -u tomoe/lib/tomoe-reading.h:1.3 tomoe/lib/tomoe-reading.h:1.4
--- tomoe/lib/tomoe-reading.h:1.3	Tue Nov 28 11:27:59 2006
+++ tomoe/lib/tomoe-reading.h	Thu Nov 30 18:13:15 2006
@@ -17,7 +17,7 @@
  *  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  *  Boston, MA  02111-1307  USA
  *
- *  $Id: tomoe-reading.h,v 1.3 2006/11/28 02:27:59 makeinu Exp $
+ *  $Id: tomoe-reading.h,v 1.4 2006/11/30 09:13:15 kous Exp $
  */
 
 /** @file tomoe-reading.h
@@ -70,6 +70,8 @@
 TomoeReadingType  tomoe_reading_get_reading_type (TomoeReading     *reading);
 const gchar      *tomoe_reading_get_reading      (TomoeReading     *reading);
 
+gchar            *tomoe_reading_to_xml           (TomoeReading     *reading);
+
 G_END_DECLS
 
 #endif /* __TOMOE_READING_H__ */


tomoe-cvs メーリングリストの案内
Back to archive index