MCDE dtfile: the network as a folder in the column view (t0117)

~/Network shows the hosts DNS-SD finds (mcde_sys_net_browse) where a folder
shows files, so Network is walked like a place: the column lists them with a
">" (Caroline's MacBook Air, KITT, N95), and a host opens a column of what it
shares -- its NFS exports and its SMB shares (mcde_sys_net_shares).  A share
chosen is mounted on ~/Network/HOST/NAME with mcde_sys_net_mount and opened
in the next column; when it cannot (no root, no guest access, no server) a
message says why.  Hosts and shares are no folders on disk: dtfile tells them
apart by their path, and a host is not made the window's folder (the columns
follow it).

Measured under Xvfb with xdotool: dtfile in ~/Network, Columns chosen ->
the first column lists the three hosts of the network; choosing KITT opens
its shares' column ("/home/lotherk/src/makronix", "nobody" -- its NFS
exports) with KITT in the preview (docs/screenshots/leopard/
Finder-Network-mcde.png).

Open: the reference's "Computer > Network" root (the columns start at the
Network place), the sidebar's eject buttons beside the devices, and the
mounting of a share as a user -- it needs the su terminal the other root
actions use, not the plain call; that part was not run.
This commit is contained in:
lotherk committed 2026-11-14 11:15:25 +00:00
1 parent 6c98b9235d
commit 76e53b4206
2 files changed
+179 -8

No files matched your search

