2 * Copyright (C) 2009 Andy Spencer <spenceal@rose-hulman.edu>
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.
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.
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/>.
20 #include "aweather-view.h"
22 G_DEFINE_TYPE(AWeatherView, aweather_view, G_TYPE_OBJECT);
36 static guint signals[NUM_SIGNALS];
38 /* Constructor / destructors */
39 static void aweather_view_init(AWeatherView *self)
41 //g_message("aweather_view_init");
43 self->time = g_strdup(""); //g_strdup("LATEST");
44 self->location = g_strdup(""); //g_strdup("IND");
47 static GObject *aweather_view_constructor(GType gtype, guint n_properties,
48 GObjectConstructParam *properties)
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);
55 static void aweather_view_dispose (GObject *gobject)
57 //g_message("aweather_view_dispose");
58 /* Drop references to other GObjects */
59 G_OBJECT_CLASS(aweather_view_parent_class)->dispose(gobject);
62 static void aweather_view_finalize(GObject *gobject)
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);
70 static void aweather_view_set_property(GObject *object, guint property_id,
71 const GValue *value, GParamSpec *pspec)
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);
82 static void aweather_view_get_property(GObject *object, guint property_id,
83 GValue *value, GParamSpec *pspec)
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);
94 static void aweather_view_class_init(AWeatherViewClass *klass)
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(
106 "time of the current frame",
109 g_object_class_install_property(gobject_class, PROP_LOCATION,
110 g_param_spec_pointer(
112 "location seen by the viewport",
113 "Location of the viewport. Currently this is the name of the radar site.",
115 signals[SIG_TIME_CHANGED] = g_signal_new(
117 G_TYPE_FROM_CLASS(gobject_class),
122 g_cclosure_marshal_VOID__INT,
126 signals[SIG_LOCATION_CHANGED] = g_signal_new(
128 G_TYPE_FROM_CLASS(gobject_class),
133 g_cclosure_marshal_VOID__STRING,
141 AWeatherView *aweather_view_new()
143 //g_message("aweather_view_new");
144 return g_object_new(AWEATHER_TYPE_VIEW, NULL);
147 void aweather_view_set_time(AWeatherView *view, const char *time)
149 g_assert(AWEATHER_IS_VIEW(view));
150 //g_message("aweather_view:set_time: setting time to %s", time);
151 view->time = g_strdup(time);
152 g_signal_emit(view, signals[SIG_TIME_CHANGED], 0, time);
155 gchar *aweather_view_get_time(AWeatherView *view)
157 g_assert(AWEATHER_IS_VIEW(view));
158 //g_message("aweather_view_get_time");
162 void aweather_view_set_location(AWeatherView *view, const gchar *location)
164 g_assert(AWEATHER_IS_VIEW(view));
165 //g_message("aweather_view_set_location");
166 g_free(view->location);
167 view->location = g_strdup(location);
168 g_signal_emit(view, signals[SIG_LOCATION_CHANGED], 0, view->location);
171 gchar *aweather_view_get_location(AWeatherView *view)
173 g_assert(AWEATHER_IS_VIEW(view));
174 //g_message("aweather_view_get_location");
175 return view->location;