2016-01-19 10:16:26 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
|
|
*/
|
2016-01-20 09:16:01 -05:00
|
|
|
#include <core/audio.h>
|
2016-01-21 08:13:14 -05:00
|
|
|
#include <core/playlist.h>
|
2016-03-29 08:39:00 -04:00
|
|
|
#include <core/settings.h>
|
2016-01-19 10:16:26 -05:00
|
|
|
#include <gui/builder.h>
|
2016-08-21 10:27:52 -04:00
|
|
|
#include <gui/filter.h>
|
2016-08-26 10:19:45 -04:00
|
|
|
#include <gui/model.h>
|
2016-09-01 09:22:59 -04:00
|
|
|
#include <gui/playlist.h>
|
2016-08-23 07:41:27 -04:00
|
|
|
#include <gui/treeview.h>
|
2016-01-21 15:18:37 -05:00
|
|
|
#include <gui/view.h>
|
2016-08-19 08:06:16 -04:00
|
|
|
#include <gui/window.h>
|
2016-08-16 08:06:48 -04:00
|
|
|
#include <glib/gi18n.h>
|
2016-01-22 13:37:22 -05:00
|
|
|
#include <stdlib.h>
|
2016-01-19 10:16:26 -05:00
|
|
|
|
|
|
|
static GtkTreeView *view_treeview = NULL;
|
2016-01-20 09:16:01 -05:00
|
|
|
|
2016-08-16 08:06:48 -04:00
|
|
|
struct view_add_data {
|
|
|
|
enum playlist_type_t vad_type;
|
2016-08-18 08:40:32 -04:00
|
|
|
const gchar *vad_name;
|
2016-08-16 08:06:48 -04:00
|
|
|
};
|
|
|
|
|
2016-01-21 08:13:14 -05:00
|
|
|
static void __view_add_to_playlist(GtkTreeModel *model, GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter, gpointer data)
|
|
|
|
{
|
2016-08-16 08:06:48 -04:00
|
|
|
struct view_add_data *vad = (struct view_add_data *)data;
|
2016-08-21 12:49:07 -04:00
|
|
|
playlist_add(vad->vad_type, vad->vad_name, gui_filter_path_get_track(path));
|
2016-01-21 08:13:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __view_delete_selection(GtkTreeSelection *selection)
|
|
|
|
{
|
2016-08-20 21:01:19 -04:00
|
|
|
struct playlist *playlist = gui_model_get_playlist();
|
|
|
|
struct queue *queue = playlist ? &playlist->pl_queue : NULL;
|
2016-01-21 08:13:14 -05:00
|
|
|
GList *rows = gtk_tree_selection_get_selected_rows(selection, NULL);
|
|
|
|
GList *cur = g_list_reverse(rows);
|
|
|
|
|
|
|
|
while (cur) {
|
2016-08-22 07:32:18 -04:00
|
|
|
queue_erase(queue, gui_filter_path_get_index(cur->data));
|
2016-01-21 08:13:14 -05:00
|
|
|
cur = g_list_next(cur);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free_full(rows, (GDestroyNotify) gtk_tree_path_free);
|
|
|
|
}
|
|
|
|
|
2016-01-22 11:22:14 -05:00
|
|
|
static void __view_process_selection(GtkTreeView *treeview, unsigned int keyval)
|
2016-01-21 08:13:14 -05:00
|
|
|
{
|
|
|
|
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
|
2016-08-16 08:06:48 -04:00
|
|
|
struct view_add_data vad_data;
|
2016-09-01 09:22:59 -04:00
|
|
|
struct playlist *playlist;
|
2016-01-21 08:13:14 -05:00
|
|
|
|
2016-01-22 11:22:14 -05:00
|
|
|
switch (keyval) {
|
2016-01-21 08:13:14 -05:00
|
|
|
case GDK_KEY_f:
|
2016-08-16 08:06:48 -04:00
|
|
|
vad_data.vad_type = PL_SYSTEM;
|
|
|
|
vad_data.vad_name = "Favorites";
|
|
|
|
gtk_tree_selection_selected_foreach(selection,
|
|
|
|
__view_add_to_playlist,
|
|
|
|
&vad_data);
|
|
|
|
break;
|
|
|
|
case GDK_KEY_p:
|
2016-09-01 09:22:59 -04:00
|
|
|
playlist = gui_pl_user_add_dialog();
|
|
|
|
if (!playlist)
|
2016-08-16 08:06:48 -04:00
|
|
|
break;
|
|
|
|
vad_data.vad_type = PL_USER;
|
2016-09-01 09:22:59 -04:00
|
|
|
vad_data.vad_name = playlist->pl_name;
|
2016-01-21 08:13:14 -05:00
|
|
|
gtk_tree_selection_selected_foreach(selection,
|
|
|
|
__view_add_to_playlist,
|
2016-08-16 08:06:48 -04:00
|
|
|
&vad_data);
|
2016-01-21 08:13:14 -05:00
|
|
|
break;
|
|
|
|
case GDK_KEY_q:
|
2016-08-16 08:06:48 -04:00
|
|
|
vad_data.vad_type = PL_SYSTEM;
|
|
|
|
vad_data.vad_name = "Queued Tracks";
|
2016-01-21 08:13:14 -05:00
|
|
|
gtk_tree_selection_selected_foreach(selection,
|
2016-08-16 08:06:48 -04:00
|
|
|
__view_add_to_playlist,
|
|
|
|
&vad_data);
|
2016-01-21 08:13:14 -05:00
|
|
|
break;
|
|
|
|
case GDK_KEY_Delete:
|
|
|
|
__view_delete_selection(selection);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-22 11:22:14 -05:00
|
|
|
void __view_keypress(GtkTreeView *treeview, GdkEventKey *event, gpointer data)
|
|
|
|
{
|
|
|
|
__view_process_selection(treeview, event->keyval);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __view_rc_new_queue(GtkMenuItem *item, gpointer data)
|
|
|
|
{
|
|
|
|
__view_process_selection(view_treeview, GDK_KEY_q);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __view_rc_add_to_queue(GtkMenuItem *item, gpointer data)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
gchar *name;
|
|
|
|
|
|
|
|
for (i = 0; i < 10; i++) {
|
|
|
|
name = g_strdup_printf("o_queue_%d", i);
|
|
|
|
if (GTK_WIDGET(item) == gui_builder_widget(name))
|
|
|
|
__view_process_selection(view_treeview, GDK_KEY_0 + i);
|
|
|
|
g_free(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void __view_rc_add_favorites(GtkMenuItem *item, gpointer data)
|
|
|
|
{
|
|
|
|
__view_process_selection(view_treeview, GDK_KEY_f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __view_rc_add_hidden(GtkMenuItem *item, gpointer data)
|
|
|
|
{
|
|
|
|
GtkTreeSelection *selection = gtk_tree_view_get_selection(view_treeview);
|
|
|
|
GList *rows = gtk_tree_selection_get_selected_rows(selection, NULL);
|
|
|
|
GList *cur = g_list_reverse(rows);
|
|
|
|
|
|
|
|
while (cur) {
|
2016-08-21 12:49:07 -04:00
|
|
|
playlist_add(PL_SYSTEM, "Hidden", gui_filter_path_get_track(cur->data));
|
2016-01-22 11:22:14 -05:00
|
|
|
cur = g_list_next(cur);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free_full(rows, (GDestroyNotify) gtk_tree_path_free);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-08-16 08:06:48 -04:00
|
|
|
void __view_rc_add_new(GtkMenuItem *item, gpointer data)
|
|
|
|
{
|
|
|
|
__view_process_selection(view_treeview, GDK_KEY_p);
|
|
|
|
}
|
|
|
|
|
2016-08-18 08:40:32 -04:00
|
|
|
static void __view_rc_add_other(GtkWidget *item, gpointer data)
|
|
|
|
{
|
2016-08-23 07:41:27 -04:00
|
|
|
GtkTreeView *treeview = gui_treeview();
|
2016-08-18 08:40:32 -04:00
|
|
|
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
|
|
|
|
struct playlist *playlist = (struct playlist *)data;
|
|
|
|
struct view_add_data vad_data = {
|
|
|
|
.vad_type = PL_USER,
|
|
|
|
.vad_name = playlist->pl_name,
|
|
|
|
};
|
|
|
|
|
|
|
|
gtk_tree_selection_selected_foreach(selection,
|
|
|
|
__view_add_to_playlist,
|
|
|
|
&vad_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkWidget *__view_rc_build_submenu(void)
|
|
|
|
{
|
|
|
|
struct playlist *playlist;
|
|
|
|
GtkWidget *submenu, *item;
|
2016-08-18 08:50:24 -04:00
|
|
|
GList *iter, *list = NULL;
|
2016-08-18 08:40:32 -04:00
|
|
|
|
|
|
|
if (pl_user_db_get()->db_size == 0)
|
|
|
|
return NULL;
|
|
|
|
|
2016-08-18 08:50:24 -04:00
|
|
|
submenu = gtk_menu_new();
|
2016-09-01 10:09:01 -04:00
|
|
|
list = gui_pl_user_list();
|
2016-08-18 08:50:24 -04:00
|
|
|
iter = g_list_first(list);
|
|
|
|
while (iter) {
|
|
|
|
playlist = (struct playlist *)iter->data;
|
2016-08-18 08:40:32 -04:00
|
|
|
item = gtk_menu_item_new_with_label(playlist->pl_name);
|
|
|
|
gtk_menu_shell_append(GTK_MENU_SHELL(submenu), item);
|
2016-08-18 08:50:24 -04:00
|
|
|
g_signal_connect(item, "activate",
|
|
|
|
G_CALLBACK(__view_rc_add_other), playlist);
|
|
|
|
iter = g_list_next(iter);
|
2016-08-18 08:40:32 -04:00
|
|
|
}
|
|
|
|
|
2016-09-01 10:09:01 -04:00
|
|
|
g_list_free(list);
|
2016-08-18 08:40:32 -04:00
|
|
|
return submenu;
|
|
|
|
}
|
|
|
|
|
2016-01-22 11:22:14 -05:00
|
|
|
bool __view_button_press(GtkTreeView *treeview, GdkEventButton *event,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2016-09-03 12:49:15 -04:00
|
|
|
GtkMenu *menu = GTK_MENU(gui_builder_widget("rc_menu"));
|
2016-08-18 08:40:32 -04:00
|
|
|
GtkWidget *submenu = NULL;
|
|
|
|
GtkMenuItem *other;
|
2016-01-22 11:22:14 -05:00
|
|
|
|
2016-08-18 08:40:32 -04:00
|
|
|
if (event->button != GDK_BUTTON_SECONDARY)
|
2016-01-22 11:22:14 -05:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Select path if it isn't already selected */
|
2016-09-03 12:16:24 -04:00
|
|
|
gui_treeview_select_path_at_pos(event->x, event->y);
|
2016-01-22 11:22:14 -05:00
|
|
|
|
2016-08-18 08:40:32 -04:00
|
|
|
/* Set the "Other Playlists" submenu. */
|
|
|
|
other = GTK_MENU_ITEM(gui_builder_widget("o_add_to_other"));
|
|
|
|
submenu = __view_rc_build_submenu();
|
|
|
|
gtk_menu_item_set_submenu(other, submenu);
|
|
|
|
|
|
|
|
if (!submenu)
|
|
|
|
gtk_widget_hide(GTK_WIDGET(other));
|
|
|
|
else
|
|
|
|
gtk_widget_show_all(GTK_WIDGET(other));
|
|
|
|
|
2016-10-31 07:42:28 -04:00
|
|
|
gtk_menu_popup_at_pointer(menu, (GdkEvent *)event);
|
2016-01-22 11:22:14 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-19 10:16:26 -05:00
|
|
|
void gui_view_init()
|
|
|
|
{
|
2016-08-23 07:41:27 -04:00
|
|
|
view_treeview = gui_treeview();
|
2016-01-19 10:16:26 -05:00
|
|
|
}
|
2016-01-21 15:18:37 -05:00
|
|
|
|
2016-08-20 21:01:19 -04:00
|
|
|
void gui_view_set_playlist(struct playlist *playlist)
|
2016-01-21 15:18:37 -05:00
|
|
|
{
|
2016-08-24 08:25:32 -04:00
|
|
|
gui_treeview_set_playlist(playlist);
|
2016-01-22 14:16:51 -05:00
|
|
|
}
|