A web page has one action on the desktop now, McdeWeb
(programs/types/datatypes.dt.src): it runs "dtsystemsettings -open-web
%Arg_1%", which reads the browser from ~/.dt/defaults (web:, chosen in the
Default Programs pane) and starts it with execlp -- no shell, and an argument
with a shell character is refused. -open-web is handled before Xt is set up,
so an action needs no display.
The .html and .htm criteria of programs/types/firefox.dt map their Open to
McdeWeb: a double click in dtfile now follows the file's choice instead of a
hard-wired Firefox. McdeWeb takes ARG_TYPE * -- an action that names a data
type the file does not have is refused ("Either action ... does not apply",
measured), and it is only named by the types that may use it.
dtthemesync gained the Firefox part: every profile under ~/.mozilla/firefox
with a prefs.js gets a user.js (downloads into ~/Downloads, reduced motion,
no cosmetic animations, no smooth scrolling, ui.key.accelKey 91 -- Command is
Mod4 in MCDE) and a chrome/userChrome.css written from the palette.
Measured under Xvfb with xdotool and a wrapper that records its arguments:
- dtsystemsettings -open-web http://example.org with web: true answers
"Opened in true: http://example.org" and exits 0, without a display;
- -open-web "http://x;rm -rf /" answers "That is not an address" and exits
1; -open-web "" answers "No address was given";
- a double click on page.html in dtfile with web: mcdetest-browser hands
exactly that path to the wrapper (cat of what it got);
- the same double click with web: firefox opens a "Mozilla Firefox" window;
- dtthemesync -v in a test home with a fake profile writes user.js and
chrome/userChrome.css; user.js carries browser.download.dir
<home>/Downloads, prefersReducedMotion 1, cosmeticAnimations false,
smoothScroll false, ui.key.accelKey 91, and the CSS starts with
--toolbar-bgcolor: #c6b2a8 (the palette Default.dp);
- the Default Programs pane shows web: firefox and, after the fix, the
links choice that the file has ("in a tab of the window that is there")
-- docs/screenshots/leopard/web-browser-default-mcde.png;
- make programs/dtsystemsettings, programs/dtthemesync, programs/types
exit=0; check programs/dtsystemsettings: test_panes PASS; check lib/DtSvc
PASS.
Not measured: Firefox's own Cmd+T/W/L in a running window (the user.js sets
the accelerator; that needs a person at the keyboard), and dtexplorer -- the
Motif browser of the task -- which is its own program and a follow-up.
1423 lines
40 KiB
C
1423 lines
40 KiB
C
/*
|
|
* main.c -- dtsystemsettings: the settings of the computer in one window
|
|
*
|
|
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
|
*
|
|
* The window shows every pane as an icon, in four bands (panes.c): Personal,
|
|
* Hardware, Internet & Network, System. A click opens the pane in the same
|
|
* window, "Show All" goes back. Panes drawn here take what they show and
|
|
* change from McdeSys (include/Mcde/McdeSys.h) and never run a system tool;
|
|
* the others start the program that has them (CDE's style manager, the
|
|
* printer tool). dtsystemsettings -pane ID opens a pane at once (the menus
|
|
* of the top bar do that).
|
|
*
|
|
* C99, POSIX, Xt and Motif only (ext/src/mcde/AGENTS.md).
|
|
*/
|
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
#include <errno.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <time.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <sys/wait.h>
|
|
|
|
#include <X11/Intrinsic.h>
|
|
#include <X11/Shell.h>
|
|
#include <Xm/Xm.h>
|
|
#include <Xm/DrawingA.h>
|
|
#include <Xm/Form.h>
|
|
#include <Xm/Frame.h>
|
|
#include <Xm/Label.h>
|
|
#include <Xm/MessageB.h>
|
|
#include <Xm/PushB.h>
|
|
#include <Xm/RowColumn.h>
|
|
#include <Xm/Scale.h>
|
|
#include <Xm/Separator.h>
|
|
#include <Xm/ToggleB.h>
|
|
#include <Xm/TextF.h>
|
|
#include <math.h>
|
|
#include <stdlib.h>
|
|
#include <Dt/Dt.h>
|
|
|
|
#include <Mcde/McdeSys.h>
|
|
#include <dirent.h>
|
|
#include <sys/stat.h>
|
|
|
|
#include <Mcde/Sound.h>
|
|
|
|
#include "panes.h"
|
|
#include "ui.h"
|
|
|
|
XtAppContext app;
|
|
static Widget shell, title, showAll, overview, paneArea, current;
|
|
static Widget backBtn, forwardBtn, searchField;
|
|
static Widget ovButton[64], ovLabel[64]; /* the overview's items */
|
|
static char *history[16]; /* the panes shown, by id */
|
|
static int histN, histPos = -1;
|
|
static Boolean histNav; /* going back or forward */
|
|
static const Pane *shown;
|
|
static XtIntervalId clockTimer;
|
|
|
|
static const char *fallback[] = {
|
|
"Dtsystemsettings*overview*category.marginHeight: 6",
|
|
"Dtsystemsettings*paneArea.marginWidth: 20",
|
|
"Dtsystemsettings*paneArea.marginHeight: 16",
|
|
NULL
|
|
};
|
|
|
|
/* ---- small helpers ------------------------------------------------------ */
|
|
|
|
XmRenderTable
|
|
PaneFont(Widget w, int size, Boolean bold)
|
|
{
|
|
XmRendition r;
|
|
XmRenderTable rt;
|
|
Arg a[4];
|
|
int n = 0;
|
|
|
|
XtSetArg(a[n], XmNfontType, XmFONT_IS_XFT); n++;
|
|
XtSetArg(a[n], XmNfontName, "Hack"); n++;
|
|
XtSetArg(a[n], XmNfontSize, size); n++;
|
|
if (bold) {
|
|
XtSetArg(a[n], XmNfontStyle, "Bold"); n++;
|
|
}
|
|
r = XmRenditionCreate(w, XmFONTLIST_DEFAULT_TAG, a, n);
|
|
rt = XmRenderTableAddRenditions(NULL, &r, 1, XmMERGE_REPLACE);
|
|
XmRenditionFree(r);
|
|
return rt;
|
|
}
|
|
|
|
Widget
|
|
Text(Widget parent, const char *name, const char *text)
|
|
{
|
|
XmString s = XmStringCreateLocalized((char *) text);
|
|
Widget w = XtVaCreateManagedWidget(name, xmLabelWidgetClass, parent,
|
|
XmNlabelString, s, XmNalignment, XmALIGNMENT_BEGINNING, NULL);
|
|
|
|
XmStringFree(s);
|
|
return w;
|
|
}
|
|
|
|
void
|
|
SetText(Widget w, const char *text)
|
|
{
|
|
XmString s = XmStringCreateLocalized((char *) text);
|
|
|
|
XtVaSetValues(w, XmNlabelString, s, NULL);
|
|
XmStringFree(s);
|
|
}
|
|
|
|
Widget
|
|
Button(Widget parent, const char *label, XtCallbackProc cb, XtPointer data)
|
|
{
|
|
XmString s = XmStringCreateLocalized((char *) label);
|
|
Widget b = XtVaCreateManagedWidget("button", xmPushButtonWidgetClass,
|
|
parent, XmNlabelString, s, NULL);
|
|
|
|
XmStringFree(s);
|
|
if (cb != NULL)
|
|
XtAddCallback(b, XmNactivateCallback, cb, data);
|
|
return b;
|
|
}
|
|
|
|
/* a button in a pane, its own width (a column would stretch it across) */
|
|
Widget
|
|
PaneButton(Widget parent, const char *label, XtCallbackProc cb, XtPointer data)
|
|
{
|
|
Widget row = XtVaCreateManagedWidget("buttonRow", xmRowColumnWidgetClass,
|
|
parent, XmNorientation, XmHORIZONTAL, XmNmarginWidth, 0, NULL);
|
|
|
|
return Button(row, label, cb, data);
|
|
}
|
|
|
|
/* a column of KEY VALUE lines; the keys right and bold */
|
|
Widget
|
|
Table(Widget parent, const char *const *rows, int n, Widget *values)
|
|
{
|
|
Widget rc = XtVaCreateManagedWidget("table", xmRowColumnWidgetClass,
|
|
parent, XmNorientation, XmVERTICAL, XmNpacking, XmPACK_COLUMN,
|
|
XmNnumColumns, 2, XmNisAligned, False, XmNspacing, 3, NULL);
|
|
XmRenderTable bold = PaneFont(parent, 10, True);
|
|
int i;
|
|
|
|
for (i = 0; i < n; i++) {
|
|
Widget k = Text(rc, "key", rows[2 * i]);
|
|
|
|
XtVaSetValues(k, XmNalignment, XmALIGNMENT_END,
|
|
XmNrenderTable, bold, NULL);
|
|
}
|
|
for (i = 0; i < n; i++) {
|
|
Widget v = Text(rc, "value", rows[2 * i + 1]);
|
|
|
|
if (values != NULL)
|
|
values[i] = v;
|
|
}
|
|
return rc;
|
|
}
|
|
|
|
Pixmap
|
|
Icon(Widget w, const char *file)
|
|
{
|
|
char path[512];
|
|
Pixel fg, bg;
|
|
|
|
XtVaGetValues(w, XmNforeground, &fg, XmNbackground, &bg, NULL);
|
|
snprintf(path, sizeof path, "%s/appconfig/icons/C/%s",
|
|
CDE_INSTALLATION_TOP, file);
|
|
return XmGetPixmap(XtScreen(w), path, fg, bg);
|
|
}
|
|
|
|
/* start a command line in a session of its own, no zombie: the child
|
|
* forks the program and ends at once */
|
|
void
|
|
Spawn(const char *command)
|
|
{
|
|
pid_t pid = fork();
|
|
|
|
if (pid == 0) {
|
|
if (fork() == 0) {
|
|
setsid();
|
|
execl("/bin/sh", "sh", "-c", command, (char *) NULL);
|
|
_exit(127);
|
|
}
|
|
_exit(0);
|
|
}
|
|
if (pid > 0)
|
|
while (waitpid(pid, NULL, 0) < 0 && errno == EINTR)
|
|
;
|
|
}
|
|
|
|
static void
|
|
MessageClosed(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) data;
|
|
(void) call;
|
|
XtDestroyWidget(XtParent(w));
|
|
}
|
|
|
|
void
|
|
Message(Widget parent, const char *text, int error)
|
|
{
|
|
XmString m = XmStringCreateLocalized((char *) text);
|
|
Arg a[2];
|
|
Widget d;
|
|
|
|
XtSetArg(a[0], XmNmessageString, m);
|
|
d = error ? XmCreateErrorDialog(parent, "message", a, 1) :
|
|
XmCreateInformationDialog(parent, "message", a, 1);
|
|
XtUnmanageChild(XmMessageBoxGetChild(d, XmDIALOG_CANCEL_BUTTON));
|
|
XtUnmanageChild(XmMessageBoxGetChild(d, XmDIALOG_HELP_BUTTON));
|
|
XtAddCallback(d, XmNokCallback, MessageClosed, NULL);
|
|
XtManageChild(d);
|
|
XmStringFree(m);
|
|
}
|
|
|
|
/* a path that may stand in single quotes on a command line */
|
|
static int
|
|
PlainPath(const char *p)
|
|
{
|
|
return p != NULL && p[0] == '/' &&
|
|
strspn(p, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
"0123456789/._-") == strlen(p);
|
|
}
|
|
|
|
/*
|
|
* A terminal in which su(1) asks for root's password and runs COMMAND as root.
|
|
* Not "su -m": that keeps the user's whole environment (su(1): "Leave the
|
|
* environment unmodified"), so root looked COMMAND up in the user's PATH --
|
|
* a ~/bin/dtsystemsettings would run as root -- and wrote ~/.dt files into the
|
|
* user's home (review 2026-11-13, tasksd t0079). Plain su sets HOME and
|
|
* SHELL to root's and keeps the rest; the command sets PATH itself, and
|
|
* XAUTHORITY is named so root still reaches this display with the user's
|
|
* cookie (DISPLAY is kept by su). On NetBSD su's -c is a login class; the
|
|
* words after the login go to the shell, so "su root -c CMD" runs CMD there
|
|
* as on Linux. A command that does not fit is not run at all.
|
|
*/
|
|
void
|
|
AsRoot(const char *title, const char *command, char *buf, size_t len)
|
|
{
|
|
char xauth[300] = "";
|
|
const char *x = getenv("XAUTHORITY"), *home = getenv("HOME");
|
|
int n;
|
|
|
|
if (PlainPath(x))
|
|
snprintf(xauth, sizeof xauth, "XAUTHORITY=%s; export XAUTHORITY; ",
|
|
x);
|
|
else if (PlainPath(home) && strlen(home) < 200)
|
|
snprintf(xauth, sizeof xauth, "XAUTHORITY=%s/.Xauthority; "
|
|
"export XAUTHORITY; ", home);
|
|
n = snprintf(buf, len, "dtterm -title '%s' -geometry 70x12 -e su root "
|
|
"-c 'PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/pkg/sbin:/usr/pkg/bin:"
|
|
CDE_INSTALLATION_TOP "/bin; export PATH; %s%s'", title, xauth,
|
|
command);
|
|
if (n < 0 || (size_t) n >= len)
|
|
buf[0] = '\0';
|
|
}
|
|
|
|
/* ---- the network pane: network.c ---------------------------------------- */
|
|
|
|
/* ---- the Bluetooth pane ------------------------------------------------- */
|
|
|
|
static Widget btState, btButton;
|
|
static McdeSysBluetooth bt;
|
|
|
|
static void
|
|
BluetoothRead(void)
|
|
{
|
|
char text[96];
|
|
|
|
(void) mcde_sys_bluetooth(&bt);
|
|
if (!bt.present) {
|
|
SetText(btState, "This computer has no Bluetooth controller.");
|
|
SetText(btButton, "Turn Bluetooth On");
|
|
XtSetSensitive(btButton, False);
|
|
return;
|
|
}
|
|
snprintf(text, sizeof text, "Bluetooth is %s (%s).", bt.on ? "on" :
|
|
"off", bt.name);
|
|
SetText(btState, text);
|
|
SetText(btButton, bt.on ? "Turn Bluetooth Off" : "Turn Bluetooth On");
|
|
XtSetSensitive(btButton, True);
|
|
}
|
|
|
|
static void
|
|
BluetoothPower(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) w;
|
|
(void) data;
|
|
(void) call;
|
|
if (mcde_sys_bluetooth_power(!bt.on) != MCDE_SYS_OK)
|
|
SetText(btState, mcde_sys_error());
|
|
else
|
|
BluetoothRead();
|
|
}
|
|
|
|
static Widget
|
|
MakeBluetooth(Widget parent)
|
|
{
|
|
Widget box = XtVaCreateWidget("bluetooth", xmRowColumnWidgetClass,
|
|
parent, XmNspacing, 10, NULL);
|
|
|
|
btState = Text(box, "state", "");
|
|
btButton = PaneButton(box, "Turn Bluetooth Off", BluetoothPower, NULL);
|
|
BluetoothRead();
|
|
return box;
|
|
}
|
|
|
|
/* ---- the date and time pane --------------------------------------------- */
|
|
|
|
static Widget dtTime, dtDate, dtZone;
|
|
static Widget dtClockArea;
|
|
static int dtClockMinute = -1;
|
|
static XtIntervalId clockTimer;
|
|
static void DtDrawClock(Widget w);
|
|
|
|
static void
|
|
ClockTick(XtPointer data, XtIntervalId *id)
|
|
{
|
|
char buf[96];
|
|
time_t now = time(NULL);
|
|
struct tm tm;
|
|
|
|
(void) data;
|
|
(void) id;
|
|
clockTimer = 0;
|
|
if (dtTime == NULL)
|
|
return;
|
|
localtime_r(&now, &tm);
|
|
strftime(buf, sizeof buf, "%H:%M:%S", &tm);
|
|
SetText(dtTime, buf);
|
|
strftime(buf, sizeof buf, "%A, %e %B %Y", &tm);
|
|
SetText(dtDate, buf);
|
|
strftime(buf, sizeof buf, "Time zone: %Z (UTC%z)", &tm);
|
|
SetText(dtZone, buf);
|
|
if (dtClockArea != NULL && tm.tm_min != dtClockMinute)
|
|
DtDrawClock(dtClockArea);
|
|
clockTimer = XtAppAddTimeOut(app, 1000, ClockTick, NULL);
|
|
}
|
|
|
|
static void
|
|
ClockGone(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) w;
|
|
(void) data;
|
|
(void) call;
|
|
dtTime = dtDate = dtZone = NULL;
|
|
if (clockTimer != 0)
|
|
XtRemoveTimeOut(clockTimer);
|
|
clockTimer = 0;
|
|
}
|
|
|
|
static Widget dtTabRow, dtTabPages, dtTabPage[3];
|
|
static int dtTabCount;
|
|
static Widget dtCalLabel, dtCalGrid[42], dtTimeField;
|
|
static Widget dtNtpToggle, dtNtpServer;
|
|
static Widget dtClockShow, dtClock24, dtClockSecs, dtClockWeekday, dtClockDate;
|
|
static int dtMonth, dtYear;
|
|
static time_t dtDay; /* the day chosen, at 00:00 local */
|
|
static Boolean dtNtpOn;
|
|
|
|
static void DtOpenLanguage(Widget w, XtPointer data, XtPointer call);
|
|
|
|
static int
|
|
LeapYear(int y)
|
|
{
|
|
return (y % 4 == 0 && y % 100 != 0) || y % 400 == 0;
|
|
}
|
|
|
|
static int
|
|
DaysInMonth(int y, int m)
|
|
{
|
|
static const int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31,
|
|
30, 31 };
|
|
|
|
return days[m] + (m == 1 && LeapYear(y) ? 1 : 0);
|
|
}
|
|
|
|
/* the month of dtDay at the top of the calendar, the chosen day marked */
|
|
static void
|
|
DtDrawCalendar(void)
|
|
{
|
|
struct tm tm;
|
|
char buf[96];
|
|
int i, first, days;
|
|
|
|
memset(&tm, 0, sizeof tm);
|
|
tm.tm_year = dtYear - 1900;
|
|
tm.tm_mon = dtMonth;
|
|
tm.tm_mday = 1;
|
|
tm.tm_isdst = -1;
|
|
(void) mktime(&tm); /* normalizes, gives the weekday */
|
|
first = tm.tm_wday;
|
|
strftime(buf, sizeof buf, "%B %Y", &tm);
|
|
SetText(dtCalLabel, buf);
|
|
days = DaysInMonth(dtYear, dtMonth);
|
|
{
|
|
struct tm chosen;
|
|
|
|
localtime_r(&dtDay, &chosen);
|
|
for (i = 0; i < 42; i++) {
|
|
int d = i - first + 1;
|
|
XmString s;
|
|
|
|
s = XmStringCreateLocalized(d >= 1 && d <= days ?
|
|
(snprintf(buf, sizeof buf, "%d", d), buf) : "");
|
|
XtVaSetValues(dtCalGrid[i], XmNlabelString, s,
|
|
XmNset, d == chosen.tm_mday &&
|
|
dtMonth == chosen.tm_mon &&
|
|
dtYear == chosen.tm_year ? XmSET : XmUNSET, NULL);
|
|
XmStringFree(s);
|
|
XtSetSensitive(dtCalGrid[i], d >= 1 && d <= days);
|
|
}
|
|
}
|
|
}
|
|
|
|
static void
|
|
DtDayChosen(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
struct tm tm;
|
|
int day = (int) (long) data;
|
|
char buf[32];
|
|
|
|
if (!XmToggleButtonGetState(w))
|
|
return; /* only the one pressed counts */
|
|
localtime_r(&dtDay, &tm);
|
|
tm.tm_mday = day;
|
|
tm.tm_isdst = -1;
|
|
dtDay = mktime(&tm);
|
|
(void)snprintf(buf, sizeof buf, "%02d:%02d:%02d", tm.tm_hour,
|
|
tm.tm_min, tm.tm_sec);
|
|
XmTextFieldSetString(dtTimeField, buf);
|
|
DtDrawCalendar();
|
|
}
|
|
|
|
static void
|
|
DtMonthStep(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
int step = (int) (long) data;
|
|
|
|
(void) w;
|
|
(void) call;
|
|
dtMonth += step;
|
|
while (dtMonth < 0) {
|
|
dtMonth += 12;
|
|
dtYear--;
|
|
}
|
|
while (dtMonth > 11) {
|
|
dtMonth -= 12;
|
|
dtYear++;
|
|
}
|
|
DtDrawCalendar();
|
|
}
|
|
|
|
static void
|
|
DtNow(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
struct tm tm;
|
|
char buf[32];
|
|
|
|
(void) w;
|
|
(void) data;
|
|
(void) call;
|
|
dtDay = time(NULL);
|
|
localtime_r(&dtDay, &tm);
|
|
dtYear = tm.tm_year + 1900;
|
|
dtMonth = tm.tm_mon;
|
|
(void)snprintf(buf, sizeof buf, "%02d:%02d:%02d", tm.tm_hour,
|
|
tm.tm_min, tm.tm_sec);
|
|
XmTextFieldSetString(dtTimeField, buf);
|
|
DtDrawCalendar();
|
|
}
|
|
|
|
/* the analog clock: a circle, twelve marks, two hands; drawn on Expose and
|
|
* when the minute changes, no timer of its own (the pane's 1 s clock asks) */
|
|
static void
|
|
DtDrawClock(Widget w)
|
|
{
|
|
Display *dpy = XtDisplay(w);
|
|
Window win = XtWindow(w);
|
|
Dimension width = 100, height = 100;
|
|
GC gc;
|
|
time_t now = time(NULL);
|
|
struct tm tm;
|
|
int cx, cy, r, i;
|
|
|
|
if (win == None)
|
|
return;
|
|
XtVaGetValues(w, XmNwidth, &width, XmNheight, &height, NULL);
|
|
cx = (int) width / 2;
|
|
cy = (int) height / 2;
|
|
r = ((int) width < (int) height ? (int) width : (int) height) / 2 - 4;
|
|
gc = XCreateGC(dpy, win, 0, NULL);
|
|
XClearWindow(dpy, win);
|
|
XDrawArc(dpy, win, gc, cx - r, cy - r, 2 * r, 2 * r, 0, 360 * 64);
|
|
for (i = 0; i < 12; i++) {
|
|
double a = (double) i * 3.14159265358979 / 6.0;
|
|
int x1 = cx + (int) ((r - 4) * sin(a));
|
|
int y1 = cy - (int) ((r - 4) * cos(a));
|
|
int x2 = cx + (int) ((r - 1) * sin(a));
|
|
int y2 = cy - (int) ((r - 1) * cos(a));
|
|
|
|
XDrawLine(dpy, win, gc, x1, y1, x2, y2);
|
|
}
|
|
localtime_r(&now, &tm);
|
|
{
|
|
double m = (double) tm.tm_min * 3.14159265358979 / 30.0;
|
|
double h = ((double) (tm.tm_hour % 12) + tm.tm_min / 60.0) *
|
|
3.14159265358979 / 6.0;
|
|
|
|
XDrawLine(dpy, win, gc, cx, cy,
|
|
cx + (int) ((r - 8) * sin(m)), cy - (int) ((r - 8) * cos(m)));
|
|
XDrawLine(dpy, win, gc, cx, cy,
|
|
cx + (int) ((r / 2) * sin(h)), cy - (int) ((r / 2) * cos(h)));
|
|
}
|
|
XFillArc(dpy, win, gc, cx - 2, cy - 2, 5, 5, 0, 360 * 64);
|
|
XFreeGC(dpy, gc);
|
|
dtClockMinute = tm.tm_min;
|
|
}
|
|
|
|
static void
|
|
DtClockExpose(Widget w, XtPointer client, XtPointer call)
|
|
{
|
|
XmDrawingAreaCallbackStruct *c = (XmDrawingAreaCallbackStruct *) call;
|
|
|
|
(void) client;
|
|
if (c != NULL && c->event != NULL && c->event->type == Expose)
|
|
DtDrawClock(w);
|
|
}
|
|
|
|
/* "dtsystemsettings -set-time EPOCH" in the root terminal */
|
|
static void
|
|
DtSetTime(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
char *text = XmTextFieldGetString(dtTimeField);
|
|
char cmd[256], line[512];
|
|
struct tm tm;
|
|
int h = 0, m = 0, s = 0;
|
|
time_t when;
|
|
|
|
(void) w;
|
|
(void) data;
|
|
(void) call;
|
|
if (text == NULL || sscanf(text, "%d:%d:%d", &h, &m, &s) != 3 ||
|
|
h < 0 || h > 23 || m < 0 || m > 59 || s < 0 || s > 60) {
|
|
SetText(dtZone, "The time has to read HH:MM:SS.");
|
|
XtFree(text);
|
|
return;
|
|
}
|
|
XtFree(text);
|
|
localtime_r(&dtDay, &tm);
|
|
tm.tm_hour = h;
|
|
tm.tm_min = m;
|
|
tm.tm_sec = s;
|
|
tm.tm_isdst = -1;
|
|
when = mktime(&tm);
|
|
(void)snprintf(cmd, sizeof cmd, "dtsystemsettings -set-time %lld",
|
|
(long long) when);
|
|
AsRoot("Set Date and Time", cmd, line, sizeof line);
|
|
if (line[0] != '\0')
|
|
Spawn(line);
|
|
SetText(dtZone, "The administrator's password is asked for in the "
|
|
"window that opened.");
|
|
}
|
|
|
|
/* a host name that may stand on the command line of su -c */
|
|
static int
|
|
PlainHost(const char *h)
|
|
{
|
|
return h != NULL && h[0] != '\0' &&
|
|
strspn(h, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
"0123456789.-") == strlen(h);
|
|
}
|
|
|
|
static void
|
|
DtApplyNtp(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
char *server;
|
|
char cmd[256], line[512];
|
|
|
|
(void) w;
|
|
(void) data;
|
|
(void) call;
|
|
server = XmTextFieldGetString(dtNtpServer);
|
|
if (!PlainHost(server)) {
|
|
SetText(dtZone, "That is not a time server name.");
|
|
XtFree(server);
|
|
return;
|
|
}
|
|
(void)snprintf(cmd, sizeof cmd, "dtsystemsettings -set-ntp %s %s",
|
|
dtNtpOn ? "on" : "off", server);
|
|
XtFree(server);
|
|
AsRoot("Time Service", cmd, line, sizeof line);
|
|
if (line[0] != '\0')
|
|
Spawn(line);
|
|
SetText(dtZone, "The administrator's password is asked for in the "
|
|
"window that opened.");
|
|
}
|
|
|
|
static void
|
|
DtNtpToggled(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
XmToggleButtonCallbackStruct *c =
|
|
(XmToggleButtonCallbackStruct *) call;
|
|
|
|
(void) w;
|
|
(void) data;
|
|
dtNtpOn = c->set ? True : False;
|
|
XtSetSensitive(dtCalGrid[0], True);
|
|
}
|
|
|
|
/* the bar's clock: ~/.dt/clock ("show=1", "format=...", read by dtbar) */
|
|
static void
|
|
DtClockApply(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
char path[512], format[128];
|
|
const char *home = getenv("HOME");
|
|
FILE *fp;
|
|
|
|
(void) w;
|
|
(void) data;
|
|
(void) call;
|
|
if (home == NULL)
|
|
return;
|
|
/* %H:%M with seconds and weekday/date as asked; the bar prints one
|
|
* line */
|
|
format[0] = '\0';
|
|
if (XmToggleButtonGetState(dtClockWeekday))
|
|
strcat(format, "%a ");
|
|
if (XmToggleButtonGetState(dtClockDate))
|
|
strcat(format, "%e %b ");
|
|
strcat(format, XmToggleButtonGetState(dtClock24) ? "%H:%M" : "%I:%M");
|
|
if (XmToggleButtonGetState(dtClockSecs))
|
|
strcat(format, ":%S");
|
|
if (!XmToggleButtonGetState(dtClock24))
|
|
strcat(format, " %p");
|
|
(void)snprintf(path, sizeof path, "%s/.dt/clock", home);
|
|
if ((fp = fopen(path, "w")) != NULL) {
|
|
fprintf(fp, "show=%d\nformat=%s\n",
|
|
XmToggleButtonGetState(dtClockShow) ? 1 : 0, format);
|
|
fclose(fp);
|
|
}
|
|
}
|
|
|
|
static void
|
|
DtTabChosen(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
XmToggleButtonCallbackStruct *c = (XmToggleButtonCallbackStruct *) call;
|
|
int which = (int) (long) data, i;
|
|
|
|
(void) w;
|
|
if (!c->set)
|
|
return;
|
|
for (i = 0; i < dtTabCount; i++)
|
|
if (i == which)
|
|
XtManageChild(dtTabPage[i]);
|
|
else
|
|
XtUnmanageChild(dtTabPage[i]);
|
|
}
|
|
|
|
static Widget
|
|
DtTab(const char *label, int idx)
|
|
{
|
|
XmString s = XmStringCreateLocalized((char *) label);
|
|
Widget t = XtVaCreateManagedWidget("tab", xmToggleButtonWidgetClass,
|
|
dtTabRow, XmNlabelString, s, XmNindicatorOn, False,
|
|
XmNshadowThickness, 2, XmNfillOnSelect, True, XmNmarginWidth, 10,
|
|
XmNset, idx == 0 ? XmSET : XmUNSET, NULL);
|
|
Widget page = XtVaCreateWidget("page", xmRowColumnWidgetClass,
|
|
dtTabPages, XmNspacing, 6, XmNmarginWidth, 6, XmNmarginHeight, 6,
|
|
NULL);
|
|
|
|
XmStringFree(s);
|
|
XtAddCallback(t, XmNvalueChangedCallback, DtTabChosen,
|
|
(XtPointer) (long) idx);
|
|
dtTabPage[dtTabCount++] = page;
|
|
return page;
|
|
}
|
|
|
|
static Widget
|
|
MakeDateTimePage(Widget parent)
|
|
{
|
|
Widget page = DtTab("Date & Time", dtTabCount);
|
|
Widget row, calRow, calCol, grid, side;
|
|
int i;
|
|
int on = 0;
|
|
char server[256];
|
|
|
|
dtNtpToggle = XtVaCreateManagedWidget("setAutomatically",
|
|
xmToggleButtonWidgetClass, page,
|
|
XmNlabelString, XmStringCreateLocalized((char *)
|
|
"Set date & time automatically:"), NULL);
|
|
(void) mcde_sys_ntp_get(&on, server, sizeof server);
|
|
dtNtpOn = on != 0;
|
|
XtVaSetValues(dtNtpToggle, XmNset, dtNtpOn ? XmSET : XmUNSET, NULL);
|
|
XtAddCallback(dtNtpToggle, XmNvalueChangedCallback, DtNtpToggled, NULL);
|
|
|
|
row = XtVaCreateManagedWidget("ntpRow", xmRowColumnWidgetClass, page,
|
|
XmNorientation, XmHORIZONTAL, XmNspacing, 6, NULL);
|
|
(void) Text(row, "ntpServerLabel", "Server:");
|
|
dtNtpServer = XtVaCreateManagedWidget("ntpServer", xmTextFieldWidgetClass,
|
|
row, XmNcolumns, 24, NULL);
|
|
XmTextFieldSetString(dtNtpServer, server[0] != '\0' ? server :
|
|
"pool.ntp.org");
|
|
(void) PaneButton(row, "Apply Time Service", DtApplyNtp, NULL);
|
|
|
|
XtVaCreateManagedWidget("sep", xmSeparatorWidgetClass, page, NULL);
|
|
|
|
/* the calendar at the left, the time at the right, as the reference */
|
|
row = XtVaCreateManagedWidget("calAndTime", xmRowColumnWidgetClass, page,
|
|
XmNorientation, XmHORIZONTAL, XmNspacing, 16, XmNmarginWidth, 0,
|
|
XmNmarginHeight, 0, NULL);
|
|
calCol = XtVaCreateManagedWidget("calendarCol", xmRowColumnWidgetClass,
|
|
row, XmNspacing, 4, XmNmarginWidth, 0, XmNmarginHeight, 0, NULL);
|
|
calRow = XtVaCreateManagedWidget("calRow", xmRowColumnWidgetClass, calCol,
|
|
XmNorientation, XmHORIZONTAL, XmNspacing, 6, NULL);
|
|
(void) Button(calRow, "<", DtMonthStep, (XtPointer) -1L);
|
|
dtCalLabel = Text(calRow, "month", "");
|
|
XtVaSetValues(dtCalLabel, XmNwidth, 150, NULL);
|
|
(void) Button(calRow, ">", DtMonthStep, (XtPointer) 1L);
|
|
|
|
grid = XtVaCreateManagedWidget("calendar", xmRowColumnWidgetClass,
|
|
calCol, XmNnumColumns, 7, XmNorientation, XmHORIZONTAL,
|
|
XmNpacking, XmPACK_COLUMN, XmNspacing, 2, NULL);
|
|
/* the weekday row is part of the same grid, so that the columns line up */
|
|
{
|
|
static const char *const names[] = { "S", "M", "T", "W", "T",
|
|
"F", "S" };
|
|
|
|
for (i = 0; i < 7; i++) {
|
|
Widget d = Text(grid, "weekday", names[i]);
|
|
|
|
XtVaSetValues(d, XmNwidth, 26, XmNalignment,
|
|
XmALIGNMENT_CENTER, NULL);
|
|
}
|
|
}
|
|
for (i = 0; i < 42; i++) {
|
|
dtCalGrid[i] = XtVaCreateManagedWidget("day",
|
|
xmToggleButtonWidgetClass, grid,
|
|
XmNlabelString, XmStringCreateLocalized((char *) ""),
|
|
XmNindicatorOn, False, XmNshadowThickness, 2,
|
|
XmNmarginWidth, 6, XmNmarginHeight, 2, NULL);
|
|
XtAddCallback(dtCalGrid[i], XmNvalueChangedCallback,
|
|
DtDayChosen, (XtPointer) (long) (i + 1));
|
|
}
|
|
|
|
side = XtVaCreateManagedWidget("timeCol", xmRowColumnWidgetClass, row,
|
|
XmNspacing, 6, XmNmarginWidth, 0, XmNmarginHeight, 0, NULL);
|
|
(void) Text(side, "timeLabel", "Time:");
|
|
dtTimeField = XtVaCreateManagedWidget("timeField",
|
|
xmTextFieldWidgetClass, side, XmNcolumns, 10, NULL);
|
|
XmTextFieldSetString(dtTimeField, "00:00:00");
|
|
(void) Button(side, "Now", DtNow, (XtPointer) NULL);
|
|
{
|
|
/* a form of its own: a column would size the area away */
|
|
Widget cf = XtVaCreateManagedWidget("clockForm",
|
|
xmFormWidgetClass, side, XmNwidth, 110, XmNheight, 110,
|
|
XmNmarginWidth, 0, XmNmarginHeight, 0, NULL);
|
|
|
|
dtClockArea = XtVaCreateManagedWidget("clock",
|
|
xmDrawingAreaWidgetClass, cf,
|
|
XmNtopAttachment, XmATTACH_FORM,
|
|
XmNleftAttachment, XmATTACH_FORM,
|
|
XmNrightAttachment, XmATTACH_FORM,
|
|
XmNbottomAttachment, XmATTACH_FORM,
|
|
XmNmarginWidth, 0, XmNmarginHeight, 0, NULL);
|
|
}
|
|
XtAddCallback(dtClockArea, XmNexposeCallback, DtClockExpose, NULL);
|
|
(void) PaneButton(side, "Set Date and Time", DtSetTime, NULL);
|
|
(void) Text(side, "formats", "To set date and time formats, use "
|
|
"Language & Region.");
|
|
(void) PaneButton(side, "Open Language & Region...", DtOpenLanguage,
|
|
NULL);
|
|
|
|
DtNow(NULL, NULL, NULL);
|
|
return page;
|
|
}
|
|
|
|
static Widget
|
|
MakeClockPage(Widget parent)
|
|
{
|
|
Widget page = DtTab("Clock", dtTabCount);
|
|
char path[512];
|
|
const char *home = getenv("HOME");
|
|
FILE *fp;
|
|
|
|
dtClockShow = XtVaCreateManagedWidget("showClock",
|
|
xmToggleButtonWidgetClass, page,
|
|
XmNlabelString, XmStringCreateLocalized((char *)
|
|
"Show the clock in the bar"), XmNset, XmSET, NULL);
|
|
dtClock24 = XtVaCreateManagedWidget("clock24",
|
|
xmToggleButtonWidgetClass, page,
|
|
XmNlabelString, XmStringCreateLocalized((char *) "24-hour time"),
|
|
XmNset, XmSET, NULL);
|
|
dtClockSecs = XtVaCreateManagedWidget("clockSeconds",
|
|
xmToggleButtonWidgetClass, page,
|
|
XmNlabelString, XmStringCreateLocalized((char *) "Show seconds"),
|
|
NULL);
|
|
dtClockWeekday = XtVaCreateManagedWidget("clockWeekday",
|
|
xmToggleButtonWidgetClass, page,
|
|
XmNlabelString, XmStringCreateLocalized((char *) "Show the "
|
|
"weekday"), XmNset, XmSET, NULL);
|
|
dtClockDate = XtVaCreateManagedWidget("clockDate",
|
|
xmToggleButtonWidgetClass, page,
|
|
XmNlabelString, XmStringCreateLocalized((char *) "Show the date"),
|
|
XmNset, XmSET, NULL);
|
|
(void) PaneButton(page, "Apply Clock Settings", DtClockApply, NULL);
|
|
(void) Text(page, "note", "The bar reads ~/.dt/clock at its next minute.");
|
|
|
|
/* what the file says now */
|
|
if (home != NULL) {
|
|
(void)snprintf(path, sizeof path, "%s/.dt/clock", home);
|
|
if ((fp = fopen(path, "r")) != NULL) {
|
|
char line[256];
|
|
|
|
while (fgets(line, sizeof line, fp) != NULL) {
|
|
if (strncmp(line, "show=0", 6) == 0)
|
|
XtVaSetValues(dtClockShow, XmNset,
|
|
XmUNSET, NULL);
|
|
}
|
|
fclose(fp);
|
|
}
|
|
}
|
|
return page;
|
|
}
|
|
|
|
static Widget
|
|
MakeDateTime(Widget parent)
|
|
{
|
|
Widget box = XtVaCreateManagedWidget("datetime", xmRowColumnWidgetClass,
|
|
parent, XmNspacing, 8, NULL);
|
|
Widget tabsRow, noteRow;
|
|
struct tm now;
|
|
|
|
dtTime = Text(box, "time", "");
|
|
XtVaSetValues(dtTime, XmNrenderTable, PaneFont(box, 28, True), NULL);
|
|
dtDate = Text(box, "date", "");
|
|
dtZone = Text(box, "zone", "");
|
|
XtVaCreateManagedWidget("sep", xmSeparatorWidgetClass, box, NULL);
|
|
|
|
tabsRow = XtVaCreateManagedWidget("dtTabs", xmRowColumnWidgetClass, box,
|
|
XmNorientation, XmHORIZONTAL, XmNspacing, 4, NULL);
|
|
dtTabRow = tabsRow;
|
|
dtTabPages = XtVaCreateManagedWidget("dtPages",
|
|
xmRowColumnWidgetClass, box, XmNspacing, 4, NULL);
|
|
(void) MakeDateTimePage(dtTabPages);
|
|
{
|
|
Widget zone = DtTab("Time Zone", dtTabCount);
|
|
Widget clock;
|
|
|
|
(void) MakeZoneChooser(zone);
|
|
clock = MakeClockPage(dtTabPages);
|
|
(void) clock;
|
|
}
|
|
XtManageChild(dtTabPage[0]);
|
|
|
|
dtDay = time(NULL);
|
|
localtime_r(&dtDay, &now);
|
|
dtYear = now.tm_year + 1900;
|
|
dtMonth = now.tm_mon;
|
|
DtDrawCalendar();
|
|
|
|
XtAddCallback(box, XmNdestroyCallback, ClockGone, NULL);
|
|
ClockTick(NULL, NULL);
|
|
return box;
|
|
}
|
|
|
|
/* the language pane of this program */
|
|
static void
|
|
DtOpenLanguage(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
char cmd[512];
|
|
|
|
(void) w;
|
|
(void) data;
|
|
(void) call;
|
|
(void)snprintf(cmd, sizeof cmd, "dtsystemsettings -pane language");
|
|
Spawn(cmd);
|
|
}
|
|
|
|
/* ---- the about pane ----------------------------------------------------- */
|
|
|
|
static Widget
|
|
MakeAbout(Widget parent)
|
|
{
|
|
Widget box = XtVaCreateWidget("about", xmRowColumnWidgetClass, parent,
|
|
XmNspacing, 8, NULL);
|
|
McdeSysInfo i;
|
|
char version[128], cpu[200], mem[32], disk[200];
|
|
const char *rows[18];
|
|
|
|
(void) mcde_sys_info(&i);
|
|
snprintf(version, sizeof version, "%s %s", i.system, i.version);
|
|
snprintf(cpu, sizeof cpu, "%s (%d)", i.cpu, i.cpus);
|
|
snprintf(mem, sizeof mem, "%llu MB", i.memory >> 20);
|
|
snprintf(disk, sizeof disk, "%s, %llu of %llu MB free", i.disk,
|
|
i.diskFree >> 20, i.diskSize >> 20);
|
|
rows[0] = "System"; rows[1] = version;
|
|
rows[2] = "Kernel"; rows[3] = i.kernel;
|
|
rows[4] = "Computer"; rows[5] = i.model;
|
|
rows[6] = "Processor"; rows[7] = cpu;
|
|
rows[8] = "Memory"; rows[9] = mem;
|
|
rows[10] = "Startup Disk"; rows[11] = disk;
|
|
rows[12] = "Host Name"; rows[13] = i.hostname;
|
|
rows[14] = "Desktop"; rows[15] = DtVERSION_STRING;
|
|
rows[16] = "System Layer"; rows[17] = mcde_sys_backend();
|
|
Table(box, rows, 9, NULL);
|
|
return box;
|
|
}
|
|
|
|
/* ---- the window --------------------------------------------------------- */
|
|
|
|
static void ShowPane(const Pane *p);
|
|
static void ShowOverview(void);
|
|
|
|
/* the panes shown, for Back and Forward; 16 are enough */
|
|
static void
|
|
HistUpdate(void)
|
|
{
|
|
XtSetSensitive(backBtn, histPos > 0);
|
|
XtSetSensitive(forwardBtn, histPos >= 0 && histPos + 1 < histN);
|
|
}
|
|
|
|
static void
|
|
HistPush(const char *id)
|
|
{
|
|
int i;
|
|
|
|
if (id == NULL)
|
|
return;
|
|
if (histNav)
|
|
return;
|
|
if (histPos >= 0 && histPos < histN && strcmp(history[histPos],
|
|
id) == 0)
|
|
return;
|
|
for (i = histPos + 1; i < histN; i++) {
|
|
XtFree(history[i]);
|
|
history[i] = NULL;
|
|
}
|
|
histN = histPos + 1;
|
|
if (histN == (int) (sizeof history / sizeof history[0])) {
|
|
XtFree(history[0]);
|
|
for (i = 1; i < histN; i++)
|
|
history[i - 1] = history[i];
|
|
histN--;
|
|
}
|
|
history[histN++] = XtNewString(id);
|
|
histPos = histN - 1;
|
|
HistUpdate();
|
|
}
|
|
|
|
static void
|
|
HistStep(int step)
|
|
{
|
|
int to = histPos + step;
|
|
const Pane *p;
|
|
|
|
if (to < 0 || to >= histN)
|
|
return;
|
|
histPos = to;
|
|
histNav = True;
|
|
if (history[histPos][0] == '\0')
|
|
ShowOverview();
|
|
else {
|
|
p = PaneFind(history[histPos]);
|
|
if (p != NULL)
|
|
ShowPane(p);
|
|
}
|
|
histNav = False;
|
|
HistUpdate();
|
|
}
|
|
|
|
static void
|
|
BackClicked(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void)w; (void)data; (void)call;
|
|
HistStep(-1);
|
|
}
|
|
|
|
static void
|
|
ForwardClicked(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void)w; (void)data; (void)call;
|
|
HistStep(1);
|
|
}
|
|
|
|
/* the search: the panes it finds keep the frame, the others go grey */
|
|
static void
|
|
SearchChanged(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
char *q = XmTextFieldGetString(searchField);
|
|
int i, m;
|
|
|
|
(void)w;
|
|
(void)data;
|
|
(void)call;
|
|
for (i = 0; i < paneCount; i++) {
|
|
m = PaneMatch(&panes[i], q);
|
|
if (panes[i].kind == PANE_LATER)
|
|
m = 0; /* named, not there: always grey */
|
|
XtSetSensitive(ovButton[i], m);
|
|
XtSetSensitive(ovLabel[i], m);
|
|
XtVaSetValues(ovButton[i], XmNshadowThickness, m ? 2 : 0,
|
|
XmNshadowType, XmSHADOW_ETCHED_OUT, NULL);
|
|
}
|
|
XtFree(q);
|
|
}
|
|
|
|
static void
|
|
ShowOverview(void)
|
|
{
|
|
HistPush(""); /* the overview is a place in the history too */
|
|
if (current != NULL) {
|
|
XtDestroyWidget(current);
|
|
current = NULL;
|
|
}
|
|
shown = NULL;
|
|
XtUnmanageChild(paneArea);
|
|
XtManageChild(overview);
|
|
SetText(title, "System Settings");
|
|
XtVaSetValues(shell, XmNtitle, "System Settings", NULL);
|
|
XtSetSensitive(showAll, False);
|
|
}
|
|
|
|
static void
|
|
ShowPane(const Pane *p)
|
|
{
|
|
Widget w = NULL;
|
|
|
|
if (p == NULL || p->kind == PANE_LATER)
|
|
return;
|
|
if (p->kind == PANE_COMMAND) {
|
|
Spawn(p->command);
|
|
return;
|
|
}
|
|
HistPush(p->id);
|
|
if (current != NULL)
|
|
XtDestroyWidget(current);
|
|
if (strcmp(p->id, "sound") == 0)
|
|
w = MakeSound(paneArea);
|
|
else if (strcmp(p->id, "printers") == 0) {
|
|
w = MakePrinters(paneArea);
|
|
XtVaSetValues(shell, XmNheight, 640, XmNwidth, 760, NULL);
|
|
}
|
|
else if (strcmp(p->id, "startupdisk") == 0) {
|
|
w = MakeStartupDisk(paneArea);
|
|
XtVaSetValues(shell, XmNheight, 560, XmNwidth, 680, NULL);
|
|
}
|
|
else if (strcmp(p->id, "sysinfo") == 0) {
|
|
w = MakeSysinfo(paneArea);
|
|
XtVaSetValues(shell, XmNheight, 520, XmNwidth, 700, NULL);
|
|
}
|
|
else if (strcmp(p->id, "defaults") == 0) {
|
|
w = MakeDefaults(paneArea);
|
|
XtVaSetValues(shell, XmNheight, 560, XmNwidth, 640, NULL);
|
|
}
|
|
else if (strcmp(p->id, "internet") == 0) {
|
|
w = MakeInternet(paneArea);
|
|
XtVaSetValues(shell, XmNheight, 560, XmNwidth, 640, NULL);
|
|
}
|
|
else if (strcmp(p->id, "energy") == 0) {
|
|
w = MakeEnergy(paneArea);
|
|
XtVaSetValues(shell, XmNheight, 520, XmNwidth, 720, NULL);
|
|
}
|
|
else if (strcmp(p->id, "cds") == 0) {
|
|
w = MakeCDs(paneArea);
|
|
XtVaSetValues(shell, XmNheight, 500, XmNwidth, 700, NULL);
|
|
}
|
|
else if (strcmp(p->id, "parental") == 0) {
|
|
w = MakeParental(paneArea);
|
|
XtVaSetValues(shell, XmNheight, 640, XmNwidth, 780, NULL);
|
|
}
|
|
else if (strcmp(p->id, "security") == 0) {
|
|
w = MakeSecurity(paneArea);
|
|
XtVaSetValues(shell, XmNheight, 620, XmNwidth, 700, NULL);
|
|
}
|
|
else if (strcmp(p->id, "network") == 0)
|
|
w = MakeNetwork(paneArea);
|
|
else if (strcmp(p->id, "bluetooth") == 0)
|
|
w = MakeBluetooth(paneArea);
|
|
else if (strcmp(p->id, "appearance") == 0) {
|
|
w = MakeAppearance(paneArea);
|
|
/* palette, the four groups and the fonts need more room than
|
|
* the overview */
|
|
XtVaSetValues(shell, XmNheight, 720, XmNwidth, 780, NULL);
|
|
}
|
|
else if (strcmp(p->id, "datetime") == 0) {
|
|
w = MakeDateTime(paneArea);
|
|
/* calendar, clock and the two tabs need more room than the
|
|
* overview's height; this pane brings its own */
|
|
XtVaSetValues(shell, XmNheight, 660, NULL);
|
|
}
|
|
else if (strcmp(p->id, "about") == 0)
|
|
w = MakeAbout(paneArea);
|
|
else if (strcmp(p->id, "accounts") == 0)
|
|
w = MakeAccounts(paneArea);
|
|
else if (strcmp(p->id, "update") == 0)
|
|
w = MakeUpdate(paneArea);
|
|
else if (strcmp(p->id, "backup") == 0)
|
|
w = MakeBackup(paneArea);
|
|
else if (strcmp(p->id, "sharing") == 0)
|
|
w = MakeSharing(paneArea);
|
|
else if (strcmp(p->id, "startup") == 0)
|
|
w = MakeStartup(paneArea);
|
|
else if (strcmp(p->id, "desktop") == 0 ||
|
|
strcmp(p->id, "screensaver") == 0) {
|
|
w = MakeDesktopPane(paneArea,
|
|
strcmp(p->id, "screensaver") == 0);
|
|
XtVaSetValues(shell, XmNheight, 660, XmNwidth, 800, NULL);
|
|
}
|
|
else if (strcmp(p->id, "keyboardmouse") == 0 ||
|
|
strcmp(p->id, "keyboard") == 0 || strcmp(p->id, "mouse") == 0 ||
|
|
strcmp(p->id, "shortcuts") == 0) {
|
|
w = MakeInput(paneArea, p->id);
|
|
XtVaSetValues(shell, XmNheight, 660, XmNwidth, 760, NULL);
|
|
}
|
|
else if (strcmp(p->id, "displays") == 0)
|
|
w = MakeDisplays(paneArea);
|
|
else if (strcmp(p->id, "language") == 0)
|
|
w = MakeLanguage(paneArea);
|
|
if (w == NULL)
|
|
return;
|
|
current = w;
|
|
shown = p;
|
|
XtManageChild(w);
|
|
XtUnmanageChild(overview);
|
|
XtManageChild(paneArea);
|
|
SetText(title, p->label);
|
|
XtVaSetValues(shell, XmNtitle, p->label, NULL);
|
|
XtSetSensitive(showAll, True);
|
|
}
|
|
|
|
static void
|
|
PaneClicked(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) w;
|
|
(void) call;
|
|
ShowPane((const Pane *) data);
|
|
}
|
|
|
|
static void
|
|
ShowAllClicked(Widget w, XtPointer data, XtPointer call)
|
|
{
|
|
(void) w;
|
|
(void) data;
|
|
(void) call;
|
|
ShowOverview();
|
|
}
|
|
|
|
/* the overview: one band a category, its panes as icons with their names */
|
|
static Widget
|
|
MakeOverview(Widget parent)
|
|
{
|
|
Widget box = XtVaCreateWidget("overview", xmRowColumnWidgetClass, parent,
|
|
XmNspacing, 4, NULL);
|
|
XmRenderTable bold = PaneFont(box, 11, True);
|
|
int c, i;
|
|
|
|
for (c = 0; c < CAT_COUNT; c++) {
|
|
Widget band, inner, row, l;
|
|
|
|
band = XtVaCreateManagedWidget("category", xmFrameWidgetClass,
|
|
box, XmNshadowType, XmSHADOW_ETCHED_IN, NULL);
|
|
inner = XtVaCreateManagedWidget("inner", xmRowColumnWidgetClass,
|
|
band, XmNspacing, 2, NULL);
|
|
l = Text(inner, "name", categoryNames[c]);
|
|
XtVaSetValues(l, XmNrenderTable, bold, NULL);
|
|
row = XtVaCreateManagedWidget("panes", xmRowColumnWidgetClass,
|
|
inner, XmNorientation, XmHORIZONTAL, XmNspacing, 8, NULL);
|
|
for (i = 0; i < paneCount; i++) {
|
|
const Pane *p = &panes[i];
|
|
Widget item, b;
|
|
|
|
if (p->category != c)
|
|
continue;
|
|
/* the icon in a field of one size, the name under it:
|
|
* the CDE icons are 16 to 37 pixels high, the names
|
|
* stand on one line all the same */
|
|
item = XtVaCreateManagedWidget("item",
|
|
xmRowColumnWidgetClass, row, XmNspacing, 0,
|
|
XmNmarginWidth, 0, XmNmarginHeight, 0,
|
|
XmNentryAlignment, XmALIGNMENT_CENTER, NULL);
|
|
b = XtVaCreateManagedWidget(p->id, xmPushButtonWidgetClass,
|
|
item, XmNlabelType, XmPIXMAP,
|
|
XmNlabelPixmap, Icon(row, p->icon),
|
|
XmNshadowThickness, 0, XmNrecomputeSize, False,
|
|
XmNwidth, 112, XmNheight, 44, NULL);
|
|
l = Text(item, "label", p->label);
|
|
XtVaSetValues(l, XmNalignment, XmALIGNMENT_CENTER, NULL);
|
|
ovButton[i] = b;
|
|
ovLabel[i] = l;
|
|
if (p->kind == PANE_LATER) {
|
|
XtSetSensitive(b, False);
|
|
XtSetSensitive(l, False);
|
|
} else
|
|
XtAddCallback(b, XmNactivateCallback, PaneClicked,
|
|
(XtPointer) p);
|
|
}
|
|
}
|
|
return box;
|
|
}
|
|
|
|
/* dtsystemsettings -set-time EPOCH, in the terminal of "Set Date and Time"
|
|
* (root); the time as a number, no secret and nothing for a shell to read */
|
|
static int
|
|
SetTimeCommand(const char *when)
|
|
{
|
|
char *end = NULL;
|
|
long long t = strtoll(when, &end, 10);
|
|
int r;
|
|
|
|
if (end == NULL || *end != '\0' || t <= 0)
|
|
r = MCDE_SYS_EINVAL;
|
|
else
|
|
r = mcde_sys_time_set((time_t) t);
|
|
if (r == MCDE_SYS_OK)
|
|
printf("The clock is set.\n");
|
|
else
|
|
printf("The clock was not set: %s\n", mcde_sys_error());
|
|
printf("\nPress Return to close this window.\n");
|
|
fflush(stdout);
|
|
(void) getchar();
|
|
return r == MCDE_SYS_OK ? 0 : 1;
|
|
}
|
|
|
|
/* dtsystemsettings -set-hostname NAME, in the terminal of "Edit..." (root) */
|
|
static int
|
|
SetHostnameCommand(const char *name)
|
|
{
|
|
int r = mcde_sys_hostname_set(name);
|
|
|
|
if (r == MCDE_SYS_OK)
|
|
printf("The computer's name is %s now.\n", name);
|
|
else
|
|
printf("The name was not changed: %s\n", mcde_sys_error());
|
|
printf("\nPress Return to close this window.\n");
|
|
fflush(stdout);
|
|
(void) getchar();
|
|
return r == MCDE_SYS_OK ? 0 : 1;
|
|
}
|
|
|
|
/* dtsystemsettings -set-ntp on|off SERVER, in the terminal of "Apply Time
|
|
* Service" (root) */
|
|
static int
|
|
SetNtpCommand(int on, const char *server)
|
|
{
|
|
int r = mcde_sys_ntp_set(on, server);
|
|
|
|
if (r == MCDE_SYS_OK)
|
|
printf("The time service is %s now.\n", on ? "on" : "off");
|
|
else
|
|
printf("The time service was not changed: %s\n",
|
|
mcde_sys_error());
|
|
printf("\nPress Return to close this window.\n");
|
|
fflush(stdout);
|
|
(void) getchar();
|
|
return r == MCDE_SYS_OK ? 0 : 1;
|
|
}
|
|
|
|
/* dtsystemsettings -set-default-printer NAME, in the terminal of the
|
|
* "Set as Default..." button (root) */
|
|
int
|
|
SetDefaultPrinterCommand(const char *name)
|
|
{
|
|
int r = mcde_sys_printer_default(name);
|
|
|
|
if (r == MCDE_SYS_OK)
|
|
printf("%s is the default printer now.\n", name);
|
|
else
|
|
printf("The default printer was not changed: %s\n",
|
|
mcde_sys_error());
|
|
printf("\nPress Return to close this window.\n");
|
|
fflush(stdout);
|
|
(void) getchar();
|
|
return r == MCDE_SYS_OK ? 0 : 1;
|
|
}
|
|
|
|
/* dtsystemsettings -add-printer NAME URI (root): a queue with the
|
|
* driverless model */
|
|
int
|
|
AddPrinterCommand(const char *name, const char *uri)
|
|
{
|
|
int r = mcde_sys_printer_add(name, uri);
|
|
|
|
if (r == MCDE_SYS_OK)
|
|
printf("%s was added (%s).\n", name, uri);
|
|
else
|
|
printf("The printer was not added: %s\n", mcde_sys_error());
|
|
printf("\nPress Return to close this window.\n");
|
|
fflush(stdout);
|
|
(void) getchar();
|
|
return r == MCDE_SYS_OK ? 0 : 1;
|
|
}
|
|
|
|
/* dtsystemsettings -remove-printer NAME (root) */
|
|
int
|
|
RemovePrinterCommand(const char *name)
|
|
{
|
|
int r = mcde_sys_printer_remove(name);
|
|
|
|
if (r == MCDE_SYS_OK)
|
|
printf("%s was removed.\n", name);
|
|
else
|
|
printf("The printer was not removed: %s\n", mcde_sys_error());
|
|
printf("\nPress Return to close this window.\n");
|
|
fflush(stdout);
|
|
(void) getchar();
|
|
return r == MCDE_SYS_OK ? 0 : 1;
|
|
}
|
|
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
Widget form, bar, sep;
|
|
const char *start = NULL;
|
|
int i;
|
|
|
|
/* the action of a web page (programs/types, McdeWeb) starts no window
|
|
* and needs no display: done before Xt is set up */
|
|
for (i = 1; i + 1 < argc; i++)
|
|
if (strcmp(argv[i], "-open-web") == 0)
|
|
return OpenWebCommand(argv[i + 1]);
|
|
|
|
XtSetLanguageProc(NULL, NULL, NULL);
|
|
shell = XtVaAppInitialize(&app, "Dtsystemsettings", NULL, 0, &argc,
|
|
argv, (String *) fallback, XmNtitle, "System Settings", NULL);
|
|
for (i = 1; i < argc; i++) {
|
|
if (strcmp(argv[i], "-pane") == 0 && i + 1 < argc)
|
|
start = argv[++i];
|
|
else if (strcmp(argv[i], "-apply-update") == 0)
|
|
return ApplyUpdate();
|
|
else if (strcmp(argv[i], "-apply-displays") == 0)
|
|
return ApplyDisplaysCommand(XtDisplay(shell));
|
|
else if (strcmp(argv[i], "-set-timezone") == 0 && i + 1 < argc)
|
|
return SetTimezoneCommand(argv[i + 1]);
|
|
else if (strcmp(argv[i], "-open-web") == 0 && i + 1 < argc)
|
|
return OpenWebCommand(argv[++i]);
|
|
else if (strcmp(argv[i], "-set-default-printer") == 0 &&
|
|
i + 1 < argc)
|
|
return SetDefaultPrinterCommand(argv[++i]);
|
|
else if (strcmp(argv[i], "-remove-printer") == 0 && i + 1 < argc)
|
|
return RemovePrinterCommand(argv[++i]);
|
|
else if (strcmp(argv[i], "-add-printer") == 0 && i + 2 < argc) {
|
|
const char *name = argv[++i];
|
|
|
|
return AddPrinterCommand(name, argv[++i]);
|
|
}
|
|
else if (strcmp(argv[i], "-set-time") == 0 && i + 1 < argc)
|
|
return SetTimeCommand(argv[++i]);
|
|
else if (strcmp(argv[i], "-set-hostname") == 0 && i + 1 < argc)
|
|
return SetHostnameCommand(argv[++i]);
|
|
else if (strcmp(argv[i], "-set-ntp") == 0 && i + 1 < argc) {
|
|
int on = strcmp(argv[i + 1], "on") == 0;
|
|
|
|
++i;
|
|
return SetNtpCommand(on,
|
|
i + 1 < argc ? argv[i + 1] : "");
|
|
}
|
|
else if (strcmp(argv[i], "-join-wifi") == 0 && i + 1 < argc)
|
|
return JoinWifiCommand(argv[i + 1],
|
|
i + 2 < argc ? argv[i + 2] : NULL);
|
|
else if (strcmp(argv[i], "-renew-dhcp") == 0 && i + 1 < argc)
|
|
return RenewDhcpCommand(argv[i + 1]);
|
|
else {
|
|
fprintf(stderr, "usage: dtsystemsettings [-pane ID | "
|
|
"-apply-update | -apply-displays | -set-timezone ZONE | "
|
|
"-set-time EPOCH | -set-ntp on|off [SERVER] | "
|
|
"-set-hostname NAME | "
|
|
"-join-wifi IF [SSID-HEX] | -renew-dhcp IF]\n");
|
|
return 1;
|
|
}
|
|
}
|
|
/* a CDE program: its menus would go to the top bar, and it is one */
|
|
(void) DtInitialize(XtDisplay(shell), shell, argv[0], "Dtsystemsettings");
|
|
|
|
form = XtVaCreateManagedWidget("form", xmFormWidgetClass, shell,
|
|
XmNmarginWidth, 8, XmNmarginHeight, 8, NULL);
|
|
bar = XtVaCreateManagedWidget("toolbar", xmRowColumnWidgetClass, form,
|
|
XmNorientation, XmHORIZONTAL, XmNspacing, 12,
|
|
XmNtopAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM,
|
|
XmNrightAttachment, XmATTACH_FORM, NULL);
|
|
backBtn = Button(bar, "<", BackClicked, NULL);
|
|
XtSetSensitive(backBtn, False);
|
|
forwardBtn = Button(bar, ">", ForwardClicked, NULL);
|
|
XtSetSensitive(forwardBtn, False);
|
|
showAll = Button(bar, "Show All", ShowAllClicked, NULL);
|
|
title = Text(bar, "title", "System Settings");
|
|
XtVaSetValues(title, XmNrenderTable, PaneFont(bar, 12, True), NULL);
|
|
(void) Text(bar, "searchLabel", "Search:");
|
|
searchField = XtVaCreateManagedWidget("search", xmTextFieldWidgetClass,
|
|
bar, XmNcolumns, 18, NULL);
|
|
XtAddCallback(searchField, XmNvalueChangedCallback, SearchChanged,
|
|
NULL);
|
|
sep = XtVaCreateManagedWidget("sep", xmSeparatorWidgetClass, form,
|
|
XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, bar,
|
|
XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM,
|
|
NULL);
|
|
overview = MakeOverview(form);
|
|
XtVaSetValues(overview, XmNtopAttachment, XmATTACH_WIDGET,
|
|
XmNtopWidget, sep, XmNleftAttachment, XmATTACH_FORM,
|
|
XmNrightAttachment, XmATTACH_FORM, XmNbottomAttachment,
|
|
XmATTACH_FORM, NULL);
|
|
paneArea = XtVaCreateWidget("paneArea", xmRowColumnWidgetClass, form,
|
|
XmNtopAttachment, XmATTACH_WIDGET, XmNtopWidget, sep,
|
|
XmNleftAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM,
|
|
XmNbottomAttachment, XmATTACH_FORM, NULL);
|
|
XtManageChild(overview);
|
|
XtSetSensitive(showAll, False);
|
|
XtRealizeWidget(shell);
|
|
if (start != NULL) {
|
|
const Pane *p = PaneFind(start);
|
|
|
|
if (p == NULL)
|
|
fprintf(stderr, "dtsystemsettings: no pane \"%s\"\n", start);
|
|
else
|
|
ShowPane(p);
|
|
}
|
|
XtAppMainLoop(app);
|
|
return 0;
|
|
}
|