3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.fr/>.
5 It may be used under the terms of the GNU General Public License. */
7 #import "HBQueueController.h"
9 #import "HBImageAndTextCell.h"
11 #define HB_ROW_HEIGHT_TITLE_ONLY 17.0
12 #define HB_ROW_HEIGHT_FULL_DESCRIPTION 200.0
13 // Pasteboard type for or drag operations
14 #define DragDropSimplePboardType @"MyCustomOutlineViewPboardType"
16 //------------------------------------------------------------------------------------
18 //------------------------------------------------------------------------------------
20 //------------------------------------------------------------------------------------
21 // NSMutableAttributedString (HBAdditions)
22 //------------------------------------------------------------------------------------
24 @interface NSMutableAttributedString (HBAdditions)
25 - (void) appendString: (NSString*)aString withAttributes: (NSDictionary *)aDictionary;
28 @implementation NSMutableAttributedString (HBAdditions)
29 - (void) appendString: (NSString*)aString withAttributes: (NSDictionary *)aDictionary
31 NSAttributedString * s = [[[NSAttributedString alloc]
32 initWithString: aString
33 attributes: aDictionary] autorelease];
34 [self appendAttributedString: s];
39 @implementation HBQueueOutlineView
41 - (void)viewDidEndLiveResize
43 // Since we disabled calculating row heights during a live resize, force them to
45 [self noteHeightOfRowsWithIndexesChanged:
46 [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [self numberOfRows])]];
47 [super viewDidEndLiveResize];
52 /* This should be for dragging, we take this info from the presets right now */
53 - (NSImage *)dragImageForRowsWithIndexes:(NSIndexSet *)dragRows tableColumns:(NSArray *)tableColumns event:(NSEvent*)dragEvent offset:(NSPointPointer)dragImageOffset
57 // By default, NSTableView only drags an image of the first column. Change this to
58 // drag an image of the queue's icon and desc and action columns.
59 NSArray * cols = [NSArray arrayWithObjects: [self tableColumnWithIdentifier:@"desc"], [self tableColumnWithIdentifier:@"icon"],[self tableColumnWithIdentifier:@"action"], nil];
60 return [super dragImageForRowsWithIndexes:dragRows tableColumns:cols event:dragEvent offset:dragImageOffset];
65 - (void) mouseDown:(NSEvent *)theEvent
67 [super mouseDown:theEvent];
82 #pragma mark Toolbar Identifiers
83 // Toolbar identifiers
84 static NSString* HBQueueToolbar = @"HBQueueToolbar1";
85 static NSString* HBQueueStartCancelToolbarIdentifier = @"HBQueueStartCancelToolbarIdentifier";
86 static NSString* HBQueuePauseResumeToolbarIdentifier = @"HBQueuePauseResumeToolbarIdentifier";
90 @implementation HBQueueController
92 //------------------------------------------------------------------------------------
94 //------------------------------------------------------------------------------------
97 if (self = [super initWithWindowNibName:@"Queue"])
99 // NSWindowController likes to lazily load its window nib. Since this
100 // controller tries to touch the outlets before accessing the window, we
101 // need to force it to load immadiately by invoking its accessor.
103 // If/when we switch to using bindings, this can probably go away.
107 [[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:
108 @"NO", @"QueueWindowIsOpen",
109 @"NO", @"QueueShowsDetail",
110 @"YES", @"QueueShowsJobsAsGroups",
113 fJobGroups = [[NSMutableArray arrayWithCapacity:0] retain];
118 - (void)setQueueArray: (NSMutableArray *)QueueFileArray
120 [fJobGroups setArray:QueueFileArray];
122 /* First stop any timer working now */
123 [self stopAnimatingCurrentJobGroupInQueue];
124 [fOutlineView reloadData];
128 /* lets get the stats on the status of the queue array */
130 fEncodingQueueItem = 0;
136 /* We use a number system to set the encode status of the queue item
138 * 0 == already encoded
139 * 1 == is being encoded
140 * 2 == is yet to be encoded
145 for(id tempObject in fJobGroups)
147 NSDictionary *thisQueueDict = tempObject;
148 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 0) // Completed
152 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 1) // being encoded
155 fEncodingQueueItem = i;
157 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 2) // pending
161 if ([[thisQueueDict objectForKey:@"Status"] intValue] == 3) // cancelled
168 /* We should fire up the encoding timer here based on fWorkingCount */
170 if (fWorkingCount > 0)
172 /* we have an encoding job so, lets start the animation timer */
173 [self startAnimatingCurrentWorkingEncodeInQueue];
176 /* Set the queue status field in the queue window */
177 NSMutableString * string;
178 if (fPendingCount == 1)
180 string = [NSMutableString stringWithFormat: NSLocalizedString( @"%d encode pending", @"" ), fPendingCount];
184 string = [NSMutableString stringWithFormat: NSLocalizedString( @"%d encode(s) pending", @"" ), fPendingCount];
186 [fQueueCountField setStringValue:string];
189 /* This method sets the status string in the queue window
190 * and is called from Controller.mm (fHBController)
191 * instead of running another timer here polling libhb
192 * for encoding status
194 - (void)setQueueStatusString: (NSString *)statusString
196 [fProgressTextField setStringValue:statusString];
199 //------------------------------------------------------------------------------------
201 //------------------------------------------------------------------------------------
204 // clear the delegate so that windowWillClose is not attempted
205 if( [[self window] delegate] == self )
206 [[self window] setDelegate:nil];
208 [fJobGroups release];
210 [fSavedExpandedItems release];
211 [fSavedSelectedItems release];
213 [[NSNotificationCenter defaultCenter] removeObserver:self];
218 //------------------------------------------------------------------------------------
220 //------------------------------------------------------------------------------------
221 - (void)setHandle: (hb_handle_t *)handle
223 fQueueEncodeLibhb = handle;
226 //------------------------------------------------------------------------------------
227 // Receive HBController
228 //------------------------------------------------------------------------------------
229 - (void)setHBController: (HBController *)controller
231 fHBController = controller;
236 //------------------------------------------------------------------------------------
237 // Displays and brings the queue window to the front
238 //------------------------------------------------------------------------------------
239 - (IBAction) showQueueWindow: (id)sender
241 [self showWindow:sender];
242 [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"QueueWindowIsOpen"];
247 //------------------------------------------------------------------------------------
249 //------------------------------------------------------------------------------------
254 if( ![[self window] setFrameUsingName:@"Queue"] )
255 [[self window] center];
256 [self setWindowFrameAutosaveName:@"Queue"];
257 [[self window] setExcludedFromWindowsMenu:YES];
259 /* lets setup our queue list outline view for drag and drop here */
260 [fOutlineView registerForDraggedTypes: [NSArray arrayWithObject:DragDropSimplePboardType] ];
261 [fOutlineView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES];
262 [fOutlineView setVerticalMotionCanBeginDrag: YES];
265 // Don't allow autoresizing of main column, else the "delete" column will get
266 // pushed out of view.
267 [fOutlineView setAutoresizesOutlineColumn: NO];
269 #if HB_OUTLINE_METRIC_CONTROLS
270 [fIndentation setHidden: NO];
271 [fSpacing setHidden: NO];
272 [fIndentation setIntegerValue:[fOutlineView indentationPerLevel]]; // debug
273 [fSpacing setIntegerValue:3]; // debug
276 // Show/hide UI elements
277 fCurrentJobPaneShown = NO; // it's shown in the nib
278 //[self showCurrentJobPane:NO];
280 //[self updateQueueCountField];
284 //------------------------------------------------------------------------------------
286 //------------------------------------------------------------------------------------
287 - (void)windowWillClose:(NSNotification *)aNotification
289 [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"QueueWindowIsOpen"];
294 //------------------------------------------------------------------------------------
296 //------------------------------------------------------------------------------------
299 // Create a new toolbar instance, and attach it to our window
300 NSToolbar *toolbar = [[[NSToolbar alloc] initWithIdentifier: HBQueueToolbar] autorelease];
302 // Set up toolbar properties: Allow customization, give a default display mode, and remember state in user defaults
303 [toolbar setAllowsUserCustomization: YES];
304 [toolbar setAutosavesConfiguration: YES];
305 [toolbar setDisplayMode: NSToolbarDisplayModeIconAndLabel];
307 // We are the delegate
308 [toolbar setDelegate: self];
310 // Attach the toolbar to our window
311 [[self window] setToolbar:toolbar];
314 //------------------------------------------------------------------------------------
315 // toolbar:itemForItemIdentifier:willBeInsertedIntoToolbar:
316 //------------------------------------------------------------------------------------
317 - (NSToolbarItem *)toolbar:(NSToolbar *)toolbar
318 itemForItemIdentifier:(NSString *)itemIdentifier
319 willBeInsertedIntoToolbar:(BOOL)flag
321 // Required delegate method: Given an item identifier, this method returns an item.
322 // The toolbar will use this method to obtain toolbar items that can be displayed
323 // in the customization sheet, or in the toolbar itself.
325 NSToolbarItem *toolbarItem = nil;
327 if ([itemIdentifier isEqual: HBQueueStartCancelToolbarIdentifier])
329 toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdentifier] autorelease];
331 // Set the text label to be displayed in the toolbar and customization palette
332 [toolbarItem setLabel: @"Start"];
333 [toolbarItem setPaletteLabel: @"Start/Cancel"];
335 // Set up a reasonable tooltip, and image
336 [toolbarItem setToolTip: @"Start Encoding"];
337 [toolbarItem setImage: [NSImage imageNamed: @"Play"]];
339 // Tell the item what message to send when it is clicked
340 [toolbarItem setTarget: self];
341 [toolbarItem setAction: @selector(toggleStartCancel:)];
344 if ([itemIdentifier isEqual: HBQueuePauseResumeToolbarIdentifier])
346 toolbarItem = [[[NSToolbarItem alloc] initWithItemIdentifier: itemIdentifier] autorelease];
348 // Set the text label to be displayed in the toolbar and customization palette
349 [toolbarItem setLabel: @"Pause"];
350 [toolbarItem setPaletteLabel: @"Pause/Resume"];
352 // Set up a reasonable tooltip, and image
353 [toolbarItem setToolTip: @"Pause Encoding"];
354 [toolbarItem setImage: [NSImage imageNamed: @"Pause"]];
356 // Tell the item what message to send when it is clicked
357 [toolbarItem setTarget: self];
358 [toolbarItem setAction: @selector(togglePauseResume:)];
364 //------------------------------------------------------------------------------------
365 // toolbarDefaultItemIdentifiers:
366 //------------------------------------------------------------------------------------
367 - (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
369 // Required delegate method: Returns the ordered list of items to be shown in the
370 // toolbar by default.
372 return [NSArray arrayWithObjects:
373 HBQueueStartCancelToolbarIdentifier,
374 HBQueuePauseResumeToolbarIdentifier,
378 //------------------------------------------------------------------------------------
379 // toolbarAllowedItemIdentifiers:
380 //------------------------------------------------------------------------------------
381 - (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
383 // Required delegate method: Returns the list of all allowed items by identifier.
384 // By default, the toolbar does not assume any items are allowed, even the
385 // separator. So, every allowed item must be explicitly listed.
387 return [NSArray arrayWithObjects:
388 HBQueueStartCancelToolbarIdentifier,
389 HBQueuePauseResumeToolbarIdentifier,
390 NSToolbarCustomizeToolbarItemIdentifier,
391 NSToolbarFlexibleSpaceItemIdentifier,
392 NSToolbarSpaceItemIdentifier,
393 NSToolbarSeparatorItemIdentifier,
397 //------------------------------------------------------------------------------------
398 // validateToolbarItem:
399 //------------------------------------------------------------------------------------
400 - (BOOL) validateToolbarItem: (NSToolbarItem *) toolbarItem
402 // Optional method: This message is sent to us since we are the target of some
403 // toolbar item actions.
405 if (!fQueueEncodeLibhb) return NO;
410 hb_get_state2 (fQueueEncodeLibhb, &s);
412 if ([[toolbarItem itemIdentifier] isEqual: HBQueueStartCancelToolbarIdentifier])
414 if ((s.state == HB_STATE_PAUSED) || (s.state == HB_STATE_WORKING) || (s.state == HB_STATE_MUXING))
417 [toolbarItem setImage:[NSImage imageNamed: @"Stop"]];
418 [toolbarItem setLabel: @"Stop"];
419 [toolbarItem setToolTip: @"Stop Encoding"];
422 else if (fPendingCount > 0)
425 [toolbarItem setImage:[NSImage imageNamed: @"Play"]];
426 [toolbarItem setLabel: @"Start"];
427 [toolbarItem setToolTip: @"Start Encoding"];
433 [toolbarItem setImage:[NSImage imageNamed: @"Play"]];
434 [toolbarItem setLabel: @"Start"];
435 [toolbarItem setToolTip: @"Start Encoding"];
439 if ([[toolbarItem itemIdentifier] isEqual: HBQueuePauseResumeToolbarIdentifier])
441 if (s.state == HB_STATE_PAUSED)
444 [toolbarItem setImage:[NSImage imageNamed: @"Play"]];
445 [toolbarItem setLabel: @"Resume"];
446 [toolbarItem setToolTip: @"Resume Encoding"];
449 else if ((s.state == HB_STATE_WORKING) || (s.state == HB_STATE_MUXING))
452 [toolbarItem setImage:[NSImage imageNamed: @"Pause"]];
453 [toolbarItem setLabel: @"Pause"];
454 [toolbarItem setToolTip: @"Pause Encoding"];
459 [toolbarItem setImage:[NSImage imageNamed: @"Pause"]];
460 [toolbarItem setLabel: @"Pause"];
461 [toolbarItem setToolTip: @"Pause Encoding"];
471 #pragma mark Queue Item Controls
472 //------------------------------------------------------------------------------------
473 // Delete encodes from the queue window and accompanying array
474 // Also handling first cancelling the encode if in fact its currently encoding.
475 //------------------------------------------------------------------------------------
476 - (IBAction)removeSelectedQueueItem: (id)sender
478 NSIndexSet * selectedRows = [fOutlineView selectedRowIndexes];
479 NSUInteger row = [selectedRows firstIndex];
480 if( row == NSNotFound )
482 /* if this is a currently encoding job, we need to be sure to alert the user,
483 * to let them decide to cancel it first, then if they do, we can come back and
486 if ([[[fJobGroups objectAtIndex:row] objectForKey:@"Status"] integerValue] == 1)
488 /* We pause the encode here so that it doesn't finish right after and then
489 * screw up the sync while the window is open
491 [fHBController Pause:NULL];
492 NSString * alertTitle = [NSString stringWithFormat:NSLocalizedString(@"Stop This Encode and Remove It ?", nil)];
493 // Which window to attach the sheet to?
494 NSWindow * docWindow = nil;
495 if ([sender respondsToSelector: @selector(window)])
496 docWindow = [sender window];
499 NSBeginCriticalAlertSheet(
501 NSLocalizedString(@"Keep Encoding", nil),
503 NSLocalizedString(@"Stop Encoding and Delete", nil),
505 nil, @selector(didDimissCancelCurrentJob:returnCode:contextInfo:), nil,
506 NSLocalizedString(@"Your movie will be lost if you don't continue encoding.", nil));
508 // didDimissCancelCurrentJob:returnCode:contextInfo: will be called when the dialog is dismissed
512 /* since we are not a currently encoding item, we can just be cancelled */
513 [fHBController removeQueueFileItem:row];
517 - (void) didDimissCancelCurrentJob: (NSWindow *)sheet returnCode: (int)returnCode contextInfo: (void *)contextInfo
519 /* We resume encoding and perform the appropriate actions
520 * Note: Pause: is a toggle type method based on hb's current
521 * state, if it paused, it will resume encoding and vice versa.
522 * In this case, we are paused from the calling window, so calling
523 * [fHBController Pause:NULL]; Again will resume encoding
525 [fHBController Pause:NULL];
526 if (returnCode == NSAlertOtherReturn)
528 /* We need to save the currently encoding item number first */
529 int encodingItemToRemove = fEncodingQueueItem;
530 /* Since we are encoding, we need to let fHBController Cancel this job
531 * upon which it will move to the next one if there is one
533 [fHBController doCancelCurrentJob];
534 /* Now, we can go ahead and remove the job we just cancelled since
535 * we have its item number from above
537 [fHBController removeQueueFileItem:encodingItemToRemove];
542 //------------------------------------------------------------------------------------
543 // Show the finished encode in the finder
544 //------------------------------------------------------------------------------------
545 - (IBAction)revealSelectedQueueItem: (id)sender
547 NSIndexSet * selectedRows = [fOutlineView selectedRowIndexes];
548 NSInteger row = [selectedRows firstIndex];
549 if (row != NSNotFound)
551 while (row != NSNotFound)
553 NSMutableDictionary *queueItemToOpen = [fOutlineView itemAtRow: row];
554 [[NSWorkspace sharedWorkspace] selectFile:[queueItemToOpen objectForKey:@"DestinationPath"] inFileViewerRootedAtPath:nil];
556 row = [selectedRows indexGreaterThanIndex: row];
562 //------------------------------------------------------------------------------------
563 // Starts or cancels the processing of jobs depending on the current state
564 //------------------------------------------------------------------------------------
565 - (IBAction)toggleStartCancel: (id)sender
567 if (!fQueueEncodeLibhb) return;
570 hb_get_state2 (fQueueEncodeLibhb, &s);
572 if ((s.state == HB_STATE_PAUSED) || (s.state == HB_STATE_WORKING) || (s.state == HB_STATE_MUXING))
573 [fHBController Cancel: fQueuePane]; // sender == fQueuePane so that warning alert shows up on queue window
575 else if (fPendingCount > 0)
576 [fHBController Rip: NULL];
579 //------------------------------------------------------------------------------------
580 // Toggles the pause/resume state of libhb
581 //------------------------------------------------------------------------------------
582 - (IBAction)togglePauseResume: (id)sender
584 if (!fQueueEncodeLibhb) return;
587 hb_get_state2 (fQueueEncodeLibhb, &s);
589 if (s.state == HB_STATE_PAUSED)
591 hb_resume (fQueueEncodeLibhb);
592 [self startAnimatingCurrentWorkingEncodeInQueue];
594 else if ((s.state == HB_STATE_WORKING) || (s.state == HB_STATE_MUXING))
596 hb_pause (fQueueEncodeLibhb);
597 [self stopAnimatingCurrentJobGroupInQueue];
604 #pragma mark Animate Endcoding Item
609 //------------------------------------------------------------------------------------
610 // Starts animating the job icon of the currently processing job in the queue outline
612 //------------------------------------------------------------------------------------
613 - (void) startAnimatingCurrentWorkingEncodeInQueue
615 if (!fAnimationTimer)
616 fAnimationTimer = [[NSTimer scheduledTimerWithTimeInterval:1.0/12.0 // 1/12 because there are 6 images in the animation cycle
618 selector:@selector(animateWorkingEncodeInQueue:)
620 repeats:YES] retain];
623 //------------------------------------------------------------------------------------
624 // If a job is currently processing, its job icon in the queue outline view is
625 // animated to its next state.
626 //------------------------------------------------------------------------------------
627 - (void) animateWorkingEncodeInQueue:(NSTimer*)theTimer
629 if (fWorkingCount > 0)
632 fAnimationIndex %= 6; // there are 6 animation images; see outlineView:objectValueForTableColumn:byItem: below.
633 [self animateWorkingEncodeIconInQueue];
638 - (void) animateWorkingEncodeIconInQueue
640 NSInteger row = fEncodingQueueItem; /// need to set to fEncodingQueueItem
641 NSInteger col = [fOutlineView columnWithIdentifier: @"icon"];
642 if (row != -1 && col != -1)
644 NSRect frame = [fOutlineView frameOfCellAtColumn:col row:row];
645 [fOutlineView setNeedsDisplayInRect: frame];
649 //------------------------------------------------------------------------------------
650 // Stops animating the job icon of the currently processing job in the queue outline
652 //------------------------------------------------------------------------------------
653 - (void) stopAnimatingCurrentJobGroupInQueue
655 if (fAnimationTimer && [fAnimationTimer isValid])
657 [fAnimationTimer invalidate];
658 [fAnimationTimer release];
659 fAnimationTimer = nil;
666 - (void)moveObjectsInArray:(NSMutableArray *)array fromIndexes:(NSIndexSet *)indexSet toIndex:(NSUInteger)insertIndex
668 NSUInteger index = [indexSet lastIndex];
669 NSUInteger aboveInsertIndexCount = 0;
671 while (index != NSNotFound)
673 NSUInteger removeIndex;
675 if (index >= insertIndex)
677 removeIndex = index + aboveInsertIndexCount;
678 aboveInsertIndexCount++;
686 id object = [[array objectAtIndex:removeIndex] retain];
687 [array removeObjectAtIndex:removeIndex];
688 [array insertObject:object atIndex:insertIndex];
691 index = [indexSet indexLessThanIndex:index];
697 #pragma mark NSOutlineView delegate
700 - (id)outlineView:(NSOutlineView *)fOutlineView child:(NSInteger)index ofItem:(id)item
703 return [fJobGroups objectAtIndex:index];
705 // We are only one level deep, so we can't be asked about children
706 NSAssert (NO, @"HBQueueController outlineView:child:ofItem: can't handle nested items.");
710 - (BOOL)outlineView:(NSOutlineView *)fOutlineView isItemExpandable:(id)item
712 // Our outline view has no levels, but we can still expand every item. Doing so
713 // just makes the row taller. See heightOfRowByItem below.
717 - (BOOL)outlineView:(NSOutlineView *)outlineView shouldExpandItem:(id)item
719 // Our outline view has no levels, but we can still expand every item. Doing so
720 // just makes the row taller. See heightOfRowByItem below.
721 return ![(HBQueueOutlineView*)outlineView isDragging];
724 - (NSInteger)outlineView:(NSOutlineView *)fOutlineView numberOfChildrenOfItem:(id)item
726 // Our outline view has no levels, so number of children will be zero for all
729 return [fJobGroups count];
734 - (void)outlineViewItemDidCollapse:(NSNotification *)notification
736 id item = [[notification userInfo] objectForKey:@"NSObject"];
737 NSInteger row = [fOutlineView rowForItem:item];
738 [fOutlineView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(row,1)]];
741 - (void)outlineViewItemDidExpand:(NSNotification *)notification
743 id item = [[notification userInfo] objectForKey:@"NSObject"];
744 NSInteger row = [fOutlineView rowForItem:item];
745 [fOutlineView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(row,1)]];
748 - (CGFloat)outlineView:(NSOutlineView *)outlineView heightOfRowByItem:(id)item
750 if ([outlineView isItemExpanded: item])
752 // Short-circuit here if in a live resize primarily to fix a bug but also to
753 // increase resposivness during a resize. There's a bug in NSTableView that
754 // causes row heights to get messed up if you try to change them during a live
755 // resize. So if in a live resize, simply return the previously calculated
756 // height. The row heights will get fixed up after the resize because we have
757 // implemented viewDidEndLiveResize to force all of them to be recalculated.
758 // if ([outlineView inLiveResize] && [item lastDescriptionHeight] > 0)
759 // return [item lastDescriptionHeight];
761 // CGFloat width = [[outlineView tableColumnWithIdentifier: @"desc"] width];
762 // Column width is NOT what is ultimately used. I can't quite figure out what
763 // width to use for calculating text metrics. No matter how I tweak this value,
764 // there are a few conditions in which the drawn text extends below the bounds
765 // of the row cell. In previous versions, which ran under Tiger, I was
766 // reducing width by 47 pixles.
767 // width -= 2; // (?) for intercell spacing
769 // CGFloat height = [item heightOfDescriptionForWidth: width];
772 return HB_ROW_HEIGHT_FULL_DESCRIPTION;
775 return HB_ROW_HEIGHT_TITLE_ONLY;
778 - (CGFloat) heightOfDescriptionForWidth:(CGFloat)width
780 // Try to return the cached value if no changes have happened since the last time
781 //if ((width == fLastDescriptionWidth) && (fLastDescriptionHeight != 0) && !fNeedsDescription)
782 // return fLastDescriptionHeight;
784 //if (fNeedsDescription)
785 // [self updateDescription];
787 // Calculate the height
788 //NSRect bounds = [fDescription boundingRectWithSize:NSMakeSize(width, 10000) options:NSStringDrawingUsesLineFragmentOrigin];
789 //fLastDescriptionHeight = bounds.size.height + 6.0; // add some border to bottom
790 //fLastDescriptionWidth = width;
791 return HB_ROW_HEIGHT_FULL_DESCRIPTION;
793 /* supposedly another way to do this, in case boundingRectWithSize isn't working
794 NSTextView* tmpView = [[NSTextView alloc] initWithFrame:NSMakeRect(0, 0, width, 1)];
795 [[tmpView textStorage] setAttributedString:aString];
796 [tmpView setHorizontallyResizable:NO];
797 [tmpView setVerticallyResizable:YES];
798 // [[tmpView textContainer] setHeightTracksTextView: YES];
799 // [[tmpView textContainer] setContainerSize: NSMakeSize(width, 10000)];
801 float height = [tmpView frame].size.height;
807 - (CGFloat) lastDescriptionHeight
809 return HB_ROW_HEIGHT_FULL_DESCRIPTION;
812 - (id)outlineView:(NSOutlineView *)fOutlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
814 // nb: The "desc" column is currently an HBImageAndTextCell. However, we are longer
815 // using the image portion of the cell so we could switch back to a regular NSTextFieldCell.
817 if ([[tableColumn identifier] isEqualToString:@"desc"])
819 /* This should have caused the description we wanted to show*/
820 //return [item objectForKey:@"SourceName"];
822 /* code to build the description as per old queue */
823 //return [self formatEncodeItemDescription:item];
825 /* Below should be put into a separate method but I am way too f'ing lazy right now */
826 NSMutableAttributedString * finalString = [[[NSMutableAttributedString alloc] initWithString: @""] autorelease];
828 NSMutableParagraphStyle * ps = [[[NSParagraphStyle defaultParagraphStyle] mutableCopy] retain];
829 [ps setHeadIndent: 40.0];
830 [ps setParagraphSpacing: 1.0];
831 [ps setTabStops:[NSArray array]]; // clear all tabs
832 [ps addTabStop: [[[NSTextTab alloc] initWithType: NSLeftTabStopType location: 20.0] autorelease]];
835 NSDictionary* detailAttr = [NSDictionary dictionaryWithObjectsAndKeys:
836 [NSFont systemFontOfSize:10.0], NSFontAttributeName,
837 ps, NSParagraphStyleAttributeName,
840 NSDictionary* detailBoldAttr = [NSDictionary dictionaryWithObjectsAndKeys:
841 [NSFont boldSystemFontOfSize:10.0], NSFontAttributeName,
842 ps, NSParagraphStyleAttributeName,
845 NSDictionary* titleAttr = [NSDictionary dictionaryWithObjectsAndKeys:
846 [NSFont systemFontOfSize:[NSFont systemFontSize]], NSFontAttributeName,
847 ps, NSParagraphStyleAttributeName,
850 NSDictionary* shortHeightAttr = [NSDictionary dictionaryWithObjectsAndKeys:
851 [NSFont systemFontOfSize:2.0], NSFontAttributeName,
854 /* First line, we should strip the destination path and just show the file name and add the title num and chapters (if any) */
855 //finalDescription = [finalDescription stringByAppendingString:[NSString stringWithFormat:@"Source: %@ Output: %@\n", [item objectForKey:@"SourceName"],[item objectForKey:@"DestinationPath"]]];
856 NSString * summaryInfo;
858 NSString * titleString = [NSString stringWithFormat:@"Title %d", [[item objectForKey:@"TitleNumber"] intValue]];
860 NSString * chapterString = ([[item objectForKey:@"ChapterStart"] intValue] == [[item objectForKey:@"ChapterEnd"] intValue]) ?
861 [NSString stringWithFormat:@"Chapter %d", [[item objectForKey:@"ChapterStart"] intValue]] :
862 [NSString stringWithFormat:@"Chapters %d through %d", [[item objectForKey:@"ChapterStart"] intValue], [[item objectForKey:@"ChapterEnd"] intValue]];
864 NSString * passesString;
865 if ([[item objectForKey:@"VideoTwoPass"] intValue] == 0)
867 passesString = [NSString stringWithFormat:@"1 Video Pass"];
871 if ([[item objectForKey:@"VideoTurboTwoPass"] intValue] == 1)
873 passesString = [NSString stringWithFormat:@"2 Video Passes Turbo"];
877 passesString = [NSString stringWithFormat:@"2 Video Passes"];
881 [finalString appendString:[NSString stringWithFormat:@"%@", [item objectForKey:@"SourceName"]] withAttributes:titleAttr];
883 /* lets add the output file name to the title string here */
884 NSString * outputFilenameString = [[item objectForKey:@"DestinationPath"] lastPathComponent];
886 summaryInfo = [NSString stringWithFormat: @" (%@, %@, %@) -> %@", titleString, chapterString, passesString, outputFilenameString];
888 [finalString appendString:[NSString stringWithFormat:@"%@\n", summaryInfo] withAttributes:detailAttr];
890 // Insert a short-in-height line to put some white space after the title
891 [finalString appendString:@"\n" withAttributes:shortHeightAttr];
892 // End of Title Stuff
894 /* Second Line (Preset Name)*/
895 [finalString appendString: @"Preset: " withAttributes:detailBoldAttr];
896 [finalString appendString:[NSString stringWithFormat:@"%@\n", [item objectForKey:@"PresetName"]] withAttributes:detailAttr];
898 /* Third Line (Format Summary) */
899 NSString * audioCodecSummary = @"";
900 /* Lets also get our audio track detail since we are going through the logic for use later */
901 NSString * audioDetail1 = @"";
902 NSString * audioDetail2 = @"";
903 NSString * audioDetail3 = @"";
904 NSString * audioDetail4 = @"";
905 if ([[item objectForKey:@"Audio1Track"] intValue] > 0)
907 audioCodecSummary = [NSString stringWithFormat:@"%@", [item objectForKey:@"Audio1Encoder"]];
908 audioDetail1 = [NSString stringWithFormat:@"%@ Encoder: %@ Mixdown: %@ SampleRate: %@(khz) Bitrate: %@(kbps)",
909 [item objectForKey:@"Audio1TrackDescription"] ,
910 [item objectForKey:@"Audio1Encoder"],
911 [item objectForKey:@"Audio1Mixdown"] ,
912 [item objectForKey:@"Audio1Samplerate"],
913 [item objectForKey:@"Audio1Bitrate"]];
915 if ([[item objectForKey:@"Audio1TrackDRCSlider"] floatValue] > 1.00)
917 audioDetail1 = [NSString stringWithFormat:@"%@, DRC: %@",audioDetail1,[item objectForKey:@"Audio1TrackDRCSlider"]];
921 audioDetail1 = [NSString stringWithFormat:@"%@, DRC: Off",audioDetail1];
925 if ([[item objectForKey:@"Audio2Track"] intValue] > 0)
927 audioCodecSummary = [NSString stringWithFormat:@"%@, %@",audioCodecSummary ,[item objectForKey:@"Audio2Encoder"]];
928 audioDetail2 = [NSString stringWithFormat:@"%@ Encoder: %@ Mixdown: %@ SampleRate: %@(khz) Bitrate: %@(kbps)",
929 [item objectForKey:@"Audio2TrackDescription"] ,
930 [item objectForKey:@"Audio2Encoder"],
931 [item objectForKey:@"Audio2Mixdown"] ,
932 [item objectForKey:@"Audio2Samplerate"],
933 [item objectForKey:@"Audio2Bitrate"]];
935 if ([[item objectForKey:@"Audio2TrackDRCSlider"] floatValue] > 1.00)
937 audioDetail2 = [NSString stringWithFormat:@"%@, DRC: %@",audioDetail2,[item objectForKey:@"Audio2TrackDRCSlider"]];
941 audioDetail2 = [NSString stringWithFormat:@"%@, DRC: Off",audioDetail2];
945 if ([[item objectForKey:@"Audio3Track"] intValue] > 0)
947 audioCodecSummary = [NSString stringWithFormat:@"%@, %@",audioCodecSummary ,[item objectForKey:@"Audio3Encoder"]];
948 audioDetail3 = [NSString stringWithFormat:@"%@ Encoder: %@ Mixdown: %@ SampleRate: %@(khz) Bitrate: %@(kbps)",
949 [item objectForKey:@"Audio3TrackDescription"] ,
950 [item objectForKey:@"Audio3Encoder"],
951 [item objectForKey:@"Audio3Mixdown"] ,
952 [item objectForKey:@"Audio3Samplerate"],
953 [item objectForKey:@"Audio3Bitrate"]];
955 if ([[item objectForKey:@"Audio3TrackDRCSlider"] floatValue] > 1.00)
957 audioDetail3 = [NSString stringWithFormat:@"%@, DRC: %@",audioDetail3,[item objectForKey:@"Audio3TrackDRCSlider"]];
961 audioDetail3 = [NSString stringWithFormat:@"%@, DRC: Off",audioDetail3];
965 if ([[item objectForKey:@"Audio4Track"] intValue] > 0)
967 audioCodecSummary = [NSString stringWithFormat:@"%@, %@",audioCodecSummary ,[item objectForKey:@"Audio3Encoder"]];
968 audioDetail4 = [NSString stringWithFormat:@"%@ Encoder: %@ Mixdown: %@ SampleRate: %@(khz) Bitrate: %@(kbps)",
969 [item objectForKey:@"Audio4TrackDescription"] ,
970 [item objectForKey:@"Audio4Encoder"],
971 [item objectForKey:@"Audio4Mixdown"] ,
972 [item objectForKey:@"Audio4Samplerate"],
973 [item objectForKey:@"Audio4Bitrate"]];
975 if ([[item objectForKey:@"Audio4TrackDRCSlider"] floatValue] > 1.00)
977 audioDetail4 = [NSString stringWithFormat:@"%@, DRC: %@",audioDetail4,[item objectForKey:@"Audio4TrackDRCSlider"]];
981 audioDetail4 = [NSString stringWithFormat:@"%@, DRC: Off",audioDetail4];
985 NSString * jobFormatInfo;
986 if ([[item objectForKey:@"ChapterMarkers"] intValue] == 1)
987 jobFormatInfo = [NSString stringWithFormat:@"%@ Container, %@ Video %@ Audio, Chapter Markers\n", [item objectForKey:@"FileFormat"], [item objectForKey:@"VideoEncoder"], audioCodecSummary];
989 jobFormatInfo = [NSString stringWithFormat:@"%@ Container, %@ Video %@ Audio\n", [item objectForKey:@"FileFormat"], [item objectForKey:@"VideoEncoder"], audioCodecSummary];
992 [finalString appendString: @"Format: " withAttributes:detailBoldAttr];
993 [finalString appendString: jobFormatInfo withAttributes:detailAttr];
995 /* Optional String for mp4 options */
996 if ([[item objectForKey:@"FileFormat"] isEqualToString: @"MP4 file"])
998 NSString * MP4Opts = @"";
999 BOOL mp4OptsPresent = NO;
1000 if( [[item objectForKey:@"Mp4LargeFile"] intValue] == 1)
1002 mp4OptsPresent = YES;
1003 MP4Opts = [MP4Opts stringByAppendingString:@" - Large file size"];
1005 if( [[item objectForKey:@"Mp4HttpOptimize"] intValue] == 1)
1007 mp4OptsPresent = YES;
1008 MP4Opts = [MP4Opts stringByAppendingString:@" - Web optimized"];
1011 if( [[item objectForKey:@"Mp4iPodCompatible"] intValue] == 1)
1013 mp4OptsPresent = YES;
1014 MP4Opts = [MP4Opts stringByAppendingString:@" - iPod 5G support "];
1016 if (mp4OptsPresent == YES)
1018 [finalString appendString: @"MP4 Options: " withAttributes:detailBoldAttr];
1019 [finalString appendString: MP4Opts withAttributes:detailAttr];
1020 [finalString appendString:@"\n" withAttributes:detailAttr];
1024 /* Fourth Line (Destination Path)*/
1025 [finalString appendString: @"Destination: " withAttributes:detailBoldAttr];
1026 [finalString appendString: [item objectForKey:@"DestinationPath"] withAttributes:detailAttr];
1027 [finalString appendString:@"\n" withAttributes:detailAttr];
1028 /* Fifth Line Picture Details*/
1029 NSString * pictureInfo;
1030 pictureInfo = [NSString stringWithFormat:@"%@", [item objectForKey:@"PictureSizingSummary"]];
1031 if ([[item objectForKey:@"PictureKeepRatio"] intValue] == 1)
1033 pictureInfo = [pictureInfo stringByAppendingString:@" Keep Aspect Ratio"];
1035 if ([[item objectForKey:@"VideoGrayScale"] intValue] == 1)
1037 pictureInfo = [pictureInfo stringByAppendingString:@", Grayscale"];
1040 [finalString appendString: @"Picture: " withAttributes:detailBoldAttr];
1041 [finalString appendString: pictureInfo withAttributes:detailAttr];
1042 [finalString appendString:@"\n" withAttributes:detailAttr];
1044 /* Optional String for Picture Filters */
1046 NSString * pictureFilters = @"";
1047 BOOL pictureFiltersPresent = NO;
1049 if( [[item objectForKey:@"PictureDetelecine"] intValue] == 1)
1051 pictureFiltersPresent = YES;
1052 pictureFilters = [pictureFilters stringByAppendingString:@" - Detelecine (Default)"];
1054 else if( [[item objectForKey:@"PictureDetelecine"] intValue] == 2)
1056 pictureFiltersPresent = YES;
1057 pictureFilters = [pictureFilters stringByAppendingString:[NSString stringWithFormat:@" - Detelecine (%@)",[item objectForKey:@"PictureDetelecineCustom"]]];
1060 if( [[item objectForKey:@"PictureDecombDeinterlace"] intValue] == 1)
1062 if ([[item objectForKey:@"PictureDecomb"] intValue] != 0)
1064 pictureFiltersPresent = YES;
1065 if( [[item objectForKey:@"PictureDecomb"] intValue] == 1)
1067 pictureFiltersPresent = YES;
1068 pictureFilters = [pictureFilters stringByAppendingString:@" - Decomb (Default)"];
1070 if( [[item objectForKey:@"PictureDecomb"] intValue] == 2)
1072 pictureFiltersPresent = YES;
1073 pictureFilters = [pictureFilters stringByAppendingString:[NSString stringWithFormat:@" - Decomb (%@)",[item objectForKey:@"PictureDecombCustom"]]];
1079 if ([[item objectForKey:@"PictureDeinterlace"] intValue] != 0)
1081 pictureFiltersPresent = YES;
1082 if ([[item objectForKey:@"PictureDeinterlace"] intValue] == 1)
1084 pictureFilters = [pictureFilters stringByAppendingString:@" - Deinterlace (Fast)"];
1086 else if ([[item objectForKey:@"PictureDeinterlace"] intValue] == 2)
1088 pictureFilters = [pictureFilters stringByAppendingString:@" - Deinterlace (Slow)"];
1090 else if ([[item objectForKey:@"PictureDeinterlace"] intValue] == 3)
1092 pictureFilters = [pictureFilters stringByAppendingString:@" - Deinterlace (Slower)"];
1094 else if ([[item objectForKey:@"PictureDeinterlace"] intValue] == 4)
1096 pictureFilters = [pictureFilters stringByAppendingString:[NSString stringWithFormat:@" - Deinterlace (%@)",[item objectForKey:@"PictureDeinterlaceCustom"]]];
1101 if ([[item objectForKey:@"PictureDenoise"] intValue] != 0)
1103 pictureFiltersPresent = YES;
1104 if ([[item objectForKey:@"PictureDenoise"] intValue] == 1)
1106 pictureFilters = [pictureFilters stringByAppendingString:@" - Denoise (Weak)"];
1108 else if ([[item objectForKey:@"PictureDenoise"] intValue] == 2)
1110 pictureFilters = [pictureFilters stringByAppendingString:@" - Denoise (Medium)"];
1112 else if ([[item objectForKey:@"PictureDenoise"] intValue] == 3)
1114 pictureFilters = [pictureFilters stringByAppendingString:@" - Denoise (Strong)"];
1116 else if ([[item objectForKey:@"PictureDenoise"] intValue] == 4)
1118 pictureFilters = [pictureFilters stringByAppendingString:[NSString stringWithFormat:@" - Denoise (%@)",[item objectForKey:@"PictureDenoiseCustom"]]];
1122 if ([[item objectForKey:@"PictureDeblock"] intValue] != 0)
1124 pictureFiltersPresent = YES;
1125 pictureFilters = [pictureFilters stringByAppendingString: [NSString stringWithFormat:@" - Deblock (pp7) (%d)",[[item objectForKey:@"PictureDeblock"] intValue]]];
1128 if ([[item objectForKey:@"VideoGrayScale"] intValue] == 1)
1130 pictureFiltersPresent = YES;
1131 pictureFilters = [pictureFilters stringByAppendingString:@" - Grayscale"];
1134 if (pictureFiltersPresent == YES)
1136 [finalString appendString: @"Filters: " withAttributes:detailBoldAttr];
1137 [finalString appendString: pictureFilters withAttributes:detailAttr];
1138 [finalString appendString:@"\n" withAttributes:detailAttr];
1141 /* Sixth Line Video Details*/
1142 NSString * videoInfo;
1143 videoInfo = [NSString stringWithFormat:@"Encoder: %@", [item objectForKey:@"VideoEncoder"]];
1145 /* for framerate look to see if we are using vfr detelecine */
1146 if ([[item objectForKey:@"JobIndexVideoFramerate"] intValue] == 0)
1148 if ([[item objectForKey:@"PictureDetelecine"] intValue] == 1)
1150 /* we are using same as source with vfr detelecine */
1151 videoInfo = [NSString stringWithFormat:@"%@ Framerate: Same as source (vfr detelecine)", videoInfo];
1155 /* we are using a variable framerate without dropping frames */
1156 videoInfo = [NSString stringWithFormat:@"%@ Framerate: Same as source (variable)", videoInfo];
1161 /* we have a specified, constant framerate */
1162 videoInfo = [NSString stringWithFormat:@"%@ Framerate: %@ (constant framerate)", videoInfo ,[item objectForKey:@"VideoFramerate"]];
1165 if ([[item objectForKey:@"VideoQualityType"] intValue] == 0)// Target Size MB
1167 videoInfo = [NSString stringWithFormat:@"%@ Target Size: %@(MB) (%d(kbps) abr)", videoInfo ,[item objectForKey:@"VideoTargetSize"],[[item objectForKey:@"VideoAvgBitrate"] intValue]];
1169 else if ([[item objectForKey:@"VideoQualityType"] intValue] == 1) // ABR
1171 videoInfo = [NSString stringWithFormat:@"%@ Bitrate: %d(kbps)", videoInfo ,[[item objectForKey:@"VideoAvgBitrate"] intValue]];
1175 videoInfo = [NSString stringWithFormat:@"%@ Constant Quality: %.2f", videoInfo ,[[item objectForKey:@"VideoQualitySlider"] floatValue]];
1178 [finalString appendString: @"Video: " withAttributes:detailBoldAttr];
1179 [finalString appendString: videoInfo withAttributes:detailAttr];
1180 [finalString appendString:@"\n" withAttributes:detailAttr];
1182 if ([[item objectForKey:@"VideoEncoder"] isEqualToString: @"H.264 (x264)"])
1184 [finalString appendString: @"x264 Options: " withAttributes:detailBoldAttr];
1185 [finalString appendString: [item objectForKey:@"x264Option"] withAttributes:detailAttr];
1186 [finalString appendString:@"\n" withAttributes:detailAttr];
1191 /* Seventh Line Audio Details*/
1192 if ([audioDetail1 length] != 0)
1194 [finalString appendString: @"Audio Track 1: " withAttributes:detailBoldAttr];
1195 [finalString appendString: audioDetail1 withAttributes:detailAttr];
1196 [finalString appendString:@"\n" withAttributes:detailAttr];
1199 if ([audioDetail2 length] != 0)
1201 [finalString appendString: @"Audio Track 2: " withAttributes:detailBoldAttr];
1202 [finalString appendString: audioDetail2 withAttributes:detailAttr];
1203 [finalString appendString:@"\n" withAttributes:detailAttr];
1206 if ([audioDetail3 length] != 0)
1208 [finalString appendString: @"Audio Track 3: " withAttributes:detailBoldAttr];
1209 [finalString appendString: audioDetail3 withAttributes:detailAttr];
1210 [finalString appendString:@"\n" withAttributes:detailAttr];
1213 if ([audioDetail4 length] != 0)
1215 [finalString appendString: @"Audio Track 4: " withAttributes:detailBoldAttr];
1216 [finalString appendString: audioDetail4 withAttributes:detailAttr];
1217 [finalString appendString:@"\n" withAttributes:detailAttr];
1219 /* Eighth Line Subtitle Details */
1222 NSEnumerator *enumerator = [[item objectForKey:@"SubtitleList"] objectEnumerator];
1224 while (tempObject = [enumerator nextObject])
1226 /* since the subtitleSourceTrackNum 0 is "None" in our array of the subtitle popups,
1227 * we want to ignore it for display as well as encoding.
1229 if ([[tempObject objectForKey:@"subtitleSourceTrackNum"] intValue] > 0)
1231 /* remember that index 0 of Subtitles can contain "Foreign Audio Search*/
1232 [finalString appendString: @"Subtitle: " withAttributes:detailBoldAttr];
1233 [finalString appendString: [tempObject objectForKey:@"subtitleSourceTrackName"] withAttributes:detailAttr];
1234 if ([[tempObject objectForKey:@"subtitleTrackForced"] intValue] == 1)
1236 [finalString appendString: @" - Forced Only" withAttributes:detailAttr];
1238 if ([[tempObject objectForKey:@"subtitleTrackBurned"] intValue] == 1)
1240 [finalString appendString: @" - Burned In" withAttributes:detailAttr];
1242 if ([[tempObject objectForKey:@"subtitleTrackDefault"] intValue] == 1)
1244 [finalString appendString: @" - Default" withAttributes:detailAttr];
1246 [finalString appendString:@"\n" withAttributes:detailAttr];
1253 else if ([[tableColumn identifier] isEqualToString:@"icon"])
1255 if ([[item objectForKey:@"Status"] intValue] == 0)
1257 return [NSImage imageNamed:@"EncodeComplete"];
1259 else if ([[item objectForKey:@"Status"] intValue] == 1)
1261 return [NSImage imageNamed: [NSString stringWithFormat: @"EncodeWorking%d", fAnimationIndex]];
1263 else if ([[item objectForKey:@"Status"] intValue] == 3)
1265 return [NSImage imageNamed:@"EncodeCanceled"];
1269 return [NSImage imageNamed:@"JobSmall"];
1279 - (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
1281 if ([[tableColumn identifier] isEqualToString:@"desc"])
1285 // nb: The "desc" column is currently an HBImageAndTextCell. However, we are longer
1286 // using the image portion of the cell so we could switch back to a regular NSTextFieldCell.
1288 // Set the image here since the value returned from outlineView:objectValueForTableColumn: didn't specify the image part
1289 [cell setImage:nil];
1291 else if ([[tableColumn identifier] isEqualToString:@"action"])
1293 [cell setEnabled: YES];
1294 BOOL highlighted = [outlineView isRowSelected:[outlineView rowForItem: item]] && [[outlineView window] isKeyWindow] && ([[outlineView window] firstResponder] == outlineView);
1295 if ([[item objectForKey:@"Status"] intValue] == 0)
1297 [cell setAction: @selector(revealSelectedQueueItem:)];
1300 [cell setImage:[NSImage imageNamed:@"RevealHighlight"]];
1301 [cell setAlternateImage:[NSImage imageNamed:@"RevealHighlightPressed"]];
1304 [cell setImage:[NSImage imageNamed:@"Reveal"]];
1308 [cell setAction: @selector(removeSelectedQueueItem:)];
1311 [cell setImage:[NSImage imageNamed:@"DeleteHighlight"]];
1312 [cell setAlternateImage:[NSImage imageNamed:@"DeleteHighlightPressed"]];
1315 [cell setImage:[NSImage imageNamed:@"Delete"]];
1320 - (void)outlineView:(NSOutlineView *)outlineView willDisplayOutlineCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
1322 // By default, the discolsure image gets centered vertically in the cell. We want
1323 // always at the top.
1324 if ([outlineView isItemExpanded: item])
1325 [cell setImagePosition: NSImageAbove];
1327 [cell setImagePosition: NSImageOnly];
1331 #pragma mark NSOutlineView delegate (dragging related)
1333 //------------------------------------------------------------------------------------
1334 // NSTableView delegate
1335 //------------------------------------------------------------------------------------
1338 - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pboard
1340 // Dragging is only allowed of the pending items.
1341 if ([[[items objectAtIndex:0] objectForKey:@"Status"] integerValue] != 2) // 2 is pending
1346 // Don't retain since this is just holding temporaral drag information, and it is
1347 //only used during a drag! We could put this in the pboard actually.
1348 fDraggedNodes = items;
1350 // Provide data for our custom type, and simple NSStrings.
1351 [pboard declareTypes:[NSArray arrayWithObjects: DragDropSimplePboardType, nil] owner:self];
1353 // the actual data doesn't matter since DragDropSimplePboardType drags aren't recognized by anyone but us!.
1354 [pboard setData:[NSData data] forType:DragDropSimplePboardType];
1360 /* This method is used to validate the drops. */
1361 - (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index
1363 // Don't allow dropping ONTO an item since they can't really contain any children.
1364 BOOL isOnDropTypeProposal = index == NSOutlineViewDropOnItemIndex;
1365 if (isOnDropTypeProposal)
1367 return NSDragOperationNone;
1370 // Don't allow dropping INTO an item since they can't really contain any children.
1373 index = [fOutlineView rowForItem: item] + 1;
1377 // NOTE: Should we allow dropping a pending job *above* the
1378 // finished or already encoded jobs ?
1379 // We do not let the user drop a pending job before or *above*
1380 // already finished or currently encoding jobs.
1381 if (index <= fEncodingQueueItem)
1383 return NSDragOperationNone;
1384 index = MAX (index, fEncodingQueueItem);
1387 [outlineView setDropItem:item dropChildIndex:index];
1388 return NSDragOperationGeneric;
1391 - (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)index
1393 NSMutableIndexSet *moveItems = [NSMutableIndexSet indexSet];
1395 for( id obj in fDraggedNodes )
1396 [moveItems addIndex:[fJobGroups indexOfObject:obj]];
1398 // Successful drop, we use moveObjectsInQueueArray:... in fHBController
1399 // to properly rearrange the queue array, save it to plist and then send it back here.
1400 // since Controller.mm is handling all queue array manipulation.
1401 // We *could do this here, but I think we are better served keeping that code together.
1402 [fHBController moveObjectsInQueueArray:fJobGroups fromIndexes:moveItems toIndex: index];