| 1 |
#import <ChatCore/MVChatConnection.h> |
|---|
| 2 |
#import "JVChatMemberInspector.h" |
|---|
| 3 |
#import "JVBuddy.h" |
|---|
| 4 |
#import "MVFileTransferController.h" |
|---|
| 5 |
|
|---|
| 6 |
@implementation JVChatRoomMember (JVChatRoomMemberInspection) |
|---|
| 7 |
- (id <JVInspector>) inspector { |
|---|
| 8 |
return [[[JVChatMemberInspector alloc] initWithChatMember:self] autorelease]; |
|---|
| 9 |
} |
|---|
| 10 |
@end |
|---|
| 11 |
|
|---|
| 12 |
#pragma mark - |
|---|
| 13 |
|
|---|
| 14 |
@implementation JVChatMemberInspector |
|---|
| 15 |
- (id) initWithChatMember:(JVChatRoomMember *) member { |
|---|
| 16 |
if( ( self = [self init] ) ) { |
|---|
| 17 |
_member = [member retain]; |
|---|
| 18 |
_localOnly = NO; |
|---|
| 19 |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector( gotUserWhois: ) name:MVChatConnectionGotUserWhoisNotification object:[_member connection]]; |
|---|
| 20 |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector( gotUserServer: ) name:MVChatConnectionGotUserServerNotification object:[_member connection]]; |
|---|
| 21 |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector( gotUserChannels: ) name:MVChatConnectionGotUserChannelsNotification object:[_member connection]]; |
|---|
| 22 |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector( gotUserOperator: ) name:MVChatConnectionGotUserOperatorNotification object:[_member connection]]; |
|---|
| 23 |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector( gotUserIdle: ) name:MVChatConnectionGotUserIdleNotification object:[_member connection]]; |
|---|
| 24 |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector( gotUserWhoisComplete: ) name:MVChatConnectionGotUserWhoisCompleteNotification object:[_member connection]]; |
|---|
| 25 |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector( gotAwayStatus: ) name:MVChatConnectionUserAwayStatusNotification object:[_member connection]]; |
|---|
| 26 |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector( errorOccurred : ) name:MVChatConnectionErrorNotification object:[_member connection]]; |
|---|
| 27 |
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector( gotCTCPResponse: ) name:MVChatConnectionSubcodeReplyNotification object:[_member connection]]; |
|---|
| 28 |
} |
|---|
| 29 |
return self; |
|---|
| 30 |
} |
|---|
| 31 |
|
|---|
| 32 |
- (void) dealloc { |
|---|
| 33 |
[[NSNotificationCenter defaultCenter] removeObserver:self]; |
|---|
| 34 |
|
|---|
| 35 |
[_member release]; |
|---|
| 36 |
_member = nil; |
|---|
| 37 |
|
|---|
| 38 |
[super dealloc]; |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
#pragma mark - |
|---|
| 42 |
|
|---|
| 43 |
- (NSView *) view { |
|---|
| 44 |
if( ! _nibLoaded ) _nibLoaded = [NSBundle loadNibNamed:@"JVChatMemberInspector" owner:self]; |
|---|
| 45 |
return view; |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
- (NSSize) minSize { |
|---|
| 49 |
return NSMakeSize( 220., 359. ); |
|---|
| 50 |
} |
|---|
| 51 |
|
|---|
| 52 |
- (NSString *) title { |
|---|
| 53 |
return [_member nickname]; |
|---|
| 54 |
} |
|---|
| 55 |
|
|---|
| 56 |
- (NSString *) type { |
|---|
| 57 |
return NSLocalizedString( @"User", "chat user inspector type" ); |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
- (void) willLoad { |
|---|
| 61 |
[progress startAnimation:nil]; |
|---|
| 62 |
_whoisComplete = NO; |
|---|
| 63 |
_addressResolved = NO; |
|---|
| 64 |
_classSet = NO; |
|---|
| 65 |
[nickname setObjectValue:[_member nickname]]; |
|---|
| 66 |
if( [[_member buddy] picture] ) [image setImage:[[_member buddy] picture]]; |
|---|
| 67 |
[[_member connection] fetchInformationForUser:[_member nickname] withPriority:NO fromLocalServer:_localOnly]; |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
#pragma mark - |
|---|
| 71 |
|
|---|
| 72 |
- (void) setFetchLocalServerInfoOnly:(BOOL) localOnly { |
|---|
| 73 |
_localOnly = localOnly; |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
- (void) gotAddress:(NSString *) ip { |
|---|
| 77 |
[address setObjectValue:( ip ? ip : NSLocalizedString( @"n/a", "not applicable or not available" ) )]; |
|---|
| 78 |
[address setToolTip:( ip ? ip : nil )]; |
|---|
| 79 |
_addressResolved = YES; |
|---|
| 80 |
if (_whoisComplete) |
|---|
| 81 |
[progress stopAnimation:nil]; |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
- (oneway void) lookupAddress:(NSString *) host { |
|---|
| 85 |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
|---|
| 86 |
NSString *ip = [[NSHost hostWithName:host] address]; |
|---|
| 87 |
[self performSelectorOnMainThread:@selector(gotAddress:) withObject:ip waitUntilDone:YES]; |
|---|
| 88 |
[pool release]; |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 |
|
|---|
| 98 |
|
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
|
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
|
|---|
| 112 |
|
|---|
| 113 |
|
|---|
| 114 |
- (void) gotUserWhois:(NSNotification *) notification { |
|---|
| 115 |
if( [[[notification userInfo] objectForKey:@"who"] caseInsensitiveCompare:[_member nickname]] != NSOrderedSame ) return; |
|---|
| 116 |
[username setObjectValue:[[notification userInfo] objectForKey:@"username"]]; |
|---|
| 117 |
[hostname setObjectValue:[[notification userInfo] objectForKey:@"hostname"]]; |
|---|
| 118 |
[hostname setToolTip:[[notification userInfo] objectForKey:@"hostname"]]; |
|---|
| 119 |
[NSThread detachNewThreadSelector:@selector( lookupAddress: ) toTarget:self withObject:[[[[notification userInfo] objectForKey:@"hostname"] copy] autorelease]]; |
|---|
| 120 |
[realName setObjectValue:[[notification userInfo] objectForKey:@"realname"]]; |
|---|
| 121 |
[realName setToolTip:[[notification userInfo] objectForKey:@"realname"]]; |
|---|
| 122 |
} |
|---|
| 123 |
|
|---|
| 124 |
- (void) gotUserServer:(NSNotification *) notification { |
|---|
| 125 |
if( [[[notification userInfo] objectForKey:@"who"] caseInsensitiveCompare:[_member nickname]] != NSOrderedSame ) return; |
|---|
| 126 |
[server setObjectValue:[[notification userInfo] objectForKey:@"server"]]; |
|---|
| 127 |
} |
|---|
| 128 |
|
|---|
| 129 |
- (void) gotUserChannels:(NSNotification *) notification { |
|---|
| 130 |
if( [[[notification userInfo] objectForKey:@"who"] caseInsensitiveCompare:[_member nickname]] != NSOrderedSame ) return; |
|---|
| 131 |
[rooms setObjectValue:[[[notification userInfo] objectForKey:@"channels"] componentsJoinedByString:@" "]]; |
|---|
| 132 |
} |
|---|
| 133 |
|
|---|
| 134 |
- (void) gotUserOperator:(NSNotification *) notification { |
|---|
| 135 |
if( [[[notification userInfo] objectForKey:@"who"] caseInsensitiveCompare:[_member nickname]] != NSOrderedSame ) return; |
|---|
| 136 |
_classSet = YES; |
|---|
| 137 |
[class setObjectValue:NSLocalizedString( @"Server operator", "server operator class" )]; |
|---|
| 138 |
} |
|---|
| 139 |
|
|---|
| 140 |
- (void) gotUserIdle:(NSNotification *) notification { |
|---|
| 141 |
if( [[[notification userInfo] objectForKey:@"who"] caseInsensitiveCompare:[_member nickname]] != NSOrderedSame ) return; |
|---|
| 142 |
[connected setObjectValue:MVReadableTime( [[[notification userInfo] objectForKey:@"connected"] doubleValue], YES )]; |
|---|
| 143 |
[idle setObjectValue:MVReadableTime( [[NSDate date] timeIntervalSince1970] + [[[notification userInfo] objectForKey:@"idle"] doubleValue], YES )]; |
|---|
| 144 |
} |
|---|
| 145 |
|
|---|
| 146 |
- (void) gotUserWhoisComplete:(NSNotification *) notification { |
|---|
| 147 |
if( [[[notification userInfo] objectForKey:@"who"] caseInsensitiveCompare:[_member nickname]] != NSOrderedSame ) return; |
|---|
| 148 |
_whoisComplete = YES; |
|---|
| 149 |
if (!_classSet) |
|---|
| 150 |
[class setObjectValue:NSLocalizedString( @"Normal user", "normal user class" )]; |
|---|
| 151 |
if (_addressResolved) |
|---|
| 152 |
[progress stopAnimation:nil]; |
|---|
| 153 |
} |
|---|
| 154 |
|
|---|
| 155 |
- (void) gotAwayStatus:(NSNotification *) notification { |
|---|
| 156 |
if( [[[notification userInfo] objectForKey:@"who"] caseInsensitiveCompare:[_member nickname]] != NSOrderedSame ) return; |
|---|
| 157 |
NSData *data = [[notification userInfo] objectForKey:@"message"]; |
|---|
| 158 |
NSString *strMsg = [[[NSString alloc] initWithData:data encoding:[[_member connection] encoding]] autorelease]; |
|---|
| 159 |
if( ! strMsg ) strMsg = [NSString stringWithCString:[data bytes] length:[data length]]; |
|---|
| 160 |
[away setObjectValue:strMsg]; |
|---|
| 161 |
} |
|---|
| 162 |
|
|---|
| 163 |
- (void) errorOccurred:(NSNotification *) notification { |
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
|
|---|
| 172 |
} |
|---|
| 173 |
|
|---|
| 174 |
- (void) gotCTCPResponse:(NSNotification *) notification { |
|---|
| 175 |
if( [[[notification userInfo] objectForKey:@"from"] caseInsensitiveCompare:[_member nickname]] != NSOrderedSame ) return; |
|---|
| 176 |
if( [[[notification userInfo] objectForKey:@"command"] caseInsensitiveCompare:@"VERSION"] == NSOrderedSame ) { |
|---|
| 177 |
[clientInfo setStringValue:[[notification userInfo] objectForKey:@"arguments"]]; |
|---|
| 178 |
} |
|---|
| 179 |
} |
|---|
| 180 |
|
|---|
| 181 |
- (IBAction) sendPing:(id) sender { |
|---|
| 182 |
[[_member connection] sendSubcodeRequest:@"PING" toUser:[_member nickname] withArguments:nil]; |
|---|
| 183 |
} |
|---|
| 184 |
|
|---|
| 185 |
- (IBAction) requestLocalTime:(id) sender { |
|---|
| 186 |
[[_member connection] sendSubcodeRequest:@"TIME" toUser:[_member nickname] withArguments:nil]; |
|---|
| 187 |
} |
|---|
| 188 |
|
|---|
| 189 |
- (IBAction) requestClientInfo:(id) sender { |
|---|
| 190 |
[[_member connection] sendSubcodeRequest:@"VERSION" toUser:[_member nickname] withArguments:nil]; |
|---|
| 191 |
} |
|---|
| 192 |
@end |
|---|