RSS

(root)/iphone/tappity : 53 : tappity/source/TappityAppDelegate.m

To get this branch, use:
bzr branch /browse/iphone/tappity

« back to all changes in this revision

Viewing changes to tappity/source/TappityAppDelegate.m

Dömötör Gulyás
2009-11-06 16:51:25
Revision ID: dognotdog@gmail.com-20091106155125-ui432mcq9jgp6332
improvements on socket messenger and tappity

Show diffs side-by-side

added added

removed removed

12
12
#import "TappityClient.h"
13
13
#import "TappityView.h"
14
14
 
 
15
static void catch_pipe(int sig_num)
 
16
{
 
17
    signal(SIGPIPE, catch_pipe);
 
18
}
 
19
 
 
20
 
 
21
 
15
22
@implementation TappityAppDelegate
16
23
 
17
24
@synthesize window, settingsView, touchSwitch, compassSwitch, locationSwitch, accelerationSwitch, feedbackSwitch;
18
25
 
19
26
 
 
27
- (void) connectionWasTerminated: (SocketMessenger*) theMessenger
 
28
{
 
29
        NSLog(@"connection dead, showing selection screen again");
 
30
        [tapView removeFromSuperview];
 
31
        [self.window addSubview: [browser view]];
 
32
}
 
33
 
 
34
- (void) setImage: (UIImage*) img
 
35
{
 
36
        [tapView setImage: img];
 
37
}
20
38
- (void)applicationDidFinishLaunching:(UIApplication *)application
21
39
{    
22
 
    
 
40
        signal(SIGPIPE, catch_pipe);
 
41
   
23
42
        tapClient = [[TappityClient alloc] init];
 
43
        [tapClient setDelegate: self];
24
44
 
25
45
        browser = [[BonjourBrowser alloc] initForType: @"_tappity._tcp"
26
46
                                                                                 inDomain: @"local"
28
48
                                                 showDisclosureIndicators: NO
29
49
                                                                 showCancelButton: YES];
30
50
 
31
 
        browser.delegate = self;
 
51
        [browser setDelegate: self];
32
52
    
33
53
    // We want to let the user know that the services list is dynamic and always updating, even when there are no
34
54
    // services currently found.
35
 
        browser.searchingForServicesString = NSLocalizedString(@"Searching for web services", @"Searching for web services string");
 
55
        browser.searchingForServicesString = NSLocalizedString(@"Searching for services", @"Searching for services string");
36
56
 
37
57
        [self.window addSubview: settingsView];
38
58
 
71
91
                tapView = [[TappityView alloc] initWithFrame: [theBrowser view].frame];
72
92
                
73
93
        tapView.tapClient = tapClient;
74
 
        tapClient.delegate = tapView;
75
94
                
76
95
        [[theBrowser view] removeFromSuperview];
77
96
        
81
100
 
82
101
        
83
102
        return;
84
 
 
85
 
        // Construct the URL including the port number
86
 
        // Also use the path, username and password fields that can be in the TXT record
87
 
        NSDictionary* dict = [[NSNetService dictionaryFromTXTRecordData:[service TXTRecordData]] retain];
88
 
        NSString *host = [service hostName];
89
 
        
90
 
        NSString* user = [[self copyStringFromTXTDict:dict which:@"u"] retain];
91
 
        NSString* pass = [[self copyStringFromTXTDict:dict which:@"p"] retain];
92
 
        
93
 
        NSString* portStr = [[NSString alloc] initWithString:@""];
94
 
        
95
 
        // Note that [NSNetService port:] returns an NSInteger in host byte order
96
 
        NSInteger port = [service port];
97
 
        if (port != 0 && port != 80)
98
 
                        portStr = [[NSString alloc] initWithFormat:@":%d",port];
99
 
        
100
 
        NSString* path = [[[self copyStringFromTXTDict:dict which:@"path"] retain] autorelease];
101
 
        if (!path || [path length]==0) {
102
 
                        path = [[[NSString alloc] initWithString:@"/"] autorelease];
103
 
        } else if (![[path substringToIndex:1] isEqual:@"/"]) {
104
 
                        path = [[[NSString alloc] initWithFormat:@"/%@",path] autorelease];
105
 
        }
106
 
        
107
 
        NSString* string = [[NSString alloc] initWithFormat:@"http://%@%@%@%@%@%@%@",
108
 
                                                                                                user?user:@"",
109
 
                                                                                                pass?@":":@"",
110
 
                                                                                                pass?pass:@"",
111
 
                                                                                                (user||pass)?@"@":@"",
112
 
                                                                                                host,
113
 
                                                                                                portStr,
114
 
                                                                                                path];
115
 
        
116
 
        NSURL *url = [[NSURL alloc] initWithString:string];
117
 
        [[UIApplication sharedApplication] openURL:url];
118
 
        
119
 
        [url release];
120
 
        [string release];
121
 
        [portStr release];
122
 
        [pass release];
123
 
        [user release];
124
 
        [dict release];
125
103
}
126
104
 
127
105
- (void)dealloc

Loggerhead 1.17 is a web-based interface for Bazaar branches