2016-05-11 21:04:49 +00:00
|
|
|
//
|
|
|
|
// SettingsViewController.m
|
|
|
|
// Mini vMac
|
|
|
|
//
|
|
|
|
// Created by Jesús A. Álvarez on 07/05/2016.
|
2018-04-28 10:12:43 +00:00
|
|
|
// Copyright © 2016-2018 namedfork. All rights reserved.
|
2016-05-11 21:04:49 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "SettingsViewController.h"
|
|
|
|
#import "AppDelegate.h"
|
|
|
|
|
|
|
|
@interface SettingsViewController ()
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2016-05-28 20:20:55 +00:00
|
|
|
typedef enum : NSInteger {
|
|
|
|
SettingsSectionSpeed,
|
|
|
|
SettingsSectionMouse,
|
|
|
|
SettingsSectionKeyboard,
|
2017-11-30 19:09:08 +00:00
|
|
|
SettingsSectionDisplay,
|
2016-05-28 20:20:55 +00:00
|
|
|
SettingsSectionMachine,
|
|
|
|
SettingsSectionAbout
|
|
|
|
} SettingsSection;
|
|
|
|
|
2016-05-11 21:04:49 +00:00
|
|
|
@implementation SettingsViewController
|
2016-05-14 11:06:42 +00:00
|
|
|
{
|
|
|
|
NSArray *keyboardLayouts;
|
2016-05-28 20:20:55 +00:00
|
|
|
NSArray<NSBundle*> *emulatorBundles;
|
2016-06-28 21:07:52 +00:00
|
|
|
NSMutableArray *machineList; // NSString (header) or NSBundle (emulator bundle)
|
2020-09-24 22:16:53 +00:00
|
|
|
NSMutableDictionary<NSString*,UIImage*> *bundleIcons;
|
2016-06-28 21:07:52 +00:00
|
|
|
NSMutableSet<NSBundle*> *groupedEmulatorBundles;
|
2016-06-06 14:09:23 +00:00
|
|
|
NSBundle *selectedEmulatorBundle;
|
2016-05-22 15:09:33 +00:00
|
|
|
NSString *aboutTitle;
|
|
|
|
NSArray<NSDictionary<NSString*,NSString*>*> *aboutItems;
|
|
|
|
UITextView *footerView;
|
2016-05-14 11:06:42 +00:00
|
|
|
}
|
2016-05-11 21:04:49 +00:00
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
|
[super viewDidLoad];
|
2024-02-10 13:09:02 +00:00
|
|
|
keyboardLayouts = [AppDelegate sharedInstance].keyboardLayoutPaths;
|
2016-06-06 14:09:23 +00:00
|
|
|
[self loadEmulatorBundles];
|
2016-05-22 15:09:33 +00:00
|
|
|
[self loadCredits];
|
|
|
|
}
|
|
|
|
|
2016-06-06 14:09:23 +00:00
|
|
|
- (void)loadEmulatorBundles {
|
|
|
|
emulatorBundles = [AppDelegate sharedInstance].emulatorBundles;
|
2020-09-24 22:16:53 +00:00
|
|
|
bundleIcons = [NSMutableDictionary dictionaryWithCapacity:emulatorBundles.count];
|
2016-06-28 21:07:52 +00:00
|
|
|
NSMutableDictionary<NSString*,NSMutableArray<NSBundle*>*> *bundlesByName = [NSMutableDictionary dictionaryWithCapacity:emulatorBundles.count];
|
2016-06-06 14:09:23 +00:00
|
|
|
NSString *selectedBundleName = [[NSUserDefaults standardUserDefaults] stringForKey:@"machine"];
|
|
|
|
for (NSBundle *bundle in emulatorBundles) {
|
|
|
|
NSString *bundleName = bundle.bundlePath.lastPathComponent.stringByDeletingPathExtension;
|
|
|
|
if ([selectedBundleName isEqualToString:bundleName]) {
|
|
|
|
selectedEmulatorBundle = bundle;
|
|
|
|
}
|
2016-06-28 21:07:52 +00:00
|
|
|
NSString *displayName = [bundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
|
|
|
|
if (bundlesByName[displayName] == nil) {
|
|
|
|
bundlesByName[displayName] = [NSMutableArray arrayWithCapacity:1];
|
|
|
|
}
|
|
|
|
[bundlesByName[displayName] addObject:bundle];
|
|
|
|
}
|
|
|
|
NSArray *sortedNames = [bundlesByName.allKeys sortedArrayUsingSelector:@selector(compare:)];
|
|
|
|
machineList = [NSMutableArray arrayWithCapacity:emulatorBundles.count];
|
|
|
|
groupedEmulatorBundles = [NSMutableSet setWithCapacity:emulatorBundles.count];
|
|
|
|
for (NSString *name in sortedNames) {
|
|
|
|
NSArray<NSBundle*>* bundles = bundlesByName[name];
|
|
|
|
if (bundles.count > 1) {
|
|
|
|
[machineList addObject:name];
|
|
|
|
[groupedEmulatorBundles addObjectsFromArray:bundles];
|
|
|
|
}
|
|
|
|
[machineList addObjectsFromArray:bundles];
|
2016-06-06 14:09:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-22 15:09:33 +00:00
|
|
|
- (void)loadCredits {
|
|
|
|
NSDictionary *aboutData = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"about" ofType:@"plist"]];
|
|
|
|
aboutTitle = aboutData[@"title"];
|
|
|
|
aboutItems = aboutData[@"items"];
|
|
|
|
footerView = [[UITextView alloc] initWithFrame:CGRectZero];
|
2017-09-23 13:54:13 +00:00
|
|
|
NSString *footerHTML = [aboutData[@"footer.html"] stringByReplacingOccurrencesOfString:@"$mnvmversion" withString:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"MNVMVersion"]];
|
|
|
|
NSAttributedString *str = [[NSAttributedString alloc] initWithData:[footerHTML dataUsingEncoding:NSUTF8StringEncoding]
|
|
|
|
options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
|
|
|
|
NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)}
|
|
|
|
documentAttributes:nil
|
|
|
|
error:NULL];
|
2016-05-22 15:09:33 +00:00
|
|
|
footerView.attributedText = str;
|
|
|
|
[footerView sizeToFit];
|
|
|
|
footerView.editable = NO;
|
|
|
|
footerView.textAlignment = NSTextAlignmentCenter;
|
|
|
|
footerView.textColor = [UIColor darkGrayColor];
|
|
|
|
footerView.font = [UIFont systemFontOfSize:[UIFont smallSystemFontSize]];
|
|
|
|
footerView.backgroundColor = [UIColor clearColor];
|
2020-06-23 16:32:07 +00:00
|
|
|
footerView.scrollEnabled = NO;
|
2016-05-11 21:04:49 +00:00
|
|
|
}
|
|
|
|
|
2016-05-14 12:04:54 +00:00
|
|
|
- (void)viewDidAppear:(BOOL)animated {
|
|
|
|
[super viewDidAppear:animated];
|
2016-05-28 11:01:13 +00:00
|
|
|
[AppDelegate sharedEmulator].running = NO;
|
2016-12-04 19:05:24 +00:00
|
|
|
if ([UIApplication instancesRespondToSelector:@selector(btcMouseSetRawMode:)]) {
|
|
|
|
[[UIApplication sharedApplication] btcMouseSetRawMode:NO];
|
|
|
|
}
|
2016-05-14 12:04:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewWillDisappear:(BOOL)animated {
|
|
|
|
[super viewWillDisappear:animated];
|
2016-05-28 11:01:13 +00:00
|
|
|
[AppDelegate sharedEmulator].running = YES;
|
2020-09-24 22:29:30 +00:00
|
|
|
if (![selectedEmulatorBundle isEqual:[AppDelegate sharedEmulator].bundle] && ![AppDelegate sharedEmulator].anyDiskInserted) {
|
2020-09-25 20:13:52 +00:00
|
|
|
[[AppDelegate sharedInstance] loadAndStartEmulator];
|
2020-09-24 22:29:30 +00:00
|
|
|
}
|
2016-05-14 12:04:54 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 21:04:49 +00:00
|
|
|
- (void)showInsertDisk:(id)sender {
|
|
|
|
[[AppDelegate sharedInstance] showInsertDisk:sender];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dismiss:(id)sender {
|
|
|
|
[self dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
}
|
|
|
|
|
2016-05-13 21:47:59 +00:00
|
|
|
- (IBAction)changeSpeed:(UISegmentedControl*)sender {
|
|
|
|
if ([sender isKindOfClass:[UISegmentedControl class]]) {
|
2016-06-06 14:09:23 +00:00
|
|
|
EmulatorSpeed speedValue = sender.selectedSegmentIndex == sender.numberOfSegments - 1 ? EmulatorSpeedAllOut : sender.selectedSegmentIndex;
|
|
|
|
[[NSUserDefaults standardUserDefaults] setInteger:speedValue forKey:@"speedValue"];
|
2016-05-13 21:47:59 +00:00
|
|
|
}
|
2016-05-11 21:04:49 +00:00
|
|
|
}
|
|
|
|
|
2016-05-13 21:47:59 +00:00
|
|
|
- (IBAction)changeMouseType:(UISegmentedControl*)sender {
|
|
|
|
if ([sender isKindOfClass:[UISegmentedControl class]]) {
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:sender.selectedSegmentIndex == 1 forKey:@"trackpad"];
|
|
|
|
}
|
2016-05-11 21:04:49 +00:00
|
|
|
}
|
|
|
|
|
2017-11-30 19:09:08 +00:00
|
|
|
- (IBAction)changeScreenScaling:(UISegmentedControl*)sender {
|
|
|
|
if ([sender isKindOfClass:[UISegmentedControl class]]) {
|
|
|
|
NSString *filter = @[kCAFilterNearest, kCAFilterLinear, kCAFilterTrilinear][sender.selectedSegmentIndex];
|
|
|
|
[[NSUserDefaults standardUserDefaults] setObject:filter forKey:@"screenFilter"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-06 14:09:23 +00:00
|
|
|
- (void)changeRunInBackground:(UISwitch*)sender {
|
|
|
|
if ([sender isKindOfClass:[UISwitch class]]) {
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:sender.on forKey:@"runInBackground"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)changeAutoSlow:(UISwitch*)sender {
|
|
|
|
if ([sender isKindOfClass:[UISwitch class]]) {
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:sender.on forKey:@"autoSlow"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 16:32:07 +00:00
|
|
|
- (void)changeAutoShowGestureHelp:(UISwitch*)sender {
|
|
|
|
if ([sender isKindOfClass:[UISwitch class]]) {
|
|
|
|
[[NSUserDefaults standardUserDefaults] setBool:sender.on forKey:@"autoShowGestureHelp"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-13 21:47:59 +00:00
|
|
|
#pragma mark - Table view data source
|
2016-05-11 21:04:49 +00:00
|
|
|
|
2016-05-13 21:47:59 +00:00
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
2017-11-30 19:09:08 +00:00
|
|
|
return 6;
|
2016-05-11 21:04:49 +00:00
|
|
|
}
|
|
|
|
|
2016-05-13 21:47:59 +00:00
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
2016-05-28 20:20:55 +00:00
|
|
|
switch (section) {
|
2016-06-06 14:09:23 +00:00
|
|
|
case SettingsSectionSpeed: {
|
|
|
|
NSDictionary *capabilities = [selectedEmulatorBundle objectForInfoDictionaryKey:@"MNVMCapabilities"];
|
|
|
|
BOOL hasAutoSlow = [capabilities[@"AutoSlow"] boolValue];
|
|
|
|
return hasAutoSlow ? 3 : 2;
|
|
|
|
}
|
2016-05-28 20:20:55 +00:00
|
|
|
case SettingsSectionKeyboard:
|
|
|
|
return keyboardLayouts.count;
|
|
|
|
case SettingsSectionMachine:
|
2016-06-28 21:07:52 +00:00
|
|
|
return machineList.count;
|
2016-05-28 20:20:55 +00:00
|
|
|
case SettingsSectionAbout:
|
2024-02-10 11:15:01 +00:00
|
|
|
#if !defined(TARGET_OS_VISION) || TARGET_OS_VISION == 0
|
2020-06-23 16:32:07 +00:00
|
|
|
return aboutItems.count + 1;
|
2024-02-10 11:15:01 +00:00
|
|
|
#else
|
|
|
|
return aboutItems.count;
|
|
|
|
#endif
|
2016-05-28 20:20:55 +00:00
|
|
|
default:
|
|
|
|
return 1;
|
2016-05-13 21:47:59 +00:00
|
|
|
}
|
2016-05-11 21:04:49 +00:00
|
|
|
}
|
|
|
|
|
2016-05-13 21:47:59 +00:00
|
|
|
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
|
|
|
|
switch (section) {
|
2016-05-28 20:20:55 +00:00
|
|
|
case SettingsSectionSpeed:
|
|
|
|
return NSLocalizedString(@"Speed", nil);
|
|
|
|
case SettingsSectionMouse:
|
|
|
|
return NSLocalizedString(@"Mouse Type", nil);
|
|
|
|
case SettingsSectionMachine:
|
|
|
|
return NSLocalizedString(@"Emulated Machine", nil);
|
|
|
|
case SettingsSectionKeyboard:
|
|
|
|
return NSLocalizedString(@"Keyboard Layout", nil);
|
2017-11-30 19:09:08 +00:00
|
|
|
case SettingsSectionDisplay:
|
|
|
|
return NSLocalizedString(@"Display Scaling", nil);
|
2016-05-28 20:20:55 +00:00
|
|
|
case SettingsSectionAbout:
|
|
|
|
return aboutTitle;
|
|
|
|
default:return nil;
|
2016-05-13 21:47:59 +00:00
|
|
|
}
|
2016-05-11 21:04:49 +00:00
|
|
|
}
|
|
|
|
|
2016-05-22 15:09:33 +00:00
|
|
|
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
|
2016-05-28 20:20:55 +00:00
|
|
|
if (section == SettingsSectionAbout) {
|
2016-05-22 15:09:33 +00:00
|
|
|
return footerView;
|
|
|
|
} else {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-28 20:20:55 +00:00
|
|
|
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section {
|
2016-06-06 14:09:23 +00:00
|
|
|
if (section == SettingsSectionSpeed) {
|
|
|
|
return NSLocalizedString(@"Faster speeds and running in background drain the battery faster", nil);
|
2020-09-24 22:29:30 +00:00
|
|
|
} else if (section == SettingsSectionMachine && [AppDelegate sharedEmulator].anyDiskInserted) {
|
|
|
|
return NSLocalizedString(@"The emulated machine cannot be changed while disks are inserted.", nil);
|
2016-05-28 20:20:55 +00:00
|
|
|
} else {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-22 15:09:33 +00:00
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
|
2016-05-28 20:20:55 +00:00
|
|
|
if (section == SettingsSectionAbout) {
|
2016-05-22 15:09:33 +00:00
|
|
|
return footerView.bounds.size.height;
|
|
|
|
} else {
|
2016-05-28 20:20:55 +00:00
|
|
|
return UITableViewAutomaticDimension;
|
2016-05-22 15:09:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-13 21:47:59 +00:00
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
UITableViewCell *cell = nil;
|
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
|
|
|
NSInteger section = indexPath.section;
|
2016-05-28 20:20:55 +00:00
|
|
|
if (section == SettingsSectionSpeed) {
|
2016-06-06 14:09:23 +00:00
|
|
|
if (indexPath.row == 0) {
|
|
|
|
cell = [tableView dequeueReusableCellWithIdentifier:@"speed" forIndexPath:indexPath];
|
|
|
|
UISegmentedControl *speedControl = (UISegmentedControl*)[cell viewWithTag:128];
|
|
|
|
EmulatorSpeed speedValue = [defaults integerForKey:@"speedValue"];
|
|
|
|
speedControl.selectedSegmentIndex = speedValue == EmulatorSpeedAllOut ? speedControl.numberOfSegments - 1 : speedValue;
|
|
|
|
} else if (indexPath.row == 1) {
|
|
|
|
cell = [self switchCellForTableView:tableView indexPath:indexPath action:@selector(changeRunInBackground:) on:[defaults boolForKey:@"runInBackground"]];
|
|
|
|
cell.textLabel.text = NSLocalizedString(@"Run in background", nil);
|
|
|
|
} else if (indexPath.row == 2) {
|
|
|
|
cell = [self switchCellForTableView:tableView indexPath:indexPath action:@selector(changeAutoSlow:) on:[defaults boolForKey:@"autoSlow"]];
|
|
|
|
cell.textLabel.text = NSLocalizedString(@"AutoSlow", nil);
|
|
|
|
}
|
2016-05-28 20:20:55 +00:00
|
|
|
} else if (section == SettingsSectionMouse) {
|
2016-05-13 21:47:59 +00:00
|
|
|
cell = [tableView dequeueReusableCellWithIdentifier:@"mouse" forIndexPath:indexPath];
|
|
|
|
UISegmentedControl *mouseControl = (UISegmentedControl*)[cell viewWithTag:128];
|
|
|
|
mouseControl.selectedSegmentIndex = [defaults boolForKey:@"trackpad"] ? 1 : 0;
|
2016-05-28 20:20:55 +00:00
|
|
|
} else if (section == SettingsSectionKeyboard) {
|
2016-05-13 21:47:59 +00:00
|
|
|
cell = [tableView dequeueReusableCellWithIdentifier:@"keyboard" forIndexPath:indexPath];
|
2016-05-14 11:06:42 +00:00
|
|
|
NSString *layout = keyboardLayouts[indexPath.row];
|
|
|
|
cell.textLabel.text = layout.lastPathComponent.stringByDeletingPathExtension;
|
|
|
|
BOOL selected = [[defaults stringForKey:@"keyboardLayout"] isEqualToString:layout.lastPathComponent];
|
|
|
|
cell.accessoryType = selected ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
|
2016-05-28 20:20:55 +00:00
|
|
|
} else if (section == SettingsSectionMachine) {
|
2016-06-28 21:07:52 +00:00
|
|
|
id item = machineList[indexPath.row];
|
|
|
|
BOOL rowIsHeader = [item isKindOfClass:[NSString class]];
|
|
|
|
BOOL rowHasHeader = [groupedEmulatorBundles containsObject:item];
|
|
|
|
NSBundle *bundle = rowIsHeader ? machineList[indexPath.row + 1] : item;
|
2016-05-28 20:20:55 +00:00
|
|
|
cell = [tableView dequeueReusableCellWithIdentifier:@"machine" forIndexPath:indexPath];
|
2016-06-28 21:07:52 +00:00
|
|
|
if (rowIsHeader) {
|
|
|
|
cell.textLabel.text = [bundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
|
|
|
|
cell.detailTextLabel.text = NSLocalizedString(@"multiple configurations available", nil);
|
|
|
|
} else if (rowHasHeader) {
|
|
|
|
cell.textLabel.text = [bundle objectForInfoDictionaryKey:@"CFBundleGetInfoString"];
|
|
|
|
cell.detailTextLabel.text = nil;
|
|
|
|
} else {
|
|
|
|
cell.textLabel.text = [bundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
|
|
|
|
cell.detailTextLabel.text = [bundle objectForInfoDictionaryKey:@"CFBundleGetInfoString"];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rowHasHeader) {
|
|
|
|
cell.imageView.image = nil;
|
|
|
|
cell.indentationLevel = 1;
|
|
|
|
} else {
|
2020-09-24 22:16:53 +00:00
|
|
|
cell.imageView.image = [self iconForBundle:bundle];
|
2016-06-28 21:07:52 +00:00
|
|
|
cell.indentationLevel = 0;
|
|
|
|
}
|
|
|
|
cell.accessoryType = (item == selectedEmulatorBundle) ? UITableViewCellAccessoryCheckmark : UITableViewCellAccessoryNone;
|
|
|
|
cell.selectionStyle = rowIsHeader ? UITableViewCellSelectionStyleNone : UITableViewCellSelectionStyleDefault;
|
2016-05-28 20:20:55 +00:00
|
|
|
} else if (section == SettingsSectionAbout) {
|
2020-06-23 16:32:07 +00:00
|
|
|
if (indexPath.row >= aboutItems.count) {
|
|
|
|
cell = [self switchCellForTableView:tableView indexPath:indexPath action:@selector(changeAutoShowGestureHelp:) on:[defaults boolForKey:@"autoShowGestureHelp"]];
|
|
|
|
cell.textLabel.text = NSLocalizedString(@"Show Gesture Help", nil);
|
2016-05-22 15:09:33 +00:00
|
|
|
} else {
|
2020-06-23 16:32:07 +00:00
|
|
|
cell = [self aboutCellForTableView:tableView indexPath:indexPath];
|
2016-05-22 15:09:33 +00:00
|
|
|
}
|
2017-11-30 19:09:08 +00:00
|
|
|
} else if (section == SettingsSectionDisplay) {
|
|
|
|
cell = [tableView dequeueReusableCellWithIdentifier:@"display" forIndexPath:indexPath];
|
|
|
|
UISegmentedControl *filterControl = (UISegmentedControl*)[cell viewWithTag:128];
|
|
|
|
NSString *filter = [defaults stringForKey:@"screenFilter"];
|
|
|
|
if ([filter isEqualToString:kCAFilterNearest]) {
|
|
|
|
filterControl.selectedSegmentIndex = 0;
|
|
|
|
} else if ([filter isEqualToString:kCAFilterTrilinear]) {
|
|
|
|
filterControl.selectedSegmentIndex = 2;
|
|
|
|
} else {
|
|
|
|
filterControl.selectedSegmentIndex = 1;
|
|
|
|
}
|
2016-05-13 21:47:59 +00:00
|
|
|
}
|
|
|
|
return cell;
|
2016-05-11 21:04:49 +00:00
|
|
|
}
|
|
|
|
|
2020-09-24 22:16:53 +00:00
|
|
|
- (UIImage*)iconForBundle:(NSBundle*)bundle {
|
|
|
|
UIImage *icon = bundleIcons[bundle.bundlePath];
|
|
|
|
if (icon != nil) {
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
NSString *iconPath = [NSString stringWithFormat:@"%@/Icon.png", bundle.bundlePath];
|
|
|
|
icon = [UIImage imageWithContentsOfFile:iconPath];
|
|
|
|
if (icon != nil) {
|
|
|
|
bundleIcons[bundle.bundlePath] = icon;
|
|
|
|
}
|
|
|
|
return icon;
|
|
|
|
}
|
|
|
|
|
2020-06-23 16:32:07 +00:00
|
|
|
- (UITableViewCell*)aboutCellForTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath {
|
|
|
|
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"about" forIndexPath:indexPath];
|
|
|
|
NSDictionary<NSString*,NSString*> *item = aboutItems[indexPath.row];
|
|
|
|
cell.textLabel.text = item[@"text"];
|
|
|
|
NSString *detailText = item[@"detailText"];
|
|
|
|
if ([detailText isEqualToString:@"$version"]) {
|
|
|
|
NSString *versionString = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
|
|
|
|
NSString *commitString = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"GitVersion"];
|
|
|
|
cell.detailTextLabel.text = commitString.length > 0 ? [NSString stringWithFormat:@"%@ (%@)", versionString, commitString] : versionString;
|
|
|
|
} else {
|
|
|
|
cell.detailTextLabel.text = detailText;
|
|
|
|
}
|
|
|
|
cell.accessoryType = item[@"link"] == nil ? UITableViewCellAccessoryNone : UITableViewCellAccessoryDisclosureIndicator;
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2020-09-24 22:29:30 +00:00
|
|
|
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
if (indexPath.section == SettingsSectionMachine && [AppDelegate sharedEmulator].anyDiskInserted) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
return indexPath;
|
|
|
|
}
|
|
|
|
|
2016-05-14 11:06:42 +00:00
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
|
|
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
|
2016-05-22 15:09:33 +00:00
|
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
2016-05-28 20:20:55 +00:00
|
|
|
if (indexPath.section == SettingsSectionKeyboard) {
|
2016-05-22 15:09:33 +00:00
|
|
|
// selected keyboard layout
|
2016-05-14 11:06:42 +00:00
|
|
|
NSString *layout = keyboardLayouts[indexPath.row];
|
|
|
|
[defaults setValue:layout.lastPathComponent forKey:@"keyboardLayout"];
|
2016-05-22 15:09:33 +00:00
|
|
|
[tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationAutomatic];
|
2016-05-28 20:20:55 +00:00
|
|
|
} else if (indexPath.section == SettingsSectionMachine) {
|
|
|
|
// selected emulated machine
|
2016-06-28 21:07:52 +00:00
|
|
|
NSBundle *bundle = machineList[indexPath.row];
|
|
|
|
if (bundle == selectedEmulatorBundle || ![bundle isKindOfClass:[NSBundle class]]) {
|
|
|
|
return;
|
|
|
|
}
|
2016-05-28 20:20:55 +00:00
|
|
|
NSString *bundleName = bundle.bundlePath.lastPathComponent.stringByDeletingPathExtension;
|
|
|
|
[defaults setValue:bundleName forKey:@"machine"];
|
2016-06-28 21:07:52 +00:00
|
|
|
NSUInteger lastSelectedIndex = [machineList indexOfObject:selectedEmulatorBundle];
|
|
|
|
if (lastSelectedIndex != NSNotFound) {
|
|
|
|
[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:lastSelectedIndex inSection:SettingsSectionMachine]].accessoryType = UITableViewCellAccessoryNone;
|
|
|
|
}
|
|
|
|
UITableViewCell *currentCell = [tableView cellForRowAtIndexPath:indexPath];
|
|
|
|
currentCell.accessoryType = UITableViewCellAccessoryCheckmark;
|
2016-06-06 14:09:23 +00:00
|
|
|
selectedEmulatorBundle = bundle;
|
|
|
|
[tableView reloadSections:[NSIndexSet indexSetWithIndex:SettingsSectionSpeed] withRowAnimation:UITableViewRowAnimationAutomatic];
|
2016-05-28 20:20:55 +00:00
|
|
|
} else if (indexPath.section == SettingsSectionAbout) {
|
2020-06-23 16:32:07 +00:00
|
|
|
if (indexPath.row >= aboutItems.count) {
|
|
|
|
// show gesture help
|
|
|
|
[self dismissViewControllerAnimated:YES completion:^{
|
|
|
|
[[AppDelegate sharedInstance] showGestureHelp:self];
|
|
|
|
}];
|
|
|
|
} else {
|
|
|
|
// links in about
|
|
|
|
NSString *linkURL = aboutItems[indexPath.row][@"link"];
|
|
|
|
if (linkURL != nil) {
|
2024-02-09 15:06:37 +00:00
|
|
|
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:linkURL] options:@{} completionHandler:nil];
|
2020-06-23 16:32:07 +00:00
|
|
|
}
|
2016-05-22 15:09:33 +00:00
|
|
|
}
|
2016-05-14 11:06:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-06 14:09:23 +00:00
|
|
|
- (UITableViewCell*)switchCellForTableView:(UITableView*)tableView indexPath:(NSIndexPath*)indexPath action:(SEL)action on:(BOOL)on {
|
|
|
|
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"toggle" forIndexPath:indexPath];
|
|
|
|
UISwitch *cellSwitch = (UISwitch*)cell.accessoryView;
|
|
|
|
if (cellSwitch == nil) {
|
|
|
|
cellSwitch = [UISwitch new];
|
|
|
|
cell.accessoryView = cellSwitch;
|
|
|
|
} else {
|
|
|
|
[cellSwitch removeTarget:nil action:nil forControlEvents:UIControlEventAllEvents];
|
|
|
|
}
|
|
|
|
cellSwitch.on = on;
|
|
|
|
[cellSwitch addTarget:self action:action forControlEvents:UIControlEventValueChanged];
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2016-05-11 21:04:49 +00:00
|
|
|
@end
|