Remove gui/view.c
This code is obsolete now that gui/playlist.c handles keypress and right-click events on the main treeview. Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
3bf99b12eb
commit
88bf71ac22
|
@ -9,7 +9,6 @@
|
|||
#include <gui/idle.h>
|
||||
#include <gui/playlist.h>
|
||||
#include <gui/treeview.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/window.h>
|
||||
|
||||
static guint audio_timeout = 0;
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include <gui/playlist.h>
|
||||
#include <gui/sidebar.h>
|
||||
#include <gui/treeview.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/window.h>
|
||||
|
||||
#define OCARINA_FLAGS (G_APPLICATION_HANDLES_COMMAND_LINE)
|
||||
|
@ -106,7 +105,6 @@ static void __ocarina_startup(GApplication *application, gpointer data)
|
|||
gui_filter_init();
|
||||
gui_treeview_init();
|
||||
gui_sidebar_init();
|
||||
gui_view_init();
|
||||
gui_playlist_init();
|
||||
gui_audio_init();
|
||||
|
||||
|
|
206
gui/view.c
206
gui/view.c
|
@ -1,206 +0,0 @@
|
|||
/*
|
||||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/audio.h>
|
||||
#include <core/playlist.h>
|
||||
#include <core/settings.h>
|
||||
#include <gui/builder.h>
|
||||
#include <gui/filter.h>
|
||||
#include <gui/model.h>
|
||||
#include <gui/playlist.h>
|
||||
#include <gui/treeview.h>
|
||||
#include <gui/view.h>
|
||||
#include <gui/window.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static GtkTreeView *view_treeview = NULL;
|
||||
|
||||
struct view_add_data {
|
||||
enum playlist_type_t vad_type;
|
||||
const gchar *vad_name;
|
||||
};
|
||||
|
||||
static void __view_add_to_playlist(GtkTreeModel *model, GtkTreePath *path,
|
||||
GtkTreeIter *iter, gpointer data)
|
||||
{
|
||||
struct view_add_data *vad = (struct view_add_data *)data;
|
||||
playlist_add(vad->vad_type, vad->vad_name, gui_filter_path_get_track(path));
|
||||
}
|
||||
|
||||
static void __view_delete_selection(GtkTreeSelection *selection)
|
||||
{
|
||||
struct playlist *playlist = gui_model_get_playlist();
|
||||
struct queue *queue = playlist ? &playlist->pl_queue : NULL;
|
||||
GList *rows = gtk_tree_selection_get_selected_rows(selection, NULL);
|
||||
GList *cur = g_list_reverse(rows);
|
||||
|
||||
while (cur) {
|
||||
queue_erase(queue, gui_filter_path_get_index(cur->data));
|
||||
cur = g_list_next(cur);
|
||||
}
|
||||
|
||||
g_list_free_full(rows, (GDestroyNotify) gtk_tree_path_free);
|
||||
}
|
||||
|
||||
static void __view_process_selection(GtkTreeView *treeview, unsigned int keyval)
|
||||
{
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
|
||||
struct view_add_data vad_data;
|
||||
struct playlist *playlist;
|
||||
|
||||
switch (keyval) {
|
||||
case GDK_KEY_f:
|
||||
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:
|
||||
playlist = gui_pl_user_add_dialog();
|
||||
if (!playlist)
|
||||
break;
|
||||
vad_data.vad_type = PL_USER;
|
||||
vad_data.vad_name = playlist->pl_name;
|
||||
gtk_tree_selection_selected_foreach(selection,
|
||||
__view_add_to_playlist,
|
||||
&vad_data);
|
||||
break;
|
||||
case GDK_KEY_q:
|
||||
vad_data.vad_type = PL_SYSTEM;
|
||||
vad_data.vad_name = "Queued Tracks";
|
||||
gtk_tree_selection_selected_foreach(selection,
|
||||
__view_add_to_playlist,
|
||||
&vad_data);
|
||||
break;
|
||||
case GDK_KEY_Delete:
|
||||
__view_delete_selection(selection);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
playlist_add(PL_SYSTEM, "Hidden", gui_filter_path_get_track(cur->data));
|
||||
cur = g_list_next(cur);
|
||||
}
|
||||
|
||||
g_list_free_full(rows, (GDestroyNotify) gtk_tree_path_free);
|
||||
|
||||
}
|
||||
|
||||
void __view_rc_add_new(GtkMenuItem *item, gpointer data)
|
||||
{
|
||||
__view_process_selection(view_treeview, GDK_KEY_p);
|
||||
}
|
||||
|
||||
static void __view_rc_add_other(GtkWidget *item, gpointer data)
|
||||
{
|
||||
GtkTreeView *treeview = gui_treeview();
|
||||
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;
|
||||
GList *iter, *list = NULL;
|
||||
|
||||
if (pl_user_db_get()->db_size == 0)
|
||||
return NULL;
|
||||
|
||||
submenu = gtk_menu_new();
|
||||
list = gui_pl_user_list();
|
||||
iter = g_list_first(list);
|
||||
while (iter) {
|
||||
playlist = (struct playlist *)iter->data;
|
||||
item = gtk_menu_item_new_with_label(playlist->pl_name);
|
||||
gtk_menu_shell_append(GTK_MENU_SHELL(submenu), item);
|
||||
g_signal_connect(item, "activate",
|
||||
G_CALLBACK(__view_rc_add_other), playlist);
|
||||
iter = g_list_next(iter);
|
||||
}
|
||||
|
||||
g_list_free(list);
|
||||
return submenu;
|
||||
}
|
||||
|
||||
bool __view_button_press(GtkTreeView *treeview, GdkEventButton *event,
|
||||
gpointer data)
|
||||
{
|
||||
GtkMenu *menu = GTK_MENU(gui_builder_widget("rc_menu"));
|
||||
GtkWidget *submenu = NULL;
|
||||
GtkMenuItem *other;
|
||||
|
||||
if (event->button != GDK_BUTTON_SECONDARY)
|
||||
return false;
|
||||
|
||||
/* Select path if it isn't already selected */
|
||||
gui_treeview_select_path_at_pos(event->x, event->y);
|
||||
|
||||
/* 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));
|
||||
|
||||
gtk_menu_popup_at_pointer(menu, (GdkEvent *)event);
|
||||
return true;
|
||||
}
|
||||
|
||||
void gui_view_init()
|
||||
{
|
||||
view_treeview = gui_treeview();
|
||||
}
|
||||
|
||||
void gui_view_set_playlist(struct playlist *playlist)
|
||||
{
|
||||
gui_treeview_set_playlist(playlist);
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
/*
|
||||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#ifndef OCARINA_GUI_VIEW_H
|
||||
#define OCARINA_GUI_VIEW_H
|
||||
#include <gui/builder.h>
|
||||
|
||||
/* Called to initialize structures needed by the treeview. */
|
||||
void gui_view_init();
|
||||
|
||||
/* Called to set the currently displayed model. */
|
||||
void gui_view_set_playlist(struct playlist *);
|
||||
|
||||
#endif /* OCARINA_GUI_VIEW_H */
|
|
@ -5,6 +5,5 @@ model
|
|||
filter
|
||||
treeview
|
||||
sidebar
|
||||
view
|
||||
playlist
|
||||
audio
|
||||
|
|
|
@ -13,6 +13,5 @@ gui_unit_test(Treeview)
|
|||
gui_unit_test(Sidebar)
|
||||
|
||||
add_subdirectory(playlists/)
|
||||
gui_unit_test(View)
|
||||
gui_unit_test(Playlist)
|
||||
gui_unit_test(Audio)
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
/*
|
||||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/audio.h>
|
||||
#include <core/core.h>
|
||||
#include <core/idle.h>
|
||||
#include <core/playlist.h>
|
||||
#include <core/settings.h>
|
||||
#include <gui/builder.h>
|
||||
#include <gui/filter.h>
|
||||
#include <gui/model.h>
|
||||
#include <gui/treeview.h>
|
||||
#include <gui/view.h>
|
||||
#include <tests/test.h>
|
||||
|
||||
unsigned int load_count = 0;
|
||||
|
||||
static void test_load(struct track *track) { load_count++; }
|
||||
static void test_state_change(GstState state) {}
|
||||
static void test_config_pause(int count) {}
|
||||
|
||||
struct audio_ops test_audio_ops = {
|
||||
.on_load = test_load,
|
||||
.on_state_change = test_state_change,
|
||||
.on_config_pause = test_config_pause,
|
||||
};
|
||||
|
||||
struct core_init_data init_data = {
|
||||
.audio_ops = &test_audio_ops,
|
||||
};
|
||||
|
||||
static void test_treeview()
|
||||
{
|
||||
GtkTreeView *treeview;
|
||||
GtkTreeModel *filter;
|
||||
GtkTreePath *path;
|
||||
GtkTreeIter iter;
|
||||
|
||||
playlist_new(PL_LIBRARY, "tests/Music/Hyrule Symphony");
|
||||
while (idle_run_task() == true) {}
|
||||
gui_filter_set_playlist(playlist_get(PL_SYSTEM, "Collection"));
|
||||
filter = GTK_TREE_MODEL(gui_filter_get());
|
||||
g_assert_nonnull(filter);
|
||||
|
||||
treeview = gui_treeview();
|
||||
g_assert_nonnull(treeview);
|
||||
|
||||
g_assert((void *)gtk_tree_view_get_model(treeview) ==
|
||||
(void *)gui_filter_get());
|
||||
|
||||
gtk_tree_model_iter_nth_child(filter, &iter, NULL, 3);
|
||||
path = gtk_tree_model_get_path(filter, &iter);
|
||||
gtk_tree_view_row_activated(treeview, path, NULL);
|
||||
g_assert_cmpuint(load_count, ==, 1);
|
||||
gtk_tree_path_free(path);
|
||||
|
||||
gui_view_set_playlist(NULL);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
gtk_init(&argc, NULL);
|
||||
core_init(&argc, NULL, &init_data);
|
||||
gui_builder_init("share/ocarina/ocarina.ui");
|
||||
gui_model_init();
|
||||
gui_filter_init();
|
||||
gui_treeview_init();
|
||||
gui_view_init();
|
||||
while (idle_run_task()) {};
|
||||
|
||||
g_test_init(&argc, &argv, NULL);
|
||||
g_test_add_func("/Gui/Treeview", test_treeview);
|
||||
return g_test_run();
|
||||
}
|
Loading…
Reference in New Issue