2007-10-07 [colin] 3.0.2cvs28
[claws.git] / src / exporthtml.c
index 6b417882448ea93909d50aca1dadaa0c142386d9..fe733ac32e4b98fae9b9b7b0198d98e02e9293f3 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2002-2006 Match Grun and the Sylpheed-Claws team
+ * Copyright (C) 2002-2007 Match Grun and the Claws Mail team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -13,8 +13,8 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 /*
 #include <glib.h>
 #include <glib/gi18n.h>
 
+#ifdef G_OS_WIN32
+#  include <w32lib.h>
+#endif
+
 #include "mgutils.h"
 #include "utils.h"
 #include "exporthtml.h"
 #define mkdir(a,b) mkdir(a)
 #endif
 
-#define DFL_DIR_SYLPHEED_OUT  "sylpheed-out"
-#define DFL_FILE_SYLPHEED_OUT "addressbook.html"
+#define DFL_DIR_CLAWS_OUT  "claws-mail-out"
+#define DFL_FILE_CLAWS_OUT "addressbook.html"
 
 #define FMT_BUFSIZE         2048
 #define SC_HTML_SPACE          "&nbsp;"
 #define BORDER_SIZE         2
 #define CELL_PADDING        2
 #define CELL_SPACING        2
-#define CHAR_ENCODING       "ISO-8859-1"
+#define CHAR_ENCODING       "UTF-8"
 
 /* Stylesheet names */
 #define FILENAME_NONE       ""
-#define FILENAME_DEFAULT    "sylpheed.css"
+#define FILENAME_DEFAULT    "claws-mail.css"
 #define FILENAME_FULL       "full.css"
 #define FILENAME_CUSTOM     "custom.css"
 #define FILENAME_CUSTOM2    "custom2.css"
@@ -117,7 +121,7 @@ ExportHtmlCtl *exporthtml_create( void ) {
        ctl->path = NULL;
        ctl->dirOutput = NULL;
        ctl->fileHtml = NULL;
-       ctl->encoding = NULL;
+       ctl->encoding = g_strconcat(CHAR_ENCODING, NULL);
        ctl->stylesheet = EXPORT_HTML_ID_NONE;
        ctl->nameFormat = EXPORT_HTML_FIRST_LAST;
        ctl->banding = FALSE;
@@ -196,25 +200,6 @@ void exporthtml_free( ExportHtmlCtl *ctl ) {
        g_free( ctl );
 }
 
-/*
- * Print control object.
- * Enter: ctl    Export control data.
- *        stream Output stream.
- */
-void exporthtml_print( ExportHtmlCtl *ctl, FILE *stream ) {
-       fprintf( stream, "ExportHtmlCtl:\n" );
-       fprintf( stream, "     path: %s\n", ctl->path );
-       fprintf( stream, "directory: %s\n", ctl->dirOutput );
-       fprintf( stream, "     file: %s\n", ctl->fileHtml );
-       fprintf( stream, " settings: %s\n", ctl->settingsFile );
-       fprintf( stream, " encoding: %s\n", ctl->encoding );
-       fprintf( stream, " css file: %d\n", ctl->stylesheet );
-       fprintf( stream, " name fmt: %d\n", ctl->nameFormat );
-       fprintf( stream, "  banding: %d\n", ctl->banding );
-       fprintf( stream, "link mail: %d\n", ctl->linkEMail );
-       fprintf( stream, "show attr: %d\n", ctl->showAttribs );
-}
-
 /*
  * Find style entry.
  * Enter: ctl Export control data.
@@ -236,34 +221,6 @@ static StylesheetEntry *exporthtml_find_stylesheet( ExportHtmlCtl *ctl ) {
        return retVal;
 }
 
-/*
- * Properties...
- */
-/*
- * Specify path to folder where files are created.
- * Enter: ctl   Export control data.
- *        value Full directory path.
- */
-void exporthtml_set_output_dir( ExportHtmlCtl *ctl, const gchar *value ) {
-       g_return_if_fail( ctl != NULL );
-       ctl->dirOutput = mgu_replace_string( ctl->dirOutput, value );
-       g_strstrip( ctl->dirOutput );
-}
-void exporthtml_set_path( ExportHtmlCtl *ctl, const gchar *value ) {
-       g_return_if_fail( ctl != NULL );
-       ctl->path = mgu_replace_string( ctl->path, value );
-       g_strstrip( ctl->path );
-}
-void exporthtml_set_file_html( ExportHtmlCtl *ctl, const gchar *value ) {
-       g_return_if_fail( ctl != NULL );
-       ctl->fileHtml = mgu_replace_string( ctl->fileHtml, value );
-       g_strstrip( ctl->fileHtml );
-}
-void exporthtml_set_encoding( ExportHtmlCtl *ctl, const gchar *value ) {
-       g_return_if_fail( ctl != NULL );
-       ctl->encoding = mgu_replace_string( ctl->encoding, value );
-       g_strstrip( ctl->encoding );
-}
 void exporthtml_set_stylesheet( ExportHtmlCtl *ctl, const gint value ) {
        g_return_if_fail( ctl != NULL );
        ctl->stylesheet = value;
@@ -957,7 +914,9 @@ static void exporthtml_fmt_header(
        entry = exporthtml_find_stylesheet( ctl );
 
        fprintf( stream,
-               "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\">\n" );
+               "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n" );
+       fprintf( stream,
+                "\"http://www.w3.org/TR/html4/loose.dtd\">\n" );
        fprintf( stream, "<html>\n" );
        fprintf( stream, "<head>\n" );
 
@@ -978,7 +937,6 @@ static void exporthtml_fmt_header(
                        fprintf( stream, "href=\"%s\" >\n", entry->fileName );
                }
        }
-       fprintf( stream, "<body>\n" );
        fprintf( stream, "</head>\n" );
 }
 
@@ -998,16 +956,17 @@ void exporthtml_process(
        time_t tt;
        gchar *dsName;
        static gchar *title;
+       gchar buf[512];
 
        htmlFile = g_fopen( ctl->path, "wb" );
        if( ! htmlFile ) {
                /* Cannot open file */
-               printf( "Cannot open file for write\n" );
+               g_print( "Cannot open file for write\n" );
                ctl->retVal = MGU_OPEN_FILE;
                return;
        }
 
-       title = _( "Sylpheed-Claws Address Book" );
+       title = _( "Claws Mail Address Book" );
        rootFolder = cache->rootFolder;
        dsName = cache->name;
 
@@ -1024,8 +983,12 @@ void exporthtml_process(
        exporthtml_fmt_folder( ctl, htmlFile, rootFolder );
 
        tt = time( NULL );
-       fprintf( htmlFile, "<p>%s</p>\n", ctime( &tt ) );
-       fprintf( htmlFile, "<hr width=\"100%%\"></hr>\n" );
+#ifdef SOLARIS
+       fprintf(htmlFile, "<p>%s</p>\n", ctime_r(&tt, buf, sizeof(buf)));
+#else
+       fprintf( htmlFile, "<p>%s</p>\n", ctime_r( &tt, buf ) );
+#endif
+       fprintf( htmlFile, "<hr width=\"100%%\">\n" );
 
        fprintf( htmlFile, "</body>\n" );
        fprintf( htmlFile, "</html>\n" );
@@ -1143,14 +1106,14 @@ static void exporthtml_default_values( ExportHtmlCtl *ctl ) {
        gchar *str;
 
        str = g_strconcat(
-               g_get_home_dir(), G_DIR_SEPARATOR_S,
-               DFL_DIR_SYLPHEED_OUT, NULL );
+               get_home_dir(), G_DIR_SEPARATOR_S,
+               DFL_DIR_CLAWS_OUT, NULL );
 
        ctl->dirOutput = mgu_replace_string( ctl->dirOutput, str );
        g_free( str );
 
        ctl->fileHtml =
-               mgu_replace_string( ctl->fileHtml, DFL_FILE_SYLPHEED_OUT );
+               mgu_replace_string( ctl->fileHtml, DFL_FILE_CLAWS_OUT );
        ctl->encoding = NULL;
        ctl->stylesheet = EXPORT_HTML_ID_DEFAULT;
        ctl->nameFormat = EXPORT_HTML_FIRST_LAST;
@@ -1223,7 +1186,8 @@ void exporthtml_save_settings( ExportHtmlCtl *ctl ) {
        xmlprops_set_property_b( props, EXMLPROP_BANDING, ctl->banding );
        xmlprops_set_property_b( props, EXMLPROP_FMT_EMAIL, ctl->linkEMail );
        xmlprops_set_property_b( props, EXMLPROP_FMT_ATTRIB, ctl->showAttribs );
-       xmlprops_save_file( props );
+       if (xmlprops_save_file( props ) != MGU_SUCCESS)
+               g_warning("can't save settings");
        xmlprops_free( props );
 }