*
* 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.
*/
/*
#include "addritem.h"
#include "addrcache.h"
#include "jpilot.h"
+#include "codeconv.h"
#include "adbookbase.h"
+#include "utils.h"
#define JPILOT_DBHOME_DIR ".jpilot"
#define JPILOT_DBHOME_FILE "AddressDB.pdb"
unsigned char attrib;
} PC3RecordHeader;
-/**
+enum {
+ FAMILY_LAST = 0,
+ FAMILY_FIRST = 1
+} name_order;
+
+gboolean convert_charcode = TRUE;
+
+/*
* Create new pilot file object.
* \return Initialized JPilot file object.
*/
pilotFile->pc3ModifyTime = 0;
pcFile = jpilot_get_pc3_file( pilotFile );
if( pcFile == NULL ) return retVal;
- if( 0 == lstat( pcFile, &filestat ) ) {
+ if( 0 == stat( pcFile, &filestat ) ) {
pilotFile->havePC3 = TRUE;
pilotFile->pc3ModifyTime = filestat.st_mtime;
retVal = TRUE;
pcFile = jpilot_get_pc3_file( pilotFile );
if( pcFile == NULL ) return FALSE;
- if( 0 == lstat( pcFile, &filestat ) ) {
+ if( 0 == stat( pcFile, &filestat ) ) {
if( filestat.st_mtime == pilotFile->pc3ModifyTime ) retVal = FALSE;
}
g_free( pcFile );
*mem_rh = NULL;
}
-/* Shamelessly copied from JPilot (libplugin.c) */
-static int jpilot_free_db_list( GList **br_list ) {
- GList *temp_list, *first;
- buf_rec *br;
-
- /* Go to first entry in the list */
- first=NULL;
- for( temp_list = *br_list; temp_list; temp_list = temp_list->prev ) {
- first = temp_list;
- }
- for (temp_list = first; temp_list; temp_list = temp_list->next) {
- if (temp_list->data) {
- br=temp_list->data;
- if (br->buf) {
- free(br->buf);
- temp_list->data=NULL;
- }
- free(br);
- }
- }
- g_list_free(*br_list);
- *br_list=NULL;
- return 0;
-}
-
/* Shamelessly copied from JPilot (libplugin.c) */
/* Read file size */
static int jpilot_get_info_size( FILE *in, int *size ) {
*buf_size=0;
if( pilotFile->path ) {
- in = fopen( pilotFile->path, "rb" );
+ in = g_fopen( pilotFile->path, "rb" );
if( !in ) {
return MGU_OPEN_FILE;
}
/* 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;
/* 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;
return MGU_BAD_ARGS;
}
- in = fopen( pilotFile->path, "rb" );
- if( ! in ) {
+ in = g_fopen( pilotFile->path, "rb" );
+ if (!in) {
return MGU_OPEN_FILE;
}
/* 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 ) {
while( node ) {
email = addritem_create_item_email();
addritem_email_set_address( email, node->data );
+ if (convert_charcode) {
+ gchar *convertBuff;
+ convertBuff = conv_codeset_strdup( labelEntry,
+ conv_get_locale_charset_str_no_utf8(),
+ CS_INTERNAL );
+ addritem_email_set_remarks( email, convertBuff );
+ g_free( convertBuff );
+ }
+ else {
+ addritem_email_set_remarks(email, buffer);
+ }
+
addrcache_id_email( pilotFile->addressCache, email );
addrcache_person_add_email( pilotFile->addressCache, person, email );
node = g_list_next( node );
GList *node;
gchar* extID;
struct AddressAppInfo *ai;
+ gchar **firstName = NULL;
+ gchar **lastName = NULL;
/* Retrieve address */
num = unpack_Address( & addr, buf->buf, buf->size );
cat_id = attrib & 0x0F;
*fullName = '\0';
+
if( addrEnt[ IND_LABEL_FIRSTNAME ] ) {
- strcat( fullName, addrEnt[ IND_LABEL_FIRSTNAME ] );
+ firstName = g_strsplit( addrEnt[ IND_LABEL_FIRSTNAME ], "\01", 2 );
}
if( addrEnt[ IND_LABEL_LASTNAME ] ) {
- strcat( fullName, " " );
- strcat( fullName, addrEnt[ IND_LABEL_LASTNAME ] );
+ lastName = g_strsplit( addrEnt[ IND_LABEL_LASTNAME ], "\01", 2 );
+ }
+
+ if( name_order == FAMILY_LAST ) {
+ g_snprintf( fullName, FULLNAME_BUFSIZE, "%s %s",
+ firstName ? firstName[0] : "",
+ lastName ? lastName[0] : "" );
+ }
+ else {
+ g_snprintf( fullName, FULLNAME_BUFSIZE, "%s %s",
+ lastName ? lastName[0] : "",
+ firstName ? firstName[0] : "" );
+ }
+
+ if( firstName ) {
+ g_strfreev( firstName );
+ }
+ if( lastName ) {
+ g_strfreev( lastName );
+ }
+
+ g_strstrip( fullName );
+
+ if( convert_charcode ) {
+ gchar *nameConv;
+ nameConv = conv_codeset_strdup( fullName,
+ conv_get_locale_charset_str_no_utf8(),
+ CS_INTERNAL );
+ strncpy2( fullName, nameConv, FULLNAME_BUFSIZE );
+ g_free( nameConv );
}
- g_strchug( fullName );
- g_strchomp( fullName );
person = addritem_create_item_person();
addritem_person_set_common_name( person, fullName );
indPhoneLbl = addr.phoneLabel;
for( k = 0; k < JPILOT_NUM_ADDR_PHONE; k++ ) {
gint ind;
+
ind = indPhoneLbl[k];
/*
* fprintf( stdout, "%d : %d : %20s : %s\n", k, ind,
node = pilotFile->labelInd;
while( node ) {
gint ind;
+
ind = GPOINTER_TO_INT( node->data );
if( ind > -1 ) {
/*
gint i;
for( i = 0; i < JPILOT_NUM_LABELS; i++ ) {
gchar *labelName = ai->labels[i];
- if( g_strcasecmp( labelName, lbl ) == 0 ) {
+ gchar convertBuff[ JPILOT_LEN_LABEL ];
+
+ if( convert_charcode ) {
+ 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;
+ }
+
+ if( g_utf8_collate( labelName, lbl ) == 0 ) {
ind = i;
break;
}
struct AddressAppInfo *ai = & pilotFile->addrInfo;
for( i = 0; i < JPILOT_NUM_LABELS; i++ ) {
gchar *labelName = ai->labels[i];
+
if( labelName ) {
- labelList = g_list_append(
- labelList, g_strdup( labelName ) );
+ if( convert_charcode ) {
+ labelName = conv_codeset_strdup( labelName,
+ conv_get_locale_charset_str_no_utf8(),
+ CS_INTERNAL );
+ }
+ else {
+ labelName = g_strdup( labelName );
+ }
+ labelList = g_list_append( labelList, labelName );
}
else {
labelList = g_list_append(
g_strchomp( labelName );
g_strchug( labelName );
if( *labelName != '\0' ) {
- labelList = g_list_append( labelList,
- g_strdup( labelName ) );
+ if( convert_charcode ) {
+ labelName = conv_codeset_strdup( labelName,
+ conv_get_locale_charset_str_no_utf8(),
+ CS_INTERNAL );
+ }
+ else {
+ labelName = g_strdup( labelName );
+ }
+ labelList = g_list_append( labelList, labelName );
}
}
}
for( i = 0; i < JPILOT_NUM_CATEG; i++ ) {
ItemFolder *folder = addritem_create_item_folder();
- addritem_folder_set_name( folder, cat->name[i] );
+
+ if( convert_charcode ) {
+ gchar *catName;
+ 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 );
+ }
+ else {
+ addritem_folder_set_name( folder, cat->name[i] );
+ }
+
addrcache_id_folder( pilotFile->addressCache, folder );
addrcache_add_folder( pilotFile->addressCache, folder );
}
* successfully.
*/
gint jpilot_read_data( JPilotFile *pilotFile ) {
+ const gchar *cur_locale;
+
+ name_order = FAMILY_LAST;
+
+ cur_locale = conv_get_current_locale();
+
+ if( g_ascii_strncasecmp( cur_locale, "ja", 2 ) == 0 ) {
+ name_order = FAMILY_FIRST;
+ }
+
g_return_val_if_fail( pilotFile != NULL, -1 );
pilotFile->retVal = MGU_SUCCESS;
return addrcache_get_all_persons( pilotFile->addressCache );
}
-/**
- * Check label list for specified label name.
- * \param ai Address info to check.
- * \param lblCheck Label name to check.
- * \return Index of label in address structure. <code>-1</code> if NULL/empty
- * label name, <code>-2</code> if label not found.
-*/
-static gint jpilot_check_label( struct AddressAppInfo *ai, gchar *lblCheck ) {
- gint i;
- gchar *lblName;
-
- if( lblCheck == NULL ) return -1;
- if( strlen( lblCheck ) < 1 ) return -1;
- for( i = 0; i < JPILOT_NUM_LABELS; i++ ) {
- lblName = ai->labels[i];
- if( lblName ) {
- if( strlen( lblName ) ) {
- if( g_strcasecmp( lblName, lblCheck ) == 0 ) return i;
- }
- }
- }
- return -2;
-}
-
/**
* Validate that all parameters specified.
* \param pilotFile JPilot control data.
* no home. Filename should be <code>g_free()</code> when done.
*/
gchar *jpilot_find_pilotdb( void ) {
- gchar *homedir;
+ const gchar *homedir;
gchar str[ WORK_BUFLEN ];
gint len;
FILE *fp;
- homedir = g_get_home_dir();
+ homedir = get_home_dir();
if( ! homedir ) return g_strdup( "" );
strcpy( str, homedir );
strcat( str, JPILOT_DBHOME_FILE );
/* Attempt to open */
- if( ( fp = fopen( str, "rb" ) ) != NULL ) {
+ if( ( fp = g_fopen( str, "rb" ) ) != NULL ) {
fclose( fp );
}
else {
if( labelName ) {
node = pilotFile->customLabels;
while( node ) {
- if( g_strcasecmp( labelName, ( gchar * ) node->data ) == 0 ) {
+ if( g_utf8_collate( labelName, ( gchar * ) node->data ) == 0 ) {
retVal = TRUE;
break;
}