示例#1
0
int rho_sysimpl_get_property(char* szPropName, VALUE* resValue)
{
	if (strcasecmp("webview_framework",szPropName) == 0)
	{
#ifdef RHODES_EMULATOR
		*resValue = rho_ruby_create_string("WEBKIT/" QTWEBKIT_VERSION_STR);
#elif defined(APP_BUILD_CAPABILITY_WEBKIT_BROWSER)
		*resValue = rho_ruby_create_string("WEBKIT");
#else
		rho::String msieVer = "IE";
		get_msie_version(msieVer);
		*resValue = rho_ruby_create_string(msieVer.c_str());
#endif
		return 1;
	}

#ifdef RHODES_EMULATOR
    if (strcasecmp("main_window_closed",szPropName) == 0) 
        {*resValue = rho_ruby_create_boolean(CMainWindow::mainWindowClosed); return 1;}
#endif

	if (strcasecmp("has_camera",szPropName) == 0) 
        {*resValue = rho_ruby_create_boolean(has_camera()); return 1;}

	if (strcasecmp("phone_number",szPropName) == 0)
        {*resValue = phone_number();return 1;}

	if (strcasecmp("ppi_x",szPropName) == 0)
        {*resValue = rho_ruby_create_double(get_screen_ppi_x()); return 1;}

	if (strcasecmp("ppi_y",szPropName) == 0)
        {*resValue = rho_ruby_create_double(get_screen_ppi_y()); return 1; }

	if (strcasecmp("locale",szPropName) == 0)
		{*resValue = rho_sys_get_locale(); return 1;}

	if (strcasecmp("country",szPropName) == 0)
	{
		wchar_t szCountry[20];
		int nRes = GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SISO3166CTRYNAME , szCountry, sizeof(szCountry)/sizeof(szCountry[0]));
		szCountry[2] = 0;

		*resValue = rho_ruby_create_string(convertToStringA(szCountry).c_str());
		return 1;
	}

	if (strcasecmp("device_name",szPropName) == 0)
	{
#ifdef OS_WINDOWS
		*resValue = rho_ruby_create_string("Win32");
        return 1;
#else
		HKEY hKey;
        int nRes = 0;
		if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("Ident"),
			0, KEY_READ, &hKey ) != ERROR_SUCCESS)
			return nRes;

		DWORD dwType = REG_SZ;
		DWORD dwDataSize = 0;
		if ( RegQueryValueEx( hKey, _T("name"), 0, &dwType, (PBYTE)NULL, &dwDataSize ) == ERROR_SUCCESS)
        {
		    CAtlString deviceName;
		    RegQueryValueEx( hKey, _T("name"), 0, &dwType, 
                (PBYTE)deviceName.GetBuffer((dwDataSize/sizeof(TCHAR) + sizeof(TCHAR))), &dwDataSize );
            deviceName.ReleaseBuffer();

		    *resValue = rho_ruby_create_string( convertToStringA(deviceName.GetString()).c_str() );

            nRes = 1;
        }

		RegCloseKey(hKey);
		return nRes;
#endif
	}

	if (strcasecmp("os_version",szPropName) == 0)
	{
		OSVERSIONINFO osv;
		osv.dwOSVersionInfoSize = sizeof(osv);
		if (!GetVersionEx(&osv))
			return 0;
		char buf[50];
		buf[sizeof(buf) - 1] = '\0';
		snprintf(buf, sizeof(buf) - 1, "%u.%u.%u", (unsigned)osv.dwMajorVersion,
			(unsigned)osv.dwMinorVersion, (unsigned)osv.dwBuildNumber);
		*resValue = rho_ruby_create_string(&buf[0]);
		return 1;
	}

	if (strcasecmp("is_emulator",szPropName) == 0)
    {
        bool bEmulator = false;
#ifdef OS_WINDOWS
        bEmulator = true;
#else

#endif
        *resValue = rho_ruby_create_boolean(bEmulator?1:0);
        return 1;
    }

	if (strcasecmp("has_calendar",szPropName) == 0)
    {
        *resValue = rho_ruby_create_boolean(1);
        return 1;
    }

	if (strcasecmp("has_touchscreen",szPropName) == 0)
    {
        *resValue = rho_ruby_create_boolean( rho_wmsys_has_touchscreen() );
        return 1;
    }
	if (strcasecmp("screen_orientation",szPropName) == 0)
    {
        if (rho_sys_get_screen_width() <= rho_sys_get_screen_height()) 
        {
		    *resValue = rho_ruby_create_string("portrait");
	    }
	    else {
		    *resValue = rho_ruby_create_string("landscape");
	    }                                                          
        return 1;
    }

