commit b36c6868f8b87c1b2c775634a4ac056a5ff6bdf5
Author: Victor A. Santos <victoraur.santos@gmail.com>
Date:   Tue Jun 10 21:47:41 2014 -0300

    Added Nautilus extension

diff --git a/Makefile.am b/Makefile.am
index 1f58f47..eddda90 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,11 @@
 ACLOCAL_AMFLAGS = -I m4
 
+if ENABLE_NAUTILUS_ACTIONS
+NAUTILUS = nautilus
+else
+NAUTILUS =
+endif
+
 DISTCHECK_CONFIGURE_FLAGS = \
 	--enable-appdata-check \
 	--enable-flac \
@@ -13,7 +19,7 @@ DISTCHECK_CONFIGURE_FLAGS = \
 	--enable-tests \
 	--enable-wavpack
  
-SUBDIRS = help po
+SUBDIRS = help po $(NAUTILUS)
 
 bin_PROGRAMS = easytag
 
diff --git a/configure.ac b/configure.ac
index 535cebf..d3ced12 100644
--- a/configure.ac
+++ b/configure.ac
@@ -19,6 +19,11 @@ AM_MAINTAINER_MODE([enable])
 AM_SILENT_RULES([yes])
 
 dnl -------------------------------
+dnl Init Libtool
+dnl -------------------------------
+LT_INIT
+
+dnl -------------------------------
 dnl Translation files.
 dnl -------------------------------
 IT_PROG_INTLTOOL([0.50.0])
@@ -136,6 +141,11 @@ AC_ARG_ENABLE([mp4],
 AC_ARG_ENABLE([wavpack],
               [AS_HELP_STRING([--disable-wavpack], [Disable support for Wavpack files (default=auto)])])
 
+AC_ARG_ENABLE([nautilus_actions],
+              [AS_HELP_STRING([--disable-nautilus-actions], [do not build the nautilus context menu actions])],,
+              [enable_nautilus_actions=yes])
+
+
 
 dnl -------------------------------
 dnl Checks for libraries.
@@ -288,6 +298,22 @@ AS_IF([test "x$have_wavpack" != "xno"],
        AS_IF([test "x$enable_wavpack" = "xyes"],
              [AC_MSG_ERROR([Wavpack support requested but required dependencies ($WAVPACK_DEPS) not found])])])
 
+dnl ################################################
+dnl # Nautilus
+dnl ################################################
+if test x"$enable_nautilus_actions" != x"no" ; then
+  PKG_CHECK_MODULES(NAUTILUS,         \
+                    [libnautilus-extension glib-2.0 gio-2.0],
+                    [enable_nautilus_actions=yes],
+                    [enable_nautilus_actions=no])
+  NAUTILUS_EXTENSION_DIR=`$PKG_CONFIG --variable=extensiondir libnautilus-extension`
+fi
+
+AC_SUBST(NAUTILUS_CFLAGS)
+AC_SUBST(NAUTILUS_LIBS)
+AC_SUBST(NAUTILUS_EXTENSION_DIR)
+AM_CONDITIONAL(ENABLE_NAUTILUS_ACTIONS, test x"$enable_nautilus_actions" != x"no")
+
 dnl Check the pkg-config dependencies
 GIO_DEPS="gio-2.0 >= 2.32.0" dnl For g_file_new_tmp()
 PKG_CHECK_MODULES([EASYTAG], [$GIO_DEPS $GTK_DEPS $OPUS_DEPS $OGG_DEPS $SPEEX_DEPS $FLAC_DEPS $ID3TAG_DEPS $TAGLIB_DEPS $WAVPACK_DEPS])
@@ -368,6 +394,7 @@ AC_CHECK_FUNCS([ftruncate mkstemp truncate])
 AC_CONFIG_FILES([ Makefile
                   doc/version.xml
                   help/Makefile
+                  nautilus/Makefile
                   po/Makefile.in
                   src/win32/easytag.rc
                ])
