+ if(!strcmp(playlists[n], fullname)) {
+ if(shared)
+ return "A shared playlist with that name already exists.";
+ else
+ return "You already have a playlist with that name.";
+ }
+ /* As far as we can tell creation would work */
+ return NULL;
+}
+
+/** @brief Called to update new playlist window state
+ *
+ * This is called whenever one the text entry or radio buttons changed, and
+ * also when the set of known playlists changes. It determines whether the new
+ * playlist would be creatable and sets the sensitivity of the OK button
+ * and info display accordingly.
+ */
+static void playlist_new_changed(const char attribute((unused)) *event,
+ void attribute((unused)) *eventdata,
+ void attribute((unused)) *callbackdata) {
+ if(!playlist_new_window)
+ return;
+ const char *reason = playlist_new_valid();
+ gtk_widget_set_sensitive(playlist_new_buttons[0].widget,
+ !reason);
+ gtk_label_set_text(GTK_LABEL(playlist_new_info), reason);
+}
+
+/** @brief Called when some radio button in the new-playlist popup changes */
+static void playlist_new_button_toggled(GtkToggleButton attribute((unused)) tb,
+ gpointer attribute((unused)) userdata) {
+ playlist_new_changed(0,0,0);
+}
+
+/** @brief Called when the text entry field in the new-playlist popup changes */
+static void playlist_new_entry_edited(GtkEditable attribute((unused)) *editable,
+ gpointer attribute((unused)) user_data) {
+ playlist_new_changed(0,0,0);
+}
+
+/** @brief Pop up a new window to enter the playlist name and details */
+static void playlist_new_playlist(void) {
+ assert(playlist_new_window == NULL);
+ playlist_new_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ g_signal_connect(playlist_new_window, "destroy",
+ G_CALLBACK(gtk_widget_destroyed), &playlist_new_window);
+ gtk_window_set_title(GTK_WINDOW(playlist_new_window), "Create new playlist");
+ /* Window will be modal, suppressing access to other windows */
+ gtk_window_set_modal(GTK_WINDOW(playlist_new_window), TRUE);
+ gtk_window_set_transient_for(GTK_WINDOW(playlist_new_window),
+ GTK_WINDOW(playlist_window));
+
+ /* Window contents will use a table (grid) layout */
+ GtkWidget *table = gtk_table_new(3, 3, FALSE/*!homogeneous*/);
+
+ /* First row: playlist name */
+ gtk_table_attach_defaults(GTK_TABLE(table),
+ gtk_label_new("Playlist name"),
+ 0, 1, 0, 1);
+ playlist_new_entry = gtk_entry_new();
+ g_signal_connect(playlist_new_entry, "changed",
+ G_CALLBACK(playlist_new_entry_edited), NULL);
+ gtk_table_attach_defaults(GTK_TABLE(table),
+ playlist_new_entry,
+ 1, 3, 0, 1);
+
+ /* Second row: radio buttons to choose type */
+ playlist_new_shared = gtk_radio_button_new_with_label(NULL, "shared");
+ playlist_new_public
+ = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(playlist_new_shared),
+ "public");
+ playlist_new_private
+ = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(playlist_new_shared),
+ "private");
+ g_signal_connect(playlist_new_shared, "toggled",
+ G_CALLBACK(playlist_new_button_toggled), NULL);
+ g_signal_connect(playlist_new_public, "toggled",
+ G_CALLBACK(playlist_new_button_toggled), NULL);
+ g_signal_connect(playlist_new_private, "toggled",
+ G_CALLBACK(playlist_new_button_toggled), NULL);
+ gtk_table_attach_defaults(GTK_TABLE(table), playlist_new_shared, 0, 1, 1, 2);
+ gtk_table_attach_defaults(GTK_TABLE(table), playlist_new_public, 1, 2, 1, 2);
+ gtk_table_attach_defaults(GTK_TABLE(table), playlist_new_private, 2, 3, 1, 2);
+
+ /* Third row: info bar saying why not */
+ playlist_new_info = gtk_label_new("");
+ gtk_table_attach_defaults(GTK_TABLE(table), playlist_new_info,
+ 0, 3, 2, 3);
+
+ /* Fourth row: ok/cancel buttons */
+ GtkWidget *hbox = create_buttons_box(playlist_new_buttons,
+ NPLAYLIST_NEW_BUTTONS,
+ gtk_hbox_new(FALSE, 0));
+ gtk_table_attach_defaults(GTK_TABLE(table), hbox, 0, 3, 3, 4);
+
+ gtk_container_add(GTK_CONTAINER(playlist_new_window),
+ frame_widget(table, NULL));
+
+ /* Set initial state of OK button */
+ playlist_new_changed(0,0,0);
+
+ /* TODO: return should = OK, escape should = cancel */
+
+ /* Display the window */
+ gtk_widget_show_all(playlist_new_window);
+}
+
+/* Playlist picker ---------------------------------------------------------- */
+
+/** @brief Delete button */
+static GtkWidget *playlist_picker_delete_button;
+
+/** @brief Tree model for list of playlists */
+static GtkListStore *playlist_picker_list;
+
+/** @brief Selection for list of playlists */
+static GtkTreeSelection *playlist_picker_selection;
+
+/** @brief Currently selected playlist */
+static const char *playlist_picker_selected;
+
+/** @brief (Re-)populate the playlist picker tree model */
+static void playlist_picker_fill(const char attribute((unused)) *event,
+ void attribute((unused)) *eventdata,
+ void attribute((unused)) *callbackdata) {
+ GtkTreeIter iter[1];
+
+ if(!playlist_window)
+ return;
+ if(!playlist_picker_list)
+ playlist_picker_list = gtk_list_store_new(1, G_TYPE_STRING);
+ const char *was_selected = playlist_picker_selected;
+ gtk_list_store_clear(playlist_picker_list); /* clears playlists_selected */
+ for(int n = 0; n < nplaylists; ++n) {
+ gtk_list_store_insert_with_values(playlist_picker_list, iter,
+ n /*position*/,
+ 0, playlists[n], /* column 0 */
+ -1); /* no more cols */
+ /* Reselect the selected playlist */
+ if(was_selected && !strcmp(was_selected, playlists[n]))
+ gtk_tree_selection_select_iter(playlist_picker_selection, iter);
+ }
+ /* TODO deselecting then reselecting the current playlist resets the playlist
+ * editor, which trashes the user's selection. */