FreeRDP
PerformanceEditorController.m
1 /*
2  controller for performance settings selection
3 
4  Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
5 
6  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7  If a copy of the MPL was not distributed with this file, You can obtain one at
8  http://mozilla.org/MPL/2.0/.
9  */
10 
11 #import "PerformanceEditorController.h"
12 #import "ConnectionParams.h"
13 #import "Utils.h"
14 
15 @interface PerformanceEditorController (Private)
16 - (NSString *)keyPathForKey:(NSString *)key;
17 @end
18 
19 @implementation PerformanceEditorController
20 
21 - (id)initWithConnectionParams:(ConnectionParams *)params
22 {
23  return [self initWithConnectionParams:params keyPath:nil];
24 }
25 
26 - (id)initWithConnectionParams:(ConnectionParams *)params keyPath:(NSString *)keyPath;
27 {
28  self = [super initWithStyle:UITableViewStyleGrouped];
29 
30  if (self)
31  {
32  _params = [params retain];
33  _keyPath = (keyPath != nil ? [keyPath retain] : nil);
34  }
35 
36  return self;
37 }
38 
39 - (void)viewDidLoad
40 {
41  [super viewDidLoad];
42  // Do any additional setup after loading the view.
43 }
44 
45 - (void)viewDidUnload
46 {
47  [super viewDidUnload];
48  // Release any retained subviews of the main view.
49 }
50 
51 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
52 {
53  return YES;
54 }
55 
56 - (NSString *)keyPathForKey:(NSString *)key
57 {
58  if (_keyPath)
59  return [_keyPath stringByAppendingFormat:@".%@", key];
60 
61  return key;
62 }
63 
64 - (void)dealloc
65 {
66  [super dealloc];
67  [_params release];
68 }
69 
70 #pragma mark -
71 #pragma mark Table view data source
72 
73 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
74 {
75  // Return the number of sections.
76  return 1;
77 }
78 
79 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
80 {
81  return 7;
82 }
83 
84 // set section headers
85 - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
86 {
87  return NSLocalizedString(@"Performance Settings",
88  @"'Performance Settings': performance settings header");
89 }
90 
91 // Customize the appearance of table view cells.
92 - (UITableViewCell *)tableView:(UITableView *)tableView
93  cellForRowAtIndexPath:(NSIndexPath *)indexPath
94 {
95  // get the table view cell
96  EditFlagTableViewCell *cell =
97  (EditFlagTableViewCell *)[self tableViewCellFromIdentifier:TableCellIdentifierYesNo];
98  NSAssert(cell, @"Invalid cell");
99 
100  switch ([indexPath row])
101  {
102  case 0:
103  {
104  [[cell label] setText:NSLocalizedString(@"RemoteFX", @"RemoteFX performance setting")];
105  [[cell toggle] setOn:[_params boolForKeyPath:[self keyPathForKey:@"perf_remotefx"]]];
106  break;
107  }
108 
109  case 1:
110  {
111  [[cell label] setText:NSLocalizedString(@"GFX", @"GFX performance setting")];
112  [[cell toggle] setOn:[_params boolForKeyPath:[self keyPathForKey:@"perf_gfx"]]];
113  break;
114  }
115 
116  case 2:
117  {
118  [[cell label] setText:NSLocalizedString(@"H264", @"H264 performance setting")];
119  [[cell toggle] setOn:[_params boolForKeyPath:[self keyPathForKey:@"perf_h264"]]];
120  break;
121  }
122 
123  case 3:
124  {
125  [[cell label] setText:NSLocalizedString(@"Desktop Background",
126  @"Desktop background performance setting")];
127  [[cell toggle]
128  setOn:[_params boolForKeyPath:[self keyPathForKey:@"perf_show_desktop"]]];
129  break;
130  }
131 
132  case 4:
133  {
134  [[cell label] setText:NSLocalizedString(@"Font Smoothing",
135  @"Font smoothing performance setting")];
136  [[cell toggle]
137  setOn:[_params boolForKeyPath:[self keyPathForKey:@"perf_font_smoothing"]]];
138  break;
139  }
140 
141  case 5:
142  {
143  [[cell label] setText:NSLocalizedString(@"Desktop Composition",
144  @"Desktop composition performance setting")];
145  [[cell toggle]
146  setOn:[_params boolForKeyPath:[self keyPathForKey:@"perf_desktop_composition"]]];
147  break;
148  }
149 
150  case 6:
151  {
152  [[cell label] setText:NSLocalizedString(@"Window contents while dragging",
153  @"Window Dragging performance setting")];
154  [[cell toggle]
155  setOn:[_params boolForKeyPath:[self keyPathForKey:@"perf_window_dragging"]]];
156  break;
157  }
158 
159  case 7:
160  {
161  [[cell label] setText:NSLocalizedString(@"Menu Animation",
162  @"Menu Animations performance setting")];
163  [[cell toggle]
164  setOn:[_params boolForKeyPath:[self keyPathForKey:@"perf_menu_animation"]]];
165  break;
166  }
167 
168  case 8:
169  {
170  [[cell label]
171  setText:NSLocalizedString(@"Visual Styles", @"Use Themes performance setting")];
172  [[cell toggle]
173  setOn:[_params boolForKeyPath:[self keyPathForKey:@"perf_windows_themes"]]];
174  break;
175  }
176 
177  default:
178  break;
179  }
180 
181  [[cell toggle] setTag:GET_TAG_FROM_PATH(indexPath)];
182  [[cell toggle] addTarget:self
183  action:@selector(togglePerformanceSetting:)
184  forControlEvents:UIControlEventValueChanged];
185  return cell;
186 }
187 
188 #pragma mark -
189 #pragma mark Action Handlers
190 
191 - (void)togglePerformanceSetting:(id)sender
192 {
193  UISwitch *valueSwitch = (UISwitch *)sender;
194 
195  switch (valueSwitch.tag)
196  {
197  case GET_TAG(0, 0):
198  [_params setBool:[valueSwitch isOn] forKeyPath:[self keyPathForKey:@"perf_remotefx"]];
199  break;
200 
201  case GET_TAG(0, 1):
202  [_params setBool:[valueSwitch isOn] forKeyPath:[self keyPathForKey:@"perf_gfx"]];
203  break;
204 
205  case GET_TAG(0, 2):
206  [_params setBool:[valueSwitch isOn] forKeyPath:[self keyPathForKey:@"perf_h264"]];
207  break;
208 
209  case GET_TAG(0, 3):
210  [_params setBool:[valueSwitch isOn]
211  forKeyPath:[self keyPathForKey:@"perf_show_desktop"]];
212  break;
213 
214  case GET_TAG(0, 4):
215  [_params setBool:[valueSwitch isOn]
216  forKeyPath:[self keyPathForKey:@"perf_font_smoothing"]];
217  break;
218 
219  case GET_TAG(0, 5):
220  [_params setBool:[valueSwitch isOn]
221  forKeyPath:[self keyPathForKey:@"perf_desktop_composition"]];
222  break;
223 
224  case GET_TAG(0, 6):
225  [_params setBool:[valueSwitch isOn]
226  forKeyPath:[self keyPathForKey:@"perf_window_dragging"]];
227  break;
228 
229  case GET_TAG(0, 7):
230  [_params setBool:[valueSwitch isOn]
231  forKeyPath:[self keyPathForKey:@"perf_menu_animation"]];
232  break;
233 
234  case GET_TAG(0, 8):
235  [_params setBool:[valueSwitch isOn]
236  forKeyPath:[self keyPathForKey:@"perf_windows_themes"]];
237  break;
238 
239  default:
240  break;
241  }
242 }
243 
244 @end