diff options
-rw-r--r-- | configure.ac | 23 | ||||
-rw-r--r-- | programs/Makefile.am | 88 | ||||
-rw-r--r-- | programs/completion/Makefile.am | 41 | ||||
-rwxr-xr-x | programs/completion/gvfs-cat | 57 | ||||
-rw-r--r-- | programs/deprecated.in | 6 | ||||
-rw-r--r-- | programs/gvfs-cat.c | 206 | ||||
-rw-r--r-- | programs/gvfs-copy.c | 252 | ||||
-rw-r--r-- | programs/gvfs-info.c | 426 | ||||
-rw-r--r-- | programs/gvfs-ls.c | 482 | ||||
-rw-r--r-- | programs/gvfs-mime.c | 197 | ||||
-rw-r--r-- | programs/gvfs-mkdir.c | 115 | ||||
-rw-r--r-- | programs/gvfs-monitor-dir.c | 175 | ||||
-rw-r--r-- | programs/gvfs-monitor-file.c | 167 | ||||
-rw-r--r-- | programs/gvfs-mount.c | 1203 | ||||
-rw-r--r-- | programs/gvfs-move.c | 247 | ||||
-rw-r--r-- | programs/gvfs-open.c | 244 | ||||
-rw-r--r-- | programs/gvfs-rename.c | 124 | ||||
-rw-r--r-- | programs/gvfs-rm.c | 106 | ||||
-rw-r--r-- | programs/gvfs-save.c | 206 | ||||
-rw-r--r-- | programs/gvfs-set-attribute.c | 244 | ||||
-rw-r--r-- | programs/gvfs-trash.c | 148 | ||||
-rw-r--r-- | programs/gvfs-tree.c | 297 |
22 files changed, 44 insertions, 5010 deletions
diff --git a/configure.ac b/configure.ac index a38f8eec..43b60873 100644 --- a/configure.ac +++ b/configure.ac @@ -61,7 +61,7 @@ GTK_DOC_CHECK DISTCHECK_CONFIGURE_FLAGS="--enable-gtk-doc" AC_SUBST(DISTCHECK_CONFIGURE_FLAGS) -PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.49.3 gobject-2.0 gmodule-no-export-2.0 gio-unix-2.0 gio-2.0]) +PKG_CHECK_MODULES([GLIB], [glib-2.0 >= 2.49.4 gobject-2.0 gmodule-no-export-2.0 gio-unix-2.0 gio-2.0]) PKG_CHECK_MODULES([DBUS], [dbus-1]) @@ -763,25 +763,6 @@ AC_CHECK_DECL(_NL_ADDRESS_COUNTRY_AB3, AC_DEFINE(HAVE_NL_ADDRESS_COUNTRY_AB3, 1, Define to 1 if _NL_ADDRESS_COUNTRY_AB3 is declared),, [#include <langinfo.h>]) -dnl Install bash-completion file? -AC_ARG_ENABLE([bash-completion], - [AS_HELP_STRING([--disable-bash-completion], - [build without bash-completion support])], - [msg_bash_completion=$enableval], - [msg_bash_completion=yes]) -if test "x$enable_bash_completion" != "xno"; then - msg_bash_completion=yes -fi -AM_CONDITIONAL([ENABLE_BASHCOMP], [test "$msg_bash_completion" = "yes"]) - -AC_ARG_WITH([bash-completion-dir], - [AS_HELP_STRING([--with-bash-completion-dir=PATH], - [choose directory for bash-completion file (default=DATADIR/bash-completion/completions)])], - [with_bashcomp_dir=$withval], - [with_bashcomp_dir=$datadir/bash-completion/completions]) -BASHCOMP_DIR=$with_bashcomp_dir -AC_SUBST(BASHCOMP_DIR) - dnl ========================================================================== dnl Globally define_GNU_SOURCE and therefore enable the GNU extensions @@ -939,7 +920,6 @@ monitor/afc/Makefile monitor/mtp/Makefile monitor/goa/Makefile programs/Makefile -programs/completion/Makefile man/Makefile test/Makefile po/Makefile.in @@ -976,7 +956,6 @@ echo " Use GCR: $msg_gcr GNOME Keyring support: $msg_keyring GTK+ support: $msg_gtk - Bash-completion support: $msg_bash_completion Installed tests: $msg_installed_tests " diff --git a/programs/Makefile.am b/programs/Makefile.am index da18410c..d69734b3 100644 --- a/programs/Makefile.am +++ b/programs/Makefile.am @@ -1,19 +1,8 @@ NULL = -if ENABLE_BASHCOMP -SUBDIRS = completion -endif +bin_in_files = program.in -AM_CPPFLAGS = \ - -I$(top_srcdir) \ - -I$(top_builddir) \ - $(GLIB_CFLAGS) \ - -DGVFS_LOCALEDIR=\""$(localedir)"\" - -libraries = \ - $(GLIB_LIBS) - -bin_PROGRAMS = \ +bin_SCRIPTS = \ gvfs-mount \ gvfs-cat \ gvfs-open \ @@ -31,61 +20,58 @@ bin_PROGRAMS = \ gvfs-monitor-dir \ gvfs-mkdir \ gvfs-mime \ - $(NULL) - -bin_SCRIPTS = \ gvfs-less \ $(NULL) -gvfs_cat_SOURCES = gvfs-cat.c -gvfs_cat_LDADD = $(libraries) +gvfs-mount: deprecated.in Makefile + $(AM_V_GEN) $(SED) -e "s|\@replacement\@|gio mount|" $< > $@ -gvfs_open_SOURCES = gvfs-open.c -gvfs_open_LDADD = $(libraries) +gvfs-cat: deprecated.in Makefile + $(AM_V_GEN) $(SED) -e "s|\@replacement\@|gio cat|" $< > $@ -gvfs_copy_SOURCES = gvfs-copy.c -gvfs_copy_LDADD = $(libraries) +gvfs-open: deprecated.in Makefile + $(AM_V_GEN) $(SED) -e "s|\@replacement\@|gio open|" $< > $@ -gvfs_save_SOURCES = gvfs-save.c -gvfs_save_LDADD = $(libraries) +gvfs-save: deprecated.in Makefile + $(AM_V_GEN) $(SED) -e "s|\@replacement\@|gio save|" $< > $@ -gvfs_info_SOURCES = gvfs-info.c -gvfs_info_LDADD = $(libraries) +gvfs-ls: deprecated.in Makefile + $(AM_V_GEN) $(SED) -e "s|\@replacement\@|gio list|" $< > $@ -gvfs_set_attribute_SOURCES = gvfs-set-attribute.c -gvfs_set_attribute_LDADD = $(libraries) +gvfs-tree: deprecated.in Makefile + $(AM_V_GEN) $(SED) -e "s|\@replacement\@|gio tree|" $< > $@ -gvfs_trash_SOURCES = gvfs-trash.c -gvfs_trash_LDADD = $(libraries) +gvfs-info: deprecated.in Makefile + $(AM_V_GEN) $(SED) -e "s|\@replacement\@|gio info|" $< > $@ -gvfs_rename_SOURCES = gvfs-rename.c -gvfs_rename_LDADD = $(libraries) +gvfs-set-attribute: deprecated.in Makefile + $(AM_V_GEN) $(SED) -e "s|\@replacement\@|gio set|" $< > $@ -gvfs_rm_SOURCES = gvfs-rm.c -gvfs_rm_LDADD = $(libraries) +gvfs-trash: deprecated.in Makefile + $(AM_V_GEN) $(SED) -e "s|\@replacement\@|gio trash|" $< > $@ -gvfs_ls_SOURCES = gvfs-ls.c -gvfs_ls_LDADD = $(libraries) +gvfs-rename: deprecated.in Makefile + $(AM_V_GEN) $(SED) -e "s|\@replacement\@|gio rename|" $< > $@ -gvfs_tree_SOURCES = gvfs-tree.c -gvfs_tree_LDADD = $(libraries) +gvfs-rm: deprecated.in Makefile + $(AM_V_GEN) $(SED) -e "s|\@replacement\@|gio remove|" $< > $@ -gvfs_move_SOURCES = gvfs-move.c -gvfs_move_LDADD = $(libraries) +gvfs-copy: deprecated.in Makefile + $(AM_V_GEN) $(SED) -e "s|\@replacement\@|gio copy|" $< > $@ -gvfs_mount_SOURCES = gvfs-mount.c -gvfs_mount_LDADD = $(libraries) +gvfs-move: deprecated.in Makefile + $(AM_V_GEN) $(SED) -e "s|\@replacement\@|gio move|" $< > $@ -gvfs_monitor_dir_SOURCES = gvfs-monitor-dir.c -gvfs_monitor_dir_LDADD = $(libraries) +gvfs-monitor-file: deprecated.in Makefile + $(AM_V_GEN) $(SED) -e "s|\@replacement\@|gio monitor|" $< > $@ -gvfs_monitor_file_SOURCES = gvfs-monitor-file.c -gvfs_monitor_file_LDADD = $(libraries) +gvfs-monitor-dir: deprecated.in Makefile + $(AM_V_GEN) $(SED) -e "s|\@replacement\@|gio monitor|" $< > $@ -gvfs_mkdir_SOURCES = gvfs-mkdir.c -gvfs_mkdir_LDADD = $(libraries) +gvfs-mkdir: deprecated.in Makefile + $(AM_V_GEN) $(SED) -e "s|\@replacement\@|gio mkdir|" $< > $@ -gvfs_mime_SOURCES = gvfs-mime.c -gvfs_mime_LDADD = $(libraries) +gvfs-mime: deprecated.in Makefile + $(AM_V_GEN) $(SED) -e "s|\@replacement\@|gio mime|" $< > $@ -EXTRA_DIST = gvfs-less +EXTRA_DIST = $(bin_in_files) diff --git a/programs/completion/Makefile.am b/programs/completion/Makefile.am deleted file mode 100644 index 0bf3a62a..00000000 --- a/programs/completion/Makefile.am +++ /dev/null @@ -1,41 +0,0 @@ -NULL = - -bashcompdir = $(BASHCOMP_DIR) -bashcomp_DATA = gvfs-cat - -EXTRA_DIST = $(bashcomp_DATA) - -.PHONY = install-symlinks uninstall-symlinks - -symlinks = \ - gvfs-copy \ - gvfs-info \ - gvfs-less \ - gvfs-ls \ - gvfs-mkdir \ - gvfs-monitor-dir \ - gvfs-monitor-file \ - gvfs-mount \ - gvfs-move \ - gvfs-open \ - gvfs-rename \ - gvfs-rm \ - gvfs-save \ - gvfs-set-attribute \ - gvfs-trash \ - gvfs-tree \ - $(NULL) - -install-symlinks: - set -e; for file in $(symlinks); do \ - $(LN_S) -f gvfs-cat $(DESTDIR)$(BASHCOMP_DIR)/$$file; \ - done - -uninstall-symlinks: - set -e; for file in $(symlinks); do \ - rm -f $(DESTDIR)$(BASHCOMP_DIR)/$$file; \ - done - -install-data-hook: install-symlinks - -uninstall-local: uninstall-symlinks diff --git a/programs/completion/gvfs-cat b/programs/completion/gvfs-cat deleted file mode 100755 index 30be46d3..00000000 --- a/programs/completion/gvfs-cat +++ /dev/null @@ -1,57 +0,0 @@ -# Copyright (C) 2006-2007 Red Hat, Inc. -# -# This library is free software; you can redistribute it and/or modify -# it under the terms of the GNU Lesser 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 -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, -# USA. -# -# Author: David Zeuthen <davidz@redhat.com> - -# Check for bash -[ -z "$BASH_VERSION" ] && return - -#################################################################################################### - - -__gvfs_multiple_uris() { - local IFS=$'\n' - local cur - _get_comp_words_by_ref -n : cur - - COMPREPLY=($(compgen -W '$(gvfs-ls --show-completions "$cur")' -- "")) - - # don't misbehave on colons; See item E13 at http://tiswww.case.edu/php/chet/bash/FAQ - # The macro below handles this by extracting any BLAH: prefix and removing it from the result. - # Not great, but better than globally changing COMP_WORDBREAKS - __ltrim_colon_completions "$cur" -} - -#################################################################################################### - -complete -o nospace -F __gvfs_multiple_uris gvfs-ls -complete -o nospace -F __gvfs_multiple_uris gvfs-info -complete -o nospace -F __gvfs_multiple_uris gvfs-cat -complete -o nospace -F __gvfs_multiple_uris gvfs-less -complete -o nospace -F __gvfs_multiple_uris gvfs-copy -complete -o nospace -F __gvfs_multiple_uris gvfs-mkdir -complete -o nospace -F __gvfs_multiple_uris gvfs-monitor-dir -complete -o nospace -F __gvfs_multiple_uris gvfs-monitor-file -complete -o nospace -F __gvfs_multiple_uris gvfs-mount -complete -o nospace -F __gvfs_multiple_uris gvfs-move -complete -o nospace -F __gvfs_multiple_uris gvfs-open -complete -o nospace -F __gvfs_multiple_uris gvfs-rename -complete -o nospace -F __gvfs_multiple_uris gvfs-rm -complete -o nospace -F __gvfs_multiple_uris gvfs-save -complete -o nospace -F __gvfs_multiple_uris gvfs-set-attribute -complete -o nospace -F __gvfs_multiple_uris gvfs-trash -complete -o nospace -F __gvfs_multiple_uris gvfs-tree diff --git a/programs/deprecated.in b/programs/deprecated.in new file mode 100644 index 00000000..70d0b832 --- /dev/null +++ b/programs/deprecated.in @@ -0,0 +1,6 @@ +#!/bin/sh +replacement="@replacement@" +>&2 echo "This tool has been deprecated, use '$replacement' instead." +>&2 echo "See 'gio help' for more info." +>&2 echo +exec $replacement "$@" diff --git a/programs/gvfs-cat.c b/programs/gvfs-cat.c deleted file mode 100644 index cd0f9111..00000000 --- a/programs/gvfs-cat.c +++ /dev/null @@ -1,206 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Author: Alexander Larsson <alexl@redhat.com> - */ - -#include <config.h> - -#include <stdio.h> -#include <unistd.h> -#include <locale.h> -#include <errno.h> - -#include <glib.h> -#include <glib/gi18n.h> -#include <gio/gio.h> - -static gboolean show_version = FALSE; -static gchar **locations = NULL; - -static GOptionEntry entries[] = { - { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program version"), NULL }, - { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &locations, NULL, NULL }, - { NULL } -}; - -static gboolean -cat (GFile * file) -{ - GInputStream *in; - char buffer[1024 * 8 + 1]; - char *p; - gssize res; - gboolean close_res; - GError *error; - gboolean success; - - error = NULL; - in = (GInputStream *) g_file_read (file, NULL, &error); - if (in == NULL) - { - /* Translators: the first %s is the program name, the second one */ - /* is the URI of the file, the third is the error message. */ - g_printerr (_("%s: %s: error opening file: %s\n"), - g_get_prgname (), g_file_get_uri (file), error->message); - g_error_free (error); - return FALSE; - } - - success = TRUE; - while (1) - { - res = - g_input_stream_read (in, buffer, sizeof (buffer) - 1, NULL, &error); - if (res > 0) - { - ssize_t written; - - p = buffer; - while (res > 0) - { - written = write (STDOUT_FILENO, p, res); - - if (written == -1 && errno != EINTR) - { - /* Translators: the first %s is the program name, the */ - /* second one is the URI of the file. */ - g_printerr (_("%s: %s, error writing to stdout"), - g_get_prgname (), g_file_get_uri (file)); - success = FALSE; - goto out; - } - res -= written; - p += written; - } - } - else if (res < 0) - { - /* Translators: the first %s is the program name, the second one */ - /* is the URI of the file, the third is the error message. */ - g_printerr (_("%s: %s: error reading: %s\n"), - g_get_prgname (), g_file_get_uri (file), - error->message); - g_error_free (error); - error = NULL; - success = FALSE; - break; - } - else if (res == 0) - break; - } - - out: - - close_res = g_input_stream_close (in, NULL, &error); - if (!close_res) - { - /* Translators: the first %s is the program name, the second one */ - /* is the URI of the file, the third is the error message. */ - g_printerr (_("%s: %s: error closing: %s\n"), - g_get_prgname (), g_file_get_uri (file), error->message); - g_error_free (error); - success = FALSE; - } - - return success; -} - -int -main (int argc, char *argv[]) -{ - GError *error = NULL; - GOptionContext *context = NULL; - GFile *file; - gchar *summary; - gchar *description; - int i; - gchar *param; - gboolean res; - - setlocale (LC_ALL, ""); - - bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - param = g_strdup_printf (("%s..."), _("FILE")); - /* Translators: this message will appear after the usage string */ - /* and before the list of options. */ - summary = _("Concatenate files and print to the standard output."); - description = g_strconcat (_("gvfs-cat works just like the traditional cat utility, but using gvfs\n" - "locations instead of local files: for example you can use something\n" - "like smb://server/resource/file.txt as location."), - "\n\n", - _("Note: just pipe through cat if you need its formatting options\n" - "like -n, -T or other."), - NULL); - - context = g_option_context_new (param); - g_option_context_set_summary (context, summary); - g_option_context_set_description (context, description); - - g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); - g_option_context_parse (context, &argc, &argv, &error); - - g_option_context_free (context); - g_free (param); - g_free (description); - - if (error != NULL) - { - g_printerr (_("Error parsing commandline options: %s\n"), error->message); - g_printerr ("\n"); - g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); - g_printerr ("\n"); - g_error_free (error); - return 1; - } - - if (show_version) - { - g_print (PACKAGE_STRING "\n"); - return 0; - } - - if (!locations) - { - /* Translators: the %s is the program name. This error message */ - /* means the user is calling gvfs-cat without any argument. */ - g_printerr (_("%s: missing locations"), g_get_prgname ()); - g_printerr ("\n"); - g_printerr (_("Try \"%s --help\" for more information."), - g_get_prgname ()); - g_printerr ("\n"); - return 1; - } - - res = TRUE; - i = 0; - - do - { - file = g_file_new_for_commandline_arg (locations[i]); - res = cat (file) && res; - g_object_unref (file); - } - while (locations[++i] != NULL); - - return res ? 0 : 2; -} diff --git a/programs/gvfs-copy.c b/programs/gvfs-copy.c deleted file mode 100644 index d4f56c81..00000000 --- a/programs/gvfs-copy.c +++ /dev/null @@ -1,252 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Author: Alexander Larsson <alexl@redhat.com> - */ - -#include <config.h> - -#include <stdio.h> -#include <unistd.h> -#include <locale.h> -#include <errno.h> -#include <string.h> - -#include <glib.h> -#include <glib/gi18n.h> -#include <gio/gio.h> - -static gboolean progress = FALSE; -static gboolean interactive = FALSE; -static gboolean no_dereference = FALSE; -static gboolean backup = FALSE; -static gboolean preserve = FALSE; -static gboolean no_target_directory = FALSE; -static gboolean show_version = FALSE; - -static GOptionEntry entries[] = -{ - { "no-target-directory", 'T', 0, G_OPTION_ARG_NONE, &no_target_directory, N_("No target directory"), NULL }, - { "progress", 'p', 0, G_OPTION_ARG_NONE, &progress, N_("Show progress"), NULL }, - { "interactive", 'i', 0, G_OPTION_ARG_NONE, &interactive, N_("Prompt before overwrite"), NULL }, - { "preserve", 'p', 0, G_OPTION_ARG_NONE, &preserve, N_("Preserve all attributes"), NULL }, - { "backup", 'b', 0, G_OPTION_ARG_NONE, &backup, N_("Backup existing destination files"), NULL }, - { "no-dereference", 'P', 0, G_OPTION_ARG_NONE, &no_dereference, N_("Never follow symbolic links"), NULL }, - { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program version"), NULL }, - { NULL } -}; - -static gboolean -is_dir (GFile *file) -{ - GFileInfo *info; - gboolean res; - - info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, 0, NULL, NULL); - res = info && g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY; - if (info) - g_object_unref (info); - return res; -} - -static gint64 start_time; -static gint64 previous_time; -static void -show_progress (goffset current_num_bytes, - goffset total_num_bytes, - gpointer user_data) -{ - gint64 tv; - char *current_size, *total_size, *rate; - - tv = g_get_monotonic_time (); - if (tv - previous_time < (G_USEC_PER_SEC / 5) && - current_num_bytes != total_num_bytes) - return; - - current_size = g_format_size (current_num_bytes); - total_size = g_format_size (total_num_bytes); - rate = g_format_size (current_num_bytes / - MAX ((tv - start_time) / G_USEC_PER_SEC, 1)); - g_print ("\r\033[K"); - g_print (_("Transferred %s out of %s (%s/s)"), - current_size, total_size, rate); - - previous_time = tv; - - g_free (current_size); - g_free (total_size); - g_free (rate); -} - -static void -show_help (GOptionContext *context, const char *error) -{ - char *help; - - if (error) - g_printerr (_("Error: %s"), error); - - help = g_option_context_get_help (context, TRUE, NULL); - g_printerr ("%s", help); - g_free (help); - g_option_context_free (context); -} - -int -main (int argc, char *argv[]) -{ - GError *error; - GOptionContext *context; - GFile *source, *dest, *target; - gboolean dest_is_dir; - char *basename; - char *uri; - int i; - GFileCopyFlags flags; - int retval = 0; - char *param; - char *summary; - - setlocale (LC_ALL, ""); - - bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - error = NULL; - param = g_strdup_printf ("%s... %s", _("SOURCE"), _("DEST")); - summary = _("Copy one or more files from SOURCE to DEST."); - - context = g_option_context_new (param); - g_option_context_set_summary (context, summary); - g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); - g_option_context_parse (context, &argc, &argv, &error); - - if (error != NULL) - { - g_printerr (_("Error parsing commandline options: %s\n"), error->message); - g_printerr ("\n"); - g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); - g_printerr ("\n"); - g_error_free (error); - return 1; - } - - if (show_version) - { - g_print (PACKAGE_STRING "\n"); - return 0; - } - - if (argc <= 2) - { - show_help (context, _("Missing operand\n")); - return 1; - } - - dest = g_file_new_for_commandline_arg (argv[argc-1]); - - if (no_target_directory && argc > 3) - { - show_help (context, _("Too many arguments\n")); - g_object_unref (dest); - return 1; - } - - dest_is_dir = is_dir (dest); - - if (!dest_is_dir && argc > 3) - { - g_printerr (_("Target %s is not a directory\n"), argv[argc-1]); - show_help (context, NULL); - g_object_unref (dest); - return 1; - } - - g_option_context_free (context); - g_free (param); - - for (i = 1; i < argc - 1; i++) - { - source = g_file_new_for_commandline_arg (argv[i]); - - if (dest_is_dir && !no_target_directory) - { - basename = g_file_get_basename (source); - target = g_file_get_child (dest, basename); - g_free (basename); - } - else - target = g_object_ref (dest); - - flags = 0; - if (backup) - flags |= G_FILE_COPY_BACKUP; - if (!interactive) - flags |= G_FILE_COPY_OVERWRITE; - if (no_dereference) - flags |= G_FILE_COPY_NOFOLLOW_SYMLINKS; - if (preserve) - flags |= G_FILE_COPY_ALL_METADATA; - - - error = NULL; - start_time = g_get_monotonic_time (); - if (!g_file_copy (source, target, flags, NULL, progress?show_progress:NULL, NULL, &error)) - { - if (interactive && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) - { - char line[16]; - - g_error_free (error); - error = NULL; - - uri = g_file_get_uri (target); - g_print (_("%s: overwrite ā%sā? "), argv[0], uri); - g_free (uri); - - if (fgets(line, sizeof (line), stdin) && - (line[0] == 'y' || line[0] == 'Y')) - { - flags |= G_FILE_COPY_OVERWRITE; - start_time = g_get_monotonic_time (); - if (!g_file_copy (source, target, flags, NULL, progress?show_progress:NULL, NULL, &error)) - goto copy_failed; - } - } - else - { - copy_failed: - g_printerr (_("Error copying file %s: %s\n"), argv[i], error->message); - g_error_free (error); - retval = 1; - } - } - if (progress && retval == 0) - g_print("\n"); - - g_object_unref (source); - g_object_unref (target); - } - - g_object_unref (dest); - - return retval; -} diff --git a/programs/gvfs-info.c b/programs/gvfs-info.c deleted file mode 100644 index 1462fef1..00000000 --- a/programs/gvfs-info.c +++ /dev/null @@ -1,426 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Author: Alexander Larsson <alexl@redhat.com> - */ - -#include <config.h> - -#include <glib.h> -#include <locale.h> -#include <glib/gi18n.h> -#include <gio/gio.h> - -static char *attributes = NULL; -static gboolean nofollow_symlinks = FALSE; -static gboolean filesystem = FALSE; -static gboolean writable = FALSE; -static gboolean show_version = FALSE; - -static GOptionEntry entries[] = -{ - { "query-writable", 'w', 0, G_OPTION_ARG_NONE, &writable, N_("List writable attributes"), NULL }, - { "filesystem", 'f', 0, G_OPTION_ARG_NONE, &filesystem, N_("Get file system info"), NULL }, - { "attributes", 'a', 0, G_OPTION_ARG_STRING, &attributes, N_("The attributes to get"), N_("ATTRIBUTES") }, - { "nofollow-symlinks", 'n', 0, G_OPTION_ARG_NONE, &nofollow_symlinks, N_("Don't follow symbolic links"), NULL }, - { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program version"), NULL }, - { NULL } -}; - -static const char * -type_to_string (GFileType type) -{ - switch (type) - { - default: - return _("invalid type"); - - case G_FILE_TYPE_UNKNOWN: - return _("unknown"); - - case G_FILE_TYPE_REGULAR: - return _("regular"); - - case G_FILE_TYPE_DIRECTORY: - return _("directory"); - - case G_FILE_TYPE_SYMBOLIC_LINK: - return _("symlink"); - - case G_FILE_TYPE_SPECIAL: - return _("special"); - - case G_FILE_TYPE_SHORTCUT: - return _("shortcut"); - - case G_FILE_TYPE_MOUNTABLE: - return _("mountable"); - } -} - -static char * -escape_string (const char *in) -{ - GString *str; - static char *hex_digits = "0123456789abcdef"; - unsigned char c; - - - str = g_string_new (""); - - while ((c = *in++) != 0) - { - if (c >= 32 && c <= 126 && c != '\\') - g_string_append_c (str, c); - else - { - g_string_append (str, "\\x"); - g_string_append_c (str, hex_digits[(c >> 4) & 0xf]); - g_string_append_c (str, hex_digits[c & 0xf]); - } - } - - return g_string_free (str, FALSE); -} - -static void -show_attributes (GFileInfo *info) -{ - char **attributes; - char *s; - int i; - - attributes = g_file_info_list_attributes (info, NULL); - - g_print (_("attributes:\n")); - for (i = 0; attributes[i] != NULL; i++) - { - /* list the icons in order rather than displaying "GThemedIcon:0x8df7200" */ - if (strcmp (attributes[i], "standard::icon") == 0 || - strcmp (attributes[i], "standard::symbolic-icon") == 0) - { - GIcon *icon; - int j; - const char * const *names = NULL; - - if (strcmp (attributes[i], "standard::symbolic-icon") == 0) - icon = g_file_info_get_symbolic_icon (info); - else - icon = g_file_info_get_icon (info); - - /* only look up names if GThemedIcon */ - if (G_IS_THEMED_ICON(icon)) - { - names = g_themed_icon_get_names (G_THEMED_ICON (icon)); - g_print (" %s: ", attributes[i]); - for (j = 0; names[j] != NULL; j++) - g_print ("%s%s", names[j], (names[j+1] == NULL)?"":", "); - g_print ("\n"); - } - else - { - s = g_file_info_get_attribute_as_string (info, attributes[i]); - g_print (" %s: %s\n", attributes[i], s); - g_free (s); - } - } - else - { - s = g_file_info_get_attribute_as_string (info, attributes[i]); - g_print (" %s: %s\n", attributes[i], s); - g_free (s); - } - } - g_strfreev (attributes); -} - -static void -show_info (GFile *file, GFileInfo *info) -{ - const char *name, *type; - char *escaped, *uri; - goffset size; - - name = g_file_info_get_display_name (info); - if (name) - /* Translators: This is a noun and represents and attribute of a file */ - g_print (_("display name: %s\n"), name); - - name = g_file_info_get_edit_name (info); - if (name) - /* Translators: This is a noun and represents and attribute of a file */ - g_print (_("edit name: %s\n"), name); - - name = g_file_info_get_name (info); - if (name) - { - escaped = escape_string (name); - g_print (_("name: %s\n"), escaped); - g_free (escaped); - } - - if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_TYPE)) - { - type = type_to_string (g_file_info_get_file_type (info)); - g_print (_("type: %s\n"), type); - } - - if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_SIZE)) - { - size = g_file_info_get_size (info); - g_print (_("size: ")); - g_print (" %"G_GUINT64_FORMAT"\n", (guint64)size); - } - - if (g_file_info_get_is_hidden (info)) - g_print (_("hidden\n")); - - uri = g_file_get_uri (file); - g_print (_("uri: %s\n"), uri); - g_free (uri); - - show_attributes (info); -} - -static gboolean -query_info (GFile *file) -{ - GFileQueryInfoFlags flags; - GFileInfo *info; - GError *error; - - if (file == NULL) - return FALSE; - - if (attributes == NULL) - attributes = "*"; - - flags = 0; - if (nofollow_symlinks) - flags |= G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS; - - error = NULL; - if (filesystem) - info = g_file_query_filesystem_info (file, attributes, NULL, &error); - else - info = g_file_query_info (file, attributes, flags, NULL, &error); - - if (info == NULL) - { - g_printerr ("Error getting info: %s\n", error->message); - g_error_free (error); - return FALSE; - } - - if (filesystem) - show_attributes (info); - else - show_info (file, info); - - g_object_unref (info); - - return TRUE; -} - -static char * -attribute_type_to_string (GFileAttributeType type) -{ - switch (type) - { - case G_FILE_ATTRIBUTE_TYPE_INVALID: - return "invalid"; - case G_FILE_ATTRIBUTE_TYPE_STRING: - return "string"; - case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING: - return "bytestring"; - case G_FILE_ATTRIBUTE_TYPE_BOOLEAN: - return "boolean"; - case G_FILE_ATTRIBUTE_TYPE_UINT32: - return "uint32"; - case G_FILE_ATTRIBUTE_TYPE_INT32: - return "int32"; - case G_FILE_ATTRIBUTE_TYPE_UINT64: - return "uint64"; - case G_FILE_ATTRIBUTE_TYPE_INT64: - return "int64"; - case G_FILE_ATTRIBUTE_TYPE_OBJECT: - return "object"; - default: - return "uknown type"; - } -} - -static char * -attribute_flags_to_string (GFileAttributeInfoFlags flags) -{ - GString *s; - int i; - gboolean first; - struct { - guint32 mask; - char *descr; - } flag_descr[] = { - { - G_FILE_ATTRIBUTE_INFO_COPY_WITH_FILE, - N_("Copy with file") - }, - { - G_FILE_ATTRIBUTE_INFO_COPY_WHEN_MOVED, - N_("Keep with file when moved") - } - }; - - first = TRUE; - - s = g_string_new (""); - for (i = 0; i < G_N_ELEMENTS (flag_descr); i++) - { - if (flags & flag_descr[i].mask) - { - if (!first) - g_string_append (s, ", "); - g_string_append (s, gettext (flag_descr[i].descr)); - first = FALSE; - } - } - - return g_string_free (s, FALSE); -} - -static gboolean -get_writable_info (GFile *file) -{ - GFileAttributeInfoList *list; - GError *error; - int i; - char *flags; - - if (file == NULL) - return FALSE; - - error = NULL; - - list = g_file_query_settable_attributes (file, NULL, &error); - if (list == NULL) - { - g_printerr (_("Error getting writable attributes: %s\n"), error->message); - g_error_free (error); - return FALSE; - } - - g_print (_("Settable attributes:\n")); - for (i = 0; i < list->n_infos; i++) - { - flags = attribute_flags_to_string (list->infos[i].flags); - g_print (" %s (%s%s%s)\n", - list->infos[i].name, - attribute_type_to_string (list->infos[i].type), - (*flags != 0)?", ":"", flags); - g_free (flags); - } - - g_file_attribute_info_list_unref (list); - - list = g_file_query_writable_namespaces (file, NULL, &error); - if (list == NULL) - { - g_printerr ("Error getting writable namespaces: %s\n", error->message); - g_error_free (error); - return FALSE; - } - - if (list->n_infos > 0) - { - g_print (_("Writable attribute namespaces:\n")); - for (i = 0; i < list->n_infos; i++) - { - flags = attribute_flags_to_string (list->infos[i].flags); - g_print (" %s (%s%s%s)\n", - list->infos[i].name, - attribute_type_to_string (list->infos[i].type), - (*flags != 0)?", ":"", flags); - } - } - - g_file_attribute_info_list_unref (list); - - return TRUE; -} - - -int -main (int argc, char *argv[]) -{ - GError *error; - GOptionContext *context; - GFile *file; - gchar *param; - gchar *summary; - gboolean res; - - setlocale (LC_ALL, ""); - - bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - error = NULL; - param = g_strdup_printf ("[%s...]", _("LOCATION")); - summary = _("Show information about locations."); - - context = g_option_context_new (param); - g_option_context_set_summary (context, summary); - g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); - g_option_context_parse (context, &argc, &argv, &error); - g_option_context_free (context); - g_free (param); - - if (error != NULL) - { - g_printerr (_("Error parsing commandline options: %s\n"), error->message); - g_printerr ("\n"); - g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); - g_printerr ("\n"); - g_error_free (error); - return 1; - } - - if (show_version) - { - g_print (PACKAGE_STRING "\n"); - return 0; - } - - res = TRUE; - if (argc > 1) - { - int i; - - for (i = 1; i < argc; i++) { - file = g_file_new_for_commandline_arg (argv[i]); - if (writable) - res = get_writable_info (file) && res; - else - res = query_info (file) && res; - g_object_unref (file); - } - } - - return res ? 0 : 2; -} diff --git a/programs/gvfs-ls.c b/programs/gvfs-ls.c deleted file mode 100644 index 6e73aca1..00000000 --- a/programs/gvfs-ls.c +++ /dev/null @@ -1,482 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Author: Alexander Larsson <alexl@redhat.com> - */ - -#include <config.h> - -#include <glib.h> -#include <locale.h> -#include <string.h> -#include <glib/gi18n.h> -#include <gio/gio.h> - -static char *attributes = NULL; -static gboolean show_hidden = FALSE; -static gboolean show_long = FALSE; -static gboolean nofollow_symlinks = FALSE; -static char *show_completions = NULL; -static gboolean print_uris = FALSE; -static gboolean show_version = FALSE; - -static GOptionEntry entries[] = -{ - { "attributes", 'a', 0, G_OPTION_ARG_STRING, &attributes, N_("The attributes to get"), N_("ATTRIBUTES") }, - { "hidden", 'h', 0, G_OPTION_ARG_NONE, &show_hidden, N_("Show hidden files"), NULL }, - { "long", 'l', 0, G_OPTION_ARG_NONE, &show_long, N_("Use a long listing format"), NULL }, - { "show-completions", 'c', 0, G_OPTION_ARG_STRING, &show_completions, N_("Show completions"), N_("PREFIX") }, - { "nofollow-symlinks", 'n', 0, G_OPTION_ARG_NONE, &nofollow_symlinks, N_("Don't follow symbolic links"), NULL}, - { "print-uris", 'u', 0, G_OPTION_ARG_NONE, &print_uris, N_("Print full URIs"), NULL}, - { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program version"), NULL }, - { NULL } -}; - -static const char * -type_to_string (GFileType type) -{ - switch (type) - { - default: - return "invalid type"; - - case G_FILE_TYPE_UNKNOWN: - return "unknown"; - - case G_FILE_TYPE_REGULAR: - return "regular"; - - case G_FILE_TYPE_DIRECTORY: - return "directory"; - - case G_FILE_TYPE_SYMBOLIC_LINK: - return "symlink"; - - case G_FILE_TYPE_SPECIAL: - return "special"; - - case G_FILE_TYPE_SHORTCUT: - return "shortcut"; - - case G_FILE_TYPE_MOUNTABLE: - return "mountable"; - } -} - -static void -show_info (GFileInfo *info, GFile *parent) -{ - const char *name, *type; - char *uri; - goffset size; - char **attributes; - int i; - gboolean first_attr; - GFile *child; - - if ((g_file_info_get_is_hidden (info)) && !show_hidden) - return; - - name = g_file_info_get_name (info); - if (name == NULL) - name = ""; - - if (print_uris) { - child = g_file_get_child (parent, name); - uri = g_file_get_uri (child); - g_object_unref (child); - } - - size = g_file_info_get_size (info); - type = type_to_string (g_file_info_get_file_type (info)); - if (show_long) - g_print ("%s\t%"G_GUINT64_FORMAT"\t(%s)", print_uris? uri: name, (guint64)size, type); - else - g_print ("%s", print_uris? uri: name); - - if (print_uris) { - g_free (uri); - } - - first_attr = TRUE; - attributes = g_file_info_list_attributes (info, NULL); - for (i = 0 ; attributes[i] != NULL; i++) - { - char *val_as_string; - - if (!show_long || - strcmp (attributes[i], G_FILE_ATTRIBUTE_STANDARD_NAME) == 0 || - strcmp (attributes[i], G_FILE_ATTRIBUTE_STANDARD_SIZE) == 0 || - strcmp (attributes[i], G_FILE_ATTRIBUTE_STANDARD_TYPE) == 0 || - strcmp (attributes[i], G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN) == 0) - continue; - - if (first_attr) - { - g_print ("\t"); - first_attr = FALSE; - } - else - g_print (" "); - val_as_string = g_file_info_get_attribute_as_string (info, attributes[i]); - g_print ("%s=%s", attributes[i], val_as_string); - g_free (val_as_string); - } - - g_strfreev (attributes); - - g_print ("\n"); -} - -static gboolean -list (GFile *file) -{ - GFileEnumerator *enumerator; - GFileInfo *info; - GError *error; - gboolean res; - - if (file == NULL) - return FALSE; - - error = NULL; - enumerator = g_file_enumerate_children (file, - attributes, - nofollow_symlinks ? G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS : 0, - NULL, - &error); - if (enumerator == NULL) - { - g_printerr ("Error: %s\n", error->message); - g_error_free (error); - error = NULL; - return FALSE; - } - - res = TRUE; - while ((info = g_file_enumerator_next_file (enumerator, NULL, &error)) != NULL) - { - show_info (info, file); - - g_object_unref (info); - } - - if (error) - { - g_printerr (_("Error: %s\n"), error->message); - g_error_free (error); - error = NULL; - res = FALSE; - } - - if (!g_file_enumerator_close (enumerator, NULL, &error)) - { - g_printerr (_("Error: %s\n"), error->message); - g_error_free (error); - error = NULL; - res = FALSE; - } - - return res; -} - -static void -print_mounts (const char *prefix) -{ - GList *l; - GList *mounts; - GVolumeMonitor *volume_monitor; - - volume_monitor = g_volume_monitor_get (); - - mounts = g_volume_monitor_get_mounts (volume_monitor); - if (mounts != NULL) - { - for (l = mounts; l != NULL; l = l->next) - { - GMount *mount = l->data; - GFile *mount_root; - char *uri; - - mount_root = g_mount_get_root (mount); - uri = g_file_get_uri (mount_root); - if (prefix == NULL || - g_str_has_prefix (uri, prefix)) - g_print ("%s%s\n", uri, g_str_has_suffix (uri, "/") ? "" : "/"); - g_free (uri); - g_object_unref (mount_root); - g_object_unref (mount); - } - g_list_free (mounts); - } - g_object_unref (volume_monitor); - - if (prefix == NULL || g_str_has_prefix ("file:///", prefix)) - g_print ("file:///\n"); -} - -static char* -shell_quote (const gchar *unquoted_string) -{ - const gchar *p; - GString *dest; - - dest = g_string_new (""); - - p = unquoted_string; - - while (*p) - { - if (*p == ' ') - g_string_append (dest, "\\ "); - else if (*p == '\n') - g_string_append (dest, "^J"); - else if (*p == '\\') - g_string_append (dest, "\\\\"); - else if (*p == '\'') - g_string_append (dest, "\\'"); - else if (*p == '"') - g_string_append (dest, "\\\""); - else - g_string_append_c (dest, *p); - - ++p; - } - - return g_string_free (dest, FALSE); -} - -static void -show_completed_file (GFile *hit, - gboolean is_dir, - const char *arg) -{ - char *path, *cwd, *display, *t; - GFile *cwd_f; - GFile *home; - - if (g_file_is_native (hit) && !g_str_has_prefix (arg, "file://")) - { - cwd = g_get_current_dir (); - cwd_f = g_file_new_for_path (cwd); - g_free (cwd); - - home = g_file_new_for_path (g_get_home_dir ()); - - if ((g_file_has_prefix (hit, home) || - g_file_equal (hit, home)) && - arg[0] == '~') - { - t = g_file_get_relative_path (home, hit); - path = g_strconcat ("~", (t != NULL) ? "/": "", t, NULL); - g_free (t); - } - else if (g_file_has_prefix (hit, cwd_f) && - !g_path_is_absolute (arg)) - path = g_file_get_relative_path (cwd_f, hit); - else - path = g_file_get_path (hit); - - g_object_unref (cwd_f); - g_object_unref (home); - - display = shell_quote (path); - g_free (path); - } - else - display = g_file_get_uri (hit); - - g_print ("%s%s\n", display, (is_dir)?"/":""); - g_free (display); -} - -static void -print_completions (const char *arg) -{ - GFile *f; - GFile *parent; - char *basename; - char *unescaped, *t; - - unescaped = g_shell_unquote (arg, NULL); - if (unescaped == NULL) - unescaped = g_strdup (arg); - - if (*unescaped == '~') - { - t = unescaped; - unescaped = g_strconcat (g_get_home_dir(), t+1, NULL); - g_free (t); - } - - f = g_file_new_for_commandline_arg (unescaped); - - if (g_str_has_suffix (arg, "/") || *arg == 0) - { - parent = g_object_ref (f); - basename = g_strdup (""); - } - else - { - parent = g_file_get_parent (f); - basename = g_file_get_basename (f); - } - - if (parent == NULL || - strchr (arg, '/') == NULL || - !g_file_query_exists (parent, NULL)) - { - print_mounts (unescaped); - } - - if (parent != NULL) - { - GFileEnumerator *enumerator; - enumerator = g_file_enumerate_children (parent, - G_FILE_ATTRIBUTE_STANDARD_NAME "," - G_FILE_ATTRIBUTE_STANDARD_TYPE, - nofollow_symlinks ? G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS : 0, - NULL, - NULL); - if (enumerator != NULL) - { - GFileInfo *info; - - while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) - { - const char *name; - GFileType type; - - name = g_file_info_get_name (info); - type = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_STANDARD_TYPE); - if (name != NULL && g_str_has_prefix (name, basename)) - { - GFile *entry; - - entry = g_file_get_child (parent, name); - show_completed_file (entry, type == G_FILE_TYPE_DIRECTORY, arg); - g_object_unref (entry); - } - g_object_unref (info); - } - g_file_enumerator_close (enumerator, NULL, NULL); - } - g_object_unref (parent); - } - - g_object_unref (f); - g_free (basename); - g_free (unescaped); -} - -int -main (int argc, char *argv[]) -{ - GError *error; - GOptionContext *context; - GFile *file; - gchar *param; - gchar *summary; - gchar *description; - gboolean res; - - setlocale (LC_ALL, ""); - - bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - error = NULL; - param = g_strdup_printf ("[%s...]", _("LOCATION")); - summary = _("List the contents of the locations."); - description = _("gvfs-ls is similar to the traditional ls utility, but using gvfs\n" - "locations instead of local files: for example you can use something\n" - "like smb://server/resource/file.txt as location. File attributes can\n" - "be specified with their gvfs name, e.g. standard::icon."); - - context = g_option_context_new (param); - g_option_context_set_summary (context, summary); - g_option_context_set_description (context, description); - g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); - g_option_context_parse (context, &argc, &argv, &error); - g_option_context_free (context); - g_free (param); - - if (error != NULL) - { - g_printerr (_("Error parsing commandline options: %s\n"), error->message); - g_printerr ("\n"); - g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); - g_printerr ("\n"); - g_error_free (error); - return 1; - } - - if (show_version) - { - g_print (PACKAGE_STRING "\n"); - return 0; - } - - if (attributes != NULL) - { - /* asking for attributes implies -l; otherwise it won't get shown */ - show_long = TRUE; - } - - attributes = g_strconcat (G_FILE_ATTRIBUTE_STANDARD_NAME "," - G_FILE_ATTRIBUTE_STANDARD_TYPE "," - G_FILE_ATTRIBUTE_STANDARD_SIZE "," - G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN, - attributes != NULL ? "," : "", - attributes, - NULL); - - if (show_completions != NULL) - { - print_completions (show_completions); - return 0; - } - - res = TRUE; - if (argc > 1) - { - int i; - - for (i = 1; i < argc; i++) { - file = g_file_new_for_commandline_arg (argv[i]); - res = list (file) && res; - g_object_unref (file); - } - } - else - { - char *cwd; - - cwd = g_get_current_dir (); - file = g_file_new_for_path (cwd); - g_free (cwd); - res = list (file); - g_object_unref (file); - } - - g_free (attributes); - - return res ? 0 : 2; -} diff --git a/programs/gvfs-mime.c b/programs/gvfs-mime.c deleted file mode 100644 index 1eaf005a..00000000 --- a/programs/gvfs-mime.c +++ /dev/null @@ -1,197 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2011 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Author: Bastien Nocera <hadess@hadess.net> - */ - -#include "config.h" - -#include <glib.h> -#include <locale.h> -#include <glib/gi18n.h> -#include <gio/gio.h> -#include <gio/gdesktopappinfo.h> - -static gboolean query = FALSE; -static gboolean set = FALSE; -static gboolean show_version = FALSE; - -static GOptionEntry entries[] = -{ - { "query", 0, 0, G_OPTION_ARG_NONE, &query, N_("Query handler for mime-type"), NULL }, - { "set", 0, 0, G_OPTION_ARG_NONE, &set, N_("Set handler for mime-type"), NULL }, - { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program version"), NULL }, - { NULL } -}; - -static GAppInfo * -get_app_info_for_id (const char *id) -{ - GList *list, *l; - GAppInfo *ret_info; - - list = g_app_info_get_all (); - ret_info = NULL; - for (l = list; l != NULL; l = l->next) - { - GAppInfo *info; - - info = l->data; - if (ret_info == NULL && g_strcmp0 (g_app_info_get_id (info), id) == 0) - ret_info = info; - else - g_object_unref (info); - } - g_list_free (list); - - return ret_info; -} - -int -main (int argc, char *argv[]) -{ - GError *error; - GOptionContext *context; - const char *mimetype; - gchar *param; - gchar *summary; - - setlocale (LC_ALL, ""); - - bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - error = NULL; - param = g_strdup_printf ("%s [%s]", _("MIMETYPE"), _("HANDLER")); - summary = _("Get or set the handler for a mime-type."); - - context = g_option_context_new (param); - g_option_context_set_summary (context, summary); - g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); - g_option_context_parse (context, &argc, &argv, &error); - g_option_context_free (context); - g_free (param); - - if (error != NULL || (query == set && !show_version)) - { - g_printerr (_("Error parsing commandline options: %s\n"), - error ? error->message : _("Specify either --query or --set")); - g_printerr ("\n"); - g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); - g_printerr ("\n"); - if (error != NULL) - g_error_free (error); - return 1; - } - - if (show_version) - { - g_print (PACKAGE_STRING "\n"); - return 0; - } - - if (query && argc != 2) - { - g_printerr (_("Must specify a single mime-type.\n")); - g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); - g_printerr ("\n"); - return 1; - } - else if (set && argc != 3) - { - g_printerr (_("Must specify the mime-type followed by the default handler.\n")); - g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); - g_printerr ("\n"); - return 1; - } - - mimetype = argv[1]; - - if (query) - { - GAppInfo *info; - - info = g_app_info_get_default_for_type (mimetype, FALSE); - if (!info) - { - g_print (_("No default applications for '%s'\n"), mimetype); - } - else - { - GList *list, *l; - - g_print (_("Default application for '%s': %s\n"), mimetype, g_app_info_get_id (info)); - g_object_unref (info); - - list = g_app_info_get_all_for_type (mimetype); - if (list != NULL) - g_print (_("Registered applications:\n")); - else - g_print (_("No registered applications\n")); - for (l = list; l != NULL; l = l->next) - { - info = l->data; - g_print ("\t%s\n", g_app_info_get_id (info)); - g_object_unref (info); - } - g_list_free (list); - - list = g_app_info_get_recommended_for_type (mimetype); - if (list != NULL) - g_print (_("Recommended applications:\n")); - else - g_print (_("No recommended applications\n")); - for (l = list; l != NULL; l = l->next) - { - info = l->data; - g_print ("\t%s\n", g_app_info_get_id (info)); - g_object_unref (info); - } - g_list_free (list); - } - } - else if (set) - { - const char *handler; - GAppInfo *info; - - handler = argv[2]; - - info = get_app_info_for_id (handler); - if (info == NULL) - { - g_printerr (_("Failed to load info for handler '%s'\n"), handler); - return 1; - } - - if (g_app_info_set_as_default_for_type (info, mimetype, &error) == FALSE) - { - g_printerr (_("Failed to set '%s' as the default handler for '%s': %s\n"), - handler, mimetype, error->message); - g_error_free (error); - g_object_unref (info); - return 1; - } - g_print ("Set %s as the default for %s\n", g_app_info_get_id (info), mimetype); - g_object_unref (info); - } - - return 0; -} diff --git a/programs/gvfs-mkdir.c b/programs/gvfs-mkdir.c deleted file mode 100644 index 347034f3..00000000 --- a/programs/gvfs-mkdir.c +++ /dev/null @@ -1,115 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Author: Alexander Larsson <alexl@redhat.com> - */ - -#include <config.h> - -#include <glib.h> -#include <glib/gi18n.h> -#include <locale.h> -#include <gio/gio.h> - -static gboolean parent = FALSE; -static gboolean show_version = FALSE; - -static GOptionEntry entries[] = -{ - { "parent", 'p', 0, G_OPTION_ARG_NONE, &parent, N_("Create parent directories"), NULL }, - { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program version"), NULL }, - { NULL } -}; - - -int -main (int argc, char *argv[]) -{ - GError *error; - GOptionContext *context; - GFile *file; - int retval = 0; - gchar *param; - gchar *summary; - - setlocale (LC_ALL, ""); - - bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - error = NULL; - param = g_strdup_printf ("[%s...]", _("LOCATION")); - summary = _("Create directories."); - - context = g_option_context_new (param); - g_option_context_set_summary (context, summary); - g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); - g_option_context_parse (context, &argc, &argv, &error); - g_option_context_free (context); - g_free (param); - - if (error != NULL) - { - g_printerr (_("Error parsing commandline options: %s\n"), error->message); - g_printerr ("\n"); - g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); - g_printerr ("\n"); - g_error_free (error); - return 1; - } - - if (show_version) - { - g_print (PACKAGE_STRING "\n"); - return 0; - } - - if (argc > 1) - { - int i; - - for (i = 1; i < argc; i++) - { - file = g_file_new_for_commandline_arg (argv[i]); - error = NULL; - if (parent) - { - if (!g_file_make_directory_with_parents (file, NULL, &error)) - { - g_printerr (_("Error creating directory: %s\n"), error->message); - g_error_free (error); - retval = 1; - } - } - else - { - if (!g_file_make_directory (file, NULL, &error)) - { - g_printerr (_("Error creating directory: %s\n"), error->message); - g_error_free (error); - retval = 1; - } - g_object_unref (file); - } - } - } - - return retval; -} diff --git a/programs/gvfs-monitor-dir.c b/programs/gvfs-monitor-dir.c deleted file mode 100644 index 7479a636..00000000 --- a/programs/gvfs-monitor-dir.c +++ /dev/null @@ -1,175 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Author: Alexander Larsson <alexl@redhat.com> - */ - -#include <config.h> - -#include <stdio.h> -#include <unistd.h> -#include <locale.h> -#include <errno.h> - -#include <glib.h> -#include <glib/gi18n.h> -#include <gio/gio.h> - -static GMainLoop *main_loop; - -static gboolean dont_pair_moves = FALSE; -static gboolean show_version = FALSE; - -static GOptionEntry entries[] = { - { "no-pair", 'N', 0, G_OPTION_ARG_NONE, &dont_pair_moves, N_("Don't send single MOVED events"), NULL }, - { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program version"), NULL }, - { NULL } -}; - -static gboolean -dir_monitor_callback (GFileMonitor* monitor, - GFile* child, - GFile* other_file, - GFileMonitorEvent eflags) -{ - - char *name = g_file_get_parse_name (child); - - g_print ("Directory Monitor Event:\n"); - g_print ("Child = %s\n", name); - g_free (name); - - if (other_file) - { - name = g_file_get_parse_name (other_file); - g_print ("Other = %s\n", name); - g_free (name); - } - - switch (eflags) - { - case G_FILE_MONITOR_EVENT_CHANGED: - g_print ("Event = CHANGED\n"); - break; - case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: - g_print ("Event = CHANGES_DONE_HINT\n"); - break; - case G_FILE_MONITOR_EVENT_DELETED: - g_print ("Event = DELETED\n"); - break; - case G_FILE_MONITOR_EVENT_CREATED: - g_print ("Event = CREATED\n"); - break; - case G_FILE_MONITOR_EVENT_PRE_UNMOUNT: - g_print ("Event = PRE_UNMOUNT\n"); - break; - case G_FILE_MONITOR_EVENT_UNMOUNTED: - g_print ("Event = UNMOUNTED\n"); - break; - case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED: - g_print ("Event = ATTRIB CHANGED\n"); - break; - case G_FILE_MONITOR_EVENT_MOVED: - g_print ("Event = MOVED\n"); - break; - case G_FILE_MONITOR_EVENT_MOVED_IN: - g_print ("Event = MOVED IN\n"); - break; - case G_FILE_MONITOR_EVENT_MOVED_OUT: - g_print ("Event = MOVED OUT\n"); - break; - case G_FILE_MONITOR_EVENT_RENAMED: - g_print ("Event = RENAMED\n"); - break; - } - - return TRUE; -} - -int -main (int argc, char *argv[]) -{ - GFileMonitor* dmonitor; - GError *error; - GOptionContext *context; - GFile *file; - gchar *param; - gchar *summary; - - setlocale (LC_ALL, ""); - - bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - error = NULL; - param = g_strdup_printf ("[%s...]", _("LOCATION")); - summary = _("Monitor directories for changes."); - - context = g_option_context_new (param); - g_option_context_set_summary (context, summary); - g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); - g_option_context_parse (context, &argc, &argv, &error); - g_option_context_free (context); - g_free (param); - - if (error != NULL) - { - g_printerr (_("Error parsing commandline options: %s\n"), error->message); - g_printerr ("\n"); - g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); - g_printerr ("\n"); - g_error_free (error); - return 1; - } - - if (show_version) - { - g_print (PACKAGE_STRING "\n"); - return 0; - } - - if (argc > 1) - { - int i; - GFileMonitorFlags flags = G_FILE_MONITOR_WATCH_MOUNTS; - - if (!dont_pair_moves) - flags |= G_FILE_MONITOR_SEND_MOVED; - - for (i = 1; i < argc; i++) - { - file = g_file_new_for_commandline_arg (argv[i]); - dmonitor = g_file_monitor_directory (file, flags, NULL, NULL); - if (dmonitor != NULL) - g_signal_connect (dmonitor, "changed", (GCallback)dir_monitor_callback, NULL); - else - { - g_print ("Monitoring not supported for %s\n", argv[1]); - return 1; - } - } - } - - main_loop = g_main_loop_new (NULL, FALSE); - - g_main_loop_run (main_loop); - - return 0; -} diff --git a/programs/gvfs-monitor-file.c b/programs/gvfs-monitor-file.c deleted file mode 100644 index 4726cfc2..00000000 --- a/programs/gvfs-monitor-file.c +++ /dev/null @@ -1,167 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Author: Alexander Larsson <alexl@redhat.com> - */ - -#include <config.h> - -#include <stdio.h> -#include <unistd.h> -#include <locale.h> -#include <errno.h> - -#include <glib.h> -#include <glib/gi18n.h> -#include <gio/gio.h> - -static GMainLoop *main_loop; - -static gboolean dont_pair_moves = FALSE; -static gboolean show_version = FALSE; - -static GOptionEntry entries[] = { - { "no-pair", 'N', 0, G_OPTION_ARG_NONE, &dont_pair_moves, N_("Don't send single MOVED events"), NULL }, - { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program version"), NULL }, - { NULL } -}; - -static gboolean -file_monitor_callback (GFileMonitor* monitor, - GFile* child, - GFile* other_file, - GFileMonitorEvent eflags) -{ - char *name = g_file_get_parse_name (child); - g_print ("File Monitor Event:\n"); - g_print ("File = %s\n", name); - g_free (name); - - if (other_file) - { - name = g_file_get_parse_name (other_file); - g_print ("Other = %s\n", name); - g_free (name); - } - - switch (eflags) - { - case G_FILE_MONITOR_EVENT_CHANGED: - g_print ("Event = CHANGED\n"); - break; - case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT: - g_print ("Event = CHANGES_DONE_HINT\n"); - break; - case G_FILE_MONITOR_EVENT_DELETED: - g_print ("Event = DELETED\n"); - break; - case G_FILE_MONITOR_EVENT_CREATED: - g_print ("Event = CREATED\n"); - break; - case G_FILE_MONITOR_EVENT_UNMOUNTED: - g_print ("Event = UNMOUNTED\n"); - break; - case G_FILE_MONITOR_EVENT_PRE_UNMOUNT: - g_print ("Event = PRE_UNMOUNT\n"); - break; - case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED: - g_print ("Event = ATTRIB CHANGED\n"); - break; - case G_FILE_MONITOR_EVENT_MOVED: - g_print ("Event = MOVED\n"); - break; - case G_FILE_MONITOR_EVENT_MOVED_IN: - g_print ("Event = MOVED IN\n"); - break; - case G_FILE_MONITOR_EVENT_MOVED_OUT: - g_print ("Event = MOVED OUT\n"); - break; - case G_FILE_MONITOR_EVENT_RENAMED: - g_print ("Event = RENAMED\n"); - break; - } - - return TRUE; -} - -int -main (int argc, char *argv[]) -{ - GFileMonitor* fmonitor; - GError *error; - GOptionContext *context; - GFile *file; - gchar *param; - gchar *summary; - - setlocale (LC_ALL, ""); - - bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - error = NULL; - param = g_strdup_printf ("[%s...]", _("LOCATION")); - summary = _("Monitor files for changes."); - - context = g_option_context_new (param); - g_option_context_set_summary (context, summary); - g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); - g_option_context_parse (context, &argc, &argv, &error); - g_option_context_free (context); - g_free (param); - - if (error != NULL) - { - g_printerr (_("Error parsing commandline options: %s\n"), error->message); - g_printerr ("\n"); - g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); - g_printerr ("\n"); - g_error_free (error); - return 1; - } - - if (show_version) - { - g_print (PACKAGE_STRING "\n"); - return 0; - } - - if (argc > 1) - { - int i; - GFileMonitorFlags flags = G_FILE_MONITOR_WATCH_MOUNTS; - - if (!dont_pair_moves) - flags |= G_FILE_MONITOR_SEND_MOVED; - - for (i = 1; i < argc; i++) - { - file = g_file_new_for_commandline_arg (argv[i]); - fmonitor = g_file_monitor_file (file, flags, NULL, NULL); - g_signal_connect (fmonitor, "changed", (GCallback)file_monitor_callback, NULL); - } - } - - main_loop = g_main_loop_new (NULL, FALSE); - - g_main_loop_run (main_loop); - - return 0; -} diff --git a/programs/gvfs-mount.c b/programs/gvfs-mount.c deleted file mode 100644 index 208e6681..00000000 --- a/programs/gvfs-mount.c +++ /dev/null @@ -1,1203 +0,0 @@ -/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Author: Alexander Larsson <alexl@redhat.com> - */ - -#include <config.h> - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#include <glib.h> -#include <locale.h> -#include <glib/gi18n.h> -#include <gio/gio.h> - -#ifdef HAVE_TERMIOS_H -#include <termios.h> -#endif - -#define STDIN_FILENO 0 - -typedef enum { - MOUNT_OP_NONE, - MOUNT_OP_ASKED, - MOUNT_OP_ABORTED -} MountOpState; - -static int outstanding_mounts = 0; -static GMainLoop *main_loop; - - -static gboolean mount_mountable = FALSE; -static gboolean mount_unmount = FALSE; -static gboolean mount_eject = FALSE; -static gboolean force = FALSE; -static gboolean anonymous = FALSE; -static gboolean mount_list = FALSE; -static gboolean extra_detail = FALSE; -static gboolean mount_monitor = FALSE; -static const char *unmount_scheme = NULL; -static const char *mount_device_file = NULL; -static gboolean success = TRUE; -static gboolean show_version = FALSE; - - -static const GOptionEntry entries[] = -{ - { "mountable", 'm', 0, G_OPTION_ARG_NONE, &mount_mountable, N_("Mount as mountable"), NULL }, - { "device", 'd', 0, G_OPTION_ARG_STRING, &mount_device_file, N_("Mount volume with device file"), N_("DEVICE") }, - { "unmount", 'u', 0, G_OPTION_ARG_NONE, &mount_unmount, N_("Unmount"), NULL}, - { "eject", 'e', 0, G_OPTION_ARG_NONE, &mount_eject, N_("Eject"), NULL}, - { "unmount-scheme", 's', 0, G_OPTION_ARG_STRING, &unmount_scheme, N_("Unmount all mounts with the given scheme"), N_("SCHEME") }, - { "force", 'f', 0, G_OPTION_ARG_NONE, &force, N_("Ignore outstanding file operations when unmounting or ejecting"), NULL }, - { "anonymous", 'a', 0, G_OPTION_ARG_NONE, &anonymous, N_("Use an anonymous user when authenticating"), NULL }, - /* Translator: List here is a verb as in 'List all mounts' */ - { "list", 'l', 0, G_OPTION_ARG_NONE, &mount_list, N_("List"), NULL}, - { "monitor", 'o', 0, G_OPTION_ARG_NONE, &mount_monitor, N_("Monitor events"), NULL}, - { "detail", 'i', 0, G_OPTION_ARG_NONE, &extra_detail, N_("Show extra information"), NULL}, - { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program version"), NULL }, - { NULL } -}; - -static char * -prompt_for (const char *prompt, const char *default_value, gboolean echo) -{ -#ifdef HAVE_TERMIOS_H - struct termios term_attr; - int old_flags; - gboolean restore_flags; -#endif - char data[256]; - int len; - - if (default_value && *default_value != 0) - g_print ("%s [%s]: ", prompt, default_value); - else - g_print ("%s: ", prompt); - - data[0] = 0; - -#ifdef HAVE_TERMIOS_H - restore_flags = FALSE; - if (!echo && tcgetattr (STDIN_FILENO, &term_attr) == 0) - { - old_flags = term_attr.c_lflag; - term_attr.c_lflag &= ~ECHO; - restore_flags = TRUE; - - if (tcsetattr (STDIN_FILENO, TCSAFLUSH, &term_attr) != 0) - g_print ("Warning! Password will be echoed"); - } - -#endif - - fgets(data, sizeof (data), stdin); - -#ifdef HAVE_TERMIOS_H - if (restore_flags) - { - term_attr.c_lflag = old_flags; - tcsetattr (STDIN_FILENO, TCSAFLUSH, &term_attr); - } -#endif - - len = strlen (data); - if (len == 0) - { - g_print ("\n"); - return NULL; - } - if (data[len-1] == '\n') - data[len-1] = 0; - - if (!echo) - g_print ("\n"); - - if (*data == 0 && default_value) - return g_strdup (default_value); - return g_strdup (data); -} - -static void -ask_password_cb (GMountOperation *op, - const char *message, - const char *default_user, - const char *default_domain, - GAskPasswordFlags flags) -{ - if ((flags & G_ASK_PASSWORD_ANONYMOUS_SUPPORTED) && anonymous) - { - g_mount_operation_set_anonymous (op, TRUE); - } - else - { - char *s; - g_print ("%s\n", message); - - if (flags & G_ASK_PASSWORD_NEED_USERNAME) - { - s = prompt_for ("User", default_user, TRUE); - if (!s) - goto error; - g_mount_operation_set_username (op, s); - g_free (s); - } - - if (flags & G_ASK_PASSWORD_NEED_DOMAIN) - { - s = prompt_for ("Domain", default_domain, TRUE); - if (!s) - goto error; - g_mount_operation_set_domain (op, s); - g_free (s); - } - - if (flags & G_ASK_PASSWORD_NEED_PASSWORD) - { - s = prompt_for ("Password", NULL, FALSE); - if (!s) - goto error; - g_mount_operation_set_password (op, s); - g_free (s); - } - } - - /* Only try anonymous access once. */ - if (anonymous && - GPOINTER_TO_INT (g_object_get_data (G_OBJECT (op), "state")) == MOUNT_OP_ASKED) - { - g_object_set_data (G_OBJECT (op), "state", GINT_TO_POINTER (MOUNT_OP_ABORTED)); - g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED); - } - else - { - g_object_set_data (G_OBJECT (op), "state", GINT_TO_POINTER (MOUNT_OP_ASKED)); - g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED); - } - - return; - -error: - g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED); -} - -static void -ask_question_cb (GMountOperation *op, - char *message, - char **choices, - gpointer user_data) -{ - char **ptr = choices; - char *s; - int i, choice; - - g_print ("%s\n", message); - - i = 1; - while (*ptr) - { - g_print ("[%d] %s\n", i, *ptr++); - i++; - } - - s = prompt_for ("Choice", NULL, TRUE); - if (!s) - goto error; - - choice = atoi (s); - if (choice > 0 && choice < i) - { - g_mount_operation_set_choice (op, choice - 1); - g_mount_operation_reply (op, G_MOUNT_OPERATION_HANDLED); - } - g_free (s); - - return; - -error: - g_mount_operation_reply (op, G_MOUNT_OPERATION_ABORTED); -} - -static void -mount_mountable_done_cb (GObject *object, - GAsyncResult *res, - gpointer user_data) -{ - GFile *target; - GError *error = NULL; - GMountOperation *op = user_data; - - target = g_file_mount_mountable_finish (G_FILE (object), res, &error); - - if (target == NULL) - { - success = FALSE; - if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (op), "state")) == MOUNT_OP_ABORTED) - g_printerr (_("Error mounting location: Anonymous access denied\n")); - else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED)) - g_printerr (_("Error mounting location: %s\n"), error->message); - } - else - g_object_unref (target); - - outstanding_mounts--; - - if (outstanding_mounts == 0) - g_main_loop_quit (main_loop); -} - -static void -mount_done_cb (GObject *object, - GAsyncResult *res, - gpointer user_data) -{ - gboolean succeeded; - GError *error = NULL; - GMountOperation *op = user_data; - - succeeded = g_file_mount_enclosing_volume_finish (G_FILE (object), res, &error); - - if (!succeeded) - { - success = FALSE; - if (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (op), "state")) == MOUNT_OP_ABORTED) - g_printerr (_("Error mounting location: Anonymous access denied\n")); - else if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_FAILED_HANDLED)) - g_printerr (_("Error mounting location: %s\n"), error->message); - } - - outstanding_mounts--; - - if (outstanding_mounts == 0) - g_main_loop_quit (main_loop); -} - -static GMountOperation * -new_mount_op (void) -{ - GMountOperation *op; - - op = g_mount_operation_new (); - - g_object_set_data (G_OBJECT (op), "state", GINT_TO_POINTER (MOUNT_OP_NONE)); - - g_signal_connect (op, "ask_password", G_CALLBACK (ask_password_cb), NULL); - g_signal_connect (op, "ask_question", G_CALLBACK (ask_question_cb), NULL); - - /* TODO: we *should* also connect to the "aborted" signal but since the - * main thread is blocked handling input we won't get that signal - * anyway... - */ - - return op; -} - - -static void -mount (GFile *file) -{ - GMountOperation *op; - - if (file == NULL) - return; - - op = new_mount_op (); - - if (mount_mountable) - g_file_mount_mountable (file, 0, op, NULL, mount_mountable_done_cb, op); - else - g_file_mount_enclosing_volume (file, 0, op, NULL, mount_done_cb, op); - - outstanding_mounts++; -} - -static void -unmount_done_cb (GObject *object, - GAsyncResult *res, - gpointer user_data) -{ - gboolean succeeded; - GError *error = NULL; - - succeeded = g_mount_unmount_with_operation_finish (G_MOUNT (object), res, &error); - - g_object_unref (G_MOUNT (object)); - - if (!succeeded) - { - g_printerr (_("Error unmounting mount: %s\n"), error->message); - success = FALSE; - } - - outstanding_mounts--; - - if (outstanding_mounts == 0) - g_main_loop_quit (main_loop); -} - -static void -unmount (GFile *file) -{ - GMount *mount; - GError *error = NULL; - GMountOperation *mount_op; - GMountUnmountFlags flags; - - if (file == NULL) - return; - - mount = g_file_find_enclosing_mount (file, NULL, &error); - if (mount == NULL) - { - g_printerr (_("Error finding enclosing mount: %s\n"), error->message); - success = FALSE; - return; - } - - mount_op = new_mount_op (); - flags = force ? G_MOUNT_UNMOUNT_FORCE : G_MOUNT_UNMOUNT_NONE; - g_mount_unmount_with_operation (mount, flags, mount_op, NULL, unmount_done_cb, NULL); - g_object_unref (mount_op); - - outstanding_mounts++; -} - -static void -eject_done_cb (GObject *object, - GAsyncResult *res, - gpointer user_data) -{ - gboolean succeeded; - GError *error = NULL; - - succeeded = g_mount_eject_with_operation_finish (G_MOUNT (object), res, &error); - - g_object_unref (G_MOUNT (object)); - - if (!succeeded) - { - g_printerr (_("Error ejecting mount: %s\n"), error->message); - success = FALSE; - } - - outstanding_mounts--; - - if (outstanding_mounts == 0) - g_main_loop_quit (main_loop); -} - -static void -eject (GFile *file) -{ - GMount *mount; - GError *error = NULL; - GMountOperation *mount_op; - GMountUnmountFlags flags; - - if (file == NULL) - return; - - mount = g_file_find_enclosing_mount (file, NULL, &error); - if (mount == NULL) - { - g_printerr (_("Error finding enclosing mount: %s\n"), error->message); - success = FALSE; - return; - } - - mount_op = new_mount_op (); - flags = force ? G_MOUNT_UNMOUNT_FORCE : G_MOUNT_UNMOUNT_NONE; - g_mount_eject_with_operation (mount, flags, mount_op, NULL, eject_done_cb, NULL); - g_object_unref (mount_op); - - outstanding_mounts++; -} - -/* =============== list mounts ================== */ - -static gboolean -iterate_gmain_timeout_function (gpointer data) -{ - g_main_loop_quit (main_loop); - return FALSE; -} - -static void -iterate_gmain(void) -{ - g_timeout_add (500, iterate_gmain_timeout_function, NULL); - g_main_loop_run (main_loop); -} - -static void -show_themed_icon_names (GThemedIcon *icon, gboolean symbolic, int indent) -{ - char **names; - char **iter; - - g_print ("%*s%sthemed icons:", indent, " ", symbolic ? "symbolic " : ""); - - names = NULL; - - g_object_get (icon, "names", &names, NULL); - - for (iter = names; *iter; iter++) - g_print (" [%s]", *iter); - - g_print ("\n"); - g_strfreev (names); -} - -/* don't copy-paste this code */ -static char * -get_type_name (gpointer object) -{ - const char *type_name; - char *ret; - - type_name = g_type_name (G_TYPE_FROM_INSTANCE (object)); - if (strcmp ("GProxyDrive", type_name) == 0) - { - ret = g_strdup_printf ("%s (%s)", - type_name, - (const char *) g_object_get_data (G_OBJECT (object), - "g-proxy-drive-volume-monitor-name")); - } - else if (strcmp ("GProxyVolume", type_name) == 0) - { - ret = g_strdup_printf ("%s (%s)", - type_name, - (const char *) g_object_get_data (G_OBJECT (object), - "g-proxy-volume-volume-monitor-name")); - } - else if (strcmp ("GProxyMount", type_name) == 0) - { - ret = g_strdup_printf ("%s (%s)", - type_name, - (const char *) g_object_get_data (G_OBJECT (object), - "g-proxy-mount-volume-monitor-name")); - } - else if (strcmp ("GProxyShadowMount", type_name) == 0) - { - ret = g_strdup_printf ("%s (%s)", - type_name, - (const char *) g_object_get_data (G_OBJECT (object), - "g-proxy-shadow-mount-volume-monitor-name")); - } - else - { - ret = g_strdup (type_name); - } - - return ret; -} - -static void -list_mounts (GList *mounts, - int indent, - gboolean only_with_no_volume) -{ - GList *l; - int c; - GMount *mount; - GVolume *volume; - char *name, *uuid, *uri; - GFile *root, *default_location; - GIcon *icon; - char **x_content_types; - char *type_name; - const gchar *sort_key; - - for (c = 0, l = mounts; l != NULL; l = l->next, c++) - { - mount = (GMount *) l->data; - - if (only_with_no_volume) - { - volume = g_mount_get_volume (mount); - if (volume != NULL) - { - g_object_unref (volume); - continue; - } - } - - name = g_mount_get_name (mount); - root = g_mount_get_root (mount); - uri = g_file_get_uri (root); - - g_print ("%*sMount(%d): %s -> %s\n", indent, "", c, name, uri); - - type_name = get_type_name (mount); - g_print ("%*sType: %s\n", indent+2, "", type_name); - g_free (type_name); - - if (extra_detail) - { - uuid = g_mount_get_uuid (mount); - if (uuid) - g_print ("%*suuid=%s\n", indent + 2, "", uuid); - - default_location = g_mount_get_default_location (mount); - if (default_location) - { - char *loc_uri = g_file_get_uri (default_location); - g_print ("%*sdefault_location=%s\n", indent + 2, "", loc_uri); - g_free (loc_uri); - g_object_unref (default_location); - } - - icon = g_mount_get_icon (mount); - if (icon) - { - if (G_IS_THEMED_ICON (icon)) - show_themed_icon_names (G_THEMED_ICON (icon), FALSE, indent + 2); - - g_object_unref (icon); - } - - icon = g_mount_get_symbolic_icon (mount); - if (icon) - { - if (G_IS_THEMED_ICON (icon)) - show_themed_icon_names (G_THEMED_ICON (icon), TRUE, indent + 2); - - g_object_unref (icon); - } - - x_content_types = g_mount_guess_content_type_sync (mount, FALSE, NULL, NULL); - if (x_content_types != NULL && g_strv_length (x_content_types) > 0) - { - int n; - g_print ("%*sx_content_types:", indent + 2, ""); - for (n = 0; x_content_types[n] != NULL; n++) - g_print (" %s", x_content_types[n]); - g_print ("\n"); - } - g_strfreev (x_content_types); - - g_print ("%*scan_unmount=%d\n", indent + 2, "", g_mount_can_unmount (mount)); - g_print ("%*scan_eject=%d\n", indent + 2, "", g_mount_can_eject (mount)); - g_print ("%*sis_shadowed=%d\n", indent + 2, "", g_mount_is_shadowed (mount)); - sort_key = g_mount_get_sort_key (mount); - if (sort_key != NULL) - g_print ("%*ssort_key=%s\n", indent + 2, "", sort_key); - g_free (uuid); - } - - g_object_unref (root); - g_free (name); - g_free (uri); - } -} - -static void -list_volumes (GList *volumes, - int indent, - gboolean only_with_no_drive) -{ - GList *l, *mounts; - int c, i; - GMount *mount; - GVolume *volume; - GDrive *drive; - char *name; - char *uuid; - GFile *activation_root; - char **ids; - GIcon *icon; - char *type_name; - const gchar *sort_key; - - for (c = 0, l = volumes; l != NULL; l = l->next, c++) - { - volume = (GVolume *) l->data; - - if (only_with_no_drive) - { - drive = g_volume_get_drive (volume); - if (drive != NULL) - { - g_object_unref (drive); - continue; - } - } - - name = g_volume_get_name (volume); - - g_print ("%*sVolume(%d): %s\n", indent, "", c, name); - g_free (name); - - type_name = get_type_name (volume); - g_print ("%*sType: %s\n", indent+2, "", type_name); - g_free (type_name); - - if (extra_detail) - { - ids = g_volume_enumerate_identifiers (volume); - if (ids && ids[0] != NULL) - { - g_print ("%*sids:\n", indent+2, ""); - for (i = 0; ids[i] != NULL; i++) - { - char *id = g_volume_get_identifier (volume, - ids[i]); - g_print ("%*s %s: '%s'\n", indent+2, "", ids[i], id); - g_free (id); - } - } - g_strfreev (ids); - - uuid = g_volume_get_uuid (volume); - if (uuid) - g_print ("%*suuid=%s\n", indent + 2, "", uuid); - activation_root = g_volume_get_activation_root (volume); - if (activation_root) - { - char *uri; - uri = g_file_get_uri (activation_root); - g_print ("%*sactivation_root=%s\n", indent + 2, "", uri); - g_free (uri); - g_object_unref (activation_root); - } - icon = g_volume_get_icon (volume); - if (icon) - { - if (G_IS_THEMED_ICON (icon)) - show_themed_icon_names (G_THEMED_ICON (icon), FALSE, indent + 2); - - g_object_unref (icon); - } - - icon = g_volume_get_symbolic_icon (volume); - if (icon) - { - if (G_IS_THEMED_ICON (icon)) - show_themed_icon_names (G_THEMED_ICON (icon), TRUE, indent + 2); - - g_object_unref (icon); - } - - g_print ("%*scan_mount=%d\n", indent + 2, "", g_volume_can_mount (volume)); - g_print ("%*scan_eject=%d\n", indent + 2, "", g_volume_can_eject (volume)); - g_print ("%*sshould_automount=%d\n", indent + 2, "", g_volume_should_automount (volume)); - sort_key = g_volume_get_sort_key (volume); - if (sort_key != NULL) - g_print ("%*ssort_key=%s\n", indent + 2, "", sort_key); - g_free (uuid); - } - - mount = g_volume_get_mount (volume); - if (mount) - { - mounts = g_list_prepend (NULL, mount); - list_mounts (mounts, indent + 2, FALSE); - g_list_free (mounts); - g_object_unref (mount); - } - } -} - -static void -list_drives (GList *drives, - int indent) -{ - GList *volumes, *l; - int c, i; - GDrive *drive; - char *name; - char **ids; - GIcon *icon; - char *type_name; - const gchar *sort_key; - - for (c = 0, l = drives; l != NULL; l = l->next, c++) - { - drive = (GDrive *) l->data; - name = g_drive_get_name (drive); - - g_print ("%*sDrive(%d): %s\n", indent, "", c, name); - g_free (name); - - type_name = get_type_name (drive); - g_print ("%*sType: %s\n", indent+2, "", type_name); - g_free (type_name); - - if (extra_detail) - { - GEnumValue *enum_value; - gpointer klass; - - ids = g_drive_enumerate_identifiers (drive); - if (ids && ids[0] != NULL) - { - g_print ("%*sids:\n", indent+2, ""); - for (i = 0; ids[i] != NULL; i++) - { - char *id = g_drive_get_identifier (drive, - ids[i]); - g_print ("%*s %s: '%s'\n", indent+2, "", ids[i], id); - g_free (id); - } - } - g_strfreev (ids); - - icon = g_drive_get_icon (drive); - if (icon) - { - if (G_IS_THEMED_ICON (icon)) - show_themed_icon_names (G_THEMED_ICON (icon), FALSE, indent + 2); - g_object_unref (icon); - } - - icon = g_drive_get_symbolic_icon (drive); - if (icon) - { - if (G_IS_THEMED_ICON (icon)) - show_themed_icon_names (G_THEMED_ICON (icon), TRUE, indent + 2); - - g_object_unref (icon); - } - - g_print ("%*sis_removable=%d\n", indent + 2, "", g_drive_is_removable (drive)); - g_print ("%*sis_media_removable=%d\n", indent + 2, "", g_drive_is_media_removable (drive)); - g_print ("%*shas_media=%d\n", indent + 2, "", g_drive_has_media (drive)); - g_print ("%*sis_media_check_automatic=%d\n", indent + 2, "", g_drive_is_media_check_automatic (drive)); - g_print ("%*scan_poll_for_media=%d\n", indent + 2, "", g_drive_can_poll_for_media (drive)); - g_print ("%*scan_eject=%d\n", indent + 2, "", g_drive_can_eject (drive)); - g_print ("%*scan_start=%d\n", indent + 2, "", g_drive_can_start (drive)); - g_print ("%*scan_stop=%d\n", indent + 2, "", g_drive_can_stop (drive)); - - enum_value = NULL; - klass = g_type_class_ref (G_TYPE_DRIVE_START_STOP_TYPE); - if (klass != NULL) - { - enum_value = g_enum_get_value (klass, g_drive_get_start_stop_type (drive)); - g_print ("%*sstart_stop_type=%s\n", indent + 2, "", - enum_value != NULL ? enum_value->value_nick : "UNKNOWN"); - g_type_class_unref (klass); - } - - sort_key = g_drive_get_sort_key (drive); - if (sort_key != NULL) - g_print ("%*ssort_key=%s\n", indent + 2, "", sort_key); - } - volumes = g_drive_get_volumes (drive); - list_volumes (volumes, indent + 2, FALSE); - g_list_free_full (volumes, g_object_unref); - } -} - - -static void -list_monitor_items(void) -{ - GVolumeMonitor *volume_monitor; - GList *drives, *volumes, *mounts; - - volume_monitor = g_volume_monitor_get(); - - /* populate gvfs network mounts */ - iterate_gmain(); - - drives = g_volume_monitor_get_connected_drives (volume_monitor); - list_drives (drives, 0); - g_list_free_full (drives, g_object_unref); - - volumes = g_volume_monitor_get_volumes (volume_monitor); - list_volumes (volumes, 0, TRUE); - g_list_free_full (volumes, g_object_unref); - - mounts = g_volume_monitor_get_mounts (volume_monitor); - list_mounts (mounts, 0, TRUE); - g_list_free_full (mounts, g_object_unref); - - g_object_unref (volume_monitor); -} - -static void -unmount_all_with_scheme (const char *scheme) -{ - GVolumeMonitor *volume_monitor; - GList *mounts; - GList *l; - - volume_monitor = g_volume_monitor_get(); - - /* populate gvfs network mounts */ - iterate_gmain(); - - mounts = g_volume_monitor_get_mounts (volume_monitor); - for (l = mounts; l != NULL; l = l->next) { - GMount *mount = G_MOUNT (l->data); - GFile *root; - - root = g_mount_get_root (mount); - if (g_file_has_uri_scheme (root, scheme)) { - unmount (root); - } - g_object_unref (root); - } - g_list_free_full (mounts, g_object_unref); - - g_object_unref (volume_monitor); -} - -static void -mount_with_device_file_cb (GObject *object, - GAsyncResult *res, - gpointer user_data) -{ - GVolume *volume; - gboolean succeeded; - GError *error = NULL; - - volume = G_VOLUME (object); - - succeeded = g_volume_mount_finish (volume, res, &error); - - if (!succeeded) - { - g_printerr (_("Error mounting %s: %s\n"), - g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE), - error->message); - success = FALSE; - } - else - { - GMount *mount; - GFile *root; - char *mount_path; - - mount = g_volume_get_mount (volume); - root = g_mount_get_root (mount); - mount_path = g_file_get_path (root); - - g_print (_("Mounted %s at %s\n"), - g_volume_get_identifier (volume, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE), - mount_path); - - g_object_unref (mount); - g_object_unref (root); - g_free (mount_path); - } - - outstanding_mounts--; - - if (outstanding_mounts == 0) - g_main_loop_quit (main_loop); -} - -static void -mount_with_device_file (const char *device_file) -{ - GVolumeMonitor *volume_monitor; - GList *volumes; - GList *l; - - volume_monitor = g_volume_monitor_get(); - - volumes = g_volume_monitor_get_volumes (volume_monitor); - for (l = volumes; l != NULL; l = l->next) - { - GVolume *volume = G_VOLUME (l->data); - - if (g_strcmp0 (g_volume_get_identifier (volume, - G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE), device_file) == 0) - { - GMountOperation *op; - - op = new_mount_op (); - - g_volume_mount (volume, - G_MOUNT_MOUNT_NONE, - op, - NULL, - mount_with_device_file_cb, - op); - - outstanding_mounts++; - } - } - g_list_free_full (volumes, g_object_unref); - - if (outstanding_mounts == 0) - { - g_print (_("No volume for device file %s\n"), device_file); - return; - } - - g_object_unref (volume_monitor); -} - -static void -monitor_print_mount (GMount *mount) -{ - if (extra_detail) - { - GList *l; - l = g_list_prepend (NULL, mount); - list_mounts (l, 2, FALSE); - g_list_free (l); - g_print ("\n"); - } -} - -static void -monitor_print_volume (GVolume *volume) -{ - if (extra_detail) - { - GList *l; - l = g_list_prepend (NULL, volume); - list_volumes (l, 2, FALSE); - g_list_free (l); - g_print ("\n"); - } -} - -static void -monitor_print_drive (GDrive *drive) -{ - if (extra_detail) - { - GList *l; - l = g_list_prepend (NULL, drive); - list_drives (l, 2); - g_list_free (l); - g_print ("\n"); - } -} - -static void -monitor_mount_added (GVolumeMonitor *volume_monitor, GMount *mount) -{ - char *name; - name = g_mount_get_name (mount); - g_print ("Mount added: '%s'\n", name); - g_free (name); - monitor_print_mount (mount); -} - -static void -monitor_mount_removed (GVolumeMonitor *volume_monitor, GMount *mount) -{ - char *name; - name = g_mount_get_name (mount); - g_print ("Mount removed: '%s'\n", name); - g_free (name); - monitor_print_mount (mount); -} - -static void -monitor_mount_changed (GVolumeMonitor *volume_monitor, GMount *mount) -{ - char *name; - name = g_mount_get_name (mount); - g_print ("Mount changed: '%s'\n", name); - g_free (name); - monitor_print_mount (mount); -} - -static void -monitor_mount_pre_unmount (GVolumeMonitor *volume_monitor, GMount *mount) -{ - char *name; - name = g_mount_get_name (mount); - g_print ("Mount pre-unmount: '%s'\n", name); - g_free (name); - monitor_print_mount (mount); -} - -static void -monitor_volume_added (GVolumeMonitor *volume_monitor, GVolume *volume) -{ - char *name; - name = g_volume_get_name (volume); - g_print ("Volume added: '%s'\n", name); - g_free (name); - monitor_print_volume (volume); -} - -static void -monitor_volume_removed (GVolumeMonitor *volume_monitor, GVolume *volume) -{ - char *name; - name = g_volume_get_name (volume); - g_print ("Volume removed: '%s'\n", name); - g_free (name); - monitor_print_volume (volume); -} - -static void -monitor_volume_changed (GVolumeMonitor *volume_monitor, GVolume *volume) -{ - char *name; - name = g_volume_get_name (volume); - g_print ("Volume changed: '%s'\n", name); - g_free (name); - monitor_print_volume (volume); -} - -static void -monitor_drive_connected (GVolumeMonitor *volume_monitor, GDrive *drive) -{ - char *name; - name = g_drive_get_name (drive); - g_print ("Drive connected: '%s'\n", name); - g_free (name); - monitor_print_drive (drive); -} - -static void -monitor_drive_disconnected (GVolumeMonitor *volume_monitor, GDrive *drive) -{ - char *name; - name = g_drive_get_name (drive); - g_print ("Drive disconnected: '%s'\n", name); - g_free (name); - monitor_print_drive (drive); -} - -static void -monitor_drive_changed (GVolumeMonitor *volume_monitor, GDrive *drive) -{ - char *name; - name = g_drive_get_name (drive); - g_print ("Drive changed: '%s'\n", name); - g_free (name); - monitor_print_drive (drive); -} - -static void -monitor_drive_eject_button (GVolumeMonitor *volume_monitor, GDrive *drive) -{ - char *name; - name = g_drive_get_name (drive); - g_print ("Drive eject button: '%s'\n", name); - g_free (name); -} - -static void -monitor (void) -{ - GVolumeMonitor *volume_monitor; - - volume_monitor = g_volume_monitor_get (); - - g_signal_connect (volume_monitor, "mount-added", (GCallback) monitor_mount_added, NULL); - g_signal_connect (volume_monitor, "mount-removed", (GCallback) monitor_mount_removed, NULL); - g_signal_connect (volume_monitor, "mount-changed", (GCallback) monitor_mount_changed, NULL); - g_signal_connect (volume_monitor, "mount-pre-unmount", (GCallback) monitor_mount_pre_unmount, NULL); - g_signal_connect (volume_monitor, "volume-added", (GCallback) monitor_volume_added, NULL); - g_signal_connect (volume_monitor, "volume-removed", (GCallback) monitor_volume_removed, NULL); - g_signal_connect (volume_monitor, "volume-changed", (GCallback) monitor_volume_changed, NULL); - g_signal_connect (volume_monitor, "drive-connected", (GCallback) monitor_drive_connected, NULL); - g_signal_connect (volume_monitor, "drive-disconnected", (GCallback) monitor_drive_disconnected, NULL); - g_signal_connect (volume_monitor, "drive-changed", (GCallback) monitor_drive_changed, NULL); - g_signal_connect (volume_monitor, "drive-eject-button", (GCallback) monitor_drive_eject_button, NULL); - - g_print ("Monitoring events. Press Ctrl+C to quit.\n"); - - g_main_loop_run (main_loop); -} - -int -main (int argc, char *argv[]) -{ - GOptionContext *context; - GError *error; - GFile *file; - gchar *param; - gchar *summary; - - setlocale (LC_ALL, ""); - - bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - error = NULL; - param = g_strdup_printf ("[%s...]", _("LOCATION")); - summary = _("Mount the locations."); - - context = g_option_context_new (param); - g_option_context_set_summary (context, summary); - g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); - g_option_context_parse (context, &argc, &argv, &error); - g_option_context_free (context); - g_free (param); - - if (error != NULL) - { - g_printerr (_("Error parsing commandline options: %s\n"), error->message); - g_printerr ("\n"); - g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); - g_printerr ("\n"); - g_error_free (error); - return 1; - } - - if (show_version) - { - g_print (PACKAGE_STRING "\n"); - return 0; - } - - main_loop = g_main_loop_new (NULL, FALSE); - - if (mount_list) - list_monitor_items (); - else if (mount_device_file != NULL) - { - mount_with_device_file (mount_device_file); - } - else if (unmount_scheme != NULL) - { - unmount_all_with_scheme (unmount_scheme); - } - else if (mount_monitor) - { - monitor (); - } - else if (argc > 1) - { - int i; - - for (i = 1; i < argc; i++) { - file = g_file_new_for_commandline_arg (argv[i]); - if (mount_unmount) - unmount (file); - else if (mount_eject) - eject (file); - else - mount (file); - g_object_unref (file); - } - } - - if (outstanding_mounts > 0) - g_main_loop_run (main_loop); - - return success ? 0 : 2; -} diff --git a/programs/gvfs-move.c b/programs/gvfs-move.c deleted file mode 100644 index ceea162a..00000000 --- a/programs/gvfs-move.c +++ /dev/null @@ -1,247 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Author: Alexander Larsson <alexl@redhat.com> - */ - -#include <config.h> - -#include <stdio.h> -#include <unistd.h> -#include <locale.h> -#include <errno.h> -#include <string.h> - -#include <glib.h> -#include <glib/gi18n.h> -#include <gio/gio.h> - -static gboolean progress = FALSE; -static gboolean interactive = FALSE; -static gboolean backup = FALSE; -static gboolean no_target_directory = FALSE; -static gboolean no_copy_fallback = FALSE; -static gboolean show_version = FALSE; - -static GOptionEntry entries[] = -{ - { "no-target-directory", 'T', 0, G_OPTION_ARG_NONE, &no_target_directory, N_("No target directory"), NULL }, - { "progress", 'p', 0, G_OPTION_ARG_NONE, &progress, N_("Show progress"), NULL }, - { "interactive", 'i', 0, G_OPTION_ARG_NONE, &interactive, N_("Prompt before overwrite"), NULL }, - { "backup", 'b', 0, G_OPTION_ARG_NONE, &backup, N_("Backup existing destination files"), NULL }, - { "no-copy-fallback", 'C', 0, G_OPTION_ARG_NONE, &no_copy_fallback, N_("Don't use copy and delete fallback"), NULL }, - { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program version"), NULL }, - { NULL } -}; - -static gboolean -is_dir (GFile *file) -{ - GFileInfo *info; - gboolean res; - - info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_TYPE, 0, NULL, NULL); - res = info && g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY; - if (info) - g_object_unref (info); - return res; -} - -static gint64 start_time; -static gint64 previous_time; -static void -show_progress (goffset current_num_bytes, - goffset total_num_bytes, - gpointer user_data) -{ - gint64 tv; - char *current_size, *total_size, *rate; - - tv = g_get_monotonic_time (); - if (tv - previous_time < (G_USEC_PER_SEC / 5) && - current_num_bytes != total_num_bytes) - return; - - current_size = g_format_size (current_num_bytes); - total_size = g_format_size (total_num_bytes); - rate = g_format_size (current_num_bytes / - MAX ((tv - start_time) / G_USEC_PER_SEC, 1)); - g_print ("\r\033[K"); - g_print (_("Transferred %s out of %s (%s/s)"), - current_size, total_size, rate); - - previous_time = tv; - - g_free (current_size); - g_free (total_size); - g_free (rate); -} - -static void -show_help (GOptionContext *context, const char *error) -{ - char *help; - - if (error) - g_printerr (_("Error: %s"), error); - - help = g_option_context_get_help (context, TRUE, NULL); - g_printerr ("%s", help); - g_free (help); - g_option_context_free (context); -} - -int -main (int argc, char *argv[]) -{ - GError *error; - GOptionContext *context; - GFile *source, *dest, *target; - gboolean dest_is_dir; - char *basename; - char *uri; - int i; - GFileCopyFlags flags; - int retval = 0; - gchar *param; - gchar *summary; - - setlocale (LC_ALL, ""); - - bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - error = NULL; - param = g_strdup_printf ("%s... %s", _("SOURCE"), _("DEST")); - summary = _("Move one or more files from SOURCE to DEST."); - - context = g_option_context_new (param); - g_option_context_set_summary (context, summary); - g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); - g_option_context_parse (context, &argc, &argv, &error); - - if (error != NULL) - { - g_printerr (_("Error parsing commandline options: %s\n"), error->message); - g_printerr ("\n"); - g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); - g_printerr ("\n"); - g_error_free (error); - return 1; - } - - if (show_version) - { - g_print (PACKAGE_STRING "\n"); - return 0; - } - - if (argc <= 2) - { - show_help (context, _("Missing operand\n")); - return 1; - } - - dest = g_file_new_for_commandline_arg (argv[argc-1]); - - if (no_target_directory && argc > 3) - { - show_help (context, _("Too many arguments\n")); - g_object_unref (dest); - return 1; - } - - dest_is_dir = is_dir (dest); - - if (!dest_is_dir && argc > 3) - { - g_printerr (_("Target %s is not a directory\n"), argv[argc-1]); - show_help (context, NULL); - g_object_unref (dest); - return 1; - } - - g_option_context_free (context); - g_free (param); - - for (i = 1; i < argc - 1; i++) - { - source = g_file_new_for_commandline_arg (argv[i]); - - if (dest_is_dir && !no_target_directory) - { - basename = g_file_get_basename (source); - target = g_file_get_child (dest, basename); - g_free (basename); - } - else - target = g_object_ref (dest); - - flags = 0; - if (backup) - flags |= G_FILE_COPY_BACKUP; - if (!interactive) - flags |= G_FILE_COPY_OVERWRITE; - if (no_copy_fallback) - flags |= G_FILE_COPY_NO_FALLBACK_FOR_MOVE; - - error = NULL; - start_time = g_get_monotonic_time (); - if (!g_file_move (source, target, flags, NULL, progress?show_progress:NULL, NULL, &error)) - { - if (interactive && g_error_matches (error, G_IO_ERROR, G_IO_ERROR_EXISTS)) - { - char line[16]; - - g_error_free (error); - error = NULL; - - uri = g_file_get_uri (target); - g_print (_("%s: overwrite ā%sā? "), argv[0], uri); - g_free (uri); - - if (fgets(line, sizeof (line), stdin) && - (line[0] == 'y' || line[0] == 'Y')) - { - flags |= G_FILE_COPY_OVERWRITE; - start_time = g_get_monotonic_time (); - if (!g_file_move (source, target, flags, NULL, progress?show_progress:NULL, NULL, &error)) - goto move_failed; - } - } - else - { - move_failed: - g_printerr (_("Error moving file %s: %s\n"), argv[i], error->message); - g_error_free (error); - retval = 1; - } - } - if (progress && retval == 0) - g_print("\n"); - - g_object_unref (source); - g_object_unref (target); - } - - g_object_unref (dest); - - return retval; -} diff --git a/programs/gvfs-open.c b/programs/gvfs-open.c deleted file mode 100644 index 624ac388..00000000 --- a/programs/gvfs-open.c +++ /dev/null @@ -1,244 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Author: Alexander Larsson <alexl@redhat.com> - */ - -#include <config.h> - -#include <stdio.h> -#include <unistd.h> -#include <locale.h> -#include <errno.h> - -#include <glib.h> -#include <glib/gi18n.h> -#include <gio/gio.h> -#include <gio/gdesktopappinfo.h> - -static gboolean show_version = FALSE; -static gchar **locations = NULL; - -static GOptionEntry entries[] = { - { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program version"), NULL }, - {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &locations, NULL, NULL }, - {NULL} -}; - -static gboolean -get_bus_name_and_path_from_uri (char *uri, - char **bus_name_out, - char **object_path_out) -{ - GAppInfo *app_info = NULL; - char *bus_name = NULL; - char *object_path = NULL; - char *uri_scheme; - const char *filename; - char *basename = NULL; - char *p; - gboolean got_name = FALSE; - - uri_scheme = g_uri_parse_scheme (uri); - if (uri_scheme && uri_scheme[0] != '\0') - app_info = g_app_info_get_default_for_uri_scheme (uri_scheme); - - g_free (uri_scheme); - - if (app_info == NULL) - { - GFile *file; - - file = g_file_new_for_uri (uri); - app_info = g_file_query_default_handler (file, NULL, NULL); - g_object_unref (file); - } - - if (app_info == NULL || !G_IS_DESKTOP_APP_INFO (app_info) || - !g_desktop_app_info_get_boolean (G_DESKTOP_APP_INFO (app_info), "DBusActivatable")) - return FALSE; - - filename = g_desktop_app_info_get_filename (G_DESKTOP_APP_INFO (app_info)); - if (filename == NULL) - goto out; - - basename = g_path_get_basename (filename); - if (!g_str_has_suffix (basename, ".desktop")) - goto out; - - basename[strlen (basename) - strlen (".desktop")] = '\0'; - if (!g_dbus_is_name (basename)) - goto out; - - bus_name = g_strdup (basename); - object_path = g_strdup_printf ("/%s", bus_name); - for (p = object_path; *p != '\0'; p++) - { - if (*p == '.') - *p = '/'; - else if (*p == '-') - *p = '_'; - } - - if (!g_variant_is_object_path (object_path)) - { - g_warning ("Invalid object path \"%s\"", object_path); - g_free (object_path); - goto out; - } - - *bus_name_out = g_steal_pointer (&bus_name); - *object_path_out = g_steal_pointer (&object_path); - got_name = TRUE; - -out: - g_clear_object (&app_info); - g_clear_pointer (&basename, g_free); - - return got_name; -} - -int -main (int argc, char *argv[]) -{ - GError *error = NULL; - GOptionContext *context = NULL; - gchar *param; - gchar *summary; - int i; - gboolean success; - gboolean res; - - setlocale (LC_ALL, ""); - - bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - param = g_strdup_printf ("%s...", _("FILE")); - /* Translators: this message will appear after the usage string */ - /* and before the list of options. */ - summary = _("Open files with the default application that\n" - "is registered to handle files of this type."); - - context = g_option_context_new (param); - g_option_context_set_summary (context, summary); - g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); - g_option_context_parse (context, &argc, &argv, &error); - g_option_context_free (context); - g_free (param); - - if (error != NULL) - { - g_printerr (_("Error parsing commandline options: %s\n"), error->message); - g_printerr ("\n"); - g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); - g_printerr ("\n"); - g_error_free (error); - return 1; - } - - if (show_version) - { - g_print (PACKAGE_STRING "\n"); - return 0; - } - - if (!locations) - { - /* Translators: the %s is the program name. This error message */ - /* means the user is calling gvfs-cat without any argument. */ - g_printerr (_("%s: missing locations"), g_get_prgname ()); - g_printerr ("\n"); - g_printerr (_("Try \"%s --help\" for more information."), - g_get_prgname ()); - g_printerr ("\n"); - return 1; - } - - i = 0; - success = TRUE; - - do - { - char *uri = NULL; - char *uri_scheme; - - /* Workaround to handle non-URI locations. We still use the original - * location for other cases, because GFile might modify the URI in ways - * we don't want. See: - * https://bugzilla.gnome.org/show_bug.cgi?id=738690 */ - uri_scheme = g_uri_parse_scheme (locations[i]); - if (!uri_scheme || uri_scheme[0] == '\0') - { - GFile *file; - - file = g_file_new_for_commandline_arg (locations[i]); - uri = g_file_get_uri (file); - g_object_unref (file); - } - g_free (uri_scheme); - - res = g_app_info_launch_default_for_uri (uri ? uri : locations[i], - NULL, - &error); - - if (!res) - { - /* Translators: the first %s is the program name, the second one */ - /* is the URI of the file, the third is the error message. */ - g_printerr (_("%s: %s: error opening location: %s\n"), - g_get_prgname (), locations[i], error->message); - g_clear_error (&error); - success = FALSE; - } - - /* FIXME: This chunk of madness is a workaround for a dbus-daemon bug. - * See https://bugzilla.gnome.org/show_bug.cgi?id=746534 - */ - if (res) - { - char *bus_name = NULL; - char *object_path = NULL; - - if (get_bus_name_and_path_from_uri (uri ? uri : locations[i], &bus_name, &object_path)) - { - GDBusConnection *connection; - connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); - - if (connection) - g_dbus_connection_call_sync (connection, - bus_name, - object_path, - "org.freedesktop.DBus.Peer", - "Ping", - NULL, NULL, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL); - g_clear_object (&connection); - g_free (bus_name); - g_free (object_path); - } - } - - g_free (uri); - } - while (locations[++i] != NULL); - - return success ? 0 : 2; -} diff --git a/programs/gvfs-rename.c b/programs/gvfs-rename.c deleted file mode 100644 index 656be160..00000000 --- a/programs/gvfs-rename.c +++ /dev/null @@ -1,124 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2008 Christian Kellner <gicmo@gnome.org> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Author: Christian Kellner <gicmo@gnome.org> - */ - -#include <config.h> - -#include <glib.h> -#include <locale.h> -#include <glib/gi18n.h> -#include <gio/gio.h> - -static gboolean show_version = FALSE; - -static GOptionEntry entries[] = -{ - { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program version"), NULL }, - { NULL } -}; - -static void -show_help (GOptionContext *context, const char *error) -{ - char *help; - - if (error) - g_printerr (_("Error: %s"), error); - - help = g_option_context_get_help (context, TRUE, NULL); - g_printerr ("%s", help); - g_free (help); - g_option_context_free (context); -} - -int -main (int argc, char *argv[]) -{ - GOptionContext *context; - GError *error; - GFile *file; - GFile *new_file; - int retval = 0; - gchar *param; - gchar *summary; - - setlocale (LC_ALL, ""); - - bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - error = NULL; - param = g_strdup_printf ("%s %s", _("LOCATION"), _("NEW-NAME")); - summary = _("Rename a file."); - - context = g_option_context_new (param); - g_option_context_set_summary (context, summary); - g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); - g_option_context_parse (context, &argc, &argv, &error); - - if (error != NULL) - { - g_printerr (_("Error parsing commandline options: %s\n"), error->message); - g_printerr ("\n"); - g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); - g_printerr ("\n"); - g_error_free (error); - return 1; - } - - if (show_version) - { - g_print (PACKAGE_STRING "\n"); - return 0; - } - - if (argc < 3) - { - show_help (context, _("Missing operand\n")); - return 1; - } - - g_option_context_free (context); - g_free (param); - - file = g_file_new_for_commandline_arg (argv[1]); - - new_file = g_file_set_display_name (file, argv[2], - NULL, &error); - - if (new_file == NULL) - { - g_printerr (_("Error: %s\n"), error->message); - g_error_free (error); - retval = 1; - } - else - { - char *uri = g_file_get_uri (new_file); - g_print (_("Rename successful. New uri: %s\n"), uri); - g_object_unref (new_file); - g_free (uri); - } - - g_object_unref (file); - return retval; -} diff --git a/programs/gvfs-rm.c b/programs/gvfs-rm.c deleted file mode 100644 index 069e9228..00000000 --- a/programs/gvfs-rm.c +++ /dev/null @@ -1,106 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Author: Alexander Larsson <alexl@redhat.com> - */ - -#include <config.h> - -#include <glib.h> -#include <locale.h> -#include <glib/gi18n.h> -#include <gio/gio.h> - -static gboolean force = FALSE; -static gboolean show_version = FALSE; - -static GOptionEntry entries[] = -{ - {"force", 'f', 0, G_OPTION_ARG_NONE, &force, N_("Ignore nonexistent files, never prompt"), NULL}, - { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program version"), NULL }, - { NULL } -}; - - -int -main (int argc, char *argv[]) -{ - GError *error; - GOptionContext *context; - GFile *file; - int retval = 0; - gchar *param; - gchar *summary; - - setlocale (LC_ALL, ""); - - bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - error = NULL; - param = g_strdup_printf ("[%s...]", _("FILE")); - summary = _("Delete the given files."); - - context = g_option_context_new (param); - g_option_context_set_summary (context, summary); - g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); - g_option_context_parse (context, &argc, &argv, &error); - g_option_context_free (context); - g_free (param); - - if (error != NULL) - { - g_printerr (_("Error parsing commandline options: %s\n"), error->message); - g_printerr ("\n"); - g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); - g_printerr ("\n"); - g_error_free (error); - return 1; - } - - if (show_version) - { - g_print (PACKAGE_STRING "\n"); - return 0; - } - - if (argc > 1) - { - int i; - - for (i = 1; i < argc; i++) { - file = g_file_new_for_commandline_arg (argv[i]); - error = NULL; - if (!g_file_delete (file, NULL, &error)) - { - if (!force || - !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) - { - g_printerr ("Error deleting file: %s\n", error->message); - retval = 1; - } - g_error_free (error); - } - g_object_unref (file); - } - } - - return retval; -} diff --git a/programs/gvfs-save.c b/programs/gvfs-save.c deleted file mode 100644 index 840e9290..00000000 --- a/programs/gvfs-save.c +++ /dev/null @@ -1,206 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Author: Alexander Larsson <alexl@redhat.com> - */ - -#include <config.h> - -#include <stdio.h> -#include <unistd.h> -#include <locale.h> -#include <errno.h> - -#include <glib.h> -#include <glib/gi18n.h> -#include <gio/gio.h> - -static char *etag = NULL; -static gboolean backup = FALSE; -static gboolean create = FALSE; -static gboolean append = FALSE; -static gboolean priv = FALSE; -static gboolean replace_dest = FALSE; -static gboolean print_etag = FALSE; -static gboolean show_version = FALSE; - -static GOptionEntry entries[] = -{ - { "backup", 'b', 0, G_OPTION_ARG_NONE, &backup, N_("Backup existing destination files"), NULL }, - { "create", 'c', 0, G_OPTION_ARG_NONE, &create, N_("Only create if not existing"), NULL }, - { "append", 'a', 0, G_OPTION_ARG_NONE, &append, N_("Append to end of file"), NULL }, - { "private", 'p', 0, G_OPTION_ARG_NONE, &priv, N_("When creating, restrict access to the current user"), NULL }, - { "unlink", 'u', 0, G_OPTION_ARG_NONE, &replace_dest, N_("When replacing, replace as if the destination did not exist"), NULL }, - /* Translators: The "etag" is a token allowing to verify whether a file has been modified */ - { "print-etag", 'v', 0, G_OPTION_ARG_NONE, &print_etag, N_("Print new etag at end"), NULL }, - /* Translators: The "etag" is a token allowing to verify whether a file has been modified */ - { "etag", 'e', 0, G_OPTION_ARG_STRING, &etag, N_("The etag of the file being overwritten"), N_("ETAG") }, - { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program version"), NULL }, - { NULL } -}; - -static gboolean -save (GFile *file) -{ - GOutputStream *out; - GFileCreateFlags flags; - char buffer[1025]; - char *p; - gssize res; - gboolean close_res; - GError *error; - gboolean save_res; - - error = NULL; - - flags = priv ? G_FILE_CREATE_PRIVATE : G_FILE_CREATE_NONE; - flags |= replace_dest ? G_FILE_CREATE_REPLACE_DESTINATION : 0; - - if (create) - out = (GOutputStream *)g_file_create (file, flags, NULL, &error); - else if (append) - out = (GOutputStream *)g_file_append_to (file, flags, NULL, &error); - else - out = (GOutputStream *)g_file_replace (file, etag, backup, flags, NULL, &error); - if (out == NULL) - { - g_printerr (_("Error opening file: %s\n"), error->message); - g_error_free (error); - return FALSE; - } - - save_res = TRUE; - - while (1) - { - res = read (STDIN_FILENO, buffer, 1024); - if (res > 0) - { - ssize_t written; - - p = buffer; - while (res > 0) - { - error = NULL; - written = g_output_stream_write (out, p, res, NULL, &error); - if (written == -1) - { - save_res = FALSE; - g_printerr ("Error writing to stream: %s\n", error->message); - g_error_free (error); - goto out; - } - res -= written; - p += written; - } - } - else if (res < 0) - { - save_res = FALSE; - perror (_("Error reading stdin")); - break; - } - else if (res == 0) - break; - } - - out: - - error = NULL; - close_res = g_output_stream_close (out, NULL, &error); - if (!close_res) - { - save_res = FALSE; - g_printerr (_("Error closing: %s\n"), error->message); - g_error_free (error); - } - - if (close_res && print_etag) - { - char *etag; - etag = g_file_output_stream_get_etag (G_FILE_OUTPUT_STREAM (out)); - - if (etag) - g_print ("Etag: %s\n", etag); - else - /* Translators: The "etag" is a token allowing to verify whether a file has been modified */ - g_print (_("Etag not available\n")); - g_free (etag); - } - - g_object_unref (out); - - return save_res; -} - -int -main (int argc, char *argv[]) -{ - GError *error; - GOptionContext *context; - GFile *file; - gboolean res; - gchar *param; - gchar *summary; - - setlocale (LC_ALL, ""); - - bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - error = NULL; - param = _("DEST"); - summary = _("Read from standard input and save to DEST."); - - context = g_option_context_new (param); - g_option_context_set_summary (context, summary); - g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); - g_option_context_parse (context, &argc, &argv, &error); - g_option_context_free (context); - - if (error != NULL) - { - g_printerr (_("Error parsing commandline options: %s\n"), error->message); - g_printerr ("\n"); - g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); - g_printerr ("\n"); - g_error_free (error); - return 1; - } - - if (show_version) - { - g_print (PACKAGE_STRING "\n"); - return 0; - } - - res = FALSE; - - if (argc > 1) - { - file = g_file_new_for_commandline_arg (argv[1]); - res = save (file); - g_object_unref (file); - } - - if (res) - return 0; - return 1; -} diff --git a/programs/gvfs-set-attribute.c b/programs/gvfs-set-attribute.c deleted file mode 100644 index f110991f..00000000 --- a/programs/gvfs-set-attribute.c +++ /dev/null @@ -1,244 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Author: Alexander Larsson <alexl@redhat.com> - */ - -#include <config.h> - -#include <glib.h> -#include <locale.h> -#include <stdlib.h> -#include <glib/gi18n.h> -#include <gio/gio.h> - -static char *attr_type = "string"; -static gboolean nofollow_symlinks = FALSE; -static gboolean show_version = FALSE; - -static GOptionEntry entries[] = -{ - { "type", 't', 0, G_OPTION_ARG_STRING, &attr_type, N_("Type of the attribute"), N_("TYPE") }, - { "nofollow-symlinks", 'n', 0, G_OPTION_ARG_NONE, &nofollow_symlinks, N_("Don't follow symbolic links"), NULL }, - { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program version"), NULL }, - { NULL } -}; - -static char * -hex_unescape (const char *str) -{ - int i; - char *unescaped_str, *p; - unsigned char c; - int len; - - len = strlen (str); - unescaped_str = g_malloc (len + 1); - - p = unescaped_str; - for (i = 0; i < len; i++) - { - if (str[i] == '\\' && - str[i+1] == 'x' && - len - i >= 4) - { - c = - (g_ascii_xdigit_value (str[i+2]) << 4) | - g_ascii_xdigit_value (str[i+3]); - *p++ = c; - i += 3; - } - else - *p++ = str[i]; - } - *p++ = 0; - - return unescaped_str; -} - -static GFileAttributeType -attribute_type_from_string (const char *str) -{ - if (strcmp (str, "string") == 0) - return G_FILE_ATTRIBUTE_TYPE_STRING; - if (strcmp (str, "stringv") == 0) - return G_FILE_ATTRIBUTE_TYPE_STRINGV; - if (strcmp (str, "bytestring") == 0) - return G_FILE_ATTRIBUTE_TYPE_BYTE_STRING; - if (strcmp (str, "boolean") == 0) - return G_FILE_ATTRIBUTE_TYPE_BOOLEAN; - if (strcmp (str, "uint32") == 0) - return G_FILE_ATTRIBUTE_TYPE_UINT32; - if (strcmp (str, "int32") == 0) - return G_FILE_ATTRIBUTE_TYPE_INT32; - if (strcmp (str, "uint64") == 0) - return G_FILE_ATTRIBUTE_TYPE_UINT64; - if (strcmp (str, "int64") == 0) - return G_FILE_ATTRIBUTE_TYPE_INT64; - if (strcmp (str, "object") == 0) - return G_FILE_ATTRIBUTE_TYPE_OBJECT; - if (strcmp (str, "unset") == 0) - return G_FILE_ATTRIBUTE_TYPE_INVALID; - return -1; -} - -static void -show_help (GOptionContext *context, const char *error) -{ - char *help; - - if (error) - g_printerr (_("Error: %s"), error); - - help = g_option_context_get_help (context, TRUE, NULL); - g_printerr ("%s", help); - g_free (help); - g_option_context_free (context); -} - -int -main (int argc, char *argv[]) -{ - GError *error; - GOptionContext *context; - GFile *file; - const char *attribute; - GFileAttributeType type; - gpointer value; - gboolean bool; - guint32 uint32; - gint32 int32; - guint64 uint64; - gint64 int64; - gchar *param; - gchar *summary; - - setlocale (LC_ALL, ""); - - bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - error = NULL; - param = g_strdup_printf ("%s %s %s...", _("LOCATION"), _("ATTRIBUTE"), _("VALUE")); - summary = _("Set a file attribute of LOCATION."); - - context = g_option_context_new (param); - g_option_context_set_summary (context, summary); - g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); - g_option_context_parse (context, &argc, &argv, &error); - - if (error != NULL) - { - g_printerr (_("Error parsing commandline options: %s\n"), error->message); - g_printerr ("\n"); - g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); - g_printerr ("\n"); - g_error_free (error); - return 1; - } - - if (show_version) - { - g_print (PACKAGE_STRING "\n"); - return 0; - } - - if (argc < 2) - { - show_help (context, _("Location not specified\n")); - return 1; - } - - file = g_file_new_for_commandline_arg (argv[1]); - - if (argc < 3) - { - show_help (context, _("Attribute not specified\n")); - return 1; - } - - attribute = argv[2]; - - type = attribute_type_from_string (attr_type); - if ((argc < 4) && (type != G_FILE_ATTRIBUTE_TYPE_INVALID)) - { - show_help (context, _("Value not specified\n")); - return 1; - } - - g_option_context_free (context); - g_free (param); - - switch (type) - { - case G_FILE_ATTRIBUTE_TYPE_STRING: - value = argv[3]; - break; - case G_FILE_ATTRIBUTE_TYPE_BYTE_STRING: - value = hex_unescape (argv[3]); - break; - case G_FILE_ATTRIBUTE_TYPE_BOOLEAN: - bool = g_ascii_strcasecmp (argv[3], "true") == 0; - value = &bool; - break; - case G_FILE_ATTRIBUTE_TYPE_UINT32: - uint32 = atol (argv[3]); - value = &uint32; - break; - case G_FILE_ATTRIBUTE_TYPE_INT32: - int32 = atol (argv[3]); - value = &int32; - break; - case G_FILE_ATTRIBUTE_TYPE_UINT64: - uint64 = g_ascii_strtoull (argv[3], NULL, 10); - value = &uint64; - break; - case G_FILE_ATTRIBUTE_TYPE_INT64: - int64 = g_ascii_strtoll (argv[3], NULL, 10); - value = &int64; - break; - case G_FILE_ATTRIBUTE_TYPE_STRINGV: - value = &argv[3]; - break; - case G_FILE_ATTRIBUTE_TYPE_INVALID: - value = NULL; - break; - case G_FILE_ATTRIBUTE_TYPE_OBJECT: - default: - g_printerr (_("Invalid attribute type %s\n"), attr_type); - return 1; - } - - if (!g_file_set_attribute (file, - attribute, - type, - value, - nofollow_symlinks ? - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS : - G_FILE_QUERY_INFO_NONE, - NULL, &error)) - { - g_printerr (_("Error setting attribute: %s\n"), error->message); - g_error_free (error); - return 1; - } - - return 0; -} diff --git a/programs/gvfs-trash.c b/programs/gvfs-trash.c deleted file mode 100644 index 0c714cb0..00000000 --- a/programs/gvfs-trash.c +++ /dev/null @@ -1,148 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Author: Alexander Larsson <alexl@redhat.com> - */ - -#include <config.h> - -#include <glib.h> -#include <locale.h> -#include <glib/gi18n.h> -#include <gio/gio.h> - -static void -delete_trash_file (GFile *file, gboolean del_file, gboolean del_children) -{ - GFileInfo *info; - GFile *child; - GFileEnumerator *enumerator; - - if (del_children) - { - enumerator = g_file_enumerate_children (file, - G_FILE_ATTRIBUTE_STANDARD_NAME "," - G_FILE_ATTRIBUTE_STANDARD_TYPE, - G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, - NULL, - NULL); - if (enumerator) - { - while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) - { - child = g_file_get_child (file, g_file_info_get_name (info)); - delete_trash_file (child, TRUE, g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY); - g_object_unref (child); - g_object_unref (info); - } - g_file_enumerator_close (enumerator, NULL, NULL); - g_object_unref (enumerator); - } - } - - if (del_file) - g_file_delete (file, NULL, NULL); -} - -static gboolean force = FALSE; -static gboolean empty = FALSE; -static gboolean show_version = FALSE; - -static GOptionEntry entries[] = -{ - { "force", 'f', 0, G_OPTION_ARG_NONE, &force, N_("Ignore nonexistent files, never prompt"), NULL }, - { "empty", 0, 0, G_OPTION_ARG_NONE, &empty, N_("Empty the trash"), NULL }, - { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program version"), NULL }, - { NULL } -}; - -int -main (int argc, char *argv[]) -{ - GError *error; - GOptionContext *context; - GFile *file; - int retval = 0; - gchar *param; - gchar *summary; - - setlocale (LC_ALL, ""); - - bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - error = NULL; - param = g_strdup_printf ("[%s...]", _("LOCATION")); - summary = _("Move files or directories to the trash."); - - context = g_option_context_new (param); - g_option_context_set_summary (context, summary); - g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); - g_option_context_parse (context, &argc, &argv, &error); - g_option_context_free (context); - g_free (param); - - if (error != NULL) - { - g_printerr (_("Error parsing commandline options: %s\n"), error->message); - g_printerr ("\n"); - g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); - g_printerr ("\n"); - g_error_free (error); - return 1; - } - - if (show_version) - { - g_print (PACKAGE_STRING "\n"); - return 0; - } - - if (argc > 1) - { - int i; - - for (i = 1; i < argc; i++) { - file = g_file_new_for_commandline_arg (argv[i]); - error = NULL; - if (!g_file_trash (file, NULL, &error)) - { - if (!force || - !g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND)) - { - g_printerr (_("Error trashing file: %s\n"), error->message); - retval = 1; - } - g_error_free (error); - } - g_object_unref (file); - } - } - - if (empty) - { - GFile *file; - file = g_file_new_for_uri ("trash:"); - delete_trash_file (file, FALSE, TRUE); - g_object_unref (file); - } - - return retval; -} diff --git a/programs/gvfs-tree.c b/programs/gvfs-tree.c deleted file mode 100644 index e5774899..00000000 --- a/programs/gvfs-tree.c +++ /dev/null @@ -1,297 +0,0 @@ -/* GIO - GLib Input, Output and Streaming Library - * - * Copyright (C) 2006-2007 Red Hat, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General - * Public License along with this library; if not, write to the - * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Author: David Zeuthen <davidz@redhat.com> - */ - -#include <config.h> - -#include <glib.h> -#include <locale.h> -#include <string.h> -#include <glib/gi18n.h> -#include <gio/gio.h> - -static gboolean show_hidden = FALSE; -static gboolean follow_symlinks = FALSE; -static gboolean show_version = FALSE; - -static GOptionEntry entries[] = -{ - { "hidden", 'h', 0, G_OPTION_ARG_NONE, &show_hidden, N_("Show hidden files"), NULL }, - { "follow-symlinks", 'l', 0, G_OPTION_ARG_NONE, &follow_symlinks, N_("Follow symbolic links, mounts and shortcuts"), NULL }, - { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program version"), NULL }, - { NULL } -}; - -static gint -sort_info_by_name (GFileInfo *a, GFileInfo *b) -{ - const char *na; - const char *nb; - - na = g_file_info_get_name (a); - nb = g_file_info_get_name (b); - - if (na == NULL) - na = ""; - if (nb == NULL) - nb = ""; - - return strcmp (na, nb); -} - -static void -do_tree (GFile *f, int level, guint64 pattern) -{ - GFileEnumerator *enumerator; - GError *error = NULL; - unsigned int n; - GFileInfo *info; - - info = g_file_query_info (f, - G_FILE_ATTRIBUTE_STANDARD_TYPE "," - G_FILE_ATTRIBUTE_STANDARD_TARGET_URI, - 0, - NULL, NULL); - if (info != NULL) - { - if (g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_STANDARD_TYPE) == G_FILE_TYPE_MOUNTABLE) - { - /* don't process mountables; we avoid these by getting the target_uri below */ - g_object_unref (info); - return; - } - g_object_unref (info); - } - - enumerator = g_file_enumerate_children (f, - G_FILE_ATTRIBUTE_STANDARD_NAME "," - G_FILE_ATTRIBUTE_STANDARD_TYPE "," - G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN "," - G_FILE_ATTRIBUTE_STANDARD_IS_SYMLINK "," - G_FILE_ATTRIBUTE_STANDARD_SYMLINK_TARGET "," - G_FILE_ATTRIBUTE_STANDARD_TARGET_URI, - 0, - NULL, - &error); - if (enumerator != NULL) - { - GList *l; - GList *info_list; - - info_list = NULL; - while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) - { - if (g_file_info_get_is_hidden (info) && !show_hidden) - { - g_object_unref (info); - } - else - { - info_list = g_list_prepend (info_list, info); - } - } - g_file_enumerator_close (enumerator, NULL, NULL); - - info_list = g_list_sort (info_list, (GCompareFunc) sort_info_by_name); - - for (l = info_list; l != NULL; l = l->next) - { - const char *name; - const char *target_uri; - GFileType type; - gboolean is_last_item; - - info = l->data; - is_last_item = (l->next == NULL); - - name = g_file_info_get_name (info); - type = g_file_info_get_attribute_uint32 (info, G_FILE_ATTRIBUTE_STANDARD_TYPE); - if (name != NULL) - { - - for (n = 0; n < level; n++) - { - if (pattern & (1<<n)) - { - g_print ("| "); - } - else - { - g_print (" "); - } - } - - if (is_last_item) - { - g_print ("`-- %s", name); - } - else - { - g_print ("|-- %s", name); - } - - target_uri = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_TARGET_URI); - if (target_uri != NULL) - { - g_print (" -> %s", target_uri); - } - else - { - if (g_file_info_get_is_symlink (info)) - { - const char *target; - target = g_file_info_get_symlink_target (info); - g_print (" -> %s", target); - } - } - - g_print ("\n"); - - if ((type & G_FILE_TYPE_DIRECTORY) && - (follow_symlinks || !g_file_info_get_is_symlink (info))) - { - guint64 new_pattern; - GFile *child; - - if (is_last_item) - new_pattern = pattern; - else - new_pattern = pattern | (1<<level); - - child = NULL; - if (target_uri != NULL) - { - if (follow_symlinks) - child = g_file_new_for_uri (target_uri); - } - else - { - child = g_file_get_child (f, name); - } - - if (child != NULL) - { - do_tree (child, level + 1, new_pattern); - g_object_unref (child); - } - } - } - g_object_unref (info); - } - g_list_free (info_list); - } - else - { - for (n = 0; n < level; n++) - { - if (pattern & (1<<n)) - { - g_print ("| "); - } - else - { - g_print (" "); - } - } - - g_print (" [%s]\n", error->message); - - g_error_free (error); - } -} - -static void -tree (GFile *f) -{ - char *uri; - - uri = g_file_get_uri (f); - g_print ("%s\n", uri); - g_free (uri); - - do_tree (f, 0, 0); -} - -int -main (int argc, char *argv[]) -{ - GError *error; - GOptionContext *context; - GFile *file; - gchar *param; - gchar *summary; - - setlocale (LC_ALL, ""); - - bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); - bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); - textdomain (GETTEXT_PACKAGE); - - error = NULL; - param = g_strdup_printf ("[%s...]", _("LOCATION")); - summary = _("List contents of directories in a tree-like format."); - - context = g_option_context_new (param); - g_option_context_set_summary (context, summary); - g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); - g_option_context_parse (context, &argc, &argv, &error); - g_option_context_free (context); - g_free (param); - - if (error != NULL) - { - g_printerr (_("Error parsing commandline options: %s\n"), error->message); - g_printerr ("\n"); - g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); - g_printerr ("\n"); - g_error_free (error); - return 1; - } - - if (show_version) - { - g_print (PACKAGE_STRING "\n"); - return 0; - } - - if (argc > 1) - { - int i; - - for (i = 1; i < argc; i++) { - file = g_file_new_for_commandline_arg (argv[i]); - tree (file); - g_object_unref (file); - } - } - else - { - char *cwd; - - cwd = g_get_current_dir (); - file = g_file_new_for_path (cwd); - g_free (cwd); - tree (file); - g_object_unref (file); - } - - return 0; -} |