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