diff --git a/src/frameworks/UBPlatformUtils.h b/src/frameworks/UBPlatformUtils.h index ebac3995..46acb6f6 100644 --- a/src/frameworks/UBPlatformUtils.h +++ b/src/frameworks/UBPlatformUtils.h @@ -171,6 +171,7 @@ class UBPlatformUtils static int nKeyboardLayouts; static UBKeyboardLocale** keyboardLayouts; + public: static void init(); static void destroy(); @@ -192,6 +193,10 @@ public: static UBKeyboardLocale** getKeyboardLayouts(int& nCount); static QString urlFromClipboard(); static QStringList availableTranslations(); + +#ifdef Q_WS_MAC + static void SetMacLocaleByIdentifier(const QString& id); +#endif }; diff --git a/src/frameworks/UBPlatformUtils_mac.mm b/src/frameworks/UBPlatformUtils_mac.mm index d62e9f2e..72dcb75c 100644 --- a/src/frameworks/UBPlatformUtils_mac.mm +++ b/src/frameworks/UBPlatformUtils_mac.mm @@ -570,3 +570,28 @@ QString UBPlatformUtils::urlFromClipboard() */ return qsRet; } + + +void UBPlatformUtils::SetMacLocaleByIdentifier(const QString& id) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + const char * strName = id.toAscii().data(); + + CFStringRef iName = CFStringCreateWithCString(NULL, strName, kCFStringEncodingMacRoman ); + + CFStringRef keys[] = { kTISPropertyInputSourceCategory, kTISPropertyInputSourceID }; + CFStringRef values[] = { kTISCategoryKeyboardInputSource, iName }; + CFDictionaryRef dict = CFDictionaryCreate(NULL, (const void **)keys, (const void **)values, 2, NULL, NULL); + CFArrayRef kbds = TISCreateInputSourceList(dict, true); + if (kbds!=NULL) + { + if (CFArrayGetCount(kbds)!=0) + { + TISInputSourceRef klRef = (TISInputSourceRef)CFArrayGetValueAtIndex(kbds, 0); + if (klRef!=NULL) + TISSelectInputSource(klRef); + } + } + [pool drain]; +} diff --git a/src/gui/UBKeyboardPalette_mac.cpp b/src/gui/UBKeyboardPalette_mac.cpp index a8ca7c72..79e48e36 100644 --- a/src/gui/UBKeyboardPalette_mac.cpp +++ b/src/gui/UBKeyboardPalette_mac.cpp @@ -57,23 +57,6 @@ void UBKeyboardPalette::createCtrlButtons() ctrlButtons[8] = new UBLocaleButton(this); } -void SetMacLocaleByIdentifier(const QString& id) -{ - const char * strName = id.toAscii().data(); - - CFStringRef iName = CFStringCreateWithCString(NULL, strName, kCFStringEncodingMacRoman ); - - CFStringRef keys[] = { kTISPropertyInputSourceCategory, kTISPropertyInputSourceID }; - CFStringRef values[] = { kTISCategoryKeyboardInputSource, iName }; - CFDictionaryRef dict = CFDictionaryCreate(NULL, (const void **)keys, (const void **)values, 2, NULL, NULL); - CFArrayRef kbds = TISCreateInputSourceList(dict, true); - if (CFArrayGetCount(kbds)!=0) - { - TISInputSourceRef klRef = (TISInputSourceRef)CFArrayGetValueAtIndex(kbds, 0); - if (klRef!=NULL) - TISSelectInputSource(klRef); - } -} void UBKeyboardPalette::checkLayout() @@ -108,6 +91,6 @@ void UBKeyboardPalette::onActivated(bool) void UBKeyboardPalette::onLocaleChanged(UBKeyboardLocale* locale) { - SetMacLocaleByIdentifier(locale->id); + UBPlatformUtils::SetMacLocaleByIdentifier(locale->id); }