From 64f46c994701e4e0a5994f610df010776e3cf584 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Thu, 11 Oct 2007 13:46:01 +0300 Subject: [PATCH] Use one global gconf client object. --- src/config-gconf.c | 39 +++++---------------------------------- src/config-gconf.h | 2 ++ src/maemo-osso.c | 6 +----- 3 files changed, 8 insertions(+), 39 deletions(-) diff --git a/src/config-gconf.c b/src/config-gconf.c index a49be3b..2986ad2 100644 --- a/src/config-gconf.c +++ b/src/config-gconf.c @@ -34,8 +34,6 @@ void config_update_proxy(void) { -GConfClient *gconf_client = gconf_client_get_default(); - if (_http_proxy_host) g_free(_http_proxy_host); @@ -47,7 +45,6 @@ if (gconf_client_get_bool(gconf_client, GCONF_KEY_HTTP_PROXY_ON, NULL)) { _http_proxy_host = NULL; _http_proxy_port = 0; } -g_object_unref(gconf_client); } static void @@ -79,14 +76,10 @@ g_free(route_file); gboolean config_save_repo(void) { -GConfClient *gconf_client = gconf_client_get_default(); GList *curr = _repo_list; GSList *temp_list = NULL; gint curr_repo_index = 0; -if (!gconf_client) - return FALSE; - /* Save the repositories. */ for (curr = _repo_list; curr != NULL; curr = curr->next) { /* Build from each part of a repo, delimited by newline characters: @@ -107,13 +100,10 @@ for (curr = _repo_list; curr != NULL; curr = curr->next) { rd->double_size, rd->nextable); temp_list = g_slist_append(temp_list, g_strdup(buffer)); if (rd == _curr_repo) - gconf_client_set_int(gconf_client, - GCONF_KEY_CURRREPO, curr_repo_index, NULL); + gconf_client_set_int(gconf_client, GCONF_KEY_CURRREPO, curr_repo_index, NULL); curr_repo_index++; } -gconf_client_set_list(gconf_client, - GCONF_KEY_REPOSITORIES, - GCONF_VALUE_STRING, temp_list, NULL); +gconf_client_set_list(gconf_client, GCONF_KEY_REPOSITORIES, GCONF_VALUE_STRING, temp_list, NULL); g_slist_free(temp_list); @@ -125,10 +115,6 @@ config_default_repo(void) { /* We have no repositories - create a default one. */ RepoData *repo = g_new(RepoData, 1); -GConfClient *gconf_client = gconf_client_get_default(); - -if (!gconf_client) - return; /* Get Map Cache Dir. Default is REPO_DEFAULT_CACHE_DIR. */ repo->cache_dir = gconf_client_get_string(gconf_client, GCONF_KEY_MAP_DIR_NAME, NULL); @@ -161,10 +147,6 @@ config_load_repo(void) { GSList *list, *curr; GConfValue *value; -GConfClient *gconf_client = gconf_client_get_default(); - -if (!gconf_client) - return FALSE; guint curr_repo_index = gconf_client_get_int(gconf_client, GCONF_KEY_CURRREPO, NULL); list = gconf_client_get_list(gconf_client, GCONF_KEY_REPOSITORIES, GCONF_VALUE_STRING, NULL); @@ -187,8 +169,6 @@ return TRUE; gboolean config_save_home(void) { -GConfClient *gconf_client = gconf_client_get_default(); - if (!gconf_client) return FALSE; @@ -202,11 +182,6 @@ return TRUE; gboolean config_save_filter(void) { -GConfClient *gconf_client = gconf_client_get_default(); - -if (!gconf_client) - return FALSE; - /* Filtering */ gconf_client_set_bool(gconf_client, GCONF_KEY_GPS_FILTER, _gps_filter, NULL); gconf_client_set_float(gconf_client, GCONF_KEY_GPS_FILTER_HDOP, _filter_hdop, NULL); @@ -224,14 +199,10 @@ gboolean config_save(void) { gchar *config_dir; -GConfClient *gconf_client = gconf_client_get_default(); gchar buffer[16]; gfloat center_lat, center_lon; gint i; -if (!gconf_client) - return FALSE; - /* Initialize config_dir. */ config_dir = gnome_vfs_expand_initial_tilde(CONFIG_DIR_NAME); g_mkdir_with_parents(config_dir, 0700); @@ -369,7 +340,6 @@ config_save_route(config_dir); #endif gconf_client_clear_cache(gconf_client); -g_object_unref(gconf_client); g_free(config_dir); return TRUE; } @@ -408,16 +378,18 @@ g_free(track_file); void config_init(void) { GConfValue *value; -GConfClient *gconf_client = gconf_client_get_default(); gchar *config_dir; gchar *str; gint i; +gconf_client=gconf_client_get_default(); if (!gconf_client) { popup_error(_window, _("Failed to initialize GConf. Quitting.")); exit(1); } +gconf_client_add_dir (gconf_client, GCONF_KEY_PREFIX, GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); + CenterMode _center_mode = CENTER_LEAD; UnitType _units = UNITS_KM; guint _degformat = DDPDDDDD; @@ -778,6 +750,5 @@ config_update_proxy(); mapper_db_connect(&_db, _mapper_db); gconf_client_clear_cache(gconf_client); -g_object_unref(gconf_client); g_free(config_dir); } diff --git a/src/config-gconf.h b/src/config-gconf.h index e269f71..49baa15 100644 --- a/src/config-gconf.h +++ b/src/config-gconf.h @@ -1,6 +1,8 @@ #ifndef _CONFIG_GCONF_H #define _CONFIG_GCONF_H +GConfClient *gconf_client; + void config_init(void); gboolean config_save_repo(void); gboolean config_load_repo(void); diff --git a/src/maemo-osso.c b/src/maemo-osso.c index be322b0..a84ea8c 100644 --- a/src/maemo-osso.c +++ b/src/maemo-osso.c @@ -47,12 +47,8 @@ if (state->system_inactivity_ind) { _must_save_data = FALSE; else { if (_conn_state > RCVR_OFF) { - GConfClient *gconf_client = gconf_client_get_default(); - if (!gconf_client || gconf_client_get_bool(gconf_client, - GCONF_KEY_DISCONNECT_ON_COVER, - NULL)) { + if (gconf_client_get_bool(gconf_client, GCONF_KEY_DISCONNECT_ON_COVER, NULL)) { gconf_client_clear_cache(gconf_client); - g_object_unref(gconf_client); set_conn_state(RCVR_OFF); rcvr_disconnect(); track_add(0, FALSE); -- 2.39.5