[nautilus-sendto] main: Strip down nautilus-sendto to only send e-mails
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus-sendto] main: Strip down nautilus-sendto to only send e-mails
- Date: Wed, 20 Mar 2013 14:12:26 +0000 (UTC)
commit 6cd1c77b582bc3eee23e4f3aced185986e263e7e
Author: Bastien Nocera <hadess hadess net>
Date: Sat Jan 26 17:42:51 2013 +0100
main: Strip down nautilus-sendto to only send e-mails
https://bugzilla.gnome.org/show_bug.cgi?id=680983
Makefile.am | 4 +-
NEWS | 9 +
configure.in | 191 +----
data/Makefile.am | 15 -
data/nautilus-sendto-convert | 3 -
data/nautilus-sendto.pc.in | 10 -
data/nautilus-sendto.ui | 187 ----
data/org.gnome.Nautilus.Sendto.gschema.xml.in | 20 -
data/pack-entry.ui | 107 ---
docs/Makefile.am | 1 -
docs/nautilus-sendto/Makefile.am | 106 ---
docs/nautilus-sendto/nautilus-sendto-docs.sgml | 34 -
docs/nautilus-sendto/version.xml.in | 1 -
po/POTFILES.in | 17 +-
src/Makefile.am | 31 +-
src/nautilus-sendto-command.c | 725 ---------------
src/nautilus-sendto-mimetype.c | 90 --
src/nautilus-sendto-mimetype.h | 28 -
src/nautilus-sendto.c | 546 ++++++++++++
src/plugins/.cvsignore | 2 -
src/plugins/Makefile.am | 82 --
src/plugins/evolution/Makefile.am | 37 -
src/plugins/evolution/e-contact-entry.c | 934 --------------------
src/plugins/evolution/e-contact-entry.h | 86 --
src/plugins/evolution/econtactentry-marshal.list | 1 -
src/plugins/evolution/evolution.c | 504 -----------
src/plugins/evolution/evolution.plugin | 6 -
src/plugins/evolution/update-from-egg.sh | 25 -
src/plugins/gajim/Makefile.am | 19 -
src/plugins/gajim/gajim.c | 517 -----------
src/plugins/nautilus-burn/Makefile.am | 20 -
src/plugins/nautilus-burn/nautilus-burn.c | 187 ----
src/plugins/nautilus-sendto-filelist.c | 210 -----
src/plugins/nautilus-sendto-filelist.h | 54 --
src/plugins/nautilus-sendto-packer.c | 439 ---------
src/plugins/nautilus-sendto-packer.h | 54 --
src/plugins/nautilus-sendto-plugin.c | 154 ----
src/plugins/nautilus-sendto-plugin.h | 136 ---
src/plugins/nautilus-sendto-progress.c | 197 ----
src/plugins/nautilus-sendto-progress.h | 48 -
src/plugins/nst-common.c | 103 ---
src/plugins/nst-common.h | 24 -
src/plugins/nst-plugin-marshal.list | 3 -
src/plugins/pidgin/Makefile.am | 20 -
src/plugins/pidgin/pidgin.c | 475 ----------
src/plugins/removable-devices/Makefile.am | 21 -
src/plugins/removable-devices/removable-devices.c | 306 -------
.../removable-devices/removable-devices.plugin | 6 -
src/plugins/socialweb/Makefile.am | 22 -
src/plugins/socialweb/socialweb.c | 536 -----------
src/plugins/socialweb/socialweb.plugin | 6 -
src/plugins/test-progress.c | 19 -
src/plugins/upnp/Makefile.am | 19 -
src/plugins/upnp/upnp.c | 320 -------
src/test-mimetype-data | 57 --
src/test-mimetype.c | 90 --
src/totem-mime-types.h | 58 --
57 files changed, 560 insertions(+), 7362 deletions(-)
---
diff --git a/Makefile.am b/Makefile.am
index aa7a9e0..99bd772 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,8 +1,6 @@
ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
-SUBDIRS = data src docs po
-
-DISTCHECK_CONFIGURE_FLAGS = --enable-gtk-doc
--with-nautilusdir='$${libdir}/nautilus/extensions-2.0-distcheck'
+SUBDIRS = src po
man_MANS = nautilus-sendto.1
diff --git a/NEWS b/NEWS
index f41b7a8..549a0bb 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,13 @@
==============
+Version 3.7.0
+==============
+
+- Remove all plugins, we will only handle sending
+ through e-mail clients for the foreseeable future
+ nautilus-sendto 3.6.x is still available for integrators
+ for which this is a problem.
+
+==============
Version 2.90.0
==============
diff --git a/configure.in b/configure.in
index 43d0214..cf14823 100644
--- a/configure.in
+++ b/configure.in
@@ -26,9 +26,6 @@ LT_INIT([disable-static])
GLIB_GSETTINGS
-dnl gtk-doc checks
-GTK_DOC_CHECK(1.9)
-
GNOME_DEBUG_CHECK
GNOME_COMPILE_WARNINGS([maximum])
GNOME_CXX_WARNINGS
@@ -42,169 +39,19 @@ dnl --------------------------------------------------
GLIB_REQUIRED=2.25.9
GTHREAD_REQUIRED=2.6.0
GTK_REQUIRED=2.91.7
-EBOOK_REQUIRED=1.5.3
-DBUS_REQUIRED=1.0
-DBUS_GLIB_REQUIRED=0.60
-GUPNP_REQUIRED=0.13
-LIBPEAS_REQUIRED=0.7.0
AC_SUBST(GLIB_REQUIRED)
AC_SUBST(GTHREAD_REQUIRED)
AC_SUBST(GTK_REQUIRED)
-AC_SUBST(EBOOK_REQUIRED)
-AC_SUBST(BLUETOOTH_REQUIRED)
-AC_SUBST(DBUS_REQUIRED)
-AC_SUBST(GUPNP_REQUIRED)
PKG_CHECK_MODULES(NAUTILUS_SENDTO, \
glib-2.0 >= $GLIB_REQUIRED \
gthread-2.0 >= $GTHREAD_REQUIRED \
- gmodule-2.0 >= $GLIB_REQUIRED \
gtk+-3.0 >= $GTK_REQUIRED \
- libpeas-1.0 >= $LIBPEAS_REQUIRED)
+ gio-2.0)
AC_SUBST(NAUTILUS_SENDTO_CFLAGS)
AC_SUBST(NAUTILUS_SENDTO_LIBS)
-PKG_CHECK_MODULES(GIO, gio-2.0)
-
-# The full list of plugins
-allowed_plugins="evolution removable-devices socialweb"
-# These need porting: gajim nautilus-burn pidgin upnp
-plugin_error_or_ignore()
-{
- if test "${error_on_bad_plugin}" = "1" ; then
- AC_MSG_ERROR([$1])
- else
- AC_MSG_WARN([$1 (disabling plugin)])
- fi
-}
-
-AC_ARG_WITH([plugins],
- [AS_HELP_STRING([--with-plugins],[Which nautilus-sendto plugins to compile (default: auto; "all",
"autodetect" are valid)])],
- [], [with_plugins=autodetect])
-
-used_plugins=""
-used_plugins2=""
-
-if test "x${with_plugins}" = "xautodetect" ; then
- # Default to all plugins and just ignore them if they won't compile
- with_plugins="all"
- error_on_bad_plugin="0"
-else
- # Clean up the plugin list and error if a plugin won't compile
- with_plugins=`echo ,"${with_plugins}", | sed -e 's/[[ ,]][[ ,]]*/ /g' -e 's/,$//'`
- error_on_bad_plugin="1"
-fi
-
-# Iterate through the wanted plugins and weed out bad ones (or error)
-for wanted_plugin in ${with_plugins}; do
- for allowed_plugin in ${allowed_plugins}; do
- case ${wanted_plugin} in
- all)
- # List all plugins as being used
- used_plugins=${allowed_plugins}
- ;;
- autodetect)
- # List all plugins as being used
- used_plugins=${allowed_plugins}
- ;;
- ${allowed_plugin}) used_plugins="${used_plugins} ${wanted_plugin}";; # List the plugin
- *) ;;
- esac
- done
-done
-
-# Check for plugin-specific requirements and error if necessary
-for plugin in ${used_plugins}; do
- add_plugin="1"
-
- case ${plugin} in
- evolution)
- PKG_CHECK_MODULES(NST_EBOOK, libebook-1.2 >= $EBOOK_REQUIRED libpeas-1.0
libedataserverui-3.0,
- enable_evolution=yes, enable_evolution=no)
- if test "${enable_evolution}" != "yes" ; then
- plugin_error_or_ignore "you need libebook from evolution-data-server to build
the Evolution plugin"
- add_plugin="0"
- else
- saved_CPPFLAGS="$CPPFLAGS"
- CPPFLAGS="$CPPFLAGS $NST_EBOOK_CFLAGS"
- AC_CHECK_TYPES([EContactPhotoType], , , [#include <libebook/e-contact.h>])
- CPPFLAGS="$saved_CPPFLAGS"
- fi
- ;;
- gajim)
- AC_ARG_WITH(gajim,
- [AS_HELP_STRING(--with-gajim,[Path to Gajim install prefix])],
- [GAJIM_PATH="$withval"],[GAJIM_PATH="$prefix"])
-
- GAJIM_SHARE_DIR="$GAJIM_PATH"/share/gajim
-
- PKG_CHECK_MODULES(DBUS, dbus-1 >= $DBUS_REQUIRED dbus-glib-1 >= $DBUS_GLIB_REQUIRED
libpeas-1.0,
- [
- AC_SUBST(DBUS_CFLAGS)
- AC_SUBST(DBUS_LIBS)
- enable_gajim=yes
- AC_DEFINE_UNQUOTED(GAJIM_SHARE_DIR, "$GAJIM_SHARE_DIR", [path to
gajim share dir])
- ],
- [
- enable_gajim=no
- ]
- )
- if test "${enable_gajim}" != "yes" ; then
- plugin_error_or_ignore "you need gajim and dbus-glib installed for the gajim
plugin"
- add_plugin="0"
- fi
- ;;
- nautilus-burn)
- ;;
- removable-devices)
- ;;
- pidgin)
- PKG_CHECK_MODULES(PIDGIN, dbus-glib-1 >= $DBUS_GLIB_REQUIRED libpeas-1.0,
- enable_pidgin=yes, enable_pidgin=no)
- if test "${enable_pidgin}" != "yes" ; then
- plugin_error_or_ignore "you need dbus-glib to build the pidgin plugin"
- add_plugin="0"
- fi
- ;;
- socialweb)
- PKG_CHECK_MODULES(SOCIALWEB, libsocialweb-client >= 0.25.7,
- enable_libsocialweb=yes, enable_libsocialweb=no)
- if test "${enable_libsocialweb}" != "yes"; then
- plugin_error_or_ignore "you need libsocialweb-client to build the
libsocialweb plugin"
- add_plugin="0"
- fi
- ;;
- upnp)
- PKG_CHECK_MODULES(UPNP, gssdp-1.0 gupnp-1.0 >= $GUPNP_REQUIRED libpeas-1.0,
- enable_upnp=yes, enable_upnp=no)
- if test "${enable_upnp}" != "yes" ; then
- plugin_error_or_ignore "you need gupnp installed for the upnp plugin"
- add_plugin="0"
- fi
- ;;
- esac
-
- # Add the specified plugin
- if test "${add_plugin}" = "1" ; then
- used_plugins2="${used_plugins2} ${plugin}"
- fi
-done
-
-ALL_PLUGINS=$allowed_plugins
-PLUGINS=$used_plugins2
-
-dnl Error out if no plugins will be built
-if test -z "${PLUGINS}" ; then
- AC_MSG_ERROR([No plugins will be built, and nautilus-sendto requires at least one])
-fi
-
-AC_MSG_CHECKING([which plugins to compile])
-AC_MSG_RESULT([$PLUGINS])
-
-AC_SUBST([ALL_PLUGINS])
-AC_SUBST([PLUGINS])
-
GLIB_GENMARSHAL=`$PKG_CONFIG --variable=glib_genmarshal glib-2.0`
AC_SUBST(GLIB_GENMARSHAL)
@@ -218,43 +65,7 @@ AM_GLIB_GNU_GETTEXT
AC_CONFIG_FILES([
Makefile
-data/Makefile
-data/nautilus-sendto.pc
src/Makefile
-src/plugins/Makefile
-src/plugins/evolution/Makefile
-src/plugins/gajim/Makefile
-src/plugins/nautilus-burn/Makefile
-src/plugins/pidgin/Makefile
-src/plugins/removable-devices/Makefile
-src/plugins/socialweb/Makefile
-src/plugins/upnp/Makefile
-docs/Makefile
-docs/nautilus-sendto/Makefile
-docs/nautilus-sendto/version.xml
po/Makefile.in
])
AC_OUTPUT
-
-echo "-------------------------------------------------------"
-echo " "
-
-if test "x${PLUGINS}" != "x" ; then
- for allowed_plugin in ${ALL_PLUGINS}; do
- for plugin in ${PLUGINS}; do
- case ${allowed_plugin} in
- ${plugin})
- AC_MSG_NOTICE([** ${allowed_plugin} plugin enabled])
- continue 2
- ;;
- *);;
- esac
- done
- AC_MSG_NOTICE([ ${allowed_plugin} plugin disabled])
- done
-else
- AC_MSG_NOTICE([ No nautilus-sendto plugins enabled])
-fi
-
-echo " "
-echo "-------------------------------------------------------"
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3266219..c30b7f1 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,18 +1,3 @@
# List of source files containing translatable strings.
# Please keep this file sorted alphabetically.
-src/nautilus-sendto-command.c
-src/nautilus-sendto-mimetype.c
-data/org.gnome.Nautilus.Sendto.gschema.xml.in
-[type: gettext/glade]data/nautilus-sendto.ui
-src/plugins/nst-common.c
-src/plugins/nautilus-sendto-packer.c
-src/plugins/nautilus-sendto-progress.c
-[type: gettext/glade]data/pack-entry.ui
-src/plugins/evolution/evolution.c
-src/plugins/evolution/e-contact-entry.c
-src/plugins/gajim/gajim.c
-src/plugins/nautilus-burn/nautilus-burn.c
-src/plugins/pidgin/pidgin.c
-src/plugins/removable-devices/removable-devices.c
-src/plugins/socialweb/socialweb.c
-src/plugins/upnp/upnp.c
+src/nautilus-sendto.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 15118c3..0a3158f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,39 +1,12 @@
-include $(top_srcdir)/Makefile.decl
-
-uidir = $(datadir)/nautilus-sendto/ui
-
-SUBDIRS = plugins
INCLUDES = \
- -DDATADIR=\"$(datadir)\" \
- -DPLUGINDIR=\"$(pkglibdir)/plugins\" \
- -DLIBDIR=\"$(pkglibdir)\" \
-I$(top_srcdir) \
-I$(top_builddir) \
- -I$(top_srcdir)/src/plugins \
- -DUIDIR=\""$(uidir)"\" \
-DLOCALEDIR="\"$(datadir)/locale\"" \
- -DTEST_SRCDIR=\""$(srcdir)/"\" \
$(NAUTILUS_SENDTO_CFLAGS) \
- $(NAUTILUS_EXT_SENDTO_CFLAGS) \
$(DISABLE_DEPRECATED) \
$(WARN_CFLAGS)
-noinst_LTLIBRARIES = libnstplugin.la
-libnstplugin_la_SOURCES = \
- nautilus-sendto-mimetype.c \
- nautilus-sendto-mimetype.h
-libnstplugin_la_LIBADD = $(NAUTILUS_SENDTO_LIBS)
-
bin_PROGRAMS = nautilus-sendto
-nautilus_sendto_SOURCES = nautilus-sendto-command.c
-nautilus_sendto_LDADD = $(NAUTILUS_SENDTO_LIBS) libnstplugin.la $(builddir)/plugins/libnautilussendto-1.0.la
-
-pwd=`pwd`
-
-noinst_PROGRAMS = $(TEST_PROGS)
-TEST_PROGS += test-mimetype
-test_mimetype_SOURCES = test-mimetype.c
-test_mimetype_LDADD = $(NAUTILUS_SENDTO_LIBS) libnstplugin.la $(builddir)/plugins/libnautilussendto-1.0.la
-
-EXTRA_DIST = test-mimetype-data
+nautilus_sendto_SOURCES = nautilus-sendto.c
+nautilus_sendto_LDADD = $(NAUTILUS_SENDTO_LIBS)
diff --git a/src/nautilus-sendto.c b/src/nautilus-sendto.c
new file mode 100644
index 0000000..1d86dde
--- /dev/null
+++ b/src/nautilus-sendto.c
@@ -0,0 +1,546 @@
+/*
+ * Copyright (C) 2004 Roberto Majadas
+ * Copyright (C) 2005-2013 Bastien Nocera
+ *
+ * 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 av.
+ *
+ * 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., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301 USA.
+ *
+ * Author: Roberto Majadas <roberto majadas openshine com>
+ * Bastien Nocera <hadess hadess net>
+ */
+
+#include "config.h"
+#include <string.h>
+#include <stdlib.h>
+#include <glib/gi18n.h>
+#include <glib/gstdio.h>
+#include <gio/gio.h>
+
+/* Options */
+static char **filenames = NULL;
+static gboolean run_from_build_dir = FALSE;
+static gint64 xid = 0;
+static gboolean show_version = FALSE;
+
+typedef enum {
+ MAILER_UNKNOWN,
+ MAILER_EVO,
+ MAILER_BALSA,
+ MAILER_SYLPHEED,
+ MAILER_THUNDERBIRD,
+} MailerType;
+
+typedef struct {
+ GList *file_list;
+ guint num_dirs;
+ MailerType type;
+ char *mail_cmd;
+} NautilusSendto;
+
+static const GOptionEntry entries[] = {
+ { "run-from-build-dir", 'b', 0, G_OPTION_ARG_NONE, &run_from_build_dir, N_("Run from build directory
(ignored)"), NULL },
+ { "xid", 'x', 0, G_OPTION_ARG_INT64, &xid, N_("Use XID as parent to the send dialogue (ignored)"),
NULL },
+ { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, N_("Files to send"),
"[FILES...]" },
+ {"version", 'v', 0, G_OPTION_ARG_NONE, &show_version, N_("Output version information and exit"),
NULL},
+ { NULL }
+};
+
+static char *
+get_evo_cmd (void)
+{
+ char *tmp = NULL;
+ char *retval;
+ char *cmds[] = {
+ "evolution",
+ "evolution-2.0",
+ "evolution-2.2",
+ "evolution-2.4",
+ "evolution-2.6",
+ "evolution-2.8", /* for the future */
+ NULL};
+ guint i;
+
+ for (i = 0; cmds[i] != NULL; i++) {
+ tmp = g_find_program_in_path (cmds[i]);
+ if (tmp != NULL)
+ break;
+ }
+
+ if (tmp == NULL)
+ return NULL;
+
+ retval = g_strdup_printf ("%s --component=mail %%s", tmp);
+ g_free (tmp);
+ return retval;
+}
+
+static void
+init_mailer (NautilusSendto *nst)
+{
+ GAppInfo *app_info;
+ char *needle;
+
+ nst->type = MAILER_UNKNOWN;
+
+ app_info = g_app_info_get_default_for_uri_scheme ("mailto");
+ if (app_info) {
+ nst->mail_cmd = g_strdup (g_app_info_get_commandline (app_info));
+ g_object_unref (app_info);
+ } else {
+ nst->mail_cmd = NULL;
+ }
+
+ if (nst->mail_cmd == NULL || *nst->mail_cmd == '\0') {
+ g_free (nst->mail_cmd);
+ nst->mail_cmd = get_evo_cmd ();
+ nst->type = MAILER_EVO;
+ } else {
+ /* Find what the default mailer is */
+ if (strstr (nst->mail_cmd, "balsa"))
+ nst->type = MAILER_BALSA;
+ else if (strstr (nst->mail_cmd, "thunder") || strstr (nst->mail_cmd, "seamonkey") || strstr
(nst->mail_cmd, "icedove")) {
+ char **strv;
+
+ nst->type = MAILER_THUNDERBIRD;
+
+ /* Thunderbird sucks, see
+ * https://bugzilla.gnome.org/show_bug.cgi?id=614222 */
+ strv = g_strsplit (nst->mail_cmd, " ", -1);
+ g_free (nst->mail_cmd);
+ nst->mail_cmd = g_strdup_printf ("%s %%s", strv[0]);
+ g_strfreev (strv);
+ } else if (strstr (nst->mail_cmd, "sylpheed") || strstr (nst->mail_cmd, "claws"))
+ nst->type = MAILER_SYLPHEED;
+ else if (strstr (nst->mail_cmd, "anjal"))
+ nst->type = MAILER_EVO;
+ }
+
+ /* Replace %U by %s */
+ while ((needle = g_strrstr (nst->mail_cmd, "%U")) != NULL)
+ needle[1] = 's';
+ while ((needle = g_strrstr (nst->mail_cmd, "%u")) != NULL)
+ needle[1] = 's';
+}
+
+static char *
+get_filename_from_list (GList *file_list)
+{
+ GList *l;
+ GString *common_part = NULL;
+ gboolean matches = TRUE;
+ guint offset = 0;
+ const char *encoding;
+ gboolean use_utf8 = TRUE;
+
+ encoding = g_getenv ("G_FILENAME_ENCODING");
+
+ if (encoding != NULL && strcasecmp (encoding, "UTF-8") != 0)
+ use_utf8 = FALSE;
+
+ if (file_list == NULL)
+ return NULL;
+
+ common_part = g_string_new ("");
+
+ while (TRUE) {
+ gunichar cur_char = '\0';
+ for (l = file_list; l ; l = l->next) {
+ char *path = NULL, *name = NULL;
+ char *offset_name = NULL;
+
+ path = g_filename_from_uri ((char *) l->data, NULL, NULL);
+ if (!path)
+ break;
+
+ name = g_path_get_basename (path);
+
+ if (!use_utf8) {
+ char *tmp;
+
+ tmp = g_filename_to_utf8 (name, -1, NULL, NULL, NULL);
+ g_free (name);
+ name = tmp;
+ }
+
+ if (!name) {
+ g_free (path);
+ break;
+ }
+
+ if (offset >= g_utf8_strlen (name, -1)) {
+ g_free(name);
+ g_free(path);
+ matches = FALSE;
+ break;
+ }
+
+ offset_name = g_utf8_offset_to_pointer (name, offset);
+
+ if (offset_name == g_utf8_strrchr (name, -1, '.')) {
+ g_free (name);
+ g_free (path);
+ matches = FALSE;
+ break;
+ }
+ if (cur_char == '\0') {
+ cur_char = g_utf8_get_char (offset_name);
+ } else if (cur_char != g_utf8_get_char (offset_name)) {
+ g_free (name);
+ g_free (path);
+ matches = FALSE;
+ break;
+ }
+ g_free (name);
+ g_free (path);
+ }
+ if (matches == TRUE &&
+ cur_char != '\0' &&
+ cur_char != '-' &&
+ cur_char != '_') {
+ offset++;
+ common_part = g_string_append_unichar (common_part,
+ cur_char);
+ } else {
+ break;
+ }
+ }
+
+ if (g_utf8_strlen (common_part->str, -1) < 4) {
+ g_string_free (common_part, TRUE);
+ return NULL;
+ }
+
+ return g_string_free (common_part, FALSE);
+}
+
+static char *
+pack_filename_from_names (GList *file_list)
+{
+ char *filename;
+ gboolean one_file;
+
+ if (file_list != NULL && file_list->next != NULL)
+ one_file = FALSE;
+ else if (file_list != NULL)
+ one_file = TRUE;
+
+ if (one_file) {
+ char *filepath;
+
+ filepath = g_filename_from_uri ((char *)file_list->data,
+ NULL, NULL);
+ filename = g_path_get_basename (filepath);
+ g_free (filepath);
+ } else {
+ filename = get_filename_from_list (file_list);
+ }
+
+ if (filename == NULL) {
+ /* Translators: the default archive name if it
+ * could not be deduced from the provided files */
+ filename = g_strdup (_("Archive"));
+ }
+
+ return filename;
+}
+
+static char *
+pack_files (GList *file_list)
+{
+ char *file_roller_cmd;
+ const char *filename;
+ GList *l;
+ GString *cmd, *tmp;
+ char *pack_type, *tmp_dir, *tmp_work_dir, *packed_file;
+
+ file_roller_cmd = g_find_program_in_path ("file-roller");
+ filename = pack_filename_from_names (file_list);
+
+ g_assert (filename != NULL && *filename != '\0');
+
+ tmp_dir = g_strdup_printf ("%s/nautilus-sendto-%s",
+ g_get_tmp_dir (), g_get_user_name ());
+ g_mkdir (tmp_dir, 0700);
+ tmp_work_dir = g_strdup_printf ("%s/nautilus-sendto-%s/%li",
+ g_get_tmp_dir (), g_get_user_name (),
+ time (NULL));
+ g_mkdir (tmp_work_dir, 0700);
+ g_free (tmp_dir);
+
+ pack_type = g_strdup (".zip");
+
+ cmd = g_string_new ("");
+ g_string_printf (cmd, "%s --add-to=\"%s/%s%s\"",
+ file_roller_cmd, tmp_work_dir,
+ filename,
+ pack_type);
+
+ /* file-roller doesn't understand URIs */
+ for (l = file_list ; l; l=l->next){
+ char *file;
+
+ file = g_filename_from_uri (l->data, NULL, NULL);
+ g_string_append_printf (cmd," \"%s\"", file);
+ g_free (file);
+ }
+
+ g_spawn_command_line_sync (cmd->str, NULL, NULL, NULL, NULL);
+ g_string_free (cmd, TRUE);
+ tmp = g_string_new("");
+ g_string_printf (tmp,"%s/%s%s", tmp_work_dir,
+ filename,
+ pack_type);
+ g_free (tmp_work_dir);
+ packed_file = g_filename_to_uri (tmp->str, NULL, NULL);
+ g_string_free(tmp, TRUE);
+
+ return packed_file;
+}
+
+static void
+get_evo_mailto (GString *mailto,
+ GList *file_list)
+{
+ GList *l;
+
+ g_string_append (mailto, "mailto:");
+ g_string_append (mailto, "\"\"");
+ g_string_append_printf (mailto,"?attach=\"%s\"", (char *)file_list->data);
+ for (l = file_list->next ; l; l=l->next)
+ g_string_append_printf (mailto,"&attach=\"%s\"", (char *)l->data);
+}
+
+static void
+get_balsa_mailto (NautilusSendto *nst,
+ GString *mailto,
+ GList *file_list)
+{
+ GList *l;
+
+ if (strstr (nst->mail_cmd, " -m ") == NULL && strstr (nst->mail_cmd, " --compose=") == NULL)
+ g_string_append (mailto, " --compose=");
+ g_string_append (mailto, "\"\"");
+ g_string_append_printf (mailto," --attach=\"%s\"", (char *)file_list->data);
+ for (l = file_list->next ; l; l=l->next)
+ g_string_append_printf (mailto," --attach=\"%s\"", (char *)l->data);
+}
+
+static void
+get_thunderbird_mailto (GString *mailto,
+ GList *file_list)
+{
+ GList *l;
+
+ g_string_append (mailto, "-compose \"");
+ g_string_append_printf (mailto,"attachment='%s", (char *)file_list->data);
+ for (l = file_list->next ; l; l=l->next)
+ g_string_append_printf (mailto,",%s", (char *)l->data);
+ g_string_append (mailto, "'\"");
+}
+
+static void
+get_sylpheed_mailto (GString *mailto,
+ GList *file_list)
+{
+ GList *l;
+
+ g_string_append (mailto, "--compose ");
+ g_string_append (mailto, "\"\"");
+ g_string_append_printf (mailto,"--attach \"%s\"", (char *)file_list->data);
+ for (l = file_list->next ; l; l=l->next)
+ g_string_append_printf (mailto," \"%s\"", (char *)l->data);
+}
+
+static void
+send_files (NautilusSendto *nst)
+{
+ GString *mailto;
+ char *cmd;
+
+ if (nst->num_dirs > 0) {
+ char *zip;
+ zip = pack_files (nst->file_list);
+ g_list_free_full (nst->file_list, g_free);
+ nst->file_list = g_list_append (NULL, zip);
+ }
+
+ mailto = g_string_new ("");
+ switch (nst->type) {
+ case MAILER_BALSA:
+ get_balsa_mailto (nst, mailto, nst->file_list);
+ break;
+ case MAILER_SYLPHEED:
+ get_sylpheed_mailto (mailto, nst->file_list);
+ break;
+ case MAILER_THUNDERBIRD:
+ get_thunderbird_mailto (mailto, nst->file_list);
+ break;
+ case MAILER_EVO:
+ default:
+ get_evo_mailto (mailto, nst->file_list);
+ }
+
+ cmd = g_strdup_printf (nst->mail_cmd, mailto->str);
+ g_string_free (mailto, TRUE);
+
+ g_debug ("Mailer type: %d", nst->type);
+ g_debug ("Command: %s", cmd);
+
+ /* FIXME: collect errors from this call */
+ g_spawn_command_line_async (cmd, NULL);
+ g_free (cmd);
+}
+
+static char *
+escape_ampersands_and_commas (const char *url)
+{
+ int i;
+ char *str, *ptr;
+
+ /* Count the number of ampersands & commas */
+ i = 0;
+ ptr = (char *) url;
+ while ((ptr = strchr (ptr, '&')) != NULL) {
+ i++;
+ ptr++;
+ }
+ ptr = (char *) url;
+ while ((ptr = strchr (ptr, ',')) != NULL) {
+ i++;
+ ptr++;
+ }
+
+ /* No ampersands or commas ? */
+ if (i == 0)
+ return NULL;
+
+ /* Replace the '&' */
+ str = g_malloc0 (strlen (url) - i + 3 * i + 1);
+ ptr = str;
+ for (i = 0; url[i] != '\0'; i++) {
+ if (url[i] == '&') {
+ *ptr++ = '%';
+ *ptr++ = '2';
+ *ptr++ = '6';
+ } else if (url[i] == ',') {
+ *ptr++ = '%';
+ *ptr++ = '2';
+ *ptr++ = 'C';
+ } else {
+ *ptr++ = url[i];
+ }
+ }
+
+ return str;
+}
+
+static void
+nautilus_sendto_init (NautilusSendto *nst)
+{
+ int i;
+
+ /* Clean up the URIs passed, and collect whether we have directories */
+ for (i = 0; filenames != NULL && filenames[i] != NULL; i++) {
+ GFile *file;
+ char *filename, *escaped, *uri;
+ GFileInfo *info;
+ const char *mimetype;
+
+ /* We need a filename */
+ file = g_file_new_for_commandline_arg (filenames[i]);
+ filename = g_file_get_path (file);
+ if (filename == NULL) {
+ g_object_unref (file);
+ continue;
+ }
+
+ /* Get the mime-type, and whether the file is readable */
+ info = g_file_query_info (file,
+
G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE","G_FILE_ATTRIBUTE_ACCESS_CAN_READ,
+ G_FILE_QUERY_INFO_NONE,
+ NULL,
+ NULL);
+ g_object_unref (file);
+
+ if (info == NULL)
+ continue;
+
+ if (g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_ACCESS_CAN_READ) == FALSE) {
+ g_debug ("'%s' is not readable", filenames[i]);
+ g_object_unref (info);
+ continue;
+ }
+ mimetype = g_file_info_get_attribute_string (info,
G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE);
+ if (g_str_equal (mimetype, "inode/directory"))
+ nst->num_dirs++;
+
+ g_object_unref (info);
+
+ uri = g_filename_to_uri (filename, NULL, NULL);
+ g_free (filename);
+ escaped = escape_ampersands_and_commas (uri);
+
+ if (escaped == NULL) {
+ nst->file_list = g_list_prepend (nst->file_list, uri);
+ } else {
+ nst->file_list = g_list_prepend (nst->file_list, escaped);
+ g_free (uri);
+ }
+ }
+
+ nst->file_list = g_list_reverse (nst->file_list);
+}
+
+int main (int argc, char **argv)
+{
+ GOptionContext *context;
+ GError *error = NULL;
+ NautilusSendto *nst;
+ int ret = 0;
+
+ bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+ textdomain (GETTEXT_PACKAGE);
+
+ context = g_option_context_new ("");
+ g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE);
+ if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) {
+ g_print (_("Could not parse command-line options: %s\n"), error->message);
+ g_error_free (error);
+ return 1;
+ }
+
+ if (show_version) {
+ g_print ("%s %s\n", PACKAGE_NAME, PACKAGE_VERSION);
+ return 0;
+ }
+
+ nst = g_new0 (NautilusSendto, 1);
+ nautilus_sendto_init (nst);
+ init_mailer (nst);
+
+ if (nst->file_list == NULL) {
+ g_print (_("Expects URIs or filenames to be passed as options\n"));
+ ret = 1;
+ goto out;
+ }
+
+ send_files (nst);
+
+out:
+ g_free (nst);
+
+ return ret;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]