diff options
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | programs/gvfs-monitor-dir.c | 38 | ||||
-rw-r--r-- | programs/gvfs-monitor-file.c | 36 |
3 files changed, 62 insertions, 14 deletions
diff --git a/configure.ac b/configure.ac index 83d82b05..66f17764 100644 --- a/configure.ac +++ b/configure.ac @@ -43,7 +43,7 @@ GTK_DOC_CHECK DISTCHECK_CONFIGURE_FLAGS="--enable-gtk-doc" AC_SUBST(DISTCHECK_CONFIGURE_FLAGS) -PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.23.2 gthread-2.0 gobject-2.0 gmodule-no-export-2.0 gio-unix-2.0 gio-2.0 ) +PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.23.4 gthread-2.0 gobject-2.0 gmodule-no-export-2.0 gio-unix-2.0 gio-2.0 ) PKG_CHECK_MODULES(DBUS, dbus-1) diff --git a/programs/gvfs-monitor-dir.c b/programs/gvfs-monitor-dir.c index ef5a1335..45e8ffc3 100644 --- a/programs/gvfs-monitor-dir.c +++ b/programs/gvfs-monitor-dir.c @@ -28,11 +28,14 @@ #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 GOptionEntry entries[] = { + { "no-pair", 'N', 0, G_OPTION_ARG_NONE, &dont_pair_moves, N_("Don't send single MOVED events."), NULL }, { NULL } }; @@ -49,6 +52,13 @@ dir_monitor_callback (GFileMonitor* monitor, 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: @@ -72,6 +82,9 @@ dir_monitor_callback (GFileMonitor* monitor, 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; } return TRUE; @@ -90,21 +103,30 @@ main (int argc, char *argv[]) g_type_init (); error = NULL; - context = g_option_context_new ("- monitor directory <location>"); + context = g_option_context_new ("- monitor directory <location> [location]..."); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (argc > 1) { - file = g_file_new_for_commandline_arg (argv[1]); - dmonitor = g_file_monitor_directory (file, G_FILE_MONITOR_WATCH_MOUNTS, NULL, NULL); - if (dmonitor != NULL) - g_signal_connect (dmonitor, "changed", (GCallback)dir_monitor_callback, NULL); - else + 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++) { - g_print ("Monitoring not supported for %s\n", argv[1]); - return 1; + 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; + } } } diff --git a/programs/gvfs-monitor-file.c b/programs/gvfs-monitor-file.c index 731a0d0c..973b43df 100644 --- a/programs/gvfs-monitor-file.c +++ b/programs/gvfs-monitor-file.c @@ -28,11 +28,14 @@ #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 GOptionEntry entries[] = { + { "no-pair", 'N', 0, G_OPTION_ARG_NONE, &dont_pair_moves, N_("Don't send single MOVED events."), NULL }, { NULL } }; @@ -42,8 +45,18 @@ file_monitor_callback (GFileMonitor* monitor, GFile* other_file, GFileMonitorEvent eflags) { + char *name = g_file_get_parse_name (child); g_print ("File Monitor Event:\n"); - g_print ("File = %s\n", g_file_get_parse_name (child)); + 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: @@ -67,6 +80,10 @@ file_monitor_callback (GFileMonitor* monitor, 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; + } return TRUE; @@ -85,16 +102,25 @@ main (int argc, char *argv[]) g_type_init (); error = NULL; - context = g_option_context_new ("- monitor file <location>"); + context = g_option_context_new ("- monitor file <location> [location]..."); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_parse (context, &argc, &argv, &error); g_option_context_free (context); if (argc > 1) { - file = g_file_new_for_commandline_arg (argv[1]); - fmonitor = g_file_monitor_file (file, G_FILE_MONITOR_WATCH_MOUNTS, NULL, NULL); - g_signal_connect (fmonitor, "changed", (GCallback)file_monitor_callback, NULL); + 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); |