[geocode-glib] lib: Add simple GeocodeLocation object



commit 464eb1e52bee30d9df38861cc446ae0d26d5c9c6
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Oct 31 23:59:35 2012 +0100

    lib: Add simple GeocodeLocation object

 geocode-glib/Makefile.am          |    4 +-
 geocode-glib/geocode-glib.h       |    1 +
 geocode-glib/geocode-glib.symbols |    3 +
 geocode-glib/geocode-location.c   |   79 +++++++++++++++++++++++++++++++++++++
 geocode-glib/geocode-location.h   |   50 +++++++++++++++++++++++
 5 files changed, 136 insertions(+), 1 deletions(-)
---
diff --git a/geocode-glib/Makefile.am b/geocode-glib/Makefile.am
index 514a753..7e951bd 100644
--- a/geocode-glib/Makefile.am
+++ b/geocode-glib/Makefile.am
@@ -6,6 +6,8 @@ BUILT_GIRSOURCES =
 lib_LTLIBRARIES = libgeocode-glib.la
 
 public_files =						\
+	geocode-location.c				\
+	geocode-location.h				\
 	geocode-glib.c					\
 	geocode-glib.h					\
 	geocode-error.c					\
@@ -24,7 +26,7 @@ libgeocode_glib_la_LDFLAGS =				\
 	-export-symbols $(srcdir)/geocode-glib.symbols
 
 gcglibdir = $(pkgincludedir)
-gcglib_HEADERS = geocode-glib.h
+gcglib_HEADERS = geocode-glib.h geocode-location.h
 
 AM_CFLAGS = -I$(top_srcdir) $(GEOCODE_CFLAGS) $(COMMON_CFLAGS) $(WARN_CFLAGS) $(DISABLE_DEPRECATED)
 
diff --git a/geocode-glib/geocode-glib.h b/geocode-glib/geocode-glib.h
index 67f33bf..fd7b8f1 100644
--- a/geocode-glib/geocode-glib.h
+++ b/geocode-glib/geocode-glib.h
@@ -25,6 +25,7 @@
 
 #include <glib.h>
 #include <gio/gio.h>
+#include <geocode-glib/geocode-location.h>
 #include <geocode-glib/geocode-error.h>
 
 G_BEGIN_DECLS
diff --git a/geocode-glib/geocode-glib.symbols b/geocode-glib/geocode-glib.symbols
index 81bf20b..a54b524 100644
--- a/geocode-glib/geocode-glib.symbols
+++ b/geocode-glib/geocode-glib.symbols
@@ -1,3 +1,6 @@
+geocode_location_get_type
+geocode_location_new
+geocode_location_new_with_description
 geocode_error_quark
 geocode_object_get_type
 geocode_object_new
diff --git a/geocode-glib/geocode-location.c b/geocode-glib/geocode-location.c
new file mode 100644
index 0000000..41b90d9
--- /dev/null
+++ b/geocode-glib/geocode-location.c
@@ -0,0 +1,79 @@
+/*
+   Copyright (C) 2012 Bastien Nocera
+
+   The Gnome Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The Gnome Library 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the Gnome Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301  USA.
+
+   Authors: Bastien Nocera <hadess hadess net>
+
+ */
+
+#include <geocode-location.h>
+
+static gpointer
+geocode_location_copy (gpointer boxed)
+{
+	GeocodeLocation *from, *to;
+
+	from = (GeocodeLocation *) boxed;
+	to = g_new (GeocodeLocation, 1);
+	to->longitude = from->longitude;
+	to->latitude = from->latitude;
+	to->timestamp = from->timestamp;
+	to->description = from->description;
+
+	return to;
+}
+
+static void
+geocode_location_free (gpointer boxed)
+{
+	GeocodeLocation *loc;
+
+	loc = (GeocodeLocation *) boxed;
+	g_free (loc->description);
+	g_free (loc);
+}
+
+G_DEFINE_BOXED_TYPE(GeocodeLocation, geocode_location, geocode_location_copy, geocode_location_free)
+
+GeocodeLocation *
+geocode_location_new (gdouble latitude,
+		      gdouble longitude)
+{
+	GeocodeLocation *ret;
+	GTimeVal tv;
+
+	ret = g_new0 (GeocodeLocation, 1);
+	ret->longitude = longitude;
+	ret->latitude = latitude;
+	g_get_current_time (&tv);
+	ret->timestamp = tv.tv_sec;
+
+	return ret;
+}
+
+GeocodeLocation *
+geocode_location_new_with_description (gdouble     latitude,
+				       gdouble     longitude,
+				       const char *description)
+{
+	GeocodeLocation *ret;
+
+	ret = geocode_location_new (latitude, longitude);
+	ret->description = g_strdup (description);
+
+	return ret;
+}
diff --git a/geocode-glib/geocode-location.h b/geocode-glib/geocode-location.h
new file mode 100644
index 0000000..7ffdff4
--- /dev/null
+++ b/geocode-glib/geocode-location.h
@@ -0,0 +1,50 @@
+/*
+   Copyright (C) 2012 Bastien Nocera
+
+   The Gnome Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The Gnome Library 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the Gnome Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+   Boston, MA 02110-1301  USA.
+
+   Authors: Bastien Nocera <hadess hadess net>
+
+ */
+
+#ifndef GEOCODE_LOCATION_H
+#define GEOCODE_LOCATION_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+typedef struct {
+	gdouble longitude;
+	gdouble latitude;
+	gint64  timestamp;
+	char   *description;
+} GeocodeLocation;
+
+#define GEOCODE_TYPE_LOCATION (geocode_location_get_type ())
+
+GType geocode_location_get_type (void) G_GNUC_CONST;
+
+GeocodeLocation *geocode_location_new (gdouble latitude,
+				       gdouble longitude);
+
+GeocodeLocation *geocode_location_new_with_description (gdouble     latitude,
+							gdouble     longitude,
+							const char *description);
+
+G_END_DECLS
+
+#endif /* GEOCODE_LOCATION_H */



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