2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2022 the Claws Mail team and Hiroyuki Yamamoto
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.
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.
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/>.
21 #include "claws-features.h"
27 #include <glib/gi18n.h>
29 #include <gdk/gdkkeysyms.h>
31 #include "prefs_gtk.h"
32 #include "prefs_common.h"
33 #include "prefs_summary_column.h"
34 #include "manage_window.h"
35 #include "summaryview.h"
36 #include "mainwindow.h"
41 static void prefs_summary_column_set_config(SummaryColumnState
*state
);
49 #define TARGET_INFO_SUMCOL (0xFEEDBABE)
51 static const GtkTargetEntry row_targets
[] = {
52 { "PREFS_SUM_COL_MODEL_ROW", GTK_TARGET_SAME_APP
, TARGET_INFO_SUMCOL
}
56 static struct _SummaryColumnDialog
60 GtkWidget
*stock_list_view
;
61 GtkWidget
*shown_list_view
;
64 GtkWidget
*remove_btn
;
68 GtkWidget
*default_btn
;
71 GtkWidget
*cancel_btn
;
76 static const gchar
*const col_name
[N_SUMMARY_COLS
] = {
77 N_("Mark"), /* S_COL_MARK */
78 N_("Status"), /* S_COL_STATUS */
79 N_("Attachment"), /* S_COL_MIME */
80 N_("Subject"), /* S_COL_SUBJECT */
81 N_("From"), /* S_COL_FROM */
82 N_("To"), /* S_COL_TO */
83 N_("Date"), /* S_COL_DATE */
84 N_("Size"), /* S_COL_SIZE */
85 N_("Number"), /* S_COL_NUMBER */
86 N_("Score"), /* S_COL_SCORE */
87 N_("Locked"), /* S_COL_LOCKED */
88 N_("Tags"), /* S_COL_TAGS */
91 static SummaryColumnState default_state
[N_SUMMARY_COLS
] = {
92 { S_COL_MARK
, TRUE
},
93 { S_COL_STATUS
, TRUE
},
94 { S_COL_MIME
, TRUE
},
95 { S_COL_SUBJECT
, TRUE
},
96 { S_COL_FROM
, TRUE
},
98 { S_COL_DATE
, TRUE
},
99 { S_COL_SIZE
, TRUE
},
100 { S_COL_NUMBER
, FALSE
},
101 { S_COL_SCORE
, FALSE
},
102 { S_COL_LOCKED
, FALSE
},
103 { S_COL_TAGS
, FALSE
},
106 static void prefs_summary_column_create (void);
108 static void prefs_summary_column_set_dialog (SummaryColumnState
*state
);
109 static void prefs_summary_column_set_view (void);
111 /* callback functions */
112 static void prefs_summary_column_add (void);
113 static void prefs_summary_column_remove (void);
115 static void prefs_summary_column_up (void);
116 static void prefs_summary_column_down (void);
118 static void prefs_summary_column_set_to_default (void);
120 static void prefs_summary_column_ok (void);
121 static void prefs_summary_column_cancel (void);
123 static gint
prefs_summary_column_delete_event (GtkWidget
*widget
,
126 static gboolean
prefs_summary_column_key_pressed(GtkWidget
*widget
,
130 static GtkListStore
*prefs_summary_column_create_store (void);
132 static void prefs_summary_column_insert_column (GtkListStore
*store
,
135 SummaryColumnType type
);
137 static SummaryColumnType
prefs_summary_column_get_column (GtkWidget
*list
,
140 static GtkWidget
*prefs_summary_column_list_view_create (const gchar
*name
);
142 static void prefs_filtering_create_list_view_columns (GtkWidget
*list_view
,
145 static void drag_data_get (GtkTreeView
*tree_view
,
146 GdkDragContext
*context
,
147 GtkSelectionData
*data
,
150 GtkTreeModel
*model
);
152 static void drag_data_received (GtkTreeView
*tree_view
,
153 GdkDragContext
*context
,
155 GtkSelectionData
*data
,
158 GtkTreeModel
*model
);
160 static void prefs_summary_column_shown_set_btn_sensitivity(void);
161 static void prefs_summary_column_shown_set_active(const gboolean active
);
162 static void prefs_summary_column_stock_set_active(const gboolean active
);
163 static void prefs_summary_column_shown_sel_changed(void);
164 static void prefs_summary_column_stock_sel_changed(void);
166 void prefs_summary_column_open(void)
170 if (!summary_col
.window
)
171 prefs_summary_column_create();
173 manage_window_set_transient(GTK_WINDOW(summary_col
.window
));
174 gtk_widget_grab_focus(summary_col
.ok_btn
);
176 prefs_summary_column_set_dialog(NULL
);
178 gtk_widget_show(summary_col
.window
);
179 gtk_window_set_modal(GTK_WINDOW(summary_col
.window
), TRUE
);
181 summary_col
.finished
= FALSE
;
182 while (summary_col
.finished
== FALSE
)
183 gtk_main_iteration();
185 gtk_widget_hide(summary_col
.window
);
186 gtk_window_set_modal(GTK_WINDOW(summary_col
.window
), FALSE
);
190 static void prefs_summary_column_create(void)
195 GtkWidget
*label_hbox
;
201 GtkWidget
*clist_hbox
;
202 GtkWidget
*scrolledwin
;
203 GtkWidget
*stock_list_view
;
204 GtkWidget
*shown_list_view
;
208 GtkWidget
*remove_btn
;
213 GtkWidget
*default_btn
;
214 GtkWidget
*confirm_area
;
216 GtkWidget
*cancel_btn
;
218 debug_print("Creating summary column setting window...\n");
220 window
= gtkut_window_new(GTK_WINDOW_TOPLEVEL
, "prefs_summary_column");
221 gtk_container_set_border_width(GTK_CONTAINER(window
), 8);
222 gtk_window_set_position(GTK_WINDOW(window
), GTK_WIN_POS_CENTER
);
223 gtk_window_set_resizable(GTK_WINDOW(window
), FALSE
);
224 gtk_window_set_type_hint(GTK_WINDOW(window
), GDK_WINDOW_TYPE_HINT_DIALOG
);
225 gtk_window_set_title(GTK_WINDOW(window
),
226 _("Message list columns configuration"));
227 g_signal_connect(G_OBJECT(window
), "delete_event",
228 G_CALLBACK(prefs_summary_column_delete_event
),
230 g_signal_connect(G_OBJECT(window
), "key_press_event",
231 G_CALLBACK(prefs_summary_column_key_pressed
),
234 vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 6);
235 gtk_widget_show(vbox
);
236 gtk_container_add(GTK_CONTAINER(window
), vbox
);
238 label_hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 0);
239 gtk_widget_show(label_hbox
);
240 gtk_box_pack_start(GTK_BOX(vbox
), label_hbox
, FALSE
, FALSE
, 4);
242 label
= gtk_label_new
243 (_("Select columns to be displayed in the message list. You can modify\n"
244 "the order by using the Up / Down buttons or by dragging the items."));
245 gtk_widget_show(label
);
246 gtk_box_pack_start(GTK_BOX(label_hbox
), label
, FALSE
, FALSE
, 4);
247 gtk_label_set_justify(GTK_LABEL(label
), GTK_JUSTIFY_LEFT
);
249 vbox1
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, VSPACING
);
250 gtk_widget_show(vbox1
);
251 gtk_box_pack_start(GTK_BOX(vbox
), vbox1
, TRUE
, TRUE
, 0);
252 gtk_container_set_border_width(GTK_CONTAINER(vbox1
), 2);
254 hbox1
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
255 gtk_widget_show(hbox1
);
256 gtk_box_pack_start(GTK_BOX(vbox1
), hbox1
, FALSE
, TRUE
, 0);
258 clist_hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
259 gtk_widget_show(clist_hbox
);
260 gtk_box_pack_start(GTK_BOX(hbox1
), clist_hbox
, TRUE
, TRUE
, 0);
262 scrolledwin
= gtk_scrolled_window_new(NULL
, NULL
);
263 gtk_widget_set_size_request(scrolledwin
, 180, 210);
264 gtk_widget_show(scrolledwin
);
265 gtk_box_pack_start(GTK_BOX(clist_hbox
), scrolledwin
, TRUE
, TRUE
, 0);
266 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin
),
267 GTK_POLICY_AUTOMATIC
,
268 GTK_POLICY_AUTOMATIC
);
269 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin
),
272 stock_list_view
= prefs_summary_column_list_view_create
273 (_("Hidden columns"));
274 g_signal_connect(G_OBJECT(stock_list_view
), "cursor-changed",
275 G_CALLBACK(prefs_summary_column_stock_sel_changed
),
277 gtk_widget_show(stock_list_view
);
278 gtk_container_add(GTK_CONTAINER(scrolledwin
), stock_list_view
);
280 /* add/remove button */
281 btn_vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 8);
282 gtk_widget_show(btn_vbox
);
283 gtk_box_pack_start(GTK_BOX(hbox1
), btn_vbox
, FALSE
, FALSE
, 0);
285 add_btn
= gtkut_stock_button("list-add", _("_Add"));
286 gtk_widget_show(add_btn
);
287 gtk_box_pack_start(GTK_BOX(btn_vbox
), add_btn
, FALSE
, TRUE
, 0);
289 g_signal_connect(G_OBJECT(add_btn
), "clicked",
290 G_CALLBACK(prefs_summary_column_add
), NULL
);
292 remove_btn
= gtkut_stock_button("list-remove", _("_Remove"));
293 gtk_widget_show(remove_btn
);
294 gtk_box_pack_start(GTK_BOX(btn_vbox
), remove_btn
, FALSE
, TRUE
, 0);
296 g_signal_connect(G_OBJECT(remove_btn
), "clicked",
297 G_CALLBACK(prefs_summary_column_remove
), NULL
);
299 clist_hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
300 gtk_widget_show(clist_hbox
);
301 gtk_box_pack_start(GTK_BOX(hbox1
), clist_hbox
, TRUE
, TRUE
, 0);
303 scrolledwin
= gtk_scrolled_window_new(NULL
, NULL
);
304 gtk_widget_set_size_request(scrolledwin
, 180, 210);
305 gtk_widget_show(scrolledwin
);
306 gtk_box_pack_start(GTK_BOX(clist_hbox
), scrolledwin
, TRUE
, TRUE
, 0);
307 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin
),
308 GTK_POLICY_AUTOMATIC
,
309 GTK_POLICY_AUTOMATIC
);
310 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolledwin
),
313 shown_list_view
= prefs_summary_column_list_view_create
314 (_("Displayed columns"));
315 g_signal_connect(G_OBJECT(shown_list_view
), "cursor-changed",
316 G_CALLBACK(prefs_summary_column_shown_sel_changed
),
318 gtk_widget_show(shown_list_view
);
319 gtk_container_add(GTK_CONTAINER(scrolledwin
), shown_list_view
);
322 btn_vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 8);
323 gtk_widget_show(btn_vbox
);
324 gtk_box_pack_start(GTK_BOX(hbox1
), btn_vbox
, FALSE
, FALSE
, 0);
326 up_btn
= gtkut_stock_button("go-up", _("_Up"));
327 gtk_widget_show(up_btn
);
328 gtk_box_pack_start(GTK_BOX(btn_vbox
), up_btn
, FALSE
, TRUE
, 0);
330 down_btn
= gtkut_stock_button("go-down", _("_Down"));
331 gtk_widget_show(down_btn
);
332 gtk_box_pack_start(GTK_BOX(btn_vbox
), down_btn
, FALSE
, TRUE
, 0);
334 g_signal_connect(G_OBJECT(up_btn
), "clicked",
335 G_CALLBACK(prefs_summary_column_up
), NULL
);
336 g_signal_connect(G_OBJECT(down_btn
), "clicked",
337 G_CALLBACK(prefs_summary_column_down
), NULL
);
339 btn_hbox
= gtk_box_new(GTK_ORIENTATION_HORIZONTAL
, 8);
340 gtk_widget_show(btn_hbox
);
341 gtk_box_pack_end(GTK_BOX(vbox
), btn_hbox
, FALSE
, FALSE
, 0);
343 btn_vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 0);
344 gtk_widget_show(btn_vbox
);
345 gtk_box_pack_start(GTK_BOX(btn_hbox
), btn_vbox
, FALSE
, FALSE
, 0);
347 default_btn
= gtk_button_new_with_label(_(" Use default "));
348 gtk_widget_show(default_btn
);
349 gtk_box_pack_start(GTK_BOX(btn_vbox
), default_btn
, TRUE
, FALSE
, 0);
350 g_signal_connect(G_OBJECT(default_btn
), "clicked",
351 G_CALLBACK(prefs_summary_column_set_to_default
),
354 gtkut_stock_button_set_create(&confirm_area
,
355 &cancel_btn
, NULL
, _("_Cancel"),
356 &ok_btn
, NULL
, _("_OK"),
358 gtk_widget_show(confirm_area
);
359 gtk_box_pack_end(GTK_BOX(btn_hbox
), confirm_area
, FALSE
, FALSE
, 0);
360 gtk_widget_grab_default(ok_btn
);
362 g_signal_connect(G_OBJECT(ok_btn
), "clicked",
363 G_CALLBACK(prefs_summary_column_ok
), NULL
);
364 g_signal_connect(G_OBJECT(cancel_btn
), "clicked",
365 G_CALLBACK(prefs_summary_column_cancel
), NULL
);
368 summary_col
.window
= window
;
369 summary_col
.add_btn
= add_btn
;
370 summary_col
.remove_btn
= remove_btn
;
371 summary_col
.up_btn
= up_btn
;
372 summary_col
.down_btn
= down_btn
;
373 summary_col
.ok_btn
= ok_btn
;
374 summary_col
.cancel_btn
= cancel_btn
;
375 summary_col
.stock_list_view
= stock_list_view
;
376 summary_col
.shown_list_view
= shown_list_view
;
378 prefs_summary_column_shown_set_active(FALSE
);
379 prefs_summary_column_stock_set_active(FALSE
);
382 SummaryColumnState
*prefs_summary_column_get_config(void)
384 static SummaryColumnState state
[N_SUMMARY_COLS
];
385 SummaryColumnType type
;
388 for (pos
= 0; pos
< N_SUMMARY_COLS
; pos
++)
389 state
[pos
].type
= -1;
391 for (type
= 0; type
< N_SUMMARY_COLS
; type
++) {
392 pos
= prefs_common
.summary_col_pos
[type
];
393 if (pos
< 0 || pos
>= N_SUMMARY_COLS
||
394 state
[pos
].type
!= -1) {
395 g_warning("wrong column position");
396 prefs_summary_column_set_config(default_state
);
397 return default_state
;
400 state
[pos
].type
= type
;
401 state
[pos
].visible
= prefs_common
.summary_col_visible
[type
];
407 static void prefs_summary_column_set_config(SummaryColumnState
*state
)
409 SummaryColumnType type
;
412 for (pos
= 0; pos
< N_SUMMARY_COLS
; pos
++) {
413 type
= state
[pos
].type
;
414 prefs_common
.summary_col_visible
[type
] = state
[pos
].visible
;
415 prefs_common
.summary_col_pos
[type
] = pos
;
419 static void prefs_summary_column_set_dialog(SummaryColumnState
*state
)
421 GtkListStore
*stock_store
, *shown_store
;
423 SummaryColumnType type
;
426 stock_store
= GTK_LIST_STORE(gtk_tree_view_get_model
427 (GTK_TREE_VIEW(summary_col
.stock_list_view
)));
428 shown_store
= GTK_LIST_STORE(gtk_tree_view_get_model
429 (GTK_TREE_VIEW(summary_col
.shown_list_view
)));
431 gtk_list_store_clear(stock_store
);
432 gtk_list_store_clear(shown_store
);
435 state
= prefs_summary_column_get_config();
437 for (pos
= 0; pos
< N_SUMMARY_COLS
; pos
++) {
438 type
= state
[pos
].type
;
439 name
= gettext(col_name
[type
]);
441 if (state
[pos
].visible
)
442 prefs_summary_column_insert_column(shown_store
,
446 prefs_summary_column_insert_column(stock_store
,
452 static void prefs_summary_column_set_view(void)
454 gint stock_n_rows
, shown_n_rows
;
455 SummaryColumnState state
[N_SUMMARY_COLS
];
456 SummaryColumnType type
;
459 stock_n_rows
= gtk_tree_model_iter_n_children
460 (gtk_tree_view_get_model(GTK_TREE_VIEW
461 (summary_col
.stock_list_view
)), NULL
);
462 shown_n_rows
= gtk_tree_model_iter_n_children
463 (gtk_tree_view_get_model(GTK_TREE_VIEW
464 (summary_col
.shown_list_view
)), NULL
);
467 (stock_n_rows
+ shown_n_rows
== N_SUMMARY_COLS
);
469 for (row
= 0; row
< stock_n_rows
; row
++) {
470 type
= prefs_summary_column_get_column
471 (summary_col
.stock_list_view
, row
);
472 state
[row
].type
= type
;
473 state
[row
].visible
= FALSE
;
477 for (row
= 0; row
< shown_n_rows
; row
++) {
478 type
= prefs_summary_column_get_column
479 (summary_col
.shown_list_view
, row
);
480 state
[pos
+ row
].type
= type
;
481 state
[pos
+ row
].visible
= TRUE
;
484 prefs_summary_column_set_config(state
);
485 main_window_set_summary_column();
488 static void prefs_summary_column_add(void)
490 GtkListStore
*stock_store
, *shown_store
;
491 GtkTreeIter stock_sel
, shown_sel
, shown_add
;
492 gboolean shown_sel_valid
;
494 SummaryColumnType type
;
496 stock_store
= GTK_LIST_STORE(gtk_tree_view_get_model
497 (GTK_TREE_VIEW(summary_col
.stock_list_view
)));
498 shown_store
= GTK_LIST_STORE(gtk_tree_view_get_model
499 (GTK_TREE_VIEW(summary_col
.shown_list_view
)));
501 if (!gtk_tree_selection_get_selected
502 (gtk_tree_view_get_selection
503 (GTK_TREE_VIEW(summary_col
.stock_list_view
)),
508 shown_sel_valid
= gtk_tree_selection_get_selected
509 (gtk_tree_view_get_selection
510 (GTK_TREE_VIEW(summary_col
.shown_list_view
)),
514 gtk_tree_model_get(GTK_TREE_MODEL(stock_store
), &stock_sel
,
518 gtk_list_store_remove(stock_store
, &stock_sel
);
520 gtk_list_store_insert_after(shown_store
, &shown_add
,
521 shown_sel_valid
? &shown_sel
: NULL
);
523 name
= gettext(col_name
[type
]);
525 gtk_list_store_set(shown_store
, &shown_add
,
530 gtk_tree_selection_select_iter(gtk_tree_view_get_selection
531 (GTK_TREE_VIEW(summary_col
.shown_list_view
)),
533 prefs_summary_column_shown_set_active(TRUE
);
534 prefs_summary_column_stock_set_active(FALSE
);
537 static void prefs_summary_column_remove(void)
539 GtkListStore
*stock_store
, *shown_store
;
540 GtkTreeIter shown_sel
, stock_sel
, stock_add
;
541 gboolean stock_sel_valid
;
543 SummaryColumnType type
;
545 stock_store
= GTK_LIST_STORE(gtk_tree_view_get_model
546 (GTK_TREE_VIEW(summary_col
.stock_list_view
)));
547 shown_store
= GTK_LIST_STORE(gtk_tree_view_get_model
548 (GTK_TREE_VIEW(summary_col
.shown_list_view
)));
550 if (!gtk_tree_selection_get_selected
551 (gtk_tree_view_get_selection
552 (GTK_TREE_VIEW(summary_col
.shown_list_view
)),
557 stock_sel_valid
= gtk_tree_selection_get_selected
558 (gtk_tree_view_get_selection
559 (GTK_TREE_VIEW(summary_col
.stock_list_view
)),
563 gtk_tree_model_get(GTK_TREE_MODEL(shown_store
), &shown_sel
,
567 gtk_list_store_remove(shown_store
, &shown_sel
);
569 gtk_list_store_insert_after(stock_store
, &stock_add
,
570 stock_sel_valid
? &stock_sel
: NULL
);
572 name
= gettext(col_name
[type
]);
574 gtk_list_store_set(stock_store
, &stock_add
,
579 gtk_tree_selection_select_iter(gtk_tree_view_get_selection
580 (GTK_TREE_VIEW(summary_col
.stock_list_view
)),
582 prefs_summary_column_shown_set_active(FALSE
);
583 prefs_summary_column_stock_set_active(TRUE
);
586 static void prefs_summary_column_up(void)
588 GtkTreePath
*prev
, *sel
;
590 GtkListStore
*shown_store
;
593 if (!gtk_tree_selection_get_selected
594 (gtk_tree_view_get_selection
595 (GTK_TREE_VIEW(summary_col
.shown_list_view
)),
600 shown_store
= GTK_LIST_STORE(gtk_tree_view_get_model
601 (GTK_TREE_VIEW(summary_col
.shown_list_view
)));
603 sel
= gtk_tree_model_get_path(GTK_TREE_MODEL(shown_store
),
608 prev
= gtk_tree_path_copy(sel
);
609 if (!gtk_tree_path_prev(prev
)) {
610 gtk_tree_path_free(prev
);
611 gtk_tree_path_free(sel
);
615 gtk_tree_model_get_iter(GTK_TREE_MODEL(shown_store
),
617 gtk_tree_path_free(sel
);
618 gtk_tree_path_free(prev
);
620 gtk_list_store_swap(shown_store
, &iprev
, &isel
);
621 prefs_summary_column_shown_set_btn_sensitivity();
624 static void prefs_summary_column_down(void)
626 GtkListStore
*shown_store
;
627 GtkTreeIter next
, sel
;
629 if (!gtk_tree_selection_get_selected
630 (gtk_tree_view_get_selection
631 (GTK_TREE_VIEW(summary_col
.shown_list_view
)),
636 shown_store
= GTK_LIST_STORE(gtk_tree_view_get_model
637 (GTK_TREE_VIEW(summary_col
.shown_list_view
)));
640 if (!gtk_tree_model_iter_next(GTK_TREE_MODEL(shown_store
), &next
))
643 gtk_list_store_swap(shown_store
, &next
, &sel
);
644 prefs_summary_column_shown_set_btn_sensitivity();
647 static void prefs_summary_column_set_to_default(void)
649 prefs_summary_column_set_dialog(default_state
);
650 prefs_summary_column_shown_set_active(FALSE
);
651 prefs_summary_column_stock_set_active(FALSE
);
654 static void prefs_summary_column_ok(void)
656 if (!summary_col
.finished
) {
657 summary_col
.finished
= TRUE
;
658 prefs_summary_column_set_view();
662 static void prefs_summary_column_cancel(void)
664 summary_col
.finished
= TRUE
;
667 static gint
prefs_summary_column_delete_event(GtkWidget
*widget
,
671 summary_col
.finished
= TRUE
;
675 static gboolean
prefs_summary_column_key_pressed(GtkWidget
*widget
,
679 if (event
&& event
->keyval
== GDK_KEY_Escape
)
680 summary_col
.finished
= TRUE
;
684 static GtkListStore
*prefs_summary_column_create_store(void)
686 return gtk_list_store_new(N_SUMCOL_COLUMNS
,
692 static void prefs_summary_column_insert_column(GtkListStore
*store
,
695 SummaryColumnType type
)
700 if (!gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(store
),
706 gtk_list_store_append(store
, &iter
);
707 gtk_list_store_set(store
, &iter
,
713 /* change existing */
714 gtk_list_store_set(store
, &iter
,
722 *\brief Return the columnn type for a row
724 static SummaryColumnType
prefs_summary_column_get_column(GtkWidget
*list
, gint row
)
726 GtkTreeView
*list_view
= GTK_TREE_VIEW(list
);
727 GtkTreeModel
*model
= gtk_tree_view_get_model(list_view
);
729 SummaryColumnType result
;
731 if (!gtk_tree_model_iter_nth_child(model
, &iter
, NULL
, row
))
734 gtk_tree_model_get(model
, &iter
,
735 SUMCOL_TYPE
, &result
,
741 static GtkWidget
*prefs_summary_column_list_view_create(const gchar
*name
)
743 GtkWidget
*list_view
;
744 GtkTreeSelection
*selector
;
747 model
= GTK_TREE_MODEL(prefs_summary_column_create_store());
748 list_view
= gtk_tree_view_new_with_model(model
);
749 g_object_unref(G_OBJECT(model
));
751 gtk_tree_view_set_rules_hint(GTK_TREE_VIEW(list_view
),
752 prefs_common
.use_stripes_everywhere
);
754 selector
= gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view
));
755 gtk_tree_selection_set_mode(selector
, GTK_SELECTION_BROWSE
);
757 prefs_filtering_create_list_view_columns(GTK_WIDGET(list_view
), name
);
759 gtk_tree_view_enable_model_drag_source(GTK_TREE_VIEW(list_view
),
762 G_N_ELEMENTS(row_targets
),
765 gtk_tree_view_enable_model_drag_dest(GTK_TREE_VIEW(list_view
),
767 G_N_ELEMENTS(row_targets
),
770 g_signal_connect(G_OBJECT(list_view
), "drag_data_get",
771 G_CALLBACK(drag_data_get
),
774 g_signal_connect(G_OBJECT(list_view
), "drag_data_received",
775 G_CALLBACK(drag_data_received
),
781 static void prefs_filtering_create_list_view_columns(GtkWidget
*list_view
,
784 GtkTreeViewColumn
*column
;
785 GtkCellRenderer
*renderer
;
787 renderer
= gtk_cell_renderer_text_new();
788 column
= gtk_tree_view_column_new_with_attributes
789 (name
, renderer
, "text", SUMCOL_NAME
, NULL
);
790 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view
), column
);
793 static void drag_data_get(GtkTreeView
*tree_view
, GdkDragContext
*context
,
794 GtkSelectionData
*data
, guint info
,
795 guint time
, GtkTreeModel
*model
)
798 SummaryColumnType type
;
799 GtkTreeModel
*source_model
;
801 if (info
!= TARGET_INFO_SUMCOL
)
804 if (!gtk_tree_selection_get_selected
805 (gtk_tree_view_get_selection(tree_view
),
806 &source_model
, &iter
))
809 gtk_tree_model_get(source_model
, &iter
,
814 gtk_selection_data_set(data
, gtk_selection_data_get_target(data
), 8,
815 (gchar
*) &type
, sizeof type
);
818 static void drag_data_received(GtkTreeView
*tree_view
, GdkDragContext
*context
,
819 gint x
, gint y
, GtkSelectionData
*data
,
820 guint info
, guint time
, GtkTreeModel
*model
)
823 GtkTreePath
*dst
= NULL
, *sel
= NULL
;
824 GtkTreeIter isel
, idst
;
825 GtkTreeViewDropPosition pos
;
826 SummaryColumnType type
;
827 GtkTreeModel
*sel_model
;
830 source
= gtk_drag_get_source_widget(context
);
832 if (source
== GTK_WIDGET(tree_view
)) {
835 * Same widget: re-order
838 if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(tree_view
),
840 sel
= gtk_tree_model_get_path(model
, &isel
);
841 gtk_tree_view_get_dest_row_at_pos(tree_view
, x
, y
,
844 /* NOTE: dst is invalid if selection beyond last row, in that
845 * case move beyond last one (XXX_move_before(..., NULL)) */
848 gtk_tree_model_get_iter(model
, &idst
, dst
);
850 gtk_list_store_move_before(GTK_LIST_STORE(model
),
854 /* we do not drag if no valid dst and sel, and when
855 * dst and sel are the same (moving after or before
856 * itself doesn't change order...) */
857 if ((dst
&& sel
) && gtk_tree_path_compare(sel
, dst
) != 0) {
858 if (pos
== GTK_TREE_VIEW_DROP_BEFORE
859 || pos
== GTK_TREE_VIEW_DROP_INTO_OR_BEFORE
)
860 gtk_list_store_move_before(GTK_LIST_STORE(model
),
864 gtk_list_store_move_after(GTK_LIST_STORE(model
),
868 gtk_tree_path_free(dst
);
869 gtk_tree_path_free(sel
);
871 gtk_drag_finish(context
, TRUE
, FALSE
, time
);
873 } else if (source
== summary_col
.stock_list_view
874 || source
== summary_col
.shown_list_view
) {
877 * Other widget: change and update
880 /* get source information and remove */
881 if (gtk_tree_selection_get_selected(gtk_tree_view_get_selection(
882 GTK_TREE_VIEW(source
)),
883 &sel_model
, &isel
)) {
884 type
= *((gint
*) gtk_selection_data_get_data(data
));
885 name
= gettext(col_name
[type
]);
886 gtk_list_store_remove(GTK_LIST_STORE(sel_model
), &isel
);
888 /* get insertion position */
889 gtk_tree_view_get_dest_row_at_pos(tree_view
, x
, y
, &dst
, &pos
);
891 /* NOTE: dst is invalid if insertion point beyond last row,
892 * just append to list in that case (XXX_store_append()) */
895 gtk_tree_model_get_iter(model
, &idst
, dst
);
897 if (pos
== GTK_TREE_VIEW_DROP_BEFORE
898 || pos
== GTK_TREE_VIEW_DROP_INTO_OR_BEFORE
)
899 gtk_list_store_insert_before(GTK_LIST_STORE(model
),
903 gtk_list_store_insert_after(GTK_LIST_STORE(model
),
907 gtk_list_store_append(GTK_LIST_STORE(model
),
910 gtk_list_store_set(GTK_LIST_STORE(model
), &isel
,
912 SUMCOL_TYPE
, type
, -1);
913 gtk_tree_path_free(dst
);
915 gtk_drag_finish(context
, TRUE
, FALSE
, time
);
918 prefs_summary_column_shown_set_active(FALSE
);
919 prefs_summary_column_stock_set_active(FALSE
);
921 /* XXXX: should we call gtk_drag_finish() for other code paths? */
924 static void prefs_summary_column_shown_set_btn_sensitivity(void)
926 GtkTreeModel
*model
= GTK_TREE_MODEL(gtk_tree_view_get_model(
927 GTK_TREE_VIEW(summary_col
.shown_list_view
)));
928 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(
929 GTK_TREE_VIEW(summary_col
.shown_list_view
));
933 if(!gtk_tree_selection_get_selected(selection
, NULL
, &iter
)) {
934 gtk_widget_set_sensitive(summary_col
.remove_btn
, FALSE
);
935 gtk_widget_set_sensitive(summary_col
.up_btn
, FALSE
);
936 gtk_widget_set_sensitive(summary_col
.down_btn
, FALSE
);
940 path
= gtk_tree_model_get_path(model
, &iter
);
942 gtk_widget_set_sensitive(summary_col
.up_btn
, gtk_tree_path_prev(path
));
943 gtk_widget_set_sensitive(summary_col
.down_btn
,
944 gtk_tree_model_iter_next(model
, &iter
));
945 gtk_tree_path_free(path
);
948 static void prefs_summary_column_shown_set_active(const gboolean active
)
950 GtkTreeSelection
*selection
= NULL
;
952 gtk_widget_set_sensitive(summary_col
.remove_btn
, active
);
954 if(active
== FALSE
) {
955 selection
= gtk_tree_view_get_selection(
956 GTK_TREE_VIEW(summary_col
.shown_list_view
));
957 gtk_tree_selection_unselect_all(selection
);
959 gtk_widget_set_sensitive(summary_col
.up_btn
, FALSE
);
960 gtk_widget_set_sensitive(summary_col
.down_btn
, FALSE
);
962 prefs_summary_column_shown_set_btn_sensitivity();
966 static void prefs_summary_column_stock_set_active(const gboolean active
)
968 GtkTreeSelection
*selection
= NULL
;
970 gtk_widget_set_sensitive(summary_col
.add_btn
, active
);
972 if(active
== FALSE
) {
973 selection
= gtk_tree_view_get_selection(
974 GTK_TREE_VIEW(summary_col
.stock_list_view
));
975 gtk_tree_selection_unselect_all(selection
);
979 static void prefs_summary_column_stock_sel_changed(void)
981 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(
982 GTK_TREE_VIEW(summary_col
.stock_list_view
));
983 prefs_summary_column_stock_set_active(
984 (selection
!= NULL
) ? TRUE
: FALSE
);
985 prefs_summary_column_shown_set_active(
986 (selection
!= NULL
) ? FALSE
: TRUE
);
989 static void prefs_summary_column_shown_sel_changed(void)
991 GtkTreeSelection
*selection
= gtk_tree_view_get_selection(
992 GTK_TREE_VIEW(summary_col
.shown_list_view
));
993 prefs_summary_column_shown_set_active(
994 (selection
!= NULL
) ? TRUE
: FALSE
);
995 prefs_summary_column_stock_set_active(
996 (selection
!= NULL
) ? FALSE
: TRUE
);