X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fui.c;h=e0541c93dd431e6079e1023dcc4beba0a56737c1;hb=b2b735205d9b6c57635a052c8d4af1329bfda723;hp=ef556b759862d362a0cffe9aca1f9ca843a59379;hpb=fbb2ba0ffc671dfa0622058bc11957f275ebb865;p=melted_gui diff --git a/src/ui.c b/src/ui.c index ef556b7..e0541c9 100644 --- a/src/ui.c +++ b/src/ui.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -35,6 +36,7 @@ #include "ui_buttons.h" #include "support.h" #include "timecode.h" +#include "playlist.h" typedef struct column_desc { @@ -57,7 +59,7 @@ static const column_desc_t playlist_columns[] = G_TYPE_STRING }, { - "ID", + "TITLE", G_TYPE_STRING }, { @@ -69,7 +71,7 @@ static const column_desc_t playlist_columns[] = G_TYPE_STRING }, { - "TITLE", + "ID", G_TYPE_STRING }, { @@ -861,3 +863,286 @@ void ui_playlist_draw_item_rem(instance_t* app, int idx, char* rem) gdk_flush(); gdk_threads_leave(); }; + +void ui_playlist_select_item(instance_t* app, int idx) +{ + GtkTreePath* path; + + path = gtk_tree_path_new_from_indices(idx, -1); + + gtk_tree_selection_select_path(gtk_tree_view_get_selection(GTK_TREE_VIEW(app->playlist_grid)), path); + gtk_tree_view_set_cursor(GTK_TREE_VIEW(app->playlist_grid), path, NULL, FALSE); + gtk_tree_path_free(path); +}; + +void ui_playlist_draw(instance_t* app) +{ + int i; + int sel; + char tc1[12], tc2[12]; + GtkListStore *list_store; + GtkTreeIter iter; + + sel = playlist_get_first_selected_item_idx(app); + + list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(app->playlist_grid))); + gtk_list_store_clear(list_store); + + pthread_mutex_lock(&app->playlist.lock); + + for(i = 0;i < app->playlist.count; i++) + { + char ch[3]; + + if(PLAYLIST_BLOCK_BEGIN & app->playlist.item[i].type) + snprintf(ch, sizeof(ch), "%c", 'A' + app->playlist.item[i].player); + else + ch[0] = 0; + + gtk_list_store_append(list_store, &iter); + + gtk_list_store_set(list_store, &iter, + 0, "", + 1, app->playlist.block_icons[app->playlist.item[i].type], + 2, ch, + 3, app->playlist.item[i].title, + 4, frames2tc(app->playlist.item[i].in, 25.0, tc1), + 5, frames2tc(app->playlist.item[i].dur, 25.0, tc2), + 6, app->playlist.item[i].id, + 7, i, + 8, (app->playlist.item[i].error != 0), + 9, (app->playlist.item[i].error & PLAYLIST_ITEM_ERROR_LIB)?"red":"orange", + -1 ); + } + + app->playlist.ver_prev = app->playlist.ver_curr; + + if(sel >= 0) + ui_playlist_select_item(app, sel); + + pthread_mutex_unlock(&app->playlist.lock); +}; + +typedef struct ui_playlist_draw_item_desc +{ + GtkListStore *list_store; + instance_t* app; + int idx; +} ui_playlist_draw_item_t; + +static gboolean ui_playlist_draw_item_iter +( + GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + gpointer user_data +) +{ + int i; + char tc1[12], tc2[12]; + char ch[3]; + ui_playlist_draw_item_t* item = (ui_playlist_draw_item_t*)user_data; + instance_t* app = item->app; + + gtk_tree_model_get(model, iter, 7, &i, -1); + + if(i != item->idx) return FALSE; + + if(PLAYLIST_BLOCK_BEGIN & app->playlist.item[i].type) + snprintf(ch, sizeof(ch), "%c", 'A' + app->playlist.item[i].player); + else + ch[0] = 0; + + gtk_list_store_set(item->list_store, iter, + 0, "", + 1, app->playlist.block_icons[app->playlist.item[i].type], + 2, ch, + 3, app->playlist.item[i].title, + 4, frames2tc(app->playlist.item[i].in, 25.0, tc1), + 5, frames2tc(app->playlist.item[i].dur, 25.0, tc2), + 6, app->playlist.item[i].id, + 7, i, + 8, (app->playlist.item[i].error != 0), + 9, (app->playlist.item[i].error & PLAYLIST_ITEM_ERROR_LIB)?"red":"orange", + -1 ); + + return TRUE; +}; + +void ui_playlist_draw_item(instance_t* app, int idx) +{ + GtkListStore *list_store; + ui_playlist_draw_item_t item; + + list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(app->playlist_grid))); + + pthread_mutex_lock(&app->playlist.lock); + + item.idx = idx; + item.app = app; + item.list_store = list_store; + gtk_tree_model_foreach(GTK_TREE_MODEL(list_store), ui_playlist_draw_item_iter, &item); + + pthread_mutex_unlock(&app->playlist.lock); +}; + +void ui_set_status(instance_t* app, char* str, int lock) +{ + if(lock) + gdk_threads_enter(); + gtk_label_set_text(GTK_LABEL(app->status_label), str); + gdk_flush(); + if(lock) + gdk_threads_leave(); +}; + +void ui_show_error(GtkWidget *window, char* title, char* message) +{ + GtkWidget *dialog; + dialog = gtk_message_dialog_new + ( + GTK_WINDOW(window), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + message + ); + + gtk_window_set_title(GTK_WINDOW(dialog), title); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); +}; + +int ui_playlist_load(instance_t* app, char* path, struct ui_playlist_io_funcs* procs) +{ + int r, i; + GtkWidget *dialog; + GtkFileFilter *filter; + char error_message[1024]; + + dialog = gtk_file_chooser_dialog_new("Open File", + GTK_WINDOW (app->window), + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path); + + for(i = 0; procs[i].title; i++) + { + filter = gtk_file_filter_new(); + gtk_file_filter_set_name(filter, procs[i].title); + gtk_file_filter_add_pattern(filter, procs[i].ext); + g_object_set_data(G_OBJECT(filter), "id", GINT_TO_POINTER(i)); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filter); + }; + + r = gtk_dialog_run(GTK_DIALOG(dialog)); + + if(r == GTK_RESPONSE_ACCEPT) + { + int l; + char *filename, *filename2; + + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + + i = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog))), "id")); + + filename2 = (char*)malloc(PATH_MAX); + strncpy(filename2, filename, PATH_MAX); + l = strlen(filename2); + if(l < 4 || strcasecmp(filename2 + l - 4, procs[i].ext + 1)) + strcat(filename2, procs[i].ext + 1); + + r = procs[i].load(app, filename2, error_message, sizeof(error_message)); + + if(r) + ui_show_error(dialog, "Playlist loading error", error_message); + + free(filename2); + + ui_playlist_draw(app); + + if(app->playlist.path) + g_free(app->playlist.path); + if((app->playlist.path = filename)) + { + char* e = strrchr(app->playlist.path, '/'); + if(e) *e = 0; + } + } + else + r = -1; + + gtk_widget_destroy (dialog); + + return r; +}; + +int ui_playlist_save(instance_t* app, char* path, struct ui_playlist_io_funcs* procs) +{ + int r, i; + GtkWidget *dialog; + GtkFileFilter *filter; + char error_message[1024]; + + dialog = gtk_file_chooser_dialog_new("Save File", + GTK_WINDOW (app->window), + GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, + NULL); + + gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); + + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path); + + for(i = 0; procs[i].title; i++) + { + filter = gtk_file_filter_new(); + gtk_file_filter_set_name(filter, procs[i].title); + gtk_file_filter_add_pattern(filter, procs[i].ext); + g_object_set_data(G_OBJECT(filter), "id", GINT_TO_POINTER(i)); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER (dialog), filter); + }; + + r = gtk_dialog_run(GTK_DIALOG(dialog)); + + if(r == GTK_RESPONSE_ACCEPT) + { + int l; + char *filename, *filename2; + + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + + i = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(dialog))), "id")); + + filename2 = (char*)malloc(PATH_MAX); + strncpy(filename2, filename, PATH_MAX); + l = strlen(filename2); + if(l < 4 || strcasecmp(filename2 + l - 4, procs[i].ext + 1)) + strcat(filename2, procs[i].ext + 1); + + r = procs[i].save(app, filename2, error_message, sizeof(error_message)); + + if(r) + ui_show_error(dialog, "Playlist saving error", error_message); + + free(filename2); + + if(app->playlist.path) + g_free(app->playlist.path); + if((app->playlist.path = filename)) + { + char* e = strrchr(app->playlist.path, '/'); + if(e) *e = 0; + } + } + else + r = -1; + + gtk_widget_destroy (dialog); + + return r; +};