New ModestServertypeComboBox for gtk.
authorJose Dapena Paz <jdapena@igalia.com>
Fri, 13 Nov 2009 06:50:08 +0000 (07:50 +0100)
committerJose Dapena Paz <jdapena@igalia.com>
Tue, 17 Nov 2009 16:59:12 +0000 (17:59 +0100)
src/hildon2/modest-easysetup-wizard-dialog.c
src/widgets/Makefile.am
src/widgets/modest-servertype-combo-box.c [new file with mode: 0644]
src/widgets/modest-servertype-combo-box.h [new file with mode: 0644]
src/widgets/modest-toolkit-factory.c
src/widgets/modest-toolkit-factory.h

index 34748f0..a6ef66f 100644 (file)
@@ -38,7 +38,6 @@
 #include <gtk/gtkbutton.h>
 #include <gtk/gtkmessagedialog.h>
 #include <gtk/gtkseparator.h>
-#include "modest-servertype-picker.h"
 #include "widgets/modest-validating-entry.h"
 #include "modest-text-utils.h"
 #include "modest-conf.h"
@@ -126,7 +125,7 @@ struct _ModestEasysetupWizardDialogPrivate
        GtkWidget *page_complete_easysetup;
 
        GtkWidget *page_custom_incoming;
-       GtkWidget *incoming_servertype_picker;
+       GtkWidget *incoming_servertype_selector;
        GtkWidget *caption_incoming;
        GtkWidget *entry_incomingserver;
 
@@ -244,7 +243,9 @@ create_subsequent_easysetup_pages (ModestEasysetupWizardDialog *self);
 static void
 set_default_custom_servernames(ModestEasysetupWizardDialog *dialog);
 
+#ifdef HILDON_PICKER_BUTTON
 static void on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data);
+#endif
 
 static gint
 get_port_from_protocol (ModestProtocolType server_type,
@@ -490,6 +491,7 @@ update_user_email_from_provider (ModestEasysetupWizardDialog *self)
        g_free (provider_id);
 }
 
