summaryrefslogtreecommitdiffstats
path: root/macosx/ChapterTitles.m
diff options
context:
space:
mode:
authorRodeo <[email protected]>2013-05-11 19:38:49 +0000
committerRodeo <[email protected]>2013-05-11 19:38:49 +0000
commit7479f4af01737781d00bf48deb3b3d923ee8d664 (patch)
tree2850e93c593e9b503fa82a5ee6a1f3b99f3659ac /macosx/ChapterTitles.m
parenta09e24030d455e435096be0dbaf4370c5696d787 (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/ChapterTitles.m')
-rw-r--r--macosx/ChapterTitles.m89
1 files changed, 43 insertions, 46 deletions
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