]> err.no Git - mapper/blob - src/import-gui.c
Include settings.h so the banner macro hildon version works.
[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
40 static GtkWidget *progress;
41 static GtkWidget *import_dialog;
42
43 static gboolean
44 osm_import_progress_cb(gpointer data)
45 {
46 gtk_progress_bar_pulse(progress);
47 return TRUE;
48 }
49
50 static gboolean
51 osm_import_done_cb(gpointer data)
52 {
53 gint ret;
54
55 ret=osm_import_join_bg();
56
57 if (ret!=0)
58         popup_error(import_dialog, _("OSM Data import failed!"));
59
60 progress_dialog_remove(import_dialog);
61 return FALSE;
62 }
63
64 gboolean
65 osm_import_dialog(GtkWidget *window)
66 {
67 GtkWidget *dialog;
68 GtkWidget *vbox;
69 GtkWidget *picker_planet;
70 GtkWidget *entry_db;
71
72 dialog = gtk_dialog_new_with_buttons(_("OSM Data import"),
73                                 GTK_WINDOW(window),
74                                 GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, 
75                                 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL);
76
77 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), vbox = gtk_vbox_new (FALSE, 3), TRUE, TRUE, 0);
78
79 picker_planet=gtk_file_chooser_button_new(_("OSM Planet file"), GTK_FILE_CHOOSER_ACTION_OPEN);
80 entry_db=gtk_entry_new();
81
82 gtk_box_pack_start(GTK_BOX(vbox), gtk_label_new("OSM Planet"), TRUE, TRUE, 0);
83 gtk_box_pack_start(GTK_BOX(vbox), picker_planet, TRUE, TRUE, 0);
84
85 gtk_box_pack_start(GTK_BOX(vbox), gtk_label_new("Destination database"), TRUE, TRUE, 0);
86 gtk_box_pack_start(GTK_BOX(vbox), entry_db, TRUE, TRUE, 0);
87
88 gtk_widget_show_all(dialog);
89
90 if (GTK_RESPONSE_ACCEPT == gtk_dialog_run(GTK_DIALOG(dialog))) {
91         gchar *planet, *db;
92
93         planet=gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(picker_planet));
94         db=gtk_entry_get_text(GTK_ENTRY(entry_db));
95
96         if (planet && db) {
97                 progress=gtk_progress_bar_new();
98                 import_dialog=progress_dialog(window, "Importing OSM data...", progress);
99
100                 if (osm_import_bg(planet, db, osm_import_progress_cb, osm_import_done_cb)==TRUE)
101                         gtk_widget_destroy(dialog);
102                 else
103                         popup_error(dialog, _("Failed to start import thread."));
104         } else {
105                 popup_error(dialog, _("Missing file selection!"));
106         }
107 } else {
108         gtk_widget_destroy(dialog);
109 }
110 return TRUE;
111 }