diff options
Diffstat (limited to 'siv.c')
-rw-r--r-- | siv.c | 159 |
1 files changed, 154 insertions, 5 deletions
@@ -5,15 +5,14 @@ #include <string.h> #include <math.h> #include "siv.h" -#include "metadata.h" #define _(a) a struct App { - MetaData *meta_data; - int n_windows; + + GHashTable *meta_data; }; static void @@ -54,12 +53,161 @@ app_unregister_window (App *app, Window *window) gtk_main_quit (); } -MetaInfo * +MetaData * app_get_meta_info (App *app, const char *file) { /* FIXME */ } +MetaData * +app_get_meta_data (App *app, + const char *file) +{ + MetaData *data = g_hash_table_lookup (app->meta_data, file); + + 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) +{ + /* FIXME */ +} + +void +app_set_meta_data (App *app, + const char *filename, + int window_x, + int window_y, + int window_height, + int window_width, + gboolean smooth_image, + BackgroundType background, + int zoom_level) +{ + GKeyFile *keyfile = g_key_file_new (); + MetaData *data = g_hash_table_lookup (app->meta_data, filename); + char *key_filename = make_filename(); + char *output; + + if (!data) + { + data = g_new0 (MetaData, 1); + + g_hash_table_insert (app->meta_data, g_strdup (filename), 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; + + g_hash_table_foreach (app->meta_data, foreach, keyfile); + + output = g_key_file_to_data (keyfile, NULL, NULL); + if (output) + { + g_file_set_contents (filename, output, -1, NULL); + g_free (output); + } + + g_key_file_free (keyfile); + g_free (key_filename); +} + + +static gboolean +get_int (GKeyFile *keyfile, const char *group, const char *key, int *result) +{ + GError *err = NULL; + int d; + + d = g_key_file_get_integer (keyfile, group, key, &err); + + if (err) + { + g_error_free (err); + return FALSE; + } + + if (result) + *result = d; + + return TRUE; +} + +static GHashTable * +load_meta_data (void) +{ + GKeyFile *keyfile; + char *filename; + GHashTable *result; + + keyfile = g_key_file_new (); + filename = make_filename(); + + result = g_hash_table_new (g_str_hash, g_str_equal); + + if (g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, NULL)) + { + gsize n_groups; + char **groups = g_key_file_get_groups (keyfile, &n_groups); + int i; + + for (i = 0; i < n_groups; ++i) + { + MetaData *data = g_new0 (MetaData, 1); + char *group = groups[i]; + int b; + + if (!get_int (keyfile, group, "window_x", &(data->window_x))) + data->window_x = 0; + + if (!get_int (keyfile, group, "window_y", &(data->window_y))) + data->window_y = 0; + + if (!get_int (keyfile, group, "window_width", &(data->window_width))) + data->window_width = 0; + + if (!get_int (keyfile, group, "window_height", &(data->window_height))) + data->window_height = 0; + + if (!get_int (keyfile, group, "background", &b)) + data->background = BG_NONE; + else + data->background = b; + + if (data->background >= BG_LAST || data->background < BG_FIRST) + data->background = BG_NONE; + + if (!get_int (keyfile, group, "smooth_image", &(data->smooth_image))) + data->smooth_image = TRUE; + + if (!get_int (keyfile, group, "zoom_level", &(data->zoom_level))) + data->zoom_level = 0; + + g_hash_table_insert (result, group, data); + } + + g_strfreev (groups); + } + + g_free (filename); + g_key_file_free (keyfile); + + return result; +} + static void app_new (int argc, char **argv) { @@ -88,7 +236,8 @@ app_new (int argc, char **argv) filenames = g_list_reverse (filenames); - app->meta_data = meta_data_new (); + app->meta_data = load_meta_data (); + g_hash_table_new (g_str_hash, g_str_equal); for (list = filenames; list != NULL; list = list->next) { |