gtk-ui: improve confirmation dialogs

This commit is contained in:
Jussi Kukkonen 2010-02-08 21:01:00 +02:00
parent 2dcbee9fd5
commit 6aef84e0dc
3 changed files with 50 additions and 57 deletions

View file

@ -249,41 +249,35 @@ use_clicked_cb (GtkButton *btn, SyncConfigWidget *self)
}
if (self->current_service_name && !self->current) {
GtkWidget *w, *top_level;
int ret;
char *msg, *yes, *no;
gboolean ret;
char *msg, *yes, *no, *new_name, *old_name;
/*TRANSLATORS: warning dialog text for changing current service */
msg = g_strdup_printf
(_("Do you want to replace %s with %s? This\n"
"will not remove any synced information on either\n"
"end but you will no longer be able to sync with\n"
"%s."),
(_("Do you want to replace %s with %s? This "
"will not remove any synced information on either "
"end but you will no longer be able to sync with %s."),
self->current_service_name,
gtk_entry_get_text (GTK_ENTRY (self->entry)),
self->current_service_name);
new_name = g_strndup (gtk_entry_get_text (GTK_ENTRY (self->entry)), 40);
old_name = g_strndup (self->current_service_name, 40);
/* TRANSLATORS: decline/accept buttons in warning dialog.
Placeholder is service name */
yes = g_strdup_printf (_("Yes, use %s"),
gtk_entry_get_text (GTK_ENTRY (self->entry)));
no = g_strdup_printf (_("No, use %s"), self->current_service_name);
top_level = gtk_widget_get_toplevel (GTK_WIDGET (self));
w = gtk_message_dialog_new (GTK_WINDOW (top_level),
GTK_DIALOG_MODAL,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
msg);
gtk_dialog_add_buttons (GTK_DIALOG (w),
no, GTK_RESPONSE_NO,
yes, GTK_RESPONSE_YES,
NULL);
ret = gtk_dialog_run (GTK_DIALOG (w));
gtk_widget_destroy (w);
yes = g_strdup_printf (_("Yes, use %s"), new_name);
no = g_strdup_printf (_("No, use %s"), old_name);
ret = show_confirmation (GTK_WIDGET (self), msg, yes, no);
g_free (msg);
g_free (yes);
g_free (no);
g_free (new_name);
g_free (old_name);
if (ret != GTK_RESPONSE_YES) {
if (!ret) {
return;
}
}
@ -375,9 +369,7 @@ use_clicked_cb (GtkButton *btn, SyncConfigWidget *self)
static void
reset_delete_clicked_cb (GtkButton *btn, SyncConfigWidget *self)
{
GtkWidget *w, *top_level;
int ret;
char *msg, *yes;
char *msg, *yes, *no;
save_config_data *data;
if (!self->config) {
@ -388,43 +380,31 @@ reset_delete_clicked_cb (GtkButton *btn, SyncConfigWidget *self)
/*TRANSLATORS: warning dialog text for resetting pre-defined
services */
msg = g_strdup_printf
(_("Do you want to reset the settings for %s?\n"
(_("Do you want to reset the settings for %s? "
"This will not remove any synced information on either end."),
self->pretty_name);
/*TRANSLATORS: accept button in warning dialog */
/*TRANSLATORS: buttons in reset-service warning dialog */
yes = _("Yes, reset");
no = _("No, keep settings");
} else {
/*TRANSLATORS: warning dialog text for deleting user-defined
services */
msg = g_strdup_printf
(_("Do you want to delete the settings for %s?\n"
"This will not remove any synced information on either\n"
(_("Do you want to delete the settings for %s? "
"This will not remove any synced information on either "
"end but it will remove this service configuration."),
self->pretty_name);
/*TRANSLATORS: accept button in warning dialog */
/*TRANSLATORS: buttons in delete-service warning dialog */
yes = _("Yes, delete");
no = _("No, keep settings");
}
top_level = gtk_widget_get_toplevel (GTK_WIDGET (self));
w = gtk_message_dialog_new (GTK_WINDOW (top_level),
GTK_DIALOG_MODAL,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
msg);
/*TRANSLATORS: decline button in warning dialog */
gtk_dialog_add_buttons (GTK_DIALOG (w),
_("No, keep settings"),
GTK_RESPONSE_NO,
yes,
GTK_RESPONSE_YES,
NULL);
ret = gtk_dialog_run (GTK_DIALOG (w));
gtk_widget_destroy (w);
g_free (msg);
if (ret != GTK_RESPONSE_YES) {
/*TRANSLATORS: decline button in "Reset/delete service" warning dialogs */
if (!show_confirmation (GTK_WIDGET (self), msg, yes, no)) {
g_free (msg);
return;
}
g_free (msg);
if (self->current) {
sync_config_widget_set_current (self, FALSE);

View file

@ -295,14 +295,14 @@ sync_cb (SyncevoSession *session,
set_app_state (data, SYNC_UI_STATE_SYNCING);
}
static gboolean
confirm (app_data *data, const char *message,
const char *yes, const char *no)
gboolean
show_confirmation (GtkWidget *widget, const char *message,
const char *yes, const char *no)
{
GtkWidget *w;
int ret;
w = gtk_message_dialog_new (GTK_WINDOW (data->sync_win),
w = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (widget)),
GTK_DIALOG_MODAL,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
@ -324,9 +324,13 @@ slow_sync (app_data *data)
operation_data *op_data;
char *message;
/* TRANSLATORS: slow sync confirmation dialog message. Placeholder
* is service/device name */
message = g_strdup_printf (_("Do you want to slow sync with %s?"),
data->current_service->pretty_name);
if (!confirm (data, message, _("Yes, do slow sync"), _("No, cancel sync"))) {
/* TRANSLATORS: slow sync confirmation dialog buttons */
if (!show_confirmation (data->sync_win, message,
_("Yes, do slow sync"), _("No, cancel sync"))) {
g_free (message);
return;
}
@ -357,10 +361,14 @@ refresh_from_server_clicked_cb (GtkButton *btn, app_data *data)
operation_data *op_data;
char *message;
/* TRANSLATORS: confirmation dialog for refresh-from-server. Placeholder
* is service/device name */
message = g_strdup_printf (_("Do you want to delete all local data and replace it with "
"data from %s? This is not usually advised."),
data->current_service->pretty_name);
if (!confirm (data, message, _("Yes, delete and replace"), _("No"))) {
/* TRANSLATORS: refresh-from-server confirmation dialog buttons */
if (!show_confirmation (data->sync_win, message,
_("Yes, delete and replace"), _("No"))) {
g_free (message);
return;
}
@ -384,10 +392,14 @@ refresh_from_client_clicked_cb (GtkButton *btn, app_data *data)
operation_data *op_data;
char *message;
/* TRANSLATORS: confirmation dialog for refresh-from-client. Placeholder
* is service/device name */
message = g_strdup_printf (_("Do you want to delete all data in %s and replace it with "
"your local data? This is not usually advised."),
data->current_service->pretty_name);
if (!confirm (data, message, _("Yes, delete and replace"), _("No"))) {
/* TRANSLATORS: refresh-from-client confirmation dialog buttons */
if (!show_confirmation (data->sync_win, message,
_("Yes, delete and replace"), _("No"))) {
g_free (message);
return;
}
@ -1133,7 +1145,7 @@ restore_clicked_cb (GtkButton *btn, app_data *data)
message = g_strdup_printf (_("Do you want to restore the backup from %s? "
"All changes you have made since then will be lost."),
time_str);
if (!confirm (data, message, _("Yes, restore"), _("No"))) {
if (!show_confirmation (data->sync_win, message, _("Yes, restore"), _("No"))) {
g_free (message);
return;
}

View file

@ -42,6 +42,7 @@ typedef enum SyncErrorResponse {
char* get_pretty_source_name (const char *source_name);
char* get_error_string_for_code (int error_code, SyncErrorResponse *response);
void show_error_dialog (GtkWidget *widget, const char* message);
gboolean show_confirmation (GtkWidget *widget, const char *message, const char *yes, const char *no);
app_data *sync_ui_create ();
GtkWindow *sync_ui_get_main_window (app_data *data);