renderer, config is not yet build with a dialog box, you have to edit .sylpheed/rende...
authorHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Sun, 27 Jan 2002 23:21:17 +0000 (23:21 +0000)
committerHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Sun, 27 Jan 2002 23:21:17 +0000 (23:21 +0000)
ChangeLog.claws
src/defs.h
src/main.c
src/procmime.c
src/procmime.h
src/textview.c

index bc25015..fdae5c3 100644 (file)
@@ -1,3 +1,18 @@
+2002-01-28 [hoa]       0.7.0claws35
+
+       * src/defs.h
+               added rendererrc
+
+       * src/main.c
+               read the renderer config
+
+       * src/procmime.[ch]
+               use the renderer config to convert mime attachments
+
+       * src/textview.c
+               don't use textview_show_html/ertf,
+               use get_text_content instead
+
 2002-01-27 [alfons]    0.7.0claws34
        
        * src/news.c
index e5d7870..88dc5bc 100644 (file)
@@ -52,6 +52,7 @@
 #define FILTERING_RC           "filteringrc"
 #define MATCHER_RC             "matcherrc"
 #define MENU_RC                        "menurc"
+#define RENDERER_RC            "rendererrc"
 #define COMMAND_HISTORY                "command_history"
 #define TEMPLATE_DIR           "templates"
 #define NEWSGROUP_LIST         ".newsgroup_list"
index 4fe31c7..fc45841 100644 (file)
@@ -261,6 +261,7 @@ int main(int argc, char *argv[])
        prefs_display_header_write_config();
        /* prefs_filtering_read_config(); */
        addressbook_read_file();
+       renderer_read_config();
 
        gtkut_widget_init();
 
index f56dc22..27d8d31 100644 (file)
@@ -45,6 +45,8 @@
 #  include "rfc2015.h"
 #endif
 
+#include "prefs.h"
+
 static GHashTable *procmime_get_mime_type_table        (void);
 
 MimeInfo *procmime_mimeinfo_new(void)
@@ -708,6 +710,103 @@ gint procmime_get_part(const gchar *outfile, const gchar *infile,
        return 0;
 }
 
+struct ContentRenderer {
+       char * content_type;
+       char * renderer;
+};
+
+static GList * renderer_list = NULL;
+
+static struct ContentRenderer *
+content_renderer_new(char * content_type, char * renderer)
+{
+       struct ContentRenderer * cr;
+
+       cr = g_new(struct ContentRenderer, 1);
+       if (cr == NULL)
+               return NULL;
+
+       cr->content_type = g_strdup(content_type);
+       cr->renderer = g_strdup(renderer);
+
+       return cr;
+}
+
+static void content_renderer_free(struct ContentRenderer * cr)
+{
+       g_free(cr->content_type);
+       g_free(cr->renderer);
+       g_free(cr);
+}
+
+void renderer_read_config(void)
+{
+       gchar buf[BUFFSIZE];
+       FILE * f;
+       gchar * rcpath;
+
+       g_list_foreach(renderer_list, (GFunc) content_renderer_free, NULL);
+       renderer_list = NULL;
+
+       rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, RENDERER_RC, NULL);
+       f = fopen(rcpath, "r");
+       g_free(rcpath);
+       
+       if (f == NULL)
+               return;
+
+       while (fgets(buf, BUFFSIZE, f)) {
+               char * p;
+               struct ContentRenderer * cr;
+
+               strretchomp(buf);
+               p = strchr(buf, ' ');
+               if (p == NULL)
+                       continue;
+               * p = 0;
+
+               cr = content_renderer_new(buf, p + 1);
+               if (cr == NULL)
+                       continue;
+
+               printf("%s %s\n", cr->content_type, cr->renderer);
+
+               renderer_list = g_list_append(renderer_list, cr);
+       }
+
+       fclose(f);
+}
+
+void renderer_write_config(void)
+{
+       int i;
+       gchar * rcpath;
+       PrefFile *pfile;
+       GList * cur;
+
+       rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, RENDERER_RC, NULL);
+       
+       if ((pfile = prefs_write_open(rcpath)) == NULL) {
+               g_warning(_("failed to write configuration to file\n"));
+               g_free(rcpath);
+               return;
+       }
+
+       g_free(rcpath);
+
+       for(cur = renderer_list ; cur != NULL ; cur = cur->next) {
+               struct ContentRenderer * renderer;
+               renderer = cur->data;
+               fprintf(pfile->fp, "%s %s\n", renderer->content_type,
+                       renderer->renderer);
+       }
+
+       if (prefs_write_close(pfile) < 0) {
+               g_warning(_("failed to write configuration to file\n"));
+               return;
+       }
+}
+
 FILE *procmime_get_text_content(MimeInfo *mimeinfo, FILE *infp)
 {
        FILE *tmpfp, *outfp;
@@ -715,6 +814,9 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo, FILE *infp)
        gboolean conv_fail = FALSE;
        gchar buf[BUFFSIZE];
        gchar *str;
