# HG changeset patch # User Calin Crisan ccrisan@gmail.com # Date 1218577772 -7200 # Node ID c27da2c06805b6325dabb32f0182e1fd83a9ba5b # Parent 5e97b55f87cf9ca12a9c0c3946da27171fd1893a initial code for bookmarks diff -r 5e97b55f87cf -r c27da2c06805 src/streambrowser/Makefile --- a/src/streambrowser/Makefile Tue Aug 12 20:40:31 2008 +0300 +++ b/src/streambrowser/Makefile Tue Aug 12 23:49:32 2008 +0200 @@ -4,11 +4,13 @@ streamdir.c \ shoutcast.c \ xiph.c \ + bookmarks.c \ gui/about_win.c \ gui/streambrowser_win.c DATA = images/shoutcast.png \ images/xiph.png \ + images/bookmarks.png \ images/streambrowser-16x16.png \ images/streambrowser-64x64.png diff -r 5e97b55f87cf -r c27da2c06805 src/streambrowser/bookmarks.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/streambrowser/bookmarks.c Tue Aug 12 23:49:32 2008 +0200 @@ -0,0 +1,79 @@ +/* + * Audacious Streambrowser Plugin + * + * Copyright (c) 2008 Calin Crisan + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; under version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#include +#include +#include + +#include "streambrowser.h" +#include "bookmarks.h" + + +static bookmark_t *bookmarks; +static int bookmarks_count; + +gboolean bookmarks_streaminfo_fetch(category_t *category, streaminfo_t *streaminfo) +{ +} + +gboolean bookmarks_category_fetch(streamdir_t *streamdir, category_t *category) +{ + debug("bookmarks: filling category '%s'\n", category->name); + + /* free/remove any existing streaminfos in this category */ + while (streaminfo_get_count(category) > 0) + streaminfo_remove(category, streaminfo_get_by_index(category, 0)); + + 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) { + + 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_add(category, streaminfo); + + debug("bookmarks: stream info added\n"); + } + + return TRUE; +} + +streamdir_t* bookmarks_streamdir_fetch(bookmark_t *bms, int count) +{ + bookmarks = bms; + bookmarks_count = count; + + streamdir_t *streamdir = streamdir_new(BOOKMARKS_NAME); + + debug("bookmarks: creating streaming directory for bookmarks\n"); + + category_t *category = category_new("Shoutcast"); + category_add(streamdir, category); + + category = category_new("Xiph"); + category_add(streamdir, category); + + debug("bookmarks: streaming directory successfuly created\n"); + + return streamdir; +} + diff -r 5e97b55f87cf -r c27da2c06805 src/streambrowser/bookmarks.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/streambrowser/bookmarks.h Tue Aug 12 23:49:32 2008 +0200 @@ -0,0 +1,48 @@ +/* + * Audacious Streambrowser Plugin + * + * Copyright (c) 2008 Calin Crisan + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; under version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +#ifndef BOOKMARKS_H +#define BOOKMARKS_H + +#include "streambrowser.h" +#include "streamdir.h" + +#define BOOKMARKS_NAME "Bookmarks" +#define BOOKMARKS_ICON DATA_DIR G_DIR_SEPARATOR_S "images" G_DIR_SEPARATOR_S "bookmarks.png" + + +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]; + gchar url[DEF_STRING_LEN]; + +} bookmark_t; + + +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); + + +#endif // BOOKMARKS_H + diff -r 5e97b55f87cf -r c27da2c06805 src/streambrowser/images/bookmarks.png Binary file src/streambrowser/images/bookmarks.png has changed diff -r 5e97b55f87cf -r c27da2c06805 src/streambrowser/shoutcast.c --- a/src/streambrowser/shoutcast.c Tue Aug 12 20:40:31 2008 +0300 +++ b/src/streambrowser/shoutcast.c Tue Aug 12 23:49:32 2008 +0200 @@ -99,7 +99,7 @@ return TRUE; } -gboolean shoutcast_category_fetch(category_t *category) +gboolean shoutcast_category_fetch(streamdir_t *streamdir, category_t *category) { gchar url[DEF_STRING_LEN]; g_snprintf(url, DEF_STRING_LEN, SHOUTCAST_CATEGORY_URL, category->name); diff -r 5e97b55f87cf -r c27da2c06805 src/streambrowser/shoutcast.h --- a/src/streambrowser/shoutcast.h Tue Aug 12 20:40:31 2008 +0300 +++ b/src/streambrowser/shoutcast.h Tue Aug 12 23:49:32 2008 +0200 @@ -31,7 +31,7 @@ gboolean shoutcast_streaminfo_fetch(category_t *category, streaminfo_t *streaminfo); -gboolean shoutcast_category_fetch(category_t *category); +gboolean shoutcast_category_fetch(streamdir_t *streamdir, category_t *category); streamdir_t* shoutcast_streamdir_fetch(); diff -r 5e97b55f87cf -r c27da2c06805 src/streambrowser/streambrowser.c --- a/src/streambrowser/streambrowser.c Tue Aug 12 20:40:31 2008 +0300 +++ b/src/streambrowser/streambrowser.c Tue Aug 12 23:49:32 2008 +0200 @@ -19,6 +19,7 @@ #include #include +#include #include #include @@ -26,15 +27,26 @@ #include "streamdir.h" #include "shoutcast.h" #include "xiph.h" +#include "bookmarks.h" #include "gui/streambrowser_win.h" #include "gui/about_win.h" typedef struct { + + gboolean debug; + bookmark_t *bookmarks; + int bookmarks_count; + +} streambrowser_cfg_t; + +typedef struct { + streamdir_t *streamdir; category_t *category; streaminfo_t *streaminfo; gboolean add_to_playlist; + } update_thread_data_t; @@ -249,12 +261,47 @@ return; } - aud_cfg_db_get_bool(db, "streambrowser", "debug", &streambrowser_cfg.debug); + 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() @@ -266,6 +313,45 @@ } 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); @@ -372,6 +458,10 @@ else if (strncmp(data->streamdir->name, XIPH_NAME, strlen(XIPH_NAME)) == 0) { xiph_streaminfo_fetch(data->category, data->streaminfo); } + /* bookmarks */ + else if (strncmp(data->streamdir->name, BOOKMARKS_NAME, strlen(BOOKMARKS_NAME)) == 0) { + bookmarks_streaminfo_fetch(data->category, data->streaminfo); + } } gdk_threads_enter(); @@ -388,11 +478,15 @@ /* shoutcast */ if (strncmp(data->streamdir->name, SHOUTCAST_NAME, strlen(SHOUTCAST_NAME)) == 0) { - shoutcast_category_fetch(data->category); + shoutcast_category_fetch(data->streamdir, data->category); } /* xiph */ else if (strncmp(data->streamdir->name, XIPH_NAME, strlen(XIPH_NAME)) == 0) { - xiph_category_fetch(data->category); + xiph_category_fetch(data->streamdir, data->category); + } + /* bookmarks */ + else if (strncmp(data->streamdir->name, BOOKMARKS_NAME, strlen(BOOKMARKS_NAME)) == 0) { + bookmarks_category_fetch(data->streamdir, data->category); } gdk_threads_enter(); @@ -420,6 +514,15 @@ gdk_threads_leave(); } } + /* 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); + if (streamdir != NULL) { + gdk_threads_enter(); + streambrowser_win_set_streamdir(streamdir, BOOKMARKS_ICON); + gdk_threads_leave(); + } + } } /* update all streamdirs */ else { @@ -437,6 +540,13 @@ streambrowser_win_set_streamdir(streamdir, XIPH_ICON); gdk_threads_leave(); } + /* bookmarks */ + 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(); + } } g_free(data); diff -r 5e97b55f87cf -r c27da2c06805 src/streambrowser/streambrowser.h --- a/src/streambrowser/streambrowser.h Tue Aug 12 20:40:31 2008 +0300 +++ b/src/streambrowser/streambrowser.h Tue Aug 12 23:49:32 2008 +0200 @@ -20,11 +20,6 @@ #ifndef STREAMBROWSER_H #define STREAMBROWSER_H -#include - -#include -#include - #define DEF_STRING_LEN 1024 #define DEF_BUFFER_SIZE 512 #define MAX_UPDATE_THREADS 4 @@ -33,13 +28,10 @@ #define STREAMBROWSER_ICON DATA_DIR G_DIR_SEPARATOR_S "images" G_DIR_SEPARATOR_S "streambrowser-64x64.png" -typedef struct { - - gboolean debug; +#include -} streambrowser_cfg_t; - -extern streambrowser_cfg_t streambrowser_cfg; +#include +#include void debug(const char *fmt, ...); diff -r 5e97b55f87cf -r c27da2c06805 src/streambrowser/xiph.c --- a/src/streambrowser/xiph.c Tue Aug 12 20:40:31 2008 +0300 +++ b/src/streambrowser/xiph.c Tue Aug 12 23:49:32 2008 +0200 @@ -90,7 +90,7 @@ return TRUE; } -gboolean xiph_category_fetch(category_t *category) +gboolean xiph_category_fetch(streamdir_t *streamdir, category_t *category) { refresh_streamdir(); diff -r 5e97b55f87cf -r c27da2c06805 src/streambrowser/xiph.h --- a/src/streambrowser/xiph.h Tue Aug 12 20:40:31 2008 +0300 +++ b/src/streambrowser/xiph.h Tue Aug 12 23:49:32 2008 +0200 @@ -30,7 +30,7 @@ gboolean xiph_streaminfo_fetch(category_t *category, streaminfo_t *streaminfo); -gboolean xiph_category_fetch(category_t *category); +gboolean xiph_category_fetch(streamdir_t *streamdir, category_t *category); streamdir_t* xiph_streamdir_fetch();