[vlc-devel] [PATCH] gui: macosx: simplify saving of playlist

Filip Roséen filip at atch.se
Thu Jul 26 11:42:38 CEST 2018


---
 modules/gui/macosx/VLCMainMenu.m | 63 +++++++++++---------------------
 1 file changed, 22 insertions(+), 41 deletions(-)

diff --git a/modules/gui/macosx/VLCMainMenu.m b/modules/gui/macosx/VLCMainMenu.m
index e0a22d6506..d3bf3cb4ac 100644
--- a/modules/gui/macosx/VLCMainMenu.m
+++ b/modules/gui/macosx/VLCMainMenu.m
@@ -1169,50 +1169,31 @@
 
     if ([savePanel runModal] == NSFileHandlingPanelOKButton) {
         NSString *filename = [[savePanel URL] path];
+        NSString *ext;
+        char const* psz_module;
+
+        switch ([_playlistSaveAccessoryPopup indexOfSelectedItem]) {
+            case 0: psz_module = "export-m3u";
+                    ext = @"m3u";
+                    break;
+            case 1: psz_module = "export-xspf";
+                    ext = @"xspf";
+                    break;
+            case 2: psz_module = "export-html";
+                    ext = @"html";
+                    break;
+            default:
+                    return;
+        }
 
-        if ([_playlistSaveAccessoryPopup indexOfSelectedItem] == 0) {
-            NSString *actualFilename;
-            NSRange range;
-            range.location = [filename length] - [@".m3u" length];
-            range.length = [@".m3u" length];
-
-            if ([filename compare:@".m3u" options: NSCaseInsensitiveSearch range: range] != NSOrderedSame)
-                actualFilename = [NSString stringWithFormat: @"%@.m3u", filename];
-            else
-                actualFilename = filename;
-
-            playlist_Export(p_playlist,
-                            [actualFilename fileSystemRepresentation],
-                            "export-m3u");
-        } else if ([_playlistSaveAccessoryPopup indexOfSelectedItem] == 1) {
-            NSString *actualFilename;
-            NSRange range;
-            range.location = [filename length] - [@".xspf" length];
-            range.length = [@".xspf" length];
-
-            if ([filename compare:@".xspf" options: NSCaseInsensitiveSearch range: range] != NSOrderedSame)
-                actualFilename = [NSString stringWithFormat: @"%@.xspf", filename];
-            else
-                actualFilename = filename;
-
-            playlist_Export(p_playlist,
-                            [actualFilename fileSystemRepresentation],
-                            "export-xspf");
-        } else {
-            NSString *actualFilename;
-            NSRange range;
-            range.location = [filename length] - [@".html" length];
-            range.length = [@".html" length];
+        NSString *actualFilename = filename;
 
-            if ([filename compare:@".html" options: NSCaseInsensitiveSearch range: range] != NSOrderedSame)
-                actualFilename = [NSString stringWithFormat: @"%@.html", filename];
-            else
-                actualFilename = filename;
+        if ([[filename pathExtension] caseInsensitiveCompare:ext] != NSOrderedSame)
+            actualFilename = [NSString stringWithFormat: @"%@.%@", filename, ext];
 
-            playlist_Export(p_playlist,
-                            [actualFilename fileSystemRepresentation],
-                            "export-html");
-        }
+        playlist_Export(p_playlist,
+                        [actualFilename fileSystemRepresentation],
+                        psz_module);
     }
 }
 
-- 
2.18.0


More information about the vlc-devel mailing list