g_return_if_fail(book != NULL);
fprintf(stream, "AddressBook:\n");
- fprintf(stream, "\tpath : '%s'\n", book->path);
- fprintf(stream, "\tfile : '%s'\n", book->fileName);
- fprintf(stream, "\tstatus : %d : '%s'\n", book->retVal,
- mgu_error2string(book->retVal));
+ fprintf(stream, "\t path : '%s'\n", book->path);
+ fprintf(stream, "\t file : '%s'\n", book->fileName);
+ fprintf(stream, "\tstatus : %d\n", book->retVal );
addrcache_print(book->addressCache, stream);
}
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2002 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2003 Hiroyuki Yamamoto
*
* 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
{N_("/Pa_ste Address"), NULL, addressbook_clip_paste_address_cb, 0, NULL}
};
+/**
+ * Structure of error message table.
+ */
+typedef struct _ErrMsgTableEntry ErrMsgTableEntry;
+struct _ErrMsgTableEntry {
+ gint code;
+ gchar *description;
+};
+
+static gchar *_errMsgUnknown_ = N_( "Unknown" );
+
+/**
+ * Lookup table of error messages for general errors. Note that a NULL
+ * description signifies the end of the table.
+ */
+static ErrMsgTableEntry _lutErrorsGeneral_[] = {
+ { MGU_SUCCESS, N_("Success") },
+ { MGU_BAD_ARGS, N_("Bad arguments") },
+ { MGU_NO_FILE, N_("File not specified") },
+ { MGU_OPEN_FILE, N_("Error opening file") },
+ { MGU_ERROR_READ, N_("Error reading file") },
+ { MGU_EOF, N_("End of file encountered") },
+ { MGU_OO_MEMORY, N_("Error allocating memory") },
+ { MGU_BAD_FORMAT, N_("Bad file format") },
+ { MGU_ERROR_WRITE, N_("Error writing to file") },
+ { MGU_OPEN_DIRECTORY, N_("Error opening directory") },
+ { MGU_NO_PATH, N_("No path specified") },
+ { 0, NULL }
+};
+
+#ifdef USE_LDAP
+/**
+ * Lookup table of error messages for LDAP errors.
+ */
+static ErrMsgTableEntry _lutErrorsLDAP_[] = {
+ { MGU_SUCCESS, N_("Success") },
+ { MGU_LDAP_CONNECT, N_("Error connecting to LDAP server") },
+ { MGU_LDAP_INIT, N_("Error initializing LDAP") },
+ { MGU_LDAP_BIND, N_("Error binding to LDAP server") },
+ { MGU_LDAP_SEARCH, N_("Error searching LDAP database") },
+ { MGU_LDAP_TIMEOUT, N_("Timeout performing LDAP operation") },
+ { MGU_LDAP_CRITERIA, N_("Error in LDAP search criteria") },
+ { MGU_LDAP_CRITERIA, N_("Error in LDAP search criteria") },
+ { MGU_LDAP_NOENTRIES, N_("No LDAP entries found for search criteria") },
+ { 0, NULL }
+};
+#endif
+
+/**
+ * Lookup message for specified error code.
+ * \param lut Lookup table.
+ * \param code Code to lookup.
+ * \return Description associated to code.
+ */
+static gchar *addressbook_err2string( ErrMsgTableEntry lut[], gint code ) {
+ gchar *desc = NULL;
+ ErrMsgTableEntry entry;
+ gint i;
+
+ for( i = 0; ; i++ ) {
+ entry = lut[ i ];
+ if( entry.description == NULL ) break;
+ if( entry.code == code ) {
+ desc = entry.description;
+ break;
+ }
+ }
+ if( ! desc ) {
+ desc = _errMsgUnknown_;
+ }
+ return desc;
+}
+
void addressbook_open(Compose *target)
{
/* Initialize all static members */
static void addressbook_ds_show_message( AddressDataSource *ds ) {
gint retVal;
gchar *name;
+ gchar *desc;
*addressbook_msgbuf = '\0';
if( ds ) {
name = addrindex_ds_get_name( ds );
sizeof(addressbook_msgbuf), "%s", name );
}
else {
+ desc = addressbook_err2string( _lutErrorsGeneral_, retVal );
g_snprintf( addressbook_msgbuf,
- sizeof(addressbook_msgbuf), "%s: %s", name,
- mgu_error2string( retVal ) );
- }
+ sizeof(addressbook_msgbuf), "%s: %s", name, desc );
+ }
}
addressbook_status_show( addressbook_msgbuf );
}
static void addressbook_ldap_show_message( SyldapServer *svr ) {
gchar *name;
+ gchar *desc;
*addressbook_msgbuf = '\0';
if( svr ) {
name = syldap_get_name( svr );
name );
}
else {
+ desc = addressbook_err2string(
+ _lutErrorsLDAP_, svr->retVal );
g_snprintf( addressbook_msgbuf,
sizeof(addressbook_msgbuf),
- "%s: %s", name,
- mgu_error2string( svr->retVal ) );
+ "%s: %s", name, desc );
}
}
}
fprintf( stream, "AddressIndex:\n" );
fprintf( stream, "\tfile path: '%s'\n", addrIndex->filePath );
fprintf( stream, "\tfile name: '%s'\n", addrIndex->fileName );
- fprintf( stream, "\t status: %d : '%s'\n", addrIndex->retVal, mgu_error2string( addrIndex->retVal ) );
+ fprintf( stream, "\t status: %d\n", addrIndex->retVal );
fprintf( stream, "\tconverted: '%s'\n", addrIndex->wasConverted ? "yes" : "no" );
fprintf( stream, "\tcvt error: '%s'\n", addrIndex->conversionError ? "yes" : "no" );
fprintf( stream, "\t---\n" );
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2001 Match Grun
+ * Copyright (C) 2001-2003 Match Grun
*
* 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
static GdkPixmap *markxpm;
static GdkBitmap *markxpmmask;
+/**
+ * Structure of error message table.
+ */
+typedef struct _ErrMsgTableEntry ErrMsgTableEntry;
+struct _ErrMsgTableEntry {
+ gint code;
+ gchar *description;
+};
+
+static gchar *_errMsgUnknown_ = N_( "Unknown" );
+
+/**
+ * Lookup table of error messages for general errors. Note that a NULL
+ * description signifies the end of the table.
+ */
+static ErrMsgTableEntry _lutErrorsLDIF_[] = {
+ { MGU_SUCCESS, N_("Success") },
+ { MGU_BAD_ARGS, N_("Bad arguments") },
+ { MGU_NO_FILE, N_("File not specified") },
+ { MGU_OPEN_FILE, N_("Error opening file") },
+ { MGU_ERROR_READ, N_("Error reading file") },
+ { MGU_EOF, N_("End of file encountered") },
+ { MGU_OO_MEMORY, N_("Error allocating memory") },
+ { MGU_BAD_FORMAT, N_("Bad file format") },
+ { MGU_ERROR_WRITE, N_("Error writing to file") },
+ { MGU_OPEN_DIRECTORY, N_("Error opening directory") },
+ { MGU_NO_PATH, N_("No path specified") },
+ { 0, NULL }
+};
+
+/**
+ * Lookup message for specified error code.
+ * \param lut Lookup table.
+ * \param code Code to lookup.
+ * \return Description associated to code.
+ */
+static gchar *imp_ldif_err2string( ErrMsgTableEntry lut[], gint code ) {
+ gchar *desc = NULL;
+ ErrMsgTableEntry entry;
+ gint i;
+
+ for( i = 0; ; i++ ) {
+ entry = lut[ i ];
+ if( entry.description == NULL ) break;
+ if( entry.code == code ) {
+ desc = entry.description;
+ break;
+ }
+ }
+ if( ! desc ) {
+ desc = _errMsgUnknown_;
+ }
+ return desc;
+}
+
static void imp_ldif_status_show( gchar *msg ) {
if( impldif_dlg.statusbar != NULL ) {
- gtk_statusbar_pop( GTK_STATUSBAR(impldif_dlg.statusbar), impldif_dlg.status_cid );
+ gtk_statusbar_pop( GTK_STATUSBAR(impldif_dlg.statusbar),
+ impldif_dlg.status_cid );
if( msg ) {
- gtk_statusbar_push( GTK_STATUSBAR(impldif_dlg.statusbar), impldif_dlg.status_cid, msg );
+ gtk_statusbar_push(
+ GTK_STATUSBAR(impldif_dlg.statusbar),
+ impldif_dlg.status_cid, msg );
}
}
}
row = gtk_clist_append( clist, text );
gtk_clist_set_row_data( clist, row, rec );
if( rec->selected )
- gtk_clist_set_pixmap( clist, row, FIELD_COL_SELECT, markxpm, markxpmmask );
+ gtk_clist_set_pixmap(
+ clist, row, FIELD_COL_SELECT, markxpm,
+ markxpmmask );
impldif_dlg.rowCount++;
}
node = g_list_next( node );
ldif_set_accessed( ldf, FALSE );
}
-static void imp_ldif_field_list_selected( GtkCList *clist, gint row, gint column, GdkEvent *event, gpointer data ) {
+static void imp_ldif_field_list_selected(
+ GtkCList *clist, gint row, gint column, GdkEvent *event,
+ gpointer data )
+{
Ldif_FieldRec *rec = gtk_clist_get_row_data( clist, row );
impldif_dlg.rowIndSelect = row;
if( rec ) {
gtk_label_set_text( GTK_LABEL(impldif_dlg.name_ldif), rec->tagName );
if( rec->userName )
- gtk_entry_set_text( GTK_ENTRY(impldif_dlg.name_attrib), rec->userName );
+ gtk_entry_set_text(
+ GTK_ENTRY(impldif_dlg.name_attrib), rec->userName );
gtk_toggle_button_set_active(
GTK_TOGGLE_BUTTON( impldif_dlg.check_select),
rec->selected );
gtk_widget_grab_focus(impldif_dlg.name_attrib);
}
-static void imp_ldif_field_list_toggle( GtkCList *clist, GdkEventButton *event, gpointer data ) {
+static void imp_ldif_field_list_toggle(
+ GtkCList *clist, GdkEventButton *event, gpointer data )
+{
if( ! event ) return;
if( impldif_dlg.rowIndSelect < 0 ) return;
if( event->button == 1 ) {
if( event->type == GDK_2BUTTON_PRESS ) {
- Ldif_FieldRec *rec = gtk_clist_get_row_data( clist, impldif_dlg.rowIndSelect );
+ Ldif_FieldRec *rec = gtk_clist_get_row_data(
+ clist, impldif_dlg.rowIndSelect );
if( rec ) {
rec->selected = ! rec->selected;
imp_ldif_update_row( clist );
rec = gtk_clist_get_row_data( clist, impldif_dlg.rowIndSelect );
g_free( rec->userName );
- rec->userName = gtk_editable_get_chars( GTK_EDITABLE(impldif_dlg.name_attrib), 0, -1 );
- rec->selected = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( impldif_dlg.check_select) );
+ rec->userName = gtk_editable_get_chars(
+ GTK_EDITABLE(impldif_dlg.name_attrib), 0, -1 );
+ rec->selected = gtk_toggle_button_get_active(
+ GTK_TOGGLE_BUTTON( impldif_dlg.check_select) );
imp_ldif_update_row( clist );
gtk_clist_select_row( clist, row, 0 );
gtk_label_set_text( GTK_LABEL(impldif_dlg.name_ldif), "" );
gtk_entry_set_text( GTK_ENTRY(impldif_dlg.name_attrib), "" );
- gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( impldif_dlg.check_select), FALSE );
+ gtk_toggle_button_set_active(
+ GTK_TOGGLE_BUTTON( impldif_dlg.check_select), FALSE );
}
/*
sMsg = _( "LDIF file imported successfully." );
}
else {
- sMsg = mgu_error2string( _ldifFile_->retVal );
+ sMsg = imp_ldif_err2string( _lutErrorsLDIF_, _ldifFile_->retVal );
}
imp_ldif_status_show( sMsg );
gtk_widget_grab_focus(impldif_dlg.btnCancel);
/* First row */
top = 0;
label = gtk_label_new(_("LDIF Field"));
- gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
+ GTK_FILL, 0, 0, 0);
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
name_ldif = gtk_label_new( "" );
gtk_misc_set_alignment(GTK_MISC(name_ldif), 0.01, 0.5);
- gtk_table_attach(GTK_TABLE(table), name_ldif, 1, 3, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), name_ldif, 1, 3, top, (top + 1),
+ GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
/* Second row */
++top;
label = gtk_label_new(_("Attribute"));
- gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
+ GTK_FILL, 0, 0, 0);
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
name_attrib = gtk_entry_new();
- gtk_table_attach(GTK_TABLE(table), name_attrib, 1, 3, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), name_attrib, 1, 3, top, (top + 1),
+ GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
/* Next row */
++top;
label = gtk_label_new(_("Select"));
- gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1), GTK_FILL, 0, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), label, 0, 1, top, (top + 1),
+ GTK_FILL, 0, 0, 0);
gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
check_select = gtk_check_button_new();
- gtk_table_attach(GTK_TABLE(table), check_select, 1, 2, top, (top + 1), GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
+ gtk_table_attach(GTK_TABLE(table), check_select, 1, 2, top, (top + 1),
+ GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
buttonMod = gtk_button_new_with_label( _("Modify"));
- gtk_table_attach(GTK_TABLE(table), buttonMod, 2, 3, top, (top + 1), GTK_FILL, 0, 3, 0);
+ gtk_table_attach(GTK_TABLE(table), buttonMod, 2, 3, top, (top + 1),
+ GTK_FILL, 0, 3, 0);
gtk_widget_show_all(vbox);
gtk_widget_show( label );
gtk_notebook_set_tab_label(
GTK_NOTEBOOK( impldif_dlg.notebook ),
- gtk_notebook_get_nth_page( GTK_NOTEBOOK( impldif_dlg.notebook ), pageNum ), label );
+ gtk_notebook_get_nth_page( GTK_NOTEBOOK( impldif_dlg.notebook ), pageNum ),
+ label );
table = gtk_table_new(3, 2, FALSE);
gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 0);
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2001 Match Grun
+ * Copyright (C) 2001-2003 Match Grun
*
* 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
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2001 Match Grun
+ * Copyright (C) 2001-2003 Match Grun
*
* 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
*/
/*
- * General functions for create common address book entries.
+ * Definitions for generic functions.
*/
#include <glib.h>
return buf;
}
-struct mgu_error_entry {
- gint e_code;
- gchar *e_reason;
-};
-
-static const struct mgu_error_entry mgu_error_list[] = {
- { MGU_SUCCESS, "Success" },
- { MGU_BAD_ARGS, "Bad arguments" },
- { MGU_NO_FILE, "File not specified" },
- { MGU_OPEN_FILE, "Error opening file" },
- { MGU_ERROR_READ, "Error reading file" },
- { MGU_EOF, "End of file encountered" },
- { MGU_OO_MEMORY, "Error allocating memory" },
- { MGU_BAD_FORMAT, "Bad file format" },
- { MGU_LDAP_CONNECT, "Error connecting to LDAP server" },
- { MGU_LDAP_INIT, "Error initializing LDAP" },
- { MGU_LDAP_BIND, "Error binding to LDAP server" },
- { MGU_LDAP_SEARCH, "Error searching LDAP database" },
- { MGU_LDAP_TIMEOUT, "Timeout performing LDAP operation" },
- { MGU_LDAP_CRITERIA, "Error in LDAP search criteria" },
- { MGU_LDAP_CRITERIA, "Error in LDAP search criteria" },
- { MGU_LDAP_NOENTRIES, "No LDAP entries found for search criteria" },
- { MGU_ERROR_WRITE, "Error writing to file" },
- { MGU_OPEN_DIRECTORY, "Error opening directory" },
- { MGU_NO_PATH, "No path specified" },
- { -999, NULL }
-};
-
-static const struct mgu_error_entry *mgu_error_find( gint err ) {
- gint i;
- for ( i = 0; mgu_error_list[i].e_code != -999; i++ ) {
- if ( err == mgu_error_list[i].e_code )
- return & mgu_error_list[i];
- }
- return NULL;
-}
-
-/*
-* Return error message for specified error code.
-*/
-gchar *mgu_error2string( gint err ) {
- const struct mgu_error_entry *e;
- e = mgu_error_find( err );
- return ( e != NULL ) ? e->e_reason : "Unknown error";
-}
-
/*
* Replace existing string with new string.
*/
return;
}
+/*
+ * Return reference to longest entry in the specified linked list.
+ * It is assumed that the list contains only gchar objects.
+ * Enter: list List of gchar strings to examine.
+ * Return: Reference to longest entry, or NULL if nothing found.
+ */
+gchar *mgu_slist_longest_entry( GSList *list ) {
+ GSList *node;
+ gchar *name = NULL;
+ gint iLen = 0, iLenT = 0;
+
+ node = list;
+ while( node ) {
+ if( name == NULL ) {
+ name = node->data;
+ iLen = strlen( name );
+ }
+ else {
+ iLenT = strlen( node->data );
+ if( iLenT > iLen ) {
+ name = node->data;
+ iLen = iLenT;
+ }
+ }
+ node = g_slist_next( node );
+ }
+ return name;
+}
+
+/*
+ * Return reference to longest entry in the specified linked list.
+ * It is assumed that the list contains only gchar objects.
+ * Enter: list List of gchar strings to examine.
+ * Return: Reference to longest entry, or NULL if nothing found.
+ */
+gchar *mgu_list_longest_entry( GList *list ) {
+ GList *node;
+ gchar *name = NULL;
+ gint iLen = 0, iLenT = 0;
+
+ node = list;
+ while( node ) {
+ if( name == NULL ) {
+ name = node->data;
+ iLen = strlen( name );
+ }
+ else {
+ iLenT = strlen( node->data );
+ if( iLenT > iLen ) {
+ name = node->data;
+ iLen = iLenT;
+ }
+ }
+ node = g_list_next( node );
+ }
+ return name;
+}
+
+/*
+ * Test whether string appears in list of strings, ignoring case. NULL or empty
+ * strings will be ignored.
+ * Enter: list List to process.
+ * str String to test.
+ * Return: TRUE if string is unique.
+ */
+gboolean mgu_slist_test_unq_nc( GSList *list, gchar *str ) {
+ GSList *node;
+
+ if( str ) {
+ if( strlen( str ) > 0 ) {
+ node = list;
+ while( node ) {
+ if( g_strcasecmp( str, node->data ) == 0 )
+ return FALSE;
+ node = g_slist_next( node );
+ }
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+/*
+ * Test whether string appears in list of strings, ignoring case. NULL or empty
+ * strings will be ignored.
+ * Enter: list List to process.
+ * str String to test.
+ * Return: TRUE if string is unique.
+ */
+gboolean mgu_list_test_unq_nc( GList *list, gchar *str ) {
+ GList *node;
+
+ if( str ) {
+ if( strlen( str ) > 0 ) {
+ node = list;
+ while( node ) {
+ if( g_strcasecmp( str, node->data ) == 0 )
+ return FALSE;
+ node = g_list_next( node );
+ }
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
/*
* End of Source.
*/
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2001 Match Grun
+ * Copyright (C) 2001-2003 Match Grun
*
* 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
*/
/*
- * General definitions for common address book entries.
+ * Definitions for generic functions.
*/
#ifndef __MGUTILS_H__
#define MGU_EOF -5
#define MGU_OO_MEMORY -6
#define MGU_BAD_FORMAT -7
-#define MGU_LDAP_CONNECT -8
-#define MGU_LDAP_INIT -9
-#define MGU_LDAP_BIND -10
-#define MGU_LDAP_SEARCH -11
-#define MGU_LDAP_TIMEOUT -12
-#define MGU_LDAP_CRITERIA -13
-#define MGU_LDAP_NOENTRIES -14
#define MGU_ERROR_WRITE -15
#define MGU_OPEN_DIRECTORY -16
#define MGU_NO_PATH -17
void mgu_free_list ( GSList *list );
void mgu_free_dlist ( GList *list );
gchar *mgu_list_coalesce ( GSList *list );
-gchar *mgu_error2string ( gint err );
gchar *mgu_replace_string ( gchar *str, const gchar *value );
void mgu_clear_slist ( GSList *list );
void mgu_clear_list ( GList *list );
gint *tokenCnt );
void mgu_str_unescape ( gchar *str );
void mgu_str_ltc2space ( gchar *str, gchar chlead, gchar chtail );
+gchar *mgu_slist_longest_entry ( GSList *list );
+gchar *mgu_list_longest_entry ( GList *list );
+gboolean mgu_slist_test_unq_nc ( GSList *list, gchar *str );
+gboolean mgu_list_test_unq_nc ( GList *list, gchar *str );
#endif /* __MGUTILS_H__ */
+
+/*
+* End of Source.
+*/
+
/*
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2001-2002 Match Grun
+ * Copyright (C) 2001-2003 Match Grun
*
* 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
#define SYLDAP_ATTR_EMAIL "mail"
#define SYLDAP_ATTR_UID "uid"
+#define MGU_LDAP_CONNECT -51
+#define MGU_LDAP_INIT -52
+#define MGU_LDAP_BIND -53
+#define MGU_LDAP_SEARCH -54
+#define MGU_LDAP_TIMEOUT -55
+#define MGU_LDAP_CRITERIA -56
+#define MGU_LDAP_NOENTRIES -57
+
typedef struct _SyldapServer SyldapServer;
struct _SyldapServer {
AddressBookType type;