* implemented the send-queue stuff (partially); still
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Mon, 5 Feb 2007 10:44:19 +0000 (10:44 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Mon, 5 Feb 2007 10:44:19 +0000 (10:44 +0000)
  not fully working due to (apparently) a send mail bug

* gtk/modest-edit-msg-window.c:
- cleanup sending of message
* gtk/modest-account-assistant.c:
- generate better (unique) server_account names
* modest-conf.h:
- cosmetics
* modest-account-mgr-helpers.c:
- clear up the TnyGetAccountRequestType/TnyAccountType confusion
* modest-mail-operation.c:
- use the brand new send queue
* modest-runtime.[ch]:
- manage the SendQueue singleton-per-accounts
* modest-tny-send-queue.[ch]:
- minimalistic send queue implementation
* modest-cache-mgr.[ch]:
- add SendQueue as a cacheable type
* widgets/modest-folder-view.c:
- make resistant agains NULL names
* modest-tny-account-store.[ch]:
- fix some bugs (TnyGetAccountRequestType/TnyAccountType confusion)
- add sanity checking for types
- cleanups

pmo-trunk-r787

20 files changed:
src/gtk/modest-account-assistant.c
src/gtk/modest-edit-msg-window.c
src/modest-account-mgr-helpers.c
src/modest-cache-mgr.c
src/modest-cache-mgr.h
src/modest-conf.h
src/modest-mail-operation.c
src/modest-runtime.c
src/modest-runtime.h
src/modest-singletons.c
src/modest-singletons.h
src/modest-tny-account-store.c
src/modest-tny-account-store.h
src/modest-tny-account.c
src/modest-tny-send-queue.c
src/modest-tny-send-queue.h
src/widgets/modest-folder-view.c
src/widgets/modest-folder-view.h
src/widgets/modest-header-view-render.c
src/widgets/modest-header-view.c

index 3ad502b..a4fbaed 100644 (file)
@@ -593,11 +593,8 @@ get_new_server_account_name (ModestAccountMgr* acc_mgr, ModestProtocol proto,
        gint  i = 0;
        
        while (TRUE) {
-               name = g_strdup_printf ("%s:%s@%s:%d",
-                                       modest_protocol_info_get_protocol_name(proto),
-                                       username   ? username   : "<none>",
-                                       servername ? servername : "<none>",
-                                       i++);
+               name = g_strdup_printf ("%s:%d",
+                                       modest_protocol_info_get_protocol_name(proto), i++);
                if (modest_account_mgr_account_exists (acc_mgr, name, TRUE, NULL))
                        g_free (name);
                else
@@ -658,7 +655,8 @@ on_apply (ModestAccountAssistant *self, gpointer user_data)
        modest_account_mgr_add_account (priv->account_mgr,
                                        account_name,
                                        store_name,
-                                       NULL, NULL);
+                                       transport_name,
+                                       NULL);
        modest_account_mgr_set_string (priv->account_mgr,
                                       account_name,
                                       MODEST_ACCOUNT_FULLNAME,
index 1261ab4..977796c 100644 (file)
@@ -320,22 +320,31 @@ MsgData *
 modest_edit_msg_window_get_msg_data (ModestEditMsgWindow *edit_window)
 {
        MsgData *data;
-       ModestAccountData *account_data;
        GtkTextBuffer *buf;
        GtkTextIter b, e;
+       const gchar *account_name;
+       gchar *from_string = NULL;
        ModestEditMsgWindowPrivate *priv;
        
        g_return_val_if_fail (MODEST_IS_EDIT_MSG_WINDOW (edit_window), NULL);
 
        priv = MODEST_EDIT_MSG_WINDOW_GET_PRIVATE (edit_window);
        
-       account_data = modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->from_field));
+       account_name = (gchar*)modest_combo_box_get_active_id (MODEST_COMBO_BOX (priv->from_field));
+       if (account_name) 
+               from_string = modest_account_mgr_get_from_string (
+                       modest_runtime_get_account_mgr(), account_name);
+       if (!from_string) {
+               g_printerr ("modest: cannot get from string\n");
+               return NULL;
+       }
+       
        buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->msg_body));
        gtk_text_buffer_get_bounds (buf, &b, &e);
 
        /* don't free these (except from) */
        data = g_slice_new0 (MsgData);
-       data->from    =  g_strdup_printf ("%s <%s>", account_data->fullname, account_data->email) ;
+       data->from    =  from_string, /* will be freed when data is freed */
        data->to      =  (gchar*) gtk_entry_get_text (GTK_ENTRY(priv->to_field));
        data->cc      =  (gchar*) gtk_entry_get_text (GTK_ENTRY(priv->cc_field));
        data->bcc     =  (gchar*) gtk_entry_get_text (GTK_ENTRY(priv->bcc_field));
