darwin_specific.m 4.05 KB
Newer Older
Sam Hocevar's avatar
   
Sam Hocevar committed
1
/*****************************************************************************
2
 * darwin_specific.m: Darwin specific features
Sam Hocevar's avatar
   
Sam Hocevar committed
3
 *****************************************************************************
zorglub's avatar
zorglub committed
4
 * Copyright (C) 2001-2004 VideoLAN
hartman's avatar
-    
hartman committed
5
 * $Id$
Sam Hocevar's avatar
   
Sam Hocevar committed
6
 *
7
 * Authors: Sam Hocevar <sam@zoy.org>
8
 *          Christophe Massiot <massiot@via.ecp.fr>
Sam Hocevar's avatar
   
Sam Hocevar committed
9
10
11
12
13
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
14
 *
Sam Hocevar's avatar
   
Sam Hocevar committed
15
16
17
18
19
20
21
22
23
24
25
26
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
 *****************************************************************************/
#include <string.h>                                              /* strdup() */
#include <stdlib.h>                                                /* free() */

27
#include <vlc/vlc.h>
Sam Hocevar's avatar
   
Sam Hocevar committed
28

29
30
#include <Cocoa/Cocoa.h>

31
32
33
34
#ifdef HAVE_LOCALE_H
#   include <locale.h>
#endif

Sam Hocevar's avatar
   
Sam Hocevar committed
35
/*****************************************************************************
36
 * system_Init: fill in program path & retrieve language
Sam Hocevar's avatar
   
Sam Hocevar committed
37
 *****************************************************************************/
38
39
static int FindLanguage( const char * psz_lang )
{
40
41
    const char ** ppsz_parser;
    const char * ppsz_all[] =
42
    {
43
        "Catalan", "ca",
44
        "Danish", "da",
45
46
        "German", "de",
        "British", "en_GB",
47
        "English", "en",
48
        "Spanish", "es",
49
50
51
52
        "French", "fr",
        "Italian", "it",
        "Japanese", "ja",
        "Dutch", "nl",
53
        "Brazillian Portuguese", "pt_BR",
54
        "Chinese Traditional", "zh_TW",
55
        NULL
56
57
58
    };

    for( ppsz_parser = ppsz_all ; ppsz_parser[0] ; ppsz_parser += 2 )
59
    {
60
61
62
63
64
65
        if( !strcmp( psz_lang, ppsz_parser[0] )
             || !strcmp( psz_lang, ppsz_parser[1] ) )
        {
            setenv( "LANG", ppsz_parser[1], 1 );
            return 1;
        }
66
67
68
69
70
    }

    return 0;
}

gbazin's avatar
   
gbazin committed
71
void system_Init( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
Sam Hocevar's avatar
   
Sam Hocevar committed
72
{
Sam Hocevar's avatar
   
Sam Hocevar committed
73
74
    char i_dummy;
    char *p_char, *p_oldchar = &i_dummy;
Sam Hocevar's avatar
   
Sam Hocevar committed
75
76

    /* Get the full program path and name */
77
    p_char = p_this->p_libvlc->psz_vlcpath = strdup( ppsz_argv[ 0 ] );
Sam Hocevar's avatar
   
Sam Hocevar committed
78
79
80
81
82

    /* Remove trailing program name */
    for( ; *p_char ; )
    {
        if( *p_char == '/' )
Sam Hocevar's avatar
   
Sam Hocevar committed
83
        {
Sam Hocevar's avatar
   
Sam Hocevar committed
84
            *p_oldchar = '/';
Sam Hocevar's avatar
   
Sam Hocevar committed
85
86
87
            *p_char = '\0';
            p_oldchar = p_char;
        }
Sam Hocevar's avatar
   
Sam Hocevar committed
88

Sam Hocevar's avatar
   
Sam Hocevar committed
89
        p_char++;
Sam Hocevar's avatar
   
Sam Hocevar committed
90
    }
91
92
93
94

    /* Check if $LANG is set. */
    if ( (p_char = getenv("LANG")) == NULL )
    {
95
        NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
96

97
        /* Retrieve user's preferences. */
98
99
100
        NSUserDefaults * o_defs = [NSUserDefaults standardUserDefaults];
        NSArray * o_languages = [o_defs objectForKey:@"AppleLanguages"];
        NSEnumerator * o_enumerator = [o_languages objectEnumerator];
101
102
        NSString * o_lang;

103
        while ( (o_lang = [o_enumerator nextObject]) )
104
        {
105
106
107
            const char * psz_string = [o_lang lossyCString];
            if ( FindLanguage( psz_string ) )
            {
108
                break;
109
110
            }
        }
111

112
        [o_pool release];
113
    }
Sam Hocevar's avatar
   
Sam Hocevar committed
114
115
}

116
117
118
/*****************************************************************************
 * system_Configure: check for system specific configuration options.
 *****************************************************************************/
gbazin's avatar
   
gbazin committed
119
void system_Configure( vlc_t *p_this, int *pi_argc, char *ppsz_argv[] )
120
121
122
123
{

}

Sam Hocevar's avatar
   
Sam Hocevar committed
124
/*****************************************************************************
Sam Hocevar's avatar
   
Sam Hocevar committed
125
 * system_End: free the program path.
Sam Hocevar's avatar
   
Sam Hocevar committed
126
 *****************************************************************************/
127
void system_End( vlc_t *p_this )
Sam Hocevar's avatar
   
Sam Hocevar committed
128
{
129
    free( p_this->p_libvlc->psz_vlcpath );
Sam Hocevar's avatar
   
Sam Hocevar committed
130
131
}