📄 st-shell.c
字号:
/* * 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 <unistd.h>#include <errno.h>#include <glib/gi18n.h>#include <gtk/gtk.h>#include "sg-util.h"#include "sgtk-hig.h"#include "sgtk-util.h"#include "st-shell.h"#include "st-browser-tab.h"#include "st-settings.h"#include "sgtk-message-dialog.h"#include "sgtk-find-dialog.h"#include "st-dialog-api.h"#include "st-action.h"#include "st-about-dialog.h"#include "st-stream-properties-dialog.h"#include "st-preferences-dialog.h"#include "st-stock.h"#include "st-stream-menu-items.h"#include "st-handlers.h"#include "st-thread.h"#include "st-link.h"#include "st-statusbar.h"#include "st-preselections.h"#include "st-main.h"#include "st-browser-tab-label.h"#include "st-stream-store.h"#include "st-util.h"#include "st-stream-columns-dialog.h"#include "st-session.h"/*** cpp *********************************************************************/#define FIND_NAVIGATION_SENSITIVE \ (st_settings.find_token && *st_settings.find_token)/*** type definitions ********************************************************/struct _STShellPrivate{ GtkWidget *window; GtkAccelGroup *accel_group; GtkWidget *box; /* menubar */ GtkItemFactory *factory; GtkWidget *menubar; STStreamMenuItems *stream_items; GtkWidget *select_all_item; GtkWidget *find_item; GtkWidget *find_next_item; GtkWidget *find_previous_item; GtkWidget *search_in_all_categories_item; GtkWidget *stop_item; GtkWidget *reload_item; GtkWidget *view_tab_icons_item; GtkWidget *directories_menu; GtkWidget *directory_preferences_item; GtkWidget *directory_homepage_item; GtkWidget *previous_directory_item; GtkWidget *next_directory_item; GtkWidget *move_directory_left_item; GtkWidget *move_directory_right_item; GSList *directory_items; /* toolbar */ GtkWidget *toolbar; GtkWidget *tune_in_button; GtkWidget *record_button; GtkWidget *browse_button; GtkWidget *stop_button; GtkWidget *reload_button; GtkWidget *link; /* notebook */ GtkWidget *notebook; unsigned int switch_page_hid; /* statusbox */ GtkWidget *statusbox; GSList *tabs; char *find_token; gboolean find_case_sensitive; STBrowserTabStreamTask *tune_in_task; gboolean restart; /* dialogs */ GtkWidget *stream_properties; GtkWidget *stream_columns; GtkWidget *find; GtkWidget *preferences; GtkWidget *about; /* fullscreen mode */ gboolean fullscreen; GtkWidget *leave_fullscreen_popup; gboolean leave_fullscreen_popup_visible; unsigned int leave_fullscreen_timeout_id; unsigned int screen_size_changed_hid; unsigned int key_press_event_hid;};/*** variable declarations ***************************************************/static GObjectClass *parent_class = NULL;STShell *st_shell = NULL;/*** function declarations ***************************************************/static void st_shell_class_init (STShellClass *class);static void st_shell_init (STShell *shell);static void st_shell_finalize (GObject *object);static void st_shell_make_window (STShell *shell);static void st_shell_make_menubar (STShell *shell);static void st_shell_menubar_make_directory_items (STShell *shell);static void st_shell_menubar_select_directory_item (STShell *shell);static void st_shell_make_toolbar (STShell *shell);static void st_shell_make_notebook (STShell *shell);static void st_shell_make_statusbox (STShell *shell);static void st_shell_menubar_init_view_item (STShell *shell, const char *path, gboolean *var);static void st_shell_menubar_view_toggled_h (GtkCheckMenuItem *item, gpointer user_data);static void st_shell_menubar_init_toolbar_style_item (STShell *shell, const char *path, int style);static void st_shell_menubar_toolbar_style_toggled_h (GtkCheckMenuItem *item, gpointer user_data);static void st_shell_menubar_init_toolbar_size_item (STShell *shell, const char *path, int size);static void st_shell_menubar_toolbar_size_toggled_h (GtkCheckMenuItem *item, gpointer user_data);static void st_shell_menubar_directory_toggled_h (GtkCheckMenuItem *item, gpointer user_data);static gboolean st_shell_window_state_event_h (GtkWidget *widget, GdkEventWindowState *event, gpointer user_data);static gboolean st_shell_window_delete_event_h (GtkWidget *widget, GdkEvent *event, gpointer user_data);static void st_shell_fullscreen (STShell *shell);static void st_shell_unfullscreen (STShell *shell);static void st_shell_leave_fullscreen_button_clicked_h (GtkButton *button, gpointer user_data);static gboolean st_shell_leave_fullscreen_timeout_cb (gpointer data);static gboolean st_shell_leave_fullscreen_enter_notify_event_h (GtkWidget *widget, GdkEventCrossing *event, gpointer user_data);static gboolean st_shell_leave_fullscreen_leave_notify_event_h (GtkWidget *widget, GdkEventCrossing *event, gpointer user_data);static void st_shell_update_leave_fullscreen_popup_position (STShell *shell);static void st_shell_screen_size_changed_h (GdkScreen *screen, gpointer user_data);static gboolean st_shell_window_key_press_event_h (GtkWidget *widget, GdkEventKey *event, gpointer user_data);static void st_shell_toolbar_button_clicked_h (GtkButton *button, gpointer user_data);static void st_shell_tab_label_drag_begin_h (GtkWidget *widget, GdkDragContext *drag_context, gpointer user_data);static void st_shell_tab_label_drag_end_h (GtkWidget *widget, GdkDragContext *drag_context, gpointer user_data);static int st_shell_handlers_compare (gconstpointer a, gconstpointer b, gpointer user_data);static void st_shell_tab_label_drag_motion_h (GtkWidget *widget, GdkDragContext *drag_context, int x, int y, unsigned int _time, gpointer user_data);static void st_shell_switch_page_h (GtkNotebook *notebook, GtkNotebookPage *page, unsigned int page_num, gpointer user_data);static void st_shell_tab_selected (STShell *shell);static void st_shell_tab_moved (STShell *shell);static void st_shell_update_visibility (STShell *shell);static void st_shell_update_toolbar_style (STShell *shell);static void st_shell_update_toolbar_size (STShell *shell);static void st_shell_update_title (STShell *shell);static void st_shell_update_sensitivity (STShell *shell);static STBrowserTab *st_shell_get_selected_tab (STShell *shell);static gboolean st_shell_can_stop (STShell *shell);static void st_shell_stop (STShell *shell);static gboolean st_shell_can_reload (STShell *shell);static void st_shell_reload (STShell *shell);static gboolean st_shell_can_select_all (STShell *shell);static void st_shell_select_all (STShell *shell);static gboolean st_shell_can_find (STShell *shell);static void st_shell_find (STShell *shell);static void st_shell_find_notify_h (GObject *object, GParamSpec *pspec, gpointer user_data);static void st_shell_find_response_h (GtkDialog *dialog, int response, gpointer data);static gboolean st_shell_can_find_next (STShell *shell);static void st_shell_find_next (STShell *shell);static gboolean st_shell_can_find_previous (STShell *shell);static void st_shell_find_previous (STShell *shell);static void st_shell_find_real (STShell *shell, sGtkDirection direction, gboolean wrap_around);static gboolean st_shell_can_search_in_all_categories (STShell *shell);static void st_shell_search_in_all_categories (STShell *shell);static void st_shell_stream_properties_response_h (GtkDialog *dialog, int response, gpointer data);static void st_shell_present_preferences (STShell *shell);static void st_shell_present_about (STShell *shell);static void st_shell_dialog_response_h (GtkDialog *dialog, int response, gpointer data);static gboolean st_shell_can_present_directory_preferences (STShell *shell);static void st_shell_present_directory_preferences (STShell *shell);static gboolean st_shell_can_visit_directory_homepage (STShell *shell);static void st_shell_visit_directory_homepage (STShell *shell);static void st_shell_stream_properties_update_stream (STShell *shell);static gboolean st_shell_can_select_previous_tab (STShell *shell);static void st_shell_select_previous_tab (STShell *shell);static gboolean st_shell_can_select_next_tab (STShell *shell);static void st_shell_select_next_tab (STShell *shell);static gboolean st_shell_can_move_tab (STShell *shell, int direction);static void st_shell_move_tab (STShell *shell, int direction);static gboolean st_shell_can_move_tab_left (STShell *shell);static void st_shell_move_tab_left (STShell *shell);static gboolean st_shell_can_move_tab_right (STShell *shell);static void st_shell_move_tab_right (STShell *shell);static void st_shell_help (STShell *shell);static void st_shell_homepage (STShell *shell);static void st_shell_new_preselection (STShell *shell);static STBrowserTab *st_shell_get_tab_with_handler (STShell *shell, STHandler *handler);static void st_shell_select_tab (STShell *shell, STBrowserTab *tab, gboolean force_update);static void st_shell_set_statusbar_of_tab (STShell *shell, STBrowserTab *tab);static void st_shell_category_selection_changed_h (STCategoryView *view, gpointer user_data);static void st_shell_stream_selection_changed_h (STStreamView *view, gpointer user_data);static void st_shell_stream_activated_h (GtkTreeView *treeview, GtkTreePath *arg1, GtkTreeViewColumn *arg2, gpointer user_data);static void st_shell_tab_notify_running_h (GObject *object, GParamSpec *pspec, gpointer user_data);static void st_shell_tab_stream_task_added_h (STBrowserTab *tab, STBrowserTabStreamTask *task, gpointer user_data);static void st_shell_tab_stream_task_removed_h (STBrowserTab *tab, STBrowserTabStreamTask *task, gpointer user_data);/*** implementation **********************************************************/GTypest_shell_get_type (void){ static GType shell_type = 0; if (! shell_type) { static const GTypeInfo shell_info = { sizeof(STShellClass), NULL, NULL, (GClassInitFunc) st_shell_class_init, NULL, NULL, sizeof(STShell), 0, (GInstanceInitFunc) st_shell_init, }; shell_type = g_type_register_static(G_TYPE_OBJECT, "STShell", &shell_info, 0); } return shell_type;}static voidst_shell_class_init (STShellClass *class){ GObjectClass *object_class = G_OBJECT_CLASS(class); parent_class = g_type_class_peek_parent(class); g_type_class_add_private(class, sizeof(STShellPrivate)); object_class->finalize = st_shell_finalize;}static voidst_shell_init (STShell *shell){ STHandler *handler = NULL; g_return_if_fail(st_shell == NULL); st_shell = shell; shell->priv = G_TYPE_INSTANCE_GET_PRIVATE(shell, ST_TYPE_SHELL, STShellPrivate); st_shell_make_window(shell); st_shell_make_menubar(shell); st_shell_make_toolbar(shell); st_shell_make_notebook(shell); st_shell_make_statusbox(shell); st_shell_update_visibility(shell); st_shell_update_toolbar_style(shell); st_shell_update_toolbar_size(shell); /* select a tab and focus its stream view */ if (st_settings.selected_handler_name) handler = st_handlers_find_by_name(st_settings.selected_handler_name); if (! handler && st_handlers_list) handler = st_handlers_list->data; /* fallback */ if (handler) { STBrowserTab *tab; tab = st_shell_get_tab_with_handler(shell, handler); st_shell_select_tab(shell, tab, TRUE); gtk_widget_grab_focus(GTK_WIDGET(tab->stream_view)); } /* initialize the sensitivity */ st_shell_update_sensitivity(shell);}static voidst_shell_finalize (GObject *object){ STShell *shell = ST_SHELL(object); GSList *l; STBrowserTab *selected_tab; /* stop everything */ SG_LIST_FOREACH(l, shell->priv->tabs) if (st_browser_tab_can_stop(l->data)) st_browser_tab_stop(l->data); /* store some settings */ selected_tab = st_shell_get_selected_tab(shell); if (selected_tab) { g_free(st_settings.selected_handler_name); st_settings.selected_handler_name = g_strdup(st_handler_get_name(selected_tab->handler)); } /* destroy the main window before the final processing (HIG 2.0) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -