1
/* libtinymail-olpc - The Tiny Mail base library for olpc
2
* Copyright (C) 2006-2007 Philip Van Hoof <pvanhoof@gnome.org>
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with self library; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
22
#include <glib/gi18n-lib.h>
24
#include <tny-olpc-device.h>
26
static GObjectClass *parent_class = NULL;
28
#include "tny-olpc-device-priv.h"
30
static void tny_olpc_device_on_online (TnyDevice *self);
31
static void tny_olpc_device_on_offline (TnyDevice *self);
32
static gboolean tny_olpc_device_is_online (TnyDevice *self);
36
emit_status (TnyDevice *self)
38
if (tny_olpc_device_is_online (self))
39
tny_olpc_device_on_online (self);
41
tny_olpc_device_on_offline (self);
47
tny_olpc_device_reset (TnyDevice *self)
49
TnyOlpcDevicePriv *priv = TNY_OLPC_DEVICE_GET_PRIVATE (self);
51
const gboolean status_before = tny_olpc_device_is_online (self);
56
/* Signal if it changed: */
57
if (status_before != tny_olpc_device_is_online (self))
58
g_idle_add_full (G_PRIORITY_DEFAULT,
59
(GSourceFunc) emit_status,
61
(GDestroyNotify) g_object_unref);
65
tny_olpc_device_force_online (TnyDevice *self)
68
TnyOlpcDevicePriv *priv = TNY_OLPC_DEVICE_GET_PRIVATE (self);
70
const gboolean already_online = tny_olpc_device_is_online (self);
75
/* Signal if it changed: */
77
g_idle_add_full (G_PRIORITY_DEFAULT,
78
(GSourceFunc) emit_status,
80
(GDestroyNotify) g_object_unref);
87
tny_olpc_device_force_offline (TnyDevice *self)
89
TnyOlpcDevicePriv *priv = TNY_OLPC_DEVICE_GET_PRIVATE (self);
91
const gboolean already_offline = !tny_olpc_device_is_online (self);
96
/* Signal if it changed: */
98
g_idle_add_full (G_PRIORITY_DEFAULT,
99
(GSourceFunc) emit_status,
101
(GDestroyNotify) g_object_unref);
107
tny_olpc_device_on_online (TnyDevice *self)
109
gdk_threads_enter ();
110
g_signal_emit (self, tny_device_signals [TNY_DEVICE_CONNECTION_CHANGED], 0, TRUE);
111
gdk_threads_leave ();
117
tny_olpc_device_on_offline (TnyDevice *self)
119
gdk_threads_enter ();
120
g_signal_emit (self, tny_device_signals [TNY_DEVICE_CONNECTION_CHANGED], 0, FALSE);
121
gdk_threads_leave ();
127
tny_olpc_device_is_online (TnyDevice *self)
129
TnyOlpcDevicePriv *priv = TNY_OLPC_DEVICE_GET_PRIVATE (self);
130
gboolean retval = FALSE;
133
retval = priv->forced;
139
tny_olpc_device_instance_init (GTypeInstance *instance, gpointer g_class)
141
TnyOlpcDevice *self = (TnyOlpcDevice *) instance;
142
TnyOlpcDevicePriv *priv = TNY_OLPC_DEVICE_GET_PRIVATE (self);
149
* tny_olpc_device_new:
151
* Return value: A new #TnyDevice implemented for OLPC
154
tny_olpc_device_new (void)
156
TnyOlpcDevice *self = g_object_new (TNY_TYPE_OLPC_DEVICE, NULL);
158
return TNY_DEVICE (self);
163
tny_olpc_device_finalize (GObject *object)
165
TnyOlpcDevice *self = (TnyOlpcDevice *) object;
166
TnyOlpcDevicePriv *priv = TNY_OLPC_DEVICE_GET_PRIVATE (self);
168
(*parent_class->finalize) (object);
175
tny_device_init (gpointer g, gpointer iface_data)
177
TnyDeviceIface *klass = (TnyDeviceIface *)g;
179
klass->is_online_func = tny_olpc_device_is_online;
180
klass->reset_func = tny_olpc_device_reset;
181
klass->force_offline_func = tny_olpc_device_force_offline;
182
klass->force_online_func = tny_olpc_device_force_online;
190
tny_olpc_device_class_init (TnyOlpcDeviceClass *class)
192
GObjectClass *object_class;
194
parent_class = g_type_class_peek_parent (class);
195
object_class = (GObjectClass*) class;
197
object_class->finalize = tny_olpc_device_finalize;
199
g_type_class_add_private (object_class, sizeof (TnyOlpcDevicePriv));
205
tny_olpc_device_get_type (void)
207
static GType type = 0;
209
if (G_UNLIKELY(type == 0))
211
static const GTypeInfo info =
213
sizeof (TnyOlpcDeviceClass),
214
NULL, /* base_init */
215
NULL, /* base_finalize */
216
(GClassInitFunc) tny_olpc_device_class_init, /* class_init */
217
NULL, /* class_finalize */
218
NULL, /* class_data */
219
sizeof (TnyOlpcDevice),
221
tny_olpc_device_instance_init /* instance_init */
224
static const GInterfaceInfo tny_device_info =
226
(GInterfaceInitFunc) tny_device_init, /* interface_init */
227
NULL, /* interface_finalize */
228
NULL /* interface_data */
231
type = g_type_register_static (G_TYPE_OBJECT,
235
g_type_add_interface_static (type, TNY_TYPE_DEVICE,