[network-manager-netbook] Implement error message showing



commit 8a0a6326b9794600c50353219e54b48dda015d40
Author: Tambet Ingo <tambet gmail com>
Date:   Thu Mar 4 13:49:07 2010 -0400

    Implement error message showing
    
    Show error messages when anything goes wrong with a connection (like connect,
    disconnect, update, delete, ...). Clear the error once any action is taken
    by user.

 libnm-gtk/nm-connection-item.c      |   10 ++++++-
 libnm-gtk/nm-device-item.c          |   19 +++++++++++---
 libnm-gtk/nm-gsm-pin-request-item.c |   47 ++++++++++++++++++++++++----------
 libnm-gtk/nm-gsm-pin-request-item.h |    1 +
 libnm-gtk/nm-list-item.c            |   20 +++++++++++++++
 libnm-gtk/nm-list-item.h            |    5 +++
 po/POTFILES.in                      |    2 +
 src/nmn-gsm-pin-request-renderer.c  |   15 ++++++++++-
 src/nmn-item-renderer.c             |   10 +++++++
 src/nmn-network-renderer.c          |   25 +++++++++++++++---
 10 files changed, 128 insertions(+), 26 deletions(-)
---
diff --git a/libnm-gtk/nm-connection-item.c b/libnm-gtk/nm-connection-item.c
index 7e5e027..023d93d 100644
--- a/libnm-gtk/nm-connection-item.c
+++ b/libnm-gtk/nm-connection-item.c
@@ -18,6 +18,7 @@
  */
 
 #include <string.h>
+#include <glib/gi18n.h>
 #include <nm-settings-interface.h>
 #include <nm-setting-connection.h>
 #include <nm-settings-connection-interface.h>
@@ -395,8 +396,13 @@ delete_cb (NMSettingsConnectionInterface *connection,
            GError *error,
            gpointer user_data)
 {
-    if (error)
-        g_warning ("Could not delete connection: %s", error->message);
+    if (error) {
+        char *msg;
+
+        msg = g_strdup_printf (_("Could not delete connection: %s"), error->message);
+        nm_list_item_warning (NM_LIST_ITEM (user_data), msg);
+        g_free (msg);
+    }
 }
 
 static void
diff --git a/libnm-gtk/nm-device-item.c b/libnm-gtk/nm-device-item.c
index cc29d10..2cc33e2 100644
--- a/libnm-gtk/nm-device-item.c
+++ b/libnm-gtk/nm-device-item.c
@@ -17,6 +17,7 @@
  * (C) Copyright 2009 Novell, Inc.
  */
 
+#include <glib/gi18n.h>
 #include "nm-device-item.h"
 
 G_DEFINE_ABSTRACT_TYPE (NMDeviceItem, nm_device_item, NM_TYPE_CONNECTION_ITEM)
@@ -58,8 +59,13 @@ nm_device_item_get_hw_address (NMDeviceItem *self)
 static void
 connect_cb (gpointer user_data, const char *object_path, GError *error)
 {
-    if (error)
-        g_warning ("Could not activate device: %s", error->message);
+    if (error) {
+        char *msg;
+
+        msg = g_strdup_printf (_("Could not activate device: %s"), error->message);
+        nm_list_item_warning (NM_LIST_ITEM (user_data), msg);
+        g_free (msg);
+    }
 }
 
 static void
@@ -98,8 +104,13 @@ connect (NMListItem *item)
 static void
 disconnect_cb (NMDevice *device, GError *error, gpointer user_data)
 {
-    if (error)
-        g_warning ("Could not deactivate device: %s", error->message);
+    if (error) {
+        char *msg;
+
+        msg = g_strdup_printf (_("Could not deactivate device: %s"), error->message);
+        nm_list_item_warning (NM_LIST_ITEM (user_data), msg);
+        g_free (msg);
+    }
 }
 
 static void
