Skip to content
This repository
Newer
Older
100644 114 lines (89 sloc) 1.946 kb
1ee8796b »
2010-06-16 Add chapter class
1 //
2 // Chapter.m
3 // AudioBookBinder
4 //
5 // Created by Oleksandr Tymoshenko on 10-06-11.
6 // Copyright 2010 Bluezbox Software. All rights reserved.
7 //
8
9 #import "Chapter.h"
10
11
12 @implementation Chapter
13
cca12305 »
2010-06-26 Add chapter support for GUI version of binder
14 @synthesize name, files;
1ee8796b »
2010-06-16 Add chapter class
15
16 - (id) init
17 {
18 if (self = [super init]) {
cca12305 »
2010-06-26 Add chapter support for GUI version of binder
19 files = [[NSMutableArray alloc] init];
1ee8796b »
2010-06-16 Add chapter class
20 name = nil;
21 }
22
23 return self;
24 }
25
ddeccf60 »
2010-07-25 Refactoring for multi-volume support
26 - (void)dealloc
27 {
28 [name release];
29 [files release];
30 [super dealloc];
31 }
32
33 - (id)copy
34 {
35 Chapter *c = [[Chapter alloc] init];
36 c.name = name;
37 [c addFiles:files];
38 return c;
39 }
40
1ee8796b »
2010-06-16 Add chapter class
41 - (void) addFile:(AudioFile *)file
42 {
cca12305 »
2010-06-26 Add chapter support for GUI version of binder
43 [files addObject:file];
44 }
45
46 - (void) addFiles:(NSArray *)newFiles
47 {
48 [files addObjectsFromArray:newFiles];
1ee8796b »
2010-06-16 Add chapter class
49 }
50
51 - (BOOL) containsFile:(AudioFile*)file
52 {
cca12305 »
2010-06-26 Add chapter support for GUI version of binder
53 return [files containsObject:file];
54 }
55
56 - (int) totalFiles
57 {
58 return [files count];
59 }
60
61 - (AudioFile*) fileAtIndex:(NSInteger)index
62 {
63 return [files objectAtIndex:index];
64 }
65
66 - (void) removeFile:(AudioFile*)file
67 {
68 [files removeObject:file];
1ee8796b »
2010-06-16 Add chapter class
69 }
70
cca12305 »
2010-06-26 Add chapter support for GUI version of binder
71 - (void) insertFile:(AudioFile*)file atIndex:(NSInteger)index
72 {
73 [files insertObject:file atIndex:index];
74 }
75
76
1ee8796b »
2010-06-16 Add chapter class
77 - (UInt32) totalDuration
78 {
79 UInt32 duration = 0;
cca12305 »
2010-06-26 Add chapter support for GUI version of binder
80 for (AudioFile *file in files) {
7a301b33 »
2011-05-29 Add sorting by column
81 duration += [[file duration] intValue];
1ee8796b »
2010-06-16 Add chapter class
82 }
83
84 return duration;
85 }
86
ddeccf60 »
2010-07-25 Refactoring for multi-volume support
87
88 // splits chapter into two. All files prior to given file
89 // remain in this chapter, the rest goes to newly-created
90 // chapter
91 - (Chapter*) splitAtFile:(AudioFile*)file
92 {
93
94 NSUInteger idx = [files indexOfObject:file];
95 if (idx == NSNotFound)
96 return nil;
97 Chapter *c = [[Chapter alloc] init];
98 c.name = name;
99 while (idx < [files count]) {
100 AudioFile *f = [files objectAtIndex:idx];
101 [c addFile:f];
102 [files removeObjectAtIndex:idx];
103 }
104
105 return c;
106 }
107
7a301b33 »
2011-05-29 Add sorting by column
108 - (void) sortUsingDecriptor:(NSSortDescriptor*)descriptor
109 {
110 [files sortUsingDescriptors:[NSArray arrayWithObject:descriptor]];
111 }
112
113
1ee8796b »
2010-06-16 Add chapter class
114 @end
Something went wrong with that request. Please try again.