2005-10-26 [colin] 1.9.15cvs111
[claws.git] / src / jpilot.c
index c700065b863c63908accab399de8dd2af51c0de4..5e67c961c605114b282900677588c97a41c0bbf2 100644 (file)
@@ -14,7 +14,7 @@
  *
  * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 /*
@@ -154,7 +154,7 @@ enum {
        FAMILY_FIRST = 1
 } name_order;
 
-gboolean convert_charcode;
+gboolean convert_charcode = TRUE;
 
 /*
 * Create new pilot file object.
@@ -638,7 +638,7 @@ static gint jpilot_get_file_info( JPilotFile *pilotFile, unsigned char **buf, in
        *buf_size=0;
 
        if( pilotFile->path ) {
-               in = fopen( pilotFile->path, "rb" );
+               in = g_fopen( pilotFile->path, "rb" );
                if( !in ) {
                        return MGU_OPEN_FILE;
                }
@@ -692,7 +692,7 @@ static gint jpilot_get_file_info( JPilotFile *pilotFile, unsigned char **buf, in
 /* Shamelessly copied from JPilot (libplugin.c) */
 static int unpack_header(PC3RecordHeader *header, unsigned char *packed_header) {
        unsigned char *p;
-       unsigned long l;
+       guint32 l;
 
        p = packed_header;
 
@@ -724,7 +724,8 @@ static int unpack_header(PC3RecordHeader *header, unsigned char *packed_header)
 
 /* Shamelessly copied from JPilot (libplugin.c) */
 static int read_header(FILE *pc_in, PC3RecordHeader *header) {
-       unsigned long l, len;
+       guint32 l;
+       unsigned long len;
        unsigned char packed_header[256];
        int num;
 
@@ -832,8 +833,8 @@ static gint jpilot_read_db_files( JPilotFile *pilotFile, GList **records ) {
                return MGU_BAD_ARGS;
        }
 
-       in = fopen( pilotFile->path, "rb" );
-       if( ! in ) {
+       in = g_fopen( pilotFile->path, "rb" );
+       if (!in) {
                return MGU_OPEN_FILE;
        }
 
@@ -962,7 +963,7 @@ static gint jpilot_read_db_files( JPilotFile *pilotFile, GList **records ) {
        /* Read the PC3 file, if present */
        pcFile = jpilot_get_pc3_file( pilotFile );
        if( pcFile == NULL ) return MGU_SUCCESS;
-       pc_in = fopen( pcFile, "rb" );
+       pc_in = g_fopen( pcFile, "rb");
        g_free( pcFile );
 
        if( pc_in == NULL ) {
@@ -1096,12 +1097,13 @@ static void jpilot_parse_label( JPilotFile *pilotFile, gchar *labelEntry, ItemPe
                strcpy( buffer, labelEntry );
                node = list = jpilot_parse_email( buffer );
                while( node ) {
-                       gchar convertBuff[JPILOT_LEN_LABEL];
                        email = addritem_create_item_email();
                        addritem_email_set_address( email, node->data );
                        if (convert_charcode) {
                                gchar *convertBuff;
-                               convertBuff = conv_codeset_strdup( ai->labels[ind], CS_SHIFT_JIS, CS_INTERNAL );
+                               convertBuff = conv_codeset_strdup( labelEntry, 
+                                               conv_get_locale_charset_str_no_utf8(), 
+                                               CS_INTERNAL );
                                addritem_email_set_remarks( email, convertBuff );
                                g_free( convertBuff );
                        }
@@ -1183,7 +1185,9 @@ static void jpilot_load_address(
 
                if( convert_charcode ) {
                        gchar *nameConv;
-                       nameConv = conv_codeset_strdup( fullName, CS_SHIFT_JIS, CS_INTERNAL );
+                       nameConv = conv_codeset_strdup( fullName, 
+                                       conv_get_locale_charset_str_no_utf8(), 
+                                       CS_INTERNAL );
                        strncpy2( fullName, nameConv, FULLNAME_BUFSIZE );
                        g_free( nameConv );
                }
@@ -1350,7 +1354,9 @@ static gboolean jpilot_setup_labels( JPilotFile *pilotFile ) {
                                gchar convertBuff[ JPILOT_LEN_LABEL ];
 
                                if( convert_charcode ) {
-                                       labelName = conv_codeset_strdup( labelName, CS_SHIFT_JIS, CS_INTERNAL );
+                                       labelName = conv_codeset_strdup( labelName, 
+                                                       conv_get_locale_charset_str_no_utf8(), 
+                                                       CS_INTERNAL );
                                        strncpy2( convertBuff, labelName, JPILOT_LEN_LABEL );
                                        g_free( labelName );
                                        labelName = convertBuff;
@@ -1388,7 +1394,9 @@ GList *jpilot_load_label( JPilotFile *pilotFile, GList *labelList ) {
 
                        if( labelName ) {
                                if( convert_charcode ) {
-                                       labelName = conv_codeset_strdup( labelName, CS_SHIFT_JIS, CS_INTERNAL );
+                                       labelName = conv_codeset_strdup( labelName, 
+                                                       conv_get_locale_charset_str_no_utf8(), 
+                                                       CS_INTERNAL );
                                }
                                else {
                                        labelName = g_strdup( labelName );
@@ -1478,7 +1486,9 @@ GList *jpilot_load_custom_label( JPilotFile *pilotFile, GList *labelList ) {
                                g_strchug( labelName );
                                if( *labelName != '\0' ) {
                                        if( convert_charcode ) {
-                                               labelName = conv_codeset_strdup( labelName, CS_SHIFT_JIS, CS_INTERNAL );
+                                               labelName = conv_codeset_strdup( labelName, 
+                                                               conv_get_locale_charset_str_no_utf8(), 
+                                                               CS_INTERNAL );
                                        }
                                        else {
                                                labelName = g_strdup( labelName );
@@ -1534,7 +1544,9 @@ static void jpilot_build_category_list( JPilotFile *pilotFile ) {
 
                if( convert_charcode ) {
                        gchar *catName;
-                       catName = conv_codeset_strdup( cat->name[i], CS_SHIFT_JIS, CS_INTERNAL );
+                       catName = conv_codeset_strdup( cat->name[i], 
+                                       conv_get_locale_charset_str_no_utf8(), 
+                                       CS_INTERNAL );
                        addritem_folder_set_name( folder, catName );
                        g_free( catName );
                }
@@ -1657,7 +1669,6 @@ gint jpilot_read_data( JPilotFile *pilotFile ) {
        const gchar *cur_locale;
 
        name_order = FAMILY_LAST;
-       convert_charcode = FALSE;
 
        cur_locale = conv_get_current_locale();
 
@@ -1665,10 +1676,6 @@ gint jpilot_read_data( JPilotFile *pilotFile ) {
                name_order = FAMILY_FIRST;
        }
 
-       if( conv_get_current_charset() == C_EUC_JP ) {
-               convert_charcode = TRUE;
-       }
-
        g_return_val_if_fail( pilotFile != NULL, -1 );
 
        pilotFile->retVal = MGU_SUCCESS;
@@ -1769,7 +1776,7 @@ gchar *jpilot_find_pilotdb( void ) {
        gint len;
        FILE *fp;
 
-       homedir = g_get_home_dir();
+       homedir = get_home_dir();
        if( ! homedir ) return g_strdup( "" );
 
        strcpy( str, homedir );
@@ -1785,7 +1792,7 @@ gchar *jpilot_find_pilotdb( void ) {
        strcat( str, JPILOT_DBHOME_FILE );
 
        /* Attempt to open */
-       if( ( fp = fopen( str, "rb" ) ) != NULL ) {
+       if( ( fp = g_fopen( str, "rb" ) ) != NULL ) {
                fclose( fp );
        }
        else {