index e719c72..c540875 100644 (file)
@@ -251,22 +251,27 @@ modest_account_mgr_set_default_account  (ModestAccountMgr *self, const gchar* ac
 
 TnyAccount*
 modest_account_mgr_get_tny_account (ModestAccountMgr *self, const gchar* account_name,
-                                       TnyAccountType type)
+                                   TnyAccountType type)
 {
        TnyAccount      *account = NULL;
        TnyList         *accounts;
        TnyIterator     *iter;
        gchar           *server_account;
        const gchar     *conf_key;
+       TnyGetAccountsRequestType request_type;  /* really confusing.... */
        
        g_return_val_if_fail (self, NULL);
        g_return_val_if_fail (account_name, NULL);
 
        switch (type) {
        case TNY_ACCOUNT_TYPE_STORE:
-               conf_key = MODEST_ACCOUNT_STORE_ACCOUNT; break;
+               conf_key     = MODEST_ACCOUNT_STORE_ACCOUNT;
+               request_type = TNY_ACCOUNT_STORE_STORE_ACCOUNTS;
+               break;
        case TNY_ACCOUNT_TYPE_TRANSPORT:
-               conf_key = MODEST_ACCOUNT_TRANSPORT_ACCOUNT; break;
+               conf_key = MODEST_ACCOUNT_TRANSPORT_ACCOUNT;
+               request_type =  TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS;
+               break;
        default:
                g_return_val_if_reached (NULL);
        }
@@ -280,7 +285,7 @@ modest_account_mgr_get_tny_account (ModestAccountMgr *self, const gchar* account
        
        accounts = tny_simple_list_new ();
        tny_account_store_get_accounts (TNY_ACCOUNT_STORE(modest_runtime_get_account_store()),
-                                       accounts, type);        
+                                       accounts, request_type);
        iter = tny_list_create_iterator (accounts);     
        while (tny_iterator_is_done (iter)) {
                account = TNY_ACCOUNT(tny_iterator_get_current(iter));
index f35c286..6e64be6 100644 (file)
@@ -46,6 +46,7 @@ struct _ModestCacheMgrPrivate {
        GHashTable *date_str_cache;
        GHashTable *display_str_cache;
        GHashTable *pixbuf_cache;
+       GHashTable *send_queue_cache;
 };
 #define MODEST_CACHE_MGR_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                               MODEST_TYPE_CACHE_MGR, \
@@ -94,10 +95,10 @@ modest_cache_mgr_class_init (ModestCacheMgrClass *klass)
 
 
 static
-void pixbuf_unref (GObject *pixbuf)
+void my_object_unref (GObject *obj)
 {
-       if (pixbuf)
-               g_object_unref (pixbuf);
+       if (obj)
+               g_object_unref (obj);
 }
 
 static void
@@ -121,7 +122,13 @@ modest_cache_mgr_init (ModestCacheMgr *obj)
                g_hash_table_new_full (g_str_hash,   /* gchar* */
                                       g_str_equal,  
                                       g_free,       /* gchar*/
-                                      (GDestroyNotify)pixbuf_unref);
+                                      (GDestroyNotify)my_object_unref);
+       priv->send_queue_cache =
+               g_hash_table_new_full (g_direct_hash,   /* ptr */
+                                      g_direct_equal,  
+                                      (GDestroyNotify)my_object_unref,   /* ref'd GObject */
+                                      (GDestroyNotify)my_object_unref);   /* ref'd GObject */  
+
 }
 
 
@@ -139,6 +146,7 @@ modest_cache_mgr_finalize (GObject *obj)
        priv->date_str_cache    = NULL;
        priv->display_str_cache = NULL;
        priv->pixbuf_cache      = NULL;
+       priv->send_queue_cache  = NULL;
 
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
@@ -153,6 +161,8 @@ get_cache (ModestCacheMgrPrivate *priv, ModestCacheMgrCacheType type)
                return priv->display_str_cache;
        case MODEST_CACHE_MGR_CACHE_TYPE_PIXBUF:
                return priv->pixbuf_cache;
+       case MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE:
+               return priv->send_queue_cache;  
        default:
                g_return_val_if_reached(NULL); /* should not happen */
        }
index 32205e8..b656337 100644 (file)
@@ -61,6 +61,7 @@ typedef enum {
        MODEST_CACHE_MGR_CACHE_TYPE_DATE_STRING,       /* time_t => string */
        MODEST_CACHE_MGR_CACHE_TYPE_DISPLAY_STRING,    /* gchar* => gchar* */
        MODEST_CACHE_MGR_CACHE_TYPE_PIXBUF,            /* gchar* => GdkPixbuf */
+       MODEST_CACHE_MGR_CACHE_TYPE_SEND_QUEUE,        /* TnyAccount* => TnySendQueue* */
 
        MODEST_CACHE_MGR_CACHE_TYPE_NUM
 } ModestCacheMgrCacheType;
@@ -92,9 +93,7 @@ ModestCacheMgr*    modest_cache_mgr_new          (void);
  * 
  * get the cache (GHashTable) of the requested type
  * 
- * Returns: the requested cache (GHashTable) or NULL in case caching
- * has been disabled (MODEST_DEBUG_DISABLE_CACHE); clients are supposed
- * to handle that case
+ * Returns: the requested cache (GHashTable) 
  * 
  * the returned  hashtable should NOT be destroyed or unref'd.
  */
