]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/open.m
Consistent strings to avoid duplications
[vlc] / modules / gui / macosx / open.m
index 565bd36a020eb7a71dbc3a44dd4987e00ed19112..d37d497e085555aa44c9438434a8deefdbdf7dec 100644 (file)
@@ -154,31 +154,24 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
     [o_disc_selector_pop removeAllItems];
     [o_disc_selector_pop setHidden: NO];
-    NSString *o_videots = _NS("Open VIDEO_TS folder");
-    NSString *o_bdmv = _NS("Open BDMV folder");
+    NSString *o_videots = _NS("Open VIDEO_TS / BDMV folder");
     [o_disc_nodisc_lbl setStringValue: _NS("Insert Disc")];
     [o_disc_nodisc_videots_btn setTitle: o_videots];
-    [o_disc_nodisc_bdmv_btn setTitle: o_bdmv];
     [o_disc_audiocd_lbl setStringValue: _NS("Audio CD")];
     [o_disc_audiocd_trackcount_lbl setStringValue: @""];
     [o_disc_audiocd_videots_btn setTitle: o_videots];
-    [o_disc_audiocd_bdmv_btn setTitle: o_bdmv];
     [o_disc_dvd_lbl setStringValue: @""];
     [o_disc_dvd_disablemenus_btn setTitle: _NS("Disable DVD menus")];
     [o_disc_dvd_videots_btn setTitle: o_videots];
-    [o_disc_dvd_bdmv_btn setTitle: o_bdmv];
     [o_disc_dvdwomenus_lbl setStringValue: @""];
     [o_disc_dvdwomenus_enablemenus_btn setTitle: _NS("Enable DVD menus")];
     [o_disc_dvdwomenus_videots_btn setTitle: o_videots];
-    [o_disc_dvdwomenus_bdmv_btn setTitle: o_bdmv];
     [o_disc_dvdwomenus_title_lbl setStringValue: _NS("Title")];
     [o_disc_dvdwomenus_chapter_lbl setStringValue: _NS("Chapter")];
     [o_disc_vcd_title_lbl setStringValue: _NS("Title")];
     [o_disc_vcd_chapter_lbl setStringValue: _NS("Chapter")];
     [o_disc_vcd_videots_btn setTitle: o_videots];
-    [o_disc_vcd_bdmv_btn setTitle: o_bdmv];
     [o_disc_bd_videots_btn setTitle: o_videots];
-    [o_disc_bd_bdmv_btn setTitle: o_bdmv];
 
     [o_net_udp_port_lbl setStringValue: _NS("Port")];
     [o_net_udpm_addr_lbl setStringValue: _NS("IP Address")];
