Created
October 20, 2015 18:06
-
-
Save scriptum/a0398b43a9137f06f643 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* xfce_dialog_show_help_with_version: | |
* @parent : transient parent of the dialog, or %NULL. | |
* @component : name of the component opening the help page or %NULL. If the | |
* value is %NULL the target will be the main page of the | |
* documentation website. | |
* @page : subpage of the @component on the website or %NULL. | |
* @offset : anchor offset in @page or %NULL. | |
* @version : alternative version, or %NULL to use xfce_version_string(). | |
* | |
* Asks the user to visit the online documentation. If confirmed, it will open | |
* the webbrowser and redirect the user to the correct location. | |
* | |
* Appart from the @component, @page and @offset the following information | |
* is also send to the server: user language and the xfce_version_string() | |
* or @version if set. | |
* | |
* See also: xfce_dialog_show_help(). | |
* | |
* Since 4.12 | |
*/ | |
void | |
xfce_dialog_show_help_with_version (GtkWindow *parent, | |
const gchar *component, | |
const gchar *page, | |
const gchar *offset, | |
const gchar *version) | |
{ | |
GtkWidget *dialog; | |
const gchar *name; | |
gchar *primary; | |
GString *uri; | |
gchar *locale; | |
GtkWidget *message_box; | |
GtkWidget *button; | |
XfceRc *rc; | |
gboolean auto_online; | |
GdkScreen *screen; | |
g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent)); | |
/* get the user's locale without encoding */ | |
locale = g_strdup (setlocale (LC_MESSAGES, NULL)); | |
if (G_LIKELY (locale != NULL)) | |
locale = g_strdelimit (locale, ".", '\0'); | |
else | |
locale = g_strdup ("C"); | |
/* use desktop version if none is set */ | |
if (version == NULL) | |
version = xfce_version_string (); | |
/* build the redirect uri */ | |
uri = g_string_new (MANUAL_WEBSITE); | |
g_string_append_printf (uri, "?version=%s&locale=%s", version, locale); | |
g_free (locale); | |
if (component != NULL) | |
g_string_append_printf (uri, "&component=%s", component); | |
if (page != NULL) | |
g_string_append_printf (uri, "&page=%s", page); | |
if (offset != NULL) | |
g_string_append_printf (uri, "&offset=%s", offset); | |
/* check if we should automatically go online */ | |
rc = xfce_rc_config_open (XFCE_RESOURCE_CONFIG, "xfce4/help.rc", TRUE); | |
if (rc != NULL) | |
{ | |
auto_online = xfce_rc_read_bool_entry (rc, "auto-online", FALSE); | |
xfce_rc_close (rc); | |
if (auto_online) | |
{ | |
if (parent != NULL) | |
screen = gtk_window_get_screen (GTK_WINDOW (parent)); | |
else | |
screen = xfce_gdk_screen_get_active (NULL); | |
xfce_dialog_show_help_uri (screen, parent, uri); | |
g_string_free (uri, TRUE); | |
return; | |
} | |
} | |
/* try to get a translated name of the application */ | |
name = g_get_application_name (); | |
if (g_strcmp0 (name, g_get_prgname ()) == 0) | |
name = NULL; | |
/* try to get a decent primary text */ | |
if (name != NULL) | |
primary = g_strdup_printf (_("Do you want to read the %s manual online?"), name); | |
else | |
primary = g_strdup (_("Do you want to read the manual online?")); | |
dialog = xfce_message_dialog_new (parent, | |
_("Online Documentation"), | |
#if !GTK_CHECK_VERSION (3, 10, 0) | |
GTK_STOCK_DIALOG_QUESTION, | |
#else | |
"dialog-question", | |
#endif | |
primary, | |
_("You will be redirected to the documentation website " | |
"where the help pages are maintained and translated."), | |
#if !GTK_CHECK_VERSION (3, 10, 0) | |
GTK_STOCK_CANCEL, | |
#else | |
"gtk-cancel", | |
#endif | |
GTK_RESPONSE_NO, | |
XFCE_BUTTON_TYPE_MIXED, | |
#if !GTK_CHECK_VERSION (3, 10, 0) | |
GTK_STOCK_HELP, | |
#else | |
"help-browser", | |
#endif | |
_("_Read Online"), | |
GTK_RESPONSE_YES, | |
NULL); | |
g_free (primary); | |
#if GTK_CHECK_VERSION (2, 22, 0) | |
message_box = gtk_message_dialog_get_message_area (GTK_MESSAGE_DIALOG (dialog)); | |
#else | |
message_box = gtk_widget_get_parent (GTK_MESSAGE_DIALOG (dialog)->label); | |
g_return_if_fail (GTK_IS_VBOX (message_box)); | |
#endif | |
button = gtk_check_button_new_with_mnemonic (_("_Always go directly to the online documentation")); | |
gtk_box_pack_end (GTK_BOX (message_box), button, FALSE, TRUE, 0); | |
g_signal_connect (G_OBJECT (button), "toggled", | |
G_CALLBACK (xfce_dialog_show_help_auto_toggled), NULL); | |
gtk_widget_show (button); | |
/* don't focus the checkbutton */ | |
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES); | |
button = gtk_dialog_get_widget_for_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES); | |
gtk_widget_grab_focus (button); | |
/* show the dialog without locking the mainloop */ | |
gtk_window_set_modal (GTK_WINDOW (dialog), parent != NULL); | |
g_signal_connect (G_OBJECT (dialog), "response", | |
G_CALLBACK (xfce_dialog_show_help_response), uri); | |
gtk_window_present (GTK_WINDOW (dialog)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment