fix bug 4239, 'Preferences: Text Options Header Display modal is not modal' (sic)
[claws.git] / src / editldap_basedn.c
index 914ee56620cffc4f5304d2f63c9180a78efa3c7c..44587cbbfb7c6bf580e2641736dae2fd9e67cb11 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2001-2009 Match Grun and the Claws Mail team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 2001-2015 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
@@ -14,7 +14,6 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
- * 
  */
 
 /*
@@ -23,6 +22,7 @@
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
+#include "claws-features.h"
 #endif
 
 #ifdef USE_LDAP
@@ -74,7 +74,7 @@ static gint edit_ldap_bdn_delete_event( GtkWidget *widget, GdkEventAny *event, g
 }
 
 static gboolean edit_ldap_bdn_key_pressed( GtkWidget *widget, GdkEventKey *event, gboolean *cancelled ) {
-       if (event && event->keyval == GDK_Escape) {
+       if (event && event->keyval == GDK_KEY_Escape) {
                ldapedit_basedn_cancelled = TRUE;
                gtk_main_quit();
        }
@@ -91,25 +91,38 @@ static void edit_ldap_bdn_cancel( GtkWidget *widget, gboolean *cancelled ) {
        gtk_main_quit();
 }
 
-static void edit_ldap_bdn_list_select( GtkCMCList *clist, gint row, gint column, GdkEvent *event, gpointer data ) {
-       gchar *text = NULL;
+static void set_selected()
+{
+       GtkWidget *entry = ldapedit_basedn.basedn_entry;
+       GtkWidget *view = ldapedit_basedn.basedn_list;
+       gchar *text;
 
-       if( gtk_cmclist_get_text( clist, row, 0, &text ) ) {
-               if( text ) {
-                       gtk_entry_set_text(GTK_ENTRY(ldapedit_basedn.basedn_entry), text );
-               }
-       }
+       if (entry == NULL || view == NULL)
+               return;
+
+       text = gtkut_tree_view_get_selected_pointer(
+                       GTK_TREE_VIEW(view), 0, NULL, NULL, NULL);
+
+       if (text == NULL)
+               return;
+
+       gtk_entry_set_text(GTK_ENTRY(entry), text);
+       g_free(text);
 }
 
-static gboolean edit_ldap_bdn_list_button( GtkCMCList *clist, GdkEventButton *event, gpointer data ) {
-       if( ! event ) return FALSE;
-       if( event->button == 1 ) {
-               if( event->type == GDK_2BUTTON_PRESS ) {
-                       ldapedit_basedn_cancelled = FALSE;
-                       gtk_main_quit();
-               }
-       }
-       return FALSE;
+static void basedn_list_cursor_changed(GtkTreeView *view,
+               gpointer user_data)
+{
+       set_selected();
+}
+
+static void basedn_list_row_activated(GtkTreeView *view,
+               GtkTreePath *path,
+               GtkTreeViewColumn *column,
+               gpointer user_data)
+{
+       set_selected();
+       edit_ldap_bdn_ok(NULL, NULL);
 }
 
 static void edit_ldap_bdn_create(void) {
@@ -130,12 +143,16 @@ static void edit_ldap_bdn_create(void) {
        GtkWidget *hsbox;
        GtkWidget *statusbar;
        gint top;
+       GtkListStore *store;
+       GtkTreeSelection *sel;
+       GtkTreeViewColumn *col;
+       GtkCellRenderer *rdr;
 
        window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "editldap_basedn");
-       gtk_widget_set_size_request(window, 300, 270);
        gtk_container_set_border_width(GTK_CONTAINER(window), 0);
        gtk_window_set_title(GTK_WINDOW(window), _("Edit LDAP - Select Search Base"));
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
+       gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG);
        g_signal_connect(G_OBJECT(window), "delete_event",
                         G_CALLBACK(edit_ldap_bdn_delete_event), NULL );
        g_signal_connect(G_OBJECT(window), "key_press_event",
@@ -191,11 +208,27 @@ static void edit_ldap_bdn_create(void) {
                                       GTK_POLICY_AUTOMATIC);
        gtk_box_pack_start(GTK_BOX(vlbox), lwindow, TRUE, TRUE, 0);
 
-       basedn_list = gtk_cmclist_new(1);
+       store = gtk_list_store_new(1, G_TYPE_STRING, -1);
+
+       basedn_list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
+       g_object_unref(store);
+       gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(basedn_list), TRUE);
+       sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(basedn_list));
+       gtk_tree_selection_set_mode(sel, GTK_SELECTION_BROWSE);
+
+       rdr = gtk_cell_renderer_text_new();
+       col = gtk_tree_view_column_new_with_attributes(
+                       _("Available Search Base(s)"), rdr,
+                       "markup", 0, NULL);
+       gtk_tree_view_append_column(GTK_TREE_VIEW(basedn_list), col);
+
        gtk_container_add(GTK_CONTAINER(lwindow), basedn_list);
-       gtk_cmclist_column_titles_show( GTK_CMCLIST(basedn_list) );
-       gtk_cmclist_set_column_title( GTK_CMCLIST(basedn_list), 0, _( "Available Search Base(s)" ) );
-       gtk_cmclist_set_selection_mode(GTK_CMCLIST(basedn_list), GTK_SELECTION_BROWSE);
+
+       g_signal_connect(G_OBJECT(basedn_list), "cursor-changed",
+                       G_CALLBACK(basedn_list_cursor_changed), NULL);
+       g_signal_connect(G_OBJECT(basedn_list), "row-activated",
+                       G_CALLBACK(basedn_list_row_activated), NULL);
+
 
        /* Status line */
        hsbox = gtk_hbox_new(FALSE, 0);
