void on_tilp_recv(void) { int ret; if ((remote.selection1 != NULL) || (remote.selection2 != NULL)) { if (remote.selection1 != NULL) { ret = tilp_calc_recv_var(); if (ret < 0) return; else if (ret > 0) save_group(); } if (remote.selection2 != NULL) { ret = tilp_calc_recv_app(); if (ret != 0) return; } } else if ((options.calc_model == CALC_TI82) || (options.calc_model == CALC_TI85)) { ret = tilp_calc_recv_var(); if (ret < 0) return; else if (ret > 0) save_group(); } clist_refresh(); labels_refresh(); }
// trash TILP_EXPORT void on_tilp_button11_clicked(GtkButton* button, gpointer user_data) { tilp_file_selection_delete(); clist_refresh(); labels_refresh(); }
GLADE_CB void on_mkdir_clicked (GtkToolButton *toolbutton, gpointer user_data) { gchar *ret; GNode *node; VarEntry *ve; if(GFMFile.trees.vars == NULL) return; if(tifiles_calc_is_ti8x(GFMFile.model)) return; ret = msgbox_input(_("New Folder"), _("folder"), _("Name of folder to create:")); if(ret == NULL) return; ret[8] = '\0'; ve = tifiles_ve_create(); strcpy(ve->name, ret); ve->type = tifiles_folder_type(GFMFile.model); node = g_node_new(ve); g_node_append(GFMFile.trees.vars, node); ctree_refresh(); labels_refresh(); }
GLADE_CB void on_new_clicked (GtkToolButton *toolbutton, gpointer user_data) { CalcModel model; int result; result = msgbox_three(_("TiGroup"), _("Single/Group"), _("File type?")); if(!result) return; model = msgbox_model(); if(!model) return; file_create(result == MSGBOX_BUTTON1 ? TIFILE_TIGROUP : TIFILE_GROUP, model); g_free(GFMFile.filename); GFMFile.filename = NULL; enable_save(FALSE); enable_tree(TRUE); ctree_refresh(); labels_refresh(); }
// Dirlist TILP_EXPORT void on_tilp_button2_clicked(GtkButton* button, gpointer user_data) { if (tilp_calc_dirlist() != 0) return; ctree_refresh(); labels_refresh(); }
// refresh TILP_EXPORT void on_tilp_button12_clicked(GtkButton* button, gpointer user_data) { if (!local.copy_cut) tilp_file_selection_destroy(); clist_refresh(); labels_refresh(); }
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(); }
GLADE_CB gboolean on_treeview2_button_press_event(GtkWidget* widget, GdkEventButton* event, gpointer user_data) { GtkTreeView *view = GTK_TREE_VIEW(widget); GtkTreeModel *model = GTK_TREE_MODEL(list); GtkTreePath *path; GtkTreeViewColumn *column; GtkTreeIter iter; GdkEventButton *bevent; gint tx = (gint) event->x; gint ty = (gint) event->y; gint cx, cy; FileEntry *fe; gtk_tree_view_get_path_at_pos(view, tx, ty, &path, &column, &cx, &cy); switch (event->type) { case GDK_BUTTON_PRESS: if (event->button == 3) { bevent = (GdkEventButton *) (event); gtk_menu_popup(GTK_MENU(create_clist_rbm()), NULL, NULL, NULL, NULL, bevent->button, bevent->time); return TRUE; } break; case GDK_2BUTTON_PRESS: if (path == NULL) return FALSE; gtk_tree_model_get_iter(model, &iter, path); gtk_tree_model_get(model, &iter, COLUMN_DATA, &fe, -1); if (S_ISDIR(fe->attrib)) { // go into folder tilp_file_chdir(fe->name); g_free(local.cwdir); local.cwdir = g_get_current_dir(); clist_refresh(); labels_refresh(); } break; default: break; } return FALSE; // pass event on }
GLADE_CB void on_open_clicked (GtkToolButton *toolbutton, gpointer user_data) { gchar *fn; if(user_data == NULL) { if(GFMFile.contents.group || GFMFile.contents.tigroup) { int result = msgbox_two(MSGBOX_YESNO, _("Do you want to save previous file?")); if(result == MSGBOX_YES) on_save_clicked(toolbutton,user_data); } fn = (char *)create_fsel(inst_paths.home_dir, "", "*.73?;*.82?;*.83?;*.8X?;*.85?;*.86?;*.89?;*.92?;*.9x?;*.V2?;*.tig", FALSE); if(fn == NULL) return; } else { // command line fn = (char *)user_data; } if(tifiles_file_is_tigroup(fn)) GFMFile.type = TIFILE_TIGROUP; else if(tifiles_file_is_regular(fn)) GFMFile.type = TIFILE_GROUP; else return; file_load(fn); g_free(GFMFile.filename); GFMFile.filename = g_strdup(fn); enable_save(FALSE); enable_tree(TRUE); ctree_refresh(); labels_refresh(); g_free(inst_paths.home_dir); inst_paths.home_dir = g_path_get_dirname(GFMFile.filename); }
// make new dir TILP_EXPORT void on_tilp_button10_clicked(GtkButton* button, gpointer user_data) { gchar *utf8 = NULL; gsize br, bw; gchar *dirname; utf8 = gif->msg_entry(_("Make a new directory"), _("Name: "), _("new_directory")); if (utf8 == NULL) return; dirname = g_filename_from_utf8(utf8, -1, &br, &bw, NULL); g_free(utf8); tilp_file_mkdir(dirname); g_free(dirname); clist_refresh(); labels_refresh(); }
// change folder TILP_EXPORT void on_button14_clicked(GtkButton* button, gpointer user_data) { gchar *folder; folder = msg_entry(_("Path"), _("Enter new path"), local.cwdir); if(folder != NULL) { if(g_file_test(folder, G_FILE_TEST_IS_DIR)) { tilp_file_chdir(folder); g_free(local.cwdir); local.cwdir = g_get_current_dir(); clist_refresh(); labels_refresh(); } g_free(folder); } }
// Recv TIGroup TILP_EXPORT void on_tilp_button7_clicked(GtkButton* button, gpointer user_data) { char* src_filename; const char *dst_filename; const char *dst_filename2; int ret; int mode = TIG_ALL; ret = backup_box(_("Backup"), _("Data to backup:"), &mode); if(ret != BUTTON1) return; if (tilp_calc_recv_tigroup(mode) != 0) return; src_filename = g_strconcat(g_get_tmp_dir(), G_DIR_SEPARATOR_S, TMPFILE_TIGROUP, NULL); dst_filename = create_fsel(local.cwdir, "backup", "*.tig", TRUE); if(!dst_filename) { g_free(src_filename); return; } if (!strcmp(tifiles_fext_get(dst_filename), "")) dst_filename2 = g_strconcat(dst_filename, ".tig", NULL); else dst_filename2 = g_strdup(dst_filename); //g_free((void *)dst_filename); if (dst_filename2) { tilp_file_move_with_check(src_filename, dst_filename2); } g_free(src_filename); g_free((void *)dst_filename2); tilp_dirlist_local(); clist_refresh(); labels_refresh(); }
// Backup TILP_EXPORT void on_tilp_button3b_clicked(GtkButton* button, gpointer user_data) { char* src_filename; const char *dst_filename; const char *dst_filename2; char *ext; if (tilp_calc_recv_backup() != 0) return; src_filename = g_strconcat(g_get_tmp_dir(), G_DIR_SEPARATOR_S, TMPFILE_BACKUP, NULL); ext = g_strconcat("*.", tifiles_fext_of_backup(options.calc_model), NULL); dst_filename = create_fsel(local.cwdir, "backup", ext, TRUE); g_free(ext); if (!dst_filename) { g_free(src_filename); return; } if (!strcmp(tifiles_fext_get(dst_filename), "")) dst_filename2 = g_strconcat(dst_filename, ".", tifiles_fext_of_backup(options.calc_model), NULL); else dst_filename2 = g_strdup(dst_filename); //g_free((void *)dst_filename); if (dst_filename2) { tilp_file_move_with_check(src_filename, dst_filename2); } g_free(src_filename); g_free((void *)dst_filename2); tilp_dirlist_local(); clist_refresh(); labels_refresh(); }
static int save_group(void) { char* src_filename; const char *dst_filename; const char *dst_filename2; char *ext; src_filename = g_strconcat(g_get_tmp_dir(), G_DIR_SEPARATOR_S, TMPFILE_GROUP, ".", tifiles_fext_of_group(options.calc_model), NULL); ext = g_strconcat("*.", tifiles_fext_of_group(options.calc_model), NULL); dst_filename = create_fsel(local.cwdir, "group", ext, TRUE); g_free(ext); if (!dst_filename) { g_free(src_filename); return -1; } if (!strcmp(tifiles_fext_get(dst_filename), "")) dst_filename2 = g_strconcat(dst_filename, ".", tifiles_fext_of_group(options.calc_model), NULL); else dst_filename2 = g_strdup(dst_filename); //g_free((void *)dst_filename); if (dst_filename2) { tilp_file_move_with_check(src_filename, dst_filename2); } g_free(src_filename); g_free((void *)dst_filename2); tilp_dirlist_local(); clist_refresh(); labels_refresh(); return 0; }
TILP_EXPORT void on_rom_dump1_activate(GtkMenuItem* menuitem, gpointer user_data) { char* src_filename; const char *dst_filename; const char *dst_filename2; char filename[128]; if (tilp_calc_rom_dump()) return; src_filename = g_strconcat(g_get_tmp_dir(), G_DIR_SEPARATOR_S, TMPFILE_ROMDUMP, NULL); sprintf(filename, "dump%s", tifiles_model_to_string(options.calc_model)); dst_filename = create_fsel(local.cwdir, filename, "*.rom", TRUE); if (!dst_filename) { g_free(src_filename); return; } if (!strcmp(tifiles_fext_get(dst_filename), "")) dst_filename2 = g_strconcat(dst_filename, ".", "rom", NULL); else dst_filename2 = g_strdup(dst_filename); //g_free((void *)dst_filename); if (dst_filename2) { tilp_file_move_with_check(src_filename, dst_filename2); } g_free(src_filename); g_free((void *)dst_filename2); tilp_dirlist_local(); clist_refresh(); labels_refresh(); }
// Used for sending vars // Note: user_data is a string: // - such as "<FLASH>" for sending var into FLASH (ti83+/84+/89/92+/v200) // - such as "" for sending var in the default folder // - such as "foo" for sending var in the 'foo' folder // - unused for sending FLASH files void on_tilp_send(const gchar *user_data) { gchar *target; FileEntry *f; int ret1 = -1; int ret2 = -1; if (local.selection0 == NULL && local.selection2 == NULL && local.selection5 == NULL) return; tilp_local_contents_load(); // send apps if(local.selection3 || (local.selection5 && local.selection3)) { f = (FileEntry *) local.selection3->data; // send os upgrades if(tifiles_file_is_flash(f->name) || tifiles_file_is_tigroup(f->name)) { if(tifiles_file_test(f->name, TIFILE_OS, options.calc_model)) { if (tilp_calc_send_os(f->name) != 0) return; } else if(tifiles_file_is_app(f->name)) { ret1 = tilp_calc_send_app(); if(!ret1) { // update dirlist (caching, avoid to request dirlist again) tilp_local_update_applist(); ctree_refresh(); labels_refresh(); } } } } // send vars if(local.selection1 || (local.selection5 && local.selection1)) { // note: dst_folder must be a copy b/c the user_data // pointer is no longer valid after dirlist_remote target = g_strdup(user_data); // change target folder if(strcmp(target, "") && strcmp(target, "<FLASH>")) tilp_local_change_folder(target); // and wait for action if (display_action_dbox(target) == BUTTON2) { g_free(target); tilp_local_contents_unload(); return; } // needed: avoid box locking/flickering ! GTK_REFRESH(); ret2 = tilp_calc_send_var(); if(!ret2) { // update dirlist (caching, avoid to request dirlist again) tilp_local_update_varlist(); ctree_refresh(); labels_refresh(); } g_free(target); } tilp_local_contents_unload(); }
GLADE_CB gboolean on_treeview1_button_press_event(GtkWidget * widget, GdkEventButton * event, gpointer user_data) { GtkTreeView *view = GTK_TREE_VIEW(gfm_widget.tree); GtkTreeModel *model = GTK_TREE_MODEL(tree); GtkTreePath *path; GtkTreeViewColumn *column; GtkTreeIter iter; VarEntry *ve; int col; gtk_tree_view_get_cursor(view, &path, &column); col = column2index(column); if (path == NULL) return FALSE; gtk_tree_model_get_iter(model, &iter, path); gtk_tree_model_get(model, &iter, COLUMN_DATA, &ve, -1); if (ve == NULL) return FALSE; if((event->type == GDK_2BUTTON_PRESS) && (col == COLUMN_ATTR)) { GdkPixbuf *pix1, *pix2, *pix3; pix1 = create_pixbuf("attr_none.xpm"); pix2 = create_pixbuf("attr_locked.xpm"); pix3 = create_pixbuf("attr_archived.xpm"); if(ve->type == tifiles_flash_type(GFMFile.model)) return FALSE; if(ve->attr == ATTRB_NONE) ve->attr = ATTRB_LOCKED; else if(ve->attr == ATTRB_LOCKED && tifiles_is_flash(GFMFile.model)) ve->attr = ATTRB_ARCHIVED; else if(ve->attr == ATTRB_LOCKED && !tifiles_is_flash(GFMFile.model)) ve->attr = ATTRB_NONE; else if(ve->attr == ATTRB_ARCHIVED) ve->attr = ATTRB_NONE; switch (ve->attr) { case ATTRB_NONE: gtk_tree_store_set(tree, &iter, COLUMN_ATTR, pix1, -1); break; case ATTRB_LOCKED: gtk_tree_store_set(tree, &iter, COLUMN_ATTR, pix2, -1); break; case ATTRB_ARCHIVED: gtk_tree_store_set(tree, &iter, COLUMN_ATTR, pix3, -1); break; default: break; } g_object_unref(pix1); g_object_unref(pix2); g_object_unref(pix3); labels_refresh(); } return FALSE; }
int main(int argc, char *argv[]) { GdkPixbuf *icon; /* Redirect standard output to a file - printing to the Windows terminal slows operation down way too much */ #ifdef __WIN32__ gchar *tmp; FILE *log_file; tmp = g_strconcat(g_get_home_dir(), G_DIR_SEPARATOR_S, LOG_FILE, NULL); log_file = g_fopen(tmp, "wt"); g_free(tmp); if (log_file != NULL) g_log_set_default_handler(&default_log_handler, log_file); #endif // Force GLib 2.32+ to print info and debug messages like older versions did, unless this variable is already set. // No effect on earlier GLib versions. g_setenv("G_MESSAGES_DEBUG", "all", /* overwrite = */ FALSE); /* Init the tilp core */ tilp_init(&argc, &argv); /* Init GTK+ */ gtk_init(&argc, &argv); add_pixmap_directory(inst_paths.pixmap_dir); add_pixmap_directory(inst_paths.icon_dir); splash_screen_start(); /* Get rid of glib, gdk, gtk warnings when compiled in Release mode */ #if !defined(_DEBUG) g_log_set_handler ("GLib", G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, my_blackhole_log_handler, NULL); g_log_set_handler ("Gdk", G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, my_blackhole_log_handler, NULL); g_log_set_handler ("Gtk", G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO | G_LOG_LEVEL_DEBUG, my_blackhole_log_handler, NULL); g_log_set_handler ("GLib", G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION, my_blackhole_log_handler, NULL); #endif /* Init the GUI-independent functions */ tilp_gif_set_gtk(); tilp_update_set_gtk(); /* Create the main window */ if(!(working_mode & MODE_CMD)) { #if WITH_KDE splash_screen_set_label(_("Initializing KDE...")); sp_kde_init(argc, argv, "tilp", _("TiLP"), VERSION, _("Tilp Is a Linking Program"), "Copyright (c) 1999-2008 Romain Lievin", "http://lpg.ticalc.org/prj_tilp/", "*****@*****.**"); atexit(sp_kde_finish); // Not needed unless we want to add a DCOP interface. // g_timeout_add(26, sp_kde_process_qt_events, NULL); #endif splash_screen_set_label(_("Loading GUI...")); main_wnd = display_tilp_dbox(); } /* Do a local directory list */ g_free(local.cwdir); local.cwdir = g_get_current_dir(); /* Update the local view (not visible yet) */ if(!(working_mode & MODE_CMD)) { clist_refresh(); labels_refresh(); } /* Inits are done ! */ working_mode &= ~MODE_INI; tilp_err(0); // pop errors (display console mode) /* In cmdline, does not display the entire window, only the pbar */ if(!(working_mode & MODE_CMD)) { gtk_widget_show(main_wnd); toolbar_refresh_buttons(); icon = create_pixbuf("tilp.xpm"); gtk_window_set_icon(GTK_WINDOW(main_wnd), icon); gdk_window_set_icon_name(main_wnd->window, _("TiLP2")); } /* If variables have been passed on the command line in GUI mode then send them */ if((working_mode & MODE_GUI) && (working_mode & MODE_CMD)) { splash_screen_set_label(_("Command line...")); if(local.selection0 || local.selection2 || local.selection5) on_tilp_send(""); else if(local.selection4) tilp_cmdline_send(); } /* GTK main loop */ splash_screen_stop(); if(!(working_mode & MODE_CMD)) gtk_main(); tilp_exit(); return 0; }
gint display_action_dbox(gchar *target) { GtkBuilder *builder; GError* error = NULL; GtkWidget *dbox; GtkWidget *data; GtkTreeIter iter; GList *sel; int button = 0; gint result; gboolean empty = TRUE; // update folder listing (if supported) if (!(ticalcs_calc_features(calc_handle) & FTS_SILENT) ) return BUTTON1; else { if(remote.var_tree == NULL) { if (tilp_dirlist_remote()) return BUTTON1; ctree_refresh(); labels_refresh(); } } // box creation builder = gtk_builder_new(); if (!gtk_builder_add_from_file (builder, tilp_paths_build_builder("action.ui"), &error)) { g_warning (_("Couldn't load builder file: %s\n"), error->message); g_error_free (error); return 0; // THIS RETURNS ! } gtk_builder_connect_signals(builder, NULL); dbox = GTK_WIDGET (gtk_builder_get_object (builder, "action_dbox")); gtk_dialog_set_alternative_button_order(GTK_DIALOG(dbox), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL,-1); clist = data = GTK_WIDGET (gtk_builder_get_object (builder, "treeview1")); // clist creation create_clist(data); // fill model for (sel = local.selection1; sel != NULL; sel = sel->next) { FileEntry *f = (FileEntry *)sel->data; FileContent *c = (FileContent *)f->content1; if(f->content1 == NULL) // file can't be loaded continue; // we have now 1 VarEntry per FileContent { VarEntry *v = c->entries[0]; VarEntry *w; gchar **row_text = g_malloc0(5 * sizeof(gchar *)); char *trans; char full_name[260]; // modify attr or folder if target is specified if(strcmp(target, "")) { if(!strcmp(target, "<FLASH>")) { v->attr = ATTRB_ARCHIVED; } else { strcpy(v->folder, target); } } // search for matching var tifiles_build_fullname(options.calc_model, full_name, v->folder, v->name); trans = ticonv_varname_to_utf8(options.calc_model, (const char *)full_name, v->type); w = ticalcs_dirlist_ve_exist(remote.var_tree, v); if (w == NULL) continue; if(w->attr == ATTRB_LOCKED || w->attr == ATTRB_ARCHIVED) v->action = ACT_SKIP; else v->action = ACT_SKIP; //don't overwrite as default behaviour // file contains an already existing var: add it to the window row_text[0] = trans; row_text[1] = g_strdup(tifiles_attribute_to_string(v->attr)); row_text[2] = g_strdup(f->name); row_text[3] = g_strdup(action2string(v->action)); tilp_vars_translate(row_text[0]); gtk_list_store_append(list, &iter); gtk_list_store_set(list, &iter, COLUMN_VAR, row_text[0], COLUMN_ATTR, row_text[1], COLUMN_FILE, row_text[2], COLUMN_ACTION, row_text[3], COLUMN_DATA_F, (gpointer)f, COLUMN_DATA_V, (gpointer)v, -1); g_strfreev(row_text); empty = FALSE; } } if (empty == TRUE) { button = BUTTON1; // skip box as ok goto out_clean; } // select all vars { GtkTreeView *view = GTK_TREE_VIEW(clist); GtkTreeSelection *sel2; sel2 = gtk_tree_view_get_selection(view); gtk_tree_selection_select_all(sel2); } // box running gtk_dialog_set_default_response(GTK_DIALOG(dbox), GTK_RESPONSE_CANCEL); result = gtk_dialog_run(GTK_DIALOG(dbox)); switch (result) { case GTK_RESPONSE_OK: button = BUTTON1; break; case GTK_RESPONSE_CANCEL: button = BUTTON2; default: button = BUTTON2; break; } out_clean: gtk_widget_destroy(dbox); return button; }