]> Pileus Git - grits/blob - src/aweather-view.c
Converting a lot of stuff to GObject and adding gtk-doc support
[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     = 0;
27         self->location = 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_int   (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_int   (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_int(
88                         "time",
89                         "time of the current frame",
90                         "(format unknown)", 
91                         G_MININT32, G_MAXINT32, 0,
92                         G_PARAM_READWRITE));
93         g_object_class_install_property(gobject_class, PROP_LOCATION,
94                 g_param_spec_pointer(
95                         "location",
96                         "location seen by the viewport",
97                         "Location of the viewport. Currently this is the name of the radar site.", 
98                         G_PARAM_READWRITE));
99         signals[SIG_TIME_CHANGED] = g_signal_new(
100                         "time-changed",
101                         G_TYPE_FROM_CLASS(gobject_class),
102                         G_SIGNAL_RUN_LAST,
103                         0,
104                         NULL,
105                         NULL,
106                         g_cclosure_marshal_VOID__INT,
107                         G_TYPE_NONE,
108                         1,
109                         G_TYPE_INT);
110         signals[SIG_LOCATION_CHANGED] = g_signal_new(
111                         "location-changed",
112                         G_TYPE_FROM_CLASS(gobject_class),
113                         G_SIGNAL_RUN_LAST,
114                         0,
115                         NULL,
116                         NULL,
117                         g_cclosure_marshal_VOID__STRING,
118                         G_TYPE_NONE,
119                         1,
120                         G_TYPE_GSTRING);
121
122 }
123
124 /* Methods */
125 AWeatherView *aweather_view_new()
126 {
127         g_message("aweather_view_new");
128         return g_object_new(AWEATHER_TYPE_VIEW, NULL);
129 }
130
131 void aweather_view_set_time(AWeatherView *view, int time)
132 {
133         g_message("aweather_view_set_time");
134         view->time = time;
135         g_signal_emit(view, signals[SIG_TIME_CHANGED], 0, time);
136 }
137
138 int aweather_view_get_time(AWeatherView *view)
139 {
140         g_message("aweather_view_get_time");
141         return view->time;
142 }
143
144 void aweather_view_set_location(AWeatherView *view, const gchar *location)
145 {
146         g_message("aweather_view_set_location");
147         g_free(view->location);
148         view->location = g_strdup(location);
149         g_signal_emit(view, signals[SIG_LOCATION_CHANGED], 0, view->location);
150 }
151
152 gchar *aweather_view_get_location(AWeatherView *view)
153 {
154         g_message("aweather_view_get_location");
155         return view->location;
156 }