@@ -243,9 +236,10 @@ static VLCOpen *_o_sharedMainInstance = nil;
         for (int ivideo = 0; ivideo < deviceCount; ivideo++) {
             QTCaptureDevice *qtk_device;
             qtk_device = [qtkvideoDevices objectAtIndex:ivideo];
-            [o_qtk_video_device_pop addItemWithTitle: [qtk_device localizedDisplayName]];
+            // allow same name for multiple times
+            [[o_qtk_video_device_pop menu] addItemWithTitle:[qtk_device localizedDisplayName] action:nil keyEquivalent:@""];
 
-            if ([[[qtk_device uniqueID]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:qtk_currdevice_uid])
+            if ([[[qtk_device uniqueID] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:qtk_currdevice_uid])
                 [o_qtk_video_device_pop selectItemAtIndex:ivideo];
         }
     } else {
@@ -265,11 +259,13 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
         NSUInteger deviceCount = [qtkaudioDevices count];
         for (int iaudio = 0; iaudio < deviceCount; iaudio++) {
-            QTCaptureDevice *qtkaudio_device;
-            qtkaudio_device = [qtkaudioDevices objectAtIndex:iaudio];
-            [o_qtk_audio_device_pop addItemWithTitle: [qtkaudio_device localizedDisplayName]];
-            [o_screen_qtk_audio_pop addItemWithTitle: [qtkaudio_device localizedDisplayName]];
-            if ([[[qtkaudio_device uniqueID]stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:qtkaudio_currdevice_uid]) {
+            QTCaptureDevice *qtkaudio_device = [qtkaudioDevices objectAtIndex:iaudio];
+
+            // allow same name for multiple times
+            [[o_qtk_audio_device_pop menu] addItemWithTitle:[qtkaudio_device localizedDisplayName] action:nil keyEquivalent:@""];
+            [[o_screen_qtk_audio_pop menu] addItemWithTitle:[qtkaudio_device localizedDisplayName] action:nil keyEquivalent:@""];
+
+            if ([[[qtkaudio_device uniqueID] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] isEqualToString:qtkaudio_currdevice_uid]) {
                 [o_qtk_audio_device_pop selectItemAtIndex:iaudio];
                 [o_screen_qtk_audio_pop selectItemAtIndex:iaudio];
             }
@@ -324,8 +320,9 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
     [[sharedWorkspace notificationCenter] addObserver:self selector:@selector(scanOpticalMedia:) name:NSWorkspaceDidMountNotification object:nil];
     [[sharedWorkspace notificationCenter] addObserver:self selector:@selector(scanOpticalMedia:) name:NSWorkspaceDidUnmountNotification object:nil];
-    [self performSelector:@selector(qtkToggleUIElements:) withObject:nil afterDelay:.3];
-    [self performSelector:@selector(scanOpticalMedia:) withObject:nil afterDelay:.5];
+
+    [self qtkToggleUIElements:nil];
+    [self scanOpticalMedia:nil];
 
     [self setMRL: @""];
 }
@@ -425,8 +422,6 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
     int i_result;
 
-    b_autoplay = config_GetInt(VLCIntf, "macosx-autoplay");
-
     [o_tabview selectTabViewItemAtIndex: i_type];
     [o_file_sub_ckbox setState: NSOffState];
 
@@ -463,7 +458,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
         if ([o_file_custom_timing_ckb state] == NSOnState) {
             NSArray * components = [[o_file_starttime_fld stringValue] componentsSeparatedByString:@":"];
             NSUInteger componentCount = [components count];
-            NSInteger tempValue;
+            NSInteger tempValue = 0;
             if (componentCount == 1)
                 tempValue = [[components objectAtIndex:0] intValue];
             else if (componentCount == 2)
@@ -522,10 +517,8 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
         /* apply the options to our item(s) */
         [o_dic setObject: (NSArray *)[o_options copy] forKey: @"ITEM_OPTIONS"];
-        if (b_autoplay)
-            [[[VLCMain sharedInstance] playlist] appendArray: [NSArray arrayWithObject:o_dic] atPos: -1 enqueue:NO];
-        else
-            [[[VLCMain sharedInstance] playlist] appendArray: [NSArray arrayWithObject:o_dic] atPos: -1 enqueue:YES];
+
+        [[[VLCMain sharedInstance] playlist] addPlaylistItems:[NSArray arrayWithObject:o_dic]];
     }
 }
 
@@ -663,7 +656,6 @@ static VLCOpen *_o_sharedMainInstance = nil;
 - (void)openFile
 {
     NSOpenPanel *o_open_panel = [NSOpenPanel openPanel];
-    b_autoplay = config_GetInt(VLCIntf, "macosx-autoplay");
 
     [o_open_panel setAllowsMultipleSelection: YES];
     [o_open_panel setCanChooseDirectories: YES];
@@ -691,10 +683,8 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
             [o_array addObject: o_dic];
         }
-        if (b_autoplay)
-            [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:NO];
-        else
-            [[[VLCMain sharedInstance] playlist] appendArray: o_array atPos: -1 enqueue:YES];
+
+        [[[VLCMain sharedInstance] playlist] addPlaylistItems:o_array];
     }
 }
 
@@ -831,7 +821,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
     [[[o_tabview tabViewItemAtIndex: [o_tabview indexOfTabViewItemWithIdentifier:@"optical"]] view] displayIfNeeded];
 }
 
