Sync with hiro's cvs 10 to 17.
[claws.git] / src / account.c
index 8b078891ebd45bd887851eac11fce4118df16eeb..34ced31edb5ce16de16f21b10e160720c489d34b 100644 (file)
@@ -40,6 +40,7 @@
 #include "prefs_folder_item.h"
 #include "compose.h"
 #include "manage_window.h"
+#include "stock_pixmap.h"
 #include "inc.h"
 #include "gtkutils.h"
 #include "utils.h"
@@ -98,6 +99,9 @@ static void account_selected          (GtkCList       *clist,
                                         gint            column,
                                         GdkEvent       *event,
                                         gpointer        data);
+static void account_row_moved          (GtkCList       *clist,
+                                        gint            source_row,
+                                        gint            dest_row);
 static void account_key_pressed                (GtkWidget      *widget,
                                         GdkEventKey    *event,
                                         gpointer        data);
@@ -175,6 +179,9 @@ PrefsAccount *account_find_from_smtp_server(const gchar *address,
        GList *cur;
        PrefsAccount *ac;
 
+       g_return_val_if_fail(address != NULL, NULL);
+       g_return_val_if_fail(smtp_server != NULL, NULL);
+
        for (cur = account_list; cur != NULL; cur = cur->next) {
                ac = (PrefsAccount *)cur->data;
                if (!strcmp2(address, ac->address) &&
@@ -198,9 +205,12 @@ PrefsAccount *account_find_from_address(const gchar *address)
        GList *cur;
        PrefsAccount *ac;
 
+       g_return_val_if_fail(address != NULL, NULL);
+
        for (cur = account_list; cur != NULL; cur = cur->next) {
                ac = (PrefsAccount *)cur->data;
-               if (ac->protocol != A_NNTP && strcasestr(address, ac->address))
+               if (ac->protocol != A_NNTP && ac->address &&
+                   strcasestr(address, ac->address))
                        return ac;
        }
 
@@ -468,6 +478,8 @@ static void account_edit_create(void)
 
        gtk_signal_connect (GTK_OBJECT (clist), "select_row",
                            GTK_SIGNAL_FUNC (account_selected), NULL);
+       gtk_signal_connect (GTK_OBJECT (clist), "row_move",
+                           GTK_SIGNAL_FUNC (account_row_moved), NULL);
 
        vbox2 = gtk_vbox_new (FALSE, 0);
        gtk_widget_show (vbox2);
@@ -527,10 +539,11 @@ static void account_edit_create(void)
                            GTK_SIGNAL_FUNC (account_edit_close),
                            NULL);
 
-       PIXMAP_CREATE(clist, markxpm, markxpmmask, mark_xpm);
-       PIXMAP_CREATE(clist, checkboxonxpm, checkboxonxpmmask, checkbox_on_xpm);
-       PIXMAP_CREATE(clist, checkboxoffxpm, checkboxoffxpmmask,
-                     checkbox_off_xpm);
+       stock_pixmap_gdk(clist, STOCK_PIXMAP_MARK, &markxpm, &markxpmmask);
+       stock_pixmap_gdk(clist, STOCK_PIXMAP_CHECKBOX_ON,
+                        &checkboxonxpm, &checkboxonxpmmask);
+       stock_pixmap_gdk(clist, STOCK_PIXMAP_CHECKBOX_OFF,
+                        &checkboxoffxpm, &checkboxoffxpmmask);
 
        edit_account.window    = window;
        edit_account.clist     = clist;
@@ -567,24 +580,24 @@ static void account_edit_prefs(void)
        account_clist_set();
 }
 
-static void account_delete_references_recursive(const GNode *node, const gint account)
+static gboolean account_delete_references_func(GNode *node, gpointer data)
 {
-       /* the son */
-       if (node->data) {
-               FolderItem *item = node->data;
-               if (item->prefs) /* && item->prefs->stype == F_NORMAL */
-                       if (item->prefs->default_account == account) {
-                               item->prefs->enable_default_account = FALSE;
-                               item->prefs->default_account = 0;
-                               prefs_folder_item_save_config(item);
-                       }
-       }
-       /* its children (vertical dive) */
-       if (node->children)
-               account_delete_references_recursive(node->children, account);
-       /* its brothers (horizontal dive) */
-       if (node->next)
-               account_delete_references_recursive(node->next, account);
+       FolderItem *item;
+       gint account;
+
+       g_return_val_if_fail(node->data != NULL, FALSE);
+
+       item = FOLDER_ITEM(node->data);
+       account = GPOINTER_TO_INT(data);
+
+       if(!item->prefs) /* && item->prefs->stype == F_NORMAL */
+               return FALSE;
+       if(item->prefs->default_account != account)
+               return FALSE;
+       
+       item->prefs->enable_default_account = FALSE;
+       item->prefs->default_account = 0;
+       prefs_folder_item_save_config(item);
 }
 
 static void account_delete(void)
@@ -616,7 +629,10 @@ static void account_delete(void)
        for (; list != NULL; list = list->next) {
                folder = FOLDER(list->data);
                if (folder->node)  /* && folder->type == F_? */
-                       account_delete_references_recursive(folder->node, ac_prefs->account_id);
+                       g_node_traverse(folder->node, G_PRE_ORDER,
+                               G_TRAVERSE_ALL, -1,
+                               account_delete_references_func,
+                               GINT_TO_POINTER(ac_prefs->account_id));
        }
 }
 
