IChatUtils.m
author Jens Alfke <jens@mooseyard.com>
Wed Apr 02 14:45:33 2008 -0700 (2008-04-02)
changeset 2 3d3dcc3116d5
child 4 64823cdde6a5
permissions -rw-r--r--
UniqueWindowController finds windows that are miniaturized.
Added some date and more graphics utilities.
jens@0
     1
//
jens@0
     2
//  IChatUtils.m
jens@0
     3
//  MYUtilities
jens@0
     4
//
jens@0
     5
//  Created by Jens Alfke on 3/3/08.
jens@0
     6
//  Copyright 2008 Jens Alfke. All rights reserved.
jens@0
     7
//
jens@0
     8
jens@0
     9
#import "IChatUtils.h"
jens@0
    10
#import "iChatBridge.h"
jens@0
    11
jens@0
    12
@implementation IChatUtils
jens@0
    13
jens@0
    14
jens@0
    15
static iChatApplication *sIChatApp;
jens@0
    16
jens@0
    17
+ (void) initialize
jens@0
    18
{
jens@0
    19
    if( ! sIChatApp ) {
jens@0
    20
        sIChatApp = [SBApplication applicationWithBundleIdentifier: @"com.apple.iChat"];
jens@0
    21
        sIChatApp.timeout = 5*60; // in ticks
jens@0
    22
    }
jens@0
    23
}
jens@0
    24
jens@0
    25
jens@0
    26
+ (SBApplication*) app  {return sIChatApp;}
jens@0
    27
+ (BOOL) isRunning      {return sIChatApp.isRunning;}
jens@0
    28
+ (void) activate       {[sIChatApp activate];}
jens@0
    29
jens@0
    30
jens@0
    31
+ (iChatTextChat*) activeChat
jens@0
    32
{
jens@0
    33
    if( ! [sIChatApp isRunning] )
jens@0
    34
        return nil;
jens@0
    35
    SBElementArray *chats = sIChatApp.textChats;
jens@0
    36
    if( chats.count==0 )
jens@0
    37
        return nil;
jens@0
    38
    iChatTextChat *chat = [chats objectAtIndex: 0];
jens@0
    39
    if( ! chat.active )
jens@0
    40
        return nil;
jens@0
    41
    return chat;
jens@0
    42
}    
jens@0
    43
jens@0
    44
+ (NSString*) activeChatPartner
jens@0
    45
{
jens@0
    46
    iChatTextChat *chat = [self activeChat];
jens@0
    47
    if( ! chat )
jens@0
    48
        return nil;
jens@0
    49
    NSMutableArray *names = $marray();
jens@0
    50
    for( iChatBuddy *b in [chat participants] )
jens@0
    51
        [names addObject: (b.fullName ?: b.name)];
jens@0
    52
    return [names componentsJoinedByString: @", "];
jens@0
    53
}
jens@0
    54
jens@0
    55
+ (BOOL) sendMessage: (NSString*)msg
jens@0
    56
{
jens@0
    57
    iChatTextChat *chat = [self activeChat];
jens@0
    58
    if( ! chat )
jens@0
    59
        return NO;
jens@0
    60
    [sIChatApp send: msg to: chat];
jens@0
    61
    return YES;
jens@0
    62
}
jens@0
    63
jens@0
    64
jens@0
    65
@end