]> git.sesse.net Git - vlc/blob - src/misc/darwin_specific.m
9906681ad79862a94fa52c24785554f0921f1091
[vlc] / src / misc / darwin_specific.m
1 /*****************************************************************************
2  * darwin_specific.m: Darwin specific features
3  *****************************************************************************
4  * Copyright (C) 2001-2004 VideoLAN
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
31 #ifdef HAVE_LOCALE_H
32 #   include <locale.h>
33 #endif
34
35 /*****************************************************************************
36  * system_Init: fill in program path & retrieve language
37  *****************************************************************************/
38 static int FindLanguage( const char * psz_lang )
39 {
40     const char ** ppsz_parser;
41     const char * ppsz_all[] =
42     {
43         "Bengali", "bn",
44         "Catalan", "ca",
45         "Danish", "da",
46         "German", "de",
47         "Modern Greek", "el",
48         "British", "en_GB",
49         "English", "en",
50         "Spanish", "es",
51         "French", "fr",
52         "Hindi", "hi",
53         "Hungarian", "hu",
54         "Italian", "it",
55         "Japanese", "ja",
56         "Burmese", "my",
57         "Nepali", "ne",
58         "Dutch", "nl",
59         "Norwegian", "no",
60         "Polish", "pl",
61         "Pashto", "ps",
62         "Brazillian Portuguese", "pt_BR",
63         "Russian", "ru",
64         "Swedish", "sv",
65         "Tetum", "tet",
66         "Tagalog", "tl",
67         "Chinese Traditional", "zh_TW",
68         NULL
69     };
70
71     for( ppsz_parser = ppsz_all ; ppsz_parser[0] ; ppsz_parser += 2 )
72     {
73         if( !strcmp( psz_lang, ppsz_parser[0] )
74              || !strcmp( psz_lang, ppsz_parser[1] ) )
75         {
76             setenv( "LANG", ppsz_parser[1], 1 );
77             return 1;
78         }
79     }
80
81     return 0;
82 }
83
84 void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
85 {
86     char i_dummy;
87     char *p_char, *p_oldchar = &i_dummy;
88
89     /* Get the full program path and name */
90     p_char = p_this->p_libvlc->psz_vlcpath = strdup( ppsz_argv[ 0 ] );
91
92     /* Remove trailing program name */
93     for( ; *p_char ; )
94     {
95         if( *p_char == '/' )
96         {
97             *p_oldchar = '/';
98             *p_char = '\0';
99             p_oldchar = p_char;
100         }
101
102         p_char++;
103     }
104
105     /* Check if $LANG is set. */
106     if ( (p_char = getenv("LANG")) == NULL )
107     {
108         NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
109
110         /* Retrieve user's preferences. */
111         NSUserDefaults * o_defs = [NSUserDefaults standardUserDefaults];
112         NSArray * o_languages = [o_defs objectForKey:@"AppleLanguages"];
113         NSEnumerator * o_enumerator = [o_languages objectEnumerator];
114         NSString * o_lang;
115
116         while ( (o_lang = [o_enumerator nextObject]) )
117         {
118             const char * psz_string = [o_lang lossyCString];
119             if ( FindLanguage( psz_string ) )
120             {
121                 break;
122             }
123         }
124
125         [o_pool release];
126     }
127 }
128
129 /*****************************************************************************
130  * system_Configure: check for system specific configuration options.
131  *****************************************************************************/
132 void system_Configure( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
133 {
134
135 }
136
137 /*****************************************************************************
138  * system_End: free the program path.
139  *****************************************************************************/
140 void system_End( vlc_t *p_this )
141 {
142     free( p_this->p_libvlc->psz_vlcpath );
143 }
144