[frogr] New FrogrLocation class



commit 91da56e53acee99a5b2d21fa63666bbe7128ca83
Author: Mario Sanchez Prada <msanchez igalia com>
Date:   Thu Aug 25 19:29:52 2011 +0200

    New FrogrLocation class

 src/Makefile.am      |    2 +
 src/frogr-location.c |  193 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/frogr-location.h |   72 +++++++++++++++++++
 3 files changed, 267 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 2cfc7b0..5c9b0d1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -73,6 +73,8 @@ frogr_SOURCES = \
 	frogr-main-view-model.h \
 	frogr-main-view.c \
 	frogr-main-view.h \
+	frogr-location.c \
+	frogr-location.h \
 	frogr-picture-loader.c \
 	frogr-picture-loader.h \
 	frogr-picture-uploader.c \
diff --git a/src/frogr-location.c b/src/frogr-location.c
new file mode 100644
index 0000000..f1b23d5
--- /dev/null
+++ b/src/frogr-location.c
@@ -0,0 +1,193 @@
+/*
+ * frogr-location.c -- A location in frogr
+ *
+ * Copyright (C) 2011 Mario Sanchez Prada
+ * Authors: Mario Sanchez Prada <msanchez igalia com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 3 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include "frogr-location.h"
+
+#define FROGR_LOCATION_GET_PRIVATE(object)              \
+  (G_TYPE_INSTANCE_GET_PRIVATE ((object),               \
+                                FROGR_TYPE_LOCATION,    \
+                                FrogrLocationPrivate))
+
+G_DEFINE_TYPE (FrogrLocation, frogr_location, G_TYPE_OBJECT)
+
+/* Private struct */
+typedef struct _FrogrLocationPrivate FrogrLocationPrivate;
+struct _FrogrLocationPrivate
+{
+  gdouble latitude;
+  gdouble longitude;
+};
+
+/* Properties */
+enum  {
+  PROP_0,
+  PROP_LATITUDE,
+  PROP_LONGITUDE,
+};
+
+/* Private API */
+
+static void
+_frogr_location_set_property (GObject *object,
+                             guint prop_id,
+                             const GValue *value,
+                             GParamSpec *pspec)
+{
+  FrogrLocation *self = FROGR_LOCATION (object);
+
+  switch (prop_id)
+    {
+    case PROP_LATITUDE:
+      frogr_location_set_latitude (self, g_value_get_double (value));
+      break;
+    case PROP_LONGITUDE:
+      frogr_location_set_longitude (self, g_value_get_double (value));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+_frogr_location_get_property (GObject *object,
+                             guint prop_id,
+                             GValue *value,
+                             GParamSpec *pspec)
+{
+  FrogrLocationPrivate *priv = FROGR_LOCATION_GET_PRIVATE (object);
+
+  switch (prop_id)
+    {
+    case PROP_LATITUDE:
+      g_value_set_double (value, priv->latitude);
+      break;
+    case PROP_LONGITUDE:
+      g_value_set_double (value, priv->longitude);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void
+frogr_location_class_init(FrogrLocationClass *klass)
+{
+  GObjectClass *obj_class = G_OBJECT_CLASS(klass);
+
+  /* GtkObject signals */
+  obj_class->set_property = _frogr_location_set_property;
+  obj_class->get_property = _frogr_location_get_property;
+
+  /* Install properties */
+  g_object_class_install_property (obj_class,
+                                   PROP_LATITUDE,
+                                   g_param_spec_double ("latitude",
+                                                        "latitude",
+                                                        "Latitude for the location",
+                                                        -90.0,
+                                                        90.0,
+                                                        0.0,
+                                                        G_PARAM_READWRITE));
+
+  g_object_class_install_property (obj_class,
+                                   PROP_LATITUDE,
+                                   g_param_spec_double ("longitude",
+                                                        "longitude",
+                                                        "Longitude for the location",
+                                                        -180.0,
+                                                        180.0,
+                                                        0.0,
+                                                        G_PARAM_READWRITE));
+
+  g_type_class_add_private (obj_class, sizeof (FrogrLocationPrivate));
+}
+
+static void
+frogr_location_init (FrogrLocation *self)
+{
+  FrogrLocationPrivate *priv = FROGR_LOCATION_GET_PRIVATE (self);
+
+  /* Default values */
+  priv->latitude = 0.0;
+  priv->longitude = 0.0;
+}
+
+
+/* Public API */
+
+FrogrLocation *
+frogr_location_new (gdouble latitude, gdouble longitude)
+{
+  return FROGR_LOCATION (g_object_new(FROGR_TYPE_LOCATION,
+                                     "latitude", latitude,
+                                     "longitude", longitude,
+                                     NULL));
+}
+
+
+/* Data Managing functions */
+
+const gdouble
+frogr_location_get_latitude (FrogrLocation *self)
+{
+  FrogrLocationPrivate *priv = NULL;
+
+  g_return_val_if_fail(FROGR_IS_LOCATION(self), 0.0);
+
+  priv = FROGR_LOCATION_GET_PRIVATE (self);
+  return priv->latitude;
+}
+
+void
+frogr_location_set_latitude (FrogrLocation *self,
+                             gdouble latitude)
+{
+  FrogrLocationPrivate *priv = NULL;
+
+  g_return_if_fail(FROGR_IS_LOCATION(self));
+
+  priv = FROGR_LOCATION_GET_PRIVATE (self);
+  priv->latitude = latitude;
+}
+
+const gdouble
+frogr_location_get_longitude (FrogrLocation *self)
+{
+  FrogrLocationPrivate *priv = NULL;
+
+  g_return_val_if_fail(FROGR_IS_LOCATION(self), 0.0);
+
+  priv = FROGR_LOCATION_GET_PRIVATE (self);
+  return priv->longitude;
+}
+
+void
+frogr_location_set_longitude (FrogrLocation *self,
+                              gdouble longitude)
+{
+  FrogrLocationPrivate *priv = NULL;
+
+  g_return_if_fail(FROGR_IS_LOCATION(self));
+
+  priv = FROGR_LOCATION_GET_PRIVATE (self);
+  priv->longitude = longitude;
+}
diff --git a/src/frogr-location.h b/src/frogr-location.h
new file mode 100644
index 0000000..e3b68fc
--- /dev/null
+++ b/src/frogr-location.h
@@ -0,0 +1,72 @@
+/*
+ * frogr-location.h -- A location in frogr
+ *
+ * Copyright (C) 2011 Mario Sanchez Prada
+ * Authors: Mario Sanchez Prada <msanchez igalia com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 3 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef _FROGR_LOCATION_H
+#define _FROGR_LOCATION_H
+
+#include "frogr-photoset.h"
+#include "frogr-group.h"
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <flicksoup/flicksoup.h>
+
+G_BEGIN_DECLS
+
+#define FROGR_TYPE_LOCATION           (frogr_location_get_type())
+#define FROGR_LOCATION(obj)           (G_TYPE_CHECK_INSTANCE_CAST(obj, FROGR_TYPE_LOCATION, FrogrLocation))
+#define FROGR_LOCATION_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST(klass, FROGR_TYPE_LOCATION, FrogrLocationClass))
+#define FROGR_IS_LOCATION(obj)           (G_TYPE_CHECK_INSTANCE_TYPE(obj, FROGR_TYPE_LOCATION))
+#define FROGR_IS_LOCATION_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE((klass), FROGR_TYPE_LOCATION))
+#define FROGR_LOCATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), FROGR_TYPE_LOCATION, FrogrLocationClass))
+
+typedef struct _FrogrLocation FrogrLocation;
+typedef struct _FrogrLocationClass FrogrLocationClass;
+
+struct _FrogrLocation
+{
+  GObject parent_instance;
+};
+
+struct _FrogrLocationClass
+{
+  GObjectClass parent_class;
+};
+
+
+GType frogr_location_get_type(void) G_GNUC_CONST;
+
+/* Constructor */
+FrogrLocation *frogr_location_new (gdouble latitude, gdouble longitude);
+
+/* Data Managing functions */
+
+const gdouble frogr_location_get_latitude (FrogrLocation *self);
+void frogr_location_set_latitude (FrogrLocation *self,
+                                  gdouble latitude);
+
+const gdouble frogr_location_get_longitude (FrogrLocation *self);
+void frogr_location_set_longitude (FrogrLocation *self,
+                                   gdouble longitude);
+
+G_END_DECLS
+
+#endif



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]