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