]> git.sesse.net Git - vlc/blobdiff - bin/darwinvlc.c
demux: ts: rewrite/split IOD parsing
[vlc] / bin / darwinvlc.c
index 8c016efc31a9ac36cc21fb698f39e444c8a641a7..fbad4152865033eb2e649bbd69841b3c5f0245db 100644 (file)
@@ -40,6 +40,8 @@
 # include <pthread.h>
 #endif
 #include <unistd.h>
+#include <TargetConditionals.h>
+#import <CoreFoundation/CoreFoundation.h>
 
 extern void vlc_enable_override (void);
 
@@ -146,7 +148,6 @@ int main( int i_argc, const char *ppsz_argv[] )
     sigaddset (&set, SIGCHLD);
 
     /* Block all these signals */
-    pthread_t self = pthread_self ();
     pthread_sigmask (SIG_SETMASK, &set, NULL);
 
     const char *argv[i_argc + 2];
@@ -154,6 +155,45 @@ int main( int i_argc, const char *ppsz_argv[] )
 
     argv[argc++] = "--no-ignore-config";
     argv[argc++] = "--media-library";
+
+    /* overwrite system language on Mac */
+#if !TARGET_OS_IPHONE && !TARGET_IPHONE_SIMULATOR // TARGET_OS_MAC is unspecific
+    char *lang = NULL;
+
+    for (int i = 0; i < i_argc; i++) {
+        if (!strncmp(ppsz_argv[i], "--language", 10)) {
+            lang = strstr(ppsz_argv[i], "=");
+            ppsz_argv++, i_argc--;
+            continue;
+        }
+    }
+    if (lang && strncmp( lang, "auto", 4 )) {
+        char tmp[11];
+        snprintf(tmp, 11, "LANG%s", lang);
+        putenv(tmp);
+    }
+
+    if (!lang) {
+        CFStringRef language;
+        language = (CFStringRef)CFPreferencesCopyAppValue(CFSTR("language"),
+                                                          kCFPreferencesCurrentApplication);
+        if (language) {
+            CFIndex length = CFStringGetLength(language) + 1;
+            if (length > 0) {
+                CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);
+                lang = (char *)malloc(maxSize);
+                CFStringGetCString(language, lang, maxSize - 1, kCFStringEncodingUTF8);
+            }
+            if (strncmp( lang, "auto", 4 )) {
+                char tmp[11];
+                snprintf(tmp, 11, "LANG=%s", lang);
+                putenv(tmp);
+            }
+            CFRelease(language);
+        }
+    }
+#endif
+
     ppsz_argv++; i_argc--; /* skip executable path */
 
     /* When VLC.app is run by double clicking in Mac OS X, the 2nd arg
@@ -169,6 +209,8 @@ int main( int i_argc, const char *ppsz_argv[] )
 
     vlc_enable_override ();
 
+    pthread_t self = pthread_self ();
+
     /* Initialize libvlc */
     libvlc_instance_t *vlc = libvlc_new (argc, argv);
     if (vlc == NULL)
@@ -179,13 +221,13 @@ int main( int i_argc, const char *ppsz_argv[] )
     libvlc_set_app_id (vlc, "org.VideoLAN.VLC", PACKAGE_VERSION, PACKAGE_NAME);
     libvlc_set_user_agent (vlc, "VLC media player", "VLC/"PACKAGE_VERSION);
 
+    libvlc_playlist_play (vlc, -1, 0, NULL);
+
     libvlc_add_intf (vlc, "hotkeys,none");
 
     if (libvlc_add_intf (vlc, NULL))
         goto out;
 
-    libvlc_playlist_play (vlc, -1, 0, NULL);
-
     /* Qt4 insists on catching SIGCHLD via signal handler. To work around that,
      * unblock it after all our child threads are created. */
     sigdelset (&set, SIGCHLD);