From 4c4d6dd727f4af01e8458cdea93373d2e4a68529 Mon Sep 17 00:00:00 2001 From: Jose Dapena Paz Date: Thu, 21 Jun 2007 16:55:08 +0000 Subject: [PATCH] Refactoring work to make new folder and rename folder share the same implementation (fixes NB#58817). * src/modest-platform.h: * New rename_folder_dialog method. * src/modest-ui-actions.c: * Now rename uses a dialog in modest platform, sharing the implementation with new folder dialog. Also removed old dialog implementation. * src/maemo/modest-platform.c: * New method rename_folder_dialog, and refactored new_folder_dialog, creating name_folder_dialog that implements the same logic and controls for both UI actions. pmo-trunk-r2367 --- src/maemo/modest-platform.c | 45 ++++++++++++++++++++++++++++--------- src/modest-platform.h | 17 ++++++++++++++ src/modest-ui-actions.c | 52 ++++++------------------------------------- 3 files changed, 59 insertions(+), 55 deletions(-) diff --git a/src/maemo/modest-platform.c b/src/maemo/modest-platform.c index 1ec6099..69a85e5 100644 --- a/src/maemo/modest-platform.c +++ b/src/maemo/modest-platform.c @@ -544,7 +544,7 @@ entry_insert_text (GtkEditable *editable, /* Show WID-INF036 */ if (chars_length == 20) { hildon_banner_show_information (gtk_widget_get_parent (GTK_WIDGET (data)), NULL, - _("mcen_ib_maxchar_reached")); + dgettext("hildon-common-strings", "ckdg_ib_maximum_characters_reached")); } else { if (chars_length == 0) { /* A blank space is not valid as first character */ @@ -720,19 +720,18 @@ launch_sort_headers_dialog (GtkWindow *parent_window, g_list_free(cols); } - - -gint -modest_platform_run_new_folder_dialog (GtkWindow *parent_window, - TnyFolderStore *parent_folder, - gchar *suggested_name, - gchar **folder_name) +static gint +modest_platform_run_folder_name_dialog (GtkWindow *parent_window, + const gchar *dialog_title, + const gchar *label_text, + const gchar *suggested_name, + gchar **folder_name) { GtkWidget *dialog, *entry, *label, *hbox; gint result; /* Ask the user for the folder name */ - dialog = gtk_dialog_new_with_buttons (_("mcen_ti_new_folder"), + dialog = gtk_dialog_new_with_buttons (dialog_title, parent_window, GTK_DIALOG_MODAL | GTK_DIALOG_NO_SEPARATOR | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, @@ -742,7 +741,7 @@ modest_platform_run_new_folder_dialog (GtkWindow *parent_window, NULL); /* Create label and entry */ - label = gtk_label_new (_("mcen_fi_new_folder_name")); + label = gtk_label_new (label_text); /* TODO: check that the suggested name does not exist */ /* We set 21 as maximum because we want to show WID-INF036 when the user inputs more that 20 */ @@ -784,6 +783,32 @@ modest_platform_run_new_folder_dialog (GtkWindow *parent_window, } gint +modest_platform_run_new_folder_dialog (GtkWindow *parent_window, + TnyFolderStore *parent_folder, + gchar *suggested_name, + gchar **folder_name) +{ + return modest_platform_run_folder_name_dialog (parent_window, + _("mcen_ti_new_folder"), + _("mcen_fi_new_folder_name"), + suggested_name, + folder_name); +} + +gint +modest_platform_run_rename_folder_dialog (GtkWindow *parent_window, + TnyFolderStore *parent_folder, + const gchar *suggested_name, + gchar **folder_name) +{ + return modest_platform_run_folder_name_dialog (parent_window, + _("New folder name"), + _("Enter new folder name:"), + suggested_name, + folder_name); +} + +gint modest_platform_run_confirmation_dialog (GtkWindow *parent_window, const gchar *message) { diff --git a/src/modest-platform.h b/src/modest-platform.h index cf17116..8d50739 100644 --- a/src/modest-platform.h +++ b/src/modest-platform.h @@ -151,6 +151,23 @@ gint modest_platform_run_new_folder_dialog (GtkWindow *parent_window gchar **folder_name); /** + * modest_platform_run_rename_folder_dialog: + * @parent_window: a #GtkWindow + * @parent: the parent of the folder + * @suggested_name: current name of the folder + * @folder_name: the new folder name selected by the user for the folder + * + * runs a "rename folder" confirmation dialog. If the user input a valid folder name it's + * returned in the #folder_name attribute. + * + * Returns: the #GtkResponseType returned by the dialog + **/ +gint modest_platform_run_rename_folder_dialog (GtkWindow *parent_window, + TnyFolderStore *parent, + const gchar *current_name, + gchar **folder_name); + +/** * modest_platform_run_confirmation_dialog: * @parent_window: the parent #GtkWindow of the dialog * @message: the message to show to the user diff --git a/src/modest-ui-actions.c b/src/modest-ui-actions.c index 111fd03..8c0dc41 100644 --- a/src/modest-ui-actions.c +++ b/src/modest-ui-actions.c @@ -122,8 +122,6 @@ static void reply_forward_cb (ModestMailOperation *mail_op, static void reply_forward (ReplyForwardAction action, ModestWindow *win); -static gchar* ask_for_folder_name (GtkWindow *parent_window, const gchar *title); - static void _on_send_receive_progress_changed (ModestMailOperation *mail_op, ModestMailOperationState *state, @@ -1779,46 +1777,6 @@ modest_ui_actions_on_remove_attachments (GtkAction *action, modest_msg_edit_window_remove_attachments (window, NULL); } -/* - * Shows a dialog with an entry that asks for some text. The returned - * value must be freed by the caller. The dialog window title will be - * set to @title. - */ -static gchar * -ask_for_folder_name (GtkWindow *parent_window, - const gchar *title) -{ - GtkWidget *dialog, *entry; - gchar *folder_name = NULL; - - /* Ask for folder name */ - dialog = gtk_dialog_new_with_buttons (_("New Folder Name"), - parent_window, - GTK_DIALOG_MODAL, - GTK_STOCK_CANCEL, - GTK_RESPONSE_REJECT, - GTK_STOCK_OK, - GTK_RESPONSE_ACCEPT, - NULL); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), - gtk_label_new(title), - FALSE, FALSE, 0); - - entry = gtk_entry_new_with_max_length (40); - gtk_box_pack_start (GTK_BOX(GTK_DIALOG(dialog)->vbox), - entry, - TRUE, FALSE, 0); - - gtk_widget_show_all (GTK_WIDGET(GTK_DIALOG(dialog)->vbox)); - - if (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) - folder_name = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry))); - - gtk_widget_destroy (dialog); - - return folder_name; -} - void modest_ui_actions_on_new_folder (GtkAction *action, ModestMainWindow *main_window) { @@ -1898,10 +1856,14 @@ modest_ui_actions_on_rename_folder (GtkAction *action, if (folder && TNY_IS_FOLDER (folder)) { gchar *folder_name; - folder_name = ask_for_folder_name (GTK_WINDOW (main_window), - _("Please enter a new name for the folder")); + gint response; + const gchar *current_name; + + current_name = tny_folder_get_name (TNY_FOLDER (folder)); + response = modest_platform_run_rename_folder_dialog (GTK_WINDOW (main_window), NULL, + current_name, &folder_name); - if (folder_name != NULL && strlen (folder_name) > 0) { + if (response == GTK_RESPONSE_OK && strlen (folder_name) > 0) { ModestMailOperation *mail_op; mail_op = modest_mail_operation_new (MODEST_MAIL_OPERATION_TYPE_INFO, G_OBJECT(main_window)); -- 1.7.9.5