Changeset 1485

Show
Ignore:
Timestamp:
01/27/07 17:57:13
Author:
pvanhoof
Message:

Changed some things about connecting

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r1484 r1485  
    99        * First LEMONADE feature, implemented support for the CONDSTORE  
    1010        capability in camel-lite's IMAP provider (RFC 4551) 
     11        * Changed some things about connecting, including the introduction of 
     12        a new api tny_account_try_connect. All this connecting stuff is yet 
     13        uncertain though. 
     14 
     15        * This was a major API change 
    1116 
    12172007-01-26  Philip Van Hoof  <pvanhoof@gnome.org> 
  • trunk/libtinymail-camel/camel-lite/camel/providers/imap/camel-imap-folder.c

    r1483 r1485  
    23452345        int retry; 
    23462346 
    2347         /* TNY TODO: Implement partial message retrieval if full==TRUE */ 
    2348  
    23492347        mi = (CamelImapMessageInfo *)camel_folder_summary_uid (folder->summary, uid); 
    23502348        if (mi == NULL) { 
     
    23582356        if ( (stream = camel_imap_folder_fetch_data (imap_folder, uid, "", TRUE, type, param, NULL)) 
    23592357             && (msg = get_message_simple(imap_folder, uid, stream, type, param, ex))) 
     2358                goto done; 
     2359 
     2360 
     2361        if (camel_disco_store_status (CAMEL_DISCO_STORE (folder->parent_store)) == CAMEL_DISCO_STORE_OFFLINE) 
    23602362                goto done; 
    23612363 
     
    24462448                 && camel_exception_get_id(ex) == CAMEL_EXCEPTION_SERVICE_UNAVAILABLE); 
    24472449 
    2448 done:   /* FIXME, this shouldn't be done this way. */ 
    2449         if (msg) 
    2450                 camel_medium_set_header (CAMEL_MEDIUM (msg), "X-Evolution-Source", store->base_url); 
     2450done: 
     2451 
    24512452fail: 
    24522453        camel_message_info_free(&mi->info); 
  • trunk/libtinymail-camel/tny-camel-account-priv.h

    r1478 r1485  
    4040        gboolean connected, inuse_spin; 
    4141        gchar *name; GList *options; 
    42         gchar *cache_location; 
     42        gchar *cache_location; gint port; 
    4343        TnyAccountType account_type; 
    4444}; 
  • trunk/libtinymail-camel/tny-camel-account.c

    r1483 r1485  
    8989        priv->options = g_list_prepend (priv->options, g_strdup (option)); 
    9090 
    91         TNY_CAMEL_ACCOUNT_GET_CLASS (self)->reconnect_func (TNY_CAMEL_ACCOUNT (self)); 
     91        TNY_CAMEL_ACCOUNT_GET_CLASS (self)->prepare_func (self); 
     92 
     93        return; 
     94
     95 
     96static void 
     97tny_camel_account_try_connect (TnyAccount *self, GError **err) 
     98
     99        TNY_CAMEL_ACCOUNT_GET_CLASS (self)->try_connect_func (self, err); 
     100
     101 
     102static void 
     103tny_camel_account_try_connect_default (TnyAccount *self, GError **err) 
     104
     105        TNY_CAMEL_ACCOUNT_GET_CLASS (self)->prepare_func (TNY_CAMEL_ACCOUNT (self)); 
    92106 
    93107        return; 
     
    111125        priv->url_string = g_strdup (url_string); 
    112126 
    113         if (G_UNLIKELY (!TNY_CAMEL_ACCOUNT_GET_CLASS (self)->reconnect_func)) 
    114                 g_error ("This TnyAccount instance isn't a fully implemented type\n"); 
    115  
    116         TNY_CAMEL_ACCOUNT_GET_CLASS (self)->reconnect_func ((TnyCamelAccount*)self); 
     127        TNY_CAMEL_ACCOUNT_GET_CLASS (self)->prepare_func (TNY_CAMEL_ACCOUNT (self)); 
    117128 
    118129        return; 
     
    279290        g_static_rec_mutex_lock (priv->service_lock); 
    280291        priv->session = session; 
    281         TNY_CAMEL_ACCOUNT_GET_CLASS (self)->reconnect_func (self); 
    282292        _tny_session_camel_add_account (session, self); 
     293 
     294        TNY_CAMEL_ACCOUNT_GET_CLASS (self)->prepare_func (self); 
     295 
    283296        g_static_rec_mutex_unlock (priv->service_lock); 
    284297 
     
    323336        priv->mech = g_strdup (mech); 
    324337 
    325         TNY_CAMEL_ACCOUNT_GET_CLASS (self)->reconnect_func (TNY_CAMEL_ACCOUNT (self)); 
    326          
     338        TNY_CAMEL_ACCOUNT_GET_CLASS (self)->prepare_func (TNY_CAMEL_ACCOUNT (self)); 
     339 
    327340        g_static_rec_mutex_unlock (priv->service_lock); 
    328341 
     
    348361        priv->proto = g_strdup (proto); 
    349362 
    350         TNY_CAMEL_ACCOUNT_GET_CLASS (self)->reconnect_func (TNY_CAMEL_ACCOUNT (self)); 
    351          
     363        TNY_CAMEL_ACCOUNT_GET_CLASS (self)->prepare_func (TNY_CAMEL_ACCOUNT (self)); 
     364 
    352365        g_static_rec_mutex_unlock (priv->service_lock); 
    353366 
     
    373386        priv->user = g_strdup (user); 
    374387 
    375         TNY_CAMEL_ACCOUNT_GET_CLASS (self)->reconnect_func (TNY_CAMEL_ACCOUNT (self)); 
     388        TNY_CAMEL_ACCOUNT_GET_CLASS (self)->prepare_func (TNY_CAMEL_ACCOUNT (self)); 
    376389 
    377390        g_static_rec_mutex_unlock (priv->service_lock); 
     
    398411        priv->host = g_strdup (host); 
    399412 
    400         TNY_CAMEL_ACCOUNT_GET_CLASS (self)->reconnect_func (TNY_CAMEL_ACCOUNT (self)); 
     413        TNY_CAMEL_ACCOUNT_GET_CLASS (self)->prepare_func (TNY_CAMEL_ACCOUNT (self)); 
    401414 
    402415        g_static_rec_mutex_unlock (priv->service_lock); 
     
    404417        return; 
    405418} 
     419 
     420 
     421 
     422static void 
     423tny_camel_account_set_port (TnyAccount *self, guint port) 
     424{ 
     425        TNY_CAMEL_ACCOUNT_GET_CLASS (self)->set_port_func (self, port); 
     426} 
     427 
     428static void 
     429tny_camel_account_set_port_default (TnyAccount *self, guint port) 
     430{ 
     431        TnyCamelAccountPriv *priv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self); 
     432         
     433        g_static_rec_mutex_lock (priv->service_lock); 
     434 
     435        priv->port = (gint) port; 
     436 
     437        TNY_CAMEL_ACCOUNT_GET_CLASS (self)->prepare_func (TNY_CAMEL_ACCOUNT (self)); 
     438 
     439        g_static_rec_mutex_unlock (priv->service_lock); 
     440 
     441        return; 
     442} 
     443 
    406444 
    407445static void 
     
    422460        priv->pass_func_set = TRUE; 
    423461 
    424         if (G_UNLIKELY (!TNY_CAMEL_ACCOUNT_GET_CLASS (self)->reconnect_func)) 
    425                 g_error ("This TnyAccount instance isn't a fully implemented type\n"); 
    426  
    427         TNY_CAMEL_ACCOUNT_GET_CLASS (self)->reconnect_func ((TnyCamelAccount*)self); 
     462        TNY_CAMEL_ACCOUNT_GET_CLASS (self)->prepare_func (TNY_CAMEL_ACCOUNT (self)); 
    428463 
    429464        g_static_rec_mutex_unlock (priv->service_lock); 
     
    449484        priv->forget_pass_func_set = TRUE; 
    450485 
     486        TNY_CAMEL_ACCOUNT_GET_CLASS (self)->prepare_func (TNY_CAMEL_ACCOUNT (self)); 
     487 
    451488        g_static_rec_mutex_unlock (priv->service_lock); 
    452489 
     
    531568tny_camel_account_get_hostname_default (TnyAccount *self) 
    532569{ 
    533         TnyCamelAccountPriv *priv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self);       
     570        TnyCamelAccountPriv *priv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self); 
    534571        const gchar *retval; 
    535572 
     
    537574 
    538575        return retval; 
     576} 
     577 
     578 
     579 
     580static guint  
     581tny_camel_account_get_port (TnyAccount *self) 
     582{ 
     583        return TNY_CAMEL_ACCOUNT_GET_CLASS (self)->get_port_func (self); 
     584} 
     585 
     586static guint  
     587tny_camel_account_get_port_default (TnyAccount *self) 
     588{ 
     589        TnyCamelAccountPriv *priv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self); 
     590        return (guint)priv->port; 
    539591} 
    540592 
     
    602654        TnyCamelAccountPriv *priv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self); 
    603655 
     656        priv->port = -1; 
    604657        priv->cache_location = NULL; 
    605658        priv->service = NULL; 
     
    767820        TnyAccountIface *klass = (TnyAccountIface *)g; 
    768821 
     822        klass->try_connect_func = tny_camel_account_try_connect; 
     823        klass->get_port_func = tny_camel_account_get_port; 
     824        klass->set_port_func = tny_camel_account_set_port; 
    769825        klass->get_hostname_func = tny_camel_account_get_hostname; 
    770826        klass->set_hostname_func = tny_camel_account_set_hostname; 
     
    799855        object_class = (GObjectClass*) class; 
    800856 
    801  
     857        class->try_connect_func = tny_camel_account_try_connect_default; 
     858        class->get_port_func = tny_camel_account_get_port_default; 
     859        class->set_port_func = tny_camel_account_set_port_default; 
    802860        class->get_hostname_func = tny_camel_account_get_hostname_default; 
    803861        class->set_hostname_func = tny_camel_account_set_hostname_default; 
  • trunk/libtinymail-camel/tny-camel-account.h

    r1478 r1485  
    4949        GObjectClass parent; 
    5050 
    51         /* This is an abstract method (it's not implemented by  
    52            TnyCamelAccount, it's also not virtual) */ 
    53  
    54         void (*reconnect_func) (TnyCamelAccount *self); 
    55  
    5651        /* Virtual methods */ 
    57  
    5852        gboolean (*is_connected_func)(TnyAccount *self); 
    5953        void (*set_id_func) (TnyAccount *self, const gchar *id); 
     
    6357        void (*set_user_func) (TnyAccount *self, const gchar *user); 
    6458        void (*set_hostname_func) (TnyAccount *self, const gchar *host); 
     59        void (*set_port_func) (TnyAccount *self, guint port); 
    6560        void (*set_url_string_func) (TnyAccount *self, const gchar *url_string); 
    6661        void (*set_pass_func_func) (TnyAccount *self, TnyGetPassFunc get_pass_func); 
     
    7469        const gchar* (*get_user_func) (TnyAccount *self); 
    7570        const gchar* (*get_hostname_func) (TnyAccount *self); 
     71        guint (*get_port_func) (TnyAccount *self); 
    7672        const gchar* (*get_url_string_func) (TnyAccount *self); 
    7773        TnyAccountType (*get_account_type_func) (TnyAccount *self); 
     74        void (*try_connect_func) (TnyAccount *self, GError **err); 
    7875 
    7976        void (*add_option_func) (TnyCamelAccount *self, const gchar *option); 
    8077        void (*set_online_status_func) (TnyCamelAccount *self, gboolean offline); 
    8178 
     79        /* Abstract methods */ 
     80        void (*prepare_func) (TnyCamelAccount *self); 
    8281}; 
    8382 
  • trunk/libtinymail-camel/tny-camel-store-account.c

    r1483 r1485  
    5454static GObjectClass *parent_class = NULL; 
    5555 
    56 static void 
    57 report_error (TnyCamelAccountPriv *priv) 
    58 
    59         if (G_UNLIKELY (priv->service == NULL)) 
    60         { 
    61                 g_error (_("Couldn't get service %s: %s\n"), priv->url_string, 
    62                            camel_exception_get_description (priv->ex)); 
    63                 camel_exception_clear (priv->ex); 
     56static void  
     57tny_camel_store_account_prepare (TnyCamelAccount *self) 
     58
     59        TnyCamelAccountPriv *apriv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self); 
     60 
     61        CamelURL *url = NULL; 
     62        GList *options = apriv->options; 
     63        gchar *proto; 
     64 
     65        if (apriv->proto == NULL) 
    6466                return; 
    65         } 
    66 
    67  
    68  
    69 static void  
    70 tny_camel_store_account_reconnect (TnyCamelAccount *self) 
    71 
    72         TnyCamelAccountPriv *apriv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self); 
    73  
    74         if (G_LIKELY (apriv->session) && G_UNLIKELY (apriv->proto) &&  
    75                 G_UNLIKELY (apriv->user) && G_UNLIKELY (apriv->host)) 
    76         { 
    77                 if (!apriv->url_string) 
    78                 { 
    79                         CamelURL *url = NULL; 
    80                         GList *options = apriv->options; 
    81                         gchar *proto = g_strdup_printf ("%s://", apriv->proto);  
    82                          
    83                         url = camel_url_new (proto, apriv->ex); 
    84                         g_free (proto); 
    85  
    86                         camel_url_set_protocol (url, apriv->proto);  
    87                         camel_url_set_user (url, apriv->user); 
    88                         camel_url_set_host (url, apriv->host); 
    89  
    90                         if (apriv->mech) 
    91                                 camel_url_set_authmech (url, apriv->mech); 
    92  
    93                         while (options) 
    94                         { 
    95                                 gchar *ptr, *dup = g_strdup (options->data); 
    96                                 gchar *option, *value; 
    97                                 ptr = strchr (dup, '='); 
    98                                 if (ptr) { 
    99                                         ptr++; 
    100                                         value = g_strdup (ptr); ptr--; 
    101                                         *ptr = '\0'; option = dup; 
    102                                 } else { 
    103                                         option = dup; 
    104                                         value = g_strdup ("1"); 
    105                                 } 
    106                                 camel_url_set_param (url, option, value); 
    107                                 g_free (value); 
    108                                 g_free (dup); 
    109                                 options = g_list_next (options); 
    110                         } 
    111  
    112                         if (G_LIKELY (apriv->url_string)) 
    113                                 g_free (apriv->url_string); 
    114  
    115                         apriv->url_string = camel_url_to_string (url, 0); 
    116                         camel_url_free (url); 
    117  
    118                         g_static_rec_mutex_lock (apriv->service_lock); 
    119                         apriv->service = camel_session_get_service 
    120                                 ((CamelSession*) apriv->session, apriv->url_string,  
    121                                 apriv->type, apriv->ex); 
    122                         if (apriv->service == NULL) 
    123                                 report_error (apriv); 
    124                         g_static_rec_mutex_unlock (apriv->service_lock); 
    125  
    126                         /* TODO: Handle priv->ex using GError */ 
     67 
     68        proto = g_strdup_printf ("%s://", apriv->proto);  
     69 
     70        url = camel_url_new (proto, apriv->ex); 
     71        g_free (proto); 
     72 
     73        if (!url) 
     74                return; 
     75 
     76        camel_url_set_protocol (url, apriv->proto);  
     77        camel_url_set_user (url, apriv->user); 
     78        camel_url_set_host (url, apriv->host); 
     79 
     80        if (apriv->port != -1) 
     81                camel_url_set_port (url, (int)apriv->port); 
     82 
     83        if (apriv->mech) 
     84                camel_url_set_authmech (url, apriv->mech); 
     85 
     86        while (options) 
     87        { 
     88                gchar *ptr, *dup = g_strdup (options->data); 
     89                gchar *option, *value; 
     90                ptr = strchr (dup, '='); 
     91                if (ptr) { 
     92                        ptr++; 
     93                        value = g_strdup (ptr); ptr--; 
     94                        *ptr = '\0'; option = dup; 
     95                } else { 
     96                        option = dup; 
     97                        value = g_strdup ("1"); 
    12798                } 
    128         } else if (G_LIKELY (apriv->session) && (apriv->url_string)) 
    129         { 
    130                 g_static_rec_mutex_lock (apriv->service_lock); 
    131                 /* camel_session_get_service can launch GUI things */ 
     99                camel_url_set_param (url, option, value); 
     100                g_free (value); 
     101                g_free (dup); 
     102                options = g_list_next (options); 
     103        } 
     104 
     105        if (G_LIKELY (apriv->url_string)) 
     106                g_free (apriv->url_string); 
     107 
     108        apriv->url_string = camel_url_to_string (url, 0); 
     109        camel_url_free (url); 
     110 
     111        /* TODO: check for old instance and clear it */ 
     112 
     113        g_static_rec_mutex_lock (apriv->service_lock); 
     114        if (apriv->session) 
    132115                apriv->service = camel_session_get_service 
    133116                        ((CamelSession*) apriv->session, apriv->url_string,  
    134117                        apriv->type, apriv->ex); 
    135                 if (apriv->service == NULL) 
    136                         report_error (apriv); 
    137                 g_static_rec_mutex_unlock (apriv->service_lock); 
    138                  
    139                 /* TODO: Handle priv->ex using GError */ 
    140         } 
    141  
    142         if ( G_LIKELY (apriv->service) && G_UNLIKELY (apriv->pass_func_set) 
    143                 && G_UNLIKELY (apriv->forget_pass_func_set) ) 
    144         { 
    145                 apriv->connected = FALSE; 
    146  
    147                 g_static_rec_mutex_lock (apriv->service_lock); 
    148                 /* camel_service_connect can launch GUI things */ 
    149                 if (!camel_service_connect (apriv->service, apriv->ex)) 
    150                 { 
    151                         /* TODO: Handle priv->ex using GError */ 
    152                         g_warning (_("Not connected with %s: %s\n"), apriv->url_string, 
    153                                    camel_exception_get_description (apriv->ex)); 
     118        g_static_rec_mutex_unlock (apriv->service_lock); 
     119
     120 
     121static void  
     122tny_camel_store_account_try_connect (TnyAccount *self, GError **err) 
     123
     124        TnyCamelAccountPriv *apriv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self); 
     125 
     126        if (!apriv->url_string || !apriv->service) 
     127        { 
     128                if (camel_exception_is_set (apriv->ex)) 
     129                { 
     130                        g_set_error (err, TNY_ACCOUNT_ERROR,  
     131                                TNY_ACCOUNT_ERROR_TRY_CONNECT, 
     132                                camel_exception_get_description (apriv->ex)); 
    154133                        camel_exception_clear (apriv->ex); 
    155134                } else { 
     135                        g_set_error (err, TNY_ACCOUNT_ERROR,  
     136                                TNY_ACCOUNT_ERROR_TRY_CONNECT, 
     137                                _("Account not yet fully configured")); 
     138                } 
     139 
     140                return; 
     141        } 
     142 
     143        if (apriv->pass_func_set && apriv->forget_pass_func_set) 
     144        { 
     145                CamelException ex = CAMEL_EXCEPTION_INITIALISER; 
     146                apriv->connected = FALSE; 
     147 
     148                if (camel_exception_is_set (apriv->ex)) 
     149                        camel_exception_clear (apriv->ex); 
     150 
     151                g_static_rec_mutex_lock (apriv->service_lock); 
     152 
     153                /* camel_service_connect can launch GUI things */ 
     154                if (!camel_service_connect (apriv->service, &ex)) 
     155                { 
     156                        if (camel_exception_is_set (&ex)) 
     157                        { 
     158                                g_set_error (err, TNY_ACCOUNT_ERROR,  
     159                                        TNY_ACCOUNT_ERROR_TRY_CONNECT, 
     160                                        camel_exception_get_description (&ex)); 
     161                                camel_exception_clear (&ex); 
     162                        } else { 
     163                                g_set_error (err, TNY_ACCOUNT_ERROR,  
     164                                        TNY_ACCOUNT_ERROR_TRY_CONNECT, 
     165                                        _("Unknown error while connecting")); 
     166                        } 
     167                } else { 
    156168                        apriv->connected = TRUE; 
     169                        /* tny_camel_account_set_online_status (self, !apriv->connected); */ 
    157170                } 
     171 
    158172                g_static_rec_mutex_unlock (apriv->service_lock); 
    159                  
    160                 /* TODO: Handle priv->ex using GError */ 
     173 
     174        } else { 
     175                        g_set_error (err, TNY_ACCOUNT_ERROR,  
     176                                TNY_ACCOUNT_ERROR_TRY_CONNECT, 
     177                                _("Get and Forget password functions not yet set")); 
    161178        } 
    162179 
     
    704721        object_class->finalize = tny_camel_store_account_finalize; 
    705722 
    706         ((TnyCamelAccountClass*)class)->reconnect_func = tny_camel_store_account_reconnect; 
     723        TNY_CAMEL_ACCOUNT_CLASS (class)->try_connect_func = tny_camel_store_account_try_connect; 
     724        TNY_CAMEL_ACCOUNT_CLASS (class)->prepare_func = tny_camel_store_account_prepare; 
    707725 
    708726        class->get_folders_async_func = tny_camel_store_account_get_folders_async_default; 
     
    710728        class->create_folder_func = tny_camel_store_account_create_folder_default; 
    711729        class->remove_folder_func = tny_camel_store_account_remove_folder_default; 
    712      
     730 
    713731        g_type_class_add_private (object_class, sizeof (TnyCamelStoreAccountPriv)); 
    714732 
     
    758776                  NULL          /* interface_data */ 
    759777                }; 
    760              
     778 
    761779                type = g_type_register_static (TNY_TYPE_CAMEL_ACCOUNT, 
    762780                        "TnyCamelStoreAccount", 
    763781                        &info, 0); 
    764782 
    765               g_type_add_interface_static (type, TNY_TYPE_FOLDER_STORE,  
     783              g_type_add_interface_static (type, TNY_TYPE_FOLDER_STORE,  
    766784                        &tny_folder_store_info);   
    767785 
    768786                g_type_add_interface_static (type, TNY_TYPE_STORE_ACCOUNT,  
    769787                        &tny_store_account_info); 
    770              
    771              
     788 
    772789        } 
    773790 
  • trunk/libtinymail-camel/tny-camel-transport-account.c

    r1480 r1485  
    5555 
    5656static void  
    57 tny_camel_transport_account_reconnect (TnyCamelAccount *self) 
     57tny_camel_transport_account_prepare (TnyCamelAccount *self) 
     58
     59        TnyCamelAccountPriv *apriv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self); 
     60 
     61        CamelURL *url = NULL; 
     62        GList *options = apriv->options; 
     63        gchar *proto; 
     64 
     65        if (apriv->proto == NULL) 
     66                return; 
     67 
     68        proto = g_strdup_printf ("%s://", apriv->proto);  
     69 
     70        url = camel_url_new (proto, apriv->ex); 
     71        g_free (proto); 
     72 
     73        if (!url) 
     74                return; 
     75 
     76        camel_url_set_protocol (url, apriv->proto);  
     77 
     78        if (apriv->user) 
     79                camel_url_set_user (url, apriv->user); 
     80 
     81        camel_url_set_host (url, apriv->host); 
     82 
     83        if (apriv->port != -1) 
     84                camel_url_set_port (url, (int)apriv->port); 
     85 
     86        if (apriv->mech) 
     87                camel_url_set_authmech (url, apriv->mech); 
     88 
     89        while (options) 
     90        { 
     91                gchar *ptr, *dup = g_strdup (options->data); 
     92                gchar *option, *value; 
     93                ptr = strchr (dup, '='); 
     94                if (ptr) { 
     95                        ptr++; 
     96                        value = g_strdup (ptr); ptr--; 
     97                        *ptr = '\0'; option = dup; 
     98                } else { 
     99                        option = dup; 
     100                        value = g_strdup ("1"); 
     101                } 
     102                camel_url_set_param (url, option, value); 
     103                g_free (value); 
     104                g_free (dup); 
     105                options = g_list_next (options); 
     106        } 
     107 
     108        if (G_LIKELY (apriv->url_string)) 
     109                g_free (apriv->url_string); 
     110 
     111        apriv->url_string = camel_url_to_string (url, 0); 
     112        camel_url_free (url); 
     113 
     114        /* TODO: check for old instance and clear it */ 
     115 
     116        g_static_rec_mutex_lock (apriv->service_lock); 
     117        /* camel_session_get_service can launch GUI things */ 
     118        if (apriv->session) 
     119                apriv->service = camel_session_get_service 
     120                        ((CamelSession*) apriv->session, apriv->url_string,  
     121                        apriv->type, apriv->ex); 
     122        g_static_rec_mutex_unlock (apriv->service_lock); 
     123 
     124        return; 
     125
     126 
     127static void  
     128tny_camel_transport_account_try_connect (TnyAccount *self, GError **err) 
    58129{ 
    59130        TnyCamelAccountPriv *apriv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self); 
    60131        CamelException ex = CAMEL_EXCEPTION_INITIALISER; 
    61132 
    62         if (G_LIKELY (apriv->session) && G_UNLIKELY (apriv->proto) && G_UNLIKELY (apriv->host)) 
    63         { 
    64                 CamelURL *url = NULL; 
    65                 GList *options = apriv->options; 
    66                 gchar *proto = g_strdup_printf ("%s://", apriv->proto);  
    67                          
    68                 url = camel_url_new (proto, apriv->ex); 
    69                 g_free (proto); 
    70  
    71                 camel_url_set_protocol (url, apriv->proto);  
    72  
    73                 if (apriv->user) 
    74                         camel_url_set_user (url, apriv->user); 
    75  
    76                 camel_url_set_host (url, apriv->host); 
    77  
    78                 if (apriv->mech) 
    79                         camel_url_set_authmech (url, apriv->mech); 
    80  
    81                 while (options) 
    82                 { 
    83                         gchar *ptr, *dup = g_strdup (options->data); 
    84                         gchar *option, *value; 
    85                         ptr = strchr (dup, '='); 
    86                         if (ptr) { 
    87                                 ptr++; 
    88                                 value = g_strdup (ptr); ptr--; 
    89                                 *ptr = '\0'; option = dup; 
     133        if (!apriv->url_string || !apriv->service) 
     134        { 
     135                if (camel_exception_is_set (apriv->ex)) 
     136                { 
     137                        g_set_error (err, TNY_ACCOUNT_ERROR,  
     138                                TNY_ACCOUNT_ERROR_TRY_CONNECT, 
     139                                camel_exception_get_description (apriv->ex)); 
     140                        camel_exception_clear (apriv->ex); 
     141                } else { 
     142                        g_set_error (err, TNY_ACCOUNT_ERROR,  
     143                                TNY_ACCOUNT_ERROR_TRY_CONNECT, 
     144                                _("Account not yet fully configured")); 
     145                } 
     146 
     147                return; 
     148        } 
     149 
     150 
     151        if (apriv->pass_func_set && apriv->forget_pass_func_set) 
     152        { 
     153 
     154                CamelException ex = CAMEL_EXCEPTION_INITIALISER; 
     155                apriv->connected = FALSE; 
     156 
     157                if (camel_exception_is_set (apriv->ex)) 
     158                        camel_exception_clear (apriv->ex); 
     159 
     160        /* g_static_rec_mutex_lock (apriv->service_lock); 
     161 
     162                camel_service_connect can launch GUI things  
     163 
     164                if (!camel_service_connect (apriv->service, &ex)) 
     165                { 
     166                        if (camel_exception_is_set (&ex)) 
     167                        { 
     168                                g_set_error (err, TNY_ACCOUNT_ERROR,  
     169                                        TNY_ACCOUNT_ERROR_TRY_CONNECT, 
     170                                        camel_exception_get_description (&ex)); 
     171                                camel_exception_clear (apriv->ex); 
    90172                        } else { 
    91                                 option = dup; 
    92                                 value = g_strdup ("1"); 
     173                                g_set_error (err, TNY_ACCOUNT_ERROR,  
     174                                        TNY_ACCOUNT_ERROR_TRY_CONNECT, 
     175                                        _("Unknown error while connecting")); 
    93176                        } 
    94                         camel_url_set_param (url, option, value); 
    95                         g_free (value); 
    96                         g_free (dup); 
    97                         options = g_list_next (options); 
     177                } else { 
     178                        apriv->connected = TRUE; 
     179                        tny_camel_account_set_online_status (self, !apriv->connected); 
    98180                } 
    99181 
    100                 if (G_LIKELY (apriv->url_string)) 
    101                         g_free (apriv->url_string); 
    102  
    103                 apriv->url_string = camel_url_to_string (url, 0); 
    104                 camel_url_free (url); 
    105  
    106  
    107                 /* TODO: check for old instance and clear it */ 
    108                 g_static_rec_mutex_lock (apriv->service_lock); 
    109                 /* camel_session_get_service can launch GUI things */ 
    110                 apriv->service = camel_session_get_service 
    111                         ((CamelSession*) apriv->session, apriv->url_string,  
    112                         apriv->type, &ex); 
    113                 /* TODO: check ex and handle it with a GError */ 
    114                 if (camel_exception_is_set (&ex)) 
    115                         g_error ("Can't get service for transport account (%s)\n",  
    116                                          camel_exception_get_description (&ex)); 
    117182                g_static_rec_mutex_unlock (apriv->service_lock); 
    118  
    119         } else if (apriv->url_string) 
    120         { 
    121  
    122                 /* TODO: check for old instance and clear it */ 
    123                 g_static_rec_mutex_lock (apriv->service_lock); 
    124                 /* camel_session_get_service can launch GUI things */ 
    125                 apriv->service = camel_session_get_service 
    126                         ((CamelSession*) apriv->session, apriv->url_string,  
    127                         apriv->type, &ex); 
    128                 /* TODO: check ex and handle it with a GError */ 
    129                 if (camel_exception_is_set (&ex)) 
    130                         g_error ("Can't get service for transport account (%s)\n",  
    131                                          camel_exception_get_description (&ex)); 
    132                 g_static_rec_mutex_unlock (apriv->service_lock); 
    133         } 
     183        */ 
     184 
     185        } else { 
     186                        g_set_error (err, TNY_ACCOUNT_ERROR,  
     187                                TNY_ACCOUNT_ERROR_TRY_CONNECT, 
     188                                _("Get and Forget password functions not yet set")); 
     189        } 
     190 
    134191} 
    135192 
     
    157214        transport = (CamelTransport *) apriv->service; 
    158215        g_assert (CAMEL_IS_TRANSPORT (transport)); 
     216 
     217        /* TODO: Why not simply use tny_account_try_connect here ? */ 
    159218 
    160219        g_static_rec_mutex_lock (apriv->service_lock); 
     
    279338        object_class->finalize = tny_camel_transport_account_finalize; 
    280339 
    281         TNY_CAMEL_ACCOUNT_CLASS (class)->reconnect_func = tny_camel_transport_account_reconnect; 
     340        TNY_CAMEL_ACCOUNT_CLASS (class)->try_connect_func = tny_camel_transport_account_try_connect; 
    282341 
    283342        g_type_class_add_private (object_class, sizeof (TnyCamelTransportAccountPriv)); 
  • trunk/libtinymail-camel/tny-session-camel.c

    r1419 r1485  
    3636 
    3737#include <tny-session-camel.h> 
     38#include <tny-account.h> 
    3839 
    3940#include <tny-device.h> 
     
    711712} 
    712713 
    713 static void 
    714 foreach_account_set_connectivity (gpointer data, gpointer udata) 
    715 { 
    716         gboolean online = (gboolean)udata; 
    717         if (data && TNY_IS_CAMEL_ACCOUNT (data)) 
    718                 tny_camel_account_set_online_status (TNY_CAMEL_ACCOUNT (data), !online); 
    719 } 
    720  
    721  
    722714typedef struct 
    723715{ 
     
    727719} BackgroundConnectInfo; 
    728720 
     721static void 
     722foreach_account_set_connectivity (gpointer data, gpointer udata) 
     723{ 
     724        BackgroundConnectInfo *info = udata; 
     725        gboolean online = (gboolean)udata; 
     726        CamelSession *session = info->user_data; 
     727 
     728        if (data && TNY_IS_CAMEL_ACCOUNT (data)) 
     729        { 
     730                GError *err = NULL; 
     731 
     732                tny_account_try_connect (TNY_ACCOUNT (data), &err); 
     733                if (err == NULL) 
     734                        tny_camel_account_set_online_status (TNY_CAMEL_ACCOUNT (data), !online); 
     735                else  
     736                        tny_session_camel_alert_user (session, CAMEL_SESSION_ALERT_ERROR, err->message, FALSE); 
     737        } 
     738} 
     739 
    729740 
    730741static void 
     
    764775        { 
    765776                g_list_foreach (priv->current_accounts,  
    766                         foreach_account_set_connectivity, (gpointer) info->online); 
     777                        foreach_account_set_connectivity, info); 
    767778        } 
    768779 
     
    809820        return; 
    810821} 
     822 
    811823 
    812824/** 
  • trunk/libtinymail-gnome-desktop/tny-gnome-account-store.c

    r1478 r1485  
    349349{ 
    350350        TnyGnomeAccountStorePriv *priv = TNY_GNOME_ACCOUNT_STORE_GET_PRIVATE (self); 
    351         gint i=0, count
     351        gint i=0, count, port
    352352 
    353353        g_assert (TNY_IS_LIST (list)); 
     
    471471                                tny_account_set_hostname (TNY_ACCOUNT (account),  
    472472                                        hostname); 
    473                                  
     473 
     474                                key = g_strdup_printf ("/apps/tinymail/accounts/%d/port", i); 
     475                                port = gconf_client_get_int (priv->client,  
     476                                        (const gchar*) key, NULL); 
     477                                g_free (key);  
     478                                if (port != 0) tny_account_set_port (TNY_ACCOUNT (account),  
     479                                        port); 
     480 
    474481                                g_free (hostname); g_free (user); 
    475482                        } else { 
  • trunk/libtinymail-gpe/tny-gpe-account-store.c

    r1478 r1485  
    229229{ 
    230230        TnyGpeAccountStorePriv *priv = TNY_GPE_ACCOUNT_STORE_GET_PRIVATE (self); 
    231         gint i=0, count
     231        gint i=0, count, port
    232232 
    233233        g_assert (TNY_IS_LIST (list)); 
     
    350350                                tny_account_set_hostname (TNY_ACCOUNT (account),  
    351351                                        hostname); 
    352                                  
     352 
     353                                key = g_strdup_printf ("/apps/tinymail/accounts/%d/port", i); 
     354                                port = gconf_client_get_int (priv->client,  
     355                                        (const gchar*) key, NULL); 
     356                                g_free (key);  
     357                                if (port != 0) tny_account_set_port (TNY_ACCOUNT (account),  
     358                                        port); 
     359 
    353360                                g_free (hostname); g_free (user); 
    354361                        } else { 
  • trunk/libtinymail-maemo/tny-maemo-account-store.c

    r1478