* Added comparisons with "Invalid" string <- should be fixed in tinymail
authorSergio Villar Senin <svillar@igalia.com>
Thu, 25 Jan 2007 11:55:15 +0000 (11:55 +0000)
committerSergio Villar Senin <svillar@igalia.com>
Thu, 25 Jan 2007 11:55:15 +0000 (11:55 +0000)
* Replaced the date generation code, now it creates valid UTF8 strings

pmo-trunk-r736

src/gtk/modest-edit-msg-window.c
src/modest-mail-operation.c
src/modest-text-utils.c
src/modest-text-utils.h
src/modest-ui.c

index e2a4d0a..018a4c6 100644 (file)
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 #include <glib/gi18n.h>
+#include <string.h>
 #include <tny-account-store.h>
+#include <tny-simple-list.h>
 
-#include <modest-account-mgr.h>
-#include <modest-account-mgr-helpers.h>
-
+#include "modest-account-mgr.h"
+#include "modest-account-mgr-helpers.h"
 #include "modest-edit-msg-window.h"
 #include "modest-edit-msg-window-ui.h"
 #include "modest-icon-names.h"
 #include "modest-icon-factory.h"
-#include "modest-widget-memory.h"
-#include "modest-window-priv.h"
 #include "modest-mail-operation.h"
+#include "modest-text-utils.h"
 #include "modest-tny-platform-factory.h"
 #include "modest-tny-msg-actions.h"
-#include <tny-simple-list.h>
 #include "modest-ui-actions.h"
+#include "modest-widget-memory.h"
+#include "modest-window-priv.h"
 
 static void  modest_edit_msg_window_class_init   (ModestEditMsgWindowClass *klass);
 static void  modest_edit_msg_window_init         (ModestEditMsgWindow *obj);
@@ -318,12 +319,14 @@ modest_edit_msg_window_set_msg (ModestEditMsgWindow *self, TnyMsg *msg)
        bcc     = tny_header_get_bcc (header);
        subject = tny_header_get_subject (header);
 
-       if (to)
-               gtk_entry_set_text (GTK_ENTRY(priv->to_field),  to);
-       if (cc)
-               gtk_entry_set_text (GTK_ENTRY(priv->cc_field),  cc);
-       if (bcc)
-               gtk_entry_set_text (GTK_ENTRY(priv->bcc_field), bcc);
+       /* TODO: the comparison with Invalid is ugly, should be fixed
+          in tinymail -> TnyCamelHeader */
+       if (strcmp (to, "Invalid"))
+               gtk_entry_set_text (GTK_ENTRY(priv->to_field), to);
+       if (strcmp (cc, "Invalid"))
+               gtk_entry_set_text (GTK_ENTRY(priv->cc_field), cc);
+       if (strcmp (bcc, "Invalid"))
+               gtk_entry_set_text (GTK_ENTRY(priv->bcc_field),  bcc);
        if (subject)
                gtk_entry_set_text (GTK_ENTRY(priv->subject_field), subject);
        
