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