home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / NEXTARCH.TAR / NeXTArchie / browserMethod.m.old < prev    next >
Encoding:
Text File  |  1992-01-20  |  2.7 KB  |  95 lines

  1. /* Browser delegate method which fills the browser with the last
  2.     query result.  This version displays the response like a normal file
  3.     browser in the sense that every subdirectory is displayed as a branch. */
  4. typedef struct _BrowserContents {
  5.     const char *name;
  6.     id link;
  7. } BrowserCell,*BrowserCellPtr;
  8.  
  9. - (int)browser: sender  fillMatrix: matrix inColumn:(int) column
  10. {
  11. const char *host_name;
  12. int row,rows, fileCount, itemCount,depth;
  13. id hostFileList,link;
  14. id itemNames;
  15. MyBrowserCell *cell;
  16. BrowserCell item,*itemPtr;
  17.  
  18.     /* Column zero */
  19.     if(column == 0)
  20.     {
  21.         rows = [hostList count];
  22.         for(row = 0; row < rows; row ++)
  23.         {
  24.             host_name = [[hostList objectAt: row] hostname];
  25.             [matrix addRow];
  26.             cell = [matrix cellAt: row : 0];
  27.             [cell setStringValue: host_name];
  28.             [cell setLoaded:YES];
  29.             [cell setLeaf: NO];
  30.         }
  31.     }
  32.     else
  33.     {
  34.         /* Get the file list for the selected host */
  35.         host_name = [[[sender matrixInColumn: 0] selectedCell] stringValue];
  36.         hostFileList = (List *) [hostHashTable valueForKey: host_name];
  37.         
  38.         /* Loop through the host's files and determine the files and directories
  39.             that exist at this level of the host file system */
  40.         itemNames = [[Storage alloc] initCount: 0 elementSize: sizeof(BrowserCell)
  41.                         description: "{*@}"];
  42.         fileCount = [hostFileList count];
  43.         for(row = 0; row < fileCount; row ++)
  44.         {
  45.             link = (ProsperoVLINK *) [hostFileList objectAt: row];
  46.             depth = [link fileDepth];
  47.             if( depth > column)
  48.             {    // This is a directory at this level
  49.             int dir;
  50.                 /* Get its name and see if it is already in the dir list */
  51.                 item.name = [link nameAtLevel: column];
  52.                 item.link = nil;
  53.                 /* Since I don't except there to be too many files at each level
  54.                     just loop through the dirNames each time.  For larger
  55.                     displays I probably need a hashtable */
  56.                 itemCount = [itemNames count];
  57.                 dir = 0;
  58.                 while(dir < itemCount)
  59.                 {
  60.                     itemPtr = (BrowserCellPtr)[itemNames elementAt : dir];
  61.                     if( strcmp(itemPtr->name,item.name) == 0)
  62.                         break;    // Already accounted for this directory
  63.                     dir ++;
  64.                 }
  65.                 if(dir == itemCount)    // Add the new directory
  66.                     [itemNames addElement : &item];
  67.             }
  68.             else if(depth == column)
  69.             {    // This is the file's level
  70.                 item.name = [link fileName];
  71.                 item.link = link;
  72.                 [itemNames addElement : &item];
  73.             }
  74.         }
  75.         /* Create the browser cells */
  76.         rows = [itemNames count];
  77.         for(row = 0; row < rows; row ++)
  78.         {    // Directories
  79.             [matrix addRow];
  80.             cell = [matrix cellAt: row : 0];
  81.             itemPtr = (BrowserCellPtr) [itemNames elementAt: row];
  82.             [cell setStringValue: itemPtr->name];
  83.             [cell setLoaded:YES];
  84.             if(itemPtr->link == nil)
  85.                 [cell setLeaf: NO];
  86.             else
  87.                 [cell setLeaf: YES];
  88.             [cell setTag: itemPtr->link];
  89.         }
  90.         [itemNames free];
  91.     }
  92.     
  93.     return rows;
  94. }
  95.