Mercurial > pidgin
diff 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 |
line wrap: on
line diff
--- a/src/gtkrequest.c Sat Jul 10 16:45:36 2004 +0000 +++ b/src/gtkrequest.c Sat Jul 10 18:38:20 2004 +0000 @@ -68,6 +68,13 @@ } multifield; + struct + { + gboolean savedialog; + gchar *name; + + } file; + } u; } GaimGtkRequestData; @@ -1344,6 +1351,119 @@ } static void +file_yes_no_cb(GaimGtkRequestData *data, gint id) +{ + if (data->cbs[id] != NULL) + ((GaimRequestFileCb)data->cbs[id])(data->user_data, data->u.file.name); + g_free(data->u.file.name); + + if (id == 1) + gaim_request_close(GAIM_REQUEST_FILE, data); +} + +static void +#if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ +file_ok_check_if_exists_cb(GtkWidget *widget, gint response, GaimGtkRequestData *data) +{ + if (response != GTK_RESPONSE_ACCEPT) { + if (data->cbs[0] != NULL) + ((GaimRequestFileCb)data->cbs[0])(data->user_data, NULL); + gaim_request_close(GAIM_REQUEST_FILE, data); + return; + } + + data->u.file.name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(data->dialog)); +#else /* FILECHOOSER */ +file_ok_check_if_exists_cb(GtkWidget *button, GaimGtkRequestData *data) +{ + gchar *name; + + name = gtk_file_selection_get_filename(GTK_FILE_SELECTION(data->dialog))); + if (gaim_gtk_check_if_dir(name, GTK_FILE_SELECTION(data->dialog))) + /* Descend into directory? */ + /* Close dialog? */ + return; + data->u.file.name = name; +#endif /* FILECHOOSER */ + + if ((data->u.file.savedialog == TRUE) && + (g_file_test(data->u.file.name, G_FILE_TEST_EXISTS))) { + gaim_request_yes_no(data, NULL, _("That file already exists"), + _("Would you like to overwrite it?"), 1, data, + G_CALLBACK(file_yes_no_cb), + G_CALLBACK(file_yes_no_cb)); + } else + file_yes_no_cb(data, 1); +} + +#if !GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ +static void +file_cancel_cb(GtkWidget *widget, GaimGtkRequestData *data) +{ + if (data->cbs[0] != NULL) + ((GaimRequestFileCb)data->cbs[0])(data->user_data, NULL); + + gaim_request_close(GAIM_REQUEST_FILE, data); +} +#endif /* FILECHOOSER */ + +static void * +gaim_gtk_request_file(const char *title, const char *filename, + gboolean savedialog, + GCallback ok_cb, GCallback cancel_cb, + void *user_data) +{ + GaimGtkRequestData *data; + GtkWidget *filesel; + + data = g_new0(GaimGtkRequestData, 1); + data->type = GAIM_REQUEST_FILE; + data->user_data = user_data; + data->cb_count = 2; + data->cbs = g_new0(GCallback, 2); + data->cbs[0] = cancel_cb; + data->cbs[1] = ok_cb; + data->u.file.savedialog = savedialog; + +#if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ + filesel = gtk_file_chooser_dialog_new( + title ? title : (savedialog ? _("Save File...") + : _("Open File...")), + NULL, + savedialog ? GTK_FILE_CHOOSER_ACTION_SAVE + : GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + savedialog ? GTK_STOCK_SAVE + : GTK_STOCK_OPEN, + GTK_RESPONSE_ACCEPT, + NULL); + gtk_dialog_set_default_response(GTK_DIALOG(filesel), GTK_RESPONSE_ACCEPT); + if (filename != NULL) { + if (savedialog) + gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(filesel), filename); + else + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(filesel), filename); + } + g_signal_connect(G_OBJECT(GTK_FILE_CHOOSER(filesel)), "response", + G_CALLBACK(file_ok_check_if_exists_cb), data); +#else /* FILECHOOSER */ + filesel = gtk_file_selection_new(title ? title : ""); + gtk_file_selection_set_filename(GTK_FILE_SELECTION(filesel), filename); + g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(filesel)), "delete_event", + G_CALLBACK(file_cancel_cb), data); + g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(filesel)->cancel_button), + "clicked", G_CALLBACK(file_cancel_cb), data); + g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(filesel)->ok_button), + "clicked", G_CALLBACK(file_ok_check_if_exists_cb), data); +#endif /* FILECHOOSER */ + + data->dialog = filesel; + gtk_widget_show(filesel); + + return (void *)data; +} + +static void gaim_gtk_close_request(GaimRequestType type, void *ui_handle) { GaimGtkRequestData *data = (GaimGtkRequestData *)ui_handle; @@ -1359,70 +1479,6 @@ g_free(data); } -static void -file_ok_cb(GtkWidget *button, GaimGtkRequestData *data) -{ - const char *name; - - if (!GTK_WIDGET_HAS_FOCUS(button)) - gtk_widget_grab_focus(button); - - if (data->cbs[0] != NULL) { - name = gtk_file_selection_get_filename(GTK_FILE_SELECTION(data->dialog)); - if (gaim_gtk_check_if_dir(name, GTK_FILE_SELECTION(data->dialog))) - name = NULL; - - ((GaimRequestInputCb)data->cbs[0])(data->user_data, name); - } - - gaim_request_close(GAIM_REQUEST_INPUT, data); -} - -static void -file_cancel_cb(GtkWidget *button, GaimGtkRequestData *data) -{ - if (data->cbs[1] != NULL) - ((GaimRequestInputCb)data->cbs[1])(data->user_data, NULL); - - gaim_request_close(GAIM_REQUEST_INPUT, data); -} - -static void * -gaim_gtk_request_file(const char *title, const char *filename, - GCallback ok_cb, GCallback cancel_cb, - void *user_data) -{ - GaimGtkRequestData *data; - GtkWidget *filesel; - char *cur_dir, *init_str, tmp[512]; - - data = g_new0(GaimGtkRequestData, 1); - data->type = GAIM_REQUEST_INPUT; - data->user_data = user_data; - data->cb_count = 2; - data->cbs = g_new0(GCallback, 2); - data->cbs[0] = ok_cb; - data->cbs[1] = cancel_cb; - - filesel = gtk_file_selection_new(title ? title : ""); - cur_dir = g_get_current_dir(); - g_snprintf(tmp, sizeof(tmp), "%s" G_DIR_SEPARATOR_S, cur_dir); - init_str = g_build_filename(tmp, filename, NULL); - gtk_file_selection_set_filename(GTK_FILE_SELECTION(filesel), init_str); - g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(filesel)), - "delete_event", G_CALLBACK(file_cancel_cb), data); - g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(filesel)->cancel_button), - "clicked", G_CALLBACK(file_cancel_cb), data); - g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(filesel)->ok_button), - "clicked", G_CALLBACK(file_ok_cb), data); - gtk_widget_show(filesel); - g_free(cur_dir); - g_free(init_str); - - data->dialog = filesel; - return (void *)data; -} - static GaimRequestUiOps ops = { gaim_gtk_request_input,