-- (NSString *) getBSDNodeFromMountPath:(NSString *)mountPath
++ (NSString *) getBSDNodeFromMountPath:(NSString *)mountPath
 {
     OSStatus err;
     FSRef ref;
@@ -866,7 +856,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
     return @"";
 }
 
-- (NSString *)getVolumeTypeFromMountPath:(NSString *)mountPath
++ (NSString *)getVolumeTypeFromMountPath:(NSString *)mountPath
 {
     OSStatus err;
     FSRef ref;
@@ -886,10 +876,10 @@ static VLCOpen *_o_sharedMainInstance = nil;
         if (noErr == err)
             actualVolume = catalogInfo.volume;
         else
-            return NULL;
+            goto out;
     }
     else
-        return NULL;
+        goto out;
 
     GetVolParmsInfoBuffer volumeParms;
     err = FSGetVolumeParms(actualVolume, &volumeParms, sizeof(volumeParms));
@@ -897,66 +887,70 @@ static VLCOpen *_o_sharedMainInstance = nil;
     CFMutableDictionaryRef matchingDict;
     io_service_t service;
 
-    if (!volumeParms.vMDeviceID)
-        return NULL;
+    if (!volumeParms.vMDeviceID) {
+        goto out;
+    }
 
     matchingDict = IOBSDNameMatching(kIOMasterPortDefault, 0, volumeParms.vMDeviceID);
     service = IOServiceGetMatchingService(kIOMasterPortDefault, matchingDict);
 
