summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorErnestas Kulik <ernestask@gnome.org>2017-08-25 14:30:39 +0300
committerErnestas Kulik <ernestask@gnome.org>2017-08-25 14:30:39 +0300
commit2494a88cfd2508f1220d5478759d201032758dc7 (patch)
tree596bb39a50c097b2083eeb8a673edbb4c14fd97b
parent327def41e24fba3821a4b7665126c6dfa2503268 (diff)
downloadnautilus-wip/ernestask/attributes.tar.gz
-rw-r--r--src-ng/nautilus-attribute.c113
-rw-r--r--src-ng/nautilus-attribute.h45
-rw-r--r--src-ng/nautilus-file.c45
-rw-r--r--src-ng/nautilus-tasks.c1
-rw-r--r--src-ng/nautilus-tasks.h6
5 files changed, 50 insertions, 160 deletions
diff --git a/src-ng/nautilus-attribute.c b/src-ng/nautilus-attribute.c
index 70b7c6df2..36890172f 100644
--- a/src-ng/nautilus-attribute.c
+++ b/src-ng/nautilus-attribute.c
@@ -20,18 +20,13 @@
struct _NautilusAttribute
{
- GRecMutex mutex;
+ GMutex mutex;
gpointer value;
NautilusAttributeState state;
- NautilusTaskFunc update_func;
- NautilusTask *update_task;
-
NautilusCopyFunc copy_func;
GDestroyNotify destroy_func;
-
- GCancellable *cancellable;
};
G_DEFINE_TYPE (NautilusAttribute, nautilus_attribute, G_TYPE_OBJECT)
@@ -43,17 +38,13 @@ finalize (GObject *object)
self = NAUTILUS_ATTRIBUTE (object);
- g_rec_mutex_clear (&self->mutex);
+ g_mutex_clear (&self->mutex);
if (self->value != NULL)
{
g_clear_pointer (&self->value, self->destroy_func);
}
- g_cancellable_cancel (self->cancellable);
-
- g_object_unref (self->cancellable);
-
G_OBJECT_CLASS (nautilus_attribute_parent_class)->finalize (object);
}
@@ -70,100 +61,26 @@ nautilus_attribute_class_init (NautilusAttributeClass *klass)
static void
nautilus_attribute_init (NautilusAttribute *self)
{
- g_rec_mutex_init (&self->mutex);
-
- self->update_task = NULL;
- self->cancellable = g_cancellable_new ();
+ g_mutex_init (&self->mutex);
}
-typedef struct
+gpointer
+nautilus_attribute_get_value (NautilusAttribute *attribute)
{
- NautilusAttribute *attribute;
-
- NautilusAttributeUpdateValueCallback callback;
- gpointer user_data;
-} GetValueCallbackDetails;
-
-static void
-update_task_callback (NautilusTask *task,
- gpointer user_data)
-{
- GetValueCallbackDetails *details;
-
- details = user_data;
-
- g_rec_mutex_lock (&attribute->mutex);
-
- if (attribute->update_task == task)
- {
- if (attribute->state == NAUTILUS_ATTRIBUTE_STATE_PENDING)
- {
- attribute->state = NAUTILUS_ATTRIBUTE_STATE_VALID;
- }
-
-
-
- details->callback (details->attribute, nautilus_task_get_result (task),
- details->user_data);
- }
-
- g_rec_mutex_lock (&attribute->mutex);
-
- g_object_unref (details->attribute);
- g_free (details);
-}
-
-void
-nautilus_attribute_get_value (NautilusAttribute *attribute,
- NautilusAttributeUpdateValueCallback callback,
- gpointer user_data)
-{
- gpointer value;
+ gpointer value = NULL;
g_return_if_fail (NAUTILUS_IS_ATTRIBUTE (attribute));
- g_rec_mutex_lock (&attribute->mutex);
+ g_mutex_lock (&attribute->mutex);
- switch (attribute->state)
+ if (attribute->value != NULL)
{
- case NAUTILUS_ATTRIBUTE_STATE_PENDING:
- {
- GetValueCallbackDetails *details;
-
- details = g_new0 (GetValueCallbackDetails, 1);
-
- details->attribute = g_object_ref (attribute);
- details->callback = callback;
- details->user_data = user_data;
-
- nautilus_task_add_callback (attribute->update_task, update_task_callback, details);
- }
- break;
-
- case NAUTILUS_ATTRIBUTE_STATE_VALID:
- {
- callback (attribute, attribute->copy_func (attribute->value), user_data);
- };
- break;
-
- case NAUTILUS_ATTRIBUTE_STATE_INVALID:
- {
- if (attribute->update_task != NULL)
- {
- g_object_unref (attribute->update_task);
- }
-
- attribute->update_task = nautilus_task_new_with_func (attribute->update_func,
- g_object_ref (attribute),
- g_object_unref,
- attribute->cancellable);
-
- nautilus_task_add_callback (
- }
- break;
+ value = attribute->copy_func (attribute->value);
}
- g_rec_mutex_unlock (&attribute->mutex);
+ g_mutex_unlock (&attribute->mutex);
+
+ return value;
}
void
@@ -172,7 +89,7 @@ nautilus_attribute_set_value (NautilusAttribute *attribute,
{
g_return_if_fail (NAUTILUS_IS_ATTRIBUTE (attribute));
- g_rec_mutex_lock (&attribute->mutex);
+ g_mutex_lock (&attribute->mutex);
if (attribute->value != NULL)
{
@@ -186,7 +103,7 @@ nautilus_attribute_set_value (NautilusAttribute *attribute,
*/
attribute->state = NAUTILUS_ATTRIBUTE_STATE_VALID;
- g_rec_mutex_unlock (&attribute->mutex);
+ g_mutex_unlock (&attribute->mutex);
}
static gpointer
@@ -203,6 +120,7 @@ dummy_destroy_func (gpointer data)
NautilusAttribute *
nautilus_attribute_new (NautilusTaskFunc update_func,
+ gpointer update_func_data,
NautilusCopyFunc copy_func,
GDestroyNotify destroy_func)
{
@@ -217,6 +135,7 @@ nautilus_attribute_new (NautilusTaskFunc update_func,
{
copy_func = dummy_copy_func;
}
+ instance->update_func_data = update_func_data;
instance->copy_func = copy_func;
if (destroy_func == NULL)
{
diff --git a/src-ng/nautilus-attribute.h b/src-ng/nautilus-attribute.h
index 56c468730..cb7bdd8bc 100644
--- a/src-ng/nautilus-attribute.h
+++ b/src-ng/nautilus-attribute.h
@@ -31,10 +31,6 @@ G_DECLARE_FINAL_TYPE (NautilusAttribute, nautilus_attribute, NAUTILUS, ATTRIBUTE
typedef gpointer (*NautilusCopyFunc) (gpointer data);
#define NAUTILUS_COPY_FUNC(x) ((NautilusCopyFunc) x)
-typedef void (*NautilusAttributeUpdateValueCallback) (NautilusAttribute *attribute,
- gpointer value,
- gpointer user_data);
-
typedef enum
{
NAUTILUS_ATTRIBUTE_STATE_INVALID,
@@ -46,44 +42,45 @@ typedef enum
* nautilus_attribute_get_state:
* @attribute: an initialized #NautilusAttribute
*
- * Returns: the current state of @attribute
+ * Returns: the current state of the attribute
*/
-NautilusAttributeState nautilus_attribute_get_state (NautilusAttribute *attribute);
+NautilusAttributeState nautilus_attribute_get_state (NautilusAttribute *self);
/**
* nautilus_attribute_invalidate:
- * @attribute: an initialized #NautilusAttribute
+ * @self: a #NautilusAttribute instance
*
* Mark the value of @attribute as no longer valid.
*/
-void nautilus_attribute_invalidate (NautilusAttribute *attribute);
+void nautilus_attribute_invalidate (NautilusAttribute *self);
/**
* nautilus_attribute_get_value:
- * @attribute: an initialized #NautilusAttribute
- * @callback: (nullable): the function to call with the value of @attribute
- * @user_data: (nullable): additional data to pass to @callback
+ * @self: a #NautilusAttribute instance
+ *
+ * Returns: (transfer full): the value of the attribute
*/
-void nautilus_attribute_get_value (NautilusAttribute *attribute,
- NautilusAttributeUpdateValueCallback callback,
- gpointer user_data);
+gpointer nautilus_attribute_get_value (NautilusAttribute *self)
/**
* nautilus_attribute_set_value:
- * @attribute: an initialized #NautilusAttribute
- * @value: (nullable) (transfer full): the new value of @attribute
+ * @self: a #NautilusAttribute instance
+ * @value: (nullable) (transfer full): the new value of the attribute
+ */
+void nautilus_attribute_set_value (NautilusAttribute *self,
+ gpointer value);
+/**
+ * nautilus_attribute_set_value_from_task:
+ * @self: a #NautilusAttribute instance
+ * @task: an idle #NautilusTask
*/
-void nautilus_attribute_set_value (NautilusAttribute *attribute,
- gpointer value);
+void nautilus_attribute_set_value_from_task (NautilusAttribute *self,
+ NautilusTask *task
/**
* nautilus_attribute_new:
- * @update_func: the function to call to update invalid values
- * @copy_func: (nullable): the function to call when copying the value
* @destroy_func: (nullable): the function to call when destroying the value
*
- * Returns: a new #NautilusAttribute
+ * Returns: (transfer full): a #NautilusAttribute instance
*/
-NautilusAttribute *nautilus_attribute_new (NautilusTaskFunc update_func,
- NautilusCopyFunc copy_func,
- GDestroyNotify destroy_func);
+NautilusAttribute *nautilus_attribute_new (GDestroyNotify destroy_func);
#endif
diff --git a/src-ng/nautilus-file.c b/src-ng/nautilus-file.c
index d9f3e3755..fae3dea4b 100644
--- a/src-ng/nautilus-file.c
+++ b/src-ng/nautilus-file.c
@@ -140,7 +140,7 @@ renamed (NautilusFile *file,
g_assert (nautilus_file_table_insert (new_location, file));
- nautilus_attribute_item_invalidate (priv->attribute_info);
+ nautilus_attribute_invalidate (priv->attribute_info);
}
static void
@@ -182,6 +182,7 @@ nautilus_file_init (NautilusFile *self)
priv = nautilus_file_get_instance_private (self);
priv->attribute_info = nautilus_attribute_new (nautilus_query_info_func,
+ self,
NAUTILUS_COPY_FUNC (g_file_info_dup),
g_object_unref);
}
@@ -230,34 +231,9 @@ nautilus_file_query_info (NautilusFile *file,
g_debug ("%s: called for %p", __func__, (gpointer) file);
priv = nautilus_file_get_instance_private (file);
- cache_state = nautilus_cache_item_get_state (priv->cache,
- priv->cache_items[INFO]);
-
- /* This is not the right thing to do if a cache update is pending.
- * A task reference could be stored and we could connect to the signal,
- * but there might be a better way.
- */
- if (cache_state == NAUTILUS_CACHE_PENDING ||
- cache_state == NAUTILUS_CACHE_VALID)
- {
- GFileInfo *info;
-
- g_debug ("%s: info for %p is either pending or valid",
- __func__, (gpointer) file);
-
- info = nautilus_cache_item_get_value (priv->cache,
- priv->cache_items[INFO],
- NAUTILUS_COPY_FUNC (g_file_info_dup));
-
- callback (file, info, NULL, user_data);
-
- return;
- }
-
- nautilus_cache_item_set_pending (priv->cache, priv->cache_items[INFO]);
-
location = nautilus_file_get_location (file);
- task = nautilus_task_new_with_func (nautilus_query_info_func, location, g_object_unref,
+ task = nautilus_task_new_with_func (nautilus_query_info_task_func,
+ location, g_object_unref,
cancellable);
details = g_new0 (QueryInfoDetails, 1);
@@ -266,9 +242,9 @@ nautilus_file_query_info (NautilusFile *file,
details->callback = callback;
details->callback_data = user_data;
- nautilus_task_add_callback (task, query_info_task_callback, details);
+ nautilus_attribute_set_value_from_task (priv->attribute_info, task);
- nautilus_task_run (task);
+ nautilus_task_add_callback (task, query_info_task_callback, details);
}
void
@@ -284,8 +260,8 @@ nautilus_file_get_thumbnail (NautilusFile *file,
location = nautilus_file_get_location (file);
task = nautilus_task_new_with_func (nautilus_thumbnail_task_func,
- g_object_ref (location), g_object_unref,
- cancellable);
+ g_object_ref (location),
+ g_object_unref, cancellable);
nautilus_task_run (task);
}
@@ -351,10 +327,7 @@ nautilus_file_new_with_info (GFile *location,
instance = nautilus_file_new (location);
priv = nautilus_file_get_instance_private (instance);
- /* Ergh. */
- nautilus_cache_item_set_pending (priv->cache, priv->cache_items[INFO]);
- nautilus_cache_item_set_value (priv->cache, priv->cache_items[INFO],
- info);
+ nautilus_attribute_set_value (priv->attribute_info, info);
return instance;
}
diff --git a/src-ng/nautilus-tasks.c b/src-ng/nautilus-tasks.c
index 518a64bca..c2eb4a3fd 100644
--- a/src-ng/nautilus-tasks.c
+++ b/src-ng/nautilus-tasks.c
@@ -18,6 +18,7 @@
#include "nautilus-tasks.h"
+#include "nautilus-file.h"
#include "nautilus-file-changes.h"
#include <gdk-pixbuf/gdk-pixbuf.h>
diff --git a/src-ng/nautilus-tasks.h b/src-ng/nautilus-tasks.h
index 3ead61586..39f7015bd 100644
--- a/src-ng/nautilus-tasks.h
+++ b/src-ng/nautilus-tasks.h
@@ -23,13 +23,13 @@
void nautilus_enumerate_children_task_func (NautilusTask *task,
gpointer task_data);
-void nautilus_load_pixbuf_func (NautilusTask *task,
+void nautilus_load_pixbuf_task_func (NautilusTask *task,
+ gpointer task_data);
+void nautilus_query_info_task_func (NautilusTask *task,
gpointer task_data);
void nautilus_rename_task_func (NautilusTask *task,
gpointer task_data);
void nautilus_thumbnail_task_func (NautilusTask *task,
gpointer task_data);
-void nautilus_query_info_func (NautilusTask *task,
- gpointer task_data);
#endif