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