RSS

(root)/iphone/tappity : /source/TappityAppDelegate.m (revision 62)

To get this branch, use:
bzr branch /browse/iphone/tappity
Line Revision Contents
1 46
//
2
//  tappityAppDelegate.m
3
//  tappity
4
//
5
//  Created by döme on 25.10.2009.
6
//
7
8 54
/*
9
 * Copyright (c) 2009 Doemoetoer Gulyas.
10
 * All rights reserved.
11
 *
12
 * Redistribution and use in source and binary forms, with or without
13
 * modification, are permitted provided that the following conditions
14
 * are met:
15
 * 1. Redistributions of source code must retain the above copyright
16
 *    notice, this list of conditions and the following disclaimer.
17
 * 2. Redistributions in binary form must reproduce the above copyright
18
 *    notice, this list of conditions and the following disclaimer in the
19
 *    documentation and/or other materials provided with the distribution.
20
 * 3. The name of the author may not be used to endorse or promote products
21
 *    derived from this software without specific prior written permission.
22
 *
23
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
 */
34
35 46
#import "TappityAppDelegate.h"
36 48
37 46
#import "BonjourBrowser.h"
38
#import "TappityClient.h"
39
#import "TappityView.h"
40
41 53
static void catch_pipe(int sig_num)
42
{
43
    signal(SIGPIPE, catch_pipe);
44
}
45
46
47
48 46
@implementation TappityAppDelegate
49
50 49
@synthesize window, settingsView, touchSwitch, compassSwitch, locationSwitch, accelerationSwitch, feedbackSwitch;
51 46
52
53 53
- (void) connectionWasTerminated: (SocketMessenger*) theMessenger
54
{
55
	NSLog(@"connection dead, showing selection screen again");
56
	[tapView removeFromSuperview];
57
	[self.window addSubview: [browser view]];
58
}
59
60
- (void) setImage: (UIImage*) img
61
{
62
	[tapView setImage: img];
63
}
64 46
- (void)applicationDidFinishLaunching:(UIApplication *)application
65
{    
66 53
	signal(SIGPIPE, catch_pipe);
67
   
68 46
	tapClient = [[TappityClient alloc] init];
69 53
	[tapClient setDelegate: self];
70 46
71
	browser = [[BonjourBrowser alloc] initForType: @"_tappity._tcp"
72
										 inDomain: @"local"
73
									customDomains: nil // we won't save any additional domains added by the user
74
						 showDisclosureIndicators: NO
75
								 showCancelButton: YES];
76
77 53
	[browser setDelegate: self];
78 46
    
79
    // We want to let the user know that the services list is dynamic and always updating, even when there are no
80
    // services currently found.
81 53
	browser.searchingForServicesString = NSLocalizedString(@"Searching for services", @"Searching for services string");
82 46
83 49
	[self.window addSubview: settingsView];
84
85
    [window makeKeyAndVisible];
86
}
87
88
- (IBAction) letsGo: (id) sender
89
{
90
	[settingsView removeFromSuperview];
91
	
92
	[tapClient setEnableAccelerometer: [accelerationSwitch isOn]];
93
	[tapClient setEnableCompass: [compassSwitch isOn]];
94
	[tapClient setEnableLocation: [locationSwitch isOn]];
95
	[tapClient setEnableFeedbackVideoDisplay: [feedbackSwitch isOn]];
96
97 46
	[self.window addSubview: [browser view]];
98
}
99
100
101
- (NSString *)copyStringFromTXTDict:(NSDictionary *)dict which:(NSString*)which {
102
	// Helper for getting information from the TXT data
103
	NSData* data = [dict objectForKey:which];
104
	return data ? [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease] : nil;
105
}
106
107
- (void) bonjourBrowser:(BonjourBrowser*) theBrowser didResolveInstance:(NSNetService*)service
108
{
109
	NSLog(@"found bonjour server");
110
	
111
	if (service)
112
	{
113
		[tapClient connectToService: service];
114
	}
115
116
	if (!tapView)
117
		tapView = [[TappityView alloc] initWithFrame: [theBrowser view].frame];
118
		
119
	tapView.tapClient = tapClient;
120
		
121
	[[theBrowser view] removeFromSuperview];
122
	
123
	[self.window addSubview: tapView];
124
	
125
	[[UIApplication sharedApplication] _addRecorder: tapClient];
126
127
	
128
	return;
129
}
130
131
- (void)dealloc
132
{
133
	[browser release];
134
    [window release];
135 49
    [touchSwitch release];
136
    [accelerationSwitch release];
137
    [locationSwitch release];
138
    [compassSwitch release];
139
    [feedbackSwitch release];
140
    [settingsView release];
141 46
    [super dealloc];
142
}
143
144 52
- (void)applicationWillTerminate:(UIApplication *)application
145
{
146
	[tapClient terminateConnection];
147
}
148
149 46
150
@end
151 50
152
153

Loggerhead 1.17 is a web-based interface for Bazaar branches