ac027948ef2d23a72fd5d01919d2bfbe0ad9cd80
[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 3 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, see <http://www.gnu.org/licenses/>.
17  * 
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[SUMMARY_OPEN_ACTIONS-1];
105
106 static gchar *action_name[SUMMARY_OPEN_ACTIONS] = 
107 {         ("UNSET (!)"),
108          N_("first marked email"),
109          N_("first new email"),
110          N_("first unread email"),
111          N_("last opened email"),
112          N_("last email in the list"),
113          N_("none"),
114          N_("first email in the list")
115 };
116
117 void prefs_summary_open_open(void)
118 {
119         int i;
120         if (!summaryopen.window) {
121                 prefs_summary_open_create();
122         }
123
124         manage_window_set_transient(GTK_WINDOW(summaryopen.window));
125         gtk_widget_grab_focus(summaryopen.ok_btn);
126
127         prefs_summary_open_set_dialog();
128         
129         for (i = 0; i < SUMMARY_OPEN_ACTIONS-1; i++)
130                 saved_summary_select_prio[i] = prefs_common.summary_select_prio[i];
131
132         gtk_widget_show(summaryopen.window);
133 }
134
135 static void prefs_summary_open_create(void)
136 {
137         GtkWidget *window;
138         GtkWidget *vbox;
139         GtkWidget *btn_hbox;
140         GtkWidget *ok_btn;
141         GtkWidget *cancel_btn;
142         GtkWidget *confirm_area;
143
144         GtkWidget *vbox1;
145
146         GtkWidget *hbox1;
147
148         GtkWidget *btn_vbox;
149         GtkWidget *reg_btn;
150         GtkWidget *del_btn;
151         GtkWidget *up_btn;
152         GtkWidget *down_btn;
153
154         GtkWidget *list_view_hbox;
155         GtkWidget *list_view_hbox1;
156         GtkWidget *list_view_hbox2;
157         GtkWidget *list_view_scrolledwin;
158         GtkWidget *possible_actions_list_view;
159         GtkWidget *actions_list_view;
160         
161         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_summary_open");
162         gtk_container_set_border_width (GTK_CONTAINER (window), 8);
163         gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
164         gtk_window_set_modal (GTK_WINDOW (window), TRUE);
165         gtk_window_set_resizable(GTK_WINDOW (window), TRUE);
166
167         vbox = gtk_vbox_new (FALSE, 6);
168         gtk_widget_show (vbox);
169         gtk_container_add (GTK_CONTAINER (window), vbox);
170
171         btn_hbox = gtk_hbox_new (FALSE, 8);
172         gtk_widget_show (btn_hbox);
173         gtk_box_pack_end (GTK_BOX (vbox), btn_hbox, FALSE, FALSE, 0);
174
175         gtkut_stock_button_set_create(&confirm_area, &cancel_btn, GTK_STOCK_CANCEL,
176                                       &ok_btn, GTK_STOCK_OK,
177                                       NULL, NULL);
178         gtk_widget_show (confirm_area);
179         gtk_box_pack_end (GTK_BOX(btn_hbox), confirm_area, FALSE, FALSE, 0);
180         gtk_widget_grab_default (ok_btn);
181
182         gtk_window_set_title (GTK_WINDOW(window),
183                               _(" Selection when entering a folder"));
184         MANAGE_WINDOW_SIGNALS_CONNECT(window);
185         g_signal_connect (G_OBJECT(window), "delete_event",
186                           G_CALLBACK(prefs_summary_open_deleted),
187                           NULL);
188         g_signal_connect (G_OBJECT(window), "key_press_event",
189                           G_CALLBACK(prefs_summary_open_key_pressed),
190                           NULL);
191         g_signal_connect (G_OBJECT(ok_btn), "clicked",
192                           G_CALLBACK(prefs_summary_open_ok),
193                           NULL);
194         g_signal_connect (G_OBJECT(cancel_btn), "clicked",
195                           G_CALLBACK(prefs_summary_open_cancel),
196                           NULL);
197
198         vbox1 = gtk_vbox_new (FALSE, VSPACING);
199         gtk_widget_show (vbox1);
200         gtk_box_pack_start (GTK_BOX (vbox), vbox1, TRUE, TRUE, 0);
201         gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
202
203         hbox1 = gtk_hbox_new (FALSE, 8);
204         gtk_widget_show (hbox1);
205         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, TRUE, 0);
206
207         /* display headers list */
208
209         list_view_hbox = gtk_hbox_new (FALSE, 10);
210         gtk_widget_show (list_view_hbox);
211         gtk_box_pack_start (GTK_BOX (vbox1), list_view_hbox, TRUE, TRUE, 0);
212
213         list_view_hbox1 = gtk_hbox_new (FALSE, 8);
214         gtk_widget_show (list_view_hbox1);
215         gtk_box_pack_start (GTK_BOX (list_view_hbox), list_view_hbox1, TRUE, TRUE, 0);
216
217         list_view_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
218         gtk_widget_set_size_request (list_view_scrolledwin, 200, 210);
219         gtk_widget_show (list_view_scrolledwin);
220         gtk_box_pack_start (GTK_BOX (list_view_hbox1), list_view_scrolledwin,
221                             TRUE, TRUE, 0);
222         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (list_view_scrolledwin),
223                                         GTK_POLICY_AUTOMATIC,
224                                         GTK_POLICY_AUTOMATIC);
225         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(list_view_scrolledwin),
226                                             GTK_SHADOW_IN);
227
228         possible_actions_list_view = prefs_summary_open_list_view_create
229                                 (_("Possible selections"));
230         gtk_widget_show (possible_actions_list_view);
231         gtk_container_add(GTK_CONTAINER(list_view_scrolledwin), possible_actions_list_view);
232
233         btn_vbox = gtk_vbox_new (FALSE, 8);
234         gtk_widget_show (btn_vbox);
235         gtk_box_pack_start (GTK_BOX (list_view_hbox1), btn_vbox, FALSE, FALSE, 0);
236
237         reg_btn = gtk_button_new_from_stock (GTK_STOCK_ADD);
238         gtk_widget_show (reg_btn);
239         gtk_box_pack_start (GTK_BOX (btn_vbox), reg_btn, FALSE, TRUE, 0);
240         g_signal_connect (G_OBJECT (reg_btn), "clicked",
241                           G_CALLBACK (prefs_summary_open_register_cb),
242                           possible_actions_list_view);
243         del_btn = gtk_button_new_from_stock (GTK_STOCK_REMOVE);
244         gtk_widget_show (del_btn);
245         gtk_box_pack_start (GTK_BOX (btn_vbox), del_btn, FALSE, TRUE, 0);
246
247         /* actions list */
248
249         list_view_hbox2 = gtk_hbox_new (FALSE, 8);
250         gtk_widget_show (list_view_hbox2);
251         gtk_box_pack_start (GTK_BOX (list_view_hbox), list_view_hbox2, TRUE, TRUE, 0);
252
253         list_view_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
254         gtk_widget_set_size_request (list_view_scrolledwin, 200, 230);
255         gtk_widget_show (list_view_scrolledwin);
256         gtk_box_pack_start (GTK_BOX (list_view_hbox2), list_view_scrolledwin,
257                             TRUE, TRUE, 0);
258         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (list_view_scrolledwin),
259                                         GTK_POLICY_AUTOMATIC,
260                                         GTK_POLICY_AUTOMATIC);
261         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(list_view_scrolledwin),
262                                             GTK_SHADOW_IN);
263
264         actions_list_view = prefs_summary_open_list_view_create
265                                         (_("Selection on folder opening"));
266         g_signal_connect (G_OBJECT (del_btn), "clicked",
267                           G_CALLBACK (prefs_summary_open_delete_cb),
268                           actions_list_view);
269         gtk_widget_show (actions_list_view);
270         gtk_container_add (GTK_CONTAINER (list_view_scrolledwin),
271                            actions_list_view);
272
273         gtk_tree_view_set_reorderable(GTK_TREE_VIEW(actions_list_view), TRUE);
274         g_signal_connect(G_OBJECT(actions_list_view), "drag_begin",                      
275                          G_CALLBACK(drag_begin),
276                          actions_list_view);
277                          
278         g_signal_connect(G_OBJECT(actions_list_view), "drag_end",                        
279                          G_CALLBACK(drag_end),
280                          actions_list_view);
281         
282         btn_vbox = gtk_vbox_new (FALSE, 8);
283         gtk_widget_show (btn_vbox);
284         gtk_box_pack_start (GTK_BOX (list_view_hbox2), btn_vbox, FALSE, FALSE, 0);
285
286         up_btn = gtk_button_new_from_stock (GTK_STOCK_GO_UP);
287         gtk_widget_show (up_btn);
288         gtk_box_pack_start (GTK_BOX (btn_vbox), up_btn, FALSE, FALSE, 0);
289         g_signal_connect (G_OBJECT (up_btn), "clicked",
290                           G_CALLBACK (prefs_summary_open_up), NULL);
291
292         down_btn = gtk_button_new_from_stock (GTK_STOCK_GO_DOWN);
293         gtk_widget_show (down_btn);
294         gtk_box_pack_start (GTK_BOX (btn_vbox), down_btn, FALSE, FALSE, 0);
295         g_signal_connect (G_OBJECT (down_btn), "clicked",
296                           G_CALLBACK (prefs_summary_open_down), NULL);
297         
298
299         gtk_widget_show_all(window);
300
301         summaryopen.window        = window;
302         summaryopen.ok_btn        = ok_btn;
303         summaryopen.cancel_btn    = cancel_btn;
304
305         summaryopen.possible_actions_list_view        = possible_actions_list_view;
306         summaryopen.actions_list_view = actions_list_view;
307 }
308
309 /* do it SUMMARY_OPEN_ACTIONS-1 times */
310 #define SET_PRIO(p_one,p_two,p_three,p_four) {                          \
311         prefs_common.summary_select_prio[0] = p_one;                    \
312         prefs_common.summary_select_prio[1] = p_two;                    \
313         prefs_common.summary_select_prio[2] = p_three;                  \
314         prefs_common.summary_select_prio[3] = p_four;                   \
315         prefs_common.summary_select_prio[4] = ACTION_UNSET;             \
316         prefs_common.summary_select_prio[5] = ACTION_UNSET;             \
317         prefs_common.summary_select_prio[6] = ACTION_UNSET;             \
318 }                                                       
319
320 void prefs_summary_open_set_defaults(void)
321 {
322         switch (prefs_common.select_on_entry) {
323                 case SELECTONENTRY_MNU:
324                         SET_PRIO(ACTION_MARKED, ACTION_NEW, ACTION_UNREAD, ACTION_LAST_LIST); break;
325                 case SELECTONENTRY_MUN:
326                         SET_PRIO(ACTION_MARKED, ACTION_UNREAD, ACTION_NEW, ACTION_LAST_LIST); break;
327                 case SELECTONENTRY_NMU:
328                         SET_PRIO(ACTION_NEW, ACTION_MARKED, ACTION_UNREAD, ACTION_LAST_LIST); break;
329                 case SELECTONENTRY_NUM:
330                         SET_PRIO(ACTION_NEW, ACTION_UNREAD, ACTION_MARKED, ACTION_LAST_LIST); break;
331                 case SELECTONENTRY_UNM:
332                         SET_PRIO(ACTION_UNREAD, ACTION_NEW, ACTION_MARKED, ACTION_LAST_LIST); break;
333                 case SELECTONENTRY_UMN:
334                         SET_PRIO(ACTION_UNREAD, ACTION_MARKED, ACTION_NEW, ACTION_LAST_LIST); break;
335                 case SELECTONENTRY_LAST:
336                         SET_PRIO(ACTION_LAST_OPENED, ACTION_LAST_LIST, ACTION_UNSET, ACTION_UNSET); break;
337                 case SELECTONENTRY_NOTHING:
338                         SET_PRIO(ACTION_LAST_LIST, ACTION_UNSET, ACTION_UNSET, ACTION_UNSET); break;
339                 default:
340                         break;
341         }
342 }
343 static void prefs_summary_open_set_dialog(void)
344 {
345         GtkTreeView *possible_list_view = GTK_TREE_VIEW(summaryopen.possible_actions_list_view);
346         GtkTreeView *actions_list_view = GTK_TREE_VIEW(summaryopen.actions_list_view);
347         GtkTreeModel *model_poss, *model_act;
348         int i;
349         gboolean set = FALSE;
350         gboolean used[SUMMARY_OPEN_ACTIONS-1] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE};
351
352         model_poss = gtk_tree_view_get_model(possible_list_view);
353         model_act = gtk_tree_view_get_model(actions_list_view);
354
355         gtk_list_store_clear(GTK_LIST_STORE(model_poss));
356         gtk_list_store_clear(GTK_LIST_STORE(model_act));
357
358 fill:
359         for (i = 0; i < SUMMARY_OPEN_ACTIONS-1; i++) {
360                 EntryAction act = prefs_common.summary_select_prio[i];
361
362                 if (act == ACTION_UNSET) 
363                         continue;
364                 
365                 set = TRUE;
366                 used[act-1] = TRUE;
367                 prefs_summary_open_insert_action(GTK_LIST_STORE
368                                         (model_act), action_name[act], act);    
369         }
370         if (!set) {
371                 /* backward compat */
372                 prefs_summary_open_set_defaults();
373                 goto fill;
374         }
375
376         for (i = 1; i < SUMMARY_OPEN_ACTIONS; i++) {
377                 if (!used[i-1]) {
378                         prefs_summary_open_insert_action(GTK_LIST_STORE
379                                         (model_poss), action_name[i], i);       
380                 }
381         }
382 }
383
384 static void prefs_summary_open_set_list(void)
385 {
386         gint row = 0;
387         gpointer data;
388         GtkTreeModel *model;
389         GtkTreeIter iter;
390
391
392         model = gtk_tree_view_get_model(GTK_TREE_VIEW(summaryopen.actions_list_view));
393         while (gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
394                 gtk_tree_model_get(model, &iter, PREFS_SUMMARY_OPEN_DATA, &data, -1);
395                 prefs_common.summary_select_prio[row] = GPOINTER_TO_INT(data);
396                 row++;                          
397         }
398         for (; row < SUMMARY_OPEN_ACTIONS-1; row++) {
399                 prefs_common.summary_select_prio[row] = ACTION_UNSET;
400         }
401 }
402
403 static void prefs_summary_open_delete_cb(GtkButton *btn, gpointer list_view_data)
404 {
405         GtkTreeView *list_view = GTK_TREE_VIEW(list_view_data);
406         gpointer data;
407         GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(list_view));
408         GtkTreeSelection *selection = gtk_tree_view_get_selection(list_view);
409         GtkTreeIter iter;
410         GtkTreeView *possible_list_view = GTK_TREE_VIEW(summaryopen.possible_actions_list_view);
411         GtkTreeModel *model, *model_poss;
412         gint i;
413
414         model = gtk_tree_view_get_model(list_view);
415         model_poss = gtk_tree_view_get_model(possible_list_view);
416
417         if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
418                 return;
419
420         gtk_tree_model_get(model, &iter, PREFS_SUMMARY_OPEN_DATA, &data, -1);
421         if (!data) 
422                 return;
423
424         gtk_list_store_remove(store, &iter);
425
426         i = GPOINTER_TO_INT(data);
427         prefs_summary_open_insert_action(GTK_LIST_STORE
428                                         (model_poss), action_name[i], i);       
429         
430         prefs_summary_open_set_list();
431 }
432
433 static void prefs_summary_open_register_cb(GtkButton *btn, gpointer list_view_data)
434 {
435         GtkTreeView *possible_list_view = GTK_TREE_VIEW(list_view_data);
436         GtkTreeView *list_view = GTK_TREE_VIEW(summaryopen.actions_list_view);
437         gpointer data;
438         GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(possible_list_view));
439         GtkTreeSelection *selection = gtk_tree_view_get_selection(possible_list_view);
440         GtkTreeIter iter;
441         GtkTreeModel *model, *model_poss;
442         gint i;
443
444         model = gtk_tree_view_get_model(list_view);
445         model_poss = gtk_tree_view_get_model(possible_list_view);
446
447         if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
448                 return;
449
450         gtk_tree_model_get(model_poss, &iter, PREFS_SUMMARY_OPEN_DATA, &data, -1);
451         if (!data) 
452                 return;
453
454         gtk_list_store_remove(store, &iter);
455
456         i = GPOINTER_TO_INT(data);
457         prefs_summary_open_insert_action(GTK_LIST_STORE
458                                         (model), action_name[i], i);    
459         
460         prefs_summary_open_set_list();
461 }
462
463 static void prefs_summary_open_up(void)
464 {
465         GtkTreePath *prev, *sel, *try;
466         GtkTreeIter isel;
467         GtkListStore *store = NULL;
468         GtkTreeModel *model = NULL;
469         GtkTreeIter iprev;
470         
471         if (!gtk_tree_selection_get_selected
472                 (gtk_tree_view_get_selection
473                         (GTK_TREE_VIEW(summaryopen.actions_list_view)),
474                  &model,        
475                  &isel))
476                 return;
477         store = (GtkListStore *)model;
478         sel = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &isel);
479         if (!sel)
480                 return;
481         
482         /* no move if we're at row 0... */
483         try = gtk_tree_path_copy(sel);
484         if (!gtk_tree_path_prev(try)) {
485                 gtk_tree_path_free(try);
486                 gtk_tree_path_free(sel);
487                 return;
488         }
489
490         prev = try;
491         gtk_tree_model_get_iter(GTK_TREE_MODEL(store),
492                                 &iprev, prev);
493         gtk_list_store_swap(store, &iprev, &isel);
494
495         gtk_tree_path_free(sel);
496         gtk_tree_path_free(prev);
497         prefs_summary_open_set_list();
498 }
499
500 static void prefs_summary_open_down(void)
501 {
502         GtkListStore *store = NULL;
503         GtkTreeModel *model = NULL;
504         GtkTreeIter next, sel;
505         GtkTreePath *try;
506         
507         if (!gtk_tree_selection_get_selected
508                 (gtk_tree_view_get_selection
509                         (GTK_TREE_VIEW(summaryopen.actions_list_view)),
510                  &model,
511                  &sel))
512                 return;
513         store = (GtkListStore *)model;
514         try = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &sel);
515         if (!try) 
516                 return;
517         
518         next = sel;
519         if (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &next))
520                 gtk_list_store_swap(store, &next, &sel);
521                 
522         gtk_tree_path_free(try);
523         prefs_summary_open_set_list();
524 }
525
526 static gboolean prefs_summary_open_key_pressed(GtkWidget *widget,
527                                              GdkEventKey *event,
528                                              gpointer data)
529 {
530         if (event && event->keyval == GDK_Escape)
531                 prefs_summary_open_cancel();
532         return FALSE;
533 }
534
535 static void prefs_summary_open_ok(void)
536 {
537         int i;
538         for (i = 0; i < SUMMARY_OPEN_ACTIONS-1; i++)
539                 saved_summary_select_prio[i] = prefs_common.summary_select_prio[i];
540
541         gtk_widget_hide(summaryopen.window);
542 }
543
544 static void prefs_summary_open_cancel(void)
545 {
546         int i;
547         for (i = 0; i < SUMMARY_OPEN_ACTIONS-1; i++)
548                 prefs_common.summary_select_prio[i] = saved_summary_select_prio[i];
549
550         gtk_widget_hide(summaryopen.window);
551 }
552
553 static gint prefs_summary_open_deleted(GtkWidget *widget, GdkEventAny *event,
554                                          gpointer data)
555 {
556         prefs_summary_open_cancel();
557         return TRUE;
558 }
559
560 static GtkListStore *prefs_summary_open_create_store(void)
561 {
562         return gtk_list_store_new(N_PREFS_SUMMARY_OPEN_COLUMNS,
563                                   G_TYPE_STRING,
564                                   G_TYPE_POINTER,
565                                   -1);
566 }
567
568 static void prefs_summary_open_insert_action(GtkListStore *store,
569                                                gchar *name,
570                                                gint dp)
571 {
572         GtkTreeIter iter;
573
574         /* add new */
575         gtk_list_store_append(store, &iter);
576         gtk_list_store_set(store, &iter,
577                            PREFS_SUMMARY_OPEN_HEADER,
578                            gettext(name),
579                            PREFS_SUMMARY_OPEN_DATA, GINT_TO_POINTER(dp),
580                            -1);
581 }
582
583 static GtkWidget *prefs_summary_open_list_view_create(const gchar *name)
584 {
585         GtkWidget *list_view;
586         GtkTreeSelection *selector;
587         GtkTreeModel *model;
588
589         model = GTK_TREE_MODEL(prefs_summary_open_create_store());
590         list_view = gtk_tree_view_new_with_model(model);
591         g_object_unref(G_OBJECT(model));
592         
593         gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(list_view),
594                                      prefs_common.use_stripes_everywhere);
595         
596         selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
597         gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
598
599         prefs_summary_open_create_list_view_columns(GTK_WIDGET(list_view), name);
600
601         return list_view;
602 }
603
604 static void prefs_summary_open_create_list_view_columns(GtkWidget *list_view, 
605                                                      const gchar *name)
606 {
607         GtkTreeViewColumn *column;
608         GtkCellRenderer *renderer;
609
610         renderer = gtk_cell_renderer_text_new();
611         column = gtk_tree_view_column_new_with_attributes
612                 (name, renderer, "text", PREFS_SUMMARY_OPEN_HEADER, NULL);
613         gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);          
614 }
615
616 /*!
617  *\brief        Called as a result of a drag & drop
618  */
619 static void actions_list_model_row_changed(GtkTreeModel *model, 
620                                            GtkTreePath *path, 
621                                            GtkTreeIter *iter, 
622                                            GtkTreeView *list_view)
623 {
624 }
625
626 /*!
627  *\brief        Called as a result of a gtk_list_store_swap()
628  */
629 static void drag_begin(GtkTreeView *list_view,
630                       GdkDragContext *context,
631                       gpointer data)
632 {
633         /* XXX unfortunately a completed drag & drop does not emit 
634          * a "rows_reordered" signal, but a "row_changed" signal.
635          * So during drag and drop, listen to "row_changed", and
636          * update the account list accordingly */
637
638         GtkTreeModel *model = gtk_tree_view_get_model(list_view);
639         g_signal_connect(G_OBJECT(model), "row_changed",
640                          G_CALLBACK(actions_list_model_row_changed),
641                          list_view);
642 }
643
644 static void drag_end(GtkTreeView *list_view,
645                     GdkDragContext *context,
646                     gpointer data)
647 {
648         GtkTreeModel *model = gtk_tree_view_get_model(list_view);
649         g_signal_handlers_disconnect_by_func(G_OBJECT(model),
650                                              G_CALLBACK(actions_list_model_row_changed),
651                                              list_view);
652         prefs_summary_open_set_list();
653 }
654