+#ifdef HILDON_PICKER_BUTTON
 static void
 on_account_serviceprovider_selector_changed (GtkWidget *widget, gint column, gpointer user_data)
 {
@@ -501,6 +503,7 @@ on_account_serviceprovider_selector_changed (GtkWidget *widget, gint column, gpo
 
        update_user_email_from_provider (self);
 }
+#endif
 
 static void
 on_account_serviceprovider_selector_combo_box_changed (GtkWidget *widget, gpointer user_data)
@@ -867,8 +870,8 @@ update_incoming_server_title (ModestEasysetupWizardDialog *self)
        priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
        protocol_registry = modest_runtime_get_protocol_registry ();
 
-       protocol_type = modest_servertype_picker_get_active_servertype (
-               MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
+       protocol_type = modest_servertype_selector_get_active_servertype (
+               priv->incoming_servertype_selector);
 
        /* This could happen when the combo box has still no active iter */
        if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
@@ -896,14 +899,12 @@ static void
 update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
 {
        ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
-       ModestServertypePicker *server_type_picker;
+       GtkWidget *server_type_selector;
        ModestProtocolType protocol_type;
        ModestSecurityOptionsView *view;
 
-       server_type_picker =
-               MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker);
-       protocol_type =
-               modest_servertype_picker_get_active_servertype (server_type_picker);
+       server_type_selector = priv->incoming_servertype_selector;
+       protocol_type = modest_servertype_selector_get_active_servertype (server_type_selector);
 
        /* Fill the combo with appropriately titled choices for all
           those protocols */
@@ -911,6 +912,7 @@ update_incoming_server_security_choices (ModestEasysetupWizardDialog *self)
        modest_security_options_view_set_server_type (view, protocol_type);
 }
 
+#ifdef HILDON_PICKER_BUTTON
 static void
 on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpointer user_data)
 {
@@ -928,6 +930,25 @@ on_servertype_selector_changed(HildonTouchSelector *selector, gint column, gpoin
 
        set_default_custom_servernames (self);
 }
+#endif
+
+static void
+on_servertype_combo_changed(GtkWidget *selector, gpointer user_data)
+{
+       ModestEasysetupWizardDialog *self = MODEST_EASYSETUP_WIZARD_DIALOG (user_data);
+       ModestEasysetupWizardDialogPrivate *priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE(self);
+
+       priv->dirty = TRUE;
+
+       /* Update title */
+       update_incoming_server_title (self);
+
+       /* Update security options if needed */
+       update_incoming_server_security_choices (self);
+       gtk_widget_show (priv->incoming_security);
+
+       set_default_custom_servernames (self);
+}
 
 static void
 on_entry_incoming_servername_changed(GtkEntry *entry, gpointer user_data)
@@ -972,16 +993,28 @@ create_page_custom_incoming (ModestEasysetupWizardDialog *self)
        value_sizegroup = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
 
        /* The incoming server widgets: */
-       priv->incoming_servertype_picker = GTK_WIDGET (modest_servertype_picker_new (MODEST_EDITABLE_SIZE,
-                                                                                    HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
-                                                                                    TRUE));
-       modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
-                                              _("mcen_li_emailsetup_type"),
-                                              priv->incoming_servertype_picker);
-       g_signal_connect (G_OBJECT (priv->incoming_servertype_picker), "value-changed",
-                         G_CALLBACK (on_picker_button_value_changed), self);
-       gtk_box_pack_start (GTK_BOX (box), priv->incoming_servertype_picker, FALSE, FALSE, 0);
-       gtk_widget_show (priv->incoming_servertype_picker);
+       priv->incoming_servertype_selector = 
+               modest_toolkit_factory_create_servertype_selector (modest_runtime_get_toolkit_factory (), 
+                                                                  TRUE);
+       if (GTK_IS_COMBO_BOX (priv->incoming_servertype_selector)) {
+               GtkWidget *captioned;
+               g_signal_connect (G_OBJECT (priv->incoming_servertype_selector), "changed",
+                                 G_CALLBACK (on_picker_button_value_changed), self);
+               captioned = modest_maemo_utils_create_captioned (title_sizegroup, value_sizegroup,
+                                                                _("mcen_fi_country"), FALSE,
+                                                                priv->incoming_servertype_selector);
+               
+               gtk_box_pack_start (GTK_BOX (box), captioned, FALSE, FALSE, MODEST_MARGIN_HALF);
+               gtk_widget_show (captioned);
+       } else {
+               modest_maemo_utils_set_hbutton_layout (title_sizegroup, value_sizegroup,
+                                                      _("mcen_li_emailsetup_type"),
+                                                      priv->incoming_servertype_selector);
+               g_signal_connect (G_OBJECT (priv->incoming_servertype_selector), "value-changed",
+                                 G_CALLBACK (on_picker_button_value_changed), self);
+               gtk_box_pack_start (GTK_BOX (box), priv->incoming_servertype_selector, FALSE, FALSE, 0);
+       }
+       gtk_widget_show (priv->incoming_servertype_selector);
 
        priv->entry_incomingserver = modest_toolkit_factory_create_entry (modest_runtime_get_toolkit_factory ());
 
@@ -1013,18 +1046,25 @@ create_page_custom_incoming (ModestEasysetupWizardDialog *self)
        gtk_widget_show (priv->incoming_security);
 
        /* Set default selection */
-       modest_servertype_picker_set_active_servertype (
-               MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker),
-               MODEST_PROTOCOLS_STORE_POP);
+       modest_servertype_selector_set_active_servertype (priv->incoming_servertype_selector,
+                                                         MODEST_PROTOCOLS_STORE_POP);
        update_incoming_server_title (self);
        update_incoming_server_security_choices (self);
        set_default_custom_servernames (self);
 
        /* Change the caption title when the servertype changes,
         * as in the UI spec: */
