gui/view: Load a track when treeview is double clicked
And remove this feature from the C++ code. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
bbf111ecb0
commit
2d1ddd5a35
|
@ -22,11 +22,8 @@ QueueWindow :: ~QueueWindow()
|
|||
|
||||
void QueueWindow :: init(queue *queue)
|
||||
{
|
||||
_queue = queue;
|
||||
GtkTreeModel *model = GTK_TREE_MODEL(gui_queue(queue)->gq_model);
|
||||
|
||||
q_treeview->signal_row_activated().connect(sigc::mem_fun(*this,
|
||||
&QueueWindow :: on_row_activated));
|
||||
q_treeview->signal_key_press_event().connect(sigc::mem_fun(*this,
|
||||
&QueueWindow :: on_key_press), false);
|
||||
gtk_tree_view_set_model(q_treeview->gobj(), model);
|
||||
|
@ -39,17 +36,3 @@ bool QueueWindow :: on_key_press(GdkEventKey *event)
|
|||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void QueueWindow :: on_row_activated(const Gtk::TreePath &path,
|
||||
Gtk::TreeViewColumn *col)
|
||||
{
|
||||
GtkTreePath *real = path.gobj_copy();
|
||||
struct track *track = gui_queue_model_path_get_track(
|
||||
gui_queue(_queue)->gq_model, real);
|
||||
|
||||
audio_load(track);
|
||||
queue_selected(_queue, gtk_tree_path_get_indices(real)[0]);
|
||||
audio_play();
|
||||
|
||||
gtk_tree_path_free(real);
|
||||
}
|
||||
|
|
33
gui/view.c
33
gui/view.c
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/audio.h>
|
||||
#include <gui/builder.h>
|
||||
#include <gui/model.h>
|
||||
#include <gui/queue.h>
|
||||
|
@ -21,6 +22,37 @@ static const gchar *QUEUE_SETTINGS[Q_MODEL_N_COLUMNS] = {
|
|||
};
|
||||
|
||||
static GtkTreeView *view_treeview = NULL;
|
||||
static GtkTreeModelFilter *view_filter = NULL;
|
||||
|
||||
static inline GuiQueueModel *__view_filter_get_model()
|
||||
{
|
||||
if (view_filter == NULL)
|
||||
return NULL;
|
||||
return GUI_QUEUE_MODEL(gtk_tree_model_filter_get_model(view_filter));
|
||||
}
|
||||
|
||||
static inline GtkTreePath *__view_filter_convert_path(GtkTreePath *orig)
|
||||
{
|
||||
return gtk_tree_model_filter_convert_path_to_child_path(view_filter, orig);
|
||||
}
|
||||
|
||||
static struct track *__view_filter_get_track(GtkTreePath *orig)
|
||||
{
|
||||
GuiQueueModel *model = __view_filter_get_model();
|
||||
GtkTreePath *real = __view_filter_convert_path(orig);
|
||||
struct track *track = gui_queue_model_path_get_track(model, real);
|
||||
|
||||
gtk_tree_path_free(real);
|
||||
return track;
|
||||
}
|
||||
|
||||
void __view_row_activated(GtkTreeView *treeview, GtkTreePath *path,
|
||||
GtkTreeViewColumn *col, gpointer data)
|
||||
{
|
||||
audio_load(__view_filter_get_track(path));
|
||||
queue_selected(__view_filter_get_model()->gqm_queue,
|
||||
gtk_tree_path_get_indices(path)[0]);
|
||||
}
|
||||
|
||||
void __view_column_resized(GtkTreeViewColumn *col, GParamSpec *pspec,
|
||||
gpointer data)
|
||||
|
@ -53,5 +85,6 @@ void gui_view_init()
|
|||
|
||||
void gui_view_set_model(GtkTreeModelFilter *filter)
|
||||
{
|
||||
view_filter = filter;
|
||||
gtk_tree_view_set_model(view_treeview, GTK_TREE_MODEL(filter));
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ extern "C" {
|
|||
class QueueWindow : public Gtk::ScrolledWindow {
|
||||
public:
|
||||
Glib::RefPtr<Gtk::Builder> _builder;
|
||||
queue *_queue;
|
||||
|
||||
Gtk::TreeView *q_treeview;
|
||||
|
||||
|
@ -22,7 +21,6 @@ public:
|
|||
void init(queue *);
|
||||
|
||||
bool on_key_press(GdkEventKey *);
|
||||
void on_row_activated(const Gtk::TreePath &, Gtk::TreeViewColumn *);
|
||||
};
|
||||
|
||||
#endif /* OCARINA_GUI_QUEUE_WINDOW_H */
|
||||
|
|
|
@ -1110,6 +1110,7 @@
|
|||
<property name="enable_search">False</property>
|
||||
<property name="rubber_banding">True</property>
|
||||
<property name="tooltip_column">9</property>
|
||||
<signal name="row-activated" handler="__view_row_activated" swapped="no"/>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection" id="treeview-selection5">
|
||||
<property name="mode">multiple</property>
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#define TEST_NEED_QUEUE
|
||||
#define TEST_NEED_SIDEBAR
|
||||
#define TEST_NEED_WINDOW
|
||||
#include <core/audio.h>
|
||||
#include <core/collection.h>
|
||||
#include <core/core.h>
|
||||
#include <core/idle.h>
|
||||
|
@ -31,7 +32,21 @@ const gchar *QUEUE_SETTINGS[Q_MODEL_N_COLUMNS] = {
|
|||
};
|
||||
|
||||
GMainLoop *main_loop;
|
||||
struct core_init_data init_data;
|
||||
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 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 = &audio_ops,
|
||||
};
|
||||
|
||||
static int test_on_idle(gpointer data)
|
||||
{
|
||||
|
@ -44,6 +59,8 @@ static void test_treeview()
|
|||
GtkTreeModel *model, *filter;
|
||||
GtkTreeViewColumn *col;
|
||||
GtkTreeView *treeview;
|
||||
GtkTreePath *path;
|
||||
GtkTreeIter iter;
|
||||
unsigned int i;
|
||||
int argc = 0;
|
||||
|
||||
|
@ -96,6 +113,12 @@ static void test_treeview()
|
|||
gui_view_set_model(GTK_TREE_MODEL_FILTER(filter));
|
||||
test_equal((void *)gtk_tree_view_get_model(treeview), (void *)filter);
|
||||
|
||||
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);
|
||||
test_equal(load_count, 1);
|
||||
gtk_tree_path_free(path);
|
||||
|
||||
gui_view_set_model(NULL);
|
||||
test_equal((void *)gtk_tree_view_get_model(treeview), NULL);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue