Commit 1a0134a9 authored by con's avatar con

Use systems preferred language on Mac.

And ensure that the menu items don't vanish from the application menu
when they are translated.
parent 8213e5bd
......@@ -17,7 +17,7 @@ win32 {
} else:macx {
CONFIG(debug, debug|release):LIBS *= -lExtensionSystem_debug -lAggregation_debug
else:LIBS *= -lExtensionSystem -lAggregation
LIBS += -framework CoreFoundation
ICON = qtcreator.icns
QMAKE_INFO_PLIST = Info.plist
FILETYPES.files = profile.icns prifile.icns
......
......@@ -48,6 +48,20 @@
#ifdef Q_OS_MAC
# include <sys/resource.h>
# include <CoreFoundation/CoreFoundation.h>
// Helper function CoreFoundation -> Qt
static QString stringFromCFString(CFStringRef value) {
QString retVal;
CFIndex maxLength = 2 * CFStringGetLength(value) + 1/*zero term*/; // max UTF8
char *cstring = new char[maxLength];
if (CFStringGetCString(CFStringRef(value), cstring, maxLength, kCFStringEncodingUTF8)) {
retVal = QString::fromUtf8(cstring);
}
delete cstring;
return retVal;
}
#endif
enum { OptionIndent = 4, DescriptionIndent = 24 };
......@@ -216,7 +230,29 @@ int main(int argc, char **argv)
QTranslator translator;
QTranslator qtTranslator;
const QString &locale = QLocale::system().name();
QString locale = QLocale::system().name();
#ifdef Q_OS_MAC
// because QLocale's system locale is basically useless on the Mac.
// Try to get the real system setting via core foundation
CFLocaleRef maclocale = CFLocaleCopyCurrent();
CFTypeRef value = CFLocaleGetValue(maclocale, kCFLocaleLanguageCode);
QString preferredLanguage = stringFromCFString(CFStringRef(value));
if (!preferredLanguage.isEmpty())
locale = preferredLanguage;
CFRelease(maclocale);
CFArrayRef languages = (CFArrayRef)CFPreferencesCopyValue(
CFSTR("AppleLanguages"),
kCFPreferencesAnyApplication,
kCFPreferencesCurrentUser,
kCFPreferencesAnyHost);
// CFShow(languages);
if (CFArrayGetCount(languages) > 0) {
QString preferredLanguage = stringFromCFString(CFStringRef(CFArrayGetValueAtIndex(languages, 0)));
if (!preferredLanguage.isEmpty())
locale = preferredLanguage;
}
CFRelease(languages);
#endif
const QString &creatorTrPath = QCoreApplication::applicationDirPath()
+ QLatin1String(SHARE_PATH "/translations");
if (translator.load(QLatin1String("qtcreator_") + locale, creatorTrPath)) {
......
......@@ -160,7 +160,7 @@ MainWindow::MainWindow() :
QCoreApplication::setOrganizationName(QLatin1String("Nokia"));
QSettings::setDefaultFormat(QSettings::IniFormat);
QString baseName = qApp->style()->objectName();
#ifdef Q_WS_X11
#ifdef Q_WS_X11
if (baseName == QLatin1String("windows")) {
// Sometimes we get the standard windows 95 style as a fallback
// e.g. if we are running on a KDE4 desktop
......@@ -325,7 +325,7 @@ bool MainWindow::init(QString *errorMessage)
void MainWindow::modeChanged(Core::IMode *mode)
{
if (mode == m_outputMode) {
if (mode == m_outputMode) {
int idx = OutputPaneManager::instance()->m_widgetComboBox->itemData(OutputPaneManager::instance()->m_widgetComboBox->currentIndex()).toInt();
IOutputPane *out = OutputPaneManager::instance()->m_pageMap.value(idx);
if (out && out->canFocus())
......@@ -678,6 +678,7 @@ void MainWindow::registerDefaultActions()
cmd = am->registerAction(m_optionsAction, Constants::OPTIONS, m_globalContext);
#ifdef Q_WS_MAC
cmd->setDefaultKeySequence(QKeySequence("Ctrl+,"));
cmd->action()->setMenuRole(QAction::PreferencesRole);
#endif
mtools->addAction(cmd, Constants::G_DEFAULT_THREE);
connect(m_optionsAction, SIGNAL(triggered()), this, SLOT(showOptionsDialog()));
......@@ -735,7 +736,11 @@ void MainWindow::registerDefaultActions()
cmd = am->registerAction(tmpaction, Constants::ABOUT_QTCREATOR, m_globalContext);
mhelp->addAction(cmd, Constants::G_HELP_ABOUT);
tmpaction->setEnabled(true);
#ifdef Q_WS_MAC
cmd->action()->setMenuRole(QAction::ApplicationSpecificRole);
#endif
connect(tmpaction, SIGNAL(triggered()), this, SLOT(aboutQtCreator()));
//About Plugins Action
tmpaction = new QAction(tr("About &Plugins..."), this);
cmd = am->registerAction(tmpaction, Constants::ABOUT_PLUGINS, m_globalContext);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment