From 3b0b1615b1929e3efa1f489c5c43a837e75867f6 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Mon, 7 Apr 2008 15:07:05 +0300 Subject: [PATCH] Disconnect and reconnect to database only if the path has changed. Use a helper function to disconnect and reconnect. --- src/settings-gui.c | 46 ++++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/src/settings-gui.c b/src/settings-gui.c index 1f10018..12fcd58 100644 --- a/src/settings-gui.c +++ b/src/settings-gui.c @@ -56,7 +56,6 @@ struct _GpsDialogInfo { GtkTreeIter iter; }; - #define UPDATE_GC(gc) gdk_gc_set_line_attributes(gc, _draw_width, GDK_LINE_SOLID, GDK_CAP_ROUND, GDK_JOIN_ROUND); void @@ -76,7 +75,7 @@ for (i=0; i < COLORABLE_ENUM_COUNT; i++) { } static gboolean -settings_dialog_browse_forfile(GtkWidget * widget, BrowseInfo * browse_info) +settings_dialog_browse_forfile(GtkWidget *widget, BrowseInfo *browse_info) { GtkWidget *dialog; gint res; @@ -404,7 +403,7 @@ while (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { gtk_tree_model_get(GTK_TREE_MODEL(gdi.store), &gdi.iter, 0, &(gps->io.type), -1); g_debug("GPS: %d", gps->io.type); } else { - popup_error(dialog, "Please select GPS type"); + popup_error(dialog, _("Please select GPS type")); continue; } @@ -438,6 +437,27 @@ gtk_widget_destroy(dialog); return rcvr_changed; } +/* XXX: Find a better place for this */ +static void +reinit_database(gchar *newdb) +{ +if (_mapper_db) + g_free(_mapper_db); +_mapper_db=newdb; + +if (_db || newdb==NULL) { + poi_deinit(_db); + osm_deinit(); + db_close(&_db); + _db=NULL; + if (newdb==NULL) + return; +} +db_connect(&_db, _mapper_db); +poi_init(&_db); +osm_init(&_db); +} + gboolean settings_dialog_osm(void) { @@ -487,23 +507,17 @@ gtk_window_set_default_size(GTK_WINDOW(dialog), 500, 300); gtk_widget_show_all(dialog); if (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) { - if (_db) { - poi_deinit(_db); - osm_deinit(); - db_close(&_db); - _db=NULL; - } - g_free(_mapper_db); + _map_location_sens=hildon_controlbar_get_value(HILDON_CONTROLBAR(num_sens)); if (strlen(gtk_entry_get_text(GTK_ENTRY(txt_mapper_db)))>0) { - _mapper_db=g_strdup(gtk_entry_get_text(GTK_ENTRY(txt_mapper_db))); - db_connect(&_db, _mapper_db); - poi_init(&_db); - osm_init(&_db); + gchar *tmp; + tmp=g_strdup(gtk_entry_get_text(GTK_ENTRY(txt_mapper_db))); + if (tmp && _mapper_db && strcmp(tmp, _mapper_db)!=0) { + reinit_database(tmp); + } } else { _mapper_db=NULL; + reinit_database(NULL); } - - _map_location_sens=hildon_controlbar_get_value(HILDON_CONTROLBAR(num_sens)); config_save(); } gtk_widget_destroy(dialog); -- 2.39.5