diff --git a/libnm-gtk/nm-gsm-pin-request-item.c b/libnm-gtk/nm-gsm-pin-request-item.c
index 606f064..c773f79 100644
--- a/libnm-gtk/nm-gsm-pin-request-item.c
+++ b/libnm-gtk/nm-gsm-pin-request-item.c
@@ -61,15 +61,16 @@ pin_disabled (GObject *obj, GAsyncResult *result, gpointer user_data)
 {
     NMGsmPinRequestItem *self = NM_GSM_PIN_REQUEST_ITEM (user_data);
     GError *error = NULL;
-    gboolean success;
 
-    success = nm_gsm_device_enable_pin_finish (NM_GSM_DEVICE (obj), result, &error);
-    if (error) {
-        g_warning ("PIN disable failed: %s", error->message);
-        g_clear_error (&error);
+    if (nm_gsm_device_enable_pin_finish (NM_GSM_DEVICE (obj), result, &error)) {
+        g_debug ("PIN disabled successfully");
     } else {
-        g_message ("PIN disabled successfully");
-        g_signal_emit (self, signals[UNLOCKED], 0);
+        char *msg;
+
+        msg = g_strdup_printf (_("PIN unlocking failed: %s"), error->message);
+        nm_list_item_warning (NM_LIST_ITEM (self), msg);
+        g_free (msg);
+        g_error_free (error);
     }
 }
 
@@ -78,15 +79,17 @@ pin_unlocked (GObject *obj, GAsyncResult *result, gpointer user_data)
 {
     NMGsmPinRequestItem *self = NM_GSM_PIN_REQUEST_ITEM (user_data);
     GError *error = NULL;
-    gboolean success;
 
-    success = nm_gsm_device_send_pin_finish (NM_GSM_DEVICE (obj), result, &error);
-    if (error) {
-        g_warning ("PIN unlocking failed: %s", error->message);
-        g_clear_error (&error);
-    } else {
-        g_message ("PIN unlocked successfully");
+    if (nm_gsm_device_send_pin_finish (NM_GSM_DEVICE (obj), result, &error)) {
+        g_debug ("PIN unlocked successfully");
         g_signal_emit (self, signals[UNLOCKED], 0);
+    } else {
+        char *msg;
+
+        msg = g_strdup_printf (_("PIN unlocking failed: %s"), error->message);
+        nm_list_item_warning (NM_LIST_ITEM (self), msg);
+        g_free (msg);
+        g_error_free (error);
     }
 }
 
@@ -106,6 +109,22 @@ nm_gsm_pin_request_item_unlock (NMGsmPinRequestItem *self,
         nm_gsm_device_send_pin (priv->device, pin, pin_unlocked, self);
 }
 
+gboolean
+nm_gsm_pin_request_item_unlock_finish (NMGsmPinRequestItem *self,
+                                       GAsyncResult *result,
+                                       GError **error)
+{
+    g_return_val_if_fail (NM_IS_GSM_PIN_REQUEST_ITEM (self), FALSE);
+
+    if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), error) ||
+        !g_simple_async_result_is_valid (result, G_OBJECT (self), nm_gsm_pin_request_item_unlock_finish))
+        return FALSE;
+
+    
+
+    return TRUE;
+}
+
 static int
 priority (NMListItem *item)
 {
diff --git a/libnm-gtk/nm-gsm-pin-request-item.h b/libnm-gtk/nm-gsm-pin-request-item.h
index f9ecb4e..2b4860f 100644
--- a/libnm-gtk/nm-gsm-pin-request-item.h
+++ b/libnm-gtk/nm-gsm-pin-request-item.h
@@ -21,6 +21,7 @@
 #define NM_GSM_PIN_REQUEST_ITEM_H
 
 #include <glib-object.h>
+#include <gio/gio.h>
 #include <nm-gsm-device.h>
 #include <nm-list-item.h>
 
diff --git a/libnm-gtk/nm-list-item.c b/libnm-gtk/nm-list-item.c
index d29da51..1317014 100644
--- a/libnm-gtk/nm-list-item.c
+++ b/libnm-gtk/nm-list-item.c
@@ -35,6 +35,7 @@ enum {
 
 enum {
 	REQUEST_REMOVE,
+    WARNING,
 
 	LAST_SIGNAL
 };
@@ -170,6 +171,16 @@ nm_list_item_compare (NMListItem *self,
     return g_strcmp0 (nm_list_item_get_name (self), nm_list_item_get_name (other));
 }
 
+void
+nm_list_item_warning (NMListItem *self,
+                      const char *message)
+{
+    g_return_if_fail (NM_IS_LIST_ITEM (self));
+    g_return_if_fail (message != NULL);
+
+    g_signal_emit (self, signals[WARNING], 0, message);
+}
+
 /*****************************************************************************/
 
 static void
@@ -340,4 +351,13 @@ nm_list_item_class_init (NMListItemClass *klass)
 					  g_cclosure_marshal_VOID__VOID,
 					  G_TYPE_NONE, 0);
 
+    signals[WARNING] =
+		g_signal_new ("warning",
+					  G_OBJECT_CLASS_TYPE (object_class),
+					  G_SIGNAL_RUN_FIRST,
+					  G_STRUCT_OFFSET (NMListItemClass, warning),
+					  NULL, NULL,
+					  g_cclosure_marshal_VOID__STRING,
+					  G_TYPE_NONE, 1,
+                      G_TYPE_STRING);
 }