@@ -394,6 +421,7 @@ echo FLAC file support .......: $have_flac
 echo MP4 file support ........: $have_taglib
 echo WavPack support .........: $have_wavpack
 echo NLS/gettext .............: $USE_NLS
+echo Nautilus actions ........: $enable_nautilus_actions
 echo Tests during make check .: $testing_utilities
 echo Install prefix ..........: $prefix
 echo 
diff --git a/nautilus/easytag-module.c b/nautilus/easytag-module.c
new file mode 100644
index 0000000..64cebe0
--- /dev/null
+++ b/nautilus/easytag-module.c
@@ -0,0 +1,48 @@
+/*
+ *  Copyright (C) 2014 Victor A. Santos <victoraur.santos@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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#include <libnautilus-extension/nautilus-extension-types.h>
+#include <libnautilus-extension/nautilus-column-provider.h>
+#include "nautilus-easytag.h"
+
+
+void
+nautilus_module_initialize (GTypeModule*module)
+{
+  nautilus_easytag_register_type (module);
+}
+
+
+void
+nautilus_module_shutdown (void)
+{
+}
+
+
+void 
+nautilus_module_list_types (const GType **types,
+                            int          *num_types)
+{
+  static GType type_list[1];
+  
+  type_list[0] = NAUTILUS_TYPE_EASYTAG;
+  *types = type_list;
+  *num_types = 1;
+}
+
diff --git a/nautilus/nautilus-easytag.c b/nautilus/nautilus-easytag.c
new file mode 100644
index 0000000..f5ef162
--- /dev/null
+++ b/nautilus/nautilus-easytag.c
@@ -0,0 +1,274 @@
+/*
+ *  Copyright (C) 2014 Victor A. Santos <victoraur.santos@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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#include <string.h>
+#include <gio/gio.h>
+#include <gio/gdesktopappinfo.h>
+#include <libnautilus-extension/nautilus-extension-types.h>
+#include <libnautilus-extension/nautilus-file-info.h>
+#include <libnautilus-extension/nautilus-menu-provider.h>
+#include "nautilus-easytag.h"
+
+
+static GObjectClass *parent_class;
+
+void
+on_open_in_easytag (NautilusMenuItem *item,
+                    gpointer          data)
+{
+  NautilusFileInfo    *dir;
+  GList               *uris = NULL;
+  GdkDisplay          *display = gdk_display_get_default ();
+  GDesktopAppInfo     *appinfo;
+  GdkAppLaunchContext *context;
+
+  dir = g_object_get_data (G_OBJECT (item), "dir");
+
+  appinfo = g_desktop_app_info_new_from_filename ("/usr/share/applications/easytag.desktop");
+
+  if (appinfo) {
+    uris = g_list_append (uris, nautilus_file_info_get_uri (dir));
+
+    context = gdk_display_get_app_launch_context (display);
+
+    g_app_info_launch_uris (G_APP_INFO (appinfo), uris, G_APP_LAUNCH_CONTEXT (context), NULL);
+  }
+}
+
+void
+on_open_with_easytag (NautilusMenuItem *item,
+                      gpointer          data)
+{
+  GList               *files, *scan;
+  GList               *uris = NULL;
+  GdkDisplay          *display = gdk_display_get_default ();
+  GDesktopAppInfo     *appinfo;
+  GdkAppLaunchContext *context;
+
+  files = g_object_get_data (G_OBJECT (item), "files");
+  
+  appinfo = g_desktop_app_info_new_from_filename ("/usr/share/applications/easytag.desktop");
+
+  if (appinfo) {
+    for (scan = files; scan; scan = scan->next)
+      uris = g_list_append (uris, nautilus_file_info_get_uri (scan->data));
+
+    context = gdk_display_get_app_launch_context (display);
+
+    g_app_info_launch_uris (G_APP_INFO (appinfo), uris, G_APP_LAUNCH_CONTEXT (context), NULL);
+  }
+}
+
+static struct {
+  char     *mime_type;
+  gboolean  is_directory;
+  gboolean  is_file;
+} easytag_mime_types[] = {
+  { "inode/directory",    TRUE, FALSE },
+  { "audio/x-mp3",        FALSE, TRUE },
+  { "audio/x-mpeg",       FALSE, TRUE },
+  { "audio/mpeg",         FALSE, TRUE },
+  { "application/ogg",    FALSE, TRUE },
+  { "audio/x-vorbis+ogg", FALSE, TRUE },
+  { "audio/x-flac",       FALSE, TRUE },
+  { "audio/x-musepack",   FALSE, TRUE },
+  { "audio/x-ape",        FALSE, TRUE },
+  { "audio/x-speex+ogg",  FALSE, TRUE },
+  { "audio/x-opus+ogg",   FALSE, TRUE },
+  { NULL, FALSE }
+};
+
+typedef struct {
+  gboolean is_directory;
+  gboolean is_file;
+} FileMimeInfo;
+
+static FileMimeInfo
+get_file_mime_info (NautilusFileInfo *file)
+{
+  FileMimeInfo file_mime_info;
+  int          i;
+
+  file_mime_info.is_directory = FALSE;
+  file_mime_info.is_file = FALSE;
+
+  for (i = 0; easytag_mime_types[i].mime_type != NULL; i++) {
+    if (nautilus_file_info_is_mime_type (file, easytag_mime_types[i].mime_type)) {
+      file_mime_info.is_directory = easytag_mime_types[i].is_directory;
+      file_mime_info.is_file = easytag_mime_types[i].is_file;
+
+      return file_mime_info;
+    }
+  }
+  return file_mime_info;
+}
+
+static gboolean
+unsupported_scheme (NautilusFileInfo *file)
+{
+  gboolean  result = FALSE;
+  GFile    *location;
+  char     *scheme;
+
+  location = nautilus_file_info_get_location (file);
+  scheme = g_file_get_uri_scheme (location);
+
+  if (scheme != NULL) {
+    const char *unsupported[] = { "trash", "computer", NULL };
+    int         i;
+
+    for (i = 0; unsupported[i] != NULL; i++)
+      if (strcmp (scheme, unsupported[i]) == 0)
+        result = TRUE;
+  }
+
+  g_free (scheme);
+  g_object_unref (location);
+
+  return result;
+}
+
+static GList *
+nautilus_easytag_get_file_items (NautilusMenuProvider *provider,
+                                 GtkWidget            *window,
+                                 GList                *files)
+{
+  GList    *items = NULL;
+  GList    *scan;
+  gboolean  one_item;
+  gboolean  one_directory = TRUE;
+  gboolean  all_files = TRUE;
+
+  if (files == NULL)
+    return NULL;
+
+  if (unsupported_scheme ((NautilusFileInfo *) files->data))
+    return NULL;
+
+  for (scan = files; scan; scan = scan->next) {
+    NautilusFileInfo *file = scan->data;
+    FileMimeInfo      file_mime_info;
+
+    file_mime_info = get_file_mime_info (file);
+
+    if (all_files && !file_mime_info.is_file)
+      all_files = FALSE;
+
+    if (one_directory && !file_mime_info.is_directory)
+      one_directory = FALSE;
+  }
+
+  one_item = (files != NULL) && (files->next == NULL);
+
+  if (one_directory && one_item) {
+    NautilusMenuItem *item;
+
+    item = nautilus_menu_item_new ("NautilusEasyTag::open_directory",
+                                   "Open in EasyTag",
+                                   "Open the current selected directory on EasyTag",
+                                   "easytag");
+    g_signal_connect (item,
+                      "activate",
+                      G_CALLBACK (on_open_in_easytag),
+                      provider);
+    g_object_set_data (G_OBJECT (item),
+                       "dir",
+                       files->data);
+
+    items = g_list_append (items, item);
+  }
+  else if (all_files) {
+    NautilusMenuItem *item;
+
+    item = nautilus_menu_item_new ("NautilusEasyTag::open_files",
+                                   "Open with EasyTag...",
+                                   "Open selected files in EasyTag",
+                                   "easytag");
+    g_signal_connect (item,
+                      "activate",
+                      G_CALLBACK (on_open_with_easytag),
+                      provider);
+    g_object_set_data_full (G_OBJECT (item),
+                            "files",
+                            nautilus_file_info_list_copy (files),
+                            (GDestroyNotify) nautilus_file_info_list_free);
+
+    items = g_list_append (items, item);
+  }
+
+  return items;
+}
+
+static void
+nautilus_easytag_menu_provider_iface_init (NautilusMenuProviderIface *iface)
+{
+  iface->get_file_items = nautilus_easytag_get_file_items;
+}
+
+static void
+nautilus_easytag_instance_init (NautilusEasyTag *fr)
+{
+}
+
+static void
+nautilus_easytag_class_init (NautilusEasyTagClass *class)
+{
+  parent_class = g_type_class_peek_parent (class);
+}
+
+GType easytag_type = 0;
+
+GType
+nautilus_easytag_get_type ()
+{
+  return easytag_type;
+}
+
+void
+nautilus_easytag_register_type (GTypeModule *module)
+{
+  static const GTypeInfo info = {
+    sizeof (NautilusEasyTagClass),
+    (GBaseInitFunc) NULL,
+    (GBaseFinalizeFunc) NULL,
+    (GClassInitFunc) nautilus_easytag_class_init,
+    NULL,
+    NULL,
+    sizeof (NautilusEasyTag),
+    0,
+    (GInstanceInitFunc) nautilus_easytag_instance_init,
+  };
+
+  static const GInterfaceInfo menu_provider_iface_info = {
+    (GInterfaceInitFunc) nautilus_easytag_menu_provider_iface_init,
+    NULL,
+    NULL
+  };
+
+  easytag_type = g_type_module_register_type (module,
+                                              G_TYPE_OBJECT,
+                                              "NautilusEasyTag",
+                                              &info, 0);
+
+  g_type_module_add_interface (module,
+                               easytag_type,
+                               NAUTILUS_TYPE_MENU_PROVIDER,
+                               &menu_provider_iface_info);
+}
+
diff --git a/nautilus/nautilus-easytag.h b/nautilus/nautilus-easytag.h
new file mode 100644
index 0000000..39b912a
--- /dev/null
+++ b/nautilus/nautilus-easytag.h
@@ -0,0 +1,47 @@
+/*
+ *  Copyright (C) 2014 Victor A. Santos <victoraur.santos@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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+#ifndef NAUTILUS_EASYTAG_H
+#define NAUTILUS_EASYTAG_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define NAUTILUS_TYPE_EASYTAG  (nautilus_easytag_get_type ())
+#define NAUTILUS_EASYTAG(o)    (G_TYPE_CHECK_INSTANCE_CAST ((o), NAUTILUS_TYPE_EASYTAG, NautilusEasyTag))
+#define NAUTILUS_IS_EASYTAG(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), NAUTILUS_TYPE_EASYTAG))
+
+typedef struct _NautilusEasyTag      NautilusEasyTag;
+typedef struct _NautilusEasyTagClass NautilusEasyTagClass;
+
+struct _NautilusEasyTag {
+  GObject __parent;
+};
+
+struct _NautilusEasyTagClass {
+  GObjectClass __parent;
+};
+
+GType nautilus_easytag_get_type      ();
+void  nautilus_easytag_register_type (GTypeModule *module);
+
+G_END_DECLS
+
+#endif /* NAUTILUS_EASYTAG_H */
\ No newline at end of file
