ocarina: Created treeview and liststore
Track information will be stored in these structures. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
abac8883c3
commit
50f2f99074
|
@ -12,7 +12,11 @@ namespace ocarina
|
|||
private:
|
||||
GtkWidget *label;
|
||||
GtkWidget *box;
|
||||
GtkWidget *treeview;
|
||||
GtkListStore *liststore;
|
||||
|
||||
void set_label_text();
|
||||
void setup_treeview();
|
||||
|
||||
public:
|
||||
Playlist(unsigned int);
|
||||
|
|
|
@ -34,8 +34,11 @@ namespace ocarina
|
|||
|
||||
label = gtk_label_new("");
|
||||
box = gtk_vbox_new(FALSE, 0);
|
||||
|
||||
setup_treeview();
|
||||
|
||||
gtk_widget_show(label);
|
||||
gtk_widget_show(box);
|
||||
gtk_widget_show_all(box);
|
||||
|
||||
set_label_text();
|
||||
body::push_page(box, label);
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
// Copyright (c) 2012 Bryan Schumaker
|
||||
#include <ocarina/playlist.h>
|
||||
|
||||
struct column_info {
|
||||
const char *name;
|
||||
int width;
|
||||
bool visible;
|
||||
GType type;
|
||||
|
||||
column_info(const char *n, GType t, int w, bool v)
|
||||
{
|
||||
name = n;
|
||||
width = w;
|
||||
visible = v;
|
||||
type = t;
|
||||
}
|
||||
};
|
||||
|
||||
static struct column_info columns[] = {
|
||||
column_info( "Pointer", G_TYPE_POINTER, 2, false),
|
||||
column_info( "#", G_TYPE_INT, 20, true),
|
||||
column_info( "Title", G_TYPE_STRING, 300, true),
|
||||
column_info( "Length", G_TYPE_STRING, 60, true),
|
||||
column_info( "Artist", G_TYPE_STRING, 125, true),
|
||||
column_info( "Album", G_TYPE_STRING, 125, true),
|
||||
column_info( "Year", G_TYPE_INT, 50, true),
|
||||
column_info("Filepath", G_TYPE_STRING, 2, false),
|
||||
};
|
||||
|
||||
#define NUM_COLUMNS (sizeof(columns) / sizeof(column_info))
|
||||
|
||||
static GtkListStore *setup_liststore(GtkWidget *treeview)
|
||||
{
|
||||
GtkListStore *liststore;
|
||||
GtkTreeViewColumn *col;
|
||||
GtkCellRenderer *textcell = gtk_cell_renderer_text_new();
|
||||
GType types[NUM_COLUMNS];
|
||||
|
||||
for (unsigned int i = 0; i < NUM_COLUMNS; i++)
|
||||
types[i] = columns[i].type;
|
||||
|
||||
liststore = gtk_list_store_newv(NUM_COLUMNS, types);
|
||||
gtk_cell_renderer_text_set_fixed_height_from_font(GTK_CELL_RENDERER_TEXT(textcell), 1);
|
||||
|
||||
for (unsigned int i = 0; i < NUM_COLUMNS; i++) {
|
||||
if (columns[i].type == G_TYPE_POINTER)
|
||||
continue;
|
||||
col = gtk_tree_view_column_new_with_attributes(columns[i].name,
|
||||
textcell,
|
||||
"text", i,
|
||||
NULL);
|
||||
gtk_tree_view_column_set_resizable(col, TRUE);
|
||||
gtk_tree_view_column_set_sizing(col, GTK_TREE_VIEW_COLUMN_FIXED);
|
||||
gtk_tree_view_column_set_min_width(col, 2);
|
||||
gtk_tree_view_column_set_max_width(col, 700);
|
||||
gtk_tree_view_column_set_fixed_width(col, columns[i].width);
|
||||
gtk_tree_view_column_set_visible(col, columns[i].visible);
|
||||
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), col);
|
||||
};
|
||||
|
||||
gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(liststore));
|
||||
return liststore;
|
||||
}
|
||||
|
||||
namespace ocarina
|
||||
{
|
||||
|
||||
void Playlist::setup_treeview()
|
||||
{
|
||||
GtkWidget *scroll_win = gtk_scrolled_window_new(NULL, NULL);
|
||||
|
||||
treeview = gtk_tree_view_new();
|
||||
liststore = setup_liststore(treeview);
|
||||
|
||||
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll_win),
|
||||
GTK_POLICY_AUTOMATIC,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
gtk_container_add(GTK_CONTAINER(scroll_win), treeview);
|
||||
gtk_box_pack_start(GTK_BOX(box), scroll_win, TRUE, TRUE, 0);
|
||||
}
|
||||
|
||||
}; /* Namespace: ocarina */
|
Loading…
Reference in New Issue