2007-08-09 [colin] 2.10.0cvs109
[claws.git] / src / editldap.c
index 3a424f3ce5c5e92e7117426b12241129e86ed955..391b511ded8efacbed616816b18c9ea513b2d3f0 100644 (file)
@@ -1,10 +1,10 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2001-2006 Match Grun and the Sylpheed-Claws team
+ * Copyright (C) 2001-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/>.
+ * 
  */
 
 /*
@@ -311,8 +311,8 @@ static void edit_ldap_basedn_select( void ) {
        g_free( sPass );
 }
 
-static void edit_ldap_search_reset( void ) {
-       gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_criteria), LDAPCTL_DFL_ATTR_LIST );
+static void edit_ldap_search_reset() {
+       gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_criteria), ldapctl_get_default_criteria());
 }
 
 static void addressbook_edit_ldap_dialog_create( gboolean *cancelled ) {
@@ -325,7 +325,7 @@ static void addressbook_edit_ldap_dialog_create( gboolean *cancelled ) {
        GtkWidget *hsbox;
        GtkWidget *statusbar;
 
-       window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "editldap");
        gtk_widget_set_size_request(window, 450, -1);
        gtk_container_set_border_width(GTK_CONTAINER(window), 0);
        gtk_window_set_title(GTK_WINDOW(window), _("Edit LDAP Server"));
@@ -395,7 +395,7 @@ static void addressbook_edit_ldap_page_basic( gint pageNum, gchar *pageLbl ) {
        GtkObject *spinbtn_port_adj;
        GtkWidget *spinbtn_port;
 #ifdef USE_LDAP_TLS
-       GtkWidget *enable_ssl_chkbtn, *enable_tls_chkbtn;
+       GtkWidget *enable_ssl_checkbtn, *enable_tls_checkbtn;
 #endif
        GtkWidget *entry_baseDN;
        GtkWidget *check_btn;
@@ -450,7 +450,7 @@ static void addressbook_edit_ldap_page_basic( gint pageNum, gchar *pageLbl ) {
                "\"ldap.mydomain.com\" may be appropriate for the " \
                "\"mydomain.com\" organization. An IP address may also be " \
                "used. You may specify \"localhost\" if running an LDAP " \
-               "server on the same computer as Sylpheed-Claws." ),
+               "server on the same computer as Claws Mail." ),
                NULL );
 
        /* Next row */
@@ -467,23 +467,23 @@ static void addressbook_edit_ldap_page_basic( gint pageNum, gchar *pageLbl ) {
        gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spinbtn_port), TRUE);
        
 #ifdef USE_LDAP_TLS
-       enable_tls_chkbtn = gtk_check_button_new_with_label(_("TLS"));
-       enable_ssl_chkbtn = gtk_check_button_new_with_label(_("SSL"));
-       SET_TOGGLE_SENSITIVITY_REVERSE(enable_tls_chkbtn, enable_ssl_chkbtn);
-       SET_TOGGLE_SENSITIVITY_REVERSE(enable_ssl_chkbtn, enable_tls_chkbtn);
-       gtk_tooltips_set_tip( toolTip, enable_tls_chkbtn, _( 
+       enable_tls_checkbtn = gtk_check_button_new_with_label(_("TLS"));
+       enable_ssl_checkbtn = gtk_check_button_new_with_label(_("SSL"));
+       SET_TOGGLE_SENSITIVITY_REVERSE(enable_tls_checkbtn, enable_ssl_checkbtn);
+       SET_TOGGLE_SENSITIVITY_REVERSE(enable_ssl_checkbtn, enable_tls_checkbtn);
+       gtk_tooltips_set_tip( toolTip, enable_tls_checkbtn, _( 
                "Enable secure connection to the LDAP server via TLS."
                "If connection fails, be sure to check the correct "
-               "configuration in ldap.conf (TLS_CACERT or TLS_CACERTDIR fields)." ),
+               "configuration in ldap.conf (TLS_CACERTDIR and TLS_REQCERT fields)." ),
                NULL );
-       gtk_tooltips_set_tip( toolTip, enable_ssl_chkbtn, _( 
+       gtk_tooltips_set_tip( toolTip, enable_ssl_checkbtn, _( 
                "Enable secure connection to the LDAP server via SSL."
                "If connection fails, be sure to check the correct "
-               "configuration in ldap.conf (TLS_CACERT or TLS_CACERTDIR fields)." ),
+               "configuration in ldap.conf (TLS_CACERTDIR and TLS_REQCERT fields)." ),
                NULL );
 
-       gtk_box_pack_start (GTK_BOX (hbox_spin), enable_tls_chkbtn, TRUE, FALSE, 0);
-       gtk_box_pack_start (GTK_BOX (hbox_spin), enable_ssl_chkbtn, TRUE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (hbox_spin), enable_tls_checkbtn, TRUE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (hbox_spin), enable_ssl_checkbtn, TRUE, FALSE, 0);
 #endif
 
        gtk_table_attach(GTK_TABLE(table), hbox_spin, 1, 2, top, (top + 1),
@@ -517,7 +517,7 @@ static void addressbook_edit_ldap_page_basic( gint pageNum, gchar *pageLbl ) {
        gtk_tooltips_set_tip( toolTip, entry_baseDN, _( 
                "This specifies the name of the directory to be searched " \
                "on the server. Examples include:\n" \
-               "  dc=sylpheed,dc=org\n" \
+               "  dc=claws-mail,dc=org\n" \
                "  ou=people,dc=domainname,dc=com\n" \
                "  o=Organization Name,c=Country\n"
                ),
@@ -546,10 +546,10 @@ static void addressbook_edit_ldap_page_basic( gint pageNum, gchar *pageLbl ) {
        ldapedit.spinbtn_port = spinbtn_port;
        ldapedit.entry_baseDN = entry_baseDN;
 #ifdef USE_LDAP_TLS
-       ldapedit.enable_ssl = enable_ssl_chkbtn;
-       ldapedit.enable_tls = enable_tls_chkbtn;
+       ldapedit.enable_ssl = enable_ssl_checkbtn;
+       ldapedit.enable_tls = enable_tls_checkbtn;
 
-       g_signal_connect(G_OBJECT(enable_ssl_chkbtn), "toggled", \
+       g_signal_connect(G_OBJECT(enable_ssl_checkbtn), "toggled", \
                         G_CALLBACK(editldap_update_port), NULL); 
 #endif                  
 }
@@ -591,6 +591,7 @@ static void addressbook_edit_ldap_page_search( gint pageNum, gchar *pageLbl ) {
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
        entry_criteria = gtk_entry_new();
+       gtk_editable_set_editable(GTK_EDITABLE(entry_criteria), FALSE);
        gtk_table_attach(GTK_TABLE(table), entry_criteria, 1, 2, top, (top + 1),
                GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
 
@@ -732,7 +733,7 @@ static void addressbook_edit_ldap_page_extended( gint pageNum, gchar *pageLbl )
        gtk_tooltips_set_tip( toolTip, entry_bindDN, _( 
                "The LDAP user account name to be used to connect to the server. " \
                "This is usually only used for protected servers. This name " \
-               "is typically formatted as: \"cn=user,dc=sylpheed,dc=com\". " \
+               "is typically formatted as: \"cn=user,dc=claws-mail,dc=org\". " \
                "This is usually left empty when performing a search." ),
                NULL );
 
@@ -811,39 +812,6 @@ static void addressbook_edit_ldap_create( gboolean *cancelled ) {
        gtk_widget_show_all( ldapedit.window );
 }
 
-void edit_ldap_set_optmenu( GtkOptionMenu *optmenu, const gint value ) {
-       GList *cur;
-       GtkWidget *menu;
-       GtkWidget *menuitem;
-       gint menuVal;
-       gint n = 0;
-
-       g_return_if_fail(optmenu != NULL);
-
-       menu = gtk_option_menu_get_menu(optmenu);
-       for( cur = GTK_MENU_SHELL(menu)->children; cur != NULL; cur = cur->next ) {
-               menuitem = GTK_WIDGET(cur->data);
-               menuVal = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), "user_data"));
-               if( menuVal == value ) {
-                       gtk_option_menu_set_history(optmenu, n);
-                       return;
-               }
-               n++;
-       }
-       gtk_option_menu_set_history(optmenu, 0);
-}
-
-gint edit_ldap_get_optmenu( GtkOptionMenu *optmenu ) {
-       GtkWidget *menu;
-       GtkWidget *menuitem;
-
-       g_return_val_if_fail(optmenu != NULL, -1);
-
-       menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optmenu));
-       menuitem = gtk_menu_get_active(GTK_MENU(menu));
-       return GPOINTER_TO_INT(g_object_get_data(G_OBJECT(menuitem), "user_data"));
-}
-
 /**
  * Format criteria list for display.
  * \param ctl Control object.
@@ -911,7 +879,7 @@ static void editldap_parse_criteria( gchar *criteria, LdapControl *ctl ) {
 /**
  * Clear entry fields to reasonable defaults (for a new server entry).
  */
-static void edit_ldap_clear_fields( void ) {
+static void edit_ldap_clear_fields() {
        gtk_entry_set_text(
                GTK_ENTRY(ldapedit.entry_name), ADDRESSBOOK_GUESS_LDAP_NAME );
        gtk_entry_set_text(
@@ -926,7 +894,7 @@ static void edit_ldap_clear_fields( void ) {
        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_ENTRY(ldapedit.entry_criteria), ldapctl_get_default_criteria());
        gtk_spin_button_set_value(
                GTK_SPIN_BUTTON(ldapedit.spinbtn_queryage), LDAPCTL_DFL_QUERY_AGE );
        gtk_toggle_button_set_active(
@@ -966,8 +934,6 @@ static void edit_ldap_set_fields( LdapServer *server ) {
        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(
@@ -978,6 +944,8 @@ static void edit_ldap_set_fields( LdapServer *server ) {
        gtk_toggle_button_set_active(
                GTK_TOGGLE_BUTTON(ldapedit.enable_ssl), ctl->enableSSL );
 #endif
+       gtk_spin_button_set_value(
+               GTK_SPIN_BUTTON(ldapedit.spinbtn_port), ctl->port );
        /* Format criteria */
        crit = editldap_build_criteria_list( ctl );
        if( crit ) {
@@ -1032,7 +1000,7 @@ AdapterDSource *addressbook_edit_ldap(
                        GTK_WINDOW(ldapedit.window), _("Edit LDAP Server"));
        }
        else {
-               edit_ldap_clear_fields();
+               edit_ldap_clear_fields(NULL);
                gtk_window_set_title(
                        GTK_WINDOW(ldapedit.window), _("Add New LDAP Server"));
        }