Commit 3971ee5e authored by Bruno Coudoin's avatar Bruno Coudoin

cleanup, removed deprecated gnet code.


svn path=/branches/gcomprixogoo/; revision=3518
parent fae6fbb2
......@@ -390,21 +390,7 @@ AC_ARG_ENABLE(sqlite,
with_sqlite="$enableval", with_sqlite="yes")
AC_MSG_RESULT($with_sqlite)
dnl GNET support (BROKEN)
dnl AC_MSG_CHECKING([wether we build with GNET (if not, networking will be disabled)])
dnl AC_ARG_ENABLE(gnet,
dnl AC_HELP_STRING(
dnl [--enable-gnet],
dnl [Turn on gnet (will let GCompris fetch content from a web server)]),
dnl with_gnet="$enableval", with_gnet="no")
dnl AC_MSG_RESULT($with_gnet)
dnl if test x$with_gnet = xyes; then
dnl PKG_CHECK_MODULES(GNET, gnet-2.0,, AC_MSG_ERROR([*** GNET not found!]))
dnl AC_DEFINE([USE_GNET], 1,[Networking is enabled])
dnl fi
dnl DBUS support
dnl DBUS support (Needed only for OLPC XO)
AC_MSG_CHECKING([wether we build with DBUS (needed only for OLPC SUGAR XO)])
AC_ARG_ENABLE(dbus,
AC_HELP_STRING(
......
......@@ -75,6 +75,10 @@ static void display_section (gchar *path);
static void display_welcome (MenuItems *menuitems);
static void create_panel(GooCanvasItem *parent);
static void create_top(GooCanvasItem *parent, gchar *path);
static GooCanvasItem *menu_difficulty_display(GooCanvasItem *parent,
double x, double y,
double ratio,
gint difficulty);
static double current_x = 0.0;
static double current_y = 0.0;
......@@ -476,11 +480,11 @@ static void menu_create_item(GooCanvasItem *parent, MenuItems *menuitems, Gcompr
if (board->difficulty != NULL)
{
difficulty = atoi(board->difficulty);
gc_difficulty_display(parent,
(double)current_x - pixmap_w/2 - 25,
(double)current_y - pixmap_h/2,
(double) 0.6,
difficulty);
menu_difficulty_display(parent,
(double)current_x - pixmap_w/2 - 25,
(double)current_y - pixmap_h/2,
(double) 0.6,
difficulty);
}
// display board availability due to sound voice not present
......@@ -903,3 +907,45 @@ static void
menu_config_stop()
{
}
/**
* Display the number of stars representing the difficulty level at the x,y location
* The stars are created in a group 'parent'
* The new group in which the stars are created is returned.
*/
static GooCanvasItem *
menu_difficulty_display(GooCanvasItem *parent,
double x, double y,
double ratio,
gint difficulty)
{
GdkPixbuf *pixmap = NULL;
GooCanvasItem *stars_group = NULL;
GooCanvasItem *item = NULL;
gchar *filename = NULL;
if(difficulty==0 || difficulty>6)
return NULL;
filename = g_strdup_printf("difficulty_star%d.png", difficulty);
pixmap = gc_skin_pixmap_load(filename);
g_free(filename);
if(!pixmap)
return NULL;
stars_group = goo_canvas_group_new (parent, NULL);
item = goo_canvas_image_new (stars_group,
pixmap,
0,
0,
NULL);
goo_canvas_item_translate(item, x, y);
goo_canvas_item_scale(item, ratio, ratio);
gdk_pixbuf_unref(pixmap);
return(stars_group);
}
......@@ -65,7 +65,6 @@ gcompris_SOURCES = \
board_config.h board_config.c \
bonus.c \
bonus.h \
cache.c \
config.c \
dbus.c \
dialog.c \
......
......@@ -42,7 +42,7 @@ typedef void (*sighandler_t)(int);
#ifdef __GNUC__
static const guint8 null_img[] __attribute__ ((__aligned__ (4))) =
#else
static const guint8 null_img[] =
static const guint8 null_img[] =
#endif
{ ""
/* Pixbuf magic (0x47646b50) */
......@@ -261,7 +261,7 @@ void gc_item_focus_init(GooCanvasItem *source_item,
goo_canvas_item_get_parent(target_item),
&bounds.x2, &bounds.y2);
highlight_item = g_object_get_data (G_OBJECT(target_item),
"highlight_item");
"highlight_item");
if(highlight_item)
{
......@@ -314,7 +314,7 @@ void gc_item_focus_init(GooCanvasItem *source_item,
* @param[in] target_itemis the same as the one passed to
* gc_item_focus_init()
*/
void gc_item_focus_remove(GooCanvasItem *source_item,
void gc_item_focus_remove(GooCanvasItem *source_item,
GooCanvasItem *target_item)
{
GooCanvasItem *highlight_item;
......@@ -327,10 +327,10 @@ void gc_item_focus_init(GooCanvasItem *source_item,
target_item);
highlight_item = g_object_get_data (G_OBJECT(target_item),
"highlight_item");
"highlight_item");
if(highlight_item)
goo_canvas_item_remove(highlight_item);
goo_canvas_item_remove(highlight_item);
}
/*
......@@ -374,8 +374,8 @@ void gc_item_absolute_move(GooCanvasItem *item, int x, int y)
/* ======================================= */
/** As gnome does not implement its own API : gc_item_rotate
we have to do it ourselves ....
rotation is clockwise if angle > 0
we have to do it ourselves ....
rotation is clockwise if angle > 0
*/
void
gc_item_rotate(GooCanvasItem *item, double angle) {
......@@ -390,7 +390,7 @@ gc_item_rotate(GooCanvasItem *item, double angle) {
we have to do it ourselves ....
IMPORTANT NOTE : This is designed for an item with "anchor" = GTK_ANCHOR_CENTER
rotation is clockwise if angle > 0
*/
*/
void
gc_item_rotate_relative(GooCanvasItem *item, double angle)
{
......@@ -494,60 +494,18 @@ gc_item_rotate_relative_with_center(GooCanvasItem *item, double angle, int x, in
goo_canvas_item_rotate(item, angle, x1+x, y1+y);
}
/**
* Display the number of stars representing the difficulty level at the x,y location
* The stars are created in a group 'parent'
* The new group in which the stars are created is returned.
* This is only usefull for the menu plugin and the configuration dialog box.
*/
GooCanvasItem *
gc_difficulty_display(GooCanvasItem *parent,
double x, double y,
double ratio,
gint difficulty)
{
GdkPixbuf *pixmap = NULL;
GooCanvasItem *stars_group = NULL;
GooCanvasItem *item = NULL;
gchar *filename = NULL;
if(difficulty==0 || difficulty>6)
return NULL;
filename = g_strdup_printf("difficulty_star%d.png", difficulty);
pixmap = gc_skin_pixmap_load(filename);
g_free(filename);
if(!pixmap)
return NULL;
stars_group = goo_canvas_group_new (parent, NULL);
item = goo_canvas_image_new (stars_group,
pixmap,
0,
0,
NULL);
goo_canvas_item_translate(item, x, y);
goo_canvas_item_scale(item, ratio, ratio);
gdk_pixbuf_unref(pixmap);
return(stars_group);
}
gchar *g_utf8_strndup(gchar* utf8text, gint n)
{
gchar* result;
gchar* result;
gint len = g_utf8_strlen(utf8text, -1);
gint len = g_utf8_strlen(utf8text, -1);
if( n < len && n > 0 )
len = n;
if( n < len && n > 0 )
len = n;
result = g_strndup(utf8text, g_utf8_offset_to_pointer(utf8text, len) - utf8text);
result = g_strndup(utf8text, g_utf8_offset_to_pointer(utf8text, len) - utf8text);
return result;
return result;
}
/** \brief search a given relative file in all gcompris dir it could be found
......@@ -577,11 +535,8 @@ 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) )
{
return filename;
}
if( g_file_test (filename, G_FILE_TEST_EXISTS) )
return filename;
/*
* Search it on the file system
......@@ -615,23 +570,14 @@ 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)))
{
g_strfreev(tmp);
g_free(filename2);
goto FOUND;
}
g_free(filename2);
g_free(absolute_filename);
g_free(filename2);
/* Try the short locale */
if(g_strv_length(tmp)>1)
{
locale[2] = '\0';
filename2 = g_strjoinv(locale, tmp);
g_strfreev(tmp);
g_free(absolute_filename);
absolute_filename = g_strdup_printf("%s/%s", dir_to_search[i], filename2);
if(g_file_test (absolute_filename, G_FILE_TEST_EXISTS))
{
......@@ -639,17 +585,11 @@ gc_file_find_absolute(const gchar *format, ...)
goto FOUND;
}
/* Now check if this file is on the net */
if((absolute_filename = gc_net_get_url_from_file(filename2, NULL)))
{
g_free(filename2);
goto FOUND;
}
g_free(filename2);
g_free(filename2);
}
else
g_strfreev(tmp);
else
g_strfreev(tmp);
}
else
{
......@@ -657,11 +597,6 @@ gc_file_find_absolute(const gchar *format, ...)
if(g_file_test (absolute_filename, G_FILE_TEST_EXISTS))
goto FOUND;
g_free(absolute_filename);
/* Now check if this file is on the net */
if((absolute_filename = gc_net_get_url_from_file(filename, NULL)))
goto FOUND;
g_free(absolute_filename);
}
i++;
......
......@@ -56,10 +56,6 @@ void gc_item_rotate_relative(GooCanvasItem *item, double angle);
void gc_item_rotate_with_center(GooCanvasItem *item, double angle, int x, int y);
void gc_item_rotate_relative_with_center(GooCanvasItem *item, double angle, int x, int y);
GooCanvasItem *gc_difficulty_display(GooCanvasItem *parent, double x, double y,
double ratio,
int difficulty);
/* find the complete filename looking for the file everywhere (printf formatting supported) */
gchar *gc_file_find_absolute(const gchar *filename, ...);
int gc_util_create_rootdir (gchar *rootdir);
......
......@@ -45,13 +45,6 @@ void gc_menu_destroy(void);
/** 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);
/** dbus */
void gc_dbus_init(gchar *sugarActivityId);
......
......@@ -19,139 +19,14 @@
#include "gc_net.h"
#include "gc_core.h"
#ifdef USE_GNET
#include <gnet.h>
#endif
/* FIXME: Should not be needed, a bug in gnet header ? */
gboolean gnet_http_get (const gchar *url,
gchar **buffer,
gsize *length,
guint *response);
#include <string.h>
#ifdef USE_GNET
static GSList *server_content_list = NULL;
#define SUPPORT_OR_RETURN(rv) {if(!gc_prop_get()->server) return rv;}
#else
#define SUPPORT_OR_RETURN(rv) { return rv; }
#endif
static inline int my_strcmp(gchar *a, gchar *b) { return strcmp( a, b); }
/** Init the network library, must be called once before using it
*
*/
void gc_net_init()
{
SUPPORT_OR_RETURN();
#ifdef USE_GNET
GcomprisProperties *properties = gc_prop_get();
gchar *url;
gchar *buf = NULL;
gsize buflen;
guint response;
gnet_init();
/*
* Get the content.txt file at the root of the http server and store it in a glist
* we then now exactly which files we have there
* warning, do not use gc_net_get_url_from_file() since we are in fact buildind the list of file
* for it.
*/
url = g_strdup_printf("%s/%s", properties->server, "/content.txt");
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;
}
}
else
{
/* We did not get the content list, disable network now */
g_free(properties->server);
properties->server = NULL;
g_warning("Failed to initialize networked GCompris because '%s' is not found", url);
}
g_free(buf);
g_free(url);
#endif
}
void
resize_pixbuf_cb(GdkPixbufLoader *loader,
gint width,
gint height,
gpointer user_data)
{
printf("resize_cb %d, %d\n", width, height);
gdk_pixbuf_loader_set_size(loader,
width*gc_zoom_factor_get(),
height*gc_zoom_factor_get());
}
/** Load a pixmap localy or from the network
/** Load a pixmap localy
*
* \param pixmapfile : a full URL to the file to load as an image
* in case a local file is given, it will be loaded.
* \param pixmapfile : a full path to the file to load as an image
* \return a GdkPixbuf or NULL
*/
GdkPixbuf *gc_net_load_pixmap(const char *url)
{
if(!gc_net_is_url(url))
{
gint width, height;
gdk_pixbuf_get_file_info(url, &width, &height);
//printf("gc_net_load_pixmap(%s) w=%d h=%d\n", url, width, height);
return(gdk_pixbuf_new_from_file (url, NULL));
// return(gdk_pixbuf_new_from_file_at_scale (url,
// width*gc_zoom_factor_get(),
// height*gc_zoom_factor_get(), TRUE, 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();
g_signal_connect(G_OBJECT(loader), "size-prepared",
G_CALLBACK(resize_pixbuf_cb), NULL);
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
return(gdk_pixbuf_new_from_file (url, NULL));
}
/** Load an xml file from the network
......@@ -162,117 +37,6 @@ GdkPixbuf *gc_net_load_pixmap(const char *url)
*/
xmlDocPtr gc_net_load_xml(const char *url)
{
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
}
/** return an absolute URL if the given file is part of the file available on our server
*
* \param file: the file to check
* \return: a newly allocated URL or NULL
*/
gchar *
gc_net_get_url_from_file(const gchar *format, ...)
{
SUPPORT_OR_RETURN(NULL);
#ifdef USE_GNET
GcomprisProperties *properties = gc_prop_get();
gchar *file, *url;
va_list args;
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 */
{
if(strncmp(file, "boards/", 7))
{
gchar *file2 = g_strconcat("boards/", file, NULL);
g_free(file);
file = file2;
}
}
g_warning("gc_net_get_url_from_file '%s'", file);
if(!g_slist_find_custom(server_content_list,(gconstpointer) file, (GCompareFunc) my_strcmp))
{
g_free(file);
return NULL;
}
url = g_strconcat(properties->server, "/", file, NULL);
g_free(file);
g_warning("gc_net_get_url_from_file returns url '%s'", url);
return url;
#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;
return(xmlParseFile(url));
}
/** return a glist with the content of the files in the given directory
*
* \param dir: the directory to scan
* \param ext: optional extention filter. e.g. ".xml" to get only *.xml files.
*
* \return: a new allocated glist that points to internal elements. Do not free the list
* data itself.
*/
GSList *gc_net_dir_read_name(const gchar* dir, const gchar *ext)
{
SUPPORT_OR_RETURN(NULL);
#ifdef USE_GNET
GSList *filelist = NULL;
GSList *i = NULL;
g_return_val_if_fail(dir!=NULL, NULL);
for (i = server_content_list; i != NULL; i = g_slist_next (i))
{
if(strncmp(dir, (gchar *)i->data, strlen(dir)) == 0)
if(ext == NULL ||
g_str_has_suffix ((gchar *)i->data, ext))
filelist = g_slist_prepend(filelist, i->data);
}
return(filelist);
#endif
}
......@@ -31,11 +31,7 @@
#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);
#endif
......@@ -138,9 +138,6 @@ static gchar *popt_user_dir = NULL;
static gint popt_experimental = FALSE;
static gint popt_no_quit = FALSE;
static gint popt_no_config = FALSE;
static gchar *popt_server = NULL;
static gint *popt_web_only = NULL;
static gchar *popt_cache_dir = NULL;
static gchar *popt_drag_mode = NULL;
static gchar *sugarBundleId = NULL;
static gchar *sugarActivityId = NULL;
......@@ -225,15 +222,6 @@ static GOptionEntry options[] = {
{"disable-config",'\0', 0, G_OPTION_ARG_NONE, &popt_no_config,
N_("Disable the config button"), NULL},
{"server", '\0', 0, G_OPTION_ARG_STRING, &popt_server,
N_("GCompris will get images, sounds and activity data from this server if not found locally."), NULL},
{"web-only", '\0', 0, G_OPTION_ARG_NONE, &popt_web_only,
N_("Only when --server is provided, disable check for local resource first."
" Data are always taken from the web server."), NULL},
{"cache-dir", '\0', 0, G_OPTION_ARG_STRING, &popt_cache_dir,
N_("In server mode, specify the cache directory used to avoid useless downloads."), NULL},
{"drag-mode", 'g', 0, G_OPTION_ARG_STRING, &popt_drag_mode,
N_("Global drag and drop mode: normal, 2clicks, both. Default mode is normal."), NULL},
......@@ -1628,27 +1616,6 @@ main (int argc, char *argv[])
properties->reread_menu = TRUE;
}
if (popt_server){
#ifdef USE_GNET
properties->server = g_strdup(popt_server);
#else
printf("The --server option cannot be used because GCompris has been compiled without network support!");
exit(1);
#endif
}
if(popt_web_only) {
g_free(properties->package_data_dir);
properties->package_data_dir = g_strdup("");
g_free(properties->system_icon_dir);
properties->system_icon_dir = g_strdup("");
}
if (popt_server){
properties->cache_dir = g_strdup(popt_cache_dir);
}
if (popt_drag_mode){
if (strcmp(popt_drag_mode, "default") == 0)
properties->drag_mode = GC_DRAG_MODE_GRAB;
......@@ -1716,18 +1683,8 @@ main (int argc, char *argv[])
rsvg_init();
/* Cache init */
gc_cache_init(-1);
/* networking init */
gc_net_init();
setup_window ();
// if (properties->fullscreen)
// gc_fullscreen_set(properties->fullscreen);
gtk_widget_show_all (window);
/* If a specific activity is selected, skeep the intro music */
......
......@@ -146,7 +146,7 @@ gc_prop_new ()
tmp = (GcomprisProperties *) malloc (sizeof (GcomprisProperties));
tmp->music = 1;
tmp->fx = 1;
tmp->fullscreen = 0;
tmp->fullscreen = 1;
tmp->timer = 1;
tmp->skin = g_strdup("babytoy");
tmp->key = g_strdup("default");
......@@ -165,8 +165,6 @@ gc_prop_new ()
tmp->reread_menu = FALSE;
tmp->experimental = FALSE;
tmp->server = NULL;
tmp->package_data_dir = NULL;
tmp->package_skin_dir = NULL;
tmp->package_locale_dir = NULL;
......@@ -529,7 +527,6 @@ gc_prop_destroy (GcomprisProperties *props)
g_free(props->database);
g_free(props->config_dir);
g_free(props->user_dir);
g_free(props->server);
g_free(props->root_menu);
g_free(props);
}
......
......@@ -62,8 +62,7 @@ typedef struct {
/* this are set by gc_im_init() */
GtkIMContext *context;
gchar *default_context;
gint experimental;
gchar *server;
gint experimental;
gint drag_mode;
} GcomprisProperties;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment