* modest_tny_msg_view get an set functions for show_attachments_inline
authorArne Zellentin <arne@kernelconcepts.de>
Mon, 12 Jun 2006 17:34:33 +0000 (17:34 +0000)
committerArne Zellentin <arne@kernelconcepts.de>
Mon, 12 Jun 2006 17:34:33 +0000 (17:34 +0000)
* use them where appropriate

pmo-trunk-r240

src/gtk-glade/modest-ui-main-view.c
src/modest-tny-msg-view.c
src/modest-tny-msg-view.h

index 49dd4dd..2fb04bf 100644 (file)
@@ -95,6 +95,7 @@ modest_ui_show_main_window (ModestUI *modest_ui)
        GtkWidget  *folder_view_holder,
                *header_view_holder,
                *mail_paned;
+       gboolean show_attachments_inline;
 
        priv = MODEST_UI_GET_PRIVATE(modest_ui);
 
@@ -131,12 +132,16 @@ modest_ui_show_main_window (ModestUI *modest_ui)
        g_signal_connect (G_OBJECT(folder_view), "folder_selected",
                          G_CALLBACK(on_folder_clicked), modest_ui);
 
-       /* TODO: get view->attachments_inline from conf instead of TRUE */
-       message_view  = GTK_WIDGET(modest_tny_msg_view_new (NULL, TRUE));
+       show_attachments_inline = modest_conf_get_bool(priv->modest_conf,
+                                            MODEST_CONF_MSG_VIEW_SHOW_ATTACHMENTS_INLINE,
+                                            NULL);
+
+       message_view  = GTK_WIDGET(modest_tny_msg_view_new (NULL, show_attachments_inline));
        if (!message_view) {
                g_warning ("failed to create message view");
                return FALSE;
        }
+       
        mail_paned = glade_xml_get_widget (priv->glade_xml, "mail_paned");
        gtk_paned_add2 (GTK_PANED(mail_paned), message_view);
 
@@ -414,20 +419,24 @@ on_view_attachments_toggled(GtkWidget *widget, ModestUI *modest_ui)
        GtkWidget *view_attachments_item, *paned;
        ModestTnyMsgView *msg_view;
        ModestUIPrivate *priv;
+       gboolean view_attachments_inline;
 
        priv = MODEST_UI_GET_PRIVATE(modest_ui);
        view_attachments_item = glade_xml_get_widget (priv->glade_xml, "menu_view_attachments");
        g_return_if_fail(view_attachments_item);
-
-       modest_conf_set_bool(priv->modest_conf,
-                                                        MODEST_CONF_MSG_VIEW_SHOW_ATTACHMENTS_INLINE,
-                                                        gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(view_attachments_item)),
-                                                        NULL);
-
-       /* refresh message view */
+       
        paned = glade_xml_get_widget (priv->glade_xml,"mail_paned");
        msg_view = MODEST_TNY_MSG_VIEW(gtk_paned_get_child2 (GTK_PANED(paned)));
-       modest_tny_msg_view_redraw(MODEST_TNY_MSG_VIEW(msg_view));
+       
+       view_attachments_inline = gtk_check_menu_item_get_active(
+                                       GTK_CHECK_MENU_ITEM(view_attachments_item));
+       
+       modest_conf_set_bool(priv->modest_conf,
+                            MODEST_CONF_MSG_VIEW_SHOW_ATTACHMENTS_INLINE,
+                            view_attachments_inline,
+                            NULL);
+       
+       modest_tny_msg_view_set_show_attachments_inline_flag(msg_view, view_attachments_inline);
 }
 
 
index 955dccd..a57ff02 100644 (file)
@@ -172,7 +172,7 @@ modest_tny_msg_view_new (TnyMsgIface *msg, const gboolean show_attachments_inlin
        if (msg)
                modest_tny_msg_view_set_message (self, msg);
        
-       priv->show_attachments_inline = show_attachments_inline;
+       modest_tny_msg_view_set_show_attachments_inline_flag(self, show_attachments_inline);
 
        return GTK_WIDGET(self);
 }
@@ -261,7 +261,7 @@ on_url_requested (GtkWidget *widget, const gchar *uri,
 
        g_message ("url requested: %s", uri);
        
-       if (!priv->show_attachments_inline)
+       if (!modest_tny_msg_view_get_show_attachments_inline_flag(msg_view))
                return TRUE; /* debatable */
        
        if (g_str_has_prefix (uri, "cid:")) {
@@ -304,10 +304,23 @@ typedef struct  {
 static gchar *
 secure_filename(const gchar *fn)
 {
-       /* WIP */
-       gchar * s;
-       s = strdup(fn);
-       return s;
+       gchar *tmp, *p;
+       GString *s;
+       
+       s = g_string_new("");
+#if 1 || DEBUG
+       tmp = g_strdup(fn);
+       for (p = tmp; p[0] ; p++ ) {
+               p[0] &= 0x5f; /* 01011111 */
+               p[0] |= 0x40; /* 01000000 */
+       }
+       g_string_printf(s, "0x%x:%s", g_str_hash(fn), tmp);
+       g_free(tmp);
+       return g_string_free(s, FALSE);
+#else
+       g_string_printf(s, "0x%x", g_str_hash(fn));
+       return g_string_free(s, FALSE);
+#endif
 }
        
        
@@ -321,7 +334,7 @@ construct_virtual_filename(const gchar *filename,
        gchar *fn;
        
        if (position < 0)
-               return "AttachmentInvalid";
+               return g_strdup("AttachmentInvalid");
 
        s = g_string_new("");
        if (active)
@@ -441,7 +454,7 @@ attachments_as_html(ModestTnyMsgView *self, TnyMsgIface *msg)
                                attachments_found = TRUE;
                        id = tny_msg_mime_part_iface_get_content_id(
                                                                                TNY_MSG_MIME_PART_IFACE(attachment->data));
-                       if (priv->show_attachments_inline) {
+                       if (modest_tny_msg_view_get_show_attachments_inline_flag(self)) {
                                virtual_filename = construct_virtual_filename(filename,
                                        g_list_position((GList *)attachment_list, (GList *) attachment),
                                        id, TRUE);
@@ -791,3 +804,28 @@ modest_tny_msg_view_redraw (ModestTnyMsgView *self)
        priv = MODEST_TNY_MSG_VIEW_GET_PRIVATE(self);
        modest_tny_msg_view_set_message(self, priv->msg);
 }
+
+gboolean
+modest_tny_msg_view_get_show_attachments_inline_flag (ModestTnyMsgView *self)
+{
+       ModestTnyMsgViewPrivate *priv;
+
+       g_return_val_if_fail (self, FALSE);
+       priv = MODEST_TNY_MSG_VIEW_GET_PRIVATE(self);
+       return priv->show_attachments_inline;
+}
+
+gboolean
+modest_tny_msg_view_set_show_attachments_inline_flag (ModestTnyMsgView *self, gboolean flag)
+{
+       ModestTnyMsgViewPrivate *priv;
+       gboolean oldflag;
+
+       g_return_val_if_fail (self, FALSE);
+       priv = MODEST_TNY_MSG_VIEW_GET_PRIVATE(self);
+       oldflag = priv->show_attachments_inline;
+       priv->show_attachments_inline = flag;
+       if (priv->show_attachments_inline != oldflag)
+               modest_tny_msg_view_redraw(self);
+       return priv->show_attachments_inline;
+}
index 0de1377..80b5dae 100644 (file)
@@ -87,6 +87,10 @@ void         modest_tny_msg_view_redraw  (ModestTnyMsgView *self);
  */
 gchar *      modest_tny_msg_view_get_selected_text (ModestTnyMsgView *self);
 
+gboolean modest_tny_msg_view_get_show_attachments_inline_flag (ModestTnyMsgView *self);
+
+gboolean modest_tny_msg_view_set_show_attachments_inline_flag (ModestTnyMsgView *self, gboolean flag);
+
 G_END_DECLS
 
 #endif /* __MODEST_TNY_MSG_VIEW_H__ */