#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include // parsing /etc/mtab /etc/fstab
#include
#include
#include
#include
#include // vertical only version
#include
#include
#include
#include
#include
#include
#include
#include
#include "Phaned.h" // hacked for horizontal
#include "dir.h"
#include "bmps.h"
Display *disp;
Widget outer, canvas_left,canvas_right,main_pane,folder_pane,menu_bar;
//
// File manager has File|Disk|Tree|View|Options|Help
//
Widget disk_bar,File,Disk,Tree,View,Options,Help;
LogicalDisks disks;
XtAppContext app_con;
XColor color[10];
Folder Froot;
void WinEvent (Widget, caddr_t, XEvent *);
void DiskEvent(Widget, caddr_t, XEvent *);
main (int argc, char **argv)
{
int i,n;
Arg args[10];
long eventmask = ButtonPressMask|ExposureMask|KeyPressMask;
long fgcolor, bgcolor;
color[0].red = 65535;
color[0].green = 65535;
color[0].blue = 65535;
color[1].red = 0;
color[1].green = 0;
color[1].blue = 0;
color[2].red = 65535;
color[2].green = 65535;
color[2].blue = 0;
color[3].red = 49344;
color[3].green = 49344;
color[3].blue = 49344;
color[4].red = 0;
color[4].green = 0;
color[4].blue = 33924;
color[5].red = 49344;
color[5].green = 0;
color[5].blue = 0;
color[6].red = 0;
color[6].green = 65535;
color[6].blue = 65535;
color[7].red = 0;
color[7].green = 33924;
color[7].blue = 33924;
color[8].red = 33924;
color[8].green = 33924;
color[8].blue = 33924;
outer = XtAppInitialize(&app_con,"XDraw",NULL,0,&argc,argv,NULL,NULL,0);
disp = XtDisplay(outer);
//
// Allocate colours
//
for(i=0;i<9;i++)
{
XAllocColor(disp,DefaultColormap(disp,DefaultScreen(disp)),&color[i]);
}
n = 0;
main_pane = XtCreateManagedWidget("main_pane", panedWidgetClass, outer, args,n);
XtManageChild(main_pane);
//
// Create the menu bar
//
n = 0;
XtSetArg(args[n],XtNshowGrip, FALSE);n++;
XtSetArg(args[n],XtNheight,100);n++;
XtSetArg(args[n],XtNwidth,400);n++;
XtSetArg(args[n],XtNbackground,color[5].pixel);n++;
menu_bar = XtCreateManagedWidget ("menu_bar", formWidgetClass, main_pane, args, n);
//
// Create the buttons on the bar
//
// File,Disk,Tree,View,Options,Help;
n=0;
XtSetArg(args[n],XtNlabel,"File");n++;
XtSetArg(args[n],XtNmenuName,"File");n++;
XtSetArg(args[n],XtNbackground,color[3].pixel);n++;
XtSetArg(args[n],XtNborderWidth,0);n++;
XtSetArg(args[n],XtNinternalWidth,50);n++;
File = XtCreateManagedWidget ("File", menuButtonWidgetClass,menu_bar, args, n);
//
// Create disk bar
//
n=0;
XtSetArg(args[n],XtNshowGrip, FALSE);n++;
XtSetArg(args[n],XtNheight,22);n++;
XtSetArg(args[n],XtNwidth,800);n++;
XtSetArg(args[n],XtNbackground,color[3].pixel);n++;
XtSetArg(args[n],XtNallowVert,True);n++;
XtSetArg(args[n],XtNallowHoriz,True);n++;
XtSetArg(args[n],XtNallowHoriz,True);n++;
XtSetArg(args[n],XtNuseBottom,True);n++;
disk_bar = XtCreateManagedWidget("disk_bar",constraintWidgetClass,main_pane,args,n);
XtManageChild(menu_bar);
//
// Split the next pane horizontally - use hacked Paned.c from Xaw (athena Widget)
//
n=0;
XtSetArg(args[n],XtNborder,color[3].pixel);n++;
XtSetArg(args[n],XtNshowGrip, FALSE);n++;
folder_pane = XtCreateManagedWidget("folder_pane", HphanedWidgetClass, main_pane, args,n);
XtManageChild(folder_pane);
n=0;
XtSetArg(args[n],XtNshowGrip, FALSE);n++;
canvas_left = XtVaCreateManagedWidget ("canvas_left",constraintWidgetClass,folder_pane,
XtNallowVert, True,
XtNallowHoriz, True,
XtNwidth, 400,
XtNheight,600,
XtNuseBottom, True, args,n);
n=0;
XtSetArg(args[n],XtNshowGrip, FALSE);n++;
canvas_right = XtVaCreateManagedWidget ("canvas_right",constraintWidgetClass,folder_pane,
XtNallowVert, True,
XtNallowHoriz, True,
XtNwidth, 400,
XtNheight,600,
XtNuseBottom, True, args,n);
XtRealizeWidget(outer);
//
// set double click time 1/2 second
//
XtSetMultiClickTime(disp,500);
XtAddEventHandler(canvas_left,eventmask,FALSE,(XtEventHandler)WinEvent,NULL);
XtAddEventHandler(canvas_right,eventmask,FALSE,(XtEventHandler)DiskEvent,NULL);
Froot.parent = NULL;
Froot.position.x = 0;
Froot.position.y = 0;
Froot.position.xc = 16;
Froot.position.yc = 16;
Froot.isExpanded = FALSE;
Froot.win = XtWindow(canvas_left);
Froot.tgc = XCreateGC(disp,Froot.win, 0,NULL);
// init using root
DIR *directory;
strcpy(Froot.fullpath,"/");
directory = opendir(Froot.fullpath);
Froot.dp = readdir(directory);
closedir(directory);
strcpy(Froot.dp->d_name ,"/");
Froot.Open();
Froot.Draw(0,0);
//
// disk stuff
//
disks.ResolveDisks();
disks.ListDisks();
disks.win = XtWindow(disk_bar);
disks.tgc = XCreateGC(disp,disks.win, 0,NULL);
XtAppMainLoop(app_con);
}
void DiskEvent(Widget w,caddr_t nil,XEvent *event)
{
disks.Draw();
}
void WinEvent(Widget w,caddr_t nil,XEvent *event)
{
Window win;
GC tgc;
int i,j;
XButtonEvent *e = (XButtonEvent *) event;
switch (event->type)
{
case KeyPress:
cout << "keypress" <y/16.),0);
XSetForeground(disp,Froot.tgc,color[0].pixel);
XFillRectangle(disp,Froot.win,Froot.tgc,0,0,(unsigned int)800,(unsigned int)800);
Froot.Draw(0,0);
break;
case Expose:
XSetForeground(disp,Froot.tgc,color[0].pixel);
XFillRectangle(disp,Froot.win,Froot.tgc,0,0,(unsigned int)800,(unsigned int)800);
Froot.Draw(0,0);
break;
default:
break;
}
win = XtWindow(w);
tgc = XCreateGC(disp,win, 0,NULL);
}
Folder::Folder()
{
nSiblings = 0;
isExpanded = FALSE;
}
int Folder::Draw(int depth,int stack)
{
int i,j,k,newstack;
position.x = depth*16;
position.y = stack*16;
stack++;
if(S_ISDIR(fstat.st_mode) && isExpanded == FALSE)
DrawIcon(dir_closed);
else if(S_ISREG(fstat.st_mode))
DrawIcon(file_unknown);
else if(S_ISLNK(fstat.st_mode))
DrawIcon(dir_link);
else if(S_ISSOCK(fstat.st_mode))
DrawIcon(dir_link);
else
DrawIcon(dir_open);
//
// print name
//
XSetBackground(disp,tgc,color[0].pixel);
XSetForeground(disp,tgc,color[1].pixel);
XDrawImageString(disp,win,tgc,position.x+16,position.y+12,fullpath,strlen(fullpath));
//
Selectable tmp;
int ilist =0;
for(k=0;k 0;i++)
{
tmp.position.x = (depth-1)*16;
tmp.position.y = i*16;
tmp.DrawIcon(tree_fill);
}
stack = newstack;
}
return stack;
}
int Folder::Expand(int stack_id,int cu_stack)
{
int i;
for(i=0;id_name);
if( stat(Siblings[nSiblings].fullpath,&Siblings[nSiblings].fstat) == 0) // file stats
{
if(S_ISREG(Siblings[nSiblings].fstat.st_mode)) // files will not expand
Siblings[nSiblings].isExpanded = TRUE;
if(!(strcmp(Siblings[nSiblings].dp->d_name,"..")==0))
if(!(strcmp(Siblings[nSiblings].dp->d_name,".")==0))
nSiblings++;
}
}
isExpanded = TRUE;
closedir(directory);
return 1;
}
int Folder::Close()
{
if(Siblings > 0)
free(Siblings);
nSiblings = 0;
isExpanded =FALSE;
return 0;
}
int Selectable::DrawIcon(int icon[16][16])
{
for(int i=0;i<16;i++)
{
for(int j=0;j<16;j++)
{
XSetForeground(disp,tgc,color[icon[i][j]].pixel);
XDrawPoint(disp,win,tgc,position.x+j,position.y+i);
}
}
return 0;
}
int Selectable::DrawDisk(int icon[14][24], bool isMounted)
{
XSetForeground(disp,tgc,color[4].pixel);
if(highlighted == TRUE)
XDrawRectangle(disp, win, tgc, position.x-3, position.y-3, 86, 19);
//
// If isMounted = FALSE change black to dark grey (8)
//
for(int i=0;i<14;i++)
{
for(int j=0;j<24;j++)
{
XSetForeground(disp,tgc,color[icon[i][j]].pixel);
if((isMounted == FALSE) && (icon[i][j] == 1))
XSetForeground(disp,tgc,color[8].pixel);
XDrawPoint(disp,win,tgc,position.x+j,position.y+i);
}
}
return 0;
}
int LogicalDisks::ResolveDisks()
{
FILE *filep;
mntent *my_mntent;
int i = 0;
nDisks = 0;
bool diskselected = FALSE;
Disks = new LogicalDisk[16]; // you tellin me you got more than 16?
//
// Open up /etc/fstab & parse.
//
cout << "parsing fstab\n";
filep = setmntent("/etc/fstab","r");
while(1)
{
my_mntent = getmntent(filep);
if(my_mntent == NULL)break;
strcpy(Disks[i].mnt_fsname,my_mntent->mnt_fsname);
strcpy(Disks[i].mnt_dir,my_mntent->mnt_dir);
strcpy(Disks[i].mnt_type,my_mntent->mnt_type);
Disks[i].isMounted = FALSE;
i++;
nDisks++;
}
endmntent(filep);
//
// Open up /etc/mtab & parse. Match disks with those in /etc/fstab
// and set 'active'. Mark first active disk selected.
//
cout << "parsing mtab\n";
filep = setmntent("/etc/mtab","r");
while(1)
{
my_mntent = getmntent(filep);
if(my_mntent == NULL)break;
for(i=0;imnt_fsname)==0)
{
Disks[i].isMounted = TRUE;
if(diskselected == FALSE)
{
cout<<"in here"<