@@ -218,10 +251,6 @@ static void edit_ldap_bdn_create(void) {
                         G_CALLBACK(edit_ldap_bdn_ok), NULL);
        g_signal_connect(G_OBJECT(cancel_btn), "clicked",
                         G_CALLBACK(edit_ldap_bdn_cancel), NULL);
-       g_signal_connect(G_OBJECT(basedn_list), "select_row",
-                        G_CALLBACK(edit_ldap_bdn_list_select), NULL);
-       g_signal_connect(G_OBJECT(basedn_list), "button_press_event",
-                        G_CALLBACK(edit_ldap_bdn_list_button), NULL);
 
        gtk_widget_show_all(vbox);
 
@@ -248,9 +277,15 @@ static void edit_ldap_bdn_load_data(
        gboolean flgConn;
        gboolean flgDN;
        GList *baseDN = NULL;
+       GtkWidget *view = ldapedit_basedn.basedn_list;
+       GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(view));
+       GtkTreeIter iter;
+       GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
 
        edit_ldap_bdn_status_show( "" );
-       gtk_cmclist_clear(GTK_CMCLIST(ldapedit_basedn.basedn_list));
+
+       gtk_list_store_clear(GTK_LIST_STORE(model));
+
        ldapedit_basedn_bad_server = TRUE;
        flgConn = flgDN = FALSE;
        sHost = g_strdup( hostName );
@@ -264,15 +299,20 @@ static void edit_ldap_bdn_load_data(
                        baseDN = ldaputil_read_basedn( sHost, iPort, bindDN, bindPW, tov, ssl, tls );
                        if( baseDN ) {
                                GList *node = baseDN;
-                               gchar *text[2] = { NULL, NULL };
 
                                while( node ) {
-                                       text[0] = (gchar *)node->data;
-                                       gtk_cmclist_append(GTK_CMCLIST(ldapedit_basedn.basedn_list), text);
+                                       gtk_list_store_append(GTK_LIST_STORE(model), &iter);
+                                       gtk_list_store_set(GTK_LIST_STORE(model), &iter,
+                                                       0, (gchar *)node->data, -1);
                                        node = g_list_next( node );
                                        flgDN = TRUE;
                                }
-                               mgu_free_dlist( baseDN );
+
+                               /* Select the first line */
+                               if (gtk_tree_model_get_iter_first(model, &iter))
+                                       gtk_tree_selection_select_iter(sel, &iter);
+
+                               g_list_free_full( baseDN, g_free );
                                baseDN = node = NULL;
                        }
                        ldapedit_basedn_bad_server = FALSE;
@@ -316,7 +356,7 @@ gchar *edit_ldap_basedn_selection( const gchar *hostName, const gint port, gchar
        if( ldapedit_basedn_bad_server ) return NULL;
 
        retVal = gtk_editable_get_chars( GTK_EDITABLE(ldapedit_basedn.basedn_entry), 0, -1 );
-       g_strchomp( retVal ); g_strchug( retVal );
+       g_strstrip( retVal );
        if( *retVal == '\0' ) {
                g_free( retVal );
                retVal = NULL;