gui/queue: Control runtime display
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
2d1ddd5a35
commit
87c59ce888
|
@ -72,28 +72,14 @@ static void collection_removed(struct queue *queue, unsigned int pos)
|
|||
gui_queue_removed(queue, pos);
|
||||
}
|
||||
|
||||
static void collection_cleared(struct queue *queue, unsigned int n)
|
||||
{
|
||||
if (collection_tab)
|
||||
collection_tab->on_tracks_cleared(n);
|
||||
gui_queue_cleared(queue, n);
|
||||
}
|
||||
|
||||
static void collection_updated(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
if (collection_tab)
|
||||
collection_tab->on_track_updated(pos);
|
||||
gui_queue_updated(queue, pos);
|
||||
}
|
||||
|
||||
struct queue_ops collection_ops = {
|
||||
collection_init,
|
||||
gui_queue_free,
|
||||
collection_added,
|
||||
collection_removed,
|
||||
collection_cleared,
|
||||
gui_queue_cleared,
|
||||
collection_save,
|
||||
collection_updated,
|
||||
gui_queue_updated,
|
||||
};
|
||||
|
||||
void init_collection_tab()
|
||||
|
|
|
@ -56,26 +56,14 @@ static void history_removed(struct queue *queue, unsigned int pos)
|
|||
gui_queue_removed(queue, pos);
|
||||
}
|
||||
|
||||
static void history_cleared(struct queue *queue, unsigned int n)
|
||||
{
|
||||
history_tab->on_tracks_cleared(n);
|
||||
gui_queue_cleared(queue, n);
|
||||
}
|
||||
|
||||
static void history_updated(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
history_tab->on_track_updated(pos);
|
||||
gui_queue_updated(queue, pos);
|
||||
}
|
||||
|
||||
struct queue_ops history_ops = {
|
||||
history_init,
|
||||
gui_queue_free,
|
||||
history_added,
|
||||
history_removed,
|
||||
history_cleared,
|
||||
gui_queue_cleared,
|
||||
NULL,
|
||||
history_updated,
|
||||
gui_queue_updated,
|
||||
};
|
||||
|
||||
void init_history_tab()
|
||||
|
|
|
@ -101,26 +101,14 @@ static void playlist_removed(struct queue *queue, unsigned int pos)
|
|||
gui_queue_removed(queue, pos);
|
||||
}
|
||||
|
||||
static void playlist_cleared(struct queue *queue, unsigned int n)
|
||||
{
|
||||
p_tab->on_tracks_cleared(n);
|
||||
gui_queue_cleared(queue, n);
|
||||
}
|
||||
|
||||
static void playlist_updated(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
p_tab->on_track_updated(pos);
|
||||
gui_queue_updated(queue, pos);
|
||||
}
|
||||
|
||||
struct queue_ops playlist_ops = {
|
||||
playlist_init,
|
||||
gui_queue_free,
|
||||
playlist_added,
|
||||
playlist_removed,
|
||||
playlist_cleared,
|
||||
gui_queue_cleared,
|
||||
NULL,
|
||||
playlist_updated,
|
||||
gui_queue_updated,
|
||||
};
|
||||
|
||||
void plist :: init()
|
||||
|
|
21
gui/queue.c
21
gui/queue.c
|
@ -10,6 +10,18 @@
|
|||
|
||||
static struct gui_queue *gq_queue = NULL;
|
||||
|
||||
static void __queue_set_runtime(struct gui_queue *queue)
|
||||
{
|
||||
gchar *len;
|
||||
|
||||
if (queue != gq_queue)
|
||||
return;
|
||||
|
||||
len = string_sec2str_long(queue->gq_queue->q_length);
|
||||
gtk_label_set_text(GTK_LABEL(gui_builder_widget("o_runtime")), len);
|
||||
g_free(len);
|
||||
}
|
||||
|
||||
static void __queue_toggle_flag(bool active, GtkWidget *widget,
|
||||
enum queue_flags flag)
|
||||
{
|
||||
|
@ -114,6 +126,7 @@ void gui_queue_show(struct gui_queue *queue)
|
|||
GtkButton *repeat = GTK_BUTTON(gui_builder_widget("o_repeat"));
|
||||
GtkSwitch *enabled = GTK_SWITCH(gui_builder_widget("o_enable"));
|
||||
GtkEntry *search = GTK_ENTRY(gui_builder_widget("o_search"));
|
||||
GtkLabel *runtime = GTK_LABEL(gui_builder_widget("o_runtime"));
|
||||
bool has_random = false, has_repeat = false, is_enabled = false;;
|
||||
|
||||
gq_queue = queue;
|
||||
|
@ -127,7 +140,9 @@ void gui_queue_show(struct gui_queue *queue)
|
|||
has_repeat = queue_has_flag(queue->gq_queue, Q_REPEAT);
|
||||
is_enabled = queue_has_flag(queue->gq_queue, Q_ENABLED);
|
||||
gui_view_set_model(GTK_TREE_MODEL_FILTER(queue->gq_filter));
|
||||
}
|
||||
__queue_set_runtime(queue);
|
||||
} else
|
||||
gtk_label_set_text(runtime, "");
|
||||
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(random), has_random);
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(repeat), has_repeat);
|
||||
|
@ -148,19 +163,23 @@ void gui_queue_show(struct gui_queue *queue)
|
|||
void gui_queue_added(struct queue *queue, unsigned int row)
|
||||
{
|
||||
gui_queue_model_add(gui_queue(queue)->gq_model, row);
|
||||
__queue_set_runtime(gui_queue(queue));
|
||||
}
|
||||
|
||||
void gui_queue_removed(struct queue *queue, unsigned int row)
|
||||
{
|
||||
gui_queue_model_remove(gui_queue(queue)->gq_model, row);
|
||||
__queue_set_runtime(gui_queue(queue));
|
||||
}
|
||||
|
||||
void gui_queue_cleared(struct queue *queue, unsigned int n)
|
||||
{
|
||||
gui_queue_model_clear(gui_queue(queue)->gq_model, n);
|
||||
__queue_set_runtime(gui_queue(queue));
|
||||
}
|
||||
|
||||
void gui_queue_updated(struct queue *queue, unsigned int row)
|
||||
{
|
||||
gui_queue_model_update(gui_queue(queue)->gq_model, row);
|
||||
__queue_set_runtime(gui_queue(queue));
|
||||
}
|
||||
|
|
42
gui/tabs.cpp
42
gui/tabs.cpp
|
@ -47,26 +47,14 @@ static void tempq_removed(struct queue *queue, unsigned int pos)
|
|||
gui_queue_removed(queue, pos);
|
||||
}
|
||||
|
||||
static void tempq_cleared(struct queue *queue, unsigned int n)
|
||||
{
|
||||
find_tab(queue)->on_tracks_cleared(n);
|
||||
gui_queue_cleared(queue, n);
|
||||
}
|
||||
|
||||
static void tempq_updated(struct queue *queue, unsigned int pos)
|
||||
{
|
||||
find_tab(queue)->on_track_updated(pos);
|
||||
gui_queue_updated(queue, pos);
|
||||
}
|
||||
|
||||
struct queue_ops tempq_ops = {
|
||||
tempq_init,
|
||||
gui_queue_free,
|
||||
tempq_added,
|
||||
tempq_removed,
|
||||
tempq_cleared,
|
||||
gui_queue_cleared,
|
||||
tempq_save,
|
||||
tempq_updated,
|
||||
gui_queue_updated,
|
||||
};
|
||||
|
||||
|
||||
|
@ -100,8 +88,6 @@ Tab :: Tab(queue *pq)
|
|||
tab_vbox.set_margin_end(1);
|
||||
tab_vbox.set_homogeneous(false);
|
||||
tab_vbox.show();
|
||||
|
||||
tab_runtime_changed();
|
||||
}
|
||||
|
||||
Tab :: ~Tab() {}
|
||||
|
@ -116,26 +102,11 @@ Tab :: ~Tab() {}
|
|||
void Tab :: on_track_added(unsigned int row)
|
||||
{
|
||||
tab_label->set_size();
|
||||
tab_runtime_changed();
|
||||
}
|
||||
|
||||
void Tab :: on_track_removed(unsigned int row)
|
||||
{
|
||||
tab_label->set_size();
|
||||
tab_runtime_changed();
|
||||
}
|
||||
|
||||
void Tab :: on_tracks_cleared(unsigned int n)
|
||||
{
|
||||
if (n > 0) {
|
||||
tab_label->set_size();
|
||||
tab_runtime_changed();
|
||||
}
|
||||
}
|
||||
|
||||
void Tab :: on_track_updated(unsigned int row)
|
||||
{
|
||||
tab_runtime_changed();
|
||||
}
|
||||
|
||||
|
||||
|
@ -157,14 +128,6 @@ bool Tab :: tab_is_cur()
|
|||
return notebook->page_num(tab_vbox) == notebook->get_current_page();
|
||||
}
|
||||
|
||||
void Tab :: tab_runtime_changed()
|
||||
{
|
||||
gchar *len = string_sec2str_long(tab_pq->q_length);
|
||||
if (tab_is_cur())
|
||||
Glib :: wrap(GTK_LABEL(gui_builder_widget("o_queue_time")), false)->set_text(len);
|
||||
g_free(len);
|
||||
}
|
||||
|
||||
void Tab :: tab_display_sorting()
|
||||
{
|
||||
std::string text = "";
|
||||
|
@ -393,7 +356,6 @@ static void on_switch_page(Gtk::Widget *page, int num)
|
|||
{
|
||||
Tab *tab = find_tab(num);
|
||||
if (tab) {
|
||||
tab->tab_runtime_changed();
|
||||
tab->tab_display_sorting();
|
||||
} else
|
||||
Glib :: wrap(GTK_LABEL(gui_builder_widget("o_queue_time")), false)->set_text("");
|
||||
|
|
|
@ -323,8 +323,8 @@
|
|||
<property name="icon_name">media-skip-backward</property>
|
||||
</object>
|
||||
</child>
|
||||
<accelerator key="AudioPrev" signal="clicked"/>
|
||||
<accelerator key="n" signal="clicked" modifiers="GDK_SHIFT_MASK"/>
|
||||
<accelerator key="AudioPrev" signal="clicked"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -358,8 +358,8 @@
|
|||
<property name="icon_size">5</property>
|
||||
</object>
|
||||
</child>
|
||||
<accelerator key="AudioPlay" signal="clicked"/>
|
||||
<accelerator key="space" signal="clicked"/>
|
||||
<accelerator key="AudioPlay" signal="clicked"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -392,8 +392,8 @@
|
|||
<property name="icon_size">5</property>
|
||||
</object>
|
||||
</child>
|
||||
<accelerator key="AudioPlay" signal="clicked"/>
|
||||
<accelerator key="space" signal="clicked"/>
|
||||
<accelerator key="AudioPlay" signal="clicked"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -426,8 +426,8 @@
|
|||
<property name="icon_name">media-skip-forward</property>
|
||||
</object>
|
||||
</child>
|
||||
<accelerator key="AudioNext" signal="clicked"/>
|
||||
<accelerator key="n" signal="clicked"/>
|
||||
<accelerator key="AudioNext" signal="clicked"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -1395,7 +1395,7 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="o_queue_time">
|
||||
<object class="GtkLabel" id="o_runtime">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="halign">end</property>
|
||||
|
|
|
@ -147,20 +147,25 @@ static void test_queue()
|
|||
test_equal((void *)gui_queue(&q), NULL);
|
||||
}
|
||||
|
||||
static void test_filter()
|
||||
static void test_tracks()
|
||||
{
|
||||
struct gui_queue *gq;
|
||||
GtkLabel *runtime;
|
||||
GtkEntry *search;
|
||||
int argc = 0;
|
||||
|
||||
search = GTK_ENTRY(gui_builder_widget("o_search"));
|
||||
runtime = GTK_LABEL(gui_builder_widget("o_runtime"));
|
||||
search = GTK_ENTRY(gui_builder_widget("o_search"));
|
||||
|
||||
core_init(&argc, NULL, &init_data);
|
||||
collection_add("tests/Music/Hyrule Symphony");
|
||||
while (idle_run_task() == true) {}
|
||||
gq = gui_queue(collection_get_queue());
|
||||
|
||||
gui_queue_show(gq);
|
||||
test_equal(gtk_label_get_text(runtime), "");
|
||||
|
||||
collection_add("tests/Music/Hyrule Symphony");
|
||||
while (idle_run_task() == true) {}
|
||||
test_equal(gtk_label_get_text(runtime), "42 minutes, 45 seconds");
|
||||
|
||||
test_not_equal((void *)gq, NULL);
|
||||
test_not_equal((void *)gq->gq_filter, NULL);
|
||||
|
@ -174,10 +179,17 @@ static void test_filter()
|
|||
g_signal_emit_by_name(search, "search-changed");
|
||||
test_equal(gtk_tree_model_iter_n_children(gq->gq_filter, NULL), 13);
|
||||
|
||||
queue_remove(collection_get_queue(), 3);
|
||||
test_equal(gtk_tree_model_iter_n_children(gq->gq_filter, NULL), 12);
|
||||
test_equal(gtk_label_get_text(runtime), "40 minutes, 35 seconds");
|
||||
|
||||
gui_queue_show(NULL);
|
||||
test_equal(gtk_label_get_text(runtime), "");
|
||||
|
||||
core_deinit();
|
||||
}
|
||||
|
||||
DECLARE_UNIT_TESTS(
|
||||
UNIT_TEST("Queue", test_queue),
|
||||
UNIT_TEST("Queue Filtering", test_filter),
|
||||
UNIT_TEST("Queue Tracks", test_tracks),
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue