Changeset 974

Show
Ignore:
Timestamp:
03/14/04 00:22:35 (5 years ago)
Author:
morris
Message:

pull in user count text field, submitted by sdz

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • WiredClient/trunk/WCChat.h

    r944 r974  
    1 /* $Id: WCChat.h,v 1.1 2004/03/08 19:23:42 morris Exp $ */ 
     1/* $Id: WCChat.h,v 1.2 2004/03/13 23:22:35 morris Exp $ */ 
    22 
    33/* 
     
    5454        IBOutlet NSButton                               *_infoButton; 
    5555 
     56        IBOutlet NSTextField                    *_userCountTextField; 
     57 
    5658        IBOutlet NSTableColumn                  *_nickTableColumn; 
    5759         
     
    8688- (void)                                                        update; 
    8789- (void)                                                        updateButtons; 
     90- (void)                                                        updateUserCount; 
    8891- (void)                                                        saveChatToURL:(NSURL *)url; 
     92- (void)                                                        printEvent:(NSString *)argument; 
     93- (BOOL)                                                        parseCommand:(NSString *)argument; 
     94 
    8995- (NSMutableDictionary *)                       users; 
     96- (unsigned int)                                        numberOfUsers; 
     97- (unsigned int)                                        numberOfActiveUsers; 
    9098- (unsigned int)                                        cid; 
    9199                 
     
    94102- (IBAction)                                            ignore:(id)sender; 
    95103- (IBAction)                                            unignore:(id)sender; 
    96          
    97 - (void)                                                        printEvent:(NSString *)argument; 
    98 - (BOOL)                                                        parseCommand:(NSString *)argument; 
     104 
    99105         
    100106@end 
  • WiredClient/trunk/WCChat.m

    r970 r974  
    1 /* $Id: WCChat.m,v 1.2 2004/03/13 21:29:14 morris Exp $ */ 
     1/* $Id: WCChat.m,v 1.3 2004/03/13 23:22:35 morris Exp $ */ 
    22 
    33/* 
     
    248248        [_sortedUsers retain]; 
    249249 
     250        // --- update users 
     251        [self updateUserCount]; 
     252 
    250253        // --- and reload the table 
    251254        [_userListTableView reloadData]; 
     
    320323        } 
    321324 
     325        // --- update users 
     326        [self updateUserCount]; 
     327 
    322328        // --- reload the table 
    323329        [_userListTableView reloadData]; 
     
    369375        _sortedUsers = [_shownUsers keysSortedByValueUsingSelector:@selector(joinTimeSort:)]; 
    370376        [_sortedUsers retain]; 
     377 
     378        // --- update users 
     379        [self updateUserCount]; 
    371380 
    372381        // --- reload the table 
     
    425434        [user setNick:nick]; 
    426435 
     436        // --- update users 
     437        [self updateUserCount]; 
     438 
    427439        // --- reload the table 
    428440        [_userListTableView reloadData]; 
     
    478490        [_sortedUsers retain]; 
    479491 
     492        // --- update users 
     493        [self updateUserCount]; 
     494 
    480495        // --- reload the table 
    481496        [_userListTableView reloadData]; 
     
    530545        _sortedUsers = [_shownUsers keysSortedByValueUsingSelector:@selector(joinTimeSort:)]; 
    531546        [_sortedUsers retain]; 
     547 
     548        // --- update users 
     549        [self updateUserCount]; 
    532550 
    533551        // --- reload the table 
     
    945963 
    946964 
     965- (void)updateUserCount { 
     966        [_userCountTextField setStringValue:[NSString stringWithFormat: 
     967                NSLocalizedString(@"%u online, %u active", @"User list status"), 
     968                [self numberOfUsers], 
     969                [self numberOfActiveUsers]]]; 
     970} 
     971 
     972 
     973 
    947974- (void)saveChatToURL:(NSURL *)url { 
    948975        NSData          *data; 
     
    954981 
    955982 
    956 - (NSMutableDictionary *)users { 
    957         return _shownUsers; 
    958 } 
    959  
    960  
    961  
    962 - (unsigned int)cid { 
    963         return _cid; 
    964 } 
    965  
    966  
    967  
    968 - (BOOL)canGetInfo { 
    969         return ([_userListTableView selectedRow] >= 0) && [[_connection account] getUserInfo]; 
    970 } 
    971  
    972  
    973  
    974 #pragma mark - 
    975  
    976 - (IBAction)sendPrivateMessage:(id)sender { 
    977         NSNumber                *key; 
    978         WCUser                  *user; 
    979         WCMessage               *message; 
    980         int                             row; 
    981          
    982         // --- get row 
    983         row = [_userListTableView selectedRow]; 
    984  
    985         if(row < 0) 
    986                 return; 
    987  
    988         // --- get user 
    989         key             = [_sortedUsers objectAtIndex:row]; 
    990         user    = [_shownUsers objectForKey:key]; 
    991          
    992         // --- create a message 
    993         message = [[WCMessage alloc] initWithType:WCMessageTypeTo]; 
    994         [message setRead:YES]; 
    995         [message setUser:user]; 
    996         [message setDate:[NSDate date]]; 
    997          
    998         // --- send message to user 
    999         [(WCSendMessage *) [WCSendMessage alloc] initWithConnection:_connection message:message]; 
    1000          
    1001         [message release]; 
    1002 } 
    1003  
    1004  
    1005  
    1006 - (IBAction)info:(id)sender { 
    1007         NSNumber        *key; 
    1008         WCUser          *user; 
    1009         int                     row; 
    1010          
    1011         // --- get row 
    1012         row = [_userListTableView selectedRow];  
    1013  
    1014         if(row < 0) 
    1015                 return; 
    1016  
    1017         // --- get user 
    1018         key             = [_sortedUsers objectAtIndex:row]; 
    1019         user    = [_shownUsers objectForKey:key]; 
    1020          
    1021         // --- create a user info window 
    1022         [[WCUserInfo alloc] initWithConnection:_connection user:user]; 
    1023 } 
    1024  
    1025  
    1026  
    1027 - (IBAction)ignore:(id)sender { 
    1028         NSMutableArray          *ignores; 
    1029         NSDictionary            *ignore; 
    1030         NSNumber                        *key; 
    1031         WCUser                          *user; 
    1032         int                                     row; 
    1033          
    1034         // --- get row 
    1035         row = [_userListTableView selectedRow];  
    1036  
    1037         if(row < 0) 
    1038                 return; 
    1039  
    1040         // --- get user 
    1041         key             = [_sortedUsers objectAtIndex:row]; 
    1042         user    = [_shownUsers objectForKey:key]; 
    1043          
    1044         if([user ignore]) 
    1045                 return; 
    1046          
    1047         // --- create mutable ignores 
    1048         ignores = [NSMutableArray arrayWithArray:[WCSettings objectForKey:WCIgnoredUsers]]; 
    1049          
    1050         // --- create new ignore 
    1051         ignore = [NSDictionary dictionaryWithObjectsAndKeys: 
    1052                                 [user nick],    @"Nick", 
    1053                                 [user login],   @"Login", 
    1054                                 [user address], @"Address", 
    1055                                 NULL]; 
    1056  
    1057         // --- add to ignores 
    1058         [ignores addObject:ignore]; 
    1059  
    1060         // --- set new ignores 
    1061         [WCSettings setObject:[NSArray arrayWithArray:ignores] forKey:WCIgnoredUsers]; 
    1062          
    1063         // --- post reload table notification 
    1064         [[NSNotificationCenter defaultCenter] 
    1065                 postNotificationName:WCChatShouldReloadListing 
    1066                 object:NULL]; 
    1067 } 
    1068  
    1069  
    1070 - (IBAction)unignore:(id)sender { 
    1071         NSMutableArray          *ignores; 
    1072         NSDictionary            *ignore; 
    1073         NSEnumerator            *enumerator; 
    1074         NSNumber                        *key; 
    1075         WCUser                          *user; 
    1076         BOOL                            nick, login, address; 
    1077         int                                     row; 
    1078          
    1079         // --- get row 
    1080         row = [_userListTableView selectedRow];  
    1081  
    1082         if(row < 0) 
    1083                 return; 
    1084  
    1085         // --- get user 
    1086         key             = [_sortedUsers objectAtIndex:row]; 
    1087         user    = [_shownUsers objectForKey:key]; 
    1088          
    1089         if(![user ignore]) 
    1090                 return; 
    1091          
    1092         // --- create mutable ignores 
    1093         ignores = [NSMutableArray arrayWithArray:[WCSettings objectForKey:WCIgnoredUsers]]; 
    1094          
    1095         // --- while the user is still ignored, loop over all ignores and remove 
    1096         //     any that matches 
    1097         while([user ignore]) { 
    1098                 enumerator = [ignores objectEnumerator]; 
    1099  
    1100                 while((ignore = [enumerator nextObject])) { 
    1101                         nick = login = address = NO; 
    1102          
    1103                         if([[ignore objectForKey:@"Nick"] isEqualToString:[user nick]] || 
    1104                                 [[ignore objectForKey:@"Nick"] isEqualToString:@""]) 
    1105                                 nick = YES; 
    1106                          
    1107                         if([[ignore objectForKey:@"Login"] isEqualToString:[user login]] || 
    1108                                 [[ignore objectForKey:@"Login"] isEqualToString:@""]) 
    1109                                 login = YES; 
    1110                          
    1111                         if([[ignore objectForKey:@"Address"] isEqualToString:[user address]] || 
    1112                                 [[ignore objectForKey:@"Address"] isEqualToString:@""]) 
    1113                                 address = YES; 
    1114          
    1115                         if(nick && login && address) { 
    1116                                 // --- remove 
    1117                                 [ignores removeObject:ignore]; 
    1118  
    1119                                 // --- set new ignores 
    1120                                 [WCSettings setObject:[NSArray arrayWithArray:ignores] forKey:WCIgnoredUsers]; 
    1121                         } 
    1122                 } 
    1123         } 
    1124          
    1125         // --- post reload table notification 
    1126         [[NSNotificationCenter defaultCenter] 
    1127                 postNotificationName:WCChatShouldReloadListing 
    1128                 object:NULL]; 
    1129 } 
    1130  
    1131  
    1132  
    1133 #pragma mark - 
    1134  
    1135983- (void)printEvent:(NSString *)argument { 
    1136984        NSString        *output; 
     
    1138986        // --- create string 
    1139987        output = [NSString stringWithFormat: 
    1140                                @"%@<<< %@ >>>", 
    1141                                [[_chatOutputTextView textStorage] length] > 0 
    1142                                        ? @"\n" 
    1143                                        : @"", 
    1144                                argument]; 
     988                @"%@<<< %@ >>>", 
     989                [[_chatOutputTextView textStorage] length] > 0 
     990                ? @"\n" 
     991                : @"", 
     992                argument]; 
    1145993         
    1146994        // --- append 
    1147995        [[_chatOutputTextView textStorage] appendAttributedString:[_chatOutputTextView scan:output]]; 
    1148  
     996         
    1149997        // --- scroll 
    1150998        if([[_chatOutputScrollView verticalScroller] floatValue] == 1.0) { 
     
    11671015        if([command isEqualToString:@"/me"] && [argument length] > 0) { 
    11681016                unsigned long long      bytes; 
    1169  
     1017                 
    11701018                // --- send ME command 
    11711019                [[_connection client] sendCommand:[NSString stringWithFormat: 
    11721020                        @"%@ %u%@%@", WCMeCommand, _cid, WCFieldSeparator, argument]]; 
    1173  
    1174  
     1021                 
     1022                 
    11751023                // --- save in stats 
    11761024                bytes = [[WCStats objectForKey:WCStatsChat] unsignedLongLongValue] + 
     
    11941042                pipe            = [NSPipe pipe]; 
    11951043                fileHandle      = [pipe fileHandleForReading]; 
    1196  
     1044                 
    11971045                // --- modify the environment 
    11981046                environment     = [NSDictionary dictionaryWithObjectsAndKeys: 
    1199                         @"/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin", 
     1047                                                                                               @"/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin", 
    12001048                        @"PATH", 
    12011049                        NULL]; 
     
    12091057                [task setEnvironment:environment]; 
    12101058                [task launch]; 
    1211  
     1059                 
    12121060                // --- read output 
    12131061                while((buffer = [fileHandle availableData]) && [buffer length] > 0) { 
     
    12361084                 
    12371085                [task release]; 
    1238  
     1086                 
    12391087                return YES; 
    12401088        } 
    12411089        else if([command isEqualToString:@"/nick"] && [argument length] > 0) { 
    12421090                [[_connection client] sendCommand:WCNickCommand withArgument:argument]; 
    1243          
     1091                
    12441092                return YES; 
    12451093        } 
     
    12571105                [[_connection client] sendCommand:WCSayCommand withArgument:[NSString stringWithFormat: 
    12581106                        @"%u%@%@", _cid, WCFieldSeparator, [WCStats stats]]]; 
    1259  
     1107                 
    12601108                return YES; 
    12611109        } 
    12621110         
    12631111        return NO; 
     1112} 
     1113 
     1114 
     1115 
     1116 
     1117#pragma mark - 
     1118 
     1119- (NSMutableDictionary *)users { 
     1120        return _shownUsers; 
     1121} 
     1122 
     1123 
     1124 
     1125- (unsigned int)numberOfUsers { 
     1126        return [_shownUsers count]; 
     1127} 
     1128 
     1129 
     1130 
     1131- (unsigned int)numberOfActiveUsers { 
     1132        NSEnumerator    *enumerator; 
     1133        WCUser                  *each; 
     1134        unsigned int    active = 0; 
     1135         
     1136        enumerator = [_shownUsers objectEnumerator]; 
     1137         
     1138        while((each = [enumerator nextObject])) { 
     1139                if(![each idle]) 
     1140                        active++; 
     1141        } 
     1142 
     1143        return active; 
     1144} 
     1145 
     1146 
     1147 
     1148- (unsigned int)cid { 
     1149        return _cid; 
     1150} 
     1151 
     1152 
     1153 
     1154- (BOOL)canGetInfo { 
     1155        return ([_userListTableView selectedRow] >= 0) && [[_connection account] getUserInfo]; 
     1156} 
     1157 
     1158 
     1159 
     1160#pragma mark - 
     1161 
     1162- (IBAction)sendPrivateMessage:(id)sender { 
     1163        NSNumber                *key; 
     1164        WCUser                  *user; 
     1165        WCMessage               *message; 
     1166        int                             row; 
     1167         
     1168        // --- get row 
     1169        row = [_userListTableView selectedRow]; 
     1170 
     1171        if(row < 0) 
     1172                return; 
     1173 
     1174        // --- get user 
     1175        key             = [_sortedUsers objectAtIndex:row]; 
     1176        user    = [_shownUsers objectForKey:key]; 
     1177         
     1178        // --- create a message 
     1179        message = [[WCMessage alloc] initWithType:WCMessageTypeTo]; 
     1180        [message setRead:YES]; 
     1181        [message setUser:user]; 
     1182        [message setDate:[NSDate date]]; 
     1183         
     1184        // --- send message to user 
     1185        [(WCSendMessage *) [WCSendMessage alloc] initWithConnection:_connection message:message]; 
     1186         
     1187        [message release]; 
     1188} 
     1189 
     1190 
     1191 
     1192- (IBAction)info:(id)sender { 
     1193        NSNumber        *key; 
     1194        WCUser          *user; 
     1195        int                     row; 
     1196         
     1197        // --- get row 
     1198        row = [_userListTableView selectedRow];  
     1199 
     1200        if(row < 0) 
     1201                return; 
     1202 
     1203        // --- get user 
     1204        key             = [_sortedUsers objectAtIndex:row]; 
     1205        user    = [_shownUsers objectForKey:key]; 
     1206         
     1207        // --- create a user info window 
     1208        [[WCUserInfo alloc] initWithConnection:_connection user:user]; 
     1209} 
     1210 
     1211 
     1212 
     1213- (IBAction)ignore:(id)sender { 
     1214        NSMutableArray          *ignores; 
     1215        NSDictionary            *ignore; 
     1216        NSNumber                        *key; 
     1217        WCUser                          *user; 
     1218        int                                     row; 
     1219         
     1220        // --- get row 
     1221        row = [_userListTableView selectedRow];  
     1222 
     1223        if(row < 0) 
     1224                return; 
     1225 
     1226        // --- get user 
     1227        key             = [_sortedUsers objectAtIndex:row]; 
     1228        user    = [_shownUsers objectForKey:key]; 
     1229         
     1230        if([user ignore]) 
     1231                return; 
     1232         
     1233        // --- create mutable ignores 
     1234        ignores = [NSMutableArray arrayWithArray:[WCSettings objectForKey:WCIgnoredUsers]]; 
     1235         
     1236        // --- create new ignore 
     1237        ignore = [NSDictionary dictionaryWithObjectsAndKeys: 
     1238                                [user nick],    @"Nick", 
     1239                                [user login],   @"Login", 
     1240                                [user address], @"Address", 
     1241                                NULL]; 
     1242 
     1243        // --- add to ignores 
     1244        [ignores addObject:ignore]; 
     1245 
     1246        // --- set new ignores 
     1247        [WCSettings setObject:[NSArray arrayWithArray:ignores] forKey:WCIgnoredUsers]; 
     1248         
     1249        // --- post reload table notification 
     1250        [[NSNotificationCenter defaultCenter] 
     1251                postNotificationName:WCChatShouldReloadListing 
     1252                object:NULL]; 
     1253} 
     1254 
     1255 
     1256 
     1257- (IBAction)unignore:(id)sender { 
     1258        NSMutableArray          *ignores; 
     1259        NSDictionary            *ignore; 
     1260        NSEnumerator            *enumerator; 
     1261        NSNumber                        *key; 
     1262        WCUser                          *user; 
     1263        BOOL                            nick, login, address; 
     1264        int                                     row; 
     1265         
     1266        // --- get row 
     1267        row = [_userListTableView selectedRow];  
     1268 
     1269        if(row < 0) 
     1270                return; 
     1271 
     1272        // --- get user 
     1273        key             = [_sortedUsers objectAtIndex:row]; 
     1274        user    = [_shownUsers objectForKey:key]; 
     1275         
     1276        if(![user ignore]) 
     1277                return; 
     1278         
     1279        // --- create mutable ignores 
     1280        ignores = [NSMutableArray arrayWithArray:[WCSettings objectForKey:WCIgnoredUsers]]; 
     1281         
     1282        // --- while the user is still ignored, loop over all ignores and remove 
     1283        //     any that matches 
     1284        while([user ignore]) { 
     1285                enumerator = [ignores objectEnumerator]; 
     1286 
     1287                while((ignore = [enumerator nextObject])) { 
     1288                        nick = login = address = NO; 
     1289         
     1290                        if([[ignore objectForKey:@"Nick"] isEqualToString:[user nick]] || 
     1291                                [[ignore objectForKey:@"Nick"] isEqualToString:@""]) 
     1292                                nick = YES; 
     1293                         
     1294                        if([[ignore objectForKey:@"Login"] isEqualToString:[user login]] || 
     1295                                [[ignore objectForKey:@"Login"] isEqualToString:@""]) 
     1296                                login = YES; 
     1297                         
     1298                        if([[ignore objectForKey:@"Address"] isEqualToString:[user address]] || 
     1299                                [[ignore objectForKey:@"Address"] isEqualToString:@""]) 
     1300                                address = YES; 
     1301         
     1302                        if(nick && login && address) { 
     1303                                // --- remove 
     1304                                [ignores removeObject:ignore]; 
     1305 
     1306                                // --- set new ignores 
     1307                                [WCSettings setObject:[NSArray arrayWithArray:ignores] forKey:WCIgnoredUsers]; 
     1308                        } 
     1309                } 
     1310        } 
     1311         
     1312        // --- post reload table notification 
     1313        [[NSNotificationCenter defaultCenter] 
     1314                postNotificationName:WCChatShouldReloadListing 
     1315                object:NULL]; 
    12641316} 
    12651317