1239 |
|
|
1240 |
/* ------------------- project setup wizard ----------------- */ |
/* ------------------- project setup wizard ----------------- */ |
1241 |
|
|
1242 |
typedef struct { |
typedef struct wizard_page_s { |
|
GtkWidget *widget; |
|
|
gint index; |
|
1243 |
const gchar *title; |
const gchar *title; |
1244 |
|
GtkWidget* (*setup)(struct wizard_page_s *page); |
1245 |
GtkAssistantPageType type; |
GtkAssistantPageType type; |
1246 |
gboolean complete; |
gboolean complete; |
1247 |
|
GtkWidget *widget; |
1248 |
|
gint index; |
1249 |
} wizard_page_t; |
} wizard_page_t; |
1250 |
|
|
1251 |
static gint on_assistant_destroy(GtkWidget *widget, gpointer data) { |
typedef struct { |
1252 |
|
gboolean running; |
1253 |
|
|
1254 |
|
int page_num; |
1255 |
|
wizard_page_t *page; |
1256 |
|
} wizard_t; |
1257 |
|
|
1258 |
|
|
1259 |
|
static gint on_assistant_destroy(GtkWidget *widget, wizard_t *wizard) { |
1260 |
|
printf("destroy callback\n"); |
1261 |
|
wizard->running = FALSE; |
1262 |
return FALSE; |
return FALSE; |
1263 |
} |
} |
1264 |
|
|
1265 |
|
static void on_assistant_cancel(GtkWidget *widget, wizard_t *wizard) { |
1266 |
|
printf("cancel callback\n"); |
1267 |
|
wizard->running = FALSE; |
1268 |
|
} |
1269 |
|
|
1270 |
|
static void on_assistant_close(GtkWidget *widget, wizard_t *wizard) { |
1271 |
|
printf("close callback\n"); |
1272 |
|
wizard->running = FALSE; |
1273 |
|
} |
1274 |
|
|
1275 |
|
static GtkWidget *wizard_text(const char *text) { |
1276 |
|
GtkTextBuffer *buffer = gtk_text_buffer_new(NULL); |
1277 |
|
gtk_text_buffer_set_text(buffer, text, -1); |
1278 |
|
|
1279 |
|
#ifndef USE_HILDON_TEXT_VIEW |
1280 |
|
GtkWidget *view = gtk_text_view_new_with_buffer(buffer); |
1281 |
|
#else |
1282 |
|
GtkWidget *view = hildon_text_view_new(); |
1283 |
|
hildon_text_view_set_buffer(HILDON_TEXT_VIEW(view), buffer); |
1284 |
|
#endif |
1285 |
|
|
1286 |
|
gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD); |
1287 |
|
gtk_text_view_set_editable(GTK_TEXT_VIEW(view), FALSE); |
1288 |
|
gtk_text_view_set_left_margin(GTK_TEXT_VIEW(view), 2 ); |
1289 |
|
gtk_text_view_set_right_margin(GTK_TEXT_VIEW(view), 2 ); |
1290 |
|
gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(view), FALSE ); |
1291 |
|
|
1292 |
|
return view; |
1293 |
|
} |
1294 |
|
|
1295 |
|
static GtkWidget *wizard_create_intro_page(wizard_page_t *page) { |
1296 |
|
static const char *text = |
1297 |
|
"This wizard will guide you through the setup of a new project.\n\n" |
1298 |
|
"An osm2go project covers a certain area of the world as seen " |
1299 |
|
"by openstreetmap.org. The wizard will help you downloading " |
1300 |
|
"the data describing that area and will enable you to make changes " |
1301 |
|
"to it using osm2go."; |
1302 |
|
|
1303 |
|
return wizard_text(text); |
1304 |
|
} |
1305 |
|
|
1306 |
|
static GtkWidget *wizard_create_source_selection_page(wizard_page_t *page) { |
1307 |
|
GtkWidget *vbox = gtk_vbox_new(FALSE, 0); |
1308 |
|
|
1309 |
|
gtk_box_pack_start_defaults(GTK_BOX(vbox), |
1310 |
|
wizard_text("Please choose how to determine the area you " |
1311 |
|
"are planning to work on.")); |
1312 |
|
|
1313 |
|
/* add selection buttons */ |
1314 |
|
GtkWidget *choice1 = |
1315 |
|
gtk_radio_button_new_with_label(NULL, |
1316 |
|
_("Use current GPS position")); |
1317 |
|
gtk_box_pack_start(GTK_BOX(vbox), choice1, TRUE, TRUE, 2); |
1318 |
|
|
1319 |
|
GtkWidget *choice2 = |
1320 |
|
gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(choice1), |
1321 |
|
_("Get from Maemo Mapper")); |
1322 |
|
gtk_box_pack_start(GTK_BOX(vbox), choice2, TRUE, TRUE, 2); |
1323 |
|
|
1324 |
|
GtkWidget *choice3 = |
1325 |
|
gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(choice1), |
1326 |
|
_("Specify area manually")); |
1327 |
|
gtk_box_pack_start(GTK_BOX(vbox), choice3, TRUE, TRUE, 2); |
1328 |
|
|
1329 |
|
|
1330 |
|
|
1331 |
|
return vbox; |
1332 |
|
} |
1333 |
|
|
1334 |
void project_wizard(appdata_t *appdata) { |
void project_wizard(appdata_t *appdata) { |
1335 |
wizard_page_t page[5] = { |
wizard_page_t page[] = { |
1336 |
{ NULL, -1, "Introduction", GTK_ASSISTANT_PAGE_INTRO, TRUE}, |
{ "Introduction", wizard_create_intro_page, |
1337 |
{ NULL, -1, NULL, GTK_ASSISTANT_PAGE_CONTENT, FALSE}, |
GTK_ASSISTANT_PAGE_INTRO, TRUE}, |
1338 |
{ NULL, -1, "Click the Check Button", GTK_ASSISTANT_PAGE_CONTENT, FALSE}, |
{ "Area source selection", wizard_create_source_selection_page, |
1339 |
{ NULL, -1, "Click the Button", GTK_ASSISTANT_PAGE_PROGRESS, FALSE}, |
GTK_ASSISTANT_PAGE_CONTENT, FALSE}, |
1340 |
{ NULL, -1, "Confirmation", GTK_ASSISTANT_PAGE_CONFIRM, TRUE}, |
{ "Click the Check Button", NULL, |
1341 |
|
GTK_ASSISTANT_PAGE_CONTENT, FALSE}, |
1342 |
|
{ "Click the Button", NULL, |
1343 |
|
GTK_ASSISTANT_PAGE_PROGRESS, FALSE}, |
1344 |
|
{ "Confirmation", NULL, |
1345 |
|
GTK_ASSISTANT_PAGE_CONFIRM, TRUE}, |
1346 |
}; |
}; |
1347 |
|
|
1348 |
|
wizard_t wizard = { |
1349 |
|
TRUE, |
1350 |
|
|
1351 |
|
/* the pages themselves */ |
1352 |
|
sizeof(page) / sizeof(wizard_page_t), page |
1353 |
|
}; |
1354 |
|
|
1355 |
GtkWidget *assistant = gtk_assistant_new(); |
GtkWidget *assistant = gtk_assistant_new(); |
1356 |
gtk_widget_set_size_request (assistant, 450, 300); |
gtk_widget_set_size_request (assistant, 450, 300); |
1357 |
|
|
1358 |
/* Add five pages to the GtkAssistant dialog. */ |
/* Add five pages to the GtkAssistant dialog. */ |
1359 |
int i; |
int i; |
1360 |
for (i = 0; i < 5; i++) { |
for (i = 0; i < wizard.page_num; i++) { |
1361 |
char *str = g_strdup_printf("Page %d", i); |
if(wizard.page[i].setup) |
1362 |
page[i].widget = gtk_label_new(str); |
wizard.page[i].widget = |
1363 |
g_free(str); |
wizard.page[i].setup(&wizard.page[i]); |
1364 |
|
else { |
1365 |
|
char *str = g_strdup_printf("Page %d", i); |
1366 |
|
wizard.page[i].widget = gtk_label_new(str); |
1367 |
|
g_free(str); |
1368 |
|
} |
1369 |
|
|
1370 |
page[i].index = gtk_assistant_append_page(GTK_ASSISTANT (assistant), |
page[i].index = gtk_assistant_append_page(GTK_ASSISTANT (assistant), |
1371 |
page[i].widget); |
wizard.page[i].widget); |
1372 |
|
|
1373 |
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), |
gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), |
1374 |
page[i].widget, page[i].title); |
wizard.page[i].widget, wizard.page[i].title); |
1375 |
gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), |
gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), |
1376 |
page[i].widget, page[i].type); |
wizard.page[i].widget, wizard.page[i].type); |
1377 |
|
|
1378 |
/* Set the introduction and conclusion pages as complete so they can be |
/* Set the introduction and conclusion pages as complete so they can be |
1379 |
* incremented or closed. */ |
* incremented or closed. */ |
1380 |
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), |
gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), |
1381 |
page[i].widget, page[i].complete); |
wizard.page[i].widget, wizard.page[i].complete); |
1382 |
} |
} |
1383 |
|
|
1384 |
/* make it a modal subdialog of the main window */ |
/* make it a modal subdialog of the main window */ |
1389 |
gtk_widget_show_all(assistant); |
gtk_widget_show_all(assistant); |
1390 |
|
|
1391 |
g_signal_connect(G_OBJECT(assistant), "destroy", |
g_signal_connect(G_OBJECT(assistant), "destroy", |
1392 |
G_CALLBACK(on_assistant_destroy), NULL); |
G_CALLBACK(on_assistant_destroy), &wizard); |
1393 |
|
|
1394 |
|
g_signal_connect(G_OBJECT(assistant), "cancel", |
1395 |
|
G_CALLBACK(on_assistant_cancel), &wizard); |
1396 |
|
|
1397 |
|
g_signal_connect(G_OBJECT(assistant), "close", |
1398 |
|
G_CALLBACK(on_assistant_close), &wizard); |
1399 |
|
|
1400 |
do { |
do { |
1401 |
if(gtk_events_pending()) |
if(gtk_events_pending()) |
1403 |
else |
else |
1404 |
usleep(100000); |
usleep(100000); |
1405 |
|
|
1406 |
putchar('.'); fflush(stdout); |
} while(wizard.running); |
|
} while(1); |
|
1407 |
|
|
1408 |
gtk_widget_destroy(assistant); |
gtk_widget_destroy(assistant); |
1409 |
} |
} |