[emerillon-plugins] Add image-export plugin
- From: Łukasz Jernaś <ljernas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [emerillon-plugins] Add image-export plugin
- Date: Tue, 1 Jun 2010 15:31:27 +0000 (UTC)
commit 1b1e42f88f1149cbc489ec4fbd983f70df300553
Author: Simon Wenner <simon wenner ch>
Date: Sun Apr 25 21:57:08 2010 +0200
Add image-export plugin
This Plugin allows you to save the currently displayed map as a PNG image or attach it to an email.
configure.ac | 29 +++-
plugins/image-export/Makefile.am | 57 ++++++
.../image-export/image-export.emerillon-plugin.in | 7 +
plugins/image-export/image-export.vala | 198 ++++++++++++++++++++
4 files changed, 288 insertions(+), 3 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 3a132b0..51507dc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -59,9 +59,9 @@ AC_SUBST(EMERILLON_CFLAGS)
AC_MSG_CHECKING([which plugins to build])
-ALL_PLUGINS="bixi sample-vala"
-USEFUL_PLUGINS="bixi"
-DEFAULT_PLUGINS="bixi"
+ALL_PLUGINS="bixi image-export sample-vala"
+USEFUL_PLUGINS="bixi image-export"
+DEFAULT_PLUGINS="bixi image-export"
PYTHON_ALL_PLUGINS=""
PYTHON_USEFUL_PLUGINS=""
@@ -303,6 +303,28 @@ then
fi
fi
+# **************
+# Image Export
+# **************
+plugin_defined image-export
+if test "$?" = 1
+then
+ AM_PROG_VALAC([0.8.0])
+
+ PKG_CHECK_MODULES(IMAGEEXPORT,
+ [
+ gconf-2.0 >= 2.0
+ clutter-1.0 >= 1.0
+ ],
+ [],[have_imageexport_deps=no])
+ AC_SUBST(IMAGEEXPORT_LIBS)
+ AC_SUBST(IMAGEEXPORT_CFLAGS)
+ if test "x$have_imageexport_deps" = "xno"
+ then
+ undef_plugin image-export "Image export plugin dependencies not satisfied."
+ fi
+fi
+
if test -z "$disabled_plugins"
then
disabled_plugins="none"
@@ -324,6 +346,7 @@ AC_CONFIG_FILES([
Makefile
plugins/Makefile
plugins/bixi/Makefile
+plugins/image-export/Makefile
plugins/sample-vala/Makefile
po/Makefile.in])
diff --git a/plugins/image-export/Makefile.am b/plugins/image-export/Makefile.am
new file mode 100644
index 0000000..f05d007
--- /dev/null
+++ b/plugins/image-export/Makefile.am
@@ -0,0 +1,57 @@
+# Image export plugin
+plugindir = $(libdir)/emerillon/plugins
+
+INCLUDES = \
+ -I$(top_srcdir) \
+ $(EMERILLON_CFLAGS) \
+ $(IMAGEEXPORT_CFLAGS) \
+ $(WARN_CFLAGS) \
+ -DEMERILLON_LOCALEDIR=\""$(prefix)/$(DATADIRNAME)/locale"\" \
+ -include config.h
+
+BUILT_SOURCES = image-export.vala.stamp
+
+AM_VALAFLAGS = \
+ --pkg gtk+-2.0 \
+ --pkg champlain-0.4 \
+ --pkg clutter-1.0 \
+ --pkg emerillon \
+ --pkg ethos-1.0 \
+ --pkg gconf-2.0 \
+ $(NULL)
+
+plugin_LTLIBRARIES = libimage-export.la
+
+libimage_export_la_VALASOURCES = \
+ image-export.vala
+
+libimage_export_la_SOURCES = \
+ image-export.vala.stamp \
+ $(libimage_export_la_VALASOURCES:.vala=.c) \
+ $(NULL)
+
+image-export.vala.stamp: $(libimage_export_la_VALASOURCES)
+ $(VALAC) -C $(AM_VALAFLAGS) $^
+ touch $@
+
+libimage_export_la_LDFLAGS = \
+ $(PLUGIN_LIBTOOL_FLAGS) \
+ $(EMERILLON_LIBS) \
+ $(IMAGEEXPORT_LIBS)
+
+# Plugin Info
+
+plugin_in_files = image-export.emerillon-plugin.in
+
+%.emerillon-plugin: %.emerillon-plugin.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(AM_V_GEN)$(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache
+
+plugin_DATA = $(plugin_in_files:.emerillon-plugin.in=.emerillon-plugin)
+
+EXTRA_DIST = $(plugin_in_files)
+
+CLEANFILES = $(plugin_DATA) \
+ image-export.vala.stamp \
+ $(libimage_export_la_VALASOURCES:.vala=.c)
+
+DISTCLEANFILES = $(plugin_DATA)
+
diff --git a/plugins/image-export/image-export.emerillon-plugin.in b/plugins/image-export/image-export.emerillon-plugin.in
new file mode 100644
index 0000000..b1d9c23
--- /dev/null
+++ b/plugins/image-export/image-export.emerillon-plugin.in
@@ -0,0 +1,7 @@
+[Emerillon Plugin]
+_Name=Image Exporter
+Module=image-export
+_Description=Exports the map as a PNG image.
+IAge=1
+Authors=Simon Wenner <simon wenner ch>
+Copyright=Copyright © 2010 Simon Wenner
diff --git a/plugins/image-export/image-export.vala b/plugins/image-export/image-export.vala
new file mode 100644
index 0000000..b0e34f3
--- /dev/null
+++ b/plugins/image-export/image-export.vala
@@ -0,0 +1,198 @@
+/*
+ * Copyright (C) 2009 Simon Wenner <simon wenner ch>
+ *
+ * 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.
+ */
+
+using GLib;
+using Ethos;
+using Champlain;
+using GConf;
+
+public class ImageExportPlugin : Ethos.Plugin
+{
+ private unowned Emerillon.Window window;
+ private Champlain.View view;
+ private Gtk.ActionGroup action_group;
+ private uint ui_id;
+
+ construct
+ {
+ this.activated.connect (activate_plugin);
+ this.deactivated.connect (deactivate_plugin);
+ }
+
+ public void activate_plugin ()
+ {
+ this.window = Emerillon.Window.dup_default ();
+ this.view = window.get_map_view ();
+
+ /* Add menu entries */
+ Gtk.UIManager manager = window.get_ui_manager ();
+
+ this.action_group = new Gtk.ActionGroup ("ImageExportActions");
+ action_group.set_translation_domain ("emerillon");
+
+ Gtk.Action action;
+ action = new Gtk.Action ("ImageExportActionSave",
+ _("Export as _image"), "", Gtk.STOCK_SAVE_AS);
+ action_group.add_action (action);
+ action.activate.connect (save_as_image_callback);
+
+ action = new Gtk.Action ("ImageExportActionMail",
+ _("Attach to _email"), "", "");
+ action_group.add_action (action);
+ action.activate.connect (attach_to_email_callback);
+
+ manager.insert_action_group (action_group, -1);
+
+ string ui = """<ui>
+ <menubar name="MainMenu">
+ <menu name="Edit" action="Edit">
+ <placeholder name="EditPluginMenu">
+ <menuitem name="ImageExportItemSave" action="ImageExportActionSave" />
+ <menuitem name="ImageExportItemMail" action="ImageExportActionMail" />
+ </placeholder>
+ </menu>
+ </menubar>
+ </ui>""";
+
+ try {
+ ui_id = manager.add_ui_from_string (ui, ui.length);
+ }
+ catch (GLib.Error e)
+ {
+ GLib.error ("%s", e.message);
+ }
+ }
+
+ public void deactivate_plugin ()
+ {
+ /* remove the buttons */
+ Gtk.UIManager manager = window.get_ui_manager ();
+ manager.remove_ui (ui_id);
+ manager.remove_action_group (action_group);
+ }
+
+ private void grab_and_save_image (string path) throws GLib.Error
+ {
+ /* create an image of the stage */
+ var clutter_stage = view.get_stage ();
+ weak uchar[] pixels = clutter_stage.read_pixels (0, 0, -1, -1);
+ int width = (int) clutter_stage.width;
+ int height = (int) clutter_stage.height;
+
+ var pixbuf = new Gdk.Pixbuf.from_data (pixels, Gdk.Colorspace.RGB,
+ true, 8, width, height, width * 4, null);
+ /* save it as png file */
+ pixbuf.save (path, "png", null, null);
+ }
+
+ public void save_as_image_callback (Gtk.Action action)
+ {
+ /* create the save dialog */
+ var file_chooser = new Gtk.FileChooserDialog (_("Save as png image"),
+ null, Gtk.FileChooserAction.SAVE, Gtk.STOCK_CANCEL,
+ Gtk.ResponseType.CANCEL, Gtk.STOCK_SAVE, Gtk.ResponseType.ACCEPT,
+ null);
+
+ file_chooser.set_current_name (_("map.png"));
+ file_chooser.set_do_overwrite_confirmation (true);
+
+ if (file_chooser.run () == Gtk.ResponseType.ACCEPT)
+ {
+ string path = file_chooser.get_filename ();
+ try {
+ grab_and_save_image (path);
+ }
+ catch (GLib.Error e)
+ {
+ /* saving failed */
+ var dialog = new Gtk.MessageDialog (file_chooser,
+ Gtk.DialogFlags.DESTROY_WITH_PARENT,
+ Gtk.MessageType.ERROR,
+ Gtk.ButtonsType.CLOSE,
+ _("Error"));
+ dialog.secondary_text = e.message;
+ dialog.position = Gtk.WindowPosition.CENTER_ON_PARENT;
+ dialog.run ();
+ dialog.destroy ();
+ }
+ }
+ file_chooser.destroy ();
+ }
+
+ public void attach_to_email_callback (Gtk.Action action)
+ {
+ /* get the default email application */
+ var gc = GConf.Client.get_default ();
+ string default_cmd;
+ try {
+ default_cmd = gc.get_string ("/desktop/gnome/url-handlers/mailto/command");
+ } catch (GLib.Error e) {
+ GLib.warning (e.message);
+ default_cmd = "evolution";
+ }
+
+ /* save the image in the temp folder */
+ string path = GLib.Environment.get_tmp_dir () + "/" + _("map.png");
+
+ /* Detect the client and set the required command arguments */
+ string cmd;
+ if (default_cmd.contains ("evolution")) {
+ cmd = "evolution mailto:?cc=\\&subject=\"\"\\&attach=\"" + path + "\"";
+ } else if (default_cmd.contains ("thunderbird")) {
+ cmd = "thunderbird -compose attachment=\"file://" + path + "\"";
+ } else if (default_cmd.contains ("icedove")) {
+ cmd = "icedove -compose attachment=\"file://" + path + "\"";
+ } else if (default_cmd.contains ("mutt")) {
+ cmd = "mutt -a \"" + path + "\"";
+ } else {
+ /* unknown mail client */
+ var dialog = new Gtk.MessageDialog (window,
+ Gtk.DialogFlags.DESTROY_WITH_PARENT,
+ Gtk.MessageType.ERROR,
+ Gtk.ButtonsType.CLOSE,
+ _("Error"));
+ dialog.secondary_text = _("Your email client is not supported.");
+ dialog.run ();
+ dialog.destroy ();
+ return;
+ }
+
+ try {
+ grab_and_save_image (path);
+ }
+ catch (GLib.Error e)
+ {
+ GLib.critical (e.message);
+ }
+
+ try {
+ GLib.message ("Execute mail command: '%s\'", cmd);
+ GLib.Process.spawn_command_line_async (cmd);
+ }
+ catch (GLib.SpawnError e)
+ {
+ GLib.critical (e.message);
+ }
+ }
+}
+
+public Ethos.Plugin? ethos_plugin_register ()
+{
+ return new ImageExportPlugin ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]