summaryrefslogtreecommitdiffstats
path: root/macosx/HBLanguagesSelection.m
diff options
context:
space:
mode:
authorritsuka <[email protected]>2014-07-29 18:38:01 +0000
committerritsuka <[email protected]>2014-07-29 18:38:01 +0000
commit56680a9b967772ca6eb9112ac6f2a9e9bbe7244b (patch)
treefa4ec9a0b75a63313b566325920225e666dcea42 /macosx/HBLanguagesSelection.m
parent6dc3dd8351bec754610bbed5fff5bfe3f5738b01 (diff)
MacGui: Implemented a configuration panel similar to the win/lin gui one for the subtitles defaults, and added some more options from the other guis (add all, remove all).
The SubtitleAddForeignAudioSubtitle setting will be added later after the automatic audio selection is done. Fixed a bug where HandBrake used 50% of cpu time if the subtitles table view was selected. Refactored a big part of HBSubtitlesController to make it works with the new automatic options and to cleaned the table view data source. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6241 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'macosx/HBLanguagesSelection.m')
-rw-r--r--macosx/HBLanguagesSelection.m123
1 files changed, 123 insertions, 0 deletions
diff --git a/macosx/HBLanguagesSelection.m b/macosx/HBLanguagesSelection.m
new file mode 100644
index 000000000..8a27ad9c1
--- /dev/null
+++ b/macosx/HBLanguagesSelection.m
@@ -0,0 +1,123 @@
+/* HBLanguagesSelection.m $
+
+ This file is part of the HandBrake source code.
+ Homepage: <http://handbrake.fr/>.
+ It may be used under the terms of the GNU General Public License. */
+
+#import "HBLanguagesSelection.h"
+#include "lang.h"
+
+@implementation HBLang
+
+- (instancetype)initWithLanguage:(NSString *)value iso639_2code:(NSString *)code
+{
+ self = [super init];
+ if (self)
+ {
+ _language = [value retain];
+ _iso639_2 = [code retain];
+ }
+ return self;
+}
+
+- (void)dealloc
+{
+ [super dealloc];
+ [_language release];
+}
+
+@end
+
+@implementation HBLanguagesSelection
+
+- (instancetype)initWithLanguages:(NSArray *)languages
+{
+ self = [super init];
+ if (self)
+ {
+ NSMutableArray *internal = [[NSMutableArray alloc] init];
+
+ int insertedItems = 0;
+ const iso639_lang_t *lang = lang_get_next(NULL);
+ for (lang = lang_get_next(lang); lang != NULL; lang = lang_get_next(lang))
+ {
+ HBLang *item = [[[HBLang alloc] initWithLanguage:@(lang->eng_name)
+ iso639_2code:@(lang->iso639_2)] autorelease];
+ if ([languages containsObject:item.iso639_2])
+ {
+ item.isSelected = YES;
+ [internal insertObject:item atIndex:insertedItems++];
+ }
+ else
+ {
+ [internal addObject:item];
+ }
+ }
+
+ // Add the (Any) item.
+ HBLang *item = [[[HBLang alloc] initWithLanguage:@"(Any)"
+ iso639_2code:@"und"] autorelease];
+ if ([languages containsObject:item.iso639_2])
+ {
+ item.isSelected = YES;
+ }
+ [internal insertObject:item atIndex:0];
+
+ _languagesArray = internal;
+ }
+
+ return self;
+}
+
+- (NSArray *)selectedLanguages
+{
+ NSMutableArray *selected = [[[NSMutableArray alloc] init] autorelease];
+ for (HBLang *lang in self.languagesArray)
+ {
+ if (lang.isSelected)
+ {
+ [selected addObject:lang.iso639_2];
+ }
+ }
+
+ return [[selected copy] autorelease];
+}
+
+- (void)dealloc
+{
+ [super dealloc];
+ [_languagesArray release];
+}
+
+@end
+
+NSString *kHBLanguagesDragRowsType = @"kHBLanguagesDragRowsType";
+
+@implementation HBLanguageArrayController
+
+- (void)setShowSelectedOnly:(BOOL)showSelectedOnly
+{
+ _showSelectedOnly = showSelectedOnly;
+ [self rearrangeObjects];
+}
+
+- (NSArray *)arrangeObjects:(NSArray *)objects
+{
+ if (!self.showSelectedOnly) {
+ return [super arrangeObjects:objects];
+ }
+
+ // Returns a filtered array with only the selected items
+ NSMutableArray *filteredObjects = [NSMutableArray arrayWithCapacity:[objects count]];
+ for (id item in objects)
+ {
+ if ([[item valueForKeyPath:@"isSelected"] boolValue])
+ {
+ [filteredObjects addObject:item];
+ }
+ }
+
+ return [super arrangeObjects:filteredObjects];
+}
+
+@end