index 6581609..eee042b 100644 (file)
@@ -70,9 +70,9 @@ struct _ModestConfClass {
 /**
  * modest_conf_get_type:
  * 
- * get the GType for ModestConf
+ * get the #GType for #ModestConf
  *  
- * Returns: the GType
+ * Returns: the #GType
  */
 GType        modest_conf_get_type    (void) G_GNUC_CONST;
 
@@ -80,9 +80,9 @@ GType        modest_conf_get_type    (void) G_GNUC_CONST;
 /**
  * modest_conf_new:
  * 
- * create a new modest ModestConf object. 
+ * create a new modest #ModestConf object. 
  * 
- * Returns: a new ModestConf instance, or NULL in case
+ * Returns: a new #ModestConf instance, or NULL in case
  * of any error
  */
 ModestConf*     modest_conf_new         (void);
index 59d3509..afa4f5b 100644 (file)
@@ -40,6 +40,8 @@
 #include <camel/camel-stream-mem.h>
 #include <glib/gi18n.h>
 #include <modest-tny-account.h>
+#include <modest-tny-send-queue.h>
+#include <modest-runtime.h>
 #include "modest-text-utils.h"
 #include "modest-tny-msg.h"
 #include "modest-tny-platform-factory.h"
@@ -213,10 +215,14 @@ modest_mail_operation_send_mail (ModestMailOperation *self,
                                 TnyTransportAccount *transport_account,
                                 TnyMsg* msg)
 {
+       TnySendQueue *send_queue;
+       
        g_return_if_fail (MODEST_IS_MAIL_OPERATION (self));
        g_return_if_fail (TNY_IS_TRANSPORT_ACCOUNT (transport_account));
 
-       tny_transport_account_send (transport_account, msg, NULL); /* FIXME */
+       send_queue = TNY_SEND_QUEUE (modest_runtime_get_send_queue (transport_account));
+       
+       tny_send_queue_add (send_queue, msg);
 }
 
 void
@@ -273,7 +279,7 @@ modest_mail_operation_send_new_mail (ModestMailOperation *self,
        add_attachments (new_msg, (GList*) attachments_list);
 
        /* Send mail */
-       tny_transport_account_send (transport_account, new_msg, NULL); /* FIXME */
+       modest_mail_operation_send_mail (self, transport_account, new_msg);
 
        /* Clean */
        g_object_unref (header);
index be73102..6fab641 100644 (file)
@@ -238,6 +238,29 @@ modest_runtime_get_widget_factory     (void)
 }
 
 
+ModestTnySendQueue*
+modest_runtime_get_send_queue  (TnyTransportAccount *account)
+{
+       ModestCacheMgr *cache_mgr;
+       GHashTable     *send_queue_cache;
+       gpointer       orig_key, send_queue;
+       
+       g_return_val_if_fail (_singletons, NULL);
+       g_return_val_if_fail (!TNY_IS_TRANSPORT_ACCOUNT(account), NULL);
+
+       cache_mgr = modest_singletons_get_cache_mgr (_singletons);
+       send_queue_cache = modest_cache_mgr_get_cache (cache_mgr,
+                                                      MODEST_CACHE_MGR_CACHE_TYPE_PIXBUF);
+       if (!g_hash_table_lookup_extended (send_queue_cache, account, &orig_key, &send_queue)) {
+               send_queue = (gpointer)modest_tny_send_queue_new (TNY_CAMEL_TRANSPORT_ACCOUNT(account));
+               g_hash_table_insert (send_queue_cache, account, send_queue);
+       }
+
+       return MODEST_TNY_SEND_QUEUE(send_queue);
+}
+
+
+
 
 /* http://primates.ximian.com/~federico/news-2006-04.html#memory-debugging-infrastructure*/
 ModestRuntimeDebugFlags
index 9097eb4..be84fbb 100644 (file)
@@ -38,6 +38,7 @@
 #include <modest-mail-operation-queue.h>
 #include <modest-tny-account-store.h>
 #include <modest-widget-factory.h>
+#include <modest-tny-send-queue.h>
 
 G_BEGIN_DECLS
 
@@ -152,23 +153,37 @@ ModestCacheMgr*           modest_runtime_get_cache_mgr     (void);
 /**
  * modest_runtime_get_mail_operation_queue:
  * 
- * get the ModestMailOperationQueue singleton instance
+ * get the #ModestMailOperationQueue singleton instance
  *
- * Returns: the ModestMailOperationQueue singleton
+ * Returns: the #ModestMailOperationQueue singleton
  **/
 ModestMailOperationQueue* modest_runtime_get_mail_operation_queue (void);
 
 
 /**
- * modest_runtime_get_widget_factory
+ * modest_runtime_get_widget_factory:
  * 
- * get the ModestWidgetFactory singleton instance
+ * get the #ModestWidgetFactory singleton instance
  *
- * Returns: the ModestCacheMgr singleton
+ * Returns: the #ModestCacheMgr singleton
  **/
 ModestWidgetFactory*      modest_runtime_get_widget_factory     (void);
 
 
+
+/**
+ * modest_runtime_get_send_queue:
+ * @account: a valid TnyTransportAccount
+ * 
+ * get the send queue for the given account
+ *
+ * Returns: the #ModestTnySendQueue singleton instance for this account
+ * (ie., one singleton per account)
+ **/
+ModestTnySendQueue* modest_runtime_get_send_queue        (TnyTransportAccount *account);
+
+
+
 G_END_DECLS
 
 #endif /*__MODEST_RUNTIME_H__*/
index 2915a0f..e7b15d9 100644 (file)
@@ -260,3 +260,4 @@ modest_singletons_get_widget_factory (ModestSingletons *self)
        }
        return priv->widget_factory;
 }
+
index 2d90a17..d71ab6f 100644 (file)
@@ -88,6 +88,7 @@ ModestSingletons*    modest_singletons_new         (void);
 
 /**
  * modest_singletons_get_conf:
+ * @self: a valid ModestSingletons instance
  * 
  * get the ModestConf singleton instance
  * don't use this function directly, use the modest-runtime
@@ -100,6 +101,7 @@ ModestConf*               modest_singletons_get_conf          (ModestSingletons
 
 /**
  * modest_singletons_get_account_mgr:
+ * @self: a valid ModestSingletons instance
  * 
  * get the ModestAccountMgr singleton instance
  * don't use this function directly, use the modest-runtime
@@ -112,53 +114,53 @@ ModestAccountMgr*         modest_singletons_get_account_mgr   (ModestSingletons
 
 /**
  * modest_singletons_get_account_store:
+ * @self: a valid #ModestSingletons instance
  * 
- * get the ModestTnyAccountStore singleton instance
+ * get the #ModestTnyAccountStore singleton instance
  * don't use this function directly, use the modest-runtime
  * functions instead.
  *
- * Returns: the ModestTnyAccountStore singleton
+ * Returns: the #ModestTnyAccountStore singleton
  **/
 ModestTnyAccountStore*    modest_singletons_get_account_store (ModestSingletons *self);
 
 
 /**
- * modest_singletons_get_cache_mgr:
+ * modest_singletons_get_widget_factory:
+ * @self: a valid #ModestSingletons instance
  * 
- * get the ModestCacheMgr singleton instance
+ * get the #ModestWidgetFactory singleton instance
  * don't use this function directly, use the modest-runtime
  * functions instead.
  *
- * Returns: the ModestCacheMgr singleton
+ * Returns: the #ModestWidgetFactory singleton
  **/
