]> err.no Git - mapper/blob - src/import-gui.c
Merge branch 'master' of ssh://git.tal.org/home/git/mapper
[mapper] / src / import-gui.c
1 /*
2  * This file is part of mapper
3  *
4  * Copyright (C) 2007 Kaj-Michael Lang
5  *
6  * Default map data provided by http://www.openstreetmap.org/
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include "config.h"
24
25 #include <unistd.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <strings.h>
29 #include <stddef.h>
30 #include <glib/gstdio.h>
31 #include <gtk/gtk.h>
32 #include <libintl.h>
33 #include <locale.h>
34
35 #include "hildon-mapper.h"
36 #include "utils.h"
37 #include "osm-db-import.h"
38 #include "dialogs.h"
39 #include "import-gui.h"
40
41 static GtkWidget *progress;
42 static GtkWidget *import_dialog;
43
44 static gboolean
45 osm_import_progress_cb(gpointer data)
46 {
47 gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progress));
48 return TRUE;
49 }
50
51 static gboolean
52 osm_import_done_cb(gpointer data)
53 {
54 gint ret;
55
56 ret=osm_import_join_bg();
57
58 if (ret!=0)
59         popup_error(import_dialog, _("OSM Data import failed!"));
60
61 progress_dialog_remove(import_dialog);
62 return FALSE;
63 }
64
65 gboolean
66 osm_import_dialog(GtkWidget *window)
67 {
68 GtkWidget *dialog;
69 GtkWidget *vbox;
70 GtkWidget *picker_planet;
71 GtkWidget *entry_db;
72
73 dialog = gtk_dialog_new_with_buttons(_("OSM Data import"),
74                                 GTK_WINDOW(window),
75                                 GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, 
76                                 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL);
77
78 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), vbox = gtk_vbox_new (FALSE, 3), TRUE, TRUE, 0);
79
80 picker_planet=gtk_file_chooser_button_new(_("OSM Planet file"), GTK_FILE_CHOOSER_ACTION_OPEN);
81 entry_db=gtk_entry_new();
82
83 gtk_box_pack_start(GTK_BOX(vbox), gtk_label_new("OSM Planet"), TRUE, TRUE, 0);
84 gtk_box_pack_start(GTK_BOX(vbox), picker_planet, TRUE, TRUE, 0);
85
86 gtk_box_pack_start(GTK_BOX(vbox), gtk_label_new("Destination database"), TRUE, TRUE, 0);
87 gtk_box_pack_start(GTK_BOX(vbox), entry_db, TRUE, TRUE, 0);
88
89 gtk_widget_show_all(dialog);
90
91 while (GTK_RESPONSE_ACCEPT==gtk_dialog_run(GTK_DIALOG(dialog))) {
92         gchar *planet, *db;
93
94         planet=gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(picker_planet));
95         db=gtk_entry_get_text(GTK_ENTRY(entry_db));
96
97         if (planet && db) {
98                 progress=gtk_progress_bar_new();
99                 import_dialog=progress_dialog(window, "Importing OSM data...", progress);
100                 gtk_widget_show_all(import_dialog);
101
102                 if (osm_import_bg(planet, db, osm_import_progress_cb, osm_import_done_cb)==TRUE) {
103                         break;
104                 } else
105                         popup_error(dialog, _("Failed to start import."));
106         } else {
107                 popup_error(dialog, _("Missing file selection!"));
108         }
109 }
110 gtk_widget_destroy(dialog);
111 return TRUE;
112 }