1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
|
/* -*- Mode: C; c-file-style: "gnu"; tab-width: 8 -*- */
/* Copyright (C) 2004 Carlos Garnacho
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* Authors: Carlos Garnacho Parro <carlosg@gnome.org>
*/
#include <glib-object.h>
#include "oobs-iface-wireless.h"
#include "oobs-iface.h"
/**
* SECTION:oobs-iface-wireless
* @title: OobsIfaceWireless
* @short_description: Object that represents an individual Wireless interface
* @see_also: #OobsIface, #OobsIfacesConfig, #OobsIfaceEthernet,
* #OobsIfaceIRLan, #OobsIfacePlip, #OobsIfacePPP, #OobsIfaceWireless
**/
#define OOBS_IFACE_WIRELESS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), OOBS_TYPE_IFACE_WIRELESS, OobsIfaceWirelessPrivate))
typedef struct _OobsIfaceWirelessPrivate OobsIfaceWirelessPrivate;
struct _OobsIfaceWirelessPrivate
{
gchar *essid;
gchar *key;
gchar *key_type;
};
static void oobs_iface_wireless_class_init (OobsIfaceWirelessClass *class);
static void oobs_iface_wireless_init (OobsIfaceWireless *iface);
static void oobs_iface_wireless_finalize (GObject *object);
static gboolean oobs_iface_wireless_is_configured (OobsIface *iface);
static void oobs_iface_wireless_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec);
static void oobs_iface_wireless_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec);
enum {
PROP_0,
PROP_ESSID,
PROP_KEY_TYPE,
PROP_KEY
};
G_DEFINE_TYPE (OobsIfaceWireless, oobs_iface_wireless, OOBS_TYPE_IFACE_ETHERNET);
static void
oobs_iface_wireless_class_init (OobsIfaceWirelessClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
OobsIfaceClass *iface_class = OOBS_IFACE_CLASS (class);
object_class->set_property = oobs_iface_wireless_set_property;
object_class->get_property = oobs_iface_wireless_get_property;
object_class->finalize = oobs_iface_wireless_finalize;
iface_class->is_configured = oobs_iface_wireless_is_configured;
g_object_class_install_property (object_class,
PROP_ESSID,
g_param_spec_string ("essid",
"Iface ESSID",
"ESSID",
NULL,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_KEY_TYPE,
g_param_spec_string ("key_type",
"Iface key type",
"key type",
NULL,
G_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_KEY,
g_param_spec_string ("key",
"Iface key",
"Key",
NULL,
G_PARAM_READWRITE));
g_type_class_add_private (object_class,
sizeof (OobsIfaceWirelessPrivate));
}
static void
oobs_iface_wireless_init (OobsIfaceWireless *iface)
{
OobsIfaceWirelessPrivate *priv;
g_return_if_fail (OOBS_IS_IFACE_WIRELESS (iface));
priv = OOBS_IFACE_WIRELESS_GET_PRIVATE (iface);
priv->essid = NULL;
priv->key = NULL;
priv->key_type = NULL;
iface->_priv = priv;
}
static void
oobs_iface_wireless_finalize (GObject *object)
{
OobsIfaceWirelessPrivate *priv;
g_return_if_fail (OOBS_IS_IFACE_WIRELESS (object));
priv = OOBS_IFACE_WIRELESS (object)->_priv;
if (priv)
{
g_free (priv->essid);
g_free (priv->key);
g_free (priv->key_type);
}
if (G_OBJECT_CLASS (oobs_iface_wireless_parent_class)->finalize)
(* G_OBJECT_CLASS (oobs_iface_wireless_parent_class)->finalize) (object);
}
static void
oobs_iface_wireless_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
OobsIfaceWirelessPrivate *priv;
g_return_if_fail (OOBS_IS_IFACE_WIRELESS (object));
priv = OOBS_IFACE_WIRELESS (object)->_priv;
switch (prop_id)
{
case PROP_ESSID:
g_free (priv->essid);
priv->essid = g_value_dup_string (value);
break;
case PROP_KEY_TYPE:
g_free (priv->key_type);
priv->key_type = g_value_dup_string (value);
break;
case PROP_KEY:
g_free (priv->key);
priv->key = g_value_dup_string (value);
break;
}
}
static void
oobs_iface_wireless_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
OobsIfaceWirelessPrivate *priv;
g_return_if_fail (OOBS_IS_IFACE_WIRELESS (object));
priv = OOBS_IFACE_WIRELESS (object)->_priv;
switch (prop_id)
{
case PROP_ESSID:
g_value_set_string (value, priv->essid);
break;
case PROP_KEY_TYPE:
g_value_set_string (value, priv->key_type);
break;
case PROP_KEY:
g_value_set_string (value, priv->key);
break;
}
}
static gboolean
oobs_iface_wireless_is_configured (OobsIface *iface)
{
OobsIfaceWirelessPrivate *priv;
priv = OOBS_IFACE_WIRELESS (iface)->_priv;
return (priv->essid &&
(* OOBS_IFACE_CLASS (oobs_iface_wireless_parent_class)->is_configured) (iface));
}
/**
* oobs_iface_wireless_get_essid:
* @iface: an #OobsIfaceWireless.
*
* Returns the network identification (ESSID) that this interface uses.
*
* Return Value: A pointer to the network identification as a string. This
* string must not be freed, modified or stored.
**/
G_CONST_RETURN gchar*
oobs_iface_wireless_get_essid (OobsIfaceWireless *iface)
{
OobsIfaceWirelessPrivate *priv;
g_return_val_if_fail (OOBS_IS_IFACE_WIRELESS (iface), NULL);
priv = iface->_priv;
return priv->essid;
}
/**
* oobs_iface_wireless_set_essid:
* @iface: An #OobsIfaceWireless.
* @essid: a new ESSID for the interface.
*
* Sets a new network identification (ESSID),
* overwriting the previous one.
**/
void
oobs_iface_wireless_set_essid (OobsIfaceWireless *iface, const gchar *essid)
{
g_return_if_fail (OOBS_IS_IFACE_WIRELESS (iface));
g_object_set (G_OBJECT (iface), "essid", essid, NULL);
}
/**
* oobs_iface_wireless_get_key:
* @iface: an #OobsIfaceWireless.
*
* Returns the network key associated to the ESSID that
* this interface uses.
*
* Return Value: A pointer to the network key as a string,
* or %NULL if it's unset. This string must
* not be freed, modified or stored.
**/
G_CONST_RETURN gchar*
oobs_iface_wireless_get_key (OobsIfaceWireless *iface)
{
OobsIfaceWirelessPrivate *priv;
g_return_val_if_fail (OOBS_IS_IFACE_WIRELESS (iface), NULL);
priv = iface->_priv;
return priv->key;
}
/**
* oobs_iface_wireless_set_key:
* @iface: an #OobsIfaceWireless.
* @key: a new key for the ESSID, or %NULL to unset it.
*
* Sets a new network key for the ESSID that the interface uses.
**/
void
oobs_iface_wireless_set_key (OobsIfaceWireless *iface, const gchar *key)
{
g_return_if_fail (OOBS_IS_IFACE_WIRELESS (iface));
g_object_set (G_OBJECT (iface), "key", key, NULL);
}
/**
* oobs_iface_wireless_get_key_type:
* @iface: an #OobsIfaceWireless.
*
* Returns the type of key that the interface uses.
*
* Return Value: The key type.
**/
G_CONST_RETURN gchar*
oobs_iface_wireless_get_key_type (OobsIfaceWireless *iface)
{
OobsIfaceWirelessPrivate *priv;
g_return_val_if_fail (OOBS_IS_IFACE_WIRELESS (iface), NULL);
priv = iface->_priv;
return priv->key_type;
}
/**
* oobs_iface_wireless_set_key_type:
* @iface: an #OobsIfaceWireless.
* @key_type: a new type to define the key.
*
* Sets the type of the contained key.
**/
void
oobs_iface_wireless_set_key_type (OobsIfaceWireless *iface,
const gchar *key_type)
{
g_return_if_fail (OOBS_IS_IFACE_WIRELESS (iface));
g_object_set (G_OBJECT (iface), "key-type", key_type, NULL);
}
|