2011-10-07 [colin] 3.7.10cvs21
[claws.git] / src / editldap.c
index c1c048ecdc90489e882e65d3cddc8ddd0dd5dea3..61e58e768d344b5029e5e8df198e5e4e733dbf40 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2001-2007 Match Grun and the Claws Mail team
+ * Copyright (C) 2001-2011 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
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <gdk/gdkkeysyms.h>
-#include <gtk/gtkwindow.h>
-#include <gtk/gtksignal.h>
-#include <gtk/gtklabel.h>
-#include <gtk/gtkentry.h>
-#include <gtk/gtktable.h>
-#include <gtk/gtkbutton.h>
+#include <gtk/gtk.h>
 
 #include "addressbook.h"
 #include "prefs_common.h"
@@ -97,7 +92,7 @@ static gboolean editldap_validate_criteria( gchar *criteria ) {
        gint i;
        gboolean errorFlag;
 
-       g_return_val_if_fail(criteria != NULL, TRUE);
+       cm_return_val_if_fail(criteria != NULL, TRUE);
 
        errorFlag = TRUE;
 
@@ -211,7 +206,7 @@ static gint edit_ldap_delete_event( GtkWidget *widget, GdkEventAny *event, gbool
 }
 
 static gboolean edit_ldap_key_pressed( GtkWidget *widget, GdkEventKey *event, gboolean *cancelled ) {
-       if (event && event->keyval == GDK_Escape) {
+       if (event && event->keyval == GDK_KEY_Escape) {
                *cancelled = TRUE;
                gtk_main_quit();
        }
@@ -248,7 +243,7 @@ static void edit_ldap_server_check( void ) {
                debug_print("ldap server: %s\nport: %d\nssl: %d\ntls: %d\nbindDN: %s\n", sHost, iPort, ssl, tls, sBind);
                if( ldaputil_test_connect( sHost, iPort, ssl, tls, iTime ) ) {
                        /* Attempt to read base DN */
-                       baseDN = ldaputil_read_basedn( sHost, iPort, sBind, sPass, iTime, ssl, tls );
+                       baseDN = ldaputil_read_basedn(sHost, iPort, sBind, sPass, iTime, ssl, tls);
                        if( baseDN ) {
                                GList *node = baseDN;
                                while( node ) {
@@ -339,7 +334,6 @@ static void addressbook_edit_ldap_dialog_create( gboolean *cancelled ) {
        gtk_container_set_border_width(GTK_CONTAINER(window), 0);
        gtk_window_set_title(GTK_WINDOW(window), _("Edit LDAP Server"));
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
-       gtk_window_set_modal(GTK_WINDOW(window), TRUE); 
        g_signal_connect(G_OBJECT(window), "delete_event",
                         G_CALLBACK(edit_ldap_delete_event),
                         cancelled);
@@ -402,7 +396,7 @@ static void addressbook_edit_ldap_page_basic( gint pageNum, gchar *pageLbl ) {
        GtkWidget *entry_name;
        GtkWidget *entry_server;
        GtkWidget *hbox_spin;
-       GtkObject *spinbtn_port_adj;
+       GtkAdjustment *spinbtn_port_adj;
        GtkWidget *spinbtn_port;
 #ifdef USE_LDAP_TLS
        GtkWidget *enable_ssl_checkbtn, *enable_tls_checkbtn;
@@ -410,7 +404,7 @@ static void addressbook_edit_ldap_page_basic( gint pageNum, gchar *pageLbl ) {
        GtkWidget *entry_baseDN;
        GtkWidget *check_btn;
        GtkWidget *lookdn_btn;
-       GtkTooltips *toolTip;
+       CLAWS_TIP_DECL();
        gint top;
 
        vbox = gtk_vbox_new( FALSE, 8 );
@@ -439,10 +433,8 @@ static void addressbook_edit_ldap_page_basic( gint pageNum, gchar *pageLbl ) {
        gtk_table_attach(GTK_TABLE(table), entry_name, 1, 2, top, (top + 1),
                GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
 
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, entry_name, _( 
-               "A name that you wish to call the server." ),
-               NULL );
+       CLAWS_SET_TIP(entry_name, _( 
+               "A name that you wish to call the server." ));
 
        /* Next row */
        ++top;
@@ -454,14 +446,12 @@ static void addressbook_edit_ldap_page_basic( gint pageNum, gchar *pageLbl ) {
        gtk_table_attach(GTK_TABLE(table), entry_server, 1, 2, top, (top + 1),
                GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
 
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, entry_server, _( 
+       CLAWS_SET_TIP(entry_server, _( 
                "This is the hostname of the server. For example, " \
                "\"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 Claws Mail." ),
-               NULL );
+               "server on the same computer as Claws Mail." ));
 
        /* Next row */
        ++top;
@@ -470,7 +460,7 @@ static void addressbook_edit_ldap_page_basic( gint pageNum, gchar *pageLbl ) {
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
        hbox_spin = gtk_hbox_new (FALSE, 8);
-       spinbtn_port_adj = gtk_adjustment_new (389, 1, 65535, 1, 1000, 1000);
+       spinbtn_port_adj = gtk_adjustment_new (389, 1, 65535, 1, 1000, 0);
        spinbtn_port = gtk_spin_button_new(GTK_ADJUSTMENT (spinbtn_port_adj), 1, 0);
        gtk_box_pack_start (GTK_BOX (hbox_spin), spinbtn_port, TRUE, FALSE, 0);
        gtk_widget_set_size_request (spinbtn_port, 64, -1);
@@ -481,16 +471,14 @@ static void addressbook_edit_ldap_page_basic( gint pageNum, gchar *pageLbl ) {
        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, _( 
+       CLAWS_SET_TIP(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_CACERTDIR and TLS_REQCERT fields)." ),
-               NULL );
-       gtk_tooltips_set_tip( toolTip, enable_ssl_checkbtn, _( 
+               "configuration in ldap.conf (TLS_CACERTDIR and TLS_REQCERT fields)." ));
+       CLAWS_SET_TIP(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_CACERTDIR and TLS_REQCERT fields)." ),
-               NULL );
+               "configuration in ldap.conf (TLS_CACERTDIR and TLS_REQCERT fields)." ));
 
        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);
@@ -499,19 +487,15 @@ static void addressbook_edit_ldap_page_basic( gint pageNum, gchar *pageLbl ) {
        gtk_table_attach(GTK_TABLE(table), hbox_spin, 1, 2, top, (top + 1),
                GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
 
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, spinbtn_port, _( 
+       CLAWS_SET_TIP(spinbtn_port, _( 
                "The port number that the server listens on. Port 389 is " \
-               "the default." ),
-               NULL );
+               "the default." ));
 
        check_btn = gtk_button_new_with_label( _(" Check Server "));
        gtk_table_attach(GTK_TABLE(table), check_btn, 2, 3, top, (top + 1), GTK_FILL, 0, 3, 0);
 
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, check_btn, _( 
-               "Press this button to test the connection to the server." ),
-               NULL );
+       CLAWS_SET_TIP(check_btn, _( 
+               "Press this button to test the connection to the server." ));
 
        /* Next row */
        ++top;
@@ -523,24 +507,20 @@ static void addressbook_edit_ldap_page_basic( gint pageNum, gchar *pageLbl ) {
        gtk_table_attach(GTK_TABLE(table), entry_baseDN, 1, 2, top, (top + 1),
                GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
 
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, entry_baseDN, _( 
+       CLAWS_SET_TIP(entry_baseDN, _( 
                "This specifies the name of the directory to be searched " \
                "on the server. Examples include:\n" \
                "  dc=claws-mail,dc=org\n" \
                "  ou=people,dc=domainname,dc=com\n" \
                "  o=Organization Name,c=Country\n"
-               ),
-               NULL );
+               ));
 
        lookdn_btn = gtkut_get_browse_file_btn(_("_Browse"));
        gtk_table_attach(GTK_TABLE(table), lookdn_btn, 2, 3, top, (top + 1), GTK_FILL, 0, 3, 0);
 
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, lookdn_btn, _( 
+       CLAWS_SET_TIP(lookdn_btn, _( 
                "Press this button to lookup the name of available " \
-               "directory names on the server." ),
-               NULL );
+               "directory names on the server." ));
 
        /* Signal handlers */
        g_signal_connect(G_OBJECT(check_btn), "clicked",
@@ -570,12 +550,12 @@ static void addressbook_edit_ldap_page_search( gint pageNum, gchar *pageLbl ) {
        GtkWidget *label;
        GtkWidget *entry_criteria;
        GtkWidget *hbox_spin;
-       GtkObject *spinbtn_queryage_adj;
+       GtkAdjustment *spinbtn_queryage_adj;
        GtkWidget *spinbtn_queryage;
        GtkWidget *check_dynsearch;
        GtkWidget *check_matchoption;
        GtkWidget *reset_btn;
-       GtkTooltips *toolTip;
+       CLAWS_TIP_DECL();
        gint top;
 
        vbox = gtk_vbox_new( FALSE, 8 );
@@ -604,21 +584,17 @@ static void addressbook_edit_ldap_page_search( gint pageNum, gchar *pageLbl ) {
        gtk_table_attach(GTK_TABLE(table), entry_criteria, 1, 2, top, (top + 1),
                GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
 
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, entry_criteria, _( 
+       CLAWS_SET_TIP(entry_criteria, _( 
                "A list of LDAP attribute names that should be searched " \
-               "when attempting to find a name or address." ),
-               NULL );
+               "when attempting to find a name or address." ));
 
        reset_btn = gtk_button_new_with_label( _(" Defaults "));
        gtk_table_attach(GTK_TABLE(table), reset_btn, 2, 3, top, (top + 1), GTK_FILL, 0, 3, 0);
 
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, reset_btn, _( 
+       CLAWS_SET_TIP(reset_btn, _( 
                "This resets the attribute names to a default value " \
                "that should find most names and addresses during a " \
-               "name or address search process." ),
-               NULL );
+               "name or address search process." ));
 
        /* Next row */
        ++top;
@@ -628,7 +604,7 @@ static void addressbook_edit_ldap_page_search( gint pageNum, gchar *pageLbl ) {
 
        hbox_spin = gtk_hbox_new (FALSE, 8);
        spinbtn_queryage_adj = gtk_adjustment_new(
-               LDAPCTL_DFL_QUERY_AGE, 1, LDAPCTL_MAX_QUERY_AGE, 10, 1000, 1000 );
+               LDAPCTL_DFL_QUERY_AGE, 1, LDAPCTL_MAX_QUERY_AGE, 10, 1000, 0 );
        spinbtn_queryage = gtk_spin_button_new(GTK_ADJUSTMENT (spinbtn_queryage_adj), 1, 0);
        gtk_box_pack_start (GTK_BOX (hbox_spin), spinbtn_queryage, FALSE, FALSE, 0);
        gtk_widget_set_size_request (spinbtn_queryage, 64, -1);
@@ -636,8 +612,7 @@ static void addressbook_edit_ldap_page_search( gint pageNum, gchar *pageLbl ) {
        gtk_table_attach(GTK_TABLE(table), hbox_spin, 1, 2, top, (top + 1),
                GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
 
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, spinbtn_queryage, _( 
+       CLAWS_SET_TIP(spinbtn_queryage, _( 
                "This defines the maximum period of time (in seconds) that " \
                "an address search result is valid for address completion " \
                "purposes. Search results are stored in a cache until this " \
@@ -650,8 +625,7 @@ static void addressbook_edit_ldap_page_search( gint pageNum, gchar *pageLbl ) {
                "servers. A larger value will reduce the search time for " \
                "subsequent searches. This is useful for servers that have " \
                "slow response times at the expense of more memory to cache " \
-               "results." ),
-               NULL );
+               "results." ));
 
        /* Next row */
        ++top;
@@ -660,11 +634,9 @@ static void addressbook_edit_ldap_page_search( gint pageNum, gchar *pageLbl ) {
        gtk_table_attach(GTK_TABLE(table), check_dynsearch, 1, 3, top, (top + 1),
                GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
 
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, check_dynsearch, _( 
+       CLAWS_SET_TIP(check_dynsearch, _( 
                "Check this option to include this server for dynamic " \
-               "searches when using address completion." ),
-               NULL );
+               "searches when using address completion." ));
 
        /* Next row */
        ++top;
@@ -673,8 +645,7 @@ static void addressbook_edit_ldap_page_search( gint pageNum, gchar *pageLbl ) {
        gtk_table_attach(GTK_TABLE(table), check_matchoption, 1, 3, top, (top + 1),
                GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
 
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, check_matchoption, _( 
+       CLAWS_SET_TIP(check_matchoption, _( 
                "Searches for names and addresses can be performed either " \
                "using \"begins-with\" or \"contains\" search term. Check " \
                "this option to perform a \"contains\" search; this type of " \
@@ -682,8 +653,7 @@ static void addressbook_edit_ldap_page_search( gint pageNum, gchar *pageLbl ) {
                "performance reasons, address completion uses " \
                "\"begins-with\" for all searches against other address " \
                "interfaces." \
-               ),
-               NULL );
+               ));
 
        /* Signal handlers */
        g_signal_connect(G_OBJECT(reset_btn), "clicked",
@@ -705,11 +675,11 @@ static void addressbook_edit_ldap_page_extended( gint pageNum, gchar *pageLbl )
        GtkWidget *entry_bindDN;
        GtkWidget *entry_bindPW;
        GtkWidget *hbox_spin;
-       GtkObject *spinbtn_timeout_adj;
+       GtkAdjustment *spinbtn_timeout_adj;
        GtkWidget *spinbtn_timeout;
-       GtkObject *spinbtn_maxentry_adj;
+       GtkAdjustment *spinbtn_maxentry_adj;
        GtkWidget *spinbtn_maxentry;
-       GtkTooltips *toolTip;
+       CLAWS_TIP_DECL();
        gint top;
 
        vbox = gtk_vbox_new( FALSE, 8 );
@@ -738,13 +708,11 @@ static void addressbook_edit_ldap_page_extended( gint pageNum, gchar *pageLbl )
        gtk_table_attach(GTK_TABLE(table), entry_bindDN, 1, 2, top, (top + 1),
                GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
 
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, entry_bindDN, _( 
+       CLAWS_SET_TIP(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=claws-mail,dc=org\". " \
-               "This is usually left empty when performing a search." ),
-               NULL );
+               "This is usually left empty when performing a search." ));
 
        /* Next row */
        ++top;
@@ -761,11 +729,9 @@ static void addressbook_edit_ldap_page_extended( gint pageNum, gchar *pageLbl )
                HILDON_GTK_INPUT_MODE_FULL | HILDON_GTK_INPUT_MODE_INVISIBLE);
 #endif
 
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, entry_bindPW, _( 
+       CLAWS_SET_TIP(entry_bindPW, _( 
                "The password to be used when connecting as the \"Bind DN\" " \
-               "user." ),
-               NULL );
+               "user." ));
 
        /* Next row */
        ++top;
@@ -774,7 +740,7 @@ static void addressbook_edit_ldap_page_extended( gint pageNum, gchar *pageLbl )
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
        hbox_spin = gtk_hbox_new (FALSE, 8);
-       spinbtn_timeout_adj = gtk_adjustment_new (0, 0, 300, 1, 10, 10);
+       spinbtn_timeout_adj = gtk_adjustment_new (0, 0, 300, 1, 10, 0);
        spinbtn_timeout = gtk_spin_button_new(GTK_ADJUSTMENT (spinbtn_timeout_adj), 1, 0);
        gtk_box_pack_start (GTK_BOX (hbox_spin), spinbtn_timeout, FALSE, FALSE, 0);
        gtk_widget_set_size_request (spinbtn_timeout, 64, -1);
@@ -782,9 +748,8 @@ static void addressbook_edit_ldap_page_extended( gint pageNum, gchar *pageLbl )
        gtk_table_attach(GTK_TABLE(table), hbox_spin, 1, 2, top, (top + 1),
                GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
 
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, spinbtn_timeout, _( 
-               "The timeout period in seconds." ), NULL );
+       CLAWS_SET_TIP(spinbtn_timeout, _( 
+               "The timeout period in seconds." ));
 
        /* Next row */
        ++top;
@@ -793,7 +758,7 @@ static void addressbook_edit_ldap_page_extended( gint pageNum, gchar *pageLbl )
        gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
        hbox_spin = gtk_hbox_new (FALSE, 8);
-       spinbtn_maxentry_adj = gtk_adjustment_new (0, 0, 500, 1, 10, 10);
+       spinbtn_maxentry_adj = gtk_adjustment_new (0, 0, 500, 1, 10, 0);
        spinbtn_maxentry = gtk_spin_button_new(GTK_ADJUSTMENT (spinbtn_maxentry_adj), 1, 0);
        gtk_box_pack_start (GTK_BOX (hbox_spin), spinbtn_maxentry, FALSE, FALSE, 0);
        gtk_widget_set_size_request (spinbtn_maxentry, 64, -1);
@@ -801,11 +766,9 @@ static void addressbook_edit_ldap_page_extended( gint pageNum, gchar *pageLbl )
        gtk_table_attach(GTK_TABLE(table), hbox_spin, 1, 2, top, (top + 1),
                GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
 
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, spinbtn_maxentry, _( 
+       CLAWS_SET_TIP(spinbtn_maxentry, _( 
                "The maximum number of entries that should be returned " \
-               "in the search result." ),
-               NULL );
+               "in the search result." ));
 
        /* Done */
        gtk_widget_show_all(vbox);
@@ -929,6 +892,7 @@ static void edit_ldap_clear_fields(void) {
 static void edit_ldap_set_fields( LdapServer *server ) {
        LdapControl *ctl;
        gchar *crit;
+       gchar *pwd;
 
        if( ldapsvr_get_name( server ) )
                gtk_entry_set_text(GTK_ENTRY(ldapedit.entry_name),
@@ -944,9 +908,11 @@ static void edit_ldap_set_fields( LdapServer *server ) {
        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 );
+       if( ctl->bindPass ) {
+               pwd = ldapctl_get_bind_password( ctl );
+               gtk_entry_set_text(     GTK_ENTRY(ldapedit.entry_bindPW),  pwd );
+               g_free(pwd);
+       }
        gtk_spin_button_set_value(
                GTK_SPIN_BUTTON(ldapedit.spinbtn_timeout), ctl->timeOut );
        gtk_spin_button_set_value(
@@ -1003,6 +969,7 @@ AdapterDSource *addressbook_edit_ldap(
        gtk_widget_grab_focus(ldapedit.entry_name);
        gtk_widget_show(ldapedit.window);
        manage_window_set_transient(GTK_WINDOW(ldapedit.window));
+       gtk_window_set_modal(GTK_WINDOW(ldapedit.window), TRUE);
 
        edit_ldap_status_show( "" );
        if( ads ) {
@@ -1020,6 +987,7 @@ AdapterDSource *addressbook_edit_ldap(
 
        gtk_main();
        gtk_widget_hide(ldapedit.window);
+       gtk_window_set_modal(GTK_WINDOW(ldapedit.window), FALSE);
        if (cancelled == TRUE) return NULL;
 
        sName = gtk_editable_get_chars(
@@ -1075,19 +1043,19 @@ AdapterDSource *addressbook_edit_ldap(
                ldapctl_set_host( ctl, sHost );
                ldapctl_set_base_dn( ctl, sBase );
                ldapctl_set_bind_dn( ctl, sBind );
-               ldapctl_set_bind_password( ctl, sPass );
+               ldapctl_set_bind_password( ctl, sPass, TRUE, TRUE );
                ldapctl_set_port( ctl, iPort );
                ldapctl_set_max_entries( ctl, iMaxE );
                ldapctl_set_timeout( ctl, iTime );
                ldapctl_set_max_query_age( ctl, iAge );
-#ifdef USE_LDAP_TLS
                ldapctl_set_tls( ctl, tls );
                ldapctl_set_ssl( ctl, ssl );
-#endif
                ldapctl_set_matching_option(
                        ctl, bMatch ?
                        LDAPCTL_MATCH_CONTAINS : LDAPCTL_MATCH_BEGINWITH );
 
+               addrindex_save_data(addrIndex);
+
                /* Save attributes */
                editldap_parse_criteria( sCrit, ctl );