[emerillon] Add CopyLink plugin



commit 87b4348ef8762a3032e0aa0923e3a98c4eaaa1b1
Author: Pierre-Luc Beaudoin <pierre-luc beaudoin novopia com>
Date:   Fri Oct 9 10:34:22 2009 -0400

    Add CopyLink plugin
    
    This plugins adds a "Edit/Copy link to" item to
    copy a web link to services such as
    Google Map, OpenStreetMap.org or Yahoo Maps.

 data/emerillon-ui.xml                           |    2 +
 plugins/Makefile.am                             |   14 ++
 plugins/copy-link/copy-link.c                   |  256 +++++++++++++++++++++++
 plugins/copy-link/copy-link.emerillon-plugin.in |    8 +
 plugins/copy-link/copy-link.h                   |   58 +++++
 5 files changed, 338 insertions(+), 0 deletions(-)
---
diff --git a/data/emerillon-ui.xml b/data/emerillon-ui.xml
index b224988..94f5a72 100644
--- a/data/emerillon-ui.xml
+++ b/data/emerillon-ui.xml
@@ -9,6 +9,8 @@
       <menuitem action="MapQuit"/>
     </menu>
     <menu action="Edit">
+      <placeholder name="EditPluginMenu" />
+      <separator/>
       <menuitem action="EditPreferences"/>
     </menu>
     <menu action="View">
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 53cc361..0b2a8ca 100755
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -33,6 +33,20 @@ placemarks_libplacemarks_la_LIBADD = \
 	$(EMERILLON_LIBS) \
 	$(top_builddir)/cut-paste/libempathycell.la
 
+# CopyLink plugin
+plugins_LTLIBRARIES += \
+	copy-link/libcopy-link.la
+
+plugins_in_files += \
+	copy-link/copy-link.emerillon-plugin.in
+
+copy_link_libcopy_link_la_SOURCES = \
+	copy-link/copy-link.h  \
+	copy-link/copy-link.c
+
+copy_link_libcopy_link_la_LIBADD = \
+	$(EMERILLON_LIBS)
+
 # Search plugin
 if ENABLE_SEARCH
 plugins_LTLIBRARIES += \
