More Coverity fixes
[claws.git] / src / importldif.c
index c2ebbf5c43b758a429c9be7359f2793b4b8e5358..e8db5b64f12231e401a41c86ba05036b5e367657 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-2012 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
@@ -23,6 +23,7 @@
 
 #ifdef HAVE_CONFIG_H
 #  include "config.h"
+#include "claws-features.h"
 #endif
 
 #include "defs.h"
 #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 "addrbook.h"
 #include "addressbook.h"
@@ -105,8 +101,7 @@ static AddressBookFile *_importedBook_;
 static AddressIndex *_imp_addressIndex_;
 static LdifFile *_ldifFile_ = NULL;
 
-static GdkPixmap *markxpm;
-static GdkBitmap *markxpmmask;
+static GdkPixbuf *markxpm;
 
 /**
  * Structure of error message table.
@@ -203,7 +198,7 @@ static void imp_ldif_message( void ) {
  * Update list with data for current row.
  * \param clist List to update.
  */
-static void imp_ldif_update_row( GtkCList *clist ) {
+static void imp_ldif_update_row( GtkCMCList *clist ) {
        Ldif_FieldRec *rec;
        gchar *text[ FIELDS_N_COLS ];
        gint row;
@@ -211,31 +206,34 @@ static void imp_ldif_update_row( GtkCList *clist ) {
        if( impldif_dlg.rowIndSelect < 0 ) return;
        row = impldif_dlg.rowIndSelect;
 
-       rec = gtk_clist_get_row_data( clist, row );
+       rec = gtk_cmclist_get_row_data( clist, row );
+       if (!rec)
+               return;
+
        text[ FIELD_COL_RESERVED ] = "";
        text[ FIELD_COL_SELECT   ] = "";
        text[ FIELD_COL_FIELD    ] = rec->tagName;
        text[ FIELD_COL_ATTRIB   ] = rec->userName;
 
-       gtk_clist_freeze( clist );
-       gtk_clist_remove( clist, row );
+       gtk_cmclist_freeze( clist );
+       gtk_cmclist_remove( clist, row );
        if( row == impldif_dlg.rowCount - 1 ) {
-               gtk_clist_append( clist, text );
+               gtk_cmclist_append( clist, text );
        }
        else {
-               gtk_clist_insert( clist, row, text );
+               gtk_cmclist_insert( clist, row, text );
        }
        if( rec->selected ) {
-               gtk_clist_set_pixmap(
-                       clist, row, FIELD_COL_SELECT, markxpm, markxpmmask );
+               gtk_cmclist_set_pixbuf(
+                       clist, row, FIELD_COL_SELECT, markxpm );
        }
        if( rec->reserved ) {
-               gtk_clist_set_pixmap(
-                       clist, row, FIELD_COL_RESERVED, markxpm, markxpmmask );
+               gtk_cmclist_set_pixbuf(
+                       clist, row, FIELD_COL_RESERVED, markxpm );
        }
 
-       gtk_clist_set_row_data( clist, row, rec );
-       gtk_clist_thaw( clist );
+       gtk_cmclist_set_row_data( clist, row, rec );
+       gtk_cmclist_thaw( clist );
 }
 
 /**
@@ -243,14 +241,14 @@ static void imp_ldif_update_row( GtkCList *clist ) {
  * \param ldf LDIF control data.
  */
 static void imp_ldif_load_fields( LdifFile *ldf ) {
-       GtkCList *clist = GTK_CLIST(impldif_dlg.clist_field);
+       GtkCMCList *clist = GTK_CMCLIST(impldif_dlg.clist_field);
        GList *node, *list;
        gchar *text[ FIELDS_N_COLS ];
 
        impldif_dlg.rowIndSelect = -1;
        impldif_dlg.rowCount = 0;
        if( ! ldf->accessFlag ) return;
-       gtk_clist_clear( clist );
+       gtk_cmclist_clear( clist );
        list = ldif_get_fieldlist( ldf );
        node = list;
        while( node ) {
@@ -261,15 +259,15 @@ static void imp_ldif_load_fields( LdifFile *ldf ) {
                text[ FIELD_COL_SELECT   ] = "";
                text[ FIELD_COL_FIELD    ] = rec->tagName;
                text[ FIELD_COL_ATTRIB   ] = rec->userName;
-               row = gtk_clist_append( clist, text );
-               gtk_clist_set_row_data( clist, row, rec );
+               row = gtk_cmclist_append( clist, text );
+               gtk_cmclist_set_row_data( clist, row, rec );
                if( rec->selected ) {
-                       gtk_clist_set_pixmap( clist, row,
-                               FIELD_COL_SELECT, markxpm, markxpmmask );
+                       gtk_cmclist_set_pixbuf( clist, row,
+                               FIELD_COL_SELECT, markxpm );
                }
                if( rec->reserved ) {
-                       gtk_clist_set_pixmap( clist, row,
-                               FIELD_COL_RESERVED, markxpm, markxpmmask );
+                       gtk_cmclist_set_pixbuf( clist, row,
+                               FIELD_COL_RESERVED, markxpm );
                }
                impldif_dlg.rowCount++;
                node = g_list_next( node );
@@ -280,7 +278,7 @@ static void imp_ldif_load_fields( LdifFile *ldf ) {
 }
 
 /**
- * Callback function when list iterm selected.
+ * Callback function when list item is selected.
  * \param clist List widget.
  * \param row   Row.
  * \param col   Column.
@@ -288,10 +286,10 @@ static void imp_ldif_load_fields( LdifFile *ldf ) {
  * \param data  User data.
  */
 static void imp_ldif_field_list_selected(
-               GtkCList *clist, gint row, gint column, GdkEvent *event,
+               GtkCMCList *clist, gint row, gint column, GdkEvent *event,
                gpointer data )
 {
-       Ldif_FieldRec *rec = gtk_clist_get_row_data( clist, row );
+       Ldif_FieldRec *rec = gtk_cmclist_get_row_data( clist, row );
 
        impldif_dlg.rowIndSelect = row;
        gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryAttrib), "" );
@@ -324,7 +322,7 @@ static void imp_ldif_field_list_selected(
  * \param data  Data.
  */
 static gboolean imp_ldif_field_list_toggle(
-               GtkCList *clist, GdkEventButton *event, gpointer data )
+               GtkCMCList *clist, GdkEventButton *event, gpointer data )
 {
        Ldif_FieldRec *rec;
        gboolean toggle = FALSE;
@@ -338,7 +336,8 @@ static gboolean imp_ldif_field_list_toggle(
                        gint y = event->y;
                        gint row, col;
 
-                       gtk_clist_get_selection_info( clist, x, y, &row, &col );
+                       if (!gtk_cmclist_get_selection_info( clist, x, y, &row, &col ))
+                               return FALSE;
                        if( col != FIELD_COL_SELECT ) return FALSE;
                        if( row > impldif_dlg.rowCount ) return FALSE;
 
@@ -354,7 +353,7 @@ static gboolean imp_ldif_field_list_toggle(
        }
        /* Toggle field selection */
        if( toggle ) {
-               rec = gtk_clist_get_row_data(
+               rec = gtk_cmclist_get_row_data(
                        clist, impldif_dlg.rowIndSelect );
                if( rec ) {
                        ldif_field_toggle( rec );
@@ -370,20 +369,20 @@ static gboolean imp_ldif_field_list_toggle(
  * \param data   User data.
  */
 static void imp_ldif_modify_pressed( GtkWidget *widget, gpointer data ) {
-       GtkCList *clist = GTK_CLIST(impldif_dlg.clist_field);
+       GtkCMCList *clist = GTK_CMCLIST(impldif_dlg.clist_field);
        Ldif_FieldRec *rec;
        gint row;
 
        if( impldif_dlg.rowIndSelect < 0 ) return;
        row = impldif_dlg.rowIndSelect;
-       rec = gtk_clist_get_row_data( clist, impldif_dlg.rowIndSelect );
+       rec = gtk_cmclist_get_row_data( clist, impldif_dlg.rowIndSelect );
 
        ldif_field_set_name( rec, gtk_editable_get_chars(
                GTK_EDITABLE(impldif_dlg.entryAttrib), 0, -1 ) );
        ldif_field_set_selected( rec, gtk_toggle_button_get_active(
                GTK_TOGGLE_BUTTON( impldif_dlg.checkSelect) ) );
        imp_ldif_update_row( clist );
-       gtk_clist_select_row( clist, row, 0 );
+       gtk_cmclist_select_row( clist, row, 0 );
        gtk_label_set_text( GTK_LABEL(impldif_dlg.entryField), "" );
        gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryAttrib), "" );
        gtk_toggle_button_set_active(
@@ -581,7 +580,7 @@ static void imp_ldif_cancel( GtkWidget *widget, gpointer data ) {
  */
 static void imp_ldif_file_select_create( AddressFileSelection *afs ) {
        gchar *file = filesel_select_file_open(_("Select LDIF File"), NULL);
-       
+
        if (file == NULL)
                afs->cancelled = TRUE;
        else {
@@ -616,7 +615,7 @@ static gint imp_ldif_delete_event( GtkWidget *widget, GdkEventAny *event, gpoint
  * \param data   User data.
  */
 static gboolean imp_ldif_key_pressed( GtkWidget *widget, GdkEventKey *event, gpointer data ) {
-       if (event && event->keyval == GDK_Escape) {
+       if (event && event->keyval == GDK_KEY_Escape) {
                imp_ldif_cancel( widget, data );
        }
        return FALSE;
@@ -634,7 +633,6 @@ static void imp_ldif_page_file( gint pageNum, gchar *pageLbl ) {
        GtkWidget *entryFile;
        GtkWidget *entryName;
        GtkWidget *btnFile;
-       GtkTooltips *toolTip;
        gint top;
 
        vbox = gtk_vbox_new(FALSE, 8);
@@ -666,11 +664,9 @@ static void imp_ldif_page_file( gint pageNum, gchar *pageLbl ) {
        gtk_table_attach(GTK_TABLE(table), entryName, 1, 2, top, (top + 1),
                GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
 
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, entryName, _( 
+       CLAWS_SET_TIP(entryName, _( 
                "Specify the name for the address book that will " \
-               "be created from the LDIF file data." ),
-               NULL );
+               "be created from the LDIF file data." ));
 
        /* Second row */
        top = 1;
@@ -683,19 +679,15 @@ static void imp_ldif_page_file( gint pageNum, gchar *pageLbl ) {
        gtk_table_attach(GTK_TABLE(table), entryFile, 1, 2, top, (top + 1),
                GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
 
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, entryFile,
-               _( "The full file specification of the LDIF file to import." ),
-               NULL );
+       CLAWS_SET_TIP(entryFile,
+               _( "The full file specification of the LDIF file to import." ));
 
        btnFile = gtkut_get_browse_file_btn(_("B_rowse"));
        gtk_table_attach(GTK_TABLE(table), btnFile, 2, 3, top, (top + 1),
                GTK_FILL, 0, 3, 0);
 
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, btnFile,
-               _( "Select the LDIF file to import." ),
-               NULL );
+       CLAWS_SET_TIP(btnFile,
+               _( "Select the LDIF file to import." ));
 
        gtk_widget_show_all(vbox);
 
@@ -705,6 +697,7 @@ static void imp_ldif_page_file( gint pageNum, gchar *pageLbl ) {
 
        impldif_dlg.entryFile = entryFile;
        impldif_dlg.entryName = entryName;
+
 }
 
 /**
@@ -725,7 +718,6 @@ static void imp_ldif_page_fields( gint pageNum, gchar *pageLbl ) {
        GtkWidget *checkSelect;
        GtkWidget *btnModify;
        GtkWidget *eventBox;
-       GtkTooltips *toolTip;
        gint top;
 
        gchar *titles[ FIELDS_N_COLS ];
@@ -757,24 +749,24 @@ static void imp_ldif_page_fields( gint pageNum, gchar *pageLbl ) {
                                       GTK_POLICY_AUTOMATIC,
                                       GTK_POLICY_AUTOMATIC);
 
-       clist_field = gtk_clist_new_with_titles( FIELDS_N_COLS, titles );
+       clist_field = gtk_cmclist_new_with_titles( FIELDS_N_COLS, titles );
        gtk_container_add( GTK_CONTAINER(clist_swin), clist_field );
-       gtk_clist_set_selection_mode(
-               GTK_CLIST(clist_field), GTK_SELECTION_BROWSE );
-       gtk_clist_set_column_width( GTK_CLIST(clist_field),
+       gtk_cmclist_set_selection_mode(
+               GTK_CMCLIST(clist_field), GTK_SELECTION_BROWSE );
+       gtk_cmclist_set_column_width( GTK_CMCLIST(clist_field),
                FIELD_COL_RESERVED, FIELDS_COL_WIDTH_RESERVED );
-       gtk_clist_set_column_width( GTK_CLIST(clist_field),
+       gtk_cmclist_set_column_width( GTK_CMCLIST(clist_field),
                FIELD_COL_SELECT, FIELDS_COL_WIDTH_SELECT );
-       gtk_clist_set_column_width( GTK_CLIST(clist_field),
+       gtk_cmclist_set_column_width( GTK_CMCLIST(clist_field),
                FIELD_COL_FIELD, FIELDS_COL_WIDTH_FIELD );
-       gtk_clist_set_column_width( GTK_CLIST(clist_field),
+       gtk_cmclist_set_column_width( GTK_CMCLIST(clist_field),
                FIELD_COL_ATTRIB, FIELDS_COL_WIDTH_ATTRIB );
 
        /* Remove focus capability for column headers */
        for( i = 0; i < FIELDS_N_COLS; i++ ) {
-               GTK_WIDGET_UNSET_FLAGS(
-                       GTK_CLIST(clist_field)->column[i].button,
-                       GTK_CAN_FOCUS);
+               gtkut_widget_set_can_focus(
+                       GTK_CMCLIST(clist_field)->column[i].button,
+                       FALSE);
        }
 
        /* Lower area - Edit area */
@@ -802,33 +794,17 @@ static void imp_ldif_page_fields( gint pageNum, gchar *pageLbl ) {
        /* 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_misc_set_alignment(GTK_MISC(label), 0, 0.5);
-
-       entryAttrib = gtk_entry_new();
-       gtk_table_attach(GTK_TABLE(table), entryAttrib, 1, 3, top, (top + 1),
-               GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
-
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, entryAttrib,
-               _( "The LDIF field can be renamed to the User Attribute name." ),
-               NULL );
-
-       /* Next row */
-       ++top;
-
        /*
         * Use an event box to attach some help in the form of a tooltip.
         * Tried this for the clist but it looked bad.
         */
        eventBox = gtk_event_box_new();
        gtk_container_add( GTK_CONTAINER(eventBox), label );
+       gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
        gtk_table_attach(GTK_TABLE(table), eventBox, 0, 1, top, (top + 1),
                GTK_FILL, 0, 0, 0);
 
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, eventBox, _(
+       CLAWS_SET_TIP(eventBox, _(
                "Choose the LDIF field that will be renamed or selected " \
                "for import in the list above. Reserved fields (marked " \
                "with a tick in the \"R\" column), are automatically " \
@@ -837,27 +813,31 @@ static void imp_ldif_page_fields( gint pageNum, gchar *pageLbl ) {
                "with a tick. A single click anywhere in the row will " \
                "select that field for rename in the input area below " \
                "the list. A double click anywhere in the row will also " \
-               "select the field for import."
-               ), NULL );
+               "select the field for import."));
 
+       entryAttrib = gtk_entry_new();
+       gtk_table_attach(GTK_TABLE(table), entryAttrib, 1, 3, top, (top + 1),
+               GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
+
+       CLAWS_SET_TIP(entryAttrib,
+               _( "The LDIF field can be renamed to the User Attribute name." ));
+
+       /* Next row */
+       ++top;
 
        checkSelect = gtk_check_button_new_with_label( _( "Select for Import" ) );
        gtk_table_attach(GTK_TABLE(table), checkSelect, 1, 2, top, (top + 1),
                GTK_EXPAND|GTK_SHRINK|GTK_FILL, 0, 0, 0);
 
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, checkSelect,
-               _( "Select the LDIF field for import into the address book." ),
-               NULL );
+       CLAWS_SET_TIP(checkSelect,
+               _( "Select the LDIF field for import into the address book." ));
 
        btnModify = gtk_button_new_with_label( _(" Modify "));
        gtk_table_attach(GTK_TABLE(table), btnModify, 2, 3, top, (top + 1),
                GTK_FILL, 0, 3, 0);
 
-       toolTip = gtk_tooltips_new();
-       gtk_tooltips_set_tip( toolTip, btnModify,
-               _( "This button will update the list above with the data supplied." ),
-               NULL );
+       CLAWS_SET_TIP(btnModify,
+               _( "This button will update the list above with the data supplied." ));
 
        gtk_widget_show_all(vbox);
 
@@ -963,7 +943,6 @@ static void imp_ldif_dialog_create() {
        gtk_container_set_border_width( GTK_CONTAINER(window), 0 );
        gtk_window_set_title( GTK_WINDOW(window), _("Import LDIF file into Address Book") );
        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(imp_ldif_delete_event),
                         NULL );
@@ -1002,7 +981,7 @@ static void imp_ldif_dialog_create() {
        btnProceed = gtk_button_new_with_mnemonic(_("Proceed"));
        gtk_button_set_image(GTK_BUTTON(btnProceed),
                        gtk_image_new_from_stock(GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON));
-       GTK_WIDGET_SET_FLAGS(btnProceed, GTK_CAN_DEFAULT);
+       gtkut_widget_set_can_default(btnProceed, TRUE);
        gtk_box_pack_start(GTK_BOX(hbbox), btnProceed, TRUE, TRUE, 0);
        gtk_widget_hide(btnProceed);
 
@@ -1067,17 +1046,18 @@ AddressBookFile *addressbook_imp_ldif( AddressIndex *addrIndex ) {
        gtk_widget_show(impldif_dlg.window);
        manage_window_set_transient(GTK_WINDOW(impldif_dlg.window));
        gtk_widget_grab_default(impldif_dlg.btnNext);
+       gtk_window_set_modal(GTK_WINDOW(impldif_dlg.window), TRUE);
 
        gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryName), IMPORTLDIF_GUESS_NAME );
        gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryFile), "" );
        gtk_label_set_text( GTK_LABEL(impldif_dlg.entryField), "" );
        gtk_entry_set_text( GTK_ENTRY(impldif_dlg.entryAttrib), "" );
-       gtk_clist_clear( GTK_CLIST(impldif_dlg.clist_field) );
+       gtk_cmclist_clear( GTK_CMCLIST(impldif_dlg.clist_field) );
        gtk_notebook_set_current_page( GTK_NOTEBOOK(impldif_dlg.notebook), PAGE_FILE_INFO );
        gtk_widget_set_sensitive( impldif_dlg.btnPrev, FALSE );
        gtk_widget_set_sensitive( impldif_dlg.btnNext, TRUE );
-       stock_pixmap_gdk( impldif_dlg.window, STOCK_PIXMAP_MARK,
-                         &markxpm, &markxpmmask );
+       stock_pixbuf_gdk( impldif_dlg.window, STOCK_PIXMAP_MARK,
+                         &markxpm );
        imp_ldif_message();
        gtk_widget_grab_focus(impldif_dlg.entryFile);
 
@@ -1091,6 +1071,7 @@ AddressBookFile *addressbook_imp_ldif( AddressIndex *addrIndex ) {
        _ldifFile_ = ldif_create();
        gtk_main();
        gtk_widget_hide(impldif_dlg.window);
+       gtk_window_set_modal(GTK_WINDOW(impldif_dlg.window), FALSE);
        ldif_free( _ldifFile_ );
        _ldifFile_ = NULL;
        _imp_addressIndex_ = NULL;