GLADE_CB void on_add_clicked (GtkToolButton *toolbutton, gpointer user_data) { char **array, **ptr; CalcModel model; FileContent *content; int ret; unsigned int i; array = create_fsels(inst_paths.home_dir, "", "*.*"); if(array == NULL) return; for(ptr = array; *ptr; ptr++) { char *fn = *ptr; if(tifiles_file_is_tigroup(fn)) { msgbox_one(MSGBOX_ERROR, _("Importing of TiGroup files is not allowed.")); return; } model = tifiles_file_get_model(fn); if(!tifiles_calc_are_compat(GFMFile.model, model)) { msgbox_one(MSGBOX_ERROR, _("File is not compatible with current target.")); return; } content = tifiles_content_create_regular(model); ret = tifiles_file_read_regular(fn, content); for(i = 0; i < content->num_entries; i++) { VarEntry *ve = content->entries[i]; if(ticalcs_dirlist_ve_exist(GFMFile.trees.vars, ve)) { msgbox_one(MSGBOX_ERROR, _("The entry already exists. Skipped!")); continue; } ticalcs_dirlist_ve_add(GFMFile.trees.vars, ve); } ret = tifiles_content_delete_regular(content); } enable_save(TRUE); enable_tree(TRUE); ctree_refresh(); labels_refresh(); }
/** * tifiles_file_test: * @filename: a filename as string. * @type: type to check * @target: hand-held model or CALC_NONE for no filtering * * Check whether #filename is a TI file of type #type useable on a #target model. * This function is a generic one which overwrap and extends the tifiles_file_is_* * functions. * * This is a powerful function which allows checking of a specific file type for * a given target. * * Return value: a boolean value. **/ TIEXPORT2 int TICALL tifiles_file_test(const char *filename, FileClass type, CalcModel target) { char *e = tifiles_fext_get(filename); if (!tifiles_file_is_ti(filename)) return 0; if (!strcmp(e, "")) return 0; if(target > CALC_MAX) { tifiles_critical("tifiles_file_test: invalid target argument! This is a bug."); return 0; } if(type & TIFILE_SINGLE) { if(target && !g_ascii_strncasecmp(e, GROUP_FILE_EXT[target], 2)) return !0; else return tifiles_file_is_single(filename); } if(type & TIFILE_GROUP) { if(target && !g_ascii_strcasecmp(e, GROUP_FILE_EXT[target])) return !0; else return tifiles_file_is_group(filename); } if(type & TIFILE_REGULAR) { return tifiles_file_test(filename, TIFILE_SINGLE, target) || tifiles_file_test(filename, TIFILE_GROUP, target); } if(type & TIFILE_BACKUP) { if(target && !g_ascii_strcasecmp(e, BACKUP_FILE_EXT[target])) return !0; else return tifiles_file_is_backup(filename); } if(type & TIFILE_OS) { if(target && !g_ascii_strcasecmp(e, FLASH_OS_FILE_EXT[target])) return !0; else if(target && tifiles_file_is_tib(filename)) { FILE *f; uint8_t data[16]; f = g_fopen(filename, "rb"); if(f == NULL) return 0; fread_n_chars(f, 16, (char *)data); fclose(f); switch(data[8]) { case 1: if(target != CALC_TI92P) return 0; case 3: if(target != CALC_TI89) return 0; case 8: if(target != CALC_V200) return 0; case 9: if(target != CALC_TI89T) return 0; } return !0; } else return tifiles_file_is_os(filename); } if(type & TIFILE_APP) { if(target && !g_ascii_strcasecmp(e, FLASH_APP_FILE_EXT[target])) return !0; else return tifiles_file_is_app(filename); } if(type & TIFILE_FLASH) { return tifiles_file_test(filename, TIFILE_OS, target) || tifiles_file_test(filename, TIFILE_APP, target); } if(type & TIFILE_TIGROUP) { if(target) { // No easy/light way for this part: we have to load the whole file // and to parse the TigEntry structures. TigContent *content; int ret, ok=0; int k; if(!tifiles_file_has_tig_header(filename)) return 0; content = tifiles_content_create_tigroup(CALC_NONE, 0); ret = tifiles_file_read_tigroup(filename, content); if(ret) return 0; for (k = 0; k < content->n_apps; k++) { TigEntry *te = content->app_entries[k]; if(tifiles_calc_are_compat(te->content.regular->model, target)) ok++; } for (k = 0; k < content->n_vars; k++) { TigEntry *te = content->var_entries[k]; if(tifiles_calc_are_compat(te->content.regular->model, target)) ok++; } tifiles_content_delete_tigroup(content); return ok; } else return tifiles_file_is_tigroup(filename); } return 0; }
void clist_refresh(void) { GtkTreeView *view = GTK_TREE_VIEW(clist_wnd); GtkTreeSelection *selection; GtkTreeViewColumn *col; GtkTreeIter iter; GdkPixbuf *pix1, *pix2, *pix; GList *dirlist; gsize br, bw; gchar *utf8; int i; if(working_mode & MODE_CMD) return; // reparse folders tilp_local_selection_destroy(); tilp_dirlist_local(); selection = gtk_tree_view_get_selection(view); g_signal_handlers_block_by_func(G_OBJECT(selection), tree_selection_changed, NULL); gtk_list_store_clear(list); g_signal_handlers_unblock_by_func(G_OBJECT(selection), tree_selection_changed, NULL); // sort files for(i = 0; i < CLIST_NVCOLS; i++) { col = gtk_tree_view_get_column(view, i); gtk_tree_view_column_set_sort_indicator(col, FALSE); } switch (options.local_sort) { case SORT_BY_NAME: tilp_file_sort_by_name(); col = gtk_tree_view_get_column(view, COLUMN_NAME); gtk_tree_view_column_set_sort_indicator(col, TRUE); gtk_tree_view_column_set_sort_order(col, options.local_sort_order ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING); break; case SORT_BY_TYPE: tilp_file_sort_by_type(); col = gtk_tree_view_get_column(view, COLUMN_TYPE); gtk_tree_view_column_set_sort_indicator(col, TRUE); gtk_tree_view_column_set_sort_order(col, options.local_sort_order ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING); break; case SORT_BY_DATE: tilp_file_sort_by_date(); col = gtk_tree_view_get_column(view, COLUMN_DATE); gtk_tree_view_column_set_sort_indicator(col, TRUE); gtk_tree_view_column_set_sort_order(col, options.local_sort_order ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING); break; case SORT_BY_SIZE: tilp_file_sort_by_size(); col = gtk_tree_view_get_column(view, COLUMN_SIZE); gtk_tree_view_column_set_sort_indicator(col, TRUE); gtk_tree_view_column_set_sort_order(col, options.local_sort_order ? GTK_SORT_ASCENDING : GTK_SORT_DESCENDING); break; } pix2 = gtk_widget_render_icon(GTK_WIDGET(view), GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL); pix1 = gtk_widget_render_icon(GTK_WIDGET(view), GTK_STOCK_GO_UP, GTK_ICON_SIZE_MENU, NULL); for (dirlist = local.dirlist; dirlist != NULL; dirlist = dirlist->next) { FileEntry *fe = (FileEntry *) dirlist->data; gboolean b; CalcModel s = tifiles_file_get_model(fe->name); CalcModel t = options.calc_model; b = options.show_all || S_ISDIR(fe->attrib) || tifiles_file_is_tib(fe->name) || #if 0 tifiles_file_is_tigroup(fe->name) || #else tifiles_file_test(fe->name, TIFILE_TIGROUP, options.calc_model) || #endif tifiles_calc_are_compat(s, t); if(!b) continue; if (S_ISDIR(fe->attrib)) { pix = strcmp(fe->name, "..") ? pix2 : pix1; } else { char icon_name[2048]; strcpy(icon_name, tifiles_file_get_icon(fe->name)); if (!strcmp(icon_name, "")) strcpy(icon_name, "TIicon1"); strcat(icon_name, ".ico"); tilp_file_underscorize(icon_name); pix = create_pixbuf(icon_name); } // filenames are stored in the 'glib filename encoding' and GTK+ uses utf8 utf8 = g_filename_to_utf8(fe->name, -1, &br, &bw, NULL); gtk_list_store_append(list, &iter); gtk_list_store_set(list, &iter, COLUMN_NAME, utf8, COLUMN_TYPE, tilp_file_get_type(fe), COLUMN_SIZE, tilp_file_get_size(fe), COLUMN_DATE, tilp_file_get_date(fe), COLUMN_DATA, (gpointer) fe, COLUMN_ICON, pix, -1); g_free(utf8); } g_object_unref(pix1); g_object_unref(pix2); }