summaryrefslogtreecommitdiff
path: root/libcaja-private/caja-undostack-manager.c
diff options
context:
space:
mode:
Diffstat (limited to 'libcaja-private/caja-undostack-manager.c')
-rw-r--r--libcaja-private/caja-undostack-manager.c132
1 files changed, 24 insertions, 108 deletions
diff --git a/libcaja-private/caja-undostack-manager.c b/libcaja-private/caja-undostack-manager.c
index 5686abfa..1d988cda 100644
--- a/libcaja-private/caja-undostack-manager.c
+++ b/libcaja-private/caja-undostack-manager.c
@@ -34,8 +34,6 @@
#include <locale.h>
#include <gdk/gdk.h>
-#include <src/glibcompat.h> /* for g_list_free_full */
-
/* *****************************************************************
Private fields
***************************************************************** */
@@ -100,11 +98,7 @@ struct _CajaUndoStackManagerPrivate
GQueue *stack;
guint undo_levels;
guint index;
-#if GLIB_CHECK_VERSION(2, 32, 0)
GMutex mutex; /* Used to protect access to stack (because of async file ops) */
-#else
- GMutex *mutex; /* Used to protect access to stack (because of async file ops) */
-#endif
gboolean dispose_has_run;
gboolean undo_redo_flag;
gboolean confirm_delete;
@@ -273,11 +267,7 @@ caja_undostack_manager_init (CajaUndoStackManager * self)
/* Initialize private fields */
priv->stack = g_queue_new ();
-#if GLIB_CHECK_VERSION(2, 32, 0)
g_mutex_init (&priv->mutex);
-#else
- priv->mutex = g_mutex_new ();
-#endif
priv->index = 0;
priv->dispose_has_run = FALSE;
priv->undo_redo_flag = FALSE;
@@ -293,22 +283,13 @@ caja_undostack_manager_dispose (GObject * object)
if (priv->dispose_has_run)
return;
-#if GLIB_CHECK_VERSION(2, 32, 0)
g_mutex_lock (&priv->mutex);
-#else
- g_mutex_lock (priv->mutex);
-#endif
/* Free each undoable action in the stack and the stack itself */
undostack_dispose_all (priv->stack);
g_queue_free (priv->stack);
-#if GLIB_CHECK_VERSION(2, 32, 0)
g_mutex_unlock (&priv->mutex);
g_mutex_clear (&priv->mutex);
-#else
- g_mutex_unlock (priv->mutex);
- g_mutex_free (priv->mutex);
-#endif
priv->dispose_has_run = TRUE;
@@ -339,17 +320,9 @@ caja_undostack_manager_set_property (GObject * object, guint prop_id,
new_undo_levels = g_value_get_uint (value);
if (new_undo_levels > 0 && (priv->undo_levels != new_undo_levels)) {
priv->undo_levels = new_undo_levels;
-#if GLIB_CHECK_VERSION(2, 32, 0)
g_mutex_lock (&priv->mutex);
-#else
- g_mutex_lock (priv->mutex);
-#endif
stack_fix_size (priv);
-#if GLIB_CHECK_VERSION(2, 32, 0)
g_mutex_unlock (&priv->mutex);
-#else
- g_mutex_unlock (priv->mutex);
-#endif
do_menu_update (manager);
}
break;
@@ -436,12 +409,7 @@ caja_undostack_manager_redo (CajaUndoStackManager * manager,
char *puri;
CajaUndoStackManagerPrivate *priv = manager->priv;
-#if GLIB_CHECK_VERSION(2, 32, 0)
g_mutex_lock (&priv->mutex);
-#else
- g_mutex_lock (priv->mutex);
-#endif
-
CajaUndoStackActionData *action = stack_scroll_left (priv);
@@ -450,12 +418,7 @@ caja_undostack_manager_redo (CajaUndoStackManager * manager,
action->locked = TRUE;
}
-#if GLIB_CHECK_VERSION(2, 32, 0)
g_mutex_unlock (&priv->mutex);
-#else
- g_mutex_unlock (priv->mutex);
-#endif
-
do_menu_update (manager);
@@ -585,11 +548,7 @@ caja_undostack_manager_undo (CajaUndoStackManager * manager,
char *new_name;
CajaUndoStackManagerPrivate *priv = manager->priv;
-#if GLIB_CHECK_VERSION(2, 32, 0)
g_mutex_lock (&priv->mutex);
-#else
- g_mutex_lock (priv->mutex);
-#endif
CajaUndoStackActionData *action = stack_scroll_right (priv);
@@ -597,11 +556,7 @@ caja_undostack_manager_undo (CajaUndoStackManager * manager,
action->locked = TRUE;
}
-#if GLIB_CHECK_VERSION(2, 32, 0)
g_mutex_unlock (&priv->mutex);
-#else
- g_mutex_unlock (priv->mutex);
-#endif
do_menu_update (manager);
@@ -757,22 +712,13 @@ caja_undostack_manager_add_action (CajaUndoStackManager * manager,
action->manager = manager;
-#if GLIB_CHECK_VERSION(2, 32, 0)
g_mutex_lock (&priv->mutex);
-#else
- g_mutex_lock (priv->mutex);
-#endif
stack_push_action (priv, action);
-#if GLIB_CHECK_VERSION(2, 32, 0)
g_mutex_unlock (&priv->mutex);
-#else
- g_mutex_unlock (priv->mutex);
-#endif
do_menu_update (manager);
-
}
static GList *
@@ -825,11 +771,7 @@ caja_undostack_manager_trash_has_emptied (CajaUndoStackManager *
/* Clear actions from the oldest to the newest move to trash */
-#if GLIB_CHECK_VERSION(2, 32, 0)
g_mutex_lock (&priv->mutex);
-#else
- g_mutex_lock (priv->mutex);
-#endif
clear_redo_actions (priv);
CajaUndoStackActionData *action = NULL;
@@ -855,11 +797,7 @@ caja_undostack_manager_trash_has_emptied (CajaUndoStackManager *
}
g_queue_free (tmp_stack);
-#if GLIB_CHECK_VERSION(2, 32, 0)
g_mutex_unlock (&priv->mutex);
-#else
- g_mutex_unlock (priv->mutex);
-#endif
do_menu_update (manager);
}
@@ -1922,11 +1860,7 @@ do_menu_update (CajaUndoStackManager * manager)
CajaUndoStackManagerPrivate *priv = manager->priv;
CajaUndoStackMenuData *data = g_slice_new0 (CajaUndoStackMenuData);
-#if GLIB_CHECK_VERSION(2, 32, 0)
g_mutex_lock (&priv->mutex);
-#else
- g_mutex_lock (priv->mutex);
-#endif
action = get_next_undo_action (priv);
data->undo_label = get_undo_label (action);
@@ -1937,11 +1871,7 @@ do_menu_update (CajaUndoStackManager * manager)
data->redo_label = get_redo_label (action);
data->redo_description = get_redo_description (action);
-#if GLIB_CHECK_VERSION(2, 32, 0)
g_mutex_unlock (&priv->mutex);
-#else
- g_mutex_unlock (priv->mutex);
-#endif
/* Update menus */
g_signal_emit_by_name (manager, "request-menu-update", data);
@@ -2034,66 +1964,52 @@ get_uri_parent_path (char *uri)
static GHashTable *
retrieve_files_to_restore (GHashTable * trashed)
{
- GFileEnumerator *enumerator;
- GFileInfo *info;
- GFile *trash;
- GFile *item;
- guint64 mtime_item;
- guint64 *mtime;
- const char *origpath;
- GFile *origfile;
- char *origuri;
- gpointer lookupvalue;
- GHashTable *to_restore;
-
- to_restore =
- g_hash_table_new_full (g_direct_hash,
- g_direct_equal, g_object_unref, g_free);
+ if (!(g_hash_table_size (trashed)) > 0) {
+ return NULL;
+ }
- trash = g_file_new_for_uri ("trash:");
+ GFile *trash = g_file_new_for_uri ("trash:");
- enumerator = g_file_enumerate_children (trash,
+ GFileEnumerator *enumerator = g_file_enumerate_children (trash,
G_FILE_ATTRIBUTE_STANDARD_NAME
","
G_FILE_ATTRIBUTE_TIME_MODIFIED
",trash::orig-path", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, FALSE, NULL);
- mtime = 0;
-
- guint nb;
- GList *l;
- if (!(g_hash_table_size (trashed)) > 0)
- return NULL;
-
+ GHashTable *to_restore = g_hash_table_new_full (g_direct_hash,
+ g_direct_equal, g_object_unref, g_free);
+
if (enumerator) {
- while ((info =
- g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) {
+ GFileInfo *info;
+ while ((info = g_file_enumerator_next_file (enumerator, NULL, NULL)) != NULL) {
/* Retrieve the original file uri */
- origpath = g_file_info_get_attribute_byte_string (info, "trash::orig-path");
- origfile = g_file_new_for_path (origpath);
- origuri = g_file_get_uri (origfile);
+ const char *origpath = g_file_info_get_attribute_byte_string (info, "trash::orig-path");
+ GFile *origfile = g_file_new_for_path (origpath);
+ char *origuri = g_file_get_uri (origfile);
g_object_unref (origfile);
- lookupvalue = g_hash_table_lookup (trashed, origuri);
+ gboolean origuri_inserted = FALSE;
+ gpointer lookupvalue = g_hash_table_lookup (trashed, origuri);
if (lookupvalue) {
- mtime = (guint64 *)
- lookupvalue;
- mtime_item =
- g_file_info_get_attribute_uint64
- (info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
+ guint64 *mtime = (guint64 *) lookupvalue;
+ guint64 mtime_item = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_TIME_MODIFIED);
if (*mtime == mtime_item) {
- item = g_file_get_child (trash, g_file_info_get_name (info)); /* File in the trash */
+ GFile *item = g_file_get_child (trash, g_file_info_get_name (info)); /* File in the trash */
g_hash_table_insert (to_restore, item, origuri);
+ origuri_inserted = TRUE;
}
- } else {
- g_free (origuri);
}
+ if (!origuri_inserted) {
+ g_free (origuri);
+ }
}
+
g_file_enumerator_close (enumerator, FALSE, NULL);
g_object_unref (enumerator);
}
+
g_object_unref (trash);
return to_restore;