- #import "StreamDeskAppDelegate.h"
- #import "TFHpple.h"
- @implementation StreamDeskAppDelegate
- @synthesize window;
- - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
- {
- // Initialise arrays
- // Stream Data View
- streamEmbedName = [[NSMutableArray alloc] init];
- streamFriendlyName = [[NSMutableArray alloc] init];
- streamEmbedFormat = [[NSMutableArray alloc] init];
- // Chat Data View
- // Stream Data
- mediaType = [[NSMutableArray alloc] init];
- mediaName = [[NSMutableArray alloc] init];
- mediaWeb = [[NSMutableArray alloc] init];
- mediaSizeWidth = [[NSMutableArray alloc] init];
- mediaSizeHeight = [[NSMutableArray alloc] init];
- mediaEmbedType = [[NSMutableArray alloc] init];
- mediaEmbedID = [[NSMutableArray alloc] init];
- // Chat Data
- // Load streams from xml file
- [self loadStreams];
- }
- -(void)loadStreams
- {
- // Clean arrays before populating
- // Stream Data View
- [streamEmbedName removeAllObjects];
- [streamFriendlyName removeAllObjects];
- [streamEmbedFormat removeAllObjects];
- // Chat Data View
- // Stream Data
- [mediaType removeAllObjects];
- [mediaName removeAllObjects];
- [mediaWeb removeAllObjects];
- [mediaSizeWidth removeAllObjects];
- [mediaSizeHeight removeAllObjects];
- [mediaEmbedType removeAllObjects];
- [mediaEmbedID removeAllObjects];
- // Chat Data
- // Read xml and allocate into arrays
- NSError *error;
- NSString *urlData;
- NSURLResponse *response;
- NSURLRequest *request = [[NSMutableURLRequest alloc]
- initWithURL:[NSURL URLWithString:@"http://streamdesk.sourceforge.net/streams.sdx"]
- cachePolicy:NSURLRequestUseProtocolCachePolicy
- timeoutInterval:20]; // 20 second timeout?
- NSData* data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
- [request release];
- urlData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
- if(data != nil)
- {
- NSData *htmlData = [urlData dataUsingEncoding:NSUTF8StringEncoding];
- TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];
- [urlData release];
- // ALL THE PARSING IS INCORRECT BUT FUNCTIONS, NEED TO CHANGE TEH PARSING SO EACH OF THE ARRAYS IS IN SYNC!
- // Stream Data View
- NSArray *streamEmbedNameArray = [xpathParser search:@"//streamembed/name"];
- NSArray *streamFriendlyNameArray = [xpathParser search:@"//streamembed/friendlyname"];
- NSArray *streamEmbedFormatArray = [xpathParser search:@"//streamembed/embedformat"];
- // Stream Data
- NSArray *mediaTypeArray = [xpathParser search:@"//media/mediatype"];
- NSArray *mediaNameArray = [xpathParser search:@"//media/name"];
- //NSArray *mediaWebArray = [xpathParser search:@"//media/web"];
- NSArray *mediaSizeHeightArray = [xpathParser search:@"//media/size/height"];
- NSArray *mediaSizeWidthArray = [xpathParser search:@"//media/size/width"];
- NSArray *mediaEmbedTypeArray = [xpathParser search:@"//media/streamembed"];
- NSArray *mediaEmbedIDArray = [xpathParser search:@"//media/streamembeddata/embeddata/value"];
- [xpathParser release];
- // Stream Data View
- for(int i=0;i<[streamEmbedNameArray count];i++)
- {
- [streamEmbedName addObject:[[streamEmbedNameArray objectAtIndex:i] content]];
- [streamFriendlyName addObject:[[streamFriendlyNameArray objectAtIndex:i] content]];
- [streamEmbedFormat addObject:[[streamEmbedFormatArray objectAtIndex:i] content]];
- }
- // Stream Data
- for(int i=0;i<[mediaTypeArray count];i++)
- {
- [mediaName addObject:[[mediaNameArray objectAtIndex:i] content]];
- [mediaType addObject:[[mediaTypeArray objectAtIndex:i] content]];
- /*if([mediaWebArray objectAtIndex:i] != nil)
- {
- NSLog(@"%@",[mediaWebArray objectAtIndex:i]);
- [mediaWeb addObject:[[mediaWebArray objectAtIndex:i] content]];
- }*/
- [mediaSizeHeight addObject:[[mediaSizeHeightArray objectAtIndex:i] content]];
- [mediaSizeWidth addObject:[[mediaSizeWidthArray objectAtIndex:i] content]];
- [mediaEmbedType addObject:[[mediaEmbedTypeArray objectAtIndex:i] content]];
- [mediaEmbedID addObject:[[mediaEmbedIDArray objectAtIndex:i] content]];
- [streamButton addItemWithTitle:[mediaName objectAtIndex:i]];
- }
- }
- else
- {
- //
- }
- }
- -(IBAction)changeStream:(id)sender
- {
- int number = [streamButton indexOfItemWithTitle:[streamButton titleOfSelectedItem]];
- int position = [streamEmbedName indexOfObject:[mediaEmbedType objectAtIndex:number]];
- NSString *embedString = [[streamEmbedFormat objectAtIndex:position] stringByReplacingOccurrencesOfString:@"$ID$" withString:[mediaEmbedID objectAtIndex:number]];
- [window setTitle:[NSString stringWithFormat:@"StreamDesk - %@",[mediaName objectAtIndex:number]]];
- NSURL *base = [[NSURL alloc] initWithString:@"http://www.example.com/"];
- [[streamView mainFrame] loadHTMLString:embedString baseURL:base];
- [base release];
- }
- /*-(IBAction)changeStream:(id)sender
- {
- // Number associated with stream
- int number = [streamButton indexOfItemWithTitle:[streamButton titleOfSelectedItem]];
- if([[typeArray objectAtIndex:number] isEqualToString:@"ustream"])
- {
- int flashWidth = 685;
- int flashHeight = 461;
- NSString *flashString = [NSString stringWithFormat:@"<body bgcolor=\"black\"></body><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"%i\" height=\"%i\" id=\"utv871327\"><param name=\"flashvars\" value=\"autoplay=true&brand=embed&cid=%@&v3=1\"/><param name=\"allowfullscreen\" value=\"true\"/><param name=\"allowscriptaccess\" value=\"always\"/><param name=\"movie\" value=\"http://www.ustream.tv/flash/viewer.swf\"/><embed flashvars=\"autoplay=true&brand=embed&cid=%@&v3=1\" width=\"%i\" height=\"%i\" allowfullscreen=\"true\" allowscriptaccess=\"always\" id=\"utv871327\" name=\"utv_n_151012\" src=\"http://www.ustream.tv/flash/viewer.swf\" type=\"application/x-shockwave-flash\"/></object>",flashWidth,flashHeight,[urlArray objectAtIndex:number],[urlArray objectAtIndex:number],flashWidth, flashHeight];
- NSURL *base = [[NSURL alloc] initWithString:@"http://www.example.com/"];
- [[streamView mainFrame] loadHTMLString:flashString baseURL:base];
- [base release];
- // Set new title
- [window setTitle:[NSString stringWithFormat:@"StreamDesk - %@",[namesArray objectAtIndex:number]]];
- }
- if([[typeArray objectAtIndex:number] isEqualToString:@"justin"])
- {
- int flashWidth = 685;
- int flashHeight = 461;
- NSString *flashString = [NSString stringWithFormat:@"<object type=\"application/x-shockwave-flash\" height=\"%i\" width=\"%i\" id=\"live_embed_player_flash\" data=\"http://www.justin.tv/widgets/live_embed_player.swf?channel=%@\" bgcolor=\"#000000\"><param name=\"allowFullScreen\" value=\"true\" /><param name=\"allowScriptAccess\" value=\"always\" /><param name=\"allowNetworking\" value=\"all\" /><param name=\"movie\" value=\"http://www.justin.tv/widgets/live_embed_player.swf\" /><param name=\"flashvars\" value=\"hostname=www.justin.tv&channel=%@&auto_play=true&start_volume=25\"/></object>",flashHeight,flashWidth,[urlArray objectAtIndex:number],[urlArray objectAtIndex:number]];
- NSURL *base = [[NSURL alloc] initWithString:@"http://www.example.com/"];
- [[streamView mainFrame] loadHTMLString:flashString baseURL:base];
- [base release];
- // Set new title
- [window setTitle:[NSString stringWithFormat:@"StreamDesk - %@",[namesArray objectAtIndex:number]]];
- }
- if([[typeArray objectAtIndex:number] isEqualToString:@"stickam"])
- {
- int flashWidth = 685;
- int flashHeight = 461;
- NSString *flashString = [NSString stringWithFormat:@"<object id=\"video_190920392\" type=\"application/x-shockwave-flash\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0\" width=\"%i\" height=\"%i\"><param name=\"movie\" value=\"http://player.stickam.com/stickamPlayer/vo/%@\"><param name=\"allowScriptAccess\" value=\"always\"><param name=\"wmode\" value=\"transparent\"><param name=\"allowfullscreen\" value=\"true\"><param name=\"scale\" value=\"noscale\"><param name=\"quality\" value=\"high\"><param name=\"flashvars\" value=\"autoPlay=1&autoMute=0&showViews=1\"><embed src=\"http://player.stickam.com/stickamPlayer/vo/%@\" flashvars=\"autoPlay=1&autoMute=0&showViews=1\" width=\"%i\" height=\"%i\" wmode=\"transparent\" allowscriptaccess=\"always\" allowfullscreen=\"true\" scale=\"noscale\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\"></object>",flashWidth,flashHeight,[urlArray objectAtIndex:number],[urlArray objectAtIndex:number],flashWidth,flashHeight];
- NSURL *base = [[NSURL alloc] initWithString:@"http://www.example.com/"];
- [[streamView mainFrame] loadHTMLString:flashString baseURL:base];
- [base release];
- // Set new title
- [window setTitle:[NSString stringWithFormat:@"StreamDesk - %@",[namesArray objectAtIndex:number]]];
- }
- }*/
- -(IBAction)goToWebsite:(id)sender
- {
- NSURL *someUrl = [NSURL URLWithString:@"http://www.google.com"];
- if ([[NSWorkspace sharedWorkspace] openURL:someUrl])
- NSLog(@"Opened successfully.");
- else
- NSLog(@"Failed to open URL.");
- }
- -(IBAction)donate:(id)sender
- {
- NSURL *someUrl = [NSURL URLWithString:@"https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=ronanjackson@gmail.com&item_name=StreamDesk Donation¤cy_code=GBP&amount="];
- if ([[NSWorkspace sharedWorkspace] openURL:someUrl])
- NSLog(@"Opened successfully.");
- else
- NSLog(@"Failed to open URL.");
- }
- -(IBAction)newWindow:(id)sender
- {
- NSLog(@"New Window");
- }
- @end