diff options
author | Bruno Coudoin <bcoudoin@src.gnome.org> | 2009-02-05 00:25:57 (GMT) |
---|---|---|
committer | Bruno Coudoin <bcoudoin@src.gnome.org> | 2009-02-05 00:25:57 (GMT) |
commit | 48c9a62bc18d8347f994f5d21688d2914c99d124 (patch) | |
tree | 6a38bbaf4499657f696ddb7d0ec4b76fe058544c /src/gcompris | |
parent | 1062aef3ec80758b7e3eb3fc1cbcf3e9ca222cc4 (diff) |
Miguel DE IZARRA added support for online wordlist.
This save custom data in user_dir and make a content.txt (a md5sum
like file) listing custom files. Simply put this files in a web server
to diffuse in classroom.
GCompris clients are launch with --server and --cache-dir
On start, client download content.txt from server.
And when a client need a file:
- first he search in server list (from content.txt)
- if found, he check md5 of file in cache_dir
- if md5 isn't ok, file is download in cache_dir
file in cache_dir is used
- if not found, search in package_dir (like now)
svn path=/trunk/; revision=3720
Diffstat (limited to 'src/gcompris')
-rw-r--r-- | src/gcompris/Makefile.am | 1 | ||||
-rw-r--r-- | src/gcompris/board_config_wordlist.c | 28 | ||||
-rw-r--r-- | src/gcompris/cache.c | 203 | ||||
-rw-r--r-- | src/gcompris/config.c | 2 | ||||
-rw-r--r-- | src/gcompris/dialog.c | 3 | ||||
-rw-r--r-- | src/gcompris/gameutil.c | 42 | ||||
-rw-r--r-- | src/gcompris/gameutil.h | 1 | ||||
-rw-r--r-- | src/gcompris/gc_core.h | 7 | ||||
-rw-r--r-- | src/gcompris/gc_net.c | 306 | ||||
-rw-r--r-- | src/gcompris/gc_net.h | 10 | ||||
-rw-r--r-- | src/gcompris/gcompris.c | 14 | ||||
-rw-r--r-- | src/gcompris/images_selector.c | 6 | ||||
-rw-r--r-- | src/gcompris/skin.c | 2 | ||||
-rw-r--r-- | src/gcompris/wordlist.c | 2 |
14 files changed, 271 insertions, 356 deletions
diff --git a/src/gcompris/Makefile.am b/src/gcompris/Makefile.am index f10a712..d91bbf2 100644 --- a/src/gcompris/Makefile.am +++ b/src/gcompris/Makefile.am @@ -76,7 +76,6 @@ gcompris_SOURCES = \ board_config.h board_config.c \ bonus.c \ bonus.h \ - cache.c \ config.c \ dialog.c \ drag.c \ diff --git a/src/gcompris/board_config_wordlist.c b/src/gcompris/board_config_wordlist.c index c0dd7c1..b0609ba 100644 --- a/src/gcompris/board_config_wordlist.c +++ b/src/gcompris/board_config_wordlist.c @@ -118,6 +118,22 @@ static void _textview_changed(GtkWidget *w, gpointer data) gtk_widget_set_sensitive(GTK_WIDGET(u->button), TRUE); } +static void _return_clicked(GtkWidget *w, gpointer data) +{ + int level; + user_param_type_wordlist *u = (user_param_type_wordlist*)data; + gchar *filename; + + filename = gc_file_find_absolute_writeable(u->wordlist->filename); + gc_cache_remove(filename); + g_free(filename); + + level = gtk_combo_box_get_active(u->combo_level)+1; + _combo_lang_changed(u->combo_lang, u); + gtk_combo_box_set_active(u->combo_level, level-1); + _combo_level_changed(u->combo_level, u); +} + static void _button_clicked(GtkWidget *w, gpointer data) { user_param_type_wordlist *u = (user_param_type_wordlist*)data; @@ -223,10 +239,18 @@ GtkWidget *gc_board_config_wordlist(GcomprisBoardConf *config, const gchar *file gtk_container_add (GTK_CONTAINER(scroll), textview); /* valid button */ + hbox = gtk_hbox_new(FALSE, 8); + gtk_widget_show(hbox); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 8); + + GtkWidget * b_default = gtk_button_new_with_label(_("Return to default")); + gtk_widget_show(b_default); + gtk_box_pack_start(GTK_BOX(hbox), b_default, FALSE, FALSE, 8); + button = gtk_button_new_from_stock(GTK_STOCK_APPLY); gtk_widget_show(button); gtk_widget_set_sensitive(button, FALSE); - gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 8); + gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 8); /* user_data */ user_data = g_malloc0(sizeof(user_param_type_wordlist)); @@ -246,6 +270,8 @@ GtkWidget *gc_board_config_wordlist(GcomprisBoardConf *config, const gchar *file G_CALLBACK(_textview_changed), (gpointer)user_data); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(_button_clicked), (gpointer)user_data); + g_signal_connect(G_OBJECT(b_default), "clicked", + G_CALLBACK(_return_clicked), (gpointer)user_data); _combo_lang_changed(GTK_COMBO_BOX(combo_lang), user_data); diff --git a/src/gcompris/cache.c b/src/gcompris/cache.c deleted file mode 100644 index 9271601..0000000 --- a/src/gcompris/cache.c +++ /dev/null @@ -1,203 +0,0 @@ -/* gcompris - gameutil_net.c - * - * Time-stamp: <2007-08-22 01:21:20 bruno> - * - * Copyright (C) 2006 Bruno Coudoin - * - * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>. - */ - -#include "gcompris.h" -#include "gc_core.h" -#include <string.h> - -/** \file Implementation of the cache functionality - * - */ - -/* The max size of the cache in bytes, - * 0 = NO LIMITS - * -1 = NO CACHE - */ -#ifdef USE_GNET -static int cache_max_size = 1000; - -static GHashTable *hash_cache = NULL; -#endif - -/** For debug only - */ -#ifdef USE_GNET -static void -_dump_cache(gchar *key, - gchar *value, - gpointer dummy) -{ - printf("cache %s = %s\n", key, value); -} - -static void dump_cache(void) -{ - g_hash_table_foreach(hash_cache, - (GHFunc) _dump_cache, - NULL); -} -#endif - -/** - * recursively parse the cache and fill up the hash with files there - */ -void _cache_init(const gchar *basedir, const gchar *currentdir) -{ -#ifdef USE_GNET - GcomprisProperties *properties = gc_prop_get(); - GDir *dir; - const gchar *file; - - if(!currentdir) - currentdir = basedir; - - dir = g_dir_open(currentdir, 0, NULL); - - printf(" _cache_init %s\n", currentdir); - - while((file = g_dir_read_name(dir))) - { - gchar *fullfile = g_strconcat(currentdir, "/", file, NULL); - printf(" processing file = %s\n", fullfile); - - if(g_file_test(fullfile, G_FILE_TEST_IS_DIR)) - { - _cache_init(basedir, fullfile); - } - else if(g_file_test(fullfile, G_FILE_TEST_IS_REGULAR)) - { - /* Strip file to get the KEY part out of it */ - printf(" Adding '%s' in the cache\n", fullfile); - g_hash_table_insert(hash_cache, - g_strconcat(properties->server, "/", - fullfile + strlen(basedir) + 1, - NULL), - g_strdup(fullfile)); - - } - g_free(fullfile); - } - - g_dir_close(dir); -#endif -} - -/** Initialize the cache system - * - * \param max_size: the max size in byte of the cache - * - */ -void gc_cache_init(int max_size) -{ -#ifdef USE_GNET - cache_max_size = max_size; - - /* No server defined, the cache is useless */ - if(!gc_prop_get()->server || - !gc_prop_get()->cache_dir) - return; - - hash_cache = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); - - printf("gc_cache_init\n"); - - /* try to create it */ - printf("Creating cache dir %s\n", gc_prop_get()->cache_dir); - if(g_mkdir_with_parents(gc_prop_get()->cache_dir, 0755)) - { - g_error("Failed to create the cache directory"); - } - printf(" opened top directory\n"); - /* Load the previous cache directory if any */ - _cache_init(gc_prop_get()->cache_dir, NULL); - - dump_cache(); -#endif -} - -/** End the cache system - * - */ -void gc_cache_end() -{ -#ifdef USE_GNET - - if(!hash_cache) - return; - - g_hash_table_destroy (hash_cache); - hash_cache = NULL; -#endif -} - - -#ifdef USE_GNET -static void -_clear_cache(gchar *key, - gchar *value, - gpointer dummy) -{ - printf("NOT IMPLEMENTED: Clearing chache %s:%s\n", key, value); -} -#endif - -/** Clear the cache. All files in the cache are removed - * - */ -void gc_cache_clear() -{ -#ifdef USE_GNET - g_hash_table_foreach(hash_cache, - (GHFunc) _clear_cache, - NULL); - -#endif -} - -/** Get a file from the cache based on it's URL - * - */ -gchar *gc_cache_get(gchar *url) -{ -#ifdef USE_GNET - return((char *)g_hash_table_lookup(hash_cache, url)); -#else - return NULL; -#endif -} - -/** Put and Get a file from the cache. The data in 'buffer' are saved in the - * cache under the name 'url'. A file is created and is returned. - * - * \param url: the url of the data in buffer - * \param buffer: the data for the url - * \param length: length of contents, or -1 if contents is a nul-terminated string - * - * \return a full path to the file in the cache - */ -gchar *gc_cache_insert(const gchar *url, const char *buffer, gssize length) -{ -#ifdef USE_GNET - /* Save the buffer in the cache */ - if(g_file_set_contents("TBD", buffer, length, NULL)) - g_hash_table_replace(hash_cache, (gpointer) url, (gpointer) "TBD"); -#endif - return("TBD"); -} diff --git a/src/gcompris/config.c b/src/gcompris/config.c index f8014b4..8cf07e2 100644 --- a/src/gcompris/config.c +++ b/src/gcompris/config.c @@ -629,7 +629,7 @@ set_locale_flag(gchar *locale) if(filename) { - pixmap = gc_net_load_pixmap(filename); + pixmap = gdk_pixbuf_new_from_file(filename,NULL); gnome_canvas_item_set (item_locale_flag, "pixbuf", pixmap, diff --git a/src/gcompris/dialog.c b/src/gcompris/dialog.c index 956b131..a1f9077 100644 --- a/src/gcompris/dialog.c +++ b/src/gcompris/dialog.c @@ -26,9 +26,6 @@ static GnomeCanvasGroup *rootDialogItem = NULL; static GnomeCanvasItem *itemDialogText = NULL; static gint item_event_ok(GnomeCanvasItem *item, GdkEvent *event, DialogBoxCallBack dbcb); -typedef void (*sighandler_t)(int); - - /* * Close the dialog box if it was open. It not, do nothing. */ diff --git a/src/gcompris/gameutil.c b/src/gcompris/gameutil.c index c5e0139..41c1b66 100644 --- a/src/gcompris/gameutil.c +++ b/src/gcompris/gameutil.c @@ -31,10 +31,6 @@ #include "gcompris.h" -extern GnomeCanvas *canvas; - -typedef void (*sighandler_t)(int); - /* GdkPixbuf RGBA C-Source image dump for a NULL image*/ #ifdef __SUNPRO_C #pragma align 4 (null_img) @@ -86,7 +82,7 @@ GdkPixbuf *gc_pixmap_load(const gchar *format, ...) filename = gc_file_find_absolute(pixmapfile); if(filename) - pixmap = gc_net_load_pixmap(filename); + pixmap = gdk_pixbuf_new_from_file(filename,NULL); if (!filename || !pixmap) { @@ -541,8 +537,7 @@ gc_file_find_absolute(const gchar *format, ...) va_end (args); /* Check it's already found */ - if( g_file_test (filename, G_FILE_TEST_EXISTS) - || gc_net_is_url(filename) ) + if( g_file_test (filename, G_FILE_TEST_EXISTS)) { return filename; } @@ -551,6 +546,9 @@ gc_file_find_absolute(const gchar *format, ...) * Search it on the file system */ + if(properties->server) + dir_to_search[i++] = ""; + dir_to_search[i++] = properties->user_dir; dir_to_search[i++] = properties->package_data_dir; dir_to_search[i++] = NULL; @@ -601,6 +599,7 @@ gc_file_find_absolute(const gchar *format, ...) g_free(filename2); goto FOUND; } + g_free(absolute_filename); /* Now check if this file is on the net */ if((absolute_filename = gc_net_get_url_from_file(filename2, NULL))) @@ -639,6 +638,35 @@ gc_file_find_absolute(const gchar *format, ...) return absolute_filename; } +gchar* +gc_file_find_absolute_writeable(const gchar *format, ...) +{ + gchar *filename, *absolute_filename, *dirname; + GcomprisProperties *prop; + va_list args; + + va_start (args, format); + filename = g_strdup_vprintf (format, args); + va_end (args); + + prop = gc_prop_get(); + absolute_filename = g_build_filename(prop->user_dir, filename,NULL); + g_free(filename); + dirname = g_path_get_dirname(absolute_filename); + if(!g_file_test(dirname, G_FILE_TEST_IS_DIR)) + { + if(g_mkdir_with_parents(dirname, 0755)) + { + g_free(absolute_filename); + absolute_filename=NULL; + } + } + g_free(dirname); + if(absolute_filename) + gc_cache_add(absolute_filename); + return absolute_filename; +} + /** Create a directory if needed. * * \param rootdir: the directory to create diff --git a/src/gcompris/gameutil.h b/src/gcompris/gameutil.h index aba9822..2f9f750 100644 --- a/src/gcompris/gameutil.h +++ b/src/gcompris/gameutil.h @@ -62,6 +62,7 @@ GnomeCanvasGroup *gc_difficulty_display(GnomeCanvasGroup *parent, double x, doub /* find the complete filename looking for the file everywhere (printf formatting supported) */ gchar *gc_file_find_absolute(const gchar *filename, ...); +gchar *gc_file_find_absolute_writeable(const gchar *filename, ...); int gc_util_create_rootdir (gchar *rootdir); void gc_activity_intro_play (GcomprisBoard *gcomprisBoard); diff --git a/src/gcompris/gc_core.h b/src/gcompris/gc_core.h index dbe98a9..e88d51d 100644 --- a/src/gcompris/gc_core.h +++ b/src/gcompris/gc_core.h @@ -48,11 +48,4 @@ void gc_mime_type_load(); /** log */ void gc_log_start (GcomprisBoard *gcomprisBoard); -/** cache */ -void gc_cache_init(int max_size); -void gc_cache_end(); -void gc_cache_clear(); -gchar *gc_cache_get(gchar *url); -gchar *gc_cache_insert(const gchar *url, const char *buffer, gssize length); - #endif diff --git a/src/gcompris/gc_net.c b/src/gcompris/gc_net.c index 55e820b..db840fb 100644 --- a/src/gcompris/gc_net.c +++ b/src/gcompris/gc_net.c @@ -20,10 +20,11 @@ #include "gc_net.h" #include "gc_core.h" - +#include <string.h> #ifdef USE_GNET #include <gnet.h> #endif +#include <glib/gstdio.h> /* FIXME: Should not be needed, a bug in gnet header ? */ gboolean gnet_http_get (const gchar *url, @@ -31,17 +32,33 @@ gboolean gnet_http_get (const gchar *url, gsize *length, guint *response); -#include <string.h> - #ifdef USE_GNET -static GSList *server_content_list = NULL; +static GHashTable *server_content = NULL; #define SUPPORT_OR_RETURN(rv) {if(!gc_prop_get()->server) return rv;} #else #define SUPPORT_OR_RETURN(rv) { return rv; } #endif +static void load_md5file(GHashTable *ht, gchar *content) +{ + gchar **lines, **keyval; + int i; -static inline int my_strcmp(gchar *a, gchar *b) { return strcmp( a, b); } + lines = g_strsplit(content, "\n", 0); + if(lines && lines[0]) + { + for(i=0; lines[i]; i++) + { + keyval = g_strsplit(lines[i], " ", 2); + if(keyval && keyval[0]) + { + g_hash_table_insert(ht, g_strdup(keyval[1]), g_strdup(keyval[0])); + } + g_strfreev(keyval); + } + } + g_strfreev(lines); +} /** Init the network library, must be called once before using it * @@ -69,15 +86,8 @@ void gc_net_init() if(gnet_http_get(url, &buf, &buflen, &response) && response == 200) { - char line[200]; - int i = 0; - /* Parse each line of the buffer and save it in 'server_content_list' */ - while( i < buflen) - { - sscanf(buf+i, "%s", (char *)&line); - server_content_list = g_slist_prepend(server_content_list, g_strdup(line)); - i+=strlen(line)+1; - } + server_content = g_hash_table_new(g_str_hash, g_str_equal); + load_md5file(server_content, buf); } else { @@ -92,81 +102,11 @@ void gc_net_init() #endif } -/** Load a pixmap localy or from the network - * - * \param pixmapfile : a full URL to the file to load as an image - * in case a local file is given, it will be loaded. - * \return a GdkPixbuf or NULL - */ -GdkPixbuf *gc_net_load_pixmap(const char *url) -{ - if(!gc_net_is_url(url)) - return(gdk_pixbuf_new_from_file (url, NULL)); - - SUPPORT_OR_RETURN(NULL); - -#ifdef USE_GNET - gchar *buf = NULL; - gsize buflen; - guint response; - - g_warning("Loading image from url '%s'", url); - - if(gnet_http_get(url, &buf, &buflen, &response) && response == 200) - { - GdkPixbuf *pixmap=NULL; - GdkPixbufLoader* loader; - loader = gdk_pixbuf_loader_new(); - gdk_pixbuf_loader_write(loader, (guchar *)buf, buflen, NULL); - g_free(buf); - gdk_pixbuf_loader_close(loader, NULL); - pixmap = gdk_pixbuf_loader_get_pixbuf(loader); - if(!pixmap) - g_warning("Loading image from url '%s' returned a null pointer", url); - - return(pixmap); - } - - g_free(buf); - return(NULL); - -#endif -} - -/** Load an xml file from the network - * - * \param xmlfile : a full URL to the xml file to load as an xmlDocPtr - * in case a local file is given, it will be loaded. - * \return a xmlDocPtr or NULL - */ -xmlDocPtr gc_net_load_xml(const char *url) +void gc_net_destroy(void) { - if(!gc_net_is_url(url)) - return(xmlParseFile(url)); - - SUPPORT_OR_RETURN(NULL); - -#ifdef USE_GNET - gchar *buf = NULL; - gsize buflen; - guint response; - - g_warning("Loading xml file from url '%s'", url); - - if(gnet_http_get(url, &buf, &buflen, &response) && response == 200) - { - xmlDocPtr doc = xmlParseMemory((const char *)buf, buflen); - g_free(buf); - if(!buf) - g_warning("Loading xml file from url '%s' returned a null pointer", url); - - return(doc); - } - - g_free(buf); - return(NULL); - -#endif + if(server_content) + g_hash_table_destroy(server_content); + server_content = NULL; } /** return an absolute URL if the given file is part of the file available on our server @@ -181,51 +121,65 @@ gc_net_get_url_from_file(const gchar *format, ...) #ifdef USE_GNET GcomprisProperties *properties = gc_prop_get(); - gchar *file, *url; + gchar *file, *cache=NULL, *value; va_list args; + gboolean cache_ok=FALSE; va_start (args, format); file = g_strdup_vprintf (format, args); va_end (args); - /* FIXME: In case the file does not starts with boards/, preprend it */ + g_warning("gc_net_get_url_from_file '%s'", file); + + value = g_hash_table_lookup(server_content, (gpointer) file); + if(value) { - if(strncmp(file, "boards/", 7)) - { - gchar *file2 = g_strconcat("boards/", file, NULL); - g_free(file); - file = file2; - } - } + cache = g_strconcat(properties->cache_dir, "/", file, NULL); + if(g_file_test(cache, G_FILE_TEST_IS_REGULAR)) + { + gchar * content; + gsize length; + GMD5 *md5cache, *md5serv; - g_warning("gc_net_get_url_from_file '%s'", file); - if(!g_slist_find_custom(server_content_list,(gconstpointer) file, (GCompareFunc) my_strcmp)) + /* calc md5 of cache file */ + g_file_get_contents(cache, &content, &length, NULL); + md5cache = gnet_md5_new(content, length); + g_free(content); + + md5serv = gnet_md5_new_string(value); + + cache_ok = gnet_md5_equal(md5serv, md5cache); + + gnet_md5_delete(md5serv); + gnet_md5_delete(md5cache); + } + if(cache_ok==0) { - g_free(file); - return NULL; + gchar *url; + gchar *buf = NULL; + gsize buflen; + guint response; + + url = g_strconcat(properties->server, "/", file, NULL); + if(gnet_http_get(url, &buf, &buflen, &response) && response == 200) + { + gchar *dirname; + + dirname = g_path_get_dirname(cache); + g_mkdir_with_parents(dirname, 0755); + g_free(dirname); + g_file_set_contents(cache, buf, buflen, NULL); + g_free(buf); + } } - url = g_strconcat(properties->server, "/", file, NULL); + } g_free(file); - g_warning("gc_net_get_url_from_file returns url '%s'", url); - return url; + return cache; #endif } -/** return TRUE if the url starts with http:// - * - * \param url: an url to check - * \return TRUE is the url starts with 'http://' - */ -gboolean -gc_net_is_url(const gchar *url) -{ - if( !url || strncmp(url, "http://", 7) ) - return FALSE; - - return TRUE; -} - +#if 0 /** return a glist with the content of the files in the given directory * * \param dir: the directory to scan @@ -255,3 +209,119 @@ GSList *gc_net_dir_read_name(const gchar* dir, const gchar *ext) return(filelist); #endif } +#endif + + +#define CONTENT_FILENAME "content.txt" + +static GHashTable *cache_content=NULL; + +void gc_cache_init(void) +{ + gchar *filename; + gchar *buf; + gsize buflen; + + cache_content = g_hash_table_new(g_str_hash, g_str_equal); + filename = gc_file_find_absolute_writeable(CONTENT_FILENAME); + + if(g_file_get_contents(filename, &buf, &buflen,NULL)) + { + load_md5file(cache_content, buf); + g_free(buf); + } + g_free(filename); +} + +static gchar *gc_cache_get_relative(gchar *filename) +{ + gchar *filename_content, *dirname; + + filename_content = gc_file_find_absolute_writeable(CONTENT_FILENAME); + dirname = g_path_get_dirname(filename_content); + if(g_str_has_prefix(filename, dirname)) + filename = filename + strlen(dirname) + 1; + g_free(filename_content); + g_free(dirname); + return filename; +} + +void gc_cache_add(gchar *filename) +{ + if(cache_content==NULL) + return; + if(g_str_has_suffix(filename, CONTENT_FILENAME)) + return; + + filename = gc_cache_get_relative(filename); + g_hash_table_insert(cache_content, g_strdup(filename), g_strdup("0")); +} + +void gc_cache_remove(gchar *filename) +{ + g_remove(filename); + filename = gc_cache_get_relative(filename); + g_hash_table_remove(cache_content, filename); +} + +struct _table_data +{ +FILE *pf; +gchar *path; +}; + +static void _table_foreach(gpointer key, gpointer value, gpointer user_data) +{ + struct _table_data *data = (struct _table_data*)user_data; + gchar * content, *filename; + gsize length; + GMD5 *md5; + + if(strcmp(value, "0")==0) + { + filename = g_build_filename(data->path, (gchar*)key, NULL); + if(g_file_get_contents(filename, &content, &length, NULL)) + { + md5 = gnet_md5_new(content, length); + value = gnet_md5_get_string(md5); + gnet_md5_delete(md5); + g_free(content); + } + g_free(filename); + } + if(strcmp(value, "0")) + { + fprintf(data->pf, "%s %s\n", (gchar*)value, (gchar*)key); + } +} + +void gc_cache_save(void) +{ + struct _table_data data; + FILE *pf; + gchar *filename; + + filename = gc_file_find_absolute_writeable(CONTENT_FILENAME); + pf = fopen(filename, "w"); + if(!pf) + { + g_warning("Couldn't save %s\n", filename); + return; + } + + data.pf = pf; + data.path = g_path_get_dirname(filename); + g_hash_table_foreach(cache_content, _table_foreach, &data); + + g_free(filename); + g_free(data.path); + fclose(pf); +} + +void gc_cache_destroy(void) +{ + gc_cache_save(); + g_hash_table_destroy(cache_content); + cache_content = NULL; +} + diff --git a/src/gcompris/gc_net.h b/src/gcompris/gc_net.h index 1ad858b..968af6e 100644 --- a/src/gcompris/gc_net.h +++ b/src/gcompris/gc_net.h @@ -34,10 +34,14 @@ #include "gcompris.h" void gc_net_init(); -GdkPixbuf *gc_net_load_pixmap(const char *url); -xmlDocPtr gc_net_load_xml(const char *url); gchar *gc_net_get_url_from_file(const gchar *format, ...); -gboolean gc_net_is_url(const char *url); GSList *gc_net_dir_read_name(const gchar* dir, const gchar *ext); +void gc_net_destroy(); + +void gc_cache_init(void); +void gc_cache_add(gchar *filename); +void gc_cache_remove(gchar *filename); +void gc_cache_save(void); +void gc_cache_destroy(void); #endif diff --git a/src/gcompris/gcompris.c b/src/gcompris/gcompris.c index d156eb1..b8355ff 100644 --- a/src/gcompris/gcompris.c +++ b/src/gcompris/gcompris.c @@ -676,7 +676,7 @@ static void setup_window () if(!icon_file) g_warning ("Couldn't find file %s !", icon_file); - icon_pixbuf = gc_net_load_pixmap(icon_file); + icon_pixbuf = gdk_pixbuf_new_from_file(icon_file,NULL); if (!icon_pixbuf) { g_warning ("Failed to load pixbuf file: %s\n", @@ -1071,6 +1071,8 @@ static void cleanup() xf86_vidmode_set_fullscreen(FALSE); #endif gc_menu_destroy(); + gc_net_destroy(); + gc_cache_destroy(); gc_prop_destroy(gc_prop_get()); } @@ -1891,6 +1893,10 @@ main (int argc, char *argv[]) single_instance_check(); + /* networking init */ + gc_net_init(); + gc_cache_init(); + gc_skin_load(properties->skin); if(properties->music || properties->fx) @@ -1899,12 +1905,6 @@ main (int argc, char *argv[]) /* Gdk-Pixbuf */ gdk_rgb_init(); - /* Cache init */ - gc_cache_init(-1); - - /* networking init */ - gc_net_init(); - setup_window (); gtk_widget_show_all (window); diff --git a/src/gcompris/images_selector.c b/src/gcompris/images_selector.c index 97b9513..3d5e751 100644 --- a/src/gcompris/images_selector.c +++ b/src/gcompris/images_selector.c @@ -276,8 +276,8 @@ gc_selector_images_start (GcomprisBoard *gcomprisBoard, gchar *dataset, g_free(dataseturl); dataseturl = g_strconcat("boards/", dataset, NULL); - - filelist = gc_net_dir_read_name(dataseturl, ".xml"); + /* TODO */ + filelist = NULL; //gc_net_dir_read_name(dataseturl, ".xml"); for (i = filelist; i != NULL; i = g_slist_next (i)) { @@ -821,7 +821,7 @@ read_xml_file(gchar *fname) g_return_val_if_fail(fname!=NULL, FALSE); - doc = gc_net_load_xml(fname); + doc = xmlParseFile(fname); /* in case something went wrong */ if(!doc) diff --git a/src/gcompris/skin.c b/src/gcompris/skin.c index f288eeb..a742ad0 100644 --- a/src/gcompris/skin.c +++ b/src/gcompris/skin.c @@ -270,7 +270,7 @@ skin_xml_load (gchar* skin) return; } - xmldoc = gc_net_load_xml(xmlfilename); + xmldoc = xmlParseFile(xmlfilename); g_free(xmlfilename); if(!xmldoc) diff --git a/src/gcompris/wordlist.c b/src/gcompris/wordlist.c index 8230e0b..1e4a061 100644 --- a/src/gcompris/wordlist.c +++ b/src/gcompris/wordlist.c @@ -384,7 +384,7 @@ void gc_wordlist_save(GcomprisWordlist *wordlist) } } - filename = gc_file_find_absolute(wordlist->filename); + filename = gc_file_find_absolute_writeable(wordlist->filename); if(filename) { if(xmlSaveFormatFileEnc(filename, doc, NULL, 1)<0) |