Mercurial > pidgin
comparison src/gtkrequest.c @ 9502:578986136bac
[gaim-migrate @ 10329]
Make gaim_request_file support saving files as well as opening files.
Changed silc appropriately, and made the Save dialog in the debug
window use this.
I changed request.c so that, when closing a request window, it also
tries to change any requests or notifies that were created using the
ui_handle as the handle.
It's similar to using "gc" as the first parameter of a gaim_request_bleh
or gaim_notify_bleh function.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 10 Jul 2004 18:38:20 +0000 |
parents | 230cf4032e3d |
children | d822b19b751c |
comparison
equal
deleted
inserted
replaced
9501:d95e134da0ac | 9502:578986136bac |
---|---|
65 struct | 65 struct |
66 { | 66 { |
67 GaimRequestFields *fields; | 67 GaimRequestFields *fields; |
68 | 68 |
69 } multifield; | 69 } multifield; |
70 | |
71 struct | |
72 { | |
73 gboolean savedialog; | |
74 gchar *name; | |
75 | |
76 } file; | |
70 | 77 |
71 } u; | 78 } u; |
72 | 79 |
73 } GaimGtkRequestData; | 80 } GaimGtkRequestData; |
74 | 81 |
1342 | 1349 |
1343 return data; | 1350 return data; |
1344 } | 1351 } |
1345 | 1352 |
1346 static void | 1353 static void |
1347 gaim_gtk_close_request(GaimRequestType type, void *ui_handle) | 1354 file_yes_no_cb(GaimGtkRequestData *data, gint id) |
1348 { | 1355 { |
1349 GaimGtkRequestData *data = (GaimGtkRequestData *)ui_handle; | 1356 if (data->cbs[id] != NULL) |
1350 | 1357 ((GaimRequestFileCb)data->cbs[id])(data->user_data, data->u.file.name); |
1351 if (data->cbs != NULL) | 1358 g_free(data->u.file.name); |
1352 g_free(data->cbs); | 1359 |
1353 | 1360 if (id == 1) |
1354 gtk_widget_destroy(data->dialog); | 1361 gaim_request_close(GAIM_REQUEST_FILE, data); |
1355 | 1362 } |
1356 if (type == GAIM_REQUEST_FIELDS) | 1363 |
1357 gaim_request_fields_destroy(data->u.multifield.fields); | 1364 static void |
1358 | 1365 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
1359 g_free(data); | 1366 file_ok_check_if_exists_cb(GtkWidget *widget, gint response, GaimGtkRequestData *data) |
1360 } | 1367 { |
1361 | 1368 if (response != GTK_RESPONSE_ACCEPT) { |
1362 static void | 1369 if (data->cbs[0] != NULL) |
1363 file_ok_cb(GtkWidget *button, GaimGtkRequestData *data) | 1370 ((GaimRequestFileCb)data->cbs[0])(data->user_data, NULL); |
1364 { | 1371 gaim_request_close(GAIM_REQUEST_FILE, data); |
1365 const char *name; | 1372 return; |
1366 | 1373 } |
1367 if (!GTK_WIDGET_HAS_FOCUS(button)) | 1374 |
1368 gtk_widget_grab_focus(button); | 1375 data->u.file.name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(data->dialog)); |
1369 | 1376 #else /* FILECHOOSER */ |
1370 if (data->cbs[0] != NULL) { | 1377 file_ok_check_if_exists_cb(GtkWidget *button, GaimGtkRequestData *data) |
1371 name = gtk_file_selection_get_filename(GTK_FILE_SELECTION(data->dialog)); | 1378 { |
1372 if (gaim_gtk_check_if_dir(name, GTK_FILE_SELECTION(data->dialog))) | 1379 gchar *name; |
1373 name = NULL; | 1380 |
1374 | 1381 name = gtk_file_selection_get_filename(GTK_FILE_SELECTION(data->dialog))); |
1375 ((GaimRequestInputCb)data->cbs[0])(data->user_data, name); | 1382 if (gaim_gtk_check_if_dir(name, GTK_FILE_SELECTION(data->dialog))) |
1376 } | 1383 /* Descend into directory? */ |
1377 | 1384 /* Close dialog? */ |
1378 gaim_request_close(GAIM_REQUEST_INPUT, data); | 1385 return; |
1379 } | 1386 data->u.file.name = name; |
1380 | 1387 #endif /* FILECHOOSER */ |
1381 static void | 1388 |
1382 file_cancel_cb(GtkWidget *button, GaimGtkRequestData *data) | 1389 if ((data->u.file.savedialog == TRUE) && |
1383 { | 1390 (g_file_test(data->u.file.name, G_FILE_TEST_EXISTS))) { |
1384 if (data->cbs[1] != NULL) | 1391 gaim_request_yes_no(data, NULL, _("That file already exists"), |
1385 ((GaimRequestInputCb)data->cbs[1])(data->user_data, NULL); | 1392 _("Would you like to overwrite it?"), 1, data, |
1386 | 1393 G_CALLBACK(file_yes_no_cb), |
1387 gaim_request_close(GAIM_REQUEST_INPUT, data); | 1394 G_CALLBACK(file_yes_no_cb)); |
1388 } | 1395 } else |
1396 file_yes_no_cb(data, 1); | |
1397 } | |
1398 | |
1399 #if !GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ | |
1400 static void | |
1401 file_cancel_cb(GtkWidget *widget, GaimGtkRequestData *data) | |
1402 { | |
1403 if (data->cbs[0] != NULL) | |
1404 ((GaimRequestFileCb)data->cbs[0])(data->user_data, NULL); | |
1405 | |
1406 gaim_request_close(GAIM_REQUEST_FILE, data); | |
1407 } | |
1408 #endif /* FILECHOOSER */ | |
1389 | 1409 |
1390 static void * | 1410 static void * |
1391 gaim_gtk_request_file(const char *title, const char *filename, | 1411 gaim_gtk_request_file(const char *title, const char *filename, |
1392 GCallback ok_cb, GCallback cancel_cb, | 1412 gboolean savedialog, |
1393 void *user_data) | 1413 GCallback ok_cb, GCallback cancel_cb, |
1414 void *user_data) | |
1394 { | 1415 { |
1395 GaimGtkRequestData *data; | 1416 GaimGtkRequestData *data; |
1396 GtkWidget *filesel; | 1417 GtkWidget *filesel; |
1397 char *cur_dir, *init_str, tmp[512]; | |
1398 | 1418 |
1399 data = g_new0(GaimGtkRequestData, 1); | 1419 data = g_new0(GaimGtkRequestData, 1); |
1400 data->type = GAIM_REQUEST_INPUT; | 1420 data->type = GAIM_REQUEST_FILE; |
1401 data->user_data = user_data; | 1421 data->user_data = user_data; |
1402 data->cb_count = 2; | 1422 data->cb_count = 2; |
1403 data->cbs = g_new0(GCallback, 2); | 1423 data->cbs = g_new0(GCallback, 2); |
1404 data->cbs[0] = ok_cb; | 1424 data->cbs[0] = cancel_cb; |
1405 data->cbs[1] = cancel_cb; | 1425 data->cbs[1] = ok_cb; |
1406 | 1426 data->u.file.savedialog = savedialog; |
1427 | |
1428 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ | |
1429 filesel = gtk_file_chooser_dialog_new( | |
1430 title ? title : (savedialog ? _("Save File...") | |
1431 : _("Open File...")), | |
1432 NULL, | |
1433 savedialog ? GTK_FILE_CHOOSER_ACTION_SAVE | |
1434 : GTK_FILE_CHOOSER_ACTION_OPEN, | |
1435 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
1436 savedialog ? GTK_STOCK_SAVE | |
1437 : GTK_STOCK_OPEN, | |
1438 GTK_RESPONSE_ACCEPT, | |
1439 NULL); | |
1440 gtk_dialog_set_default_response(GTK_DIALOG(filesel), GTK_RESPONSE_ACCEPT); | |
1441 if (filename != NULL) { | |
1442 if (savedialog) | |
1443 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(filesel), filename); | |
1444 else | |
1445 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(filesel), filename); | |
1446 } | |
1447 g_signal_connect(G_OBJECT(GTK_FILE_CHOOSER(filesel)), "response", | |
1448 G_CALLBACK(file_ok_check_if_exists_cb), data); | |
1449 #else /* FILECHOOSER */ | |
1407 filesel = gtk_file_selection_new(title ? title : ""); | 1450 filesel = gtk_file_selection_new(title ? title : ""); |
1408 cur_dir = g_get_current_dir(); | 1451 gtk_file_selection_set_filename(GTK_FILE_SELECTION(filesel), filename); |
1409 g_snprintf(tmp, sizeof(tmp), "%s" G_DIR_SEPARATOR_S, cur_dir); | 1452 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(filesel)), "delete_event", |
1410 init_str = g_build_filename(tmp, filename, NULL); | 1453 G_CALLBACK(file_cancel_cb), data); |
1411 gtk_file_selection_set_filename(GTK_FILE_SELECTION(filesel), init_str); | |
1412 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(filesel)), | |
1413 "delete_event", G_CALLBACK(file_cancel_cb), data); | |
1414 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(filesel)->cancel_button), | 1454 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(filesel)->cancel_button), |
1415 "clicked", G_CALLBACK(file_cancel_cb), data); | 1455 "clicked", G_CALLBACK(file_cancel_cb), data); |
1416 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(filesel)->ok_button), | 1456 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(filesel)->ok_button), |
1417 "clicked", G_CALLBACK(file_ok_cb), data); | 1457 "clicked", G_CALLBACK(file_ok_check_if_exists_cb), data); |
1458 #endif /* FILECHOOSER */ | |
1459 | |
1460 data->dialog = filesel; | |
1418 gtk_widget_show(filesel); | 1461 gtk_widget_show(filesel); |
1419 g_free(cur_dir); | 1462 |
1420 g_free(init_str); | |
1421 | |
1422 data->dialog = filesel; | |
1423 return (void *)data; | 1463 return (void *)data; |
1464 } | |
1465 | |
1466 static void | |
1467 gaim_gtk_close_request(GaimRequestType type, void *ui_handle) | |
1468 { | |
1469 GaimGtkRequestData *data = (GaimGtkRequestData *)ui_handle; | |
1470 | |
1471 if (data->cbs != NULL) | |
1472 g_free(data->cbs); | |
1473 | |
1474 gtk_widget_destroy(data->dialog); | |
1475 | |
1476 if (type == GAIM_REQUEST_FIELDS) | |
1477 gaim_request_fields_destroy(data->u.multifield.fields); | |
1478 | |
1479 g_free(data); | |
1424 } | 1480 } |
1425 | 1481 |
1426 static GaimRequestUiOps ops = | 1482 static GaimRequestUiOps ops = |
1427 { | 1483 { |
1428 gaim_gtk_request_input, | 1484 gaim_gtk_request_input, |