Add more granular options on when to open a selected message.
[claws.git] / src / prefs_summary_open.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2012 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 #include "claws-features.h"
23 #endif
24
25 #include "defs.h"
26
27 #include <glib.h>
28 #include <glib/gi18n.h>
29 #include <gtk/gtk.h>
30 #include <gdk/gdkkeysyms.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <errno.h>
35
36 #include "prefs_gtk.h"
37 #include "prefs_summary_open.h"
38 #include "prefs_common.h"
39 #include "manage_window.h"
40 #include "alertpanel.h"
41 #include "displayheader.h"
42 #include "utils.h"
43 #include "gtkutils.h"
44
45 enum {
46         PREFS_SUMMARY_OPEN_HEADER,
47         PREFS_SUMMARY_OPEN_DATA,
48         N_PREFS_SUMMARY_OPEN_COLUMNS
49 };
50
51 static struct SummaryOpen {
52         GtkWidget *window;
53
54         GtkWidget *ok_btn;
55         GtkWidget *cancel_btn;
56
57         GtkWidget *possible_actions_list_view;
58         GtkWidget *actions_list_view;
59 } summaryopen;
60
61 /* widget creating functions */
62 static void prefs_summary_open_create   (void);
63
64 static void prefs_summary_open_set_dialog       (void);
65 static void prefs_summary_open_set_list (void);
66
67 /* callback functions */
68 static void prefs_summary_open_register_cb      (GtkButton      *btn,
69                                                  gpointer        hidden_data);
70 static void prefs_summary_open_delete_cb        (GtkButton      *btn,
71                                                  gpointer        list_view_data);
72 static void prefs_summary_open_up               (void);
73 static void prefs_summary_open_down             (void);
74
75 static gboolean prefs_summary_open_key_pressed  (GtkWidget      *widget,
76                                                          GdkEventKey    *event,
77                                                          gpointer        data);
78 static void prefs_summary_open_ok               (void);
79 static void prefs_summary_open_cancel           (void);
80 static gint prefs_summary_open_deleted  (GtkWidget      *widget,
81                                                  GdkEventAny    *event,
82                                                  gpointer        data);
83
84
85 static GtkListStore *prefs_summary_open_create_store    (void);
86 static void prefs_summary_open_insert_action            (GtkListStore *store,
87                                                          gchar *name,
88                                                          gint act);
89 static GtkWidget *prefs_summary_open_list_view_create   (const gchar *name);
90 static void prefs_summary_open_create_list_view_columns (GtkWidget *list_view, 
91                                                          const gchar *name);
92 static void actions_list_model_row_changed              (GtkTreeModel *model, 
93                                                          GtkTreePath *path, 
94                                                          GtkTreeIter *iter, 
95                                                          GtkTreeView *list_view);
96                                                          
97 static void drag_begin  (GtkTreeView *list_view,
98                          GdkDragContext *context,
99                          gpointer data);
100
101 static void drag_end    (GtkTreeView *list_view,
102                          GdkDragContext *context,
103                          gpointer data);
104
105 static EntryAction saved_summary_select_prio[SUMMARY_OPEN_ACTIONS-1];
106
107 static gchar *action_name[SUMMARY_OPEN_ACTIONS] = 
108 {         ("UNSET (!)"),
109          N_("first marked email"),
110          N_("first new email"),
111          N_("first unread email"),
112          N_("last opened email"),
113          N_("last email in the list"),
114          N_("none"),
115          N_("first email in the list")
116 };
117
118 void prefs_summary_open_open(void)
119 {
120         int i;
121         if (!summaryopen.window) {
122                 prefs_summary_open_create();
123         }
124
125         manage_window_set_transient(GTK_WINDOW(summaryopen.window));
126         gtk_widget_grab_focus(summaryopen.ok_btn);
127
128         prefs_summary_open_set_dialog();
129         
130         for (i = 0; i < SUMMARY_OPEN_ACTIONS-1; i++)
131                 saved_summary_select_prio[i] = prefs_common.summary_select_prio[i];
132
133         gtk_widget_show(summaryopen.window);
134         gtk_window_set_modal(GTK_WINDOW(summaryopen.window), TRUE);
135 }
136
137 static void prefs_summary_open_create(void)
138 {
139         GtkWidget *window;
140         GtkWidget *vbox;
141         GtkWidget *btn_hbox;
142         GtkWidget *ok_btn;
143         GtkWidget *cancel_btn;
144         GtkWidget *confirm_area;
145
146         GtkWidget *vbox1;
147
148         GtkWidget *hbox1;
149
150         GtkWidget *btn_vbox;
151         GtkWidget *reg_btn;
152         GtkWidget *del_btn;
153         GtkWidget *up_btn;
154         GtkWidget *down_btn;
155
156         GtkWidget *list_view_hbox;
157         GtkWidget *list_view_hbox1;
158         GtkWidget *list_view_hbox2;
159         GtkWidget *list_view_scrolledwin;
160         GtkWidget *possible_actions_list_view;
161         GtkWidget *actions_list_view;
162         
163         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_summary_open");
164         gtk_container_set_border_width (GTK_CONTAINER (window), 8);
165         gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
166         gtk_window_set_resizable(GTK_WINDOW (window), TRUE);
167
168         vbox = gtk_vbox_new (FALSE, 6);
169         gtk_widget_show (vbox);
170         gtk_container_add (GTK_CONTAINER (window), vbox);
171
172         btn_hbox = gtk_hbox_new (FALSE, 8);
173         gtk_widget_show (btn_hbox);
174         gtk_box_pack_end (GTK_BOX (vbox), btn_hbox, FALSE, FALSE, 0);
175
176         gtkut_stock_button_set_create(&confirm_area, &cancel_btn, GTK_STOCK_CANCEL,
177                                       &ok_btn, GTK_STOCK_OK,
178                                       NULL, NULL);
179         gtk_widget_show (confirm_area);
180         gtk_box_pack_end (GTK_BOX(btn_hbox), confirm_area, FALSE, FALSE, 0);
181         gtk_widget_grab_default (ok_btn);
182
183         gtk_window_set_title (GTK_WINDOW(window),
184                               _(" Selection when entering a folder"));
185         MANAGE_WINDOW_SIGNALS_CONNECT(window);
186         g_signal_connect (G_OBJECT(window), "delete_event",
187                           G_CALLBACK(prefs_summary_open_deleted),
188                           NULL);
189         g_signal_connect (G_OBJECT(window), "key_press_event",
190                           G_CALLBACK(prefs_summary_open_key_pressed),
191                           NULL);
192         g_signal_connect (G_OBJECT(ok_btn), "clicked",
193                           G_CALLBACK(prefs_summary_open_ok),
194                           NULL);
195         g_signal_connect (G_OBJECT(cancel_btn), "clicked",
196                           G_CALLBACK(prefs_summary_open_cancel),
197                           NULL);
198
199         vbox1 = gtk_vbox_new (FALSE, VSPACING);
200         gtk_widget_show (vbox1);
201         gtk_box_pack_start (GTK_BOX (vbox), vbox1, TRUE, TRUE, 0);
202         gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
203
204         hbox1 = gtk_hbox_new (FALSE, 8);
205         gtk_widget_show (hbox1);
206         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, TRUE, 0);
207
208         /* display headers list */
209
210         list_view_hbox = gtk_hbox_new (FALSE, 10);
211         gtk_widget_show (list_view_hbox);
212         gtk_box_pack_start (GTK_BOX (vbox1), list_view_hbox, TRUE, TRUE, 0);
213
214         list_view_hbox1 = gtk_hbox_new (FALSE, 8);
215         gtk_widget_show (list_view_hbox1);
216         gtk_box_pack_start (GTK_BOX (list_view_hbox), list_view_hbox1, TRUE, TRUE, 0);
217
218         list_view_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
219         gtk_widget_set_size_request (list_view_scrolledwin, 200, 210);
220         gtk_widget_show (list_view_scrolledwin);
221         gtk_box_pack_start (GTK_BOX (list_view_hbox1), list_view_scrolledwin,
222                             TRUE, TRUE, 0);
223         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (list_view_scrolledwin),
224                                         GTK_POLICY_AUTOMATIC,
225                                         GTK_POLICY_AUTOMATIC);
226         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(list_view_scrolledwin),
227                                             GTK_SHADOW_IN);
228
229         possible_actions_list_view = prefs_summary_open_list_view_create
230                                 (_("Possible selections"));
231         gtk_widget_show (possible_actions_list_view);
232         gtk_container_add(GTK_CONTAINER(list_view_scrolledwin), possible_actions_list_view);
233
234         btn_vbox = gtk_vbox_new (FALSE, 8);
235         gtk_widget_show (btn_vbox);
236         gtk_box_pack_start (GTK_BOX (list_view_hbox1), btn_vbox, FALSE, FALSE, 0);
237
238         reg_btn = gtk_button_new_from_stock (GTK_STOCK_ADD);
239         gtk_widget_show (reg_btn);
240         gtk_box_pack_start (GTK_BOX (btn_vbox), reg_btn, FALSE, TRUE, 0);
241         g_signal_connect (G_OBJECT (reg_btn), "clicked",
242                           G_CALLBACK (prefs_summary_open_register_cb),
243                           possible_actions_list_view);
244         del_btn = gtk_button_new_from_stock (GTK_STOCK_REMOVE);
245         gtk_widget_show (del_btn);
246         gtk_box_pack_start (GTK_BOX (btn_vbox), del_btn, FALSE, TRUE, 0);
247
248         /* actions list */
249
250         list_view_hbox2 = gtk_hbox_new (FALSE, 8);
251         gtk_widget_show (list_view_hbox2);
252         gtk_box_pack_start (GTK_BOX (list_view_hbox), list_view_hbox2, TRUE, TRUE, 0);
253
254         list_view_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
255         gtk_widget_set_size_request (list_view_scrolledwin, 200, 230);
256         gtk_widget_show (list_view_scrolledwin);
257         gtk_box_pack_start (GTK_BOX (list_view_hbox2), list_view_scrolledwin,
258                             TRUE, TRUE, 0);
259         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (list_view_scrolledwin),
260                                         GTK_POLICY_AUTOMATIC,
261                                         GTK_POLICY_AUTOMATIC);
262         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(list_view_scrolledwin),
263                                             GTK_SHADOW_IN);
264
265         actions_list_view = prefs_summary_open_list_view_create
266                                         (_("Selection on folder opening"));
267         g_signal_connect (G_OBJECT (del_btn), "clicked",
268                           G_CALLBACK (prefs_summary_open_delete_cb),
269                           actions_list_view);
270         gtk_widget_show (actions_list_view);
271         gtk_container_add (GTK_CONTAINER (list_view_scrolledwin),
272                            actions_list_view);
273
274         gtk_tree_view_set_reorderable(GTK_TREE_VIEW(actions_list_view), TRUE);
275         g_signal_connect(G_OBJECT(actions_list_view), "drag_begin",                      
276                          G_CALLBACK(drag_begin),
277                          actions_list_view);
278                          
279         g_signal_connect(G_OBJECT(actions_list_view), "drag_end",                        
280                          G_CALLBACK(drag_end),
281                          actions_list_view);
282         
283         btn_vbox = gtk_vbox_new (FALSE, 8);
284         gtk_widget_show (btn_vbox);
285         gtk_box_pack_start (GTK_BOX (list_view_hbox2), btn_vbox, FALSE, FALSE, 0);
286
287         up_btn = gtk_button_new_from_stock (GTK_STOCK_GO_UP);
288         gtk_widget_show (up_btn);
289         gtk_box_pack_start (GTK_BOX (btn_vbox), up_btn, FALSE, FALSE, 0);
290         g_signal_connect (G_OBJECT (up_btn), "clicked",
291                           G_CALLBACK (prefs_summary_open_up), NULL);
292
293         down_btn = gtk_button_new_from_stock (GTK_STOCK_GO_DOWN);
294         gtk_widget_show (down_btn);
295         gtk_box_pack_start (GTK_BOX (btn_vbox), down_btn, FALSE, FALSE, 0);
296         g_signal_connect (G_OBJECT (down_btn), "clicked",
297                           G_CALLBACK (prefs_summary_open_down), NULL);
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         model = gtk_tree_view_get_model(GTK_TREE_VIEW(summaryopen.actions_list_view));
392         while (gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
393                 gtk_tree_model_get(model, &iter, PREFS_SUMMARY_OPEN_DATA, &data, -1);
394                 prefs_common.summary_select_prio[row] = GPOINTER_TO_INT(data);
395                 row++;                          
396         }
397         for (; row < SUMMARY_OPEN_ACTIONS-1; row++) {
398                 prefs_common.summary_select_prio[row] = ACTION_UNSET;
399         }
400 }
401
402 static void prefs_summary_open_delete_cb(GtkButton *btn, gpointer list_view_data)
403 {
404         GtkTreeView *list_view = GTK_TREE_VIEW(list_view_data);
405         gpointer data;
406         GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(list_view));
407         GtkTreeSelection *selection = gtk_tree_view_get_selection(list_view);
408         GtkTreeIter iter;
409         GtkTreeView *possible_list_view = GTK_TREE_VIEW(summaryopen.possible_actions_list_view);
410         GtkTreeModel *model, *model_poss;
411         gint i;
412
413         model = gtk_tree_view_get_model(list_view);
414         model_poss = gtk_tree_view_get_model(possible_list_view);
415
416         if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
417                 return;
418
419         gtk_tree_model_get(model, &iter, PREFS_SUMMARY_OPEN_DATA, &data, -1);
420         if (!data) 
421                 return;
422
423         gtk_list_store_remove(store, &iter);
424
425         i = GPOINTER_TO_INT(data);
426         prefs_summary_open_insert_action(GTK_LIST_STORE
427                                         (model_poss), action_name[i], i);       
428         
429         prefs_summary_open_set_list();
430 }
431
432 static void prefs_summary_open_register_cb(GtkButton *btn, gpointer list_view_data)
433 {
434         GtkTreeView *possible_list_view = GTK_TREE_VIEW(list_view_data);
435         GtkTreeView *list_view = GTK_TREE_VIEW(summaryopen.actions_list_view);
436         gpointer data;
437         GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(possible_list_view));
438         GtkTreeSelection *selection = gtk_tree_view_get_selection(possible_list_view);
439         GtkTreeIter iter;
440         GtkTreeModel *model, *model_poss;
441         gint i;
442
443         model = gtk_tree_view_get_model(list_view);
444         model_poss = gtk_tree_view_get_model(possible_list_view);
445
446         if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
447                 return;
448
449         gtk_tree_model_get(model_poss, &iter, PREFS_SUMMARY_OPEN_DATA, &data, -1);
450         if (!data) 
451                 return;
452
453         gtk_list_store_remove(store, &iter);
454
455         i = GPOINTER_TO_INT(data);
456         prefs_summary_open_insert_action(GTK_LIST_STORE
457                                         (model), action_name[i], i);    
458         
459         prefs_summary_open_set_list();
460 }
461
462 static void prefs_summary_open_up(void)
463 {
464         GtkTreePath *prev, *sel, *try;
465         GtkTreeIter isel;
466         GtkListStore *store = NULL;
467         GtkTreeModel *model = NULL;
468         GtkTreeIter iprev;
469         
470         if (!gtk_tree_selection_get_selected
471                 (gtk_tree_view_get_selection
472                         (GTK_TREE_VIEW(summaryopen.actions_list_view)),
473                  &model,        
474                  &isel))
475                 return;
476         store = (GtkListStore *)model;
477         sel = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &isel);
478         if (!sel)
479                 return;
480         
481         /* no move if we're at row 0... */
482         try = gtk_tree_path_copy(sel);
483         if (!gtk_tree_path_prev(try)) {
484                 gtk_tree_path_free(try);
485                 gtk_tree_path_free(sel);
486                 return;
487         }
488
489         prev = try;
490         gtk_tree_model_get_iter(GTK_TREE_MODEL(store),
491                                 &iprev, prev);
492         gtk_list_store_swap(store, &iprev, &isel);
493
494         gtk_tree_path_free(sel);
495         gtk_tree_path_free(prev);
496         prefs_summary_open_set_list();
497 }
498
499 static void prefs_summary_open_down(void)
500 {
501         GtkListStore *store = NULL;
502         GtkTreeModel *model = NULL;
503         GtkTreeIter next, sel;
504         GtkTreePath *try;
505         
506         if (!gtk_tree_selection_get_selected
507                 (gtk_tree_view_get_selection
508                         (GTK_TREE_VIEW(summaryopen.actions_list_view)),
509                  &model,
510                  &sel))
511                 return;
512         store = (GtkListStore *)model;
513         try = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &sel);
514         if (!try) 
515                 return;
516         
517         next = sel;
518         if (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &next))
519                 gtk_list_store_swap(store, &next, &sel);
520                 
521         gtk_tree_path_free(try);
522         prefs_summary_open_set_list();
523 }
524
525 static gboolean prefs_summary_open_key_pressed(GtkWidget *widget,
526                                              GdkEventKey *event,
527                                              gpointer data)
528 {
529         if (event && event->keyval == GDK_KEY_Escape)
530                 prefs_summary_open_cancel();
531         return FALSE;
532 }
533
534 static void prefs_summary_open_ok(void)
535 {
536         int i;
537
538         /* force an empty list to be at least ACTION_NONE */
539         if (prefs_common.summary_select_prio[0] == ACTION_UNSET)
540                 prefs_common.summary_select_prio[0] = ACTION_NOTHING;
541
542         for (i = 0; i < SUMMARY_OPEN_ACTIONS-1; i++)
543                 saved_summary_select_prio[i] = prefs_common.summary_select_prio[i];
544
545         gtk_widget_hide(summaryopen.window);
546         gtk_window_set_modal(GTK_WINDOW(summaryopen.window), FALSE);
547 }
548
549 static void prefs_summary_open_cancel(void)
550 {
551         int i;
552         for (i = 0; i < SUMMARY_OPEN_ACTIONS-1; i++)
553                 prefs_common.summary_select_prio[i] = saved_summary_select_prio[i];
554
555         gtk_widget_hide(summaryopen.window);
556 }
557
558 static gint prefs_summary_open_deleted(GtkWidget *widget, GdkEventAny *event,
559                                          gpointer data)
560 {
561         prefs_summary_open_cancel();
562         return TRUE;
563 }
564
565 static GtkListStore *prefs_summary_open_create_store(void)
566 {
567         return gtk_list_store_new(N_PREFS_SUMMARY_OPEN_COLUMNS,
568                                   G_TYPE_STRING,
569                                   G_TYPE_POINTER,
570                                   -1);
571 }
572
573 static void prefs_summary_open_insert_action(GtkListStore *store,
574                                                gchar *name,
575                                                gint dp)
576 {
577         GtkTreeIter iter;
578
579         /* add new */
580         gtk_list_store_append(store, &iter);
581         gtk_list_store_set(store, &iter,
582                            PREFS_SUMMARY_OPEN_HEADER,
583                            gettext(name),
584                            PREFS_SUMMARY_OPEN_DATA, GINT_TO_POINTER(dp),
585                            -1);
586 }
587
588 static GtkWidget *prefs_summary_open_list_view_create(const gchar *name)
589 {
590         GtkWidget *list_view;
591         GtkTreeSelection *selector;
592         GtkTreeModel *model;
593
594         model = GTK_TREE_MODEL(prefs_summary_open_create_store());
595         list_view = gtk_tree_view_new_with_model(model);
596         g_object_unref(G_OBJECT(model));
597         
598         gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(list_view),
599                                      prefs_common.use_stripes_everywhere);
600         
601         selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
602         gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
603
604         prefs_summary_open_create_list_view_columns(GTK_WIDGET(list_view), name);
605
606         return list_view;
607 }
608
609 static void prefs_summary_open_create_list_view_columns(GtkWidget *list_view, 
610                                                      const gchar *name)
611 {
612         GtkTreeViewColumn *column;
613         GtkCellRenderer *renderer;
614
615         renderer = gtk_cell_renderer_text_new();
616         column = gtk_tree_view_column_new_with_attributes
617                 (name, renderer, "text", PREFS_SUMMARY_OPEN_HEADER, NULL);
618         gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);          
619 }
620
621 /*!
622  *\brief        Called as a result of a drag & drop
623  */
624 static void actions_list_model_row_changed(GtkTreeModel *model, 
625                                            GtkTreePath *path, 
626                                            GtkTreeIter *iter, 
627                                            GtkTreeView *list_view)
628 {
629 }
630
631 /*!
632  *\brief        Called as a result of a gtk_list_store_swap()
633  */
634 static void drag_begin(GtkTreeView *list_view,
635                       GdkDragContext *context,
636                       gpointer data)
637 {
638         /* XXX unfortunately a completed drag & drop does not emit 
639          * a "rows_reordered" signal, but a "row_changed" signal.
640          * So during drag and drop, listen to "row_changed", and
641          * update the account list accordingly */
642
643         GtkTreeModel *model = gtk_tree_view_get_model(list_view);
644         g_signal_connect(G_OBJECT(model), "row_changed",
645                          G_CALLBACK(actions_list_model_row_changed),
646                          list_view);
647 }
648
649 static void drag_end(GtkTreeView *list_view,
650                     GdkDragContext *context,
651                     gpointer data)
652 {
653         GtkTreeModel *model = gtk_tree_view_get_model(list_view);
654         g_signal_handlers_disconnect_by_func(G_OBJECT(model),
655                                              G_CALLBACK(actions_list_model_row_changed),
656                                              list_view);
657         prefs_summary_open_set_list();
658 }
659