2007-04-18 Murray Cumming <murrayc@murrayc.com>
+ * src/widgets/Makefile.am:
+ * src/widgets/modest-limit-retrieve-combo-box.c:
+ * src/widgets/modest-limit-retrieve-combo-box.h:
+ * src/widgets/modest-retrieve-combo-box.c:
+ * src/widgets/modest-retrieve-combo-box.h: Added new widgets for use in
+ the account settings dialog.
+
+ * src/modest-defs.h:
+ * src/modest-account-mgr-helpers.h:
+ * src/modest-account-mgr-helpers.c:
+ (modest_server_account_get_option_secure_auth),
+ (modest_server_account_set_option_secure_auth):
+ * src/modest-account-mgr.c:
+ (modest_account_mgr_add_server_account):
+ Use the existing AUTH_MECH conf key for the secure-auth setting,
+ instead of putting it in the list options, because this was actually used already.
+
+ * src/maemo/modest-account-settings-dialog.c:
+ (create_page_account_details),
+ (modest_account_settings_dialog_set_account_name),
+ (save_configuration):
+ * src/maemo/modest-account-settings-dialog.h:
+ Add the retrieve and retrieve-limit combo boxes, as per the UI spec.
+ Hide the leave-messages checkbox for non-POP accounts, as per the UI spec.
+
+2007-04-18 Murray Cumming <murrayc@murrayc.com>
+
* src/maemo/easysetup/modest-easysetup-serversecurity-combo-box.h:
* src/maemo/easysetup/modest-easysetup-serversecurity-combo-box.c:
Added easysetup_serversecurity_combo_box_get_active_serversecurity_port()
#include "maemo/easysetup/modest-easysetup-serversecurity-combo-box.h"
#include "maemo/easysetup/modest-easysetup-secureauth-combo-box.h"
#include "maemo/easysetup/modest-validating-entry.h"
+#include "widgets/modest-retrieve-combo-box.h"
+#include "widgets/modest-limit-retrieve-combo-box.h"
#include "modest-text-utils.h"
#include "modest-account-mgr.h"
#include "modest-account-mgr-helpers.h" /* For modest_account_mgr_get_account_data(). */
* TODO: The UI spec seems to want us to show a dialog if we hit the maximum. */
gtk_entry_set_max_length (GTK_ENTRY (self->entry_account_title), 64);
- /* TODO: The Retrieve and Limit Retrieve combo boxes. */
+ /* The retrieve combobox: */
+ self->combo_retrieve = GTK_WIDGET (modest_retrieve_combo_box_new ());
+ caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_advsetup_retrievetype"),
+ self->combo_retrieve, NULL, HILDON_CAPTION_MANDATORY);
+ gtk_widget_show (self->combo_retrieve);
+ gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
+ gtk_widget_show (caption);
+ /* The limit-retrieve combobox: */
+ self->combo_limit_retrieve = GTK_WIDGET (modest_limit_retrieve_combo_box_new ());
+ caption = create_caption_new_with_asterix (self, sizegroup, _("mcen_fi_advsetup_limit_retrieve"),
+ self->combo_limit_retrieve, NULL, HILDON_CAPTION_MANDATORY);
+ gtk_widget_show (self->combo_limit_retrieve);
+ gtk_box_pack_start (GTK_BOX (box), caption, FALSE, FALSE, 2);
+ gtk_widget_show (caption);
+
/* The leave-messages widgets: */
if(!self->checkbox_leave_messages)
self->checkbox_leave_messages =
gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_email),
account_data->email ? account_data->email : "");
+ ModestServerAccountData *incoming_account = account_data->store_account;
+
+ if (incoming_account)
+ modest_retrieve_combo_box_fill (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), incoming_account->proto);
+ gchar *retrieve = modest_account_mgr_get_string (dialog->account_manager, account_name,
+ MODEST_ACCOUNT_RETRIEVE, FALSE /* not server account */);
+ if (!retrieve) {
+ /* Default to something, though no default is specified in the UI spec: */
+ retrieve = g_strdup (MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY);
+ }
+ modest_retrieve_combo_box_set_active_retrieve_conf (MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve), retrieve);
+ g_free (retrieve);
+
+ const gint limit_retrieve = modest_account_mgr_get_int (dialog->account_manager, account_name,
+ MODEST_ACCOUNT_LIMIT_RETRIEVE, FALSE /* not server account */);
+ modest_limit_retrieve_combo_box_set_active_limit_retrieve (MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve), limit_retrieve);
+
+
const gboolean leave_on_server = modest_account_mgr_get_bool (dialog->account_manager, account_name,
MODEST_ACCOUNT_LEAVE_ON_SERVER, FALSE /* not server account */);
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages), leave_on_server);
+
+ /* Only show the leave-on-server checkbox for POP,
+ * as per the UI spec: */
+ if (incoming_account->proto != MODEST_PROTOCOL_STORE_POP) {
+ gtk_widget_hide (dialog->checkbox_leave_messages);
+ } else {
+ gtk_widget_show (dialog->checkbox_leave_messages);
+ }
- ModestServerAccountData *incoming_account = account_data->store_account;
if (incoming_account) {
gtk_entry_set_text( GTK_ENTRY (dialog->entry_user_username),
incoming_account->username ? incoming_account->username : "");
gtk_entry_set_text( GTK_ENTRY (dialog->entry_incomingserver),
incoming_account->hostname ? incoming_account->hostname : "");
- const ModestProtocol secure_auth = modest_server_account_data_get_option_secure_auth(incoming_account);
+ const ModestProtocol secure_auth = modest_server_account_get_option_secure_auth(
+ dialog->account_manager, incoming_account->account_name);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (dialog->checkbox_incoming_auth),
secure_auth == MODEST_PROTOCOL_AUTH_PASSWORD);
outgoing_account->password ? outgoing_account->password : "");
/* Get the secure-auth setting: */
- const ModestProtocol secure_auth = modest_server_account_data_get_option_secure_auth(outgoing_account);
+ const ModestProtocol secure_auth = modest_server_account_get_option_secure_auth(
+ dialog->account_manager, outgoing_account->account_name);
easysetup_secureauth_combo_box_set_active_secureauth (
EASYSETUP_SECUREAUTH_COMBO_BOX (dialog->combo_outgoing_auth), secure_auth);
on_combo_outgoing_auth_changed (GTK_COMBO_BOX (dialog->combo_outgoing_auth), dialog);
if (!test)
return FALSE;
+ gchar *retrieve = modest_retrieve_combo_box_get_active_retrieve_conf (
+ MODEST_RETRIEVE_COMBO_BOX (dialog->combo_retrieve));
+ modest_account_mgr_set_string (dialog->account_manager, account_name,
+ MODEST_ACCOUNT_RETRIEVE, retrieve, FALSE /* not server account */);
+ g_free (retrieve);
+
+ const gint limit_retrieve = modest_limit_retrieve_combo_box_get_active_limit_retrieve (
+ MODEST_LIMIT_RETRIEVE_COMBO_BOX (dialog->combo_limit_retrieve));
+ modest_account_mgr_set_int (dialog->account_manager, account_name,
+ MODEST_ACCOUNT_LIMIT_RETRIEVE, limit_retrieve, FALSE /* not server account */);
+
const gboolean leave_on_server = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->checkbox_leave_messages));
test = modest_account_mgr_set_bool (dialog->account_manager, account_name,
MODEST_ACCOUNT_LEAVE_ON_SERVER, leave_on_server, FALSE /* not server account */);
GtkWidget *page_account_details;
GtkWidget *entry_account_title;
+ GtkWidget *combo_retrieve;
+ GtkWidget *combo_limit_retrieve;
GtkWidget *checkbox_leave_messages;
GtkWidget *page_user_details;
}
ModestProtocol
-modest_server_account_data_get_option_secure_auth (ModestServerAccountData *account_data)
+modest_server_account_get_option_secure_auth (ModestAccountMgr *self,
+ const gchar* account_name)
{
ModestProtocol result = MODEST_PROTOCOL_AUTH_NONE;
- gchar* value = modest_server_account_data_get_option_value (account_data->options,
- MODEST_ACCOUNT_OPTION_SECURE_AUTH);
+ gchar* value =modest_account_mgr_get_string (self, account_name, MODEST_ACCOUNT_AUTH_MECH,
+ TRUE /* server account */);
if (value) {
- if (strcmp(value, MODEST_ACCOUNT_OPTION_SECURE_AUTH_VALUE_NONE) == 0)
+ if (strcmp(value, MODEST_ACCOUNT_AUTH_MECH_VALUE_NONE) == 0)
result = MODEST_PROTOCOL_AUTH_NONE;
- else if (strcmp(value, MODEST_ACCOUNT_OPTION_SECURE_AUTH_VALUE_PASSWORD) == 0)
+ else if (strcmp(value, MODEST_ACCOUNT_AUTH_MECH_VALUE_PASSWORD) == 0)
result = MODEST_PROTOCOL_AUTH_PASSWORD;
- else if (strcmp(value, MODEST_ACCOUNT_OPTION_SECURE_AUTH_VALUE_CRAMMD5) == 0)
+ else if (strcmp(value, MODEST_ACCOUNT_AUTH_MECH_VALUE_CRAMMD5) == 0)
result = MODEST_PROTOCOL_AUTH_CRAMMD5;
g_free (value);
modest_server_account_set_option_secure_auth (ModestAccountMgr *self,
const gchar* account_name, ModestProtocol secure_auth)
{
- GSList *options_list = modest_account_mgr_get_list (self, account_name, MODEST_ACCOUNT_OPTIONS,
- MODEST_CONF_VALUE_STRING, TRUE);
- if(options_list) {
- /* Remove the item if it exists already: */
- GSList* option = NULL;
- do {
- option = g_slist_find_custom(options_list, MODEST_ACCOUNT_OPTION_SECURE_AUTH, (GCompareFunc)compare_option_strings_for_name);
- if(option)
- options_list = g_slist_remove (options_list, option->data);
- } while (option);
- }
-
- /* Add the new item to the list: */
+ /* Get the conf string for the enum value: */
const gchar* str_value = NULL;
if (secure_auth == MODEST_PROTOCOL_AUTH_NONE)
- str_value = MODEST_ACCOUNT_OPTION_SECURE_AUTH_VALUE_NONE;
+ str_value = MODEST_ACCOUNT_AUTH_MECH_VALUE_NONE;
else if (secure_auth == MODEST_PROTOCOL_AUTH_PASSWORD)
- str_value = MODEST_ACCOUNT_OPTION_SECURE_AUTH_VALUE_PASSWORD;
+ str_value = MODEST_ACCOUNT_AUTH_MECH_VALUE_PASSWORD;
else if (secure_auth == MODEST_PROTOCOL_AUTH_CRAMMD5)
- str_value = MODEST_ACCOUNT_OPTION_SECURE_AUTH_VALUE_CRAMMD5;
-
- if (str_value) {
- gchar* pair = g_strdup_printf(MODEST_ACCOUNT_OPTION_SECURE_AUTH "=%s", str_value);
- options_list = g_slist_append(options_list, pair);
- }
+ str_value = MODEST_ACCOUNT_AUTH_MECH_VALUE_CRAMMD5;
/* Set it in the configuration: */
- modest_account_mgr_set_list (self, account_name, MODEST_ACCOUNT_OPTIONS, options_list,
- MODEST_CONF_VALUE_STRING, TRUE);
-
- /* TODO: Should we free the items too, or just the list? */
- g_slist_free (options_list);
+ modest_account_mgr_set_string (self, account_name, MODEST_ACCOUNT_AUTH_MECH, str_value, TRUE);
}
ModestProtocol
gboolean modest_account_mgr_get_enabled (ModestAccountMgr *self, const gchar* name);
/**
- * modest_server_account_data_get_option_secure_auth:
- * @account_data: a ModestAccountData instance.
+ * modest_server_account_get_option_secure_auth:
+ * @self: a ModestAccountMgr instance
+ * @account_name: The name of a server account.
*
* Gets the secure authentication method for this server account.
*
* Returns: The secure authentication enum value.
*/
ModestProtocol
-modest_server_account_data_get_option_secure_auth (ModestServerAccountData *account_data);
+modest_server_account_get_option_secure_auth (ModestAccountMgr *self, const gchar* account_name);
/**
* modest_server_account_data_get_option_secure_auth:
* @self: a ModestAccountMgr instance
+ * @account_name: The name of a server account.
* @secure_auth: The secure authentication enum value.
*
* Gets the secure authentication method for this server account.
g_free (key);
- /* Add the security and secure-auth settings: */
+ /* Add the security settings: */
modest_server_account_set_option_security (self, name, security);
- modest_server_account_set_option_secure_auth (self, name, auth);
}
cleanup:
#define MODEST_ACCOUNT_PREFERRED_CNX "preferred_cnx" /* string */
#define MODEST_ACCOUNT_PORT "port" /* int */
#define MODEST_ACCOUNT_OPTIONS "options" /* list */
+
#define MODEST_ACCOUNT_AUTH_MECH "auth_mech" /* string */
+#define MODEST_ACCOUNT_AUTH_MECH_VALUE_NONE "none"
+#define MODEST_ACCOUNT_AUTH_MECH_VALUE_PASSWORD "password"
+#define MODEST_ACCOUNT_AUTH_MECH_VALUE_CRAMMD5 "cram-md5"
-/* Keys and values used in the text items in the options GSList: */
-#define MODEST_ACCOUNT_OPTION_SECURE_AUTH "secure_auth"
-#define MODEST_ACCOUNT_OPTION_SECURE_AUTH_VALUE_NONE "none"
-#define MODEST_ACCOUNT_OPTION_SECURE_AUTH_VALUE_PASSWORD "password"
-#define MODEST_ACCOUNT_OPTION_SECURE_AUTH_VALUE_CRAMMD5 "cram-md5"
+#define MODEST_ACCOUNT_RETRIEVE "retrieve" /* string */
+#define MODEST_ACCOUNT_RETRIEVE_VALUE_HEADERS_ONLY "headers-only"
+#define MODEST_ACCOUNT_RETRIEVE_VALUE_MESSAGES "messages"
+#define MODEST_ACCOUNT_RETRIEVE_VALUE_MESSAGES_AND_ATTACHMENTS "messages-and-attachments"
+#define MODEST_ACCOUNT_LIMIT_RETRIEVE "limit-retrieve" /* int */
+
+/* Keys and values used in the text items in the options GSList: */
#define MODEST_ACCOUNT_OPTION_SECURITY "security"
#define MODEST_ACCOUNT_OPTION_SECURITY_VALUE_NONE "none"
#define MODEST_ACCOUNT_OPTION_SECURITY_VALUE_NORMAL "normal"
modest-header-view-render.c \
modest-header-view.c \
modest-header-view.h \
+ modest-limit-retrieve-combo-box.h \
+ modest-limit-retrieve-combo-box.c \
modest-mail-header-view.c \
modest-mail-header-view.h \
modest-main-window.h \
modest-recpt-editor.h \
modest-recpt-view.c \
modest-recpt-view.h \
+ modest-retrieve-combo-box.h \
+ modest-retrieve-combo-box.c \
modest-scroll-text.c \
modest-scroll-text.h \
modest-tny-stream-gtkhtml.c \
--- /dev/null
+/* Copyright (c) 2007, Nokia Corporation
+ * All rights reserved.
+ *
+ */
+
+#include "modest-limit-retrieve-combo-box.h"
+#include <gtk/gtkliststore.h>
+#include <gtk/gtkcelllayout.h>
+#include <gtk/gtkcellrenderertext.h>
+#include <glib/gi18n.h>
+
+#include <stdlib.h>
+#include <string.h> /* For memcpy() */
+
+/* Include config.h so that _() works: */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+G_DEFINE_TYPE (ModestLimitRetrieveComboBox, modest_limit_retrieve_combo_box, GTK_TYPE_COMBO_BOX);
+
+#define LIMIT_RETRIEVE_COMBO_BOX_GET_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_LIMIT_RETRIEVE_COMBO_BOX, ModestLimitRetrieveComboBoxPrivate))
+
+typedef struct _ModestLimitRetrieveComboBoxPrivate ModestLimitRetrieveComboBoxPrivate;
+
+struct _ModestLimitRetrieveComboBoxPrivate
+{
+ GtkTreeModel *model;
+};
+
+static void
+modest_limit_retrieve_combo_box_get_property (GObject *object, guint property_id,
+ GValue *value, GParamSpec *pspec)
+{
+ switch (property_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+modest_limit_retrieve_combo_box_set_property (GObject *object, guint property_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ switch (property_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+modest_limit_retrieve_combo_box_dispose (GObject *object)
+{
+ if (G_OBJECT_CLASS (modest_limit_retrieve_combo_box_parent_class)->dispose)
+ G_OBJECT_CLASS (modest_limit_retrieve_combo_box_parent_class)->dispose (object);
+}
+
+static void
+modest_limit_retrieve_combo_box_finalize (GObject *object)
+{
+ ModestLimitRetrieveComboBoxPrivate *priv = LIMIT_RETRIEVE_COMBO_BOX_GET_PRIVATE (object);
+
+ g_object_unref (G_OBJECT (priv->model));
+
+ G_OBJECT_CLASS (modest_limit_retrieve_combo_box_parent_class)->finalize (object);
+}
+
+static void
+modest_limit_retrieve_combo_box_class_init (ModestLimitRetrieveComboBoxClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (ModestLimitRetrieveComboBoxPrivate));
+
+ object_class->get_property = modest_limit_retrieve_combo_box_get_property;
+ object_class->set_property = modest_limit_retrieve_combo_box_set_property;
+ object_class->dispose = modest_limit_retrieve_combo_box_dispose;
+ object_class->finalize = modest_limit_retrieve_combo_box_finalize;
+}
+
+enum MODEL_COLS {
+ MODEL_COL_NAME = 0, /* a string */
+ MODEL_COL_NUM = 1 /* an int */
+};
+
+void modest_limit_retrieve_combo_box_fill (ModestLimitRetrieveComboBox *combobox);
+
+static void
+modest_limit_retrieve_combo_box_init (ModestLimitRetrieveComboBox *self)
+{
+ ModestLimitRetrieveComboBoxPrivate *priv = LIMIT_RETRIEVE_COMBO_BOX_GET_PRIVATE (self);
+
+ /* Create a tree model for the combo box,
+ * with a string for the name, and an ID for the limit_retrieve.
+ * This must match our MODEL_COLS enum constants.
+ */
+ priv->model = GTK_TREE_MODEL (gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT));
+
+ /* Setup the combo box: */
+ GtkComboBox *combobox = GTK_COMBO_BOX (self);
+ gtk_combo_box_set_model (combobox, priv->model);
+
+ /* LimitRetrieve column:
+ * The ID model column in not shown in the view. */
+ GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start(GTK_CELL_LAYOUT (combobox), renderer, TRUE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
+ "text", MODEL_COL_NAME, NULL);
+
+ modest_limit_retrieve_combo_box_fill (self);
+}
+
+ModestLimitRetrieveComboBox*
+modest_limit_retrieve_combo_box_new (void)
+{
+ return g_object_new (MODEST_TYPE_LIMIT_RETRIEVE_COMBO_BOX, NULL);
+}
+
+/* Fill the combo box with appropriate choices.
+ * #combobox: The combo box.
+ * @protocol: IMAP or POP.
+ */
+void modest_limit_retrieve_combo_box_fill (ModestLimitRetrieveComboBox *combobox)
+{
+ ModestLimitRetrieveComboBoxPrivate *priv = LIMIT_RETRIEVE_COMBO_BOX_GET_PRIVATE (combobox);
+
+ /* 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_NUM, 0, MODEL_COL_NAME, _("mcen_fi_advsetup_retrieve_nolimit"), -1);
+
+ gtk_list_store_append (liststore, &iter);
+ gtk_list_store_set (liststore, &iter, MODEL_COL_NUM, 200, MODEL_COL_NAME, _("mcen_fi_advsetup_retrieve_200"), -1);
+
+ gtk_list_store_append (liststore, &iter);
+ gtk_list_store_set (liststore, &iter, MODEL_COL_NUM, 100, MODEL_COL_NAME, _("mcen_fi_advsetup_retrieve_100"), -1);
+
+ gtk_list_store_append (liststore, &iter);
+ gtk_list_store_set (liststore, &iter, MODEL_COL_NUM, 50, MODEL_COL_NAME, _("mcen_fi_advsetup_retrieve_50"), -1);
+
+ gtk_list_store_append (liststore, &iter);
+ gtk_list_store_set (liststore, &iter, MODEL_COL_NUM, 10, MODEL_COL_NAME, _("mcen_fi_advsetup_retrieve_10"), -1);
+}
+
+/**
+ * Returns the selected limit_retrieve,
+ * or 0 if no limit_retrieve was selected.
+ */
+gint
+modest_limit_retrieve_combo_box_get_active_limit_retrieve (ModestLimitRetrieveComboBox *combobox)
+{
+ GtkTreeIter active;
+ const gboolean found = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combobox), &active);
+ if (found) {
+ ModestLimitRetrieveComboBoxPrivate *priv = LIMIT_RETRIEVE_COMBO_BOX_GET_PRIVATE (combobox);
+
+ gint limit_retrieve = 0;
+ gtk_tree_model_get (priv->model, &active, MODEL_COL_NUM, &limit_retrieve, -1);
+ return limit_retrieve;
+ }
+
+ return 0; /* Failed. */
+}
+
+/* This allows us to pass more than one piece of data to the signal handler,
+ * and get a result: */
+typedef struct
+{
+ ModestLimitRetrieveComboBox* self;
+ gint num;
+ 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: */
+ gint num = 0;
+ gtk_tree_model_get (model, iter, MODEL_COL_NUM, &num, -1);
+ if(num == state->num) {
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (state->self), iter);
+
+ state->found = TRUE;
+ result = TRUE; /* Stop walking the tree. */
+ }
+
+ return result; /* Whether we keep walking the tree. */
+}
+
+/**
+ * Selects the specified limit_retrieve,
+ * or FALSE if no limit_retrieve was selected.
+ */
+gboolean
+modest_limit_retrieve_combo_box_set_active_limit_retrieve (ModestLimitRetrieveComboBox *combobox, gint limit_retrieve)
+{
+ ModestLimitRetrieveComboBoxPrivate *priv = LIMIT_RETRIEVE_COMBO_BOX_GET_PRIVATE (combobox);
+
+ /* Create a state instance so we can send two items of data to the signal handler: */
+ ForEachData *state = g_new0 (ForEachData, 1);
+ state->self = combobox;
+ state->num = limit_retrieve;
+ 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;
+}
+
--- /dev/null
+/* Copyright (c) 2007, Nokia Corporation
+ * All rights reserved.
+ *
+ */
+
+#ifndef _MODEST_LIMIT_RETRIEVE_COMBO_BOX
+#define _MODEST_LIMIT_RETRIEVE_COMBO_BOX
+
+#include <gtk/gtkcombobox.h>
+#include "modest-protocol-info.h"
+
+G_BEGIN_DECLS
+
+#define MODEST_TYPE_LIMIT_RETRIEVE_COMBO_BOX modest_limit_retrieve_combo_box_get_type()
+
+#define MODEST_LIMIT_RETRIEVE_COMBO_BOX(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ MODEST_TYPE_LIMIT_RETRIEVE_COMBO_BOX, ModestLimitRetrieveComboBox))
+
+#define MODEST_LIMIT_RETRIEVE_COMBO_BOX_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ MODEST_TYPE_LIMIT_RETRIEVE_COMBO_BOX, ModestLimitRetrieveComboBoxClass))
+
+#define MODEST_IS_LIMIT_RETRIEVE_COMBO_BOX(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ MODEST_TYPE_LIMIT_RETRIEVE_COMBO_BOX))
+
+#define MODEST_IS_LIMIT_RETRIEVE_COMBO_BOX_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ MODEST_TYPE_LIMIT_RETRIEVE_COMBO_BOX))
+
+#define MODEST_LIMIT_RETRIEVE_COMBO_BOX_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ MODEST_TYPE_LIMIT_RETRIEVE_COMBO_BOX, ModestLimitRetrieveComboBoxClass))
+
+typedef struct {
+ GtkComboBox parent;
+} ModestLimitRetrieveComboBox;
+
+typedef struct {
+ GtkComboBoxClass parent_class;
+} ModestLimitRetrieveComboBoxClass;
+
+GType modest_limit_retrieve_combo_box_get_type (void);
+
+ModestLimitRetrieveComboBox* modest_limit_retrieve_combo_box_new (void);
+
+gint modest_limit_retrieve_combo_box_get_active_limit_retrieve (ModestLimitRetrieveComboBox *combobox);
+
+gboolean modest_limit_retrieve_combo_box_set_active_limit_retrieve (ModestLimitRetrieveComboBox *combobox, gint limit_retrieve);
+
+
+G_END_DECLS
+
+#endif /* _MODEST_LIMIT_RETRIEVE_COMBO_BOX */
--- /dev/null
+/* Copyright (c) 2007, Nokia Corporation
+ * All rights reserved.
+ *
+ */
+
+#include "modest-retrieve-combo-box.h"
+#include "modest-defs.h" /* For the conf names. */
+#include <gtk/gtkliststore.h>
+#include <gtk/gtkcelllayout.h>
+#include <gtk/gtkcellrenderertext.h>
+#include <glib/gi18n.h>
+
+#include <stdlib.h>
+#include <string.h> /* For memcpy() */
+
+/* Include config.h so that _() works: */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+G_DEFINE_TYPE (ModestRetrieveComboBox, modest_retrieve_combo_box, GTK_TYPE_COMBO_BOX);
+
+#define RETRIEVE_COMBO_BOX_GET_PRIVATE(o) \
+ (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_RETRIEVE_COMBO_BOX, ModestRetrieveComboBoxPrivate))
+
+typedef struct _ModestRetrieveComboBoxPrivate ModestRetrieveComboBoxPrivate;
+
+struct _ModestRetrieveComboBoxPrivate
+{
+ GtkTreeModel *model;
+};
+
+static void
+modest_retrieve_combo_box_get_property (GObject *object, guint property_id,
+ GValue *value, GParamSpec *pspec)
+{
+ switch (property_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+modest_retrieve_combo_box_set_property (GObject *object, guint property_id,
+ const GValue *value, GParamSpec *pspec)
+{
+ switch (property_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ }
+}
+
+static void
+modest_retrieve_combo_box_dispose (GObject *object)
+{
+ if (G_OBJECT_CLASS (modest_retrieve_combo_box_parent_class)->dispose)
+ G_OBJECT_CLASS (modest_retrieve_combo_box_parent_class)->dispose (object);
+}
+
+static void
+modest_retrieve_combo_box_finalize (GObject *object)
+{
+ ModestRetrieveComboBoxPrivate *priv = RETRIEVE_COMBO_BOX_GET_PRIVATE (object);
+
+ g_object_unref (G_OBJECT (priv->model));
+
+ G_OBJECT_CLASS (modest_retrieve_combo_box_parent_class)->finalize (object);
+}
+
+static void
+modest_retrieve_combo_box_class_init (ModestRetrieveComboBoxClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ g_type_class_add_private (klass, sizeof (ModestRetrieveComboBoxPrivate));
+
+ object_class->get_property = modest_retrieve_combo_box_get_property;
+ object_class->set_property = modest_retrieve_combo_box_set_property;
+ object_class->dispose = modest_retrieve_combo_box_dispose;
+ object_class->finalize = modest_retrieve_combo_box_finalize;
+}
+
+enum MODEL_COLS {
+ MODEL_COL_NAME = 0, /* a string */
+ MODEL_COL_CONF_NAME = 1 /* a string */
+};
+
+void modest_retrieve_combo_box_fill (ModestRetrieveComboBox *combobox, ModestProtocol protocol);
+
+static void
+modest_retrieve_combo_box_init (ModestRetrieveComboBox *self)
+{
+ ModestRetrieveComboBoxPrivate *priv = RETRIEVE_COMBO_BOX_GET_PRIVATE (self);
+
+ /* Create a tree model for the combo box,
+ * with a string for the name, and an ID for the retrieve.
+ * This must match our MODEL_COLS enum constants.
+ */
+ priv->model = GTK_TREE_MODEL (gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING));
+
+ /* Setup the combo box: */
+ GtkComboBox *combobox = GTK_COMBO_BOX (self);
+ gtk_combo_box_set_model (combobox, priv->model);
+
+ /* Retrieve column:
+ * The ID model column in not shown in the view. */
+ GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
+ gtk_cell_layout_pack_start(GTK_CELL_LAYOUT (combobox), renderer, TRUE);
+ gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
+ "text", MODEL_COL_NAME, NULL);
+
+ /* The application must call modest_retrieve_combo_box_fill(), specifying POP or IMAP. */
+}
+
+
+
+ModestRetrieveComboBox*
+modest_retrieve_combo_box_new (void)
+{
+ return g_object_new (MODEST_TYPE_RETRIEVE_COMBO_BOX, NULL);
+}
+
+/* Fill the combo box with appropriate choices.
+ * #combobox: The combo box.
+ * @protocol: IMAP or POP.
+ */
+void modest_retrieve_combo_box_fill (ModestRetrieveComboBox *combobox, ModestProtocol protocol)
+{
+ ModestRetrieveComboBoxPrivate *priv = RETRIEVE_COMBO_BOX_GET_PRIVATE (combobox);
+
+ /* 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_CONF_NAME, MODEST_ACCOUNT_RETRIEVE_VALUE_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_CONF_NAME, MODEST_ACCOUNT_RETRIEVE_VALUE_MESSAGES,
+ MODEL_COL_NAME, _("mcen_fi_advsetup_retrievetype_messages"), -1);
+
+ /* Only IMAP should have this option, according to the UI spec: */
+ if (protocol == MODEST_PROTOCOL_STORE_IMAP) {
+ gtk_list_store_append (liststore, &iter);
+ gtk_list_store_set (liststore, &iter,
+ MODEL_COL_CONF_NAME, MODEST_ACCOUNT_RETRIEVE_VALUE_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().
+ */
+gchar*
+modest_retrieve_combo_box_get_active_retrieve_conf (ModestRetrieveComboBox *combobox)
+{
+ GtkTreeIter active;
+ const gboolean found = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combobox), &active);
+ if (found) {
+ ModestRetrieveComboBoxPrivate *priv = RETRIEVE_COMBO_BOX_GET_PRIVATE (combobox);
+
+ gchar *retrieve = NULL;
+ gtk_tree_model_get (priv->model, &active, MODEL_COL_CONF_NAME, &retrieve, -1);
+ return retrieve;
+ }
+
+ return NULL; /* Failed. */
+}
+
+/* This allows us to pass more than one piece of data to the signal handler,
+ * and get a result: */
+typedef struct
+{
+ ModestRetrieveComboBox* self;
+ const gchar* conf_name;
+ 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: */
+ gchar * conf_name = 0;
+ gtk_tree_model_get (model, iter, MODEL_COL_CONF_NAME, &conf_name, -1);
+ if(conf_name && state->conf_name && (strcmp(conf_name, state->conf_name) == 0)) {
+ gtk_combo_box_set_active_iter (GTK_COMBO_BOX (state->self), iter);
+
+ state->found = TRUE;
+ result = TRUE; /* Stop walking the tree. */
+ }
+ g_free (conf_name);
+
+ return result; /* Whether we keep walking the tree. */
+}
+
+/**
+ * Selects the specified retrieve,
+ * or FALSE if no retrieve was selected.
+ */
+gboolean
+modest_retrieve_combo_box_set_active_retrieve_conf (ModestRetrieveComboBox *combobox, const gchar* retrieve)
+{
+ ModestRetrieveComboBoxPrivate *priv = RETRIEVE_COMBO_BOX_GET_PRIVATE (combobox);
+
+ /* Create a state instance so we can send two items of data to the signal handler: */
+ ForEachData *state = g_new0 (ForEachData, 1);
+ state->self = combobox;
+ state->conf_name = retrieve;
+ 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;
+}
+
--- /dev/null
+/* Copyright (c) 2007, Nokia Corporation
+ * All rights reserved.
+ *
+ */
+
+#ifndef _MODEST_RETRIEVE_COMBO_BOX
+#define _MODEST_RETRIEVE_COMBO_BOX
+
+#include <gtk/gtkcombobox.h>
+#include "modest-protocol-info.h"
+
+G_BEGIN_DECLS
+
+#define MODEST_TYPE_RETRIEVE_COMBO_BOX modest_retrieve_combo_box_get_type()
+
+#define MODEST_RETRIEVE_COMBO_BOX(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+ MODEST_TYPE_RETRIEVE_COMBO_BOX, ModestRetrieveComboBox))
+
+#define MODEST_RETRIEVE_COMBO_BOX_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST ((klass), \
+ MODEST_TYPE_RETRIEVE_COMBO_BOX, ModestRetrieveComboBoxClass))
+
+#define MODEST_IS_RETRIEVE_COMBO_BOX(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+ MODEST_TYPE_RETRIEVE_COMBO_BOX))
+
+#define MODEST_IS_RETRIEVE_COMBO_BOX_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+ MODEST_TYPE_RETRIEVE_COMBO_BOX))
+
+#define MODEST_RETRIEVE_COMBO_BOX_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+ MODEST_TYPE_RETRIEVE_COMBO_BOX, ModestRetrieveComboBoxClass))
+
+typedef struct {
+ GtkComboBox parent;
+} ModestRetrieveComboBox;
+
+typedef struct {
+ GtkComboBoxClass parent_class;
+} ModestRetrieveComboBoxClass;
+
+GType modest_retrieve_combo_box_get_type (void);
+
+ModestRetrieveComboBox* modest_retrieve_combo_box_new (void);
+
+void modest_retrieve_combo_box_fill (ModestRetrieveComboBox *combobox, ModestProtocol protocol);
+
+gchar* modest_retrieve_combo_box_get_active_retrieve_conf (ModestRetrieveComboBox *combobox);
+
+gboolean modest_retrieve_combo_box_set_active_retrieve_conf (ModestRetrieveComboBox *combobox, const gchar* retrieve);
+
+
+G_END_DECLS
+
+#endif /* _MODEST_RETRIEVE_COMBO_BOX */