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