-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPreferencesView.m
More file actions
executable file
·220 lines (186 loc) · 7.11 KB
/
PreferencesView.m
File metadata and controls
executable file
·220 lines (186 loc) · 7.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*******************************************************************************
* iPhone Project : iMPDclient *
* Copyright (C) 2008 Boris Nagels <joogels@gmail.com> *
*******************************************************************************
* $LastChangedDate:: 2008-01-29 22:02:23 +0100 (Tue, 29 Jan 2008) $ *
* $LastChangedBy:: boris $ *
* $LastChangedRevision:: 140 $ *
* $Id:: application.m 140 2008-01-29 21:02:23Z boris $ *
*******************************************************************************
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*******************************************************************************/
#import <CoreFoundation/CoreFoundation.h>
#import <Foundation/Foundation.h>
#import <UIKit/CDStructures.h>
#import <UIKit/UISliderControl.h>
#import "PreferencesView.h"
#import "impdclientApp.h"
//////////////////////////////////////////////////////////////////////////
// PreferencesView: implementation.
//////////////////////////////////////////////////////////////////////////
@implementation PreferencesView
- (void)dealloc
{
// Release all objects.
[_hostnameCell release];
[_portCell release];
[_volumeCell release];
[_volumeSlider release];
[_table release];
[_navBar release];
// Call the base class.
[super dealloc];
}
- (void)initialize:(MPDClientApplication *)app mpd:(MpdObj *)mpdServer
{
_app = app;
_mpdServer = mpdServer;
// Set the values to the correct ones.
int volume = mpd_status_get_volume(_mpdServer);
[_volumeSlider setValue: volume];
}
-(id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
_navBar = [[UINavigationBar alloc] initWithFrame: CGRectMake(0, 0, 320, NAVBARHEIGHT)];
[_navBar setDelegate:self];
[_navBar setBarStyle: 1]; // Dark style.
[_navBar enableAnimation];
[_navBar showLeftButton:@"Hide" withStyle:0 rightButton:@"About" withStyle:0];
[_navBar pushNavigationItem: [[UINavigationItem alloc] initWithTitle: @"Preferences"]];
[self addSubview:_navBar];
_table = [[UIPreferencesTable alloc] initWithFrame:CGRectMake(0, NAVBARHEIGHT, 320, MAXHEIGHT)];
[_table setDataSource:self];
[_table setDelegate:self];
[_table reloadData];
[self addSubview:_table];
// Get the hostname and port number.
NSUserDefaults* pDefaults = [NSUserDefaults standardUserDefaults];
NSString* hostname = [pDefaults stringForKey:@"hostname"];
int port = [pDefaults integerForKey:@"port"];
_hostnameCell = [[UIPreferencesTextTableCell alloc] initWithFrame:CGRectMake(0.0f, 48.0f, frame.size.width, 48.0f)];
[_hostnameCell setTitle:@"Hostname:"];
[[[_hostnameCell textField] textTraits] setAutoCapsType:0];
[_hostnameCell setValue:hostname];
_portCell = [[UIPreferencesTextTableCell alloc] initWithFrame:CGRectMake(0.0f, 48.0f, frame.size.width, 48.0f)];
[_portCell setTitle:@"Port:"];
[[[_portCell textField] textTraits] setAutoCapsType:0];
[[[_portCell textField] textTraits] setPreferredKeyboardType:2]; // numbers only.
[_portCell setValue:[NSString stringWithFormat: @"%i", port]];
_volumeCell = [[UIPreferencesTableCell alloc] init];
[_volumeCell setTitle:@"Volume"];
[_volumeCell setShowSelection:NO];
_volumeSlider = [[UISliderControl alloc] initWithFrame:CGRectMake(90, 12, 210, 24)];
[_volumeSlider setMinValue:0.0];
[_volumeSlider setMaxValue:100.0];
[_volumeSlider setShowValue:YES];
[_volumeSlider addTarget:self action:@selector(changeVolume) forEvents:1|4]; // mouseDown | mouseDragged
[_volumeCell addSubview:_volumeSlider];
return self;
}
- (void)changeVolume
{
int volume = [_volumeSlider value];
mpd_status_set_volume(_mpdServer, volume);
// NSLog(@"Change volume %d", volume);
}
- (void)saveSettings
{
NSUserDefaults* pDefaults = [NSUserDefaults standardUserDefaults];
[pDefaults setObject:[_hostnameCell value] forKey:@"hostname"];
[pDefaults setInteger:[[_portCell value] intValue] forKey:@"port"];
}
- (void)displayAbout
{
UIAlertSheet * hotSheet = [[UIAlertSheet alloc]
initWithTitle:@"iMPDclient v1.0"
buttons:[NSArray arrayWithObject:NSLocalizedString(@"OK", nil)]
defaultButtonIndex:0
delegate:self
context:self];
[hotSheet setBodyText:@"iPod remote for your MPD server. Copyright 2008, Boris Nagels"];
[hotSheet setDimsBackground:YES];
[hotSheet setRunsModal:YES];
[hotSheet setShowsOverSpringBoardAlerts:NO];
[hotSheet popupAlertAnimated:YES];
}
//////////////////////////////////////////////////////////////////////////
// Datasource Methods
//////////////////////////////////////////////////////////////////////////
- (int)numberOfGroupsInPreferencesTable:(UIPreferencesTable *)table
{
return 2;
}
- (float)preferencesTable:(id)table heightForRow:(int)row inGroup:(int)group withProposedHeight:(float)proposedHeight;
{
return 48.0f;
}
- (int)preferencesTable:(UIPreferencesTable *)table numberOfRowsInGroup:(int)group
{
if (group == 0)
return 2;
if (group == 1)
return 1;
return 0;
}
- (id)preferencesTable:(id)preferencesTable titleForGroup:(int)group
{
NSString *title = nil;
switch (group) {
case 0:
title = @"Server information:";
break;
case 1:
title = @"Server settings:";
break;
}
return title;
}
- (UIPreferencesTableCell *)preferencesTable:(UIPreferencesTable *)table cellForRow:(int)row inGroup:(int)group
{
if (group == 0) {
switch (row) {
case 0: return _hostnameCell; break;
case 1: return _portCell; break;
}
}
if (group == 1) {
switch (row) {
case 0: return _volumeCell; break;
}
}
return nil;
}
//////////////////////////////////////////////////////////////////////////
// Navigation Methods
//////////////////////////////////////////////////////////////////////////
- (void)navigationBar:(UINavigationBar*)navbar buttonClicked:(int)button
{
NSLog(@"PreferencesView: button %d", button);
if (button == 1) {
[_app showPlaylistViewWithTransition:5];
// Save the settings.
[self saveSettings];
} else {
// Show the about dialog.
[self displayAbout];
}
}
- (void)alertSheet:(id)sheet buttonClicked:(int)buttonIndex
{
// Just close and release all sheets.
[sheet dismissAnimated:YES];
[sheet release];
}
@end