From: Maksym Veremeyenko Date: Tue, 3 Jul 2012 07:53:17 +0000 (+0300) Subject: minimal working library X-Git-Url: http://research.m1stereo.tv/gitweb?a=commitdiff_plain;h=fbb2ba0ffc671dfa0622058bc11957f275ebb865;p=melted_gui minimal working library --- diff --git a/src/instance.h b/src/instance.h index 99b3de6..dab8930 100644 --- a/src/instance.h +++ b/src/instance.h @@ -156,6 +156,9 @@ typedef struct instance_desc struct { void* handle[2]; + GdkPixbuf *icons[8]; + + playlist_item_t item[MAX_LIBRARY_ITEMS]; int count; char filename[PATH_MAX]; diff --git a/src/library.c b/src/library.c index 0ca9e38..bbda4b8 100644 --- a/src/library.c +++ b/src/library.c @@ -46,6 +46,89 @@ void library_release(instance_t* app) mvcp_parser_close(app->library.handle[1]); }; + +static int library_load_node(instance_t* app, GtkTreeStore *tree_store, GtkTreeIter* parent, char* path) +{ + int i; + GtkTreeIter iter; + mvcp_dir_entry_t entry; + mvcp_dir dir = mvcp_dir_init(app->library.handle[0], path); + + for (i = 0; i < mvcp_dir_count(dir); i++) + { + if(mvcp_ok != mvcp_dir_get(dir, i, &entry)) + continue; + + g_warning("library_load_node: path=[%s], entry.dur=[%d], entry.full=[%s], entry.name[%s]", + path, entry.dir, entry.full, entry.name); + + if(entry.dir) + { + gtk_tree_store_prepend(tree_store, &iter, parent); + + gtk_tree_store_set(tree_store, &iter, + 0, app->library.icons[0], + 1, "", + 2, entry.name, + 3, NULL, + 4, NULL, + 5, FALSE, + 6, "red", + -1 ); + + library_load_node(app, tree_store, &iter, entry.full); + } + else + { + gtk_tree_store_append(tree_store, &iter, parent); + + gtk_tree_store_set(tree_store, &iter, + 0, app->library.icons[1], + 1, "", + 2, entry.name, + 3, NULL, + 4, NULL, + 5, FALSE, + 6, "red", + -1 ); + }; + }; + + return 0; +}; + +static int library_init_load(instance_t* app) +{ + int i; + char tc[12]; + GtkTreeStore *tree_store; + GtkTreeIter iter; + + tree_store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(app->library_tree))); + gtk_tree_store_clear(tree_store); + +/* + gtk_tree_store_append(tree_store, &iter, NULL); + + gtk_tree_store_set(tree_store, &iter, + 0, NULL, + 1, "/", + 2, "", + 3, NULL, + 4, NULL, + 5, FALSE, + 6, "red", + -1 ); +*/ + + library_load_node(app, tree_store, NULL, "/home/studio/Videos"); + + gtk_tree_view_collapse_all(GTK_TREE_VIEW(app->library_tree)); + + return 0; +}; + + void library_init(instance_t* app) { /* connect to library */ @@ -56,6 +139,12 @@ void library_init(instance_t* app) g_warning("library_init: failed to connect to server %s", app->players.host); return; }; + + app->library.icons[0] = create_pixbuf("Axialis_Team_playlist_open_16x16.png"); + app->library.icons[1] = create_pixbuf("Axialis_Team_playlist_save_16x16.png"); + + library_init_load(app); + #if 0 pthread_mutex_lock(&app->library.lock); diff --git a/src/ui.c b/src/ui.c index 9ceebfe..ef556b7 100644 --- a/src/ui.c +++ b/src/ui.c @@ -81,15 +81,15 @@ static const column_desc_t playlist_columns[] = const static column_desc_t library_columns[] = { { - "ID", - G_TYPE_STRING + "TYPE", + G_TYPE_OBJECT }, { "DUR", G_TYPE_STRING }, { - "TITLE", + "NAME", G_TYPE_STRING }, { @@ -118,7 +118,7 @@ static GtkWidget* create_label(GtkWidget* top, char* text, char* reg, GtkJustifi 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; @@ -192,6 +192,81 @@ static GtkWidget* create_treeview(GtkWidget* top, char* name, const column_desc_ return treeview; }; +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; @@ -202,7 +277,7 @@ static GtkWidget* pane_library_tree(GtkWidget* top, instance_t* app) GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add (GTK_CONTAINER (scrolledwindow), - app->library_tree = create_treeview(top, "treeview_library", library_columns)); + app->library_tree = create_treeview_tree(top, "treeview_library", library_columns)); return scrolledwindow; } @@ -462,7 +537,7 @@ static GtkWidget* pane_operate_grid(GtkWidget* top, instance_t* app) 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; }