@@ -628,10 +644,8 @@ static void account_up(void)
        if (!clist->selection) return;
 
        row = GPOINTER_TO_INT(clist->selection->data);
-       if (row > 0) {
+       if (row > 0)
                gtk_clist_row_move(clist, row, row - 1);
-               account_list_set();
-       }
 }
 
 static void account_down(void)
@@ -642,10 +656,8 @@ static void account_down(void)
        if (!clist->selection) return;
 
        row = GPOINTER_TO_INT(clist->selection->data);
-       if (row < clist->rows - 1) {
+       if (row < clist->rows - 1)
                gtk_clist_row_move(clist, row, row + 1);
-               account_list_set();
-       }
 }
 
 static void account_set_default(void)
@@ -709,6 +721,15 @@ static void account_selected(GtkCList *clist, gint row, gint column,
        }
 }
 
+static void account_row_moved(GtkCList *clist, gint source_row, gint dest_row)
+{
+       account_list_set();
+       if (gtk_clist_row_is_visible(clist, dest_row) != GTK_VISIBILITY_FULL) {
+               gtk_clist_moveto(clist, dest_row, -1,
+                                source_row < dest_row ? 1.0 : 0.0, 0.0);
+       }
+}
+
 static void account_key_pressed(GtkWidget *widget, GdkEventKey *event,
                                gpointer data)
 {
@@ -781,19 +802,15 @@ static void account_clist_set(void)
 {
        GtkCList *clist = GTK_CLIST(edit_account.clist);
        GList *cur;
-       gint prev_row;
+       gint row = -1, prev_row = -1;
 
        if (clist->selection)
                prev_row = GPOINTER_TO_INT(clist->selection->data);
-       else
-               prev_row = -1;
 
        gtk_clist_freeze(clist);
        gtk_clist_clear(clist);
 
        for (cur = account_list; cur != NULL; cur = cur->next) {
-               gint row;
-
                row = account_clist_set_row((PrefsAccount *)cur->data, -1);
                if ((PrefsAccount *)cur->data == cur_account) {
                        gtk_clist_select_row(clist, row, -1);
@@ -802,10 +819,15 @@ static void account_clist_set(void)
        }
 
        if (prev_row >= 0) {
-               gtk_clist_select_row(clist, prev_row, -1);
-               gtkut_clist_set_focus_row(clist, prev_row);
+               row = prev_row;
+               gtk_clist_select_row(clist, row, -1);
+               gtkut_clist_set_focus_row(clist, row);
        }
 
+       if (row >= 0 &&
+           gtk_clist_row_is_visible(clist, row) != GTK_VISIBILITY_FULL)
+               gtk_clist_moveto(clist, row, -1, 0.5, 0);
+
        gtk_clist_thaw(clist);
 }