/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * gpdf preferences
 *
 */

#include <glib.h>
#include <gconf/gconf-client.h>

#include "gpdf-prefs.h"

gint      gpdf_default_width = DEFAULT_WINDOW_WIDTH;
gint      gpdf_default_height = DEFAULT_WINDOW_HEIGHT;

void gpdf_prefs_load (void)
{  
  GConfClient *gconf_client;
  
  gconf_client = gpdf_prefs_gconf_client();
  if((gpdf_default_width = gconf_client_get_int
      (gconf_client, "/apps/gpdf/layout/windowwidth", NULL)) == 0)
    gpdf_default_width = DEFAULT_WINDOW_WIDTH;
  if((gpdf_default_height = gconf_client_get_int
      (gconf_client, "/apps/gpdf/layout/windowheight", NULL)) == 0)
    gpdf_default_height = DEFAULT_WINDOW_HEIGHT;

}

static void
gpdf_prefs_changed(GConfClient* client, guint cnxn_id,
                  GConfEntry *entry, gpointer user_data)
{
  if(!strcmp(entry->key, "/apps/gpdf/layout/windowwidth")) {
    if((gpdf_default_width = gconf_client_get_int
	(client, "/apps/gpdf/layout/windowwidth", NULL)) == 0)
      gpdf_default_width = DEFAULT_WINDOW_WIDTH;
  }
  else if(!strcmp(entry->key, "/apps/gpdf/layout/windowheight")) {
    if((gpdf_default_height = gconf_client_get_int
	(client, "/apps/gpdf/layout/windowheight", NULL)) == 0)
      gpdf_default_height = DEFAULT_WINDOW_HEIGHT;
  }
}

GConfClient *
gpdf_prefs_gconf_client()
{
        static GConfClient *gconf_client = NULL;

        if(!gconf_client) {
                g_assert(gconf_is_initialized());
                gconf_client = gconf_client_get_default();
                g_assert(gconf_client != NULL);
                gconf_client_add_dir(gconf_client, "/apps/gpdf",
                                     GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
                gconf_client_notify_add(gconf_client, "/apps/gpdf",
                                        (GConfClientNotifyFunc)gpdf_prefs_changed,
                                        NULL, NULL, NULL);
        }

        return gconf_client;
}

