Re: [gnome-network]PATCHES for bug 114826
- From: Emil Soleyman-Zomalan <emil nishra com>
- To: Rodrigo Moya <rodrigo gnome-db org>
- Cc: gnome-network-list gnome org
- Subject: Re: [gnome-network]PATCHES for bug 114826
- Date: Tue, 09 Dec 2003 10:19:41 -0800
On Tue, 2003-12-09 at 03:34, Rodrigo Moya wrote:
> it's still wrong :-(
>
> > msgerror = (gchar *) strerror (errno);
> > msgerror = g_locale_to_utf8 (msgerror, strlen (msgerror), NULL, NULL, NULL);
> > - gnome_error_dialog_parented (_(msgerror), GTK_WINDOW (dialog));
> > +
> > + title = g_strdup_printf ("There is a connection error");
> > + create_error (title, msgerror);
> > +
> > + g_free (title);
> >
> no need to allocate memory for 'title'. Also, you are missing marking
> the strings for translation _("String"), and are leaking 'msgerror',
> which should be freed, since the value returned by g_locate_to_utf8
> is a new allocated string.
Hi Rodrigo,
Please excuse the mistakes. I'm trying to learn GNOME's conventions and
APIs as I go on.
With this patch I've done the following:
[1] I took a look at the #includes and I've re-jiggered them to fit
better with the functions we are using.
ADDED
<gtk/gtklabel.h> for gtk_label_set_use_markup
<gtk/gtkmessagedialog.h> for gtk_message_dialog_new
<libgnome/gnome-help.h> for gnome_help_display
<libgnomeui/gnome-window-icon.h> for gnome_window_icon_set_
default_from_file
[2] All strings are now prefixed with _(" and postfixed with ") so
that they are translatable.
[3] Don't leak msgerror.
[4] Don't allocate memory for 'title'.
--
Emil Soleyman-Zomalan <emil nishra com>
--- gnome-remote-shell.c.orig 2003-12-09 09:43:38.000000000 -0800
+++ gnome-remote-shell.c 2003-12-09 10:14:30.000000000 -0800
@@ -31,15 +31,18 @@
#include <gtk/gtkdialog.h>
#include <gtk/gtkentry.h>
#include <gtk/gtkimage.h>
+#include <gtk/gtklabel.h>
#include <gtk/gtkmain.h>
+#include <gtk/gtkmessagedialog.h>
#include <gtk/gtkradiobutton.h>
#include <gtk/gtkspinbutton.h>
#include <glade/glade.h>
+#include <libgnome/gnome-help.h>
#include <libgnome/gnome-i18n.h>
#include <libgnome/gnome-util.h>
-#include <libgnomeui/gnome-dialog-util.h>
#include <libgnomeui/gnome-entry.h>
#include <libgnomeui/gnome-ui-init.h>
+#include <libgnomeui/gnome-window-icon.h>
#define SSH_PORT 22
#define TELNET_PORT 23
@@ -68,6 +71,8 @@
static gint get_ip_version (const gchar *ip_address);
static gboolean check_network_status (const gchar *host, gint port);
+static void create_error (gchar *title, gchar *reason);
+static void launch_help (void);
static void activate_shell (void);
static void set_spin_from_config (GtkWidget *spin, const gchar *key, gint default_value);
static gboolean validate_host (const gchar *host);
@@ -81,17 +86,24 @@
void
dialog_response_cb (GtkDialog *dialog, gint response_id, gpointer user_data)
{
- if (response_id == GTK_RESPONSE_OK)
- activate_shell ();
- else
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ switch (response_id) {
+ case GTK_RESPONSE_OK:
+ activate_shell ();
+ break;
+ case GTK_RESPONSE_CANCEL:
+ gtk_widget_destroy (GTK_WIDGET (dialog));
+ break;
+ case GTK_RESPONSE_HELP:
+ launch_help ();
+ break;
+ }
}
void
radio_button_toggled_cb (GtkToggleButton *button, gpointer user_data)
{
gint port = -1;
-
+
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ssh_method))) {
gtk_widget_set_sensitive (user_entry, TRUE);
} else {
@@ -118,7 +130,7 @@
port_default_toggled_cb (GtkToggleButton *button, gpointer user_data)
{
gint port = -1;
-
+
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) {
gtk_widget_set_sensitive (port_entry, FALSE);
@@ -188,7 +200,10 @@
if (connect (sd, (struct sockaddr *) addr, sizeof (struct sockaddr_in)) != 0) {
msgerror = (gchar *) strerror (errno);
msgerror = g_locale_to_utf8 (msgerror, strlen (msgerror), NULL, NULL, NULL);
- gnome_error_dialog_parented (_(msgerror), GTK_WINDOW (dialog));
+
+ create_error (_("There is a connection error"), msgerror);
+
+ g_free (msgerror);
g_free (addr);
return FALSE;
@@ -212,7 +227,10 @@
if (connect (sd, (struct sockaddr *) addr6, sizeof (struct sockaddr_in6)) != 0) {
msgerror = (gchar *) strerror (errno);
msgerror = g_locale_to_utf8 (msgerror, strlen (msgerror), NULL, NULL, NULL);
- gnome_error_dialog_parented (_(msgerror), GTK_WINDOW (dialog));
+
+ create_error (_("There is a connection error"), msgerror);
+
+ g_free (msgerror);
g_free (addr6);
return FALSE;
@@ -229,6 +247,59 @@
return TRUE;
}
+/*
+ * Given a title and reason for an application error, produce a
+ * HIG compliant error alert
+ */
+static void
+create_error (gchar *title, gchar *reason)
+{
+ GtkWidget *error_dialog;
+ gchar *title_esc, *reason_esc;
+
+ title_esc = g_markup_escape_text (title, -1);
+ reason_esc = g_markup_escape_text (reason, -1);
+
+ error_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_OK,
+ "<span weight='bold' size='larger'>%s</span>.\n\n%s.", title_esc, reason_esc);
+
+ g_free (title_esc);
+ g_free (reason_esc);
+
+ gtk_dialog_set_default_response (GTK_DIALOG (error_dialog),
+ GTK_RESPONSE_OK);
+
+ gtk_label_set_use_markup (GTK_LABEL (GTK_MESSAGE_DIALOG (error_dialog)->label), TRUE);
+
+ g_signal_connect (error_dialog, "destroy",
+ G_CALLBACK (gtk_widget_destroy), NULL);
+
+ g_signal_connect (error_dialog, "response",
+ G_CALLBACK (gtk_widget_destroy), NULL);
+
+ gtk_window_set_modal (GTK_WINDOW (error_dialog), TRUE);
+
+ gtk_widget_show (error_dialog);
+}
+
+/*
+ * Display the help file in GNOME's help browser
+ */
+static void
+launch_help (void)
+{
+ GError *err = NULL;
+
+ gnome_help_display ("gnome-remote-shell.xml", NULL, &err);
+
+ if (err) {
+ create_error (_("There is an error with displaying help"), err->message);
+ }
+}
+
static void
activate_shell (void)
{
@@ -259,7 +330,8 @@
*/
host = gtk_entry_get_text (GTK_ENTRY (gnome_entry_gtk_entry (GNOME_ENTRY (host_entry))));
if (!host || !strlen (host)) {
- gnome_error_dialog_parented (_("No host specified."), GTK_WINDOW (dialog));
+ create_error (_("Failed to create a connection"), _("A hostname is required"));
+
return;
}
@@ -308,8 +380,8 @@
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ssh_method))) {
user = gtk_entry_get_text (GTK_ENTRY (gnome_entry_gtk_entry (GNOME_ENTRY (user_entry))));
if (!user || !strlen (user)) {
- gnome_error_dialog_parented (_("A user name is required for SSH"),
- GTK_WINDOW (dialog));
+ create_error (_("Failed to create a connection"), _("A user name is required for SSH"));
+
return;
}
@@ -386,7 +458,8 @@
}
if (!g_spawn_command_line_async (cmd, &err)) {
- gnome_error_dialog_parented (err->message, GTK_WINDOW (dialog));
+ create_error (_("There is a command line error"), err->message);
+
g_error_free (err);
}
@@ -436,8 +509,8 @@
if (hostname == NULL) {
hostname = gethostbyname2 (host, AF_INET);
if (hostname == NULL) {
- gnome_error_dialog_parented (_("The host cannot be found."),
- GTK_WINDOW (dialog));
+ create_error (_("Failed to create a connection"), _("The host cannot be found"));
+
return FALSE;
}
}
@@ -448,7 +521,7 @@
int
main (int argc, char **argv)
{
- const gchar *xml_file = DIALOGDIR "gnome-remote-shell.glade";
+ const gchar *xml_file = DIALOGDIR "gnome-remote-shell.glade";
GladeXML *xml;
gchar *icon_path;
@@ -458,8 +531,9 @@
textdomain (GETTEXT_PACKAGE);
#endif
- gnome_program_init ("gnome-remote-shell", VERSION,
- LIBGNOMEUI_MODULE, argc, argv, NULL);
+ gnome_program_init ("gnome-remote-shell", VERSION,
+ LIBGNOMEUI_MODULE, argc, argv,
+ GNOME_PROGRAM_STANDARD_PROPERTIES, NULL);
icon_path = g_build_filename (GNOME_ICONDIR, "gnome-remote-shell.png", NULL);
gnome_window_icon_set_default_from_file (icon_path);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]