-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
-
82
-
83
-
84
-
85
-
86
-
87
-
88
-
89
-
90
-
91
-
92
-
93
-
94
-
95
-
96
-
97
-
98
-
99
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
-
166
-
167
-
168
-
169
-
170
-
171
-
172
-
173
-
174
// Copyright 2026 Shota FUJI
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
namespace PlacGtkAdwaita {
[GtkTemplate(ui = "/jp/pocka/plac/gtk-adwaita/ui/preferences-dialog.ui")]
private class PreferencesDialog : Adw.PreferencesDialog {
private Settings settings = new Settings();
[GtkChild]
private unowned Adw.ComboRow startup_category;
[GtkChild]
private unowned Adw.SwitchRow disable_csd;
[GtkChild]
private unowned Adw.SwitchRow label_parsing_enabled;
[GtkChild]
private unowned Adw.SwitchRow show_browse_item_separators;
[GtkChild]
private unowned Adw.SwitchRow show_seek_by_10secs;
[GtkChild]
private unowned Adw.SwitchRow show_stop_button;
[GtkChild]
private unowned Adw.SwitchRow focus_browse_items_on_load;
[GtkChild]
private unowned Adw.EntryRow seek_step_size;
[GtkChild]
private unowned Adw.EntryRow seek_page_size;
[GtkChild]
private unowned Adw.SwitchRow fixed_discovery_udp_port_enabled;
[GtkChild]
private unowned Adw.EntryRow discovery_udp_port;
public PreferencesDialog() {
Object();
}
construct {
var startup_category_factory = new Gtk.SignalListItemFactory();
startup_category_factory.setup.connect(setup_startup_category);
startup_category_factory.bind.connect(bind_startup_category);
var startup_category_model = new Adw.EnumListModel(typeof (Roon.Browse.Hierarchy));
startup_category.model = startup_category_model;
startup_category.factory = startup_category_factory;
settings.settings.bind_with_mapping(Settings.STARTUP_CATEGORY, startup_category, "selected", DEFAULT, (to, from, user_data) => {
var model = (Adw.EnumListModel) user_data;
var hierarchy = Roon.Browse.Hierarchy.from_int(from.get_int32());
to.set_uint(model.find_position(hierarchy));
return true;
}, (from, variant_type, user_data) => {
var model = (Adw.EnumListModel) user_data;
var item = (Adw.EnumListItem) model.get_item(from.get_uint());
if (item == null) {
// Vala's type definition wrongly defines return type signature of
// "SettingsBindSetMappingShared" as non-null, despite it being nullable and
// even documentation saying "return null in case of an error."
// This cast suppress compiler warning.
return (Variant) null;
}
var hierarchy = Roon.Browse.Hierarchy.from_int(item.value);
return new Variant("i", hierarchy);
}, startup_category_model, null);
settings.settings.bind(Settings.DISABLE_CSD, disable_csd, "active", DEFAULT);
settings.settings.bind(Settings.LABEL_PARSING_ENABLED, label_parsing_enabled, "active", DEFAULT);
settings.settings.bind(Settings.SHOW_BROWSE_ITEM_SEPARATORS, show_browse_item_separators, "active", DEFAULT);
settings.settings.bind(Settings.SHOW_SEEK_BY_10SECS, show_seek_by_10secs, "active", DEFAULT);
settings.settings.bind(Settings.SHOW_STOP_BUTTON, show_stop_button, "active", DEFAULT);
settings.settings.bind(Settings.FOCUS_BROWSE_ITEMS_ON_LOAD, focus_browse_items_on_load, "active", DEFAULT);
settings.settings.bind_with_mapping(Settings.SEEK_STEP_SIZE, seek_step_size, "text", DEFAULT, (to, from) => {
var size = from.get_uint32();
to.set_string(size.to_string());
return true;
}, (from, variant) => {
var text = from.get_string();
var raw_val = uint.parse(text, 10);
if (raw_val == 0) {
// Vala's type definition wrongly defines return type signature of
// "SettingsBindSetMappingShared" as non-null, despite it being nullable and
// even documentation saying "return null in case of an error."
// This cast suppress compiler warning.
return (Variant) null;
}
return new Variant("u", raw_val);
}, null, null);
settings.settings.bind_with_mapping(Settings.SEEK_PAGE_SIZE, seek_page_size, "text", DEFAULT, (to, from) => {
var size = from.get_uint32();
to.set_string(size.to_string());
return true;
}, (from, variant) => {
var text = from.get_string();
var raw_val = uint.parse(text, 10);
if (raw_val == 0) {
// Vala's type definition wrongly defines return type signature of
// "SettingsBindSetMappingShared" as non-null, despite it being nullable and
// even documentation saying "return null in case of an error."
// This cast suppress compiler warning.
return (Variant) null;
}
return new Variant("u", raw_val);
}, null, null);
settings.settings.bind_with_mapping(Settings.DISCOVERY_UDP_PORT, fixed_discovery_udp_port_enabled, "active", DEFAULT, (to, from) => {
var port = from.get_uint32();
to.set_boolean(port != 0);
return true;
}, (from, variant) => {
return new Variant("u", from.get_boolean() ? 9003 : 0);
}, null, null);
settings.settings.bind_with_mapping(Settings.DISCOVERY_UDP_PORT, discovery_udp_port, "text", DEFAULT, (to, from) => {
var port = from.get_uint32();
to.set_string(port.to_string());
return true;
}, (from, variant) => {
var text = from.get_string();
var raw_val = uint.parse(text, 10);
if (raw_val == 0 || raw_val > uint16.MAX) {
// Vala's type definition wrongly defines return type signature of
// "SettingsBindSetMappingShared" as non-null, despite it being nullable and
// even documentation saying "return null in case of an error."
// This cast suppress compiler warning.
return (Variant) null;
}
return new Variant("u", raw_val);
}, null, null);
fixed_discovery_udp_port_enabled.bind_property("active", discovery_udp_port, "visible", SYNC_CREATE);
}
private static void setup_startup_category(Gtk.ListItemFactory factory, Object object) {
var list_item = (Gtk.ListItem) object;
list_item.child = new Gtk.Label("");
}
private static void bind_startup_category(Gtk.ListItemFactory factory, Object object) {
var list_item = (Gtk.ListItem) object;
var item = (Adw.EnumListItem) list_item.item;
var hierarchy = Roon.Browse.Hierarchy.from_int(item.value);
var label = (Gtk.Label) list_item.child;
label.label = hierarchy.to_display_string();
}
}
}