/* * Load a desktop style data file and create the levels array */ static void load_datafile() { gchar *filename = gc_file_find_absolute("click_on_letter/default-$LOCALE.desktop"); clear_levels(); // Reset the alphabet to match the current locale alphabet = get_alphabet(); /* create level array */ levels = g_array_sized_new (FALSE, FALSE, sizeof (Level), 10); if ( filename ) { load_desktop_datafile(filename); } else if ( ! filename && alphabet[0] == 'a') { /* This is a LATIN based language, let's fallback to english */ filename = gc_file_find_absolute("click_on_letter/default-en.desktop"); if( filename ) load_desktop_datafile(filename); else // Should not happens but in case let's create the level for LATIN create_level_from_alphabet(alphabet); } else { // No data file and no latin character set create_level_from_alphabet(alphabet); } g_free(filename); }
void selection_changed (GtkTreeSelection *selection,gpointer data) { _config_missing *u = (_config_missing*)data; gchar *question, *answer, *choice, *pixmap, *pixfile; GtkTreeModel *model; GtkTreeIter iter; if (gtk_tree_selection_get_selected (selection, &model, &iter)) { gtk_tree_model_get (model, &iter, QUESTION_COLUMN, &question, ANSWER_COLUMN, &answer, CHOICE_COLUMN, &choice, PIXMAP_COLUMN, &pixmap, -1); u->inprocess = TRUE; gtk_entry_set_text(u->question, question); gtk_entry_set_text(u->answer, answer); gtk_entry_set_text(u->choice, choice); pixfile = gc_file_find_absolute(pixmap); gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(u->pixmap), pixfile); u->inprocess = FALSE; g_free(question); g_free(answer); g_free(choice); g_free(pixmap); g_free(pixfile); } }
static void display_sponsor(GooCanvasItem *rootitem) { GooCanvasItem *item; GdkPixbuf *pixmap = NULL; /* Location for a potential sponsor */ gchar *sponsor_image = gc_file_find_absolute("sponsor.png"); if(sponsor_image) { pixmap = gc_pixmap_load("sponsor.png"); item = goo_canvas_image_new (rootitem, pixmap, 0.0, 0.0, NULL); SET_ITEM_LOCATION_CENTER(item, display_x + display_w/2.0, display_y + display_h/3.0 + 150); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif g_free(sponsor_image); } }
/* * return TRUE if the sound is found and the audio is activated * FALSE if the sound was not played */ static gboolean _repeat () { gboolean retval = FALSE; gchar *str1 = NULL; gchar *right_letter_ogg = NULL; GcomprisProperties *properties = gc_prop_get(); if( !properties->fx ) return FALSE; str1 = gc_sound_alphabet(right_letter); right_letter_ogg = g_strdup_printf("voices/$LOCALE/alphabet/%s", str1); g_free(str1); if(right_letter_ogg) { /* Let's check the file exist to be abble to return FALSE */ gchar *absolute_file = gc_file_find_absolute(right_letter_ogg, NULL); if (absolute_file) { gc_sound_play_ogg_cb(right_letter_ogg, sound_played); g_free(absolute_file); retval = TRUE; } } g_free(right_letter_ogg); return retval; }
static void init_xml(guint level) { gchar *filename; filename = gc_file_find_absolute("%s/board%d.xml", gcomprisBoard->boarddir, level); g_assert(read_xml_file(filename)== TRUE); g_free(filename); }
/* =================================== * XML stuff * Ref : shapegame.c * ==================================== */ static void init_xml(guint level) { gchar *filename; if(board_list) { missing_destroy_board_list(board_list); board_list = NULL; } filename = gc_file_find_absolute("%s/board%d.xml", gcomprisBoard_missing->boarddir, level); missing_read_xml_file(filename, &board_list); gcomprisBoard_missing->number_of_sublevel = g_list_length(board_list); g_free(filename); }
static void _init(GcomprisBoard *agcomprisBoard) { gchar * filename; gcomprisBoard_missing->level=1; /* Calculate the maxlevel based on the available data file for this board */ gcomprisBoard_missing->maxlevel = 1; while((filename = gc_file_find_absolute("%s/board%d.xml", gcomprisBoard_missing->boarddir, ++gcomprisBoard_missing->maxlevel))) g_free(filename); gcomprisBoard_missing->maxlevel--; gcomprisBoard_missing->sublevel=1; gcomprisBoard_missing->number_of_sublevel=G_MAXINT; }
static guint sounds_are_fine() { char *letter_str; char *str2; GcomprisProperties *properties = gc_prop_get(); gchar *text_mode_str = _("This activity will be played with questions displayed as text" " instead of being spoken"); if(!properties->fx) { gchar *msg = g_strconcat( _("Error: this activity cannot be played with the\n" "sound effects disabled.\nGo to the configuration" " dialog to\nenable the sound"), "\n", text_mode_str, NULL); gc_dialog(msg, click_on_letter_next_level); g_free(msg); return(OK_NO_INIT); } alphabet = get_alphabet(); gchar *letter = g_new0(gchar, 8); g_unichar_to_utf8(g_utf8_get_char(alphabet), letter); letter_str = gc_sound_alphabet(letter); g_free(letter); str2 = gc_file_find_absolute("voices/$LOCALE/alphabet/%s", letter_str); g_free(letter_str); if (!str2) { gchar *msg2 = g_strdup_printf( _("Error: this activity requires that you first install\nthe packages with GCompris voices for the %s locale."), gc_locale_get_name( gc_locale_get() ) ); gchar *msg = g_strconcat(msg2, "\n", text_mode_str, NULL); g_free(msg2); gc_dialog(msg, click_on_letter_next_level); g_free(msg); return (OK_NO_INIT); } return(OK); }
static void start_board (GcomprisBoard *agcomprisBoard) { gchar *filename = NULL; GHashTable *config = gc_db_get_board_conf(); gc_locale_set(g_hash_table_lookup( config, "locale")); g_hash_table_destroy(config); if(agcomprisBoard!=NULL) { gcomprisBoard=agcomprisBoard; gc_set_background(goo_canvas_get_root_item(gcomprisBoard->canvas), "imageid/imageid-bg.svgz"); gcomprisBoard->level=1; gcomprisBoard->sublevel=1; /* Calculate the maxlevel based on the available data file for this board */ gcomprisBoard->maxlevel=1; while( (filename = gc_file_find_absolute("%s/board%d.xml", gcomprisBoard->boarddir, gcomprisBoard->maxlevel++, NULL)) ) { g_free(filename); } g_free(filename); gcomprisBoard->maxlevel -= 2; gc_bar_set(GC_BAR_CONFIG|GC_BAR_LEVEL); imageid_next_level(); gamewon = FALSE; pause_board(FALSE); } }
static void level_changed(GtkComboBox *combo, gpointer data) { _config_missing *u = (_config_missing*)data; GtkListStore *ls; GtkTreeIter iter; gchar *filename; GList *list=NULL, *l; int level, result; level = gtk_combo_box_get_active(u->combo_level)+1; if(level==0) return; if(u->changed) { GtkWidget *dialog; dialog = gtk_dialog_new_with_buttons("Save changes ?", NULL, GTK_DIALOG_MODAL, GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); result = gtk_dialog_run(GTK_DIALOG(dialog)); switch(result) { case GTK_RESPONSE_ACCEPT: save_clicked(NULL, data); break; default: u->changed=FALSE; break; } gtk_widget_destroy (dialog); } ls = GTK_LIST_STORE(gtk_tree_view_get_model(u->view)); filename = gc_file_find_absolute("%s/board%d.xml", gcomprisBoard_missing->boarddir, level); missing_read_xml_file(filename,&list); g_free(filename); gtk_list_store_clear(ls); for(l=list; l; l=l->next) { Board *b = l->data; gchar *pixfile = gc_file_find_absolute(b->pixmapfile); GdkPixbuf *pixbuf; gchar tmp[MAX_PROPOSAL+1]; int i = 0; pixbuf = gdk_pixbuf_new_from_file_at_size(pixfile, ICON_SIZE, ICON_SIZE, NULL); tmp[0] = '\0'; while(b->choices[i]) { g_strlcat(tmp, b->choices[i], MAX_PROPOSAL); i++; } gtk_list_store_append(ls, &iter); gtk_list_store_set(ls, &iter, QUESTION_COLUMN, b->question, ANSWER_COLUMN, b->answer, CHOICE_COLUMN, tmp, PIXMAP_COLUMN, b->pixmapfile, PIXBUF_COLUMN, pixbuf, -1); g_free(pixfile); g_object_unref(pixbuf); } missing_destroy_board_list(list); }
/** Load a wordlist formatted xml file. It contains a list of words. * * The xml file format must be like this: * <?xml version="1.0" encoding="UTF-8" standalone="no"?> * <GCompris> * <Wordlist name="default-da" description="Default Danish" locale="da"> * <level value="1"> * word1 * word2 * ... * </level> * <level value="2"> * word3 * word4 * ... * </level> * <level value="3"> * ... * </level> * </Wordlist> * </GCompris> * * * \param format: the xml file to load (ex: wordsgame/default-fr.xml) * If format contains $LOCALE, it will be first replaced by the current long locale * and if not found the short locale name. It support printf formating. * \param ...: additional params for the format (printf like) * * \return a new GcomprisWordlist or NULL */ GcomprisWordlist *gc_wordlist_get_from_file(const gchar *format, ...) { va_list args; gchar* xmlfilename; gchar* filename; xmlDocPtr xmldoc; xmlNodePtr wlNode; xmlNodePtr node; xmlNodePtr wordsNode; guint level; GcomprisWordlist *wordlist; xmlChar *text; if (!format) return NULL; va_start (args, format); filename = g_strdup_vprintf (format, args); va_end (args); xmlfilename = gc_file_find_absolute(filename); /* if the file doesn't exist */ if(!xmlfilename) { g_warning("Couldn't find file %s !", filename); g_free(filename); return NULL; } g_warning("Wordlist found %s\n", xmlfilename); xmldoc = xmlParseFile(xmlfilename); if(!xmldoc){ g_warning("Couldn't parse file %s !", xmlfilename); g_free(filename); g_free(xmlfilename); return NULL; } g_free(xmlfilename); if(/* if there is no root element */ !xmldoc->children || /* if it doesn't have a name */ !xmldoc->children->name || /* if it isn't a GCompris node */ g_strcasecmp((gchar *)xmldoc->children->name,(gchar *)"GCompris")!=0) { g_warning("No Gcompris node"); xmlFreeDoc(xmldoc); g_free(filename); return NULL; } /* there is only one element child */ wlNode = xmldoc->children->children; while((wlNode!=NULL)&&(wlNode->type!=XML_ELEMENT_NODE)) wlNode = wlNode->next; if((wlNode==NULL)|| g_strcasecmp((gchar *)wlNode->name,"Wordlist")!=0) { g_warning("No wordlist node %s", (wlNode == NULL) ? (gchar *)wlNode->name : "NULL node"); xmlFreeDoc(xmldoc); g_free(filename); return NULL; } /* ok, we can process the wordlist */ wordlist = g_malloc0(sizeof(GcomprisWordlist)); wordlist->filename = filename; /* Get name */ text = xmlGetProp ( wlNode, (const xmlChar *) "name"); if (text) { wordlist->name = g_strdup ((gchar *) text); xmlFree (text); } /* Get description */ text = xmlGetProp ( wlNode, (const xmlChar *) "description"); if (text) { wordlist->description = g_strdup ((gchar *) text); xmlFree (text); } /* Get locale */ text = xmlGetProp ( wlNode, (const xmlChar *) "locale"); if (text) { wordlist->locale = g_strdup ((gchar *) text); xmlFree (text); } /* Levels loop */ node = wlNode->children; while((node!=NULL)) { if (node->type!=XML_ELEMENT_NODE){ node = node->next; continue; } if (strcmp((char *)node->name,"level")!=0){ g_warning("Parsing %s error", filename); break; } wordsNode = node->children; if (wordsNode->type!=XML_TEXT_NODE){ g_warning("Parsing %s error", filename); break; } level=-1; text = xmlGetProp ( node, (const xmlChar *) "value"); if (text) { level = atoi((gchar *) text); xmlFree (text); } text = xmlNodeGetContent ( wordsNode); gc_wordlist_set_wordlist(wordlist, level, (const gchar*)text); xmlFree(text); node = node->next; } xmlFreeDoc(xmldoc); return wordlist; }
/* * Do all the bar display and register the events */ void gc_about_start () { GdkPixbuf *pixmap = NULL; gdouble y_start = 0; gint y = 0; GooCanvasItem *item; static gchar *content = N_("Author: Bruno Coudoin\n" "Contribution: Pascal Georges, Jose Jorge, Yves Combe\n" "Graphics: Renaud Blanchard, Franck Doucet\n" "Intro Music: Djilali Sebihi\n" "Background Music: Rico Da Halvarez\n" ); /* TRANSLATORS: Replace this string with your names, one name per line. */ gchar *translators = _("translator_credits"); /* Pause the board */ gc_board_pause(TRUE); if(rootitem) { gc_about_stop(); return; } gc_bar_hide (TRUE); rootitem = goo_canvas_group_new (goo_canvas_get_root_item(gc_get_canvas()), NULL); item = goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", "#DIALOG", "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); GooCanvasBounds bounds; goo_canvas_item_get_bounds(item, &bounds); y_start = bounds.y1; y = bounds.y2 - 26; goo_canvas_text_new (rootitem, _("About GCompris"), (gdouble) BOARDWIDTH/2, (gdouble) y_start + 35, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_title, "fill-color-rgba", gc_skin_color_title, NULL); goo_canvas_text_new (rootitem, _("GCompris Home Page: http://gcompris.net"), (gdouble) BOARDWIDTH/2, (gdouble) y_start + 58, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_color_subtitle, NULL); gchar *text = g_strdup_printf("%s\n%s\n%s", _(content), _("Translators:"), translators); y_start += 100; goo_canvas_text_new (rootitem, text, (gdouble) BOARDWIDTH/2-320, (gdouble) y_start, -1, GTK_ANCHOR_NORTH_WEST, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_color_content, NULL); g_free(text); // Version item = \ goo_canvas_text_new (rootitem, "GCompris V" VERSION, (gdouble) 0, (gdouble) y_start, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_title, "fill-color-rgba", gc_skin_color_subtitle, NULL); goo_canvas_item_get_bounds(item, &bounds); gdouble x = BOARDWIDTH - (bounds.x2 - bounds.x1) - 20; g_object_set( (GooCanvasItem*)item, "x", x, NULL); y_start += 180; /* Location for a potential sponsor */ gchar *sponsor_image = gc_file_find_absolute("sponsor_about.png"); if(sponsor_image) { pixmap = gc_pixmap_load("sponsor_about.png"); goo_canvas_text_new (rootitem, "Version parrainée par", (gdouble) BOARDWIDTH*0.75, (gdouble) y_start - gdk_pixbuf_get_height(pixmap), -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_color_content, NULL); item = goo_canvas_image_new (rootitem, pixmap, (gdouble) (BOARDWIDTH*0.75) - gdk_pixbuf_get_width(pixmap)/2, (gdouble) y_start - gdk_pixbuf_get_height(pixmap) + 15, NULL); #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(pixmap); #else g_object_unref(pixmap); #endif g_free(sponsor_image); } else { // Default sponsor is the FSF RsvgHandle *svg_handle; svg_handle = gc_skin_rsvg_get(); item = goo_canvas_svg_new (rootitem, svg_handle, "svg-id", "#FSF_LOGO", "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); goo_canvas_item_get_bounds(item, &bounds); SET_ITEM_LOCATION_CENTER(item, (BOARDWIDTH*0.75), y_start + 50 - (bounds.y2 - bounds.y1) / 2); item = goo_canvas_text_new (rootitem, "Free Software Foundation\nhttp://www.fsf.org", (gdouble) (BOARDWIDTH*0.75), (gdouble) y_start + 80, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_color_subtitle, NULL); } // Copyright item = goo_canvas_text_new (rootitem, "Copyright 2000-2013 Bruno Coudoin and Others", (gdouble) BOARDWIDTH/2, (gdouble) y - 55, -1, GTK_ANCHOR_CENTER, "font", gc_skin_font_content, "fill-color-rgba", gc_skin_color_content, NULL); // License item = goo_canvas_text_new (rootitem, _("This software is a GNU Package and is released under the GNU General Public License"), (gdouble) BOARDWIDTH/2, (gdouble) y - 40, -1, GTK_ANCHOR_CENTER, "font", "sans 8", "fill-color-rgba", gc_skin_color_content, NULL); // OK gc_util_button_text_svg(rootitem, BOARDWIDTH * 0.5, y, "#BUTTON_TEXT", _("OK"), (GCallback) item_event_ok, "ok"); is_displayed = TRUE; }
static void menu_create_item(GooCanvasItem *parent, MenuItems *menuitems, GcomprisBoard *board) { GdkPixbuf *menu_pixmap = NULL; GooCanvasItem *menu_button; int difficulty; gdouble ratio, pixmap_w, pixmap_h; menu_pixmap = gc_pixmap_load(board->icon_name); ratio = get_ratio (menu_pixmap, icon_size); pixmap_w = gdk_pixbuf_get_width(menu_pixmap) * ratio; pixmap_h = gdk_pixbuf_get_height(menu_pixmap) * ratio; next_spot(); menu_button = goo_canvas_image_new (parent, menu_pixmap, current_x - pixmap_w/2, current_y - pixmap_h/2, NULL); goo_canvas_item_scale(menu_button, ratio, ratio); // display board availability due to sound voice not present if(board->mandatory_sound_file) { gchar *soundfile = NULL; /* We search a fixed path sound file */ soundfile = gc_file_find_absolute(board->mandatory_sound_file); if (!soundfile || !gc_prop_get()->fx) { GooCanvasItem *item = \ goo_canvas_svg_new (parent, gc_skin_rsvg_get(), "svg-id", "#SOUND_UNCHECKED", "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); GooCanvasBounds bounds; goo_canvas_item_get_bounds(item, &bounds); SET_ITEM_LOCATION(item, current_x - pixmap_w/2 - 25 - (bounds.x2 - bounds.x1)/2, current_y - pixmap_h/2 + 28- (bounds.y2 - bounds.y1)/2); } g_free(soundfile); } // display menu icon ========================== BEGIN if(g_ascii_strcasecmp(board->type, "menu") == 0) { GooCanvasItem *item = goo_canvas_svg_new (parent, gc_skin_rsvg_get(), "svg-id", "#MENUICON", "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); SET_ITEM_LOCATION(item, current_x - pixmap_w/2 - 25, current_y - pixmap_h/2); } else { // display difficulty stars if (board->difficulty != NULL) { difficulty = atoi(board->difficulty); menu_difficulty_display(parent, (double)current_x - pixmap_w/2 - 25, (double)current_y - pixmap_h/2, (double) 0.6, difficulty); } if ( gc_board_is_demo_only(board) ) menu_demo_display(parent, (gdouble)(current_x - pixmap_w/2 - 20), (gdouble)(current_y - pixmap_h/2 + 60) ); } #if GDK_PIXBUF_MAJOR <= 2 && GDK_PIXBUF_MINOR <= 24 gdk_pixbuf_unref(menu_pixmap); #else g_object_unref(menu_pixmap); #endif // display menu icon ========================== END /* * Now everything ready, map the events * ------------------------------------- */ g_object_set_data (G_OBJECT (menu_button), "board", board); g_signal_connect(menu_button, "button_press_event", (GCallback) item_event, menuitems); g_signal_connect (menu_button, "enter_notify_event", (GCallback) on_enter_notify, menuitems); g_signal_connect (menu_button, "leave_notify_event", (GCallback) on_leave_notify, menuitems); gc_item_focus_init(menu_button, NULL); }
static void parseImage (xmlDocPtr doc, xmlNodePtr cur) { GcomprisProperties *properties = gc_prop_get(); gchar *imageSetName = NULL; gchar *filename; gchar *pathname = NULL; gchar *absolutepath; GSList *imageList = NULL; /* List of Images */ gboolean havePathName = FALSE; gchar *type = NULL; GDir *imageset_directory; /* get the filename of this ImageSet */ imageSetName = (gchar *)xmlGetProp(cur, BAD_CAST "filename"); if (xmlHasProp(cur, BAD_CAST "PathName")){ pathname = (gchar *)xmlGetProp(cur, BAD_CAST "PathName"); havePathName = TRUE; } if (havePathName && pathname[0] == '~' && g_get_home_dir()) { /* replace '~' by home dir */ pathname = g_strdup_printf("%s%s",g_get_home_dir(), pathname+1); if (!g_file_test ((pathname), G_FILE_TEST_IS_DIR)){ g_warning("In ImageSet %s, the pathname for the home directory '%s' is not found. Skipping the whole ImageSet.", imageSetName, pathname); return; } } if (xmlHasProp(cur, BAD_CAST "type")){ /* lsdir means try all file of directory */ /* list means just keep old behaviour */ /* others are extensions to look for */ type = (gchar *)xmlGetProp(cur, BAD_CAST "type"); } /* Looking for imageSetName */ /* absolute path -> we check it's here */ /* relative path -> we check for pathname/imagesetname */ /* -> and else for PACKAGE_DATA_DIR/imagesetname */ if (havePathName) { if (!g_path_is_absolute (imageSetName)){ absolutepath = gc_file_find_absolute(imageSetName, NULL); } else absolutepath = g_strdup(imageSetName); } else absolutepath = gc_file_find_absolute(imageSetName, NULL); if(!absolutepath) { g_warning("In ImageSet %s, an image is not found. Skipping ImageSet...", imageSetName); return; } if ((type == NULL) || (g_ascii_strcasecmp (type,"list")==0)) { /* old behaviour : we read the filenames from xml files */ cur = cur->xmlChildrenNode; while (cur != NULL) { if ((!xmlStrcmp(cur->name, (const xmlChar *)"Image"))) { /* get the filename of this ImageSet */ filename = (gchar *)xmlGetProp(cur, BAD_CAST "filename"); if (havePathName){ filename = g_strdup_printf("%s/%s",pathname,filename); } imageList = g_slist_prepend (imageList, filename); } cur = cur->next; } } else { /* new behaviour : we read all file of a directory */ /* or all files with a given suffix */ if (!g_file_test ((pathname), G_FILE_TEST_IS_DIR)){ char *tmpdir; tmpdir = g_strdup_printf("%s/%s", properties->package_data_dir, pathname); g_free(pathname); pathname = tmpdir; if (!g_file_test ((pathname), G_FILE_TEST_IS_DIR)){ g_warning("In ImageSet %s, directory %s is not found. Skipping all the ImageSet...", absolutepath, pathname); return; } } imageset_directory = g_dir_open (pathname, 0, NULL); const gchar * onefile; while ((onefile = g_dir_read_name(imageset_directory))) { /* Skip README file */ if(g_ascii_strcasecmp (onefile, "readme") == 0) continue; if ((g_ascii_strcasecmp (type,"lsdir") != 0) && (!g_str_has_suffix (onefile, type))){ continue; } filename = g_strdup_printf("%s/%s", pathname, onefile); if (!g_file_test ((filename), G_FILE_TEST_IS_REGULAR)){ continue; } { /* Add a % before a % to avoid it being used as a format arg */ gchar **tmp; gchar *filename2; if((tmp = g_strsplit(filename, "%", -1))) { filename2 = g_strjoinv("%%", tmp); g_strfreev(tmp); g_free(filename); filename = filename2; } } imageList = g_slist_prepend (imageList, filename); } g_dir_close(imageset_directory); } /* do not display if there is nothing to display */ if (imageList != NULL) /* g_slist is not empty */ display_image_set(imageSetName, imageList); g_free(absolutepath); if(pathname) g_free(pathname); if(type) g_free(type); return; }
void gc_selector_images_start (GcomprisBoard *gcomprisBoard, gchar *dataset, ImageSelectorCallBack iscb, void *user_context) { gint y_start = 0; gchar *dataseturl = NULL; GtkWidget *w; if(sugar_detected()) { sugar_choose_image(iscb, user_context); return; } if(rootitem) return; gc_bar_hide(TRUE); gc_board_pause(TRUE); imageSelectorCallBack = iscb; current_user_context = user_context; rootitem = goo_canvas_group_new (goo_canvas_get_root_item(gc_get_canvas()), NULL); images_selector_displayed = TRUE; goo_canvas_svg_new (rootitem, gc_skin_rsvg_get(), "svg-id", "#IMAGE_SELECTOR", "pointer-events", GOO_CANVAS_EVENTS_NONE, NULL); y_start += 110; /* * Create the list scrollbar * ------------------------- */ canvas_list_selector = goo_canvas_new (); goo_canvas_widget_new (rootitem, canvas_list_selector, LIST_AREA_X1, LIST_AREA_Y1, LIST_AREA_X2 - LIST_AREA_X1, LIST_AREA_Y2 - LIST_AREA_Y1 - 35.0, NULL); gtk_widget_show (canvas_list_selector); /* Set the new canvas to the background color or it's white */ list_bg_item = goo_canvas_rect_new (goo_canvas_get_root_item(GOO_CANVAS(canvas_list_selector)), 0, 0, (LIST_AREA_X2 - LIST_AREA_X1) * gc_zoom_factor_get(), (LIST_AREA_Y2 - LIST_AREA_Y1) * gc_zoom_factor_get(), "fill-color-rgba", gc_skin_get_color("gcompris/imageselectbg_left"), "line-width", 0.0, NULL); list_adj = \ GTK_ADJUSTMENT (gtk_adjustment_new (0.00, 0.00, 0.00, 10, IMAGE_HEIGHT, (LIST_AREA_Y2 - LIST_AREA_Y1) * gc_zoom_factor_get()) ); w = gtk_vscrollbar_new (list_adj); goo_canvas_widget_new (rootitem, w, LIST_AREA_X2 - 5.0, LIST_AREA_Y1, 30.0, LIST_AREA_Y2 - LIST_AREA_Y1 - 20.0, NULL); gtk_widget_show (w); /* Set the scrollwheel event */ g_signal_connect (list_adj, "value_changed", (GCallback) item_event_scroll, canvas_list_selector); /* * Create the image scrollbar * -------------------------- */ canvas_image_selector = goo_canvas_new (); goo_canvas_widget_new (rootitem, canvas_image_selector, DRAWING_AREA_X1, DRAWING_AREA_Y1, DRAWING_AREA_X2 - DRAWING_AREA_X1, DRAWING_AREA_Y2 - DRAWING_AREA_Y1, NULL); gtk_widget_show (canvas_image_selector); /* Set the new canvas to the background color or it's white */ image_bg_item = \ goo_canvas_rect_new (goo_canvas_get_root_item(GOO_CANVAS(canvas_image_selector)), 0, 0, (DRAWING_AREA_X2 - DRAWING_AREA_X1) * gc_zoom_factor_get(), (DRAWING_AREA_Y2 - DRAWING_AREA_Y1) * gc_zoom_factor_get(), "fill-color-rgba", gc_skin_get_color("gcompris/imageselectbg_right"), "line-width", 0.0, NULL); image_adj = \ GTK_ADJUSTMENT (gtk_adjustment_new (0.00, 0.00, 0.00, 10, IMAGE_HEIGHT, (DRAWING_AREA_Y2 - DRAWING_AREA_Y1) * gc_zoom_factor_get()) ); w = gtk_vscrollbar_new (image_adj); goo_canvas_widget_new (rootitem, w, DRAWING_AREA_X2 - 5.0, DRAWING_AREA_Y1, 30.0, DRAWING_AREA_Y2 - DRAWING_AREA_Y1 - 20.0, NULL); gtk_widget_show (w); /* Set the scrollwheel event */ g_signal_connect (image_adj, "value_changed", (GCallback) item_event_scroll, canvas_image_selector); /* * DISPLAY IMAGES */ /* Initial image position */ isy = 0.0; /* I need the following : -> if dataset is a file read it. -> if dataset is a directory, read all xml file in it. */ dataseturl = \ gc_file_find_absolute(dataset, NULL); /* if the file doesn't exist */ if(g_file_test ((dataseturl), G_FILE_TEST_IS_DIR) ) { g_warning("dataset %s is a directory. Trying to read xml", dataseturl); read_dataset_directory(dataseturl); } else if(dataseturl) { /* Read the given data set file, local or net */ read_xml_file(dataseturl); } else { /* Network code for dataset directory */ GSList *filelist = NULL; GSList *i = NULL; g_free(dataseturl); dataseturl = g_strconcat("boards/", dataset, NULL); /* TODO */ filelist = NULL; //gc_net_dir_read_name(dataseturl, ".xml"); for (i = filelist; i != NULL; i = g_slist_next (i)) { gchar *url = gc_file_find_absolute(i->data, NULL); g_warning("processing dataset=%s\n", (char *)i->data); read_xml_file(url); g_free(url); } g_slist_free(filelist); } g_free(dataseturl); /* * OK Button * --------- */ gc_util_button_text_svg(rootitem, (BOARDWIDTH*0.5), BOARDHEIGHT - 32, "#BUTTON_TEXT", _("OK"), (GCallback) item_event_images_selector, "/ok/"); }