X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=src%2Faweather-view.c;h=fe8bafa462f42384e94ca949b29c80cd7c4991d8;hb=1019fcfe2d612df24355f2597e661c28621b01c3;hp=7caaf9b9a3868fddff8039eead3304273e335a1f;hpb=55d69c616a9f4f3bae23045f1174047003e2e1d4;p=grits diff --git a/src/aweather-view.c b/src/aweather-view.c index 7caaf9b..fe8bafa 100644 --- a/src/aweather-view.c +++ b/src/aweather-view.c @@ -23,59 +23,53 @@ /**************** * GObject code * ****************/ -G_DEFINE_TYPE(AWeatherView, aweather_view, G_TYPE_OBJECT); - +/* Constants */ enum { PROP_0, PROP_TIME, PROP_SITE, }; - enum { SIG_TIME_CHANGED, SIG_SITE_CHANGED, SIG_LOCATION_CHANGED, SIG_REFRESH, + SIG_OFFLINE, NUM_SIGNALS, }; - static guint signals[NUM_SIGNALS]; +/* Class/Object init */ +G_DEFINE_TYPE(AWeatherView, aweather_view, G_TYPE_OBJECT); static void aweather_view_init(AWeatherView *self) { - //g_message("aweather_view_init"); + g_debug("AWeatherView: init"); /* Default values */ self->time = g_strdup(""); self->site = g_strdup(""); + self->location[0] = 0; + self->location[1] = 0; + self->location[2] = -300*1000; + self->offline = FALSE; } - -static GObject *aweather_view_constructor(GType gtype, guint n_properties, - GObjectConstructParam *properties) +static void aweather_view_dispose(GObject *gobject) { - //g_message("aweather_view_constructor"); - GObjectClass *parent_class = G_OBJECT_CLASS(aweather_view_parent_class); - return parent_class->constructor(gtype, n_properties, properties); -} - -static void aweather_view_dispose (GObject *gobject) -{ - //g_message("aweather_view_dispose"); + g_debug("AWeatherView: dispose"); /* Drop references to other GObjects */ G_OBJECT_CLASS(aweather_view_parent_class)->dispose(gobject); } - static void aweather_view_finalize(GObject *gobject) { - //g_message("aweather_view_finalize"); + g_debug("AWeatherView: finalize"); AWeatherView *self = AWEATHER_VIEW(gobject); + g_free(self->time); g_free(self->site); G_OBJECT_CLASS(aweather_view_parent_class)->finalize(gobject); } - static void aweather_view_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec) { - //g_message("aweather_view_set_property"); + g_debug("AWeatherView: set_property"); AWeatherView *self = AWEATHER_VIEW(object); switch (property_id) { case PROP_TIME: aweather_view_set_time(self, g_value_get_string(value)); break; @@ -83,11 +77,10 @@ static void aweather_view_set_property(GObject *object, guint property_id, default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); } } - static void aweather_view_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec) { - //g_message("aweather_view_get_property"); + g_debug("AWeatherView: get_property"); AWeatherView *self = AWEATHER_VIEW(object); switch (property_id) { case PROP_TIME: g_value_set_string(value, aweather_view_get_time(self)); break; @@ -95,12 +88,10 @@ static void aweather_view_get_property(GObject *object, guint property_id, default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec); } } - static void aweather_view_class_init(AWeatherViewClass *klass) { - //g_message("aweather_view_class_init"); + g_debug("AWeatherView: class_init"); GObjectClass *gobject_class = G_OBJECT_CLASS(klass); - gobject_class->constructor = aweather_view_constructor; gobject_class->dispose = aweather_view_dispose; gobject_class->finalize = aweather_view_finalize; gobject_class->get_property = aweather_view_get_property; @@ -124,7 +115,7 @@ static void aweather_view_class_init(AWeatherViewClass *klass) 0, NULL, NULL, - g_cclosure_marshal_VOID__INT, + g_cclosure_marshal_VOID__STRING, G_TYPE_NONE, 1, G_TYPE_STRING); @@ -162,7 +153,17 @@ static void aweather_view_class_init(AWeatherViewClass *klass) g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - + signals[SIG_OFFLINE] = g_signal_new( + "offline", + G_TYPE_FROM_CLASS(gobject_class), + G_SIGNAL_RUN_LAST, + 0, + NULL, + NULL, + g_cclosure_marshal_VOID__BOOLEAN, + G_TYPE_NONE, + 1, + G_TYPE_BOOLEAN); } /* Signal helpers */ @@ -187,6 +188,11 @@ static void _aweather_view_emit_refresh(AWeatherView *view) { g_signal_emit(view, signals[SIG_REFRESH], 0); } +static void _aweather_view_emit_offline(AWeatherView *view) +{ + g_signal_emit(view, signals[SIG_OFFLINE], 0, + view->offline); +} /*********** @@ -194,14 +200,14 @@ static void _aweather_view_emit_refresh(AWeatherView *view) ***********/ AWeatherView *aweather_view_new() { - //g_message("aweather_view_new"); + g_debug("AWeatherView: new"); return g_object_new(AWEATHER_TYPE_VIEW, NULL); } void aweather_view_set_time(AWeatherView *view, const char *time) { g_assert(AWEATHER_IS_VIEW(view)); - //g_message("aweather_view:set_time: setting time to %s", time); + g_debug("AWeatherView: set_time - time=%s", time); g_free(view->time); view->time = g_strdup(time); _aweather_view_emit_time_changed(view); @@ -210,33 +216,33 @@ void aweather_view_set_time(AWeatherView *view, const char *time) gchar *aweather_view_get_time(AWeatherView *view) { g_assert(AWEATHER_IS_VIEW(view)); - //g_message("aweather_view_get_time"); + g_debug("AWeatherView: get_time"); return view->time; } -void aweather_view_get_location(AWeatherView *view, gdouble *x, gdouble *y, gdouble *z) -{ - g_assert(AWEATHER_IS_VIEW(view)); - //g_message("aweather_view_get_location"); - *x = view->location[0]; - *y = view->location[1]; - *z = view->location[2]; -} - void aweather_view_set_location(AWeatherView *view, gdouble x, gdouble y, gdouble z) { g_assert(AWEATHER_IS_VIEW(view)); - //g_message("aweather_view_set_location"); + g_debug("AWeatherView: set_location"); view->location[0] = x; view->location[1] = y; view->location[2] = z; _aweather_view_emit_location_changed(view); } +void aweather_view_get_location(AWeatherView *view, gdouble *x, gdouble *y, gdouble *z) +{ + g_assert(AWEATHER_IS_VIEW(view)); + g_debug("AWeatherView: get_location"); + *x = view->location[0]; + *y = view->location[1]; + *z = view->location[2]; +} + void aweather_view_pan(AWeatherView *view, gdouble x, gdouble y, gdouble z) { g_assert(AWEATHER_IS_VIEW(view)); - g_message("aweather_view_pan: %f, %f, %f", x, y, z); + g_debug("AWeatherView: pan - x=%.0f, y=%.0f, z=%.0f", x, y, z); view->location[0] += x; view->location[1] += y; view->location[2] += z; @@ -246,20 +252,37 @@ void aweather_view_pan(AWeatherView *view, gdouble x, gdouble y, gdouble z) void aweather_view_zoom(AWeatherView *view, gdouble scale) { g_assert(AWEATHER_IS_VIEW(view)); + g_debug("AWeatherView: zoom"); view->location[2] *= scale; _aweather_view_emit_location_changed(view); } void aweather_view_refresh(AWeatherView *view) { - g_message("aweather_view_refresh: .."); + g_debug("AWeatherView: refresh"); _aweather_view_emit_refresh(view); } +void aweather_view_set_offline(AWeatherView *view, gboolean offline) +{ + g_assert(AWEATHER_IS_VIEW(view)); + g_debug("AWeatherView: set_offline - %d", offline); + view->offline = offline; + _aweather_view_emit_offline(view); +} + +gboolean aweather_view_get_offline(AWeatherView *view) +{ + g_assert(AWEATHER_IS_VIEW(view)); + g_debug("AWeatherView: get_offline - %d", view->offline); + return view->offline; +} + +/* To be deprecated, use {get,set}_location */ void aweather_view_set_site(AWeatherView *view, const gchar *site) { g_assert(AWEATHER_IS_VIEW(view)); - //g_message("aweather_view_set_site"); + g_debug("AWeatherView: set_site"); g_free(view->site); view->site = g_strdup(site); _aweather_view_emit_site_changed(view); @@ -268,7 +291,6 @@ void aweather_view_set_site(AWeatherView *view, const gchar *site) gchar *aweather_view_get_site(AWeatherView *view) { g_assert(AWEATHER_IS_VIEW(view)); - //g_message("aweather_view_get_site"); + g_debug("AWeatherView: get_site"); return view->site; } -