gui/model: Set text to bold for the currently playing track
This patch adds support for changing a rows font face to bold for the currently playing track. This should make it easier to find what track is playing while quickly skimming through the list. Fixes #22: Highlight the currently-playing song in the collection Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
a89aa5a201
commit
dfb023a0fc
|
@ -1,4 +1,5 @@
|
|||
6.4.13:
|
||||
- Enable bolding the current track in the GtkTreeView
|
||||
- Enable GtkTreeView fixed-height mode
|
||||
- Fix bug where temporary queues don't save
|
||||
- Fix bug where a queue is not selected on startup
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/audio.h>
|
||||
#include <core/queue.h>
|
||||
#include <core/string.h>
|
||||
#include <gui/model.h>
|
||||
|
@ -8,6 +9,8 @@
|
|||
static const GTypeInfo queue_type_info;
|
||||
static const GInterfaceInfo queue_tree_model;
|
||||
static GObjectClass *parent_class = NULL;
|
||||
static gchar *font_current = "bold";
|
||||
static gchar *font_regular = "";
|
||||
|
||||
static GType queue_columns[Q_MODEL_N_COLUMNS] = {
|
||||
[Q_MODEL_TRACK_NR] = G_TYPE_UINT,
|
||||
|
@ -20,6 +23,7 @@ static GType queue_columns[Q_MODEL_N_COLUMNS] = {
|
|||
[Q_MODEL_COUNT] = G_TYPE_UINT,
|
||||
[Q_MODEL_LAST_PLAY] = G_TYPE_STRING,
|
||||
[Q_MODEL_FILE_PATH] = G_TYPE_STRING,
|
||||
[Q_MODEL_FONT] = G_TYPE_STRING,
|
||||
};
|
||||
|
||||
static gboolean __queue_model_iter_nth(GuiQueueModel *model,
|
||||
|
@ -126,6 +130,10 @@ static void _queue_model_get_value(GtkTreeModel *model, GtkTreeIter *iter,
|
|||
g_value_take_string(value, g_markup_escape_text(str, -1));
|
||||
g_free(str);
|
||||
break;
|
||||
case Q_MODEL_FONT:
|
||||
str = (track == audio_cur_track()) ? font_current : font_regular;
|
||||
g_value_set_static_string(value, str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ static const gchar *QUEUE_SETTINGS[Q_MODEL_N_COLUMNS] = {
|
|||
[Q_MODEL_COUNT] = "gui.queue.count",
|
||||
[Q_MODEL_LAST_PLAY] = "gui.queue.played",
|
||||
[Q_MODEL_FILE_PATH] = "gui.queue.filepath",
|
||||
[Q_MODEL_FONT] = "gui.queue.font",
|
||||
};
|
||||
|
||||
static const enum compare_t QUEUE_SORT[Q_MODEL_N_COLUMNS] = {
|
||||
|
|
|
@ -21,6 +21,7 @@ enum queue_model_columns {
|
|||
Q_MODEL_COUNT,
|
||||
Q_MODEL_LAST_PLAY,
|
||||
Q_MODEL_FILE_PATH,
|
||||
Q_MODEL_FONT,
|
||||
Q_MODEL_N_COLUMNS,
|
||||
};
|
||||
|
||||
|
|
|
@ -1146,6 +1146,7 @@
|
|||
<child>
|
||||
<object class="GtkCellRendererText" id="cellrenderertext4"/>
|
||||
<attributes>
|
||||
<attribute name="font">10</attribute>
|
||||
<attribute name="text">0</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
|
@ -1163,6 +1164,7 @@
|
|||
<child>
|
||||
<object class="GtkCellRendererText" id="cellrenderertext5"/>
|
||||
<attributes>
|
||||
<attribute name="font">10</attribute>
|
||||
<attribute name="text">1</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
|
@ -1180,6 +1182,7 @@
|
|||
<child>
|
||||
<object class="GtkCellRendererText" id="cellrenderertext6"/>
|
||||
<attributes>
|
||||
<attribute name="font">10</attribute>
|
||||
<attribute name="text">2</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
|
@ -1197,6 +1200,7 @@
|
|||
<child>
|
||||
<object class="GtkCellRendererText" id="cellrenderertext7"/>
|
||||
<attributes>
|
||||
<attribute name="font">10</attribute>
|
||||
<attribute name="text">3</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
|
@ -1214,6 +1218,7 @@
|
|||
<child>
|
||||
<object class="GtkCellRendererText" id="cellrenderertext8"/>
|
||||
<attributes>
|
||||
<attribute name="font">10</attribute>
|
||||
<attribute name="text">4</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
|
@ -1231,6 +1236,7 @@
|
|||
<child>
|
||||
<object class="GtkCellRendererText" id="cellrenderertext9"/>
|
||||
<attributes>
|
||||
<attribute name="font">10</attribute>
|
||||
<attribute name="text">5</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
|
@ -1248,6 +1254,7 @@
|
|||
<child>
|
||||
<object class="GtkCellRendererText" id="cellrenderertext10"/>
|
||||
<attributes>
|
||||
<attribute name="font">10</attribute>
|
||||
<attribute name="text">6</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
|
@ -1265,6 +1272,7 @@
|
|||
<child>
|
||||
<object class="GtkCellRendererText" id="cellrenderertext11"/>
|
||||
<attributes>
|
||||
<attribute name="font">10</attribute>
|
||||
<attribute name="text">7</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
|
@ -1282,6 +1290,7 @@
|
|||
<child>
|
||||
<object class="GtkCellRendererText" id="cellrenderertext12"/>
|
||||
<attributes>
|
||||
<attribute name="font">10</attribute>
|
||||
<attribute name="text">8</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/*
|
||||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/audio.h>
|
||||
#include <core/collection.h>
|
||||
#include <core/idle.h>
|
||||
#include <core/core.h>
|
||||
|
@ -31,6 +32,9 @@ void test_queue_cleared(struct queue *queue, unsigned int n)
|
|||
void test_queue_save(struct queue *queue, enum queue_flags flag) {}
|
||||
void test_queue_updated(struct queue *queue, unsigned int row)
|
||||
{ gui_queue_model_update(queue->q_private, row); }
|
||||
void test_on_load(struct track *track) {}
|
||||
void test_on_state_change(GstState state) {}
|
||||
void test_on_config_pause(int count) {}
|
||||
|
||||
struct queue_ops test_ops = {
|
||||
.qop_init = test_queue_init,
|
||||
|
@ -42,8 +46,15 @@ struct queue_ops test_ops = {
|
|||
.qop_updated = test_queue_updated,
|
||||
};
|
||||
|
||||
struct audio_ops test_audio_ops = {
|
||||
.on_load = test_on_load,
|
||||
.on_state_change = test_on_state_change,
|
||||
.on_config_pause = test_on_config_pause,
|
||||
};
|
||||
|
||||
struct core_init_data init_data = {
|
||||
.collection_ops = &test_ops,
|
||||
.audio_ops = &test_audio_ops,
|
||||
};
|
||||
|
||||
static void test_init()
|
||||
|
@ -59,7 +70,7 @@ static void test_init()
|
|||
|
||||
treemodel = GTK_TREE_MODEL(model);
|
||||
test_equal(gtk_tree_model_get_flags(treemodel), GTK_TREE_MODEL_LIST_ONLY);
|
||||
test_equal(gtk_tree_model_get_n_columns(treemodel), 10);
|
||||
test_equal(gtk_tree_model_get_n_columns(treemodel), 11);
|
||||
|
||||
type = gtk_tree_model_get_column_type(treemodel, Q_MODEL_TRACK_NR);
|
||||
test_equal(type, G_TYPE_UINT);
|
||||
|
@ -81,6 +92,8 @@ static void test_init()
|
|||
test_equal(type, G_TYPE_STRING);
|
||||
type = gtk_tree_model_get_column_type(treemodel, Q_MODEL_FILE_PATH);
|
||||
test_equal(type, G_TYPE_STRING);
|
||||
type = gtk_tree_model_get_column_type(treemodel, Q_MODEL_FONT);
|
||||
test_equal(type, G_TYPE_STRING);
|
||||
|
||||
/* This should trigger an assertion failure */
|
||||
type = gtk_tree_model_get_column_type(treemodel, Q_MODEL_N_COLUMNS);
|
||||
|
@ -125,6 +138,8 @@ static void test_empty()
|
|||
test_equal(G_IS_VALUE(&value), false);
|
||||
gtk_tree_model_get_value(model, &iter, Q_MODEL_FILE_PATH, &value);
|
||||
test_equal(G_IS_VALUE(&value), false);
|
||||
gtk_tree_model_get_value(model, &iter, Q_MODEL_FONT, &value);
|
||||
test_equal(G_IS_VALUE(&value), false);
|
||||
|
||||
test_equal(gtk_tree_model_iter_next(model, &iter), false);
|
||||
test_equal(gtk_tree_model_iter_children(model, &iter, NULL), false);
|
||||
|
@ -167,6 +182,7 @@ static void test_model()
|
|||
test_equal(gtk_tree_model_get_iter_first(model, &iter), true);
|
||||
track = gui_queue_model_iter_get_track(GUI_QUEUE_MODEL(model), &iter);
|
||||
test_equal(track->tr_track, 1);
|
||||
audio_load(track);
|
||||
|
||||
path = gtk_tree_model_get_path(model, &iter);
|
||||
test_not_equal((void *)path, NULL);
|
||||
|
@ -206,10 +222,16 @@ static void test_model()
|
|||
test_equal(g_value_get_string(&value),
|
||||
"tests/Music/Hyrule Symphony/01 - Title Theme.ogg");
|
||||
g_value_unset(&value);
|
||||
gtk_tree_model_get_value(model, &iter, Q_MODEL_FONT, &value);
|
||||
test_equal(g_value_get_string(&value), "bold");
|
||||
g_value_unset(&value);
|
||||
|
||||
test_equal(gtk_tree_model_iter_next(model, &iter), true);
|
||||
track = gui_queue_model_iter_get_track(GUI_QUEUE_MODEL(model), &iter);
|
||||
test_equal(track->tr_track, 2);
|
||||
gtk_tree_model_get_value(model, &iter, Q_MODEL_FONT, &value);
|
||||
test_equal(g_value_get_string(&value), "");
|
||||
g_value_unset(&value);
|
||||
|
||||
test_equal(gtk_tree_model_iter_children(model, &iter, NULL), true);
|
||||
track = gui_queue_model_iter_get_track(GUI_QUEUE_MODEL(model), &iter);
|
||||
|
|
|
@ -29,6 +29,7 @@ const gchar *QUEUE_SETTINGS[Q_MODEL_N_COLUMNS] = {
|
|||
[Q_MODEL_COUNT] = "gui.queue.count",
|
||||
[Q_MODEL_LAST_PLAY] = "gui.queue.played",
|
||||
[Q_MODEL_FILE_PATH] = "gui.queue.filepath",
|
||||
[Q_MODEL_FONT] = "gui.queue.font",
|
||||
};
|
||||
|
||||
GMainLoop *main_loop;
|
||||
|
@ -84,17 +85,19 @@ static void test_treeview()
|
|||
(bool)false, i);
|
||||
} test_loop_passed();
|
||||
|
||||
for (i = 0; i < (Q_MODEL_N_COLUMNS - 1); i++) {
|
||||
for (i = 0; i < Q_MODEL_N_COLUMNS; i++) {
|
||||
if (i == Q_MODEL_FILE_PATH || i == Q_MODEL_FONT)
|
||||
continue;
|
||||
col = gtk_tree_view_get_column(treeview, i);
|
||||
gtk_tree_view_column_set_fixed_width(col, (i + 1) * 10);
|
||||
}
|
||||
|
||||
g_main_loop_run(main_loop);
|
||||
for (i = 0; i < (Q_MODEL_N_COLUMNS - 1); i++) {
|
||||
test_loop_equal(gui_settings_has(QUEUE_SETTINGS[i]),
|
||||
(bool)true, i);
|
||||
for (i = 0; i < Q_MODEL_N_COLUMNS; i++) {
|
||||
bool has = (i != Q_MODEL_FILE_PATH) && (i != Q_MODEL_FONT);
|
||||
test_loop_equal(gui_settings_has(QUEUE_SETTINGS[i]), has, i);
|
||||
/* The "Played" column gets any remaining space. */
|
||||
if (i != Q_MODEL_LAST_PLAY)
|
||||
if (has && i != Q_MODEL_LAST_PLAY)
|
||||
test_loop_equal(gui_settings_get(QUEUE_SETTINGS[i]),
|
||||
(i + 1) * 10, i);
|
||||
} test_loop_passed();
|
||||
|
|
Loading…
Reference in New Issue