Commit 2d618954 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

selections: make volatile again

permanent selections break natural workflows.
parent 57df6d22
......@@ -160,13 +160,6 @@ folder_changed_cb (GthMonitor *monitor,
}
void
selections__initialize_cb (void)
{
gth_selections_manager_load_from_file ();
}
void
selections__gth_browser_construct_cb (GthBrowser *browser)
{
......@@ -199,13 +192,6 @@ selections__gth_browser_construct_cb (GthBrowser *browser)
}
void
selections__gth_browser_close_last_window_cb (GthBrowser *browser)
{
gth_selections_manager_save_to_file ();
}
void
selections__gth_browser_update_sensitivity_cb (GthBrowser *browser)
{
......
......@@ -24,9 +24,7 @@
#include <gthumb.h>
void selections__initialize_cb (void);
void selections__gth_browser_construct_cb (GthBrowser *browser);
void selections__gth_browser_close_last_window_cb (GthBrowser *browser);
void selections__gth_browser_update_sensitivity_cb (GthBrowser *browser);
gpointer selections__gth_browser_file_list_key_press_cb (GthBrowser *browser,
GdkEventKey *event);
......
......@@ -33,8 +33,6 @@ struct _GthSelectionsManagerPrivate {
char *order[GTH_SELECTIONS_MANAGER_N_SELECTIONS];
gboolean order_inverse[GTH_SELECTIONS_MANAGER_N_SELECTIONS];
GMutex mutex;
gboolean loaded;
gboolean changed;
};
......@@ -108,8 +106,6 @@ gth_selections_manager_init (GthSelectionsManager *self)
self->priv->order[i] = NULL;
self->priv->order_inverse[i] = FALSE;
}
self->priv->loaded = FALSE;
self->priv->changed = FALSE;
}
......@@ -330,55 +326,6 @@ _gth_selections_manager_load_from_node (GthSelectionsManager *self,
}
static void
_gth_selections_manager_load_if_required (GthSelectionsManager *self)
{
GFile *file;
char *buffer;
gsize size;
DomDocument *doc;
if (self->priv->loaded)
return;
file = gth_user_dir_get_file_for_read (GTH_DIR_DATA, GTHUMB_DIR, "selections.xml", NULL);
if (! _g_file_load_in_buffer (file, (void **) &buffer, &size, NULL, NULL)) {
g_object_unref (file);
return;
}
g_mutex_lock (&self->priv->mutex);
doc = dom_document_new ();
if (dom_document_load (doc, buffer, size, NULL)) {
DomElement *root = DOM_ELEMENT (doc)->first_child;
if (g_strcmp0 (root->tag_name, "selections") == 0) {
DomElement *child;
for (child = root->first_child; child; child = child->next_sibling) {
if (g_strcmp0 (child->tag_name, "selection") == 0)
_gth_selections_manager_load_from_node (self, child);
}
}
}
self->priv->loaded = TRUE;
g_mutex_unlock (&self->priv->mutex);
g_object_unref (doc);
g_free (buffer);
g_object_unref (file);
}
static void
_gth_selections_manager_changed (GthSelectionsManager *self)
{
self->priv->changed = TRUE;
}
void
gth_selections_manager_for_each_child (GFile *folder,
const char *attributes,
......@@ -394,8 +341,6 @@ gth_selections_manager_for_each_child (GFile *folder,
self = gth_selections_manager_get_default ();
n_selection = _g_file_get_n_selection (folder);
_gth_selections_manager_load_if_required (self);
g_mutex_lock (&self->priv->mutex);
data = g_new0 (ForEachChildData, 1);
data->selections_manager = self;
......@@ -444,8 +389,6 @@ gth_selections_manager_add_files (GFile *folder,
if (n_selection <= 0)
return FALSE;
_gth_selections_manager_load_if_required (self);
g_mutex_lock (&self->priv->mutex);
new_list = _g_file_list_dup (file_list);
......@@ -472,7 +415,6 @@ gth_selections_manager_add_files (GFile *folder,
g_mutex_unlock (&self->priv->mutex);
_gth_selections_manager_changed (self);
gth_monitor_emblems_changed (gth_main_get_default_monitor (), file_list);
gth_monitor_folder_changed (gth_main_get_default_monitor (),
folder,
......@@ -499,8 +441,6 @@ gth_selections_manager_remove_files (GFile *folder,
if (n_selection <= 0)
return;
_gth_selections_manager_load_if_required (self);
g_mutex_lock (&self->priv->mutex);
files_to_remove = g_hash_table_new (g_file_hash, (GEqualFunc) g_file_equal);
......@@ -527,7 +467,6 @@ gth_selections_manager_remove_files (GFile *folder,
g_mutex_unlock (&self->priv->mutex);
_gth_selections_manager_changed (self);
if (notify)
gth_monitor_folder_changed (gth_main_get_default_monitor (),
folder,
......@@ -554,8 +493,6 @@ gth_selections_manager_reorder (GFile *folder,
self = gth_selections_manager_get_default ();
_gth_selections_manager_load_if_required (self);
/* reorder the file list */
g_mutex_lock (&self->priv->mutex);
......@@ -571,7 +508,6 @@ gth_selections_manager_reorder (GFile *folder,
gth_selections_manager_set_sort_type (folder, "general::unsorted", FALSE);
_gth_selections_manager_changed (self);
gth_monitor_order_changed (gth_main_get_default_monitor (),
folder,
new_order);
......@@ -600,8 +536,6 @@ gth_selections_manager_set_sort_type (GFile *folder,
self->priv->order_inverse[n_selection - 1] = sort_inverse;
g_mutex_unlock (&self->priv->mutex);
_gth_selections_manager_changed (self);
}
......@@ -616,7 +550,6 @@ gth_selections_manager_file_exists (int n_selection,
return FALSE;
self = gth_selections_manager_get_default ();
_gth_selections_manager_load_if_required (self);
g_mutex_lock (&self->priv->mutex);
result = (g_hash_table_lookup (self->priv->files_hash[n_selection - 1], file) != NULL);
......@@ -637,7 +570,6 @@ gth_selections_manager_get_is_empty (int n_selection)
return TRUE;
self = gth_selections_manager_get_default ();
_gth_selections_manager_load_if_required (self);
g_mutex_lock (&self->priv->mutex);
size = g_hash_table_size (self->priv->files_hash[n_selection - 1]);
......@@ -675,51 +607,6 @@ _gth_selections_manager_create_selection_node (GthSelectionsManager *self,
}
void
gth_selections_manager_load_from_file (void)
{
GthSelectionsManager *self;
self = gth_selections_manager_get_default ();
_gth_selections_manager_load_if_required (self);
}
void
gth_selections_manager_save_to_file (void)
{
GthSelectionsManager *self;
DomDocument *doc;
DomElement *root, *selections;
GFile *file;
char *buffer;
gsize size;
self = gth_selections_manager_get_default ();
if (! self->priv->changed)
return;
g_mutex_lock (&self->priv->mutex);
doc = dom_document_new ();
root = DOM_ELEMENT (doc);
selections = dom_document_create_element (doc, "selections", NULL);
dom_element_append_child (root, selections);
for (int i = 1; i <= GTH_SELECTIONS_MANAGER_N_SELECTIONS; i++)
dom_element_append_child (selections, _gth_selections_manager_create_selection_node (self, i, doc));
buffer = dom_document_dump (doc, &size);
file = gth_user_dir_get_file_for_write (GTH_DIR_DATA, GTHUMB_DIR, "selections.xml", NULL);
_g_file_write (file, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, buffer, size, NULL, NULL);
self->priv->changed = FALSE;
g_mutex_unlock (&self->priv->mutex);
g_object_unref (file);
g_free (buffer);
}
int
_g_file_get_n_selection (GFile *file)
{
......
......@@ -76,8 +76,6 @@ void gth_selections_manager_update_file_info (GFile *file,
gboolean gth_selections_manager_file_exists (int n_selection,
GFile *file);
gboolean gth_selections_manager_get_is_empty (int n_selection);
void gth_selections_manager_load_from_file (void);
void gth_selections_manager_save_to_file (void);
/* utilities */
......
......@@ -33,9 +33,7 @@ gthumb_extension_activate (void)
{
gth_main_register_file_source (GTH_TYPE_FILE_SOURCE_SELECTIONS);
gth_main_register_metadata_provider (GTH_TYPE_METADATA_PROVIDER_SELECTIONS);
gth_hook_add_callback ("initialize", 10, G_CALLBACK (selections__initialize_cb), NULL);
gth_hook_add_callback ("gth-browser-construct", 10, G_CALLBACK (selections__gth_browser_construct_cb), NULL);
gth_hook_add_callback ("gth-browser-close-last-window", 10, G_CALLBACK (selections__gth_browser_close_last_window_cb), NULL);
gth_hook_add_callback ("gth-browser-update-sensitivity", 10, G_CALLBACK (selections__gth_browser_update_sensitivity_cb), NULL);
gth_hook_add_callback ("gth-browser-file-list-key-press", 10, G_CALLBACK (selections__gth_browser_file_list_key_press_cb), NULL);
gth_hook_add_callback ("gth-browser-load-location-after", 10, G_CALLBACK (selections__gth_browser_load_location_after_cb), NULL);
......
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