gui/playlist: Select playlists by double clicking

I make the current playlist bold so the user has an easier time finding
it.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2016-08-01 10:24:52 -04:00
parent 7a79ac26b0
commit c6e9c176d8
2 changed files with 35 additions and 5 deletions

View File

@ -2,6 +2,7 @@
* Copyright 2016 (c) Anna Schumaker.
*/
#include <core/idle.h>
#include <core/settings.h>
#include <core/string.h>
#include <gui/builder.h>
#include <gui/playlist.h>
@ -17,6 +18,7 @@ static GtkTreeStore *p_store;
static gchar *p_name = NULL;
static bool p_init_done = false;
static void __playlist_update_sizes(struct queue *);
static inline enum playlist_type_t __playlist_type(GtkTreeIter *iter)
{
@ -37,12 +39,14 @@ static void __playlist_set(GtkTreeIter *iter, const gchar *name,
static void __playlist_set_size(GtkTreeIter *iter, const gchar *name)
{
GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(p_store), iter);
unsigned int size = playlist_size(__playlist_type(iter), name);
enum playlist_type_t type = __playlist_type(iter);
unsigned int size = playlist_size(type, name);
const gchar *fmt = "%s\n%d track%s";
gchar *text;
if (gtk_tree_path_get_depth(path) == 1)
fmt = "<b>%s</b>\n%d track%s";
if (settings_get("core.playlist.cur.type") == type &&
settings_get("core.playlist.cur.id") == playlist_get_id(type, name))
fmt = "<b>%s\n%d track%s</b>";
text = g_markup_printf_escaped(fmt, name, size, (size == 1) ? "" : "s");
gtk_tree_store_set(p_store, iter, P_SB_NAME, text, -1);
@ -139,6 +143,31 @@ out:
return true;
}
void __playlist_row_activated(GtkTreeView *treeview, GtkTreePath *path,
GtkTreeViewColumn *col, gpointer data)
{
enum playlist_type_t type;
struct queue *queue;
GtkTreeIter iter;
unsigned int id;
gchar *name;
type = settings_get("core.playlist.cur.type");
id = settings_get("core.playlist.cur.id");
gtk_tree_model_get_iter(GTK_TREE_MODEL(p_store), &iter, path);
name = __playlist_name(&iter);
playlist_select(__playlist_type(&iter), name);
__playlist_set_size(&iter, name);
g_free(name);
name = playlist_get_name(type, id);
queue = playlist_get_queue(type, name);
__playlist_update_sizes(queue);
g_free(name);
}
static bool __playlist_queue_set_size(struct queue *queue, GtkTreeIter *iter)
{
struct gui_queue *gq = gui_queue(queue);
@ -179,10 +208,10 @@ static void *__playlist_init(struct queue *queue, void *data)
struct playlist *playlist = (struct playlist *)data;
unsigned int flags = 0;
if (string_match(playlist->pl_name, "Collection"))
if (!string_match(playlist->pl_name, "History"))
flags = GQ_CAN_RANDOM;
if (string_match(playlist->pl_name, "Queued Tracks"))
flags = GQ_CAN_RANDOM | GQ_CAN_REPEAT;
flags = GQ_CAN_REPEAT;
if (p_init_done && playlist->pl_type == PL_ARTIST)
gui_playlist_add_artist(artist_find(playlist->pl_name));
return gui_queue_alloc(playlist, queue, playlist->pl_name, flags);

View File

@ -722,6 +722,7 @@
<property name="search_column">1</property>
<property name="enable_tree_lines">True</property>
<signal name="key-press-event" handler="__playlist_keypress" swapped="no"/>
<signal name="row-activated" handler="__playlist_row_activated" swapped="no"/>
<child internal-child="selection">
<object class="GtkTreeSelection" id="treeview-selection3">
<signal name="changed" handler="__playlist_selection_changed" swapped="no"/>