#include "ui_buttons.h"
#include "support.h"
#include "timecode.h"
+#include "playlist.h"
typedef struct column_desc
{
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;
+};