Changeset 1212

Show
Ignore:
Timestamp:
11/23/06 14:46:55
Author:
svillar
Message:

* Added support to folder rename
* Fixed a leak
* Refactored subscriptions code

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r1211 r1212  
     12006-11-23  Sergio Villar Senin <svillar@igalia.com> 
     2        * libtinymail-camel/tny-camel-folder.c: added support to rename 
     3        folders 
     4        * libtinymail-camel/tny-camel-store-account.c: refactored the 
     5        subscriptions code 
     6        * libtinymail-gnome-desktop/tny-gnome-account-store.c: removed a small 
     7        leak 
     8 
    192006-11-21  Sergio Villar Senin <svillar@igalia.com> 
    210        * Fixed a bug when subscribing new folders 
  • trunk/docs/devel/reference/tmpl/tny-account-store.sgml

    r1202 r1212  
    4343</para> 
    4444 
     45@:  
     46@: 
     47 
    4548@tnyaccountstore: the object which received the signal. 
    4649@arg1:  
     
    5053 
    5154</para> 
     55 
     56@:  
     57@: 
    5258 
    5359@tnyaccountstore: the object which received the signal. 
     
    5965</para> 
    6066 
     67@:  
     68@: 
     69 
    6170@tnyaccountstore: the object which received the signal. 
    6271@arg1:  
     
    6675 
    6776</para> 
     77 
     78@: 
    6879 
    6980@tnyaccountstore: the object which received the signal. 
  • trunk/docs/devel/reference/tmpl/tny-device.sgml

    r1202 r1212  
    2929 
    3030</para> 
     31 
     32@:  
     33@: 
    3134 
    3235@tnydevice: the object which received the signal. 
  • trunk/docs/devel/reference/tmpl/tny-shared.sgml

    r1202 r1212  
    292292</para> 
    293293 
    294 @tnystoreaccount: the object which received the signal. 
    295 @arg1:  
     294@:  
     295@:  
    296296 
    297297<!-- ##### STRUCT TnyStoreAccountIface ##### --> 
  • trunk/libtinymail-camel/tny-camel-folder.c

    r1202 r1212  
    196196                } 
    197197 
    198         priv->cached_length = camel_folder_get_message_count (priv->folder); 
     198                priv->subscribed =  
     199                        camel_store_folder_subscribed (store, 
     200                                                       camel_folder_get_full_name (priv->folder)); 
     201                priv->cached_length = camel_folder_get_message_count (priv->folder); 
    199202 
    200203                /* priv->folder_changed_id = camel_object_hook_event (priv->folder,  
     
    381384 
    382385        g_mutex_lock (priv->folder_lock); 
     386 
     387        if (!priv->folder || !priv->loaded || !CAMEL_IS_FOLDER (priv->folder)) 
     388        { 
     389                CamelStore *store; 
     390                CamelFolder *cfolder; 
     391 
     392                if (!load_folder_no_lock (priv))  
     393                { 
     394                        g_mutex_unlock (priv->folder_lock); 
     395                        return; 
     396                } 
     397                store = (CamelStore*) _tny_camel_account_get_service  
     398                        (TNY_CAMEL_ACCOUNT (priv->account)); 
     399                cfolder = tny_camel_folder_get_folder (TNY_CAMEL_FOLDER (self)); 
     400                priv->subscribed = camel_store_folder_subscribed (store,  
     401                                                                  camel_folder_get_full_name (cfolder)); 
     402        } 
     403 
    383404        retval = priv->subscribed; 
    384405        g_mutex_unlock (priv->folder_lock); 
     
    10681089{ 
    10691090        TnyCamelFolderPriv *priv = TNY_CAMEL_FOLDER_GET_PRIVATE (self); 
    1070  
    1071         if (!load_folder (priv)) 
     1091        gchar *full_name; 
     1092        CamelFolder *cfolder; 
     1093        CamelFolderInfo *parent_info; 
     1094        const gchar *old_path; 
     1095        gchar *new_path; 
     1096        CamelException ex; 
     1097 
     1098        g_mutex_lock (priv->folder_lock); 
     1099 
     1100        if (!priv->folder || !priv->loaded || !CAMEL_IS_FOLDER (priv->folder)) 
     1101                if (!load_folder_no_lock (priv))  
     1102                { 
     1103                        g_mutex_unlock (priv->folder_lock); 
     1104                        return; 
     1105                } 
     1106 
     1107        if (!priv->iter || !priv->iter_parented) 
    10721108                return; 
    10731109 
    1074         camel_folder_rename (priv->folder, name); 
     1110        /* Create new full name */ 
     1111        cfolder = tny_camel_folder_get_folder (TNY_CAMEL_FOLDER (self)); 
     1112        old_path = camel_folder_get_full_name (cfolder); 
     1113        parent_info = priv->iter->parent; 
     1114        new_path = g_strdup_printf ("%s/%s", parent_info->name, name); 
     1115 
     1116        /* Check that the name really changes */ 
     1117        if (!strcmp (old_path, new_path))  
     1118        { 
     1119                g_free (new_path); 
     1120                return; 
     1121        } 
     1122 
     1123        /* Rename folder */ 
     1124        camel_exception_init (&ex); 
     1125        camel_store_rename_folder (cfolder->parent_store, old_path, (const gchar *) new_path, &ex); 
     1126        g_free (new_path); 
     1127 
     1128        if (camel_exception_is_set (&ex)) 
     1129        { 
     1130                g_warning (N_("Renaming folder %s to %s failed: %s\n"), 
     1131                           camel_folder_get_name (cfolder), 
     1132                           name, 
     1133                           camel_exception_get_description (&ex)); 
     1134                camel_exception_clear (&ex); 
     1135                return; 
     1136        } 
    10751137 
    10761138        if (G_UNLIKELY (priv->cached_name)) 
     
    10791141        priv->cached_name = g_strdup (name); 
    10801142 
    1081         return
     1143        g_mutex_unlock (priv->folder_lock)
    10821144} 
    10831145 
     
    13561418        info = camel_store_create_folder (store, priv->folder_name, name, &ex); 
    13571419 
    1358         if (camel_exception_is_set (&ex)) { 
    1359                 g_warning ("Creating folder failed: %s\n",  
     1420        if (camel_exception_is_set (&ex))  
     1421        { 
     1422                g_warning (N_("Creating folder failed: %s\n"),  
    13601423                        camel_exception_get_description (&ex)); 
    13611424                g_object_unref (G_OBJECT (folder)); 
  • trunk/libtinymail-camel/tny-camel-store-account.c

    r1202 r1212  
    8989                 
    9090                        camel_url_set_protocol (url, priv->proto);  
    91  
    9291                        camel_url_set_user (url, priv->user); 
    9392                        camel_url_set_host (url, priv->host); 
     
    165164} 
    166165 
    167  
    168 static void 
    169 tny_camel_store_account_subscribe (TnyStoreAccount *self, TnyFolder *folder) 
    170 
    171         TnyCamelAccountPriv *apriv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self); 
     166/** 
     167 * This utility function performs folder subscriptions/unsubscriptions 
     168 * since the code for both operations is almost the same. If the 
     169 * subscribe parameter is TRUE, then we're asking for a folder 
     170 * subscription, else for a folder unsubscription */ 
     171static void 
     172set_subscription (TnyStoreAccount *self, TnyFolder *folder, gboolean subscribe) 
     173
     174        TnyCamelAccountPriv *apriv; 
    172175        CamelException ex = CAMEL_EXCEPTION_INITIALISER; 
    173176        CamelStore *store; 
     
    175178        const gchar *folder_full_name; 
    176179 
    177         g_assert (TNY_IS_CAMEL_FOLDER (folder)); 
    178  
     180        apriv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self); 
     181 
     182        /* Get store */ 
    179183        g_static_rec_mutex_lock (apriv->service_lock); 
    180184        store = camel_session_get_store ((CamelSession*) apriv->session,  
     
    182186        g_static_rec_mutex_unlock (apriv->service_lock); 
    183187 
     188        if (!camel_store_supports_subscriptions (store))  
     189                goto cleanup; 
     190 
    184191        /* Retrieve the folder full name */ 
    185192        cfolder = tny_camel_folder_get_folder (TNY_CAMEL_FOLDER (folder)); 
    186193        folder_full_name = camel_folder_get_full_name (cfolder); 
    187194 
    188         if (camel_store_supports_subscriptions (store) 
    189             && !camel_store_folder_subscribed (store, folder_full_name)) { 
    190                  
     195        if (camel_store_folder_subscribed (store, folder_full_name) == subscribe) 
     196                goto cleanup; 
     197 
     198        /* Subscribe or unsubscribe */ 
     199        if (subscribe) 
    191200                camel_store_subscribe_folder (store, folder_full_name, &ex); 
    192  
    193                 if (camel_exception_is_set (&ex)) { 
    194                         g_warning (N_("Could not subscribe to folder %s: %s\n"), 
    195                                    tny_folder_get_name (folder),  
    196                                    camel_exception_get_description (&ex)); 
    197                         camel_exception_clear (&ex); 
    198                 } else { 
    199                         /* Sync */ 
    200                         _tny_camel_folder_set_subscribed (TNY_CAMEL_FOLDER (folder), TRUE); 
    201  
    202                         g_signal_emit (self,  
    203                                        tny_store_account_signals [TNY_STORE_ACCOUNT_SUBSCRIPTION_CHANGED],  
    204                                        0, folder); 
    205                 } 
    206         } 
    207  
    208         camel_object_unref (CAMEL_OBJECT (cfolder)); 
    209         camel_object_unref (CAMEL_OBJECT (store)); 
    210      
    211         return; 
    212 
    213  
    214 static void 
    215 tny_camel_store_account_unsubscribe (TnyStoreAccount *self, TnyFolder *folder) 
    216 
    217         TnyCamelAccountPriv *apriv = TNY_CAMEL_ACCOUNT_GET_PRIVATE (self); 
    218         CamelException ex = CAMEL_EXCEPTION_INITIALISER; 
    219         CamelStore *store; 
    220  
    221         g_assert (TNY_IS_CAMEL_FOLDER (folder)); 
    222  
    223         g_static_rec_mutex_lock (apriv->service_lock); 
    224         store = camel_session_get_store ((CamelSession*) apriv->session,  
    225                         apriv->url_string, &ex); 
    226         g_static_rec_mutex_unlock (apriv->service_lock); 
    227  
    228         camel_store_unsubscribe_folder (store, tny_folder_get_name (folder), &ex); 
     201        else 
     202                camel_store_unsubscribe_folder (store, folder_full_name, &ex); 
    229203 
    230204        if (camel_exception_is_set (&ex)) { 
    231                 g_warning (N_("Could not unsubscribe to folder %s: %s\n"), 
     205                g_warning (N_("Could not %s folder %s: %s\n"), 
     206                           subscribe ? _("subscribe to") : _("unsubscribe"), 
    232207                           tny_folder_get_name (folder),  
    233208                           camel_exception_get_description (&ex)); 
     
    235210        } else { 
    236211                /* Sync */ 
    237                 _tny_camel_folder_set_subscribed (TNY_CAMEL_FOLDER (folder), FALSE); 
    238  
     212                _tny_camel_folder_set_subscribed (TNY_CAMEL_FOLDER (folder), subscribe); 
     213                 
    239214                g_signal_emit (self,  
    240215                               tny_store_account_signals [TNY_STORE_ACCOUNT_SUBSCRIPTION_CHANGED],  
    241216                               0, folder); 
    242217        } 
    243  
    244         camel_object_unref (CAMEL_OBJECT (store)); 
    245  
    246         return; 
     218        camel_object_unref (CAMEL_OBJECT (cfolder)); 
     219 
     220cleanup: 
     221        camel_object_unref (CAMEL_OBJECT (store)); 
     222
     223 
     224static void 
     225tny_camel_store_account_subscribe (TnyStoreAccount *self, TnyFolder *folder) 
     226
     227        g_assert (TNY_IS_CAMEL_FOLDER (folder)); 
     228 
     229        set_subscription (self, folder, TRUE); 
     230
     231 
     232static void 
     233tny_camel_store_account_unsubscribe (TnyStoreAccount *self, TnyFolder *folder) 
     234
     235        g_assert (TNY_IS_CAMEL_FOLDER (folder)); 
     236 
     237        set_subscription (self, folder, FALSE); 
    247238} 
    248239 
  • trunk/libtinymail-gnome-desktop/tny-gnome-account-store.c

    r1107 r1212  
    415415                        if (options) 
    416416                        { 
     417                                GSList *tmp = options; 
    417418                                while (options) 
    418419                                { 
     
    421422                                        options = g_slist_next (options); 
    422423                                } 
    423                                 g_slist_free (options); 
     424                                g_slist_free (tmp); 
    424425                        } 
    425426