summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann <sandmann@redhat.com>2008-06-20 21:36:26 -0400
committerSøren Sandmann <sandmann@redhat.com>2008-06-20 21:36:26 -0400
commit02a89709e71384a4f6ef54bfd97eb2c4100d8136 (patch)
treed90e6fed03df943dc68dd03f12b3293d6acd0bbe
parent8111bc0c9600e42a96b01d6f6ad630f4bb06c970 (diff)
Don't cache the meta data
-rw-r--r--TODO34
-rw-r--r--siv.c199
-rw-r--r--siv.h5
-rw-r--r--window.c18
4 files changed, 151 insertions, 105 deletions
diff --git a/TODO b/TODO
index ec000f6..879a0ca 100644
--- a/TODO
+++ b/TODO
@@ -5,12 +5,46 @@
- Statusbar
- Size, position, color
+- One-instance
+ - Make it one-instance with d-bus so that if you try to open the
+ same image twice, you will get the old window.
+
+ - Own the "siv.gnome.org" name, have a method to open a new
+ window (or present an existing one).
+
+ - On startup:
+ if (!own_name())
+ get_name().open (filename);
+ else
+ open (filename);
+
+ - Look at evince.
+
+ - "Open a copy"
+
+ - At that point, caching the meta data should be feasible (though it
+ should still deal with the case where someone presses Ctrl-C).
+
- Metadata
- Keep track of when files are used
- Limit size to 1000 most recently used files
Done:
+- If more than one instance of the application is
+ open, then things go haywrite.
+
+ Either only allow one open instance, or monitor the metadata file.
+
+ Or only write out the ones we have changed - ie., write-out
+ consists of reading the file into hash table, then modifying, then
+ writing out.
+
+ In fact, maybe we should just never cache the table in memory.
+ Just read it every time we need data from it.
+
+ If people put .gnome2 on NFS, then they lose.
+
- Set mimetypes in open dialog
- Dragging
diff --git a/siv.c b/siv.c
index b0294e2..71e2ff0 100644
--- a/siv.c
+++ b/siv.c
@@ -11,8 +11,6 @@
struct App
{
int n_windows;
-
- GHashTable *meta_data;
};
void
@@ -38,7 +36,7 @@ app_show_warning (GtkWidget *parent_window,
if (secondary)
{
gtk_message_dialog_format_secondary_markup (
- dialog, "%s", secondary);
+ GTK_MESSAGE_DIALOG (dialog), "%s", secondary);
}
g_free (message);
@@ -113,94 +111,6 @@ encode (const char *filename)
return g_string_free (result, FALSE);
}
-MetaData *
-app_get_meta_data (App *app,
- const char *file)
-{
- char *encoded = encode (file);
- MetaData *data = g_hash_table_lookup (app->meta_data, encoded);
-
- g_free (encoded);
-
- return data;
-}
-
-static gchar *
-make_filename (void)
-{
- return g_build_filename (
- g_get_home_dir(), ".gnome2", "siv.metadata", NULL);
-}
-
-static void
-foreach (gpointer key, gpointer value, gpointer user_data)
-{
- gchar *filename = key;
- MetaData *meta = value;
- GKeyFile *key_file = user_data;
-
- g_key_file_set_integer (key_file, filename, "window_x", meta->window_x);
- g_key_file_set_integer (key_file, filename, "window_y", meta->window_y);
- g_key_file_set_integer (key_file, filename, "window_width", meta->window_width);
- g_key_file_set_integer (key_file, filename, "window_height", meta->window_height);
- g_key_file_set_integer (key_file, filename, "background", meta->background);
- g_key_file_set_integer (key_file, filename, "smooth_image", meta->smooth_image);
- g_key_file_set_integer (key_file, filename, "zoom_level", meta->zoom_level);
- g_key_file_set_integer (key_file, filename, "hadj", meta->hadj);
- g_key_file_set_integer (key_file, filename, "vadj", meta->vadj);
-}
-
-void
-app_set_meta_data (App *app,
- const char *filename,
- int window_x,
- int window_y,
- int window_width,
- int window_height,
- gboolean smooth_image,
- BackgroundType background,
- int zoom_level,
- int vadj,
- int hadj)
-{
- GKeyFile *keyfile = g_key_file_new ();
- char *encoded = encode (filename);
- MetaData *data = g_hash_table_lookup (app->meta_data, encoded);
- char *key_filename = make_filename();
- char *output;
-
- if (!data)
- {
- data = g_new0 (MetaData, 1);
-
- g_hash_table_insert (app->meta_data, g_strdup (encoded), data);
- }
-
- data->window_x = window_x;
- data->window_y = window_y;
- data->window_width = window_width;
- data->window_height = window_height;
- data->background = background;
- data->smooth_image = smooth_image;
- data->zoom_level = zoom_level;
- data->hadj = hadj;
- data->vadj = vadj;
-
- g_hash_table_foreach (app->meta_data, foreach, keyfile);
-
- output = g_key_file_to_data (keyfile, NULL, NULL);
- if (output)
- {
- g_file_set_contents (key_filename, output, -1, NULL);
- g_free (output);
- }
-
- g_key_file_free (keyfile);
- g_free (key_filename);
- g_free (encoded);
-}
-
-
static gboolean
get_int (GKeyFile *keyfile, const char *group, const char *key, int *result)
{
@@ -221,6 +131,13 @@ get_int (GKeyFile *keyfile, const char *group, const char *key, int *result)
return TRUE;
}
+static gchar *
+make_filename (void)
+{
+ return g_build_filename (
+ g_get_home_dir(), ".gnome2", "siv.metadata", NULL);
+}
+
static GHashTable *
load_meta_data (void)
{
@@ -231,7 +148,7 @@ load_meta_data (void)
keyfile = g_key_file_new ();
filename = make_filename();
- result = g_hash_table_new (g_str_hash, g_str_equal);
+ result = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
if (g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, NULL))
{
@@ -289,6 +206,102 @@ load_meta_data (void)
return result;
}
+gboolean
+app_get_meta_data (App *app,
+ const char *file,
+ MetaData *data)
+{
+ char *encoded = encode (file);
+ GHashTable *table = load_meta_data ();
+ MetaData *d = g_hash_table_lookup (table, encoded);
+ gboolean result = FALSE;
+
+ if (d)
+ {
+ if (data)
+ *data = *d;
+
+ result = TRUE;
+ }
+
+ g_free (encoded);
+ g_hash_table_destroy (table);
+
+ return result;
+}
+
+static void
+foreach (gpointer key, gpointer value, gpointer user_data)
+{
+ gchar *filename = key;
+ MetaData *meta = value;
+ GKeyFile *key_file = user_data;
+
+ g_key_file_set_integer (key_file, filename, "window_x", meta->window_x);
+ g_key_file_set_integer (key_file, filename, "window_y", meta->window_y);
+ g_key_file_set_integer (key_file, filename, "window_width", meta->window_width);
+ g_key_file_set_integer (key_file, filename, "window_height", meta->window_height);
+ g_key_file_set_integer (key_file, filename, "background", meta->background);
+ g_key_file_set_integer (key_file, filename, "smooth_image", meta->smooth_image);
+ g_key_file_set_integer (key_file, filename, "zoom_level", meta->zoom_level);
+ g_key_file_set_integer (key_file, filename, "hadj", meta->hadj);
+ g_key_file_set_integer (key_file, filename, "vadj", meta->vadj);
+}
+
+void
+app_set_meta_data (App *app,
+ const char *filename,
+ int window_x,
+ int window_y,
+ int window_width,
+ int window_height,
+ gboolean smooth_image,
+ BackgroundType background,
+ int zoom_level,
+ int vadj,
+ int hadj)
+{
+ GKeyFile *keyfile = g_key_file_new ();
+ char *encoded = encode (filename);
+ GHashTable *table = load_meta_data ();
+ MetaData *data = g_hash_table_lookup (table, encoded);
+ char *key_filename = make_filename();
+ char *output;
+
+ if (!data)
+ {
+ data = g_new0 (MetaData, 1);
+
+ g_hash_table_insert (table, g_strdup (encoded), data);
+ }
+
+ data->window_x = window_x;
+ data->window_y = window_y;
+ data->window_width = window_width;
+ data->window_height = window_height;
+ data->background = background;
+ data->smooth_image = smooth_image;
+ data->zoom_level = zoom_level;
+ data->hadj = hadj;
+ data->vadj = vadj;
+
+ g_hash_table_foreach (table, foreach, keyfile);
+
+ output = g_key_file_to_data (keyfile, NULL, NULL);
+ if (output)
+ {
+ g_file_set_contents (key_filename, output, -1, NULL);
+ g_free (output);
+ }
+
+ g_key_file_free (keyfile);
+ g_free (key_filename);
+ g_free (encoded);
+
+ g_hash_table_destroy (table);
+}
+
+
static void
app_new (int argc, char **argv)
{
@@ -328,8 +341,6 @@ app_new (int argc, char **argv)
filenames = g_list_reverse (filenames);
- app->meta_data = load_meta_data ();
-
/* When a window is created, it increases the app->n_windows counter;
* when it is destroyed it decreases it. The problem is if the first
* window fails to load the file, it will cause the counter to reach
diff --git a/siv.h b/siv.h
index 1fcc595..6c5905a 100644
--- a/siv.h
+++ b/siv.h
@@ -39,8 +39,9 @@ void app_register_window (App *app,
SivWindow *window);
void app_unregister_window (App *app,
SivWindow *window);
-MetaData *app_get_meta_data (App *app,
- const char *file);
+gboolean app_get_meta_data (App *app,
+ const char *file,
+ MetaData *data);
void app_set_meta_data (App *data,
const char *filename,
int window_x,
diff --git a/window.c b/window.c
index cdaf7fb..e7831e1 100644
--- a/window.c
+++ b/window.c
@@ -1022,18 +1022,18 @@ static void
apply_meta_data (SivWindow *window, const char *filename)
{
- const MetaData *data = app_get_meta_data (window->app, filename);
GtkCheckMenuItem *item;
+ MetaData data;
- if (data)
+ if (app_get_meta_data (window->app, filename, &data))
{
gtk_window_move (get_widget (window, "main_window"),
- data->window_x, data->window_y);
+ data.window_x, data.window_y);
gtk_window_resize (get_widget (window, "main_window"),
- data->window_width, data->window_height);
+ data.window_width, data.window_height);
- switch (data->background)
+ switch (data.background)
{
default:
case BG_NONE:
@@ -1052,13 +1052,13 @@ apply_meta_data (SivWindow *window, const char *filename)
gtk_check_menu_item_set_active (item, TRUE);
gtk_check_menu_item_set_active (get_widget (window, "menu_smooth_image"),
- data->smooth_image);
+ data.smooth_image);
- window->zoom_level = data->zoom_level;
+ window->zoom_level = data.zoom_level;
/* Adjustments have to be set after the window is shown */
- window->hadj = data->hadj;
- window->vadj = data->vadj;
+ window->hadj = data.hadj;
+ window->vadj = data.vadj;
}
else
{