st-preselections.c
来自「linux下网络收音机的源码」· C语言 代码 · 共 545 行 · 第 1/2 页
C
545 行
st_stream_free((STStream *) stream);}static gbooleanst_preselections_stream_tune_in_cb (STPreselectionsStream *stream, gpointer data, GError **err){ if (! stream->url) { g_set_error(err, 0, 0, _("the stream URL is not set")); return FALSE; } return st_action_run("play-stream", stream->url, err);}static gbooleanst_preselections_stream_record_cb (STPreselectionsStream *stream, gpointer data, GError **err){ if (! stream->url) { g_set_error(err, 0, 0, _("the stream URL is not set")); return FALSE; } return st_action_run("record-stream", stream->url, err);}static gbooleanst_preselections_stream_browse_cb (STPreselectionsStream *stream, gpointer data, GError **err){ if (! stream->homepage) { g_set_error(err, 0, 0, _("the stream homepage is not set")); return FALSE; } return st_action_run("view-web", stream->homepage, err);}static voidst_preselections_init_handler (void){ GdkPixbuf *pixbuf; STHandlerField *field; st_preselections_handler = st_handler_new("preselections"); st_handler_set_label(st_preselections_handler, _("Preselections")); st_handler_set_copyright(st_preselections_handler, "Copyright \302\251 2004 Jean-Yves Lefort"); st_handler_set_description(st_preselections_handler, _("Manually Edited Streams")); st_handler_set_flags(st_preselections_handler, ST_HANDLER_NO_CATEGORIES); pixbuf = st_pixbuf_new_from_file(ST_PNG("preselections")); if (pixbuf) { st_handler_set_icon_from_pixbuf(st_preselections_handler, pixbuf); g_object_unref(pixbuf); } st_handler_bind(st_preselections_handler, ST_HANDLER_EVENT_STREAM_NEW, st_preselections_stream_new_cb, NULL); st_handler_bind(st_preselections_handler, ST_HANDLER_EVENT_STREAM_FIELD_GET, st_preselections_stream_field_get_cb, NULL); st_handler_bind(st_preselections_handler, ST_HANDLER_EVENT_STREAM_FIELD_SET, st_preselections_stream_field_set_cb, NULL); st_handler_bind(st_preselections_handler, ST_HANDLER_EVENT_STREAM_STOCK_FIELD_GET, st_preselections_stream_stock_field_get_cb, NULL); st_handler_bind(st_preselections_handler, ST_HANDLER_EVENT_STREAM_MODIFY, st_preselections_stream_modify_cb, NULL); st_handler_bind(st_preselections_handler, ST_HANDLER_EVENT_STREAM_DELETE, st_preselections_stream_delete_cb, NULL); st_handler_bind(st_preselections_handler, ST_HANDLER_EVENT_STREAM_FREE, st_preselections_stream_free_cb, NULL); st_handler_bind(st_preselections_handler, ST_HANDLER_EVENT_STREAM_TUNE_IN, st_preselections_stream_tune_in_cb, NULL); st_handler_bind(st_preselections_handler, ST_HANDLER_EVENT_STREAM_RECORD, st_preselections_stream_record_cb, NULL); st_handler_bind(st_preselections_handler, ST_HANDLER_EVENT_STREAM_BROWSE, st_preselections_stream_browse_cb, NULL); field = st_handler_field_new(FIELD_NAME, _("Name"), G_TYPE_STRING, ST_HANDLER_FIELD_VISIBLE | ST_HANDLER_FIELD_EDITABLE); st_handler_field_set_description(field, _("The preselection name")); st_handler_add_field(st_preselections_handler, field); field = st_handler_field_new(FIELD_GENRE, _("Genre"), G_TYPE_STRING, ST_HANDLER_FIELD_VISIBLE | ST_HANDLER_FIELD_EDITABLE); st_handler_field_set_description(field, _("The preselection genre")); st_handler_add_field(st_preselections_handler, field); field = st_handler_field_new(FIELD_HOMEPAGE, _("Homepage"), G_TYPE_STRING, ST_HANDLER_FIELD_VISIBLE | ST_HANDLER_FIELD_EDITABLE | ST_HANDLER_FIELD_START_HIDDEN); st_handler_field_set_description(field, _("The preselection homepage URL")); st_handler_add_field(st_preselections_handler, field); field = st_handler_field_new(FIELD_URL, _("URL"), G_TYPE_STRING, ST_HANDLER_FIELD_VISIBLE | ST_HANDLER_FIELD_EDITABLE | ST_HANDLER_FIELD_START_HIDDEN); st_handler_field_set_description(field, _("The preselection listen URL")); st_handler_add_field(st_preselections_handler, field); st_handlers_add(st_preselections_handler);}voidst_preselections_init (void){ st_preselections_init_handler(); st_action_register("play-stream", _("Listen to a stream"), "xmms %q"); st_action_register("record-stream", _("Record a stream"), "xterm -e streamripper %q"); st_action_register("view-web", _("Open a web page"), "epiphany %q");}voidst_preselections_add_stock (void){ STStreamStore *preselections; preselections = st_handler_get_streams(st_preselections_handler, ST_CATEGORY_BAG_MAIN); if (! preselections) { int i; const struct { const char *name; const char *genre; const char *homepage; const char *url; } entries[] = { { "Virgin Radio 1215AM", "Eclectic", "http://www.virginradio.co.uk/", "http://ogg.smgradio.com/vr160.ogg" }, { "Virgin Radio Classic Rock", "Classic Rock", "http://www.virginradio.co.uk/", "http://ogg.smgradio.com/vc160.ogg" }, { "The Virgin Radio Groove", "Soul", "http://www.virginradio.co.uk/", "http://ogg.smgradio.com/gr160.ogg" }, { "Kill Radio", "Eclectic", "http://www.killradio.org/", "http://slaptech.net:8000/killradio64.mp3" }, { "DFM Radio Television International", "Alternative, Experimental", "http://dfm.nu/", "http://194.109.209.34:8000/dfm_1" }, { "Blazeradio", "Eclectic", "http://blazeradio.newsroom.uab.edu/", "http://blazeradio.newsroom.uab.edu:8000" } }; preselections = st_stream_store_new(st_preselections_handler); for (i = 0; i < G_N_ELEMENTS(entries); i++) { STStreamBag *stream_bag = st_stream_bag_new(st_preselections_handler); ST_PRESELECTIONS_STREAM(stream_bag)->name = g_strdup(entries[i].name); ST_PRESELECTIONS_STREAM(stream_bag)->genre = g_strdup(entries[i].genre); ST_PRESELECTIONS_STREAM(stream_bag)->homepage = g_strdup(entries[i].homepage); ST_PRESELECTIONS_STREAM(stream_bag)->url = g_strdup(entries[i].url); ST_STREAM(stream_bag)->name = g_strdup_printf("%i", i); st_stream_store_append(preselections, stream_bag); g_object_unref(stream_bag); } st_handler_set_streams(st_preselections_handler, ST_CATEGORY_BAG_MAIN, preselections); } g_object_unref(preselections);}static voidst_preselections_make_unique_names (STStreamBag *bag, STStreamStore *preselections){ MakeUniqueInfo info = { bag }; int i; g_return_if_fail(ST_IS_STREAM_BAG(bag)); g_return_if_fail(ST_IS_STREAM_STORE(preselections)); i = 0; do { g_free(ST_STREAM(bag)->name); ST_STREAM(bag)->name = g_strdup_printf("%i", i++); info.taken = FALSE; st_stream_store_foreach(preselections, st_preselections_make_unique_name_cb, &info); } while (info.taken); i = 0; do { g_free(ST_PRESELECTIONS_STREAM(bag)->name); ST_PRESELECTIONS_STREAM(bag)->name = ++i == 1 ? g_strdup(_("Unnamed preselection")) : g_strdup_printf(_("Unnamed preselection #%i"), i); info.taken = FALSE; st_stream_store_foreach(preselections, st_preselections_make_unique_visible_name_cb, &info); } while (info.taken);}static gbooleanst_preselections_make_unique_name_cb (STStreamStore *store, STStreamBag *bag, gpointer data){ MakeUniqueInfo *info = data; return info->taken = ! strcmp(ST_STREAM(bag)->name, ST_STREAM(info->bag)->name);}static gbooleanst_preselections_make_unique_visible_name_cb (STStreamStore *store, STStreamBag *bag, gpointer data){ MakeUniqueInfo *info = data; return info->taken = ! strcmp(ST_PRESELECTIONS_STREAM(bag)->name, ST_PRESELECTIONS_STREAM(info->bag)->name);}STStreamBag *st_preselections_new (void){ STStreamStore *preselections; STStreamBag *stream_bag; preselections = st_handler_get_streams(st_preselections_handler, ST_CATEGORY_BAG_MAIN); g_return_val_if_fail(preselections != NULL, NULL); stream_bag = st_stream_bag_new(st_preselections_handler); st_preselections_make_unique_names(stream_bag, preselections); st_stream_store_append(preselections, stream_bag); st_stream_store_touch(preselections); g_object_unref(preselections); /* we don't unref stream_bag, that's caller's responsability */ return stream_bag;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?