File: menu_prefs.c

package info (click to toggle)
brltty 6.8-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,776 kB
  • sloc: ansic: 150,447; java: 13,484; sh: 9,667; xml: 5,702; tcl: 2,634; makefile: 2,328; awk: 713; lisp: 366; python: 321; ml: 301
file content (1861 lines) | stat: -rw-r--r-- 53,707 bytes parent folder | download | duplicates (2)
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
/*
 * BRLTTY - A background process providing access to the console screen (when in
 *          text mode) for a blind person using a refreshable braille display.
 *
 * Copyright (C) 1995-2025 by The BRLTTY Developers.
 *
 * BRLTTY comes with ABSOLUTELY NO WARRANTY.
 *
 * This is free software, placed under the terms of the
 * GNU Lesser General Public License, as published by the Free Software
 * Foundation; either version 2.1 of the License, or (at your option) any
 * later version. Please see the file LICENSE-LGPL for details.
 *
 * Web Page: http://brltty.app/
 *
 * This software is maintained by Dave Mielke <dave@mielke.cc>.
 */

#include "prologue.h"

#include <stdio.h>
#include <string.h>

#include "log.h"
#include "log_history.h"
#include "embed.h"
#include "revision.h"
#include "api_control.h"
#include "menu.h"
#include "menu_prefs.h"
#include "prefs.h"
#include "file.h"
#include "profile.h"
#include "status_types.h"
#include "blink.h"
#include "timing.h"
#include "brl.h"
#include "spk.h"
#include "ttb.h"
#include "ctb.h"
#include "atb.h"
#include "ktb.h"
#include "tune.h"
#include "bell.h"
#include "leds.h"
#include "midi.h"
#include "options.h"
#include "core.h"

#define PREFS_MENU_ITEM_VARIABLE(name) prefsMenuItemVariable_##name
#define PREFS_MENU_ITEM_GETTER_DECLARE(name) \
static MenuItem *PREFS_MENU_ITEM_VARIABLE(name) = NULL; \
PREFS_MENU_ITEM_GETTER_PROTOTYPE(name) { \
  return getPreferencesMenu()? PREFS_MENU_ITEM_VARIABLE(name): NULL; \
}

PREFS_MENU_ITEM_APPLY(PREFS_MENU_ITEM_GETTER_DECLARE)

#define NAME(name) static const MenuString itemName = {.label=name}
#define ITEM(new) MenuItem *item = (new); if (!item) goto noItem
#define TEST(property) setMenuItemTester(item, test##property)
#define CHANGED(property) setMenuItemChanged(item, changed##property)
#define SET(name) PREFS_MENU_ITEM_VARIABLE(name) = item

#define SUBMENU(variable, parent, name) \
  NAME(name); \
  Menu *variable = newSubmenuMenuItem(parent, &itemName); \
  if (!variable) goto noItem

#define PROPERTY(variable, value) \
  static unsigned char variable; \
  variable = (value)

#define BLINK_PERIOD(blink) PROPERTY(period, MSECS2PREFS(getBlinkPeriod((blink))))
#define BLINK_VISIBLE(blink) PROPERTY(visible, getBlinkPercentVisible((blink)))

static int
testAdvancedSubmenu (void) {
  return prefs.showAdvancedSubmenus;
}

static void
setAdvancedSubmenu (Menu *submenu) {
  Menu *parent = getMenuParent(submenu);

  if (parent) {
    unsigned int size = getMenuSize(parent);

    if (size) {
      MenuItem *item = getMenuItem(parent, size-1);

      if (item) setMenuItemTester(item, testAdvancedSubmenu);
    }
  }
}

static int
testSlidingBrailleWindow (void) {
  return prefs.slidingBrailleWindow;
}

static int
changedBrailleWindowOverlap (const MenuItem *item UNUSED, unsigned char setting) {
  if (setting >= textCount) return 0;
  reconfigureBrailleWindow();
  return 1;
}

static int
changedAutoreleaseTime (const MenuItem *item UNUSED, unsigned char setting) {
  if (brl.keyTable) setKeyAutoreleaseTime(brl.keyTable, setting);
  return 1;
}

static int
testAutorepeatEnabled (void) {
  return prefs.autorepeatEnabled;
}

static int
changeAutorepeatProperties (BrailleDisplay *brl, int on, int delay, int interval) {
  if (!canSetAutorepeatProperties(brl)) return 1;
  return setAutorepeatProperties(brl, on, delay, interval);
}

static int
changedAutorepeatEnabled (const MenuItem *item UNUSED, unsigned char setting) {
  return changeAutorepeatProperties(&brl, setting,
                                    PREFS2MSECS(prefs.longPressTime),
                                    PREFS2MSECS(prefs.autorepeatInterval));
}

static int
changedAutorepeatDelay (const MenuItem *item UNUSED, unsigned char setting) {
  return changeAutorepeatProperties(&brl, prefs.autorepeatEnabled,
                                    setting,
                                    PREFS2MSECS(prefs.autorepeatInterval));
}

static int
changedAutorepeatInterval (const MenuItem *item UNUSED, unsigned char setting) {
  return changeAutorepeatProperties(&brl, prefs.autorepeatEnabled,
                                    PREFS2MSECS(prefs.longPressTime),
                                    setting);
}

static int
testShowScreenCursor (void) {
  return prefs.showScreenCursor;
}

static int
testBlinkingScreenCursor (void) {
  return testShowScreenCursor() && prefs.blinkingScreenCursor;
}

static int
changedScreenCursorBlinkPeriod (const MenuItem *item UNUSED, unsigned char setting) {
  setBlinkPeriod(&screenCursorBlinkDescriptor, PREFS2MSECS(setting));
  return 1;
}

static int
changedScreenCursorBlinkPercentage (const MenuItem *item UNUSED, unsigned char setting) {
  return setBlinkPercentVisible(&screenCursorBlinkDescriptor, setting);
}

static int
testShowAttributes (void) {
  return prefs.showAttributes;
}

static int
testBlinkingAttributes (void) {
  return testShowAttributes() && prefs.blinkingAttributes;
}

static int
changedAttributesUnderlineBlinkPeriod (const MenuItem *item UNUSED, unsigned char setting) {
  setBlinkPeriod(&attributesUnderlineBlinkDescriptor, PREFS2MSECS(setting));
  return 1;
}

static int
changedAttributesUnderlineBlinkPercentage (const MenuItem *item UNUSED, unsigned char setting) {
  return setBlinkPercentVisible(&attributesUnderlineBlinkDescriptor, setting);
}

static int
testBlinkingCapitals (void) {
  return prefs.blinkingCapitals;
}

static int
changedUppercaseLettersBlinkPeriod (const MenuItem *item UNUSED, unsigned char setting) {
  setBlinkPeriod(&uppercaseLettersBlinkDescriptor, PREFS2MSECS(setting));
  return 1;
}

static int
changedUppercaseLettersBlinkPercentage (const MenuItem *item UNUSED, unsigned char setting) {
  return setBlinkPercentVisible(&uppercaseLettersBlinkDescriptor, setting);
}

static int
testBrailleFirmness (void) {
  return canSetBrailleFirmness(&brl);
}

static int
changedBrailleFirmness (const MenuItem *item UNUSED, unsigned char setting) {
  return setBrailleFirmness(&brl, setting);
}

static int
testTouchSensitivity (void) {
  return canSetTouchSensitivity(&brl);
}

static int
changedTouchSensitivity (const MenuItem *item UNUSED, unsigned char setting) {
  return setTouchSensitivity(&brl, setting);
}

static int
testConsoleBellAlert (void) {
  return canMonitorConsoleBell();
}

static int
changedConsoleBellAlert (const MenuItem *item UNUSED, unsigned char setting) {
  return setConsoleBellMonitoring(setting);
}

static int
testKeyboardLedAlerts (void) {
  return canMonitorLeds();
}

static int
changedKeyboardLedAlerts (const MenuItem *item UNUSED, unsigned char setting) {
  return setLedMonitoring(setting);
}

static int
testAlertTunes (void) {
  return prefs.alertTunes;
}

static int
changedAlertTunes (const MenuItem *item UNUSED, unsigned char setting) {
  api.updateParameter(BRLAPI_PARAM_AUDIBLE_ALERTS, 0);
  return 1;
}

static int
changedTuneDevice (const MenuItem *item UNUSED, unsigned char setting) {
  return tuneSetDevice(setting);
}

#ifdef HAVE_PCM_SUPPORT
static int
testTunesPcm (void) {
  return testAlertTunes() && (prefs.tuneDevice == tdPcm);
}
#endif /* HAVE_PCM_SUPPORT */

#ifdef HAVE_MIDI_SUPPORT
static int
testTunesMidi (void) {
  return testAlertTunes() && (prefs.tuneDevice == tdMidi);
}
#endif /* HAVE_MIDI_SUPPORT */

#ifdef HAVE_FM_SUPPORT
static int
testTunesFm (void) {
  return testAlertTunes() && (prefs.tuneDevice == tdFm);
}
#endif /* HAVE_FM_SUPPORT */

#ifdef ENABLE_SPEECH_SUPPORT
static int
testSpeechVolume (void) {
  return canSetSpeechVolume(&spk);
}

static int
changedSpeechVolume (const MenuItem *item UNUSED, unsigned char setting) {
  return setSpeechVolume(&spk, setting, !prefs.autospeak);
}

static void
formatSpeechVolume (Menu *menu, unsigned char volume, char *buffer, size_t size) {
  snprintf(
    buffer, size, "%d", toNormalizedSpeechVolume(volume)
  );
}

static int
testSpeechRate (void) {
  return canSetSpeechRate(&spk);
}

static int
changedSpeechRate (const MenuItem *item UNUSED, unsigned char setting) {
  return setSpeechRate(&spk, setting, !prefs.autospeak);
}

static void
formatSpeechRate (Menu *menu, unsigned char rate, char *buffer, size_t size) {
  snprintf(
    buffer, size, "%d", toNormalizedSpeechRate(rate)
  );
}

static int
testSpeechPitch (void) {
  return canSetSpeechPitch(&spk);
}

static int
changedSpeechPitch (const MenuItem *item UNUSED, unsigned char setting) {
  return setSpeechPitch(&spk, setting, !prefs.autospeak);
}

static void
formatSpeechPitch (Menu *menu, unsigned char pitch, char *buffer, size_t size) {
  snprintf(
    buffer, size, "%d", toNormalizedSpeechPitch(pitch)
  );
}

static int
testSpeechPunctuation (void) {
  return canSetSpeechPunctuation(&spk);
}

static int
changedSpeechPunctuation (const MenuItem *item UNUSED, unsigned char setting) {
  return setSpeechPunctuation(&spk, setting, !prefs.autospeak);
}

static int
testAutospeak (void) {
  return prefs.autospeak;
}

static int
testShowSpeechCursor (void) {
  return prefs.showSpeechCursor;
}

static int
testBlinkingSpeechCursor (void) {
  return testShowSpeechCursor() && prefs.blinkingSpeechCursor;
}

static int
changedSpeechCursorBlinkPeriod (const MenuItem *item UNUSED, unsigned char setting) {
  setBlinkPeriod(&speechCursorBlinkDescriptor, PREFS2MSECS(setting));
  return 1;
}

static int
changedSpeechCursorBlinkPercentage (const MenuItem *item UNUSED, unsigned char setting) {
  return setBlinkPercentVisible(&speechCursorBlinkDescriptor, setting);
}
#endif /* ENABLE_SPEECH_SUPPORT */

static int
testShowDate (void) {
  return prefs.datePosition != dpNone;
}

static int
testStatusPosition (void) {
  return !haveStatusCells();
}

static int
changedStatusPosition (const MenuItem *item UNUSED, unsigned char setting UNUSED) {
  reconfigureBrailleWindow();
  return 1;
}

static int
testStatusCount (void) {
  return testStatusPosition() && (prefs.statusPosition != spNone);
}

static int
changedStatusCount (const MenuItem *item UNUSED, unsigned char setting UNUSED) {
  reconfigureBrailleWindow();
  return 1;
}

static int
testStatusSeparator (void) {
  return testStatusCount();
}

static int
changedStatusSeparator (const MenuItem *item UNUSED, unsigned char setting UNUSED) {
  reconfigureBrailleWindow();
  return 1;
}

static int
testStatusField (unsigned char index) {
  return (haveStatusCells() || (prefs.statusPosition != spNone)) &&
         ((index == 0) || (prefs.statusFields[index-1] != sfEnd));
}

static int
changedStatusField (unsigned char index, unsigned char setting) {
  switch (setting) {
    case sfGeneric:
      if (index > 0) return 0;
      if (!haveStatusCells()) return 0;
      if (!braille->statusFields) return 0;
      if (*braille->statusFields != sfGeneric) return 0;
      /* fall through */

    case sfEnd:
      if (prefs.statusFields[index+1] != sfEnd) return 0;
      break;

    default:
      if ((index > 0) && (prefs.statusFields[index-1] == sfGeneric)) return 0;
      break;
  }

  reconfigureBrailleWindow();
  return 1;
}

#define STATUS_FIELD_HANDLERS(n) \
  static int testStatusField##n (void) { return testStatusField(n-1); } \
  static int changedStatusField##n (const MenuItem *item UNUSED, unsigned char setting) { return changedStatusField(n-1, setting); }
STATUS_FIELD_HANDLERS(1)
STATUS_FIELD_HANDLERS(2)
STATUS_FIELD_HANDLERS(3)
STATUS_FIELD_HANDLERS(4)
STATUS_FIELD_HANDLERS(5)
STATUS_FIELD_HANDLERS(6)
STATUS_FIELD_HANDLERS(7)
STATUS_FIELD_HANDLERS(8)
STATUS_FIELD_HANDLERS(9)
#undef STATUS_FIELD_HANDLERS

static int
changedSkipIdenticalLines (const MenuItem *item, unsigned char setting UNUSED) {
  api.updateParameter(BRLAPI_PARAM_SKIP_IDENTICAL_LINES, 0);
  return 1;
}

static int
changedTextTable (const MenuItem *item, unsigned char setting UNUSED) {
  return changeTextTable(getMenuItemValue(item));
}

static int
changedAttributesTable (const MenuItem *item, unsigned char setting UNUSED) {
  return changeAttributesTable(getMenuItemValue(item));
}

static int
changedKeyboardTable (const MenuItem *item, unsigned char setting UNUSED) {
  return changeKeyboardTable(getMenuItemValue(item));
}

static int
testComputerBraille (void) {
  return !isContractedBraille();
}

static int
testContractedBraille (void) {
  return isContractedBraille();
}

static int
changedContractedBraille (const MenuItem *item, unsigned char setting UNUSED) {
  setContractedBraille(setting);
  api.updateParameter(BRLAPI_PARAM_LITERARY_BRAILLE, 0);
  return 1;
}

static int
changedContractionTable (const MenuItem *item, unsigned char setting UNUSED) {
  return changeContractionTable(getMenuItemValue(item));
}

static int
changedComputerBraille (const MenuItem *item, unsigned char setting UNUSED) {
  setSixDotComputerBraille(setting);
  api.updateParameter(BRLAPI_PARAM_COMPUTER_BRAILLE_CELL_SIZE, 0);
  return 1;
}

static int
testInputTable (void) {
  return !!brl.keyTable;
}

static int
testKeyboardTable (void) {
  return !!keyboardTable;
}

static MenuItem *
newProfileMenuItem (Menu *menu, const ProfileDescriptor *profile) {
  MenuString name = {.label = profile->category};

  return newFilesMenuItem(menu, &name, opt_tablesDirectory, PROFILES_SUBDIRECTORY, profile->extension, "", 1);
}