-    NSString *returnValue;
+
+    NSString *returnValue = nil;
     if (IO_OBJECT_NULL != service) {
-        if (IOObjectConformsTo(service, kIOCDMediaClass)) {
+        if (IOObjectConformsTo(service, kIOCDMediaClass))
             returnValue = kVLCMediaAudioCD;
-        }
         else if (IOObjectConformsTo(service, kIODVDMediaClass))
             returnValue = kVLCMediaDVD;
         else if (IOObjectConformsTo(service, kIOBDMediaClass))
             returnValue = kVLCMediaBD;
-        else {
-            if ([mountPath rangeOfString:@"VIDEO_TS" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
-                returnValue = kVLCMediaVideoTSFolder;
-            else if ([mountPath rangeOfString:@"BDMV" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
-                returnValue = kVLCMediaBDMVFolder;
-            else {
-                // NSFileManager is not thread-safe, don't use defaultManager outside of the main thread
-                NSFileManager * fm = [[NSFileManager alloc] init];
-
-                NSArray *dirContents = [fm contentsOfDirectoryAtPath:mountPath error:nil];
-                for (int i = 0; i < [dirContents count]; i++) {
-                    NSString *currentFile = [dirContents objectAtIndex:i];
-                    NSString *fullPath = [mountPath stringByAppendingPathComponent:currentFile];
-
-                    BOOL isDir;
-                    if ([fm fileExistsAtPath:fullPath isDirectory:&isDir] && isDir)
-                    {
-                        if ([currentFile caseInsensitiveCompare:@"SVCD"] == NSOrderedSame) {
-                            returnValue = kVLCMediaSVCD;
-                            break;
-                        }
-                        if ([currentFile caseInsensitiveCompare:@"VCD"] == NSOrderedSame) {
-                            returnValue = kVLCMediaVCD;
-                            break;
-                        }
-                        if ([currentFile caseInsensitiveCompare:@"BDMV"] == NSOrderedSame) {
-                            returnValue = kVLCMediaBDMVFolder;
-                            break;
-                        }
-                        if ([currentFile caseInsensitiveCompare:@"VIDEO_TS"] == NSOrderedSame) {
-                            returnValue = kVLCMediaVideoTSFolder;
-                            break;
-                        }
-                    }
-                }
+        IOObjectRelease(service);
 
-                [fm release];
+        if (returnValue)
+            return returnValue;
+    }
 
-                if (!returnValue)
+out:
+    if ([mountPath rangeOfString:@"VIDEO_TS" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
+        returnValue = kVLCMediaVideoTSFolder;
+    else if ([mountPath rangeOfString:@"BDMV" options:NSCaseInsensitiveSearch | NSBackwardsSearch].location != NSNotFound)
+        returnValue = kVLCMediaBDMVFolder;
+    else {
+        // NSFileManager is not thread-safe, don't use defaultManager outside of the main thread
+        NSFileManager * fm = [[NSFileManager alloc] init];
+
+        NSArray *dirContents = [fm contentsOfDirectoryAtPath:mountPath error:nil];
+        for (int i = 0; i < [dirContents count]; i++) {
+            NSString *currentFile = [dirContents objectAtIndex:i];
+            NSString *fullPath = [mountPath stringByAppendingPathComponent:currentFile];
+
+            BOOL isDir;
+            if ([fm fileExistsAtPath:fullPath isDirectory:&isDir] && isDir)
+            {
+                if ([currentFile caseInsensitiveCompare:@"SVCD"] == NSOrderedSame) {
+                    returnValue = kVLCMediaSVCD;
+                    break;
+                }
+                if ([currentFile caseInsensitiveCompare:@"VCD"] == NSOrderedSame) {
+                    returnValue = kVLCMediaVCD;
+                    break;
+                }
+                if ([currentFile caseInsensitiveCompare:@"BDMV"] == NSOrderedSame) {
+                    returnValue = kVLCMediaBDMVFolder;
+                    break;
+                }
+                if ([currentFile caseInsensitiveCompare:@"VIDEO_TS"] == NSOrderedSame) {
                     returnValue = kVLCMediaVideoTSFolder;
+                    break;
+                }
             }
         }
 
-        IOObjectRelease(service);
+        [fm release];
+
+        if (!returnValue)
+            returnValue = kVLCMediaVideoTSFolder;
     }
+
     return returnValue;
 }
 
@@ -1005,17 +999,24 @@ static VLCOpen *_o_sharedMainInstance = nil;
 
 - (NSDictionary *)scanPath:(NSString *)o_path
 {
-    NSString *o_type = [self getVolumeTypeFromMountPath:o_path];
+    NSString *o_type = [VLCOpen getVolumeTypeFromMountPath:o_path];
     NSImage *o_image = [[NSWorkspace sharedWorkspace] iconForFile: o_path];
     NSString *o_device_path;
 
+    // BDMV path must not end with BDMV directory
+    if([o_type isEqualToString: kVLCMediaBDMVFolder]) {
+        if([[o_path lastPathComponent] isEqualToString: @"BDMV"]) {
+            o_path = [o_path stringByDeletingLastPathComponent];
+        }
+    }
+
     if ([o_type isEqualToString: kVLCMediaVideoTSFolder] ||
         [o_type isEqualToString: kVLCMediaBD] ||
         [o_type isEqualToString: kVLCMediaBDMVFolder] ||
         [o_type isEqualToString: kVLCMediaUnknown])
         o_device_path = o_path;
     else
-        o_device_path = [self getBSDNodeFromMountPath:o_path];
+        o_device_path = [VLCOpen getBSDNodeFromMountPath:o_path];
 
     return [NSDictionary dictionaryWithObjectsAndKeys: o_path, @"path",
                                                 o_device_path, @"devicePath",
@@ -1489,7 +1490,7 @@ static VLCOpen *_o_sharedMainInstance = nil;
     if (channels) {
         NSString *channel;
         [[o_eyetv_channels_pop menu] addItem: [NSMenuItem separatorItem]];
-        while (channel = [channels nextObject])
+        while ((channel = [channels nextObject]) != nil)
             /* we have to add items this way, because we accept duplicates
              * additionally, we save a bit of time */
             [[[o_eyetv_channels_pop menu] addItemWithTitle: channel action: nil keyEquivalent: @""] setTag:++x];