[network-manager-netbook/MplPanelClient] Add notification windows
- From: Tambet Ingo <tambeti src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [network-manager-netbook/MplPanelClient] Add notification windows
- Date: Tue, 17 Nov 2009 12:36:28 +0000 (UTC)
commit 60bd363c37ea620ba7e82491d51eec9c449a8a0a
Author: Tambet Ingo <tambet gmail com>
Date: Tue Nov 17 14:32:24 2009 +0200
Add notification windows
configure.in | 2 +-
src/nmn-status-icon.c | 182 ++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 160 insertions(+), 24 deletions(-)
---
diff --git a/configure.in b/configure.in
index fe14a1c..9d42df8 100644
--- a/configure.in
+++ b/configure.in
@@ -24,7 +24,7 @@ AM_GLIB_GNU_GETTEXT
NM_REQUIRED=0.7.996
-PKG_CHECK_MODULES(NMN, dbus-glib-1 >= 0.75 gtk+-2.0 gconf-2.0 gnome-keyring-1 libnm-util >= $NM_REQUIRED libnm-glib >= $NM_REQUIRED mobile-broadband-provider-info moblin-panel nbtk-gtk-1.2)
+PKG_CHECK_MODULES(NMN, dbus-glib-1 >= 0.75 gtk+-2.0 gconf-2.0 gnome-keyring-1 libnotify libnm-util >= $NM_REQUIRED libnm-glib >= $NM_REQUIRED mobile-broadband-provider-info moblin-panel nbtk-gtk-1.2)
GLIB_GENMARSHAL=`pkg-config --variable=glib_genmarshal glib-2.0`
AC_SUBST(GLIB_GENMARSHAL)
diff --git a/src/nmn-status-icon.c b/src/nmn-status-icon.c
index 958ffb8..7b1ae10 100644
--- a/src/nmn-status-icon.c
+++ b/src/nmn-status-icon.c
@@ -21,6 +21,7 @@
#include <glib/gi18n.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
+#include <libnotify/notify.h>
#include <nm-device-ethernet.h>
#include <nm-device-wifi.h>
#include <nm-gsm-device.h>
@@ -36,6 +37,12 @@ G_DEFINE_TYPE (NmnStatusIcon, nmn_status_icon, G_TYPE_OBJECT)
#define GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), NMN_TYPE_STATUS_ICON, NmnStatusIconPrivate))
+enum {
+ STATUS_DISCONNECTED,
+ STATUS_CONNECTING,
+ STATUS_CONNECTED
+};
+
typedef struct {
NmnStatusIcon *icon;
void (*destroy) (gpointer);
@@ -47,6 +54,11 @@ typedef struct {
GSList *ac_list;
NmnIconHandler *ac_icon_handler;
+
+ /* Notification ... and state */
+ char *connection_type;
+ char *connection_name;
+ int status;
} NmnStatusIconPrivate;
NmnStatusIcon *
@@ -56,21 +68,137 @@ nmn_status_icon_new (void)
}
static void
-update_tooltip (NmnStatusIcon *self, const char *text)
+update_icon (NmnStatusIcon *self, const char *image)
{
NmnStatusIconPrivate *priv = GET_PRIVATE (self);
if (priv->panel_client)
- mpl_panel_client_request_tooltip (priv->panel_client, text);
+ mpl_panel_client_request_button_style (priv->panel_client, image);
}
static void
-update_icon (NmnStatusIcon *self, const char *image)
+update_notification (NmnStatusIcon *self,
+ int status,
+ const char *connection_type,
+ const char *connection_name,
+ const char *icon)
{
NmnStatusIconPrivate *priv = GET_PRIVATE (self);
+ const char *title;
+ char *msg;
+
+ if (priv->status == STATUS_DISCONNECTED && status == STATUS_CONNECTED) {
+ title = _("Network connected");
+
+ if (connection_type) {
+ if (connection_name)
+ msg = g_strdup_printf (_("You're now connected to %s, a %s network"),
+ connection_name, connection_type);
+ else
+ msg = g_strdup_printf (_("You're now connected to %s network"), connection_type);
+ } else
+ msg = g_strdup (_("You're now connected to network"));
+ } else if (priv->status == STATUS_CONNECTED && status == STATUS_DISCONNECTED) {
+ title = _("Network lost");
+
+ if (priv->connection_type) {
+ if (priv->connection_name)
+ msg = g_strdup_printf (_("Sorry, we've lost your %s connection to %s"),
+ priv->connection_type, priv->connection_name);
+ else
+ msg = g_strdup_printf (_("Sorry, we've lost your %s connection"), priv->connection_type);
+ } else
+ msg = g_strdup (_("Sorry, we've lost your connection"));
+ } else {
+ title = NULL;
+ msg = NULL;
+ }
- if (priv->panel_client)
- mpl_panel_client_request_button_style (priv->panel_client, image);
+ if (title && msg) {
+ NotifyNotification *note;
+
+ note = notify_notification_new (title, msg, icon, NULL);
+ notify_notification_set_timeout (note, 10000);
+ notify_notification_show (note, NULL);
+ g_object_unref (note);
+ g_free (msg);
+
+ priv->status = status;
+ g_free (priv->connection_type);
+ priv->connection_type = connection_type ? g_strdup (connection_type) : NULL;
+ g_free (priv->connection_name);
+ priv->connection_name = connection_name ? g_strdup (connection_name) : NULL;
+ }
+}
+
+static void
+update_tooltip (NmnStatusIcon *self,
+ int status,
+ const char *connection_type,
+ const char *connection_name)
+{
+ NmnStatusIconPrivate *priv = GET_PRIVATE (self);
+ char *tip;
+
+ switch (status) {
+ case STATUS_DISCONNECTED:
+ tip = g_strdup_printf (_("networks - not connected"));
+ break;
+ case STATUS_CONNECTING:
+ tip = g_strdup_printf (_("networks - connecting"));
+ break;
+ case STATUS_CONNECTED:
+ if (connection_type) {
+ if (connection_name)
+ tip = g_strdup_printf (_("networks - %s - %s"), connection_name, connection_type);
+ else
+ tip = g_strdup_printf (_("networks - %s"), connection_type);
+ } else
+ tip = g_strdup (_("networks - connected"));
+
+ break;
+ }
+
+ mpl_panel_client_request_tooltip (priv->panel_client, tip);
+ g_free (tip);
+}
+
+static void
+update (NmnStatusIcon *self,
+ int status,
+ const char *connection_type,
+ const char *connection_name,
+ const char *icon)
+{
+ NmnStatusIconPrivate *priv = GET_PRIVATE (self);
+
+ update_notification (self, status, connection_type, connection_name, icon);
+
+ if (priv->panel_client) {
+ update_icon (self, icon);
+ update_tooltip (self, status, connection_type, connection_name);
+ }
+}
+
+static void
+set_status_disconnected (NmnStatusIcon *self)
+{
+ update (self, STATUS_DISCONNECTED, NULL, NULL, "no-network");
+}
+
+static void
+set_status_connecting (NmnStatusIcon *self)
+{
+ update_tooltip (self, STATUS_CONNECTING, NULL, NULL);
+}
+
+static void
+set_status_connected (NmnStatusIcon *self,
+ const char *connection_type,
+ const char *connection_name,
+ const char *icon)
+{
+ update (self, STATUS_CONNECTED, connection_type, connection_name, icon);
}
static void
@@ -129,7 +257,7 @@ icon_handler_pending_activation_new (NmnStatusIcon *icon)
handler->animation_id = g_timeout_add (200, activation_animation, handler);
activation_animation (handler);
- update_tooltip (icon, _("networks - connecting"));
+ set_status_connecting (icon);
return (NmnIconHandler *) handler;
}
@@ -144,8 +272,7 @@ icon_handler_ethernet_new (NmnStatusIcon *icon)
handler = g_new0 (NmnIconHandler, 1);
handler->destroy = g_free;
- update_icon (icon, "device-wired");
- update_tooltip (icon, _("networks - wired"));
+ set_status_connected (icon, _("wired"), NULL, "device-wired");
return handler;
}
@@ -161,6 +288,8 @@ typedef struct {
NMAccessPoint *ap;
gulong ap_strength_id;
+
+ gboolean just_activated;
} NmnWifiHandler;
static void
@@ -206,6 +335,7 @@ static void
active_ap_changed (NMDeviceWifi *device, GParamSpec *pspec, gpointer user_data)
{
NmnWifiHandler *handler = (NmnWifiHandler *) user_data;
+ NmnStatusIcon *icon = ((NmnIconHandler *) handler)->icon;
if (handler->ap_strength_id) {
g_signal_handler_disconnect (handler->ap, handler->ap_strength_id);
@@ -218,7 +348,7 @@ active_ap_changed (NMDeviceWifi *device, GParamSpec *pspec, gpointer user_data)
if (handler->ap) {
const GByteArray *ssid;
char *id;
- char *tip;
+ const char *connection_type = _("WiFi");
ssid = nm_access_point_get_ssid (handler->ap);
if (ssid)
@@ -226,11 +356,13 @@ active_ap_changed (NMDeviceWifi *device, GParamSpec *pspec, gpointer user_data)
else
id = g_strdup (_("(Hidden"));
- tip = g_strdup_printf (_("networks - %s - wifi"), id);
- g_free (id);
+ if (handler->just_activated) {
+ update_notification (icon, STATUS_CONNECTED, connection_type, id, "nm-device-wifi");
+ handler->just_activated = FALSE;
+ }
- update_tooltip (((NmnIconHandler *) handler)->icon, tip);
- g_free (tip);
+ update_tooltip (icon, STATUS_CONNECTED, connection_type, id);
+ g_free (id);
handler->ap_strength_id = g_signal_connect (handler->ap, "notify::" NM_ACCESS_POINT_STRENGTH,
G_CALLBACK (ap_strength_changed), handler);
@@ -255,6 +387,7 @@ icon_handler_wifi_new (NmnStatusIcon *icon, NMActiveConnection *ac)
handler = g_new0 (NmnWifiHandler, 1);
handler->parent.icon = icon;
handler->parent.destroy = icon_handler_wifi_destroy;
+ handler->just_activated = TRUE;
handler->device = device;
handler->active_ap_id = g_signal_connect (device, "notify::" NM_DEVICE_WIFI_ACTIVE_ACCESS_POINT,
@@ -276,8 +409,9 @@ icon_handler_3g_new (NmnStatusIcon *icon)
handler = g_new0 (NmnIconHandler, 1);
handler->destroy = g_free;
- update_tooltip (icon, _("networks - 3G"));
- update_icon (icon, "device-wwan");
+
+ /* FIXME: Get the connection name */
+ set_status_connected (icon, _("3G"), NULL, "device-wwan");
return handler;
}
@@ -348,10 +482,8 @@ update_best_ac (NmnStatusIcon *self)
if (best_ac)
priv->ac_icon_handler = icon_handler_create (self, best_ac);
- if (!priv->ac_icon_handler) {
- update_tooltip (self, _("networks - not connected"));
- update_icon (self, "no-connection");
- }
+ if (!priv->ac_icon_handler)
+ set_status_disconnected (self);
}
static void
@@ -443,8 +575,7 @@ nmn_status_icon_set_panel_client (NmnStatusIcon *self,
priv->panel_client = g_object_ref (panel_client);
- update_tooltip (self, _("networks - not connected"));
- update_icon (self, "no-connection");
+ set_status_disconnected (self);
}
/*****************************************************************************/
@@ -454,8 +585,8 @@ set_initial_icon (gpointer data)
{
NmnStatusIcon *self = NMN_STATUS_ICON (data);
- update_tooltip (self, _("networks - not connected"));
- update_icon (self, "no-connection");
+ notify_init ("network-manager-netbook");
+ set_status_disconnected (self);
return FALSE;
}
@@ -471,6 +602,9 @@ finalize (GObject *object)
{
NmnStatusIconPrivate *priv = GET_PRIVATE (object);
+ g_free (priv->connection_type);
+ g_free (priv->connection_name);
+
if (priv->ac_icon_handler)
icon_handler_destroy (priv->ac_icon_handler);
@@ -482,6 +616,8 @@ finalize (GObject *object)
if (priv->nm_client)
g_object_unref (priv->nm_client);
+ notify_uninit ();
+
G_OBJECT_CLASS (nmn_status_icon_parent_class)->finalize (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]