static int
changedProfile (const ProfileDescriptor *profile, const MenuItem *item) {
  const char *value = getMenuItemValue(item);

  if (*value) {
    activateProfile(profile, opt_tablesDirectory, value);
  } else {
    deactivateProfile(profile);
  }

  return 1;
}

static int
changedLanguageProfile (const MenuItem *item, unsigned char setting UNUSED) {
  return changedProfile(&languageProfile, item);
}

static MenuItem *
newStatusFieldMenuItem (
  Menu *menu, unsigned char number,
  MenuItemTester *test, MenuItemChanged *changed
) {
  static const MenuString strings[] = {
    [sfEnd] = {.label=strtext("End")},
    [sfWindowCoordinates2] = {.label=strtext("Window Coordinates"), .comment=strtext("2 cells")},
    [sfWindowColumn] = {.label=strtext("Window Column"), .comment=strtext("1 cell")},
    [sfWindowRow] = {.label=strtext("Window Row"), .comment=strtext("1 cell")},
    [sfCursorCoordinates2] = {.label=strtext("Cursor Coordinates"), .comment=strtext("2 cells")},
    [sfCursorColumn] = {.label=strtext("Cursor Column"), .comment=strtext("1 cell")},
    [sfCursorRow] = {.label=strtext("Cursor Row"), .comment=strtext("1 cell")},
    [sfCursorAndWindowColumn2] = {.label=strtext("Cursor and Window Column"), .comment=strtext("2 cells")},
    [sfCursorAndWindowRow2] = {.label=strtext("Cursor and Window Row"), .comment=strtext("2 cells")},
    [sfScreenNumber] = {.label=strtext("Screen Number"), .comment=strtext("1 cell")},
    [sfStateDots] = {.label=strtext("State Dots"), .comment=strtext("1 cell")},
    [sfStateLetter] = {.label=strtext("State Letter"), .comment=strtext("1 cell")},
    [sfTime] = {.label=strtext("Time"), .comment=strtext("2 cells")},
    [sfAlphabeticWindowCoordinates] = {.label=strtext("Alphabetic Window Coordinates"), .comment=strtext("1 cell")},
    [sfAlphabeticCursorCoordinates] = {.label=strtext("Alphabetic Cursor Coordinates"), .comment=strtext("1 cell")},
    [sfGeneric] = {.label=strtext("Generic")},
    [sfCursorCoordinates3] = {.label=strtext("Cursor Coordinates"), .comment=strtext("3 cells")},
    [sfWindowCoordinates3] = {.label=strtext("Window Coordinates"), .comment=strtext("3 cells")},
    [sfCursorAndWindowColumn3] = {.label=strtext("Cursor and Window Column"), .comment=strtext("3 cells")},
    [sfCursorAndWindowRow3] = {.label=strtext("Cursor and Window Row"), .comment=strtext("3 cells")},
    [sfSpace] = {.label=strtext("Space"), .comment=strtext("1 cell")},
  };

  MenuString name = {
    .label = strtext("Status Field")
  };

  char *comment;
  {
    char buffer[0X3];
    snprintf(buffer, sizeof(buffer), "%u", number);
    name.comment = comment = strdup(buffer);
  }

  if (comment) {
    MenuItem *item = newEnumeratedMenuItem(menu, &prefs.statusFields[number-1], &name, strings);

    if (item) {
      setMenuItemTester(item, test);
      setMenuItemChanged(item, changed);
      return item;
    }

    free(comment);
  } else {
    logMallocError();
  }

  return NULL;
}

static MenuItem *
newBlinkVisibleMenuItem (Menu *menu, unsigned char *setting, const MenuString *name) {
  return newPercentMenuItem(menu, setting, name, 5);
}

#if defined(HAVE_PCM_SUPPORT) || defined(HAVE_MIDI_SUPPORT) || defined(HAVE_FM_SUPPORT)
static MenuItem *
newVolumeMenuItem (Menu *menu, unsigned char *setting, const MenuString *name) {
  return newPercentMenuItem(menu, setting, name, 5);
}
#endif /* defined(HAVE_PCM_SUPPORT) || defined(HAVE_MIDI_SUPPORT) || defined(HAVE_FM_SUPPORT) */

#ifdef HAVE_MIDI_SUPPORT
static MenuString *
makeMidiInstrumentMenuStrings (void) {
  MenuString *strings = malloc(midiInstrumentCount * sizeof(*strings));

  if (strings) {
    for (unsigned int instrument=0; instrument<midiInstrumentCount; instrument+=1) {
      MenuString *string = &strings[instrument];
      string->label = midiInstrumentTable[instrument];
      string->comment = midiGetInstrumentGroup(instrument);
    }
  }

  return strings;
}
#endif /* HAVE_MIDI_SUPPORT */

static Menu *logMessagesMenu = NULL;
static const LogEntry *newestLogMessage = NULL;

static int
addNewLogMessages (const LogEntry *message) {
  if (message == newestLogMessage) return 1;
  if (!addNewLogMessages(getPreviousLogEntry(message))) return 0;

  MenuString name;
  const TimeValue *time = getLogEntryTime(message);
  unsigned int count = getLogEntryCount(message);

  if (time) {
    char buffer[0X20];
    formatSeconds(buffer, sizeof(buffer), "%Y-%m-%d@%H:%M:%S", time->seconds);
    name.label = strdup(buffer);
  } else {
    name.label = NULL;
  }

  if (count > 1) {
    char buffer[0X10];
    snprintf(buffer, sizeof(buffer), "(%u)", count);
    name.comment = strdup(buffer);
  } else {
    name.comment = NULL;
  }

  MenuItem *item = newTextMenuItem(logMessagesMenu, &name, getLogEntryText(message));
  if (!item) return 0;

  newestLogMessage = message;
  return 1;
}

int
updateLogMessagesSubmenu (void) {
  return addNewLogMessages(getNewestLogMessage(1));
}

