diff options
author | Mikkel Krautz <mikkel@krautz.dk> | 2011-08-09 02:11:37 +0400 |
---|---|---|
committer | Mikkel Krautz <mikkel@krautz.dk> | 2011-08-09 02:11:37 +0400 |
commit | b25eb2228dc8d560e86037d5d3bae1d69bc45a1c (patch) | |
tree | 8e300f92f9e809e95de5f0f5ff6154c136ca70e0 /Source/Classes | |
parent | 26600e4d440afc645eb18e40ecf6336ba065877b (diff) |
Add transmission preferences and improve push-to-talk mode.
Diffstat (limited to 'Source/Classes')
-rw-r--r-- | Source/Classes/MUApplicationDelegate.m | 9 | ||||
-rw-r--r-- | Source/Classes/MUAudioTransmissionPreferencesViewController.h | 32 | ||||
-rw-r--r-- | Source/Classes/MUAudioTransmissionPreferencesViewController.m | 143 | ||||
-rw-r--r-- | Source/Classes/MUChannelViewController.m | 45 | ||||
-rw-r--r-- | Source/Classes/MUPreferencesViewController.m | 32 | ||||
-rw-r--r-- | Source/Classes/MUServerRootViewController.m | 4 | ||||
-rw-r--r-- | Source/Classes/MUServerViewController.m | 3 |
7 files changed, 254 insertions, 14 deletions
diff --git a/Source/Classes/MUApplicationDelegate.m b/Source/Classes/MUApplicationDelegate.m index 2e5ee2e..7763a7d 100644 --- a/Source/Classes/MUApplicationDelegate.m +++ b/Source/Classes/MUApplicationDelegate.m @@ -121,8 +121,15 @@ - (void) setupAudio { // Set up a good set of default audio settings. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; - MKAudioSettings settings; + if ([[defaults stringForKey:@"xmit"] isEqualToString:@"vad"]) + settings.transmitType = MKTransmitTypeVAD; + else if ([[defaults stringForKey:@"xmit"] isEqualToString:@"continuous"]) + settings.transmitType = MKTransmitTypeContinuous; + else if ([[defaults stringForKey:@"xmit"] isEqualToString:@"ptt"]) + settings.transmitType = MKTransmitTypeToggle; + else + settings.transmitType = MKTransmitTypeVAD; settings.codec = MKCodecFormatCELT; settings.quality = 24000; settings.audioPerPacket = 10; diff --git a/Source/Classes/MUAudioTransmissionPreferencesViewController.h b/Source/Classes/MUAudioTransmissionPreferencesViewController.h new file mode 100644 index 0000000..af4ac11 --- /dev/null +++ b/Source/Classes/MUAudioTransmissionPreferencesViewController.h @@ -0,0 +1,32 @@ +/* Copyright (C) 2009-2011 Mikkel Krautz <mikkel@krautz.dk> + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + - Neither the name of the Mumble Developers nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +@interface MUAudioTransmissionPreferencesViewController : UITableViewController +@end diff --git a/Source/Classes/MUAudioTransmissionPreferencesViewController.m b/Source/Classes/MUAudioTransmissionPreferencesViewController.m new file mode 100644 index 0000000..1f63d3c --- /dev/null +++ b/Source/Classes/MUAudioTransmissionPreferencesViewController.m @@ -0,0 +1,143 @@ +/* Copyright (C) 2009-2011 Mikkel Krautz <mikkel@krautz.dk> + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + - Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + - Neither the name of the Mumble Developers nor the names of its + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#import "MUAudioTransmissionPreferencesViewController.h" + +@interface MUAudioTransmissionPreferencesViewController () { +} +@end + +@implementation MUAudioTransmissionPreferencesViewController + +- (id) init { + if ((self = [super initWithStyle:UITableViewStyleGrouped])) { + } + return self; +} + +- (void) didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; +} + +#pragma mark - View lifecycle + +- (void) viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + self.title = @"Transmission"; +} + +- (void) viewDidAppear:(BOOL)animated { + [super viewDidAppear:animated]; +} + +- (void) viewWillDisappear:(BOOL)animated { + [super viewWillDisappear:animated]; +} + +- (void) viewDidDisappear:(BOOL)animated { + [super viewDidDisappear:animated]; +} + +- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { + // Return YES for supported orientations + return (interfaceOrientation == UIInterfaceOrientationPortrait); +} + +#pragma mark - Table view data source + +- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return 3; +} + +- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + static NSString *CellIdentifier = @"AudioXmitOptionCell"; + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; + if (cell == nil) { + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; + } + + NSString *current = [[NSUserDefaults standardUserDefaults] stringForKey:@"xmit"]; + cell.accessoryType = UITableViewCellAccessoryNone; + if (indexPath.section == 0) { + if (indexPath.row == 0) { + cell.textLabel.text = @"Voice Activated"; + if ([current isEqualToString:@"vad"]) + cell.accessoryType = UITableViewCellAccessoryCheckmark; + } else if (indexPath.row == 1) { + cell.textLabel.text = @"Push-to-talk"; + if ([current isEqualToString:@"ptt"]) + cell.accessoryType = UITableViewCellAccessoryCheckmark; + } else if (indexPath.row == 2) { + cell.textLabel.text = @"Continuous"; + if ([current isEqualToString:@"continuous"]) + cell.accessoryType = UITableViewCellAccessoryCheckmark; + } + } + + return cell; +} + +- (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { + if (section == 0) { + return @"Transmission method"; + } + + return @"???"; +} + +#pragma mark - Table view delegate + +- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + UITableViewCell *cell = nil; + + // Transmission setting change + if (indexPath.section == 0) { + for (int i = 0; i < 3; i++) { + cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]]; + cell.accessoryType = UITableViewCellAccessoryNone; + } + [self.tableView deselectRowAtIndexPath:indexPath animated:YES]; + if (indexPath.row == 0) { + [[NSUserDefaults standardUserDefaults] setObject:@"vad" forKey:@"xmit"]; + } else if (indexPath.row == 1) { + [[NSUserDefaults standardUserDefaults] setObject:@"ptt" forKey:@"xmit"]; + } else if (indexPath.row == 2) { + [[NSUserDefaults standardUserDefaults] setObject:@"continuous" forKey:@"xmit"]; + } + cell = [self.tableView cellForRowAtIndexPath:indexPath]; + cell.accessoryType = UITableViewCellAccessoryCheckmark; + } +} + +@end diff --git a/Source/Classes/MUChannelViewController.m b/Source/Classes/MUChannelViewController.m index 441d6dc..2694287 100644 --- a/Source/Classes/MUChannelViewController.m +++ b/Source/Classes/MUChannelViewController.m @@ -37,6 +37,7 @@ MKChannel *_channel; MKServerModel *_model; BOOL _pttState; + UIButton *_talkButton; } - (UIView *) stateAccessoryViewForUser:(MKUser *)user; @end @@ -67,10 +68,29 @@ [self.tableView reloadData]; - UIBarButtonItem *pttButton = [[[UIBarButtonItem alloc] initWithTitle:@"PushToTalk" style:UIBarButtonItemStyleBordered target:self action:@selector(pushToTalkClicked:)] autorelease]; - UIBarButtonItem *flexSpace = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil] autorelease]; - self.toolbarItems = [NSArray arrayWithObjects:flexSpace, pttButton, flexSpace, nil]; - self.navigationController.toolbarHidden = NO; + if ([[MKAudio sharedAudio] transmitType] == MKTransmitTypeToggle) { + UIImage *onImage = [UIImage imageNamed:@"talkbutton_on"]; + UIImage *offImage = [UIImage imageNamed:@"talkbutton_off"]; + + UIWindow *window = [[[UIApplication sharedApplication] windows] objectAtIndex:0]; + CGRect windowRect = [window frame]; + CGRect buttonRect = windowRect; + buttonRect.size = onImage.size; + buttonRect.origin.y = windowRect.size.height - (buttonRect.size.height + 40); + buttonRect.origin.x = (windowRect.size.width - buttonRect.size.width)/2; + + _talkButton = [UIButton buttonWithType:UIButtonTypeCustom]; + _talkButton.frame = buttonRect; + [_talkButton setBackgroundImage:onImage forState:UIControlStateHighlighted]; + [_talkButton setBackgroundImage:offImage forState:UIControlStateNormal]; + [_talkButton setOpaque:NO]; + [_talkButton setAlpha:0.25f]; + [window addSubview:_talkButton]; + + [_talkButton addTarget:self action:@selector(talkOn:) forControlEvents:UIControlEventTouchDown]; + [_talkButton addTarget:self action:@selector(talkOff:) forControlEvents:UIControlEventTouchUpInside|UIControlEventTouchUpOutside]; + } + } - (void) viewWillDisappear:(BOOL)animated { @@ -81,8 +101,12 @@ [_users release]; _users = nil; + if (_talkButton) { + [_talkButton removeFromSuperview]; + _talkButton = nil; + } + [self.tableView reloadData]; - self.navigationController.toolbarHidden = YES; } - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { @@ -352,9 +376,14 @@ #pragma mark - PushToTalk -- (void) pushToTalkClicked:(id)sender { - _pttState = !_pttState; - [[MKAudio sharedAudio] setForceTransmit:_pttState]; +- (void) talkOn:(UIButton *)button { + [button setAlpha:1.0f]; + [[MKAudio sharedAudio] setForceTransmit:YES]; +} + +- (void) talkOff:(UIButton *)button { + [button setAlpha:0.25f]; + [[MKAudio sharedAudio] setForceTransmit:NO]; } @end diff --git a/Source/Classes/MUPreferencesViewController.m b/Source/Classes/MUPreferencesViewController.m index 5b753b2..c0ec194 100644 --- a/Source/Classes/MUPreferencesViewController.m +++ b/Source/Classes/MUPreferencesViewController.m @@ -32,6 +32,7 @@ #import "MUApplication.h" #import "MUApplicationDelegate.h" #import "MUCertificatePreferencesViewController.h" +#import "MUAudioTransmissionPreferencesViewController.h" #import "MUDiagnosticsViewController.h" #import "MUCertificateController.h" @@ -64,8 +65,8 @@ #pragma mark Looks - (void) viewWillAppear:(BOOL)animated { - [self setTitle:@"Preferences"]; - [[self tableView] reloadData]; + self.title = @"Preferences"; + [self.tableView reloadData]; } #pragma mark - @@ -78,7 +79,7 @@ - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { // Audio if (section == 0) { - return 1; + return 2; // Network } else if (section == 1) { return 2; @@ -112,6 +113,23 @@ [volSlider addTarget:self action:@selector(audioVolumeChanged:) forControlEvents:UIControlEventValueChanged]; [volSlider release]; } + // Transmit method + if ([indexPath row] == 1) { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"AudioXmitCell"]; + if (cell == nil) + cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"AudioXmitCell"] autorelease]; + cell.textLabel.text = @"Transmission"; + NSString *xmit = [[NSUserDefaults standardUserDefaults] stringForKey:@"xmit"]; + if ([xmit isEqualToString:@"vad"]) { + cell.detailTextLabel.text = @"Voice Activated"; + } else if ([xmit isEqualToString:@"ptt"]) { + cell.detailTextLabel.text = @"Push-to-talk"; + } else if ([xmit isEqualToString:@"continuous"]) { + cell.detailTextLabel.text = @"Continuous"; + } + cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; + return cell; + } // Network } else if ([indexPath section] == 1) { @@ -163,7 +181,13 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [[self tableView] deselectRowAtIndexPath:indexPath animated:YES]; - if ([indexPath section] == 1) { // Network + if (indexPath.section == 0) { // Audio + if (indexPath.row == 1) { // Transmission + MUAudioTransmissionPreferencesViewController *audioXmit = [[MUAudioTransmissionPreferencesViewController alloc] init]; + [self.navigationController pushViewController:audioXmit animated:YES]; + [audioXmit release]; + } + } else if ([indexPath section] == 1) { // Network if ([indexPath row] == 1) { // Certificates MUCertificatePreferencesViewController *certPref = [[MUCertificatePreferencesViewController alloc] init]; [self.navigationController pushViewController:certPref animated:YES]; diff --git a/Source/Classes/MUServerRootViewController.m b/Source/Classes/MUServerRootViewController.m index 93dedf8..0561e1c 100644 --- a/Source/Classes/MUServerRootViewController.m +++ b/Source/Classes/MUServerRootViewController.m @@ -74,6 +74,10 @@ [_username release]; [_password release]; + [_serverView release]; + [_channelView release]; + [_connectionView release]; + [_model release]; [_connection disconnect]; [_connection release]; diff --git a/Source/Classes/MUServerViewController.m b/Source/Classes/MUServerViewController.m index a9585e4..a46390b 100644 --- a/Source/Classes/MUServerViewController.m +++ b/Source/Classes/MUServerViewController.m @@ -94,7 +94,7 @@ - (id) initWithServerModel:(MKServerModel *)serverModel { if ((self = [super initWithStyle:UITableViewStylePlain])) { - _serverModel = serverModel; + _serverModel = [serverModel retain]; [_serverModel addDelegate:self]; } return self; @@ -102,6 +102,7 @@ - (void) dealloc { [_serverModel removeDelegate:self]; + [_serverModel release]; [super dealloc]; } |