Revert "On creating forward, don't include purged parts (fixes NB#124831)."
[modest] / src / gnome / modest-store-widget.c
index 27918d2..7a0a0d1 100644 (file)
@@ -31,6 +31,7 @@
 #include <gtk/gtk.h>
 #include <widgets/modest-combo-box.h>
 #include "modest-store-widget.h"
+#include "modest-runtime.h"
 #include <string.h>
 
 /* 'private'/'protected' functions */
@@ -48,11 +49,16 @@ struct _ModestStoreWidgetPrivate {
        
        GtkWidget *servername;
        GtkWidget *username;
+       
+       ModestPairList *security_protos;
        GtkWidget *security;
+       
+       ModestPairList *auth_protos;
        GtkWidget *auth;
+       
        GtkWidget *chooser;
 
-       ModestTransportStoreProtocol proto;
+       ModestProtocolType proto;
 };
 #define MODEST_STORE_WIDGET_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                                  MODEST_TYPE_STORE_WIDGET, \
@@ -115,7 +121,7 @@ modest_store_widget_init (ModestStoreWidget *obj)
        ModestStoreWidgetPrivate *priv;
        
        priv = MODEST_STORE_WIDGET_GET_PRIVATE(obj); 
-       priv->proto = MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN;
+       priv->proto = MODEST_PROTOCOL_REGISTRY_TYPE_INVALID;
 }
 
 
@@ -195,7 +201,6 @@ on_entry_changed (GtkEntry *entry, gpointer user_data)
 static GtkWidget*
 imap_pop_configuration (ModestStoreWidget *self)
 {
-       ModestPairList *protos;
        ModestStoreWidgetPrivate *priv;
        GtkWidget *label, *box, *hbox;
        
@@ -226,9 +231,12 @@ imap_pop_configuration (ModestStoreWidget *self)
        gtk_label_set_markup (GTK_LABEL(label),_("<b>Security</b>"));
        gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 0);
 
-       protos = modest_protocol_info_get_connection_protocol_pair_list ();
-       priv->security = modest_combo_box_new (protos, g_str_equal);
-       modest_pair_list_free (protos);
+       /* Note: This ModestPairList* must exist for as long as the combo
+        * that uses it, because the ModestComboBox uses the ID opaquely, 
+        * so it can't know how to manage its memory. */ 
+       priv->security_protos = modest_protocol_info_get_connection_protocol_pair_list ();
+
+       priv->security = modest_combo_box_new (priv->security_protos, g_str_equal);
        
        hbox = gtk_hbox_new (FALSE, 6);
        label = gtk_label_new(NULL);
@@ -243,9 +251,11 @@ imap_pop_configuration (ModestStoreWidget *self)
        gtk_label_set_text (GTK_LABEL(label),_("Authentication:"));
        gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 6);
        
-       protos = modest_protocol_info_get_auth_protocol_pair_list (;
-       priv->auth =  modest_combo_box_new (protos, g_str_equal);
-       modest_pair_list_free (protos);
+       /* Note: This ModestPairList* must exist for as long as the combo
+        * that uses it, because the ModestComboBox uses the ID opaquely, 
+        * so it can't know how to manage its memory. */ 
+       priv->auth_protos = modest_protocol_info_get_auth_protocol_pair_list ();
+       priv->auth =  modest_combo_box_new (priv->auth_protos, g_str_equal);
 
        gtk_box_pack_start (GTK_BOX(hbox), priv->auth, FALSE, FALSE, 0);
        
@@ -262,13 +272,19 @@ imap_pop_configuration (ModestStoreWidget *self)
 static void
 modest_store_widget_finalize (GObject *obj)
 {
+       ModestStoreWidgetPrivate *priv = MODEST_STORE_WIDGET_GET_PRIVATE(obj);
+       
+       /* These had to stay alive for as long as the comboboxes that used them: */
+       modest_pair_list_free (priv->security_protos);
+       modest_pair_list_free (priv->auth_protos);
+       
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
 
 
 
 GtkWidget*
-modest_store_widget_new (ModestTransportStoreProtocol proto)
+modest_store_widget_new (ModestProtocolType proto)
 {
        GObject *obj;
        GtkWidget *w;
@@ -283,11 +299,11 @@ modest_store_widget_new (ModestTransportStoreProtocol proto)
 
        priv->proto = proto;
        
-       if (proto == MODEST_PROTOCOL_STORE_POP || proto == MODEST_PROTOCOL_STORE_IMAP)
+       if (proto == MODEST_PROTOCOLS_STORE_POP || proto == MODEST_PROTOCOLS_STORE_IMAP)
                w = imap_pop_configuration (self);
-       else if (proto == MODEST_PROTOCOL_STORE_MAILDIR) 
+       else if (proto == MODEST_PROTOCOLS_STORE_MAILDIR) 
                w = maildir_configuration (self);
-       else if (proto == MODEST_PROTOCOL_STORE_MBOX)
+       else if (proto == MODEST_PROTOCOLS_STORE_MBOX)
                w = mbox_configuration (self);
        else
                w = gtk_label_new ("");
@@ -327,12 +343,12 @@ modest_store_widget_get_servername (ModestStoreWidget *self)
 }
 
 
-ModestTransportStoreProtocol
+ModestProtocolType
 modest_store_widget_get_proto (ModestStoreWidget *self)
 {
        ModestStoreWidgetPrivate *priv;
 
-       g_return_val_if_fail (self, MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN);
+       g_return_val_if_fail (self, MODEST_PROTOCOL_REGISTRY_TYPE_INVALID);
        priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
 
        return priv->proto;
@@ -353,37 +369,42 @@ modest_store_widget_get_path (ModestStoreWidget *self)
                return NULL;
 }
 
-static gint
+static ModestProtocolType
 get_value_from_combo (GtkWidget *combo)
 {
        gchar *chosen;
+       ModestProtocol *proto;
+       const gchar *tag;
 
-       if (!combo)
-               return -1;
+       g_return_val_if_fail (combo, MODEST_PROTOCOL_REGISTRY_TYPE_INVALID);
 
        chosen = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo));
+       tag = MODEST_PROTOCOL_REGISTRY_TRANSPORT_STORE_PROTOCOLS;
+       proto = modest_protocol_registry_get_protocol_by_name (modest_runtime_get_protocol_registry (),
+                                                              tag,
+                                                              chosen);
 
-       return modest_protocol_info_get_transport_store_protocol (chosen);
+       return modest_protocol_get_type_id (proto);
 
 }
 
-ModestAuthProtocol
+ModestProtocolType
 modest_store_widget_get_auth (ModestStoreWidget *self)
 {
        ModestStoreWidgetPrivate *priv; 
 
-       g_return_val_if_fail (self, MODEST_PROTOCOL_AUTH_NONE);
+       g_return_val_if_fail (self, MODEST_PROTOCOLS_AUTH_NONE);
        priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
 
        return get_value_from_combo (priv->auth);
 }
 
-ModestConnectionProtocol
+ModestProtocolType
 modest_store_widget_get_security (ModestStoreWidget *self)
 {
        ModestStoreWidgetPrivate *priv; 
 
-       g_return_val_if_fail (self, MODEST_PROTOCOL_CONNECTION_NORMAL);
+       g_return_val_if_fail (self, MODEST_PROTOCOLS_CONNECTION_NONE);
        priv = MODEST_STORE_WIDGET_GET_PRIVATE(self);
 
        return get_value_from_combo (priv->security);