fix bug 4239, 'Preferences: Text Options Header Display modal is not modal' (sic)
[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_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG);
171         gtk_widget_set_size_request (GTK_WIDGET (window), 610, 310);
172
173         vbox = gtk_vbox_new (FALSE, 6);
174         gtk_widget_show (vbox);
175         gtk_container_add (GTK_CONTAINER (window), vbox);
176
177         btn_hbox = gtk_hbox_new (FALSE, 8);
178         gtk_widget_show (btn_hbox);
179         gtk_box_pack_end (GTK_BOX (vbox), btn_hbox, FALSE, FALSE, 0);
180
181         gtkut_stock_button_set_create(&confirm_area, &cancel_btn, GTK_STOCK_CANCEL,
182                                       &ok_btn, GTK_STOCK_OK,
183                                       NULL, NULL);
184         gtk_widget_show (confirm_area);
185         gtk_box_pack_end (GTK_BOX(btn_hbox), confirm_area, FALSE, FALSE, 0);
186         gtk_widget_grab_default (ok_btn);
187
188         gtk_window_set_title (GTK_WINDOW(window),
189                               _("Message selection when entering a folder"));
190         MANAGE_WINDOW_SIGNALS_CONNECT(window);
191         g_signal_connect (G_OBJECT(window), "delete_event",
192                           G_CALLBACK(prefs_summary_open_deleted),
193                           NULL);
194         g_signal_connect (G_OBJECT(window), "key_press_event",
195                           G_CALLBACK(prefs_summary_open_key_pressed),
196                           NULL);
197         g_signal_connect (G_OBJECT(ok_btn), "clicked",
198                           G_CALLBACK(prefs_summary_open_ok),
199                           NULL);
200         g_signal_connect (G_OBJECT(cancel_btn), "clicked",
201                           G_CALLBACK(prefs_summary_open_cancel),
202                           NULL);
203
204         vbox1 = gtk_vbox_new (FALSE, VSPACING);
205         gtk_widget_show (vbox1);
206         gtk_box_pack_start (GTK_BOX (vbox), vbox1, TRUE, TRUE, 0);
207         gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
208
209         hbox1 = gtk_hbox_new (FALSE, 8);
210         gtk_widget_show (hbox1);
211         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, TRUE, 0);
212
213         /* display headers list */
214
215         list_view_hbox = gtk_hbox_new (FALSE, 10);
216         gtk_widget_show (list_view_hbox);
217         gtk_box_pack_start (GTK_BOX (vbox1), list_view_hbox, TRUE, TRUE, 0);
218
219         list_view_hbox1 = gtk_hbox_new (FALSE, 8);
220         gtk_widget_show (list_view_hbox1);
221         gtk_box_pack_start (GTK_BOX (list_view_hbox), list_view_hbox1, TRUE, TRUE, 0);
222
223         list_view_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
224         gtk_widget_show (list_view_scrolledwin);
225         gtk_box_pack_start (GTK_BOX (list_view_hbox1), list_view_scrolledwin,
226                             TRUE, TRUE, 0);
227         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (list_view_scrolledwin),
228                                         GTK_POLICY_AUTOMATIC,
229                                         GTK_POLICY_AUTOMATIC);
230         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(list_view_scrolledwin),
231                                             GTK_SHADOW_IN);
232
233         possible_actions_list_view = prefs_summary_open_list_view_create
234                                 (_("Available selections"));
235         gtk_widget_show (possible_actions_list_view);
236         gtk_container_add(GTK_CONTAINER(list_view_scrolledwin), possible_actions_list_view);
237
238         btn_vbox = gtk_vbox_new (FALSE, 8);
239         gtk_widget_show (btn_vbox);
240         gtk_box_pack_start (GTK_BOX (list_view_hbox1), btn_vbox, FALSE, FALSE, 0);
241
242         reg_btn = gtk_button_new_from_stock (GTK_STOCK_ADD);
243         gtk_widget_show (reg_btn);
244         gtk_box_pack_start (GTK_BOX (btn_vbox), reg_btn, FALSE, TRUE, 0);
245         g_signal_connect (G_OBJECT (reg_btn), "clicked",
246                           G_CALLBACK (prefs_summary_open_register_cb),
247                           possible_actions_list_view);
248         del_btn = gtk_button_new_from_stock (GTK_STOCK_REMOVE);
249         gtk_widget_show (del_btn);
250         gtk_box_pack_start (GTK_BOX (btn_vbox), del_btn, FALSE, TRUE, 0);
251
252         /* actions list */
253
254         list_view_hbox2 = gtk_hbox_new (FALSE, 8);
255         gtk_widget_show (list_view_hbox2);
256         gtk_box_pack_start (GTK_BOX (list_view_hbox), list_view_hbox2, TRUE, TRUE, 0);
257
258         list_view_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
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                                         (_("Current selections"));
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         gtk_widget_show_all(window);
303
304         summaryopen.window        = window;
305         summaryopen.ok_btn        = ok_btn;
306         summaryopen.cancel_btn    = cancel_btn;
307
308         summaryopen.possible_actions_list_view        = possible_actions_list_view;
309         summaryopen.actions_list_view = actions_list_view;
310 }
311
312 /* do it SUMMARY_OPEN_ACTIONS-1 times */
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         prefs_common.summary_select_prio[6] = ACTION_UNSET;             \
321         prefs_common.summary_select_prio[7] = ACTION_UNSET;             \
322         prefs_common.summary_select_prio[8] = ACTION_UNSET;             \
323         prefs_common.summary_select_prio[9] = ACTION_UNSET;             \
324 }
325
326 void prefs_summary_open_set_defaults(void)
327 {
328         switch (prefs_common.select_on_entry) {
329                 case SELECTONENTRY_MNU:
330                         SET_PRIO(ACTION_OLDEST_MARKED, ACTION_OLDEST_NEW, ACTION_OLDEST_UNREAD, ACTION_NEWEST_LIST); break;
331                 case SELECTONENTRY_MUN:
332                         SET_PRIO(ACTION_OLDEST_MARKED, ACTION_OLDEST_UNREAD, ACTION_OLDEST_NEW, ACTION_NEWEST_LIST); break;
333                 case SELECTONENTRY_NMU:
334                         SET_PRIO(ACTION_OLDEST_NEW, ACTION_OLDEST_MARKED, ACTION_OLDEST_UNREAD, ACTION_NEWEST_LIST); break;
335                 case SELECTONENTRY_NUM:
336                         SET_PRIO(ACTION_OLDEST_NEW, ACTION_OLDEST_UNREAD, ACTION_OLDEST_MARKED, ACTION_NEWEST_LIST); break;
337                 case SELECTONENTRY_UNM:
338                         SET_PRIO(ACTION_OLDEST_UNREAD, ACTION_OLDEST_NEW, ACTION_OLDEST_MARKED, ACTION_NEWEST_LIST); break;
339                 case SELECTONENTRY_UMN:
340                         SET_PRIO(ACTION_OLDEST_UNREAD, ACTION_OLDEST_MARKED, ACTION_OLDEST_NEW, ACTION_NEWEST_LIST); break;
341                 case SELECTONENTRY_LAST:
342                         SET_PRIO(ACTION_LAST_OPENED, ACTION_NEWEST_LIST, ACTION_UNSET, ACTION_UNSET); break;
343                 case SELECTONENTRY_NOTHING:
344                         SET_PRIO(ACTION_NEWEST_LIST, ACTION_UNSET, ACTION_UNSET, ACTION_UNSET); break;
345                 default:
346                         break;
347         }
348 }
349 static void prefs_summary_open_set_dialog(void)
350 {
351         GtkTreeView *possible_list_view = GTK_TREE_VIEW(summaryopen.possible_actions_list_view);
352         GtkTreeView *actions_list_view = GTK_TREE_VIEW(summaryopen.actions_list_view);
353         GtkTreeModel *model_poss, *model_act;
354         int i;
355         gboolean set = FALSE;
356         gboolean used[SUMMARY_OPEN_ACTIONS-1] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE};
357
358         model_poss = gtk_tree_view_get_model(possible_list_view);
359         model_act = gtk_tree_view_get_model(actions_list_view);
360
361         gtk_list_store_clear(GTK_LIST_STORE(model_poss));
362         gtk_list_store_clear(GTK_LIST_STORE(model_act));
363
364 fill:
365         for (i = 0; i < SUMMARY_OPEN_ACTIONS-1; i++) {
366                 EntryAction act = prefs_common.summary_select_prio[i];
367
368                 if (act == ACTION_UNSET) 
369                         continue;
370                 
371                 set = TRUE;
372                 used[act-1] = TRUE;
373                 prefs_summary_open_insert_action(GTK_LIST_STORE
374                                         (model_act), action_name[act], act);    
375         }
376         if (!set) {
377                 /* backward compat */
378                 prefs_summary_open_set_defaults();
379                 goto fill;
380         }
381
382         for (i = 1; i < SUMMARY_OPEN_ACTIONS; i++) {
383                 if (!used[i-1]) {
384                         prefs_summary_open_insert_action(GTK_LIST_STORE
385                                         (model_poss), action_name[i], i);       
386                 }
387         }
388 }
389
390 static void prefs_summary_open_set_list(void)
391 {
392         gint row = 0;
393         gpointer data;
394         GtkTreeModel *model;
395         GtkTreeIter iter;
396
397         model = gtk_tree_view_get_model(GTK_TREE_VIEW(summaryopen.actions_list_view));
398         while (gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
399                 gtk_tree_model_get(model, &iter, PREFS_SUMMARY_OPEN_DATA, &data, -1);
400                 prefs_common.summary_select_prio[row] = GPOINTER_TO_INT(data);
401                 row++;                          
402         }
403         for (; row < SUMMARY_OPEN_ACTIONS-1; row++) {
404                 prefs_common.summary_select_prio[row] = ACTION_UNSET;
405         }
406 }
407
408 static void prefs_summary_open_delete_cb(GtkButton *btn, gpointer list_view_data)
409 {
410         GtkTreeView *list_view = GTK_TREE_VIEW(list_view_data);
411         gpointer data;
412         GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(list_view));
413         GtkTreeSelection *selection = gtk_tree_view_get_selection(list_view);
414         GtkTreeIter iter;
415         GtkTreeView *possible_list_view = GTK_TREE_VIEW(summaryopen.possible_actions_list_view);
416         GtkTreeModel *model, *model_poss;
417         gint i;
418
419         model = gtk_tree_view_get_model(list_view);
420         model_poss = gtk_tree_view_get_model(possible_list_view);
421
422         if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
423                 return;
424
425         gtk_tree_model_get(model, &iter, PREFS_SUMMARY_OPEN_DATA, &data, -1);
426         if (!data) 
427                 return;
428
429         gtk_list_store_remove(store, &iter);
430
431         i = GPOINTER_TO_INT(data);
432         prefs_summary_open_insert_action(GTK_LIST_STORE
433                                         (model_poss), action_name[i], i);       
434         
435         prefs_summary_open_set_list();
436 }
437
438 static void prefs_summary_open_register_cb(GtkButton *btn, gpointer list_view_data)
439 {
440         GtkTreeView *possible_list_view = GTK_TREE_VIEW(list_view_data);
441         GtkTreeView *list_view = GTK_TREE_VIEW(summaryopen.actions_list_view);
442         gpointer data;
443         GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(possible_list_view));
444         GtkTreeSelection *selection = gtk_tree_view_get_selection(possible_list_view);
445         GtkTreeIter iter;
446         GtkTreeModel *model, *model_poss;
447         gint i;
448
449         model = gtk_tree_view_get_model(list_view);
450         model_poss = gtk_tree_view_get_model(possible_list_view);
451
452         if (!gtk_tree_selection_get_selected(selection, NULL, &iter))
453                 return;
454
455         gtk_tree_model_get(model_poss, &iter, PREFS_SUMMARY_OPEN_DATA, &data, -1);
456         if (!data) 
457                 return;
458
459         gtk_list_store_remove(store, &iter);
460
461         i = GPOINTER_TO_INT(data);
462         prefs_summary_open_insert_action(GTK_LIST_STORE
463                                         (model), action_name[i], i);    
464         
465         prefs_summary_open_set_list();
466 }
467
468 static void prefs_summary_open_up(void)
469 {
470         GtkTreePath *prev, *sel, *try;
471         GtkTreeIter isel;
472         GtkListStore *store = NULL;
473         GtkTreeModel *model = NULL;
474         GtkTreeIter iprev;
475         
476         if (!gtk_tree_selection_get_selected
477                 (gtk_tree_view_get_selection
478                         (GTK_TREE_VIEW(summaryopen.actions_list_view)),
479                  &model,        
480                  &isel))
481                 return;
482         store = (GtkListStore *)model;
483         sel = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &isel);
484         if (!sel)
485                 return;
486         
487         /* no move if we're at row 0... */
488         try = gtk_tree_path_copy(sel);
489         if (!gtk_tree_path_prev(try)) {
490                 gtk_tree_path_free(try);
491                 gtk_tree_path_free(sel);
492                 return;
493         }
494
495         prev = try;
496         gtk_tree_model_get_iter(GTK_TREE_MODEL(store),
497                                 &iprev, prev);
498         gtk_list_store_swap(store, &iprev, &isel);
499
500         gtk_tree_path_free(sel);
501         gtk_tree_path_free(prev);
502         prefs_summary_open_set_list();
503 }
504
505 static void prefs_summary_open_down(void)
506 {
507         GtkListStore *store = NULL;
508         GtkTreeModel *model = NULL;
509         GtkTreeIter next, sel;
510         GtkTreePath *try;
511         
512         if (!gtk_tree_selection_get_selected
513                 (gtk_tree_view_get_selection
514                         (GTK_TREE_VIEW(summaryopen.actions_list_view)),
515                  &model,
516                  &sel))
517                 return;
518         store = (GtkListStore *)model;
519         try = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &sel);
520         if (!try) 
521                 return;
522         
523         next = sel;
524         if (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &next))
525                 gtk_list_store_swap(store, &next, &sel);
526                 
527         gtk_tree_path_free(try);
528         prefs_summary_open_set_list();
529 }
530
531 static gboolean prefs_summary_open_key_pressed(GtkWidget *widget,
532                                              GdkEventKey *event,
533                                              gpointer data)
534 {
535         if (event && event->keyval == GDK_KEY_Escape)
536                 prefs_summary_open_cancel();
537         return FALSE;
538 }
539
540 static void prefs_summary_open_ok(void)
541 {
542         int i;
543
544         /* force an empty list to be at least ACTION_NONE */
545         if (prefs_common.summary_select_prio[0] == ACTION_UNSET)
546                 prefs_common.summary_select_prio[0] = ACTION_NOTHING;
547
548         for (i = 0; i < SUMMARY_OPEN_ACTIONS-1; i++)
549                 saved_summary_select_prio[i] = prefs_common.summary_select_prio[i];
550
551         gtk_widget_hide(summaryopen.window);
552         gtk_window_set_modal(GTK_WINDOW(summaryopen.window), FALSE);
553 }
554
555 static void prefs_summary_open_cancel(void)
556 {
557         int i;
558         for (i = 0; i < SUMMARY_OPEN_ACTIONS-1; i++)
559                 prefs_common.summary_select_prio[i] = saved_summary_select_prio[i];
560
561         gtk_widget_hide(summaryopen.window);
562 }
563
564 static gint prefs_summary_open_deleted(GtkWidget *widget, GdkEventAny *event,
565                                          gpointer data)
566 {
567         prefs_summary_open_cancel();
568         return TRUE;
569 }
570
571 static GtkListStore *prefs_summary_open_create_store(void)
572 {
573         return gtk_list_store_new(N_PREFS_SUMMARY_OPEN_COLUMNS,
574                                   G_TYPE_STRING,
575                                   G_TYPE_POINTER,
576                                   -1);
577 }
578
579 static void prefs_summary_open_insert_action(GtkListStore *store,
580                                                gchar *name,
581                                                gint dp)
582 {
583         GtkTreeIter iter;
584
585         /* add new */
586         gtk_list_store_append(store, &iter);
587         gtk_list_store_set(store, &iter,
588                            PREFS_SUMMARY_OPEN_HEADER,
589                            gettext(name),
590                            PREFS_SUMMARY_OPEN_DATA, GINT_TO_POINTER(dp),
591                            -1);
592 }
593
594 static GtkWidget *prefs_summary_open_list_view_create(const gchar *name)
595 {
596         GtkWidget *list_view;
597         GtkTreeSelection *selector;
598         GtkTreeModel *model;
599
600         model = GTK_TREE_MODEL(prefs_summary_open_create_store());
601         list_view = gtk_tree_view_new_with_model(model);
602         g_object_unref(G_OBJECT(model));
603         
604         gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(list_view),
605                                      prefs_common.use_stripes_everywhere);
606         
607         selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
608         gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
609
610         prefs_summary_open_create_list_view_columns(GTK_WIDGET(list_view), name);
611
612         return list_view;
613 }
614
615 static void prefs_summary_open_create_list_view_columns(GtkWidget *list_view, 
616                                                      const gchar *name)
617 {
618         GtkTreeViewColumn *column;
619         GtkCellRenderer *renderer;
620
621         renderer = gtk_cell_renderer_text_new();
622         column = gtk_tree_view_column_new_with_attributes
623                 (name, renderer, "text", PREFS_SUMMARY_OPEN_HEADER, NULL);
624         gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);          
625 }
626
627 /*!
628  *\brief        Called as a result of a drag & drop
629  */
630 static void actions_list_model_row_changed(GtkTreeModel *model, 
631                                            GtkTreePath *path, 
632                                            GtkTreeIter *iter, 
633                                            GtkTreeView *list_view)
634 {
635 }
636
637 /*!
638  *\brief        Called as a result of a gtk_list_store_swap()
639  */
640 static void drag_begin(GtkTreeView *list_view,
641                       GdkDragContext *context,
642                       gpointer data)
643 {
644         /* XXX unfortunately a completed drag & drop does not emit 
645          * a "rows_reordered" signal, but a "row_changed" signal.
646          * So during drag and drop, listen to "row_changed", and
647          * update the account list accordingly */
648
649         GtkTreeModel *model = gtk_tree_view_get_model(list_view);
650         g_signal_connect(G_OBJECT(model), "row_changed",
651                          G_CALLBACK(actions_list_model_row_changed),
652                          list_view);
653 }
654
655 static void drag_end(GtkTreeView *list_view,
656                     GdkDragContext *context,
657                     gpointer data)
658 {
659         GtkTreeModel *model = gtk_tree_view_get_model(list_view);
660         g_signal_handlers_disconnect_by_func(G_OBJECT(model),
661                                              G_CALLBACK(actions_list_model_row_changed),
662                                              list_view);
663         prefs_summary_open_set_list();
664 }
665