+2008-12-13
+Guilhem Bonnefille <guilhem.bonnefille@gmail.com>:
+ * Add external tools framework
+ * Add OpenStreetMap and Google web tools
+
2008-12-07
Quy Tonthat <qtonthat@gmail.com>:
* Clicking on "vivisble" tick no longer makes the layer selected.
dem.c dem.h \
vikdemlayer.h vikdemlayer.c \
vikfilelist.c vikfilelist.h \
+ vikexttool.c vikexttool.h \
+ vikexttools.c vikexttools.h \
+ vikwebtool.c vikwebtool.h \
+ vikwebtoolcenter.c vikwebtoolcenter.h \
dems.c dems.h \
srtm_continent.c \
uibuilder.c uibuilder.h \
#include "globals.h"
#include "google.h"
#include "vikmapslayer.h"
+#include "vikexttools.h"
+#include "vikwebtoolcenter.h"
static int google_download ( MapCoord *src, const gchar *dest_fn );
maps_layer_register_type(_("Google Street Maps"), 7, &google_1);
maps_layer_register_type(_("Transparent Google Maps"), 10, &google_2);
maps_layer_register_type(_("Google Terrain Maps"), 16, &google_4);
+
+ // Webtools
+ VikWebtoolCenter *webtool = vik_webtool_center_new_with_members ( _("Google"), "http://maps.google.com/maps?f=q&hl=fr&geocode=&ie=UTF8&ll=%s,%s&z=%d&iwloc=addr" );
+ vik_ext_tools_register ( VIK_EXT_TOOL ( webtool ) );
+ g_object_unref ( webtool );
}
/* 1 << (x) is like a 2**(x) */
" <separator/>"
" </menu>"
" <menu action='Tools'>"
+ " <menu action='Exttools'/>"
" <menuitem action='Pan'/>"
" <menuitem action='Zoom'/>"
" <menuitem action='Ruler'/>"
#endif
#include <gtk/gtk.h>
+#include <glib/gi18n.h>
#ifdef HAVE_MATH_H
#include <math.h>
#endif
-
#include "viking.h"
#include "coords.h"
#include "vikcoord.h"
#include "mapcoord.h"
#include "vikmapslayer.h"
+#include "vikwebtoolcenter.h"
+#include "vikexttools.h"
#include "osm.h"
maps_layer_register_type("BlueMarble", 15, &bluemarble_type);
maps_layer_register_type("OpenAerialMap", 20, &openaerialmap_type);
+
+ // Webtools
+ VikWebtoolCenter *webtool = NULL;
+ webtool = vik_webtool_center_new_with_members ( _("OSM (view)"), "http://openstreetmap.org/?lat=%s&lon=%s&zoom=%d&layers=B000FTF" );
+ vik_ext_tools_register ( VIK_EXT_TOOL ( webtool ) );
+ g_object_unref ( webtool );
+
+ webtool = vik_webtool_center_new_with_members ( _("OSM (edit)"), "http://www.openstreetmap.org/edit?lat=%s&lon=%s&zoom=%d" );
+ vik_ext_tools_register ( VIK_EXT_TOOL ( webtool ) );
+ g_object_unref ( webtool );
+
+ webtool = vik_webtool_center_new_with_members ( _("OSM (render)"), "http://www.informationfreeway.org/?lat=%s&lon=%s&zoom=%d&layers=B0000F000F" );
+ vik_ext_tools_register ( VIK_EXT_TOOL ( webtool ) );
+ g_object_unref ( webtool );
}
/* 1 << (x) is like a 2**(x) */
--- /dev/null
+/*
+ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
+ *
+ * Copyright (C) 2008, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "vikexttool.h"
+
+#include <string.h>
+
+#include <glib/gi18n.h>
+
+static void ext_tool_class_init ( VikExtToolClass *klass );
+static void ext_tool_init ( VikExtTool *vlp );
+
+static GObjectClass *parent_class;
+
+static void ext_tool_finalize ( GObject *gob );
+static gchar *ext_tool_get_label ( VikExtTool *vw );
+
+typedef struct _VikExtToolPrivate VikExtToolPrivate;
+
+struct _VikExtToolPrivate
+{
+ gint id;
+ gchar *label;
+};
+
+#define EXT_TOOL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
+ VIK_EXT_TOOL_TYPE, \
+ VikExtToolPrivate))
+
+GType vik_ext_tool_get_type()
+{
+ static GType w_type = 0;
+
+ if (!w_type)
+ {
+ static const GTypeInfo w_info =
+ {
+ sizeof (VikExtToolClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc) ext_tool_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (VikExtTool),
+ 0,
+ (GInstanceInitFunc) ext_tool_init,
+ };
+ w_type = g_type_register_static ( G_TYPE_OBJECT, "VikExtTool", &w_info, G_TYPE_FLAG_ABSTRACT );
+ }
+
+ return w_type;
+}
+
+enum
+{
+ PROP_0,
+
+ PROP_ID,
+ PROP_LABEL,
+};
+
+static void
+ext_tool_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ VikExtTool *self = VIK_EXT_TOOL (object);
+ VikExtToolPrivate *priv = EXT_TOOL_GET_PRIVATE (self);
+
+ switch (property_id)
+ {
+ case PROP_ID:
+ priv->id = g_value_get_uint (value);
+ g_debug ("VikExtTool.id: %d", priv->id);
+ break;
+
+ case PROP_LABEL:
+ g_free (priv->label);
+ priv->label = g_value_dup_string (value);
+ g_debug ("VikExtTool.label: %s", priv->label);
+ break;
+
+ default:
+ /* We don't have any other property... */
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+ext_tool_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ VikExtTool *self = VIK_EXT_TOOL (object);
+ VikExtToolPrivate *priv = EXT_TOOL_GET_PRIVATE (self);
+
+ switch (property_id)
+ {
+ case PROP_ID:
+ g_value_set_uint (value, priv->id);
+ break;
+
+ case PROP_LABEL:
+ g_value_set_string (value, priv->label);
+ break;
+
+ default:
+ /* We don't have any other property... */
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void ext_tool_class_init ( VikExtToolClass *klass )
+{
+ GObjectClass *gobject_class;
+ GParamSpec *pspec;
+
+ gobject_class = G_OBJECT_CLASS (klass);
+ gobject_class->finalize = ext_tool_finalize;
+ gobject_class->set_property = ext_tool_set_property;
+ gobject_class->get_property = ext_tool_get_property;
+
+ pspec = g_param_spec_string ("label",
+ "Label",
+ "Set the label",
+ "<no-set>" /* default value */,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
+ g_object_class_install_property (gobject_class,
+ PROP_LABEL,
+ pspec);
+
+ pspec = g_param_spec_uint ("id",
+ "Id of the tool",
+ "Set the id",
+ 0 /* minimum value */,
+ G_MAXUINT16 /* maximum value */,
+ 0 /* default value */,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
+ g_object_class_install_property (gobject_class,
+ PROP_ID,
+ pspec);
+
+ klass->get_label = ext_tool_get_label;
+
+ parent_class = g_type_class_peek_parent (klass);
+
+ g_type_class_add_private (klass, sizeof (VikExtToolPrivate));
+}
+
+VikExtTool *vik_ext_tool_new ()
+{
+ return VIK_EXT_TOOL ( g_object_new ( VIK_EXT_TOOL_TYPE, NULL ) );
+}
+
+static void ext_tool_init ( VikExtTool *self )
+{
+ VikExtToolPrivate *priv = EXT_TOOL_GET_PRIVATE (self);
+ priv->label = NULL;
+}
+
+static void ext_tool_finalize ( GObject *gob )
+{
+ VikExtToolPrivate *priv = EXT_TOOL_GET_PRIVATE ( gob );
+ g_free ( priv->label ); priv->label = NULL;
+ G_OBJECT_CLASS(parent_class)->finalize(gob);
+}
+
+static gchar *ext_tool_get_label ( VikExtTool *self )
+{
+ VikExtToolPrivate *priv = NULL;
+ priv = EXT_TOOL_GET_PRIVATE (self);
+ return g_strdup ( priv->label );
+}
+
+gchar *vik_ext_tool_get_label ( VikExtTool *w )
+{
+ return VIK_EXT_TOOL_GET_CLASS( w )->get_label( w );
+}
+
+void vik_ext_tool_open ( VikExtTool *self, VikWindow *vwindow )
+{
+ VIK_EXT_TOOL_GET_CLASS( self )->open( self, vwindow );
+}
--- /dev/null
+/*
+ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
+ *
+ * Copyright (C) 2008, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifndef _VIKING_EXT_TOOL_H
+#define _VIKING_EXT_TOOL_H
+
+#include <glib.h>
+
+#include "vikwindow.h"
+
+#define VIK_EXT_TOOL_TYPE (vik_ext_tool_get_type ())
+#define VIK_EXT_TOOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIK_EXT_TOOL_TYPE, VikExtTool))
+#define VIK_EXT_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VIK_EXT_TOOL_TYPE, VikExtToolClass))
+#define IS_VIK_EXT_TOOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIK_EXT_TOOL_TYPE))
+#define IS_VIK_EXT_TOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VIK_EXT_TOOL_TYPE))
+#define VIK_EXT_TOOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VIK_EXT_TOOL_TYPE, VikExtToolClass))
+
+
+typedef struct _VikExtTool VikExtTool;
+typedef struct _VikExtToolClass VikExtToolClass;
+
+struct _VikExtToolClass
+{
+ GObjectClass object_class;
+ gchar *(* get_label) (VikExtTool *self);
+ void (* open) (VikExtTool *self, VikWindow *vwindow);
+};
+
+GType vik_ext_tool_get_type ();
+
+struct _VikExtTool {
+ GObject obj;
+};
+
+gchar *vik_ext_tool_get_label ( VikExtTool *self );
+void vik_ext_tool_open ( VikExtTool *self, VikWindow *vwindow );
+
+#endif
--- /dev/null
+/*
+ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
+ *
+ * Copyright (C) 2008, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "vikexttools.h"
+
+#include <string.h>
+
+#include <glib/gi18n.h>
+
+#define VIK_TOOL_DATA_KEY "vik-tool-data"
+
+static GList *ext_tools_list = NULL;
+
+void vik_ext_tools_register ( VikExtTool *tool )
+{
+ IS_VIK_EXT_TOOL( tool );
+
+ ext_tools_list = g_list_append ( ext_tools_list, g_object_ref ( tool ) );
+}
+
+void vik_ext_tools_unregister_all ()
+{
+ g_list_foreach ( ext_tools_list, (GFunc) g_object_unref, NULL );
+}
+
+static void ext_tools_open_cb ( GtkWidget *widget, VikWindow *vwindow )
+{
+ gpointer ptr = g_object_get_data ( G_OBJECT(widget), VIK_TOOL_DATA_KEY );
+ VikExtTool *ext_tool = VIK_EXT_TOOL ( ptr );
+ vik_ext_tool_open ( ext_tool, vwindow );
+}
+
+void vik_ext_tools_add_menu_items_to_menu ( VikWindow *vwindow, GtkMenu *menu )
+{
+ GList *iter;
+ for (iter = ext_tools_list; iter; iter = iter->next)
+ {
+ VikExtTool *ext_tool = NULL;
+ gchar *label = NULL;
+ ext_tool = VIK_EXT_TOOL ( iter->data );
+ label = vik_ext_tool_get_label ( ext_tool );
+ if ( label )
+ {
+ GtkWidget *item = NULL;
+ item = gtk_menu_item_new_with_label ( _(label) );
+ g_free ( label ); label = NULL;
+ // Store tool's ref into the menu entry
+ g_object_set_data ( G_OBJECT(item), VIK_TOOL_DATA_KEY, ext_tool );
+ g_signal_connect ( G_OBJECT(item), "activate", G_CALLBACK(ext_tools_open_cb), vwindow );
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show ( item );
+ }
+ }
+}
+
+void vik_ext_tools_add_menu_items ( VikWindow *vwindow, GtkUIManager *uim )
+{
+ GtkWidget *widget = NULL;
+ GtkMenu *menu = NULL;
+ widget = gtk_ui_manager_get_widget (uim, "/MainMenu/Tools/Exttools");
+ menu = GTK_MENU ( gtk_menu_item_get_submenu ( GTK_MENU_ITEM ( widget ) ) );
+ vik_ext_tools_add_menu_items_to_menu ( vwindow, menu );
+ gtk_widget_show ( widget );
+}
--- /dev/null
+/*
+ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
+ *
+ * Copyright (C) 2008, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifndef _VIKING_EXT_TOOLS_H
+#define _VIKING_EXT_TOOLS_H
+
+#include <gtk/gtk.h>
+
+#include "vikwindow.h"
+
+#include "vikexttool.h"
+
+void vik_ext_tools_register ( VikExtTool *tool );
+void vik_ext_tools_unregister_all ();
+void vik_ext_tools_add_menu_items ( VikWindow *vwindow, GtkUIManager *uim );
+
+#endif
--- /dev/null
+/*
+ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
+ *
+ * Copyright (C) 2008, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "vikwebtool.h"
+
+#include <string.h>
+
+#include <glib/gi18n.h>
+
+#include "util.h"
+
+static void webtool_class_init ( VikWebtoolClass *klass );
+static void webtool_init ( VikWebtool *vwd );
+
+static GObjectClass *parent_class;
+
+static void webtool_finalize ( GObject *gob );
+
+static void webtool_open ( VikExtTool *self, VikWindow *vwindow );
+
+GType vik_webtool_get_type()
+{
+ static GType w_type = 0;
+
+ if (!w_type)
+ {
+ static const GTypeInfo w_info =
+ {
+ sizeof (VikWebtoolClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc) webtool_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (VikWebtool),
+ 0,
+ (GInstanceInitFunc) webtool_init,
+ };
+ w_type = g_type_register_static ( VIK_EXT_TOOL_TYPE, "VikWebtool", &w_info, G_TYPE_FLAG_ABSTRACT );
+ }
+
+ return w_type;
+}
+
+static void webtool_class_init ( VikWebtoolClass *klass )
+{
+ GObjectClass *object_class;
+ VikExtToolClass *ext_tool_class;
+
+ object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = webtool_finalize;
+
+ parent_class = g_type_class_peek_parent (klass);
+
+ ext_tool_class = VIK_EXT_TOOL_CLASS ( klass );
+ ext_tool_class->open = webtool_open;
+}
+
+VikWebtool *vik_webtool_new ()
+{
+ return VIK_WEBTOOL ( g_object_new ( VIK_WEBTOOL_TYPE, NULL ) );
+}
+
+static void webtool_init ( VikWebtool *vlp )
+{
+}
+
+static void webtool_finalize ( GObject *gob )
+{
+ // VikWebtool *w = VIK_WEBTOOL ( gob );
+ G_OBJECT_CLASS(parent_class)->finalize(gob);
+}
+
+static void webtool_open ( VikExtTool *self, VikWindow *vwindow )
+{
+ VikWebtool *vwd = VIK_WEBTOOL ( self );
+ gchar *url = vik_webtool_get_url ( vwd, vwindow );
+ open_url ( NULL, url );
+ g_free ( url );
+}
+
+gchar *vik_webtool_get_url ( VikWebtool *self, VikWindow *vwindow )
+{
+ return VIK_WEBTOOL_GET_CLASS( self )->get_url( self, vwindow );
+}
--- /dev/null
+/*
+ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
+ *
+ * Copyright (C) 2008, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifndef _VIKING_WEBTOOL_H
+#define _VIKING_WEBTOOL_H
+
+#include <glib.h>
+
+#include "vikwindow.h"
+
+#include "vikexttool.h"
+
+#define VIK_WEBTOOL_TYPE (vik_webtool_get_type ())
+#define VIK_WEBTOOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIK_WEBTOOL_TYPE, VikWebtool))
+#define VIK_WEBTOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VIK_WEBTOOL_TYPE, VikWebtoolClass))
+#define IS_VIK_WEBTOOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIK_WEBTOOL_TYPE))
+#define IS_VIK_WEBTOOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VIK_WEBTOOL_TYPE))
+#define VIK_WEBTOOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VIK_WEBTOOL_TYPE, VikWebtoolClass))
+
+
+typedef struct _VikWebtool VikWebtool;
+typedef struct _VikWebtoolClass VikWebtoolClass;
+
+struct _VikWebtoolClass
+{
+ VikExtToolClass object_class;
+ gchar *(* get_url) (VikWebtool *self, VikWindow *vwindow);
+};
+
+GType vik_webtool_get_type ();
+
+struct _VikWebtool {
+ VikExtTool obj;
+};
+
+gchar *vik_webtool_get_url ( VikWebtool *self, VikWindow *vwindow );
+
+#endif
--- /dev/null
+/*
+ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
+ *
+ * Copyright (C) 2008, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "vikwebtoolcenter.h"
+
+#include <string.h>
+
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include "util.h"
+#include "globals.h"
+
+static void webtool_center_class_init ( VikWebtoolCenterClass *klass );
+static void webtool_center_init ( VikWebtoolCenter *vwd );
+
+static GObjectClass *parent_class;
+
+static void webtool_center_finalize ( GObject *gob );
+
+static guint8 webtool_center_mpp_to_zoom ( VikWebtool *self, gdouble mpp );
+static gchar *webtool_center_get_url ( VikWebtool *vw, VikWindow *vwindow );
+
+typedef struct _VikWebtoolCenterPrivate VikWebtoolCenterPrivate;
+
+struct _VikWebtoolCenterPrivate
+{
+ gchar *url;
+};
+
+#define WEBTOOL_CENTER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \
+ VIK_WEBTOOL_CENTER_TYPE, \
+ VikWebtoolCenterPrivate))
+
+GType vik_webtool_center_get_type()
+{
+ static GType w_type = 0;
+
+ if (!w_type)
+ {
+ static const GTypeInfo w_info =
+ {
+ sizeof (VikWebtoolCenterClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc) webtool_center_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof (VikWebtoolCenter),
+ 0,
+ (GInstanceInitFunc) webtool_center_init,
+ };
+ w_type = g_type_register_static ( VIK_WEBTOOL_TYPE, "VikWebtoolCenter", &w_info, 0 );
+ }
+
+ return w_type;
+}
+
+enum
+{
+ PROP_0,
+
+ PROP_URL,
+};
+
+static void
+webtool_center_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ VikWebtoolCenter *self = VIK_WEBTOOL_CENTER (object);
+ VikWebtoolCenterPrivate *priv = WEBTOOL_CENTER_GET_PRIVATE (self);
+
+ switch (property_id)
+ {
+ case PROP_URL:
+ g_free (priv->url);
+ priv->url = g_value_dup_string (value);
+ g_debug ("VikWebtoolCenter.url: %s", priv->url);
+ break;
+
+ default:
+ /* We don't have any other property... */
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+webtool_center_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ VikWebtoolCenter *self = VIK_WEBTOOL_CENTER (object);
+ VikWebtoolCenterPrivate *priv = WEBTOOL_CENTER_GET_PRIVATE (self);
+
+ switch (property_id)
+ {
+ case PROP_URL:
+ g_value_set_string (value, priv->url);
+ break;
+
+ default:
+ /* We don't have any other property... */
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void webtool_center_class_init ( VikWebtoolCenterClass *klass )
+{
+ GObjectClass *gobject_class;
+ VikWebtoolClass *base_class;
+ GParamSpec *pspec;
+
+ gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->finalize = webtool_center_finalize;
+ gobject_class->set_property = webtool_center_set_property;
+ gobject_class->get_property = webtool_center_get_property;
+
+ pspec = g_param_spec_string ("url",
+ "Template Url",
+ "Set the template url",
+ VIKING_URL /* default value */,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
+ g_object_class_install_property (gobject_class,
+ PROP_URL,
+ pspec);
+
+ parent_class = g_type_class_peek_parent (klass);
+
+ base_class = VIK_WEBTOOL_CLASS ( klass );
+ base_class->get_url = webtool_center_get_url;
+
+ klass->mpp_to_zoom = webtool_center_mpp_to_zoom;
+
+ g_type_class_add_private (klass, sizeof (VikWebtoolCenterPrivate));
+}
+
+VikWebtoolCenter *vik_webtool_center_new ()
+{
+ return VIK_WEBTOOL_CENTER ( g_object_new ( VIK_WEBTOOL_CENTER_TYPE, NULL ) );
+}
+
+VikWebtoolCenter *vik_webtool_center_new_with_members ( const gchar *label, const gchar *url )
+{
+ VikWebtoolCenter *result = VIK_WEBTOOL_CENTER ( g_object_new ( VIK_WEBTOOL_CENTER_TYPE,
+ "label", label,
+ "url", url,
+ NULL ) );
+
+ return result;
+}
+
+static void webtool_center_init ( VikWebtoolCenter *self )
+{
+ VikWebtoolCenterPrivate *priv = WEBTOOL_CENTER_GET_PRIVATE (self);
+ priv->url = NULL;
+}
+
+static void webtool_center_finalize ( GObject *gob )
+{
+ VikWebtoolCenterPrivate *priv = WEBTOOL_CENTER_GET_PRIVATE ( gob );
+ g_free ( priv->url ); priv->url = NULL;
+ G_OBJECT_CLASS(parent_class)->finalize(gob);
+}
+
+/* 1 << (x) is like a 2**(x) */
+#define GZ(x) (1<<(x))
+
+static const gdouble scale_mpps[] = { GZ(0), GZ(1), GZ(2), GZ(3), GZ(4), GZ(5), GZ(6), GZ(7), GZ(8), GZ(9),
+ GZ(10), GZ(11), GZ(12), GZ(13), GZ(14), GZ(15), GZ(16), GZ(17) };
+
+static const gint num_scales = (sizeof(scale_mpps) / sizeof(scale_mpps[0]));
+
+#define ERROR_MARGIN 0.01
+static guint8 webtool_center_mpp_to_zoom ( VikWebtool *self, gdouble mpp ) {
+ gint i;
+ for ( i = 0; i < num_scales; i++ ) {
+ if ( ABS(scale_mpps[i] - mpp) < ERROR_MARGIN ) {
+ g_debug ( "webtool_center_mpp_to_zoom: %f -> %d", mpp, i );
+ return i;
+ }
+ }
+ return 255;
+}
+
+static gchar *webtool_center_get_url ( VikWebtool *self, VikWindow *vwindow )
+{
+ VikWebtoolCenterPrivate *priv = NULL;
+ VikViewport *viewport = NULL;
+ const VikCoord *coord = NULL;
+ guint8 zoom = 0;
+ struct LatLon ll;
+ gchar strlat[G_ASCII_DTOSTR_BUF_SIZE], strlon[G_ASCII_DTOSTR_BUF_SIZE];
+
+ priv = WEBTOOL_CENTER_GET_PRIVATE (self);
+ viewport = vik_window_viewport ( vwindow );
+
+ // Coords
+ coord = vik_viewport_get_center ( viewport );
+ vik_coord_to_latlon ( coord, &ll );
+
+ // zoom
+ g_assert ( vik_viewport_get_xmpp ( viewport ) == vik_viewport_get_ympp ( viewport ) );
+ zoom = vik_webtool_center_mpp_to_zoom ( self, vik_viewport_get_zoom ( viewport ) );
+
+ // Cannot simply use g_strdup_printf and gdouble due to locale.
+ // As we compute an URL, we have to think in C locale.
+ g_ascii_dtostr (strlat, G_ASCII_DTOSTR_BUF_SIZE, ll.lat);
+ g_ascii_dtostr (strlon, G_ASCII_DTOSTR_BUF_SIZE, ll.lon);
+
+ return g_strdup_printf ( priv->url, strlat, strlon, 17-zoom );
+}
+
+guint8 vik_webtool_center_mpp_to_zoom (VikWebtool *self, gdouble mpp)
+{
+ return VIK_WEBTOOL_CENTER_GET_CLASS( self )->mpp_to_zoom( self, mpp );
+}
--- /dev/null
+/*
+ * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
+ *
+ * Copyright (C) 2008, Guilhem Bonnefille <guilhem.bonnefille@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+#ifndef _VIKING_WEBTOOL_CENTER_H
+#define _VIKING_WEBTOOL_CENTER_H
+
+#include <glib.h>
+
+#include "vikwebtool.h"
+
+#define VIK_WEBTOOL_CENTER_TYPE (vik_webtool_center_get_type ())
+#define VIK_WEBTOOL_CENTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), VIK_WEBTOOL_CENTER_TYPE, VikWebtoolCenter))
+#define VIK_WEBTOOL_CENTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), VIK_WEBTOOL_CENTER_TYPE, VikWebtoolCenterClass))
+#define IS_VIK_WEBTOOL_CENTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), VIK_WEBTOOL_CENTER_TYPE))
+#define IS_VIK_WEBTOOL_CENTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), VIK_WEBTOOL_CENTER_TYPE))
+#define VIK_WEBTOOL_CENTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), VIK_WEBTOOL_CENTER_TYPE, VikWebtoolCenterClass))
+
+
+typedef struct _VikWebtoolCenter VikWebtoolCenter;
+typedef struct _VikWebtoolCenterClass VikWebtoolCenterClass;
+
+struct _VikWebtoolCenterClass
+{
+ VikWebtoolClass object_class;
+ guint8 (* mpp_to_zoom) (VikWebtool *self, gdouble mpp);
+};
+
+GType vik_webtool_center_get_type ();
+
+struct _VikWebtoolCenter {
+ VikWebtool obj;
+};
+
+guint8 vik_webtool_center_mpp_to_zoom (VikWebtool *self, gdouble mpp);
+
+VikWebtoolCenter* vik_webtool_center_new ( );
+VikWebtoolCenter* vik_webtool_center_new_with_members ( const gchar *label, const gchar *url );
+
+#endif
#include "print.h"
#include "preferences.h"
#include "icons/icons.h"
+#include "vikexttools.h"
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
gtk_toolbar_set_icon_size(GTK_TOOLBAR(gtk_ui_manager_get_widget (vw->uim, "/MainToolbar")), GTK_ICON_SIZE_SMALL_TOOLBAR);
gtk_toolbar_set_style (GTK_TOOLBAR(gtk_ui_manager_get_widget (vw->uim, "/MainToolbar")), GTK_TOOLBAR_ICONS);
+ vik_ext_tools_add_menu_items ( vw, vw->uim );
g_signal_connect (G_OBJECT (vw), "delete_event", G_CALLBACK (delete_event), NULL);
{ "SetPan", NULL, N_("_Pan"), 0, 0, 0 },
{ "Layers", NULL, N_("_Layers"), 0, 0, 0 },
{ "Tools", NULL, N_("_Tools"), 0, 0, 0 },
+ { "Exttools", NULL, N_("_Webtools"), 0, 0, 0 },
{ "Help", NULL, N_("_Help"), 0, 0, 0 },
{ "New", GTK_STOCK_NEW, N_("_New"), "<control>N", N_("New file"), (GCallback)newwindow_cb },