home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Internet / News / Alexandra.0.82 / Source / KillFilePanel.subproj / KillPanelController.m < prev    next >
Encoding:
Text File  |  1996-01-30  |  4.9 KB  |  211 lines

  1.  
  2. #import "KillPanelController.h"
  3. #import "../ServerCell.h"
  4. #import "../MainWindowControl.h"
  5. #import "../KillFile.h"
  6.  
  7. @implementation KillPanelController
  8.  
  9. - awakeFromNib
  10. {
  11.    NXRect frameRect;
  12.    NXSize newCellSize,cellDist;
  13.    id aCell;
  14.  
  15.    [authorMatrix getFrame:&frameRect];
  16.    newCellSize.height=16.0;
  17.    newCellSize.width = frameRect.size.width;
  18.    cellDist.width=0.0;
  19.    cellDist.height=0.0;
  20.  
  21.    [authorMatrix setIntercell:&cellDist];
  22.    [[authorMatrix setCellSize:&newCellSize] setMode:NX_RADIOMODE];
  23.    [authorMatrix setEmptySelectionEnabled:YES];
  24.    //aCell=[[Cell alloc] init];
  25.    aCell=[[ServerCell alloc] init];
  26.    [[[aCell setSlowLink:FALSE] setOpenOnStartup:FALSE] serverClosed:self];
  27.    [authorMatrix setPrototype:aCell];
  28.  
  29.    nntpServerName=NULL;
  30.  
  31.    return self;
  32. }
  33.  
  34. - addName:sender
  35. {
  36.    const char *aString;
  37.    id mainDelegate;
  38.    id authorTable;
  39.  
  40.    mainDelegate=[[NXApp mainWindow] delegate];
  41.    if([mainDelegate class]!=[MainWindowControl class])
  42.       return self;
  43.    authorTable=[[mainDelegate killFile] getAuthorTable];
  44.  
  45.    aString=[nameFormCell stringValue];
  46.    if(aString[0]!='\0'){
  47.       authorCount++;
  48.       [authorMatrix selectCellAt:[self addAuthorNamed:aString] :0];
  49.       [authorMatrix display];
  50.       [[mainDelegate killFile] killUnkillAuthor:YES author:aString];
  51.    }
  52.  
  53.    [[nameFormCell controlView] selectTextAt:0];
  54.    return self;
  55.  
  56. }
  57.  
  58. - (int)addAuthorNamed:(const char *)name
  59. {
  60.    int r=0;
  61.    int c=0;
  62.    int i;
  63.    id aCell;
  64.  
  65.    [authorMatrix getNumRows:&r numCols:&c];
  66.    for(i=0;i<r;i++)
  67.       if(strcasecmp([[authorMatrix cellAt:i :0] stringValue],name)>0)
  68.          break;
  69.    [authorMatrix insertRowAt:i];
  70.    aCell=[authorMatrix cellAt:i :0];
  71.    [aCell setStringValue:name];
  72.    [authorMatrix sizeToCells];
  73.    return i;
  74. }
  75.  
  76. - removeName:sender
  77. {
  78.    int i,j;
  79.    List *cellList;
  80.    id mainDelegate;
  81.    id authorTable;
  82.  
  83.    mainDelegate=[[NXApp mainWindow] delegate];
  84.    if([mainDelegate class]!=[MainWindowControl class])
  85.       return self;
  86.    authorTable=[[mainDelegate killFile] getAuthorTable];
  87.  
  88.    cellList=[authorMatrix cellList];
  89.    j=[cellList count];
  90.    for(i=j-1;i>=0;i--){
  91.       id aCell=[cellList objectAt:i];
  92.       if([aCell state]==1){
  93.          authorCount--;
  94.          [[mainDelegate killFile] killUnkillAuthor:NO author:[aCell stringValue]];
  95.          [authorMatrix removeRowAt:i andFree:YES];
  96.       }
  97.    }
  98.    [[authorMatrix sizeToCells] display];
  99.    [self authorsSelected:self];
  100.    
  101.    return self;
  102. }
  103.  
  104. - showPanel:mainWindow
  105. {
  106.     if(nntpServerName!=NULL)
  107.        free(nntpServerName);
  108.     [myPanel makeKeyAndOrderFront:self];
  109.     return self;
  110. }
  111.  
  112. - windowDidUpdate:(Window *)sender
  113. {
  114.    const char *uname;
  115.    int r,c;
  116.    id authorTable;
  117.    const void *key; 
  118.    void *value; 
  119.    NXHashState  state;
  120.    int i=0;
  121.    int j=0;
  122.    
  123.    if([NXApp keyWindow]==myPanel){
  124.       uname=[nameFormCell stringValue];
  125.       [authorMatrix getNumRows:&r numCols:&c];
  126.       for(i=0;i<r;i++)
  127.          if(!strcmp([[authorMatrix cellAt:i:0] stringValue],uname))
  128.             break;
  129.          if(i==r)
  130.             [authorMatrix selectCellAt:-1:-1];
  131.          else
  132.         [authorMatrix selectCellAt:i:0];
  133.          [addButton setEnabled:((i==r)&&(uname[0]!='\0'))];
  134.          [removeButton setEnabled:(i!=r)];
  135.    }
  136.    else{
  137.       id d;
  138.       id mWindow=[NXApp mainWindow];
  139.       if(mWindow==nil){
  140.          [myPanel close];
  141.          return self;
  142.       }
  143.       d=[mWindow delegate];
  144.       if([d isKindOf:[MainWindowControl class]]){
  145.          if(nntpServerName!=NULL){
  146.             if(strcmp(nntpServerName,[mWindow title])==0){
  147.                if([[[d killFile] getAuthorTable] count]==authorCount)
  148.                   return self;
  149.             }
  150.             else{
  151.                free(nntpServerName);
  152.                    *nntpServerName='\0';
  153.                 }
  154.             }
  155.             if(nntpServerName==NULL)
  156.             nntpServerName=NXCopyStringBuffer([mWindow title]);
  157.       
  158.          [authorMatrix getNumRows:&i numCols:&j];
  159.          i--;
  160.          for(;i>=0;i--)
  161.             [authorMatrix removeRowAt:i andFree:YES];
  162.          authorTable=[[d killFile] getAuthorTable];
  163.          state = [authorTable initState];
  164.          i=0; 
  165.          while([authorTable nextState:&state key:&key value:&value]){
  166.             [self addAuthorNamed:(const char *)key];
  167.             i++;
  168.          }
  169.          authorCount=i;
  170.          [authorMatrix sizeToCells];
  171.          if(authorCount==0)
  172.             [[[authorMatrix superview] superview] display];
  173.          else
  174.             [authorMatrix display];
  175.          [self authorsSelected:self];
  176.       }
  177.       else
  178.          [myPanel close];
  179.    }
  180.  
  181.    return self;
  182. }
  183.  
  184. - authorsSelected:sender
  185. {
  186.  
  187.    List *aList=[authorMatrix getSelectedCells:nil];
  188.  
  189.    if([aList count]==1){
  190.       [nameFormCell takeStringValueFrom:[aList lastObject]];
  191.       [addButton setEnabled:FALSE];
  192.       [removeButton setEnabled:TRUE];
  193.       [[nameFormCell controlView] selectTextAt:0];
  194.    }
  195.    else{
  196.       [nameFormCell setStringValue:""];
  197.       [removeButton setEnabled:FALSE];
  198.    }
  199.  
  200.    [aList free];
  201.  
  202.    return self;
  203. }
  204.  
  205. - killPanel
  206. {
  207.    return myPanel;
  208. }
  209.  
  210. @end
  211.