diff options
author | Rodeo <[email protected]> | 2013-05-11 19:38:49 +0000 |
---|---|---|
committer | Rodeo <[email protected]> | 2013-05-11 19:38:49 +0000 |
commit | 7479f4af01737781d00bf48deb3b3d923ee8d664 (patch) | |
tree | 2850e93c593e9b503fa82a5ee6a1f3b99f3659ac /macosx | |
parent | a09e24030d455e435096be0dbaf4370c5696d787 (diff) |
MacGui: refactor handling on chapter titles.
job->list_chapters is reset by any call to hb_job_reset(), so store chapter titles in an NSArray instead.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@5451 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/ChapterTitles.h | 6 | ||||
-rw-r--r-- | macosx/ChapterTitles.m | 89 | ||||
-rw-r--r-- | macosx/Controller.m | 14 |
3 files changed, 49 insertions, 60 deletions
diff --git a/macosx/ChapterTitles.h b/macosx/ChapterTitles.h index 94d06c806..4b6a3fb07 100644 --- a/macosx/ChapterTitles.h +++ b/macosx/ChapterTitles.h @@ -8,12 +8,16 @@ #include "hb.h" @interface ChapterTitles : NSObject { - hb_title_t *fTitle; + hb_title_t *fTitle; + NSMutableArray *fChapterTitlesArray; } // Trigger a refresh of data - (void)resetWithTitle:(hb_title_t *)title; +// Get the list of chapter titles +- (NSArray*)chapterTitlesArray; + // Table View Delegates - (int)numberOfRowsInTableView:(NSTableView *)aTableView; diff --git a/macosx/ChapterTitles.m b/macosx/ChapterTitles.m index 2fcd77272..d568af8a4 100644 --- a/macosx/ChapterTitles.m +++ b/macosx/ChapterTitles.m @@ -11,50 +11,62 @@ - (id)init { self = [super init]; - if( self != nil ) + if (self != nil) { - fTitle = NULL; + fTitle = NULL; + fChapterTitlesArray = [[[NSMutableArray alloc] init] retain]; } - return self; } +- (void)dealloc +{ + [fChapterTitlesArray release]; + [super dealloc]; +} + - (void)resetWithTitle:(hb_title_t *)title { - int i; - NSString *chapterString; - fTitle = title; + [fChapterTitlesArray removeAllObjects]; - if (!title) + if (fTitle == NULL) return; - hb_job_t * job = title->job; - int count = hb_list_count( job->list_chapter ); - - for( i = 0; i < count; i++ ) + for (int i = 0; i < hb_list_count(fTitle->job->list_chapter); i++) { - hb_chapter_t *chapter = hb_list_item( job->list_chapter, i ); - - if( chapter != NULL && chapter->title == NULL ) + hb_chapter_t *chapter = hb_list_item(fTitle->job->list_chapter, i); + if (chapter != NULL) { - chapterString = [NSString stringWithFormat:@"Chapter %2d",(i+1)]; - - hb_chapter_set_title( chapter, [chapterString UTF8String]); + if (chapter->title != NULL) + { + [fChapterTitlesArray addObject:[NSString + stringWithUTF8String:chapter->title]]; + } + else + { + [fChapterTitlesArray addObject:[NSString + stringWithFormat:@"Chapter %d", + i + 1]]; + } } } - +} + +- (NSArray*)chapterTitlesArray +{ + return [NSArray arrayWithArray:fChapterTitlesArray]; } - (int)numberOfRowsInTableView:(NSTableView *)aTableView { - if( fTitle == NULL ) + if (fTitle == NULL) { return 0; } else { - return hb_list_count( fTitle->list_chapter ); + return [fChapterTitlesArray count]; } } @@ -63,17 +75,12 @@ forTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { - if(aTableColumn != nil && [[aTableColumn identifier] intValue] == 2) + if (aTableColumn != nil && [[aTableColumn identifier] intValue] == 2 && + fTitle != NULL) { - if( fTitle ) - { - hb_chapter_t *chapter = hb_list_item( fTitle->job->list_chapter, rowIndex ); - - if( chapter != NULL ) - { - hb_chapter_set_title( chapter, [anObject UTF8String]); - } - } + [fChapterTitlesArray replaceObjectAtIndex:rowIndex + withObject:[NSString + stringWithString:anObject]]; } } @@ -81,26 +88,16 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex { - NSString *cellEntry = @"__DATA ERROR__"; - - if([[aTableColumn identifier] intValue] == 1) + if ([[aTableColumn identifier] intValue] == 1) { - cellEntry = [NSString stringWithFormat:@"%d",rowIndex+1]; + return [NSString stringWithFormat:@"%d", rowIndex + 1]; } - else + else if (fTitle != NULL) { - if( fTitle ) - { - hb_chapter_t *chapter = hb_list_item( fTitle->job->list_chapter, rowIndex ); - - if( chapter != NULL ) - { - cellEntry = [NSString stringWithUTF8String:chapter->title]; - } - } + return [NSString stringWithString:[fChapterTitlesArray + objectAtIndex:rowIndex]]; } - - return cellEntry; + return @"__DATA ERROR__"; } /* Method to edit the next chapter when the user presses Return. We have to use diff --git a/macosx/Controller.m b/macosx/Controller.m index a94a2e177..c95ee6aa1 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -2566,19 +2566,7 @@ fWorkingCount = 0; * in our queue, so they can be reapplied in prepareJob when this queue * item comes up if Chapter Markers is set to on. */ - int i; - NSMutableArray *ChapterNamesArray = [[NSMutableArray alloc] init]; - int chaptercount = hb_list_count( fTitle->job->list_chapter ); - for( i = 0; i < chaptercount; i++ ) - { - hb_chapter_t *chapter = (hb_chapter_t *) hb_list_item( fTitle->job->list_chapter, i ); - if( chapter != NULL ) - { - [ChapterNamesArray addObject:[NSString stringWithUTF8String:chapter->title]]; - } - } - [queueFileJob setObject:[NSMutableArray arrayWithArray: ChapterNamesArray] forKey:@"ChapterNames"]; - [ChapterNamesArray autorelease]; + [queueFileJob setObject:[fChapterTitlesDelegate chapterTitlesArray] forKey:@"ChapterNames"]; /* Allow Mpeg4 64 bit formatting +4GB file sizes */ [queueFileJob setObject:[NSNumber numberWithInt:[fDstMp4LargeFileCheck state]] forKey:@"Mp4LargeFile"]; |