📄 embeddedapp.cpp
字号:
HXStatisticsObserver* title_observer; HXStatisticsObserver* author_observer; HXStatisticsObserver* copyright_observer;} HXEmbeddedWindow;typedef struct _HXEmbeddedConsole{ /* The audio player is created and used if the console ends up having to play, but does not have an ImageWindow to play into. The image window player links to an ImageWindow in the console, if available. */ HXPlayer* audio_player; HXPlayer* image_window_player; GList* windows_list; const gchar* name; } HXEmbeddedConsole;typedef struct _HXEmbeddedApp{ /* Embedded */ GList* consoles_list; HXEmbeddedConsole* master_console; HXEmbeddedConsole* active_console; /* private - modified by hxwindow_add_update_timer */ guint update_timer_id; guint update_timer_ref_count; guint next_window_id; gboolean have_callbacks; gboolean show_unsupported_browser_dialog; gboolean unsupported_browser_dialog_shown; } HXEmbeddedApp;typedef struct _HXUnsupportedBrowserDialog{ GladeXML* xml; HXEmbeddedWindow* window; GtkWidget* show_warning_in_future_checkbox;} HXUnsupportedBrowserDialog;static GtkWidget* create_controls_image_window (HXEmbeddedWindow* window);static void popup_volume_update_icons (HXEmbeddedWindow* window);static void hxembedded_window_update_volume_icons(HXEmbeddedWindow* window);/* hxembedded_window_get_player may create a player if none exists */static HXPlayer* hxembedded_window_get_player (HXEmbeddedWindow* window);static HXPlayer* hxembedded_window_get_player_no_create(HXEmbeddedWindow* window);/* Our global data is stored in an app object. Data that is common between our player and the top-level player can be found in g_hxcommon_app. */static HXEmbeddedApp g_hxembedded_app;static voidhxwindow_update_mute_ctrl_icons(HXEmbeddedWindow* window){ HXPlayer* player = hxembedded_window_get_player_no_create(window); gboolean mute = FALSE; guint vol = 0; if(player) { mute = hx_player_is_muted(HX_PLAYER(player)); vol = hx_player_get_volume(HX_PLAYER(player)); } if(mute) { gtk_image_set_from_pixbuf(GTK_IMAGE(window->mute_ctrl->image), window->mute_ctrl->mute_pixbuf); } else if(vol == 0) { gtk_image_set_from_pixbuf(GTK_IMAGE(window->mute_ctrl->image), window->mute_ctrl->off_pixbuf); } else if(vol < 33) { gtk_image_set_from_pixbuf(GTK_IMAGE(window->mute_ctrl->image), window->mute_ctrl->low_pixbuf); } else if(vol < 66) { gtk_image_set_from_pixbuf(GTK_IMAGE(window->mute_ctrl->image), window->mute_ctrl->mid_pixbuf); } else { gtk_image_set_from_pixbuf(GTK_IMAGE(window->mute_ctrl->image), window->mute_ctrl->high_pixbuf); } }/* hxembedded_console implementation * ================================= */static voidhxembedded_console_destroy_player_window_associations(HXEmbeddedConsole* console){ /* Destroys all players, and all window associations for a given console */ GList* windows_iter; HXEmbeddedWindow* window = NULL; HXCallbackFlags flags; windows_iter = console->windows_list; while(windows_iter) { window = (HXEmbeddedWindow*)windows_iter->data; /* Remove all player signals */ flags = window->attr.scriptcallbacks; window->attr.scriptcallbacks = (HXCallbackFlags) (window->attr.scriptcallbacks & ~(HX_CALLBACK_ON_AUTHOR_CHANGE | HX_CALLBACK_ON_BUFFERING | HX_CALLBACK_ON_CLIP_CLOSED | HX_CALLBACK_ON_CLIP_OPENED | HX_CALLBACK_ON_CONTACTING | HX_CALLBACK_ON_COPYRIGHT_CHANGE | HX_CALLBACK_ON_ERROR_MESSAGE | HX_CALLBACK_ON_GOTO_URL | HX_CALLBACK_ON_MUTE_CHANGE | HX_CALLBACK_ON_PLAY_STATE_CHANGE | HX_CALLBACK_ON_POS_LENGTH | HX_CALLBACK_ON_POSITION_CHANGE | HX_CALLBACK_ON_POST_SEEK | HX_CALLBACK_ON_PREFETCH_COMPLETE | HX_CALLBACK_ON_PRE_SEEK | HX_CALLBACK_ON_PRESENTATION_CLOSED | HX_CALLBACK_ON_PRESENTATION_OPENED | HX_CALLBACK_ON_SHOW_STATUS | HX_CALLBACK_ON_STATE_CHANGE | HX_CALLBACK_ON_TITLE_CHANGE | HX_CALLBACK_ON_VOLUME_CHANGE)); hxembedded_window_hookup_ipc_callbacks(window); window->attr.scriptcallbacks = flags; windows_iter = g_list_next(windows_iter); } /* The corresponding ImageWindow may have been removed from this console. Set to NULL, and let the console building function reset it. */ console->image_window_player = NULL;}voidhxembedded_console_adopt_player(HXEmbeddedConsole* console){ GList* windows_iter; HXEmbeddedWindow* window = NULL; HXPlayer* player; /* Go through all the status widgets, set the player for them */ windows_iter = console->windows_list; while(windows_iter) { window = (HXEmbeddedWindow*)windows_iter->data; player = hxembedded_window_get_player(window); if(player) { /* Create observers */ if(window->title_observer) { g_object_unref(window->title_observer); } window->title_observer = hx_statistics_observer_new(player, "title"); if(window->author_observer) { g_object_unref(window->author_observer); } window->author_observer = hx_statistics_observer_new(player, "author"); if(window->copyright_observer) { g_object_unref(window->copyright_observer); } window->copyright_observer = hx_statistics_observer_new(player, "copyright"); } player = hxembedded_window_get_player_no_create(window); if(player) { if(window->info_panel) { hxstatus_display_set_player(HX_STATUS_DISPLAY(window->info_panel), player); } if(window->position_field) { hxstatus_display_set_player(HX_STATUS_DISPLAY(window->position_field), player); } if(window->status_field) { hxstatus_display_set_player(HX_STATUS_DISPLAY(window->status_field), player); } if(window->position_slider) { hxstatus_display_set_player(HX_STATUS_DISPLAY(window->position_slider), player); } if(window->tac_ctrl) { hxstatus_display_set_player(HX_STATUS_DISPLAY(window->tac_ctrl), player); } if(window->congestion) { hxstatus_display_set_player(HX_STATUS_DISPLAY(window->congestion), player); } if(window->volume_slider) { guint vol; vol = hx_player_get_volume(player); gtk_range_set_value(GTK_RANGE(window->volume_slider->scale), (gdouble) vol); } if(window->mute_ctrl) { gboolean muted; muted = hx_player_is_muted(player); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(window->mute_ctrl->button), muted); hxembedded_window_update_volume_icons (window); } if(window->mute_volume_popup) { popup_volume_update_icons(window); } } windows_iter = g_list_next(windows_iter); } /* Update ipc callbacks */ hxembedded_window_hookup_ipc_callbacks(window);}/* This function assumes there will be only one player in the console. This is not necessarily true for a _master console. */gbooleanhxembedded_console_build_players_from_windows(HXEmbeddedConsole* console){ GList* windows_iter; HXEmbeddedWindow* window = NULL; /* Step 0: See if all the windows created with Embed have been set with SetWindow. If not, we probably have more SetWindow commands pending, so we return FALSE for now, and wait until all outstanding windows are accounted for. */ windows_iter = console->windows_list; while(windows_iter) { window = (HXEmbeddedWindow*)windows_iter->data; if(!window->is_window_set && (window->attr.width > 0 && window->attr.height > 0)) { return FALSE; } windows_iter = g_list_next(windows_iter); } /* Step 1: Break all existing player-console-window associations */ hxembedded_console_destroy_player_window_associations(console); /* Step 2: See if we can find an image_window player for this console */ windows_iter = console->windows_list; while(windows_iter) { window = (HXEmbeddedWindow*)windows_iter->data; if(window->image_window) { if(console->image_window_player) { /* We already have a player_widget - this can happen if we're using a recent version of mozilla, and we transition between two pages with plugins, and those pages both have consoles with the same name (mozilla will SetWindow the new plugins before UnsetWindow'ing the old plugins), or if an author has put two ImageWindows in a webpage. Content will play to the first ImageWindow it comes across. In addition, there are a couple of other cases where there can be multiple ImageWindows per console. 1. Wall of TV's -- multiple image windows all playing the same clip 2. SMIL Regions -- multiple image windows playing different regions of the same smil file. */ } else { console->image_window_player = window->image_window->player; } } windows_iter = g_list_next(windows_iter); } if(console->image_window_player) { hxembedded_console_adopt_player(console); } return TRUE;}/* Get a list of all windows in this console, and potentially in other consoles if we're the master console. */GList*hxembedded_console_get_windows_list(HXEmbeddedConsole* console){ GList* windows_list = NULL; GList* windows_list_iter; HXEmbeddedConsole* consoles[2] = { NULL, NULL }; guint i; consoles[0] = console; if(console && console == g_hxembedded_app.master_console) { consoles[1] = g_hxembedded_app.active_console; } for(i = 0; i < sizeof(consoles) / sizeof(*consoles); i++) { if(consoles[i]) { windows_list_iter = console->windows_list; while(windows_list_iter) { windows_list = g_list_append(windows_list, windows_list_iter->data); windows_list_iter = g_list_next(windows_list_iter); } } } return windows_list;}/* hxembedded_window implementation * ================================= */static HXEmbeddedWindow*hxembedded_window_get_window(GtkWidget* widget){ GtkWidget* toplevel; HXEmbeddedWindow* window; toplevel = hxcommon_get_toplevel_widget_no_menus(widget); window = (HXEmbeddedWindow*) g_object_get_data(G_OBJECT(toplevel), "hxembeddedwindow"); g_assert(window != NULL); return window;}static HXPlayer*hxembedded_window_get_player_no_create(HXEmbeddedWindow* window){ HXPlayer* player = NULL; g_return_val_if_fail(window->console, NULL); /* Try the master console first */ if(g_hxembedded_app.master_console) { if(g_hxembedded_app.master_console->image_window_player) { player = g_hxembedded_app.master_console->image_window_player; } else if(g_hxembedded_app.master_console->audio_player) { player = g_hxembedded_app.master_console->audio_player; } } if(!player) { player = window->console->image_window_player; } if(!player) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -