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