216 lines
5.9 KiB
C
216 lines
5.9 KiB
C
/*
|
|
* dtcmprefs.c -- MCDE: the calendar's settings window (t0149)
|
|
*
|
|
* Copyright (c) 2026 The Makronix project. GNU LGPL 2.0 or later, as CDE.
|
|
*
|
|
* The reference's preferences window for the calendar, on the shared pattern
|
|
* (lib/DtWidget/McdePrefs.c): icon tabs with the page under them, no OK or
|
|
* Cancel, a change kept at once in ~/.dt/dtcm.conf. Three pages:
|
|
*
|
|
* General the first day of the week, week numbers, the default length of
|
|
* an appointment.
|
|
* Accounts what the calendar keeps its appointments in (read-only: the
|
|
* rpc.cmsd server of the session; a CalDAV account is one of the
|
|
* Internet accounts the desktop knows).
|
|
* Advanced the reminder, in minutes before an appointment.
|
|
*
|
|
* dtcm's own Options... menu starts this window (programs/dtcm/calendarA.c).
|
|
*
|
|
* C99, POSIX, Xt and Motif only (ext/src/mcde/AGENTS.md).
|
|
*/
|
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include <X11/Intrinsic.h>
|
|
#include <Xm/Label.h>
|
|
#include <Xm/PushB.h>
|
|
#include <Xm/PushBG.h>
|
|
#include <Xm/RowColumn.h>
|
|
#include <Xm/Scale.h>
|
|
#include <Xm/ToggleB.h>
|
|
#include <Dt/McdePrefs.h>
|
|
|
|
static Widget prefs, mondayToggle, sundayToggle, weeksToggle, lengthScale,
|
|
remindScale;
|
|
|
|
static void
|
|
Set(Widget w, const char *text)
|
|
{
|
|
XmString s = XmStringCreateLocalized((char *) text);
|
|
|
|
XtVaSetValues(w, XmNlabelString, s, NULL);
|
|
XmStringFree(s);
|
|
}
|
|
|
|
static void
|
|
Kept(const char *key, const char *value)
|
|
{
|
|
(void)McdePrefsConfSet("dtcm", key, value);
|
|
}
|
|
|
|
static void
|
|
DayChosen(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) w;
|
|
if (((XmToggleButtonCallbackStruct *) call)->set)
|
|
Kept("weekstarts", (const char *) data);
|
|
}
|
|
|
|
static void
|
|
WeeksChosen(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) w;
|
|
(void) data;
|
|
Kept("weeknumbers", XmToggleButtonGetState(weeksToggle) ? "1" : "0");
|
|
}
|
|
|
|
static void
|
|
LengthChosen(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
int v = 0;
|
|
|
|
(void) w;
|
|
(void) data;
|
|
XmScaleGetValue(lengthScale, &v);
|
|
{
|
|
char s[16];
|
|
|
|
(void)snprintf(s, sizeof s, "%d", v);
|
|
Kept("length", s);
|
|
}
|
|
}
|
|
|
|
static void
|
|
RemindChosen(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
int v = 0;
|
|
|
|
(void) w;
|
|
(void) data;
|
|
XmScaleGetValue(remindScale, &v);
|
|
{
|
|
char s[16];
|
|
|
|
(void)snprintf(s, sizeof s, "%d", v);
|
|
Kept("remind", s);
|
|
}
|
|
}
|
|
|
|
static int
|
|
GetInt(const char *key, int def)
|
|
{
|
|
char v[32];
|
|
|
|
if (!McdePrefsConfGet("dtcm", key, v, sizeof v) || v[0] == '\0')
|
|
return def;
|
|
return atoi(v);
|
|
}
|
|
|
|
static Widget
|
|
GeneralPage(Widget form, void *data)
|
|
{
|
|
Widget row, radio, label;
|
|
char v[32];
|
|
XmString s;
|
|
|
|
(void) data;
|
|
row = McdePrefsRowBegin(form, "First day of the week:");
|
|
radio = XtVaCreateManagedWidget("days", xmRowColumnWidgetClass, row,
|
|
XmNorientation, XmHORIZONTAL, XmNradioBehavior, True,
|
|
XmNspacing, 10, XmNmarginWidth, 0, NULL);
|
|
mondayToggle = XtVaCreateManagedWidget("Monday",
|
|
xmToggleButtonWidgetClass, radio, NULL);
|
|
sundayToggle = XtVaCreateManagedWidget("Sunday",
|
|
xmToggleButtonWidgetClass, radio, NULL);
|
|
XtAddCallback(mondayToggle, XmNvalueChangedCallback, DayChosen,
|
|
(XtPointer) "monday");
|
|
XtAddCallback(sundayToggle, XmNvalueChangedCallback, DayChosen,
|
|
(XtPointer) "sunday");
|
|
McdePrefsConfGet("dtcm", "weekstarts", v, sizeof v);
|
|
XmToggleButtonSetState(strcmp(v, "sunday") == 0 ? sundayToggle :
|
|
mondayToggle, True, False);
|
|
McdePrefsRowEnd(row, radio);
|
|
|
|
weeksToggle = XtVaCreateManagedWidget("Show the week numbers",
|
|
xmToggleButtonWidgetClass, form, NULL);
|
|
XmToggleButtonSetState(weeksToggle, GetInt("weeknumbers", 1) != 0,
|
|
False);
|
|
XtAddCallback(weeksToggle, XmNvalueChangedCallback, WeeksChosen, NULL);
|
|
|
|
McdePrefsSeparator(form);
|
|
label = XtVaCreateManagedWidget("lengthLabel", xmLabelWidgetClass,
|
|
form, NULL);
|
|
Set(label, "Default length of an appointment (minutes):");
|
|
lengthScale = XtVaCreateManagedWidget("length", xmScaleWidgetClass,
|
|
form, XmNorientation, XmHORIZONTAL, XmNminimum, 15,
|
|
XmNmaximum, 120, XmNshowValue, True, XmNscaleWidth, 260, NULL);
|
|
XmScaleSetValue(lengthScale, GetInt("length", 30));
|
|
XtAddCallback(lengthScale, XmNvalueChangedCallback, LengthChosen, NULL);
|
|
(void) s;
|
|
return form;
|
|
}
|
|
|
|
static Widget
|
|
AccountsPage(Widget form, void *data)
|
|
{
|
|
Widget label;
|
|
|
|
(void) data;
|
|
label = XtVaCreateManagedWidget("accountsNote", xmLabelWidgetClass,
|
|
form, NULL);
|
|
Set(label, "The appointments live in the session's calendar server "
|
|
"(rpc.cmsd).");
|
|
label = XtVaCreateManagedWidget("accountsNote2", xmLabelWidgetClass,
|
|
form, NULL);
|
|
Set(label, "A CalDAV account is one of the Internet accounts of the "
|
|
"desktop; the calendar");
|
|
label = XtVaCreateManagedWidget("accountsNote3", xmLabelWidgetClass,
|
|
form, NULL);
|
|
Set(label, "reads it from ~/.dt/accounts.conf once the connection part "
|
|
"is built.");
|
|
return form;
|
|
}
|
|
|
|
static Widget
|
|
AdvancedPage(Widget form, void *data)
|
|
{
|
|
Widget label;
|
|
|
|
(void) data;
|
|
label = XtVaCreateManagedWidget("remindLabel", xmLabelWidgetClass,
|
|
form, NULL);
|
|
Set(label, "Remind me this many minutes before an appointment:");
|
|
remindScale = XtVaCreateManagedWidget("remind", xmScaleWidgetClass,
|
|
form, XmNorientation, XmHORIZONTAL, XmNminimum, 0,
|
|
XmNmaximum, 60, XmNshowValue, True, XmNscaleWidth, 260, NULL);
|
|
XmScaleSetValue(remindScale, GetInt("remind", 10));
|
|
XtAddCallback(remindScale, XmNvalueChangedCallback, RemindChosen, NULL);
|
|
return form;
|
|
}
|
|
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
static String fallback[] = { "*renderTable: mcde", NULL };
|
|
Widget shell;
|
|
XtAppContext app;
|
|
|
|
XtSetLanguageProc(NULL, NULL, NULL);
|
|
shell = XtVaAppInitialize(&app, "Dtcmprefs", NULL, 0, &argc, argv,
|
|
(String *) fallback, XmNtitle, "Calendar Settings", NULL);
|
|
prefs = McdePrefsCreate(shell, "dtcm");
|
|
(void) McdePrefsAddTab(prefs, "General", "Dtdate.m.pm", GeneralPage,
|
|
NULL);
|
|
(void) McdePrefsAddTab(prefs, "Accounts", "Dtmail.t.pm",
|
|
AccountsPage, NULL);
|
|
(void) McdePrefsAddTab(prefs, "Advanced", "Dtstyle.m.pm",
|
|
AdvancedPage, NULL);
|
|
McdePrefsShow(prefs, NULL);
|
|
XtAppMainLoop(app);
|
|
return 0;
|
|
}
|