-       g_signal_connect (G_OBJECT (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (priv->incoming_servertype_picker))),
-                         "changed",
-                         G_CALLBACK (on_servertype_selector_changed), self);
+       if (GTK_IS_COMBO_BOX (priv->incoming_servertype_selector)) {
+               g_signal_connect (priv->incoming_servertype_selector,
+                                 "changed",
+                                 G_CALLBACK (on_servertype_combo_changed), self);
+       } else {
+#ifdef HILDON_PICKER_BUTTON
+               g_signal_connect (G_OBJECT (hildon_picker_button_get_selector (HILDON_PICKER_BUTTON (priv->incoming_servertype_selector))),
+                                 "changed",
+                                 G_CALLBACK (on_servertype_selector_changed), self);
+#endif
+       }
 
        align = gtk_alignment_new (0.0, 0.0, 1.0, 1.0);
        gtk_alignment_set_padding (GTK_ALIGNMENT (align), 0, 0, MODEST_MARGIN_DOUBLE, 0);
@@ -1341,10 +1381,12 @@ fill_providers (ModestEasysetupWizardDialog *self)
                                          "changed",
                                          G_CALLBACK (on_account_serviceprovider_selector_combo_box_changed), self);
                } else {
+#ifdef HILDON_PICKER_BUTTON
                        g_signal_connect (G_OBJECT (hildon_picker_button_get_selector
                                                    (HILDON_PICKER_BUTTON (priv->account_serviceprovider_selector))),
                                          "changed",
                                          G_CALLBACK (on_account_serviceprovider_selector_changed), self);
+#endif
                }
                modest_provider_selector_set_others_provider (priv->account_serviceprovider_selector);
        }
