]> Pileus Git - grits/blob - src/aweather-view.c
* Road plan (HACKING)
[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 "aweather-view.h"
21
22 G_DEFINE_TYPE(AWeatherView, aweather_view, G_TYPE_OBJECT);
23
24 enum {
25         PROP_0,
26         PROP_TIME,
27         PROP_LOCATION,
28 };
29
30 enum {
31         SIG_TIME_CHANGED,
32         SIG_LOCATION_CHANGED,
33         SIG_REFRESH,
34         NUM_SIGNALS,
35 };
36
37 static guint signals[NUM_SIGNALS];
38
39 /* Constructor / destructors */
40 static void aweather_view_init(AWeatherView *self)
41 {
42         //g_message("aweather_view_init");
43         /* Default values */
44         self->time     = g_strdup(""); //g_strdup("LATEST");
45         self->location = g_strdup(""); //g_strdup("IND");
46 }
47
48 static GObject *aweather_view_constructor(GType gtype, guint n_properties,
49                 GObjectConstructParam *properties)
50 {
51         //g_message("aweather_view_constructor");
52         GObjectClass *parent_class = G_OBJECT_CLASS(aweather_view_parent_class);
53         return  parent_class->constructor(gtype, n_properties, properties);
54 }
55
56 static void aweather_view_dispose (GObject *gobject)
57 {
58         //g_message("aweather_view_dispose");
59         /* Drop references to other GObjects */
60         G_OBJECT_CLASS(aweather_view_parent_class)->dispose(gobject);
61 }
62
63 static void aweather_view_finalize(GObject *gobject)
64 {
65         //g_message("aweather_view_finalize");
66         AWeatherView *self = AWEATHER_VIEW(gobject);
67         g_free(self->location);
68         G_OBJECT_CLASS(aweather_view_parent_class)->finalize(gobject);
69 }
70
71 static void aweather_view_set_property(GObject *object, guint property_id,
72                 const GValue *value, GParamSpec *pspec)
73 {
74         //g_message("aweather_view_set_property");
75         AWeatherView *self = AWEATHER_VIEW(object);
76         switch (property_id) {
77         case PROP_TIME:     aweather_view_set_time    (self, g_value_get_string(value)); break;
78         case PROP_LOCATION: aweather_view_set_location(self, g_value_get_string(value)); break;
79         default:            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
80         }
81 }
82
83 static void aweather_view_get_property(GObject *object, guint property_id,
84                 GValue *value, GParamSpec *pspec)
85 {
86         //g_message("aweather_view_get_property");
87         AWeatherView *self = AWEATHER_VIEW(object);
88         switch (property_id) {
89         case PROP_TIME:     g_value_set_string(value, aweather_view_get_time    (self)); break;
90         case PROP_LOCATION: g_value_set_string(value, aweather_view_get_location(self)); break;
91         default:            G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
92         }
93 }
94
95 static void aweather_view_class_init(AWeatherViewClass *klass)
96 {
97         //g_message("aweather_view_class_init");
98         GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
99         gobject_class->constructor  = aweather_view_constructor;
100         gobject_class->dispose      = aweather_view_dispose;
101         gobject_class->finalize     = aweather_view_finalize;
102         gobject_class->get_property = aweather_view_get_property;
103         gobject_class->set_property = aweather_view_set_property;
104         g_object_class_install_property(gobject_class, PROP_TIME,
105                 g_param_spec_pointer(
106                         "time",
107                         "time of the current frame",
108                         "(format unknown)", 
109                         G_PARAM_READWRITE));
110         g_object_class_install_property(gobject_class, PROP_LOCATION,
111                 g_param_spec_pointer(
112                         "location",
113                         "location seen by the viewport",
114                         "Location of the viewport. Currently this is the name of the radar site.", 
115                         G_PARAM_READWRITE));
116         signals[SIG_TIME_CHANGED] = g_signal_new(
117                         "time-changed",
118                         G_TYPE_FROM_CLASS(gobject_class),
119                         G_SIGNAL_RUN_LAST,
120                         0,
121                         NULL,
122                         NULL,
123                         g_cclosure_marshal_VOID__INT,
124                         G_TYPE_NONE,
125                         1,
126                         G_TYPE_STRING);
127         signals[SIG_LOCATION_CHANGED] = g_signal_new(
128                         "location-changed",
129                         G_TYPE_FROM_CLASS(gobject_class),
130                         G_SIGNAL_RUN_LAST,
131                         0,
132                         NULL,
133                         NULL,
134                         g_cclosure_marshal_VOID__STRING,
135                         G_TYPE_NONE,
136                         1,
137                         G_TYPE_STRING);
138         signals[SIG_REFRESH] = g_signal_new(
139                         "refresh",
140                         G_TYPE_FROM_CLASS(gobject_class),
141                         G_SIGNAL_RUN_LAST,
142                         0,
143                         NULL,
144                         NULL,
145                         g_cclosure_marshal_VOID__VOID,
146                         G_TYPE_NONE,
147                         0);
148
149 }
150
151 /* Methods */
152 AWeatherView *aweather_view_new()
153 {
154         //g_message("aweather_view_new");
155         return g_object_new(AWEATHER_TYPE_VIEW, NULL);
156 }
157
158 void aweather_view_set_time(AWeatherView *view, const char *time)
159 {
160         g_assert(AWEATHER_IS_VIEW(view));
161         //g_message("aweather_view:set_time: setting time to %s", time);
162         g_free(view->time);
163         view->time = g_strdup(time);
164         g_signal_emit(view, signals[SIG_TIME_CHANGED], 0, time);
165 }
166
167 gchar *aweather_view_get_time(AWeatherView *view)
168 {
169         g_assert(AWEATHER_IS_VIEW(view));
170         //g_message("aweather_view_get_time");
171         return view->time;
172 }
173
174 void aweather_view_set_location(AWeatherView *view, const gchar *location)
175 {
176         g_assert(AWEATHER_IS_VIEW(view));
177         //g_message("aweather_view_set_location");
178         g_free(view->location);
179         view->location = g_strdup(location);
180         g_signal_emit(view, signals[SIG_LOCATION_CHANGED], 0, view->location);
181 }
182
183 gchar *aweather_view_get_location(AWeatherView *view)
184 {
185         g_assert(AWEATHER_IS_VIEW(view));
186         //g_message("aweather_view_get_location");
187         return view->location;
188 }
189
190 void aweather_view_refresh(AWeatherView *view)
191 {
192         g_message("aweather_view_refresh: ..");
193         g_signal_emit(view, signals[SIG_REFRESH], 0);
194 }
195
196 void aweather_view_zoomin(AWeatherView *view)
197 {
198         g_message("aweather_view_zoomin: ..");
199 }
200
201 void aweather_view_zoomout(AWeatherView *view)
202 {
203         g_message("aweather_view_zoomout: ..");
204 }