diff --git a/programs/dtfile/Navigation.c b/programs/dtfile/Navigation.c index ac320d04..6edb9650 100644 --- a/programs/dtfile/Navigation.c +++ b/programs/dtfile/Navigation.c @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include #include
@@ -45,6 +47,8 @@ #include "Desktop.h" #include "Main.h" #include "Prefs.h" +#include + #include "Navigation.h" #define SIDEBAR_WIDTH 150 @@ -406,11 +410,218 @@ Button(Widget parent, const char *name, const char *label, return b; } +/* ---- the sidebar: groups of places, devices, shares and searches -------- */ + +typedef struct { + FileMgrRec *rec; + int place; /* >= 0: places[]; -1: path; -2: network */ + char *path; +} SideEntry; + +typedef struct { + FileMgrRec *rec; + Widget col; + Widget placeholder; +} SharedFill; + +static void +SideGroupToggled(Widget w, XtPointer client, XtPointer call) +{ + XmToggleButtonCallbackStruct *c = (XmToggleButtonCallbackStruct *) call; + Widget col = (Widget) client; + XmString ls = NULL; + char *text = NULL; + + XtVaGetValues(w, XmNlabelString, &ls, NULL); + if (ls == NULL || !XmStringGetLtoR(ls, XmFONTLIST_DEFAULT_TAG, &text)) + return; + text[0] = c->set ? 'v' : '>'; + { + XmString s = XmStringCreateLocalized(text); + + XtVaSetValues(w, XmNlabelString, s, NULL); + XmStringFree(s); + } + XtFree(text); + if (c->set) + XtManageChild(col); + else + XtUnmanageChild(col); +} + +/* a group of the sidebar: the folding head, and the column of its entries */ +static Widget +SideGroup(Widget parent, const char *title) +{ + Widget head, col; + XmString s; + char label[64]; + + (void)snprintf(label, sizeof label, "v %s", title); + s = XmStringCreateLocalized(label); + head = XtVaCreateManagedWidget("sideGroup", xmToggleButtonWidgetClass, + parent, XmNlabelString, s, XmNindicatorOn, False, XmNset, True, + XmNalignment, XmALIGNMENT_BEGINNING, XmNmarginTop, 8, + XmNmarginBottom, 2, NULL); + XmStringFree(s); + col = XtVaCreateManagedWidget("sideEntries", xmRowColumnWidgetClass, + parent, XmNspacing, 1, XmNmarginWidth, 10, XmNmarginHeight, 0, + NULL); + XtAddCallback(head, XmNvalueChangedCallback, SideGroupToggled, col); + return col; +} + +static Widget +SideItem(Widget col, const char *label, XtCallbackProc cb, SideEntry *data, + Boolean sensitive) +{ + XmString s = XmStringCreateLocalized((char *) label); + Widget b = XtVaCreateManagedWidget("sideItem", xmPushButtonGadgetClass, + col, XmNlabelString, s, XmNalignment, XmALIGNMENT_BEGINNING, + XmNmarginHeight, 1, XmNtraversalOn, False, NULL); + + XmStringFree(s); + if (cb != NULL) + XtAddCallback(b, XmNactivateCallback, cb, data); + if (!sensitive) + XtSetSensitive(b, False); + return b; +} + +static void +SideEntryCB(Widget w, XtPointer client, XtPointer call) +{ + SideEntry *e = client; + + (void) w; + (void) call; + if (e == NULL || e->rec == NULL) + return; + if (e->place >= 0) + PlaceTo(e->rec, e->place); + else if (e->place == -1 && e->path != NULL) { + _McdeNetShow(e->rec, False); + GoTo(e->rec, e->path, False); + } else if (e->place == -2) + _McdeNetShow(e->rec, True); +} + +static SideEntry * +SideData(FileMgrRec *rec, int place, const char *path) +{ + SideEntry *e = XtNew(SideEntry); + + e->rec = rec; + e->place = place; + e->path = path != NULL ? XtNewString(path) : NULL; + return e; +} + +/* the drives and partitions that are mounted, the system's own left out */ +static void +FillDevices(FileMgrRec *rec, Widget col) +{ + McdeSysDisk disks[32]; + int n = mcde_sys_disks(disks, 32), i, shown = 0; + + for (i = 0; i < n && shown < 8; i++) { + char label[200]; + + if (disks[i].mountpoint[0] == '\0' || disks[i].system) + continue; + (void)snprintf(label, sizeof label, "%s%s", + disks[i].label[0] != '\0' ? disks[i].label : disks[i].name, + disks[i].removable ? " (removable)" : ""); + SideItem(col, label, SideEntryCB, SideData(rec, -1, + disks[i].mountpoint), True); + shown++; + } + if (shown == 0) + (void) SideItem(col, "No device mounted", NULL, NULL, False); +} + +/* the computers found on the local network, once, after the window is up */ +static void +FillSharedLater(XtPointer client, XtIntervalId *id) +{ + SharedFill *sf = client; + McdeSysNetHost hosts[16]; + int n, i, shown = 0; + + (void) id; + if (sf == NULL) + return; + n = mcde_sys_net_browse(hosts, 16, 1500); + if (sf->placeholder != NULL && XtIsManaged(sf->placeholder)) { + XtUnmanageChild(sf->placeholder); + XtDestroyWidget(sf->placeholder); + } + for (i = 0; i < n && shown < 8; i++) { + SideItem(sf->col, hosts[i].name[0] != '\0' ? hosts[i].name : + hosts[i].host, SideEntryCB, SideData(sf->rec, -2, NULL), + True); + shown++; + } + if (shown == 0) + (void) SideItem(sf->col, "No computer found", NULL, NULL, False); + XtFree((char *) sf); +} + +static void +MakeSidebar(FileMgrRec *rec, Widget form, Widget bar) +{ + Arg args[8]; + int n = 0, i; + Widget frame, sw, col, group; + SharedFill *sf; + static const char *const searches[] = { "Today", "Yesterday", + "Past Week", "All Images", "All Movies", "All Documents" }; + + XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; + XtSetArg(args[n], XmNtopWidget, bar); n++; + XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; + XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; + XtSetArg(args[n], XmNshadowType, XmSHADOW_IN); n++; + XtSetArg(args[n], XmNwidth, SIDEBAR_WIDTH + 4); n++; + frame = XmCreateFrame(form, "mcdeSidebarFrame", args, n); + sw = XtVaCreateManagedWidget("mcdeSidebarScroll", + xmScrolledWindowWidgetClass, frame, + XmNscrollingPolicy, XmAUTOMATIC, + XmNwidth, SIDEBAR_WIDTH, NULL); + col = XtVaCreateManagedWidget("mcdeSidebar", xmRowColumnWidgetClass, sw, + XmNorientation, XmVERTICAL, XmNpacking, XmPACK_TIGHT, NULL); + rec->mcde_sidebar = col; + + group = SideGroup(col, "DEVICES"); + FillDevices(rec, group); + + group = SideGroup(col, "SHARED"); + sf = XtNew(SharedFill); + sf->rec = rec; + sf->col = group; + sf->placeholder = SideItem(group, "Looking for computers...", NULL, + NULL, False); + XtAppAddTimeOut(XtWidgetToApplicationContext(frame), 200, FillSharedLater, + sf); + + group = SideGroup(col, "PLACES"); + for (i = 0; i < (int) NPLACES; i++) + (void) SideItem(group, places[i].label, SideEntryCB, + SideData(rec, i, NULL), True); + + /* the reference's saved searches wait for dtfile's search (t0119) */ + group = SideGroup(col, "SEARCH FOR"); + for (i = 0; i < (int) (sizeof searches / sizeof searches[0]); i++) + (void) SideItem(group, searches[i], NULL, NULL, False); + + XtManageChild(frame); + rec->mcde_sidebar_frame = frame; +} + Widget _McdeNavCreate(FileMgrRec *rec, Widget parent) { Widget form, bar, views_rc, frame; - XmString items[NPLACES]; Arg args[12]; size_t k; int i, n; @@ -486,34 +697,8 @@ _McdeNavCreate(FileMgrRec *rec, Widget parent) } UpdateButtons(rec); - /* the sidebar: the places */ - for (k = 0; k < NPLACES; k++) - items[k] = XmStringCreateLocalized((char *)places[k].label); - n = 0; - XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++; - XtSetArg(args[n], XmNtopWidget, bar); n++; - XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++; - XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++; - XtSetArg(args[n], XmNshadowType, XmSHADOW_IN); n++; - XtSetArg(args[n], XmNwidth, SIDEBAR_WIDTH + 4); n++; - frame = XmCreateFrame(form, "mcdeSidebarFrame", args, n); - n = 0; - XtSetArg(args[n], XmNitems, items); n++; - XtSetArg(args[n], XmNitemCount, (int)NPLACES); n++; - XtSetArg(args[n], XmNvisibleItemCount, (int)NPLACES); n++; - XtSetArg(args[n], XmNselectionPolicy, XmBROWSE_SELECT); n++; - XtSetArg(args[n], XmNwidth, SIDEBAR_WIDTH); n++; - XtSetArg(args[n], XmNlistMarginWidth, 6); n++; - XtSetArg(args[n], XmNlistMarginHeight, 6); n++; - XtSetArg(args[n], XmNshadowThickness, 0); n++; - rec->mcde_sidebar = XmCreateList(frame, "mcdeSidebar", args, n); - for (k = 0; k < NPLACES; k++) - XmStringFree(items[k]); - XtAddCallback(rec->mcde_sidebar, XmNbrowseSelectionCallback, PlaceCB, - rec); - XtManageChild(rec->mcde_sidebar); - XtManageChild(frame); - rec->mcde_sidebar_frame = frame; + /* the sidebar: devices, shares, places and searches (Navigation.c) */ + MakeSidebar(rec, form, bar); XtManageChild(form); SyncViews(rec);