+ /*
+ * If scanning we need to do some extra setup of the job.
+ */
+ if( job->indepth_scan == 1 )
+ {
+ char *x264opts_tmp;
+
+ /*
+ * When subtitle scan is enabled do a fast pre-scan job
+ * which will determine which subtitles to enable, if any.
+ */
+ job->pass = -1;
+ x264opts_tmp = job->x264opts;
+
+ job->x264opts = NULL;
+
+ job->indepth_scan = 1;
+
+
+ /*
+ * Add the pre-scan job
+ */
+ hb_add( fQueueEncodeLibhb, job );
+ job->x264opts = x264opts_tmp;
+ }
+
+
+ if( [[queueToApply objectForKey:@"VideoTwoPass"] intValue] == 1 )
+ {
+ job->indepth_scan = 0;
+
+
+
+ job->pass = 1;
+
+ hb_add( fQueueEncodeLibhb, job );
+
+ job->pass = 2;
+
+ job->x264opts = (char *)calloc(1024, 1); /* Fixme, this just leaks */
+ strcpy(job->x264opts, [[queueToApply objectForKey:@"x264Option"] UTF8String]);
+
+ hb_add( fQueueEncodeLibhb, job );
+
+ }
+ else
+ {
+ job->indepth_scan = 0;
+ job->pass = 0;
+
+ hb_add( fQueueEncodeLibhb, job );
+ }
+
+ NSString *destinationDirectory = [[queueToApply objectForKey:@"DestinationPath"] stringByDeletingLastPathComponent];
+ [[NSUserDefaults standardUserDefaults] setObject:destinationDirectory forKey:@"LastDestinationDirectory"];
+ /* Lets mark our new encode as 1 or "Encoding" */
+ [queueToApply setObject:[NSNumber numberWithInt:1] forKey:@"Status"];
+ [self saveQueueFileItem];
+
+ /* we need to clean up the subtitle tracks after the job(s) have been set */
+ int num_subtitle_tracks = hb_list_count(job->list_subtitle);
+ int ii;
+ for(ii = 0; ii < num_subtitle_tracks; ii++)
+ {
+ hb_subtitle_t * subtitle;
+ subtitle = (hb_subtitle_t *)hb_list_item(job->list_subtitle, 0);
+
+
+ hb_list_rem(job->list_subtitle, subtitle);
+ free(subtitle);
+ }
+
+
+ /* We should be all setup so let 'er rip */
+ [self doRip];
+}
+
+
+
+#pragma mark -
+#pragma mark Queue Item Editing
+
+/* Rescans the chosen queue item back into the main window */
+- (void)rescanQueueItemToMainWindow:(NSString *) scanPath scanTitleNum: (int) scanTitleNum selectedQueueItem: (int) selectedQueueItem
+{
+ fqueueEditRescanItemNum = selectedQueueItem;
+ [self writeToActivityLog: "rescanQueueItemToMainWindow: Re-scanning queue item at index:%d",fqueueEditRescanItemNum];
+ applyQueueToScan = YES;
+ /* Set the browsedSourceDisplayName for showNewScan */
+ browsedSourceDisplayName = [[QueueFileArray objectAtIndex:fqueueEditRescanItemNum] objectForKey:@"SourceName"];
+ [self performScan:scanPath scanTitleNum:scanTitleNum];
+}
+
+
+/* We use this method after a queue item rescan for edit.
+ * it largely mirrors -selectPreset in terms of structure.
+ * Assumes that a queue item has been reloaded into the main window.
+ */
+- (IBAction)applyQueueSettingsToMainWindow:(id)sender
+{
+ NSMutableDictionary * queueToApply = [QueueFileArray objectAtIndex:fqueueEditRescanItemNum];
+ hb_job_t * job = fTitle->job;
+ if (queueToApply)
+ {
+ [self writeToActivityLog: "applyQueueSettingsToMainWindow: queue item found"];
+ }