@@ -1450,7 +1492,7 @@ static void
 init_incoming_page (ModestEasysetupWizardDialogPrivate *priv)
 {
        priv->page_custom_incoming = NULL;
-       priv->incoming_servertype_picker = NULL;
+       priv->incoming_servertype_selector = NULL;
        priv->caption_incoming = NULL;
        priv->entry_incomingserver = NULL;
        priv->entry_user_email = NULL;
@@ -1876,8 +1918,8 @@ set_default_custom_servernames (ModestEasysetupWizardDialog *self)
         */
        if (priv->entry_user_email
            && ((priv->server_changes & MODEST_EASYSETUP_WIZARD_DIALOG_INCOMING_CHANGED) == 0)) {
-               const ModestProtocolType protocol_type = modest_servertype_picker_get_active_servertype (
-                       MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
+               const ModestProtocolType protocol_type = modest_servertype_selector_get_active_servertype (
+                       priv->incoming_servertype_selector);
 
                /* This could happen when the combo box has still no active iter */
                if (protocol_type != MODEST_PROTOCOL_REGISTRY_TYPE_INVALID) {
@@ -2348,8 +2390,8 @@ save_to_settings (ModestEasysetupWizardDialog *self)
        } else {
                /* Use custom pages because no preset was specified: */
                store_hostname = g_strdup (modest_entry_get_text (priv->entry_incomingserver ));
-               store_protocol = modest_servertype_picker_get_active_servertype (
-                       MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
+               store_protocol = modest_servertype_selector_get_active_servertype (
+                       priv->incoming_servertype_selector);
 
                modest_security_options_view_save_settings (
                                    MODEST_SECURITY_OPTIONS_VIEW (priv->incoming_security),
@@ -2520,8 +2562,8 @@ check_for_supported_auth_methods (ModestEasysetupWizardDialog* self)
 
        priv = MODEST_EASYSETUP_WIZARD_DIALOG_GET_PRIVATE (self);
        registry = modest_runtime_get_protocol_registry ();
-       protocol_type = modest_servertype_picker_get_active_servertype (
-               MODEST_SERVERTYPE_PICKER (priv->incoming_servertype_picker));
+       protocol_type = modest_servertype_selector_get_active_servertype (
+               priv->incoming_servertype_selector);
        hostname = gtk_entry_get_text(GTK_ENTRY(priv->entry_incomingserver));
        username = gtk_entry_get_text(GTK_ENTRY(priv->entry_user_username));
        security_protocol_incoming_type = modest_security_options_view_get_connection_protocol
index e0004c1..8a8986f 100644 (file)
@@ -115,6 +115,8 @@ libmodest_widgets_la_SOURCES=          \
        modest-security-options-view.c  \
        modest-serversecurity-combo-box.h \
        modest-serversecurity-combo-box.c \
+       modest-servertype-combo-box.h \
+       modest-servertype-combo-box.c \
        modest-secureauth-combo-box.h \
        modest-secureauth-combo-box.c \
        modest-sort-criterium-view.c   \
diff --git a/src/widgets/modest-servertype-combo-box.c b/src/widgets/modest-servertype-combo-box.c
new file mode 100644 (file)
index 0000000..aa9a246
--- /dev/null
@@ -0,0 +1,276 @@
+/* Copyright (c) 2006, 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-runtime.h>
+#include "modest-servertype-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 (ModestServertypeComboBox, modest_servertype_combo_box, GTK_TYPE_COMBO_BOX);
+
+#define MODEST_SERVERTYPE_COMBO_BOX_GET_PRIVATE(o) \
+       (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_SERVERTYPE_COMBO_BOX, ModestServertypeComboBoxPrivate))
+
+typedef struct _ModestServertypeComboBoxPrivate ModestServertypeComboBoxPrivate;
+
+struct _ModestServertypeComboBoxPrivate
+{
+       GtkTreeModel *model;
+};
+
+static void
+modest_servertype_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_servertype_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_servertype_combo_box_dispose (GObject *object)
+{
+       if (G_OBJECT_CLASS (modest_servertype_combo_box_parent_class)->dispose)
+               G_OBJECT_CLASS (modest_servertype_combo_box_parent_class)->dispose (object);
+}
+
+static void
+modest_servertype_combo_box_finalize (GObject *object)
+{
+       ModestServertypeComboBoxPrivate *priv = MODEST_SERVERTYPE_COMBO_BOX_GET_PRIVATE (object);
+
+       g_object_unref (G_OBJECT (priv->model));
+
+       G_OBJECT_CLASS (modest_servertype_combo_box_parent_class)->finalize (object);
+}
+
+static void
+modest_servertype_combo_box_class_init (ModestServertypeComboBoxClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       g_type_class_add_private (klass, sizeof (ModestServertypeComboBoxPrivate));
+
+       object_class->get_property = modest_servertype_combo_box_get_property;
+       object_class->set_property = modest_servertype_combo_box_set_property;
+       object_class->dispose = modest_servertype_combo_box_dispose;
+       object_class->finalize = modest_servertype_combo_box_finalize;
+}
+
+enum MODEL_COLS {
+       MODEL_COL_NAME = 0, /* a string */
+       MODEL_COL_ID = 1 /* an int. */
+};
+
+static void
+modest_servertype_combo_box_init (ModestServertypeComboBox *self)
+{
+       ModestServertypeComboBoxPrivate *priv = MODEST_SERVERTYPE_COMBO_BOX_GET_PRIVATE (self);
+
+       /* Create a tree model for the combo box,
+        * 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));
+
+       /* Setup the combo box: */
+       GtkComboBox *combobox = GTK_COMBO_BOX (self);
+       gtk_combo_box_set_model (combobox, priv->model);
+
+       /* Servertype 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);
+}
+
+static void 
+modest_servertype_combo_box_fill (ModestServertypeComboBox *combobox,
+                                    gboolean filter_providers)
+{      
+       ModestServertypeComboBoxPrivate *priv;
+       GtkListStore *liststore;
+       ModestProtocolRegistry *protocol_registry;
+       GSList *remote_protocols, *node;
+       GtkTreeIter iter;
+       
+       /* Remove any existing rows: */
+       priv = MODEST_SERVERTYPE_COMBO_BOX_GET_PRIVATE (combobox);
+       protocol_registry = modest_runtime_get_protocol_registry ();
+       remote_protocols = modest_protocol_registry_get_by_tag (protocol_registry, MODEST_PROTOCOL_REGISTRY_REMOTE_STORE_PROTOCOLS);
+
+       liststore = GTK_LIST_STORE (priv->model);
+       gtk_list_store_clear (liststore);
+
+       for (node = remote_protocols; node != NULL; node = g_slist_next (node)) {
+               ModestProtocol* protocol;
+               gboolean add = TRUE;
+
+               protocol = (ModestProtocol *) node->data;
+
+               /* Do not include the protocols that would be listed
+                  in the providers combo */
+               if (filter_providers)
+                       if (modest_protocol_registry_protocol_type_is_provider (protocol_registry,
+                                                                               modest_protocol_get_type_id (protocol))) {
+                               add = FALSE;
+                       }
+               
+               if (add) {
+                       gtk_list_store_append (liststore, &iter);
+                       gtk_list_store_set (liststore, &iter, 
+                                           MODEL_COL_ID, 
+                                           modest_protocol_get_type_id (protocol),
+                                           MODEL_COL_NAME, 
+                                           modest_protocol_get_display_name (protocol),
+                                           -1);
+               }
+       }
+       
+       g_slist_free (remote_protocols);
+}
+
+ModestServertypeComboBox*
+modest_servertype_combo_box_new (gboolean filter_providers)
+{
+       ModestServertypeComboBox *combo;
+
+       combo = g_object_new (MODEST_TYPE_SERVERTYPE_COMBO_BOX, NULL);
+
+       /* Fill the combo */    
+       modest_servertype_combo_box_fill (combo, filter_providers);
+
+       return combo;
+}
+
+/**
+ * Returns the selected servertype, 
+ * or MODEST_PROTOCOL_REGISTRY_TYPE_INVALID if no servertype was selected.
+ */
+ModestProtocolType
+modest_servertype_combo_box_get_active_servertype (ModestServertypeComboBox *combobox)
+{
+       GtkTreeIter active;
+       gboolean found;
+
+       found = gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combobox), &active);
+       if (found) {
+               ModestServertypeComboBoxPrivate *priv;
+               ModestProtocolType servertype;
+
+               priv = MODEST_SERVERTYPE_COMBO_BOX_GET_PRIVATE (combobox);
+
+               servertype = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
+               gtk_tree_model_get (priv->model, &active, MODEL_COL_ID, &servertype, -1);
+               return servertype;      
+       }
+
+       return MODEST_PROTOCOL_REGISTRY_TYPE_INVALID; /* Failed. */
+}
+
+/* This allows us to pass more than one piece of data to the signal handler,
+ * and get a result: */
+typedef struct 
+{
+               ModestServertypeComboBox* self;
+               ModestProtocolType id;
+               gboolean found;
+} ForEachData;
+
+static gboolean
+on_model_foreach_select_id(GtkTreeModel *model, 
+       GtkTreePath *path, GtkTreeIter *iter, gpointer user_data)
+{
+       ModestProtocolType id = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
+       ForEachData *state = (ForEachData*)(user_data);
+       
+       /* Select the item if it has the matching ID: */
+       gtk_tree_model_get (model, iter, MODEL_COL_ID, &id, -1); 
+       if(id == state->id) {
+               gtk_combo_box_set_active_iter (GTK_COMBO_BOX (state->self), iter);
+               
+               state->found = TRUE;
+               return TRUE; /* Stop walking the tree. */
+       }
+       
+       return FALSE; /* Keep walking the tree. */
+}
+
+/**
+ * Selects the specified servertype, 
+ * or MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN if no servertype was selected.
+ */
+gboolean
+modest_servertype_combo_box_set_active_servertype (ModestServertypeComboBox *combobox, ModestProtocolType servertype)
+{
+       ModestServertypeComboBoxPrivate *priv;
+       ForEachData *state;
+       gboolean result;
+       
+       priv = MODEST_SERVERTYPE_COMBO_BOX_GET_PRIVATE (combobox);
+
+       /* Create a state instance so we can send two items of data to the signal handler: */
+       state = g_new0 (ForEachData, 1);
+       state->self = combobox;
+       state->id = servertype;
+       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);
+
+       result = state->found;
+       
+       /* Free the state instance: */
+       g_free(state);
+       
+       return result;
+}
+
diff --git a/src/widgets/modest-servertype-combo-box.h b/src/widgets/modest-servertype-combo-box.h
new file mode 100644 (file)
index 0000000..ee482e0
--- /dev/null
@@ -0,0 +1,79 @@
+/* Copyright (c) 2006, 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_SERVERTYPE_COMBO_BOX
+#define _MODEST_SERVERTYPE_COMBO_BOX
+
+#include <gtk/gtkcombobox.h>
+#include "modest-protocol-registry.h"
+
+G_BEGIN_DECLS
+
+#define MODEST_TYPE_SERVERTYPE_COMBO_BOX modest_servertype_combo_box_get_type()
+
+#define MODEST_SERVERTYPE_COMBO_BOX(obj) \
+       (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
+       MODEST_TYPE_SERVERTYPE_COMBO_BOX, ModestServertypeComboBox))
+
+#define MODEST_SERVERTYPE_COMBO_BOX_CLASS(klass) \
+       (G_TYPE_CHECK_CLASS_CAST ((klass), \
+       MODEST_TYPE_SERVERTYPE_COMBO_BOX, ModestServertypeComboBoxClass))
+
+#define MODEST_IS_SERVERTYPE_COMBO_BOX(obj) \
+       (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
+       MODEST_TYPE_SERVERTYPE_COMBO_BOX))
+
+#define MODEST_IS_SERVERTYPE_COMBO_BOX_CLASS(klass) \
+       (G_TYPE_CHECK_CLASS_TYPE ((klass), \
+       MODEST_TYPE_SERVERTYPE_COMBO_BOX))
+
+#define MODEST_SERVERTYPE_COMBO_BOX_GET_CLASS(obj) \
+       (G_TYPE_INSTANCE_GET_CLASS ((obj), \
+       MODEST_TYPE_SERVERTYPE_COMBO_BOX, ModestServertypeComboBoxClass))
+
+typedef struct {
+       GtkComboBox parent;
+} ModestServertypeComboBox;
+
+typedef struct {
+       GtkComboBoxClass parent_class;
+} ModestServertypeComboBoxClass;
+
+GType modest_servertype_combo_box_get_type (void);
+
+ModestServertypeComboBox* modest_servertype_combo_box_new (gboolean filter_providers);
+
+ModestProtocolType modest_servertype_combo_box_get_active_servertype (ModestServertypeComboBox *combobox);
+
+gboolean modest_servertype_combo_box_set_active_servertype (ModestServertypeComboBox *combobox, ModestProtocolType servertype);
+
+
+G_END_DECLS
+
+#endif /* _MODEST_SERVERTYPE_COMBO_BOX */
index f4eef10..0263507 100644 (file)
@@ -44,7 +44,6 @@
 #define USE_GTK_ENTRY
 #define USE_GTK_FILE_CHOOSER
 #define USE_COUNTRY_COMBOBOX
-#define USE_PROVIDER_COMBOBOX
 #endif
 
 #ifdef USE_SCROLLED_WINDOW
 #include <modest-provider-picker.h>
 #endif
 
+#ifdef USE_SERVERTYPE_COMBOBOX
+#include <modest-servertype-combo-box.h>
+#else
+#include <modest-servertype-picker.h>
+#endif
+
 static void modest_toolkit_factory_class_init (ModestToolkitFactoryClass *klass);
 static void modest_toolkit_factory_init (ModestToolkitFactory *self);
 
@@ -91,7 +96,9 @@ static GtkWidget * modest_toolkit_factory_create_file_chooser_dialog_default  (M
                                                                               GtkWindow *parent,
                                                                               GtkFileChooserAction action);
 static GtkWidget * modest_toolkit_factory_create_country_selector_default     (ModestToolkitFactory *self);
-static GtkWidget * modest_toolkit_factory_create_provider_selector_default     (ModestToolkitFactory *self);
+static GtkWidget * modest_toolkit_factory_create_provider_selector_default    (ModestToolkitFactory *self);
+static GtkWidget * modest_toolkit_factory_create_servertype_selector_default  (ModestToolkitFactory *self,
+                                                                              gboolean filter_providers);
 /* globals */
 static GObjectClass *parent_class = NULL;
 
@@ -121,6 +128,7 @@ modest_toolkit_factory_class_init (ModestToolkitFactoryClass *klass)
        klass->create_file_chooser_dialog = modest_toolkit_factory_create_file_chooser_dialog_default;
        klass->create_country_selector = modest_toolkit_factory_create_country_selector_default;
        klass->create_provider_selector = modest_toolkit_factory_create_provider_selector_default;
+       klass->create_servertype_selector = modest_toolkit_factory_create_servertype_selector_default;
 }
 
 static void
@@ -547,3 +555,44 @@ modest_provider_selector_set_others_provider (GtkWidget *self)
        modest_provider_picker_set_others_provider (MODEST_PROVIDER_PICKER (self));
 #endif
 }