+6
View File
@@ -136,6 +136,12 @@ narratives and test notes, is `docs/reference/mcde-agents-history-2026-11-13.txt
`~/.dt/screensaver`. The start time has the reference's seven steps
(3/5/15/30/60/120 minutes, never) and goes to dtsession as the saver
timeout.
- **Network in the column view**: `~/Network` lists the hosts DNS-SD finds
(`mcde_sys_net_browse`) instead of files; a host is a column of its NFS
exports and SMB shares (`mcde_sys_net_shares`), and a share chosen is
mounted on `~/Network/HOST/NAME` (`mcde_sys_net_mount`) and opened. The
mount needs root; as a user it says why in a message. The sidebar's eject
buttons and a "Computer > Network" root are not built.
- **Disk Utility**: the toolbar carries Mount, Unmount, Eject, Verify,
Info, Log, Refresh and Unlock; the detail block under the list shows
device, mount point, format, capacity, available and used from
+173 -8
View File
@@ -28,6 +28,7 @@
#include <strings.h>
#include <time.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <Xm/Xm.h>
@@ -39,7 +40,9 @@
#include <Dt/Action.h>
#include <Dt/Dts.h>
#include <Dt/SharedProcs.h>
#include <Mcde/McdeSys.h>
#include <Mcde/Sound.h> /* McdeSoundEvent, used on a launch */
#include "Encaps.h"
@@ -55,6 +58,7 @@
typedef struct {
char *dir; /* the folder the column shows */
char **names; /* its entries, sorted */
char **proto; /* "smb"/"nfs" for a share, NULL otherwise */
int n;
Widget list; /* the scrolled list */
} Column;
@@ -229,9 +233,13 @@ FreeColumn(Column *c)
{
int i;
for (i = 0; i < c->n; i++)
for (i = 0; i < c->n; i++) {
XtFree(c->names[i]);
if (c->proto != NULL)
XtFree(c->proto[i]);
}
XtFree((char *)c->names);
XtFree((char *)c->proto);
XtFree(c->dir);
if (c->list != NULL)
XtDestroyWidget(XtParent(c->list));
@@ -275,6 +283,103 @@ Layout(int k)
}
}
/* ~/Network is the network: the hosts found there and their shares, as the
* network view shows them (NetView.c), here as folders one walks into */
static const char *
NetRoot(void)
{
static char path[1024];
const char *home = getenv("HOME");
if (home == NULL)
return NULL;
(void)snprintf(path, sizeof path, "%s/Network", home);
return path;
}
static Boolean
IsNetRoot(const char *dir)
{
const char *root = NetRoot();
return root != NULL && strcmp(dir, root) == 0;
}
/* DIR is ~/Network/HOST: the host into HOST and 1 */
static int
NetHost(const char *dir, char *host, size_t len)
{
const char *root = NetRoot(), *h;
size_t n;
if (root == NULL)
return 0;
n = strlen(root);
if (strncmp(dir, root, n) != 0 || dir[n] != '/' || dir[n + 1] == '\0')
return 0;
h = dir + n + 1;
if (strchr(h, '/') != NULL) /* a share's own folder */
return 0;
(void)snprintf(host, len, "%s", h);
return 1;
}
static Boolean
IsNetHostPath(const char *dir)
{
char host[256];
return NetHost(dir, host, sizeof host) != 0;
}
/* the hosts of the network; each is a column of its shares */
static void
NetAddHosts(Column *c)
{
McdeSysNetHost hosts[32];
int n = mcde_sys_net_browse(hosts, 32, 1500), i;
for (i = 0; i < n; i++) {
const char *name = hosts[i].name[0] != '\0' ? hosts[i].name :
hosts[i].host;
c->names = (char **)XtRealloc((char *)c->names,
(Cardinal)((c->n + 1) * sizeof(char *)));
if (c->proto != NULL)
c->proto = (char **)XtRealloc((char *)c->proto,
(Cardinal)((c->n + 1) * sizeof(char *)));
c->names[c->n] = XtNewString(name);
if (c->proto != NULL)
c->proto[c->n] = NULL;
c->n++;
}
}
/* what HOST shares: its NFS exports and its SMB shares */
static void
NetAddShares(Column *c, const char *host)
{
static char names[256][256];
int n, i, kind;
for (kind = 0; kind < 2; kind++) {
n = mcde_sys_net_shares(host, kind == 0 ? MCDE_NET_HAS_NFS :
MCDE_NET_HAS_SMB, names, 256);
if (n < 0)
continue;
for (i = 0; i < n; i++) {
c->names = (char **)XtRealloc((char *)c->names,
(Cardinal)((c->n + 1) * sizeof(char *)));
c->proto = (char **)XtRealloc((char *)c->proto,
(Cardinal)((c->n + 1) * sizeof(char *)));
c->names[c->n] = XtNewString(names[i]);
c->proto[c->n] = XtNewString(kind == 0 ? "nfs" :
"smb");
c->n++;
}
}
}
static void
AddColumn(int k, const char *dir)
{
@@ -290,7 +395,19 @@ AddColumn(int k, const char *dir)
c = &wins[k].col[wins[k].ncol];
memset(c, 0, sizeof *c);
c->dir = XtNewString(dir);
if ((d = opendir(dir)) != NULL) {
{
char host[256];
if (IsNetRoot(dir)) {
NetAddHosts(c);
d = NULL;
} else if (NetHost(dir, host, sizeof host)) {
NetAddShares(c, host);
d = NULL;
} else
d = opendir(dir);
}
if (d != NULL) {
while ((de = readdir(d)) != NULL) {
if (de->d_name[0] == '.')
continue; /* hidden, as dtfile hides them */
@@ -319,9 +436,9 @@ AddColumn(int k, const char *dir)
char *path = Join(dir, c->names[i]), label[600];
XmString s;
/* a folder says so: it leads on */
/* a folder says so: it leads on; a host too */
(void)snprintf(label, sizeof label, "%s%s", c->names[i],
IsDir(path) ? " >" : "");
IsDir(path) || IsNetHostPath(path) ? " >" : "");
XtFree(path);
s = XmStringCreateLocalized(label);
XmListAddItemUnselected(c->list, s, 0);
@@ -395,18 +512,66 @@ ColumnChosen(Widget w, XtPointer client, XtPointer call)
if (k < 0 || (ci = Chosen(k, w, &entry)) < 0)
return;
path = Join(wins[k].col[ci].dir, wins[k].col[ci].names[entry]);
/* a share of a host: mounted on ~/Network/HOST/NAME, then shown */
{
char host[256];
if (NetHost(wins[k].col[ci].dir, host, sizeof host) &&
wins[k].col[ci].proto != NULL &&
wins[k].col[ci].proto[entry] != NULL) {
char mp[1300], url[700], *p, *slash;
(void)snprintf(mp, sizeof mp, "%s/%s/%s",
NetRoot(), host, wins[k].col[ci].names[entry]);
(void)snprintf(url, sizeof url, "%s://%s/%s",
wins[k].col[ci].proto[entry], host,
wins[k].col[ci].names[entry]);
/* the folders down to it */
(void)snprintf(mp, sizeof mp, "%s/%s",
NetRoot(), host);
for (p = mp + 1; (slash = strchr(p, '/')) != NULL;
p = slash + 1) {
*slash = '\0';
(void)mkdir(mp, 0755);
*slash = '/';
}
(void)mkdir(mp, 0755);
(void)snprintf(mp, sizeof mp, "%s/%s/%s",
NetRoot(), host, wins[k].col[ci].names[entry]);
(void)mkdir(mp, 0755);
if (mcde_sys_net_mount(url, mp, NULL) == MCDE_SYS_OK &&
IsDir(mp)) {
while (wins[k].ncol > ci + 1)
FreeColumn(&wins[k].col[--wins[k].ncol]);
Preview(k, mp);
AddColumn(k, mp);
Layout(k);
_McdeNavGoTo(rec, mp);
} else {
char msg[1200];
(void)snprintf(msg, sizeof msg, "Could not "
"connect to %s: %s", url, mcde_sys_error());
_DtMessage(rec->shell, (char *) "Network", msg,
NULL, NULL);
}
XtFree(path);
return;
}
}
/* what lay behind this column goes */
while (wins[k].ncol > ci + 1)
FreeColumn(&wins[k].col[--wins[k].ncol]);
Preview(k, path);
/* MCDE: the preview window, if it is up, follows the column */
_McdePeekPath(rec, path);
if (IsDir(path)) {
if (IsDir(path) || IsNetHostPath(path)) {
AddColumn(k, path);
Layout(k);
/* the window's folder follows; _McdeNavVisit finds the
* columns already there (_McdeColumnsFollow) */
_McdeNavGoTo(rec, path);
/* the window's folder follows (a host is no folder); the
* columns are found again by _McdeColumnsFollow */
if (IsDir(path))
_McdeNavGoTo(rec, path);
} else
Layout(k);
XtFree(path);