diff --git a/libnm-gtk/nm-list-item.h b/libnm-gtk/nm-list-item.h
index 02d6045..6032f4b 100644
--- a/libnm-gtk/nm-list-item.h
+++ b/libnm-gtk/nm-list-item.h
@@ -70,6 +70,8 @@ typedef struct {
 
     /* Signals */
     void (*request_remove) (NMListItem *self);
+    void (*warning)    (NMListItem *self,
+                        const char *message);
 } NMListItemClass;
 
 GType nm_list_item_get_type (void);
@@ -89,6 +91,9 @@ void              nm_list_item_delete          (NMListItem *self);
 int               nm_list_item_compare         (NMListItem *self,
                                                 NMListItem *other);
 
+void              nm_list_item_warning         (NMListItem *self,
+                                                const char *message);
+
 G_END_DECLS
 
 #endif /* NM_LIST_ITEM_H */
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 552a290..71961bd 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -2,6 +2,8 @@ network-manager-netbook.desktop.in
 gnome-bluetooth/network-manager-applet.c
 libnm-gtk/nm-mobile-providers.c
 libnm-gtk/nm-bt-item.c
+libnm-gtk/nm-connection-item.c
+libnm-gtk/nm-device-item.c
 libnm-gtk/nm-ethernet-item.c
 libnm-gtk/nm-gsm-pin-request-item.c
 libnm-gtk/nm-wifi-item.c
diff --git a/src/nmn-gsm-pin-request-renderer.c b/src/nmn-gsm-pin-request-renderer.c
index 10c1913..4802ff6 100644
--- a/src/nmn-gsm-pin-request-renderer.c
+++ b/src/nmn-gsm-pin-request-renderer.c
@@ -20,6 +20,7 @@
 #include <string.h>
 #include <glib/gi18n.h>
 #include "nmn-gsm-pin-request-renderer.h"
+#include "libnm-gtk-gsm-device.h"
 #include "nm-gsm-pin-request-item.h"
 #include "nm-icon-cache.h"
 #include "nm-connection-item.h"
@@ -47,6 +48,17 @@ nmn_gsm_pin_request_renderer_new (void)
 }
 
 static void
+item_warning (NMListItem *item,
+              const char *message,
+              gpointer user_data)
+{
+    NmnGsmPinRequestRendererPrivate *priv = GET_PRIVATE (user_data);
+
+    gtk_editable_select_region (GTK_EDITABLE (priv->entry), 0, -1);
+    gtk_widget_grab_focus (priv->entry);
+}
+
+static void
 unlock (NmnGsmPinRequestRenderer *self)
 {
     NmnGsmPinRequestRendererPrivate *priv = GET_PRIVATE (self);
@@ -56,7 +68,7 @@ unlock (NmnGsmPinRequestRenderer *self)
 
     text = gtk_entry_get_text (GTK_ENTRY (priv->entry));
     disable_pin = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->disable_pin));
-    
+
     item = nmn_item_renderer_get_item (NMN_ITEM_RENDERER (self));
     nm_gsm_pin_request_item_unlock (NM_GSM_PIN_REQUEST_ITEM (item), text, disable_pin);
 }
@@ -98,6 +110,7 @@ init_widgets (NmnGsmPinRequestRenderer *self)
     NMListItem *item;
 
     item = nmn_item_renderer_get_item (NMN_ITEM_RENDERER (self));
+    g_signal_connect (item, "warning", G_CALLBACK (item_warning), self);
 
     parent_container = nmn_item_renderer_get_content_area (NMN_ITEM_RENDERER (self));
 
diff --git a/src/nmn-item-renderer.c b/src/nmn-item-renderer.c
index 1bfd794..127e92e 100644
--- a/src/nmn-item-renderer.c
+++ b/src/nmn-item-renderer.c
@@ -87,6 +87,14 @@ nmn_item_renderer_get_item (NmnItemRenderer *self)
     return GET_PRIVATE (self)->item;
 }
 