+
+GtkWidget *
+modest_toolkit_factory_create_servertype_selector (ModestToolkitFactory *self, gboolean filter_providers)
+{
+       return MODEST_TOOLKIT_FACTORY_GET_CLASS (self)->create_servertype_selector (self, filter_providers);
+}
+
+static GtkWidget *
+modest_toolkit_factory_create_servertype_selector_default (ModestToolkitFactory *self, gboolean filter_providers)
+{
+       GtkWidget *result;
+#ifdef USE_PROVIDER_COMBOBOX
+       result = GTK_WIDGET (modest_servertype_combo_box_new (filter_providers));
+#else
+       result = GTK_WIDGET (modest_servertype_picker_new (MODEST_EDITABLE_SIZE, 
+                                                        HILDON_BUTTON_ARRANGEMENT_HORIZONTAL,
+                                                        filter_providers));
+#endif
+       return result;
+}
+
+ModestProtocolType
+modest_servertype_selector_get_active_servertype (GtkWidget *self)
+{
+#ifdef USE_SERVERTYPE_COMBOBOX
+       return modest_servertype_combo_box_get_active_servertype (MODEST_SERVERTYPE_COMBO_BOX (self));
+#else
+       return modest_servertype_picker_get_active_servertype (MODEST_SERVERTYPE_PICKER (self));
+#endif
+}
+
+void
+modest_servertype_selector_set_active_servertype (GtkWidget *self,
+                                                 ModestProtocolType protocol_type_id)
+{
+#ifdef USE_SERVERTYPE_COMBOBOX
+       modest_servertype_combo_box_set_active_servertype (MODEST_SERVERTYPE_COMBO_BOX (self), protocol_type_id);
+#else
+       modest_servertype_picker_set_active_servertype (MODEST_SERVERTYPE_PICKER (self), protocol_type_id);
+#endif
+}
index a3e04f4..ef1a788 100644 (file)
@@ -46,6 +46,7 @@ struct                                          _ModestToolkitFactoryClass
                                                   GtkWindow *parent, GtkFileChooserAction action);
        GtkWidget * (*create_country_selector) (ModestToolkitFactory *self);
        GtkWidget * (*create_provider_selector) (ModestToolkitFactory *self);
