/*
- * ui.c -- GTK+ 2 omnplay
- * Copyright (C) 2011 Maksym Veremeyenko <verem@m1stereo.tv>
+ * ui.c -- GTK+ 2 melted gui
+ * Copyright (C) 2012 Maksym Veremeyenko <verem@m1stereo.tv>
*
* 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
#include "ui_buttons.h"
#include "support.h"
#include "timecode.h"
+#include "playlist.h"
typedef struct column_desc
{
const static column_desc_t library_columns[] =
{
{
- "ID",
- G_TYPE_STRING
+ "TYPE",
+ G_TYPE_OBJECT
},
{
"DUR",
G_TYPE_STRING
},
{
- "TITLE",
+ "NAME",
G_TYPE_STRING
},
{
return label;
};
-static GtkWidget* create_treeview(GtkWidget* top, char* name, const column_desc_t columns[])
+static GtkWidget* create_treeview_list(GtkWidget* top, char* name, const column_desc_t columns[])
{
int i, count;
return treeview;
};
-static GtkWidget* pane_library_grid(GtkWidget* top, omnplay_instance_t* app)
+static GtkWidget* create_treeview_tree(GtkWidget* top, char* name, const column_desc_t columns[])
+{
+ int i, count;
+
+ GtkWidget *treeview;
+ GtkTreeSelection *selection;
+ GtkCellRenderer *renderer;
+ GtkTreeViewColumn *column;
+ GtkTreeStore *tree_store;
+ GType tree_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++)
+ tree_store_types[i] = (columns[i].type == G_TYPE_OBJECT)?GDK_TYPE_PIXBUF:columns[i].type;
+ tree_store_types[count + 0] = G_TYPE_POINTER;
+ tree_store_types[count + 1] = G_TYPE_POINTER;
+ tree_store_types[count + 2] = G_TYPE_BOOLEAN;
+ tree_store_types[count + 3] = G_TYPE_STRING;
+
+ tree_store = gtk_tree_store_newv(count + 4, tree_store_types);
+
+ gtk_tree_view_set_model( GTK_TREE_VIEW( treeview ), GTK_TREE_MODEL( tree_store ) );
+
+ for(i = 0; columns[i].title; i++)
+ {
+ 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 + 2,
+ "background", count + 3,
+ 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(tree_store);
+
+ GLADE_HOOKUP_OBJECT (top, treeview, name);
+
+ return treeview;
+};
+
+static GtkWidget* pane_library_tree(GtkWidget* top, instance_t* app)
{
GtkWidget *scrolledwindow;
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (scrolledwindow),
- app->library_grid = create_treeview(top, "treeview_library", library_columns));
+ app->library_tree = create_treeview_tree(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;
return hbox;
}
-static GtkWidget* pane_library_search_buttons(GtkWidget* top, omnplay_instance_t* app)
+static GtkWidget* pane_library_search_buttons(GtkWidget* top, instance_t* app)
{
GtkWidget* hbox;
return hbox;
}
-static GtkWidget* pane_library(GtkWidget* top, omnplay_instance_t* app)
+static GtkWidget* pane_library(GtkWidget* top, instance_t* app)
{
GtkWidget* vbox;
/* 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 */
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;
char name[PATH_MAX];
- omnplay_player_t* player;
+ player_t* player;
player = &app->players.item[idx];
- snprintf(name, sizeof(name), "%c [%s]", idx + 'A', player->name);
+ snprintf(name, sizeof(name), "unit %d [%c]", player->unit, idx + 'A');
frame = gtk_frame_new(name);
gtk_widget_show(frame);
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;
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;
return hbox;
}
-static GtkWidget* pane_operate_grid(GtkWidget* top, omnplay_instance_t* app)
+static GtkWidget* pane_operate_grid(GtkWidget* top, instance_t* app)
{
GtkWidget *scrolledwindow;
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_container_add (GTK_CONTAINER (scrolledwindow),
- app->playlist_grid = create_treeview(top, "treeview_playlist", playlist_columns));
+ app->playlist_grid = create_treeview_list(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;
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;
}
-static GtkWidget* pane_operate(GtkWidget* top, omnplay_instance_t* app)
+static GtkWidget* pane_operate(GtkWidget* top, instance_t* app)
{
GtkWidget* hbox;
};
-static GtkWidget* pane_top(GtkWidget* top, omnplay_instance_t* app)
+static GtkWidget* pane_top(GtkWidget* top, instance_t* app)
{
GtkWidget* pane;
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);
vbox = gtk_vbox_new(FALSE, 0);
pane_top(wnd, app),
TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (vbox),
- app->status_label = create_label(wnd, "omnplay started", NULL, GTK_JUSTIFY_LEFT),
+ app->status_label = create_label(wnd, "started", NULL, GTK_JUSTIFY_LEFT),
FALSE, FALSE, 0);
- app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_BLOCK_BEGIN] =
+ app->playlist.block_icons[PLAYLIST_ITEM_BLOCK_BEGIN] =
create_pixbuf("block_type_block_start_16x16.png");
- app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_BLOCK_BODY] =
+ app->playlist.block_icons[PLAYLIST_ITEM_BLOCK_BODY] =
create_pixbuf("block_type_block_middle_16x16.png");
- app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_BLOCK_END] =
+ app->playlist.block_icons[PLAYLIST_ITEM_BLOCK_END] =
create_pixbuf("block_type_block_end_16x16.png");
- app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_BLOCK_SINGLE] =
+ app->playlist.block_icons[PLAYLIST_ITEM_BLOCK_SINGLE] =
create_pixbuf("block_type_block_single_16x16.png");
- app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_LOOP_BEGIN] =
+ app->playlist.block_icons[PLAYLIST_ITEM_LOOP_BEGIN] =
create_pixbuf("block_type_loop_start_16x16.png");
- app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_LOOP_BODY] =
+ app->playlist.block_icons[PLAYLIST_ITEM_LOOP_BODY] =
create_pixbuf("block_type_loop_middle_16x16.png");
- app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_LOOP_END] =
+ app->playlist.block_icons[PLAYLIST_ITEM_LOOP_END] =
create_pixbuf("block_type_loop_end_16x16.png");
- app->playlist.block_icons[OMNPLAY_PLAYLIST_ITEM_LOOP_SINGLE] =
+ app->playlist.block_icons[PLAYLIST_ITEM_LOOP_SINGLE] =
create_pixbuf("block_type_block_loop_16x16.png");
return wnd;
}
-int ui_playlist_item_dialog(omnplay_instance_t* app, playlist_item_t* item)
+int ui_playlist_item_dialog(instance_t* app, playlist_item_t* item)
{
int r, c;
char tc[32];
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();
+};
+
+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);
+};
+
+void ui_set_status(instance_t* app, char* str)
+{
+ gdk_threads_enter();
+ gtk_label_set_text(GTK_LABEL(app->status_label), str);
+ gdk_flush();
+ gdk_threads_leave();
+};
+
+int ui_playlist_load(instance_t* app, char* path, struct ui_playlist_io_funcs* procs)
+{
+ int r, i;
+
+ GtkWidget *dialog;
+ GtkFileFilter *filter;
+
+ 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)
+ {
+ char *filename;
+
+ 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"));
+
+ r = procs[i].load(app, filename);
+
+ 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;
+
+ 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)
+ {
+ char *filename;
+
+ 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"));
+
+ r = procs[i].save(app, filename);
+
+ 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;
+};