116 lines
3.3 KiB
C
116 lines
3.3 KiB
C
/*
|
|
* Copyright 2016 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/audio.h>
|
|
#include <core/idle.h>
|
|
#include <core/playlist.h>
|
|
#include <core/string.h>
|
|
#include <gui/playlists/system.h>
|
|
#include <gui/sidebar.h>
|
|
|
|
static bool __gui_pl_system_is_playlist(struct playlist *playlist)
|
|
{
|
|
return string_match(playlist->pl_name, "Favorites") ||
|
|
string_match(playlist->pl_name, "Hidden");
|
|
}
|
|
|
|
static bool __gui_pl_system_is_dynamic(struct playlist *playlist)
|
|
{
|
|
return string_match(playlist->pl_name, "Most Played") ||
|
|
string_match(playlist->pl_name, "Least Played") ||
|
|
string_match(playlist->pl_name, "Unplayed");
|
|
}
|
|
|
|
static bool __gui_pl_system_find_descend_header(GtkTreeIter *iter,
|
|
const gchar *name)
|
|
{
|
|
GtkTreeIter header;
|
|
|
|
if (!gui_sidebar_iter_first(&header))
|
|
return false;
|
|
if (!gui_sidebar_iter_find(&header, name, PL_MAX_TYPE))
|
|
return false;
|
|
return gui_sidebar_iter_down(&header, iter);
|
|
}
|
|
|
|
void __gui_pl_system_favorite_toggled(GtkToggleButton *toggle, gpointer data)
|
|
{
|
|
if (gtk_toggle_button_get_active(toggle))
|
|
playlist_add(PL_SYSTEM, "Favorites", audio_cur_track());
|
|
else
|
|
playlist_remove(PL_SYSTEM, "Favorites", audio_cur_track());
|
|
}
|
|
|
|
void __gui_pl_system_hide_toggled(GtkToggleButton *toggle, gpointer data)
|
|
{
|
|
if (gtk_toggle_button_get_active(toggle)) {
|
|
if (playlist_add(PL_SYSTEM, "Hidden", audio_cur_track()))
|
|
audio_next();
|
|
} else
|
|
playlist_remove(PL_SYSTEM, "Hidden", audio_cur_track());
|
|
}
|
|
|
|
static bool __gui_pl_system_init_idle()
|
|
{
|
|
GtkTreeIter iter;
|
|
|
|
/* Add toplevel playlists. */
|
|
gui_sidebar_iter_first(&iter);
|
|
gui_sidebar_iter_add(&iter, playlist_get(PL_SYSTEM, "Queued Tracks"),
|
|
"audio-x-generic");
|
|
gui_sidebar_iter_add(&iter, playlist_get(PL_SYSTEM, "Collection"),
|
|
"media-optical");
|
|
gui_sidebar_iter_add(&iter, playlist_get(PL_SYSTEM, "History"),
|
|
"document-open-recent");
|
|
|
|
/* Add user-modifiable playlists. */
|
|
gui_sidebar_iter_find(&iter, "Playlists", PL_MAX_TYPE);
|
|
gui_sidebar_iter_append_child(&iter, playlist_get(PL_SYSTEM, "Favorites"),
|
|
"emblem-favorite");
|
|
gui_sidebar_iter_append_child(&iter, playlist_get(PL_SYSTEM, "Hidden"),
|
|
"window-close");
|
|
|
|
/* Add dynamic playlists. */
|
|
gui_sidebar_iter_find(&iter, "Dynamic", PL_MAX_TYPE);
|
|
gui_sidebar_iter_append_child(&iter, playlist_get(PL_SYSTEM, "Most Played"),
|
|
"go-up");
|
|
gui_sidebar_iter_append_child(&iter, playlist_get(PL_SYSTEM, "Least Played"),
|
|
"go-down");
|
|
gui_sidebar_iter_append_child(&iter, playlist_get(PL_SYSTEM, "Unplayed"),
|
|
"audio-x-generic");
|
|
|
|
return true;
|
|
}
|
|
|
|
void gui_pl_system_init()
|
|
{
|
|
idle_schedule(IDLE_SYNC, __gui_pl_system_init_idle, NULL);
|
|
}
|
|
|
|
void gui_pl_system_update(struct playlist *playlist)
|
|
{
|
|
GtkTreeIter iter;
|
|
|
|
if (__gui_pl_system_is_playlist(playlist)) {
|
|
if (!__gui_pl_system_find_descend_header(&iter, "Playlists"))
|
|
return;
|
|
} else if (__gui_pl_system_is_dynamic(playlist)) {
|
|
if (!__gui_pl_system_find_descend_header(&iter, "Dynamic"))
|
|
return;
|
|
} else {
|
|
if (!gui_sidebar_iter_first(&iter))
|
|
return;
|
|
}
|
|
|
|
if (gui_sidebar_iter_find(&iter, playlist->pl_name, playlist->pl_type))
|
|
gui_sidebar_iter_update(&iter);
|
|
}
|
|
|
|
void gui_pl_system_track_loaded(struct track *track)
|
|
{
|
|
gtk_toggle_button_set_active(gui_favorite_button(),
|
|
playlist_has(PL_SYSTEM, "Favorites", track));
|
|
gtk_toggle_button_set_active(gui_hide_button(),
|
|
playlist_has(PL_SYSTEM, "Hidden", track));
|
|
}
|