]> err.no Git - mapper/commitdiff
Disconnect and reconnect to database only if the path has changed. Use a helper funct...
authorKaj-Michael Lang <milang@tal.org>
Mon, 7 Apr 2008 12:07:05 +0000 (15:07 +0300)
committerKaj-Michael Lang <milang@tal.org>
Mon, 7 Apr 2008 12:07:05 +0000 (15:07 +0300)
src/settings-gui.c

index 1f10018c3ef2b2ebdbe72033aea2e6972238bc7c..12fcd58b31bc858fe50b277c782f1890257df7c4 100644 (file)
@@ -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);