[PATCH] applet: show an error dialog on connection failures
- From: Jirka Klimes <jklimes redhat com>
- To: networkmanager-list gnome org
- Subject: [PATCH] applet: show an error dialog on connection failures
- Date: Mon, 19 Mar 2012 15:26:49 +0100
The patch adds a functionality to present a user with an error dialog (in
addition to writting a message to console), when there is a connection
failure.
Using the notifications would be an option, but I think a dialog is more
appropriate in this case, because notifications can be disabled and we really
want to alert the user.
Jirka
>From d947c6366be6e13d3eaf5aea0f874fb494a22b73 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ji=C5=99=C3=AD=20Klime=C5=A1?= <jklimes redhat com>
Date: Mon, 19 Mar 2012 11:02:45 +0100
Subject: [PATCH] applet: show an error dialog on connection failures
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Show the user an error dialog, when connection activation failed, so that
he knows what's the problem. This is useful mainly for situations when
user is not allowed to perform an action, PolicyKit is misconfigured or
something.
Signed-off-by: Jiří Klimeš <jklimes redhat com>
---
src/applet-device-wifi.c | 22 +++++++++++++++++---
src/applet.c | 33 +++++++++++++++++++++++-------
src/gconf-helpers/tests/Makefile.am | 2 +
src/utils/utils.c | 37 +++++++++++++++++++++++++++++++++++
src/utils/utils.h | 7 ++++++
5 files changed, 89 insertions(+), 12 deletions(-)
diff --git a/src/applet-device-wifi.c b/src/applet-device-wifi.c
index f17324c..15fcf7b 100644
--- a/src/applet-device-wifi.c
+++ b/src/applet-device-wifi.c
@@ -1377,8 +1377,15 @@ activate_existing_cb (NMClient *client,
GError *error,
gpointer user_data)
{
- if (error)
- g_warning ("Failed to activate connection: (%d) %s", error->code, error->message);
+ if (error) {
+ const char *text = _("Failed to activate connection");
+ char *err_text = g_strdup_printf ("(%d) %s", error->code,
+ error->message ? error->message : _("Unknown error"));
+
+ g_warning ("%s: %s", text, err_text);
+ utils_show_error_dialog (_("Connection failure"), text, err_text, FALSE, NULL);
+ g_free (err_text);
+ }
applet_schedule_update_icon (NM_APPLET (user_data));
}
@@ -1389,8 +1396,15 @@ activate_new_cb (NMClient *client,
GError *error,
gpointer user_data)
{
- if (error)
- g_warning ("Failed to add new connection: (%d) %s", error->code, error->message);
+ if (error) {
+ const char *text = _("Failed to add new connection");
+ char *err_text = g_strdup_printf ("(%d) %s", error->code,
+ error->message ? error->message : _("Unknown error"));
+
+ g_warning ("%s: %s", text, err_text);
+ utils_show_error_dialog (_("Connection failure"), text, err_text, FALSE, NULL);
+ g_free (err_text);
+ }
applet_schedule_update_icon (NM_APPLET (user_data));
}
diff --git a/src/applet.c b/src/applet.c
index cb5b5e4..c7a362e 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -483,8 +483,15 @@ add_and_activate_cb (NMClient *client,
GError *error,
gpointer user_data)
{
- if (error)
- g_warning ("Failed to add/activate connection: (%d) %s", error->code, error->message);
+ if (error) {
+ const char *text = _("Failed to add/activate connection");
+ char *err_text = g_strdup_printf ("(%d) %s", error->code,
+ error->message ? error->message : _("Unknown error"));
+
+ g_warning ("%s: %s", text, err_text);
+ utils_show_error_dialog (_("Connection failure"), text, err_text, FALSE, NULL);
+ g_free (err_text);
+ }
applet_schedule_update_icon (NM_APPLET (user_data));
}
@@ -521,10 +528,13 @@ static void
disconnect_cb (NMDevice *device, GError *error, gpointer user_data)
{
if (error) {
- g_warning ("%s: device disconnect failed: (%d) %s",
- __func__,
- error ? error->code : -1,
- error && error->message ? error->message : "(unknown)");
+ const char *text = _("Device disconnect failed");
+ char *err_text = g_strdup_printf ("(%d) %s", error->code,
+ error->message ? error->message : _("Unknown error"));
+
+ g_warning ("%s: %s: %s", __func__, text, err_text);
+ utils_show_error_dialog (_("Disconnect failure"), text, err_text, FALSE, NULL);
+ g_free (err_text);
}
}
@@ -543,8 +553,15 @@ activate_connection_cb (NMClient *client,
GError *error,
gpointer user_data)
{
- if (error)
- g_warning ("Connection activation failed: %s", error->message);
+ if (error) {
+ const char *text = _("Connection activation failed");
+ char *err_text = g_strdup_printf ("(%d) %s", error->code,
+ error->message ? error->message : _("Unknown error"));
+
+ g_warning ("%s: %s", text, err_text);
+ utils_show_error_dialog (_("Connection failure"), text, err_text, FALSE, NULL);
+ g_free (err_text);
+ }
applet_schedule_update_icon (NM_APPLET (user_data));
}
diff --git a/src/gconf-helpers/tests/Makefile.am b/src/gconf-helpers/tests/Makefile.am
index 8226347..882af31 100644
--- a/src/gconf-helpers/tests/Makefile.am
+++ b/src/gconf-helpers/tests/Makefile.am
@@ -12,12 +12,14 @@ test_upgrade_SOURCES = \
test_upgrade_CPPFLAGS = \
-I ${srcdir}/../ \
-DTESTDIR=\"$(srcdir)\" \
+ $(GTK_CFLAGS) \
$(NMA_CFLAGS) \
$(GCONF_CFLAGS) \
$(GNOME_KEYRING_CFLAGS)
test_upgrade_LDADD = \
${builddir}/../libgconf-helpers-test.la \
+ $(GTK_CFLAGS) \
$(NMA_LIBS) \
$(GNOME_KEYRING_LIBS)
diff --git a/src/utils/utils.c b/src/utils/utils.c
index 62f0307..6e4cbde 100644
--- a/src/utils/utils.c
+++ b/src/utils/utils.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <netinet/ether.h>
#include <glib.h>
+#include <gtk/gtk.h>
#include <nm-device-ethernet.h>
#include <nm-device-wifi.h>
@@ -369,3 +370,39 @@ utils_create_keyring_add_attr_list (NMConnection *connection,
setting_key);
return attrs;
}
+
+void
+utils_show_error_dialog (const char *title,
+ const char *text1,
+ const char *text2,
+ gboolean modal,
+ GtkWindow *parent)
+{
+ GtkWidget *err_dialog;
+
+ g_return_if_fail (text1 != NULL);
+
+ err_dialog = gtk_message_dialog_new (parent,
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_ERROR,
+ GTK_BUTTONS_CLOSE,
+ "%s",
+ text1);
+
+ if (text2)
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (err_dialog), text2);
+ if (title)
+ gtk_window_set_title (GTK_WINDOW (err_dialog), title);
+
+ if (modal) {
+ gtk_dialog_run (GTK_DIALOG (err_dialog));
+ gtk_widget_destroy (err_dialog);
+ } else {
+ g_signal_connect (err_dialog, "delete-event", G_CALLBACK (gtk_widget_destroy), NULL);
+ g_signal_connect (err_dialog, "response", G_CALLBACK (gtk_widget_destroy), NULL);
+
+ gtk_widget_show_all (err_dialog);
+ gtk_window_present (GTK_WINDOW (err_dialog));
+ }
+}
+
diff --git a/src/utils/utils.h b/src/utils/utils.h
index bc37670..383d14f 100644
--- a/src/utils/utils.h
+++ b/src/utils/utils.h
@@ -24,6 +24,7 @@
#define UTILS_H
#include <glib.h>
+#include <gtk/gtk.h>
#include <nm-connection.h>
#include <nm-device.h>
#include <net/ethernet.h>
@@ -57,6 +58,12 @@ GnomeKeyringAttributeList *utils_create_keyring_add_attr_list (NMConnection *con
const char *setting_key,
char **out_display_name);
+void utils_show_error_dialog (const char *title,
+ const char *text1,
+ const char *text2,
+ gboolean modal,
+ GtkWindow *parent);
+
#define NMA_ERROR (g_quark_from_static_string ("nma-error-quark"))
typedef enum {
--
1.7.7.6
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]