2007-11-28 [wwp] 3.1.0cvs43
[claws.git] / src / prefs_summary_open.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2007 Hiroyuki Yamamoto and the Claws Mail team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <glib.h>
27 #include <glib/gi18n.h>
28 #include <gtk/gtk.h>
29 #include <gdk/gdkkeysyms.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <errno.h>
34
35 #include "prefs_gtk.h"
36 #include "prefs_summary_open.h"
37 #include "prefs_common.h"
38 #include "manage_window.h"
39 #include "alertpanel.h"
40 #include "displayheader.h"
41 #include "utils.h"
42 #include "gtkutils.h"
43
44 enum {
45         PREFS_SUMMARY_OPEN_HEADER,
46         PREFS_SUMMARY_OPEN_DATA,
47         N_PREFS_SUMMARY_OPEN_COLUMNS
48 };
49
50 static struct SummaryOpen {
51         GtkWidget *window;
52
53         GtkWidget *ok_btn;
54         GtkWidget *cancel_btn;
55
56         GtkWidget *possible_actions_list_view;
57         GtkWidget *actions_list_view;
58 } summaryopen;
59
60 /* widget creating functions */
61 static void prefs_summary_open_create   (void);
62
63 static void prefs_summary_open_set_dialog       (void);
64 static void prefs_summary_open_set_list (void);
65
66 /* callback functions */
67 static void prefs_summary_open_register_cb      (GtkButton      *btn,
68                                                  gpointer        hidden_data);
69 static void prefs_summary_open_delete_cb        (GtkButton      *btn,
70                                                  gpointer        list_view_data);
71 static void prefs_summary_open_up               (void);
72 static void prefs_summary_open_down             (void);
73
74 static gboolean prefs_summary_open_key_pressed  (GtkWidget      *widget,
75                                                          GdkEventKey    *event,
76                                                          gpointer        data);
77 static void prefs_summary_open_ok               (void);
78 static void prefs_summary_open_cancel           (void);
79 static gint prefs_summary_open_deleted  (GtkWidget      *widget,
80                                                  GdkEventAny    *event,
81                                                  gpointer        data);
82
83
84 static GtkListStore *prefs_summary_open_create_store    (void);
85 static void prefs_summary_open_insert_action            (GtkListStore *store,
86                                                          gchar *name,
87                                                          gint act);
88 static GtkWidget *prefs_summary_open_list_view_create   (const gchar *name);
89 static void prefs_summary_open_create_list_view_columns (GtkWidget *list_view, 
90                                                          const gchar *name);
91 static void actions_list_model_row_changed              (GtkTreeModel *model, 
92                                                          GtkTreePath *path, 
93                                                          GtkTreeIter *iter, 
94                                                          GtkTreeView *list_view);
95                                                          
96 static void drag_begin  (GtkTreeView *list_view,
97                          GdkDragContext *context,
98                          gpointer data);
99
100 static void drag_end    (GtkTreeView *list_view,
101                          GdkDragContext *context,
102                          gpointer data);
103
104 static EntryAction saved_summary_select_prio[SUMMARY_OPEN_ACTIONS-1];
105
106 static gchar *action_name[SUMMARY_OPEN_ACTIONS] = 
107 {         ("UNSET (!)"),
108          N_("first marked email"),
109          N_("first new email"),
110          N_("first unread email"),
111          N_("last opened email"),
112          N_("last email in the list"),
113          N_("none"),
114          N_("first email in the list")
115 };
116
117 void prefs_summary_open_open(void)
118 {
119         int i;
120         if (!summaryopen.window) {
121                 prefs_summary_open_create();
122         }
123
124         manage_window_set_transient(GTK_WINDOW(summaryopen.window));
125         gtk_widget_grab_focus(summaryopen.ok_btn);
126
127         prefs_summary_open_set_dialog();
128         
129         for (i = 0; i < SUMMARY_OPEN_ACTIONS-1; i++)
130                 saved_summary_select_prio[i] = prefs_common.summary_select_prio[i];
131
132         gtk_widget_show(summaryopen.window);
133 }
134
135 static void prefs_summary_open_create(void)
136 {
137         GtkWidget *window;
138         GtkWidget *vbox;
139         GtkWidget *btn_hbox;
140         GtkWidget *ok_btn;
141         GtkWidget *cancel_btn;
142         GtkWidget *confirm_area;
143
144         GtkWidget *vbox1;
145
146         GtkWidget *hbox1;
147
148         GtkWidget *btn_vbox;
149         GtkWidget *reg_btn;
150         GtkWidget *del_btn;
151         GtkWidget *up_btn;
152         GtkWidget *down_btn;
153
154         GtkWidget *list_view_hbox;
155         GtkWidget *list_view_hbox1;
156         GtkWidget *list_view_hbox2;
157         GtkWidget *list_view_scrolledwin;
158         GtkWidget *possible_actions_list_view;
159         GtkWidget *actions_list_view;
160         
161         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "prefs_summary_open");
162         gtk_container_set_border_width (GTK_CONTAINER (window), 8);
163         gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
164         gtk_window_set_modal (GTK_WINDOW (window), TRUE);
165         gtk_window_set_resizable(GTK_WINDOW (window), TRUE);
166
167         vbox = gtk_vbox_new (FALSE, 6);
168         gtk_widget_show (vbox);
169         gtk_container_add (GTK_CONTAINER (window), vbox);
170
171         btn_hbox = gtk_hbox_new (FALSE, 8);
172         gtk_widget_show (btn_hbox);
173         gtk_box_pack_end (GTK_BOX (vbox), btn_hbox, FALSE, FALSE, 0);
174
175         gtkut_stock_button_set_create(&confirm_area, &cancel_btn, GTK_STOCK_CANCEL,
176                                       &ok_btn, GTK_STOCK_OK,
177                                       NULL, NULL);
178         gtk_widget_show (confirm_area);
179         gtk_box_pack_end (GTK_BOX(btn_hbox), confirm_area, FALSE, FALSE, 0);
180         gtk_widget_grab_default (ok_btn);
181
182         gtk_window_set_title (GTK_WINDOW(window),
183                               _(" Selection when entering a folder"));
184         MANAGE_WINDOW_SIGNALS_CONNECT(window);
185         g_signal_connect (G_OBJECT(window), "delete_event",
186                           G_CALLBACK(prefs_summary_open_deleted),
187                           NULL);
188         g_signal_connect (G_OBJECT(window), "key_press_event",
189                           G_CALLBACK(prefs_summary_open_key_pressed),
190                           NULL);
191         g_signal_connect (G_OBJECT(ok_btn), "clicked",
192                           G_CALLBACK(prefs_summary_open_ok),
193                           NULL);
194         g_signal_connect (G_OBJECT(cancel_btn), "clicked",
195                           G_CALLBACK(prefs_summary_open_cancel),
196                           NULL);
197
198         vbox1 = gtk_vbox_new (FALSE, VSPACING);
199         gtk_widget_show (vbox1);
200         gtk_box_pack_start (GTK_BOX (vbox), vbox1, TRUE, TRUE, 0);
201         gtk_container_set_border_width (GTK_CONTAINER (vbox1), 2);
202
203         hbox1 = gtk_hbox_new (FALSE, 8);
204         gtk_widget_show (hbox1);
205         gtk_box_pack_start (GTK_BOX (vbox1), hbox1, FALSE, TRUE, 0);
206
207         /* display headers list */
208
209         list_view_hbox = gtk_hbox_new (FALSE, 10);
210         gtk_widget_show (list_view_hbox);
211         gtk_box_pack_start (GTK_BOX (vbox1), list_view_hbox, TRUE, TRUE, 0);
212
213         list_view_hbox1 = gtk_hbox_new (FALSE, 8);
214         gtk_widget_show (list_view_hbox1);
215         gtk_box_pack_start (GTK_BOX (list_view_hbox), list_view_hbox1, TRUE, TRUE, 0);
216
217         list_view_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
218         gtk_widget_set_size_request (list_view_scrolledwin, 200, 210);
219         gtk_widget_show (list_view_scrolledwin);
220         gtk_box_pack_start (GTK_BOX (list_view_hbox1), list_view_scrolledwin,
221                             TRUE, TRUE, 0);
222         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (list_view_scrolledwin),
223                                         GTK_POLICY_AUTOMATIC,
224                                         GTK_POLICY_AUTOMATIC);
225         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(list_view_scrolledwin),
226                                             GTK_SHADOW_IN);
227
228         possible_actions_list_view = prefs_summary_open_list_view_create
229                                 (_("Possible selections"));
230         gtk_widget_show (possible_actions_list_view);
231         gtk_container_add(GTK_CONTAINER(list_view_scrolledwin), possible_actions_list_view);
232
233         btn_vbox = gtk_vbox_new (FALSE, 8);
234         gtk_widget_show (btn_vbox);
235         gtk_box_pack_start (GTK_BOX (list_view_hbox1), btn_vbox, FALSE, FALSE, 0);
236
237         reg_btn = gtk_button_new_from_stock (GTK_STOCK_ADD);
238         gtk_widget_show (reg_btn);
239         gtk_box_pack_start (GTK_BOX (btn_vbox), reg_btn, FALSE, TRUE, 0);
240         g_signal_connect (G_OBJECT (reg_btn), "clicked",
241                           G_CALLBACK (prefs_summary_open_register_cb),
242                           possible_actions_list_view);
243         del_btn = gtk_button_new_from_stock (GTK_STOCK_REMOVE);
244         gtk_widget_show (del_btn);
245         gtk_box_pack_start (GTK_BOX (btn_vbox), del_btn, FALSE, TRUE, 0);
246
247         /* actions list */
248
249         list_view_hbox2 = gtk_hbox_new (FALSE, 8);
250         gtk_widget_show (list_view_hbox2);
251         gtk_box_pack_start (GTK_BOX (list_view_hbox), list_view_hbox2, TRUE, TRUE, 0);
252
253         list_view_scrolledwin = gtk_scrolled_window_new (NULL, NULL);
254         gtk_widget_set_size_request (list_view_scrolledwin, 200, 230);
255         gtk_widget_show (list_view_scrolledwin);
256         gtk_box_pack_start (GTK_BOX (list_view_hbox2), list_view_scrolledwin,
257                             TRUE, TRUE, 0);
258         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (list_view_scrolledwin),
259                                         GTK_POLICY_AUTOMATIC,
260                                         GTK_POLICY_AUTOMATIC);
261         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(list_view_scrolledwin),
262                                             GTK_SHADOW_IN);
263
264         actions_list_view = prefs_summary_open_list_view_create
265                                         (_("Selection on folder opening"));
266         g_signal_connect (G_OBJECT (del_btn), "clicked",
267                           G_CALLBACK (prefs_summary_open_delete_cb),
268                           actions_list_view);
269         gtk_widget_show (actions_list_view);
270         gtk_container_add (GTK_CONTAINER (list_view_scrolledwin),
271                            actions_list_view);
272
273         gtk_tree_view_set_reorderable(GTK_TREE_VIEW(actions_list_view), TRUE);
274         g_signal_connect(G_OBJECT(actions_list_view), "drag_begin",                      
275                          G_CALLBACK(drag_begin),
276                          actions_list_view);
277                          
278         g_signal_connect(G_OBJECT(actions_list_view), "drag_end",                        
279                          G_CALLBACK(drag_end),
280                          actions_list_view);
281         
282         btn_vbox = gtk_vbox_new (FALSE, 8);
283         gtk_widget_show (btn_vbox);
284         gtk_box_pack_start (GTK_BOX (list_view_hbox2), btn_vbox, FALSE, FALSE, 0);
285
286         up_btn = gtk_button_new_from_stock (GTK_STOCK_GO_UP);
287         gtk_widget_show (up_btn);
288         gtk_box_pack_start (GTK_BOX (btn_vbox), up_btn, FALSE, FALSE, 0);
289         g_signal_connect (G_OBJECT (up_btn), "clicked",
290                           G_CALLBACK (prefs_summary_open_up), NULL);
291
292         down_btn = gtk_button_new_from_stock (GTK_STOCK_GO_DOWN);
293         gtk_widget_show (down_btn);
294         gtk_box_pack_start (GTK_BOX (btn_vbox), down_btn, FALSE, FALSE, 0);
295         g_signal_connect (G_OBJECT (down_btn), "clicked",
296                           G_CALLBACK (prefs_summary_open_down), NULL);
297         
298
299         gtk_widget_show_all(window);
300
301         summaryopen.window        = window;
302         summaryopen.ok_btn        = ok_btn;
303         summaryopen.cancel_btn    = cancel_btn;
304
305         summaryopen.possible_actions_list_view        = possible_actions_list_view;
306         summaryopen.actions_list_view = actions_list_view;
307 }
308
309 /* do it SUMMARY_OPEN_ACTIONS-1 times */
310 #define SET_PRIO(p_one,p_two,p_three,p_four) {                          \
311         prefs_common.summary_select_prio[0] = p_one;                    \
312         prefs_common.summary_select_prio[1] = p_two;                    \
313         prefs_common.summary_select_prio[2] = p_three;                  \
314         prefs_common.summary_select_prio[3] = p_four;                   \
315         prefs_common.summary_select_prio[4] = ACTION_UNSET;             \
316         prefs_common.summary_select_prio[5] = ACTION_UNSET;             \
317         prefs_common.summary_select_prio[6] = ACTION_UNSET;             \
318 }                                                       
319
320 void prefs_summary_open_set_defaults(void)
321 {
322         switch (prefs_common.select_on_entry) {
323                 case SELECTONENTRY_MNU:
324                         SET_PRIO(ACTION_MARKED, ACTION_NEW, ACTION_UNREAD, ACTION_LAST_LIST); break;
325                 case SELECTONENTRY_MUN:
326                         SET_PRIO(ACTION_MARKED, ACTION_UNREAD, ACTION_NEW, ACTION_LAST_LIST); break;
327                 case SELECTONENTRY_NMU:
328                         SET_PRIO(ACTION_NEW, ACTION_MARKED, ACTION_UNREAD, ACTION_LAST_LIST); break;
329                 case SELECTONENTRY_NUM:
330                         SET_PRIO(ACTION_NEW, ACTION_UNREAD, ACTION_MARKED, ACTION_LAST_LIST); break;
331                 case SELECTONENTRY_UNM:
332                         SET_PRIO(ACTION_UNREAD, ACTION_NEW, ACTION_MARKED, ACTION_LAST_LIST); break;
333                 case SELECTONENTRY_UMN:
334                         SET_PRIO(ACTION_UNREAD, ACTION_MARKED, ACTION_NEW, ACTION_LAST_LIST); break;
335                 case SELECTONENTRY_LAST:
336                         SET_PRIO(ACTION_LAST_OPENED, ACTION_LAST_LIST, ACTION_UNSET, ACTION_UNSET); break;
337                 case SELECTONENTRY_NOTHING:
338                         SET_PRIO(ACTION_LAST_LIST, ACTION_UNSET, ACTION_UNSET, ACTION_UNSET); break;
339                 default:
340                         break;
341         }
342 }
343 static void prefs_summary_open_set_dialog(void)
344 {
345         GtkTreeView *possible_list_view = GTK_TREE_VIEW(summaryopen.possible_actions_list_view);
346         GtkTreeView *actions_list_view = GTK_TREE_VIEW(summaryopen.actions_list_view);
347         GtkTreeModel *model_poss, *model_act;
348         int i;
349         gboolean set = FALSE;
350         gboolean used[SUMMARY_OPEN_ACTIONS-1] = {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE};
351
352         model_poss = gtk_tree_view_get_model(possible_list_view);
353         model_act = gtk_tree_view_get_model(actions_list_view);
354
355         gtk_list_store_clear(GTK_LIST_STORE(model_poss));
356         gtk_list_store_clear(GTK_LIST_STORE(model_act));
357
358 fill:
359         for (i = 0; i < SUMMARY_OPEN_ACTIONS-1; i++) {
360                 EntryAction act = prefs_common.summary_select_prio[i];
361
362                 if (act == ACTION_UNSET) 
363                         continue;
364                 
365                 set = TRUE;
366                 used[act-1] = TRUE;
367                 prefs_summary_open_insert_action(GTK_LIST_STORE
368                                         (model_act), action_name[act], act);    
369         }
370         if (!set) {
371                 /* backward compat */
372                 prefs_summary_open_set_defaults();
373                 goto fill;
374         }
375
376         for (i = 1; i < SUMMARY_OPEN_ACTIONS; i++) {
377                 if (!used[i-1]) {
378                         prefs_summary_open_insert_action(GTK_LIST_STORE
379                                         (model_poss), action_name[i], i);       
380                 }
381         }
382 }
383
384 static void prefs_summary_open_set_list(void)
385 {
386         gint row = 0;
387         gpointer data;
388         GtkTreeModel *model;
389         GtkTreeIter iter;
390
391         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_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 }
547
548 static void prefs_summary_open_cancel(void)
549 {
550         int i;
551         for (i = 0; i < SUMMARY_OPEN_ACTIONS-1; i++)
552                 prefs_common.summary_select_prio[i] = saved_summary_select_prio[i];
553
554         gtk_widget_hide(summaryopen.window);
555 }
556
557 static gint prefs_summary_open_deleted(GtkWidget *widget, GdkEventAny *event,
558                                          gpointer data)
559 {
560         prefs_summary_open_cancel();
561         return TRUE;
562 }
563
564 static GtkListStore *prefs_summary_open_create_store(void)
565 {
566         return gtk_list_store_new(N_PREFS_SUMMARY_OPEN_COLUMNS,
567                                   G_TYPE_STRING,
568                                   G_TYPE_POINTER,
569                                   -1);
570 }
571
572 static void prefs_summary_open_insert_action(GtkListStore *store,
573                                                gchar *name,
574                                                gint dp)
575 {
576         GtkTreeIter iter;
577
578         /* add new */
579         gtk_list_store_append(store, &iter);
580         gtk_list_store_set(store, &iter,
581                            PREFS_SUMMARY_OPEN_HEADER,
582                            gettext(name),
583                            PREFS_SUMMARY_OPEN_DATA, GINT_TO_POINTER(dp),
584                            -1);
585 }
586
587 static GtkWidget *prefs_summary_open_list_view_create(const gchar *name)
588 {
589         GtkWidget *list_view;
590         GtkTreeSelection *selector;
591         GtkTreeModel *model;
592
593         model = GTK_TREE_MODEL(prefs_summary_open_create_store());
594         list_view = gtk_tree_view_new_with_model(model);
595         g_object_unref(G_OBJECT(model));
596         
597         gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(list_view),
598                                      prefs_common.use_stripes_everywhere);
599         
600         selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
601         gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
602
603         prefs_summary_open_create_list_view_columns(GTK_WIDGET(list_view), name);
604
605         return list_view;
606 }
607
608 static void prefs_summary_open_create_list_view_columns(GtkWidget *list_view, 
609                                                      const gchar *name)
610 {
611         GtkTreeViewColumn *column;
612         GtkCellRenderer *renderer;
613
614         renderer = gtk_cell_renderer_text_new();
615         column = gtk_tree_view_column_new_with_attributes
616                 (name, renderer, "text", PREFS_SUMMARY_OPEN_HEADER, NULL);
617         gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);          
618 }
619
620 /*!
621  *\brief        Called as a result of a drag & drop
622  */
623 static void actions_list_model_row_changed(GtkTreeModel *model, 
624                                            GtkTreePath *path, 
625                                            GtkTreeIter *iter, 
626                                            GtkTreeView *list_view)
627 {
628 }
629
630 /*!
631  *\brief        Called as a result of a gtk_list_store_swap()
632  */
633 static void drag_begin(GtkTreeView *list_view,
634                       GdkDragContext *context,
635                       gpointer data)
636 {
637         /* XXX unfortunately a completed drag & drop does not emit 
638          * a "rows_reordered" signal, but a "row_changed" signal.
639          * So during drag and drop, listen to "row_changed", and
640          * update the account list accordingly */
641
642         GtkTreeModel *model = gtk_tree_view_get_model(list_view);
643         g_signal_connect(G_OBJECT(model), "row_changed",
644                          G_CALLBACK(actions_list_model_row_changed),
645                          list_view);
646 }
647
648 static void drag_end(GtkTreeView *list_view,
649                     GdkDragContext *context,
650                     gpointer data)
651 {
652         GtkTreeModel *model = gtk_tree_view_get_model(list_view);
653         g_signal_handlers_disconnect_by_func(G_OBJECT(model),
654                                              G_CALLBACK(actions_list_model_row_changed),
655                                              list_view);
656         prefs_summary_open_set_list();
657 }
658