2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2024 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"
25 #include <glib/gi18n.h>
28 #include <gdk/gdkkeysyms.h>
31 #include "prefswindow.h"
33 #include "prefs_common.h"
34 #include "gtk/manage_window.h"
36 static void prefs_size_allocate_cb(GtkWidget
*widget
,
37 GtkAllocation
*allocation
, gpointer
*user_data
);
38 static GtkTreeStore
*prefswindow_create_data_store (void);
39 static GtkWidget
*prefswindow_tree_view_create (PrefsWindow
* prefswindow
);
40 static void prefs_filtering_create_tree_view_columns (GtkWidget
*tree_view
);
41 static gboolean
prefswindow_row_selected (GtkTreeSelection
*selector
,
44 gboolean currently_selected
,
47 static void save_all_pages(GSList
*prefs_pages
)
51 for (cur
= prefs_pages
; cur
!= NULL
; cur
= g_slist_next(cur
)) {
52 PrefsPage
*page
= (PrefsPage
*) cur
->data
;
54 if (page
->page_open
) {
55 page
->save_page(page
);
60 static gboolean
query_can_close_all_pages(GSList
*prefs_pages
)
64 for (cur
= prefs_pages
; cur
!= NULL
; cur
= g_slist_next(cur
)) {
65 PrefsPage
*page
= (PrefsPage
*) cur
->data
;
68 if (!page
->can_close(page
))
74 static void close_all_pages(GSList
*prefs_pages
)
78 for (cur
= prefs_pages
; cur
!= NULL
; cur
= g_slist_next(cur
)) {
79 PrefsPage
*page
= (PrefsPage
*) cur
->data
;
81 if (page
->page_open
) {
82 page
->destroy_widget(page
);
83 page
->page_open
= FALSE
;
89 static void prefs_show_sections(PrefsWindow
*prefswindow
)
92 GtkWidget
*paned
= prefswindow
->paned
;
94 g_object_get (G_OBJECT(paned
),
98 gtk_widget_show(gtk_paned_get_child1(GTK_PANED(paned
)));
99 gtk_widget_hide(gtk_paned_get_child2(GTK_PANED(paned
)));
100 gtk_paned_set_position(GTK_PANED(paned
), max
);
103 static void prefs_show_page(PrefsWindow
*prefswindow
)
106 GtkWidget
*paned
= prefswindow
->paned
;
108 g_object_get (G_OBJECT(paned
),
112 gtk_widget_hide(gtk_paned_get_child1(GTK_PANED(paned
)));
113 gtk_widget_show(gtk_paned_get_child2(GTK_PANED(paned
)));
114 gtk_paned_set_position(GTK_PANED(paned
), min
);
118 static void apply_button_clicked(GtkButton
*button
, gpointer user_data
)
120 PrefsWindow
*prefswindow
= (PrefsWindow
*) user_data
;
122 prefswindow
->dialog_response
= PREFSWINDOW_RESPONSE_APPLY
;
124 save_all_pages(prefswindow
->prefs_pages
);
126 prefs_show_sections(prefswindow
);
129 if (prefswindow
->apply_cb
)
130 prefswindow
->apply_cb(prefswindow
);
133 static void close_prefs_window(PrefsWindow
*prefswindow
)
135 debug_print("prefs window closed\n");
137 close_all_pages(prefswindow
->prefs_pages
);
139 if (prefswindow
->close_cb
)
140 prefswindow
->close_cb(prefswindow
);
142 gtk_widget_destroy(prefswindow
->window
);
143 g_slist_free(prefswindow
->prefs_pages
);
144 if(prefswindow
->func
!= NULL
)
145 prefswindow
->func(prefswindow
->data
);
149 static void ok_button_clicked(GtkButton
*button
, gpointer user_data
)
151 PrefsWindow
*prefswindow
= (PrefsWindow
*) user_data
;
153 prefswindow
->dialog_response
= PREFSWINDOW_RESPONSE_OK
;
155 if (query_can_close_all_pages(prefswindow
->prefs_pages
)) {
156 save_all_pages(prefswindow
->prefs_pages
);
157 close_prefs_window(prefswindow
);
161 static void cancel_button_clicked(GtkButton
*button
, gpointer user_data
)
163 PrefsWindow
*prefswindow
= (PrefsWindow
*) user_data
;
165 close_prefs_window(prefswindow
);
168 static gboolean
window_closed(GtkWidget
*widget
, GdkEvent
*event
, gpointer user_data
)
170 PrefsWindow
*prefswindow
= (PrefsWindow
*) user_data
;
173 save_all_pages(prefswindow
->prefs_pages
);
175 close_prefs_window(prefswindow
);
180 static gboolean
prefswindow_key_pressed(GtkWidget
*widget
, GdkEventKey
*event
,
183 GtkWidget
*focused_child
;
186 switch (event
->keyval
) {
187 case GDK_KEY_Escape
:
188 cancel_button_clicked(NULL
, data
);
190 case GDK_KEY_Return
:
191 case GDK_KEY_KP_Enter
:
192 focused_child
= gtkut_get_focused_child
193 (GTK_CONTAINER(data
->notebook
));
194 /* Press ok, if the focused child is not a text view
195 * and text (anything that accepts return) (can pass
196 * NULL to any of the GTK_xxx() casts) */
197 if (!GTK_IS_TEXT_VIEW(focused_child
))
198 ok_button_clicked(NULL
, data
);
207 typedef struct FindNodeByName
{
213 static gboolean
find_node_by_name(GtkTreeModel
*model
, GtkTreePath
*path
,
214 GtkTreeIter
*iter
, FindNodeByName
*data
)
217 gboolean result
= FALSE
;
219 gtk_tree_model_get(model
, iter
, PREFS_PAGE_TITLE
, &name
, -1);
221 result
= strcmp(name
, data
->name
) == 0;
232 static gint
prefswindow_tree_sort_by_weight(GtkTreeModel
*model
,
240 /* From observation sorting should keep in account the original
241 * order in the prefs_pages list. I.e. if equal weight, prefer
242 * the index in the pages list */
243 gtk_tree_model_get(model
, a
,
244 PREFS_PAGE_INDEX
, &i1
,
245 PREFS_PAGE_WEIGHT
, &f1
, -1);
246 gtk_tree_model_get(model
, b
,
247 PREFS_PAGE_INDEX
, &i2
,
248 PREFS_PAGE_WEIGHT
, &f2
, -1);
250 return f1
< f2
? -1 : (f1
> f2
? 1 :
251 (i1
< i2
? 1 : (i1
> i2
? -1 : 0)));
254 static void prefswindow_build_page(PrefsWindow
*prefswindow
, PrefsPage
*page
)
256 GtkWidget
*scrolledwin
;
258 if (!page
->page_open
) {
259 scrolledwin
= gtk_scrolled_window_new(NULL
, NULL
);
260 gtk_widget_show(scrolledwin
);
261 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin
),
262 GTK_POLICY_AUTOMATIC
, GTK_POLICY_AUTOMATIC
);
264 page
->create_widget(page
, GTK_WINDOW(prefswindow
->window
), prefswindow
->data
);
265 gtk_container_add(GTK_CONTAINER(scrolledwin
), page
->widget
);
267 gtk_container_add(GTK_CONTAINER(prefswindow
->notebook
), scrolledwin
);
269 page
->widget
= scrolledwin
;
270 page
->page_open
= TRUE
;
274 static GSList
*prefswindow_build_all_pages(PrefsWindow
*prefswindow
, GSList
*prefs_pages
)
278 prefs_pages
= g_slist_reverse(prefs_pages
);
279 for (cur
= prefs_pages
; cur
!= NULL
; cur
= g_slist_next(cur
)) {
280 PrefsPage
*page
= (PrefsPage
*) cur
->data
;
282 prefswindow_build_page(prefswindow
, page
);
284 return g_slist_reverse(prefs_pages
);
287 static void prefswindow_build_tree(GtkWidget
*tree_view
, GSList
*prefs_pages
,
288 PrefsWindow
*prefswindow
,
289 gboolean preload_pages
)
291 GtkTreeStore
*store
= GTK_TREE_STORE(gtk_tree_view_get_model
292 (GTK_TREE_VIEW(tree_view
)));
294 gint index
; /* index in pages list */
296 GtkTreeSelection
*selection
;
300 for (cur
= prefs_pages
, index
= 0; cur
!= NULL
; cur
= g_slist_next(cur
), index
++) {
301 PrefsPage
*page
= (PrefsPage
*)cur
->data
;
302 FindNodeByName find_name
;
303 GtkTreeIter node
, child
;
304 PrefsTreeNode
*prefs_node
= NULL
;
307 /* each page tree component string */
308 for (i
= 0; page
->path
[i
] != NULL
; i
++) {
309 find_name
.found
= FALSE
;
310 find_name
.name
= page
->path
[i
];
312 /* find node to attach to
313 * FIXME: we search the entire tree, so this is suboptimal... */
314 gtk_tree_model_foreach(GTK_TREE_MODEL(store
),
315 (GtkTreeModelForeachFunc
) find_node_by_name
,
317 if (find_name
.found
&& (i
== 0 || page
->path
[i
] != page
->path
[i
-1])) {
318 node
= find_name
.node
;
319 gtk_tree_model_get(GTK_TREE_MODEL(store
), &node
,
320 PREFS_PAGE_DATA
, &prefs_node
,
325 /* create a new top level */
326 gtk_tree_store_append(store
, &child
, i
== 0 ? NULL
: &node
);
327 prefs_node
= g_new0(PrefsTreeNode
, 1);
328 autoptr
= g_auto_pointer_new(prefs_node
);
329 gtk_tree_store_set(store
, &child
,
330 PREFS_PAGE_TITLE
, page
->path
[i
],
331 PREFS_PAGE_DATA
, prefs_node
,
332 PREFS_PAGE_DATA_AUTO_FREE
, autoptr
,
333 PREFS_PAGE_INDEX
, index
,
334 PREFS_PAGE_WEIGHT
, 0.0f
,
336 g_auto_pointer_free(autoptr
);
341 /* right now we have a node and its prefs_node */
343 g_warning("no prefs_node :/");
345 prefs_node
->page
= page
;
347 /* parents "inherit" the max weight of the children */
351 gtk_tree_model_get(GTK_TREE_MODEL(store
), &node
,
352 PREFS_PAGE_WEIGHT
, &f
,
354 if (page
->weight
> f
) {
356 gtk_tree_store_set(store
, &node
,
357 PREFS_PAGE_WEIGHT
, f
,
361 } while (gtk_tree_model_iter_parent(GTK_TREE_MODEL(store
),
365 gtk_tree_view_expand_all(GTK_TREE_VIEW(tree_view
));
367 /* set sort func & sort */
368 gtk_tree_sortable_set_sort_func(GTK_TREE_SORTABLE(store
),
370 prefswindow_tree_sort_by_weight
,
372 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store
),
374 GTK_SORT_DESCENDING
);
377 prefs_pages
= prefswindow_build_all_pages(prefswindow
, prefs_pages
);
379 /* select first one or its first child if necessary */
381 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view
));
382 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store
), &iter
)) {
383 if (gtk_tree_model_iter_has_child(GTK_TREE_MODEL(store
), &iter
)) {
384 GtkTreeIter parent
= iter
;
385 if (!gtk_tree_model_iter_children(GTK_TREE_MODEL(store
), &iter
, &parent
))
388 gtk_tree_selection_select_iter(selection
, &iter
);
393 void prefswindow_open_full(const gchar
*title
, GSList
*prefs_pages
,
394 gpointer data
, GDestroyNotify func
,
395 gint
*save_width
, gint
*save_height
,
396 gboolean preload_pages
,
397 PrefsOpenCallbackFunc open_cb
,
398 PrefsApplyCallbackFunc apply_cb
,
399 PrefsCloseCallbackFunc close_cb
)
401 PrefsWindow
*prefswindow
;
404 static GdkGeometry geometry
;
406 GdkRectangle workarea
= {0};
408 prefswindow
= g_new0(PrefsWindow
, 1);
410 prefswindow
->data
= data
;
411 prefswindow
->func
= func
;
412 prefswindow
->prefs_pages
= g_slist_copy(prefs_pages
);
413 prefswindow
->save_width
= save_width
;
414 prefswindow
->save_height
= save_height
;
415 prefswindow
->open_cb
= open_cb
;
416 prefswindow
->apply_cb
= apply_cb
;
417 prefswindow
->close_cb
= close_cb
;
418 prefswindow
->dialog_response
= PREFSWINDOW_RESPONSE_CANCEL
;
420 prefswindow
->window
= gtkut_window_new(GTK_WINDOW_TOPLEVEL
, "prefswindow");
421 gtk_window_set_title(GTK_WINDOW(prefswindow
->window
), title
);
423 gtk_window_set_position (GTK_WINDOW(prefswindow
->window
), GTK_WIN_POS_CENTER
);
424 gtk_window_set_modal (GTK_WINDOW (prefswindow
->window
), TRUE
);
425 gtk_window_set_resizable (GTK_WINDOW(prefswindow
->window
), TRUE
);
426 gtk_window_set_type_hint(GTK_WINDOW(prefswindow
->window
), GDK_WINDOW_TYPE_HINT_DIALOG
);
427 gtk_window_set_transient_for (GTK_WINDOW(prefswindow
->window
),
428 GTK_WINDOW(mainwindow_get_mainwindow()->window
));
429 gtk_container_set_border_width(GTK_CONTAINER(prefswindow
->window
), 4);
431 prefswindow
->vbox
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 6);
432 gtk_widget_show(prefswindow
->vbox
);
434 prefswindow
->paned
= gtk_paned_new(GTK_ORIENTATION_HORIZONTAL
);
435 gtk_widget_show(prefswindow
->paned
);
437 gtk_container_add(GTK_CONTAINER(prefswindow
->window
), prefswindow
->vbox
);
439 gtk_box_pack_start(GTK_BOX(prefswindow
->vbox
), prefswindow
->paned
, TRUE
, TRUE
, 0);
441 prefswindow
->scrolledwindow1
= gtk_scrolled_window_new(NULL
, NULL
);
442 gtk_widget_show(prefswindow
->scrolledwindow1
);
443 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(prefswindow
->scrolledwindow1
),
445 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(prefswindow
->scrolledwindow1
),
446 GTK_POLICY_NEVER
, GTK_POLICY_AUTOMATIC
);
448 gtk_paned_add1(GTK_PANED(prefswindow
->paned
), prefswindow
->scrolledwindow1
);
450 prefswindow
->tree_view
= prefswindow_tree_view_create(prefswindow
);
451 gtk_widget_show(prefswindow
->tree_view
);
452 gtk_container_add(GTK_CONTAINER(prefswindow
->scrolledwindow1
),
453 prefswindow
->tree_view
);
455 prefswindow
->vbox2
= gtk_box_new(GTK_ORIENTATION_VERTICAL
, 2);
456 gtk_widget_show(prefswindow
->vbox2
);
458 gtk_paned_add2(GTK_PANED(prefswindow
->paned
), prefswindow
->vbox2
);
460 prefswindow
->table2
= gtk_grid_new();
461 gtk_widget_show(prefswindow
->table2
);
462 gtk_box_pack_start(GTK_BOX(prefswindow
->vbox2
), prefswindow
->table2
, TRUE
, TRUE
, 0);
464 prefswindow
->labelframe
= gtk_frame_new(NULL
);
465 gtk_widget_show(prefswindow
->labelframe
);
466 gtk_frame_set_shadow_type(GTK_FRAME(prefswindow
->labelframe
), GTK_SHADOW_NONE
);
467 gtk_grid_attach(GTK_GRID(prefswindow
->table2
), prefswindow
->labelframe
, 0, 0, 1, 1);
468 gtk_widget_set_hexpand(prefswindow
->labelframe
, TRUE
);
469 gtk_widget_set_halign(prefswindow
->labelframe
, GTK_ALIGN_FILL
);
471 prefswindow
->pagelabel
= gtk_label_new("");
472 gtk_widget_set_margin_top(prefswindow
->pagelabel
, 4);
473 gtk_widget_set_margin_bottom(prefswindow
->pagelabel
, 4);
474 gtk_widget_set_margin_start(prefswindow
->pagelabel
, 4);
475 gtk_widget_show(prefswindow
->pagelabel
);
476 gtk_label_set_justify(GTK_LABEL(prefswindow
->pagelabel
), GTK_JUSTIFY_LEFT
);
477 gtk_label_set_xalign(GTK_LABEL(prefswindow
->pagelabel
), 0.0);
478 gtk_label_set_yalign(GTK_LABEL(prefswindow
->pagelabel
), 0.0);
479 gtk_container_add(GTK_CONTAINER(prefswindow
->labelframe
), prefswindow
->pagelabel
);
481 prefswindow
->notebook
= gtk_notebook_new();
482 gtk_widget_show(prefswindow
->notebook
);
483 gtk_notebook_set_scrollable(GTK_NOTEBOOK(prefswindow
->notebook
), TRUE
);
484 gtk_notebook_set_show_tabs(GTK_NOTEBOOK(prefswindow
->notebook
), FALSE
);
485 gtk_notebook_set_show_border(GTK_NOTEBOOK(prefswindow
->notebook
), FALSE
);
487 gtk_grid_attach(GTK_GRID(prefswindow
->table2
), prefswindow
->notebook
, 0, 1, 1, 1);
488 gtk_widget_set_vexpand(prefswindow
->notebook
, TRUE
);
489 gtk_widget_set_hexpand(prefswindow
->notebook
, TRUE
);
490 gtk_widget_set_halign(prefswindow
->notebook
, GTK_ALIGN_FILL
);
492 prefswindow
->empty_page
= gtk_label_new("");
493 gtk_widget_show(prefswindow
->empty_page
);
494 gtk_container_add(GTK_CONTAINER(prefswindow
->notebook
), prefswindow
->empty_page
);
496 prefswindow_build_tree(prefswindow
->tree_view
, prefs_pages
, prefswindow
,
500 open_cb(prefswindow
);
502 gtk_widget_grab_focus(prefswindow
->tree_view
);
505 gtkut_stock_button_set_create(&prefswindow
->confirm_area
,
506 &prefswindow
->apply_btn
, NULL
, _("_Apply"),
507 &prefswindow
->cancel_btn
, NULL
, _("_Cancel"),
508 &prefswindow
->ok_btn
, NULL
, _("_OK"));
510 gtkut_stock_button_set_create(&prefswindow
->confirm_area
,
511 &prefswindow
->apply_btn
, NULL
, _("_Apply"),
512 &prefswindow
->ok_btn
, "window-close", _("_Close"),
515 gtk_widget_show_all(prefswindow
->confirm_area
);
516 gtk_widget_show(prefswindow
->vbox
);
517 gtk_widget_show(prefswindow
->scrolledwindow1
);
519 gtk_box_pack_start(GTK_BOX(prefswindow
->vbox
), prefswindow
->confirm_area
, FALSE
, FALSE
, 0);
522 g_signal_connect(G_OBJECT(prefswindow
->ok_btn
), "clicked",
523 G_CALLBACK(ok_button_clicked
), prefswindow
);
524 g_signal_connect(G_OBJECT(prefswindow
->cancel_btn
), "clicked",
525 G_CALLBACK(cancel_button_clicked
), prefswindow
);
526 g_signal_connect(G_OBJECT(prefswindow
->apply_btn
), "clicked",
527 G_CALLBACK(apply_button_clicked
), prefswindow
);
529 g_signal_connect(G_OBJECT(prefswindow
->ok_btn
), "clicked",
530 G_CALLBACK(ok_button_clicked
), prefswindow
);
531 g_signal_connect(G_OBJECT(prefswindow
->apply_btn
), "clicked",
532 G_CALLBACK(apply_button_clicked
), prefswindow
);
535 g_signal_connect(G_OBJECT(prefswindow
->window
), "delete_event",
536 G_CALLBACK(window_closed
), prefswindow
);
537 g_signal_connect(G_OBJECT(prefswindow
->window
), "key_press_event",
538 G_CALLBACK(prefswindow_key_pressed
), &(prefswindow
->window
));
540 /* connect to callback only if we have non-NULL pointers to store size to */
541 if (prefswindow
->save_width
&& prefswindow
->save_height
) {
542 g_signal_connect(G_OBJECT(prefswindow
->window
), "size_allocate",
543 G_CALLBACK(prefs_size_allocate_cb
), prefswindow
);
546 MANAGE_WINDOW_SIGNALS_CONNECT(prefswindow
->window
);
548 gdk_monitor_get_workarea(gdk_display_get_primary_monitor(gdk_display_get_default()),
553 if (!geometry
.min_height
) {
555 if (x
< 800 && y
< 600) {
556 geometry
.min_width
= 600;
557 geometry
.min_height
= 440;
559 geometry
.min_width
= 700;
560 geometry
.min_height
= 550;
563 gtk_window_set_geometry_hints(GTK_WINDOW(prefswindow
->window
),
564 NULL
, &geometry
, GDK_HINT_MIN_SIZE
);
565 if (prefswindow
->save_width
&& prefswindow
->save_height
) {
566 gtk_window_set_default_size(GTK_WINDOW(prefswindow
->window
),
567 *(prefswindow
->save_width
),
568 *(prefswindow
->save_height
));
572 prefs_show_sections(prefswindow
);
574 gtk_widget_show(prefswindow
->window
);
575 adj
= gtk_scrolled_window_get_vadjustment(
576 GTK_SCROLLED_WINDOW(prefswindow
->scrolledwindow1
));
577 gtk_adjustment_set_value(adj
, gtk_adjustment_get_lower(adj
));
580 void prefswindow_open(const gchar
*title
, GSList
*prefs_pages
, gpointer data
,
581 gint
*save_width
, gint
*save_height
,
582 PrefsOpenCallbackFunc open_cb
,
583 PrefsApplyCallbackFunc apply_cb
,
584 PrefsCloseCallbackFunc close_cb
)
586 prefswindow_open_full(title
, prefs_pages
, data
, NULL
, save_width
, save_height
,
587 FALSE
, open_cb
, apply_cb
, close_cb
);
591 *\brief Save Gtk object size to prefs dataset
593 static void prefs_size_allocate_cb(GtkWidget
*widget
,
594 GtkAllocation
*allocation
, gpointer
*user_data
)
596 PrefsWindow
*prefswindow
= (PrefsWindow
*) user_data
;
598 cm_return_if_fail(allocation
!= NULL
);
600 /* don't try to save size to NULL pointers */
601 if (prefswindow
&& prefswindow
->save_width
&& prefswindow
->save_height
) {
602 gtk_window_get_size(GTK_WINDOW(widget
),
603 prefswindow
->save_width
, prefswindow
->save_height
);
607 static GtkTreeStore
*prefswindow_create_data_store(void)
609 return gtk_tree_store_new(N_PREFS_PAGE_COLUMNS
,
618 static GtkWidget
*prefswindow_tree_view_create(PrefsWindow
*prefswindow
)
620 GtkTreeView
*tree_view
;
621 GtkTreeSelection
*selector
;
624 model
= GTK_TREE_MODEL(prefswindow_create_data_store());
625 tree_view
= GTK_TREE_VIEW(gtk_tree_view_new_with_model(model
));
626 g_object_unref(model
);
628 selector
= gtk_tree_view_get_selection(tree_view
);
629 gtk_tree_selection_set_mode(selector
, GTK_SELECTION_BROWSE
);
630 gtk_tree_selection_set_select_function(selector
, prefswindow_row_selected
,
633 /* create the columns */
634 prefs_filtering_create_tree_view_columns(GTK_WIDGET(tree_view
));
636 return GTK_WIDGET(tree_view
);
639 static void prefs_filtering_create_tree_view_columns(GtkWidget
*tree_view
)
641 GtkTreeViewColumn
*column
;
642 GtkCellRenderer
*renderer
;
644 renderer
= gtk_cell_renderer_text_new();
645 column
= gtk_tree_view_column_new_with_attributes
648 "text", PREFS_PAGE_TITLE
,
650 gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view
), column
);
653 static gboolean
prefswindow_row_selected(GtkTreeSelection
*selector
,
656 gboolean currently_selected
,
659 PrefsTreeNode
*prefsnode
;
661 PrefsWindow
*prefswindow
= (PrefsWindow
*) data
;
670 if (currently_selected
)
673 if (!gtk_tree_model_get_iter(GTK_TREE_MODEL(model
), &iter
, path
))
676 gtk_tree_model_get(model
, &iter
, PREFS_PAGE_DATA
, &prefsnode
, -1);
677 page
= prefsnode
->page
;
679 debug_print("%f\n", prefsnode
->treeweight
);
682 gtk_label_set_text(GTK_LABEL(prefswindow
->pagelabel
), "");
683 pagenum
= gtk_notebook_page_num(GTK_NOTEBOOK(prefswindow
->notebook
),
684 prefswindow
->empty_page
);
685 gtk_notebook_set_current_page(GTK_NOTEBOOK(prefswindow
->notebook
),
690 prefswindow_build_page(prefswindow
, page
);
693 while (page
->path
[i
+ 1] != 0)
695 labeltext
= page
->path
[i
];
697 markup
= g_markup_printf_escaped("<span weight=\"bold\">\%s</span>", labeltext
);
698 gtk_label_set_markup(GTK_LABEL(prefswindow
->pagelabel
), markup
);
701 pagenum
= gtk_notebook_page_num(GTK_NOTEBOOK(prefswindow
->notebook
),
703 gtk_notebook_set_current_page(GTK_NOTEBOOK(prefswindow
->notebook
),
706 adj
= gtk_scrolled_window_get_vadjustment(
707 GTK_SCROLLED_WINDOW(page
->widget
));
708 lower
= gtk_adjustment_get_lower(adj
);
709 gtk_adjustment_set_value(adj
, lower
);
710 adj
= gtk_scrolled_window_get_hadjustment(
711 GTK_SCROLLED_WINDOW(page
->widget
));
712 gtk_adjustment_set_value(adj
, lower
);
715 prefs_show_page(prefswindow
);