2007-06-12 [colin] 2.9.2cvs57
[claws.git] / src / prefs_summary_open.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <glib.h>
27 #include <glib/gi18n.h>
28 #include <gtk/gtk.h>
29 #include <gdk/gdkkeysyms.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <errno.h>
34
35 #include "prefs_gtk.h"
36 #include "prefs_summary_open.h"
37 #include "prefs_common.h"
38 #include "manage_window.h"
39 #include "alertpanel.h"
40 #include "displayheader.h"
41 #include "utils.h"
42 #include "gtkutils.h"
43
44 enum {
45         PREFS_SUMMARY_OPEN_HEADER,
46         PREFS_SUMMARY_OPEN_DATA,
47         N_PREFS_SUMMARY_OPEN_COLUMNS
48 };
49
50 static struct SummaryOpen {
51         GtkWidget *window;
52
53         GtkWidget *ok_btn;
54         GtkWidget *cancel_btn;
55
56         GtkWidget *possible_actions_list_view;
57         GtkWidget *actions_list_view;
58 } summaryopen;
59
60 /* widget creating functions */
61 static void prefs_summary_open_create   (void);
62
63 static void prefs_summary_open_set_dialog       (void);
64 static void prefs_summary_open_set_list (void);
65
66 /* callback functions */
67 static void prefs_summary_open_register_cb      (GtkButton      *btn,
68                                                  gpointer        hidden_data);
69 static void prefs_summary_open_delete_cb        (GtkButton      *btn,
70                                                  gpointer        list_view_data);
71 static void prefs_summary_open_up               (void);
72 static void prefs_summary_open_down             (void);
73
74 static gboolean prefs_summary_open_key_pressed  (GtkWidget      *widget,
75                                                          GdkEventKey    *event,
76                                                          gpointer        data);
77 static void prefs_summary_open_ok               (void);
78 static void prefs_summary_open_cancel           (void);
79 static gint prefs_summary_open_deleted  (GtkWidget      *widget,
80                                                  GdkEventAny    *event,
81                                                  gpointer        data);
82
83
84 static GtkListStore *prefs_summary_open_create_store    (void);
85 static void prefs_summary_open_insert_action            (GtkListStore *store,
86                                                          gchar *name,
87                                                          gint act);
88 static GtkWidget *prefs_summary_open_list_view_create   (const gchar *name);
89 static void prefs_summary_open_create_list_view_columns (GtkWidget *list_view, 
90                                                          const gchar *name);
91 static void actions_list_model_row_changed              (GtkTreeModel *model, 
92                                                          GtkTreePath *path, 
93                                                          GtkTreeIter *iter, 
94                                                          GtkTreeView *list_view);
95                                                          
96 static void drag_begin  (GtkTreeView *list_view,
97                          GdkDragContext *context,
98                          gpointer data);
99
100 static void drag_end    (GtkTreeView *list_view,
101                          GdkDragContext *context,
102                          gpointer data);
103
104 static EntryAction saved_summary_select_prio[6];
105
106 static gchar *action_name[7] = 
107 {         ("UNSET (!)"),
108          N_("Go to first marked email"),
109          N_("Go to first new email"),
110          N_("Go to first unread email"),
111          N_("Go to last opened email"),
112          N_("Go to last email in the list"),
113          N_("Do nothing")
114 };
115
116 const gchar *prefs_summary_open_get_label(int act)
117 {
118         return gettext(action_name[act]);
119 }
120
121 void prefs_summary_open_open(void)
122 {
123         int i = 0;
124         if (!summaryopen.window) {
125                 prefs_summary_open_create();
126         }
127
128         manage_window_set_transient(GTK_WINDOW(summaryopen.window));
129         gtk_widget_grab_focus(summaryopen.ok_btn);
130
131         prefs_summary_open_set_dialog();
132         
133         for (i = 0; i < 6; i++)
134                 saved_summary_select_prio[i] = prefs_common.summary_select_prio[i];
135
136         gtk_widget_show(summaryopen.window);
137 }
138
139 static void prefs_summary_open_create(void)
140 {
141         GtkWidget *window;
142         GtkWidget *vbox;
143         GtkWidget *btn_hbox;
144         GtkWidget *ok_btn;
145         GtkWidget *cancel_btn;
146         GtkWidget *confirm_area;
147
148         GtkWidget *vbox1;
149
150         GtkWidget *hbox1;
151
152         GtkWidget *btn_vbox;
153         GtkWidget *reg_btn;
154         GtkWidget *del_btn;
155         GtkWidget *up_btn;
156         GtkWidget *down_btn;
157
158         GtkWidget *list_view_hbox;
159         GtkWidget *list_view_hbox1;
160         GtkWidget *list_view_hbox2;
161         GtkWidget *list_view_scrolledwin;
162         GtkWidget *possible_actions_list_view;
163         GtkWidget *actions_list_view;
164         
165         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_summary_open");
166         gtk_container_set_border_width (GTK_CONTAINER (window), 8);
167         gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
168         gtk_window_set_modal (GTK_WINDOW (window), TRUE);
169         gtk_window_set_resizable(GTK_WINDOW (window), TRUE);
170
171         vbox = gtk_vbox_new (FALSE, 6);
172         gtk_widget_show (vbox);
173         gtk_container_add (GTK_CONTAINER (window), vbox);
174
175         btn_hbox = gtk_hbox_new (FALSE, 8);
176         gtk_widget_show (btn_hbox);
177         gtk_box_pack_end (GTK_BOX (vbox), btn_hbox, FALSE, FALSE, 0);
178
179         gtkut_stock_button_set_create(&confirm_area, &cancel_btn, GTK_STOCK_CANCEL,
180                                       &ok_btn, GTK_STOCK_OK,
181                                       NULL, NULL);
182         gtk_widget_show (confirm_area);
183         gtk_box_pack_end (GTK_BOX(btn_hbox), confirm_area, FALSE, FALSE, 0);
184         gtk_widget_grab_default (ok_btn);
185
186         gtk_window_set_title (GTK_WINDOW(window),
187                               _("Action on folder opening"));
188         MANAGE_WINDOW_SIGNALS_CONNECT(window);
189         g_signal_connect (G_OBJECT(window), "delete_event",
190                           G_CALLBACK(prefs_summary_open_deleted),
191                           NULL);
192         g_signal_connect (G_OBJECT(window), "key_press_event",
193                           G_CALLBACK(prefs_summary_open_key_pressed),
194                           NULL);
195         g_signal_connect (G_OBJECT(ok_btn), "clicked",
196                           G_CALLBACK(prefs_summary_open_ok),
197                           NULL);
198         g_signal_connect (G_OBJECT(cancel_btn), "clicked",
199                           G_CALLBACK(prefs_summary_open_cancel),
200                           NULL);
201
202         vbox1 = gtk_vbox_new (FALSE, VSPACING);
203         gtk_widget_show (vbox1);
204         gtk_box_pack_start (GTK_BOX (vbox), vbox1, TRUE, TRUE, 0);
205         gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
206
207         hbox1 = gtk_hbox_new (FALSE, 8);
208         gtk_widget_show (hbox1);
209         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, TRUE, 0);
210
211         /* display headers list */
212
213         list_view_hbox = gtk_hbox_new (FALSE, 10);
214         gtk_widget_show (list_view_hbox);
215         gtk_box_pack_start (GTK_BOX (vbox1), list_view_hbox, TRUE, TRUE, 0);
216
217         list_view_hbox1 = gtk_hbox_new (FALSE, 8);
218         gtk_widget_show (list_view_hbox1);
219         gtk_box_pack_start (GTK_BOX (list_view_hbox), list_view_hbox1, TRUE, TRUE, 0);
220
221         list_view_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
222         gtk_widget_set_size_request (list_view_scrolledwin, 200, 210);
223         gtk_widget_show (list_view_scrolledwin);
224         gtk_box_pack_start (GTK_BOX (list_view_hbox1), list_view_scrolledwin,
225                             TRUE, TRUE, 0);
226         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (list_view_scrolledwin),
227                                         GTK_POLICY_AUTOMATIC,
228                                         GTK_POLICY_AUTOMATIC);
229         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(list_view_scrolledwin),
230                                             GTK_SHADOW_IN);
231
232         possible_actions_list_view = prefs_summary_open_list_view_create
233                                 (_("Possible actions"));
234         gtk_widget_show (possible_actions_list_view);
235         gtk_container_add(GTK_CONTAINER(list_view_scrolledwin), possible_actions_list_view);
236
237         btn_vbox = gtk_vbox_new (FALSE, 8);
238         gtk_widget_show (btn_vbox);
239         gtk_box_pack_start (GTK_BOX (list_view_hbox1), btn_vbox, FALSE, FALSE, 0);
240
241         reg_btn = gtk_button_new_from_stock (GTK_STOCK_ADD);
242         gtk_widget_show (reg_btn);
243         gtk_box_pack_start (GTK_BOX (btn_vbox), reg_btn, FALSE, TRUE, 0);
244         g_signal_connect (G_OBJECT (reg_btn), "clicked",
245                           G_CALLBACK (prefs_summary_open_register_cb),
246                           possible_actions_list_view);
247         del_btn = gtk_button_new_from_stock (GTK_STOCK_REMOVE);
248         gtk_widget_show (del_btn);
249         gtk_box_pack_start (GTK_BOX (btn_vbox), del_btn, FALSE, TRUE, 0);
250
251         /* actions list */
252
253         list_view_hbox2 = gtk_hbox_new (FALSE, 8);
254         gtk_widget_show (list_view_hbox2);
255         gtk_box_pack_start (GTK_BOX (list_view_hbox), list_view_hbox2, TRUE, TRUE, 0);
256
257         list_view_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
258         gtk_widget_set_size_request (list_view_scrolledwin, 200, 210);
259         gtk_widget_show (list_view_scrolledwin);
260         gtk_box_pack_start (GTK_BOX (list_view_hbox2), list_view_scrolledwin,
261                             TRUE, TRUE, 0);
262         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (list_view_scrolledwin),
263                                         GTK_POLICY_AUTOMATIC,
264                                         GTK_POLICY_AUTOMATIC);
265         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(list_view_scrolledwin),
266                                             GTK_SHADOW_IN);
267
268         actions_list_view = prefs_summary_open_list_view_create
269                                         (_("Action on folder opening"));
270         g_signal_connect (G_OBJECT (del_btn), "clicked",
271                           G_CALLBACK (prefs_summary_open_delete_cb),
272                           actions_list_view);
273         gtk_widget_show (actions_list_view);
274         gtk_container_add (GTK_CONTAINER (list_view_scrolledwin),
275                            actions_list_view);
276
277         gtk_tree_view_set_reorderable(GTK_TREE_VIEW(actions_list_view), TRUE);
278         g_signal_connect(G_OBJECT(actions_list_view), "drag_begin",                      
279                          G_CALLBACK(drag_begin),
280                          actions_list_view);
281                          
282         g_signal_connect(G_OBJECT(actions_list_view), "drag_end",                        
283                          G_CALLBACK(drag_end),
284                          actions_list_view);
285         
286         btn_vbox = gtk_vbox_new (FALSE, 8);
287         gtk_widget_show (btn_vbox);
288         gtk_box_pack_start (GTK_BOX (list_view_hbox2), btn_vbox, FALSE, FALSE, 0);
289
290         up_btn = gtk_button_new_from_stock (GTK_STOCK_GO_UP);
291         gtk_widget_show (up_btn);
292         gtk_box_pack_start (GTK_BOX (btn_vbox), up_btn, FALSE, FALSE, 0);
293         g_signal_connect (G_OBJECT (up_btn), "clicked",
294                           G_CALLBACK (prefs_summary_open_up), NULL);
295
296         down_btn = gtk_button_new_from_stock (GTK_STOCK_GO_DOWN);
297         gtk_widget_show (down_btn);
298         gtk_box_pack_start (GTK_BOX (btn_vbox), down_btn, FALSE, FALSE, 0);
299         g_signal_connect (G_OBJECT (down_btn), "clicked",
300                           G_CALLBACK (prefs_summary_open_down), NULL);
301         
302
303         gtk_widget_show_all(window);
304
305         summaryopen.window        = window;
306         summaryopen.ok_btn        = ok_btn;
307         summaryopen.cancel_btn    = cancel_btn;
308
309         summaryopen.possible_actions_list_view        = possible_actions_list_view;
310         summaryopen.actions_list_view = actions_list_view;
311 }
312
313 #define SET_PRIO(p_one,p_two,p_three,p_four) {                          \
314         prefs_common.summary_select_prio[0] = p_one;                    \
315         prefs_common.summary_select_prio[1] = p_two;                    \
316         prefs_common.summary_select_prio[2] = p_three;                  \
317         prefs_common.summary_select_prio[3] = p_four;                   \
318         prefs_common.summary_select_prio[4] = ACTION_UNSET;             \
319         prefs_common.summary_select_prio[5] = ACTION_UNSET;             \
320 }                                                       
321
322 void prefs_summary_open_set_defaults(void)
323 {
324         switch (prefs_common.select_on_entry) {
325                 case SELECTONENTRY_MNU:
326                         SET_PRIO(ACTION_MARKED, ACTION_NEW, ACTION_UNREAD, ACTION_LAST_LIST); break;
327                 case SELECTONENTRY_MUN:
328                         SET_PRIO(ACTION_MARKED, ACTION_UNREAD, ACTION_NEW, ACTION_LAST_LIST); break;
329                 case SELECTONENTRY_NMU:
330                         SET_PRIO(ACTION_NEW, ACTION_MARKED, ACTION_UNREAD, ACTION_LAST_LIST); break;
331                 case SELECTONENTRY_NUM:
332                         SET_PRIO(ACTION_NEW, ACTION_UNREAD, ACTION_MARKED, ACTION_LAST_LIST); break;
333                 case SELECTONENTRY_UNM:
334                         SET_PRIO(ACTION_UNREAD, ACTION_NEW, ACTION_MARKED, ACTION_LAST_LIST); break;
335                 case SELECTONENTRY_UMN:
336                         SET_PRIO(ACTION_UNREAD, ACTION_MARKED, ACTION_NEW, ACTION_LAST_LIST); break;
337                 case SELECTONENTRY_LAST:
338                         SET_PRIO(ACTION_LAST_OPENED, ACTION_LAST_LIST, ACTION_UNSET, ACTION_UNSET); break;
339                 case SELECTONENTRY_NOTHING:
340                         SET_PRIO(ACTION_LAST_LIST, ACTION_UNSET, ACTION_UNSET, ACTION_UNSET); break;
341                 default:
342                         break;
343         }
344 }
345 static void prefs_summary_open_set_dialog(void)
346 {
347         GtkTreeView *possible_list_view = GTK_TREE_VIEW(summaryopen.possible_actions_list_view);
348         GtkTreeView *actions_list_view = GTK_TREE_VIEW(summaryopen.actions_list_view);
349         GtkTreeModel *model_poss, *model_act;
350         int i = 0;
351         gboolean set = FALSE;
352         gboolean used[7] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE};
353
354         model_poss = gtk_tree_view_get_model(possible_list_view);
355         model_act = gtk_tree_view_get_model(actions_list_view);
356
357         gtk_list_store_clear(GTK_LIST_STORE(model_poss));
358         gtk_list_store_clear(GTK_LIST_STORE(model_act));
359
360 fill:
361         for (i = 0; i < 6; i++) {
362                 EntryAction act = prefs_common.summary_select_prio[i];
363
364                 if (act == ACTION_UNSET) 
365                         continue;
366                 
367                 set = TRUE;
368                 used[act] = TRUE;
369                 prefs_summary_open_insert_action(GTK_LIST_STORE
370                                         (model_act), action_name[act], act);    
371         }
372         if (!set) {
373                 /* backward compat */
374                 prefs_summary_open_set_defaults();
375                 goto fill;
376         }
377
378         for (i = ACTION_MARKED; i <= ACTION_NOTHING; i++) {
379                 if (!used[i]) {
380                         prefs_summary_open_insert_action(GTK_LIST_STORE
381                                         (model_poss), action_name[i], i);       
382                 }
383         }
384 }
385
386 static void prefs_summary_open_set_list(void)
387 {
388         gint row = 0;
389         gpointer data;
390         GtkTreeModel *model;
391         GtkTreeIter iter;
392
393
394         model = gtk_tree_view_get_model(GTK_TREE_VIEW(summaryopen.actions_list_view));
395         while (gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
396                 gtk_tree_model_get(model, &iter, PREFS_SUMMARY_OPEN_DATA, &data, -1);
397                 prefs_common.summary_select_prio[row] = GPOINTER_TO_INT(data);
398                 row++;                          
399         }
400         for (; row < 6; row++) {
401                 prefs_common.summary_select_prio[row] = ACTION_UNSET;
402         }
403 }
404
405 static void prefs_summary_open_delete_cb(GtkButton *btn, gpointer list_view_data)
406 {
407         GtkTreeView *list_view = GTK_TREE_VIEW(list_view_data);
408         gpointer data;
409         GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(list_view));
410         GtkTreeSelection *selection = gtk_tree_view_get_selection(list_view);
411         GtkTreeIter iter;
412         GtkTreeView *possible_list_view = GTK_TREE_VIEW(summaryopen.possible_actions_list_view);
413         GtkTreeModel *model, *model_poss;
414         gint i;
415
416         model = gtk_tree_view_get_model(list_view);
417         model_poss = gtk_tree_view_get_model(possible_list_view);
418
419         if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
420                 return;
421
422         gtk_tree_model_get(model, &iter, PREFS_SUMMARY_OPEN_DATA, &data, -1);
423         if (!data) 
424                 return;
425
426         gtk_list_store_remove(store, &iter);
427
428         i = GPOINTER_TO_INT(data);
429         prefs_summary_open_insert_action(GTK_LIST_STORE
430                                         (model_poss), action_name[i], i);       
431         
432         prefs_summary_open_set_list();
433 }
434
435 static void prefs_summary_open_register_cb(GtkButton *btn, gpointer list_view_data)
436 {
437         GtkTreeView *possible_list_view = GTK_TREE_VIEW(list_view_data);
438         GtkTreeView *list_view = GTK_TREE_VIEW(summaryopen.actions_list_view);
439         gpointer data;
440         GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(possible_list_view));
441         GtkTreeSelection *selection = gtk_tree_view_get_selection(possible_list_view);
442         GtkTreeIter iter;
443         GtkTreeModel *model, *model_poss;
444         gint i;
445
446         model = gtk_tree_view_get_model(list_view);
447         model_poss = gtk_tree_view_get_model(possible_list_view);
448
449         if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
450                 return;
451
452         gtk_tree_model_get(model_poss, &iter, PREFS_SUMMARY_OPEN_DATA, &data, -1);
453         if (!data) 
454                 return;
455
456         gtk_list_store_remove(store, &iter);
457
458         i = GPOINTER_TO_INT(data);
459         prefs_summary_open_insert_action(GTK_LIST_STORE
460                                         (model), action_name[i], i);    
461         
462         prefs_summary_open_set_list();
463 }
464
465 static void prefs_summary_open_up(void)
466 {
467         GtkTreePath *prev, *sel, *try;
468         GtkTreeIter isel;
469         GtkListStore *store = NULL;
470         GtkTreeModel *model = NULL;
471         GtkTreeIter iprev;
472         
473         if (!gtk_tree_selection_get_selected
474                 (gtk_tree_view_get_selection
475                         (GTK_TREE_VIEW(summaryopen.actions_list_view)),
476                  &model,        
477                  &isel))
478                 return;
479         store = (GtkListStore *)model;
480         sel = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &isel);
481         if (!sel)
482                 return;
483         
484         /* no move if we're at row 0... */
485         try = gtk_tree_path_copy(sel);
486         if (!gtk_tree_path_prev(try)) {
487                 gtk_tree_path_free(try);
488                 gtk_tree_path_free(sel);
489                 return;
490         }
491
492         prev = try;
493         gtk_tree_model_get_iter(GTK_TREE_MODEL(store),
494                                 &iprev, prev);
495         gtk_list_store_swap(store, &iprev, &isel);
496
497         gtk_tree_path_free(sel);
498         gtk_tree_path_free(prev);
499         prefs_summary_open_set_list();
500 }
501
502 static void prefs_summary_open_down(void)
503 {
504         GtkListStore *store = NULL;
505         GtkTreeModel *model = NULL;
506         GtkTreeIter next, sel;
507         GtkTreePath *try;
508         
509         if (!gtk_tree_selection_get_selected
510                 (gtk_tree_view_get_selection
511                         (GTK_TREE_VIEW(summaryopen.actions_list_view)),
512                  &model,
513                  &sel))
514                 return;
515         store = (GtkListStore *)model;
516         try = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &sel);
517         if (!try) 
518                 return;
519         
520         next = sel;
521         if (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &next))
522                 gtk_list_store_swap(store, &next, &sel);
523                 
524         gtk_tree_path_free(try);
525         prefs_summary_open_set_list();
526 }
527
528 static gboolean prefs_summary_open_key_pressed(GtkWidget *widget,
529                                              GdkEventKey *event,
530                                              gpointer data)
531 {
532         if (event && event->keyval == GDK_Escape)
533                 prefs_summary_open_cancel();
534         return FALSE;
535 }
536
537 static void prefs_summary_open_ok(void)
538 {
539         int i = 0;
540         for (i = 0; i < 6; i++)
541                 saved_summary_select_prio[i] = prefs_common.summary_select_prio[i];
542
543         gtk_widget_hide(summaryopen.window);
544 }
545
546 static void prefs_summary_open_cancel(void)
547 {
548         int i = 0;
549         for (i = 0; i < 6; i++)
550                 prefs_common.summary_select_prio[i] = saved_summary_select_prio[i];
551
552         gtk_widget_hide(summaryopen.window);
553 }
554
555 static gint prefs_summary_open_deleted(GtkWidget *widget, GdkEventAny *event,
556                                          gpointer data)
557 {
558         prefs_summary_open_cancel();
559         return TRUE;
560 }
561
562 static GtkListStore *prefs_summary_open_create_store(void)
563 {
564         return gtk_list_store_new(N_PREFS_SUMMARY_OPEN_COLUMNS,
565                                   G_TYPE_STRING,
566                                   G_TYPE_POINTER,
567                                   -1);
568 }
569
570 static void prefs_summary_open_insert_action(GtkListStore *store,
571                                                gchar *name,
572                                                gint dp)
573 {
574         GtkTreeIter iter;
575
576         /* add new */
577         gtk_list_store_append(store, &iter);
578         gtk_list_store_set(store, &iter,
579                            PREFS_SUMMARY_OPEN_HEADER,
580                            gettext(name),
581                            PREFS_SUMMARY_OPEN_DATA, GINT_TO_POINTER(dp),
582                            -1);
583 }
584
585 static GtkWidget *prefs_summary_open_list_view_create(const gchar *name)
586 {
587         GtkWidget *list_view;
588         GtkTreeSelection *selector;
589         GtkTreeModel *model;
590
591         model = GTK_TREE_MODEL(prefs_summary_open_create_store());
592         list_view = gtk_tree_view_new_with_model(model);
593         g_object_unref(G_OBJECT(model));
594         
595         gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(list_view),
596                                      prefs_common.use_stripes_everywhere);
597         
598         selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
599         gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
600
601         prefs_summary_open_create_list_view_columns(GTK_WIDGET(list_view), name);
602
603         return list_view;
604 }
605
606 static void prefs_summary_open_create_list_view_columns(GtkWidget *list_view, 
607                                                      const gchar *name)
608 {
609         GtkTreeViewColumn *column;
610         GtkCellRenderer *renderer;
611
612         renderer = gtk_cell_renderer_text_new();
613         column = gtk_tree_view_column_new_with_attributes
614                 (name, renderer, "text", PREFS_SUMMARY_OPEN_HEADER, NULL);
615         gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);          
616 }
617
618 /*!
619  *\brief        Called as a result of a drag & drop
620  */
621 static void actions_list_model_row_changed(GtkTreeModel *model, 
622                                            GtkTreePath *path, 
623                                            GtkTreeIter *iter, 
624                                            GtkTreeView *list_view)
625 {
626 }
627
628 /*!
629  *\brief        Called as a result of a gtk_list_store_swap()
630  */
631 static void drag_begin(GtkTreeView *list_view,
632                       GdkDragContext *context,
633                       gpointer data)
634 {
635         /* XXX unfortunately a completed drag & drop does not emit 
636          * a "rows_reordered" signal, but a "row_changed" signal.
637          * So during drag and drop, listen to "row_changed", and
638          * update the account list accordingly */
639
640         GtkTreeModel *model = gtk_tree_view_get_model(list_view);
641         g_signal_connect(G_OBJECT(model), "row_changed",
642                          G_CALLBACK(actions_list_model_row_changed),
643                          list_view);
644 }
645
646 static void drag_end(GtkTreeView *list_view,
647                     GdkDragContext *context,
648                     gpointer data)
649 {
650         GtkTreeModel *model = gtk_tree_view_get_model(list_view);
651         g_signal_handlers_disconnect_by_func(G_OBJECT(model),
652                                              G_CALLBACK(actions_list_model_row_changed),
653                                              list_view);
654         prefs_summary_open_set_list();
655 }
656