+static void
+item_warning (NMListItem *item,
+              const char *message,
+              gpointer user_data)
+{
+    nmn_item_renderer_show_error (NMN_ITEM_RENDERER (user_data), message);
+}
+
 void
 nmn_item_renderer_set_item (NmnItemRenderer *self,
                             NMListItem *item)
@@ -100,6 +108,8 @@ nmn_item_renderer_set_item (NmnItemRenderer *self,
     g_return_if_fail (priv->item == NULL);
 
     priv->item = g_object_ref (item);
+    g_signal_connect (item, "warning", G_CALLBACK (item_warning), self);
+
     g_signal_emit (self, signals[ITEM_CHANGED], 0);
 }
 
diff --git a/src/nmn-network-renderer.c b/src/nmn-network-renderer.c
index 1085645..ab0355a 100644
--- a/src/nmn-network-renderer.c
+++ b/src/nmn-network-renderer.c
@@ -147,10 +147,18 @@ update_connection_cb (NMSettingsConnectionInterface *connection,
                       GError *error,
                       gpointer user_data)
 {
-    if (error)
-        g_warning ("Couldn't update connection: %s", error->message);
-    else
-        nm_list_item_connect (nmn_item_renderer_get_item (NMN_ITEM_RENDERER (user_data)));
+    NMListItem *item;
+
+    item = nmn_item_renderer_get_item (NMN_ITEM_RENDERER (user_data));
+
+    if (error) {
+        char *msg;
+
+        msg = g_strdup_printf (_("Could not update connection: %s"), error->message);
+        nm_list_item_warning (item, msg);
+        g_free (msg);
+    } else
+        nm_list_item_connect (item);
 }
 
 static void
@@ -206,6 +214,8 @@ connect_button_clicked (GtkButton *button, gpointer user_data)
     NmnItemRenderer *self = NMN_ITEM_RENDERER (user_data);
     NMListItem *item;
 
+    nmn_item_renderer_hide_error (self);
+
     item = nmn_item_renderer_get_item (self);
     if (nm_list_item_get_status (item) == NM_LIST_ITEM_STATUS_DISCONNECTED) {
         NMConnectionItem *connection_item;
@@ -229,6 +239,7 @@ details_changed (NmnConnectionDetails *details,
 {
     NmnNetworkRendererPrivate *priv = GET_PRIVATE (user_data);
 
+    nmn_item_renderer_hide_error (NMN_ITEM_RENDERER (user_data));
     gtk_widget_set_sensitive (GTK_WIDGET (priv->connect_button), complete);
 }
 
@@ -267,6 +278,7 @@ advanced_expanded (GtkExpander *expander,
 {
     NmnConnectionDetails *details;
 
+    nmn_item_renderer_hide_error (NMN_ITEM_RENDERER (user_data));
     details = get_details (NMN_NETWORK_RENDERER (user_data));
     if (details)
         g_object_set (details, "visible", gtk_expander_get_expanded (expander), NULL);
@@ -275,13 +287,15 @@ advanced_expanded (GtkExpander *expander,
 static void
 remove_button_clicked (GtkButton *button, gpointer user_data)
 {
+    NmnItemRenderer *renderer = NMN_ITEM_RENDERER (user_data);
     GtkDialog *dialog;
     GtkWidget *label;
     const char *name;
     char *label_text;
     NMListItem *item;
 
-    item = nmn_item_renderer_get_item (NMN_ITEM_RENDERER (user_data));
+    nmn_item_renderer_hide_error (renderer);
+    item = nmn_item_renderer_get_item (renderer);
     dialog = GTK_DIALOG (gtk_dialog_new_with_buttons (_("Really remove?"),
                                                       NULL,
                                                       GTK_DIALOG_MODAL |
@@ -374,6 +388,7 @@ init_widgets (NmnNetworkRenderer *self)
     gtk_box_pack_end (priv->hbox, vbox, FALSE, FALSE, 0);
 
     w = gtk_button_new ();
+    gtk_widget_set_no_show_all (w, TRUE);
     gtk_button_set_image (GTK_BUTTON (w),
                           gtk_image_new_from_icon_name ("edit-clear", GTK_ICON_SIZE_MENU));
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]