+/**
+ * Format criteria list for display.
+ * \param ctl Control object.
+ * \return Formatted string, or <i>NULL</i> if no attributes found.
+ */
+static gchar *editldap_build_criteria_list( const LdapControl *ctl ) {
+ gchar *str = NULL;
+ gchar *tmp = NULL;
+ GList *node;
+
+ node = ldapctl_get_criteria_list( ctl );
+ while( node ) {
+ gchar *attr = node->data;
+ if( str ) {
+ tmp = g_strdup_printf( "%s, %s", str, attr );
+ g_free( str );
+ str = tmp;
+ tmp = NULL;
+ }
+ else {
+ str = g_strdup( attr );
+ }
+ node = g_list_next( node );
+ }
+
+ return str;
+}
+
+/**
+ * Parse out individual attribute names from criteria string.
+ * \param criteria Criteria string.
+ * \ctl Control object.
+ */
+static void editldap_parse_criteria( gchar *criteria, LdapControl *ctl ) {
+ gchar *ptr;
+ gchar **splitStr;
+ gint i;
+
+ /* Replace delimiters with spaces */
+ ptr = criteria;
+ while( *ptr ) {
+ if( *ptr == ',' || *ptr == ';' || *ptr == '|' )
+ *ptr = ' ';
+ ptr++;
+ }
+
+ /* Parse string */
+ ldapctl_criteria_list_clear( ctl );
+ splitStr = g_strsplit( criteria, " ", 0 );
+ i = 0;
+ while( TRUE ) {
+ if( splitStr[i] ) {
+ if( *splitStr[i] ) {
+ ldapctl_criteria_list_add( ctl, splitStr[i] );
+ }
+ }
+ else {
+ break;
+ }
+ i++;
+ }
+ g_strfreev( splitStr );
+}
+
+/**
+ * Clear entry fields to reasonable defaults (for a new server entry).
+ */
+static void edit_ldap_clear_fields( void ) {
+ gtk_entry_set_text(
+ GTK_ENTRY(ldapedit.entry_name), ADDRESSBOOK_GUESS_LDAP_NAME );
+ gtk_entry_set_text(
+ GTK_ENTRY(ldapedit.entry_server), ADDRESSBOOK_GUESS_LDAP_SERVER );
+ gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_baseDN), "");
+ gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_bindDN), "");
+ gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_bindPW), "");
+ gtk_spin_button_set_value(
+ GTK_SPIN_BUTTON( ldapedit.spinbtn_port ), LDAPCTL_DFL_PORT );
+ gtk_spin_button_set_value(
+ GTK_SPIN_BUTTON( ldapedit.spinbtn_timeout ), LDAPCTL_DFL_TIMEOUT );
+ gtk_spin_button_set_value(
+ GTK_SPIN_BUTTON( ldapedit.spinbtn_maxentry ), LDAPCTL_DFL_TIMEOUT );
+ gtk_entry_set_text(
+ GTK_ENTRY(ldapedit.entry_criteria), LDAPCTL_DFL_ATTR_LIST );
+ gtk_spin_button_set_value(
+ GTK_SPIN_BUTTON(ldapedit.spinbtn_queryage), LDAPCTL_DFL_QUERY_AGE );
+ gtk_toggle_button_set_active(
+ GTK_TOGGLE_BUTTON( ldapedit.check_dynsearch), TRUE );
+ gtk_toggle_button_set_active(
+ GTK_TOGGLE_BUTTON( ldapedit.check_matchoption), FALSE );
+}
+
+/**
+ * Load entry fields from server control data.
+ * \param server Server object.
+ */
+static void edit_ldap_set_fields( LdapServer *server ) {
+ LdapControl *ctl;
+ gchar *crit;
+
+ if( ldapsvr_get_name( server ) )
+ gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_name),
+ ldapsvr_get_name( server ) );
+
+ ctl = server->control;
+ if( ctl->hostName )
+ gtk_entry_set_text(
+ GTK_ENTRY(ldapedit.entry_server), ctl->hostName);
+ if( ctl->baseDN )
+ gtk_entry_set_text(
+ GTK_ENTRY(ldapedit.entry_baseDN), ctl->baseDN );
+ if( ctl->bindDN )
+ gtk_entry_set_text(
+ GTK_ENTRY(ldapedit.entry_bindDN), ctl->bindDN );
+ if( ctl->bindPass )
+ gtk_entry_set_text(
+ GTK_ENTRY(ldapedit.entry_bindPW), ctl->bindPass );
+ gtk_spin_button_set_value(
+ GTK_SPIN_BUTTON(ldapedit.spinbtn_port), ctl->port );
+ gtk_spin_button_set_value(
+ GTK_SPIN_BUTTON(ldapedit.spinbtn_timeout), ctl->timeOut );
+ gtk_spin_button_set_value(
+ GTK_SPIN_BUTTON(ldapedit.spinbtn_maxentry), ctl->maxEntries );
+
+ /* Format criteria */
+ crit = editldap_build_criteria_list( ctl );
+ if( crit ) {
+ gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_criteria), crit );
+ g_free( crit );
+ }
+ else {
+ gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_criteria), "" );
+ }
+ gtk_spin_button_set_value(
+ GTK_SPIN_BUTTON(ldapedit.spinbtn_queryage), ctl->maxQueryAge );
+ gtk_toggle_button_set_active(
+ GTK_TOGGLE_BUTTON( ldapedit.check_dynsearch), server->searchFlag );
+ gtk_toggle_button_set_active(
+ GTK_TOGGLE_BUTTON( ldapedit.check_matchoption),
+ ( ctl->matchingOption == LDAPCTL_MATCH_CONTAINS ) );
+}
+
+/**
+ * Edit LDAP server datasource that appears addressbook.
+ * \param addrIndex Address index object.
+ * \param ads Data source adapter.
+ * \return Update data source adapter, or <code>NULL</code> if user cancelled
+ * edit with dialog.
+ */
+AdapterDSource *addressbook_edit_ldap(
+ AddressIndex *addrIndex, AdapterDSource *ads )
+{