st-preselections.c
来自「linux下网络收音机的源码」· C语言 代码 · 共 545 行 · 第 1/2 页
C
545 行
/* * Copyright (c) 2004 Jean-Yves Lefort * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of Jean-Yves Lefort nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */#include "config.h"#include <string.h>#include <glib.h>#include <glib/gi18n.h>#include "sg-util.h"#include "st-action.h"#include "st-handler.h"#include "st-handlers-api.h"#include "st-stream-store.h"#include "st-util.h"#include "st-util-api.h"/*** cpp *********************************************************************/#define ST_PRESELECTIONS_STREAM(bag) \ ((STPreselectionsStream *) ST_STREAM((bag)))/*** type definitions ********************************************************/typedef struct{ STStream stream; char *name; char *genre; char *homepage; char *url;} STPreselectionsStream;enum { FIELD_NAME, FIELD_GENRE, FIELD_HOMEPAGE, FIELD_URL};typedef struct{ STStreamBag *bag; gboolean taken;} MakeUniqueInfo;/*** variable declarations ***************************************************/STHandler *st_preselections_handler = NULL;/*** function declarations ***************************************************/static STPreselectionsStream *st_preselections_stream_new_cb (gpointer data);static void st_preselections_stream_field_get_cb (STPreselectionsStream *stream, STHandlerField *field, GValue *value, gpointer data);static void st_preselections_stream_field_set_cb (STPreselectionsStream *stream, STHandlerField *field, const GValue *value, gpointer data);static void st_preselections_stream_stock_field_get_cb (STPreselectionsStream *stream, STHandlerStockField stock_field, GValue *value, gpointer data);static gboolean st_preselections_stream_modify_cb (STPreselectionsStream *stream, GSList *fields, GSList *values, gpointer data, GError **err);static gboolean st_preselections_stream_delete_cb (STPreselectionsStream *stream, gpointer data, GError **err);static void st_preselections_stream_free_cb (STPreselectionsStream *stream, gpointer data);static gboolean st_preselections_stream_tune_in_cb (STPreselectionsStream *stream, gpointer data, GError **err);static gboolean st_preselections_stream_record_cb (STPreselectionsStream *stream, gpointer data, GError **err);static gboolean st_preselections_stream_browse_cb (STPreselectionsStream *stream, gpointer data, GError **err);static void st_preselections_init_handler (void);static void st_preselections_make_unique_names (STStreamBag *bag, STStreamStore *preselections);static gboolean st_preselections_make_unique_name_cb (STStreamStore *store, STStreamBag *bag, gpointer data);static gboolean st_preselections_make_unique_visible_name_cb (STStreamStore *store, STStreamBag *bag, gpointer data);/*** implementation **********************************************************/static STPreselectionsStream *st_preselections_stream_new_cb (gpointer data){ return g_new0(STPreselectionsStream, 1);}static voidst_preselections_stream_field_get_cb (STPreselectionsStream *stream, STHandlerField *field, GValue *value, gpointer data){ switch (field->id) { case FIELD_NAME: g_value_set_string(value, stream->name); break; case FIELD_GENRE: g_value_set_string(value, stream->genre); break; case FIELD_HOMEPAGE: g_value_set_string(value, stream->homepage); break; case FIELD_URL: g_value_set_string(value, stream->url); break; default: g_return_if_reached(); }}static voidst_preselections_stream_field_set_cb (STPreselectionsStream *stream, STHandlerField *field, const GValue *value, gpointer data){ switch (field->id) { case FIELD_NAME: g_free(stream->name); stream->name = g_value_dup_string(value); break; case FIELD_GENRE: g_free(stream->genre); stream->genre = g_value_dup_string(value); break; case FIELD_HOMEPAGE: g_free(stream->homepage); stream->homepage = g_value_dup_string(value); break; case FIELD_URL: g_free(stream->url); stream->url = g_value_dup_string(value); break; default: g_return_if_reached(); }}static voidst_preselections_stream_stock_field_get_cb (STPreselectionsStream *stream, STHandlerStockField stock_field, GValue *value, gpointer data){ switch (stock_field) { case ST_HANDLER_STOCK_FIELD_NAME: g_value_set_string(value, stream->name); break; case ST_HANDLER_STOCK_FIELD_GENRE: g_value_set_string(value, stream->genre); break; case ST_HANDLER_STOCK_FIELD_DESCRIPTION: /* nop */ break; case ST_HANDLER_STOCK_FIELD_HOMEPAGE: g_value_set_string(value, stream->homepage); break; case ST_HANDLER_STOCK_FIELD_URI_LIST: { GValueArray *value_array; GValue uri_value = { 0, }; value_array = g_value_array_new(1); g_value_init(&uri_value, G_TYPE_STRING); g_value_set_string(&uri_value, stream->url); g_value_array_append(value_array, &uri_value); g_value_unset(&uri_value); g_value_take_boxed(value, value_array); break; } }}static gbooleanst_preselections_stream_modify_cb (STPreselectionsStream *stream, GSList *fields, GSList *values, gpointer data, GError **err){ GSList *field = fields; GSList *value = values; while (field && value) { st_preselections_stream_field_set_cb(stream, field->data, value->data, NULL); field = field->next; value = value->next; } return TRUE;}static gbooleanst_preselections_stream_delete_cb (STPreselectionsStream *stream, gpointer data, GError **err){ return TRUE; /* nop */}static voidst_preselections_stream_free_cb (STPreselectionsStream *stream, gpointer data){ g_free(stream->name); g_free(stream->homepage); g_free(stream->url);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?