Implement modified signal for playlist and hook it into nav and playlist page.

Fixes #4.
This commit is contained in:
Joshua Strobl 2021-05-11 14:43:20 +03:00
parent b4ffba62c7
commit a3632b8757
5 changed files with 85 additions and 0 deletions

View file

@ -224,10 +224,40 @@ void koto_nav_handle_playlist_added(KotoCartographer *carto, KotoPlaylist *playl
koto_button_add_click_handler(playlist_button, KOTO_BUTTON_CLICK_TYPE_PRIMARY, G_CALLBACK(koto_nav_handle_playlist_button_click), playlist_uuid);
koto_window_handle_playlist_added(koto_maps, playlist, main_window); // TODO: MOVE THIS
g_signal_connect(playlist, "modified", G_CALLBACK(koto_nav_handle_playlist_modified), self);
}
}
}
void koto_nav_handle_playlist_modified(KotoPlaylist *playlist, gpointer user_data) {
if (!KOTO_IS_PLAYLIST(playlist)) {
return;
}
KotoNav *self = user_data;
if (!KOTO_IS_NAV(self)) {
return;
}
gchar *playlist_uuid = koto_playlist_get_uuid(playlist); // Get the UUID for a playlist
KotoButton *playlist_button = g_hash_table_lookup(self->playlist_buttons, playlist_uuid);
if (!KOTO_IS_BUTTON(playlist_button)) {
return;
}
gchar *artwork = koto_playlist_get_artwork(playlist); // Get the artwork
if (koto_utils_is_string_valid(artwork)) { // Have valid artwork
koto_button_set_file_path(playlist_button, artwork); // Update the artwork path
}
gchar *name = koto_playlist_get_name(playlist); // Get the name
if (koto_utils_is_string_valid(name)) { // Have valid name
koto_button_set_text(playlist_button, name); // Update the button text
}
}
void koto_nav_handle_playlist_removed(KotoCartographer *carto, gchar *playlist_uuid, gpointer user_data) {
(void) carto;
KotoNav *self = user_data;

View file

@ -33,6 +33,7 @@ void koto_nav_create_playlist_section(KotoNav *self);
void koto_nav_create_podcasts_section(KotoNav *self);
void koto_nav_handle_playlist_add_click(GtkGestureClick *gesture, int n_press, double x, double y, gpointer user_data);
void koto_nav_handle_playlist_added(KotoCartographer *carto, KotoPlaylist *playlist, gpointer user_data);
void koto_nav_handle_playlist_modified(KotoPlaylist *playlist, gpointer user_data);
void koto_nav_handle_playlist_removed(KotoCartographer *carto, gchar *playlist_uuid, gpointer user_data);
void koto_nav_handle_local_music_click(GtkGestureClick *gesture, int n_press, double x, double y, gpointer user_data);

View file

@ -310,6 +310,27 @@ void koto_playlist_page_handle_edit_button_clicked(GtkGestureClick *gesture, int
koto_window_show_dialog(main_window, "create-modify-playlist");
}
void koto_playlist_page_handle_playlist_modified(KotoPlaylist *playlist, gpointer user_data) {
if (!KOTO_IS_PLAYLIST(playlist)) {
return;
}
KotoPlaylistPage *self = user_data;
if (!KOTO_IS_PLAYLIST_PAGE(self)) {
return;
}
gchar *artwork = koto_playlist_get_artwork(playlist); // Get the artwork
if (koto_utils_is_string_valid(artwork)) { // Have valid artwork
koto_cover_art_button_set_art_path(self->playlist_image, artwork); // Update our Koto Cover Art Button
}
gchar *name = koto_playlist_get_name(playlist); // Get the name
if (koto_utils_is_string_valid(name)) { // Have valid name
gtk_label_set_label(GTK_LABEL(self->name_label), name); // Update the name label
}
}
void koto_playlist_page_handle_track_album_clicked(GtkGestureClick *gesture, int n_press, double x, double y, gpointer user_data) {
(void) gesture; (void) n_press; (void) x; (void) y;
KotoPlaylistPage *self = user_data;
@ -411,6 +432,8 @@ void koto_playlist_page_set_playlist_uuid(KotoPlaylistPage *self, gchar *playlis
self->playlist = playlist;
koto_playlist_page_set_playlist_model(self, KOTO_PREFERRED_MODEL_TYPE_DEFAULT); // TODO: Enable this to be changed
koto_playlist_page_update_header(self); // Update our header
g_signal_connect(playlist, "modified", G_CALLBACK(koto_playlist_page_handle_playlist_modified), self); // Handle playlist modification
}
void koto_playlist_page_set_playlist_model(KotoPlaylistPage *self, KotoPreferredModelType model) {

View file

@ -38,6 +38,7 @@ GtkWidget* koto_playlist_page_get_main(KotoPlaylistPage *self);
void koto_playlist_page_handle_action_bar_closed(KotoActionBar *bar, gpointer data);
void koto_playlist_page_handle_cover_art_clicked(GtkGestureClick *gesture, int n_press, double x, double y, gpointer user_data);
void koto_playlist_page_handle_edit_button_clicked(GtkGestureClick *gesture, int n_press, double x, double y, gpointer user_data);
void koto_playlist_page_handle_playlist_modified(KotoPlaylist *playlist, gpointer user_data);
void koto_playlist_page_handle_track_album_clicked(GtkGestureClick *gesture, int n_press, double x, double y, gpointer user_data);
void koto_playlist_page_handle_track_artist_clicked(GtkGestureClick *gesture, int n_press, double x, double y, gpointer user_data);
void koto_playlist_page_handle_track_name_clicked(GtkGestureClick *gesture, int n_press, double x, double y, gpointer user_data);

View file

@ -37,6 +37,7 @@ enum {
};
enum {
SIGNAL_MODIFIED,
SIGNAL_TRACK_ADDED,
SIGNAL_TRACK_LOAD_FINALIZED,
SIGNAL_TRACK_REMOVED,
@ -67,6 +68,7 @@ struct _KotoPlaylist {
struct _KotoPlaylistClass {
GObjectClass parent_class;
void (* modified) (KotoPlaylist *playlist);
void (* track_added) (KotoPlaylist *playlist, gchar *track_uuid);
void (* track_load_finalized) (KotoPlaylist *playlist);
void (* track_removed) (KotoPlaylist *playlist, gchar *track_uuid);
@ -128,6 +130,18 @@ static void koto_playlist_class_init(KotoPlaylistClass *c) {
g_object_class_install_properties(gobject_class, N_PROPERTIES, props);
playlist_signals[SIGNAL_MODIFIED] = g_signal_new(
"modified",
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
G_STRUCT_OFFSET(KotoPlaylistClass, modified),
NULL,
NULL,
NULL,
G_TYPE_NONE,
0
);
playlist_signals[SIGNAL_TRACK_ADDED] = g_signal_new(
"track-added",
G_TYPE_FROM_CLASS(gobject_class),
@ -714,6 +728,14 @@ void koto_playlist_set_artwork(KotoPlaylist *self, const gchar *path) {
self->art_path = g_strdup(path); // Update our art path to a duplicate of provided path
if (self->finalized) { // Has already been loaded
g_signal_emit(
self,
playlist_signals[SIGNAL_MODIFIED],
0
);
}
free_cookie:
magic_close(cookie); // Close and free the cookie to the cookie monster
}
@ -728,6 +750,14 @@ void koto_playlist_set_name(KotoPlaylist *self, const gchar *name) {
}
self->name = g_strdup(name);
if (self->finalized) { // Has already been loaded
g_signal_emit(
self,
playlist_signals[SIGNAL_MODIFIED],
0
);
}
}
void koto_playlist_set_position(KotoPlaylist *self, gint position) {