Commit 926810ba authored by Ernestas Kulik's avatar Ernestas Kulik 🦑

Remove file change queueing

parent eaf3c3ec
......@@ -106,11 +106,19 @@ perform_self_test_checks (const gchar *path)
}
static void
rename (const gchar *target,
const gchar *name)
on_children_changed (NautilusDirectory *directory,
gpointer user_data)
{
g_main_loop_quit ((GMainLoop *) user_data);
}
static void
_rename (const gchar *target,
const gchar *name)
{
g_autoptr (GFile) location = NULL;
g_autoptr (NautilusFile) file = NULL;
g_autoptr (NautilusFile) parent = NULL;
g_autoptr (NautilusTaskManager) manager = NULL;
g_autoptr (NautilusTask) task = NULL;
GMainLoop *loop;
......@@ -119,12 +127,16 @@ rename (const gchar *target,
g_message ("Constructed GFile %p for path %s",
(gpointer) location, target);
file = nautilus_file_new (location);
parent = nautilus_file_get_parent (file);
g_message ("Constructed NautilusFile %p for location %p",
(gpointer) file, (gpointer) location);
manager = nautilus_task_manager_dup_singleton ();
task = nautilus_rename_task_new ();
loop = g_main_loop_new (NULL, TRUE);
g_signal_connect (parent, "children-changed",
G_CALLBACK (on_children_changed), loop);
nautilus_rename_task_add_target (NAUTILUS_RENAME_TASK (task),
location, name);
......@@ -189,7 +201,7 @@ main (int argc,
if (new_name != NULL && new_name[0] != '\0')
{
rename (files[0], new_name);
_rename (files[0], new_name);
}
return EXIT_SUCCESS;
......
......@@ -59,7 +59,7 @@ nautilus_directory_class_init (NautilusDirectoryClass *klass)
signals[CHILDREN_CHANGED] = g_signal_new ("children-changed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NautilusDirectoryClass, children_changed),
NULL, NULL,
g_cclosure_marshal_VOID__VOID,
......
......@@ -38,9 +38,6 @@ static void move_change_free (MoveChange *change);
G_DEFINE_AUTOPTR_CLEANUP_FUNC (MoveChange, move_change_free)
static guint source = 0;
static GMutex source_mutex;
static void
move_change_free (MoveChange *change)
{
......@@ -49,94 +46,48 @@ move_change_free (MoveChange *change)
g_free (change);
}
static gpointer
init_default_queue (gpointer data)
{
return g_async_queue_new ();
}
static GAsyncQueue *
get_default_queue (void)
{
static GOnce once = G_ONCE_INIT;
g_once (&once, init_default_queue, NULL);
return once.retval;
}
static gboolean
emit_signals (gpointer user_data)
static void
emit_signal_for_change (Change *change)
{
GAsyncQueue *queue;
Change *change;
queue = user_data;
g_async_queue_lock (queue);
g_autoptr (NautilusFile) file = NULL;
g_autoptr (NautilusFile) parent = NULL;
while ((change = g_async_queue_try_pop_unlocked (queue)) != NULL)
file = nautilus_file_new (change->location);
if (file == NULL)
{
g_autoptr (NautilusFile) file = NULL;
g_autoptr (NautilusFile) parent = NULL;
file = nautilus_file_new (change->location);
if (file == NULL)
{
continue;
}
parent = nautilus_file_get_parent (file);
return;
}
parent = nautilus_file_get_parent (file);
switch (change->type)
switch (change->type)
{
case NAUTILUS_FILE_CHANGE_RENAMED:
{
case NAUTILUS_FILE_CHANGE_RENAMED:
{
g_autoptr (MoveChange) move_change = NULL;
g_autoptr (MoveChange) move_change = NULL;
move_change = (MoveChange *) change;
move_change = (MoveChange *) change;
nautilus_emit_signal_in_main_context_by_name (file,
NULL,
"renamed",
move_change->location_to);
nautilus_emit_signal_in_main_context_by_name (file,
NULL,
"renamed",
move_change->location_to);
if (parent == NULL)
{
break;
}
nautilus_emit_signal_in_main_context_by_name (parent,
NULL,
"children-changed");
if (parent == NULL)
{
break;
}
break;
}
}
g_async_queue_unlock (queue);
g_mutex_lock (&source_mutex);
source = 0;
g_mutex_unlock (&source_mutex);
return G_SOURCE_REMOVE;
}
static void
schedule_signal_emission (void)
{
g_mutex_lock (&source_mutex);
nautilus_emit_signal_in_main_context_by_name (parent,
NULL,
"children-changed");
}
break;
if (source == 0)
{
source = g_timeout_add (100, emit_signals, get_default_queue ());
}
else
{
g_source_remove (source);
case NAUTILUS_FILE_CHANGE_MOVED:
{
}
break;
}
g_mutex_unlock (&source_mutex);
}
static void
......@@ -145,19 +96,15 @@ notify_file_moved_or_renamed (GFile *from,
gboolean move_is_rename)
{
MoveChange *change;
GAsyncQueue *queue;
change = g_new0 (MoveChange, 1);
queue = get_default_queue ();
change->type = move_is_rename? NAUTILUS_FILE_CHANGE_RENAMED
: NAUTILUS_FILE_CHANGE_MOVED;
change->location_from = g_object_ref (from);
change->location_to = g_object_ref (to);
g_async_queue_push (queue, change);
schedule_signal_emission ();
emit_signal_for_change ((Change *) change);
}
void
......
......@@ -191,7 +191,7 @@ nautilus_file_class_init (NautilusFileClass *klass)
signals[RENAMED] = g_signal_new ("renamed",
G_TYPE_FROM_CLASS (klass),
G_SIGNAL_RUN_LAST,
G_SIGNAL_RUN_FIRST,
G_STRUCT_OFFSET (NautilusFileClass, renamed),
NULL, NULL,
g_cclosure_marshal_VOID__OBJECT,
......
......@@ -73,6 +73,8 @@ execute (NautilusTask *task)
g_autoptr (GFile) location_to = NULL;
location_from = G_FILE (key);
g_message ("Renaming GFile %p",
(gpointer) location_from);
location_to = g_file_set_display_name (location_from,
(const gchar *) value,
cancellable, &error);
......@@ -84,6 +86,12 @@ execute (NautilusTask *task)
(gpointer) location_to);
nautilus_notify_file_renamed (location_from, location_to);
}
else
{
g_message ("Renaming GFile %p failed: %s",
(gpointer) location_from,
error->message);
}
}
/* This will typically be handled before the file and its parent
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment