Browse Source

New methods SystemStats::getUserLanguage(), SystemStats::getUserRegion().

tags/2021-05-28
jules 13 years ago
parent
commit
44ac462768
10 changed files with 80 additions and 0 deletions
  1. +8
    -0
      extras/JuceDemo/Builds/Android/src/com/juce/JuceDemo.java
  2. +1
    -0
      extras/JuceDemo/Source/ApplicationStartup.cpp
  3. +4
    -0
      modules/juce_core/juce_core.cpp
  4. +8
    -0
      modules/juce_core/native/java/JuceAppActivity.java
  5. +1
    -0
      modules/juce_core/native/juce_android_JNIHelpers.h
  6. +14
    -0
      modules/juce_core/native/juce_android_SystemStats.cpp
  7. +11
    -0
      modules/juce_core/native/juce_linux_SystemStats.cpp
  8. +11
    -0
      modules/juce_core/native/juce_mac_SystemStats.mm
  9. +12
    -0
      modules/juce_core/native/juce_win32_SystemStats.cpp
  10. +10
    -0
      modules/juce_core/system/juce_SystemStats.h

+ 8
- 0
extras/JuceDemo/Builds/Android/src/com/juce/JuceDemo.java View File

@@ -495,4 +495,12 @@ public final class JuceDemo extends Activity
{
startActivity (new Intent (Intent.ACTION_VIEW, Uri.parse (url)));
}
public static final String getLocaleValue (boolean isRegion)
{
java.util.Locale locale = java.util.Locale.getDefault();
return isRegion ? locale.getDisplayCountry (java.util.Locale.US)
: locale.getDisplayLanguage (java.util.Locale.US);
}
}

+ 1
- 0
extras/JuceDemo/Source/ApplicationStartup.cpp View File

@@ -114,6 +114,7 @@ private:
<< "Full user name: " << SystemStats::getFullUserName() << newLine
<< "Host name: " << SystemStats::getComputerName() << newLine
<< "Operating system: " << SystemStats::getOperatingSystemName() << newLine
<< "Locale: " << SystemStats::getUserLanguage() << "-" << SystemStats::getUserRegion() << newLine
<< "Memory size: " << SystemStats::getMemorySizeInMegabytes() << "MB" << newLine
<< "Number of CPUs: " << SystemStats::getNumCpus() << newLine


+ 4
- 0
modules/juce_core/juce_core.cpp View File

@@ -66,6 +66,10 @@
#include <netinet/in.h>
#endif
#if JUCE_LINUX
#include <langinfo.h>
#endif
#include <pwd.h>
#include <fcntl.h>
#include <netdb.h>


+ 8
- 0
modules/juce_core/native/java/JuceAppActivity.java View File

@@ -495,4 +495,12 @@ public final class JuceAppActivity extends Activity
{
startActivity (new Intent (Intent.ACTION_VIEW, Uri.parse (url)));
}
public static final String getLocaleValue (boolean isRegion)
{
java.util.Locale locale = java.util.Locale.getDefault();
return isRegion ? locale.getDisplayCountry (java.util.Locale.US)
: locale.getDisplayLanguage (java.util.Locale.US);
}
}

+ 1
- 0
modules/juce_core/native/juce_android_JNIHelpers.h View File

@@ -359,6 +359,7 @@ extern ThreadLocalJNIEnvHolder threadLocalJNIEnvHolder;
METHOD (showMessageBox, "showMessageBox", "(Ljava/lang/String;Ljava/lang/String;J)V") \
METHOD (showOkCancelBox, "showOkCancelBox", "(Ljava/lang/String;Ljava/lang/String;J)V") \
METHOD (showYesNoCancelBox, "showYesNoCancelBox", "(Ljava/lang/String;Ljava/lang/String;J)V") \
STATICMETHOD (getLocaleValue, "getLocaleValue", "(Z)Ljava/lang/String;") \
DECLARE_JNI_CLASS (JuceAppActivity, JUCE_ANDROID_ACTIVITY_CLASSPATH);
#undef JNI_CLASS_MEMBERS


+ 14
- 0
modules/juce_core/native/juce_android_SystemStats.cpp View File

@@ -172,6 +172,14 @@ namespace AndroidStatsHelpers
SystemClass.getProperty,
javaString (name).get())));
}
//==============================================================================
String getLocaleValue (bool isRegion)
{
return juceString (LocalRef<jstring> ((jstring) getEnv()->CallStaticObjectMethod (JuceAppActivity,
JuceAppActivity.getLocaleValue,
isRegion)));
}
}
//==============================================================================
@@ -250,6 +258,12 @@ String SystemStats::getComputerName()
return String::empty;
}
String SystemStats::getUserLanguage() { return AndroidStatsHelpers::getLocaleValue (false); }
String SystemStats::getUserRegion() { return AndroidStatsHelpers::getLocaleValue (true); }
//==============================================================================
SystemStats::CPUFlags::CPUFlags()
{


+ 11
- 0
modules/juce_core/native/juce_linux_SystemStats.cpp View File

@@ -119,6 +119,17 @@ String SystemStats::getComputerName()
return String::empty;
}
String getLocaleValue (nl_item key)
{
const char* oldLocale = ::setlocale (LC_ALL, "");
return String (const_cast <const char*> (nl_langinfo (key)));
::setlocale (LC_ALL, oldLocale);
}
String SystemStats::getUserLanguage() { return getLocaleValue (_NL_IDENTIFICATION_LANGUAGE); }
String SystemStats::getUserRegion() { return getLocaleValue (_NL_IDENTIFICATION_TERRITORY); }
//==============================================================================
SystemStats::CPUFlags::CPUFlags()
{


+ 11
- 0
modules/juce_core/native/juce_mac_SystemStats.mm View File

@@ -202,6 +202,17 @@ String SystemStats::getComputerName()
return String::empty;
}
static String getLocaleValue (CFStringRef key)
{
CFLocaleRef cfLocale = CFLocaleCopyCurrent();
const String result (String::fromCFString ((CFStringRef) CFLocaleGetValue (cfLocale, key)));
CFRelease (cfLocale);
return result;
}
String SystemStats::getUserLanguage() { return getLocaleValue (kCFLocaleLanguageCode); }
String SystemStats::getUserRegion() { return getLocaleValue (kCFLocaleCountryCode); }
//==============================================================================
class HiResCounterHandler
{


+ 12
- 0
modules/juce_core/native/juce_win32_SystemStats.cpp View File

@@ -370,3 +370,15 @@ String SystemStats::getComputerName()
GetComputerName (text, &len);
return String (text, len);
}
static String getLocaleValue (LCTYPE key, const char* defaultValue)
{
TCHAR buffer [256] = { 0 };
if (GetLocaleInfo (LOCALE_USER_DEFAULT, key, buffer, 255) > 0)
return buffer;
return defaultValue;
}
String SystemStats::getUserLanguage() { return getLocaleValue (LOCALE_SISO639LANGNAME, "en"); }
String SystemStats::getUserRegion() { return getLocaleValue (LOCALE_SISO3166CTRYNAME, "US"); }

+ 10
- 0
modules/juce_core/system/juce_SystemStats.h View File

@@ -109,6 +109,16 @@ public:
/** Returns the host-name of the computer. */
static String getComputerName();
/** Returns the user's language.
The return value is a 2 or 3 letter language code (ISO 639-1 or ISO 639-2)
*/
static String getUserLanguage();
/** Returns the user's region.
The return value is a 2 letter country code (ISO 3166-1 alpha-2).
*/
static String getUserRegion();
//==============================================================================
// CPU and memory information..


Loading…
Cancel
Save