-ModestCacheMgr*           modest_singletons_get_cache_mgr     (ModestSingletons *self);
-
+ModestWidgetFactory* modest_singletons_get_widget_factory (ModestSingletons *self);
 
 /**
- * modest_singletons_get_mail_operation_queue:
+ * modest_singletons_get_cache_mgr:
+ * @self: a valid #ModestSingletons instance
  * 
- * get the ModestMailOperationQueue singleton instance
+ * get the #ModestCacheMgr singleton instance
  * don't use this function directly, use the modest-runtime
  * functions instead.
  *
- * Returns: the ModestMailOperationQueue singleton
+ * Returns: the #ModestCacheMgr singleton
  **/
-ModestMailOperationQueue* modest_singletons_get_mail_operation_queue (ModestSingletons *self);
-
-
+ModestCacheMgr*           modest_singletons_get_cache_mgr     (ModestSingletons *self);
 
 
 /**
- * modest_singletons_get_widget_factory:
+ * modest_singletons_get_mail_operation_queue:
+ * @self: a valid ModestSingletons instance
  * 
- * get the ModestWidgetFactory singleton instance
+ * get the ModestMailOperationQueue singleton instance
  * don't use this function directly, use the modest-runtime
  * functions instead.
  *
- * Returns: the ModestWidgetFactory singleton
+ * Returns: the ModestMailOperationQueue singleton
  **/
-ModestWidgetFactory* modest_singletons_get_widget_factory (ModestSingletons *self);
-
+ModestMailOperationQueue* modest_singletons_get_mail_operation_queue (ModestSingletons *self);
 
 G_END_DECLS
 
index 98d63c7..19d5b46 100644 (file)
@@ -402,38 +402,11 @@ forget_password (TnyAccount *account)
                                  TRUE, NULL);
 }
 
-
-
-/* instantiate the correct tny account subclass */
-static TnyAccount*
-tny_account_for_proto (ModestProtocol proto) 
-{
-       ModestProtocolType type;        
-       TnyAccount *tny_account = NULL;
-       
-       type  = modest_protocol_info_get_protocol_type (proto);
-       
-       if (type == MODEST_PROTOCOL_TYPE_TRANSPORT) 
-               tny_account = TNY_ACCOUNT(tny_camel_transport_account_new ());
-       else if (proto == MODEST_PROTOCOL_STORE_POP)
-               tny_account = TNY_ACCOUNT(tny_camel_pop_store_account_new ());
-       else if (proto == MODEST_PROTOCOL_STORE_IMAP)
-               tny_account = TNY_ACCOUNT(tny_camel_imap_store_account_new ());
-       else if (proto == MODEST_PROTOCOL_STORE_MAILDIR || proto == MODEST_PROTOCOL_STORE_MBOX)
-               tny_account = TNY_ACCOUNT(tny_camel_store_account_new());
-       else
-               g_return_val_if_reached (NULL);
-       
-       return tny_account;
-}
-
-
 /* create a tnyaccount for the server account connected to the account with name 'key'
  */
 static TnyAccount*
 get_tny_account_from_server_account (ModestTnyAccountStore *self,
-                                    ModestServerAccountData *account_data,
-                                    ModestProtocolType modest_type)
+                                    ModestServerAccountData *account_data, TnyAccountType type)
 {
        TnyAccount *tny_account;
        ModestTnyAccountStorePrivate *priv;
@@ -443,20 +416,50 @@ get_tny_account_from_server_account (ModestTnyAccountStore *self,
 
        priv = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
        
-       /* proto */
+       /* sanity checks */
        if (account_data->proto == MODEST_PROTOCOL_UNKNOWN) {
                g_printerr ("modest: '%s' does not provide a protocol\n",
                            account_data->account_name);
                return NULL;
        }
-       tny_account = tny_account_for_proto (account_data->proto);
+       if ((account_data->proto == MODEST_PROTOCOL_TYPE_TRANSPORT && type != TNY_ACCOUNT_TYPE_TRANSPORT) ||
+           (account_data->proto == MODEST_PROTOCOL_TYPE_STORE     && type != TNY_ACCOUNT_TYPE_STORE)) {
+               g_printerr ("modest: protocol types do not match <%d,%d>\n", account_data->proto, type);
+               return NULL;
+       }
+       
+       switch (account_data->proto) {
+       case MODEST_PROTOCOL_TRANSPORT_SENDMAIL:
+       case MODEST_PROTOCOL_TRANSPORT_SMTP:
+               tny_account = TNY_ACCOUNT(tny_camel_transport_account_new ()); break;
+       case MODEST_PROTOCOL_STORE_POP:
+               tny_account = TNY_ACCOUNT(tny_camel_pop_store_account_new ()); break;
+       case MODEST_PROTOCOL_STORE_IMAP:
+               tny_account = TNY_ACCOUNT(tny_camel_imap_store_account_new ()); break;
+       case MODEST_PROTOCOL_STORE_MAILDIR:
+       case MODEST_PROTOCOL_STORE_MBOX:
+               tny_account = TNY_ACCOUNT(tny_camel_store_account_new()); break;
+       default:
+               g_return_val_if_reached (NULL);
+       }
+
        if (!tny_account) {
                g_printerr ("modest: could not create tny account for '%s'\n",
                            account_data->account_name);
                return NULL;
        }
        tny_account_set_id (tny_account, account_data->account_name);
-       tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account),  priv->tny_session_camel);
+
+       /*
+        * FIXME --> bug in tinymail
+        */
+       if (type == TNY_ACCOUNT_TYPE_TRANSPORT) {
+               g_printerr ("modest: BUG: cannot create transports accounts... stay tuned\n");
+               g_object_unref (G_OBJECT(tny_account));
+               return NULL;
+       }
+       
+       tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account), priv->tny_session_camel);
        tny_account_set_forget_pass_func (tny_account, forget_password);
        tny_account_set_pass_func (tny_account, get_password);
 
