Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

120 columns in AccountController

  • Loading branch information...
commit ea20225d2594155bd2932916fdc9a3ada862e455 1 parent 89fa954
@eofster authored
View
91 Classes/AccountController.h
@@ -36,9 +36,9 @@
// Account states.
enum {
- kSIPAccountOffline = 1,
- kSIPAccountUnavailable = 2,
- kSIPAccountAvailable = 3
+ kSIPAccountOffline = 1,
+ kSIPAccountUnavailable = 2,
+ kSIPAccountAvailable = 3
};
// Address Book label for SIP address in the email field.
@@ -50,27 +50,27 @@ extern NSString * const kEmailSIPLabel;
// A SIP account controller.
@interface AccountController : XSWindowController <AKSIPAccountDelegate> {
- @private
- BOOL enabled_;
- AKSIPAccount *account_;
- NSMutableArray *callControllers_;
- NSString *accountDescription_;
- BOOL attemptingToRegisterAccount_;
- BOOL attemptingToUnregisterAccount_;
- BOOL shouldPresentRegistrationError_;
- BOOL accountUnavailable_;
- NSTimer *reRegistrationTimer_;
- BOOL shouldMakeCall_;
- NSString *catchedURLString_;
- AKNetworkReachability *registrarReachability_;
-
- BOOL substitutesPlusCharacter_;
- NSString *plusCharacterSubstitution_;
-
- ActiveAccountViewController *activeAccountViewController_;
- AuthenticationFailureController *authenticationFailureController_;
-
- NSPopUpButton *accountStatePopUp_;
+ @private
+ BOOL enabled_;
+ AKSIPAccount *account_;
+ NSMutableArray *callControllers_;
+ NSString *accountDescription_;
+ BOOL attemptingToRegisterAccount_;
+ BOOL attemptingToUnregisterAccount_;
+ BOOL shouldPresentRegistrationError_;
+ BOOL accountUnavailable_;
+ NSTimer *reRegistrationTimer_;
+ BOOL shouldMakeCall_;
+ NSString *catchedURLString_;
+ AKNetworkReachability *registrarReachability_;
+
+ BOOL substitutesPlusCharacter_;
+ NSString *plusCharacterSubstitution_;
+
+ ActiveAccountViewController *activeAccountViewController_;
+ AuthenticationFailureController *authenticationFailureController_;
+
+ NSPopUpButton *accountStatePopUp_;
}
// A Boolean value indicating whether receiver is enabled.
@@ -88,36 +88,31 @@ extern NSString * const kEmailSIPLabel;
// Account description.
@property (nonatomic, copy) NSString *accountDescription;
-// A Boolean value indicating whether a user is attempting to register
-// an account.
+// A Boolean value indicating whether a user is attempting to register an account.
@property (nonatomic, assign) BOOL attemptingToRegisterAccount;
-// A Boolean value indicating whether a user is attempting to unregister
-// an account.
+// A Boolean value indicating whether a user is attempting to unregister an account.
@property (nonatomic, assign) BOOL attemptingToUnregisterAccount;
-// A Boolean value indicting whether the receiver should present account
-// registration error to the user.
+// A Boolean value indicting whether the receiver should present account registration error to the user.
@property (nonatomic, assign) BOOL shouldPresentRegistrationError;
-// A Boolean value indicating whether account is unavailable. When it is, we
-// reply with |480 Temporarily Unavailable| to all incoming calls.
+// A Boolean value indicating whether account is unavailable. When it is, we reply with |480 Temporarily Unavailable|
+// to all incoming calls.
@property (nonatomic, assign, getter=isAccountUnavailable) BOOL accountUnavailable;
// A Boolean value indicating whether the receiver should make a call ASAP.
-// (User can initiate a call from the Address Book when application is not
-// yet launched.)
+// (User can initiate a call from the Address Book when application is not yet launched.)
@property (nonatomic, assign) BOOL shouldMakeCall;
// URL string catched by the URL handler.
@property (nonatomic, copy) NSString *catchedURLString;
-// Registrar network reachability. When registrar becomes reachable, we try to
-// register the receiver's account.
+// Registrar network reachability. When registrar becomes reachable, we try to register the receiver's account.
@property (nonatomic, retain) AKNetworkReachability *registrarReachability;
-// A Boolean value indicating whether a plus character at the beginning of the
-// phone number to be dialed should be replaced.
+// A Boolean value indicating whether a plus character at the beginning of the phone number to be dialed should be
+// replaced.
@property (nonatomic, assign) BOOL substitutesPlusCharacter;
// A replacement for the plus character in the phone number.
@@ -137,8 +132,7 @@ extern NSString * const kEmailSIPLabel;
// Initializes an AccountController object with a given account.
- (id)initWithSIPAccount:(AKSIPAccount *)anAccount;
-// Initializes an AccountController object with a given full name, SIP address,
-// regisrar, realm, and user name.
+// Initializes an AccountController object with a given full name, SIP address, regisrar, realm, and user name.
- (id)initWithFullName:(NSString *)aFullName
SIPAddress:(NSString *)aSIPAddress
registrar:(NSString *)aRegistrar
@@ -149,18 +143,15 @@ extern NSString * const kEmailSIPLabel;
- (void)removeAccountFromUserAgent;
// Makes a call to a given destination URI with a given phone label.
-// When |callTransferController| is not nil, no new window will be created,
-// existing |callTransferController| will be used instead.
-// Host part of the |destinationURI| can be empty, in which case host part from
-// the account's |registrationURI| will be taken.
+// When |callTransferController| is not nil, no new window will be created, existing |callTransferController| will be
+// used instead. Host part of the |destinationURI| can be empty, in which case host part from the account's
+// |registrationURI| will be taken.
- (void)makeCallToURI:(AKSIPURI *)destinationURI
- phoneLabel:(NSString *)phoneLabel
- callTransferController:(CallTransferController *)callTransferController;
+ phoneLabel:(NSString *)phoneLabel
+ callTransferController:(CallTransferController *)callTransferController;
-// Calls makeCallToURI:phoneLabel:callTransferController: with
-// |callTransferController| set to nil.
-- (void)makeCallToURI:(AKSIPURI *)destinationURI
- phoneLabel:(NSString *)phoneLabel;
+// Calls makeCallToURI:phoneLabel:callTransferController: with |callTransferController| set to nil.
+- (void)makeCallToURI:(AKSIPURI *)destinationURI phoneLabel:(NSString *)phoneLabel;
// Changes account state.
- (IBAction)changeAccountState:(id)sender;
View
1,777 Classes/AccountController.m
@@ -115,164 +115,150 @@ @implementation AccountController
@synthesize accountStatePopUp = accountStatePopUp_;
- (void)setEnabled:(BOOL)flag {
- enabled_ = flag;
-
- NSNotificationCenter *notificationCenter
- = [NSNotificationCenter defaultCenter];
-
- if (flag) {
- AKNetworkReachability *reachability
- = [AKNetworkReachability networkReachabilityWithHost:
- [[self account] registrar]];
- [self setRegistrarReachability:reachability];
-
- if (reachability != nil) {
- [notificationCenter
- addObserver:self
- selector:@selector(networkReachabilityDidBecomeReachable:)
- name:AKNetworkReachabilityDidBecomeReachableNotification
- object:reachability];
- }
- } else {
- if ([self registrarReachability] != nil) {
- [notificationCenter
- removeObserver:self
- name:AKNetworkReachabilityDidBecomeReachableNotification
- object:[self registrarReachability]];
-
- [self setRegistrarReachability:nil];
+ enabled_ = flag;
+
+ NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
+
+ if (flag) {
+ AKNetworkReachability *reachability
+ = [AKNetworkReachability networkReachabilityWithHost:[[self account] registrar]];
+ [self setRegistrarReachability:reachability];
+
+ if (reachability != nil) {
+ [notificationCenter addObserver:self
+ selector:@selector(networkReachabilityDidBecomeReachable:)
+ name:AKNetworkReachabilityDidBecomeReachableNotification
+ object:reachability];
+ }
+ } else {
+ if ([self registrarReachability] != nil) {
+ [notificationCenter removeObserver:self
+ name:AKNetworkReachabilityDidBecomeReachableNotification
+ object:[self registrarReachability]];
+
+ [self setRegistrarReachability:nil];
+ }
}
- }
}
- (BOOL)isAccountRegistered {
- return [[self account] isRegistered];
+ return [[self account] isRegistered];
}
- (void)setAccountRegistered:(BOOL)flag {
- if ([self reRegistrationTimer] != nil) {
- [[self reRegistrationTimer] invalidate];
- [self setReRegistrationTimer:nil];
- }
-
- if ([[self account] identifier] != kAKSIPUserAgentInvalidIdentifier) {
- // Account has been added.
- [self showConnectingState];
-
- [[self account] setRegistered:flag];
-
- } else {
- NSString *serviceName = [NSString stringWithFormat:@"SIP: %@",
- [[self account] registrar]];
- NSString *password
- = [AKKeychain passwordForServiceName:serviceName
- accountName:[[self account] username]];
-
- [self showConnectingState];
-
- BOOL accountAdded = [[[NSApp delegate] userAgent] addAccount:[self account]
- withPassword:password];
-
- // Error connecting to registrar.
- if (accountAdded &&
- ![self isAccountRegistered] &&
- [[self account] registrationExpireTime] < 0 &&
- [[[NSApp delegate] userAgent] isStarted]) {
-
- [self showUnavailableState];
-
- // Schedule account automatic re-registration timer.
- if ([self reRegistrationTimer] == nil) {
- NSTimeInterval reregistrationTimeInterval
- = (NSTimeInterval)[[self account] reregistrationTime];
+ if ([self reRegistrationTimer] != nil) {
+ [[self reRegistrationTimer] invalidate];
+ [self setReRegistrationTimer:nil];
+ }
+
+ if ([[self account] identifier] != kAKSIPUserAgentInvalidIdentifier) {
+ // Account has been added.
+ [self showConnectingState];
- [self setReRegistrationTimer:
- [NSTimer
- scheduledTimerWithTimeInterval:reregistrationTimeInterval
- target:self
- selector:@selector(reRegistrationTimerTick:)
- userInfo:nil
- repeats:YES]];
- }
+ [[self account] setRegistered:flag];
- if ([self shouldPresentRegistrationError]) {
- NSString *statusText;
- NSString *preferredLocalization
- = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
- if ([preferredLocalization isEqualToString:@"Russian"]) {
- statusText = [[NSApp delegate] localizedStringForSIPResponseCode:
- [[self account] registrationStatus]];
- } else {
- statusText = [[self account] registrationStatusText];
- }
+ } else {
+ NSString *serviceName = [NSString stringWithFormat:@"SIP: %@",
+ [[self account] registrar]];
+ NSString *password = [AKKeychain passwordForServiceName:serviceName accountName:[[self account] username]];
- NSString *error;
- if (statusText == nil) {
- error = [NSString stringWithFormat:
- NSLocalizedString(@"Error %d", @"Error #."),
- [[self account] registrationStatus]];
- error = [error stringByAppendingString:@"."];
- } else {
- error = [NSString stringWithFormat:
- NSLocalizedString(@"The error was: \\U201C%d %@\\U201D.",
- @"Error description."),
- [[self account] registrationStatus], statusText];
- }
+ [self showConnectingState];
- [self showRegistrarConnectionErrorSheetWithError:error];
- }
-
- [self setShouldPresentRegistrationError:NO];
+ BOOL accountAdded = [[[NSApp delegate] userAgent] addAccount:[self account] withPassword:password];
+
+ // Error connecting to registrar.
+ if (accountAdded &&
+ ![self isAccountRegistered] &&
+ [[self account] registrationExpireTime] < 0 &&
+ [[[NSApp delegate] userAgent] isStarted]) {
+
+ [self showUnavailableState];
+
+ // Schedule account automatic re-registration timer.
+ if ([self reRegistrationTimer] == nil) {
+ NSTimeInterval reregistrationTimeInterval = (NSTimeInterval)[[self account] reregistrationTime];
+
+ [self setReRegistrationTimer:
+ [NSTimer scheduledTimerWithTimeInterval:reregistrationTimeInterval
+ target:self
+ selector:@selector(reRegistrationTimerTick:)
+ userInfo:nil
+ repeats:YES]];
+ }
+
+ if ([self shouldPresentRegistrationError]) {
+ NSString *statusText;
+ NSString *preferredLocalization = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
+ if ([preferredLocalization isEqualToString:@"Russian"]) {
+ statusText = [[NSApp delegate] localizedStringForSIPResponseCode:
+ [[self account] registrationStatus]];
+ } else {
+ statusText = [[self account] registrationStatusText];
+ }
+
+ NSString *error;
+ if (statusText == nil) {
+ error = [NSString stringWithFormat:
+ NSLocalizedString(@"Error %d", @"Error #."),
+ [[self account] registrationStatus]];
+ error = [error stringByAppendingString:@"."];
+ } else {
+ error = [NSString stringWithFormat:
+ NSLocalizedString(@"The error was: \\U201C%d %@\\U201D.", @"Error description."),
+ [[self account] registrationStatus], statusText];
+ }
+
+ [self showRegistrarConnectionErrorSheetWithError:error];
+ }
+
+ [self setShouldPresentRegistrationError:NO];
+ }
}
- }
}
- (ActiveAccountViewController *)activeAccountViewController {
- if (activeAccountViewController_ == nil) {
- activeAccountViewController_
- = [[ActiveAccountViewController alloc] initWithAccountController:self
- windowController:self];
- }
-
- return activeAccountViewController_;
+ if (activeAccountViewController_ == nil) {
+ activeAccountViewController_ = [[ActiveAccountViewController alloc] initWithAccountController:self
+ windowController:self];
+ }
+
+ return activeAccountViewController_;
}
- (AuthenticationFailureController *)authenticationFailureController {
- if (authenticationFailureController_ == nil) {
- authenticationFailureController_ = [[AuthenticationFailureController alloc]
- initWithAccountController:self];
- }
-
- return authenticationFailureController_;
+ if (authenticationFailureController_ == nil) {
+ authenticationFailureController_ = [[AuthenticationFailureController alloc] initWithAccountController:self];
+ }
+
+ return authenticationFailureController_;
}
- (id)initWithSIPAccount:(AKSIPAccount *)anAccount {
- self = [super initWithWindowNibName:@"Account"];
- if (self == nil) {
- return nil;
- }
-
- [self setAccount:anAccount];
- callControllers_ = [[NSMutableArray alloc] init];
- [self setSubstitutesPlusCharacter:NO];
-
- [self setAttemptingToRegisterAccount:NO];
- [self setAttemptingToUnregisterAccount:NO];
- [self setShouldPresentRegistrationError:NO];
- [self setAccountUnavailable:NO];
- [self setShouldMakeCall:NO];
-
- [[self account] setDelegate:self];
-
- [[self window] setTitle:[[self account] SIPAddress]];
-
- [[NSNotificationCenter defaultCenter]
- addObserver:self
- selector:@selector(SIPUserAgentDidFinishStarting:)
- name:AKSIPUserAgentDidFinishStartingNotification
- object:nil];
-
- return self;
+ self = [super initWithWindowNibName:@"Account"];
+ if (self == nil) {
+ return nil;
+ }
+
+ [self setAccount:anAccount];
+ callControllers_ = [[NSMutableArray alloc] init];
+ [self setSubstitutesPlusCharacter:NO];
+
+ [self setAttemptingToRegisterAccount:NO];
+ [self setAttemptingToUnregisterAccount:NO];
+ [self setShouldPresentRegistrationError:NO];
+ [self setAccountUnavailable:NO];
+ [self setShouldMakeCall:NO];
+
+ [[self account] setDelegate:self];
+
+ [[self window] setTitle:[[self account] SIPAddress]];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(SIPUserAgentDidFinishStarting:)
+ name:AKSIPUserAgentDidFinishStartingNotification
+ object:nil];
+
+ return self;
}
- (id)initWithFullName:(NSString *)aFullName
@@ -280,420 +266,367 @@ - (id)initWithFullName:(NSString *)aFullName
registrar:(NSString *)aRegistrar
realm:(NSString *)aRealm
username:(NSString *)aUsername {
-
- AKSIPAccount *anAccount = [AKSIPAccount SIPAccountWithFullName:aFullName
- SIPAddress:aSIPAddress
- registrar:aRegistrar
- realm:aRealm
- username:aUsername];
-
- return [self initWithSIPAccount:anAccount];
+
+ AKSIPAccount *anAccount = [AKSIPAccount SIPAccountWithFullName:aFullName
+ SIPAddress:aSIPAddress
+ registrar:aRegistrar
+ realm:aRealm
+ username:aUsername];
+
+ return [self initWithSIPAccount:anAccount];
}
- (void)dealloc {
- for (CallController *aCallController in [self callControllers]) {
- [aCallController close];
- }
-
- if ([[[self account] delegate] isEqual:self]) {
- [[self account] setDelegate:nil];
- }
-
- [[NSNotificationCenter defaultCenter] removeObserver:self];
-
- // Close authentication failure sheet if it's raised.
- [[authenticationFailureController_ cancelButton] performClick:nil];
-
- [account_ release];
- [callControllers_ release];
- [accountDescription_ release];
- [catchedURLString_ release];
- [registrarReachability_ release];
- [plusCharacterSubstitution_ release];
-
- [activeAccountViewController_ release];
-
- [accountStatePopUp_ release];
-
- [super dealloc];
+ for (CallController *aCallController in [self callControllers]) {
+ [aCallController close];
+ }
+
+ if ([[[self account] delegate] isEqual:self]) {
+ [[self account] setDelegate:nil];
+ }
+
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+
+ // Close authentication failure sheet if it's raised.
+ [[authenticationFailureController_ cancelButton] performClick:nil];
+
+ [account_ release];
+ [callControllers_ release];
+ [accountDescription_ release];
+ [catchedURLString_ release];
+ [registrarReachability_ release];
+ [plusCharacterSubstitution_ release];
+
+ [activeAccountViewController_ release];
+
+ [accountStatePopUp_ release];
+
+ [super dealloc];
}
- (NSString *)description {
- return [NSString stringWithFormat:@"%@ controller", [self account]];
+ return [NSString stringWithFormat:@"%@ controller", [self account]];
}
- (void)awakeFromNib {
- [self setShouldCascadeWindows:NO];
- [[self window] setFrameAutosaveName:[[self account] SIPAddress]];
+ [self setShouldCascadeWindows:NO];
+ [[self window] setFrameAutosaveName:[[self account] SIPAddress]];
}
- (void)removeAccountFromUserAgent {
- NSAssert([self isEnabled],
- @"Account conroller must be enabled to remove account "
- "from the user agent.");
-
- if ([self reRegistrationTimer] != nil) {
- [[self reRegistrationTimer] invalidate];
- [self setReRegistrationTimer:nil];
- }
-
- [self showOfflineState];
- [[[NSApp delegate] userAgent] removeAccount:[self account]];
+ NSAssert([self isEnabled], @"Account conroller must be enabled to remove account from the user agent.");
+
+ if ([self reRegistrationTimer] != nil) {
+ [[self reRegistrationTimer] invalidate];
+ [self setReRegistrationTimer:nil];
+ }
+
+ [self showOfflineState];
+ [[[NSApp delegate] userAgent] removeAccount:[self account]];
}
- (void)makeCallToURI:(AKSIPURI *)destinationURI
- phoneLabel:(NSString *)phoneLabel
- callTransferController:(CallTransferController *)callTransferController {
-
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- AKTelephoneNumberFormatter *telephoneNumberFormatter
- = [[[AKTelephoneNumberFormatter alloc] init] autorelease];
- [telephoneNumberFormatter setSplitsLastFourDigits:
- [defaults boolForKey:kTelephoneNumberFormatterSplitsLastFourDigits]];
-
- NSString *enteredCallDestinationString
- = [[[destinationURI user] copy] autorelease];
-
- // Make user part a string of contiguous digits if needed.
- if (![[destinationURI user] ak_hasLetters]) {
- [destinationURI setUser:
- [telephoneNumberFormatter telephoneNumberFromString:
- [destinationURI user]]];
- }
-
- // Replace plus character if needed.
- if ([self substitutesPlusCharacter] &&
- [[destinationURI user] hasPrefix:@"+"]) {
- [destinationURI setUser:
- [[destinationURI user]
- stringByReplacingCharactersInRange:NSMakeRange(0, 1)
- withString:[self plusCharacterSubstitution]]];
- enteredCallDestinationString
- = [enteredCallDestinationString
- stringByReplacingCharactersInRange:NSMakeRange(0, 1)
- withString:[self plusCharacterSubstitution]];
- }
-
- // If it's a regular call, not a transfer, create the new CallController.
- CallController *aCallController;
- if (callTransferController == nil) {
- aCallController = [[[CallController alloc] initWithWindowNibName:@"Call"
- accountController:self]
- autorelease];
- } else {
- aCallController = [[callTransferController retain] autorelease];
- }
-
- [aCallController setNameFromAddressBook:[destinationURI displayName]];
- [aCallController setPhoneLabelFromAddressBook:phoneLabel];
- [aCallController setEnteredCallDestination:enteredCallDestinationString];
- [[self callControllers] addObject:aCallController];
-
- // Set title.
- if ([[destinationURI host] length] > 0) {
- [[aCallController window] setTitle:[destinationURI SIPAddress]];
-
- } else if (![enteredCallDestinationString ak_hasLetters]) {
- if ([enteredCallDestinationString ak_isTelephoneNumber] &&
- [defaults boolForKey:kFormatTelephoneNumbers]) {
- [[aCallController window] setTitle:
- [telephoneNumberFormatter stringForObjectValue:
- enteredCallDestinationString]];
+ phoneLabel:(NSString *)phoneLabel
+ callTransferController:(CallTransferController *)callTransferController {
+
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+ AKTelephoneNumberFormatter *telephoneNumberFormatter = [[[AKTelephoneNumberFormatter alloc] init] autorelease];
+ [telephoneNumberFormatter setSplitsLastFourDigits:
+ [defaults boolForKey:kTelephoneNumberFormatterSplitsLastFourDigits]];
+
+ NSString *enteredCallDestinationString = [[[destinationURI user] copy] autorelease];
+
+ // Make user part a string of contiguous digits if needed.
+ if (![[destinationURI user] ak_hasLetters]) {
+ [destinationURI setUser:[telephoneNumberFormatter telephoneNumberFromString:[destinationURI user]]];
+ }
+
+ // Replace plus character if needed.
+ if ([self substitutesPlusCharacter] &&
+ [[destinationURI user] hasPrefix:@"+"]) {
+ [destinationURI setUser:[[destinationURI user]
+ stringByReplacingCharactersInRange:NSMakeRange(0, 1)
+ withString:[self plusCharacterSubstitution]]];
+ enteredCallDestinationString = [enteredCallDestinationString
+ stringByReplacingCharactersInRange:NSMakeRange(0, 1)
+ withString:[self plusCharacterSubstitution]];
+ }
+
+ // If it's a regular call, not a transfer, create the new CallController.
+ CallController *aCallController;
+ if (callTransferController == nil) {
+ aCallController = [[[CallController alloc] initWithWindowNibName:@"Call" accountController:self]
+ autorelease];
} else {
- [[aCallController window] setTitle:enteredCallDestinationString];
+ aCallController = [[callTransferController retain] autorelease];
}
- } else {
- NSString *SIPAddress = [NSString stringWithFormat:@"%@@%@",
- [destinationURI user],
- [[[self account] registrationURI] host]];
- [[aCallController window] setTitle:SIPAddress];
- }
-
- // Set displayed name.
- if ([[destinationURI displayName] length] > 0) {
- [aCallController setDisplayedName:[destinationURI displayName]];
-
- } else {
+
+ [aCallController setNameFromAddressBook:[destinationURI displayName]];
+ [aCallController setPhoneLabelFromAddressBook:phoneLabel];
+ [aCallController setEnteredCallDestination:enteredCallDestinationString];
+ [[self callControllers] addObject:aCallController];
+
+ // Set title.
if ([[destinationURI host] length] > 0) {
- [aCallController setDisplayedName:[destinationURI SIPAddress]];
-
- } else if ([enteredCallDestinationString ak_isTelephoneNumber] &&
- [defaults boolForKey:kFormatTelephoneNumbers]) {
- [aCallController setDisplayedName:
- [telephoneNumberFormatter stringForObjectValue:
- enteredCallDestinationString]];
-
+ [[aCallController window] setTitle:[destinationURI SIPAddress]];
+
+ } else if (![enteredCallDestinationString ak_hasLetters]) {
+ if ([enteredCallDestinationString ak_isTelephoneNumber] && [defaults boolForKey:kFormatTelephoneNumbers]) {
+ [[aCallController window] setTitle:
+ [telephoneNumberFormatter stringForObjectValue:enteredCallDestinationString]];
+ } else {
+ [[aCallController window] setTitle:enteredCallDestinationString];
+ }
} else {
- [aCallController setDisplayedName:enteredCallDestinationString];
+ NSString *SIPAddress = [NSString stringWithFormat:@"%@@%@",
+ [destinationURI user], [[[self account] registrationURI] host]];
+ [[aCallController window] setTitle:SIPAddress];
+ }
+
+ // Set displayed name.
+ if ([[destinationURI displayName] length] > 0) {
+ [aCallController setDisplayedName:[destinationURI displayName]];
+
+ } else {
+ if ([[destinationURI host] length] > 0) {
+ [aCallController setDisplayedName:[destinationURI SIPAddress]];
+
+ } else if ([enteredCallDestinationString ak_isTelephoneNumber] &&
+ [defaults boolForKey:kFormatTelephoneNumbers]) {
+
+ [aCallController setDisplayedName:
+ [telephoneNumberFormatter stringForObjectValue:enteredCallDestinationString]];
+
+ } else {
+ [aCallController setDisplayedName:enteredCallDestinationString];
+ }
+ }
+
+ // Clean display-name part of the destination URI to prevent another call
+ // party from seeing local Address Book records.
+ [destinationURI setDisplayName:nil];
+
+ if ([[destinationURI host] length] == 0) {
+ [destinationURI setHost:[[[self account] registrationURI] host]];
+ }
+
+ // Set URI for redial.
+ [aCallController setRedialURI:destinationURI];
+
+ if (callTransferController == nil) {
+ [aCallController addViewController:[aCallController activeCallViewController]];
+ [[aCallController window] setContentView:[[aCallController activeCallViewController] view]];
+ }
+
+ if ([phoneLabel length] > 0) {
+ [aCallController setStatus:
+ [NSString stringWithFormat:NSLocalizedString(@"calling %@...",
+ @"Outgoing call in progress. Calling specific phone "
+ "type (mobile, home, etc)."), phoneLabel]];
+ } else {
+ [aCallController setStatus:NSLocalizedString(@"calling...", @"Outgoing call in progress.")];
+ }
+
+ if (callTransferController == nil) {
+ [aCallController showWindow:self];
+ }
+
+ // Finally, make a call.
+ AKSIPCall *aCall = [[self account] makeCallTo:destinationURI];
+ if (aCall != nil) {
+ [aCallController setCall:aCall];
+ [aCallController setCallActive:YES];
+ } else {
+ [aCallController removeObjectFromViewControllersAtIndex:0];
+ [aCallController addViewController:[aCallController endedCallViewController]];
+ [[aCallController window] setContentView:[[aCallController endedCallViewController] view]];
+ [aCallController setStatus:NSLocalizedString(@"Call Failed", @"Call failed.")];
}
- }
-
- // Clean display-name part of the destination URI to prevent another call
- // party from seeing local Address Book records.
- [destinationURI setDisplayName:nil];
-
- if ([[destinationURI host] length] == 0) {
- [destinationURI setHost:[[[self account] registrationURI] host]];
- }
-
- // Set URI for redial.
- [aCallController setRedialURI:destinationURI];
-
- if (callTransferController == nil) {
- [aCallController addViewController:
- [aCallController activeCallViewController]];
- [[aCallController window] setContentView:
- [[aCallController activeCallViewController] view]];
- }
-
- if ([phoneLabel length] > 0) {
- [aCallController setStatus:
- [NSString stringWithFormat:
- NSLocalizedString(@"calling %@...",
- @"Outgoing call in progress. Calling specific phone "
- "type (mobile, home, etc)."), phoneLabel]];
- } else {
- [aCallController setStatus:
- NSLocalizedString(@"calling...",
- @"Outgoing call in progress.")];
- }
-
- if (callTransferController == nil) {
- [aCallController showWindow:self];
- }
-
- // Finally, make a call.
- AKSIPCall *aCall = [[self account] makeCallTo:destinationURI];
- if (aCall != nil) {
- [aCallController setCall:aCall];
- [aCallController setCallActive:YES];
- } else {
- [aCallController removeObjectFromViewControllersAtIndex:0];
- [aCallController addViewController:
- [aCallController endedCallViewController]];
- [[aCallController window] setContentView:
- [[aCallController endedCallViewController] view]];
- [aCallController setStatus:NSLocalizedString(@"Call Failed",
- @"Call failed.")];
- }
}
-- (void)makeCallToURI:(AKSIPURI *)destinationURI
- phoneLabel:(NSString *)phoneLabel {
-
- [self makeCallToURI:destinationURI
- phoneLabel:phoneLabel
- callTransferController:nil];
+- (void)makeCallToURI:(AKSIPURI *)destinationURI phoneLabel:(NSString *)phoneLabel {
+ [self makeCallToURI:destinationURI phoneLabel:phoneLabel callTransferController:nil];
}
- (IBAction)changeAccountState:(id)sender {
- if ([self reRegistrationTimer] != nil) {
- [[self reRegistrationTimer] invalidate];
- [self setReRegistrationTimer:nil];
- }
-
- NSInteger selectedItemTag = [[sender selectedItem] tag];
-
- if (selectedItemTag == kSIPAccountOffline) {
- [self setAccountUnavailable:NO];
- [self removeAccountFromUserAgent];
-
- } else if (selectedItemTag == kSIPAccountUnavailable) {
- // Unregister account only if it is registered or it wasn't added to the
- // user agent.
- if ([self isAccountRegistered] ||
- [[self account] identifier] == kAKSIPUserAgentInvalidIdentifier) {
- [self setAccountUnavailable:YES];
- [self setAttemptingToUnregisterAccount:YES];
- [self setShouldPresentRegistrationError:YES];
- [self setAccountRegistered:NO];
+ if ([self reRegistrationTimer] != nil) {
+ [[self reRegistrationTimer] invalidate];
+ [self setReRegistrationTimer:nil];
}
- } else if (selectedItemTag == kSIPAccountAvailable) {
- [self setAccountUnavailable:NO];
- [self setAttemptingToRegisterAccount:YES];
- [self setShouldPresentRegistrationError:YES];
- [self setAccountRegistered:YES];
- }
+ NSInteger selectedItemTag = [[sender selectedItem] tag];
+
+ if (selectedItemTag == kSIPAccountOffline) {
+ [self setAccountUnavailable:NO];
+ [self removeAccountFromUserAgent];
+
+ } else if (selectedItemTag == kSIPAccountUnavailable) {
+ // Unregister account only if it is registered or it wasn't added to the user agent.
+ if ([self isAccountRegistered] || [[self account] identifier] == kAKSIPUserAgentInvalidIdentifier) {
+ [self setAccountUnavailable:YES];
+ [self setAttemptingToUnregisterAccount:YES];
+ [self setShouldPresentRegistrationError:YES];
+ [self setAccountRegistered:NO];
+ }
+
+ } else if (selectedItemTag == kSIPAccountAvailable) {
+ [self setAccountUnavailable:NO];
+ [self setAttemptingToRegisterAccount:YES];
+ [self setShouldPresentRegistrationError:YES];
+ [self setAccountRegistered:YES];
+ }
}
- (void)showRegistrarConnectionErrorSheetWithError:(NSString *)error {
- NSAlert *alert = [[[NSAlert alloc] init] autorelease];
- [alert addButtonWithTitle:@"OK"];
- [alert setMessageText:[NSString stringWithFormat:
- NSLocalizedString(@"Could not register with %@.",
- @"Registrar connection error."),
- [[self account] registrar]]];
-
- if (error == nil) {
- [alert setInformativeText:
- [NSString stringWithFormat:
- NSLocalizedString(@"Please check network connection and Registry Server "
- "settings.",
- @"Registrar connection error informative text."),
- [[self account] registrar]]];
- } else {
- [alert setInformativeText:error];
- }
-
- [alert beginSheetModalForWindow:[self window]
- modalDelegate:nil
- didEndSelector:NULL
- contextInfo:NULL];
+ NSAlert *alert = [[[NSAlert alloc] init] autorelease];
+ [alert addButtonWithTitle:@"OK"];
+ [alert setMessageText:[NSString stringWithFormat:
+ NSLocalizedString(@"Could not register with %@.", @"Registrar connection error."),
+ [[self account] registrar]]];
+
+ if (error == nil) {
+ [alert setInformativeText:
+ [NSString stringWithFormat:
+ NSLocalizedString(@"Please check network connection and Registry Server settings.",
+ @"Registrar connection error informative text."),
+ [[self account] registrar]]];
+ } else {
+ [alert setInformativeText:error];
+ }
+
+ [alert beginSheetModalForWindow:[self window] modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
}
- (void)showAvailableState {
- NSSize buttonSize = [[self accountStatePopUp] frame].size;
-
- NSString *preferredLocalization
- = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
-
- if ([preferredLocalization isEqualToString:@"English"]) {
- buttonSize.width = kAccountStatePopUpAvailableEnglishWidth;
- } else if ([preferredLocalization isEqualToString:@"Russian"]) {
- buttonSize.width = kAccountStatePopUpAvailableRussianWidth;
- } else if ([preferredLocalization isEqualToString:@"German"]) {
- buttonSize.width = kAccountStatePopUpAvailableGermanWidth;
- }
-
- [[self accountStatePopUp] setFrameSize:buttonSize];
- [[self accountStatePopUp] setTitle:
- NSLocalizedString(@"Available",
- @"Account registration Available menu item.")];
-
- [[[[self accountStatePopUp] menu]
- itemWithTag:kSIPAccountAvailable] setState:NSOnState];
- [[[[self accountStatePopUp] menu]
- itemWithTag:kSIPAccountUnavailable] setState:NSOffState];
-
- if ([self countOfViewControllers] == 0) {
- [self addViewController:[self activeAccountViewController]];
- [[self window] setContentView:[[self activeAccountViewController] view]];
-
- if ([[[self activeAccountViewController] callDestinationField]
- acceptsFirstResponder]) {
- [[self window] makeFirstResponder:
- [[self activeAccountViewController] callDestinationField]];
+ NSSize buttonSize = [[self accountStatePopUp] frame].size;
+
+ NSString *preferredLocalization = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
+
+ if ([preferredLocalization isEqualToString:@"English"]) {
+ buttonSize.width = kAccountStatePopUpAvailableEnglishWidth;
+ } else if ([preferredLocalization isEqualToString:@"Russian"]) {
+ buttonSize.width = kAccountStatePopUpAvailableRussianWidth;
+ } else if ([preferredLocalization isEqualToString:@"German"]) {
+ buttonSize.width = kAccountStatePopUpAvailableGermanWidth;
+ }
+
+ [[self accountStatePopUp] setFrameSize:buttonSize];
+ [[self accountStatePopUp] setTitle:NSLocalizedString(@"Available", @"Account registration Available menu item.")];
+
+ [[[[self accountStatePopUp] menu] itemWithTag:kSIPAccountAvailable] setState:NSOnState];
+ [[[[self accountStatePopUp] menu] itemWithTag:kSIPAccountUnavailable] setState:NSOffState];
+
+ if ([self countOfViewControllers] == 0) {
+ [self addViewController:[self activeAccountViewController]];
+ [[self window] setContentView:[[self activeAccountViewController] view]];
+
+ if ([[[self activeAccountViewController] callDestinationField] acceptsFirstResponder]) {
+ [[self window] makeFirstResponder:[[self activeAccountViewController] callDestinationField]];
+ }
}
- }
}
- (void)showUnavailableState {
- NSSize buttonSize = [[self accountStatePopUp] frame].size;
-
- NSString *preferredLocalization
- = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
-
- if ([preferredLocalization isEqualToString:@"English"]) {
- buttonSize.width = kAccountStatePopUpUnavailableEnglishWidth;
- } else if ([preferredLocalization isEqualToString:@"Russian"]) {
- buttonSize.width = kAccountStatePopUpUnavailableRussianWidth;
- } else if ([preferredLocalization isEqualToString:@"German"]) {
- buttonSize.width = kAccountStatePopUpUnavailableGermanWidth;
- }
-
- [[self accountStatePopUp] setFrameSize:buttonSize];
- [[self accountStatePopUp] setTitle:
- NSLocalizedString(@"Unavailable",
- @"Account registration Unavailable menu item.")];
-
- [[[[self accountStatePopUp] menu]
- itemWithTag:kSIPAccountAvailable] setState:NSOffState];
- [[[[self accountStatePopUp] menu]
- itemWithTag:kSIPAccountUnavailable] setState:NSOnState];
-
- if ([self countOfViewControllers] == 0) {
- [self addViewController:[self activeAccountViewController]];
- [[self window] setContentView:[[self activeAccountViewController] view]];
-
- if ([[[self activeAccountViewController] callDestinationField]
- acceptsFirstResponder]) {
- [[self window] makeFirstResponder:
- [[self activeAccountViewController] callDestinationField]];
+ NSSize buttonSize = [[self accountStatePopUp] frame].size;
+
+ NSString *preferredLocalization = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
+
+ if ([preferredLocalization isEqualToString:@"English"]) {
+ buttonSize.width = kAccountStatePopUpUnavailableEnglishWidth;
+ } else if ([preferredLocalization isEqualToString:@"Russian"]) {
+ buttonSize.width = kAccountStatePopUpUnavailableRussianWidth;
+ } else if ([preferredLocalization isEqualToString:@"German"]) {
+ buttonSize.width = kAccountStatePopUpUnavailableGermanWidth;
+ }
+
+ [[self accountStatePopUp] setFrameSize:buttonSize];
+ [[self accountStatePopUp] setTitle:
+ NSLocalizedString(@"Unavailable", @"Account registration Unavailable menu item.")];
+
+ [[[[self accountStatePopUp] menu] itemWithTag:kSIPAccountAvailable] setState:NSOffState];
+ [[[[self accountStatePopUp] menu] itemWithTag:kSIPAccountUnavailable] setState:NSOnState];
+
+ if ([self countOfViewControllers] == 0) {
+ [self addViewController:[self activeAccountViewController]];
+ [[self window] setContentView:[[self activeAccountViewController] view]];
+
+ if ([[[self activeAccountViewController] callDestinationField] acceptsFirstResponder]) {
+ [[self window] makeFirstResponder:[[self activeAccountViewController] callDestinationField]];
+ }
}
- }
}
- (void)showOfflineState {
- NSSize buttonSize = [[self accountStatePopUp] frame].size;
-
- NSString *preferredLocalization
- = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
-
- if ([preferredLocalization isEqualToString:@"English"]) {
- buttonSize.width = kAccountStatePopUpOfflineEnglishWidth;
- } else if ([preferredLocalization isEqualToString:@"Russian"]) {
- buttonSize.width = kAccountStatePopUpOfflineRussianWidth;
- } else if ([preferredLocalization isEqualToString:@"German"]) {
- buttonSize.width = kAccountStatePopUpOfflineGermanWidth;
- }
-
- [[self accountStatePopUp] setFrameSize:buttonSize];
- [[self accountStatePopUp] setTitle:
- NSLocalizedString(@"Offline",
- @"Account registration Offline menu item.")];
-
- [[[[self accountStatePopUp] menu]
- itemWithTag:kSIPAccountAvailable] setState:NSOffState];
- [[[[self accountStatePopUp] menu]
- itemWithTag:kSIPAccountUnavailable] setState:NSOffState];
-
- [self removeViewController:[self activeAccountViewController]];
- NSRect frame = [[[self window] contentView] frame];
- NSView *emptyView = [[[NSView alloc] initWithFrame:frame] autorelease];
- NSUInteger autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
- [emptyView setAutoresizingMask:autoresizingMask];
- [[self window] setContentView:emptyView];
+ NSSize buttonSize = [[self accountStatePopUp] frame].size;
+
+ NSString *preferredLocalization = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
+
+ if ([preferredLocalization isEqualToString:@"English"]) {
+ buttonSize.width = kAccountStatePopUpOfflineEnglishWidth;
+ } else if ([preferredLocalization isEqualToString:@"Russian"]) {
+ buttonSize.width = kAccountStatePopUpOfflineRussianWidth;
+ } else if ([preferredLocalization isEqualToString:@"German"]) {
+ buttonSize.width = kAccountStatePopUpOfflineGermanWidth;
+ }
+
+ [[self accountStatePopUp] setFrameSize:buttonSize];
+ [[self accountStatePopUp] setTitle:NSLocalizedString(@"Offline", @"Account registration Offline menu item.")];
+
+ [[[[self accountStatePopUp] menu] itemWithTag:kSIPAccountAvailable] setState:NSOffState];
+ [[[[self accountStatePopUp] menu] itemWithTag:kSIPAccountUnavailable] setState:NSOffState];
+
+ [self removeViewController:[self activeAccountViewController]];
+ NSRect frame = [[[self window] contentView] frame];
+ NSView *emptyView = [[[NSView alloc] initWithFrame:frame] autorelease];
+ NSUInteger autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
+ [emptyView setAutoresizingMask:autoresizingMask];
+ [[self window] setContentView:emptyView];
}
- (void)showConnectingState {
- NSSize buttonSize = [[self accountStatePopUp] frame].size;
-
- NSString *preferredLocalization
- = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
-
- if ([preferredLocalization isEqualToString:@"English"]) {
- buttonSize.width = kAccountStatePopUpConnectingEnglishWidth;
- } else if ([preferredLocalization isEqualToString:@"Russian"]) {
- buttonSize.width = kAccountStatePopUpConnectingRussianWidth;
- } else if ([preferredLocalization isEqualToString:@"German"]) {
- buttonSize.width = kAccountStatePopUpConnectingGermanWidth;
- }
-
- [[self accountStatePopUp] setFrameSize:buttonSize];
- [[self accountStatePopUp] setTitle:
- NSLocalizedString(@"Connecting...",
- @"Account registration Connecting... menu item.")];
+ NSSize buttonSize = [[self accountStatePopUp] frame].size;
+
+ NSString *preferredLocalization = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
+
+ if ([preferredLocalization isEqualToString:@"English"]) {
+ buttonSize.width = kAccountStatePopUpConnectingEnglishWidth;
+ } else if ([preferredLocalization isEqualToString:@"Russian"]) {
+ buttonSize.width = kAccountStatePopUpConnectingRussianWidth;
+ } else if ([preferredLocalization isEqualToString:@"German"]) {
+ buttonSize.width = kAccountStatePopUpConnectingGermanWidth;
+ }
+
+ [[self accountStatePopUp] setFrameSize:buttonSize];
+ [[self accountStatePopUp] setTitle:
+ NSLocalizedString(@"Connecting...", @"Account registration Connecting... menu item.")];
}
- (void)reRegistrationTimerTick:(NSTimer *)theTimer {
- [[self account] setRegistered:YES];
+ [[self account] setRegistered:YES];
}
- (void)handleCatchedURL {
- AKSIPURI *uri = [AKSIPURI SIPURIWithString:[self catchedURLString]];
-
- [self setCatchedURLString:nil];
-
- if ([[uri user] length] == 0) {
- return;
- }
-
- [[[self activeAccountViewController] callDestinationField]
- setTokenStyle:NSPlainTextTokenStyle];
-
- NSString *theString;
- if ([[uri host] length] > 0) {
- theString = [uri SIPAddress];
- } else {
- theString = [uri user];
- }
-
- [[[self activeAccountViewController] callDestinationField]
- setStringValue:theString];
-
- [[self activeAccountViewController] makeCall:nil];
+ AKSIPURI *uri = [AKSIPURI SIPURIWithString:[self catchedURLString]];
+
+ [self setCatchedURLString:nil];
+
+ if ([[uri user] length] == 0) {
+ return;
+ }
+
+ [[[self activeAccountViewController] callDestinationField] setTokenStyle:NSPlainTextTokenStyle];
+
+ NSString *theString;
+ if ([[uri host] length] > 0) {
+ theString = [uri SIPAddress];
+ } else {
+ theString = [uri user];
+ }
+
+ [[[self activeAccountViewController] callDestinationField] setStringValue:theString];
+
+ [[self activeAccountViewController] makeCall:nil];
}
@@ -701,162 +634,148 @@ - (void)handleCatchedURL {
#pragma mark NSWindow delegate methods
- (void)windowDidLoad {
- [self showOfflineState];
+ [self showOfflineState];
}
- (BOOL)windowShouldClose:(id)sender {
- BOOL result = YES;
-
- if (sender == [self window]) {
- [[self window] orderOut:self];
- result = NO;
- }
-
- return result;
+ BOOL result = YES;
+
+ if (sender == [self window]) {
+ [[self window] orderOut:self];
+ result = NO;
+ }
+
+ return result;
}
#pragma mark -
#pragma mark AKSIPAccount notifications
-// When account registration changes, make appropriate modifications to the UI.
-// A call can also be made from here if the user called from the Address Book
-// or from the application URL handler.
+// When account registration changes, make appropriate modifications to the UI. A call can also be made from here if
+// the user called from the Address Book or from the application URL handler.
- (void)SIPAccountRegistrationDidChange:(NSNotification *)notification {
- // Account identifier can be kAKSIPUserAgentInvalidIdentifier if notification
- // on the main thread was delivered after user agent had removed the account.
- // Don't bother in that case.
- if ([[self account] identifier] == kAKSIPUserAgentInvalidIdentifier) {
- return;
- }
-
- if ([[self account] isRegistered]) {
- if ([self reRegistrationTimer] != nil) {
- [[self reRegistrationTimer] invalidate];
- [self setReRegistrationTimer:nil];
+ // Account identifier can be kAKSIPUserAgentInvalidIdentifier if notification on the main thread was delivered after
+ // user agent had removed the account. Don't bother in that case.
+ if ([[self account] identifier] == kAKSIPUserAgentInvalidIdentifier) {
+ return;
}
- // If the account was offline and the user chose Unavailable state,
- // setAccountRegistered:NO will add the account to the user agent. User
- // agent will register the account. Set the account to Unavailable
- // (unregister it) here.
- if ([self attemptingToUnregisterAccount]) {
- [self setAccountRegistered:NO];
-
- } else {
- [self setAccountUnavailable:NO];
- [self showAvailableState];
-
- // The user could initiate a call from the Address Book plug-in.
- if ([self shouldMakeCall]) {
- // Explicitly display registered mode before calling.
- [[self window] display];
-
- [self setShouldMakeCall:NO];
- [[self activeAccountViewController] makeCall:nil];
- }
-
- // The user could click a URL.
- if ([self catchedURLString] != nil) {
- // Explicitly display registered mode before calling.
- [[self window] display];
+ if ([[self account] isRegistered]) {
+ if ([self reRegistrationTimer] != nil) {
+ [[self reRegistrationTimer] invalidate];
+ [self setReRegistrationTimer:nil];
+ }
- [self handleCatchedURL];
- }
- }
-
- } else {
- [self showUnavailableState];
-
- // Handle authentication failure
- if ([[self account] registrationStatus] == PJSIP_EFAILEDCREDENTIAL) {
- [[[self authenticationFailureController] informativeText] setStringValue:
- [NSString stringWithFormat:
- NSLocalizedString(@"Telephone was unable to login to %@. "
- "Change user name or password and try again.",
- @"Registrar authentication failed."),
- [[self account] registrar]]];
-
- NSString *serviceName = [NSString stringWithFormat:@"SIP: %@",
- [[self account] registrar]];
- NSString *password
- = [AKKeychain passwordForServiceName:serviceName
- accountName:[[self account] username]];
-
- [[[self authenticationFailureController] usernameField]
- setStringValue:[[self account] username]];
- [[[self authenticationFailureController] passwordField]
- setStringValue:password];
-
- [NSApp beginSheet:[[self authenticationFailureController] window]
- modalForWindow:[self window]
- modalDelegate:nil
- didEndSelector:NULL
- contextInfo:NULL];
-
- } else if (([[self account] registrationStatus] / 100 != 2) &&
- ([[self account] registrationExpireTime] < 0)) {
- // Raise a sheet if connection to the registrar failed.
- // If last registration status is 2xx and expiration interval is less
- // than zero, it is unregistration, not failure. Condition of failure is:
- // last registration status != 2xx AND expiration interval < 0.
-
- if ([[[NSApp delegate] userAgent] isStarted]) {
- if ([self shouldPresentRegistrationError]) {
- NSString *statusText;
- NSString *preferredLocalization
- = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
- if ([preferredLocalization isEqualToString:@"Russian"]) {
- statusText = [[NSApp delegate] localizedStringForSIPResponseCode:
- [[self account] registrationStatus]];
- } else {
- statusText = [[self account] registrationStatusText];
- }
-
- NSString *error;
- if (statusText == nil) {
- error = [NSString stringWithFormat:
- NSLocalizedString(@"Error %d", @"Error #."),
- [[self account] registrationStatus]];
- error = [error stringByAppendingString:@"."];
- } else {
- error = [NSString stringWithFormat:
- NSLocalizedString(@"The error was: \\U201C%d %@\\U201D.",
- @"Error description."),
- [[self account] registrationStatus], statusText];
- }
-
- [self showRegistrarConnectionErrorSheetWithError:error];
-
+ // If the account was offline and the user chose Unavailable state, setAccountRegistered:NO will add the account
+ // to the user agent. User agent will register the account. Set the account to Unavailable (unregister it) here.
+ if ([self attemptingToUnregisterAccount]) {
+ [self setAccountRegistered:NO];
+
} else {
- // Schedule account automatic re-registration timer.
- if ([self reRegistrationTimer] == nil) {
- NSTimeInterval reregistrationTimeInterval
- = (NSTimeInterval)[[self account] reregistrationTime];
+ [self setAccountUnavailable:NO];
+ [self showAvailableState];
+
+ // The user could initiate a call from the Address Book plug-in.
+ if ([self shouldMakeCall]) {
+ // Explicitly display registered mode before calling.
+ [[self window] display];
+
+ [self setShouldMakeCall:NO];
+ [[self activeAccountViewController] makeCall:nil];
+ }
- [self setReRegistrationTimer:
- [NSTimer
- scheduledTimerWithTimeInterval:reregistrationTimeInterval
- target:self
- selector:@selector(reRegistrationTimerTick:)
- userInfo:nil
- repeats:YES]];
- }
+ // The user could click a URL.
+ if ([self catchedURLString] != nil) {
+ // Explicitly display registered mode before calling.
+ [[self window] display];
+
+ [self handleCatchedURL];
+ }
+ }
+
+ } else {
+ [self showUnavailableState];
+
+ // Handle authentication failure
+ if ([[self account] registrationStatus] == PJSIP_EFAILEDCREDENTIAL) {
+ [[[self authenticationFailureController] informativeText] setStringValue:
+ [NSString stringWithFormat:
+ NSLocalizedString(@"Telephone was unable to login to %@. "
+ "Change user name or password and try again.",
+ @"Registrar authentication failed."),
+ [[self account] registrar]]];
+
+ NSString *serviceName = [NSString stringWithFormat:@"SIP: %@",
+ [[self account] registrar]];
+ NSString *password = [AKKeychain passwordForServiceName:serviceName accountName:[[self account] username]];
+
+ [[[self authenticationFailureController] usernameField] setStringValue:[[self account] username]];
+ [[[self authenticationFailureController] passwordField] setStringValue:password];
+
+ [NSApp beginSheet:[[self authenticationFailureController] window]
+ modalForWindow:[self window]
+ modalDelegate:nil
+ didEndSelector:NULL
+ contextInfo:NULL];
+
+ } else if (([[self account] registrationStatus] / 100 != 2) &&
+ ([[self account] registrationExpireTime] < 0)) {
+ // Raise a sheet if connection to the registrar failed. If last registration status is 2xx and expiration
+ // interval is less than zero, it is unregistration, not failure. Condition of failure is: last registration
+ // status != 2xx AND expiration interval < 0.
+
+ if ([[[NSApp delegate] userAgent] isStarted]) {
+ if ([self shouldPresentRegistrationError]) {
+ NSString *statusText;
+ NSString *preferredLocalization = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];
+ if ([preferredLocalization isEqualToString:@"Russian"]) {
+ statusText = [[NSApp delegate] localizedStringForSIPResponseCode:
+ [[self account] registrationStatus]];
+ } else {
+ statusText = [[self account] registrationStatusText];
+ }
+
+ NSString *error;
+ if (statusText == nil) {
+ error = [NSString stringWithFormat:NSLocalizedString(@"Error %d", @"Error #."),
+ [[self account] registrationStatus]];
+ error = [error stringByAppendingString:@"."];
+ } else {
+ error = [NSString stringWithFormat:
+ NSLocalizedString(@"The error was: \\U201C%d %@\\U201D.", @"Error description."),
+ [[self account] registrationStatus], statusText];
+ }
+
+ [self showRegistrarConnectionErrorSheetWithError:error];
+
+ } else {
+ // Schedule account automatic re-registration timer.
+ if ([self reRegistrationTimer] == nil) {
+ NSTimeInterval reregistrationTimeInterval = (NSTimeInterval)[[self account] reregistrationTime];
+
+ [self setReRegistrationTimer:
+ [NSTimer scheduledTimerWithTimeInterval:reregistrationTimeInterval
+ target:self
+ selector:@selector(reRegistrationTimerTick:)
+ userInfo:nil
+ repeats:YES]];
+ }
+ }
+ }
}
- }
}
- }
-
- [self setAttemptingToRegisterAccount:NO];
- [self setAttemptingToUnregisterAccount:NO];
- [self setShouldPresentRegistrationError:NO];
+
+ [self setAttemptingToRegisterAccount:NO];
+ [self setAttemptingToUnregisterAccount:NO];
+ [self setShouldPresentRegistrationError:NO];
}
- (void)SIPAccountWillRemove:(NSNotification *)notification {
- if ([self reRegistrationTimer] != nil) {
- [[self reRegistrationTimer] invalidate];
- [self setReRegistrationTimer:nil];
- }
+ if ([self reRegistrationTimer] != nil) {
+ [[self reRegistrationTimer] invalidate];
+ [self setReRegistrationTimer:nil];
+ }
}
@@ -864,8 +783,8 @@ - (void)SIPAccountWillRemove:(NSNotification *)notification {
#pragma mark CallController notifications
- (void)callWindowWillClose:(NSNotification *)notification {
- CallController *aCallController = [notification object];
- [[self callControllers] removeObject:aCallController];
+ CallController *aCallController = [notification object];
+ [[self callControllers] removeObject:aCallController];
}
@@ -873,313 +792,293 @@ - (void)callWindowWillClose:(NSNotification *)notification {
#pragma mark AKSIPAccountDelegate protocol
- (void)SIPAccountDidReceiveCall:(AKSIPCall *)aCall {
- if ([self isAccountUnavailable]) {
- // Reply with 480 Temporarily Unavailable if the user selected Unavailable
- // account state.
- [aCall replyWithTemporarilyUnavailable];
-
- return;
-
- } else if (![[NSUserDefaults standardUserDefaults] boolForKey:kCallWaiting]) {
- // Reply with 486 Busy Here if needed.
- for (CallController *callController in [self callControllers]) {
- if ([callController isCallActive]) {
- [aCall replyWithBusyHere];
+ if ([self isAccountUnavailable]) {
+ // Reply with 480 Temporarily Unavailable if the user selected Unavailable account state.
+ [aCall replyWithTemporarilyUnavailable];
return;
- }
- }
- }
-
- [[NSApp delegate] pauseITunes];
-
- CallController *aCallController
- = [[[CallController alloc] initWithWindowNibName:@"Call"
- accountController:self]
- autorelease];
-
- [aCallController setCall:aCall];
- [aCallController setCallActive:YES];
- [aCallController setCallUnhandled:YES];
- [[self callControllers] addObject:aCallController];
-
- AKSIPURIFormatter *SIPURIFormatter
- = [[[AKSIPURIFormatter alloc] init] autorelease];
- NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
- [SIPURIFormatter setFormatsTelephoneNumbers:
- [defaults boolForKey:kFormatTelephoneNumbers]];
- [SIPURIFormatter setTelephoneNumberFormatterSplitsLastFourDigits:
- [defaults boolForKey:kTelephoneNumberFormatterSplitsLastFourDigits]];
-
- // These variables will be changed during the Address Book search if the
- // record is found.
- NSString *finalTitle = [[aCall remoteURI] SIPAddress];
- NSString *finalDisplayedName
- = [SIPURIFormatter stringForObjectValue:[aCall remoteURI]];
- NSString *finalStatus
- = NSLocalizedString(@"calling",
- @"John Smith calling. Somebody is calling us right "
- "now. Call status string. Deliberately in lower case, "
- "translators should do the same, if possible.");
- AKSIPURI *finalRedialURI = [aCall remoteURI];
-
- // Search Address Book for caller's name.
-
- ABAddressBook *AB = [ABAddressBook sharedAddressBook];
- NSArray *records = nil;
-
- ABSearchElement *SIPAddressMatch
- = [ABPerson searchElementForProperty:kABEmailProperty
- label:nil
- key:nil
- value:[[aCall remoteURI] SIPAddress]
- comparison:kABEqualCaseInsensitive];
-
- records = [AB recordsMatchingSearchElement:SIPAddressMatch];
-
- if ([records count] > 0) {
- id theRecord = [records objectAtIndex:0];
-
- finalDisplayedName = [theRecord ak_fullName];
- [aCallController setNameFromAddressBook:[theRecord ak_fullName]];
-
- NSString *localizedLabel = [AB ak_localizedLabel:kEmailSIPLabel];
- finalStatus = localizedLabel;
- [aCallController setPhoneLabelFromAddressBook:localizedLabel];
-
- finalRedialURI = [aCall remoteURI];
-
- } else if ([[[aCall remoteURI] displayName] ak_isTelephoneNumber] ||
- ([[[aCall remoteURI] displayName] length] == 0 &&
- [[[aCall remoteURI] user] ak_isTelephoneNumber]))
- { // No SIP Address found, search for the phone number.
- NSString *phoneNumberToSearch;
- if ([[[aCall remoteURI] displayName] length] > 0) {
- phoneNumberToSearch = [[aCall remoteURI] displayName];
- } else {
- phoneNumberToSearch = [[aCall remoteURI] user];
+
+ } else if (![[NSUserDefaults standardUserDefaults] boolForKey:kCallWaiting]) {
+ // Reply with 486 Busy Here if needed.
+ for (CallController *callController in [self callControllers]) {
+ if ([callController isCallActive]) {
+ [aCall replyWithBusyHere];
+
+ return;
+ }
+ }
}
- BOOL recordFound = NO;
+ [[NSApp delegate] pauseITunes];
+
+ CallController *aCallController = [[[CallController alloc] initWithWindowNibName:@"Call" accountController:self]
+ autorelease];
+
+ [aCallController setCall:aCall];
+ [aCallController setCallActive:YES];
+ [aCallController setCallUnhandled:YES];
+ [[self callControllers] addObject:aCallController];
+
+ AKSIPURIFormatter *SIPURIFormatter = [[[AKSIPURIFormatter alloc] init] autorelease];
+ NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
+ [SIPURIFormatter setFormatsTelephoneNumbers:[defaults boolForKey:kFormatTelephoneNumbers]];
+ [SIPURIFormatter setTelephoneNumberFormatterSplitsLastFourDigits:
+ [defaults boolForKey:kTelephoneNumberFormatterSplitsLastFourDigits]];
+
+ // These variables will be changed during the Address Book search if the record is found.
+ NSString *finalTitle = [[aCall remoteURI] SIPAddress];
+ NSString *finalDisplayedName = [SIPURIFormatter stringForObjectValue:[aCall remoteURI]];
+ NSString *finalStatus = NSLocalizedString(@"calling",
+ @"John Smith calling. Somebody is calling us right "
+ "now. Call status string. Deliberately in lower case, "
+ "translators should do the same, if possible.");
+ AKSIPURI *finalRedialURI = [aCall remoteURI];
+
+ // Search Address Book for caller's name.
+
+ ABAddressBook *AB = [ABAddressBook sharedAddressBook];
+ NSArray *records = nil;
+
+ ABSearchElement *SIPAddressMatch
+ = [ABPerson searchElementForProperty:kABEmailProperty
+ label:nil
+ key:nil
+ value:[[aCall remoteURI] SIPAddress]
+ comparison:kABEqualCaseInsensitive];
- // Look for the whole phone number match first.
- ABSearchElement *phoneNumberMatch
- = [ABPerson searchElementForProperty:kABPhoneProperty
- label:nil
- key:nil
- value:phoneNumberToSearch
- comparison:kABEqual];
+ records = [AB recordsMatchingSearchElement:SIPAddressMatch];
- records = [AB recordsMatchingSearchElement:phoneNumberMatch];
if ([records count] > 0) {
- recordFound = YES;
- id theRecord = [records objectAtIndex:0];
- finalDisplayedName = [theRecord ak_fullName];
- [aCallController setNameFromAddressBook:[theRecord ak_fullName]];
-
- // Find the exact phone number match.
- ABMultiValue *phones = [theRecord valueForProperty:kABPhoneProperty];
- for (NSUInteger i = 0; i < [phones count]; ++i) {
- if ([[phones valueAtIndex:i] isEqualToString:phoneNumberToSearch]) {
- NSString *localizedLabel
- = [AB ak_localizedLabel:[phones labelAtIndex:i]];
- finalStatus = localizedLabel;
- [aCallController setPhoneLabelFromAddressBook:localizedLabel];
-
- finalRedialURI
- = [AKSIPURI SIPURIWithUser:[phones valueAtIndex:i]
- host:[[[self account] registrationURI] host]
- displayName:nil];
- break;
+ id theRecord = [records objectAtIndex:0];
+
+ finalDisplayedName = [theRecord ak_fullName];
+ [aCallController setNameFromAddressBook:[theRecord ak_fullName]];
+
+ NSString *localizedLabel = [AB ak_localizedLabel:kEmailSIPLabel];
+ finalStatus = localizedLabel;
+ [aCallController setPhoneLabelFromAddressBook:localizedLabel];
+
+ finalRedialURI = [aCall remoteURI];
+
+ } else if ([[[aCall remoteURI] displayName] ak_isTelephoneNumber] ||
+ ([[[aCall remoteURI] displayName] length] == 0 &&
+ [[[aCall remoteURI] user] ak_isTelephoneNumber]))
+ { // No SIP Address found, search for the phone number.
+ NSString *phoneNumberToSearch;
+ if ([[[aCall remoteURI] displayName] length] > 0) {
+ phoneNumberToSearch = [[aCall remoteURI] displayName];
+ } else {
+ phoneNumberToSearch = [[aCall remoteURI] user];
}
- }
- }
-
- NSUInteger significantPhoneNumberLength
- = [defaults integerForKey:kSignificantPhoneNumberLength];
-
- // Get the significant phone suffix if the phone number length is greater
- // than we defined.
- NSString *significantPhoneSuffix;
- if ([phoneNumberToSearch length] > significantPhoneNumberLength) {
- significantPhoneSuffix
- = [phoneNumberToSearch substringFromIndex:
- ([phoneNumberToSearch length] - significantPhoneNumberLength)];
-
- // If the the record hasn't been found with the whole number, look for
- // significant suffix match.
- if (!recordFound) {
- ABSearchElement *phoneNumberSuffixMatch
- = [ABPerson searchElementForProperty:kABPhoneProperty
- label:nil
- key:nil
- value:significantPhoneSuffix
- comparison:kABSuffixMatch];
- records = [AB recordsMatchingSearchElement:phoneNumberSuffixMatch];
+ BOOL recordFound = NO;
+
+ // Look for the whole phone number match first.
+ ABSearchElement *phoneNumberMatch
+ = [ABPerson searchElementForProperty:kABPhoneProperty
+ label:nil
+ key:nil
+ value:phoneNumberToSearch
+ comparison:kABEqual];
+
+ records = [AB recordsMatchingSearchElement:phoneNumberMatch];
if ([records count] > 0) {
- recordFound = YES;
- id theRecord = [records objectAtIndex:0];
- finalDisplayedName = [theRecord ak_fullName];
- [aCallController setNameFromAddressBook:[theRecord ak_fullName]];
-
- // Find the exact phone number match.
- ABMultiValue *phones = [theRecord valueForProperty:kABPhoneProperty];
- for (NSUInteger i = 0; i < [phones count]; ++i) {
- if ([[phones valueAtIndex:i] hasSuffix:significantPhoneSuffix]) {
- NSString *localizedLabel
- = [AB ak_localizedLabel:[phones labelAtIndex:i]];
- finalStatus = localizedLabel;
- [aCallController setPhoneLabelFromAddressBook:localizedLabel];
-
- finalRedialURI
- = [AKSIPURI SIPURIWithUser:[phones valueAtIndex:i]
- host:[[[self account] registrationURI] host]
- displayName:nil];
- break;
+ recordFound = YES;
+ id theRecord = [records objectAtIndex:0];
+ finalDisplayedName = [theRecord ak_fullName];
+ [aCallController setNameFromAddressBook:[theRecord ak_fullName]];
+
+ // Find the exact phone number match.
+ ABMultiValue *phones = [theRecord valueForProperty:kABPhoneProperty];
+ for (NSUInteger i = 0; i < [phones count]; ++i) {
+ if ([[phones valueAtIndex:i] isEqualToString:phoneNumberToSearch]) {
+ NSString *localizedLabel = [AB ak_localizedLabel:[phones labelAtIndex:i]];
+ finalStatus = localizedLabel;
+ [aCallController setPhoneLabelFromAddressBook:localizedLabel];
+
+ finalRedialURI = [AKSIPURI SIPURIWithUser:[phones valueAtIndex:i]
+ host:[[[self account] registrationURI] host]
+ displayName:nil];
+ break;
+ }
}
- }
}
- }
- }
-
- // If still not found, search phone numbers that contain spaces, dashes, etc.
- if (!recordFound) {
- NSArray *allPeople = [AB people];
-
- AKTelephoneNumberFormatter *telephoneNumberFormatter
- = [[[AKTelephoneNumberFormatter alloc] init] autorelease];
- for (id theRecord in allPeople) {
- ABMultiValue *phones = [theRecord valueForProperty:kABPhoneProperty];
- for (NSUInteger i = 0; i < [phones count]; ++i) {
- NSString *phoneNumber = [phones valueAtIndex:i];
-
- // Don't bother if the phone number contains only contiguous
- // digits, we should have covered such numbers in previous search.
- if ([phoneNumber ak_isTelephoneNumber]) {
- continue;
- }
-
- // Don't bother if the phone number has letters.
- if ([phoneNumber ak_hasLetters]) {
- continue;
- }
-
- // Here phone number probably includes spaces or other dividers.
- // Scan valid phone characters to compare with a given string.
- NSString *scannedPhoneNumber
- = [telephoneNumberFormatter telephoneNumberFromString:phoneNumber];
- if ([scannedPhoneNumber isEqualToString:phoneNumberToSearch]) {
- recordFound = YES;
- } else if (([phoneNumberToSearch length] > significantPhoneNumberLength) &&
- [scannedPhoneNumber hasSuffix:significantPhoneSuffix]) {
- recordFound = YES;
- }
-
- if (recordFound) {
- NSString *localizedLabel
- = [AB ak_localizedLabel:[phones labelAtIndex:i]];
- finalStatus = localizedLabel;
- [aCallController setPhoneLabelFromAddressBook:localizedLabel];
+ NSUInteger significantPhoneNumberLength = [defaults integerForKey:kSignificantPhoneNumberLength];
+
+ // Get the significant phone suffix if the phone number length is greater
+ // than we defined.
+ NSString *significantPhoneSuffix;
+ if ([phoneNumberToSearch length] > significantPhoneNumberLength) {
+ significantPhoneSuffix = [phoneNumberToSearch substringFromIndex:
+ ([phoneNumberToSearch length] - significantPhoneNumberLength)];
- finalRedialURI
- = [AKSIPURI SIPURIWithUser:scannedPhoneNumber
- host:[[[self account] registrationURI] host]
- displayName:nil];
- break;
- }
+ // If the the record hasn't been found with the whole number, look for
+ // significant suffix match.
+ if (!recordFound) {
+ ABSearchElement *phoneNumberSuffixMatch
+ = [ABPerson searchElementForProperty:kABPhoneProperty
+ label:nil
+ key:nil
+ value:significantPhoneSuffix
+ comparison:kABSuffixMatch];
+
+ records = [AB recordsMatchingSearchElement:phoneNumberSuffixMatch];
+ if ([records count] > 0) {
+ recordFound = YES;
+ id theRecord = [records objectAtIndex:0];
+ finalDisplayedName = [theRecord ak_fullName];
+ [aCallController setNameFromAddressBook:[theRecord ak_fullName]];
+
+ // Find the exact phone number match.
+ ABMultiValue *phones = [theRecord valueForProperty:kABPhoneProperty];
+ for (NSUInteger i = 0; i < [phones count]; ++i) {
+ if ([[phones valueAtIndex:i] hasSuffix:significantPhoneSuffix]) {
+ NSString *localizedLabel = [AB ak_localizedLabel:[phones labelAtIndex:i]];
+ finalStatus = localizedLabel;
+ [aCallController setPhoneLabelFromAddressBook:localizedLabel];
+
+ finalRedialURI = [AKSIPURI SIPURIWithUser:[phones valueAtIndex:i]
+ host:[[[self account] registrationURI] host]
+ displayName:nil];
+ break;
+ }
+ }
+ }
+ }
}
- if (recordFound) {
- finalDisplayedName = [theRecord ak_fullName];
- [aCallController setNameFromAddressBook:[theRecord ak_fullName]];
- break;
+ // If still not found, search phone numbers that contain spaces, dashes, etc.
+ if (!recordFound) {
+ NSArray *allPeople = [AB people];
+
+ AKTelephoneNumberFormatter *telephoneNumberFormatter
+ = [[[AKTelephoneNumberFormatter alloc] init] autorelease];
+ for (id theRecord in allPeople) {
+ ABMultiValue *phones = [theRecord valueForProperty:kABPhoneProperty];
+
+ for (NSUInteger i = 0; i < [phones count]; ++i) {
+ NSString *phoneNumber = [phones valueAtIndex:i];
+
+ // Don't bother if the phone number contains only contiguous
+ // digits, we should have covered such numbers in previous search.
+ if ([phoneNumber ak_isTelephoneNumber]) {
+ continue;
+ }
+
+ // Don't bother if the phone number has letters.
+ if ([phoneNumber ak_hasLetters]) {
+ continue;
+ }
+
+ // Here phone number probably includes spaces or other dividers.
+ // Scan valid phone characters to compare with a given string.
+ NSString *scannedPhoneNumber = [telephoneNumberFormatter telephoneNumberFromString:phoneNumber];
+ if ([scannedPhoneNumber isEqualToString:phoneNumberToSearch]) {
+ recordFound = YES;
+ } else if (([phoneNumberToSearch length] > significantPhoneNumberLength) &&
+ [scannedPhoneNumber hasSuffix:significantPhoneSuffix]) {
+
+ recordFound = YES;
+ }
+
+ if (recordFound) {
+ NSString *localizedLabel = [AB ak_localizedLabel:[phones labelAtIndex:i]];
+ finalStatus = localizedLabel;
+ [aCallController setPhoneLabelFromAddressBook:localizedLabel];
+
+ finalRedialURI = [AKSIPURI SIPURIWithUser:scannedPhoneNumber
+ host:[[[self account] registrationURI] host]
+ displayName:nil];
+ break;
+ }
+ }
+
+ if (recordFound) {
+ finalDisplayedName = [theRecord ak_fullName];
+ [aCallController setNameFromAddressBook:[theRecord ak_fullName]];
+ break;
+ }
+ }
+ }
+ }
+
+ // Address Book search ends here.
+
+ [[aCallController window] setTitle:finalTitle];
+ [aCallController setDisplayedName:finalDisplayedName];
+ [aCallController setStatus:finalStatus];
+ [aCallController setRedialURI:finalRedialURI];
+
+ [aCallController addViewController:[aCallController incomingCallViewController]];
+ [[aCallController window] ak_resizeAndSwapToContentView:[[aCallController incomingCallViewController] view]];
+
+ [aCallController showWindow:nil];
+
+ // Show Growl notification.
+ NSString *callSource;
+ AKTelephoneNumberFormatter *telephoneNumberFormatter = [[[AKTelephoneNumberFormatter alloc] init] autorelease];
+ [telephoneNumberFormatter setSplitsLastFourDigits:
+ [defaults boolForKey:kTelephoneNumberFormatterSplitsLastFourDigits]];
+ if ([[aCallController phoneLabelFromAddressBook] length] > 0) {
+ callSource = [aCallController phoneLabelFromAddressBook];
+ } else if ([[[aCall remoteURI] user] length] > 0) {
+ if ([[[aCall remoteURI] user] ak_isTelephoneNumber]) {
+ if ([defaults boolForKey:kFormatTelephoneNumbers]) {
+ callSource = [telephoneNumberFormatter stringForObjectValue:[[aCall remoteURI] user]];
+ } else {
+ callSource = [[aCall remoteURI] user];
+ }
+ } else {
+ callSource = [[aCall remoteURI] SIPAddress];
}
- }
+ } else {
+ callSource = [[aCall remoteURI] host];
}
- }
-
- // Address Book search ends here.
-
- [[aCallController window] setTitle:finalTitle];
- [aCallController setDisplayedName:finalDisplayedName];
- [aCallController setStatus:finalStatus];
- [aCallController setRedialURI:finalRedialURI];
-
- [aCallController addViewController:
- [aCallController incomingCallViewController]];
- [[aCallController window] ak_resizeAndSwapToContentView:
- [[aCallController incomingCallViewController] view]];
-
- [aCallController showWindow:nil];
-
- // Show Growl notification.
- NSString *callSource;
- AKTelephoneNumberFormatter *telephoneNumberFormatter
- = [[[AKTelephoneNumberFormatter alloc] init] autorelease];
- [telephoneNumberFormatter setSplitsLastFourDigits:
- [defaults boolForKey:kTelephoneNumberFormatterSplitsLastFourDigits]];
- if ([[aCallController phoneLabelFromAddressBook] length] > 0) {
- callSource = [aCallController phoneLabelFromAddressBook];
- } else if ([[[aCall remoteURI] user] length] > 0) {
- if ([[[aCall remoteURI] user] ak_isTelephoneNumber]) {
- if ([defaults boolForKey:kFormatTelephoneNumbers]) {
- callSource = [telephoneNumberFormatter stringForObjectValue:
- [[aCall remoteURI] user]];
- } else {
- callSource = [[aCall remoteURI] user];
- }
+
+ NSString *notificationTitle, *notificationDescription;
+ if ([[aCallController nameFromAddressBook] length] > 0) {
+ notificationTitle = [aCallController nameFromAddressBook];
+ notificationDescription = callSource;
+
+ } else if ([[[aCall remoteURI] displayName] length] > 0) {
+ notificationTitle = [[aCall remoteURI] displayName];
+ notificationDescription
+ = [NSString stringWithFormat:
+ NSLocalizedString(@"calling from %@",
+ @"John Smith calling from 1234567. "
+ "Somebody is calling us right now from some source. "
+ "Growl notification description. Deliberately in "
+ "lower case, translators should do the same, if "
+ "possible."),
+ callSource];
} else {
- callSource = [[aCall remoteURI] SIPAddress];
+ notificationTitle = callSource;
+ notificationDescription
+ = NSLocalizedString(@"calling",
+ @"John Smith calling. Somebody is calling us right "
+ "now. Growl notification description. "
+ "Deliberately in lower case, translators should do "
+ "the same, if possible.");
+ }
+
+ [GrowlApplicationBridge notifyWithTitle:notificationTitle
+ description:notificationDescription
+ notificationName:kGrowlNotificationIncomingCall
+ iconData:nil
+ priority:0
+ isSticky:NO
+ clickContext:[aCallController identifier]];
+
+ [[[NSApp delegate] ringtone] play];
+ [[NSApp delegate] startRingtoneTimer];
+
+ if (![NSApp isActive]) {
+ [NSApp requestUserAttention:NSInformationalRequest];
+ [[NSApp delegate] startUserAttentionTimer];
}
- } else {
- callSource = [[aCall remoteURI] host];
- }
-
- NSString *notificationTitle, *notificationDescription;
- if ([[aCallController nameFromAddressBook] length] > 0) {
- notificationTitle = [aCallController nameFromAddressBook];
- notificationDescription = callSource;
-
- } else if ([[[aCall remoteURI] displayName] length] > 0) {
- notificationTitle = [[aCall remoteURI] displayName];
- notificationDescription
- = [NSString stringWithFormat:
- NSLocalizedString(@"calling from %@",
- @"John Smith calling from 1234567. "
- "Somebody is calling us right now from some source. "
- "Growl notification description. Deliberately in "
- "lower case, translators should do the same, if "
- "possible."),
- callSource];
- } else {
- notificationTitle = callSource;
- notificationDescription
- = NSLocalizedString(@"calling",
- @"John Smith calling. Somebody is calling us right "
- "now. Growl notification description. "
- "Deliberately in lower case, translators should do "
- "the same, if possible.");
- }
-
- [GrowlApplicationBridge notifyWithTitle:notificationTitle
- description:notificationDescription
- notificationName:kGrowlNotificationIncomingCall
- iconData:nil
- priority:0
- isSticky:NO
- clickContext:[aCallController identifier]];
-
- [[[NSApp delegate] ringtone] play];
- [[NSApp delegate] startRingtoneTimer];
-
- if (![NSApp isActive]) {
- [NSApp requestUserAttention:NSInformationalRequest];
- [[NSApp delegate] startUserAttentionTimer];
- }
-
- [aCall sendRingingNotification];
+
+ [aCall sendRingingNotification];
}
@@ -1187,17 +1086,17 @@ - (void)SIPAccountDidReceiveCall:(AKSIPCall *)aCall {
#pragma mark AKSIPUserAgent notifications
- (void)SIPUserAgentDidFinishStarting:(NSNotification *)notification {
- if (![[notification object] isStarted]) {
- [self showOfflineState];
+ if (![[notification object] isStarted]) {
+ [self showOfflineState];
+
+ return;
+ }
- return;
- }
-
- if ([self attemptingToRegisterAccount]) {
- [self setAccountRegistered:YES];
- } else if ([self attemptingToUnregisterAccount]) {
- [self setAccountRegistered:NO];
- }
+ if ([self attemptingToRegisterAccount]) {
+ [self setAccountRegistered:YES];
+ } else if ([self attemptingToUnregisterAccount]) {
+ [self setAccountRegistered:NO];
+ }
}
@@ -1206,10 +1105,10 @@ - (void)SIPUserAgentDidFinishStarting:(NSNotification *)notification {
// This is the moment when the application starts doing its main job.
- (void)networkReachabilityDidBecomeReachable:(NSNotification *)notification {
- if (![self isAccountUnavailable] && ![self isAccountRegistered]) {
- [self setAttemptingToRegisterAccount:YES];
- [self setAccountRegistered:YES];
- }
+ if (![self isAccountUnavailable] && ![self isAccountRegistered]) {
+ [self setAttemptingToRegisterAccount:YES];
+ [self setAccountRegistered:YES];
+ }
}
@end
View
4 Telephone.xcodeproj/project.pbxproj
@@ -192,8 +192,8 @@
AA34AF811073BF5D00FA38F7 /* GeneralPreferencesViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; path = GeneralPreferencesViewController.h; sourceTree = "<group>"; tabWidth = 2; };
AA34AF821073BF5D00FA38F7 /* GeneralPreferencesViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.objc; path = GeneralPreferencesViewController.m; sourceTree = "<group>"; tabWidth = 2; };
AA3578680E3FD91400021989 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/Call.xib; sourceTree = "<group>"; };
- AA3578B10E40709900021989 /* AccountController.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; path = AccountController.h; sourceTree = "<group>"; tabWidth = 2; };
- AA3578B20E40709900021989 /* AccountController.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.objc; path = AccountController.m; sourceTree = "<group>"; tabWidth = 2; };
+ AA3578B10E40709900021989 /* AccountController.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = AccountController.h; sourceTree = "<group>"; tabWidth = 4; };
+ AA3578B20E40709900021989 /* AccountController.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = AccountController.m; sourceTree = "<group>"; tabWidth = 4; };
AA3578B40E4070AD00021989 /* CallController.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; path = CallController.h; sourceTree = "<group>"; tabWidth = 2; };
AA3578B50E4070AD00021989 /* CallController.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.objc; path = CallController.m; sourceTree = "<group>"; tabWidth = 2; };
AA3A14F90F309C7C00C45739 /* AKABAddressBook+Localizing.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; path = "AKABAddressBook+Localizing.h"; sourceTree = "<group>"; tabWidth = 2; };
Please sign in to comment.
Something went wrong with that request. Please try again.