Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 9.61 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #import "StreamDeskAppDelegate.h"
  2. #import "TFHpple.h"
  3.  
  4. @implementation StreamDeskAppDelegate
  5.  
  6. @synthesize window;
  7.  
  8. - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
  9. {
  10.         // Initialise arrays
  11.         // Stream Data View
  12.         streamEmbedName = [[NSMutableArray alloc] init];
  13.         streamFriendlyName = [[NSMutableArray alloc] init];
  14.         streamEmbedFormat = [[NSMutableArray alloc] init];
  15.        
  16.         // Chat Data View
  17.        
  18.         // Stream Data
  19.         mediaType = [[NSMutableArray alloc] init];
  20.         mediaName = [[NSMutableArray alloc] init];
  21.         mediaWeb = [[NSMutableArray alloc] init];
  22.         mediaSizeWidth = [[NSMutableArray alloc] init];
  23.         mediaSizeHeight = [[NSMutableArray alloc] init];
  24.         mediaEmbedType = [[NSMutableArray alloc] init];
  25.         mediaEmbedID = [[NSMutableArray alloc] init];
  26.        
  27.         // Chat Data
  28.        
  29.        
  30.         // Load streams from xml file
  31.         [self loadStreams];
  32. }
  33.  
  34. -(void)loadStreams
  35. {
  36.         // Clean arrays before populating
  37.         // Stream Data View
  38.         [streamEmbedName removeAllObjects];
  39.         [streamFriendlyName removeAllObjects];
  40.         [streamEmbedFormat removeAllObjects];
  41.        
  42.         // Chat Data View
  43.        
  44.         // Stream Data
  45.         [mediaType removeAllObjects];
  46.         [mediaName removeAllObjects];
  47.         [mediaWeb removeAllObjects];
  48.         [mediaSizeWidth removeAllObjects];
  49.         [mediaSizeHeight removeAllObjects];
  50.         [mediaEmbedType removeAllObjects];
  51.         [mediaEmbedID removeAllObjects];
  52.        
  53.         // Chat Data
  54.        
  55.        
  56.         // Read xml and allocate into arrays
  57.         NSError *error;
  58.         NSString *urlData;
  59.         NSURLResponse *response;
  60.     NSURLRequest *request = [[NSMutableURLRequest alloc]
  61.                              initWithURL:[NSURL URLWithString:@"http://streamdesk.sourceforge.net/streams.sdx"]
  62.                              cachePolicy:NSURLRequestUseProtocolCachePolicy
  63.                              timeoutInterval:20]; // 20 second timeout?
  64.         NSData* data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
  65.         [request release];
  66.         urlData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  67.         if(data != nil)
  68.         {
  69.                 NSData *htmlData = [urlData dataUsingEncoding:NSUTF8StringEncoding];
  70.                 TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];
  71.         [urlData release];
  72.        
  73.        
  74.         // ALL THE PARSING IS INCORRECT BUT FUNCTIONS, NEED TO CHANGE TEH PARSING SO EACH OF THE ARRAYS IS IN SYNC!
  75.                
  76.         // Stream Data View
  77.         NSArray *streamEmbedNameArray = [xpathParser search:@"//streamembed/name"];
  78.         NSArray *streamFriendlyNameArray = [xpathParser search:@"//streamembed/friendlyname"];
  79.         NSArray *streamEmbedFormatArray = [xpathParser search:@"//streamembed/embedformat"];
  80.        
  81.         // Stream Data
  82.         NSArray *mediaTypeArray = [xpathParser search:@"//media/mediatype"];
  83.                 NSArray *mediaNameArray = [xpathParser search:@"//media/name"];
  84.         //NSArray *mediaWebArray = [xpathParser search:@"//media/web"];
  85.         NSArray *mediaSizeHeightArray = [xpathParser search:@"//media/size/height"];
  86.         NSArray *mediaSizeWidthArray = [xpathParser search:@"//media/size/width"];
  87.         NSArray *mediaEmbedTypeArray = [xpathParser search:@"//media/streamembed"];
  88.         NSArray *mediaEmbedIDArray = [xpathParser search:@"//media/streamembeddata/embeddata/value"];
  89.                
  90.                 [xpathParser release];
  91.        
  92.         // Stream Data View
  93.         for(int i=0;i<[streamEmbedNameArray count];i++)
  94.         {
  95.             [streamEmbedName addObject:[[streamEmbedNameArray objectAtIndex:i] content]];
  96.             [streamFriendlyName addObject:[[streamFriendlyNameArray objectAtIndex:i] content]];
  97.             [streamEmbedFormat addObject:[[streamEmbedFormatArray objectAtIndex:i] content]];
  98.         }
  99.                
  100.         // Stream Data
  101.                 for(int i=0;i<[mediaTypeArray count];i++)
  102.                 {
  103.                         [mediaName addObject:[[mediaNameArray objectAtIndex:i] content]];
  104.             [mediaType addObject:[[mediaTypeArray objectAtIndex:i] content]];
  105.             /*if([mediaWebArray objectAtIndex:i] != nil)
  106.             {
  107.                 NSLog(@"%@",[mediaWebArray objectAtIndex:i]);
  108.                 [mediaWeb addObject:[[mediaWebArray objectAtIndex:i] content]];
  109.             }*/
  110.             [mediaSizeHeight addObject:[[mediaSizeHeightArray objectAtIndex:i] content]];
  111.             [mediaSizeWidth addObject:[[mediaSizeWidthArray objectAtIndex:i] content]];
  112.             [mediaEmbedType addObject:[[mediaEmbedTypeArray objectAtIndex:i] content]];
  113.             [mediaEmbedID addObject:[[mediaEmbedIDArray objectAtIndex:i] content]];
  114.             [streamButton addItemWithTitle:[mediaName objectAtIndex:i]];
  115.                 }
  116.     }
  117.     else
  118.         {
  119.                 //
  120.         }
  121. }
  122.  
  123. -(IBAction)changeStream:(id)sender
  124. {
  125.     int number = [streamButton indexOfItemWithTitle:[streamButton titleOfSelectedItem]];
  126.     int position = [streamEmbedName indexOfObject:[mediaEmbedType objectAtIndex:number]];
  127.     NSString *embedString = [[streamEmbedFormat objectAtIndex:position] stringByReplacingOccurrencesOfString:@"$ID$" withString:[mediaEmbedID objectAtIndex:number]];
  128.     [window setTitle:[NSString stringWithFormat:@"StreamDesk - %@",[mediaName objectAtIndex:number]]];
  129.     NSURL *base = [[NSURL alloc] initWithString:@"http://www.example.com/"];
  130.     [[streamView mainFrame] loadHTMLString:embedString baseURL:base];
  131.     [base release];
  132. }
  133.  
  134.  
  135.  
  136.  
  137. /*-(IBAction)changeStream:(id)sender
  138. {
  139.         // Number associated with stream
  140.         int number = [streamButton indexOfItemWithTitle:[streamButton titleOfSelectedItem]];
  141.        
  142.         if([[typeArray objectAtIndex:number] isEqualToString:@"ustream"])
  143.         {
  144.                 int flashWidth = 685;
  145.                 int flashHeight = 461;
  146.                 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];
  147.                 NSURL *base = [[NSURL alloc] initWithString:@"http://www.example.com/"];
  148.                 [[streamView mainFrame] loadHTMLString:flashString baseURL:base];
  149.                 [base release];
  150.                
  151.                 // Set new title
  152.                 [window setTitle:[NSString stringWithFormat:@"StreamDesk - %@",[namesArray objectAtIndex:number]]];
  153.         }
  154.        
  155.         if([[typeArray objectAtIndex:number] isEqualToString:@"justin"])
  156.         {
  157.                 int flashWidth = 685;
  158.                 int flashHeight = 461;
  159.                 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]];
  160.                 NSURL *base = [[NSURL alloc] initWithString:@"http://www.example.com/"];
  161.                 [[streamView mainFrame] loadHTMLString:flashString baseURL:base];
  162.                 [base release];
  163.                
  164.                 // Set new title
  165.                 [window setTitle:[NSString stringWithFormat:@"StreamDesk - %@",[namesArray objectAtIndex:number]]];
  166.         }
  167.        
  168.         if([[typeArray objectAtIndex:number] isEqualToString:@"stickam"])
  169.         {
  170.                 int flashWidth = 685;
  171.                 int flashHeight = 461;
  172.                 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];
  173.                 NSURL *base = [[NSURL alloc] initWithString:@"http://www.example.com/"];
  174.                 [[streamView mainFrame] loadHTMLString:flashString baseURL:base];
  175.                 [base release];
  176.                
  177.                 // Set new title
  178.                 [window setTitle:[NSString stringWithFormat:@"StreamDesk - %@",[namesArray objectAtIndex:number]]];
  179.         }
  180. }*/
  181.  
  182. -(IBAction)goToWebsite:(id)sender
  183. {
  184.         NSURL *someUrl = [NSURL URLWithString:@"http://www.google.com"];
  185.         if ([[NSWorkspace sharedWorkspace] openURL:someUrl])
  186.                 NSLog(@"Opened successfully.");
  187.         else
  188.                 NSLog(@"Failed to open URL.");
  189. }
  190.  
  191. -(IBAction)donate:(id)sender
  192. {
  193.         NSURL *someUrl = [NSURL URLWithString:@"https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=ronanjackson@gmail.com&item_name=StreamDesk&nbsp;Donation&currency_code=GBP&amount="];
  194.         if ([[NSWorkspace sharedWorkspace] openURL:someUrl])
  195.                 NSLog(@"Opened successfully.");
  196.         else
  197.                 NSLog(@"Failed to open URL.");
  198. }
  199.  
  200. -(IBAction)newWindow:(id)sender
  201. {
  202.         NSLog(@"New Window");
  203. }
  204.  
  205. @end