RSS

(root)/iphone/common : /source/BonjourSupport/BonjourBrowser.m (revision 100)

To get this branch, use:
bzr branch /browse/iphone/common
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
	
110
	return self;
111
}
112
113
- (NSString*) searchingForServicesString {
114
	return _searchingForServicesString;
115
}
116
117
// This property holds a string that displays the status of the service search to the user.
118
- (void) setSearchingForServicesString:(NSString*)searchingForServicesString {
119
	if (_searchingForServicesString != searchingForServicesString) {
120
		_searchingForServicesString = [searchingForServicesString copy];
121
122
		if (self.bvc) {
123
			self.bvc.searchingForServicesString = _searchingForServicesString;
124
		}
125
	}
126
}
127
128
- (void) setDelegate:(id<BonjourBrowserDelegate>)delegate {
129
	__delegate = delegate;
130
	super.delegate = delegate;
131
}
132
133
134
- (id<BonjourBrowserDelegate>) delegate {
135
	assert(__delegate == super.delegate);
136
	return __delegate;
137
}
138
139
140
- (BOOL) showTitleInNavigationBar {
141
	return _showTitleInNavigationBar;
142
}
143
144
145
- (void) setShowTitleInNavigationBar:(BOOL)show {
146
	_showTitleInNavigationBar = show;
147
	if (show) {
148
		self.bvc.navigationItem.prompt = self.title;
149
		self.dvc.navigationItem.prompt = self.title;
150
	} else {
151
		self.bvc.navigationItem.prompt = nil;
152
		self.dvc.navigationItem.prompt = nil;
153
	}
154
}
155
156
157
- (void) browserViewController:(BrowserViewController*)bvc didResolveInstance:(NSNetService*)service {
158
	assert(bvc == self.bvc);
159
	[self.delegate bonjourBrowser:self didResolveInstance:service];
160
}
161
162
// Create a BrowserViewController, which manages a NSNetServiceBrowser configured to look for Bonjour services.
163
- (void) setupBrowser {
164
	BrowserViewController* aBvc = [[BrowserViewController alloc] initWithTitle:self.domain showDisclosureIndicators:self.showDisclosureIndicators showCancelButton:self.showCancelButton];
165
    aBvc.searchingForServicesString = self.searchingForServicesString;
166
	aBvc.delegate = self;
167
    // Calls -[NSNetServiceBrowser searchForServicesOfType:inDomain:].
168
	[aBvc searchForServicesOfType:self.type inDomain:self.domain];
169
170
    // Store the BrowerViewController in an instance variable.
171
	self.bvc = aBvc;
172 94
173 46
	if (self.showTitleInNavigationBar)
174
		self.bvc.navigationItem.prompt = self.title;
175
}
176
177
// This method will be invoked when the user selects one of the domains from the list.
178
// The domain parameter will be the selected domain or nil if the user taps the 'Cancel' button (if shown).
179
- (void) domainViewController:(DomainViewController*)dvc didSelectDomain:(NSString*)domain {
180
	if (!domain) {
181
		// Cancel
182
		[self.delegate bonjourBrowser:self didResolveInstance:nil];
183
		return;
184
	}
185
186
	self.domain = domain;
187
	[self setupBrowser];
188
	[self pushViewController:self.bvc animated:YES];
189
}
190
191
192 94
- (void) dealloc
193
{
194 46
}
195
196
@end

Loggerhead 1.17 is a web-based interface for Bazaar branches