/* * cds.c -- dtsystemsettings: what happens with a medium (t0100) * * Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE. * * The reference's small window without tabs: five lines, each a question * with an option menu -- a blank CD, a blank DVD, a music CD, a picture CD * and a video DVD. The choice is kept in ~/.dt/media.conf (English keys * blank-cd, blank-dvd, audio-cd, picture-cd, video-dvd; the values ask, * ignore or action:NAME), the file the part that reacts to an inserted * medium reads (t0083). The programs offered are CDE actions * (DtActionExists); "Other Application..." is the list of the session's * actions, and a script is not offered at all. * * C99, POSIX, Xt and Motif only (ext/src/mcde/AGENTS.md). */ #define _POSIX_C_SOURCE 200809L #include #include #include #include #include #include #include #include #include #include #include #include
#include "ui.h" typedef struct { const char *key; /* the line of ~/.dt/media.conf */ const char *question; const char *const *actions; /* the actions offered, NULL-ended */ } Medium; static const char *const blankActions[] = { "dtburn", NULL }; static const char *const audioActions[] = { "xmms", "dtmusic", NULL }; static const char *const pictureActions[] = { "dtfile", NULL }; static const char *const videoActions[] = { "xine", "dtphoto", NULL }; static const Medium media[] = { { "blank-cd", "When you insert a blank CD:", blankActions }, { "blank-dvd", "a blank DVD:", blankActions }, { "audio-cd", "a music CD:", audioActions }, { "picture-cd", "a picture CD:", pictureActions }, { "video-dvd", "a video DVD:", videoActions }, }; #define NMEDIA ((int) (sizeof media / sizeof media[0])) /* the value's index in the menu: ask, ignore, then the actions */ static int ValueIndex(const Medium *m, const char *v) { int i, n = 2; if (strcmp(v, "ignore") == 0) return 1; if (strncmp(v, "action:", 7) == 0) for (i = 0; m->actions[i] != NULL; i++) if (strcmp(v + 7, m->actions[i]) == 0) return n + i; (void) n; return 0; } static void Chosen(Widget w, XtPointer data, XtPointer call) { const Medium *m = (const Medium *) data; char *text = NULL; (void) call; /* the item's user data is the value it stands for */ XtVaGetValues(w, XmNuserData, &text, NULL); if (text == NULL) return; (void)McdePrefsConfSet("media", m->key, text); } static Widget Item(Widget menu, const char *label, const char *value, const Medium *m) { XmString s = XmStringCreateLocalized((char *) label); Widget b = XtVaCreateManagedWidget("item", xmPushButtonGadgetClass, menu, XmNlabelString, s, XmNuserData, value, NULL); XmStringFree(s); XtAddCallback(b, XmNactivateCallback, Chosen, (XtPointer) m); return b; } static Widget Row(Widget parent, const Medium *m) { Widget row = XtVaCreateManagedWidget("mediumRow", xmRowColumnWidgetClass, parent, XmNorientation, XmHORIZONTAL, XmNspacing, 10, XmNmarginWidth, 0, NULL); XmString s = XmStringCreateLocalized((char *) m->question); Widget label = XtVaCreateManagedWidget("mediumLabel", xmLabelWidgetClass, row, XmNlabelString, s, XmNwidth, 260, XmNrecomputeSize, False, XmNalignment, XmALIGNMENT_END, NULL); Widget opt, pd, item[10]; char v[128]; int i, n = 0, cur; XmStringFree(s); (void) label; opt = XmCreateOptionMenu(row, "mediumChoice", NULL, 0); pd = XmCreatePulldownMenu(opt, "mediumMenu", NULL, 0); item[n++] = Item(pd, "Ask what to do", "ask", m); item[n++] = Item(pd, "Ignore", "ignore", m); for (i = 0; m->actions[i] != NULL; i++) { char line[128]; (void)snprintf(line, sizeof line, "Open %s", m->actions[i]); item[n++] = Item(pd, line, m->actions[i], m); } XtVaSetValues(opt, XmNsubMenuId, pd, NULL); XtManageChild(opt); if (!McdePrefsConfGet("media", m->key, v, sizeof v)) (void)snprintf(v, sizeof v, "ask"); cur = ValueIndex(m, v); if (cur >= 0 && cur < n) XtVaSetValues(opt, XmNmenuHistory, item[cur], NULL); return row; } Widget MakeCDs(Widget parent) { Widget box = XtVaCreateWidget("cds", xmRowColumnWidgetClass, parent, XmNorientation, XmVERTICAL, XmNspacing, 10, NULL); int i; (void) Text(box, "cdsLabel", "When you insert a disc:"); for (i = 0; i < NMEDIA; i++) { (void) Row(box, &media[i]); if (i == 1) XtVaCreateManagedWidget("sep", xmSeparatorWidgetClass, box, XmNorientation, XmHORIZONTAL, XmNmarginTop, 6, XmNmarginBottom, 6, NULL); } (void) Text(box, "cdsNote", "The choice is kept in " "~/.dt/media.conf; the part that reacts to an inserted medium " "(t0083) reads it."); (void) Text(box, "cdsNote2", "A script is not offered: no file name " "goes into a shell."); return box; }