2 Copyright (C) 2007 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <pbd/error.h>
23 #include <gtkmm2ext/gtkapplication.h>
24 #include <gdk/gdkquartz.h>
29 #include "ardour_ui.h"
33 #include <CoreFoundation/CFLocale.h>
34 #import <CoreFoundation/CFString.h>
35 #import <Foundation/NSString.h>
36 #import <Foundation/NSAutoreleasePool.h>
42 ARDOUR_UI::platform_specific ()
44 gtk_application_ready ();
46 if (!ARDOUR_COMMAND_LINE::finder_invoked_ardour) {
48 /* if invoked from the command line, make sure we're visible */
50 [NSApp activateIgnoringOtherApps:1];
55 ARDOUR_UI::platform_setup ()
60 cocoa_open_url (const char* uri)
62 NSString* struri = [[NSString alloc] initWithUTF8String:uri];
63 NSURL* nsurl = [[NSURL alloc] initWithString:struri];
65 bool ret = [[NSWorkspace sharedWorkspace] openURL:nsurl];
74 set_language_preference ()
76 gtk_disable_setlocale ();
78 /* the gettext manual is potentially misleading about the utility of
79 LANGUAGE. It notes that if LANGUAGE is set to include a dialect/region-free
80 language code, like "it", it will assume that you mean the main
81 dialect (e.g. "it_IT"). But in reality, it doesn't bother looking for
82 locale dirs with the full name, only the short code (it doesn't
85 Since Apple's preferred language list only consists of short language codes,
86 if we set LANGUAGE then gettext will not look for the relevant long-form
90 /* how to get language preferences with CoreFoundation
93 NSArray* languages = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"];
95 /* push into LANGUAGE */
97 if (languages && [languages count] > 0) {
99 int i, count = [languages count];
100 for (i = 0; i < count; ++i) {
101 if ([[languages objectAtIndex:i]
102 isEqualToString:@"en"]) {
107 NSRange r = { 0, static_cast<NSUInteger> (count) };
108 setenv ("LANGUAGE", [[[languages subarrayWithRange:r] componentsJoinedByString:@":"] UTF8String], 0);
109 cout << "LANGUAGE set to " << getenv ("LANGUAGE") << endl;
112 /* now get AppleLocale value and use that for LANG */
114 CFLocaleRef cflocale = CFLocaleCopyCurrent();
115 NSString* nslocale = (NSString*) CFLocaleGetValue (cflocale, kCFLocaleIdentifier);
117 /* the full POSIX locale specification allows for lots of things. that could be an issue. Silly Apple.
120 cout << "LANG set to " << [nslocale UTF8String] << endl;
121 setenv ("LANG", [nslocale UTF8String], 0);
122 CFRelease (cflocale);