X-Git-Url: http://research.m1stereo.tv/gitweb?a=blobdiff_plain;f=src%2Fui.c;h=9ceebfe50de8193c4f1e59980e9b6309f3a00f5c;hb=8f058cdb606938af320e3ca33a7c10a14741a0d6;hp=ee736a3407d0230e0a5675229b5aa9421fab6d3c;hpb=767eb14d4a3d2ae37d4dddcb29ba61af74b81515;p=melted_gui diff --git a/src/ui.c b/src/ui.c index ee736a3..9ceebfe 100644 --- a/src/ui.c +++ b/src/ui.c @@ -1,6 +1,6 @@ /* - * ui.c -- GTK+ 2 omnplay - * Copyright (C) 2011 Maksym Veremeyenko + * ui.c -- GTK+ 2 melted gui + * Copyright (C) 2012 Maksym Veremeyenko * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -34,6 +34,70 @@ #include "ui_utils.h" #include "ui_buttons.h" #include "support.h" +#include "timecode.h" + +typedef struct column_desc +{ + char* title; + GType type; +} column_desc_t; + +static const column_desc_t playlist_columns[] = +{ + { + "REM", + G_TYPE_STRING + }, + { + "B", + G_TYPE_OBJECT + }, + { + "CH", + G_TYPE_STRING + }, + { + "ID", + G_TYPE_STRING + }, + { + "IN", + G_TYPE_STRING + }, + { + "DUR", + G_TYPE_STRING + }, + { + "TITLE", + G_TYPE_STRING + }, + { + NULL, + G_TYPE_STRING + } +}; + +const static column_desc_t library_columns[] = +{ + { + "ID", + G_TYPE_STRING + }, + { + "DUR", + G_TYPE_STRING + }, + { + "TITLE", + G_TYPE_STRING + }, + { + NULL, + G_TYPE_STRING + } +}; + static GtkWidget* create_label(GtkWidget* top, char* text, char* reg, GtkJustification jtype) { @@ -42,7 +106,8 @@ static GtkWidget* create_label(GtkWidget* top, char* text, char* reg, GtkJustifi label = gtk_label_new (""); gtk_widget_show (label); - gtk_label_set_justify (GTK_LABEL (label), jtype); + if(jtype) + gtk_label_set_justify (GTK_LABEL (label), jtype); if(reg) GLADE_HOOKUP_OBJECT (top, label, reg); @@ -53,44 +118,82 @@ static GtkWidget* create_label(GtkWidget* top, char* text, char* reg, GtkJustifi return label; }; -static GtkWidget* create_treeview(GtkWidget* top, char* name, const char* columns[]) +static GtkWidget* create_treeview(GtkWidget* top, char* name, const column_desc_t columns[]) { - int i; + int i, count; GtkWidget *treeview; + GtkTreeSelection *selection; GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkListStore *list_store; + GType list_store_types[32]; treeview = gtk_tree_view_new (); gtk_widget_show (treeview); + gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(treeview), TRUE); + gtk_tree_view_set_grid_lines(GTK_TREE_VIEW(treeview), GTK_TREE_VIEW_GRID_LINES_BOTH); + + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); + gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); + + for(i = 0, count = 0; columns[i].title; i++, count++) + list_store_types[i] = (columns[i].type == G_TYPE_OBJECT)?GDK_TYPE_PIXBUF:columns[i].type; + list_store_types[count] = G_TYPE_INT; + list_store_types[count + 1] = G_TYPE_BOOLEAN; + list_store_types[count + 2] = G_TYPE_STRING; + + list_store = gtk_list_store_newv(count + 3, list_store_types); - list_store = gtk_list_store_new(7, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING); gtk_tree_view_set_model( GTK_TREE_VIEW( treeview ), GTK_TREE_MODEL( list_store ) ); - for(i = 0; columns[i]; i++) + for(i = 0; columns[i].title; i++) { - renderer = gtk_cell_renderer_toggle_new(); - column = gtk_tree_view_column_new_with_attributes( - columns[i], renderer, "text", i, NULL); + char* prop; + column = NULL; + + if(columns[i].type == G_TYPE_OBJECT) + { + renderer = gtk_cell_renderer_pixbuf_new(); + gtk_cell_renderer_set_padding(renderer, 0, 0); + prop = "pixbuf"; + } + else if(columns[i].type == G_TYPE_BOOLEAN) + { + renderer = gtk_cell_renderer_toggle_new(); + prop = "active"; + } + else + { + renderer = gtk_cell_renderer_text_new(); + prop = "text"; + + column = gtk_tree_view_column_new_with_attributes( + columns[i].title, renderer, + prop, i, + "background-set", count + 1, + "background", count + 2, + NULL); + } + + if(!column) + column = gtk_tree_view_column_new_with_attributes( + columns[i].title, renderer, + prop, i, + NULL); + gtk_tree_view_append_column(GTK_TREE_VIEW( treeview ), column); }; + g_object_unref(list_store); + GLADE_HOOKUP_OBJECT (top, treeview, name); return treeview; }; -static GtkWidget* pane_library_grid(GtkWidget* top, omnplay_instance_t* app) +static GtkWidget* pane_library_tree(GtkWidget* top, instance_t* app) { - static const char* columns[] = {"ID", "DUR", "TITLE", NULL}; GtkWidget *scrolledwindow; scrolledwindow = gtk_scrolled_window_new (NULL, NULL); @@ -99,12 +202,12 @@ static GtkWidget* pane_library_grid(GtkWidget* top, omnplay_instance_t* app) GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add (GTK_CONTAINER (scrolledwindow), - app->library_grid = create_treeview(top, "treeview_library", columns)); + app->library_tree = create_treeview(top, "treeview_library", library_columns)); return scrolledwindow; } -static GtkWidget* pane_library_buttons(GtkWidget* top, omnplay_instance_t* app) +static GtkWidget* pane_library_buttons(GtkWidget* top, instance_t* app) { GtkWidget* hbox; @@ -127,7 +230,31 @@ static GtkWidget* pane_library_buttons(GtkWidget* top, omnplay_instance_t* app) return hbox; } -static GtkWidget* pane_library(GtkWidget* top, omnplay_instance_t* app) +static GtkWidget* pane_library_search_buttons(GtkWidget* top, instance_t* app) +{ + GtkWidget* hbox; + + hbox = gtk_hbox_new (FALSE, 0); + gtk_widget_show (hbox); + + /* text entry */ + gtk_box_pack_start (GTK_BOX (hbox), + app->library.search = gtk_entry_new(), + TRUE, TRUE, 0); + gtk_widget_show(app->library.search); + + /* playlist modify buttons */ + gtk_box_pack_start (GTK_BOX (hbox), + ui_create_button(top, app, BUTTON_LIBRARY_FIND), + FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (hbox), + ui_create_button(top, app, BUTTON_LIBRARY_FIND_NEXT), + FALSE, FALSE, 0); + + return hbox; +} + +static GtkWidget* pane_library(GtkWidget* top, instance_t* app) { GtkWidget* vbox; @@ -140,24 +267,32 @@ static GtkWidget* pane_library(GtkWidget* top, omnplay_instance_t* app) pane_library_buttons(top, app), FALSE, FALSE, 0); - /* add buttons box */ + /* add grid */ gtk_box_pack_start (GTK_BOX (vbox), - pane_library_grid(top, app), + pane_library_tree(top, app), TRUE, TRUE, 0); + /* add search buttons */ + gtk_box_pack_start (GTK_BOX (vbox), + pane_library_search_buttons(top, app), + FALSE, FALSE, 0); + return vbox; } -static GtkWidget* create_channel_status(GtkWidget* top, omnplay_instance_t* app, int idx) +static GtkWidget* create_channel_status(GtkWidget* top, instance_t* app, int idx) { GtkWidget* vbox; GtkWidget* hbox; GtkWidget* frame; - omnplay_player_t* player; + char name[PATH_MAX]; + player_t* player; player = &app->players.item[idx]; - frame = gtk_frame_new(player->name); + snprintf(name, sizeof(name), "unit %d [%c]", player->unit, idx + 'A'); + + frame = gtk_frame_new(name); gtk_widget_show(frame); vbox = gtk_vbox_new(FALSE, 0); @@ -218,7 +353,7 @@ static GtkWidget* create_channel_status(GtkWidget* top, omnplay_instance_t* app, return frame; } -static GtkWidget* pane_operate_status(GtkWidget* top, omnplay_instance_t* app) +static GtkWidget* pane_operate_status(GtkWidget* top, instance_t* app) { int i; GtkWidget* vbox; @@ -247,7 +382,7 @@ static GtkWidget* pane_operate_status(GtkWidget* top, omnplay_instance_t* app) return vbox; } -static GtkWidget* pane_operate_buttons_playlist(GtkWidget* top, omnplay_instance_t* app) +static GtkWidget* pane_operate_buttons_playlist(GtkWidget* top, instance_t* app) { GtkWidget* hbox; @@ -304,12 +439,21 @@ static GtkWidget* pane_operate_buttons_playlist(GtkWidget* top, omnplay_instance ui_create_button(top, app, BUTTON_PLAYLIST_ITEM_DOWN), FALSE, FALSE, 0); + /* spacer */ + gtk_box_pack_start (GTK_BOX (hbox), + create_label(top, " ", NULL, GTK_JUSTIFY_CENTER), + FALSE, FALSE, 0); + + /* playlist relink */ + gtk_box_pack_start (GTK_BOX (hbox), + ui_create_button(top, app, BUTTON_PLAYLIST_RELINK), + FALSE, FALSE, 0); + return hbox; } -static GtkWidget* pane_operate_grid(GtkWidget* top, omnplay_instance_t* app) +static GtkWidget* pane_operate_grid(GtkWidget* top, instance_t* app) { - static const char* columns[] = {"REM", "B", "CH", "ID", "IN", "DUR", "TITLE", NULL}; GtkWidget *scrolledwindow; scrolledwindow = gtk_scrolled_window_new (NULL, NULL); @@ -318,12 +462,12 @@ static GtkWidget* pane_operate_grid(GtkWidget* top, omnplay_instance_t* app) GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add (GTK_CONTAINER (scrolledwindow), - app->playlist_grid = create_treeview(top, "treeview_playlist", columns)); + app->playlist_grid = create_treeview(top, "treeview_playlist", playlist_columns)); return scrolledwindow; } -static GtkWidget* pane_operate_buttons_operate(GtkWidget* top, omnplay_instance_t* app) +static GtkWidget* pane_operate_buttons_operate(GtkWidget* top, instance_t* app) { GtkWidget* hbox; @@ -357,7 +501,7 @@ static GtkWidget* pane_operate_buttons_operate(GtkWidget* top, omnplay_instance_ return hbox; } -static GtkWidget* pane_operate_operate(GtkWidget* top, omnplay_instance_t* app) +static GtkWidget* pane_operate_operate(GtkWidget* top, instance_t* app) { GtkWidget* vbox; @@ -383,7 +527,7 @@ static GtkWidget* pane_operate_operate(GtkWidget* top, omnplay_instance_t* app) } -static GtkWidget* pane_operate(GtkWidget* top, omnplay_instance_t* app) +static GtkWidget* pane_operate(GtkWidget* top, instance_t* app) { GtkWidget* hbox; @@ -404,7 +548,7 @@ static GtkWidget* pane_operate(GtkWidget* top, omnplay_instance_t* app) }; -static GtkWidget* pane_top(GtkWidget* top, omnplay_instance_t* app) +static GtkWidget* pane_top(GtkWidget* top, instance_t* app) { GtkWidget* pane; @@ -424,18 +568,221 @@ static GtkWidget* pane_top(GtkWidget* top, omnplay_instance_t* app) return pane; } -GtkWidget* ui_omnplay (omnplay_instance_t* app) +GtkWidget* ui_create(instance_t* app) { GtkWidget *wnd; + GtkWidget* vbox; wnd = gtk_window_new (GTK_WINDOW_TOPLEVEL); - GLADE_HOOKUP_OBJECT_NO_REF (wnd, wnd, "omnplay_window"); + GLADE_HOOKUP_OBJECT_NO_REF (wnd, wnd, PACKAGE "_window"); - gtk_window_set_title (GTK_WINDOW (wnd), _("Omneon Player")); + gtk_window_set_title (GTK_WINDOW (wnd), _(PRODUCT_NAME)); gtk_window_set_default_size (GTK_WINDOW (wnd), 1024, 768); - gtk_container_add (GTK_CONTAINER (wnd), - pane_top(wnd, app)); + vbox = gtk_vbox_new(FALSE, 0); + gtk_widget_show(vbox); + + gtk_container_add(GTK_CONTAINER(wnd), vbox); + + gtk_box_pack_start (GTK_BOX (vbox), + pane_top(wnd, app), + TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox), + app->status_label = create_label(wnd, "started", NULL, GTK_JUSTIFY_LEFT), + FALSE, FALSE, 0); + + app->playlist.block_icons[PLAYLIST_ITEM_BLOCK_BEGIN] = + create_pixbuf("block_type_block_start_16x16.png"); + app->playlist.block_icons[PLAYLIST_ITEM_BLOCK_BODY] = + create_pixbuf("block_type_block_middle_16x16.png"); + app->playlist.block_icons[PLAYLIST_ITEM_BLOCK_END] = + create_pixbuf("block_type_block_end_16x16.png"); + app->playlist.block_icons[PLAYLIST_ITEM_BLOCK_SINGLE] = + create_pixbuf("block_type_block_single_16x16.png"); + app->playlist.block_icons[PLAYLIST_ITEM_LOOP_BEGIN] = + create_pixbuf("block_type_loop_start_16x16.png"); + app->playlist.block_icons[PLAYLIST_ITEM_LOOP_BODY] = + create_pixbuf("block_type_loop_middle_16x16.png"); + app->playlist.block_icons[PLAYLIST_ITEM_LOOP_END] = + create_pixbuf("block_type_loop_end_16x16.png"); + app->playlist.block_icons[PLAYLIST_ITEM_LOOP_SINGLE] = + create_pixbuf("block_type_block_loop_16x16.png"); return wnd; } + +int ui_playlist_item_dialog(instance_t* app, playlist_item_t* item) +{ + int r, c; + char tc[32]; + GtkWidget *dlg; + gint response; + GtkWidget *box, *table; + GtkWidget *entry[4], *combo; + + dlg = gtk_dialog_new_with_buttons( + "Playlist item", + GTK_WINDOW(app->window), + GTK_DIALOG_MODAL, + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, + NULL); + + box = gtk_dialog_get_content_area(GTK_DIALOG(dlg)); + + table = gtk_table_new(5, 2, TRUE); + gtk_widget_show(table); + gtk_box_pack_start(GTK_BOX(box), table, TRUE, TRUE, 0); + + gtk_table_attach(GTK_TABLE(table), + create_label(NULL, "ID:", NULL, 0), + 0, 1, 0, 1, + GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5); + + gtk_table_attach(GTK_TABLE(table), + create_label(NULL, "IN:", NULL, GTK_JUSTIFY_RIGHT), + 0, 1, 1, 2, + GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5); + + gtk_table_attach(GTK_TABLE(table), + create_label(NULL, "DUR:", NULL, GTK_JUSTIFY_RIGHT), + 0, 1, 2, 3, + GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5); + + gtk_table_attach(GTK_TABLE(table), + create_label(NULL, "TITLE:", NULL, GTK_JUSTIFY_RIGHT), + 0, 1, 3, 4, + GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5); + + gtk_table_attach(GTK_TABLE(table), + create_label(NULL, "CHANNEL:", NULL, GTK_JUSTIFY_RIGHT), + 0, 1, 4, 5, + GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5); + + + gtk_table_attach(GTK_TABLE(table), + entry[0] = gtk_entry_new_with_max_length(32), + 1, 2, 0, 1, + GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5); + + gtk_table_attach(GTK_TABLE(table), + entry[1] = gtk_entry_new_with_max_length(12), + 1, 2, 1, 2, + GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5); + + gtk_table_attach(GTK_TABLE(table), + entry[2] = gtk_entry_new_with_max_length(12), + 1, 2, 2, 3, + GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5); + + gtk_table_attach(GTK_TABLE(table), + entry[3] = gtk_entry_new_with_max_length(128), + 1, 2, 3, 4, + GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5); + + gtk_table_attach(GTK_TABLE(table), + combo = gtk_combo_box_new_text(), + 1, 2, 4, 5, + GTK_FILL/* | GTK_SHRINK */, GTK_FILL | GTK_SHRINK, 5, 5); + + + /* setup data */ + gtk_entry_set_text(GTK_ENTRY(entry[0]), item->id); + gtk_entry_set_text(GTK_ENTRY(entry[1]), frames2tc(item->in, 25.0, tc)); + gtk_entry_set_text(GTK_ENTRY(entry[2]), frames2tc(item->dur, 25.0, tc)); + gtk_entry_set_text(GTK_ENTRY(entry[3]), item->title); + gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "A"); + gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "B"); + gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "C"); + gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "D"); + gtk_combo_box_set_active(GTK_COMBO_BOX(combo), item->player); + + gtk_widget_show_all(dlg); + + /* Run dialog */ + for(c = 1; c;) + { + response = gtk_dialog_run(GTK_DIALOG(dlg)); + + if( GTK_RESPONSE_REJECT == response || + GTK_RESPONSE_DELETE_EVENT == response || + GTK_RESPONSE_CANCEL == response) + { + r = 0; + c = 0; + } + else + { + r = 1; + + /* get item data back */ + strncpy(item->id, gtk_entry_get_text(GTK_ENTRY(entry[0])), PATH_MAX); + tc2frames((char*)gtk_entry_get_text(GTK_ENTRY(entry[1])), 25.0, &item->in); + tc2frames((char*)gtk_entry_get_text(GTK_ENTRY(entry[2])), 25.0, &item->dur); + strncpy(item->title, gtk_entry_get_text(GTK_ENTRY(entry[3])), PATH_MAX); + item->player = gtk_combo_box_get_active(GTK_COMBO_BOX(combo)); + + /* check if all data entered correctly */ + if(item->id[0]) + c = 0; + }; + }; + + gtk_widget_hide(dlg); + gtk_widget_destroy(dlg); + + return r; +}; + +/********************************************************************************/ + +void ui_update_player(player_t* player, char *tc_cur, char *tc_rem, char *state, char *status, char *clip) +{ + /* update status in status page */ + gdk_threads_enter(); + gtk_label_set_text(GTK_LABEL (player->label_tc_cur), tc_cur); + gtk_label_set_text(GTK_LABEL (player->label_tc_rem), tc_rem); + gtk_label_set_text(GTK_LABEL (player->label_state), state); + gtk_label_set_text(GTK_LABEL (player->label_status), status); + gtk_label_set_text(GTK_LABEL (player->label_clip), clip); + gdk_flush(); + gdk_threads_leave(); +}; + +static gboolean ui_playlist_draw_item_rem_proc( + GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer user_data) +{ + int i; + void** args = (void**)user_data; + GtkListStore *list_store = (GtkListStore *)args[1]; + int idx = (int)args[2]; + char* rem = (char*)args[3]; + + gtk_tree_model_get(model, iter, 7, &i, -1); + + if(i != idx) return FALSE; + + gtk_list_store_set(list_store, iter, 0, rem, -1); + + return TRUE; +}; + +void ui_playlist_draw_item_rem(instance_t* app, int idx, char* rem) +{ + void* item[4]; + GtkListStore *list_store; + + gdk_threads_enter(); + + list_store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(app->playlist_grid))); + + item[0] = (void*)app; + item[1] = (void*)list_store; + item[2] = (void*)idx; + item[3] = (void*)rem; + + gtk_tree_model_foreach(GTK_TREE_MODEL(list_store), ui_playlist_draw_item_rem_proc, item); + + gdk_flush(); + gdk_threads_leave(); +};