Changeset 1713

Show
Ignore:
Timestamp:
03/09/07 17:42:59
Author:
pvanhoof
Message:

A few major API changes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r1708 r1713  
     12007-03-09  Philip Van Hoof  <pvanhoof@gnome.org> 
     2 
     3        * Added the tny_account_store_find_account API. It's possible that in 
     4        future a set and get find strategy API will be added. For now, finding 
     5        using only the url-string will suffice (and adding the find strategy 
     6        later wont break the existing API, or at least doesn't have to as far 
     7        as I can see now -- I might laugh at this entry in future, we'll see) 
     8         
     9        * Changes to the TnyAccountStore implementations, it's more typical  
     10        now to let the account store store the instances internally, rather  
     11        than letting it always return new instances. How else are you going  
     12        to find the original TnyAccount instance with  
     13        tny_account_store_find_account? 
     14 
     15        * Added the tny_account_matches_url_string API, to determine whether a 
     16        specific account instance matches a specific url_string. 
     17 
     18        * This was a major API change 
     19 
    1202007-03-06  Philip Van Hoof  <pvanhoof@gnome.org> 
    221 
  • trunk/libtinymail-camel/tny-camel-account.c

    r1712 r1713  
    4949 
    5050static GObjectClass *parent_class = NULL; 
     51 
     52static gboolean  
     53tny_camel_account_matches_url_string (TnyAccount *self, const gchar *url_string) 
     54{ 
     55        return TNY_CAMEL_ACCOUNT_GET_CLASS (self)->matches_url_string_func (self, url_string); 
     56} 
     57 
     58static gboolean  
     59tny_camel_account_matches_url_string_default (TnyAccount *self, const gchar *url_string) 
     60{ 
     61        /* TODO implement */ 
     62        return FALSE; 
     63} 
    5164 
    5265static TnyAccountType 
     
    922935        klass->get_account_type_func = tny_camel_account_get_account_type; 
    923936        klass->cancel_func = tny_camel_account_cancel; 
     937        klass->matches_url_string_func = tny_camel_account_matches_url_string; 
    924938 
    925939        return; 
     
    957971        class->get_account_type_func = tny_camel_account_get_account_type_default; 
    958972        class->cancel_func = tny_camel_account_cancel_default; 
     973        class->matches_url_string_func = tny_camel_account_matches_url_string_default; 
    959974 
    960975        class->add_option_func = tny_camel_account_add_option_default; 
  • trunk/libtinymail-camel/tny-camel-account.h

    r1665 r1713  
    7474        void (*try_connect_func) (TnyAccount *self, GError **err); 
    7575        void (*cancel_func) (TnyAccount *self); 
     76        gboolean (*matches_url_string_func) (TnyAccount *self, const gchar *url_string); 
    7677 
    7778        void (*add_option_func) (TnyCamelAccount *self, const gchar *option); 
  • trunk/libtinymail-gnome-desktop/tny-gnome-account-store.c

    r1485 r1713  
    6767        TnyDevice *device; 
    6868        guint notify; 
     69        GList *accounts; 
    6970}; 
    7071 
     
    291292} 
    292293 
     294static void 
     295kill_stored_accounts (TnyGnomeAccountStorePriv *priv) 
     296{ 
     297        if (priv->accounts) 
     298        { 
     299                g_list_foreach (priv->accounts, (GFunc) g_object_unref, NULL); 
     300                g_list_free (priv->accounts); 
     301                priv->accounts = NULL; 
     302        } 
     303 
     304        return; 
     305} 
    293306 
    294307static void 
     
    297310{ 
    298311        TnyAccountStore *self = user_data; 
     312        TnyGnomeAccountStorePriv *priv = TNY_GNOME_ACCOUNT_STORE_GET_PRIVATE (self); 
    299313 
    300314        gchar *key = g_strdup (entry->key); 
    301315        gchar *ptr = strrchr (key, '/'); ptr++; 
    302316 
     317 
    303318        if (!strcmp (ptr, "count")) 
    304319        { 
     320                kill_stored_accounts (priv); 
    305321                g_signal_emit (self,  
    306322                        tny_account_store_signals [TNY_ACCOUNT_STORE_ACCOUNTS_RELOADED], 0); 
    307  
    308323        } 
    309324 
     
    313328} 
    314329 
    315  
    316 static const gchar* 
    317 tny_gnome_account_store_get_cache_dir (TnyAccountStore *self) 
    318 
    319         TnyGnomeAccountStorePriv *priv = TNY_GNOME_ACCOUNT_STORE_GET_PRIVATE (self); 
    320  
    321         if (G_UNLIKELY (!priv->cache_dir)) 
    322         { 
    323                 /* Note that there's no listener for this key. If it changes, 
    324                    the camelsession should be destroyed and rebuild from scratch. 
    325                    Which basically means reloading the accounts aswell.  
    326                    
    327                    So say you're a nut who wants this key to be updatable at  
    328                    runtime, you'll have to unload all the accounts here, and of 
    329                    course reload them. All the functionality for that is already 
    330                    available. Perhaps I should just do it ... hmm, maybe another 
    331                    day. Soon. Perhaps. I don't know. Probably . . . . bleh.  
    332  
    333                    Oh and, not to forget! You should probably also move the old 
    334                    cache location to the new one. Or cleanup the old one. */ 
    335  
    336                 gchar *cache_dir = gconf_client_get_string (priv->client,  
    337                         "/apps/tinymail/cache_dir", NULL); 
    338                 priv->cache_dir = g_build_filename (g_get_home_dir (),  
    339                         cache_dir, NULL); 
    340                 g_free (cache_dir); 
    341         } 
    342  
    343         return priv->cache_dir; 
    344 
    345  
    346  
    347 static void 
    348 tny_gnome_account_store_get_accounts (TnyAccountStore *self, TnyList *list, TnyGetAccountsRequestType types) 
     330static void 
     331load_accounts (TnyAccountStore *self) 
    349332{ 
    350333        TnyGnomeAccountStorePriv *priv = TNY_GNOME_ACCOUNT_STORE_GET_PRIVATE (self); 
    351334        gint i=0, count, port; 
    352  
    353         g_assert (TNY_IS_LIST (list)); 
    354335 
    355336        count = gconf_client_get_int (priv->client,  
     
    363344 
    364345                key = g_strdup_printf ("/apps/tinymail/accounts/%d", i); 
    365                  
     346 
    366347                if (!gconf_client_dir_exists (priv->client, (const gchar*)key, NULL)) 
    367348                { 
     
    371352                g_free (key); 
    372353 
    373              
    374354                key = g_strdup_printf ("/apps/tinymail/accounts/%d/disabled", i); 
    375355                if (gconf_client_get_bool (priv->client, (const gchar*) key, NULL)) 
     
    384364                        (const gchar*) key, NULL); 
    385365                g_free (key); 
    386              
     366 
    387367                key = g_strdup_printf ("/apps/tinymail/accounts/%d/proto", i); 
    388368                proto = gconf_client_get_string (priv->client,  
     
    394374                        (const gchar*) key, NULL); 
    395375                g_free (key); 
    396    
    397                 if (type && G_LIKELY (!g_ascii_strncasecmp (type, "transport", 9))) 
    398                 { 
    399                         if (types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS) 
    400                                 account = TNY_ACCOUNT (tny_camel_transport_account_new ()); 
    401                 } else if (type && (types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_STORE_ACCOUNTS)) 
    402                 { 
    403                         if (!g_ascii_strncasecmp (proto, "imap", 4)) 
    404                                 account = TNY_ACCOUNT (tny_camel_imap_store_account_new ()); 
    405                         else if (!g_ascii_strncasecmp (proto, "nntp", 4)) 
    406                                 account = TNY_ACCOUNT (tny_camel_nntp_store_account_new ()); 
    407                         else if (!g_ascii_strncasecmp (proto, "pop", 3)) 
    408                                 account = TNY_ACCOUNT (tny_camel_pop_store_account_new ()); 
    409                         else    /* Unknown, create a generic one? */ 
    410                             account = TNY_ACCOUNT (tny_camel_store_account_new ()); 
    411                 } 
     376 
     377                if (!g_ascii_strncasecmp (proto, "smtp", 4)) 
     378                        account = TNY_ACCOUNT (tny_camel_transport_account_new ()); 
     379                else if (!g_ascii_strncasecmp (proto, "imap", 4)) 
     380                        account = TNY_ACCOUNT (tny_camel_imap_store_account_new ()); 
     381                else if (!g_ascii_strncasecmp (proto, "nntp", 4)) 
     382                        account = TNY_ACCOUNT (tny_camel_nntp_store_account_new ()); 
     383                else if (!g_ascii_strncasecmp (proto, "pop", 3)) 
     384                        account = TNY_ACCOUNT (tny_camel_pop_store_account_new ()); 
     385                else    /* Unknown, create a generic one? */ 
     386                        account = TNY_ACCOUNT (tny_camel_store_account_new ()); 
    412387 
    413388                if (type) 
     
    423398                                (const gchar*) key, NULL); 
    424399                        g_free (key); 
    425  
    426400 
    427401                        if (name) 
     
    451425                        } 
    452426 
    453                         /* Because we only check for the n first bytes, the pops, imaps and smtps also work */ 
    454427                        if (!g_ascii_strncasecmp (proto, "pop", 3) || 
    455428                                !g_ascii_strncasecmp (proto, "imap", 4)) 
     
    457430                                gchar *user, *hostname; 
    458431 
    459                                 /* TODO: Add other supported and tested providers here */ 
    460432                                key = g_strdup_printf ("/apps/tinymail/accounts/%d/user", i); 
    461433                                user = gconf_client_get_string (priv->client,  
     
    499471                        g_free (key); 
    500472 
    501                         /*  
    502                          * Setting the password function must happen after 
    503                          * setting the host, user and protocol. 
    504                          */ 
    505  
    506473                        tny_account_set_forget_pass_func (TNY_ACCOUNT (account), 
    507474                                per_account_forget_pass_func); 
     
    510477                                per_account_get_pass_func); 
    511478 
    512                         tny_list_prepend (list, (GObject*)account); 
    513                         g_object_unref (G_OBJECT (account)); 
    514  
     479                        priv->accounts = g_list_prepend (priv->accounts, account); 
    515480                } 
    516481 
     
    521486                        g_free (proto); 
    522487        } 
    523  
    524         return;  
     488
     489 
     490static TnyAccount*  
     491tny_gnome_account_store_find_account (TnyAccountStore *self, const gchar *url_string) 
     492
     493        TnyGnomeAccountStorePriv *priv = TNY_GNOME_ACCOUNT_STORE_GET_PRIVATE (self); 
     494        TnyAccount *found = NULL; 
     495 
     496        if (!priv->accounts) 
     497                load_accounts (self); 
     498 
     499        if (priv->accounts) 
     500        { 
     501                GList *copy = priv->accounts; 
     502                while (copy) 
     503                { 
     504                        TnyAccount *account = copy->data; 
     505 
     506                        if (tny_account_matches_url_string (account, url_string)) 
     507                        { 
     508                                found = TNY_ACCOUNT (g_object_ref (G_OBJECT (found))); 
     509                                break; 
     510                        } 
     511 
     512                        copy = g_list_next (copy); 
     513                } 
     514        } 
     515 
     516        return found; 
     517
     518 
     519 
     520static const gchar* 
     521tny_gnome_account_store_get_cache_dir (TnyAccountStore *self) 
     522
     523        TnyGnomeAccountStorePriv *priv = TNY_GNOME_ACCOUNT_STORE_GET_PRIVATE (self); 
     524 
     525        if (G_UNLIKELY (!priv->cache_dir)) 
     526        { 
     527                /* Note that there's no listener for this key. If it changes, 
     528                   the camelsession should be destroyed and rebuild from scratch. 
     529                   Which basically means reloading the accounts aswell.  
     530                   
     531                   So say you're a nut who wants this key to be updatable at  
     532                   runtime, you'll have to unload all the accounts here, and of 
     533                   course reload them. All the functionality for that is already 
     534                   available. Perhaps I should just do it ... hmm, maybe another 
     535                   day. Soon. Perhaps. I don't know. Probably . . . . bleh.  
     536 
     537                   Oh and, not to forget! You should probably also move the old 
     538                   cache location to the new one. Or cleanup the old one. */ 
     539 
     540                gchar *cache_dir = gconf_client_get_string (priv->client,  
     541                        "/apps/tinymail/cache_dir", NULL); 
     542                priv->cache_dir = g_build_filename (g_get_home_dir (),  
     543                        cache_dir, NULL); 
     544                g_free (cache_dir); 
     545        } 
     546 
     547        return priv->cache_dir; 
     548
     549 
     550 
     551static void 
     552tny_gnome_account_store_get_accounts (TnyAccountStore *self, TnyList *list, TnyGetAccountsRequestType types) 
     553
     554        TnyGnomeAccountStorePriv *priv = TNY_GNOME_ACCOUNT_STORE_GET_PRIVATE (self); 
     555 
     556        g_assert (TNY_IS_LIST (list)); 
     557 
     558        if (!priv->accounts) 
     559                load_accounts (self); 
     560 
     561        if (priv->accounts) 
     562        { 
     563                GList *copy = priv->accounts; 
     564                while (copy) 
     565                { 
     566                        TnyAccount *account = copy->data; 
     567 
     568                        if (types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_STORE_ACCOUNTS) 
     569                        { 
     570                                if (TNY_IS_STORE_ACCOUNT (account)) 
     571                                        tny_list_prepend (list, (GObject*)account); 
     572                        } else if (types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS) 
     573                        { 
     574                                if (TNY_IS_TRANSPORT_ACCOUNT (account)) 
     575                                        tny_list_prepend (list, (GObject*)account); 
     576                        } 
     577 
     578                        copy = g_list_next (copy); 
     579                } 
     580        } 
     581 
     582        return; 
    525583} 
    526584 
     
    586644        g_free (key);  
    587645 
    588       count++; 
     646      count++; 
    589647 
    590648        gconf_client_set_int (priv->client, "/apps/tinymail/accounts/count",  
     
    643701        tny_session_camel_set_ui_locker (priv->session, tny_gtk_lockable_new ()); 
    644702 
    645  
    646703        return TNY_ACCOUNT_STORE (self); 
    647704} 
     
    655712        TnyPlatformFactory *platfact; 
    656713 
     714        priv->accounts = NULL; 
    657715        priv->client = gconf_client_get_default (); 
    658716 
     
    663721 
    664722        platfact = TNY_PLATFORM_FACTORY (tny_gnome_platform_factory_get_instance ()); 
    665         priv->device = tny_platform_factory_new_device (platfact); 
    666         /* tny_device_force_online (priv->device); */ 
    667          
     723        priv->device = tny_platform_factory_new_device (platfact); 
    668724 
    669725        return; 
     
    679735        tny_gnome_account_store_notify_remove (TNY_ACCOUNT_STORE (self)); 
    680736        g_object_unref (G_OBJECT (priv->client)); 
     737 
     738        kill_stored_accounts (priv); 
    681739 
    682740        if (G_LIKELY (priv->cache_dir)) 
     
    729787        klass->get_device_func = tny_gnome_account_store_get_device; 
    730788        klass->alert_func = tny_gnome_account_store_alert; 
     789        klass->find_account_func = tny_gnome_account_store_find_account; 
    731790 
    732791        return; 
  • trunk/libtinymail-gpe/tny-gpe-account-store.c

    r1485 r1713  
    6060        TnyDevice *device; 
    6161        guint notify; 
     62        GList *accounts; 
    6263}; 
    6364 
     
    170171} 
    171172 
     173 
     174static void 
     175kill_stored_accounts (TnyGpeAccountStorePriv *priv) 
     176{ 
     177        if (priv->accounts) 
     178        { 
     179                g_list_foreach (priv->accounts, (GFunc) g_object_unref, NULL); 
     180                g_list_free (priv->accounts); 
     181                priv->accounts = NULL; 
     182        } 
     183 
     184        return; 
     185} 
     186 
    172187static void 
    173188gconf_listener_account_changed (GConfClient *client, guint cnxn_id, 
     
    177192        TnyGpeAccountStorePriv *priv = TNY_GPE_ACCOUNT_STORE_GET_PRIVATE (self); 
    178193 
    179  
    180194        gchar *key = g_strdup (entry->key); 
    181195        gchar *ptr = strrchr (key, '/'); ptr++; 
     
    183197        if (!strcmp (ptr, "count")) 
    184198        { 
     199                kill_stored_accounts (priv); 
    185200                g_signal_emit (self,  
    186201                        tny_account_store_signals [TNY_ACCOUNT_STORE_ACCOUNTS_RELOADED], 0); 
    187  
    188202        } 
    189203 
     
    193207} 
    194208 
    195  
    196 static const gchar* 
    197 tny_gpe_account_store_get_cache_dir (TnyAccountStore *self) 
    198 
    199         TnyGpeAccountStorePriv *priv = TNY_GPE_ACCOUNT_STORE_GET_PRIVATE (self); 
    200  
    201         if (G_UNLIKELY (!priv->cache_dir)) 
    202         { 
    203                 /* Note that there's no listener for this key. If it changes, 
    204                    the camelsession should be destroyed and rebuild from scratch. 
    205                    Which basically means reloading the accounts aswell.  
    206                    
    207                    So say you're a nut who wants this key to be updatable at  
    208                    runtime, you'll have to unload all the accounts here, and of 
    209                    course reload them. All the functionality for that is already 
    210                    available. Perhaps I should just do it ... hmm, maybe another 
    211                    day. Soon. Perhaps. I don't know. Probably . . . . bleh.  
    212  
    213                    Oh and, not to forget! You should probably also move the old 
    214                    cache location to the new one. Or cleanup the old one. */ 
    215  
    216                 gchar *cache_dir = gconf_client_get_string (priv->client,  
    217                         "/apps/tinymail/cache_dir", NULL); 
    218                 priv->cache_dir = g_build_filename (g_get_home_dir (),  
    219                         cache_dir, NULL); 
    220                 g_free (cache_dir); 
    221         } 
    222  
    223         return priv->cache_dir; 
    224 
    225  
    226  
    227 static void 
    228 tny_gpe_account_store_get_accounts (TnyAccountStore *self, TnyList *list, TnyGetAccountsRequestType types) 
    229 
    230         TnyGpeAccountStorePriv *priv = TNY_GPE_ACCOUNT_STORE_GET_PRIVATE (self); 
     209static void 
     210load_accounts (TnyAccountStore *self) 
     211
     212        TnyGpeAccountStorePriv *priv = TNY_GPE_ACCOUNT_STORE_GET_PRIVATE (self); 
     213 
    231214        gint i=0, count, port; 
    232215 
    233         g_assert (TNY_IS_LIST (list)); 
    234  
    235216        count = gconf_client_get_int (priv->client,  
    236                        "/apps/tinymail/accounts/count", NULL); 
     217                "/apps/tinymail/accounts/count", NULL); 
    237218 
    238219        for (i=0; i < count; i++) 
     
    273254                        (const gchar*) key, NULL); 
    274255                g_free (key); 
    275              
    276              
    277                 if (type && G_LIKELY (!g_ascii_strncasecmp (type, "transport", 9))) 
    278                 { 
    279                         if (types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS) 
    280                                 account = TNY_ACCOUNT (tny_camel_transport_account_new ()); 
    281                 } else if (type && types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_STORE_ACCOUNTS) 
    282                 {                
    283                         if (!g_ascii_strncasecmp (proto, "imap", 4)) 
    284                                 account = TNY_ACCOUNT (tny_camel_imap_store_account_new ()); 
    285                         else if (!g_ascii_strncasecmp (proto, "nntp", 4)) 
    286                                 account = TNY_ACCOUNT (tny_camel_nntp_store_account_new ()); 
    287                         else if (!g_ascii_strncasecmp (proto, "pop", 3)) 
    288                                 account = TNY_ACCOUNT (tny_camel_pop_store_account_new ()); 
    289                         else    /* Unknown, create a generic one? */ 
    290                                 account = TNY_ACCOUNT (tny_camel_store_account_new ()); 
    291                 } 
    292              
     256 
     257                if (!g_ascii_strncasecmp (proto, "smtp", 4)) 
     258                        account = TNY_ACCOUNT (tny_camel_transport_account_new ()); 
     259                else if (!g_ascii_strncasecmp (proto, "imap", 4)) 
     260                        account = TNY_ACCOUNT (tny_camel_imap_store_account_new ()); 
     261                else if (!g_ascii_strncasecmp (proto, "nntp", 4)) 
     262                        account = TNY_ACCOUNT (tny_camel_nntp_store_account_new ()); 
     263                else if (!g_ascii_strncasecmp (proto, "pop", 3)) 
     264                        account = TNY_ACCOUNT (tny_camel_pop_store_account_new ()); 
     265                else    /* Unknown, create a generic one? */ 
     266                        account = TNY_ACCOUNT (tny_camel_store_account_new ()); 
     267 
    293268                if (type) 
    294269                        g_free (type); 
     
    330305                        } 
    331306 
    332                         /* Because we only check for the n first bytes, the pops, imaps and smtps also work */ 
    333307                        if (!g_ascii_strncasecmp (proto, "pop", 3) || 
    334308                                !g_ascii_strncasecmp (proto, "imap", 4)) 
     
    336310                                gchar *user, *hostname; 
    337311 
    338                                 /* TODO: Add other supported and tested providers here */ 
    339312                                key = g_strdup_printf ("/apps/tinymail/accounts/%d/user", i); 
    340313                                user = gconf_client_get_string (priv->client,  
     
    378351                        g_free (key); 
    379352 
    380                         /*  
    381                          * Setting the password function must happen after 
    382                          * setting the host, user and protocol. 
    383                          */ 
    384  
    385353                        tny_account_set_forget_pass_func (TNY_ACCOUNT (account), 
    386354                                per_account_forget_pass_func); 
     
    389357                                per_account_get_pass_func); 
    390358 
    391  
    392                         tny_list_prepend (list, (GObject*)account); 
    393                         g_object_unref (G_OBJECT (account)); 
    394  
     359                        priv->accounts = g_list_prepend (priv->accounts, account); 
    395360                } 
    396361 
     
    402367 
    403368        } 
    404  
    405         return;  
     369
     370 
     371static TnyAccount*  
     372tny_gpe_account_store_find_account (TnyAccountStore *self, const gchar *url_string) 
     373
     374        TnyGpeAccountStorePriv *priv = TNY_GPE_ACCOUNT_STORE_GET_PRIVATE (self); 
     375        TnyAccount *found = NULL; 
     376 
     377        if (!priv->accounts) 
     378                load_accounts (self); 
     379 
     380        if (priv->accounts) 
     381        { 
     382                GList *copy = priv->accounts; 
     383                while (copy) 
     384                { 
     385                        TnyAccount *account = copy->data; 
     386 
     387                        if (tny_account_matches_url_string (account, url_string)) 
     388                        { 
     389                                found = TNY_ACCOUNT (g_object_ref (G_OBJECT (found))); 
     390                                break; 
     391                        } 
     392 
     393                        copy = g_list_next (copy); 
     394                } 
     395        } 
     396 
     397        return found; 
     398
     399 
     400 
     401static const gchar* 
     402tny_gpe_account_store_get_cache_dir (TnyAccountStore *self) 
     403
     404        TnyGpeAccountStorePriv *priv = TNY_GPE_ACCOUNT_STORE_GET_PRIVATE (self); 
     405 
     406        if (G_UNLIKELY (!priv->cache_dir)) 
     407        { 
     408                /* Note that there's no listener for this key. If it changes, 
     409                   the camelsession should be destroyed and rebuild from scratch. 
     410                   Which basically means reloading the accounts aswell.  
     411                   
     412                   So say you're a nut who wants this key to be updatable at  
     413                   runtime, you'll have to unload all the accounts here, and of 
     414                   course reload them. All the functionality for that is already 
     415                   available. Perhaps I should just do it ... hmm, maybe another 
     416                   day. Soon. Perhaps. I don't know. Probably . . . . bleh.  
     417 
     418                   Oh and, not to forget! You should probably also move the old 
     419                   cache location to the new one. Or cleanup the old one. */ 
     420 
     421                gchar *cache_dir = gconf_client_get_string (priv->client,  
     422                        "/apps/tinymail/cache_dir", NULL); 
     423                priv->cache_dir = g_build_filename (g_get_home_dir (),  
     424                        cache_dir, NULL); 
     425                g_free (cache_dir); 
     426        } 
     427 
     428        return priv->cache_dir; 
     429
     430 
     431 
     432static void 
     433tny_gpe_account_store_get_accounts (TnyAccountStore *self, TnyList *list, TnyGetAccountsRequestType types) 
     434
     435        TnyGpeAccountStorePriv *priv = TNY_GPE_ACCOUNT_STORE_GET_PRIVATE (self); 
     436 
     437        g_assert (TNY_IS_LIST (list)); 
     438 
     439        if (!priv->accounts) 
     440                load_accounts (self); 
     441 
     442        if (priv->accounts) 
     443        { 
     444                GList *copy = priv->accounts; 
     445                while (copy) 
     446                { 
     447                        TnyAccount *account = copy->data; 
     448 
     449                        if (types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_STORE_ACCOUNTS) 
     450                        { 
     451                                if (TNY_IS_STORE_ACCOUNT (account)) 
     452                                        tny_list_prepend (list, (GObject*)account); 
     453                        } else if (types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS) 
     454                        { 
     455                                if (TNY_IS_TRANSPORT_ACCOUNT (account)) 
     456                                        tny_list_prepend (list, (GObject*)account); 
     457                        } 
     458 
     459                        copy = g_list_next (copy); 
     460                } 
     461        } 
     462 
     463        return; 
    406464} 
    407465 
     
    538596        TnyGpeAccountStorePriv *priv = TNY_GPE_ACCOUNT_STORE_GET_PRIVATE (self); 
    539597        TnyPlatformFactory *platfact; 
    540      
     598 
     599        priv->accounts = NULL; 
    541600        priv->client = gconf_client_get_default (); 
    542601 
     
    549608 
    550609        priv->device = tny_platform_factory_new_device (platfact); 
    551         /* tny_device_force_online (priv->device); */ 
    552              
     610 
    553611        return; 
    554612} 
     
    563621        tny_gpe_account_store_notify_remove (TNY_ACCOUNT_STORE (self)); 
    564622        g_object_unref (G_OBJECT (priv->client)); 
     623 
     624        kill_stored_accounts (priv); 
    565625 
    566626        if (G_LIKELY (priv->cache_dir)) 
     
    613673        klass->get_device_func = tny_gpe_account_store_get_device; 
    614674        klass->alert_func = tny_gpe_account_store_alert; 
     675        klass->find_account_func = tny_gpe_account_store_find_account; 
    615676 
    616677        return; 
  • trunk/libtinymail-maemo/tny-maemo-account-store.c

    r1485 r1713  
    6060        TnyDevice *device; 
    6161        guint notify; 
     62        GList *accounts; 
    6263}; 
    6364 
     
    120121{ 
    121122        TnyGetPassFunc func; 
    122      
     123 
    123124        if (G_LIKELY (passwords)) 
    124125        { 
     
    171172} 
    172173 
     174 
     175static void 
     176kill_stored_accounts (TnyMaemoAccountStorePriv *priv) 
     177{ 
     178        if (priv->accounts) 
     179        { 
     180                g_list_foreach (priv->accounts, (GFunc) g_object_unref, NULL); 
     181                g_list_free (priv->accounts); 
     182                priv->accounts = NULL; 
     183        } 
     184 
     185        return; 
     186} 
     187 
    173188static void 
    174189gconf_listener_account_changed (GConfClient *client, guint cnxn_id, 
     
    178193        TnyMaemoAccountStorePriv *priv = TNY_MAEMO_ACCOUNT_STORE_GET_PRIVATE (self); 
    179194 
    180  
    181195        gchar *key = g_strdup (entry->key); 
    182196        gchar *ptr = strrchr (key, '/'); ptr++; 
     
    184198        if (!strcmp (ptr, "count")) 
    185199        { 
     200                kill_stored_accounts (priv); 
    186201                g_signal_emit (self,  
    187202                        tny_account_store_signals [TNY_ACCOUNT_STORE_ACCOUNTS_RELOADED], 0); 
    188  
    189203        } 
    190204 
     
    194208} 
    195209 
    196  
    197 static const gchar* 
    198 tny_maemo_account_store_get_cache_dir (TnyAccountStore *self) 
    199 
    200         TnyMaemoAccountStorePriv *priv = TNY_MAEMO_ACCOUNT_STORE_GET_PRIVATE (self); 
    201  
    202         if (G_UNLIKELY (!priv->cache_dir)) 
    203         { 
    204                 /* Note that there's no listener for this key. If it changes, 
    205                    the camelsession should be destroyed and rebuild from scratch. 
    206                    Which basically means reloading the accounts aswell.  
    207                    
    208                    So say you're a nut who wants this key to be updatable at  
    209                    runtime, you'll have to unload all the accounts here, and of 
    210                    course reload them. All the functionality for that is already 
    211                    available. Perhaps I should just do it ... hmm, maybe another 
    212                    day. Soon. Perhaps. I don't know. Probably . . . . bleh.  
    213  
    214                    Oh and, not to forget! You should probably also move the old 
    215                    cache location to the new one. Or cleanup the old one. */ 
    216  
    217                 gchar *cache_dir = gconf_client_get_string (priv->client,  
    218                         "/apps/tinymail/cache_dir", NULL); 
    219                 priv->cache_dir = g_build_filename (g_get_home_dir (),  
    220                         cache_dir, NULL); 
    221                 g_free (cache_dir); 
    222         } 
    223  
    224         return priv->cache_dir; 
    225 
    226  
    227  
    228 static void 
    229 tny_maemo_account_store_get_accounts (TnyAccountStore *self, TnyList *list, TnyGetAccountsRequestType types) 
    230 
    231         TnyMaemoAccountStorePriv *priv = TNY_MAEMO_ACCOUNT_STORE_GET_PRIVATE (self); 
     210static void  
     211load_accounts (TnyAccountStore *self) 
     212
     213        TnyMaemoAccountStorePriv *priv = TNY_MAEMO_ACCOUNT_STORE_GET_PRIVATE (self); 
     214 
    232215        gint i=0, count, port; 
    233  
    234         g_assert (TNY_IS_LIST (list)); 
    235216 
    236217        count = gconf_client_get_int (priv->client,  
     
    239220        for (i=0; i < count; i++) 
    240221        { 
     222 
    241223                gchar *proto, *type, *key, *name, *mech; 
    242224                TnyAccount *account = NULL; 
     
    274256                        (const gchar*) key, NULL); 
    275257                g_free (key); 
    276              
    277              
    278                 if (type && G_LIKELY (!g_ascii_strncasecmp (type, "transport", 9))) 
    279                 { 
    280                         if (types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS) 
    281                                 account = TNY_ACCOUNT (tny_camel_transport_account_new ()); 
    282                 } else if (type && types == TNY_ACCOUNT_STORE_BOTH || types == TNY_ACCOUNT_STORE_STORE_ACCOUNTS) 
    283                 {                
    284                         if (!g_ascii_strncasecmp (proto, "imap", 4)) 
    285                                 account = TNY_ACCOUNT (tny_camel_imap_store_account_new ()); 
    286                         else if (!g_ascii_strncasecmp (proto, "nntp", 4)) 
    287                                 account = TNY_ACCOUNT (tny_camel_nntp_store_account_new ()); 
    288                         else if (!g_ascii_strncasecmp (proto, "pop", 3)) 
    289                                 account = TNY_ACCOUNT (tny_camel_pop_store_account_new ()); 
    290                         else    /* Unknown, create a generic one? */ 
    291                                 account = TNY_ACCOUNT (tny_camel_store_account_new ()); 
    292                 } 
    293                  
     258 
     259                if (!g_ascii_strncasecmp (proto, "smtp", 4)) 
     260                        account = TNY_ACCOUNT (tny_camel_transport_account_new ()); 
     261                else if (!g_ascii_strncasecmp (proto, "imap", 4)) 
     262                        account = TNY_ACCOUNT (tny_camel_imap_store_account_new ()); 
     263                else if (!g_ascii_strncasecmp (proto, "nntp", 4)) 
     264                        account = TNY_ACCOUNT (tny_camel_nntp_store_account_new ()); 
     265                else if (!g_ascii_strncasecmp (proto, "pop", 3)) 
     266                        account = TNY_ACCOUNT (tny_camel_pop_store_account_new ()); 
     267                else    /* Unknown, create a generic one? */ 
     268                        account = TNY_ACCOUNT (tny_camel_store_account_new ()); 
     269 
    294270                if (type) 
    295271                        g_free (type); 
     
    330306                        } 
    331307 
    332                         /* Because we only check for the n first bytes, the pops, imaps and smtps also work */ 
    333308                        if (!g_ascii_strncasecmp (proto, "pop", 3) || 
    334309                                !g_ascii_strncasecmp (proto, "imap", 4)) 
     
    336311                                gchar *user, *hostname; 
    337312 
    338                                 /* TODO: Add other supported and tested providers here */ 
    339313                                key = g_strdup_printf ("/apps/tinymail/accounts/%d/user", i); 
    340314                                user = gconf_client_get_string (priv->client,  
     
    378352                        g_free (key); 
    379353 
    380                         /*  
    381                          * Setting the password function must happen after 
    382                          * setting the host, user and protocol. 
    383                          */ 
    384  
    385354                        tny_account_set_forget_pass_func (TNY_ACCOUNT (account), 
    386355                                per_account_forget_pass_func); 
     
    389358                                per_account_get_pass_func); 
    390359 
    391  
    392                         tny_list_prepend (list, (GObject*)account); 
    393                         g_object_unref (G_OBJECT (account)); 
     360                        priv->accounts = g_list_prepend (priv->accounts, account); 
    394361 
    395362                } 
     
    401368                        g_free (mech); 
    402369 
    403  
    404         } 
    405  
    406         return;  
     370        } 
     371
     372 
     373static TnyAccount*  
     374tny_maemo_account_store_find_account (TnyAccountStore *self, const gchar *url_string) 
     375
     376        TnyMaemoAccountStorePriv *priv = TNY_MAEMO_ACCOUNT_STORE_GET_PRIVATE (self); 
     377        TnyAccount *found = NULL; 
     378 
     379        if (!priv->accounts) 
     380                load_accounts (self); 
     381 
     382        if (priv->accounts) 
     383        { 
     384                GList *copy = priv->accounts; 
     385                while (copy) 
     386                { 
     387                        TnyAccount *account = copy->data; 
     388 
     389                        if (tny_account_matches_url_string (account, url_string)) 
     390                        { 
     391                                found = TNY_ACCOUNT (g_object_ref (G_OBJECT (found))); 
     392                                break; 
     393                        } 
     394 
     395                        copy = g_list_next (copy); 
     396                } 
     397        } 
     398 
     399        return found; 
     400
     401 
     402 
     403static const gchar* 
    &n