]> Pileus Git - grits/blob - src/gis-world.c
4350f3a8c52533cc27312a22703458164a2c0403
[grits] / src / gis-world.c
1 /*
2  * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
3  * 
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  * 
9  * This program 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
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include <glib.h>
19
20 #include "marshal.h"
21 #include "gis-world.h"
22
23 /****************
24  * GObject code *
25  ****************/
26 /* Constants */
27 enum {
28         SIG_REFRESH,
29         SIG_OFFLINE,
30         NUM_SIGNALS,
31 };
32 static guint signals[NUM_SIGNALS];
33
34 /* Class/Object init */
35 G_DEFINE_TYPE(GisWorld, gis_world, G_TYPE_OBJECT);
36 static void gis_world_init(GisWorld *self)
37 {
38         g_debug("GisWorld: init");
39         /* Default values */
40         self->offline = FALSE;
41 }
42 static void gis_world_dispose(GObject *gobject)
43 {
44         g_debug("GisWorld: dispose");
45         /* Drop references to other GObjects */
46         G_OBJECT_CLASS(gis_world_parent_class)->dispose(gobject);
47 }
48 static void gis_world_finalize(GObject *gobject)
49 {
50         g_debug("GisWorld: finalize");
51         GisWorld *self = GIS_WORLD(gobject);
52         G_OBJECT_CLASS(gis_world_parent_class)->finalize(gobject);
53 }
54 static void gis_world_class_init(GisWorldClass *klass)
55 {
56         g_debug("GisWorld: class_init");
57         GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
58         gobject_class->dispose      = gis_world_dispose;
59         gobject_class->finalize     = gis_world_finalize;
60         signals[SIG_REFRESH] = g_signal_new(
61                         "refresh",
62                         G_TYPE_FROM_CLASS(gobject_class),
63                         G_SIGNAL_RUN_LAST,
64                         0,
65                         NULL,
66                         NULL,
67                         g_cclosure_marshal_VOID__VOID,
68                         G_TYPE_NONE,
69                         0);
70         signals[SIG_OFFLINE] = g_signal_new(
71                         "offline",
72                         G_TYPE_FROM_CLASS(gobject_class),
73                         G_SIGNAL_RUN_LAST,
74                         0,
75                         NULL,
76                         NULL,
77                         g_cclosure_marshal_VOID__BOOLEAN,
78                         G_TYPE_NONE,
79                         1,
80                         G_TYPE_BOOLEAN);
81 }
82
83 /* Signal helpers */
84 static void _gis_world_emit_refresh(GisWorld *world)
85 {
86         g_signal_emit(world, signals[SIG_REFRESH], 0);
87 }
88 static void _gis_world_emit_offline(GisWorld *world)
89 {
90         g_signal_emit(world, signals[SIG_OFFLINE], 0,
91                         world->offline);
92 }
93
94
95 /***********
96  * Methods *
97  ***********/
98 GisWorld *gis_world_new()
99 {
100         g_debug("GisWorld: new");
101         return g_object_new(GIS_TYPE_WORLD, NULL);
102 }
103
104 void gis_world_refresh(GisWorld *world)
105 {
106         g_debug("GisWorld: refresh");
107         _gis_world_emit_refresh(world);
108 }
109
110 void gis_world_set_offline(GisWorld *world, gboolean offline)
111 {
112         g_assert(GIS_IS_WORLD(world));
113         g_debug("GisWorld: set_offline - %d", offline);
114         world->offline = offline;
115         _gis_world_emit_offline(world);
116 }
117
118 gboolean gis_world_get_offline(GisWorld *world)
119 {
120         g_assert(GIS_IS_WORLD(world));
121         g_debug("GisWorld: get_offline - %d", world->offline);
122         return world->offline;
123 }