]> git.sesse.net Git - vlc/blob - src/misc/darwin_specific.m
8478466db51b96dbe62bbb7d8137de97d9e256b1
[vlc] / src / misc / darwin_specific.m
1 /*****************************************************************************
2  * darwin_specific.m: Darwin specific features
3  *****************************************************************************
4  * Copyright (C) 2001-2004 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Sam Hocevar <sam@zoy.org>
8  *          Christophe Massiot <massiot@via.ecp.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
23  *****************************************************************************/
24 #include <string.h>                                              /* strdup() */
25 #include <stdlib.h>                                                /* free() */
26
27 #include <vlc/vlc.h>
28
29 #include <Cocoa/Cocoa.h>
30 #include <CoreFoundation/CFString.h>
31
32 #ifdef HAVE_LOCALE_H
33 #   include <locale.h>
34 #endif
35
36 /*****************************************************************************
37  * system_Init: fill in program path & retrieve language
38  *****************************************************************************/
39 static int FindLanguage( const char * psz_lang )
40 {
41     const char ** ppsz_parser;
42     const char * ppsz_all[] =
43     {
44         "Catalan", "ca",
45         "Danish", "da",
46         "German", "de",
47         "British", "en_GB",
48         "English", "en",
49         "Spanish", "es",
50         "French", "fr",
51         "Italian", "it",
52         "Japanese", "ja",
53         "Korean", "ko",
54         "Dutch", "nl",
55         "Brazillian Portuguese", "pt_BR",
56         "Romanian", "ro",
57         "Russian", "ru",
58         "Turkish", "tr",
59         "Simplified Chinese", "zh_CN", 
60         "Chinese Traditional", "zh_TW",
61         NULL
62     };
63
64     for( ppsz_parser = ppsz_all ; ppsz_parser[0] ; ppsz_parser += 2 )
65     {
66         if( !strcmp( psz_lang, ppsz_parser[0] )
67              || !strcmp( psz_lang, ppsz_parser[1] ) )
68         {
69             setenv( "LANG", ppsz_parser[1], 1 );
70             return 1;
71         }
72     }
73
74     return 0;
75 }
76
77 void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
78 {
79     char i_dummy;
80     char *p_char, *p_oldchar = &i_dummy;
81
82     /* Get the full program path and name */
83     p_char = p_this->p_libvlc->psz_vlcpath = strdup( ppsz_argv[ 0 ] );
84
85     /* Remove trailing program name */
86     for( ; *p_char ; )
87     {
88         if( *p_char == '/' )
89         {
90             *p_oldchar = '/';
91             *p_char = '\0';
92             p_oldchar = p_char;
93         }
94
95         p_char++;
96     }
97
98     /* Check if $LANG is set. */
99     if ( (p_char = getenv("LANG")) == NULL )
100     {
101         NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
102
103         /* Retrieve user's preferences. */
104         NSUserDefaults * o_defs = [NSUserDefaults standardUserDefaults];
105         NSArray * o_languages = [o_defs objectForKey:@"AppleLanguages"];
106         NSEnumerator * o_enumerator = [o_languages objectEnumerator];
107         NSString * o_lang;
108
109         while ( (o_lang = [o_enumerator nextObject]) )
110         {
111             const char * psz_string = [o_lang lossyCString];
112             if ( FindLanguage( psz_string ) )
113             {
114                 break;
115             }
116         }
117
118         [o_pool release];
119     }
120
121     vlc_mutex_init( p_this, &p_this->p_libvlc->iconv_lock );
122     p_this->p_libvlc->iconv_macosx = vlc_iconv_open( "UTF-8", "UTF-8-MAC" );
123 }
124
125 /*****************************************************************************
126  * system_Configure: check for system specific configuration options.
127  *****************************************************************************/
128 void system_Configure( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
129 {
130
131 }
132
133 /*****************************************************************************
134  * system_End: free the program path.
135  *****************************************************************************/
136 void system_End( vlc_t *p_this )
137 {
138     free( p_this->p_libvlc->psz_vlcpath );
139
140     if ( p_this->p_libvlc->iconv_macosx != (vlc_iconv_t)-1 )
141         vlc_iconv_close( p_this->p_libvlc->iconv_macosx );
142     vlc_mutex_destroy( &p_this->p_libvlc->iconv_lock );
143 }
144