Browse files

Account menu items in Window menu.

Application Window menu now contains menu items for all accounts. First nine menu items have key equivalents. AccountController has new accountDescription property.
  • Loading branch information...
1 parent 67b13e6 commit 3509409ff3e6449a5dd1d2c105d4513000173cb7 @eofster committed Jan 16, 2011
Showing with 211 additions and 57 deletions.
  1. +4 −0 AccountController.h
  2. +2 −0 AccountController.m
  3. +14 −0 AppController.h
  4. +81 −13 AppController.m
  5. +38 −16 English.lproj/MainMenu.xib
  6. +36 −14 German.lproj/MainMenu.xib
  7. +36 −14 Russian.lproj/MainMenu.xib
View
4 AccountController.h
@@ -54,6 +54,7 @@ extern NSString * const kEmailSIPLabel;
BOOL enabled_;
AKSIPAccount *account_;
NSMutableArray *callControllers_;
+ NSString *accountDescription_;
BOOL attemptingToRegisterAccount_;
BOOL attemptingToUnregisterAccount_;
BOOL shouldPresentRegistrationError_;
@@ -84,6 +85,9 @@ extern NSString * const kEmailSIPLabel;
// An array of call controllers managed by the receiver.
@property(nonatomic, retain) NSMutableArray *callControllers;
+// Account description.
+@property(nonatomic, copy) NSString *accountDescription;
+
// A Boolean value indicating whether a user is attempting to register
// an account.
@property(nonatomic, assign) BOOL attemptingToRegisterAccount;
View
2 AccountController.m
@@ -96,6 +96,7 @@ @implementation AccountController
@synthesize account = account_;
@dynamic accountRegistered;
@synthesize callControllers = callControllers_;
+@synthesize accountDescription = accountDescription_;
@synthesize attemptingToRegisterAccount = attemptingToRegisterAccount_;
@synthesize attemptingToUnregisterAccount = attemptingToUnregisterAccount_;
@synthesize shouldPresentRegistrationError = shouldPresentRegistrationError_;
@@ -298,6 +299,7 @@ - (void)dealloc {
[account_ release];
[callControllers_ release];
+ [accountDescription_ release];
[catchedURLString_ release];
[registrarReachability_ release];
[plusCharacterSubstitution_ release];
View
14 AppController.h
@@ -69,6 +69,8 @@ extern NSString * const kGrowlNotificationCallEnded;
BOOL shouldPresentUserAgentLaunchError_;
NSTimer *userAttentionTimer_;
+ NSArray *accountsMenuItems_;
+ NSMenu *windowMenu_;
NSMenuItem *preferencesMenuItem_;
}
@@ -144,6 +146,12 @@ extern NSString * const kGrowlNotificationCallEnded;
// Timer for bouncing icon in the Dock.
@property(nonatomic, assign) NSTimer *userAttentionTimer;
+// Accounts menu items to show in windows menu.
+@property(nonatomic, retain) NSArray *accountsMenuItems;
+
+// Application Window menu.
+@property(nonatomic, retain) IBOutlet NSMenu *windowMenu;
+
// Preferences menu item outlet.
@property(nonatomic, retain) IBOutlet NSMenuItem *preferencesMenuItem;
@@ -197,6 +205,12 @@ extern NSString * const kGrowlNotificationCallEnded;
// Updates Dock tile badge label.
- (void)updateDockTileBadgeLabel;
+// Updates accounts menu items.
+- (void)updateAccountsMenuItems;
+
+// Makes account winfow key or hides it.
+- (IBAction)toggleAccountWindow:(id)sender;
+
// Installs Address Book plug-ins to |~/Library/Address Book Plug-Ins|. Updates
// plug-ins if the installed versions are outdated. Does not guaranteed to
// return a valid |error| if the method returns NO.
View
94 AppController.m
@@ -128,6 +128,8 @@ @implementation AppController
@dynamic unhandledIncomingCallsCount;
@synthesize userAttentionTimer = userAttentionTimer_;
+@synthesize accountsMenuItems = accountsMenuItems_;
+@synthesize windowMenu = windowMenu_;
@synthesize preferencesMenuItem = preferencesMenuItem_;
- (NSArray *)enabledAccountControllers {
@@ -412,6 +414,8 @@ - (void)dealloc {
[audioDevices_ release];
[ringtone_ release];
+ [accountsMenuItems_ release];
+ [windowMenu_ release];
[preferencesMenuItem_ release];
[[NSNotificationCenter defaultCenter] removeObserver:self];
@@ -800,6 +804,56 @@ - (CallController *)callControllerByIdentifier:(NSString *)identifier {
return nil;
}
+- (void)updateAccountsMenuItems {
+ // Remove old menu items.
+ for (NSMenuItem *menuItem in [self accountsMenuItems]) {
+ [[self windowMenu] removeItem:menuItem];
+ }
+
+ // Create new menu items.
+ NSArray *enabledControllers = [self enabledAccountControllers];
+ NSMutableArray *itemsArray
+ = [NSMutableArray arrayWithCapacity:[enabledControllers count]];
+ NSUInteger accountNumber = 1;
+ for (AccountController *accountController in enabledControllers) {
+ NSMenuItem *menuItem = [[[NSMenuItem alloc] init] autorelease];
+ [menuItem setRepresentedObject:accountController];
+ [menuItem setAction:@selector(toggleAccountWindow:)];
+ if ([[accountController accountDescription] length] > 0) {
+ [menuItem setTitle:[accountController accountDescription]];
+ } else {
+ [menuItem setTitle:[[accountController account] SIPAddress]];
+ }
+ if (accountNumber < 10) {
+ // Only add key equivalents for Command-[1..9].
+ [menuItem setKeyEquivalent:
+ [NSString stringWithFormat:@"%lu", (long)accountNumber]];
+ }
+ [itemsArray addObject:menuItem];
+ accountNumber++;
+ }
+ if ([itemsArray count] > 0) {
+ [itemsArray insertObject:[NSMenuItem separatorItem] atIndex:0];
+ [self setAccountsMenuItems:itemsArray];
+ }
+
+ // Add menu items to the Window menu.
+ NSUInteger itemTag = 4;
+ for (NSMenuItem *menuItem in itemsArray) {
+ [[self windowMenu] insertItem:menuItem atIndex:itemTag];
+ itemTag++;
+ }
+}
+
+- (IBAction)toggleAccountWindow:(id)sender {
+ AccountController *accountController = [sender representedObject];
+ if ([[accountController window] isKeyWindow]) {
+ [[accountController window] performClose:self];
+ } else {
+ [[accountController window] makeKeyAndOrderFront:self];
+ }
+}
+
- (void)updateDockTileBadgeLabel {
NSString *badgeString;
NSUInteger badgeNumber = [self unhandledIncomingCallsCount];
@@ -1315,9 +1369,12 @@ - (void)accountSetupControllerDidAddAccount:(NSNotification *)notification {
username:[accountDict objectForKey:kUsername]]
autorelease];
+ [[theAccountController window] setExcludedFromWindowsMenu:YES];
+
[theAccountController setEnabled:YES];
[[self accountControllers] addObject:theAccountController];
+ [self updateAccountsMenuItems];
[[theAccountController window] orderFront:self];
@@ -1343,6 +1400,7 @@ - (void)preferencesControllerDidRemoveAccount:(NSNotification *)notification {
[anAccountController removeAccountFromUserAgent];
[[self accountControllers] removeObjectAtIndex:index];
+ [self updateAccountsMenuItems];
}
- (void)preferencesControllerDidChangeAccountEnabled:(NSNotification *)notification {
@@ -1379,7 +1437,10 @@ - (void)preferencesControllerDidChangeAccountEnabled:(NSNotification *)notificat
username:[accountDict objectForKey:kUsername]]
autorelease];
+ [[theAccountController window] setExcludedFromWindowsMenu:YES];
+
NSString *description = [accountDict objectForKey:kDescription];
+ [theAccountController setAccountDescription:description];
if ([description length] > 0)
[[theAccountController window] setTitle:description];
@@ -1432,6 +1493,8 @@ - (void)preferencesControllerDidChangeAccountEnabled:(NSNotification *)notificat
// Prevent conflict with setFrameAutosaveName: when re-enabling the account.
[theAccountController setWindow:nil];
}
+
+ [self updateAccountsMenuItems];
}
- (void)preferencesControllerDidSwapAccounts:(NSNotification *)notification {
@@ -1450,6 +1513,8 @@ - (void)preferencesControllerDidSwapAccounts:(NSNotification *)notification {
[[self accountControllers] removeObjectAtIndex:sourceIndex];
else if (sourceIndex > destinationIndex)
[[self accountControllers] removeObjectAtIndex:(sourceIndex + 1)];
+
+ [self updateAccountsMenuItems];
}
- (void)preferencesControllerDidChangeNetworkSettings:(NSNotification *)notification {
@@ -1735,7 +1800,10 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
username:username]
autorelease];
+ [[anAccountController window] setExcludedFromWindowsMenu:YES];
+
NSString *description = [accountDict objectForKey:kDescription];
+ [anAccountController setAccountDescription:description];
if ([description length] > 0)
[[anAccountController window] setTitle:description];
@@ -1779,6 +1847,9 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
}
}
+ // Update account menu items.
+ [self updateAccountsMenuItems];
+
// Install audio devices changes callback.
AudioHardwareAddPropertyListener(kAudioHardwarePropertyDevices,
&AudioDevicesChanged, self);
@@ -1811,29 +1882,26 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Reopen all account windows when the user clicks the dock icon.
- (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication
hasVisibleWindows:(BOOL)flag {
+
// Show incoming call window, if any.
if ([self hasIncomingCallControllers]) {
for (AccountController *anAccountController in [self enabledAccountControllers]) {
- for (CallController *aCallController in [anAccountController callControllers])
+ for (CallController *aCallController in [anAccountController callControllers]) {
if ([[aCallController call] identifier] != kAKSIPUserAgentInvalidIdentifier &&
- [[aCallController call] state] == kAKSIPCallIncomingState)
- {
+ [[aCallController call] state] == kAKSIPCallIncomingState) {
[aCallController showWindow:nil];
+ // Return early, beause we can't break from two for loops.
return YES;
}
+ }
+ }
+ } else {
+ // Show window of first enalbed account.
+ if ([NSApp keyWindow] == nil && [[self enabledAccountControllers] count] > 0) {
+ [[[self enabledAccountControllers] objectAtIndex:0] showWindow:self];
}
}
- // No incoming calls, show window of the enabled accounts.
- for (AccountController *anAccountController in [self enabledAccountControllers]) {
- if (![[anAccountController window] isVisible])
- [[anAccountController window] orderFront:nil];
- }
-
- // Make first enabled account window key if there are no other key windows.
- if ([NSApp keyWindow] == nil && [[self enabledAccountControllers] count] > 0)
- [[[[self enabledAccountControllers] objectAtIndex:0] window] makeKeyWindow];
-
return YES;
}
View
54 English.lproj/MainMenu.xib
@@ -12,7 +12,7 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="106"/>
+ <integer value="24"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -710,6 +710,14 @@
</object>
<int key="connectionID">514</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">windowMenu</string>
+ <reference key="source" ref="971613649"/>
+ <reference key="destination" ref="835318025"/>
+ </object>
+ <int key="connectionID">515</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -1291,7 +1299,7 @@
<integer value="1"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
- <string>{{541, 931}, {194, 73}}</string>
+ <string>{{472, 660}, {194, 73}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<integer value="1"/>
<string>{{525, 802}, {197, 73}}</string>
@@ -1348,7 +1356,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">514</int>
+ <int key="maxID">515</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -1480,22 +1488,19 @@
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>addAccountOnFirstLaunch:</string>
- <string>openFAQURL:</string>
<string>showPreferencePanel:</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>id</string>
<string>id</string>
- <string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>addAccountOnFirstLaunch:</string>
- <string>openFAQURL:</string>
<string>showPreferencePanel:</string>
</object>
<object class="NSMutableArray" key="dict.values">
@@ -1505,24 +1510,41 @@
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
- <string key="name">openFAQURL:</string>
- <string key="candidateClassName">id</string>
- </object>
- <object class="IBActionInfo">
<string key="name">showPreferencePanel:</string>
<string key="candidateClassName">id</string>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="outlets">
- <string key="NS.key.0">preferencesMenuItem</string>
- <string key="NS.object.0">NSMenuItem</string>
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>preferencesMenuItem</string>
+ <string>windowMenu</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>NSMenuItem</string>
+ <string>NSMenu</string>
+ </object>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
- <string key="NS.key.0">preferencesMenuItem</string>
- <object class="IBToOneOutletInfo" key="NS.object.0">
- <string key="name">preferencesMenuItem</string>
- <string key="candidateClassName">NSMenuItem</string>
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>preferencesMenuItem</string>
+ <string>windowMenu</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBToOneOutletInfo">
+ <string key="name">preferencesMenuItem</string>
+ <string key="candidateClassName">NSMenuItem</string>
+ </object>
+ <object class="IBToOneOutletInfo">
+ <string key="name">windowMenu</string>
+ <string key="candidateClassName">NSMenu</string>
+ </object>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
View
50 German.lproj/MainMenu.xib
@@ -648,6 +648,14 @@
</object>
<int key="connectionID">512</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">windowMenu</string>
+ <reference key="source" ref="971613649"/>
+ <reference key="destination" ref="835318025"/>
+ </object>
+ <int key="connectionID">513</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -1226,7 +1234,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">512</int>
+ <int key="maxID">513</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -1358,22 +1366,19 @@
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>addAccountOnFirstLaunch:</string>
- <string>openFAQURL:</string>
<string>showPreferencePanel:</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>id</string>
<string>id</string>
- <string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>addAccountOnFirstLaunch:</string>
- <string>openFAQURL:</string>
<string>showPreferencePanel:</string>
</object>
<object class="NSMutableArray" key="dict.values">
@@ -1383,24 +1388,41 @@
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
- <string key="name">openFAQURL:</string>
- <string key="candidateClassName">id</string>
- </object>
- <object class="IBActionInfo">
<string key="name">showPreferencePanel:</string>
<string key="candidateClassName">id</string>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="outlets">
- <string key="NS.key.0">preferencesMenuItem</string>
- <string key="NS.object.0">NSMenuItem</string>
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>preferencesMenuItem</string>
+ <string>windowMenu</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>NSMenuItem</string>
+ <string>NSMenu</string>
+ </object>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
- <string key="NS.key.0">preferencesMenuItem</string>
- <object class="IBToOneOutletInfo" key="NS.object.0">
- <string key="name">preferencesMenuItem</string>
- <string key="candidateClassName">NSMenuItem</string>
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>preferencesMenuItem</string>
+ <string>windowMenu</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBToOneOutletInfo">
+ <string key="name">preferencesMenuItem</string>
+ <string key="candidateClassName">NSMenuItem</string>
+ </object>
+ <object class="IBToOneOutletInfo">
+ <string key="name">windowMenu</string>
+ <string key="candidateClassName">NSMenu</string>
+ </object>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
View
50 Russian.lproj/MainMenu.xib
@@ -709,6 +709,14 @@
</object>
<int key="connectionID">512</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">windowMenu</string>
+ <reference key="source" ref="971613649"/>
+ <reference key="destination" ref="835318025"/>
+ </object>
+ <int key="connectionID">513</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -1347,7 +1355,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">512</int>
+ <int key="maxID">513</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -1479,22 +1487,19 @@
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>addAccountOnFirstLaunch:</string>
- <string>openFAQURL:</string>
<string>showPreferencePanel:</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>id</string>
<string>id</string>
- <string>id</string>
</object>
</object>
<object class="NSMutableDictionary" key="actionInfosByName">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>addAccountOnFirstLaunch:</string>
- <string>openFAQURL:</string>
<string>showPreferencePanel:</string>
</object>
<object class="NSMutableArray" key="dict.values">
@@ -1504,24 +1509,41 @@
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo">
- <string key="name">openFAQURL:</string>
- <string key="candidateClassName">id</string>
- </object>
- <object class="IBActionInfo">
<string key="name">showPreferencePanel:</string>
<string key="candidateClassName">id</string>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="outlets">
- <string key="NS.key.0">preferencesMenuItem</string>
- <string key="NS.object.0">NSMenuItem</string>
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>preferencesMenuItem</string>
+ <string>windowMenu</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>NSMenuItem</string>
+ <string>NSMenu</string>
+ </object>
</object>
<object class="NSMutableDictionary" key="toOneOutletInfosByName">
- <string key="NS.key.0">preferencesMenuItem</string>
- <object class="IBToOneOutletInfo" key="NS.object.0">
- <string key="name">preferencesMenuItem</string>
- <string key="candidateClassName">NSMenuItem</string>
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>preferencesMenuItem</string>
+ <string>windowMenu</string>
+ </object>
+ <object class="NSMutableArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBToOneOutletInfo">
+ <string key="name">preferencesMenuItem</string>
+ <string key="candidateClassName">NSMenuItem</string>
+ </object>
+ <object class="IBToOneOutletInfo">
+ <string key="name">windowMenu</string>
+ <string key="candidateClassName">NSMenu</string>
+ </object>
</object>
</object>
<object class="IBClassDescriptionSource" key="sourceIdentifier">

0 comments on commit 3509409

Please sign in to comment.