From e2d4dd61fb1eb29257ed9139d9cfd6f2fdf015cf Mon Sep 17 00:00:00 2001 From: Anna Schumaker Date: Tue, 16 Aug 2016 08:06:48 -0400 Subject: [PATCH] gui/view: Add "New Playlist" menu options And pop up a dialog mox to ask the user for the name of the new playlist. Signed-off-by: Anna Schumaker --- gui/view.c | 60 ++++++++++++++++++-- share/ocarina/ocarina6.glade | 105 ++++++++++++++++++++--------------- 2 files changed, 116 insertions(+), 49 deletions(-) diff --git a/gui/view.c b/gui/view.c index 1245d613..7ad52651 100644 --- a/gui/view.c +++ b/gui/view.c @@ -8,6 +8,7 @@ #include #include #include +#include #include static const gchar *QUEUE_SETTINGS[Q_MODEL_N_COLUMNS] = { @@ -174,10 +175,16 @@ void __view_column_clicked(GtkTreeViewColumn *col, gpointer data) g_timeout_add_seconds(3, __view_dec_sort, NULL); } +struct view_add_data { + enum playlist_type_t vad_type; + gchar *vad_name; +}; + static void __view_add_to_playlist(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data) { - playlist_add(PL_SYSTEM, (gchar *)data, __view_filter_get_track(path)); + struct view_add_data *vad = (struct view_add_data *)data; + playlist_add(vad->vad_type, vad->vad_name, __view_filter_get_track(path)); } static void __view_delete_selection(GtkTreeSelection *selection) @@ -194,20 +201,60 @@ static void __view_delete_selection(GtkTreeSelection *selection) g_list_free_full(rows, (GDestroyNotify) gtk_tree_path_free); } +static gchar *__view_get_new_playlist_name(void) +{ + gchar *text = NULL; + GtkWidget *entry = gtk_entry_new(); + GtkWidget *dialog = gtk_dialog_new_with_buttons("New Playlist Name?", + GTK_WINDOW(gui_builder_widget("o_window")), + GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL, + _("_Cancel"), GTK_RESPONSE_CANCEL, + _("_OK"), GTK_RESPONSE_ACCEPT, + NULL); + GtkWidget *content = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + + gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); + gtk_entry_set_activates_default(GTK_ENTRY(entry), true); + gtk_container_add(GTK_CONTAINER(content), entry); + gtk_widget_show_all(dialog); + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) + text = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry))); + gtk_widget_destroy(dialog); + + return text; +} + static void __view_process_selection(GtkTreeView *treeview, unsigned int keyval) { GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview); + struct view_add_data vad_data; + gchar *text = NULL; switch (keyval) { case GDK_KEY_f: + vad_data.vad_type = PL_SYSTEM; + vad_data.vad_name = "Favorites"; gtk_tree_selection_selected_foreach(selection, __view_add_to_playlist, - "Favorites"); + &vad_data); + break; + case GDK_KEY_p: + text = __view_get_new_playlist_name(); + if (!text || !playlist_new(PL_USER, text)) + break; + vad_data.vad_type = PL_USER; + vad_data.vad_name = text; + gtk_tree_selection_selected_foreach(selection, + __view_add_to_playlist, + &vad_data); + g_free(text); break; case GDK_KEY_q: + vad_data.vad_type = PL_SYSTEM; + vad_data.vad_name = "Queued Tracks"; gtk_tree_selection_selected_foreach(selection, - __view_add_to_playlist, - "Queued Tracks"); + __view_add_to_playlist, + &vad_data); break; case GDK_KEY_Delete: __view_delete_selection(selection); @@ -258,6 +305,11 @@ void __view_rc_add_hidden(GtkMenuItem *item, gpointer data) } +void __view_rc_add_new(GtkMenuItem *item, gpointer data) +{ + __view_process_selection(view_treeview, GDK_KEY_p); +} + bool __view_button_press(GtkTreeView *treeview, GdkEventButton *event, gpointer data) { diff --git a/share/ocarina/ocarina6.glade b/share/ocarina/ocarina6.glade index 52b22243..d5ef5dad 100644 --- a/share/ocarina/ocarina6.glade +++ b/share/ocarina/ocarina6.glade @@ -9,12 +9,6 @@ 10 media-playlist-repeat - - True - False - emblem-documents - 1 - True False @@ -27,50 +21,16 @@ emblem-favorite 1 - - True - False - - - Add to Playlist - True - False - image18 - False - - - True - False - - - Favorites - True - False - image20 - False - - - - - - Hidden - True - False - image19 - False - - - - - - - - True False folder-new + + True + False + document-new + True False @@ -84,6 +44,61 @@ + + + Playlist + True + False + image22 + False + + + + + + True + False + document-new + + + True + False + + + Add to New Playlist + True + False + image23 + False + + + + + + Add to Favorites + True + False + image20 + False + + + + + + Add to Hidden + True + False + image19 + False + + + + + + True + False + + True