Kouhei Sutou
kous****@users*****
2006年 11月 30日 (木) 15:40:33 JST
Index: tomoe/module/dict/tomoe-dict-est.c diff -u tomoe/module/dict/tomoe-dict-est.c:1.1 tomoe/module/dict/tomoe-dict-est.c:1.2 --- tomoe/module/dict/tomoe-dict-est.c:1.1 Thu Nov 30 15:27:19 2006 +++ tomoe/module/dict/tomoe-dict-est.c Thu Nov 30 15:40:33 2006 @@ -17,7 +17,7 @@ * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA * - * $Id: tomoe-dict-est.c,v 1.1 2006/11/30 06:27:19 kous Exp $ + * $Id: tomoe-dict-est.c,v 1.2 2006/11/30 06:40:33 kous Exp $ */ #include <stdio.h> @@ -95,6 +95,7 @@ const gchar *utf8); static GList *search (TomoeDict *dict, TomoeQuery *query); +static gboolean flush (TomoeDict *dict); static gboolean tomoe_dict_est_open (TomoeDictEst *dict); static gboolean tomoe_dict_est_close (TomoeDictEst *dict); @@ -119,6 +120,7 @@ dict_class->unregister_char = unregister_char; dict_class->get_char = get_char; dict_class->search = search; + dict_class->flush = flush; g_object_class_install_property ( gobject_class, @@ -470,6 +472,14 @@ } static gboolean +flush (TomoeDict *_dict) +{ + TomoeDictEst *dict = TOMOE_DICT_EST (_dict); + + return est_db_sync (dict->db); +} + +static gboolean tomoe_dict_est_open (TomoeDictEst *dict) { gboolean success = TRUE; Index: tomoe/module/dict/tomoe-dict-xml.c diff -u tomoe/module/dict/tomoe-dict-xml.c:1.5 tomoe/module/dict/tomoe-dict-xml.c:1.6 --- tomoe/module/dict/tomoe-dict-xml.c:1.5 Thu Nov 30 15:27:19 2006 +++ tomoe/module/dict/tomoe-dict-xml.c Thu Nov 30 15:40:33 2006 @@ -21,7 +21,7 @@ * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA * - * $Id: tomoe-dict-xml.c,v 1.5 2006/11/30 06:27:19 kous Exp $ + * $Id: tomoe-dict-xml.c,v 1.6 2006/11/30 06:40:33 kous Exp $ */ #include <stdio.h> @@ -97,8 +97,9 @@ const gchar *utf8); static GList *search (TomoeDict *dict, TomoeQuery *query); +static gboolean flush (TomoeDict *dict); static gboolean tomoe_dict_xml_load (TomoeDictXML *dict); -static void tomoe_dict_xml_save (TomoeDictXML *dict); +static gboolean tomoe_dict_xml_save (TomoeDictXML *dict); static gint letter_compare_func (gconstpointer a, gconstpointer b); @@ -123,7 +124,8 @@ dict_class->unregister_char = unregister_char; dict_class->get_char = get_char; dict_class->search = search; - + dict_class->flush = flush; + g_object_class_install_property ( gobject_class, PROP_FILENAME, @@ -259,10 +261,7 @@ dict = TOMOE_DICT_XML(object); - if (dict->editable && dict->modified) { - dict->modified = FALSE; - tomoe_dict_xml_save (dict); - } + flush (TOMOE_DICT (dict)); if (dict->name) g_free (dict->name); @@ -439,6 +438,19 @@ return search_context.results; } +static gboolean +flush (TomoeDict *_dict) +{ + TomoeDictXML *dict = TOMOE_DICT_XML (_dict); + + if (dict->editable && dict->modified) { + dict->modified = FALSE; + return tomoe_dict_xml_save (dict); + } else { + return TRUE; + } +} + static gint letter_compare_func (gconstpointer a, gconstpointer b) { @@ -466,7 +478,7 @@ return success; } -static void +static gboolean tomoe_dict_xml_save (TomoeDictXML *dict) { FILE *f; @@ -474,11 +486,11 @@ const gchar *foot = "</dictionary>\n"; guint i; - g_return_if_fail (TOMOE_IS_DICT (dict)); - if (!dict->editable) return; + g_return_val_if_fail (TOMOE_IS_DICT (dict), FALSE); + if (!dict->editable) return FALSE; f = fopen (dict->filename, "wb"); - g_return_if_fail (f); + g_return_val_if_fail (f, FALSE); /* write the header */ head = g_strdup ( @@ -515,13 +527,13 @@ g_free (head); fclose (f); dict->modified = FALSE; - return; + return TRUE; ERROR: g_free (head); g_warning ("Faild to write %s.", dict->filename); fclose (f); - return; + return FALSE; } /*