summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGlynn Foster <glynn.foster@sun.com>2003-01-14 15:35:24 +0000
committerGlynn Foster <gman@src.gnome.org>2003-01-14 15:35:24 +0000
commit97656d7e299eb2f2063278711eddfff0d2db9392 (patch)
tree5498a97dba4cc045f326e5f4d3eec93bc06c66c5 /src
parent15538e120d8d184962d406fee5d7bd6600d2463d (diff)
Update to add new gconf requirement.
2003-01-14 Glynn Foster <glynn.foster@sun.com> * configure.in: Update to add new gconf requirement. * src/zenity.h, src/about.c: Hurray for a new about box, although it lacks an icon. I wonder if people would actually like to see this as part of the dialog options. Can't think of any reason to do so at the moment though. Large chunks copied from libgnomeui/gnome-about.[ch] * src/util.h, src/util.c: Add new helper functions because I don't want to touch gnome_program with a bargepole. Copied from libgnome/gnome-url.[ch] * po/POTFILES.in: Add missing files. I think we have everything now. * TODO: Update accordingly.
Diffstat (limited to 'src')
-rw-r--r--src/about.c160
-rw-r--r--src/util.c107
-rw-r--r--src/util.h2
-rw-r--r--src/zenity.h1
4 files changed, 260 insertions, 10 deletions
diff --git a/src/about.c b/src/about.c
index 43b023c..3818c2c 100644
--- a/src/about.c
+++ b/src/about.c
@@ -2,6 +2,8 @@
* about.c
*
* Copyright (C) 2002 Sun Microsystems, Inc.
+ * Copyright (C) 2001 CodeFactory AB
+ * Copyright (C) 2001, 2002 Anders Carlsson
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -19,22 +21,33 @@
* Boston, MA 02111-1307, USA.
*
* Authors: Glynn Foster <glynn.foster@sun.com>
+ * Anders Carlsson <andersca@gnu.org>
*/
-#include <glade/glade.h>
#include "config.h"
#include "zenity.h"
#include "util.h"
+#include <glade/glade.h>
+
+#define GTK_RESPONSE_CREDITS 0
-#define GTK_RESPONSE_CREDITS 1
+static GtkWidget *dialog;
+static GtkWidget *cred_dialog;
static void zenity_about_dialog_response (GtkWidget *widget, int response, gpointer data);
+static const gchar *author_credits[] = {
+ "Glynn Foster <glynn.foster@sun.com>",
+ "Mike Newman <mike@gtnorthern.demon.co.uk>",
+ NULL
+};
+
+gchar *translator_credits;
+
void
zenity_about (ZenityData *data)
{
GladeXML *glade_dialog = NULL;
- GtkWidget *dialog;
GtkWidget *label;
gchar *text;
@@ -43,8 +56,11 @@ zenity_about (ZenityData *data)
if (glade_dialog == NULL) {
data->exit_code = -1;
return;
- }
-
+ }
+
+ translator_credits = _("translator_credits");
+
+
glade_xml_signal_autoconnect (glade_dialog);
dialog = glade_xml_get_widget (glade_dialog, "zenity_about_dialog");
@@ -76,10 +92,138 @@ zenity_about (ZenityData *data)
gtk_main ();
}
+static GtkWidget *
+zenity_about_create_label (void)
+{
+ GtkWidget *label;
+
+ label = gtk_label_new ("");
+ gtk_label_set_selectable (GTK_LABEL (label), TRUE);
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
+ gtk_misc_set_padding (GTK_MISC (label), 8, 8);
+
+ gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
+
+ return label;
+}
+
+static void
+zenity_about_update_author_label (GtkWidget *label)
+{
+ GString *string;
+ gchar *tmp;
+ gint i = 0;
+
+ gtk_widget_show (label);
+
+ string = g_string_new ("");
+
+ for (i = 0; author_credits[i] != NULL; i++) {
+ tmp = g_markup_escape_text (author_credits[i], -1);
+ g_string_append (string, tmp);
+
+ if (author_credits[i+1] != NULL)
+ g_string_append (string, "\n");
+
+ g_free (tmp);
+ }
+ gtk_label_set_markup (GTK_LABEL (label), string->str);
+ g_string_free (string, TRUE);
+}
+
+static void
+zenity_about_update_translator_label (GtkWidget *label)
+{
+ GString *string;
+ gchar *tmp;
+
+ if (strcmp (translator_credits, "translator_credits") == 0) {
+ gtk_widget_hide (label);
+ return;
+ } else {
+ gtk_widget_show (label);
+ }
+
+ string = g_string_new ("");
+
+ tmp = g_markup_escape_text (translator_credits, -1);
+ g_string_append (string, tmp);
+ g_free (tmp);
+
+ gtk_label_set_markup (GTK_LABEL (label), string->str);
+ g_string_free (string, TRUE);
+}
+
+static void
+zenity_about_dialog_credits_response (GtkWidget *widget, int response, gpointer data)
+{
+ gtk_widget_destroy (widget);
+ widget = NULL;
+}
+
+static void
+zenity_about_display_credits_dialog (void)
+{
+ GtkWidget *credits_dialog;
+ GtkWidget *label, *notebook, *sw;
+
+ if (cred_dialog != NULL) {
+ gtk_window_present (GTK_WINDOW (cred_dialog));
+ return;
+ }
+
+ credits_dialog = gtk_dialog_new_with_buttons (_("Credits"),
+ GTK_WINDOW (dialog), GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
+
+ g_signal_connect (G_OBJECT (credits_dialog), "response",
+ G_CALLBACK (gtk_widget_destroy), credits_dialog);
+ g_signal_connect (G_OBJECT (credits_dialog), "destroy",
+ G_CALLBACK (gtk_widget_destroyed), &cred_dialog);
+
+ cred_dialog = credits_dialog;
+
+ gtk_window_set_default_size (GTK_WINDOW (credits_dialog), 360, 260);
+ gtk_dialog_set_default_response (GTK_DIALOG (credits_dialog), GTK_RESPONSE_OK);
+
+ notebook = gtk_notebook_new ();
+ gtk_container_set_border_width (GTK_CONTAINER (notebook), 8);
+ gtk_box_pack_start (GTK_BOX (GTK_DIALOG (credits_dialog)->vbox), notebook, TRUE, TRUE, 0);
+
+ if (author_credits != NULL) {
+ label = zenity_about_create_label ();
+ sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (sw), label);
+ gtk_viewport_set_shadow_type (GTK_VIEWPORT (GTK_BIN (sw)->child), GTK_SHADOW_NONE);
+ gtk_notebook_append_page (GTK_NOTEBOOK (notebook), sw,
+ gtk_label_new (_("Written by")));
+ zenity_about_update_author_label (label);
+ }
+
+ if (translator_credits != NULL) {
+ label = zenity_about_create_label ();
+ sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+ GTK_POLICY_AUTOMATIC,
+ GTK_POLICY_AUTOMATIC);
+ gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (sw), label);
+ gtk_viewport_set_shadow_type (GTK_VIEWPORT (GTK_BIN (sw)->child), GTK_SHADOW_NONE);
+ gtk_notebook_append_page (GTK_NOTEBOOK (notebook), sw,
+ gtk_label_new (_("Translated by")));
+ zenity_about_update_translator_label (label);
+ }
+
+ gtk_widget_show_all (credits_dialog);
+}
+
static void
zenity_about_dialog_response (GtkWidget *widget, int response, gpointer data)
{
ZenityData *zen_data = data;
+ GError *error = NULL;
switch (response) {
case GTK_RESPONSE_OK:
@@ -88,13 +232,11 @@ zenity_about_dialog_response (GtkWidget *widget, int response, gpointer data)
break;
case GTK_RESPONSE_HELP:
- zen_data->exit_code = 1;
- gtk_main_quit ();
+ zenity_util_show_help ("ghelp:///", NULL);
break;
case GTK_RESPONSE_CREDITS:
- zen_data->exit_code = 1;
- gtk_main_quit ();
+ zenity_about_display_credits_dialog ();
break;
default:
/* Esc dialog */
diff --git a/src/util.c b/src/util.c
index b9116ac..dbc30d8 100644
--- a/src/util.c
+++ b/src/util.c
@@ -2,6 +2,8 @@
* util.c
*
* Copyright (C) 2002 Sun Microsystems, Inc.
+ * (C) 1999, 2000 Red Hat Inc.
+ * (C) 1998 James Henstridge
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -19,13 +21,18 @@
* Boston, MA 02111-1307, USA.
*
* Authors: Glynn Foster <glynn.foster@sun.com>
- * Havoc Pennington <hp@redhat.com>
+ * Havoc Pennington <hp@redhat.com>
+ * James Henstridge <james@daa.com.au>
*/
#include <stdio.h>
#include <errno.h>
#include "config.h"
#include "util.h"
+#include <gconf/gconf-client.h>
+
+#define URL_HANDLER_DIR "/desktop/gnome/url-handlers/"
+#define DEFAULT_HANDLER_PATH "/desktop/gnome/url-handlers/unknown/command"
GladeXML*
zenity_util_load_glade_file (const gchar *widget_root)
@@ -156,3 +163,101 @@ zenity_util_set_window_icon_from_stock (GtkWidget *widget, const gchar *stock_id
gtk_window_set_icon (GTK_WINDOW (widget), pixbuf);
g_object_unref (pixbuf);
}
+
+/* This is copied from libgnome/gnome-url.c since we try and avoid using
+ * the evils of gnome_program_init (), which messes up the commandline
+ */
+
+gboolean
+zenity_util_show_help (const gchar *url, GError **error)
+{
+ GConfClient *client;
+ gint i;
+ gchar *pos, *template;
+ int argc;
+ char **argv;
+ gboolean ret;
+
+ g_return_val_if_fail (url != NULL, FALSE);
+
+ pos = strchr (url, ':');
+
+ client = gconf_client_get_default ();
+
+ if (pos != NULL) {
+ gchar *protocol, *path;
+
+ g_return_val_if_fail (pos >= url, FALSE);
+
+ protocol = g_new (gchar, pos - url + 1);
+ strncpy (protocol, url, pos - url);
+ protocol[pos - url] = '\0';
+ g_ascii_strdown (protocol, -1);
+
+ path = g_strconcat (URL_HANDLER_DIR, protocol, "/command", NULL);
+ template = gconf_client_get_string (client, path, NULL);
+
+ if (template == NULL) {
+ gchar* template_temp;
+
+ template_temp = gconf_client_get_string (client,
+ DEFAULT_HANDLER_PATH,
+ NULL);
+
+ /* Retry to get the right url handler */
+ template = gconf_client_get_string (client, path, NULL);
+
+ if (template == NULL)
+ template = template_temp;
+ else
+ g_free (template_temp);
+
+ }
+
+ g_free (path);
+ g_free (protocol);
+
+ } else {
+ /* no ':' ? this shouldn't happen. Use default handler */
+ template = gconf_client_get_string (client,
+ DEFAULT_HANDLER_PATH,
+ NULL);
+ }
+
+ g_object_unref (G_OBJECT (client));
+
+ if (!g_shell_parse_argv (template,
+ &argc,
+ &argv,
+ error)) {
+ g_free (template);
+ return FALSE;
+ }
+
+ g_free (template);
+
+ for (i = 0; i < argc; i++) {
+ char *arg;
+
+ if (strcmp (argv[i], "%s") != 0)
+ continue;
+
+ arg = argv[i];
+ argv[i] = g_strdup (url);
+ g_free (arg);
+ }
+
+ /* This can return some errors */
+ ret = g_spawn_async (NULL /* working directory */,
+ argv,
+ NULL,
+ G_SPAWN_SEARCH_PATH /* flags */,
+ NULL /* child_setup */,
+ NULL /* data */,
+ NULL /* child_pid */,
+ error);
+
+ g_strfreev (argv);
+
+ return ret;
+}
diff --git a/src/util.h b/src/util.h
index 3f9d8e1..99c20cb 100644
--- a/src/util.h
+++ b/src/util.h
@@ -21,6 +21,8 @@ void zenity_util_set_window_icon (GtkWidget *widget,
void zenity_util_set_window_icon_from_stock (GtkWidget *widget,
const gchar *stock_id);
+gboolean zenity_util_show_help (const gchar *url,
+ GError **error);
G_END_DECLS
#endif /* UTIL_H */
diff --git a/src/zenity.h b/src/zenity.h
index 9431138..813fbdd 100644
--- a/src/zenity.h
+++ b/src/zenity.h
@@ -93,6 +93,7 @@ void zenity_text (ZenityData *data,
ZenityTextData *text_data);
void zenity_tree (ZenityData *data,
ZenityTreeData *tree_data);
+void zenity_about (ZenityData *data);
G_END_DECLS