gcompris r3720 - in trunk: . src/boards src/boards/python/admin src/gcompris
- From: bcoudoin svn gnome org
- To: svn-commits-list gnome org
- Subject: gcompris r3720 - in trunk: . src/boards src/boards/python/admin src/gcompris
- Date: Thu, 5 Feb 2009 00:25:57 +0000 (UTC)
Author: bcoudoin
Date: Thu Feb 5 00:25:57 2009
New Revision: 3720
URL: http://svn.gnome.org/viewvc/gcompris?rev=3720&view=rev
Log:
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)
Removed:
trunk/src/gcompris/cache.c
Modified:
trunk/ChangeLog
trunk/configure.in
trunk/src/boards/advanced_colors.c
trunk/src/boards/imageid.c
trunk/src/boards/missingletter.c
trunk/src/boards/python/admin/board_list.py
trunk/src/boards/read_colors.c
trunk/src/boards/shapegame.c
trunk/src/boards/superbrain.c
trunk/src/boards/wordprocessor.c
trunk/src/gcompris/Makefile.am
trunk/src/gcompris/board_config_wordlist.c
trunk/src/gcompris/config.c
trunk/src/gcompris/dialog.c
trunk/src/gcompris/gameutil.c
trunk/src/gcompris/gameutil.h
trunk/src/gcompris/gc_core.h
trunk/src/gcompris/gc_net.c
trunk/src/gcompris/gc_net.h
trunk/src/gcompris/gcompris.c
trunk/src/gcompris/images_selector.c
trunk/src/gcompris/skin.c
trunk/src/gcompris/wordlist.c
Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in (original)
+++ trunk/configure.in Thu Feb 5 00:25:57 2009
@@ -366,6 +366,20 @@
AC_MSG_WARN(Couldn't find texi2html usualy in the tetex package, please install it)
fi
+
+dnl GNET support
+AC_MSG_CHECKING([wether we build with GNET (if not, networking will be disabled)])
+AC_ARG_ENABLE(gnet,
+ AC_HELP_STRING(
+ [--disable-gnet],
+ [Turn on gnet (will let GCompris fetch content from a web server)]),
+ with_gnet="$enableval", with_gnet="no")
+AC_MSG_RESULT($with_gnet)
+
+if test x$with_gnet = xyes; then
+ PKG_CHECK_MODULES(GNET, gnet-2.0,, AC_MSG_ERROR([*** GNET not found!]))
+ AC_DEFINE([USE_GNET], 1,[Networking is enabled])
+fi
dnl SQLITE support
AC_MSG_CHECKING([wether we build with SQLITE (if not profile will be disabled)])
@@ -569,6 +583,7 @@
echo "SQLITE database (--enable-sqlite) = $with_sqlite (profiles depend on this)"
+echo "GNET Networking (--enable-gnet) = $with_gnet (networking depends on this)"
echo "BINRELOC (--enable-binreloc) = $br_cv_binreloc"
echo "NSBundle (--enable-nsbundle) = $nsbundle"
Modified: trunk/src/boards/advanced_colors.c
==============================================================================
--- trunk/src/boards/advanced_colors.c (original)
+++ trunk/src/boards/advanced_colors.c Thu Feb 5 00:25:57 2009
@@ -520,7 +520,7 @@
g_return_val_if_fail(fname!=NULL,FALSE);
/* parse the new file and put the result into newdoc */
- doc = gc_net_load_xml(fname);
+ doc = xmlParseFile(fname);
/* in case something went wrong */
if(!doc)
Modified: trunk/src/boards/imageid.c
==============================================================================
--- trunk/src/boards/imageid.c (original)
+++ trunk/src/boards/imageid.c Thu Feb 5 00:25:57 2009
@@ -632,7 +632,7 @@
g_return_val_if_fail(fname!=NULL,FALSE);
/* parse the new file and put the result into newdoc */
- doc = gc_net_load_xml(fname);
+ doc = xmlParseFile(fname);
/* in case something went wrong */
if(!doc)
Modified: trunk/src/boards/missingletter.c
==============================================================================
--- trunk/src/boards/missingletter.c (original)
+++ trunk/src/boards/missingletter.c Thu Feb 5 00:25:57 2009
@@ -653,7 +653,7 @@
g_return_val_if_fail(fname!=NULL,FALSE);
/* parse the new file and put the result into newdoc */
- doc = gc_net_load_xml(fname);
+ doc = xmlParseFile(fname);
/* in case something went wrong */
if(!doc)
Modified: trunk/src/boards/python/admin/board_list.py
==============================================================================
--- trunk/src/boards/python/admin/board_list.py (original)
+++ trunk/src/boards/python/admin/board_list.py Thu Feb 5 00:25:57 2009
@@ -166,13 +166,6 @@
self.button_locales_sound.show()
box3.pack_end(self.button_locales_sound, False, False, 0)
- self.button_wordlist = gtk.Button(_('Wordlist'))
- self.button_wordlist.connect("clicked", self.wordlist)
- self.button_wordlist.show()
- box3.pack_end(self.button_wordlist, False, False, 0)
- #not ready yet
- self.button_wordlist.set_sensitive(False)
-
self.button_login = gtk.Button(_('Login'))
self.button_login.connect("clicked", self.login_configure)
self.button_login.show()
Modified: trunk/src/boards/read_colors.c
==============================================================================
--- trunk/src/boards/read_colors.c (original)
+++ trunk/src/boards/read_colors.c Thu Feb 5 00:25:57 2009
@@ -472,7 +472,7 @@
g_return_val_if_fail(fname!=NULL,FALSE);
/* parse the new file and put the result into newdoc */
- doc = gc_net_load_xml(fname);
+ doc = xmlParseFile(fname);
/* in case something went wrong */
if(!doc)
Modified: trunk/src/boards/shapegame.c
==============================================================================
--- trunk/src/boards/shapegame.c (original)
+++ trunk/src/boards/shapegame.c Thu Feb 5 00:25:57 2009
@@ -1746,7 +1746,7 @@
g_return_val_if_fail(fname!=NULL,FALSE);
/* parse the new file and put the result into newdoc */
- doc = gc_net_load_xml(fname);
+ doc = xmlParseFile(fname);
/* in case something went wrong */
if(!doc)
return FALSE;
Modified: trunk/src/boards/superbrain.c
==============================================================================
--- trunk/src/boards/superbrain.c (original)
+++ trunk/src/boards/superbrain.c Thu Feb 5 00:25:57 2009
@@ -617,6 +617,10 @@
current_y_position -= Y_STEP;
+ GList *l;
+ for(l=listPieces; l; l= l->next)
+ g_free(l->data);
+
g_list_free(listPieces);
superbrain_create_item(boardRootItem);
Modified: trunk/src/boards/wordprocessor.c
==============================================================================
--- trunk/src/boards/wordprocessor.c (original)
+++ trunk/src/boards/wordprocessor.c Thu Feb 5 00:25:57 2009
@@ -1026,7 +1026,7 @@
GtkTextIter iter_start, iter_end;
/* parse the new file and put the result into newdoc */
- doc = gc_net_load_xml(file);
+ doc = xmlParseFile(file);
/* in case something went wrong */
if(!doc)
Modified: trunk/src/gcompris/Makefile.am
==============================================================================
--- trunk/src/gcompris/Makefile.am (original)
+++ trunk/src/gcompris/Makefile.am Thu Feb 5 00:25:57 2009
@@ -76,7 +76,6 @@
board_config.h board_config.c \
bonus.c \
bonus.h \
- cache.c \
config.c \
dialog.c \
drag.c \
Modified: trunk/src/gcompris/board_config_wordlist.c
==============================================================================
--- trunk/src/gcompris/board_config_wordlist.c (original)
+++ trunk/src/gcompris/board_config_wordlist.c Thu Feb 5 00:25:57 2009
@@ -118,6 +118,22 @@
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 @@
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 @@
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);
Modified: trunk/src/gcompris/config.c
==============================================================================
--- trunk/src/gcompris/config.c (original)
+++ trunk/src/gcompris/config.c Thu Feb 5 00:25:57 2009
@@ -629,7 +629,7 @@
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,
Modified: trunk/src/gcompris/dialog.c
==============================================================================
--- trunk/src/gcompris/dialog.c (original)
+++ trunk/src/gcompris/dialog.c Thu Feb 5 00:25:57 2009
@@ -26,9 +26,6 @@
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.
*/
Modified: trunk/src/gcompris/gameutil.c
==============================================================================
--- trunk/src/gcompris/gameutil.c (original)
+++ trunk/src/gcompris/gameutil.c Thu Feb 5 00:25:57 2009
@@ -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 @@
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 @@
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 @@
* 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 @@
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 @@
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
Modified: trunk/src/gcompris/gameutil.h
==============================================================================
--- trunk/src/gcompris/gameutil.h (original)
+++ trunk/src/gcompris/gameutil.h Thu Feb 5 00:25:57 2009
@@ -62,6 +62,7 @@
/* 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);
Modified: trunk/src/gcompris/gc_core.h
==============================================================================
--- trunk/src/gcompris/gc_core.h (original)
+++ trunk/src/gcompris/gc_core.h Thu Feb 5 00:25:57 2009
@@ -48,11 +48,4 @@
/** 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
Modified: trunk/src/gcompris/gc_net.c
==============================================================================
--- trunk/src/gcompris/gc_net.c (original)
+++ trunk/src/gcompris/gc_net.c Thu Feb 5 00:25:57 2009
@@ -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 @@
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 @@
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 @@
#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 @@
#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 @@
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;
+}
+
Modified: trunk/src/gcompris/gc_net.h
==============================================================================
--- trunk/src/gcompris/gc_net.h (original)
+++ trunk/src/gcompris/gc_net.h Thu Feb 5 00:25:57 2009
@@ -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
Modified: trunk/src/gcompris/gcompris.c
==============================================================================
--- trunk/src/gcompris/gcompris.c (original)
+++ trunk/src/gcompris/gcompris.c Thu Feb 5 00:25:57 2009
@@ -676,7 +676,7 @@
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 @@
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 @@
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 @@
/* Gdk-Pixbuf */
gdk_rgb_init();
- /* Cache init */
- gc_cache_init(-1);
-
- /* networking init */
- gc_net_init();
-
setup_window ();
gtk_widget_show_all (window);
Modified: trunk/src/gcompris/images_selector.c
==============================================================================
--- trunk/src/gcompris/images_selector.c (original)
+++ trunk/src/gcompris/images_selector.c Thu Feb 5 00:25:57 2009
@@ -276,8 +276,8 @@
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 @@
g_return_val_if_fail(fname!=NULL, FALSE);
- doc = gc_net_load_xml(fname);
+ doc = xmlParseFile(fname);
/* in case something went wrong */
if(!doc)
Modified: trunk/src/gcompris/skin.c
==============================================================================
--- trunk/src/gcompris/skin.c (original)
+++ trunk/src/gcompris/skin.c Thu Feb 5 00:25:57 2009
@@ -270,7 +270,7 @@
return;
}
- xmldoc = gc_net_load_xml(xmlfilename);
+ xmldoc = xmlParseFile(xmlfilename);
g_free(xmlfilename);
if(!xmldoc)
Modified: trunk/src/gcompris/wordlist.c
==============================================================================
--- trunk/src/gcompris/wordlist.c (original)
+++ trunk/src/gcompris/wordlist.c Thu Feb 5 00:25:57 2009
@@ -384,7 +384,7 @@
}
}
- filename = gc_file_find_absolute(wordlist->filename);
+ filename = gc_file_find_absolute_writeable(wordlist->filename);
if(filename)
{
if(xmlSaveFormatFileEnc(filename, doc, NULL, 1)<0)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]