summaryrefslogtreecommitdiff
path: root/programs
diff options
context:
space:
mode:
authorChristian Kellner <gicmo@gnome.org>2010-02-18 16:03:20 +0100
committerChristian Kellner <gicmo@gnome.org>2010-02-18 16:06:15 +0100
commit79baa66e0c7cae05620187948c960bbe04f731a6 (patch)
treebae3dfa0cbfccbfede5a889356ea8102e56dc897 /programs
parente1777882d5f8088c9c61732396aceb835139c531 (diff)
downloadgvfs-79baa66e0c7cae05620187948c960bbe04f731a6.tar.gz
gvfs-monitor-[dir|file]: Support for "move events"
GIO gained has support for file-monitoring "move events" since 2.23.4. Make use of those in gvfs-monitor-[dir|file] unless new commandline option "-N" is specified. (Bump glib requirement accordingly).
Diffstat (limited to 'programs')
-rw-r--r--programs/gvfs-monitor-dir.c38
-rw-r--r--programs/gvfs-monitor-file.c36
2 files changed, 61 insertions, 13 deletions
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);