@@ -35,18 +35,40 @@ - (void)viewWillAppear:(BOOL)animated {
35
35
36
36
- (void )refreshViewFromConfiguration {
37
37
[super refreshViewFromConfiguration ];
38
+ self.imageTypePickerActive = NO ;
38
39
self.driveLocationPickerActive = NO ;
39
40
if (self.valid ) {
40
41
self.existingPathLabel .text = [self .configuration driveImagePathForIndex: self .driveIndex];
41
- self.isCdromSwitch . on = [self .configuration driveIsCdromForIndex :self .driveIndex];
42
+ self.imageType = [self .configuration driveImageTypeForIndex :self .driveIndex];
42
43
self.driveInterfaceType = [self .configuration driveInterfaceTypeForIndex: self .driveIndex];
43
44
} else {
45
+ self.imageType = UTMDiskImageTypeDisk;
44
46
self.driveInterfaceType = [UTMConfiguration defaultDriveInterface ];
45
47
}
46
48
}
47
49
48
50
#pragma mark - Properties
49
51
52
+ - (void )setImageTypePickerActive : (BOOL )imageTypePickerActive {
53
+ _imageTypePickerActive = imageTypePickerActive;
54
+ [self pickerCell: self .imageTypePickerCell setActive: imageTypePickerActive];
55
+ }
56
+
57
+ - (void )setImageType : (UTMDiskImageType)imageType {
58
+ NSAssert (imageType < UTMDiskImageTypeMax, @" Invalid image type %lu " , imageType);
59
+ _imageType = imageType;
60
+ if (self.valid ) {
61
+ [self .configuration setDriveImageType: imageType forIndex: self .driveIndex];
62
+ }
63
+ self.imageTypeLabel .text = [UTMConfiguration supportedImageTypes ][imageType];
64
+ if (imageType == UTMDiskImageTypeDisk || imageType == UTMDiskImageTypeCD) {
65
+ [self pickerCell: self .driveLocationCell setActive: YES ];
66
+ } else {
67
+ [self pickerCell: self .driveLocationCell setActive: NO ];
68
+ self.driveLocationPickerActive = NO ;
69
+ }
70
+ }
71
+
50
72
- (void )setDriveLocationPickerActive : (BOOL )driveLocationPickerActive {
51
73
_driveLocationPickerActive = driveLocationPickerActive;
52
74
[self pickerCell: self .driveLocationPickerCell setActive: driveLocationPickerActive];
@@ -66,6 +88,9 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
66
88
if ([tableView cellForRowAtIndexPath: indexPath] == self.driveLocationCell ) {
67
89
self.driveLocationPickerActive = !self.driveLocationPickerActive ;
68
90
[tableView deselectRowAtIndexPath: indexPath animated: YES ];
91
+ } else if ([tableView cellForRowAtIndexPath: indexPath] == self.imageTypeCell ) {
92
+ self.imageTypePickerActive = !self.imageTypePickerActive ;
93
+ [tableView deselectRowAtIndexPath: indexPath animated: YES ];
69
94
}
70
95
}
71
96
@@ -74,6 +99,8 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
74
99
- (NSInteger )numberOfComponentsInPickerView : (nonnull UIPickerView *)pickerView {
75
100
if (pickerView == self.driveLocationPicker ) {
76
101
return 1 ;
102
+ } else if (pickerView == self.imageTypePicker ) {
103
+ return 1 ;
77
104
} else {
78
105
NSAssert (0 , @" Invalid picker" );
79
106
}
@@ -84,6 +111,8 @@ - (NSInteger)pickerView:(nonnull UIPickerView *)pickerView numberOfRowsInCompone
84
111
NSAssert (component == 0 , @" Invalid component" );
85
112
if (pickerView == self.driveLocationPicker ) {
86
113
return [UTMConfiguration supportedDriveInterfaces ].count ;
114
+ } else if (pickerView == self.imageTypePicker ) {
115
+ return [UTMConfiguration supportedImageTypes ].count ;
87
116
} else {
88
117
NSAssert (0 , @" Invalid picker" );
89
118
}
@@ -94,6 +123,8 @@ - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row f
94
123
NSAssert (component == 0 , @" Invalid component" );
95
124
if (pickerView == self.driveLocationPicker ) {
96
125
return [UTMConfiguration supportedDriveInterfaces ][row];
126
+ } else if (pickerView == self.imageTypePicker ) {
127
+ return [UTMConfiguration supportedImageTypesPretty ][row];
97
128
} else {
98
129
NSAssert (0 , @" Invalid picker" );
99
130
}
@@ -104,6 +135,8 @@ - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComp
104
135
NSAssert (component == 0 , @" Invalid component" );
105
136
if (pickerView == self.driveLocationPicker ) {
106
137
self.driveInterfaceType = [UTMConfiguration supportedDriveInterfaces ][row];
138
+ } else if (pickerView == self.imageTypePicker ) {
139
+ self.imageType = row;
107
140
} else {
108
141
NSAssert (0 , @" Invalid picker" );
109
142
}
@@ -125,19 +158,10 @@ - (IBAction)unwindToDriveDetailFromDrivePicker:(UIStoryboardSegue*)sender {
125
158
VMConfigDrivePickerViewController *source = (VMConfigDrivePickerViewController *)sender.sourceViewController ;
126
159
if (!self.valid ) {
127
160
self.valid = YES ;
128
- self.driveIndex = [self .configuration newDrive: source.selectedName interface :self .driveInterfaceType isCdrom :self .isCdromSwitch.on ];
161
+ self.driveIndex = [self .configuration newDrive: source.selectedName type :self .imageType interface :self .driveInterfaceType ];
129
162
} else {
130
163
[self .configuration setImagePath: source.selectedName forIndex: self .driveIndex];
131
164
}
132
165
}
133
166
134
- #pragma mark - Event handlers
135
-
136
- - (IBAction )isCdromSwitchChanged : (UISwitch *)sender {
137
- NSAssert (sender == self.isCdromSwitch, @" Invalid sender" );
138
- if (self.valid ) {
139
- [self .configuration setDriveIsCdrom: sender.on forIndex: self .driveIndex];
140
- }
141
- }
142
-
143
167
@end
0 commit comments