# HG changeset patch # User Calin Crisan ccrisan@gmail.com # Date 1218808853 -7200 # Node ID 457260d5542870969caed02059bd9c6afc51c546 # Parent 8f0a8a0d71c5bf61e09b6407937cc1a6c3238c24# Parent 113454baecf839d7e506ec5d3ea1f43f8196155d Automated merge with ssh://hg.atheme-project.org//hg//audacious-plugins diff -r 8f0a8a0d71c5 -r 457260d55428 src/streambrowser/bookmarks.c --- a/src/streambrowser/bookmarks.c Thu Aug 14 00:46:34 2008 +0200 +++ b/src/streambrowser/bookmarks.c Fri Aug 15 16:00:53 2008 +0200 @@ -25,11 +25,14 @@ #include "bookmarks.h" -static bookmark_t *bookmarks; -static int bookmarks_count; +static bookmark_t **bookmarks; +static int *bookmarks_count; gboolean bookmarks_streaminfo_fetch(category_t *category, streaminfo_t *streaminfo) { + // todo: implement and make use of this + + return FALSE; } gboolean bookmarks_category_fetch(streamdir_t *streamdir, category_t *category) @@ -42,13 +45,11 @@ int i; /* find bookmarks that match this category */ - for (i = 0; i < bookmarks_count; i++) - if (strcmp(bookmarks[i].streamdir_name, streamdir->name) == 0 && - strcmp(bookmarks[i].category_name, category->name) == 0) { - + for (i = 0; i < *bookmarks_count; i++) + if (strcmp((*bookmarks)[i].streamdir_name, category->name) == 0) { debug("bookmarks: adding stream info for '%s/%d'\n", streamdir->name, category->name); - streaminfo_t *streaminfo = streaminfo_new(bookmarks[i].name, bookmarks[i].playlist_url, bookmarks[i].url, ""); + streaminfo_t *streaminfo = streaminfo_new((*bookmarks)[i].name, (*bookmarks)[i].playlist_url, (*bookmarks)[i].url, ""); streaminfo_add(category, streaminfo); debug("bookmarks: stream info added\n"); @@ -57,10 +58,10 @@ return TRUE; } -streamdir_t* bookmarks_streamdir_fetch(bookmark_t *bms, int count) +streamdir_t* bookmarks_streamdir_fetch(bookmark_t **p_bookmarks, int *p_bookmarks_count) { - bookmarks = bms; - bookmarks_count = count; + bookmarks = p_bookmarks; + bookmarks_count = p_bookmarks_count; streamdir_t *streamdir = streamdir_new(BOOKMARKS_NAME); @@ -77,3 +78,70 @@ return streamdir; } +void bookmark_add(bookmark_t *bookmark) +{ + debug("bookmarks: adding bookmark with streamdir = '%s', name = '%s', playlist_url = '%s', url = '%s'\n", + bookmark->streamdir_name, bookmark->name, bookmark->playlist_url, bookmark->url); + + int i; + for (i = 0; i < *bookmarks_count; i++) + if (strcmp((*bookmarks)[i].name, bookmark->name) == 0) { + debug("bookmarks: bookmark with name = '%s' already exists, skipping\n", bookmark->name); + return; + } + + *bookmarks = realloc(*bookmarks, sizeof(bookmark_t) * ((*bookmarks_count) + 1)); + + strncpy((*bookmarks)[*bookmarks_count].streamdir_name, bookmark->streamdir_name, DEF_STRING_LEN); + strncpy((*bookmarks)[*bookmarks_count].name, bookmark->name, DEF_STRING_LEN); + strncpy((*bookmarks)[*bookmarks_count].playlist_url, bookmark->playlist_url, DEF_STRING_LEN); + strncpy((*bookmarks)[*bookmarks_count].url, bookmark->url, DEF_STRING_LEN); + + (*bookmarks_count)++; + + debug("bookmarks: bookmark added, there are now %d bookmarks\n", *bookmarks_count); + + /* issue a configuration save for immediately saving the new added bookmark */ + config_save(); +} + +void bookmark_remove(gchar *name) +{ + debug("bookmarks: searching for bookmark with name = '%s'\n", name); + + int pos = -1, i; + + for (i = 0; i < *bookmarks_count; i++) + if (strcmp((*bookmarks)[i].name, name) == 0) { + pos = i; + break; + } + + if (pos != -1) { + debug("bookmarks: removing bookmark with streamdir = '%s', name = '%s', playlist_url = '%s', url = '%s'\n", + (*bookmarks)[i].streamdir_name, (*bookmarks)[i].name, (*bookmarks)[i].playlist_url, (*bookmarks)[i].url); + + for (i = pos; i < (*bookmarks_count) - 1; i++) { + /* bookmarks[i] = bookmarks[i + 1] */ + + strncpy((*bookmarks)[i].streamdir_name, (*bookmarks)[i + 1].streamdir_name, DEF_STRING_LEN); + strncpy((*bookmarks)[i].name, (*bookmarks)[i + 1].name, DEF_STRING_LEN); + strncpy((*bookmarks)[i].playlist_url, (*bookmarks)[i + 1].playlist_url, DEF_STRING_LEN); + strncpy((*bookmarks)[i].url, (*bookmarks)[i + 1].url, DEF_STRING_LEN); + } + + (*bookmarks_count)--; + if (*bookmarks_count > 0) + *bookmarks = realloc(*bookmarks, sizeof(bookmark_t) * (*bookmarks_count)); + else + *bookmarks = NULL; + + debug("bookmarks: bookmark removed, there are now %d bookmarks\n", *bookmarks_count); + } + else + failure("bookmarks: cannot find a bookmark with name = '%s'\n", name); + + /* issue a configuration save for immediately saving the remaining bookmarks */ + config_save(); +} + diff -r 8f0a8a0d71c5 -r 457260d55428 src/streambrowser/bookmarks.h --- a/src/streambrowser/bookmarks.h Thu Aug 14 00:46:34 2008 +0200 +++ b/src/streambrowser/bookmarks.h Fri Aug 15 16:00:53 2008 +0200 @@ -30,7 +30,6 @@ typedef struct { gchar streamdir_name[DEF_STRING_LEN]; - gchar category_name[DEF_STRING_LEN]; gchar name[DEF_STRING_LEN]; gchar playlist_url[DEF_STRING_LEN]; @@ -41,7 +40,10 @@ gboolean bookmarks_streaminfo_fetch(category_t *category, streaminfo_t *streaminfo); gboolean bookmarks_category_fetch(streamdir_t *streamdir, category_t *category); -streamdir_t* bookmarks_streamdir_fetch(bookmark_t *bms, int count); +streamdir_t* bookmarks_streamdir_fetch(bookmark_t **p_bookmarks, int *p_bookmarks_count); + +void bookmark_add(bookmark_t *bookmark); +void bookmark_remove(gchar *name); #endif // BOOKMARKS_H diff -r 8f0a8a0d71c5 -r 457260d55428 src/streambrowser/gui/streambrowser_win.c --- a/src/streambrowser/gui/streambrowser_win.c Thu Aug 14 00:46:34 2008 +0200 +++ b/src/streambrowser/gui/streambrowser_win.c Fri Aug 15 16:00:53 2008 +0200 @@ -8,6 +8,7 @@ #include "../streambrowser.h" #include "streambrowser_win.h" +#include "../bookmarks.h" typedef struct { @@ -28,12 +29,12 @@ static gboolean on_notebook_switch_page(GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, gpointer data); static gboolean on_tree_view_cursor_changed(GtkTreeView *tree_view, gpointer data); static gboolean on_add_button_clicked(GtkButton *button, gpointer data); +static gboolean on_bookmark_button_clicked(GtkButton *button, gpointer data); static gboolean on_search_entry_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data); static gboolean on_tree_view_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data); static gboolean on_tree_view_button_pressed(GtkWidget *widget, GdkEventButton *event, gpointer data); static streamdir_gui_t* find_streamdir_gui_by_name(gchar *name); -//static streamdir_gui_t* find_streamdir_gui_by_tree_view(GtkTreeView *tree_view); todo: remove this static streamdir_gui_t* find_streamdir_gui_by_table(GtkTable *table); static streamdir_gui_t* find_streamdir_gui_by_streamdir(streamdir_t *streamdir); static gboolean tree_view_search_equal_func(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer data); @@ -41,6 +42,7 @@ static GtkWidget* notebook; static GtkWidget* search_entry; static GtkWidget* add_button; +static GtkWidget* bookmark_button; static GtkWidget* streambrowser_window; static GList* streamdir_gui_list; static GtkCellRenderer* cell_renderer_pixbuf; @@ -75,17 +77,24 @@ g_signal_connect(G_OBJECT(add_button), "clicked", G_CALLBACK(on_add_button_clicked), NULL); gtk_widget_show(add_button); - GtkWidget *vbox1 = gtk_vbox_new(FALSE, 3); + /* bookmark button */ + bookmark_button = gtk_button_new_with_label(_("Add Bookmark")); + gtk_button_set_image(GTK_BUTTON(bookmark_button), gtk_image_new_from_file(BOOKMARKS_ICON)); + g_signal_connect(G_OBJECT(bookmark_button), "clicked", G_CALLBACK(on_bookmark_button_clicked), NULL); + gtk_widget_show(bookmark_button); + + GtkWidget *vbox1 = gtk_vbox_new(FALSE, 4); gtk_box_pack_start(GTK_BOX(vbox1), notebook, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox1), hbox1, FALSE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox1), add_button, FALSE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(vbox1), bookmark_button, FALSE, TRUE, 0); gtk_widget_show(vbox1); /* streambrowser window */ streambrowser_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(streambrowser_window), _("Stream browser")); gtk_window_set_position(GTK_WINDOW(streambrowser_window), GTK_WIN_POS_CENTER); - gtk_window_set_default_size(GTK_WINDOW(streambrowser_window), 700, 400); + gtk_window_set_default_size(GTK_WINDOW(streambrowser_window), 1000, 700); gtk_window_set_icon_from_file(GTK_WINDOW(streambrowser_window), STREAMBROWSER_ICON, NULL); g_signal_connect(G_OBJECT(streambrowser_window), "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), streambrowser_window); gtk_container_add(GTK_CONTAINER(streambrowser_window), vbox1); @@ -153,7 +162,7 @@ category = category_get_by_index(streamdir, i); gtk_tree_store_append(store, &iter, NULL); - gtk_tree_store_set(store, &iter, 0, "gtk-directory", 1, category->name, 2, "", -1); + gtk_tree_store_set(store, &iter, 0, "gtk-directory", 1, category->name, 2, "", 3, PANGO_WEIGHT_NORMAL, -1); } } @@ -189,7 +198,7 @@ streaminfo = streaminfo_get_by_index(category, i); gtk_tree_store_append(store, &new_iter, &iter); - gtk_tree_store_set(store, &new_iter, 0, "gtk-media-play", 1, streaminfo->name, 2, streaminfo->current_track, -1); + gtk_tree_store_set(store, &new_iter, 0, "gtk-media-play", 1, streaminfo->name, 2, streaminfo->current_track, 3, PANGO_WEIGHT_NORMAL, -1); } gtk_tree_path_free(path); @@ -214,7 +223,7 @@ return; /* update the streaminfo*/ - gtk_tree_store_set(store, &new_iter, 0, "gtk-media-play", 1, streaminfo->name, 2, streaminfo->current_track, -1); + gtk_tree_store_set(store, &new_iter, 0, "gtk-media-play", 1, streaminfo->name, 2, streaminfo->current_track, 3, PANGO_WEIGHT_NORMAL -1); gtk_tree_path_free(path); } @@ -238,12 +247,13 @@ return; if (fetching) { - gchar temp[DEF_STRING_LEN]; - sprintf(temp, "%s", category->name); - gtk_tree_store_set(store, &iter, 0, "gtk-refresh", 1, temp, 2, "", -1); + gtk_tree_store_set(store, &iter, 0, "gtk-refresh", 1, category->name, 2, "", 3, PANGO_WEIGHT_BOLD, -1); } else { - gtk_tree_store_set(store, &iter, 0, "gtk-directory", 1, category->name, 2, "", -1); + gtk_tree_store_set(store, &iter, 0, "gtk-directory", 1, category->name, 2, "", 3, PANGO_WEIGHT_NORMAL, -1); + + /* we also expand the corresponding category tree element in the treeview */ + gtk_tree_view_expand_row(tree_view, path, FALSE); } } @@ -261,13 +271,10 @@ return; if (fetching) { - gchar temp[DEF_STRING_LEN]; - sprintf(temp, "%s", streaminfo->name); - - gtk_tree_store_set(store, &iter, 0, "gtk-refresh", 1, temp, 2, streaminfo->current_track, -1); + gtk_tree_store_set(store, &iter, 0, "gtk-media-play", 1, streaminfo->name, 2, streaminfo->current_track, 3, PANGO_WEIGHT_BOLD, -1); } else { - gtk_tree_store_set(store, &iter, 0, "gtk-media-play", 1, streaminfo->name, 2, streaminfo->current_track, -1); + gtk_tree_store_set(store, &iter, 0, "gtk-media-play", 1, streaminfo->name, 2, streaminfo->current_track, 3, PANGO_WEIGHT_NORMAL, -1); } } @@ -287,7 +294,7 @@ { GtkWidget *tree_view = gtk_tree_view_new(); - GtkTreeStore *store = gtk_tree_store_new(3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); + GtkTreeStore *store = gtk_tree_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT); gtk_tree_view_set_model(GTK_TREE_VIEW(tree_view), GTK_TREE_MODEL(store)); gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree_view), TRUE); @@ -306,7 +313,8 @@ column = gtk_tree_view_column_new(); gtk_tree_view_column_pack_start(column, cell_renderer_text, TRUE); - gtk_tree_view_column_add_attribute(column, cell_renderer_text, "markup", 1); + gtk_tree_view_column_add_attribute(column, cell_renderer_text, "text", 1); + gtk_tree_view_column_add_attribute(column, cell_renderer_text, "weight", 3); gtk_tree_view_column_set_resizable(column, TRUE); gtk_tree_view_column_set_title(column, _("Stream name")); gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), column); @@ -353,6 +361,14 @@ /* clear the search box */ gtk_entry_set_text(GTK_ENTRY(search_entry), ""); + + /* if this is the last page, aka the bookmarks page, bookmark button has to say "Remove bookmark", instead of "Add bookmark"0 */ + if (page_num == gtk_notebook_get_n_pages(notebook) - 1) { + gtk_button_set_label(GTK_BUTTON(bookmark_button), _("Remove Bookmark")); + } + else { + gtk_button_set_label(GTK_BUTTON(bookmark_button), _("Add Bookmark")); + } return TRUE; } @@ -420,7 +436,6 @@ } /* single click triggers a refresh of the selected item */ else { - // todo: separate single from double click somehow tree_view_button_pressed = TRUE; } @@ -473,6 +488,66 @@ return TRUE; } +static gboolean on_bookmark_button_clicked(GtkButton *button, gpointer data) +{ + GtkTreePath *path; + GtkTreeViewColumn *focus_column; + + /* get the currently selected tree view */ + GtkWidget *table = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook))); + streamdir_gui_t *streamdir_gui = find_streamdir_gui_by_table(GTK_TABLE(table)); + if (streamdir_gui == NULL) + return TRUE; + + GtkTreeView *tree_view = GTK_TREE_VIEW(streamdir_gui->tree_view); + + /* get the currently selected path in the tree */ + gtk_tree_view_get_cursor(tree_view, &path, &focus_column); + + if (path == NULL) + return TRUE; + + gint *indices = gtk_tree_path_get_indices(path); + if (gtk_tree_path_get_depth(path) == 1) { + gtk_tree_path_free(path); + return TRUE; + } + + int category_index = indices[0]; + int streaminfo_index = indices[1]; + + gtk_tree_path_free(path); + + /* get the currently selected stream (info) */ + streamdir_t *streamdir = streamdir_gui->streamdir; + category_t *category = category_get_by_index(streamdir_gui->streamdir, category_index); + streaminfo_t *streaminfo = streaminfo_get_by_index(category, streaminfo_index); + + /* if we have the bookmarks tab focused, we remove the stream, rather than add it. otherwise we simply add it */ + if (strcmp(streamdir->name, BOOKMARKS_NAME) == 0) { + bookmark_remove(streaminfo->name); + + update_function(streamdir, category, NULL, FALSE); + } + else { + bookmark_t bookmark; + strncpy(bookmark.streamdir_name, streamdir->name, DEF_STRING_LEN); + strncpy(bookmark.name, streaminfo->name, DEF_STRING_LEN); + strncpy(bookmark.playlist_url, streaminfo->playlist_url, DEF_STRING_LEN); + strncpy(bookmark.url, streaminfo->url, DEF_STRING_LEN); + + bookmark_add(&bookmark); + + /* find the corresponding category (having the current streamdir name) in the bookmarks */ + streamdir_t *bookmarks_streamdir = find_streamdir_gui_by_name(BOOKMARKS_NAME)->streamdir; + category_t *bookmarks_category = category_get_by_name(bookmarks_streamdir, streamdir->name); + + update_function(bookmarks_streamdir, bookmarks_category, NULL, FALSE); + } + + return TRUE; +} + static gboolean on_search_entry_key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data) { if (event->keyval == GDK_Return || event->keyval == GDK_KP_Enter) { @@ -519,23 +594,6 @@ return NULL; } -/* todo: remove this -static streamdir_gui_t *find_streamdir_gui_by_tree_view(GtkTreeView *tree_view) -{ - GList *iterator; - streamdir_gui_t *streamdir_gui; - - for (iterator = g_list_first(streamdir_gui_list); iterator != NULL; iterator = g_list_next(iterator)) { - streamdir_gui = iterator->data; - - if ((void *) streamdir_gui->tree_view == (void *) tree_view) - return streamdir_gui; - } - - return NULL; -} -*/ - static streamdir_gui_t *find_streamdir_gui_by_table(GtkTable *table) { GList *iterator; diff -r 8f0a8a0d71c5 -r 457260d55428 src/streambrowser/shoutcast.c --- a/src/streambrowser/shoutcast.c Thu Aug 14 00:46:34 2008 +0200 +++ b/src/streambrowser/shoutcast.c Fri Aug 15 16:00:53 2008 +0200 @@ -72,7 +72,7 @@ g_snprintf(streaminfo_playlist_url, DEF_STRING_LEN, SHOUTCAST_STREAMINFO_URL, streaminfo_id); if (strncmp(streaminfo_playlist_url, streaminfo->playlist_url, DEF_STRING_LEN) == 0) { - debug("shoutcast: updating stream info for '%s/%d' from '%s'\n", streaminfo_name, streaminfo_id, url); + debug("shoutcast: updating stream info for '%s' with id %s from '%s'\n", streaminfo_name, streaminfo_id, url); strcpy(streaminfo->name, streaminfo_name); strcpy(streaminfo->playlist_url, streaminfo_playlist_url); diff -r 8f0a8a0d71c5 -r 457260d55428 src/streambrowser/streambrowser.c --- a/src/streambrowser/streambrowser.c Thu Aug 14 00:46:34 2008 +0200 +++ b/src/streambrowser/streambrowser.c Fri Aug 15 16:00:53 2008 +0200 @@ -57,8 +57,6 @@ static void gui_init(); static void gui_done(); -static void config_load(); -static void config_save(); static void streamdir_update(streamdir_t *streamdir, category_t *category, streaminfo_t *streaminfo, gboolean add_to_playlist); static gpointer update_thread_core(gpointer user_data); @@ -152,6 +150,132 @@ return TRUE; } +void config_load() +{ + streambrowser_cfg.debug = FALSE; + streambrowser_cfg.bookmarks = NULL; + streambrowser_cfg.bookmarks_count = 0; + + mcs_handle_t *db; + if ((db = aud_cfg_db_open()) == NULL) { + failure("failed to load configuration\n"); + return; + } + + aud_cfg_db_get_bool(db, "streambrowser", "debug", &streambrowser_cfg.debug); + aud_cfg_db_get_int(db, "streambrowser", "bookmarks_count", &streambrowser_cfg.bookmarks_count); + + debug("debug = %d\n", streambrowser_cfg.debug); + + if (streambrowser_cfg.bookmarks_count == 0) + streambrowser_cfg.bookmarks = NULL; + else + streambrowser_cfg.bookmarks = g_malloc(sizeof(bookmark_t) * streambrowser_cfg.bookmarks_count); + + int i; + gchar item[DEF_STRING_LEN]; + gchar *value; + for (i = 0; i < streambrowser_cfg.bookmarks_count; i++) { + g_snprintf(item, DEF_STRING_LEN, "bookmark%d_streamdir_name", i); + if (aud_cfg_db_get_string(db, "streambrowser", item, &value)) { + strncpy(streambrowser_cfg.bookmarks[i].streamdir_name, value, DEF_STRING_LEN); + g_free(value); + } + else + streambrowser_cfg.bookmarks[i].streamdir_name[0] = '\0'; + + g_snprintf(item, DEF_STRING_LEN, "bookmark%d_name", i); + if (aud_cfg_db_get_string(db, "streambrowser", item, &value)) { + strncpy(streambrowser_cfg.bookmarks[i].name, value, DEF_STRING_LEN); + g_free(value); + } + else + streambrowser_cfg.bookmarks[i].name[0] = '\0'; + + g_snprintf(item, DEF_STRING_LEN, "bookmark%d_playlist_url", i); + if (aud_cfg_db_get_string(db, "streambrowser", item, &value)) { + strncpy(streambrowser_cfg.bookmarks[i].playlist_url, value, DEF_STRING_LEN); + g_free(value); + } + else + streambrowser_cfg.bookmarks[i].playlist_url[0] = '\0'; + + g_snprintf(item, DEF_STRING_LEN, "bookmark%d_url", i); + if (aud_cfg_db_get_string(db, "streambrowser", item, &value)) { + strncpy(streambrowser_cfg.bookmarks[i].url, value, DEF_STRING_LEN); + g_free(value); + } + else + streambrowser_cfg.bookmarks[i].url[0] = '\0'; + + debug("loaded a bookmark with streamdir_name = '%s', name = '%s', playlist_url = '%s', url = '%s'\n", + streambrowser_cfg.bookmarks[i].streamdir_name, + streambrowser_cfg.bookmarks[i].name, + streambrowser_cfg.bookmarks[i].playlist_url, + streambrowser_cfg.bookmarks[i].url); + } + + debug("loaded %d bookmarks\n", streambrowser_cfg.bookmarks_count); + + aud_cfg_db_close(db); + + debug("configuration loaded\n"); +} + +void config_save() +{ + mcs_handle_t *db; + if ((db = aud_cfg_db_open()) == NULL) { + failure("failed to save configuration\n"); + return; + } + + aud_cfg_db_set_bool(db, "streambrowser", "debug", streambrowser_cfg.debug); + + int old_bookmarks_count, i; + gchar item[DEF_STRING_LEN]; + aud_cfg_db_get_int(db, "streambrowser", "bookmarks_count", &old_bookmarks_count); + aud_cfg_db_set_int(db, "streambrowser", "bookmarks_count", streambrowser_cfg.bookmarks_count); + + for (i = 0; i < streambrowser_cfg.bookmarks_count; i++) { + debug("saving bookmark with streamdir_name = '%s', name = '%s', playlist_url = '%s', url = '%s'\n", + streambrowser_cfg.bookmarks[i].streamdir_name, + streambrowser_cfg.bookmarks[i].name, + streambrowser_cfg.bookmarks[i].playlist_url, + streambrowser_cfg.bookmarks[i].url); + + g_snprintf(item, DEF_STRING_LEN, "bookmark%d_streamdir_name", i); + aud_cfg_db_set_string(db, "streambrowser", item, streambrowser_cfg.bookmarks[i].streamdir_name); + + g_snprintf(item, DEF_STRING_LEN, "bookmark%d_name", i); + aud_cfg_db_set_string(db, "streambrowser", item, streambrowser_cfg.bookmarks[i].name); + + g_snprintf(item, DEF_STRING_LEN, "bookmark%d_playlist_url", i); + aud_cfg_db_set_string(db, "streambrowser", item, streambrowser_cfg.bookmarks[i].playlist_url); + + g_snprintf(item, DEF_STRING_LEN, "bookmark%d_url", i); + aud_cfg_db_set_string(db, "streambrowser", item, streambrowser_cfg.bookmarks[i].url); + } + + for (i = streambrowser_cfg.bookmarks_count; i < old_bookmarks_count; i++) { + g_snprintf(item, DEF_STRING_LEN, "bookmark%d_streamdir_name", i); + aud_cfg_db_unset_key(db, "streambrowser", item); + + g_snprintf(item, DEF_STRING_LEN, "bookmark%d_name", i); + aud_cfg_db_unset_key(db, "streambrowser", item); + + g_snprintf(item, DEF_STRING_LEN, "bookmark%d_playlist_url", i); + aud_cfg_db_unset_key(db, "streambrowser", item); + + g_snprintf(item, DEF_STRING_LEN, "bookmark%d_url", i); + aud_cfg_db_unset_key(db, "streambrowser", item); + } + + aud_cfg_db_close(db); + + debug("configuration saved\n"); +} + gboolean mystrcasestr(const char *haystack, const char *needle) { int len_h = strlen(haystack) + 1; @@ -251,113 +375,6 @@ debug("gui destroyed\n"); } -static void config_load() -{ - streambrowser_cfg.debug = FALSE; - - mcs_handle_t *db; - if ((db = aud_cfg_db_open()) == NULL) { - failure("failed to load configuration\n"); - return; - } - - aud_cfg_db_get_bool(db, "streambrowser", "debug", &streambrowser_cfg.debug); - aud_cfg_db_get_int(db, "streambrowser", "bookmarks_count", &streambrowser_cfg.bookmarks_count); - - streambrowser_cfg.bookmarks = g_malloc(sizeof(bookmark_t) * streambrowser_cfg.bookmarks_count); - - int i; - gchar item[DEF_STRING_LEN]; - gchar *value; - for (i = 0; i < streambrowser_cfg.bookmarks_count; i++) { - g_snprintf(item, DEF_STRING_LEN, "bookmark%d_streamdir_name", i); - aud_cfg_db_get_string(db, "streambrowser", item, &value); - strncpy(streambrowser_cfg.bookmarks[i].streamdir_name, value, DEF_STRING_LEN); - g_free(value); - - g_snprintf(item, DEF_STRING_LEN, "bookmark%d_category_name", i); - aud_cfg_db_get_string(db, "streambrowser", item, &value); - strncpy(streambrowser_cfg.bookmarks[i].category_name, value, DEF_STRING_LEN); - g_free(value); - - g_snprintf(item, DEF_STRING_LEN, "bookmark%d_name", i); - aud_cfg_db_get_string(db, "streambrowser", item, &value); - strncpy(streambrowser_cfg.bookmarks[i].name, value, DEF_STRING_LEN); - g_free(value); - - g_snprintf(item, DEF_STRING_LEN, "bookmark%d_playlist_url", i); - aud_cfg_db_get_string(db, "streambrowser", item, &value); - strncpy(streambrowser_cfg.bookmarks[i].playlist_url, value, DEF_STRING_LEN); - g_free(value); - - g_snprintf(item, DEF_STRING_LEN, "bookmark%d_url", i); - aud_cfg_db_get_string(db, "streambrowser", item, &value); - strncpy(streambrowser_cfg.bookmarks[i].url, value, DEF_STRING_LEN); - g_free(value); - } - - aud_cfg_db_close(db); - - debug("configuration loaded\n"); - debug("debug = %d\n", streambrowser_cfg.debug); - - // todo: write all other config options to the console -} - -static void config_save() -{ - mcs_handle_t *db; - if ((db = aud_cfg_db_open()) == NULL) { - failure("failed to save configuration\n"); - return; - } - - aud_cfg_db_set_bool(db, "streambrowser", "debug", streambrowser_cfg.debug); - - int old_bookmarks_count, i; - gchar item[DEF_STRING_LEN]; - aud_cfg_db_get_int(db, "streambrowser", "bookmarks_count", &old_bookmarks_count); - aud_cfg_db_set_int(db, "streambrowser", "bookmarks_count", streambrowser_cfg.bookmarks_count); - - for (i = 0; i < streambrowser_cfg.bookmarks_count; i++) { - g_snprintf(item, DEF_STRING_LEN, "bookmark%d_streamdir_name", i); - aud_cfg_db_set_string(db, "streambrowser", item, streambrowser_cfg.bookmarks[i].streamdir_name); - - g_snprintf(item, DEF_STRING_LEN, "bookmark%d_category_name", i); - aud_cfg_db_set_string(db, "streambrowser", item, streambrowser_cfg.bookmarks[i].category_name); - - g_snprintf(item, DEF_STRING_LEN, "bookmark%d_name", i); - aud_cfg_db_set_string(db, "streambrowser", item, streambrowser_cfg.bookmarks[i].name); - - g_snprintf(item, DEF_STRING_LEN, "bookmark%d_playlist_url", i); - aud_cfg_db_set_string(db, "streambrowser", item, streambrowser_cfg.bookmarks[i].playlist_url); - - g_snprintf(item, DEF_STRING_LEN, "bookmark%d_url", i); - aud_cfg_db_set_string(db, "streambrowser", item, streambrowser_cfg.bookmarks[i].url); - } - - for (i = streambrowser_cfg.bookmarks_count; i < old_bookmarks_count; i++) { - g_snprintf(item, DEF_STRING_LEN, "bookmark%d_streamdir_name", i); - aud_cfg_db_unset_key(db, "streambrowser", item); - - g_snprintf(item, DEF_STRING_LEN, "bookmark%d_category_name", i); - aud_cfg_db_unset_key(db, "streambrowser", item); - - g_snprintf(item, DEF_STRING_LEN, "bookmark%d_name", i); - aud_cfg_db_unset_key(db, "streambrowser", item); - - g_snprintf(item, DEF_STRING_LEN, "bookmark%d_playlist_url", i); - aud_cfg_db_unset_key(db, "streambrowser", item); - - g_snprintf(item, DEF_STRING_LEN, "bookmark%d_url", i); - aud_cfg_db_unset_key(db, "streambrowser", item); - } - - aud_cfg_db_close(db); - - debug("configuration saved\n"); -} - static void streamdir_update(streamdir_t *streamdir, category_t *category, streaminfo_t *streaminfo, gboolean add_to_playlist) { debug("requested streamdir update (streamdir = '%s', category = '%s', streaminfo = '%s', add_to_playlist = %d)\n", @@ -516,7 +533,7 @@ } /* bookmarks */ else if (strncmp(data->streamdir->name, BOOKMARKS_NAME, strlen(BOOKMARKS_NAME)) == 0) { - streamdir_t *streamdir = bookmarks_streamdir_fetch(streambrowser_cfg.bookmarks, streambrowser_cfg.bookmarks_count); + streamdir_t *streamdir = bookmarks_streamdir_fetch(&streambrowser_cfg.bookmarks, &streambrowser_cfg.bookmarks_count); if (streamdir != NULL) { gdk_threads_enter(); streambrowser_win_set_streamdir(streamdir, BOOKMARKS_ICON); @@ -541,11 +558,15 @@ gdk_threads_leave(); } /* bookmarks */ - streamdir = bookmarks_streamdir_fetch(streambrowser_cfg.bookmarks, streambrowser_cfg.bookmarks_count); + streamdir = bookmarks_streamdir_fetch(&streambrowser_cfg.bookmarks, &streambrowser_cfg.bookmarks_count); if (streamdir != NULL) { gdk_threads_enter(); streambrowser_win_set_streamdir(streamdir, BOOKMARKS_ICON); gdk_threads_leave(); + + int i; + for (i = 0; i < category_get_count(streamdir); i++) + streamdir_update(streamdir, category_get_by_index(streamdir, i), NULL, FALSE); } } @@ -592,9 +613,9 @@ static void on_plugin_services_menu_item_click() { - debug("on_plugin_services_menu_item_click()\n"); + debug("on_plugin_services_menu_item_click()\n"); streambrowser_win_show(); - streamdir_update(NULL, NULL, NULL, FALSE); + streamdir_update(NULL, NULL, NULL, FALSE); } diff -r 8f0a8a0d71c5 -r 457260d55428 src/streambrowser/streambrowser.h --- a/src/streambrowser/streambrowser.h Thu Aug 14 00:46:34 2008 +0200 +++ b/src/streambrowser/streambrowser.h Fri Aug 15 16:00:53 2008 +0200 @@ -38,6 +38,9 @@ void failure(const char *fmt, ...); gboolean fetch_remote_to_local_file(gchar *remote_url, gchar *local_url); +void config_load(); +void config_save(); + /* returns true if the substring has been found, false otherwise */ gboolean mystrcasestr(const char *haystack, const char *needle); diff -r 8f0a8a0d71c5 -r 457260d55428 src/streambrowser/streamdir.c --- a/src/streambrowser/streamdir.c Thu Aug 14 00:46:34 2008 +0200 +++ b/src/streambrowser/streamdir.c Fri Aug 15 16:00:53 2008 +0200 @@ -113,17 +113,6 @@ streaminfo_t* streaminfo_new(gchar *name, gchar *playlist_url, gchar *url, gchar *current_track) { - /* replace ampersands with slashes, to avoit gtk/pango markup confusions */ - int i, count = strlen(name); - for (i = 0; i < count; i++) - if (name[i] == '&') - name[i] = '/'; - - count = strlen(current_track); - for (i = 0; i < count; i++) - if (current_track[i] == '&') - current_track[i] = '/'; - streaminfo_t *streaminfo = (streaminfo_t*) g_malloc(sizeof(streaminfo_t)); strncpy(streaminfo->name, name, DEF_STRING_LEN); strncpy(streaminfo->playlist_url, playlist_url, DEF_STRING_LEN);