2 * This file is part of vpngui
4 * Copyright © 2009 Nokia Corporation and/or its subsidiary(-ies)
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "vpn_notify.h"
24 vpn_notify_get_status (VpnNotify * self,
25 gboolean * ret_up, gchar ** ret_ip, GError ** error);
27 #include "vpn_notify-glue.h"
29 #define VPN_NOTIFY_GET_PRIVATE(obj) \
30 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), VPN_TYPE_NOTIFY, VpnNotifyPrivate))
32 typedef struct _VpnNotifyPrivate VpnNotifyPrivate;
34 struct _VpnNotifyPrivate
43 G_DEFINE_TYPE (VpnNotify, vpn_notify, G_TYPE_OBJECT)
46 vpn_notify_finalize (GObject * object)
48 VpnNotifyPrivate *priv;
50 g_debug ("%s", G_STRFUNC);
53 g_assert (VPN_IS_NOTIFY (object));
54 priv = VPN_NOTIFY_GET_PRIVATE (object);
61 vpn_notify_get_property (GObject * object,
62 guint property_id, GValue * value, GParamSpec * pspec)
64 VpnNotifyPrivate *priv;
66 g_debug ("%s", G_STRFUNC);
69 g_assert (VPN_IS_NOTIFY (object));
70 priv = VPN_NOTIFY_GET_PRIVATE (object);
76 g_value_set_string (value, priv->ip);
77 g_debug("ip = %s", priv->ip);
80 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
85 vpn_notify_set_property (GObject * object,
86 guint property_id, const GValue * value, GParamSpec * pspec)
88 VpnNotifyPrivate *priv;
90 g_debug ("%s", G_STRFUNC);
93 g_assert (VPN_IS_NOTIFY (object));
94 priv = VPN_NOTIFY_GET_PRIVATE (object);
101 priv->ip = g_value_dup_string (value);
102 g_debug("ip = %s", priv->ip);
103 if (priv->ip[0] != '\0')
104 g_signal_emit_by_name (object, "up", priv->ip);
106 g_signal_emit_by_name (object, "down");
109 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
114 vpn_notify_class_init (VpnNotifyClass * klass)
116 GObjectClass *gobject_class;
118 g_debug ("%s", G_STRFUNC);
120 gobject_class = G_OBJECT_CLASS (klass);
122 gobject_class->finalize = vpn_notify_finalize;
123 gobject_class->get_property = vpn_notify_get_property;
124 gobject_class->set_property = vpn_notify_set_property;
126 g_object_class_install_property (gobject_class,
127 PROP_IP, g_param_spec_string ("ip",
128 "IP address", "The local IP address", "", G_PARAM_READWRITE));
131 G_OBJECT_CLASS_TYPE (klass),
135 g_cclosure_marshal_VOID__STRING,
139 g_signal_new ("down",
140 G_OBJECT_CLASS_TYPE (klass),
144 g_cclosure_marshal_VOID__VOID,
148 g_type_class_add_private (klass, sizeof (VpnNotifyPrivate));
150 dbus_g_object_type_install_info (VPN_TYPE_NOTIFY,
151 &dbus_glib_vpn_notify_object_info);
155 vpn_notify_init (VpnNotify * self)
157 VpnNotifyPrivate *priv;
159 g_debug ("%s", G_STRFUNC);
162 g_assert (VPN_IS_NOTIFY (self));
163 priv = VPN_NOTIFY_GET_PRIVATE (self);
166 priv->ip = g_strdup ("");
170 vpn_notify_get_status (VpnNotify * self,
171 gboolean * ret_up, gchar ** ret_ip, GError ** error)
173 VpnNotifyPrivate *priv;
175 g_debug ("%s", G_STRFUNC);
178 g_assert (VPN_IS_NOTIFY (self));
179 priv = VPN_NOTIFY_GET_PRIVATE (self);
182 *ret_up = priv->ip[0] != '\0';
183 *ret_ip = g_strdup (priv->ip);
185 g_debug ("%s: up = %d, ip = %s", G_STRFUNC, *ret_up, *ret_ip);