ocarina: Support removing library paths
Use the "Delete" key for now. I also added in using the plus key to add new paths. Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
parent
6e97f04e85
commit
537dc3a22d
|
@ -40,9 +40,9 @@ namespace ocarina
|
|||
|
||||
void goto_index(unsigned int);
|
||||
|
||||
void insert_prepare();
|
||||
void modify_prepare();
|
||||
void insert(libsaria::Track *, unsigned int);
|
||||
void insert_done();
|
||||
void modify_done();
|
||||
|
||||
void remove_index(unsigned int);
|
||||
};
|
||||
|
|
|
@ -22,6 +22,7 @@ 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;
|
||||
|
@ -35,25 +36,33 @@ static struct library_info columns[] = {
|
|||
|
||||
static unsigned int NUM_COLUMNS = sizeof(columns) / sizeof(library_info);
|
||||
|
||||
void LibraryDriver::path_updated(libsaria::library::Path *path)
|
||||
static bool find_path(libsaria::library::Path *path, GtkTreeIter *iter)
|
||||
{
|
||||
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;
|
||||
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) {
|
||||
gtk_list_store_set(path_list, &iter,
|
||||
1, path->path.c_str(),
|
||||
2, path->tracks.size(),
|
||||
-1);
|
||||
break;
|
||||
};
|
||||
} while (gtk_tree_model_iter_next(GTK_TREE_MODEL(path_list), &iter));
|
||||
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->path.c_str(),
|
||||
2, path->tracks.size(),
|
||||
-1);
|
||||
}
|
||||
|
||||
void LibraryDriver::path_added(libsaria::library::Path *path)
|
||||
|
@ -68,6 +77,14 @@ void LibraryDriver::path_added(libsaria::library::Path *path)
|
|||
-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, GdkEvent *e, gpointer d)
|
||||
{
|
||||
string dir = ocarina::choose_dir();
|
||||
|
@ -82,6 +99,52 @@ static void on_click_update(GtkWidget *b, GdkEvent *e, 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);
|
||||
}
|
||||
|
||||
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 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, NULL);
|
||||
else
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GtkWidget *button_row()
|
||||
{
|
||||
GtkWidget *button_row = gtk_vbox_new(FALSE, 0);
|
||||
|
@ -131,6 +194,9 @@ namespace ocarina
|
|||
|
||||
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,
|
||||
|
|
|
@ -13,7 +13,7 @@ static string formatted(string str)
|
|||
namespace ocarina
|
||||
{
|
||||
|
||||
void Playlist::insert_prepare()
|
||||
void Playlist::modify_prepare()
|
||||
{
|
||||
gtk_widget_freeze_child_notify(treeview);
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ namespace ocarina
|
|||
-1);
|
||||
}
|
||||
|
||||
void Playlist::insert_done()
|
||||
void Playlist::modify_done()
|
||||
{
|
||||
gtk_widget_thaw_child_notify(treeview);
|
||||
set_label_text();
|
||||
|
|
|
@ -14,7 +14,12 @@ using namespace std;
|
|||
static void new_playlist(ocarina::Playlist *plist, PlaylistType type)
|
||||
{
|
||||
list<libsaria::Track *> tracks;
|
||||
|
||||
plist->list_selected_tracks(tracks);
|
||||
if (tracks.size() == 0)
|
||||
return;
|
||||
|
||||
plist->select_none();
|
||||
libsaria::create_new_playlist(tracks, type);
|
||||
/*
|
||||
* The new playlist will set the length string text,
|
||||
|
@ -61,8 +66,6 @@ gboolean key_pressed(GtkWidget *widget, GdkEvent *event, gpointer data)
|
|||
else if (key == "q" || key == "Q")
|
||||
new_playlist(plist, PLIST_QUEUE);
|
||||
else if (key >= "0" && key <= "9") {
|
||||
if (!(event->key.state & GDK_MOD1_MASK))
|
||||
return FALSE;
|
||||
list<libsaria::Track *> tracks;
|
||||
unsigned int k;
|
||||
stringstream s(key);
|
||||
|
|
|
@ -85,8 +85,6 @@ static gboolean key_pressed(GtkWidget *widget, GdkEvent *event, gpointer data)
|
|||
libsaria::deck::prev();
|
||||
else if (key == "space")
|
||||
libsaria::audio::toggle_play();
|
||||
else if (key == "Escape")
|
||||
gtk_widget_grab_focus(win);
|
||||
else
|
||||
return FALSE;
|
||||
return TRUE;
|
||||
|
@ -102,8 +100,12 @@ static gboolean key_pressed_after(GtkWidget *widget, GdkEvent *event, gpointer d
|
|||
stringstream s(key);
|
||||
s >> k;
|
||||
ocarina::playlist::switch_to_plist(k);
|
||||
} else
|
||||
} else if (key == "Escape")
|
||||
gtk_widget_grab_focus(win);
|
||||
else {
|
||||
println("Unhandled key: " + key);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue