ocarina: Remove old library.cpp

I've re-implemented everything here with GtkBuilder, so this file is now
obsolete.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-08-13 08:21:11 -04:00
parent 01d8eb15d8
commit 22694e1bfe
1 changed files with 0 additions and 244 deletions

View File

@ -1,244 +0,0 @@
// Copyright (c) 2012 Bryan Schumaker
#include <libsaria/library.h>
#include <ocarina/ocarina.h>
#include <ocarina/chooser.h>
#include <ocarina/body.h>
struct library_info {
const char *name;
GType type;
bool visible;
library_info(const char *n, GType t, bool v)
{
name = n;
type = t;
visible = v;
}
};
/*class LibraryDriver : public libsaria::library::Driver {
public:
void path_added(libsaria::library::Path *);
void path_updated(libsaria::library::Path *);
void path_removed(libsaria::library::Path *);
};
static LibraryDriver driver;*/
static GtkListStore *path_list;
static struct library_info columns[] = {
library_info("Enabled", G_TYPE_BOOLEAN, true),
library_info("Filepath", G_TYPE_STRING, true),
library_info("Size", G_TYPE_UINT, true),
};
static unsigned int NUM_COLUMNS = sizeof(columns) / sizeof(library_info);
/*static bool find_path(libsaria::library::Path *path, GtkTreeIter *iter)
{
libsaria::library::Path *list_path;*/
/* get_iter_first() return FALSE if the liststore is empty */
/* if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(path_list), iter))
return false;
do {
gtk_tree_model_get(GTK_TREE_MODEL(path_list), iter, 0, &list_path, -1);
if (list_path == path)
return true;
} while (gtk_tree_model_iter_next(GTK_TREE_MODEL(path_list), iter));
return false;
}*/
/*void LibraryDriver::path_updated(libsaria::library::Path *path)
{
GtkTreeIter iter;
if (!find_path(path, &iter))
return;
gtk_list_store_set(path_list, &iter,
1, path->visible,
2, path->path.c_str(),
3, path->tracks.size(),
-1);
}
void LibraryDriver::path_added(libsaria::library::Path *path)
{
GtkTreeIter iter;
println("Path added: " + path->path);
gtk_list_store_append(path_list, &iter);
gtk_list_store_set(path_list, &iter,
0, path,
1, path->visible,
2, path->path.c_str(),
3, path->tracks.size(),
-1);
}
void LibraryDriver::path_removed(libsaria::library::Path *path)
{
GtkTreeIter iter;
if (!find_path(path, &iter))
return;
gtk_list_store_remove(path_list, &iter);
}*/
static void on_click_add(GtkWidget *b, gpointer d)
{
string dir = ocarina::choose_dir();
if (dir != "") {
println("Scanning dir: " + dir);
libsaria::library::add_path(dir);
}
}
/*static void on_click_update(GtkWidget *b, gpointer d)
{
println("Update button clicked");
}*/
static void row_activated(GtkWidget *treeview, GtkTreePath *path,
GtkTreeViewColumn *col, gpointer data)
{
GtkTreeIter iter;
libsaria::library::Path *ls_path;
gtk_tree_model_get_iter(GTK_TREE_MODEL(path_list), &iter, path);
gtk_tree_model_get(GTK_TREE_MODEL(path_list), &iter, 0, &ls_path, -1);
libsaria::library::update_path(ls_path);
}
static libsaria::library::Path *get_selected_path(GtkWidget *treeview)
{
GtkTreeIter iter;
GtkTreeModel *model = GTK_TREE_MODEL(path_list);
GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
libsaria::library::Path *path;
if (!gtk_tree_selection_get_selected(sel, &model, &iter))
return NULL;
gtk_tree_model_get(model, &iter, 0, &path, -1);
return path;
}
static void path_toggled(GtkCellRendererToggle *toggle, gchar *path, gpointer data)
{
GtkTreeIter iter;
libsaria::library::Path *lib_path = NULL;
if (!gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(path_list), &iter, path))
return;
gtk_tree_model_get(GTK_TREE_MODEL(path_list), &iter, 0, &lib_path, -1);
if (gtk_cell_renderer_toggle_get_active(toggle))
libsaria::library::hide_path(lib_path);
else
libsaria::library::show_path(lib_path);
}
static void show_rc_menu(GtkWidget *widget, GdkEvent *event, gpointer data)
{
}
static gboolean key_pressed(GtkWidget *treeview, GdkEvent *event, gpointer data)
{
libsaria::library::Path *path;
string key = gdk_keyval_name(event->key.keyval);
println("Library settings handling key press: " + key);
path = get_selected_path(treeview);
if (!path)
return FALSE;
if (key == "Delete")
libsaria::library::delete_path(path);
else if (key == "plus" || key == "KP_Add")
on_click_add(NULL, NULL);
else
return FALSE;
return TRUE;
}
static GtkWidget *button_row()
{
GtkWidget *button_row = gtk_vbox_new(FALSE, 0);
//GtkWidget *add = make_button(GTK_STOCK_ADD, on_click_add, true);
//GtkWidget *update = make_button(GTK_STOCK_REFRESH, on_click_update, true);
//gtk_widget_set_tooltip_text(add, "Add path to library");
//gtk_widget_set_tooltip_text(update, "Update all library paths");
//gtk_box_pack_start(GTK_BOX(button_row), add, FALSE, FALSE, 0);
//gtk_box_pack_start(GTK_BOX(button_row), update, FALSE, FALSE, 0);
return button_row;
}
static void setup_liststore(GtkWidget *treeview)
{
GtkTreeViewColumn *col;
GtkCellRenderer *textcell = gtk_cell_renderer_text_new();
GtkCellRenderer *checkcell = gtk_cell_renderer_toggle_new();
GType types[NUM_COLUMNS + 1];
types[0] = G_TYPE_POINTER;
for (unsigned int i = 0; i < NUM_COLUMNS; i++)
types[i + 1] = columns[i].type;
path_list = gtk_list_store_newv(NUM_COLUMNS + 1, types);
gtk_cell_renderer_text_set_fixed_height_from_font(GTK_CELL_RENDERER_TEXT(textcell), 1);
g_signal_connect(checkcell, "toggled", G_CALLBACK(path_toggled), NULL);
for (unsigned int i = 0; i < NUM_COLUMNS; i++) {
string attribute;
GtkCellRenderer *renderer;
if (columns[i].type == G_TYPE_BOOLEAN) {
renderer = checkcell;
attribute = "active";
} else {
renderer = textcell;
attribute = "text";
}
col = gtk_tree_view_column_new_with_attributes(columns[i].name,
renderer,
attribute.c_str(),
i + 1,
NULL);
gtk_tree_view_column_set_visible(col, columns[i].visible);
gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), col);
}
}
namespace ocarina
{
GtkWidget *body::library_page()
{
GtkWidget *box = gtk_hbox_new(FALSE, 0);
GtkWidget *scroll_win = gtk_scrolled_window_new(NULL, NULL);
GtkWidget *treeview = gtk_tree_view_new();
setup_liststore(treeview);
gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(path_list));
g_signal_connect(treeview, "row-activated", G_CALLBACK(row_activated), NULL);
g_signal_connect(treeview, "button-release-event", G_CALLBACK(show_rc_menu), NULL);
g_signal_connect(treeview, "key-press-event", G_CALLBACK(key_pressed), NULL);
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);
gtk_box_pack_start(GTK_BOX(box), button_row(), FALSE, FALSE, 0);
gtk_widget_show_all(box);
return box;
}
}; /* Namespace: ocarina */