📄 favorites.cpp
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: favorites.cpp,v 1.7.2.4 2004/10/18 18:53:31 rggammon Exp $ * * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved. * * The contents of this file, and the files included with this file, * are subject to the current version of the RealNetworks Public * Source License (the "RPSL") available at * http://www.helixcommunity.org/content/rpsl unless you have licensed * the file under the current version of the RealNetworks Community * Source License (the "RCSL") available at * http://www.helixcommunity.org/content/rcsl, in which case the RCSL * will apply. You may also obtain the license terms directly from * RealNetworks. You may not use this file except in compliance with * the RPSL or, if you have a valid RCSL with RealNetworks applicable * to this file, the RCSL. Please see the applicable RPSL or RCSL for * the rights, obligations and limitations governing use of the * contents of the file. * * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL") in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your version of * this file only under the terms of the GPL, and not to allow others * to use your version of this file under the terms of either the RPSL * or RCSL, indicate your decision by deleting the provisions above * and replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient may * use your version of this file under the terms of any one of the * RPSL, the RCSL or the GPL. * * This file is part of the Helix DNA Technology. RealNetworks is the * developer of the Original Code and owns the copyrights in the * portions it created. * * This file, and the files included with this file, is distributed * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET * ENJOYMENT OR NON-INFRINGEMENT. * * Technology Compatibility Kit Test Suite(s) Location: * http://www.helixcommunity.org/content/tck * * Contributor(s): * * ***** END LICENSE BLOCK ***** */#include "favorites.h"#include "commonapp.h"#include "hxplayer-i18n.h"#include <string.h>enum{ COLUMN_TITLE = 0, COLUMN_URL, COLUMN_EDITABLE, COLUMN_FAVORITE, NUM_COLUMNS};/* Manage HXFavorite structure * =========================== */HXFavorite*hx_favorite_new(void){ return g_new0(HXFavorite, 1);}voidhx_favorite_free(HXFavorite* favorite){ g_free(favorite->title); g_free(favorite->url); g_free(favorite);}/* Signal handler prototypes * ========================= */extern "C"{void hfd_new_favorite(GtkWidget* widget);void hfd_delete_favorite(GtkWidget* widget);};/* Import/export functionality * ========================= */gbooleanfavorites_export_to_m3u(const gchar* filename, const GList* favorites_list){ GIOChannel* chan; GError *error = NULL; const GList* favorites_iter; gboolean result = TRUE; chan = g_io_channel_new_file(filename, "w", &error); if(error) { g_warning(error->message); g_free(error); error = NULL; return FALSE; } if(!chan) { /* File does not exist */ return FALSE; } favorites_iter = favorites_list; while(favorites_iter) { HXFavorite* favorite = (HXFavorite*)favorites_iter->data; gchar* line; GError* error = NULL; gsize bytes_written; gsize len; GIOStatus status; line = g_strdup_printf("%s\n", favorite->url); len = strlen(line); status = g_io_channel_write_chars(chan, line, len, &bytes_written, &error); g_free(line); if(error) { g_warning(error->message); g_free(error); result = FALSE; break; } if(status != G_IO_STATUS_NORMAL || len != bytes_written) { g_warning("Error writing config file"); result = FALSE; break; } favorites_iter = g_list_next(favorites_iter); } g_io_channel_shutdown(chan, TRUE, &error); return TRUE;}gbooleanfavorites_import_from_m3u(const gchar* filename, GList** favorites_list_ptr){ GIOChannel* chan; GError *error = NULL; GList* favorites_list = *favorites_list_ptr; chan = g_io_channel_new_file(filename, "r", &error); if(error) { g_warning(error->message); g_free(error); error = NULL; return FALSE; } if(!chan) { /* File does not exist */ return FALSE; } for(;;) { GIOStatus status; gchar* line; gsize terminator_pos; status = g_io_channel_read_line(chan, &line, NULL, &terminator_pos, &error); if(error) { g_warning(error->message); g_free(error); error = NULL; break; } if(status == G_IO_STATUS_EOF) { break; } else if(status == G_IO_STATUS_AGAIN || !line) { continue; } else if(status != G_IO_STATUS_NORMAL) { g_warning("Error reading config file"); break; } if(line[terminator_pos] == '\n') { /* Strip newline */ line[terminator_pos] = '\0'; } HXFavorite* favorite; gchar* filename; favorite = hx_favorite_new(); filename = strrchr(line, '/'); if(filename) { filename++; if(*filename) { favorite->title = g_strdup(filename); } } if(!favorite->title) { favorite->title = g_strdup(line); } favorite->url = line; favorites_list = g_list_append(favorites_list, favorite); } g_io_channel_shutdown(chan, TRUE, &error); *favorites_list_ptr = favorites_list; return TRUE;}/* Import/export favorites dialogs * =============================== */static voidhxplay_export_favorites_dialog_response(GtkWidget* dialog, gint response_id, GList* favorites_list){ if(response_id == GTK_RESPONSE_OK || response_id == GTK_RESPONSE_ACCEPT) { const gchar* dialog_selection = NULL; #if GTK_CHECK_VERSION(2, 4, 0) dialog_selection = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));#else dialog_selection = gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog));#endif favorites_export_to_m3u(dialog_selection, favorites_list); }}GtkDialog*hxplay_export_favorites_dialog_new(const GList* favorites_list){ GtkWidget* fs; const gchar* export_favorites = _("Export Favorites");#if GTK_CHECK_VERSION(2, 4, 0) fs = gtk_file_chooser_dialog_new(export_favorites, NULL, GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(fs), TRUE); #else fs = gtk_file_selection_new (export_favorites);#endif g_signal_connect (G_OBJECT (fs), "response", G_CALLBACK (hxplay_export_favorites_dialog_response), (gpointer)favorites_list); return GTK_DIALOG(fs);}static voidhxplay_import_favorites_dialog_response(GtkWidget* dialog, gint response_id, GList** favorites_list_ptr) { if(response_id == GTK_RESPONSE_OK || response_id == GTK_RESPONSE_ACCEPT) { const gchar* dialog_selection = NULL;#if GTK_CHECK_VERSION(2, 4, 0) dialog_selection = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));#else dialog_selection = gtk_file_selection_get_filename(GTK_FILE_SELECTION(dialog));#endif favorites_import_from_m3u(dialog_selection, favorites_list_ptr); }}GtkDialog*hxplay_import_favorites_dialog_new(GList** favorites_list_ptr){ GtkWidget* fs; const gchar* import_favorites = _("Import Favorites");#if GTK_CHECK_VERSION(2, 4, 0) fs = gtk_file_chooser_dialog_new(import_favorites, NULL, GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(fs), TRUE);#else fs = gtk_file_selection_new (import_favorites); gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(fs));#endif g_signal_connect (G_OBJECT (fs), "response", G_CALLBACK (hxplay_import_favorites_dialog_response), favorites_list_ptr); return GTK_DIALOG(fs);}/* Favorites management dialog callbacks * ===================================== */static voidhfd_cell_edited(GtkCellRendererText *cell, const gchar *path_string, const gchar *new_text, gpointer /* data */)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -