VMConfigNewStorageViewController.m 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. //
  2. // Copyright © 2019 osy. All rights reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. #import "VMConfigDriveDetailViewController.h"
  17. @interface VMConfigDriveDetailViewController ()
  18. @end
  19. @implementation VMConfigDriveDetailViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. }
  23. - (void)refreshViewFromConfiguration {
  24. [super refreshViewFromConfiguration];
  25. UTMNewDrive *driveParams = [self.configuration driveNewParamsAtIndex:self.driveIndex];
  26. if (driveParams) {
  27. self.driveImageExisting = YES;
  28. self.nonexistingPathName.text = driveParams.name;
  29. self.nonexistingImageSize = driveParams.sizeMB;
  30. self.nonexistingImageExpandingSwitch.on = driveParams.isQcow2;
  31. } else {
  32. self.driveImageExisting = NO;
  33. self.existingPathLabel.text = [self.configuration driveImagePathForIndex:self.driveIndex];
  34. self.isCdromSwitch.on = [self.configuration driveIsCdromForIndex:self.driveIndex];
  35. self.driveInterfaceType = [self.configuration driveInterfaceTypeForIndex:self.driveIndex];
  36. }
  37. }
  38. #pragma mark - Properties
  39. - (void)setDriveLocationPickerActive:(BOOL)driveLocationPickerActive {
  40. _driveLocationPickerActive = driveLocationPickerActive;
  41. [self pickerCell:self.driveLocationPickerCell setActive:driveLocationPickerActive];
  42. }
  43. - (void)setDriveImageExisting:(BOOL)driveImageExisting {
  44. _driveImageExisting = driveImageExisting;
  45. if (driveImageExisting) {
  46. [self.configuration prepareNewDriveAtIndex:self.driveIndex];
  47. [self cells:self.nonexistingImageCells setHidden:YES];
  48. [self cells:self.existingImageCells setHidden:NO];
  49. [self reloadDataAnimated:self.doneLoadingConfiguration];
  50. [self.driveTypeExistingCell setAccessoryType:UITableViewCellAccessoryCheckmark];
  51. [self.driveTypeNewCell setAccessoryType:UITableViewCellAccessoryNone];
  52. } else {
  53. [self.configuration discardNewDriveAtIndex:self.driveIndex];
  54. [self cells:self.existingImageCells setHidden:YES];
  55. [self cells:self.nonexistingImageCells setHidden:NO];
  56. [self reloadDataAnimated:self.doneLoadingConfiguration];
  57. [self.driveTypeExistingCell setAccessoryType:UITableViewCellAccessoryNone];
  58. [self.driveTypeNewCell setAccessoryType:UITableViewCellAccessoryCheckmark];
  59. }
  60. }
  61. - (void)setDriveInterfaceType:(NSString *)driveInterfaceType {
  62. _driveInterfaceType = driveInterfaceType;
  63. [self.configuration setDriveInterfaceType:driveInterfaceType forIndex:self.driveIndex];
  64. self.driveLocationLabel.text = driveInterfaceType;
  65. }
  66. - (NSNumber *)nonexistingImageSize {
  67. return [NSNumber numberWithLong:[self.nonexistingImageSizeField.text intValue]];
  68. }
  69. - (void)setNonexistingImageSize:(NSNumber *)nonexistingImageSize {
  70. self.nonexistingImageSizeField.text = [nonexistingImageSize stringValue];
  71. }
  72. #pragma mark - Table delegate
  73. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  74. if ([tableView cellForRowAtIndexPath:indexPath] == self.driveLocationCell) {
  75. self.driveLocationPickerActive = !self.driveLocationPickerActive;
  76. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  77. }
  78. if ([tableView cellForRowAtIndexPath:indexPath] == self.driveTypeExistingCell) {
  79. self.driveImageExisting = YES;
  80. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  81. }
  82. if ([tableView cellForRowAtIndexPath:indexPath] == self.driveTypeNewCell) {
  83. self.driveImageExisting = NO;
  84. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  85. }
  86. }
  87. #pragma mark - Picker delegate
  88. - (NSInteger)numberOfComponentsInPickerView:(nonnull UIPickerView *)pickerView {
  89. if (pickerView == self.driveLocationPicker) {
  90. return 1;
  91. }
  92. return 0;
  93. }
  94. - (NSInteger)pickerView:(nonnull UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
  95. if (component == 0) {
  96. if (pickerView == self.driveLocationPicker) {
  97. return [UTMConfiguration supportedDriveInterfaces].count;
  98. }
  99. }
  100. return 0;
  101. }
  102. - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
  103. if (component == 0) {
  104. if (pickerView == self.driveLocationPicker) {
  105. return [UTMConfiguration supportedDriveInterfaces][row];
  106. }
  107. }
  108. return nil;
  109. }
  110. - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
  111. if (component == 0) {
  112. if (pickerView == self.driveLocationPicker) {
  113. self.driveInterfaceType = [UTMConfiguration supportedDriveInterfaces][row];
  114. }
  115. }
  116. }
  117. #pragma mark - Event handlers
  118. - (IBAction)nonexistingImageExpandingSwitchChanged:(UISwitch *)sender {
  119. [self.configuration driveNewParamsAtIndex:self.driveIndex].isQcow2 = sender.on;
  120. }
  121. - (IBAction)existingImageMakeCopySwitchChanged:(UISwitch *)sender {
  122. // TODO: implement me
  123. }
  124. - (IBAction)nonexistingPathNameChanged:(UITextField *)sender {
  125. [self.configuration driveNewParamsAtIndex:self.driveIndex].name = sender.text;
  126. }
  127. - (IBAction)nonexistingImageSizeChanged:(UITextField *)sender {
  128. [self.configuration driveNewParamsAtIndex:self.driveIndex].sizeMB = self.nonexistingImageSize;
  129. }
  130. - (IBAction)isCdromSwitchChanged:(UISwitch *)sender {
  131. [self.configuration setDriveIsCdrom:sender.on forIndex:self.driveIndex];
  132. }
  133. @end