#if defined( OS_WINCE )&& !defined( OS_PLATFORM_MOTCE )
    if (strcasecmp("device_id",szPropName) == 0) 
    {
        rho::String strDeviceID = "";
        String strAppData = "RHODES_" + RHODESAPP().getAppName() + "_DEVICEID";

        BYTE rgDeviceId[20];
        DWORD cbDeviceId = sizeof(rgDeviceId);
        HRESULT hr = GetDeviceUniqueID( (PBYTE)(strAppData.c_str()),
           strAppData.length(),
           GETDEVICEUNIQUEID_V1,
           rgDeviceId,
           &cbDeviceId);

        if ( SUCCEEDED(hr) )
        {
            for(unsigned int i = 0; i < cbDeviceId; i++)
            {
                toHexString( rgDeviceId[i], strDeviceID, 16);
            }
        }

        *resValue = rho_ruby_create_string(strDeviceID.c_str());

        return 1;
    }
#endif

	if (strcasecmp("has_cell_network",szPropName) == 0) 
    {
        *resValue = rho_ruby_create_boolean( g_rho_has_cellnetwork != 0 );
        return 1;
    }

	if (strcasecmp("has_wifi_network",szPropName) == 0) 
    {
        *resValue = rho_ruby_create_boolean( g_rho_has_network != 0 );
        return 1;
    }

    return 0;
}
示例#2
0
int rho_sysimpl_get_property(char* szPropName, VALUE* resValue)
{
	if (strcasecmp("has_camera",szPropName) == 0) 
        {*resValue = rho_ruby_create_boolean(has_camera()); return 1;}

	if (strcasecmp("phone_number",szPropName) == 0)
        {*resValue = phone_number();return 1;}

	if (strcasecmp("ppi_x",szPropName) == 0)
        {*resValue = rho_ruby_create_double(get_screen_ppi_x()); return 1;}

	if (strcasecmp("ppi_y",szPropName) == 0)
        {*resValue = rho_ruby_create_double(get_screen_ppi_y()); return 1; }

	if (strcasecmp("locale",szPropName) == 0)
		{*resValue = rho_sys_get_locale(); return 1;}

	if (strcasecmp("country",szPropName) == 0)
	{
		wchar_t szCountry[20];
		int nRes = GetLocaleInfo(LOCALE_USER_DEFAULT,LOCALE_SISO3166CTRYNAME , szCountry, sizeof(szCountry)/sizeof(szCountry[0]));
		szCountry[2] = 0;

		*resValue = rho_ruby_create_string(convertToStringA(szCountry).c_str());
		return 1;
	}

	if (strcasecmp("device_name",szPropName) == 0)
	{
#ifdef OS_WINDOWS
		*resValue = rho_ruby_create_string("Win32");
        return 1;
#else
		HKEY hKey;
        int nRes = 0;
		if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("Ident"),
			0, KEY_READ, &hKey ) != ERROR_SUCCESS)
			return nRes;

		DWORD dwType = REG_SZ;
		DWORD dwDataSize = 0;
		if ( RegQueryValueEx( hKey, _T("name"), 0, &dwType, (PBYTE)NULL, &dwDataSize ) == ERROR_SUCCESS)
        {
		    CAtlString deviceName;
		    RegQueryValueEx( hKey, _T("name"), 0, &dwType, 
                (PBYTE)deviceName.GetBuffer((dwDataSize/sizeof(TCHAR) + sizeof(TCHAR))), &dwDataSize );
            deviceName.ReleaseBuffer();

		    *resValue = rho_ruby_create_string( convertToStringA(deviceName.GetString()).c_str() );

            nRes = 1;
        }

		RegCloseKey(hKey);
		return nRes;
#endif
	}

	if (strcasecmp("os_version",szPropName) == 0)
	{
		OSVERSIONINFO osv;
		osv.dwOSVersionInfoSize = sizeof(osv);
		if (!GetVersionEx(&osv))
			return 0;
		char buf[50];
		buf[sizeof(buf) - 1] = '\0';
		snprintf(buf, sizeof(buf) - 1, "%u.%u.%u", (unsigned)osv.dwMajorVersion,
			(unsigned)osv.dwMinorVersion, (unsigned)osv.dwBuildNumber);
		*resValue = rho_ruby_create_string(&buf[0]);
		return 1;
	}

	if (strcasecmp("is_emulator",szPropName) == 0)
    {
        bool bEmulator = false;
#ifdef OS_WINDOWS
        bEmulator = true;
#else

#endif
        *resValue = rho_ruby_create_boolean(bEmulator?1:0);
        return 1;
    }

    return 0;
}