📄 commonapp.cpp
字号:
g_return_if_fail(context != NULL); hxcommon_launch_context_help(context);} GtkWidget*hxcommon_get_toplevel_widget_no_menus(GtkWidget* widget){ GtkWidget* parent; /* Get the toplevel widget, bypassing menu toplevels */ for(;;) { if(GTK_IS_MENU(widget)) { parent = gtk_menu_get_attach_widget (GTK_MENU (widget)); } else { parent = widget->parent; } if(parent == NULL) { break; } widget = parent; } return widget;}gbooleanhxcommon_player_has_feature (GtkWidget* /* player */, const gchar* feature){ gboolean has_feature = FALSE; #ifdef HELIX_FEATURE_REAL_BRANDING /* If we're branded as a RealPlayer, claim compatibility with RealOne, as authoring often uses this to determine whether or not a player can play SMIL2.0. For Helix Player, do the right thing and don't claim support for RealOne. */ /* http://features.real.com/? */ gchar feature_player[] = "component;player="; gint feature_player_len = sizeof(feature_player) - 1; if(strncmp(feature, feature_player, feature_player_len) == 0) { int version[3]; sscanf(feature + feature_player_len, "%d.%d.%d", &version[0], &version[1], &version[2]); /* We only match version 6.0.10 exactly, as our intention is only to pass the SMIL1.0/SMIL2.0 test authoring uses. */ if(version[0] == 6 && version[1] == 0 && version[2] == 10) { has_feature = TRUE; } } else { g_warning("Unhandled request for feature %s", feature); }#endif return has_feature;}voidhxcommon_run_error_dialog(GtkWindow* win_parent, GdkWindow* embedded_parent, guint hxcode, guint user_code, const gchar* error_string, const gchar* user_string, const gchar* more_info_url){ GtkDialog* dialog; gint response; g_return_if_fail(win_parent != NULL || embedded_parent != NULL); dialog = hxplay_error_dialog_new(hxcode, user_code, error_string, user_string, more_info_url); g_return_if_fail(dialog != NULL); if(win_parent) { gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(win_parent)); } else if(embedded_parent) { /* We do transient setting this way so we can pop up this dialog from the embedded player, where we don't have a GtkWindow to work with. */ g_signal_connect (G_OBJECT (dialog), "realize", G_CALLBACK (hxcommon_embedded_transient_parent_realized), embedded_parent); } do { response = gtk_dialog_run (GTK_DIALOG (dialog)); } while(response == GTK_RESPONSE_HELP); gtk_widget_destroy(GTK_WIDGET(dialog)); }voidhxcommon_run_request_upgrade_dialog(GtkWindow* win_parent, GdkWindow* embedded_parent, const gchar* url, GList* components_list, gboolean blocking){ GtkDialog* dialog; gint response; g_return_if_fail(win_parent != NULL || embedded_parent != NULL); dialog = hxplay_request_upgrade_dialog_new (url, components_list, blocking); g_return_if_fail(dialog != NULL); if(win_parent) { gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(win_parent)); } else if(embedded_parent) { /* We do transient setting this way so we can pop up this dialog from the embedded player, where we don't have a GtkWindow to work with. */ g_signal_connect (G_OBJECT (dialog), "realize", G_CALLBACK (hxcommon_embedded_transient_parent_realized), embedded_parent); } do { response = gtk_dialog_run (GTK_DIALOG (dialog)); } while(response == GTK_RESPONSE_HELP); gtk_widget_destroy(GTK_WIDGET(dialog)); }voidhxcommon_run_authentication_dialog (GtkWindow* win_parent, GdkWindow* embedded_parent, HXPlayer* player, const gchar* server_proxy, const gchar* realm, gboolean is_proxy_server){ /* We run authentication as a modal dialog box. */ GtkDialog* dialog; const gchar* str; gchar* username = NULL; gchar* password = NULL; gint response; g_return_if_fail(win_parent != NULL || embedded_parent != NULL); dialog = hxplay_authentication_dialog_new(player, server_proxy, realm, is_proxy_server); g_return_if_fail(dialog != NULL); if(win_parent) { gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(win_parent)); } else if(embedded_parent) { /* We do transient setting this way so we can pop up this dialog from the embedded player, where we don't have a GtkWindow to work with. */ g_signal_connect (G_OBJECT (dialog), "realize", G_CALLBACK (hxcommon_embedded_transient_parent_realized), embedded_parent); } do { response = gtk_dialog_run (GTK_DIALOG (dialog)); } while(response == GTK_RESPONSE_HELP); if(response == GTK_RESPONSE_OK) { str = hxplay_authentication_dialog_get_username(dialog); if(str) { username = g_strdup(str); } str = hxplay_authentication_dialog_get_password(dialog); if(str) { password = g_strdup(str); } } gtk_widget_destroy(GTK_WIDGET(dialog)); if(username && password) { hx_player_authenticate(player, TRUE, username, password); } if(username) { g_free(username); } if(password) { g_free(password); }}#ifdef HELIX_FEATURE_RP_SIGN_INvoidhxcommon_run_signin_dialog(GtkWindow* parent, HXPlayer* player){ /* We run authentication as a modal dialog box. */ GtkDialog* dialog; const gchar* str; gchar* username = NULL; gchar* password = NULL; gint response; dialog = hxplay_sign_in_dialog_new(player); g_return_if_fail(dialog != NULL); gtk_window_set_transient_for(GTK_WINDOW(dialog), parent); do { response = gtk_dialog_run (GTK_DIALOG (dialog)); } while(response == GTK_RESPONSE_HELP); if(response == GTK_RESPONSE_OK) { str = hxplay_sign_in_dialog_get_username(dialog); if(str) { username = g_strdup(str); } str = hxplay_sign_in_dialog_get_password(dialog); if(str) { password = g_strdup(str); } } gtk_widget_destroy(GTK_WIDGET(dialog)); if(username && password) { const char* pParams = NULL; const char* pSwitchboardParams = NULL; const char* pFormattedParams = ""; //"&language=%@&country=%@"; INT32 nSessionIdIn = 0; INT32 nSessionIdOut = 0; retVal = g_pR1ServiceAuthentication->AuthenticateUser( username, password, nSessionIdIn, pParams, pSwitchboardParams, &nSessionIdOut, pFormattedParams ); if(FAILED(retVal)) { g_warning("sign-in failed"); } } if(username) { g_free(username); } if(password) { g_free(password); }}#endif/* convenience wrapper around g_io_channel_write_chars */gbooleanhxcommon_channel_write(GIOChannel* chan, const gchar* data){ GIOStatus status; GError* error = NULL; gsize bytes_written; gsize len; len = strlen(data); status = g_io_channel_write_chars(chan, data, len, &bytes_written, &error); if(error) { g_warning(error->message); g_error_free(error); return FALSE; } if(status != G_IO_STATUS_NORMAL || len != bytes_written) { g_warning("Error writing config file"); return FALSE; } return TRUE;} static gchar*strdup_and_unescape(const gchar* src_str){ /* This is what the unix prefs do */ gchar* dest_str; gchar* dest_pos; const gchar* src_pos; gint buffer_length = 0; if(!src_str) { return NULL; } /* Calculate buffer length */ src_pos = src_str; while(*src_pos) { if(*src_pos == '%') { src_pos += 3; } else { src_pos++; } buffer_length++; } dest_str = (gchar*)g_malloc(buffer_length + 1); src_pos = src_str; dest_pos = dest_str; while(*src_pos) { if(*src_pos != '%') { *dest_pos++ = *src_pos++; } else { int c = ' '; sscanf(src_pos, "%02x", &c); *dest_pos++ = (gchar)c; src_pos += 3; } } *dest_pos = '\0'; return dest_str; }static gbooleanis_special_character(gchar c){ gboolean is_special = FALSE; is_special = (c == '%' || c == '\n' || c == '='); return is_special;}static gchar*strdup_and_escape(const gchar* src_str){ /* This is what the unix prefs do */ gchar* dest_str; gchar* dest_pos; const gchar* src_pos; gint buffer_length = 0; if(!src_str) { return NULL; } /* Calculate buffer length */ src_pos = src_str; while(*src_pos) { if(is_special_character(*src_pos)) { buffer_length += 3; } else { buffer_length++; } src_pos++; } dest_str = (gchar*)g_malloc(buffer_length + 1); src_pos = src_str; dest_pos = dest_str; while(*src_pos) { if(is_special_character(*src_pos)) { /* These characters are also escaped by the real prefs code in common/util/platform/unix/unix_pref.cpp */ dest_pos += sprintf(dest_pos, "%%%02x", *src_pos); src_pos++; } else { *dest_pos++ = *src_pos++; } } *dest_pos = '\0'; return dest_str;}gchar*hxcommon_strdup_and_escape_url(const gchar* url){ CHXString strEncodedUrl; const char* encoded_url; HX_RESULT result; result = CHXURL::encodeURL(url, strEncodedUrl); g_return_val_if_fail(SUCCEEDED(result), NULL); encoded_url = (const char*) strEncodedUrl; return g_strdup(encoded_url);}gchar*hxcommon_strdup_and_unescape_url(const gchar* url){ CHXString strDecodedUrl; const char* decoded_url; HX_RESULT result; result = CHXURL::decodeURL(url, strDecodedUrl); g_return_val_if_fail(SUCCEEDED(result), NULL); decoded_url = (const char*) strDecodedUrl; return g_strdup(decoded_url);}voidhxcommon_save_preferences(HXMainWindow* window){ GIOChannel* chan; const gchar* home; gchar* filename; GError* error = NULL; gchar* line; GSList* prefs_iter; gboolean result; /* XXXRGG: For now, don't support saving prefs from the embedded player */ g_return_if_fail(window != NULL); if(!g_hxcommon_app.save_preferences) { /* Right now, this means that we're doing a player reset */ return; } home = g_get_home_dir(); g_return_if_fail(home != NULL); filename = g_strdup_printf("%s/%s", home, HXPLAYER_RC); chan = g_io_channel_new_file(filename, "w", &error); g_free(filename); if(error) { if(error->code != G_FILE_ERROR_NOENT) { /* If the file doesn't exist, this may be the first time we've run */ g_warning(error->message); } g_error_free(error); error = NULL; return; } if(!chan) { /* File can't be created */ return; } /* Step 1: Write out all the helix engine preferences */ hxcommon_channel_write(chan, "[helix]\n"); prefs_iter = hx_prefs_get_all_entries(); while(prefs_iter) { HXValue* value = NULL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -