[gnome-panel/wip/muktupavels/help-about: 2/5] libgnome-panel: add gp_applet_show_help
- From: Alberts Muktupāvels <muktupavels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel/wip/muktupavels/help-about: 2/5] libgnome-panel: add gp_applet_show_help
- Date: Tue, 31 Mar 2020 17:58:05 +0000 (UTC)
commit 612ad31a6e35b3d0df10f55b9b5232ff42e0107f
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date: Tue Mar 31 19:56:37 2020 +0300
libgnome-panel: add gp_applet_show_help
libgnome-panel/gp-applet.c | 21 ++++++++++-
libgnome-panel/gp-applet.h | 3 ++
libgnome-panel/gp-module-private.h | 5 +++
libgnome-panel/gp-module.c | 71 ++++++++++++++++++++++++++++++++++++++
po/POTFILES.in | 1 +
5 files changed, 100 insertions(+), 1 deletion(-)
---
diff --git a/libgnome-panel/gp-applet.c b/libgnome-panel/gp-applet.c
index d7bc10da2..a992c4b1d 100644
--- a/libgnome-panel/gp-applet.c
+++ b/libgnome-panel/gp-applet.c
@@ -48,7 +48,7 @@
#include "gp-applet-private.h"
#include "gp-enum-types.h"
-#include "gp-module.h"
+#include "gp-module-private.h"
typedef struct
{
@@ -1380,3 +1380,22 @@ gp_applet_get_menu_icon_size (GpApplet *applet)
return priv->menu_icon_size;
}
+
+/**
+ * gp_applet_show_help:
+ * @applet: a #GpApplet
+ * @section: the name of optional section
+ *
+ * Show help. Help URI must be set with gp_applet_info_set_help_uri().
+ */
+void
+gp_applet_show_help (GpApplet *applet,
+ const char *section)
+{
+ GpAppletPrivate *priv;
+
+ g_return_if_fail (GP_IS_APPLET (applet));
+ priv = gp_applet_get_instance_private (applet);
+
+ gp_module_show_help (priv->module, NULL, priv->id, section);
+}
diff --git a/libgnome-panel/gp-applet.h b/libgnome-panel/gp-applet.h
index e99ecaf29..8b4513c05 100644
--- a/libgnome-panel/gp-applet.h
+++ b/libgnome-panel/gp-applet.h
@@ -121,6 +121,9 @@ guint gp_applet_get_panel_icon_size (GpApplet *applet
guint gp_applet_get_menu_icon_size (GpApplet *applet);
+void gp_applet_show_help (GpApplet *applet,
+ const char *section);
+
G_END_DECLS
#endif
diff --git a/libgnome-panel/gp-module-private.h b/libgnome-panel/gp-module-private.h
index 87761bd49..ba8f47360 100644
--- a/libgnome-panel/gp-module-private.h
+++ b/libgnome-panel/gp-module-private.h
@@ -59,6 +59,11 @@ GpApplet *gp_module_applet_new (GpModule *module,
GVariant *initial_settings,
GError **error);
+void gp_module_show_help (GpModule *module,
+ GtkWindow *parent,
+ const char *applet,
+ const char *section);
+
G_END_DECLS
#endif
diff --git a/libgnome-panel/gp-module.c b/libgnome-panel/gp-module.c
index 824edfed7..64f21ab79 100644
--- a/libgnome-panel/gp-module.c
+++ b/libgnome-panel/gp-module.c
@@ -108,6 +108,7 @@
#include "config.h"
+#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include <stdarg.h>
@@ -650,3 +651,73 @@ gp_module_applet_new (GpModule *module,
"gettext-domain", module->gettext_domain,
NULL);
}
+
+void
+gp_module_show_help (GpModule *module,
+ GtkWindow *parent,
+ const char *applet,
+ const char *section)
+{
+ GpAppletInfo *info;
+ char *help_uri;
+ guint32 timestamp;
+ GError *error;
+ char *message;
+ GtkWidget *dialog;
+
+ info = get_applet_info (module, applet, NULL);
+ g_assert (info != NULL);
+
+ if (info->help_uri == NULL || *info->help_uri == '\0')
+ return;
+
+ if (section != NULL && *section != '\0')
+ help_uri = g_strdup_printf ("%s/%s", info->help_uri, section);
+ else
+ help_uri = g_strdup (info->help_uri);
+
+ timestamp = gtk_get_current_event_time ();
+
+ error = NULL;
+ gtk_show_uri_on_window (parent, help_uri, timestamp, &error);
+
+ if (error == NULL)
+ {
+ g_free (help_uri);
+ return;
+ }
+
+ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+ {
+ g_error_free (error);
+ g_free (help_uri);
+ return;
+ }
+
+ message = g_markup_printf_escaped (_("Could not display help document '%s'"),
+ help_uri);
+
+ dialog = gtk_message_dialog_new (parent,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "%s",
+ message);
+
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ "%s",
+ error->message);
+
+ g_signal_connect (dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
+
+ gtk_window_set_title (GTK_WINDOW (dialog),
+ _("Error displaying help document"));
+
+ gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+ gtk_widget_show (dialog);
+
+ g_error_free (error);
+
+ g_free (help_uri);
+ g_free (message);
+}
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 28f6e7a05..20f72e907 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -37,6 +37,7 @@ gnome-panel/panel-run-dialog.ui
gnome-panel/panel-toplevel.c
gnome-panel/panel-util.c
libgnome-panel/gp-initial-setup-dialog.c
+libgnome-panel/gp-module.c
modules/clock/calendar-client.c
modules/clock/calendar-window.c
modules/clock/clock-applet.c
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]