Files
lotherk 63acc18853 MCDE: one settings window for every program, dtpad first (t0164)
lib/DtWidget/McdePrefs.c and include/Dt/McdePrefs.h: the reference's
preferences window -- a row of icon tabs from appconfig/icons/C (the active
one pressed), the tab's form under it, no OK or Cancel.  A tab's form is
built the first time it is shown; Escape closes, the close box only hides
it.  McdePrefsRow() puts a right-aligned label left of a widget and stacks
the rows; McdePrefsSeparator() draws the group lines.

Values are kept in ~/.dt/<prog>.conf as KEY=VALUE (English, the tab shown
last as lasttab=) -- McdePrefsConf.c does that without X, so test_prefs
tests it without a display: get/set, keep the other keys, replace instead of
doubling, no comment pile-up.

dtpad is the first user: Options > Preferences... opens two tabs, "Editing"
(Wrap to fit, Overstrike) and "Window" (Status line).  A change goes to the
Dt Editor at once, the Options menu's toggle follows, and the value is
written.  At start dtpad overlays ~/.dt/dtpad.conf over its X resources, so
the next start has it.

Measured under Xvfb with xdotool:

  - Options > Preferences... shows the icon tabs and the rows
    (docs/screenshots/leopard/dtpad-preferences-mcde.png);
  - switching "Wrap to fit" on writes "wrap=1" into ~/.dt/dtpad.conf (cat;
    the header is written once, lasttab=Editing is kept);
  - starting dtpad with "wrap=1" and "status=1" in that file shows the
    status line (Line: 1  Total: 1) without any menu being touched -- the
    change survives a restart;
  - Escape closes the window;
  - make check in lib/DtWidget: test_prefs PASS.

Open: dtfile's Prefs.c and dtcalendar (t0149, not built yet) are not moved
to it -- dtpad proves the building block; Command+, still finds a program's
menu entry through the old name heuristic instead of an explicit
registration.  Both are follow-up tasks.
2026-11-14 11:52:34 +00:00

73 lines
1.8 KiB
C

/*
* test_prefs.c -- MCDE: ~/.dt/<prog>.conf without a display (McdePrefs.h)
*
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
*/
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <Dt/McdePrefs.h>
static int failures;
#define CHECK(c) do { \
if (!(c)) { \
fprintf(stderr, "%s:%d: %s\\n", __FILE__, __LINE__, #c); \
failures++; \
} \
} while (0)
int
main(void)
{
char home[] = "/tmp/mcde-prefs-XXXXXX", buf[64];
char path[1024];
if (mkdtemp(home) == NULL) {
perror("mkdtemp");
return 1;
}
(void)setenv("HOME", home, 1);
/* nothing there yet */
CHECK(McdePrefsConfGet("dtpad", "wrap", buf, sizeof buf) == 0);
/* it is written and read back */
CHECK(McdePrefsConfSet("dtpad", "wrap", "1") == 0);
CHECK(McdePrefsConfGet("dtpad", "wrap", buf, sizeof buf) == 1);
CHECK(strcmp(buf, "1") == 0);
/* another key keeps it */
CHECK(McdePrefsConfSet("dtpad", "status", "0") == 0);
CHECK(McdePrefsConfGet("dtpad", "wrap", buf, sizeof buf) == 1 &&
strcmp(buf, "1") == 0);
CHECK(McdePrefsConfGet("dtpad", "status", buf, sizeof buf) == 1 &&
strcmp(buf, "0") == 0);
/* a key is replaced, not doubled */
CHECK(McdePrefsConfSet("dtpad", "wrap", "0") == 0);
CHECK(McdePrefsConfGet("dtpad", "wrap", buf, sizeof buf) == 1 &&
strcmp(buf, "0") == 0);
{
FILE *f;
int n = 0;
char line[256];
(void)snprintf(path, sizeof path, "%s/.dt/dtpad.conf", home);
if ((f = fopen(path, "r")) != NULL) {
while (fgets(line, sizeof line, f) != NULL)
if (strncmp(line, "wrap=", 5) == 0)
n++;
fclose(f);
}
CHECK(n == 1);
}
/* programmes do not share a file */
CHECK(McdePrefsConfGet("dtfile", "wrap", buf, sizeof buf) == 0);
(void)snprintf(path, sizeof path, "rm -rf %s", home);
(void)system(path);
return failures == 0 ? 0 : 1;
}