]> Pileus Git - grits/blob - src/aweather-view.c
Download progress bars
[grits] / src / aweather-view.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 "aweather-view.h"
22
23 /****************
24  * GObject code *
25  ****************/
26 /* Constants */
27 enum {
28         PROP_0,
29         PROP_TIME,
30         PROP_SITE,
31 };
32 enum {
33         SIG_TIME_CHANGED,
34         SIG_SITE_CHANGED,
35         SIG_LOCATION_CHANGED,
36         SIG_REFRESH,
37         SIG_OFFLINE,
38         NUM_SIGNALS,
39 };
40 static guint signals[NUM_SIGNALS];
41
42 /* Class/Object init */
43 G_DEFINE_TYPE(AWeatherView, aweather_view, G_TYPE_OBJECT);
44 static void aweather_view_init(AWeatherView *self)
45 {
46         g_debug("AWeatherView: init");
47         /* Default values */
48         self->time = g_strdup("");
49         self->site = g_strdup("");
50         self->location[0] = 0;
51         self->location[1] = 0;
52         self->location[2] = -300*1000;
53         self->offline = FALSE;
54 }
55 static void aweather_view_dispose(GObject *gobject)
56 {
57         g_debug("AWeatherView: dispose");
58         /* Drop references to other GObjects */
59         G_OBJECT_CLASS(aweather_view_parent_class)->dispose(gobject);
60 }
61 static void aweather_view_finalize(GObject *gobject)
62 {
63         g_debug("AWeatherView: finalize");
64         AWeatherView *self = AWEATHER_VIEW(gobject);
65         g_free(self->time);
66         g_free(self->site);
67         G_OBJECT_CLASS(aweather_view_parent_class)->finalize(gobject);
68 }
69 static void aweather_view_set_property(GObject *object, guint property_id,
70                 const GValue *value, GParamSpec *pspec)
71 {
72         g_debug("AWeatherView: set_property");
73         AWeatherView *self = AWEATHER_VIEW(object);
74         switch (property_id) {
75         case PROP_TIME:     aweather_view_set_time(self, g_value_get_string(value)); break;
76         case PROP_SITE:     aweather_view_set_site(self, g_value_get_string(value)); break;
77         default:            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
78         }
79 }
80 static void aweather_view_get_property(GObject *object, guint property_id,
81                 GValue *value, GParamSpec *pspec)
82 {
83         g_debug("AWeatherView: get_property");
84         AWeatherView *self = AWEATHER_VIEW(object);
85         switch (property_id) {
86         case PROP_TIME:     g_value_set_string(value, aweather_view_get_time(self)); break;
87         case PROP_SITE:     g_value_set_string(value, aweather_view_get_site(self)); break;
88         default:            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
89         }
90 }
91 static void aweather_view_class_init(AWeatherViewClass *klass)
92 {
93         g_debug("AWeatherView: class_init");
94         GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
95         gobject_class->dispose      = aweather_view_dispose;
96         gobject_class->finalize     = aweather_view_finalize;
97         gobject_class->get_property = aweather_view_get_property;
98         gobject_class->set_property = aweather_view_set_property;
99         g_object_class_install_property(gobject_class, PROP_TIME,
100                 g_param_spec_pointer(
101                         "time",
102                         "time of the current frame",
103                         "(format unknown)", 
104                         G_PARAM_READWRITE));
105         g_object_class_install_property(gobject_class, PROP_SITE,
106                 g_param_spec_pointer(
107                         "site",
108                         "site seen by the viewport",
109                         "Site of the viewport. Currently this is the name of the radar site.", 
110                         G_PARAM_READWRITE));
111         signals[SIG_TIME_CHANGED] = g_signal_new(
112                         "time-changed",
113                         G_TYPE_FROM_CLASS(gobject_class),
114                         G_SIGNAL_RUN_LAST,
115                         0,
116                         NULL,
117                         NULL,
118                         g_cclosure_marshal_VOID__STRING,
119                         G_TYPE_NONE,
120                         1,
121                         G_TYPE_STRING);
122         signals[SIG_SITE_CHANGED] = g_signal_new(
123                         "site-changed",
124                         G_TYPE_FROM_CLASS(gobject_class),
125                         G_SIGNAL_RUN_LAST,
126                         0,
127                         NULL,
128                         NULL,
129                         g_cclosure_marshal_VOID__STRING,
130                         G_TYPE_NONE,
131                         1,
132                         G_TYPE_STRING);
133         signals[SIG_LOCATION_CHANGED] = g_signal_new(
134                         "location-changed",
135                         G_TYPE_FROM_CLASS(gobject_class),
136                         G_SIGNAL_RUN_LAST,
137                         0,
138                         NULL,
139                         NULL,
140                         aweather_cclosure_marshal_VOID__DOUBLE_DOUBLE_DOUBLE,
141                         G_TYPE_NONE,
142                         3,
143                         G_TYPE_DOUBLE,
144                         G_TYPE_DOUBLE,
145                         G_TYPE_DOUBLE);
146         signals[SIG_REFRESH] = g_signal_new(
147                         "refresh",
148                         G_TYPE_FROM_CLASS(gobject_class),
149                         G_SIGNAL_RUN_LAST,
150                         0,
151                         NULL,
152                         NULL,
153                         g_cclosure_marshal_VOID__VOID,
154                         G_TYPE_NONE,
155                         0);
156         signals[SIG_OFFLINE] = g_signal_new(
157                         "offline",
158                         G_TYPE_FROM_CLASS(gobject_class),
159                         G_SIGNAL_RUN_LAST,
160                         0,
161                         NULL,
162                         NULL,
163                         g_cclosure_marshal_VOID__BOOLEAN,
164                         G_TYPE_NONE,
165                         1,
166                         G_TYPE_BOOLEAN);
167 }
168
169 /* Signal helpers */
170 static void _aweather_view_emit_location_changed(AWeatherView *view)
171 {
172         g_signal_emit(view, signals[SIG_LOCATION_CHANGED], 0, 
173                         view->location[0],
174                         view->location[1],
175                         view->location[2]);
176 }
177 static void _aweather_view_emit_time_changed(AWeatherView *view)
178 {
179         g_signal_emit(view, signals[SIG_TIME_CHANGED], 0,
180                         view->time);
181 }
182 static void _aweather_view_emit_site_changed(AWeatherView *view)
183 {
184         g_signal_emit(view, signals[SIG_SITE_CHANGED], 0,
185                         view->site);
186 }
187 static void _aweather_view_emit_refresh(AWeatherView *view)
188 {
189         g_signal_emit(view, signals[SIG_REFRESH], 0);
190 }
191 static void _aweather_view_emit_offline(AWeatherView *view)
192 {
193         g_signal_emit(view, signals[SIG_OFFLINE], 0,
194                         view->offline);
195 }
196
197
198 /***********
199  * Methods *
200  ***********/
201 AWeatherView *aweather_view_new()
202 {
203         g_debug("AWeatherView: new");
204         return g_object_new(AWEATHER_TYPE_VIEW, NULL);
205 }
206
207 void aweather_view_set_time(AWeatherView *view, const char *time)
208 {
209         g_assert(AWEATHER_IS_VIEW(view));
210         g_debug("AWeatherView: set_time - time=%s", time);
211         g_free(view->time);
212         view->time = g_strdup(time);
213         _aweather_view_emit_time_changed(view);
214 }
215
216 gchar *aweather_view_get_time(AWeatherView *view)
217 {
218         g_assert(AWEATHER_IS_VIEW(view));
219         g_debug("AWeatherView: get_time");
220         return view->time;
221 }
222
223 void aweather_view_set_location(AWeatherView *view, gdouble x, gdouble y, gdouble z)
224 {
225         g_assert(AWEATHER_IS_VIEW(view));
226         g_debug("AWeatherView: set_location");
227         view->location[0] = x;
228         view->location[1] = y;
229         view->location[2] = z;
230         _aweather_view_emit_location_changed(view);
231 }
232
233 void aweather_view_get_location(AWeatherView *view, gdouble *x, gdouble *y, gdouble *z)
234 {
235         g_assert(AWEATHER_IS_VIEW(view));
236         g_debug("AWeatherView: get_location");
237         *x = view->location[0];
238         *y = view->location[1];
239         *z = view->location[2];
240 }
241
242 void aweather_view_pan(AWeatherView *view, gdouble x, gdouble y, gdouble z)
243 {
244         g_assert(AWEATHER_IS_VIEW(view));
245         g_debug("AWeatherView: pan - x=%.0f, y=%.0f, z=%.0f", x, y, z);
246         view->location[0] += x;
247         view->location[1] += y;
248         view->location[2] += z;
249         _aweather_view_emit_location_changed(view);
250 }
251
252 void aweather_view_zoom(AWeatherView *view, gdouble scale)
253 {
254         g_assert(AWEATHER_IS_VIEW(view));
255         g_debug("AWeatherView: zoom");
256         view->location[2] *= scale;
257         _aweather_view_emit_location_changed(view);
258 }
259
260 void aweather_view_refresh(AWeatherView *view)
261 {
262         g_debug("AWeatherView: refresh");
263         _aweather_view_emit_refresh(view);
264 }
265
266 void aweather_view_set_offline(AWeatherView *view, gboolean offline)
267 {
268         g_assert(AWEATHER_IS_VIEW(view));
269         g_debug("AWeatherView: set_offline - %d", offline);
270         view->offline = offline;
271         _aweather_view_emit_offline(view);
272 }
273
274 gboolean aweather_view_get_offline(AWeatherView *view)
275 {
276         g_assert(AWEATHER_IS_VIEW(view));
277         g_debug("AWeatherView: get_offline - %d", view->offline);
278         return view->offline;
279 }
280
281 /* To be deprecated, use {get,set}_location */
282 void aweather_view_set_site(AWeatherView *view, const gchar *site)
283 {
284         g_assert(AWEATHER_IS_VIEW(view));
285         g_debug("AWeatherView: set_site");
286         g_free(view->site);
287         view->site = g_strdup(site);
288         _aweather_view_emit_site_changed(view);
289 }
290
291 gchar *aweather_view_get_site(AWeatherView *view)
292 {
293         g_assert(AWEATHER_IS_VIEW(view));
294         g_debug("AWeatherView: get_site");
295         return view->site;
296 }