Changeset 550

Show
Ignore:
Timestamp:
07/04/06 11:56:36
Author:
pvanhoof
Message:

Major API refactoring

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libtinymail-camel/tny-account-priv.h

    r505 r550  
    4141        gboolean connected, inuse_spin; 
    4242        gchar *name; GList *options; 
     43        TnyAccountType account_type; 
    4344}; 
    4445 
  • trunk/libtinymail-camel/tny-account.c

    r548 r550  
    5050 
    5151#include <tny-camel-shared.h> 
     52 
     53 
     54static void 
     55tny_account_set_account_type (TnyAccountIface *self, TnyAccountType type) 
     56{ 
     57        TnyAccountPriv *priv = TNY_ACCOUNT_GET_PRIVATE (self); 
     58 
     59        priv->account_type = type; 
     60} 
     61 
     62static TnyAccountType 
     63tny_account_get_account_type (TnyAccountIface *self) 
     64{ 
     65        TnyAccountPriv *priv = TNY_ACCOUNT_GET_PRIVATE (self); 
     66 
     67        return priv->account_type; 
     68} 
    5269 
    5370void  
     
    608625        klass->get_name_func = tny_account_get_name; 
    609626        klass->set_name_func = tny_account_set_name; 
     627        klass->set_account_type_func = tny_account_set_account_type; 
     628        klass->get_account_type_func = tny_account_get_account_type; 
    610629 
    611630        return; 
  • trunk/libtinymail-camel/tny-account.h

    r485 r550  
    3535#define TNY_ACCOUNT_GET_CLASS(inst)  (G_TYPE_INSTANCE_GET_CLASS ((inst), TNY_TYPE_ACCOUNT, TnyAccountClass)) 
    3636 
    37 /* This is an abstract type */ 
     37/* This is an abstract type, you cannot (should not) instantiate it */ 
    3838 
    3939typedef struct _TnyAccount TnyAccount; 
     
    4949        GObjectClass parent; 
    5050 
     51        /* This is an abstract method */ 
    5152        void (*reconnect_func) (TnyAccount *self); 
    5253}; 
  • trunk/libtinymail-camel/tny-msg-folder-list-iterator.c

    r542 r550  
    183183 
    184184        g_mutex_lock (me->model->iterator_lock); 
    185         retval = (G_UNLIKELY (me->current) && me->current->next); 
     185        retval = (G_LIKELY (me->current) && me->current->next); 
     186        g_mutex_unlock (me->model->iterator_lock); 
     187 
     188        return retval; 
     189
     190 
     191static gboolean  
     192tny_msg_folder_list_iterator_has_first (TnyIteratorIface *self) 
     193
     194        TnyMsgFolderListIterator *me = (TnyMsgFolderListIterator*) self; 
     195        gboolean retval; 
     196 
     197        if (G_UNLIKELY (!me || !me->model)) 
     198                return FALSE; 
     199 
     200        /* Return whether or not there's a next node */ 
     201 
     202        g_mutex_lock (me->model->iterator_lock); 
     203        retval = G_LIKELY (me->current); 
    186204        g_mutex_unlock (me->model->iterator_lock); 
    187205 
     
    212230        klass->current_func = tny_msg_folder_list_iterator_current; 
    213231        klass->has_next_func = tny_msg_folder_list_iterator_has_next; 
     232        klass->has_first_func = tny_msg_folder_list_iterator_has_first; 
    214233        klass->get_list_func = tny_msg_folder_list_iterator_get_list; 
    215234 
  • trunk/libtinymail-camel/tny-session-camel.c

    r518 r550  
    443443} 
    444444 
     445void  
     446tny_session_camel_set_current_accounts (TnySessionCamel *self, TnyListIface *list) 
     447{ 
     448        self->current_accounts = list; 
     449} 
     450 
    445451static void 
    446452connection_changed (TnyDeviceIface *device, gboolean online, gpointer user_data) 
     
    450456        camel_session_set_online ((CamelSession *) self, online);  
    451457 
    452         if (!self->first_switch && self->prev_constat != online && self->account_store) 
    453         { 
    454                 GList *copy; 
    455  
    456                 copy = (GList*) tny_account_store_iface_get_store_accounts (self->account_store);; 
    457          
    458                 while (G_LIKELY (copy)) 
    459                 { 
    460                         TnyStoreAccountIface *account = copy->data; 
     458        if (self->current_accounts && TNY_IS_LIST_IFACE (self->current_accounts) && 
     459                !self->first_switch && self->prev_constat != online  
     460                && self->account_store) 
     461        { 
     462                TnyListIface *accounts = self->current_accounts; 
     463                gboolean next = FALSE; 
     464                TnyIteratorIface *iterator; 
     465 
     466                iterator = tny_list_iface_create_iterator (accounts); 
     467                next = tny_iterator_iface_has_first (iterator); 
     468         
     469                while (next) 
     470                { 
     471                        TnyStoreAccountIface *account = tny_iterator_iface_current (iterator); 
    461472 
    462473                        _tny_account_set_online_status (account, !online); 
    463474 
    464                         copy = g_list_next (copy); 
    465                 } 
    466  
     475                        next = tny_iterator_iface_has_next (iterator); 
     476                        if (next) 
     477                                tny_iterator_iface_next (iterator); 
     478                } 
     479 
     480                g_object_unref (G_OBJECT (iterator)); 
    467481        } 
    468482 
     
    471485                        tny_account_store_iface_signals [TNY_ACCOUNT_STORE_IFACE_ACCOUNTS_RELOADED], 0); 
    472486 
     487 
    473488        self->first_switch = FALSE; 
    474  
    475489        self->prev_constat = online; 
    476490 
  • trunk/libtinymail-camel/tny-session-camel.h

    r514 r550  
    4141        gboolean interactive, prev_constat, first_switch; 
    4242        guint connchanged_signal; 
     43        TnyListIface *current_accounts; 
    4344}; 
    4445 
     
    6061void              tny_session_camel_set_account_store (TnySessionCamel *self, TnyAccountStoreIface *account_store); 
    6162void              tny_session_camel_set_device (TnySessionCamel *self, TnyDeviceIface *device); 
     63void              tny_session_camel_set_current_accounts (TnySessionCamel *self, TnyListIface *list); 
    6264 
    6365G_END_DECLS 
  • trunk/libtinymail-camel/tny-store-account.c

    r547 r550  
    8686  { 
    8787        TnyIteratorIface *iterator = tny_list_iface_create_iterator (folders); 
    88         gboolean next = TRUE
     88        gboolean next = tny_iterator_iface_has_first (iterator)
    8989 
    9090        while (next) 
     
    333333                folder = tny_iterator_iface_current (iterator); 
    334334                g_signal_emit (folder, tny_msg_folder_iface_signals [TNY_MSG_FOLDER_IFACE_FOLDERS_RELOADED], 0); 
     335 
    335336                g_object_unref (G_OBJECT (iterator)); 
    336337        } 
     
    543544        apriv->connected = FALSE; 
    544545        priv->folders_lock = g_mutex_new (); 
     546        apriv->account_type = TNY_ACCOUNT_TYPE_STORE; 
    545547 
    546548        return; 
  • trunk/libtinymail-camel/tny-transport-account.c

    r385 r550  
    139139tny_transport_account_instance_init (GTypeInstance *instance, gpointer g_class) 
    140140{ 
    141          
    142141        TnyTransportAccount *self = (TnyTransportAccount *)instance; 
    143142        TnyAccountPriv *apriv = TNY_ACCOUNT_GET_PRIVATE (self); 
     
    145144        apriv->connected = FALSE; 
    146145        apriv->type = CAMEL_PROVIDER_TRANSPORT; 
     146        apriv->account_type = TNY_ACCOUNT_TYPE_TRANSPORT; 
    147147 
    148148        return; 
  • trunk/libtinymail-gnome-desktop/tny-account-store.c

    r545 r550  
    5757{ 
    5858        GConfClient *client; 
    59  
    6059        gchar *cache_dir; 
    61  
    62         GMutex *store_accounts_lock; 
    63         GList *store_accounts; 
    64  
    65         GMutex *transport_accounts_lock; 
    66         GList *transport_accounts; 
    67  
    6860        TnySessionCamel *session; 
    6961        TnyDeviceIface *device; 
    70  
    7162        guint notify; 
    7263}; 
     
    7566        (G_TYPE_INSTANCE_GET_PRIVATE ((o), TNY_TYPE_ACCOUNT_STORE, TnyAccountStorePriv)) 
    7667 
    77 static GHashTable *passwords; 
    78  
    79  
    80 static const GList* tny_account_store_get_accounts (TnyAccountStoreIface *self); 
    81  
    82 static void 
    83 destroy_account (gpointer data, gpointer user_data) 
    84 { 
    85         g_object_unref (G_OBJECT (data)); 
    86  
    87         return; 
    88 } 
    89  
    90 static void 
    91 destroy_these_accounts (GList *accounts) 
    92 { 
    93         g_list_foreach (accounts, destroy_account, NULL); 
    94         g_list_free (accounts); 
    95         accounts = NULL; 
    96  
    97         return; 
    98 } 
    99  
    100 static void 
    101 destroy_current_accounts (TnyAccountStorePriv *priv) 
    102 { 
    103         g_mutex_lock (priv->store_accounts_lock); 
    104         g_mutex_lock (priv->transport_accounts_lock); 
    105  
    106         if (G_LIKELY (priv->store_accounts)) 
    107                 destroy_these_accounts (priv->store_accounts); 
    108  
    109         if (G_LIKELY (priv->transport_accounts)) 
    110                 destroy_these_accounts (priv->transport_accounts); 
    111  
    112         priv->transport_accounts = NULL; 
    113         priv->store_accounts = NULL; 
    114  
    115         g_mutex_unlock (priv->transport_accounts_lock); 
    116         g_mutex_unlock (priv->store_accounts_lock); 
    117  
    118         return; 
    119 } 
    12068 
    12169#ifdef GNOME 
    122  
    12370static gchar*  
    12471per_account_get_pass_func (TnyAccountIface *account, const gchar *prompt, gboolean *cancel) 
     
    234181#else  
    235182 
     183static GHashTable *passwords; 
     184 
    236185static gchar*  
    237186per_account_get_pass_func (TnyAccountIface *account, const gchar *prompt, gboolean *cancel) 
     
    307256#endif 
    308257 
    309  
    310  
    311 static TnyAccountIface * 
    312 find_account_by_gconf_key (GList *accounts, const gchar *key) 
    313 { 
    314         TnyAccountIface *found = NULL; 
    315  
    316         while (G_LIKELY (accounts)) 
    317         { 
    318                 TnyAccountIface *account = accounts->data; 
    319                 const gchar *aid = tny_account_iface_get_id (account); 
    320                  
    321                 if (G_UNLIKELY (strcmp (key, aid) == 0)) 
    322                 { 
    323                         found = account; 
    324                         break; 
    325                 } 
    326  
    327                 accounts = g_list_next (accounts); 
    328         } 
    329  
    330         return found; 
    331 } 
    332258 
    333259static gboolean 
     
    370296        TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 
    371297 
     298 
    372299        gchar *key = g_strdup (entry->key); 
    373300        gchar *ptr = strrchr (key, '/'); ptr++; 
     
    375302        if (!strcmp (ptr, "count")) 
    376303        { 
    377                 destroy_current_accounts (priv); 
    378  
    379304                g_signal_emit (self,  
    380305                        tny_account_store_iface_signals [TNY_ACCOUNT_STORE_IFACE_ACCOUNTS_RELOADED], 0); 
    381306 
    382         } else { 
    383                 GList *accounts; 
    384                 TnyAccountIface *found = NULL; 
    385                 const gchar *val; 
    386  
    387                 /* Whooo, crazy pointer hocus! */ 
    388                 gchar orig = *ptr--; *ptr = '\0'; 
    389  
    390                 g_mutex_lock (priv->transport_accounts_lock); 
    391                 accounts = priv->transport_accounts; 
    392                 found = find_account_by_gconf_key (accounts, key); 
    393                 g_mutex_unlock (priv->transport_accounts_lock); 
    394  
    395                 g_mutex_lock (priv->store_accounts_lock); 
    396                 accounts = priv->store_accounts; 
    397                 if (!found)  
    398                         found = find_account_by_gconf_key (accounts, key); 
    399                 g_mutex_unlock (priv->store_accounts_lock); 
    400  
    401                 /* pocus! */ 
    402                 *ptr = orig; *ptr++; 
    403  
    404                 val = gconf_value_get_string (entry->value); 
    405  
    406                 /* phoef! */ 
    407                 if (found && strcmp (ptr, "user")==0) 
    408                         tny_account_iface_set_user (found, val); 
    409                 else if (found && strcmp (ptr, "proto")==0) 
    410                         tny_account_iface_set_proto (found, val); 
    411                 else if (found && strcmp (ptr, "hostname")==0) 
    412                         tny_account_iface_set_hostname (found, val); 
    413307        } 
    414308 
     
    449343} 
    450344 
    451 static void 
    452 tny_account_store_get_all_accounts (TnyAccountStoreIface *self) 
    453 
    454         TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 
    455  
     345 
     346static void 
     347tny_account_store_get_accounts (TnyAccountStoreIface *self, TnyListIface *list, TnyGetAccountsRequestType types) 
     348
     349        TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 
    456350        gint i=0, count; 
    457  
    458         destroy_current_accounts (priv); 
    459351 
    460352        count = gconf_client_get_int (priv->client,  
     
    464356        { 
    465357                gchar *proto, *type, *key, *name; 
    466                 TnyAccountIface *account; GSList *options; 
     358                TnyAccountIface *account = NULL; 
     359                GSList *options; 
    467360 
    468361                key = g_strdup_printf ("/apps/tinymail/accounts/%d", i); 
     
    473366                        continue; 
    474367                } 
    475          
    476368                g_free (key); 
    477369 
     
    483375                if (type && G_LIKELY (!g_ascii_strncasecmp (type, "transport", 9))) 
    484376                { 
    485                         account = TNY_ACCOUNT_IFACE (tny_transport_account_new ()); 
    486                         priv->transport_accounts =  
    487                                 g_list_append (priv->transport_accounts, account); 
    488                 } else { 
    489                         account = TNY_ACCOUNT_IFACE (tny_store_account_new ()); 
    490                         priv->store_accounts =  
    491                                 g_list_append (priv->store_accounts, account); 
     377                        if (types == TNY_ACCOUNT_STORE_IFACE_BOTH ||  
     378                            types == TNY_ACCOUNT_STORE_IFACE_TRANSPORT_ACCOUNTS) 
     379                        { 
     380                                account = TNY_ACCOUNT_IFACE (tny_transport_account_new ()); 
     381                        } 
     382         
     383                } else  
     384                { 
     385 
     386                        if (types == TNY_ACCOUNT_STORE_IFACE_BOTH ||  
     387                            types == TNY_ACCOUNT_STORE_IFACE_STORE_ACCOUNTS) 
     388                        { 
     389                                account = TNY_ACCOUNT_IFACE (tny_store_account_new ()); 
     390                        } 
    492391                } 
    493392 
    494                 tny_account_iface_set_account_store (account, self); 
    495  
    496                 if (type) 
    497                         g_free (type); 
    498  
    499                 key = g_strdup_printf ("/apps/tinymail/accounts/%d/proto", i); 
    500                 proto = gconf_client_get_string (priv->client,  
    501                         (const gchar*) key, NULL); 
    502                 g_free (key); 
    503                 tny_account_iface_set_proto (TNY_ACCOUNT_IFACE (account), proto); 
    504  
    505                 key = g_strdup_printf ("/apps/tinymail/accounts/%d/name", i); 
    506                 name = gconf_client_get_string (priv->client,  
    507                         (const gchar*) key, NULL); 
    508                 g_free (key); 
    509                 tny_account_iface_set_name (TNY_ACCOUNT_IFACE (account), name); 
    510                 g_free (name); 
    511  
    512  
    513                 key = g_strdup_printf ("/apps/tinymail/accounts/%d/options", i); 
    514                 options = gconf_client_get_list (priv->client,  
    515                         (const gchar*) key, GCONF_VALUE_STRING, NULL); 
    516                 g_free (key); 
    517  
    518                 if (options) 
    519                 { 
    520                         while (options) 
     393 
     394                if (account) 
     395                { 
     396                        tny_account_iface_set_account_store (account, self); 
     397 
     398                        if (type) 
     399                                g_free (type); 
     400 
     401                        key = g_strdup_printf ("/apps/tinymail/accounts/%d/proto", i); 
     402                        proto = gconf_client_get_string (priv->client,  
     403                                (const gchar*) key, NULL); 
     404                        g_free (key); 
     405                        tny_account_iface_set_proto (TNY_ACCOUNT_IFACE (account), proto); 
     406 
     407                        key = g_strdup_printf ("/apps/tinymail/accounts/%d/name", i); 
     408                        name = gconf_client_get_string (priv->client,  
     409                                (const gchar*) key, NULL); 
     410                        g_free (key); 
     411                        tny_account_iface_set_name (TNY_ACCOUNT_IFACE (account), name); 
     412                        g_free (name); 
     413 
     414 
     415                        key = g_strdup_printf ("/apps/tinymail/accounts/%d/options", i); 
     416                        options = gconf_client_get_list (priv->client,  
     417                                (const gchar*) key, GCONF_VALUE_STRING, NULL); 
     418                        g_free (key); 
     419 
     420                        if (options) 
    521421                        { 
    522                                 tny_account_add_option (TNY_ACCOUNT (account), options->data); 
    523                                 g_free (options->data); 
    524                                 options = g_slist_next (options); 
     422                                while (options) 
     423                                { 
     424                                        tny_account_add_option (TNY_ACCOUNT (account), options->data); 
     425                                        g_free (options->data); 
     426                                        options = g_slist_next (options); 
     427                                } 
     428                                g_slist_free (options); 
    525429                        } 
    526                         g_slist_free (options); 
     430 
     431                        /* Because we only check for the n first bytes, the pops, imaps and smtps also work */ 
     432                        if (!g_ascii_strncasecmp (proto, "pop", 3) || 
     433                                !g_ascii_strncasecmp (proto, "imap", 4)|| 
     434                                !g_ascii_strncasecmp (proto, "smtp", 4)) 
     435                        { 
     436                                gchar *user, *hostname; 
     437 
     438                                /* TODO: Add other supported and tested providers here */ 
     439                                key = g_strdup_printf ("/apps/tinymail/accounts/%d/user", i); 
     440                                user = gconf_client_get_string (priv->client,  
     441                                        (const gchar*) key, NULL); 
     442 
     443                                g_free (key); 
     444                                tny_account_iface_set_user (TNY_ACCOUNT_IFACE (account), user); 
     445 
     446                                key = g_strdup_printf ("/apps/tinymail/accounts/%d/hostname", i); 
     447                                hostname = gconf_client_get_string (priv->client,  
     448                                        (const gchar*) key, NULL); 
     449                                g_free (key);  
     450                                tny_account_iface_set_hostname (TNY_ACCOUNT_IFACE (account),  
     451                                        hostname); 
     452                                 
     453                                g_free (hostname); g_free (proto); g_free (user); 
     454                        } else { 
     455                                gchar *url_string; 
     456 
     457                                /* Un officially supported provider */ 
     458                                /* Assuming there's a url_string in this case */ 
     459 
     460                                key = g_strdup_printf ("/apps/tinymail/accounts/%d/url_string", i); 
     461                                url_string = gconf_client_get_string (priv->client,  
     462                                        (const gchar*) key, NULL); 
     463 
     464                                g_free (key); 
     465                                tny_account_iface_set_url_string (TNY_ACCOUNT_IFACE (account), url_string); 
     466                                g_free (url_string); 
     467                        } 
     468 
     469                        key = g_strdup_printf ("/apps/tinymail/accounts/%d", i); 
     470                        tny_account_iface_set_id (TNY_ACCOUNT_IFACE (account), key); 
     471                        g_free (key); 
     472 
     473                        /*  
     474                         * Setting the password function must happen after 
     475                         * setting the host, user and protocol. 
     476                         */ 
     477 
     478                        tny_account_iface_set_forget_pass_func (TNY_ACCOUNT_IFACE (account), 
     479                                per_account_forget_pass_func); 
     480 
     481                        tny_account_iface_set_pass_func (TNY_ACCOUNT_IFACE (account), 
     482                                per_account_get_pass_func); 
     483 
     484 
     485                        tny_list_iface_prepend (list, account); 
    527486                } 
    528  
    529                 /* Because we only check for the n first bytes, the pops, imaps and smtps also work */ 
    530                 if (!g_ascii_strncasecmp (proto, "pop", 3) || 
    531                         !g_ascii_strncasecmp (proto, "imap", 4)|| 
    532                         !g_ascii_strncasecmp (proto, "smtp", 4)) 
    533                 { 
    534                         gchar *user, *hostname; 
    535  
    536                         /* TODO: Add other supported and tested providers here */ 
    537                         key = g_strdup_printf ("/apps/tinymail/accounts/%d/user", i); 
    538                         user = gconf_client_get_string (priv->client,  
    539                                 (const gchar*) key, NULL); 
    540  
    541                         g_free (key); 
    542                         tny_account_iface_set_user (TNY_ACCOUNT_IFACE (account), user); 
    543  
    544                         key = g_strdup_printf ("/apps/tinymail/accounts/%d/hostname", i); 
    545                         hostname = gconf_client_get_string (priv->client,  
    546                                 (const gchar*) key, NULL); 
    547                         g_free (key);  
    548                         tny_account_iface_set_hostname (TNY_ACCOUNT_IFACE (account),  
    549                                 hostname); 
    550                          
    551                         g_free (hostname); g_free (proto); g_free (user); 
    552                 } else { 
    553                         gchar *url_string; 
    554  
    555                         /* Un officially supported provider */ 
    556                         /* Assuming there's a url_string in this case */ 
    557  
    558                         key = g_strdup_printf ("/apps/tinymail/accounts/%d/url_string", i); 
    559                         url_string = gconf_client_get_string (priv->client,  
    560                                 (const gchar*) key, NULL); 
    561  
    562                         g_free (key); 
    563                         tny_account_iface_set_url_string (TNY_ACCOUNT_IFACE (account), url_string); 
    564                         g_free (url_string); 
    565                 } 
    566  
    567                 key = g_strdup_printf ("/apps/tinymail/accounts/%d", i); 
    568                 tny_account_iface_set_id (TNY_ACCOUNT_IFACE (account), key); 
    569                 g_free (key); 
    570  
    571                 /*  
    572                  * Setting the password function must happen after 
    573                  * setting the host, user and protocol. 
    574                  */ 
    575  
    576                 tny_account_iface_set_forget_pass_func (TNY_ACCOUNT_IFACE (account), 
    577                         per_account_forget_pass_func); 
    578  
    579                 tny_account_iface_set_pass_func (TNY_ACCOUNT_IFACE (account), 
    580                         per_account_get_pass_func); 
    581         } 
    582  
    583         return; 
    584 
    585  
    586 /* TODO: 
    587  
    588         - Refactor to let this return a TnyListIface  
    589  
    590         - No two methods, just add a TnyAccountType parameter? 
    591  
    592         - No caching allowed here! (no reason) 
    593  
    594 */ 
    595  
    596 static const GList* 
    597 tny_account_store_get_store_accounts (TnyAccountStoreIface *self) 
    598 
    599         TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 
    600         const GList *retval; 
    601  
    602         if (G_UNLIKELY (!priv->store_accounts)) 
    603                 tny_account_store_get_all_accounts (self); 
    604  
    605         g_mutex_lock (priv->store_accounts_lock); 
    606         retval = (const GList*) priv->store_accounts; 
    607         g_mutex_unlock (priv->store_accounts_lock); 
    608  
    609         return retval; 
    610 
    611  
    612 /* TODO: 
    613  
    614         - Refactor to let this return a TnyListIface  
    615  
    616         - No two methods, just add a TnyAccountType parameter? 
    617  
    618         - No caching allowed here! (no reason) 
    619  
    620 */ 
    621  
    622 static const GList* 
    623 tny_account_store_get_transport_accounts (TnyAccountStoreIface *self) 
    624 
    625         TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 
    626         const GList *retval; 
    627  
    628         if (G_UNLIKELY (!priv->transport_accounts)) 
    629                 tny_account_store_get_all_accounts (self); 
    630  
    631         g_mutex_lock (priv->transport_accounts_lock); 
    632         retval = (const GList*) priv->transport_accounts; 
    633         g_mutex_unlock (priv->transport_accounts_lock); 
    634  
    635         return retval; 
    636 
     487        } 
     488 
     489        tny_session_camel_set_current_accounts (priv->session, list); 
     490 
     491        return;  
     492
     493 
    637494 
    638495static void 
     
    663520        gconftool-2 -s /apps/tinymail/accounts/0/user -t string username 
    664521        gconftool-2 -s /apps/tinymail/accounts/0/hostname -t string mailserver 
    665  
    666522or 
    667  
    668523        gconftool-2 -s /apps/tinymail/accounts/0/url_string -t string url_string 
    669524 
     
    705560 
    706561 
    707 /* TODO: 
    708  
    709         - Refactor to let this return a TnyListIface  
    710  
    711         - No two methods, just add a TnyAccountType parameter? 
    712  
    713         - No caching allowed here! (no reason) 
    714  
    715 */ 
    716562 
    717563static void 
     
    724570        tny_account_store_notify_add (self); 
    725571 
    726         /* g_object_ref (G_OBJECT (account)); */ 
    727  
    728         g_mutex_lock (priv->store_accounts_lock); 
    729         priv->store_accounts = g_list_append (priv->store_accounts, account); 
    730         g_mutex_unlock (priv->store_accounts_lock); 
    731  
    732572        g_signal_emit (self, tny_account_store_iface_signals [TNY_ACCOUNT_STORE_IFACE_ACCOUNT_INSERTED], 0, account); 
    733573 
     
    739579{ 
    740580        TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 
    741  
    742         /* g_object_ref (G_OBJECT (account)); */ 
    743581 
    744582        tny_account_store_notify_remove (self); 
    745583        tny_account_store_add_account (self, TNY_ACCOUNT_IFACE (account), "transport"); 
    746584        tny_account_store_notify_add (self); 
    747  
    748         g_mutex_lock (priv->transport_accounts_lock); 
    749         priv->transport_accounts = g_list_append (priv->transport_accounts, account); 
    750         g_mutex_unlock (priv->transport_accounts_lock); 
    751585 
    752586        g_signal_emit (self, tny_account_store_iface_signals [TNY_ACCOUNT_STORE_IFACE_ACCOUNT_INSERTED], 0, account); 
     
    778612 
    779613        priv->device = tny_platform_factory_iface_new_device (platfact); 
    780         //tny_device_iface_force_online (priv->device); 
     614        /* tny_device_iface_force_online (priv->device); */ 
    781615        priv->session = tny_session_camel_new (TNY_ACCOUNT_STORE_IFACE (self)); 
    782616 
     
    790624        TnyAccountStore *self = (TnyAccountStore *)instance; 
    791625        TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 
    792  
    793         priv->store_accounts_lock = g_mutex_new (); 
    794         priv->transport_accounts_lock = g_mutex_new (); 
    795626 
    796627        priv->client = gconf_client_get_default (); 
     
    813644        tny_account_store_notify_remove (TNY_ACCOUNT_STORE_IFACE (self)); 
    814645        g_object_unref (G_OBJECT (priv->client)); 
    815  
    816         destroy_current_accounts (priv); 
    817  
    818         g_mutex_free (priv->store_accounts_lock); 
    819         g_mutex_free (priv->transport_accounts_lock); 
    820  
    821         priv->store_accounts_lock = NULL; 
    822         priv->transport_accounts_lock = NULL; 
    823646 
    824647        if (G_LIKELY (priv->cache_dir)) 
     
    865688        TnyAccountStoreIfaceClass *klass = (TnyAccountStoreIfaceClass *)g_iface; 
    866689 
     690        klass->get_accounts_func = tny_account_store_get_accounts; 
    867691        klass->add_store_account_func = tny_account_store_add_store_account; 
    868         klass->get_store_accounts_func = tny_account_store_get_store_accounts; 
    869692        klass->add_transport_account_func = tny_account_store_add_transport_account; 
    870         klass->get_transport_accounts_func = tny_account_store_get_transport_accounts; 
    871693        klass->get_cache_dir_func = tny_account_store_get_cache_dir; 
    872694        klass->get_device_func = tny_account_store_get_device; 
  • trunk/libtinymail-gpe/tny-account-store.c

    r529 r550  
    5353{ 
    5454        GConfClient *client; 
    55  
    5655        gchar *cache_dir; 
    57  
    58         GMutex *store_accounts_lock; 
    59         GList *store_accounts; 
    60  
    61         GMutex *transport_accounts_lock; 
    62         GList *transport_accounts; 
    63  
    6456        TnySessionCamel *session; 
    6557        TnyDeviceIface *device; 
    66  
    6758        guint notify; 
    6859}; 
     
    7162        (G_TYPE_INSTANCE_GET_PRIVATE ((o), TNY_TYPE_ACCOUNT_STORE, TnyAccountStorePriv)) 
    7263 
     64 
    7365static GHashTable *passwords; 
    74  
    75  
    76 static const GList* tny_account_store_get_accounts (TnyAccountStoreIface *self); 
    77  
    78 static void 
    79 destroy_account (gpointer data, gpointer user_data) 
    80 { 
    81         g_object_unref (G_OBJECT (data)); 
    82  
    83         return; 
    84 } 
    85  
    86 static void 
    87 destroy_these_accounts (GList *accounts) 
    88 { 
    89         g_list_foreach (accounts, destroy_account, NULL); 
    90         g_list_free (accounts); 
    91         accounts = NULL; 
    92  
    93         return; 
    94 } 
    95  
    96 static void 
    97 destroy_current_accounts (TnyAccountStorePriv *priv) 
    98 { 
    99         g_mutex_lock (priv->store_accounts_lock); 
    100         g_mutex_lock (priv->transport_accounts_lock); 
    101  
    102         if (G_LIKELY (priv->store_accounts)) 
    103                 destroy_these_accounts (priv->store_accounts); 
    104  
    105         if (G_LIKELY (priv->transport_accounts)) 
    106                 destroy_these_accounts (priv->transport_accounts); 
    107  
    108         priv->transport_accounts = NULL; 
    109         priv->store_accounts = NULL; 
    110  
    111         g_mutex_unlock (priv->transport_accounts_lock); 
    112         g_mutex_unlock (priv->store_accounts_lock); 
    113  
    114         return; 
    115 } 
    116  
    11766 
    11867static gchar*  
     
    185134 
    186135        return; 
    187 } 
    188  
    189  
    190 static TnyAccountIface * 
    191 find_account_by_gconf_key (GList *accounts, const gchar *key) 
    192 { 
    193         TnyAccountIface *found = NULL; 
    194  
    195         while (G_LIKELY (accounts)) 
    196         { 
    197                 TnyAccountIface *account = accounts->data; 
    198                 const gchar *aid = tny_account_iface_get_id (account); 
    199                  
    200                 if (G_UNLIKELY (strcmp (key, aid) == 0)) 
    201                 { 
    202                         found = account; 
    203                         break; 
    204                 } 
    205  
    206                 accounts = g_list_next (accounts); 
    207         } 
    208  
    209         return found; 
    210136} 
    211137 
     
    249175        TnyAccountStorePriv *priv = TNY_ACCOUNT_STORE_GET_PRIVATE (self); 
    250176 
     177 
    251178        gchar *key = g_strdup (entry->key); 
    252179        gchar *ptr = strrchr (key, '/'); ptr++; 
     
    254181        if (!strcmp (ptr, "count")) 
    255182        { 
    256                 destroy_current_accounts (priv); 
    257  
    258183                g_signal_emit (self,  
    259184                        tny_account_store_iface_signals [TNY_ACCOUNT_STORE_IFACE_ACCOUNTS_RELOADED], 0); 
    260185 
    261         } else { 
    262                 GList *accounts; 
    263                 TnyAccountIface *found = NULL; 
    264                 const gchar *val; 
    265  
    266                 /* Whooo, crazy pointer hocus! */ 
    267                 gchar orig = *ptr--; *ptr = '\0'; 
    268  
    269                 g_mutex_lock (priv->transport_accounts_lock); 
    270                 accounts = priv->transport_accounts; 
    271                 found = find_account_by_gconf_key (accounts, key); 
    272                 g_mutex_unlock (priv->transport_accounts_lock); 
    273  
    274                 g_mutex_lock (priv->store_accounts_lock); 
    275                 accounts = priv->store_accounts; 
    276                 if (!found)  
    277                         found = find_account_by_gconf_key (accounts, key); 
    278                 g_mutex_unlock (priv->store_accounts_lock); 
    279  
    280                 /* pocus! */ 
    281                 *ptr = orig; *ptr++; 
    282  
    283                 val = gconf_value_get_string (entry->value); 
    284  
    285                 /* phoef! */ 
    286                 if (found && strcmp (ptr, "user")==0) 
    287                         tny_account