home *** CD-ROM | disk | FTP | other *** search
- /* Browser delegate method which fills the browser with the last
- query result. This version displays the response like a normal file
- browser in the sense that every subdirectory is displayed as a branch. */
- typedef struct _BrowserContents {
- const char *name;
- id link;
- } BrowserCell,*BrowserCellPtr;
-
- - (int)browser: sender fillMatrix: matrix inColumn:(int) column
- {
- const char *host_name;
- int row,rows, fileCount, itemCount,depth;
- id hostFileList,link;
- id itemNames;
- MyBrowserCell *cell;
- BrowserCell item,*itemPtr;
-
- /* Column zero */
- if(column == 0)
- {
- rows = [hostList count];
- for(row = 0; row < rows; row ++)
- {
- host_name = [[hostList objectAt: row] hostname];
- [matrix addRow];
- cell = [matrix cellAt: row : 0];
- [cell setStringValue: host_name];
- [cell setLoaded:YES];
- [cell setLeaf: NO];
- }
- }
- else
- {
- /* Get the file list for the selected host */
- host_name = [[[sender matrixInColumn: 0] selectedCell] stringValue];
- hostFileList = (List *) [hostHashTable valueForKey: host_name];
-
- /* Loop through the host's files and determine the files and directories
- that exist at this level of the host file system */
- itemNames = [[Storage alloc] initCount: 0 elementSize: sizeof(BrowserCell)
- description: "{*@}"];
- fileCount = [hostFileList count];
- for(row = 0; row < fileCount; row ++)
- {
- link = (ProsperoVLINK *) [hostFileList objectAt: row];
- depth = [link fileDepth];
- if( depth > column)
- { // This is a directory at this level
- int dir;
- /* Get its name and see if it is already in the dir list */
- item.name = [link nameAtLevel: column];
- item.link = nil;
- /* Since I don't except there to be too many files at each level
- just loop through the dirNames each time. For larger
- displays I probably need a hashtable */
- itemCount = [itemNames count];
- dir = 0;
- while(dir < itemCount)
- {
- itemPtr = (BrowserCellPtr)[itemNames elementAt : dir];
- if( strcmp(itemPtr->name,item.name) == 0)
- break; // Already accounted for this directory
- dir ++;
- }
- if(dir == itemCount) // Add the new directory
- [itemNames addElement : &item];
- }
- else if(depth == column)
- { // This is the file's level
- item.name = [link fileName];
- item.link = link;
- [itemNames addElement : &item];
- }
- }
- /* Create the browser cells */
- rows = [itemNames count];
- for(row = 0; row < rows; row ++)
- { // Directories
- [matrix addRow];
- cell = [matrix cellAt: row : 0];
- itemPtr = (BrowserCellPtr) [itemNames elementAt: row];
- [cell setStringValue: itemPtr->name];
- [cell setLoaded:YES];
- if(itemPtr->link == nil)
- [cell setLeaf: NO];
- else
- [cell setLeaf: YES];
- [cell setTag: itemPtr->link];
- }
- [itemNames free];
- }
-
- return rows;
- }
-