1
/* libtinymail-maemo - The Tiny Mail base library for maemo
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-maemo-device.h>
27
static GObjectClass *parent_class = NULL;
29
#include "tny-maemo-device-priv.h"
31
static void tny_maemo_device_on_online (TnyDevice *self);
32
static void tny_maemo_device_on_offline (TnyDevice *self);
33
static gboolean tny_maemo_device_is_online (TnyDevice *self);
37
emit_status (TnyDevice *self)
39
if (tny_maemo_device_is_online (self))
40
tny_maemo_device_on_online (self);
42
tny_maemo_device_on_offline (self);
48
tny_maemo_device_reset (TnyDevice *self)
50
TnyMaemoDevicePriv *priv = TNY_MAEMO_DEVICE_GET_PRIVATE (self);
52
const gboolean status_before = tny_maemo_device_is_online (self);
57
/* Signal if it changed: */
58
if (status_before != tny_maemo_device_is_online (self))
59
g_idle_add_full (G_PRIORITY_DEFAULT,
60
(GSourceFunc) emit_status,
62
(GDestroyNotify) g_object_unref);
66
tny_maemo_device_force_online (TnyDevice *self)
69
TnyMaemoDevicePriv *priv = TNY_MAEMO_DEVICE_GET_PRIVATE (self);
71
const gboolean already_online = tny_maemo_device_is_online (self);
76
/* Signal if it changed: */
78
g_idle_add_full (G_PRIORITY_DEFAULT,
79
(GSourceFunc) emit_status,
81
(GDestroyNotify) g_object_unref);
88
tny_maemo_device_force_offline (TnyDevice *self)
90
TnyMaemoDevicePriv *priv = TNY_MAEMO_DEVICE_GET_PRIVATE (self);
92
const gboolean already_offline = !tny_maemo_device_is_online (self);
97
/* Signal if it changed: */
99
g_idle_add_full (G_PRIORITY_DEFAULT,
100
(GSourceFunc) emit_status,
102
(GDestroyNotify) g_object_unref);
108
tny_maemo_device_on_online (TnyDevice *self)
110
gdk_threads_enter ();
111
g_signal_emit (self, tny_device_signals [TNY_DEVICE_CONNECTION_CHANGED], 0, TRUE);
112
gdk_threads_leave ();
118
tny_maemo_device_on_offline (TnyDevice *self)
120
gdk_threads_enter ();
121
g_signal_emit (self, tny_device_signals [TNY_DEVICE_CONNECTION_CHANGED], 0, FALSE);
122
gdk_threads_leave ();
128
tny_maemo_device_is_online (TnyDevice *self)
130
TnyMaemoDevicePriv *priv = TNY_MAEMO_DEVICE_GET_PRIVATE (self);
131
gboolean retval = FALSE;
134
retval = priv->forced;
140
tny_maemo_device_instance_init (GTypeInstance *instance, gpointer g_class)
147
* tny_maemo_device_new:
149
* Return value: A new #TnyDevice implemented for MAEMO
152
tny_maemo_device_new (void)
154
TnyMaemoDevice *self = g_object_new (TNY_TYPE_MAEMO_DEVICE, NULL);
156
return TNY_DEVICE (self);
161
tny_maemo_device_finalize (GObject *object)
163
(*parent_class->finalize) (object);
170
tny_device_init (gpointer g, gpointer iface_data)
172
TnyDeviceIface *klass = (TnyDeviceIface *)g;
174
klass->is_online_func = tny_maemo_device_is_online;
175
klass->reset_func = tny_maemo_device_reset;
176
klass->force_offline_func = tny_maemo_device_force_offline;
177
klass->force_online_func = tny_maemo_device_force_online;
185
tny_maemo_device_class_init (TnyMaemoDeviceClass *class)
187
GObjectClass *object_class;
189
parent_class = g_type_class_peek_parent (class);
190
object_class = (GObjectClass*) class;
192
object_class->finalize = tny_maemo_device_finalize;
194
g_type_class_add_private (object_class, sizeof (TnyMaemoDevicePriv));
200
tny_maemo_device_get_type (void)
202
static GType type = 0;
204
if (G_UNLIKELY(type == 0))
206
static const GTypeInfo info =
208
sizeof (TnyMaemoDeviceClass),
209
NULL, /* base_init */
210
NULL, /* base_finalize */
211
(GClassInitFunc) tny_maemo_device_class_init, /* class_init */
212
NULL, /* class_finalize */
213
NULL, /* class_data */
214
sizeof (TnyMaemoDevice),
216
tny_maemo_device_instance_init /* instance_init */
219
static const GInterfaceInfo tny_device_info =
221
(GInterfaceInitFunc) tny_device_init, /* interface_init */
222
NULL, /* interface_finalize */
223
NULL /* interface_data */
226
type = g_type_register_static (G_TYPE_OBJECT,
230
g_type_add_interface_static (type, TNY_TYPE_DEVICE,