// Does 2 things: // - locate project directory. This is either // a) env var BOINC_PROJECT_DIR, if defined // b) current dir, if config.xml exists there // c) parent dir, if config.xml exists there // - returns a path relative to the project dir, // specified by a format string + args // const char *SCHED_CONFIG::project_path(const char *fmt, ...) { static char path[MAXPATHLEN]; va_list ap; if (!strlen(project_dir)) { char *p = getenv("BOINC_PROJECT_DIR"); if (p) { if (!is_project_dir(p)) { fprintf(stderr, "BOINC_PROJECT_DIR env var exists but is not a project dir\n"); exit(1); } strlcpy(project_dir, p, sizeof(project_dir)); } else if (is_project_dir(".")) { strcpy(project_dir, "."); } else if (is_project_dir("..")) { strcpy(project_dir, ".."); } else { fprintf(stderr, "Not in a project directory or subdirectory\n"); exit(1); } } va_start(ap, fmt); snprintf(path, sizeof(path), "%s/", project_dir); vsnprintf(path + strlen(path), sizeof(path) - strlen(path), fmt, ap); va_end(ap); return (const char *)path; }
//static void on_browse(GtkWidget * widget, gpointer data) void ladish_run_load_project_dialog(ladish_room_proxy_handle room) { GtkFileFilter * filter; GtkWidget * dialog; char * filename; dialog = gtk_file_chooser_dialog_new( _("Load project"), NULL, GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); gtk_file_chooser_set_create_folders(GTK_FILE_CHOOSER(dialog), FALSE); filter = gtk_file_filter_new(); gtk_file_filter_add_custom(filter, GTK_FILE_FILTER_FILENAME, reject_filter, dialog, NULL); /* reject all files */ gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter); //g_signal_connect(G_OBJECT(dialog), "selection-changed", G_CALLBACK(on_dir_select), dialog); g_signal_connect(G_OBJECT(dialog), "current-folder-changed", G_CALLBACK(dir_changed), dialog); loop: if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); if (!is_project_dir(filename)) { GtkWidget * dialog; dialog = get_gtk_builder_widget("error_dialog"); gtk_message_dialog_set_markup(GTK_MESSAGE_DIALOG(dialog), _("<b><big>Not a project dir</big></b>")); gtk_message_dialog_format_secondary_markup(GTK_MESSAGE_DIALOG(dialog), "%s", filename); gtk_widget_show(dialog); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_hide(dialog); goto loop; } //gtk_entry_set_text(GTK_ENTRY(get_gtk_builder_widget("load_project_path_entry")), filename); log_info("Loading project from '%s'", filename); if (!ladish_room_proxy_load_project(room, filename)) { log_error("ladish_room_proxy_load_project() failed."); } g_free(filename); //gtk_widget_activate(gtk_dialog_get_widget_for_response(GTK_DIALOG(data), GTK_RESPONSE_OK)); } gtk_widget_destroy(dialog); return; }
static void on_dir_select(GtkWidget * widget, gpointer data) { char * dir; gboolean sensitive; //log_info("selection-changed signal"); dir = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(data)); sensitive = FALSE; if (dir != NULL) { sensitive = is_project_dir(dir); g_free(dir); } gtk_widget_set_sensitive(gtk_dialog_get_widget_for_response(GTK_DIALOG(data), GTK_RESPONSE_ACCEPT), sensitive); }
static void dir_changed(GtkWidget * UNUSED(widget), gpointer data) { char * dir; //log_info("current-folder-changed signal"); dir = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(data)); if (dir == NULL) { return; } //log_info("dir changed: '%s'", dir); if (is_project_dir(dir)) { gtk_widget_activate(gtk_dialog_get_widget_for_response(GTK_DIALOG(data), GTK_RESPONSE_ACCEPT)); } }