X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fui.c;fp=src%2Fui.c;h=b7c230ea162948c9d430124add7bee0f6860f773;hb=cfbef984de0dc53c8b882d7706556656b9934de2;hp=ef556b759862d362a0cffe9aca1f9ca843a59379;hpb=07c6d84a23c9043e2334987fc8533f68e5e23183;p=melted_gui diff --git a/src/ui.c b/src/ui.c index ef556b7..b7c230e 100644 --- a/src/ui.c +++ b/src/ui.c @@ -35,6 +35,7 @@ #include "ui_buttons.h" #include "support.h" #include "timecode.h" +#include "playlist.h" typedef struct column_desc { @@ -861,3 +862,125 @@ 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].id, + 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].title, + 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].id, + 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].title, + 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); +};