[network-manager-applet] applet: show an error dialog on connection failures
- From: JiÅÃ KlimeÅ <jklimes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet] applet: show an error dialog on connection failures
- Date: Fri, 23 Mar 2012 08:27:30 +0000 (UTC)
commit ba8381aed2cebaea13b8fc739a80bc63c7e153a3
Author: JiÅÃ KlimeÅ <jklimes redhat com>
Date: Mon Mar 19 11:02:45 2012 +0100
applet: show an error dialog on connection failures
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.
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 d674e3b..ff0e374 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 8ef5a29..be4e516 100644
--- a/src/applet.c
+++ b/src/applet.c
@@ -485,8 +485,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));
}
@@ -523,10 +530,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);
}
}
@@ -545,8 +555,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 b6194a5..4d52a69 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-setting-connection.h>
#include <nm-utils.h>
@@ -353,3 +354,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 {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]