]> Pileus Git - grits/blob - src/gis/gis-world.c
Splitting GIS into a shared library, and a lot more
[grits] / src / gis / 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 "gis-marshal.h"
21 #include "gis-world.h"
22
23 /****************
24  * GObject code *
25  ****************/
26 /* Constants */
27 double WGS884_SEMI_MAJOR = 6378137.0;      // a
28 double WGS884_SEMI_MINOR = 6356752.314245; // b
29 double WGS884_INV_FLAT   = 298.257223563;  // 1/f
30
31 enum {
32         SIG_REFRESH,
33         SIG_OFFLINE,
34         NUM_SIGNALS,
35 };
36 static guint signals[NUM_SIGNALS];
37
38 /* Class/Object init */
39 G_DEFINE_TYPE(GisWorld, gis_world, G_TYPE_OBJECT);
40 static void gis_world_init(GisWorld *self)
41 {
42         g_debug("GisWorld: init");
43         /* Default values */
44         self->offline = FALSE;
45 }
46 static void gis_world_dispose(GObject *gobject)
47 {
48         g_debug("GisWorld: dispose");
49         /* Drop references to other GObjects */
50         G_OBJECT_CLASS(gis_world_parent_class)->dispose(gobject);
51 }
52 static void gis_world_finalize(GObject *gobject)
53 {
54         g_debug("GisWorld: finalize");
55         GisWorld *self = GIS_WORLD(gobject);
56         G_OBJECT_CLASS(gis_world_parent_class)->finalize(gobject);
57 }
58 static void gis_world_class_init(GisWorldClass *klass)
59 {
60         g_debug("GisWorld: class_init");
61         GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
62         gobject_class->dispose      = gis_world_dispose;
63         gobject_class->finalize     = gis_world_finalize;
64         signals[SIG_REFRESH] = g_signal_new(
65                         "refresh",
66                         G_TYPE_FROM_CLASS(gobject_class),
67                         G_SIGNAL_RUN_LAST,
68                         0,
69                         NULL,
70                         NULL,
71                         g_cclosure_marshal_VOID__VOID,
72                         G_TYPE_NONE,
73                         0);
74         signals[SIG_OFFLINE] = g_signal_new(
75                         "offline",
76                         G_TYPE_FROM_CLASS(gobject_class),
77                         G_SIGNAL_RUN_LAST,
78                         0,
79                         NULL,
80                         NULL,
81                         g_cclosure_marshal_VOID__BOOLEAN,
82                         G_TYPE_NONE,
83                         1,
84                         G_TYPE_BOOLEAN);
85 }
86
87 /* Signal helpers */
88 static void _gis_world_emit_refresh(GisWorld *world)
89 {
90         g_signal_emit(world, signals[SIG_REFRESH], 0);
91 }
92 static void _gis_world_emit_offline(GisWorld *world)
93 {
94         g_signal_emit(world, signals[SIG_OFFLINE], 0,
95                         world->offline);
96 }
97
98
99 /***********
100  * Methods *
101  ***********/
102 GisWorld *gis_world_new()
103 {
104         g_debug("GisWorld: new");
105         return g_object_new(GIS_TYPE_WORLD, NULL);
106 }
107
108 void gis_world_refresh(GisWorld *world)
109 {
110         g_debug("GisWorld: refresh");
111         _gis_world_emit_refresh(world);
112 }
113
114 void gis_world_set_offline(GisWorld *world, gboolean offline)
115 {
116         g_assert(GIS_IS_WORLD(world));
117         g_debug("GisWorld: set_offline - %d", offline);
118         world->offline = offline;
119         _gis_world_emit_offline(world);
120 }
121
122 gboolean gis_world_get_offline(GisWorld *world)
123 {
124         g_assert(GIS_IS_WORLD(world));
125         g_debug("GisWorld: get_offline - %d", world->offline);
126         return world->offline;
127 }
128
129