+       int i;
+       struct ContentRenderer * renderer;
+       GList * cur;
 
        g_return_val_if_fail(mimeinfo != NULL, NULL);
        g_return_val_if_fail(infp != NULL, NULL);
@@ -743,7 +845,39 @@ FILE *procmime_get_text_content(MimeInfo *mimeinfo, FILE *infp)
        src_codeset = prefs_common.force_charset
                ? prefs_common.force_charset : mimeinfo->charset;
 
-       if (mimeinfo->mime_type == MIME_TEXT) {
+       renderer = NULL;
+
+       for(cur = renderer_list ; cur != NULL ; cur = cur->next) {
+               struct ContentRenderer * cr;
+               cr = cur->data;
+               if (g_strcasecmp(cr->content_type,
+                                mimeinfo->content_type) == 0) {
+                       renderer = cr;
+                       break;
+               }
+       }
+
+       if (renderer != NULL) {
+               FILE * p;
+               int oldout;
+               
+               oldout = dup(1);
+               
+               dup2(fileno(outfp), 1);
+               
+               p = popen(renderer->renderer, "w");
+               if (p != NULL) {
+                       size_t count;
+                       
+                       while ((count =
+                               fread(buf, sizeof(char), sizeof(buf),
+                                     tmpfp)) > 0)
+                               fwrite(buf, sizeof(char), count, p);
+                       pclose(p);
+               }
+               
+               dup2(oldout, 1);
+       } else if (mimeinfo->mime_type == MIME_TEXT) {
                while (fgets(buf, sizeof(buf), tmpfp) != NULL) {
                        str = conv_codeset_strdup(buf, src_codeset, NULL);
                        if (str) {
index a21858e..38ab7bc 100644 (file)
@@ -180,4 +180,7 @@ GList *procmime_get_mime_type_list  (void);
 EncodingType procmime_get_encoding_for_charset (const gchar    *charset);
 const gchar *procmime_get_encoding_str         (EncodingType    encoding);
 
+void renderer_read_config(void);
+void renderer_write_config(void);
+
 #endif /* __PROCMIME_H__ */
index 3961f2f..8f38d2a 100644 (file)
@@ -382,7 +382,9 @@ void textview_show_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
                procheader_header_array_destroy(headers);
        }
 
+#if 0
        tmpfp = procmime_decode_content(NULL, fp, mimeinfo);
+
        if (tmpfp) {
                if (mimeinfo->mime_type == MIME_TEXT_HTML)
                        textview_show_html(textview, tmpfp, conv);
@@ -393,6 +395,14 @@ void textview_show_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
                                textview_write_line(textview, buf, conv);
                fclose(tmpfp);
        }
+#else
+       tmpfp = procmime_get_text_content(mimeinfo, fp);
+
+       while (fgets(buf, sizeof(buf), tmpfp) != NULL)
+               textview_write_line(textview, buf, conv);
+
+       fclose(tmpfp);
+#endif
 
        conv_code_converter_destroy(conv);