2016-01-01 19:58:30 -05:00
|
|
|
/*
|
|
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
|
|
*/
|
2016-05-15 19:53:59 -04:00
|
|
|
#include <core/idle.h>
|
2016-04-27 09:25:37 -04:00
|
|
|
#include <core/string.h>
|
2016-08-22 10:15:09 -04:00
|
|
|
#include <gui/filter.h>
|
2016-08-26 10:19:45 -04:00
|
|
|
#include <gui/model.h>
|
2016-01-01 19:58:30 -05:00
|
|
|
#include <gui/playlist.h>
|
2016-08-25 07:44:02 -04:00
|
|
|
#include <gui/sidebar.h>
|
2016-01-01 19:58:30 -05:00
|
|
|
|
2016-09-02 10:02:58 -04:00
|
|
|
static void (*update_size[PL_MAX_TYPE])(struct playlist *) = {
|
|
|
|
[PL_SYSTEM] = gui_pl_system_update,
|
|
|
|
[PL_ARTIST] = gui_pl_artist_update,
|
|
|
|
[PL_LIBRARY] = gui_pl_library_update,
|
|
|
|
[PL_USER] = gui_pl_user_update,
|
|
|
|
};
|
2016-05-15 19:46:28 -04:00
|
|
|
|
2016-09-02 10:02:58 -04:00
|
|
|
static inline void __gui_playlist_update_size(struct playlist *playlist)
|
2016-08-01 10:24:52 -04:00
|
|
|
{
|
2016-09-02 10:02:58 -04:00
|
|
|
update_size[playlist->pl_type](playlist);
|
2016-05-03 11:20:31 -04:00
|
|
|
}
|
|
|
|
|
2016-09-02 10:02:58 -04:00
|
|
|
void __playlist_row_activated(GtkTreeView *treeview, GtkTreePath *path,
|
|
|
|
GtkTreeViewColumn *col, gpointer data)
|
2016-04-28 11:06:50 -04:00
|
|
|
{
|
2016-09-02 10:02:58 -04:00
|
|
|
gui_sidebar_filter_path_select(path);
|
|
|
|
__gui_playlist_update_size(playlist_cur());
|
2016-04-28 11:06:50 -04:00
|
|
|
}
|
|
|
|
|
2017-04-04 09:46:15 -04:00
|
|
|
void __playlist_row_collapsed(GtkTreeView *treeview, GtkTreeIter *iter,
|
|
|
|
GtkTreePath *path, gpointer data)
|
|
|
|
{
|
|
|
|
gui_sidebar_filter_row_expanded(iter, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __playlist_row_expanded(GtkTreeView *treeview, GtkTreeIter *iter,
|
|
|
|
GtkTreePath *path, gpointer data)
|
|
|
|
{
|
|
|
|
gui_sidebar_filter_row_expanded(iter, true);
|
|
|
|
}
|
|
|
|
|
2016-05-02 07:52:18 -04:00
|
|
|
static void *__playlist_init(struct queue *queue, void *data)
|
2016-01-21 09:42:37 -05:00
|
|
|
{
|
2016-05-02 08:42:28 -04:00
|
|
|
struct playlist *playlist = (struct playlist *)data;
|
2016-05-03 11:20:31 -04:00
|
|
|
|
2016-09-01 09:22:59 -04:00
|
|
|
if (playlist->pl_type == PL_ARTIST)
|
2016-09-01 08:19:31 -04:00
|
|
|
gui_pl_artist_add(playlist);
|
2016-08-26 10:19:45 -04:00
|
|
|
return playlist;
|
2016-01-21 09:42:37 -05:00
|
|
|
}
|
|
|
|
|
2016-08-22 10:15:09 -04:00
|
|
|
static void __playlist_deinit(struct queue *queue)
|
|
|
|
{
|
2016-08-26 10:19:45 -04:00
|
|
|
gui_filter_clear_search(queue->q_private);
|
2016-08-22 10:15:09 -04:00
|
|
|
}
|
|
|
|
|
2016-04-28 11:06:50 -04:00
|
|
|
static void __playlist_added(struct queue *queue, unsigned int row)
|
|
|
|
{
|
2016-08-26 10:19:45 -04:00
|
|
|
gui_model_add(queue->q_private, row);
|
2016-09-02 10:02:58 -04:00
|
|
|
__gui_playlist_update_size(queue->q_private);
|
2016-04-28 11:06:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __playlist_removed(struct queue *queue, unsigned int row)
|
|
|
|
{
|
2016-08-26 10:19:45 -04:00
|
|
|
gui_model_remove(queue->q_private, row);
|
2016-09-02 10:02:58 -04:00
|
|
|
__gui_playlist_update_size(queue->q_private);
|
2016-04-28 11:06:50 -04:00
|
|
|
}
|
|
|
|
|
2016-07-28 11:57:39 -04:00
|
|
|
static void __playlist_cleared(struct queue *queue, unsigned int n)
|
|
|
|
{
|
2016-08-26 10:19:45 -04:00
|
|
|
gui_model_clear(queue->q_private, n);
|
2016-09-02 10:02:58 -04:00
|
|
|
__gui_playlist_update_size(queue->q_private);
|
2016-07-28 11:57:39 -04:00
|
|
|
}
|
|
|
|
|
2016-08-20 21:01:19 -04:00
|
|
|
static void __playlist_updated(struct queue *queue, unsigned int n)
|
|
|
|
{
|
2016-08-26 10:19:45 -04:00
|
|
|
gui_model_update(queue->q_private, n);
|
2016-08-20 21:01:19 -04:00
|
|
|
}
|
|
|
|
|
2016-01-21 09:42:37 -05:00
|
|
|
static bool __playlist_erase(struct queue *queue, struct track *track)
|
|
|
|
{
|
2016-08-26 10:19:45 -04:00
|
|
|
struct playlist *playlist = queue->q_private;
|
|
|
|
enum playlist_type_t type = playlist->pl_type;
|
|
|
|
const gchar *name = playlist->pl_name;
|
2016-08-16 08:35:32 -04:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case PL_SYSTEM:
|
|
|
|
if (string_match(name, "Collection"))
|
|
|
|
name = "Hidden";
|
|
|
|
else if (!string_match(name, "Favorites") &&
|
|
|
|
!string_match(name, "Hidden") &&
|
|
|
|
!string_match(name, "Queued Tracks"))
|
|
|
|
break;
|
|
|
|
case PL_USER:
|
|
|
|
playlist_remove(type, name, track);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
|
2016-01-21 09:42:37 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-15 19:53:59 -04:00
|
|
|
bool __gui_playlist_init_idle()
|
|
|
|
{
|
2016-07-29 10:12:57 -04:00
|
|
|
GtkTreeSelection *selection;
|
|
|
|
GtkTreeModel *filter;
|
|
|
|
GtkTreeIter iter;
|
2016-05-15 19:53:59 -04:00
|
|
|
|
2016-08-25 07:50:16 -04:00
|
|
|
filter = GTK_TREE_MODEL(gui_sidebar_filter());
|
2016-09-01 09:22:59 -04:00
|
|
|
selection = gtk_tree_view_get_selection(gui_sidebar_treeview());
|
2016-07-29 10:12:57 -04:00
|
|
|
gtk_tree_model_get_iter_first(filter, &iter);
|
|
|
|
gtk_tree_selection_select_iter(selection, &iter);
|
|
|
|
|
2017-04-04 10:23:12 -04:00
|
|
|
do {
|
|
|
|
gui_sidebar_filter_set_expand(&iter);
|
|
|
|
} while (gtk_tree_model_iter_next(filter, &iter));
|
|
|
|
|
2016-05-15 19:53:59 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-01-01 19:58:30 -05:00
|
|
|
void gui_playlist_init()
|
|
|
|
{
|
2016-09-02 09:22:14 -04:00
|
|
|
gui_pl_system_init();
|
2016-09-01 08:19:31 -04:00
|
|
|
gui_pl_artist_init();
|
2016-09-01 09:22:59 -04:00
|
|
|
gui_pl_user_init();
|
2016-08-31 08:08:26 -04:00
|
|
|
gui_pl_library_init();
|
2016-09-02 09:22:14 -04:00
|
|
|
|
|
|
|
idle_schedule(IDLE_SYNC, __gui_playlist_init_idle, NULL);
|
2016-01-01 19:58:30 -05:00
|
|
|
}
|
2016-01-04 08:15:55 -05:00
|
|
|
|
2016-08-26 09:25:17 -04:00
|
|
|
const gchar *gui_playlist_cur()
|
2016-01-04 08:15:55 -05:00
|
|
|
{
|
2016-08-26 09:25:17 -04:00
|
|
|
if (gui_model_get_playlist())
|
|
|
|
return gui_model_get_playlist()->pl_name;
|
|
|
|
return NULL;
|
2016-01-04 08:15:55 -05:00
|
|
|
}
|
2016-01-21 09:42:37 -05:00
|
|
|
|
|
|
|
struct queue_ops playlist_ops = {
|
|
|
|
.qop_init = __playlist_init,
|
2016-08-22 10:15:09 -04:00
|
|
|
.qop_deinit = __playlist_deinit,
|
2016-04-28 11:06:50 -04:00
|
|
|
.qop_added = __playlist_added,
|
2016-01-21 09:42:37 -05:00
|
|
|
.qop_erase = __playlist_erase,
|
2016-04-28 11:06:50 -04:00
|
|
|
.qop_removed = __playlist_removed,
|
2016-07-28 11:57:39 -04:00
|
|
|
.qop_cleared = __playlist_cleared,
|
2016-08-20 21:01:19 -04:00
|
|
|
.qop_updated = __playlist_updated,
|
2016-01-21 09:42:37 -05:00
|
|
|
};
|