summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann <sandmann@redhat.com>2008-03-09 12:22:32 -0400
committerSøren Sandmann <sandmann@redhat.com>2008-03-09 12:22:32 -0400
commit1e212475d90102c11d2642b046c63afd1363e797 (patch)
tree760529c220fbfff17f19e81610ae62866ed1b8c2
parent239031074fe2cc2c41ac4ae4e1ed4b54a5d74c21 (diff)
Add metadata
-rw-r--r--metadata.c166
-rw-r--r--metadata.h37
-rw-r--r--siv.c17
3 files changed, 210 insertions, 10 deletions
diff --git a/metadata.c b/metadata.c
new file mode 100644
index 0000000..bc50540
--- /dev/null
+++ b/metadata.c
@@ -0,0 +1,166 @@
+#include "metadata.h"
+
+struct MetaData
+{
+ GHashTable *info; /* filename=>MetaInfo */
+};
+
+static gchar *
+make_filename (void)
+{
+ return g_build_filename (
+ g_get_home_dir(), ".gnome2", "siv.metadata", NULL);
+}
+
+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 void
+populate_meta_data_from_keyfile (MetaData *data, GKeyFile *keyfile)
+{
+ gchar **groups;
+ gsize n_groups;
+ int i;
+
+ groups = g_key_file_get_groups (keyfile, &n_groups);
+
+ for (i = 0; i < n_groups; ++i)
+ {
+ MetaInfo *info = g_new0 (MetaInfo, 1);
+ char *group = groups[i];
+ int b;
+
+ if (!get_int (keyfile, group, "window_x", &(info->window_x)))
+ info->window_x = 0;
+
+ if (!get_int (keyfile, group, "window_y", &(info->window_y)))
+ info->window_y = 0;
+
+ if (!get_int (keyfile, group, "window_width", &(info->window_width)))
+ info->window_width = 0;
+
+ if (!get_int (keyfile, group, "window_height", &(info->window_height)))
+ info->window_height = 0;
+
+ if (!get_int (keyfile, group, "background", &b))
+ info->background = BG_NONE;
+ else
+ info->background = b;
+
+ if (info->background >= BG_LAST || info->background < BG_FIRST)
+ info->background = BG_NONE;
+
+ if (!get_int (keyfile, group, "smooth_image", &(info->smooth_image)))
+ info->smooth_image = TRUE;
+
+ if (!get_int (keyfile, group, "zoom_level", &(info->zoom_level)))
+ info->zoom_level = 0;
+
+ g_hash_table_insert (data->info, group, info);
+ }
+
+ g_strfreev (groups);
+}
+
+MetaData *
+meta_data_new (void)
+{
+ GKeyFile *keyfile;
+ char *filename;
+ MetaData *meta_data;
+
+ keyfile = g_key_file_new ();
+ filename = make_filename();
+
+ meta_data = g_new0 (MetaData, 1);
+ meta_data->info = g_hash_table_new (g_str_hash, g_str_equal);
+
+ if (g_key_file_load_from_file (keyfile, filename, G_KEY_FILE_NONE, NULL))
+ populate_meta_data_from_keyfile (meta_data, keyfile);
+
+ g_free (filename);
+ g_key_file_free (keyfile);
+
+ return meta_data;
+}
+
+const MetaInfo *
+meta_data_get_info (MetaData *data,
+ const char *filename)
+{
+ const MetaInfo *info = g_hash_table_lookup (data->info, filename);
+
+ return info;
+}
+
+static void
+foreach (gpointer key, gpointer value, gpointer user_data)
+{
+
+
+}
+
+static void
+meta_data_save (MetaData *meta_data)
+{
+ char *filename;
+ GKeyFile *keyfile = g_key_file_new ();
+ char *data;
+
+ g_hash_table_foreach (meta_data->info, foreach, keyfile);
+
+ filename = make_filename ();
+
+ data = g_key_file_to_data (keyfile, NULL, NULL);
+ if (data)
+ {
+ g_file_set_contents (filename, data, -1, NULL);
+ g_free (data);
+ }
+
+ g_free (filename);
+}
+
+void
+meta_data_add_info (MetaData *data,
+ const char *filename,
+ int window_x,
+ int window_y,
+ int window_width,
+ int window_height,
+ int smooth_image,
+ BackgroundType background,
+ int zoom_level)
+{
+ MetaInfo *info = g_hash_table_lookup (data->info, filename);
+
+ if (!info)
+ info = g_new0 (MetaInfo, 1);
+
+ info->window_x = window_x;
+ info->window_y = window_y;
+ info->window_width = window_width;
+ info->window_height = window_height;
+ info->background = background;
+ info->smooth_image = smooth_image;
+ info->zoom_level = zoom_level;
+
+ meta_data_save (data);
+}
diff --git a/metadata.h b/metadata.h
new file mode 100644
index 0000000..258f57c
--- /dev/null
+++ b/metadata.h
@@ -0,0 +1,37 @@
+#include <glib.h>
+
+typedef struct MetaData MetaData;
+typedef struct MetaInfo MetaInfo;
+typedef enum
+{
+ BG_FIRST,
+ BG_NONE = BG_FIRST,
+ BG_CHECKERBAORD,
+ BG_WHITE,
+ BG_LAST
+} BackgroundType;
+
+
+struct MetaInfo
+{
+ int window_x;
+ int window_y;
+ int window_width;
+ int window_height;
+ BackgroundType background;
+ gboolean smooth_image;
+ int zoom_level;
+};
+
+MetaData * meta_data_new (void);
+const MetaInfo *meta_data_get_info (MetaData *data,
+ const char *filename);
+void meta_data_add_info (MetaData *data,
+ const char *filename,
+ int window_x,
+ int window_y,
+ int window_height,
+ int window_width,
+ gboolean smooth_image,
+ BackgroundType background,
+ int zoom_level);
diff --git a/siv.c b/siv.c
index 309187e..f4f6906 100644
--- a/siv.c
+++ b/siv.c
@@ -32,6 +32,12 @@
#define MIN_ZOOM -80
#define MAX_ZOOM 65
+typedef struct Window Window;
+struct Window
+{
+
+};
+
typedef struct Application Application;
struct Application
@@ -100,12 +106,9 @@ compute_size (Application *app, int *w, int *h)
static gboolean
on_expose (GtkWidget *drawing_area, GdkEventExpose *expose, Application *app)
{
- int w, h;
GdkPixbuf *tmp;
GdkInterpType interp;
- gboolean has_alpha;
GdkRectangle dest;
- int win_x, win_y;
int window_width, window_height;
GdkRectangle image;
guint32 color1, color2;
@@ -147,7 +150,7 @@ on_expose (GtkWidget *drawing_area, GdkEventExpose *expose, Application *app)
color1 = 0x00ffffff;
color2 = 0x00ffffff;
}
- else if (gtk_check_menu_item_get_active (GET_WIDGET (app, "menu_checkerboard")))
+ else /* Checkerboard */
{
color1 = 0x00808080;
color2 = 0x00cccccc;
@@ -209,7 +212,6 @@ rebuild (Application *app)
{
int w, h;
GtkAdjustment *vadj, *hadj;
- double new_v;
compute_size (app, &w, &h);
@@ -334,13 +336,10 @@ on_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer data)
}
else
{
- int w, h;
GdkRectangle old;
GdkRectangle new;
GdkRegion *region;
int dx, dy;
- int old_x, new_x;
- int old_y, new_y;
if (!app->original)
return;
@@ -379,8 +378,6 @@ on_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer data)
region = gdk_region_rectangle (&old);
- g_print ("%d %d\n", dx, dy);
-
gdk_window_move_region (widget->window, region, dx, dy);
gdk_region_destroy (region);