index 8c1aa43..2e190d8 100644 (file)
@@ -405,7 +405,9 @@ modest_mail_operation_create_reply_mail (TnyMsg *msg,
        header = tny_msg_get_header (msg);
        new_header = tny_msg_get_header (new_msg);
        reply_to = tny_header_get_replyto (header);
-       if (reply_to)
+
+       /* TODO: tinymail returns Invalid and it should return NULL */
+       if (strcmp (reply_to, "Invalid"))
                tny_header_set_to (new_header, reply_to);
        else
                tny_header_set_to (new_header, tny_header_get_from (header));
index 598a132..7b58257 100644 (file)
@@ -178,7 +178,7 @@ modest_text_utils_inline (const gchar *text,
        g_return_val_if_fail (to, NULL);
        g_return_val_if_fail (subject, NULL);
        
-       modest_text_utils_strftime (sent_str, 100, "%c", localtime (&sent_date));
+       modest_text_utils_strftime (sent_str, 100, "%c", sent_date);
 
        if (!strcmp (content_type, "text/html"))
                /* TODO: extract the <body> of the HTML and pass it to
@@ -199,10 +199,14 @@ modest_text_utils_inline (const gchar *text,
 /* just to prevent warnings:
  * warning: `%x' yields only last 2 digits of year in some locales
  */
-size_t
-modest_text_utils_strftime(char *s, size_t max, const char  *fmt, const  struct tm *tm)
+gsize
+modest_text_utils_strftime(char *s, gsize max, const char *fmt, time_t timet)
 {
-       return strftime(s, max, fmt, tm);
+       static GDate date;
+
+       g_date_set_time_t (&date, timet);
+
+       return g_date_strftime (s, max, fmt, (const GDate*) &date);
 }
 
 gchar *
@@ -478,7 +482,7 @@ cite (const time_t sent_date, const gchar *from)
        gchar sent_str[101];
 
        /* format sent_date */
-       modest_text_utils_strftime (sent_str, 100, "%c", localtime (&sent_date));
+       modest_text_utils_strftime (sent_str, 100, "%c", sent_date);
        return g_strdup_printf (N_("On %s, %s wrote:\n"), sent_str, from);
 }
 
@@ -775,9 +779,7 @@ modest_text_utils_get_display_date (time_t date)
 {
        static GHashTable *date_cache = NULL;
 
-       struct tm date_tm, now_tm; 
        time_t now;
-
        const guint BUF_SIZE = 64; 
        gchar date_buf[BUF_SIZE];  
        gchar now_buf [BUF_SIZE];  
@@ -792,17 +794,14 @@ modest_text_utils_get_display_date (time_t date)
                                                    
        now = time (NULL);
        
-       localtime_r(&now, &now_tm);
-       localtime_r(&date, &date_tm);
-
        /* get today's date */
-       modest_text_utils_strftime (date_buf, BUF_SIZE, "%x", &date_tm);
-       modest_text_utils_strftime (now_buf,  BUF_SIZE, "%x",  &now_tm);
+       modest_text_utils_strftime (date_buf, BUF_SIZE, "%x", date);
+       modest_text_utils_strftime (now_buf,  BUF_SIZE, "%x",  now);
        /* today */
 
        /* if this is today, get the time instead of the date */
        if (strcmp (date_buf, now_buf) == 0)
-               strftime (date_buf, BUF_SIZE, _("%X"), &date_tm); 
+               modest_text_utils_strftime (date_buf, BUF_SIZE, _("%X"), date);
 
        cached_val = g_strdup(date_buf);
        g_hash_table_insert (date_cache, (gpointer)&date, (gpointer)cached_val);
index 5e897d3..2a3002b 100644 (file)
@@ -135,14 +135,14 @@ gchar*  modest_text_utils_convert_to_html (const gchar *txt);
  * @s:
  * @max:
  * @fmt:
- * @tm
+ * @timet:
  *
  * this is just an alias for strftime(3), so we can use that without
  * getting warning from gcc
  * 
  * Returns: a formatted string of max length @max in @s
  */
-size_t modest_text_utils_strftime(char *s, size_t max, const char  *fmt, const  struct tm *tm);
+size_t modest_text_utils_strftime(char *s, size_t max, const char  *fmt, time_t timet);
 
 
 
index f877ed9..5f8e194 100644 (file)
@@ -39,6 +39,7 @@
 #include "modest-icon-names.h"
 #include "modest-tny-platform-factory.h"
 #include "modest-account-view-window.h"
+#include "modest-account-mgr-helpers.h"
 #include "modest-main-window.h"
 #include "modest-mail-operation.h"
 #include <modest-widget-memory.h>
@@ -604,14 +605,16 @@ reply_forward (GtkWidget *widget,
               ModestMainWindow *main_window)
 {
        ModestHeaderView *header_view;
+       ModestAccountMgr *account_mgr;
        ModestWidgetFactory *widget_factory;
        TnyList *header_list;
        guint reply_forward_type;
-       ModestConf *conf;
+       ModestConf *conf;       
+       ModestAccountData *default_account_data;
        TnyPlatformFactory *plat_factory;
        TnyHeader *header;
        TnyFolder *folder;
-       gchar *from, *key;
+       gchar *from, *key, *default_account_name;
        GetMsgAsyncHelper *helper;
        ReplyForwardHelper *rf_helper;
 
@@ -639,9 +642,15 @@ reply_forward (GtkWidget *widget,
           same folder and that we reply all of them from the
           same account. In fact the interface currently only
           allows single selection */
-
-       /* TODO: get the from string from account */
-       from = g_strdup ("Invalid");
+       account_mgr = modest_tny_platform_factory_get_account_mgr_instance
+               (MODEST_TNY_PLATFORM_FACTORY(plat_factory));
+       default_account_name = modest_account_mgr_get_default_account (account_mgr);
+       default_account_data = 
+               modest_account_mgr_get_account_data (account_mgr,
+                                                    (const gchar*) default_account_name);
+       from = g_strdup (default_account_data->email);
+       modest_account_mgr_free_account_data (account_mgr, default_account_data);
+       g_free (default_account_name);
        
        /* Fill helpers */
        rf_helper = g_slice_new0 (ReplyForwardHelper);