From: Jose Dapena Paz Date: Thu, 2 Oct 2008 15:57:40 +0000 (+0000) Subject: * Added new ModestRetrievePicker as a replacement of X-Git-Tag: git_migration_finished~1171 X-Git-Url: http://git.maemo.org/git/?p=modest;a=commitdiff_plain;h=ae5eada0abaf6b2dd5eac4db96f618cdb2f41f29;ds=sidebyside * Added new ModestRetrievePicker as a replacement of ModestRetrieveComboBox in hildon2 toolkit. Modified also dialogs to use the new widget. pmo-trunk-r5883 --- diff --git a/src/hildon2/Makefile.am b/src/hildon2/Makefile.am index 0687a81..f07c819 100644 --- a/src/hildon2/Makefile.am +++ b/src/hildon2/Makefile.am @@ -81,6 +81,7 @@ libmodest_ui_la_SOURCES= \ modest-osso-state-saving.c \ modest-osso-state-saving.h \ modest-presets.h modest-presets.c \ + modest-retrieve-picker.h modest-retrieve-picker.c \ modest-secureauth-picker.h modest-secureauth-picker.c \ modest-selector-picker.h modest-selector-picker.c diff --git a/src/hildon2/modest-default-account-settings-dialog.c b/src/hildon2/modest-default-account-settings-dialog.c index 9d8e433..b3c24df 100644 --- a/src/hildon2/modest-default-account-settings-dialog.c +++ b/src/hildon2/modest-default-account-settings-dialog.c @@ -41,9 +41,9 @@ #include "modest-hildon-includes.h" #include "modest-default-account-settings-dialog.h" #include "modest-account-mgr.h" -#include "widgets/modest-secureauth-combo-box.h" +#include "modest-secureauth-picker.h" #include "widgets/modest-validating-entry.h" -#include "widgets/modest-retrieve-combo-box.h" +#include "modest-retrieve-picker.h" #include "widgets/modest-limit-retrieve-combo-box.h" #include "modest-text-utils.h" #include "modest-account-mgr.h" @@ -104,7 +104,7 @@ struct _ModestDefaultAccountSettingsDialogPrivate GtkWidget *page_account_details; GtkWidget *entry_account_title; - GtkWidget *combo_retrieve; + GtkWidget *retrieve_picker; GtkWidget *combo_limit_retrieve; GtkWidget *caption_leave_messages; GtkWidget *checkbox_leave_messages; @@ -122,18 +122,9 @@ struct _ModestDefaultAccountSettingsDialogPrivate GtkWidget *page_incoming; GtkWidget *caption_incoming; GtkWidget *entry_incomingserver; -/* GtkWidget *combo_incoming_security; */ -/* GtkWidget *checkbox_incoming_auth; */ GtkWidget *page_outgoing; GtkWidget *entry_outgoingserver; -/* GtkWidget *caption_outgoing_username; */ -/* GtkWidget *entry_outgoing_username; */ -/* GtkWidget *caption_outgoing_password; */ -/* GtkWidget *entry_outgoing_password; */ -/* GtkWidget *combo_outgoing_security; */ -/* GtkWidget *combo_outgoing_auth; */ -/* GtkWidget *entry_outgoing_port; */ GtkWidget *checkbox_outgoing_smtp_specific; GtkWidget *button_outgoing_smtp_servers; @@ -209,6 +200,12 @@ on_modified_combobox_changed (GtkComboBox *widget, gpointer user_data) } static void +on_modified_picker_changed (HildonPickerButton *widget, gpointer user_data) +{ + set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE); +} + +static void on_modified_entry_changed (GtkEditable *editable, gpointer user_data) { set_modified (MODEST_DEFAULT_ACCOUNT_SETTINGS_DIALOG (user_data), TRUE); @@ -251,7 +248,10 @@ connect_for_modified (ModestDefaultAccountSettingsDialog *self, GtkWidget *widge G_CALLBACK (on_modified_entry_changed), self); } else if (GTK_IS_COMBO_BOX (widget)) { g_signal_connect (G_OBJECT (widget), "changed", - G_CALLBACK (on_modified_combobox_changed), self); + G_CALLBACK (on_modified_combobox_changed), self); + } else if (HILDON_IS_PICKER_BUTTON (widget)) { + g_signal_connect (G_OBJECT (widget), "value-changed", + G_CALLBACK (on_modified_picker_changed), self); } else if (GTK_IS_TOGGLE_BUTTON (widget)) { g_signal_connect (G_OBJECT (widget), "toggled", G_CALLBACK (on_modified_checkbox_toggled), self); @@ -406,13 +406,11 @@ create_page_account_details (ModestDefaultAccountSettingsDialog *self) on_entry_max, self); /* The retrieve combobox: */ - priv->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ()); - caption = create_caption_new_with_asterisk (self, sizegroup, _("mcen_fi_advsetup_retrievetype"), - priv->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY); - gtk_widget_show (priv->combo_retrieve); - connect_for_modified (self, priv->combo_retrieve); - gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, MODEST_MARGIN_HALF); - gtk_widget_show (caption); + priv->retrieve_picker = GTK_WIDGET (modest_retrieve_picker_new ()); + hildon_button_set_title (HILDON_BUTTON (priv->retrieve_picker), _("mcen_fi_advsetup_retrievetype")); + gtk_widget_show (priv->retrieve_picker); + connect_for_modified (self, priv->retrieve_picker); + gtk_box_pack_start (GTK_BOX (box), priv->retrieve_picker, FALSE, FALSE, MODEST_MARGIN_HALF); /* The limit-retrieve combobox: */ priv->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ()); @@ -1167,8 +1165,6 @@ modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialo null_means_empty (modest_account_settings_get_fullname (settings))); gtk_entry_set_text( GTK_ENTRY (priv->entry_user_email), null_means_empty (modest_account_settings_get_email_address (settings))); - modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (priv->combo_retrieve), - modest_account_settings_get_retrieve_type (settings)); modest_limit_retrieve_combo_box_set_active_limit_retrieve ( MODEST_LIMIT_RETRIEVE_COMBO_BOX (priv->combo_limit_retrieve), modest_account_settings_get_retrieve_limit (settings)); @@ -1183,7 +1179,9 @@ modest_default_account_settings_dialog_load_settings (ModestAccountSettingsDialo gchar *proto_name, *title; ModestProtocolType incoming_protocol; - modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (priv->combo_retrieve), modest_server_account_settings_get_protocol (incoming_account)); + modest_retrieve_picker_fill (MODEST_RETRIEVE_PICKER (priv->retrieve_picker), modest_server_account_settings_get_protocol (incoming_account)); + modest_retrieve_picker_set_active_retrieve_conf (MODEST_RETRIEVE_PICKER (priv->retrieve_picker), + modest_account_settings_get_retrieve_type (settings)); if (!modest_protocol_registry_protocol_type_has_leave_on_server (protocol_registry, modest_server_account_settings_get_protocol (incoming_account))) { @@ -1317,8 +1315,8 @@ save_configuration (ModestDefaultAccountSettingsDialog *dialog) modest_account_settings_set_signature (priv->settings, signature); } - retrieve_type = modest_retrieve_combo_box_get_active_retrieve_conf ( - MODEST_RETRIEVE_COMBO_BOX (priv->combo_retrieve)); + retrieve_type = modest_retrieve_picker_get_active_retrieve_conf ( + MODEST_RETRIEVE_PICKER (priv->retrieve_picker)); modest_account_settings_set_retrieve_type (priv->settings, retrieve_type); retrieve_limit = modest_limit_retrieve_combo_box_get_active_limit_retrieve ( diff --git a/src/hildon2/modest-maemo-security-options-view.c b/src/hildon2/modest-maemo-security-options-view.c index 578fd01..72c8f2f 100644 --- a/src/hildon2/modest-maemo-security-options-view.c +++ b/src/hildon2/modest-maemo-security-options-view.c @@ -285,7 +285,7 @@ create_outgoing_security (ModestSecurityOptionsView* self, g_signal_connect (G_OBJECT (ppriv->security_view), "value-changed", G_CALLBACK (on_security_changed), self); if (ppriv->full) { - g_signal_connect (G_OBJECT (ppriv->auth_view), "changed", + g_signal_connect (G_OBJECT (ppriv->auth_view), "value-changed", G_CALLBACK (on_auth_changed), self); g_signal_connect (G_OBJECT (ppriv->user_entry), "changed", G_CALLBACK (on_entry_changed), self); diff --git a/src/hildon2/modest-retrieve-picker.c b/src/hildon2/modest-retrieve-picker.c new file mode 100644 index 0000000..82b34cb --- /dev/null +++ b/src/hildon2/modest-retrieve-picker.c @@ -0,0 +1,252 @@ +/* Copyright (c) 2007, 2008, Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Nokia Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "modest-retrieve-picker.h" +#include "modest-defs.h" /* For the conf names. */ +#include "modest-account-settings.h" +#include +#include +#include +#include + +#include +#include /* For memcpy() */ + +/* Include config.h so that _() works: */ +#ifdef HAVE_CONFIG_H +#include +#endif + +G_DEFINE_TYPE (ModestRetrievePicker, modest_retrieve_picker, HILDON_TYPE_PICKER_BUTTON); + +#define MODEST_RETRIEVE_PICKER_GET_PRIVATE(o) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_RETRIEVE_PICKER, ModestRetrievePickerPrivate)) + +typedef struct _ModestRetrievePickerPrivate ModestRetrievePickerPrivate; + +struct _ModestRetrievePickerPrivate +{ + GtkTreeModel *model; +}; + +enum MODEL_COLS { + MODEL_COL_NAME = 0, /* a string */ + MODEL_COL_RETRIEVE_TYPE = 1 /* a gint (a ModestAccountRetrieveType) */ +}; + +void modest_retrieve_picker_fill (ModestRetrievePicker *picker, ModestProtocolType protocol); + +static gchar * +touch_selector_print_func (HildonTouchSelector *selector) +{ + GtkTreeIter iter; + if (hildon_touch_selector_get_selected (HILDON_TOUCH_SELECTOR (selector), 0, &iter)) { + GtkTreeModel *model; + GValue value = {0,}; + + model = hildon_touch_selector_get_model (HILDON_TOUCH_SELECTOR (selector), 0); + gtk_tree_model_get_value (model, &iter, MODEL_COL_NAME, &value); + return g_value_dup_string (&value); + } + return NULL; +} + +static void +modest_retrieve_picker_finalize (GObject *object) +{ + ModestRetrievePickerPrivate *priv = MODEST_RETRIEVE_PICKER_GET_PRIVATE (object); + + g_object_unref (G_OBJECT (priv->model)); + + G_OBJECT_CLASS (modest_retrieve_picker_parent_class)->finalize (object); +} + +static void +modest_retrieve_picker_class_init (ModestRetrievePickerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (ModestRetrievePickerPrivate)); + + object_class->finalize = modest_retrieve_picker_finalize; +} + +static void +modest_retrieve_picker_init (ModestRetrievePicker *self) +{ + ModestRetrievePickerPrivate *priv = MODEST_RETRIEVE_PICKER_GET_PRIVATE (self); + + priv->model = NULL; +} + + + +ModestRetrievePicker* +modest_retrieve_picker_new (void) +{ + ModestRetrievePicker *self; + ModestRetrievePickerPrivate *priv; + GtkCellRenderer *renderer; + GtkWidget *selector; + + self = g_object_new (MODEST_TYPE_RETRIEVE_PICKER, + "arrangement", HILDON_BUTTON_ARRANGEMENT_VERTICAL, + "size", HILDON_SIZE_AUTO, + NULL); + priv = MODEST_RETRIEVE_PICKER_GET_PRIVATE (self); + + /* Create a tree model, + * with a string for the name, and an ID for the servertype. + * This must match our MODEL_COLS enum constants. + */ + priv->model = GTK_TREE_MODEL (gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT)); + renderer = gtk_cell_renderer_text_new (); + g_object_set (G_OBJECT (renderer), "ellipsize", PANGO_ELLIPSIZE_END, NULL); + + selector = hildon_touch_selector_new (); + hildon_touch_selector_append_column (HILDON_TOUCH_SELECTOR (selector), GTK_TREE_MODEL (priv->model), + renderer, "text", MODEL_COL_NAME, NULL); + + hildon_touch_selector_set_model (HILDON_TOUCH_SELECTOR (selector), 0, GTK_TREE_MODEL (priv->model)); + hildon_touch_selector_set_print_func (HILDON_TOUCH_SELECTOR (selector), touch_selector_print_func); + + hildon_picker_button_set_selector (HILDON_PICKER_BUTTON (self), HILDON_TOUCH_SELECTOR (selector)); + + return self; +} + +/* Fill the picker box with appropriate choices. + * #picker: The picker box. + * @protocol: IMAP or POP. + */ +void modest_retrieve_picker_fill (ModestRetrievePicker *picker, ModestProtocolType protocol) +{ + ModestRetrievePickerPrivate *priv = MODEST_RETRIEVE_PICKER_GET_PRIVATE (picker); + + /* Remove any existing rows: */ + GtkListStore *liststore = GTK_LIST_STORE (priv->model); + gtk_list_store_clear (liststore); + + GtkTreeIter iter; + gtk_list_store_append (liststore, &iter); + gtk_list_store_set (liststore, &iter, + MODEL_COL_RETRIEVE_TYPE, MODEST_ACCOUNT_RETRIEVE_HEADERS_ONLY, + MODEL_COL_NAME, _("mcen_fi_advsetup_retrievetype_headers"), -1); + + gtk_list_store_append (liststore, &iter); + gtk_list_store_set (liststore, &iter, + MODEL_COL_RETRIEVE_TYPE, MODEST_ACCOUNT_RETRIEVE_MESSAGES_AND_ATTACHMENTS, + MODEL_COL_NAME, _("mcen_fi_advsetup_retrievetype_messages_attachments"), -1); +} + +/** + * Returns the selected retrieve. + * or NULL if no retrieve was selected. The result must be freed with g_free(). + */ +ModestAccountRetrieveType +modest_retrieve_picker_get_active_retrieve_conf (ModestRetrievePicker *picker) +{ + GtkTreeIter active; + GtkWidget *selector; + gboolean found; + + selector = GTK_WIDGET (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (picker))); + found = hildon_touch_selector_get_selected (HILDON_TOUCH_SELECTOR (selector), 0, &active); + if (found) { + ModestRetrievePickerPrivate *priv = MODEST_RETRIEVE_PICKER_GET_PRIVATE (picker); + + ModestAccountRetrieveType retrieve_type = MODEST_ACCOUNT_RETRIEVE_HEADERS_ONLY; + gtk_tree_model_get (priv->model, &active, MODEL_COL_RETRIEVE_TYPE, &retrieve_type, -1); + return retrieve_type; + } + + return MODEST_ACCOUNT_RETRIEVE_HEADERS_ONLY; /* Failed. */ +} + +/* This allows us to pass more than one piece of data to the signal handler, + * and get a result: */ +typedef struct +{ + ModestRetrievePicker* self; + ModestAccountRetrieveType retrieve_type; + gboolean found; +} ForEachData; + +static gboolean +on_model_foreach_select_id(GtkTreeModel *model, + GtkTreePath *path, GtkTreeIter *iter, gpointer user_data) +{ + ForEachData *state = (ForEachData*)(user_data); + + gboolean result = FALSE; + + /* Select the item if it has the matching name: */ + ModestAccountRetrieveType retrieve_type; + gtk_tree_model_get (model, iter, MODEL_COL_RETRIEVE_TYPE, &retrieve_type, -1); + if (retrieve_type == state->retrieve_type) { + GtkWidget *selector; + selector = GTK_WIDGET (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (state->self))); + hildon_touch_selector_select_iter (HILDON_TOUCH_SELECTOR (selector), 0, iter, TRUE); + hildon_button_set_value (HILDON_BUTTON (state->self), + hildon_touch_selector_get_current_text (HILDON_TOUCH_SELECTOR (selector))); + + state->found = TRUE; + return TRUE; /* Stop walking the tree. */ + } + + return result; /* Whether we keep walking the tree. */ +} + +/** + * Selects the specified retrieve, + * or FALSE if no retrieve was selected. + */ +gboolean +modest_retrieve_picker_set_active_retrieve_conf (ModestRetrievePicker *picker, + ModestAccountRetrieveType retrieve_type) +{ + ModestRetrievePickerPrivate *priv = MODEST_RETRIEVE_PICKER_GET_PRIVATE (picker); + + /* Create a state instance so we can send two items of data to the signal handler: */ + ForEachData *state = g_new0 (ForEachData, 1); + state->self = picker; + state->retrieve_type = retrieve_type; + state->found = FALSE; + + /* Look at each item, and select the one with the correct ID: */ + gtk_tree_model_foreach (priv->model, &on_model_foreach_select_id, state); + + const gboolean result = state->found; + + /* Free the state instance: */ + g_free(state); + + return result; +} + diff --git a/src/hildon2/modest-retrieve-picker.h b/src/hildon2/modest-retrieve-picker.h new file mode 100644 index 0000000..59f4656 --- /dev/null +++ b/src/hildon2/modest-retrieve-picker.h @@ -0,0 +1,83 @@ +/* Copyright (c) 2007, 2008, Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * * Neither the name of the Nokia Corporation nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER + * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MODEST_RETRIEVE_PICKER +#define _MODEST_RETRIEVE_PICKER + +#include +#include "modest-protocol-registry.h" +#include + +G_BEGIN_DECLS + +#define MODEST_TYPE_RETRIEVE_PICKER modest_retrieve_picker_get_type() + +#define MODEST_RETRIEVE_PICKER(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + MODEST_TYPE_RETRIEVE_PICKER, ModestRetrievePicker)) + +#define MODEST_RETRIEVE_PICKER_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + MODEST_TYPE_RETRIEVE_PICKER, ModestRetrievePickerClass)) + +#define MODEST_IS_RETRIEVE_PICKER(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + MODEST_TYPE_RETRIEVE_PICKER)) + +#define MODEST_IS_RETRIEVE_PICKER_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), \ + MODEST_TYPE_RETRIEVE_PICKER)) + +#define MODEST_RETRIEVE_PICKER_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + MODEST_TYPE_RETRIEVE_PICKER, ModestRetrievePickerClass)) + +typedef struct { + HildonPickerButton parent; +} ModestRetrievePicker; + +typedef struct { + HildonPickerButtonClass parent_class; +} ModestRetrievePickerClass; + +GType modest_retrieve_picker_get_type (void); + +ModestRetrievePicker* modest_retrieve_picker_new (void); + +void modest_retrieve_picker_fill (ModestRetrievePicker *picker, ModestProtocolType protocol); + +ModestAccountRetrieveType modest_retrieve_picker_get_active_retrieve_conf (ModestRetrievePicker *picker); + +gboolean modest_retrieve_picker_set_active_retrieve_conf (ModestRetrievePicker *picker, + ModestAccountRetrieveType retrieve_type); + + +G_END_DECLS + +#endif /* _MODEST_RETRIEVE_PICKER */