@@ -465,7 +468,6 @@ get_tny_account_from_server_account (ModestTnyAccountStore *self,
                               modest_protocol_info_get_protocol_name(account_data->proto));
        g_object_set_data (G_OBJECT(tny_account), "account_store", (gpointer)self);
 
-
        if (account_data->uri) 
                tny_account_set_url_string (TNY_ACCOUNT(tny_account), account_data->uri);
        else {
@@ -554,51 +556,35 @@ modest_tny_account_store_new (ModestAccountMgr *account_mgr) {
        return MODEST_TNY_ACCOUNT_STORE(obj);
 }
 
-static void
-modest_tny_account_store_add_store_account  (TnyAccountStore *self,
-                                            TnyStoreAccount *account)
-{
-       /* we should not need this...*/
-       g_printerr ("modest: add_store_account_func not implemented\n");
-}
-
-
-static void
-modest_tny_account_store_add_transport_account  (TnyAccountStore *self,
-                                                TnyTransportAccount *account)
-{      
-       /* we should not need this...*/
-       g_printerr ("modest: add_transport_account_func not implemented\n");
-}
-
-
 
 static TnyAccount*
 get_tny_account_from_account (ModestTnyAccountStore *self, ModestAccountData *account_data,
-                             TnyGetAccountsRequestType type) 
+                             TnyAccountType type) 
 {
        TnyAccount *tny_account = NULL;
        ModestServerAccountData *server_account = NULL;
 
-       if (type == TNY_ACCOUNT_STORE_STORE_ACCOUNTS && account_data->store_account)
+       if (type == TNY_ACCOUNT_TYPE_STORE && account_data->store_account)
                server_account = account_data->store_account;
-       else if (type == TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS && account_data->transport_account)
+       else if (type == TNY_ACCOUNT_TYPE_TRANSPORT && account_data->transport_account)
                server_account = account_data->transport_account;
        
        if (!server_account) {
                g_printerr ("modest: no %s account defined for '%s'\n",
-                           type == TNY_ACCOUNT_STORE_STORE_ACCOUNTS ? "store" : "transport",
+                           type == TNY_ACCOUNT_TYPE_STORE ? "store" : "transport",
                            account_data->display_name);
                return NULL;
        }
        
        tny_account = get_tny_account_from_server_account (self, server_account, type);
        if (!tny_account) { 
-               g_printerr ("modest: failed to create tny account for %s\n",
-                           account_data->account_name);
+               g_printerr ("modest: failed to create tny account for %s (%s)\n",
+                           account_data->account_name, server_account->account_name);
                return NULL;
        }
-       
+
+       /* this name is what shows up in the folder view -- so for some POP/IMAP/... server
+        * account, we set its name to the acount of which it is part */
        if (account_data->display_name)
                tny_account_set_name (tny_account, account_data->display_name); 
        
@@ -608,19 +594,23 @@ get_tny_account_from_account (ModestTnyAccountStore *self, ModestAccountData *ac
 
 static void
 modest_tny_account_store_get_accounts  (TnyAccountStore *account_store, TnyList *list,
-                                       TnyGetAccountsRequestType type)
+                                       TnyGetAccountsRequestType request_type)
 {
+       TnyAccountType               type;
        ModestTnyAccountStore        *self;
        ModestTnyAccountStorePrivate *priv;
        GSList                       *accounts, *cursor;
        
        g_return_if_fail (account_store);
        g_return_if_fail (TNY_IS_LIST(list));
-
+       g_return_if_fail (request_type == TNY_ACCOUNT_STORE_STORE_ACCOUNTS ||
+                         request_type == TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS ||
+                         request_type == TNY_ACCOUNT_STORE_BOTH);
+       
        self        = MODEST_TNY_ACCOUNT_STORE(account_store);
        priv        = MODEST_TNY_ACCOUNT_STORE_GET_PRIVATE(self);
        
-       if (type == TNY_ACCOUNT_STORE_BOTH) {
+       if (request_type == TNY_ACCOUNT_STORE_BOTH) {
                modest_tny_account_store_get_accounts (account_store, list,
                                                       TNY_ACCOUNT_STORE_STORE_ACCOUNTS);
                modest_tny_account_store_get_accounts (account_store, list,
@@ -628,6 +618,15 @@ modest_tny_account_store_get_accounts  (TnyAccountStore *account_store, TnyList
                return;
        }
 
+       /*
+        * confusingly, tinymail uses both TnyAccountRequestType and TnyAccountType
+        */
+       switch (request_type) {
+       case TNY_ACCOUNT_STORE_STORE_ACCOUNTS    : type = TNY_ACCOUNT_TYPE_STORE; break;
+       case TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS: type = TNY_ACCOUNT_TYPE_TRANSPORT; break;
+       default: g_return_if_reached (); /* 'BOTH' is not possible here */
+       }
+       
        accounts = modest_account_mgr_account_names (priv->account_mgr, NULL); 
        for (cursor = accounts; cursor; cursor = cursor->next) {
                TnyAccount *tny_account = NULL;
@@ -636,8 +635,10 @@ modest_tny_account_store_get_accounts  (TnyAccountStore *account_store, TnyList
                                                             (gchar*)cursor->data);
                if (account_data && account_data->is_enabled) {
                        tny_account = get_tny_account_from_account (self, account_data, type);
-                       if (tny_account)
+                       if (tny_account) {
                                tny_list_prepend (list, G_OBJECT(tny_account));
+                               g_object_unref (G_OBJECT(tny_account));
+                       }
                }
                g_free (cursor->data);
                modest_account_mgr_free_account_data (priv->account_mgr, account_data);
@@ -645,12 +646,12 @@ modest_tny_account_store_get_accounts  (TnyAccountStore *account_store, TnyList
        g_slist_free (accounts);
 
        /* also, add the local folder pseudo-account */
-       if (type != TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS) {
+       if (request_type != TNY_ACCOUNT_STORE_TRANSPORT_ACCOUNTS) {
                if (!priv->local_folders)
                        priv->local_folders = get_local_folders_account (self);
                if (!priv->local_folders)
                        g_printerr ("modest: no local folders account\n");
-               else
+               else 
                        tny_list_prepend (list, G_OBJECT(priv->local_folders));
        }
 }
@@ -723,6 +724,26 @@ modest_tny_account_store_alert (TnyAccountStore *self, TnyAlertType type,
 }
 
 
+
+static void
+modest_tny_account_store_add_store_account  (TnyAccountStore *self,
+                                            TnyStoreAccount *account)
+{
+       /* we should not need this...*/
+       g_printerr ("modest: add_store_account_func not implemented\n");
+}
+
+
+static void
+modest_tny_account_store_add_transport_account  (TnyAccountStore *self,
+                                                TnyTransportAccount *account)
+{      
+       /* we should not need this...*/
+       g_printerr ("modest: add_transport_account_func not implemented\n");
+}
+
+
+
 static void
 modest_tny_account_store_init (gpointer g, gpointer iface_data)
 {
index 5bc3723..861209a 100644 (file)
@@ -69,8 +69,6 @@ struct _ModestTnyAccountStoreClass {
                                   gpointer user_data);
 };
 
-/* member functions */
-
 /**
  * modest_tny_account_store_get_type:
  *
index 4053808..88a90ac 100644 (file)
@@ -81,3 +81,5 @@ modest_tny_account_get_special_folder (TnyAccount *account,
 
        return special_folder;
 }
+
+
index 2c238f2..11d31af 100644 (file)
@@ -37,7 +37,6 @@
 
 /* 'private'/'protected' functions */
 static void modest_tny_send_queue_class_init (ModestTnySendQueueClass *klass);
-static void modest_tny_send_queue_init       (gpointer g, gpointer iface_data);
 static void modest_tny_send_queue_finalize   (GObject *obj);
 static void modest_tny_send_queue_instance_init (GTypeInstance *instance, gpointer g_class);
 
@@ -50,16 +49,13 @@ enum {
 
 typedef struct _ModestTnySendQueuePrivate ModestTnySendQueuePrivate;
 struct _ModestTnySendQueuePrivate {
-       TnyTransportAccount *account;
-       GThread *flush_outbox_thread;
-       GMutex  *flush_lock;
-       
+       TnyCamelTransportAccount *account;      
 };
 #define MODEST_TNY_SEND_QUEUE_GET_PRIVATE(o)      (G_TYPE_INSTANCE_GET_PRIVATE((o), \
                                                    MODEST_TYPE_TNY_SEND_QUEUE, \
                                                    ModestTnySendQueuePrivate))
 /* globals */
-static GObjectClass *parent_class = NULL;
+static TnyCamelSendQueueClass *parent_class = NULL;
 
 /* uncomment the following if you have defined any signals */
 /* static guint signals[LAST_SIGNAL] = {0}; */
@@ -68,111 +64,31 @@ static GObjectClass *parent_class = NULL;
 /*
  * this thread actually tries to send all the mails in the outbox
  */
-static void
-flush_outbox_thread (TnySendQueue *self)
-{
-       TnyFolder *outbox, *sentbox;
-       TnyMsg    *msg;
-       TnyHeader *header;
-
-       TnyList *headers;               
-       TnyIterator *iter;
-
-       ModestTnySendQueuePrivate *priv;
-
-       priv    = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
-
-       outbox  = tny_send_queue_get_outbox (self);
-       sentbox = tny_send_queue_get_sentbox (self);
-       
-       headers = tny_simple_list_new ();
-
-       g_mutex_lock (priv->flush_lock);
-       tny_folder_get_headers (outbox, headers, TRUE, NULL); /* FIXME: err */
-       iter = tny_list_create_iterator (headers);
-
-       while (!tny_iterator_is_done (iter)) {
-               header = TNY_HEADER(tny_iterator_get_current(iter));
-               msg = tny_folder_get_msg (outbox, header, NULL);        
-               tny_transport_account_send (priv->account,
-                                           msg, NULL); /* FIXME: err */
-               tny_folder_add_msg    (sentbox, msg, NULL); /* FIXME: err */
-               tny_folder_remove_msg (outbox, header, NULL); /* FIXME: err */
-
-               g_object_unref (G_OBJECT(header));
-               g_object_unref (G_OBJECT(msg));
-
-               tny_iterator_next (iter);
-       }
-       
-       
-       g_object_unref (G_OBJECT(headers));
-       g_object_unref (G_OBJECT(iter));
-
-       priv->flush_outbox_thread = NULL;
-       g_mutex_unlock (priv->flush_lock);
-       
-       g_thread_exit (NULL);
-}
 
 
 static void
 modest_tny_send_queue_cancel (TnySendQueue *self, gboolean remove)
 {
-       MODEST_TNY_SEND_QUEUE_GET_CLASS(self)->cancel_func (self, remove);
+       TNY_CAMEL_SEND_QUEUE_GET_CLASS(parent_class)->cancel_func (self, remove);
 }
 
 static void
 modest_tny_send_queue_add (TnySendQueue *self, TnyMsg *msg)
 {
-       MODEST_TNY_SEND_QUEUE_GET_CLASS(self)->add_func (self, msg);
-}
-
-
-static TnyFolder*
-modest_tny_send_queue_get_sentbox (TnySendQueue *self)
-{
-       return MODEST_TNY_SEND_QUEUE_GET_CLASS(self)->get_sentbox_func (self);
-}
-
-
-static TnyFolder*
-modest_tny_send_queue_get_outbox (TnySendQueue *self)
-{
-       return MODEST_TNY_SEND_QUEUE_GET_CLASS(self)->get_outbox_func (self);
-}
-
-
-
-
-static void
-modest_tny_send_queue_cancel_default (TnySendQueue *self, gboolean remove)
-{
-       /* FIXME */
-}
-
-
-static void
-modest_tny_send_queue_add_default (TnySendQueue *self, TnyMsg *msg)
-{
        ModestTnySendQueuePrivate *priv; 
-       TnyFolder *outbox;
        
        g_return_if_fail (self);
        g_return_if_fail (TNY_IS_CAMEL_MSG(msg));
        
        priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
-       
-       outbox = tny_send_queue_get_outbox (self);
-       tny_folder_add_msg (outbox, msg, NULL);
 
-       priv->flush_outbox_thread = g_thread_create (
-               (GThreadFunc)flush_outbox_thread,
-               self, FALSE, NULL);
+       /* FIXME: do something smart here... */
+               
+       TNY_CAMEL_SEND_QUEUE_GET_CLASS(parent_class)->add_func (self, msg);
 }
 
 static TnyFolder*
-modest_tny_send_queue_get_sentbox_default (TnySendQueue *self)
+modest_tny_send_queue_get_sentbox (TnySendQueue *self)
 {
        ModestTnySendQueuePrivate *priv; 
 
@@ -186,7 +102,7 @@ modest_tny_send_queue_get_sentbox_default (TnySendQueue *self)
 
 
 static TnyFolder*
-modest_tny_send_queue_get_outbox_default (TnySendQueue *self)
+modest_tny_send_queue_get_outbox (TnySendQueue *self)
 {
        ModestTnySendQueuePrivate *priv; 
 
@@ -204,14 +120,7 @@ modest_tny_send_queue_get_type (void)
 {
        static GType my_type = 0;
 
-       if (G_UNLIKELY (!camel_type_init_done)) {
-               if (!g_thread_supported ()) 
-                       g_thread_init (NULL);
-               camel_type_init ();
-               camel_type_init_done = TRUE;
-       }
-       
-       if (!my_type) {
+       if (my_type == 0) {
                static const GTypeInfo my_info = {
                        sizeof(ModestTnySendQueueClass),
                        NULL,           /* base init */
@@ -220,43 +129,19 @@ modest_tny_send_queue_get_type (void)
                        NULL,           /* class finalize */
                        NULL,           /* class data */
                        sizeof(ModestTnySendQueue),
-                       1,              /* n_preallocs */
+                       0,              /* n_preallocs */
                        (GInstanceInitFunc) modest_tny_send_queue_instance_init,
                        NULL
                };
-
-               static const GInterfaceInfo tny_send_queue_info = {
-                       (GInterfaceInitFunc) modest_tny_send_queue_init,
-                       /* interface_init */
-                       NULL,         /* interface_finalize */
-                       NULL          /* interface_data */
-               };
-       
                my_type = g_type_register_static (G_TYPE_OBJECT,
                                                  "ModestTnySendQueue",
-                                                 &my_info, 0);
-               g_type_add_interface_static (my_type, TNY_TYPE_SEND_QUEUE,
-                                            &tny_send_queue_info);
+                                                 &my_info, 0);
        }
-       
        return my_type;
 }
 
 
 static void
-modest_tny_send_queue_init (gpointer g, gpointer iface_data)
-{
-       TnySendQueueIface *klass = (TnySendQueueIface*)g;
-       
-       klass->add_func         = modest_tny_send_queue_add;
-       klass->get_outbox_func  = modest_tny_send_queue_get_outbox;
-        klass->get_sentbox_func = modest_tny_send_queue_get_sentbox;
-        klass->cancel_func      = modest_tny_send_queue_cancel;
-}
-
-
-
-static void
 modest_tny_send_queue_class_init (ModestTnySendQueueClass *klass)
 {
        GObjectClass *gobject_class;
@@ -266,10 +151,10 @@ modest_tny_send_queue_class_init (ModestTnySendQueueClass *klass)
        parent_class            = g_type_class_peek_parent (klass);
        gobject_class->finalize = modest_tny_send_queue_finalize;
 
-       klass->add_func         = modest_tny_send_queue_add_default;
-       klass->get_outbox_func  = modest_tny_send_queue_get_outbox_default;
-        klass->get_sentbox_func = modest_tny_send_queue_get_sentbox_default;
-        klass->cancel_func      = modest_tny_send_queue_cancel_default;
+       parent_class->add_func         = modest_tny_send_queue_add;
+       parent_class->get_outbox_func  = modest_tny_send_queue_get_outbox;
+        parent_class->get_sentbox_func = modest_tny_send_queue_get_sentbox;
+        parent_class->cancel_func      = modest_tny_send_queue_cancel;
 
        g_type_class_add_private (gobject_class, sizeof(ModestTnySendQueuePrivate));
 }
@@ -283,8 +168,6 @@ modest_tny_send_queue_instance_init (GTypeInstance *instance, gpointer g_class)
        self = (ModestTnySendQueue*)instance;
        priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
 
-       priv->flush_lock          = g_mutex_new ();
-       priv->flush_outbox_thread = NULL;
        priv->account = NULL;
 }
 
@@ -299,21 +182,16 @@ modest_tny_send_queue_finalize (GObject *obj)
                priv->account = NULL;
        }
 
-       if (priv->flush_lock) {
-               g_mutex_free (priv->flush_lock);
-               priv->flush_lock = NULL;
-       }
-       
        G_OBJECT_CLASS(parent_class)->finalize (obj);
 }
 
 ModestTnySendQueue*
-modest_tny_send_queue_new (TnyTransportAccount *account)
+modest_tny_send_queue_new (TnyCamelTransportAccount *account)
 {
        ModestTnySendQueue *self;
        ModestTnySendQueuePrivate *priv;
 
-       g_return_val_if_fail (account, NULL);
+       g_return_val_if_fail (TNY_IS_CAMEL_TRANSPORT_ACCOUNT(account), NULL);
        
        self = MODEST_TNY_SEND_QUEUE(g_object_new(MODEST_TYPE_TNY_SEND_QUEUE, NULL));
        priv = MODEST_TNY_SEND_QUEUE_GET_PRIVATE (self);
index fc82ed7..0af775a 100644 (file)
@@ -34,6 +34,7 @@
 #include <glib.h>
 #include <glib-object.h>
 #include <tny-send-queue.h>
+#include <tny-camel-send-queue.h>
 #include <tny-msg.h>
 #include <tny-camel-transport-account.h>
 
@@ -51,24 +52,33 @@ typedef struct _ModestTnySendQueue      ModestTnySendQueue;
 typedef struct _ModestTnySendQueueClass ModestTnySendQueueClass;
 
 struct _ModestTnySendQueue {
-       GObject  parent;
+       TnyCamelSendQueue  parent;
 };
 
 struct _ModestTnySendQueueClass {
-       GObjectClass parent_class;
-       
-        void (*add_func)               (TnySendQueue *self, TnyMsg *msg);
-        TnyFolder* (*get_sentbox_func) (TnySendQueue *self);
-        TnyFolder* (*get_outbox_func)  (TnySendQueue *self);
-        void (*cancel_func)            (TnySendQueue *self, gboolean remove);  
+       TnyCamelSendQueueClass parent_class;
 };
 
-/* member functions */
+/**
+ * modest_tny_send_queue_get_type:
+ * 
+ * get the #GType for #ModestTnySendQueue
+ *  
+ * Returns: the #GType
+ */
 GType        modest_tny_send_queue_get_type    (void) G_GNUC_CONST;
 
-/* typical parameter-less _new function */
-/* if this is a kind of GtkWidget, it should probably return at GtkWidget* */
-ModestTnySendQueue*    modest_tny_send_queue_new         (TnyTransportAccount *account);
+
+/**
+ * modest_tny_send_queue_new:
+ * @account: a valid camel transport account
+ * 
+ * create a new modest #ModestTnySendQueue object. 
+ * 
+ * Returns: a new #ModestTnySendQueue instance, or NULL in case
+ * of any error
+ */
+ModestTnySendQueue*    modest_tny_send_queue_new        (TnyCamelTransportAccount *account);
 
 G_END_DECLS
 
index 9bdb0df..cf5fae0 100644 (file)
@@ -590,9 +590,9 @@ cmp_rows (GtkTreeModel *tree_model, GtkTreeIter *iter1, GtkTreeIter *iter2,
        if (type == TNY_FOLDER_TYPE_ROOT) {
                /* the account name is also the name of the root folder
                 * in case of local folders */
-               if (strcmp (name1, MODEST_LOCAL_FOLDERS_ACCOUNT_NAME) == 0)
+               if (name1 && strcmp (name1, MODEST_LOCAL_FOLDERS_ACCOUNT_NAME) == 0)
                        cmp = +1;
-               else if (strcmp (name2, MODEST_LOCAL_FOLDERS_ACCOUNT_NAME) == 0)
+               else if (name2 && strcmp (name2, MODEST_LOCAL_FOLDERS_ACCOUNT_NAME) == 0)
                        cmp = -1;
                else 
                        cmp = modest_text_utils_utf8_strcmp (name1, name2, TRUE);
index da31e4b..e99dfd9 100644 (file)
@@ -116,7 +116,7 @@ TnyFolder*    modest_folder_view_get_selected    (ModestFolderView *self);
  * modest_folder_view_update_model:
  * @self: a #ModestFolderView
  * 
- * returns a new reference to the #TnyFolder that is already selected
+ * refresh the current model
  * 
  * Returns: the selected folder or NULL if none is selected
  **/
index 2031c5d..47c97b5 100644 (file)
@@ -27,7 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-
 #include <modest-header-view.h>
 #include <modest-header-view-priv.h>
 #include <modest-icon-names.h>
@@ -52,7 +51,7 @@ get_cached_icon (const gchar *name)
        if (!icon_cache || !g_hash_table_lookup_extended (icon_cache, name, &orig_key,&pixbuf)) {
                pixbuf = (gpointer)gdk_pixbuf_new_from_file (name, &err);
                if (!pixbuf) {
-                       g_printerr ("modest: error in icon factory while loading '%s': %s\n",
+                       g_printerr ("modest: error while loading '%s': %s\n",
                                    name, err->message);
                        g_error_free (err);
                }
index 35b9def..c3fe409 100644 (file)
@@ -48,15 +48,6 @@ static void on_selection_changed (GtkTreeSelection *sel, gpointer user_data);
 static gint cmp_rows (GtkTreeModel *tree_model, GtkTreeIter *iter1, GtkTreeIter *iter2,
                      gpointer user_data);
 
-#define MODEST_HEADER_VIEW_PTR "modest-header-view"
-
-enum {
-       HEADER_SELECTED_SIGNAL,
-       ITEM_NOT_FOUND_SIGNAL,
-       STATUS_UPDATE_SIGNAL,
-       LAST_SIGNAL
-};
-
 
 typedef struct _ModestHeaderViewPrivate ModestHeaderViewPrivate;
 struct _ModestHeaderViewPrivate {
@@ -70,6 +61,17 @@ struct _ModestHeaderViewPrivate {
                                                MODEST_TYPE_HEADER_VIEW, \
                                                 ModestHeaderViewPrivate))
 
+
+
+#define MODEST_HEADER_VIEW_PTR "modest-header-view"
+
+enum {
+       HEADER_SELECTED_SIGNAL,
+       ITEM_NOT_FOUND_SIGNAL,
+       STATUS_UPDATE_SIGNAL,
+       LAST_SIGNAL
+};
+
 /* globals */
 static GObjectClass *parent_class = NULL;