static Menu *
makePreferencesMenu (void) {
  static const MenuString cursorStyles[] = {
    [csBottomDots] = {.label=strtext("Underline"), .comment=strtext("dots 7 and 8")},
    [csAllDots] = {.label=strtext("Block"), .comment=strtext("all dots")},
    [csLowerLeftDot] = {.label=strtext("Lower Left Dot"), .comment=strtext("dot 7")},
    [csLowerRightDot] = {.label=strtext("Lower Right Dot"), .comment=strtext("dot 8")},
    [csNoDots] = {.label=strtext("Hide"), .comment=strtext("no dots")},
  };

  Menu *rootMenu = newMenu();
  if (!rootMenu) goto noMenu;

  {
    NAME(strtext("Save on Exit"));
    ITEM(newBooleanMenuItem(rootMenu, &prefs.saveOnExit, &itemName));
  }

  {
    SUBMENU(menuSubmenu, rootMenu, strtext("Menu Options"));

    {
      NAME(strtext("Show Submenu Sizes"));
      ITEM(newBooleanMenuItem(menuSubmenu, &prefs.showSubmenuSizes, &itemName));
    }

    {
      NAME(strtext("Show Advanced Submenus"));
      ITEM(newBooleanMenuItem(menuSubmenu, &prefs.showAdvancedSubmenus, &itemName));
    }

    {
      NAME(strtext("Show All Items"));
      ITEM(newBooleanMenuItem(menuSubmenu, &prefs.showAllItems, &itemName));
    }
  }

  {
    SUBMENU(presentationSubmenu, rootMenu, strtext("Braille Presentation"));

    {
      static const MenuString strings[] = {
        {.label=strtext("Computer Braille")},
        {.label=strtext("Contracted Braille")},
      };

      NAME(strtext("Braille Variant"));
      PROPERTY(yes, isContractedBraille());
      ITEM(newEnumeratedMenuItem(presentationSubmenu, &yes, &itemName, strings));
      CHANGED(ContractedBraille);
    }

    {
      NAME(strtext("Expand Current Word"));
      ITEM(newBooleanMenuItem(presentationSubmenu, &prefs.expandCurrentWord, &itemName));
      TEST(ContractedBraille);
    }

    {
      static const MenuString strings[] = {
        [CTB_CAP_NONE] = {.label=strtext("No Capitalization")},
        [CTB_CAP_SIGN] = {.label=strtext("Use Capital Sign")},
        [CTB_CAP_DOT7] = {.label=strtext("Superimpose Dot 7")},
      };

      NAME(strtext("Capitalization Mode"));
      ITEM(newEnumeratedMenuItem(presentationSubmenu, &prefs.capitalizationMode, &itemName, strings));
      TEST(ContractedBraille);
    }

    {
      static const MenuString strings[] = {
        {.label=strtext("8-dot")},
        {.label=strtext("6-dot")},
      };

      NAME(strtext("Computer Braille Cell Type"));
      PROPERTY(yes, isSixDotComputerBraille());
      ITEM(newEnumeratedMenuItem(presentationSubmenu, &yes, &itemName, strings));
      TEST(ComputerBraille);
      CHANGED(ComputerBraille);
    }

    {
      static const MenuString strings[] = {
        [BRL_FIRMNESS_MINIMUM] = {.label=strtext("Minimum")},
        [BRL_FIRMNESS_LOW] = {.label=strtext("Low")},
        [BRL_FIRMNESS_MEDIUM] = {.label=strtext("Medium")},
        [BRL_FIRMNESS_HIGH] = {.label=strtext("High")},
        [BRL_FIRMNESS_MAXIMUM] = {.label=strtext("Maximum")},
      };

      NAME(strtext("Braille Firmness"));
      ITEM(newEnumeratedMenuItem(presentationSubmenu, &prefs.brailleFirmness, &itemName, strings));
      TEST(BrailleFirmness);
      CHANGED(BrailleFirmness);
    }
  }

  {
    SUBMENU(indicatorsSubmenu, rootMenu, strtext("Text Indicators"));

    {
      NAME(strtext("Show Screen Cursor"));
      ITEM(newBooleanMenuItem(indicatorsSubmenu, &prefs.showScreenCursor, &itemName));
    }

    {
      NAME(strtext("Screen Cursor Style"));
      ITEM(newEnumeratedMenuItem(indicatorsSubmenu, &prefs.screenCursorStyle, &itemName, cursorStyles));
      TEST(ShowScreenCursor);
    }

    {
      NAME(strtext("Blinking Screen Cursor"));
      ITEM(newBooleanMenuItem(indicatorsSubmenu, &prefs.blinkingScreenCursor, &itemName));
      TEST(ShowScreenCursor);
    }

    {
      NAME(strtext("Screen Cursor Blink Period"));
      BLINK_PERIOD(&screenCursorBlinkDescriptor);
      ITEM(newTimeMenuItem(indicatorsSubmenu, &period, &itemName));
      TEST(BlinkingScreenCursor);
      CHANGED(ScreenCursorBlinkPeriod);
    }

    {
      NAME(strtext("Screen Cursor Percent Visible"));
      BLINK_VISIBLE(&screenCursorBlinkDescriptor);
      ITEM(newBlinkVisibleMenuItem(indicatorsSubmenu, &visible, &itemName));
      TEST(BlinkingScreenCursor);
      CHANGED(ScreenCursorBlinkPercentage);
    }

    {
      NAME(strtext("Show Attributes"));
      ITEM(newBooleanMenuItem(indicatorsSubmenu, &prefs.showAttributes, &itemName));
    }

    {
      NAME(strtext("Blinking Attributes"));
      ITEM(newBooleanMenuItem(indicatorsSubmenu, &prefs.blinkingAttributes, &itemName));
      TEST(ShowAttributes);
    }

    {
      NAME(strtext("Attributes Blink Period"));
      BLINK_PERIOD(&attributesUnderlineBlinkDescriptor);
      ITEM(newTimeMenuItem(indicatorsSubmenu, &period, &itemName));
      TEST(BlinkingAttributes);
      CHANGED(AttributesUnderlineBlinkPeriod);
    }

    {
      NAME(strtext("Attributes Percent Visible"));
      BLINK_VISIBLE(&attributesUnderlineBlinkDescriptor);
      ITEM(newBlinkVisibleMenuItem(indicatorsSubmenu, &visible, &itemName));
      TEST(BlinkingAttributes);
      CHANGED(AttributesUnderlineBlinkPercentage);
    }

    {
      NAME(strtext("Blinking Capitals"));
      ITEM(newBooleanMenuItem(indicatorsSubmenu, &prefs.blinkingCapitals, &itemName));
    }

    {
      NAME(strtext("Capitals Blink Period"));
      BLINK_PERIOD(&uppercaseLettersBlinkDescriptor);
      ITEM(newTimeMenuItem(indicatorsSubmenu, &period, &itemName));
      TEST(BlinkingCapitals);
      CHANGED(UppercaseLettersBlinkPeriod);
    }

    {
      NAME(strtext("Capitals Percent Visible"));
      BLINK_VISIBLE(&uppercaseLettersBlinkDescriptor);
      ITEM(newBlinkVisibleMenuItem(indicatorsSubmenu, &visible, &itemName));
      TEST(BlinkingCapitals);
      CHANGED(UppercaseLettersBlinkPercentage);
    }
  }

  {
    SUBMENU(navigationSubmenu, rootMenu, strtext("Navigation Options"));

    {
      NAME(strtext("Word Wrap"));
      ITEM(newBooleanMenuItem(navigationSubmenu, &prefs.wordWrap, &itemName));
    }

    {
      NAME(strtext("Skip Identical Lines"));
      ITEM(newBooleanMenuItem(navigationSubmenu, &prefs.skipIdenticalLines, &itemName));
      CHANGED(SkipIdenticalLines);
    }

    {
      NAME(strtext("Skip Blank Braille Windows"));
      ITEM(newBooleanMenuItem(navigationSubmenu, &prefs.skipBlankBrailleWindows, &itemName));
    }

    {
      static const MenuString strings[] = {
        [sbwAll] = {.label=strtext("All")},
        [sbwEndOfLine] = {.label=strtext("End of Line")},
        [sbwRestOfLine] = {.label=strtext("Rest of Line")},
      };

      NAME(strtext("Skip Which Blank Braille Windows"));
      ITEM(newEnumeratedMenuItem(navigationSubmenu, &prefs.skipBlankBrailleWindowsMode, &itemName, strings));
    }

    {
      NAME(strtext("Sliding Braille Window"));
      ITEM(newBooleanMenuItem(navigationSubmenu, &prefs.slidingBrailleWindow, &itemName));
    }

    {
      NAME(strtext("Eager Sliding Braille Window"));
      ITEM(newBooleanMenuItem(navigationSubmenu, &prefs.eagerSlidingBrailleWindow, &itemName));
      TEST(SlidingBrailleWindow);
    }

    {
      NAME(strtext("Braille Window Overlap"));
      ITEM(newNumericMenuItem(navigationSubmenu, &prefs.brailleWindowOverlap, &itemName, 0, 20, 1, strtext("cells"), NULL));
      CHANGED(BrailleWindowOverlap);
    }

    {
      NAME(strtext("Scroll-aware Cursor Navigation"));
      ITEM(newBooleanMenuItem(navigationSubmenu, &prefs.scrollAwareCursorNavigation, &itemName));
    }

    {
      static const MenuString strings[] = {
        [ctdNone] = {.label=strtext("None")},
        [ctd250ms] = {.label=strtext("250 milliseconds")},
        [ctd500ms] = {.label=strtext("500 milliseconds")},
        [ctd1s] = {.label=strtext("1 second")},
        [ctd2s] = {.label=strtext("2 seconds")},
      };

      NAME(strtext("Cursor Tracking Delay"));
      ITEM(newEnumeratedMenuItem(navigationSubmenu, &prefs.cursorTrackingDelay, &itemName, strings));
    }

    {
      NAME(strtext("Track Screen Scroll"));
      ITEM(newBooleanMenuItem(navigationSubmenu, &prefs.trackScreenScroll, &itemName));
    }

  #ifdef HAVE_LIBGPM
    {
      NAME(strtext("Track Screen Pointer"));
      ITEM(newBooleanMenuItem(navigationSubmenu, &prefs.trackScreenPointer, &itemName));
    }
  #endif /* HAVE_LIBGPM */

    {
      NAME(strtext("Highlight Braille Window Location"));
      ITEM(newBooleanMenuItem(navigationSubmenu, &prefs.highlightBrailleWindowLocation, &itemName));
    }

    {
      NAME(strtext("Start Selection with Routing Key"));
      ITEM(newBooleanMenuItem(navigationSubmenu, &prefs.startSelectionWithRoutingKey, &itemName));
    }
  }

  {
    SUBMENU(typingSubmenu, rootMenu, strtext("Braille Typing"));

    {
      NAME(strtext("Keyboard Enabled"));
      ITEM(newBooleanMenuItem(typingSubmenu, &prefs.brailleKeyboardEnabled, &itemName));
    }

    {
      static const MenuString strings[] = {
        [BRL_TYPING_TEXT] = {.label=strtext("Translated via Text Table")},
        [BRL_TYPING_DOTS] = {.label=strtext("Dots via Unicode Braille")},
      };

      NAME(strtext("Typing Mode"));
      ITEM(newEnumeratedMenuItem(typingSubmenu, &prefs.brailleTypingMode, &itemName, strings));
    }

    {
      NAME(strtext("Quick Space"));
      ITEM(newBooleanMenuItem(typingSubmenu, &prefs.brailleQuickSpace, &itemName));
    }
  }

  {
    SUBMENU(inputSubmenu, rootMenu, strtext("Input Options"));

    {
      static const MenuString strings[] = {
        [atOff] = {.label=strtext("Off")},
        [at5s] = {.label=strtext("5 seconds")},
        [at10s] = {.label=strtext("10 seconds")},
        [at20s] = {.label=strtext("20 seconds")},
        [at40s] = {.label=strtext("40 seconds")},
      };

      NAME(strtext("Autorelease Time"));
      ITEM(newEnumeratedMenuItem(inputSubmenu, &prefs.autoreleaseTime, &itemName, strings));
      CHANGED(AutoreleaseTime);
    }

    {
      NAME(strtext("On First Release"));
      ITEM(newBooleanMenuItem(inputSubmenu, &prefs.onFirstRelease, &itemName));
    }

    {
      NAME(strtext("Long Press Time"));
      ITEM(newTimeMenuItem(inputSubmenu, &prefs.longPressTime, &itemName));
      CHANGED(AutorepeatDelay);
    }

    {
      NAME(strtext("Autorepeat Enabled"));
      ITEM(newBooleanMenuItem(inputSubmenu, &prefs.autorepeatEnabled, &itemName));
      CHANGED(AutorepeatEnabled);
    }

    {
      NAME(strtext("Autorepeat Interval"));
      ITEM(newTimeMenuItem(inputSubmenu, &prefs.autorepeatInterval, &itemName));
      TEST(AutorepeatEnabled);
      CHANGED(AutorepeatInterval);
    }

    {
      NAME(strtext("Autorepeat Panning"));
      ITEM(newBooleanMenuItem(inputSubmenu, &prefs.autorepeatPanning, &itemName));
      TEST(AutorepeatEnabled);
    }

    {
      NAME(strtext("Alternate Paste Mode Enabled"));
      ITEM(newBooleanMenuItem(inputSubmenu, &prefs.alternatePasteModeEnabled, &itemName));
    }

    {
      NAME(strtext("Touch Navigation"));
      ITEM(newBooleanMenuItem(inputSubmenu, &prefs.touchNavigation, &itemName));
      TEST(TouchSensitivity);
    }

    {
      static const MenuString strings[] = {
        [BRL_SENSITIVITY_MINIMUM] = {.label=strtext("Minimum")},
        [BRL_SENSITIVITY_LOW] = {.label=strtext("Low")},
        [BRL_SENSITIVITY_MEDIUM] = {.label=strtext("Medium")},
        [BRL_SENSITIVITY_HIGH] = {.label=strtext("High")},
        [BRL_SENSITIVITY_MAXIMUM] = {.label=strtext("Maximum")},
      };

      NAME(strtext("Touch Sensitivity"));
      ITEM(newEnumeratedMenuItem(inputSubmenu, &prefs.touchSensitivity, &itemName, strings));
      TEST(TouchSensitivity);
      CHANGED(TouchSensitivity);
    }

    {
      NAME(strtext("Keyboard Table"));
      ITEM(newFilesMenuItem(inputSubmenu, &itemName, opt_tablesDirectory, KEYBOARD_TABLES_SUBDIRECTORY, KEY_TABLE_EXTENSION, opt_keyboardTable, 1));
      CHANGED(KeyboardTable);
      SET(keyboardTable);
    }
  }

  {
    SUBMENU(alertsSubmenu, rootMenu, strtext("Event Alerts"));

    {
      NAME(strtext("Console Bell Alert"));
      ITEM(newBooleanMenuItem(alertsSubmenu, &prefs.consoleBellAlert, &itemName));
      TEST(ConsoleBellAlert);
      CHANGED(ConsoleBellAlert);
    }

    {
      NAME(strtext("Keyboard LED Alerts"));
      ITEM(newBooleanMenuItem(alertsSubmenu, &prefs.keyboardLedAlerts, &itemName));
      TEST(KeyboardLedAlerts);
      CHANGED(KeyboardLedAlerts);
    }

    {
      NAME(strtext("Alert Tunes"));
      ITEM(newBooleanMenuItem(alertsSubmenu, &prefs.alertTunes, &itemName));
      CHANGED(AlertTunes);
    }

    {
      static const MenuString strings[] = {
        [tdBeeper] = {.label=strtext("Beeper"), .comment=strtext("console tone generator")},
        [tdPcm] = {.label=strtext("PCM"), .comment=strtext("soundcard digital audio")},
        [tdMidi] = {.label=strtext("MIDI"), .comment=strtext("Musical Instrument Digital Interface")},
        [tdFm] = {.label=strtext("FM"), .comment=strtext("soundcard synthesizer")},
      };

      NAME(strtext("Tune Device"));
      ITEM(newEnumeratedMenuItem(alertsSubmenu, &prefs.tuneDevice, &itemName, strings));
      TEST(AlertTunes);
      CHANGED(TuneDevice);
    }

  #ifdef HAVE_PCM_SUPPORT
    {
      NAME(strtext("PCM Volume"));
      ITEM(newVolumeMenuItem(alertsSubmenu, &prefs.pcmVolume, &itemName));
      TEST(TunesPcm);
    }
  #endif /* HAVE_PCM_SUPPORT */

  #ifdef HAVE_MIDI_SUPPORT
    {
      NAME(strtext("MIDI Volume"));
      ITEM(newVolumeMenuItem(alertsSubmenu, &prefs.midiVolume, &itemName));
      TEST(TunesMidi);
    }

    {
      const MenuString *strings = makeMidiInstrumentMenuStrings();
      if (!strings) goto noItem;

      {
        NAME(strtext("MIDI Instrument"));
        ITEM(newStringsMenuItem(alertsSubmenu, &prefs.midiInstrument, &itemName, strings, midiInstrumentCount));
        TEST(TunesMidi);
      }
    }
  #endif /* HAVE_MIDI_SUPPORT */

  #ifdef HAVE_FM_SUPPORT
    {
      NAME(strtext("FM Volume"));
      ITEM(newVolumeMenuItem(alertsSubmenu, &prefs.fmVolume, &itemName));
      TEST(TunesFm);
    }
  #endif /* HAVE_FM_SUPPORT */

    {
      NAME(strtext("Alert Dots"));
      ITEM(newBooleanMenuItem(alertsSubmenu, &prefs.alertDots, &itemName));
    }

    {
      NAME(strtext("Alert Messages"));
      ITEM(newBooleanMenuItem(alertsSubmenu, &prefs.alertMessages, &itemName));
    }

#ifdef ENABLE_SPEECH_SUPPORT
    {
      NAME(strtext("Speak Key Context"));
      ITEM(newBooleanMenuItem(alertsSubmenu, &prefs.speakKeyContext, &itemName));
    }

    {
      NAME(strtext("Speak Modifier Key"));
      ITEM(newBooleanMenuItem(alertsSubmenu, &prefs.speakModifierKey, &itemName));
    }
#endif /* ENABLE_SPEECH_SUPPORT */
  }

#ifdef ENABLE_SPEECH_SUPPORT
  {
    SUBMENU(autospeakSubmenu, rootMenu, strtext("Autospeak Options"));

    {
      NAME(strtext("Autospeak"));
      ITEM(newBooleanMenuItem(autospeakSubmenu, &prefs.autospeak, &itemName));
    }

    {
      NAME(strtext("Speak Selected Line"));
      ITEM(newBooleanMenuItem(autospeakSubmenu, &prefs.autospeakSelectedLine, &itemName));
      TEST(Autospeak);
    }

    {
      NAME(strtext("Speak Empty Line"));
      ITEM(newBooleanMenuItem(autospeakSubmenu, &prefs.autospeakEmptyLine, &itemName));
      TEST(Autospeak);
    }

    {
      NAME(strtext("Speak Selected Character"));
      ITEM(newBooleanMenuItem(autospeakSubmenu, &prefs.autospeakSelectedCharacter, &itemName));
      TEST(Autospeak);
    }

    {
      NAME(strtext("Speak Inserted Characters"));
      ITEM(newBooleanMenuItem(autospeakSubmenu, &prefs.autospeakInsertedCharacters, &itemName));
      TEST(Autospeak);
    }

    {
      NAME(strtext("Speak Deleted Characters"));
      ITEM(newBooleanMenuItem(autospeakSubmenu, &prefs.autospeakDeletedCharacters, &itemName));
      TEST(Autospeak);
    }

    {
      NAME(strtext("Speak Replaced Characters"));
      ITEM(newBooleanMenuItem(autospeakSubmenu, &prefs.autospeakReplacedCharacters, &itemName));
      TEST(Autospeak);
    }

    {
      NAME(strtext("Speak Completed Words"));
      ITEM(newBooleanMenuItem(autospeakSubmenu, &prefs.autospeakCompletedWords, &itemName));
      TEST(Autospeak);
    }

    {
      NAME(strtext("Speak Line Indent"));
      ITEM(newBooleanMenuItem(autospeakSubmenu, &prefs.autospeakLineIndent, &itemName));
      TEST(Autospeak);
    }
  }

  {
    SUBMENU(speechSubmenu, rootMenu, strtext("Speech Options"));

    {
      NAME(strtext("Speech Volume"));
      ITEM(newNumericMenuItem(speechSubmenu, &prefs.speechVolume, &itemName, 0, SPK_VOLUME_MAXIMUM, 1, "%", formatSpeechVolume));
      TEST(SpeechVolume);
      CHANGED(SpeechVolume);
    }

    {
      NAME(strtext("Speech Rate"));
      ITEM(newNumericMenuItem(speechSubmenu, &prefs.speechRate, &itemName, 0, SPK_RATE_MAXIMUM, 1, NULL, formatSpeechRate));
      TEST(SpeechRate);
      CHANGED(SpeechRate);
    }

    {
      NAME(strtext("Speech Pitch"));
      ITEM(newNumericMenuItem(speechSubmenu, &prefs.speechPitch, &itemName, 0, SPK_PITCH_MAXIMUM, 1, NULL, formatSpeechPitch));
      TEST(SpeechPitch);
      CHANGED(SpeechPitch);
    }

    {
      static MenuString strings[SPK_PUNCTUATION_ALL + 1];
      strings[SPK_PUNCTUATION_NONE].label = getSpeechPunctuation(SPK_PUNCTUATION_NONE);
      strings[SPK_PUNCTUATION_SOME].label = getSpeechPunctuation(SPK_PUNCTUATION_SOME);
      strings[SPK_PUNCTUATION_MOST].label = getSpeechPunctuation(SPK_PUNCTUATION_MOST);
      strings[SPK_PUNCTUATION_ALL].label = getSpeechPunctuation(SPK_PUNCTUATION_ALL);

      NAME(strtext("Speech Punctuation"));
      ITEM(newEnumeratedMenuItem(speechSubmenu, &prefs.speechPunctuation, &itemName, strings));
      TEST(SpeechPunctuation);
      CHANGED(SpeechPunctuation);
    }

    {
      static const MenuString strings[] = {
        [sucNone] = {.label=strtext("None")},
        // "cap" here, used during speech output, is short for "capital".
        // It is spoken just before an uppercase letter, e.g. "cap A".
        [sucSayCap] = {.label=strtext("Say Cap")},
        [sucRaisePitch] = {.label=strtext("Raise Pitch")},
      };

      NAME(strtext("Speech Uppercase Indicator"));
      ITEM(newEnumeratedMenuItem(speechSubmenu, &prefs.speechUppercaseIndicator, &itemName, strings));
    }

    {
      static const MenuString strings[] = {
        [swsNone] = {.label=strtext("None")},
        [swsSaySpace] = {.label=strtext("Say Space")},
      };

      NAME(strtext("Speech Whitespace Indicator"));
      ITEM(newEnumeratedMenuItem(speechSubmenu, &prefs.speechWhitespaceIndicator, &itemName, strings));
    }

    {
      static const MenuString strings[] = {
        [sayImmediate] = {.label=strtext("Immediate")},
        [sayEnqueue] = {.label=strtext("Enqueue")},
      };

      NAME(strtext("Say Line Mode"));
      ITEM(newEnumeratedMenuItem(speechSubmenu, &prefs.sayLineMode, &itemName, strings));
    }

    {
      NAME(strtext("Show Speech Cursor"));
      ITEM(newBooleanMenuItem(speechSubmenu, &prefs.showSpeechCursor, &itemName));
    }

    {
      NAME(strtext("Speech Cursor Style"));
      ITEM(newEnumeratedMenuItem(speechSubmenu, &prefs.speechCursorStyle, &itemName, cursorStyles));
      TEST(ShowSpeechCursor);
    }

    {
      NAME(strtext("Blinking Speech Cursor"));
      ITEM(newBooleanMenuItem(speechSubmenu, &prefs.blinkingSpeechCursor, &itemName));
      TEST(ShowSpeechCursor);
    }

    {
      NAME(strtext("Speech Cursor Blink Period"));
      BLINK_PERIOD(&speechCursorBlinkDescriptor);
      ITEM(newTimeMenuItem(speechSubmenu, &period, &itemName));
      TEST(BlinkingSpeechCursor);
      CHANGED(SpeechCursorBlinkPeriod);
    }

    {
      NAME(strtext("Speech Cursor Percent Visible"));
      BLINK_VISIBLE(&speechCursorBlinkDescriptor);
      ITEM(newBlinkVisibleMenuItem(speechSubmenu, &visible, &itemName));
      TEST(BlinkingSpeechCursor);
      CHANGED(SpeechCursorBlinkPercentage);
    }
  }
#endif /* ENABLE_SPEECH_SUPPORT */

  {
    SUBMENU(timeSubmenu, rootMenu, strtext("Time Presentation"));

    {
      static const MenuString strings[] = {
        [tf24Hour] = {.label=strtext("24 Hour")},
        [tf12Hour] = {.label=strtext("12 Hour")},
      };

      NAME(strtext("Time Format"));
      ITEM(newEnumeratedMenuItem(timeSubmenu, &prefs.timeFormat, &itemName, strings));
    }

    {
      static const MenuString strings[] = {
        [tsColon] = {.label=strtext("Colon"), ":"},
        [tsDot] = {.label=strtext("Dot"), "."},
      };

      NAME(strtext("Time Separator"));
      ITEM(newEnumeratedMenuItem(timeSubmenu, &prefs.timeSeparator, &itemName, strings));
    }

    {
      NAME(strtext("Show Seconds"));
      ITEM(newBooleanMenuItem(timeSubmenu, &prefs.showSeconds, &itemName));
    }

    {
      static const MenuString strings[] = {
        [dpNone] = {.label=strtext("None")},
        [dpBeforeTime] = {.label=strtext("Before Time")},
        [dpAfterTime] = {.label=strtext("After Time")},
      };

      NAME(strtext("Date Position"));
      ITEM(newEnumeratedMenuItem(timeSubmenu, &prefs.datePosition, &itemName, strings));
    }

    {
      static const MenuString strings[] = {
        [dfYearMonthDay] = {.label=strtext("Year Month Day")},
        [dfMonthDayYear] = {.label=strtext("Month Day Year")},
        [dfDayMonthYear] = {.label=strtext("Day Month Year")},
      };

      NAME(strtext("Date Format"));
      ITEM(newEnumeratedMenuItem(timeSubmenu, &prefs.dateFormat, &itemName, strings));
      TEST(ShowDate);
    }

    {
      static const MenuString strings[] = {
        [dsDash] = {.label=strtext("Dash"), "-"},
        [dsSlash] = {.label=strtext("Slash"), "/"},
        [dsDot] = {.label=strtext("Dot"), "."},
      };

      NAME(strtext("Date Separator"));
      ITEM(newEnumeratedMenuItem(timeSubmenu, &prefs.dateSeparator, &itemName, strings));
      TEST(ShowDate);
    }
  }

  {
    SUBMENU(statusSubmenu, rootMenu, strtext("Status Cells"));

    {
      static const MenuString strings[] = {
        [spNone] = {.label=strtext("None")},
        [spLeft] = {.label=strtext("Left")},
        [spRight] = {.label=strtext("Right")},
      };

      NAME(strtext("Status Position"));
      ITEM(newEnumeratedMenuItem(statusSubmenu, &prefs.statusPosition, &itemName, strings));
      TEST(StatusPosition);
      CHANGED(StatusPosition);
    }

    {
      NAME(strtext("Status Count"));
      ITEM(newNumericMenuItem(statusSubmenu, &prefs.statusCount, &itemName, 0, MAX((int)brl.textColumns/2-1, 0), 1, strtext("cells"), NULL));
      TEST(StatusCount);
      CHANGED(StatusCount);
    }

    {
      static const MenuString strings[] = {
        [ssNone] = {.label=strtext("None")},
        [ssSpace] = {.label=strtext("Space")},
        [ssBlock] = {.label=strtext("Block")},
        [ssStatusSide] = {.label=strtext("Status Side")},
        [ssTextSide] = {.label=strtext("Text Side")},
      };

      NAME(strtext("Status Separator"));
      ITEM(newEnumeratedMenuItem(statusSubmenu, &prefs.statusSeparator, &itemName, strings));
      TEST(StatusSeparator);
      CHANGED(StatusSeparator);
    }

    {
      #define STATUS_FIELD_ITEM(number) { ITEM(newStatusFieldMenuItem(statusSubmenu, number, testStatusField##number, changedStatusField##number)); }
      STATUS_FIELD_ITEM(1);
      STATUS_FIELD_ITEM(2);
      STATUS_FIELD_ITEM(3);
      STATUS_FIELD_ITEM(4);
      STATUS_FIELD_ITEM(5);
      STATUS_FIELD_ITEM(6);
      STATUS_FIELD_ITEM(7);
      STATUS_FIELD_ITEM(8);
      STATUS_FIELD_ITEM(9);
      #undef STATUS_FIELD_ITEM
    }
  }

  {
    SUBMENU(tablesSubmenu, rootMenu, strtext("Braille Tables"));

    {
      NAME(strtext("Text Table"));
      ITEM(newFilesMenuItem(tablesSubmenu, &itemName, opt_tablesDirectory, TEXT_TABLES_SUBDIRECTORY, TEXT_TABLE_EXTENSION, opt_textTable, 0));
      CHANGED(TextTable);
      SET(textTable);
    }

    {
      NAME(strtext("Contraction Table"));
      ITEM(newFilesMenuItem(tablesSubmenu, &itemName, opt_tablesDirectory, CONTRACTION_TABLES_SUBDIRECTORY, CONTRACTION_TABLE_EXTENSION, opt_contractionTable, 1));
      CHANGED(ContractionTable);
      SET(contractionTable);
    }

    {
      NAME(strtext("Attributes Table"));
      ITEM(newFilesMenuItem(tablesSubmenu, &itemName, opt_tablesDirectory, ATTRIBUTES_TABLES_SUBDIRECTORY, ATTRIBUTES_TABLE_EXTENSION, opt_attributesTable, 0));
      CHANGED(AttributesTable);
      SET(attributesTable);
    }
  }

  {
    SUBMENU(profilesSubmenu, rootMenu, strtext("Profiles"));

    {
      ITEM(newProfileMenuItem(profilesSubmenu, &languageProfile));
      CHANGED(LanguageProfile);
      SET(languageProfile);
    }
  }

  {
    SUBMENU(toolsSubmenu, rootMenu, strtext("Tools"));
    setAdvancedSubmenu(toolsSubmenu);

    {
      NAME(strtext("Restart Braille Driver"));
      ITEM(newToolMenuItem(toolsSubmenu, &itemName, restartBrailleDriver));
    }

  #ifdef ENABLE_SPEECH_SUPPORT
    {
      NAME(strtext("Restart Speech Driver"));
      ITEM(newToolMenuItem(toolsSubmenu, &itemName, restartSpeechDriver));
    }
  #endif /* ENABLE_SPEECH_SUPPORT */

    {
      NAME(strtext("Restart Screen Driver"));
      ITEM(newToolMenuItem(toolsSubmenu, &itemName, restartScreenDriver));
    }
  }

  {
    SUBMENU(buildSubmenu, rootMenu, strtext("Build Information"));
    setAdvancedSubmenu(buildSubmenu);

    {
      NAME(strtext("Package Version"));
      ITEM(newTextMenuItem(buildSubmenu, &itemName, PACKAGE_VERSION));
    }

    {
      NAME(strtext("Package Revision"));
      ITEM(newTextMenuItem(buildSubmenu, &itemName, getRevisionIdentifier()));
    }

    {
      NAME(strtext("Web Site"));
      ITEM(newTextMenuItem(buildSubmenu, &itemName, PACKAGE_URL));
    }

    {
      NAME(strtext("Mailing List"));
      ITEM(newTextMenuItem(buildSubmenu, &itemName, PACKAGE_BUGREPORT));
    }

    {
      NAME(strtext("Configuration File"));
      ITEM(newTextMenuItem(buildSubmenu, &itemName, CONFIGURATION_FILE));
    }

    {
      NAME(strtext("Preferences File"));
      ITEM(newTextMenuItem(buildSubmenu, &itemName, PREFERENCES_FILE));
    }

    {
      NAME(strtext("Configuration Directory"));
      ITEM(newTextMenuItem(buildSubmenu, &itemName, CONFIGURATION_DIRECTORY));
    }

    {
      NAME(strtext("Tables Directory"));
      ITEM(newTextMenuItem(buildSubmenu, &itemName, TABLES_DIRECTORY));
    }

    {
      NAME(strtext("Drivers Directory"));
      ITEM(newTextMenuItem(buildSubmenu, &itemName, DRIVERS_DIRECTORY));
    }

    {
      NAME(strtext("Helpers Directory"));
      ITEM(newTextMenuItem(buildSubmenu, &itemName, HELPERS_DIRECTORY));
    }

    {
      NAME(strtext("Updatable Directory"));
      ITEM(newTextMenuItem(buildSubmenu, &itemName, UPDATABLE_DIRECTORY));
    }

    {
      NAME(strtext("Writable Directory"));
      ITEM(newTextMenuItem(buildSubmenu, &itemName, WRITABLE_DIRECTORY));
    }

    {
      NAME(strtext("Locale Directory"));
      ITEM(newTextMenuItem(buildSubmenu, &itemName, LOCALE_DIRECTORY));
    }
  }

  {
    SUBMENU(optionsSubmenu, rootMenu, strtext("Command Options"));
    setAdvancedSubmenu(optionsSubmenu);

    {
      NAME(strtext("Configuration File"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_configurationFile));
    }

    {
      NAME(strtext("Environment Variables"));
      ITEM(newFlagOptionMenuItem(optionsSubmenu, &itemName, &opt_environmentVariables));
    }

    {
      NAME(strtext("Boot Parameters"));
      ITEM(newFlagOptionMenuItem(optionsSubmenu, &itemName, &opt_bootParameters));
    }

    {
      NAME(strtext("Preferences File"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_preferencesFile));
    }

    {
      NAME(strtext("Override Preferences"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_overridePreferences));
    }

    {
      NAME(strtext("Tables Directory"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_tablesDirectory));
    }

    {
      NAME(strtext("Drivers Directory"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_driversDirectory));
    }

    {
      NAME(strtext("Helpers Directory"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_helpersDirectory));
    }

    {
      NAME(strtext("Updatable Directory"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_updatableDirectory));
    }

    {
      NAME(strtext("Writable Directory"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_writableDirectory));
    }

    {
      NAME(strtext("Locale Directory"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_localeDirectory));
    }

    {
      const char *const *directories = getAllOverrideDirectories();

      if (directories) {
        const char *const *directory = directories;
        NAME(strtext("Override Directory"));

        while (*directory) {
          ITEM(newTextMenuItem(optionsSubmenu, &itemName, *directory));
          directory += 1;
        }
      }
    }
     
    {
      NAME(strtext("Text Table"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_textTable));
    }

    {
      NAME(strtext("Contraction Table"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_contractionTable));
    }

    {
      NAME(strtext("Attributes Table"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_attributesTable));
    }

    {
      NAME(strtext("Keyboard Table"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_keyboardTable));
    }

    {
      NAME(strtext("Keyboard Properties"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_keyboardProperties));
    }

    {
      NAME(strtext("GUI Keyboard Enabled"));
      ITEM(newFlagOptionMenuItem(optionsSubmenu, &itemName, &opt_guiKeyboardEnabled));
    }

    {
      NAME(strtext("GUI Keyboard Table"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_guiKeyboardTable));
    }

    {
      NAME(strtext("Braille Driver"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_brailleDriver));
    }

    {
      NAME(strtext("Braille Parameters"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_brailleParameters));
    }

    {
      NAME(strtext("Braille Device"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_brailleDevice));
    }

    {
      NAME(strtext("Release Device"));
      ITEM(newFlagOptionMenuItem(optionsSubmenu, &itemName, &opt_releaseDevice));
    }

#ifdef ENABLE_SPEECH_SUPPORT
    {
      NAME(strtext("Speech Driver"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_speechDriver));
    }

    {
      NAME(strtext("Speech Parameters"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_speechParameters));
    }

    {
      NAME(strtext("Quiet If No Braille"));
      ITEM(newFlagOptionMenuItem(optionsSubmenu, &itemName, &opt_quietIfNoBraille));
    }

    {
      NAME(strtext("Speech Input"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_speechInput));
    }
#endif /* ENABLE_SPEECH_SUPPORT */

    {
      NAME(strtext("Screen Driver"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_screenDriver));
    }

    {
      NAME(strtext("Screen Parameters"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_screenParameters));
    }

#ifdef HAVE_PCM_SUPPORT
    {
      NAME(strtext("PCM Device"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_pcmDevice));
    }
#endif /* HAVE_PCM_SUPPORT */

#ifdef HAVE_MIDI_SUPPORT
    {
      NAME(strtext("MIDI Device"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_midiDevice));
    }
#endif /* HAVE_MIDI_SUPPORT */

    {
      NAME(strtext("Log File"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_logFile));
    }

    {
      NAME(strtext("Log to Standard Error"));
      ITEM(newFlagOptionMenuItem(optionsSubmenu, &itemName, &opt_logToStandardError));
    }

    {
      NAME(strtext("PID File"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_pidFile));
    }

    {
      NAME(strtext("No Daemon"));
      ITEM(newFlagOptionMenuItem(optionsSubmenu, &itemName, &opt_noDaemon));
    }

    {
      NAME(strtext("Privilege Parameters"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_privilegeParameters));
    }

    {
      NAME(strtext("Stay Privileged"));
      ITEM(newFlagOptionMenuItem(optionsSubmenu, &itemName, &opt_stayPrivileged));
    }

    {
      NAME(strtext("Start Message"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_startMessage));
    }

    {
      NAME(strtext("Stop Message"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_stopMessage));
    }

    {
      NAME(strtext("Prompt Patterns"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_promptPatterns));
    }

#ifdef ENABLE_API
    {
      NAME(strtext("No API"));
      ITEM(newFlagOptionMenuItem(optionsSubmenu, &itemName, &opt_noApi));
    }

    {
      NAME(strtext("API Parameters"));
      ITEM(newStringOptionMenuItem(optionsSubmenu, &itemName, &opt_apiParameters));
    }
#endif /* ENABLE_API */
  }

  {
    SUBMENU(logSettingsSubmenu, rootMenu, strtext("Log Settings"));
    setAdvancedSubmenu(logSettingsSubmenu);

    static const MenuString logLevelNames[] = {
      [LOG_EMERG] = {.label=strtext("Emergency")},
      [LOG_ALERT] = {.label=strtext("Alert")},
      [LOG_CRIT] = {.label=strtext("Critical")},
      [LOG_ERR] = {.label=strtext("Error")},
      [LOG_WARNING] = {.label=strtext("Warning")},
      [LOG_NOTICE] = {.label=strtext("Notice")},
      [LOG_INFO] = {.label=strtext("Information")},
      [LOG_DEBUG] = {.label=strtext("Debug")},
    };

    {
      NAME(strtext("System Log Level"));
      ITEM(newEnumeratedMenuItem(logSettingsSubmenu, &systemLogLevel, &itemName, logLevelNames));
    }

    {
      NAME(strtext("Standard Error Log Level"));
      ITEM(newEnumeratedMenuItem(logSettingsSubmenu, &stderrLogLevel, &itemName, logLevelNames));
    }

    {
      NAME(strtext("Category Log Level"));
      ITEM(newEnumeratedMenuItem(logSettingsSubmenu, &categoryLogLevel, &itemName, logLevelNames));
    }

    {
      SUBMENU(logCategoriesSubmenu, logSettingsSubmenu, strtext("Log Categories"));
      setAdvancedSubmenu(logCategoriesSubmenu);

      {
        LogCategoryIndex category;

        for (category=0; category<LOG_CATEGORY_COUNT; category+=1) {
          const char *description = getLogCategoryTitle(category);

          if (description && *description) {
            MenuString *name;

            if (!(name = malloc(sizeof(*name)))) goto noItem;
            memset(name, 0, sizeof(*name));
            name->label = description;

            {
              ITEM(newBooleanMenuItem(logCategoriesSubmenu, &logCategoryFlags[category], name));

              switch (category) {
                case LOG_CATEGORY_INDEX(BRAILLE_KEYS):
                  TEST(InputTable);
                  break;

                case LOG_CATEGORY_INDEX(KEYBOARD_KEYS):
                  TEST(KeyboardTable);
                  break;

                default:
                  break;
              }
            }
          }
        }
      }
    }
  }

  {
    NAME(strtext("Log Messages"));
    logMessagesMenu = newSubmenuMenuItem(rootMenu, &itemName);
  }

  return rootMenu;

noItem:
  destroyMenu(rootMenu);
noMenu:
  return NULL;
}

Menu *
getPreferencesMenu (void) {
  static Menu *menu = NULL;
  if (!menu) menu = makePreferencesMenu();
  return menu;
}