-
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
-
175
-
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
-
184
-
185
-
186
-
187
-
188
-
189
-
190
-
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
-
202
-
203
-
204
-
205
-
206
-
207
-
208
-
209
-
210
-
211
-
212
-
213
-
214
-
215
-
216
-
217
-
218
-
219
-
220
-
221
-
222
-
223
-
224
-
225
-
226
-
227
-
228
-
229
-
230
-
231
-
232
-
233
-
234
-
235
-
236
-
237
-
238
-
239
-
240
-
241
-
242
-
243
-
244
-
245
-
246
-
247
-
248
-
249
-
250
-
251
-
252
-
253
-
254
-
255
-
256
-
257
-
258
-
259
-
260
-
261
-
262
-
263
-
264
-
265
-
266
-
267
-
268
-
269
-
270
-
271
-
272
-
273
-
274
-
275
-
276
-
277
-
278
-
279
-
280
-
281
// Copyright 2025 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 {
public class App : Adw.Application {
private static GLib.ActionEntry[] app_entries = {
GLib.ActionEntry() {
name = "preferences",
activate = on_preferences,
},
GLib.ActionEntry() {
name = "about",
activate = on_about,
},
GLib.ActionEntry() {
name = "quit",
activate = on_quit,
},
};
private Settings settings = new Settings();
public App(){
Object(
application_id: Config.PLAC_APP_ID,
flags : ApplicationFlags.DEFAULT_FLAGS
);
}
protected override void activate() {
if (settings.connected_server_id == "") {
var selector = new ServerSelector.Window(this);
selector.start();
} else {
var main_window = new MainWindow.from_server_id(this, settings.connected_server_id);
main_window.start();
}
}
public static int main(string[] args) {
return new App().run(args);
}
private void on_preferences() {
var startup_category_factory = new Gtk.SignalListItemFactory();
startup_category_factory.setup.connect(CategoryComboRowFactory.setup);
startup_category_factory.bind.connect(CategoryComboRowFactory.bind);
var startup_category_model = new Adw.EnumListModel(typeof (Roon.Browse.Hierarchy));
var startup_category = new Adw.ComboRow();
startup_category.model = startup_category_model;
startup_category.factory = startup_category_factory;
startup_category.title = "Default category";
startup_category.subtitle = "Category to be selected on startup.";
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);
var general = new Adw.PreferencesGroup();
general.add(startup_category);
general.title = "General";
var disable_csd = new Adw.SwitchRow();
settings.settings.bind(Settings.DISABLE_CSD, disable_csd, "active", DEFAULT);
disable_csd.title = "Hide window titlebar";
disable_csd.subtitle = "Hide window control buttons and title. Menu button and sidebar button remain.";
var label_parsing_enabled = new Adw.SwitchRow();
settings.settings.bind(Settings.LABEL_PARSING_ENABLED, label_parsing_enabled, "active", DEFAULT);
label_parsing_enabled.title = "Parse labels";
label_parsing_enabled.subtitle = "Enable parsing of \"[[id|text]]\" labels in browse section.";
var show_browse_item_separators = new Adw.SwitchRow();
settings.settings.bind(Settings.SHOW_BROWSE_ITEM_SEPARATORS, show_browse_item_separators, "active", DEFAULT);
show_browse_item_separators.title = "Show separators for browse items";
show_browse_item_separators.subtitle = "Show separator between browse items.";
var show_seek_by_10secs = new Adw.SwitchRow();
settings.settings.bind(Settings.SHOW_SEEK_BY_10SECS, show_seek_by_10secs, "active", DEFAULT);
show_seek_by_10secs.title = "Show seek by 10secs buttons";
show_seek_by_10secs.subtitle = "Show buttons that seek forward/backwards by 10 seconds.";
var show_stop_button = new Adw.SwitchRow();
settings.settings.bind(Settings.SHOW_STOP_BUTTON, show_stop_button, "active", DEFAULT);
show_stop_button.title = "Show stop button";
show_stop_button.subtitle = "Show stop button next to play/pause button. Stopping playback releases audio device immediately.";
var appearance = new Adw.PreferencesGroup();
appearance.add(disable_csd);
appearance.add(label_parsing_enabled);
appearance.add(show_browse_item_separators);
appearance.add(show_seek_by_10secs);
appearance.add(show_stop_button);
appearance.title = "Appearance";
var focus_browse_items_on_load = new Adw.SwitchRow();
settings.settings.bind(Settings.FOCUS_BROWSE_ITEMS_ON_LOAD, focus_browse_items_on_load, "active", DEFAULT);
focus_browse_items_on_load.title = "Focus browse items on load";
focus_browse_items_on_load.subtitle = "Move focus to the first browse item or search entry right after the page is loaded.";
var seek_step_size = new Adw.EntryRow();
seek_step_size.title = "Seekbar step size";
seek_step_size.input_purpose = NUMBER;
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);
seek_step_size.add_suffix(new Gtk.Label("secs."));
var seek_page_size = new Adw.EntryRow();
seek_page_size.title = "Seekbar jump size";
seek_page_size.input_purpose = NUMBER;
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);
seek_page_size.add_suffix(new Gtk.Label("secs."));
var keyboard_navigation = new Adw.PreferencesGroup();
keyboard_navigation.add(focus_browse_items_on_load);
keyboard_navigation.add(seek_step_size);
keyboard_navigation.add(seek_page_size);
keyboard_navigation.title = "Keyboard Navigation";
var fixed_discovery_udp_port_enabled = new Adw.SwitchRow();
fixed_discovery_udp_port_enabled.title = "Use fixed UDP port";
fixed_discovery_udp_port_enabled.subtitle =
"Fix UDP port number to use for sending and receiving of Roon Server discovery. If this option is off, Plac will pick a random available UDP port. Requires restart to take effect.";
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);
var discovery_udp_port = new Adw.EntryRow();
discovery_udp_port.title = "Port number";
discovery_udp_port.input_purpose = NUMBER;
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);
var discovery = new Adw.PreferencesGroup();
discovery.add(fixed_discovery_udp_port_enabled);
discovery.add(discovery_udp_port);
discovery.title = "Server Discovery";
var page = new Adw.PreferencesPage();
page.add(general);
page.add(appearance);
page.add(keyboard_navigation);
page.add(discovery);
var dialog = new Adw.PreferencesDialog();
dialog.add(page);
dialog.present(this.active_window);
}
private void on_about() {
var dialog = new Adw.AboutDialog.from_appdata("/jp/pocka/plac/gtk-adwaita/metainfo.xml", null);
dialog.copyright = "Copyright 2025 Shota FUJI";
dialog.version = Config.PLAC_APP_VERSION;
dialog.present(this.active_window);
}
private void on_quit() {
this.quit();
}
public override void startup() {
base.startup();
this.add_action_entries(app_entries, this);
}
}
class CategoryComboRowFactory {
public static void setup(Gtk.ListItemFactory factory, Object object) {
var list_item = (Gtk.ListItem) object;
list_item.child = new Gtk.Label("");
}
public static void bind(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();
}
}
[GtkTemplate(ui = "/jp/pocka/plac/gtk-adwaita/ui/server-list-network-error-dialog.ui")]
class ServerListNetworkErrorDialog : GenericErrorDialog {
public ServerListNetworkErrorDialog(string details) {
Object(details: details);
}
}
[GtkTemplate(ui = "/jp/pocka/plac/gtk-adwaita/ui/server-connecting.ui")]
class ServerConnecting : Gtk.Box {
public ServerConnecting() {
Object();
}
}
}