RSS

(root)/iphone/tappity : /tappity/source/BonjourSupport/BonjourBrowser.m (revision 46)

To get this branch, use:
bzr branch /browse/iphone/tappity
Line Revision Contents
1 46
/*
2
     File: BonjourBrowser.m
3
 Abstract:  A subclass of UINavigationController that handles the UI needed for a user to
4
browse for Bonjour services.
5
 It contains list view controllers for domains and service instances.
6
 It allows the user to add their own domains.
7
8
  Version: 2.8
9
 
10
 Disclaimer: IMPORTANT:  This Apple software is supplied to you by Apple
11
 Inc. ("Apple") in consideration of your agreement to the following
12
 terms, and your use, installation, modification or redistribution of
13
 this Apple software constitutes acceptance of these terms.  If you do
14
 not agree with these terms, please do not use, install, modify or
15
 redistribute this Apple software.
16
 
17
 In consideration of your agreement to abide by the following terms, and
18
 subject to these terms, Apple grants you a personal, non-exclusive
19
 license, under Apple's copyrights in this original Apple software (the
20
 "Apple Software"), to use, reproduce, modify and redistribute the Apple
21
 Software, with or without modifications, in source and/or binary forms;
22
 provided that if you redistribute the Apple Software in its entirety and
23
 without modifications, you must retain this notice and the following
24
 text and disclaimers in all such redistributions of the Apple Software.
25
 Neither the name, trademarks, service marks or logos of Apple Inc. may
26
 be used to endorse or promote products derived from the Apple Software
27
 without specific prior written permission from Apple.  Except as
28
 expressly stated in this notice, no other rights or licenses, express or
29
 implied, are granted by Apple herein, including but not limited to any
30
 patent rights that may be infringed by your derivative works or by other
31
 works in which the Apple Software may be incorporated.
32
 
33
 The Apple Software is provided by Apple on an "AS IS" basis.  APPLE
34
 MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
35
 THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS
36
 FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND
37
 OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
38
 
39
 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL
40
 OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
41
 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
42
 INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION,
43
 MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
44
 AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE),
45
 STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE
46
 POSSIBILITY OF SUCH DAMAGE.
47
 
48
 Copyright (C) 2009 Apple Inc. All Rights Reserved.
49
 
50
 */
51
52
#import "BonjourBrowser.h"
53
#import "BrowserViewController.h"
54
#import "DomainViewController.h"
55
56
57
@interface BonjourBrowser ()
58
@property(nonatomic, retain, readwrite) BrowserViewController* bvc;
59
@property(nonatomic, retain, readwrite) DomainViewController* dvc;
60
@property(nonatomic, retain, readwrite) NSString* type;
61
@property(nonatomic, retain, readwrite) NSString* domain;
62
@property(nonatomic, assign, readwrite) BOOL showDisclosureIndicators;
63
@property(nonatomic, assign, readwrite) BOOL showCancelButton;
64
- (void) setupBrowser;
65
@end
66
67
68
@implementation BonjourBrowser
69
70
71
@synthesize bvc = _bvc;
72
@synthesize dvc = _dvc;
73
@synthesize type = _type;
74
@synthesize domain = _domain;
75
@synthesize showDisclosureIndicators = _showDisclosureIndicators;
76
@synthesize showCancelButton = _showCancelButton;
77
78
79
- (id) initForType:(NSString*)type inDomain:(NSString*)domain
80
	   customDomains:(NSMutableArray*)customDomains
81
	   showDisclosureIndicators:(BOOL)showDisclosureIndicators
82
	   showCancelButton:(BOOL)showCancelButton {
83
	
84
    // Create some strings that will be used in the DomainViewController.
85
	NSString *domainsTitle = NSLocalizedString(@"Domains", @"Domains title");
86
	NSString *domainLabel = NSLocalizedString(@"Added Domains", @"Added Domains label");
87
	NSString *addDomainTitle = NSLocalizedString(@"Add Domain", @"Add Domain title");
88
	NSString *searchingForServicesString = NSLocalizedString(@"Searching for services", @"Searching for services string");
89
    
90
    // Initialize the DomainViewController, which uses a NSNetServiceBrowser to look for Bonjour domains.
91
	DomainViewController* dvc = [[DomainViewController alloc] initWithTitle:domainsTitle showDisclosureIndicators:YES customsTitle:domainLabel customs:customDomains addDomainTitle:addDomainTitle showCancelButton:showCancelButton];
92
	
93
	if (dvc && (self = [super initWithRootViewController:dvc])) {
94
		self.type = type;
95
		self.showDisclosureIndicators = showDisclosureIndicators;
96
		self.showCancelButton = showCancelButton;
97
		self.searchingForServicesString	= searchingForServicesString;
98
		self.dvc = dvc;
99
		[self.dvc setDelegate:self];
100
		[self.dvc searchForBrowsableDomains]; // Tells the DomainViewController's NSNetServiceBrowser to start a search for domains that are browsable via Bonjour and the computer's network configuration.
101
102
		if ([domain length]) {
103
			self.domain = domain;
104
			[self setupBrowser]; // Initiate a search for Bonjour services of the type self.type.
105
			[self pushViewController:self.bvc animated:NO];
106
		}
107
	}
108
	
109
	[dvc release];
110
	
111
	return self;
112
}
113
114
- (NSString*) searchingForServicesString {
115
	return _searchingForServicesString;
116
}
117
118
// This property holds a string that displays the status of the service search to the user.
119
- (void) setSearchingForServicesString:(NSString*)searchingForServicesString {
120
	if (_searchingForServicesString != searchingForServicesString) {
121
		[_searchingForServicesString release];
122
		_searchingForServicesString = [searchingForServicesString copy];
123
124
		if (self.bvc) {
125
			self.bvc.searchingForServicesString = _searchingForServicesString;
126
		}
127
	}
128
}
129
130
- (void) setDelegate:(id<BonjourBrowserDelegate>)delegate {
131
	__delegate = delegate;
132
	super.delegate = delegate;
133
}
134
135
136
- (id<BonjourBrowserDelegate>) delegate {
137
	assert(__delegate == super.delegate);
138
	return __delegate;
139
}
140
141
142
- (BOOL) showTitleInNavigationBar {
143
	return _showTitleInNavigationBar;
144
}
145
146
147
- (void) setShowTitleInNavigationBar:(BOOL)show {
148
	_showTitleInNavigationBar = show;
149
	if (show) {
150
		self.bvc.navigationItem.prompt = self.title;
151
		self.dvc.navigationItem.prompt = self.title;
152
	} else {
153
		self.bvc.navigationItem.prompt = nil;
154
		self.dvc.navigationItem.prompt = nil;
155
	}
156
}
157
158
159
- (void) browserViewController:(BrowserViewController*)bvc didResolveInstance:(NSNetService*)service {
160
	assert(bvc == self.bvc);
161
	[self.delegate bonjourBrowser:self didResolveInstance:service];
162
}
163
164
// Create a BrowserViewController, which manages a NSNetServiceBrowser configured to look for Bonjour services.
165
- (void) setupBrowser {
166
	BrowserViewController* aBvc = [[BrowserViewController alloc] initWithTitle:self.domain showDisclosureIndicators:self.showDisclosureIndicators showCancelButton:self.showCancelButton];
167
    aBvc.searchingForServicesString = self.searchingForServicesString;
168
	aBvc.delegate = self;
169
    // Calls -[NSNetServiceBrowser searchForServicesOfType:inDomain:].
170
	[aBvc searchForServicesOfType:self.type inDomain:self.domain];
171
172
    // Store the BrowerViewController in an instance variable.
173
	self.bvc = aBvc;
174
	[aBvc release];
175
	if (self.showTitleInNavigationBar)
176
		self.bvc.navigationItem.prompt = self.title;
177
}
178
179
// This method will be invoked when the user selects one of the domains from the list.
180
// The domain parameter will be the selected domain or nil if the user taps the 'Cancel' button (if shown).
181
- (void) domainViewController:(DomainViewController*)dvc didSelectDomain:(NSString*)domain {
182
	if (!domain) {
183
		// Cancel
184
		[self.delegate bonjourBrowser:self didResolveInstance:nil];
185
		return;
186
	}
187
188
	self.domain = domain;
189
	[self setupBrowser];
190
	[self pushViewController:self.bvc animated:YES];
191
}
192
193
194
- (void) dealloc {
195
	[_dvc release];
196
	[_bvc release];
197
	[_type release];
198
	[_domain release];
199
	[_searchingForServicesString release];
200
	[super dealloc];
201
}
202
203
@end

Loggerhead 1.17 is a web-based interface for Bazaar branches