diff --git a/plugins/copy-link/copy-link.c b/plugins/copy-link/copy-link.c
new file mode 100644
index 0000000..19b9950
--- /dev/null
+++ b/plugins/copy-link/copy-link.c
@@ -0,0 +1,256 @@
+/*
+ * Copyright (C) 2009 Novopia Inc.
+ *
+ * This 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.
+ *
+ * This 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 this 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "copy-link.h"
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include "emerillon/emerillon.h"
+
+G_DEFINE_TYPE (CopyLinkPlugin, copy_link_plugin, ETHOS_TYPE_PLUGIN)
+
+#define OSM_ID "copy_link_osm"
+#define GOOGLE_ID "copy_link_google"
+#define YAHOO_ID "copy_link_yahoo"
+
+struct _CopyLinkPluginPrivate
+{
+  EmerillonWindow *window;
+  ChamplainView *map_view;
+
+  GtkActionGroup *action_group;
+  guint ui_id;
+  guint osm_ui_id;
+  guint google_ui_id;
+  guint yahoo_ui_id;
+};
+
+static void
+copy_cb (GtkAction *action,
+         CopyLinkPlugin *plugin)
+{
+  const gchar *id;
+  gdouble lat, lon;
+  gint zoom;
+  gchar *url = NULL;
+  GtkClipboard *clipboard;
+  CopyLinkPluginPrivate *priv;
+
+  priv = COPY_LINK_PLUGIN (plugin)->priv;
+  g_object_get (priv->map_view,
+                "latitude", &lat,
+                "longitude", &lon,
+                "zoom-level", &zoom,
+                NULL);
+
+  id = gtk_action_get_name (action);
+
+  if (strcmp (id, OSM_ID) == 0)
+    {
+      url = g_strdup_printf ("http://www.openstreetmap.org/?lat=%f&lon=%f&zoom=%d";, lat, lon, zoom);
+    }
+  else if (strcmp (id, GOOGLE_ID) == 0)
+    {
+      url = g_strdup_printf ("http://maps.google.com?ll=%f,%f&z=%d";, lat, lon, zoom);
+    }
+  else if (strcmp (id, YAHOO_ID) == 0)
+    {
+      zoom += 1;
+      if (zoom < 2)
+        zoom = 2;
+      url = g_strdup_printf ("http://maps.yahoo.com/#mvt=m&lat=%f&lon=%f&zoom=%d";, lat, lon, zoom);
+    }
+
+  clipboard = gtk_clipboard_get (GDK_SELECTION_CLIPBOARD);
+  gtk_clipboard_set_text (clipboard, url, -1);
+
+  g_free (url);
+}
+
+static guint
+append_menu_item (CopyLinkPlugin *plugin,
+                  const gchar *id,
+                  const gchar *name)
+{
+  CopyLinkPluginPrivate *priv;
+  GtkUIManager *manager;
+  GError *error = NULL;
+  gchar * item_ui_definition;
+  GtkActionEntry actions[] = {
+    { id,
+      NULL,
+      name,
+      NULL,
+      N_("Copy to clipboard the link to this web service"),
+      G_CALLBACK (copy_cb) }
+  };
+  guint ui_id;
+
+  priv = COPY_LINK_PLUGIN (plugin)->priv;
+  manager = emerillon_window_get_ui_manager (priv->window);
+
+  item_ui_definition = g_strconcat (
+    "<ui>"
+      "<menubar name=\"MainMenu\">"
+          "<menu name=\"Edit\" action=\"Edit\">"
+            "<placeholder name=\"EditPluginMenu\">"
+              "<menu name=\"CopyLinkMenu\" action=\"CopyLinkAction\">"
+                "<menuitem action=\"", id, "\"/>"
+              "</menu>"
+            "</placeholder>"
+          "</menu>"
+      "</menubar>"
+    "</ui>", NULL);
+
+
+  gtk_action_group_add_actions (priv->action_group,
+                                actions,
+                                G_N_ELEMENTS (actions),
+                                plugin);
+
+  ui_id = gtk_ui_manager_add_ui_from_string (manager,
+                                             item_ui_definition,
+                                             -1, &error);
+  if (ui_id == 0)
+    {
+      g_warning ("Error adding UI %s", error->message);
+      g_error_free (error);
+    }
+
+  g_free (item_ui_definition);
+  return ui_id;
+}
+
+static void
+load_menus (CopyLinkPlugin *plugin)
+{
+  CopyLinkPluginPrivate *priv;
+
+  priv = COPY_LINK_PLUGIN (plugin)->priv;
+
+  priv->osm_ui_id = append_menu_item (plugin, OSM_ID, _("OpenStreetMap"));
+  priv->yahoo_ui_id = append_menu_item (plugin, YAHOO_ID, _("Yahoo! Maps"));
+  priv->google_ui_id = append_menu_item (plugin, GOOGLE_ID, _("Google Maps"));
+}
+
+static const gchar * const ui_definition =
+    "<ui>"
+      "<menubar name=\"MainMenu\">"
+          "<menu name=\"Edit\" action=\"Edit\">"
+            "<placeholder name=\"EditPluginMenu\">"
+              "<menu name=\"CopyLinkMenu\" action=\"CopyLinkAction\" />"
+            "</placeholder>"
+          "</menu>"
+      "</menubar>"
+    "</ui>";
+
+static const GtkActionEntry action_entries[] =
+{
+  { "CopyLinkAction",   NULL, N_("_Copy link to") },
+
+};
+
+static void
+activated (EthosPlugin *plugin)
+{
+  CopyLinkPluginPrivate *priv;
+  GtkUIManager *manager;
+  GError *error = NULL;
+
+  priv = COPY_LINK_PLUGIN (plugin)->priv;
+  priv->window = EMERILLON_WINDOW (emerillon_window_dup_default ());
+  priv->map_view = emerillon_window_get_map_view (priv->window);
+
+  manager = emerillon_window_get_ui_manager (priv->window);
+
+  priv->action_group = gtk_action_group_new ("CopyLinkActions");
+  gtk_action_group_set_translation_domain (priv->action_group,
+                                           GETTEXT_PACKAGE);
+  gtk_action_group_add_actions (priv->action_group,
+                                action_entries,
+                                G_N_ELEMENTS (action_entries),
+                                plugin);
+  gtk_ui_manager_insert_action_group (manager,
+                                      priv->action_group,
+                                      -1);
+
+  priv->ui_id = gtk_ui_manager_add_ui_from_string (manager,
+                                                   ui_definition,
+                                                   -1, &error);
+  if (priv->ui_id == 0)
+    {
+      g_warning ("Error adding UI %s", error->message);
+      g_error_free (error);
+    }
+
+  load_menus (COPY_LINK_PLUGIN (plugin));
+}
+
+static void
+deactivated (EthosPlugin *plugin)
+{
+  GtkUIManager *manager;
+  CopyLinkPluginPrivate *priv;
+
+  priv = COPY_LINK_PLUGIN (plugin)->priv;
+  manager = emerillon_window_get_ui_manager (priv->window);
+
+  gtk_ui_manager_remove_ui (manager, priv->osm_ui_id);
+  gtk_ui_manager_remove_ui (manager, priv->google_ui_id);
+  gtk_ui_manager_remove_ui (manager, priv->yahoo_ui_id);
+
+  gtk_ui_manager_remove_ui (manager, priv->ui_id);
+}
+
+static void
+copy_link_plugin_class_init (CopyLinkPluginClass *klass)
+{
+  EthosPluginClass *plugin_class;
+
+  g_type_class_add_private (klass, sizeof (CopyLinkPluginPrivate));
+
+  plugin_class = ETHOS_PLUGIN_CLASS (klass);
+  plugin_class->activated = activated;
+  plugin_class->deactivated = deactivated;
+}
+
+static void
+copy_link_plugin_init (CopyLinkPlugin *plugin)
+{
+  plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE (plugin,
+                                              COPY_LINK_TYPE_PLUGIN,
+                                              CopyLinkPluginPrivate);
+}
+
+EthosPlugin*
+copy_link_plugin_new (void)
+{
+  return g_object_new (COPY_LINK_TYPE_PLUGIN, NULL);
+}
+
+G_MODULE_EXPORT EthosPlugin*
+ethos_plugin_register (void)
+{
+  return copy_link_plugin_new ();
+}
diff --git a/plugins/copy-link/copy-link.emerillon-plugin.in b/plugins/copy-link/copy-link.emerillon-plugin.in
new file mode 100644
index 0000000..04806b6
--- /dev/null
+++ b/plugins/copy-link/copy-link.emerillon-plugin.in
@@ -0,0 +1,8 @@
+[Emerillon Plugin]
+_Name=Copy link to Web
+Module=copy-link
+_Description=Provides a link for current view to major online maps
+IAge=1
+Authors=Pierre-Luc Beaudoin <pierre-luc beaudoin novopia com>
+Copyright=Copyright © 2009 Novopia Inc.
+
diff --git a/plugins/copy-link/copy-link.h b/plugins/copy-link/copy-link.h
new file mode 100644
index 0000000..35eaba3
--- /dev/null
+++ b/plugins/copy-link/copy-link.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2009 Novopia Inc.
+ *
+ * This 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.
+ *
+ * This 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 this 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.
+ */
+
+#ifndef __COPY_LINK_PLUGIN_H__
+#define __COPY_LINK_PLUGIN_H__
+
+#include <glib-object.h>
+#include <ethos/ethos.h>
+#include <ethos/ethos-ui.h>
+
+G_BEGIN_DECLS
+
+#define COPY_LINK_TYPE_PLUGIN            (copy_link_plugin_get_type())
+#define COPY_LINK_PLUGIN(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), COPY_LINK_TYPE_PLUGIN, CopyLinkPlugin))
+#define COPY_LINK_PLUGIN_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass),  COPY_LINK_TYPE_PLUGIN, CopyLinkPluginClass))
+#define COPY_LINK_IS_PLUGIN(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COPY_LINK_TYPE_PLUGIN))
+#define COPY_LINK_IS_PLUGIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),  COPY_LINK_TYPE_PLUGIN))
+#define COPY_LINK_PLUGIN_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj),  COPY_LINK_TYPE_PLUGIN, CopyLinkPluginClass))
+
+typedef struct _CopyLinkPlugin        CopyLinkPlugin;
+typedef struct _CopyLinkPluginClass   CopyLinkPluginClass;
+typedef struct _CopyLinkPluginPrivate CopyLinkPluginPrivate;
+
+struct _CopyLinkPlugin
+{
+  EthosPlugin parent;
+
+  /*< private >*/
+  CopyLinkPluginPrivate *priv;
+};
+
+struct _CopyLinkPluginClass
+{
+  EthosPluginClass parent_class;
+};
+
+GType        copy_link_plugin_get_type (void);
+EthosPlugin* copy_link_plugin_new      (void);
+
+G_END_DECLS
+
+#endif /* __COPY_LINK_PLUGIN_H__ */



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