+       GtkWidget * (*create_servertype_selector) (ModestToolkitFactory *self, gboolean filter_providers);
 };
 
 struct                                          _ModestToolkitFactory
@@ -88,6 +89,9 @@ modest_toolkit_factory_create_country_selector (ModestToolkitFactory *self);
 GtkWidget *
 modest_toolkit_factory_create_provider_selector (ModestToolkitFactory *self);
 
+GtkWidget *
+modest_toolkit_factory_create_servertype_selector (ModestToolkitFactory *self, gboolean filter_providers);
+
 gboolean
 modest_togglable_get_active (GtkWidget *widget);
 
@@ -152,15 +156,28 @@ modest_provider_selector_get_active_id_type (GtkWidget *widget);
 void
 modest_provider_selector_set_others_provider (GtkWidget *self);
 
+ModestProtocolType
+modest_servertype_selector_get_active_servertype (GtkWidget *self);
+
+void
+modest_servertype_selector_set_active_servertype (GtkWidget *self, ModestProtocolType protocol_type_id);
 
 #ifndef MODEST_TOOLKIT_HILDON2
-#define USE_GTK_SPIN_BUTTON
+#define USE_PROVIDER_COMBOBOX
+#define USE_SERVERTYPE_COMBOBOX
 #endif
 
 #ifndef USE_GTK_SPIN_BUTTON
 #define MODEST_NUMBER_ENTRY_SUPPORT_VALID_CHANGED
 #endif
 
+#ifndef USE_PROVIDER_COMBOBOX
+#include <hildon/hildon.h>
+#endif
+#ifndef USE_SERVERTYPE_COMBOBOX
+#include <hildon/hildon.h>
+#endif
+
 G_END_DECLS
 
 #endif /* __MODEST_WP_TEXT_VIEW_H__ */