add wxGetLinuxDistributionInfo() and wxPlatformInfo::GetLinuxDistribution() functions; also add to wxPlatformInfo the GetOperatingSystemDescription(), GetDesktopEnvironment(), GetOperatingSystemDirectory() functions to group in the same class (wxPlatformInfo) all available platform-detection functions
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60873 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
ed1288eef0
commit
23790a2a29
@ -15,7 +15,7 @@
|
|||||||
#include "wx/string.h"
|
#include "wx/string.h"
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxPlatformInfo
|
// wxPlatformInfo enums & structs
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
// VERY IMPORTANT: when changing these enum values, also change the relative
|
// VERY IMPORTANT: when changing these enum values, also change the relative
|
||||||
@ -114,6 +114,31 @@ enum wxEndianness
|
|||||||
wxENDIAN_MAX
|
wxENDIAN_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// informations about a linux distro returned by the lsb_release utility
|
||||||
|
struct wxLinuxDistributionInfo
|
||||||
|
{
|
||||||
|
wxString Id;
|
||||||
|
wxString Release;
|
||||||
|
wxString CodeName;
|
||||||
|
wxString Description;
|
||||||
|
|
||||||
|
bool operator==(const wxLinuxDistributionInfo& ldi) const
|
||||||
|
{
|
||||||
|
return Id == ldi.Id &&
|
||||||
|
Release == ldi.Release &&
|
||||||
|
CodeName == ldi.CodeName &&
|
||||||
|
Description == ldi.Description;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const wxLinuxDistributionInfo& ldi) const
|
||||||
|
{ return !(*this == ldi); }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxPlatformInfo
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
// Information about the toolkit that the app is running under and some basic
|
// Information about the toolkit that the app is running under and some basic
|
||||||
// platform and architecture info
|
// platform and architecture info
|
||||||
class WXDLLIMPEXP_BASE wxPlatformInfo
|
class WXDLLIMPEXP_BASE wxPlatformInfo
|
||||||
@ -161,6 +186,7 @@ public:
|
|||||||
static wxString GetArchName(wxArchitecture arch);
|
static wxString GetArchName(wxArchitecture arch);
|
||||||
static wxString GetEndiannessName(wxEndianness end);
|
static wxString GetEndiannessName(wxEndianness end);
|
||||||
|
|
||||||
|
|
||||||
// getters
|
// getters
|
||||||
// -----------------
|
// -----------------
|
||||||
|
|
||||||
@ -196,6 +222,8 @@ public:
|
|||||||
|
|
||||||
wxOperatingSystemId GetOperatingSystemId() const
|
wxOperatingSystemId GetOperatingSystemId() const
|
||||||
{ return m_os; }
|
{ return m_os; }
|
||||||
|
wxLinuxDistributionInfo GetLinuxDistributionInfo() const
|
||||||
|
{ return m_ldi; }
|
||||||
wxPortId GetPortId() const
|
wxPortId GetPortId() const
|
||||||
{ return m_port; }
|
{ return m_port; }
|
||||||
wxArchitecture GetArchitecture() const
|
wxArchitecture GetArchitecture() const
|
||||||
@ -219,6 +247,16 @@ public:
|
|||||||
{ return GetArchName(m_arch); }
|
{ return GetArchName(m_arch); }
|
||||||
wxString GetEndiannessName() const
|
wxString GetEndiannessName() const
|
||||||
{ return GetEndiannessName(m_endian); }
|
{ return GetEndiannessName(m_endian); }
|
||||||
|
wxString GetOperatingSystemDescription() const
|
||||||
|
{ return m_osDesc; }
|
||||||
|
wxString GetDesktopEnvironment() const
|
||||||
|
{ return m_desktopEnv; }
|
||||||
|
|
||||||
|
static wxString GetOperatingSystemDirectory();
|
||||||
|
// doesn't make sense to store inside wxPlatformInfo the OS directory,
|
||||||
|
// thus this function is static; note that this function simply calls
|
||||||
|
// wxGetOSDirectory() and is here just to make it easier for the user to
|
||||||
|
// find it that feature (global functions can be difficult to find in the docs)
|
||||||
|
|
||||||
// setters
|
// setters
|
||||||
// -----------------
|
// -----------------
|
||||||
@ -230,12 +268,20 @@ public:
|
|||||||
|
|
||||||
void SetOperatingSystemId(wxOperatingSystemId n)
|
void SetOperatingSystemId(wxOperatingSystemId n)
|
||||||
{ m_os = n; }
|
{ m_os = n; }
|
||||||
|
void SetOperatingSystemDescription(const wxString& desc)
|
||||||
|
{ m_osDesc = desc; }
|
||||||
void SetPortId(wxPortId n)
|
void SetPortId(wxPortId n)
|
||||||
{ m_port = n; }
|
{ m_port = n; }
|
||||||
void SetArchitecture(wxArchitecture n)
|
void SetArchitecture(wxArchitecture n)
|
||||||
{ m_arch = n; }
|
{ m_arch = n; }
|
||||||
void SetEndianness(wxEndianness n)
|
void SetEndianness(wxEndianness n)
|
||||||
{ m_endian = n; }
|
{ m_endian = n; }
|
||||||
|
|
||||||
|
void SetDesktopEnvironment(const wxString& de)
|
||||||
|
{ m_desktopEnv = de; }
|
||||||
|
void SetLinuxDistributionInfo(const wxLinuxDistributionInfo& di)
|
||||||
|
{ m_ldi = di; }
|
||||||
|
|
||||||
|
|
||||||
// miscellaneous
|
// miscellaneous
|
||||||
// -----------------
|
// -----------------
|
||||||
@ -244,9 +290,13 @@ public:
|
|||||||
{
|
{
|
||||||
return m_osVersionMajor != -1 && m_osVersionMinor != -1 &&
|
return m_osVersionMajor != -1 && m_osVersionMinor != -1 &&
|
||||||
m_os != wxOS_UNKNOWN &&
|
m_os != wxOS_UNKNOWN &&
|
||||||
|
!m_osDesc.IsEmpty() &&
|
||||||
m_tkVersionMajor != -1 && m_tkVersionMinor != -1 &&
|
m_tkVersionMajor != -1 && m_tkVersionMinor != -1 &&
|
||||||
m_port != wxPORT_UNKNOWN &&
|
m_port != wxPORT_UNKNOWN &&
|
||||||
m_arch != wxARCH_INVALID && m_endian != wxENDIAN_INVALID;
|
m_arch != wxARCH_INVALID &&
|
||||||
|
m_endian != wxENDIAN_INVALID;
|
||||||
|
|
||||||
|
// do not check linux-specific info; it's ok to have them empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -269,6 +319,16 @@ protected:
|
|||||||
|
|
||||||
// Operating system ID.
|
// Operating system ID.
|
||||||
wxOperatingSystemId m_os;
|
wxOperatingSystemId m_os;
|
||||||
|
|
||||||
|
// Operating system description.
|
||||||
|
wxString m_osDesc;
|
||||||
|
|
||||||
|
|
||||||
|
// linux-specific
|
||||||
|
// -----------------
|
||||||
|
|
||||||
|
wxString m_desktopEnv;
|
||||||
|
wxLinuxDistributionInfo m_ldi;
|
||||||
|
|
||||||
|
|
||||||
// toolkit
|
// toolkit
|
||||||
@ -288,7 +348,7 @@ protected:
|
|||||||
// others
|
// others
|
||||||
// -----------------
|
// -----------------
|
||||||
|
|
||||||
// architecture of the OS
|
// architecture of the OS/machine
|
||||||
wxArchitecture m_arch;
|
wxArchitecture m_arch;
|
||||||
|
|
||||||
// endianness of the machine
|
// endianness of the machine
|
||||||
|
@ -32,7 +32,7 @@ class WXDLLIMPEXP_FWD_BASE wxArrayInt;
|
|||||||
// wxLongLong
|
// wxLongLong
|
||||||
#include "wx/longlong.h"
|
#include "wx/longlong.h"
|
||||||
|
|
||||||
// need for wxOperatingSystemId
|
// needed for wxOperatingSystemId, wxLinuxDistributionInfo
|
||||||
#include "wx/platinfo.h"
|
#include "wx/platinfo.h"
|
||||||
|
|
||||||
#ifdef __WATCOMC__
|
#ifdef __WATCOMC__
|
||||||
@ -116,6 +116,11 @@ WXDLLIMPEXP_BASE bool wxIsPlatformLittleEndian();
|
|||||||
// Get platform architecture
|
// Get platform architecture
|
||||||
WXDLLIMPEXP_BASE bool wxIsPlatform64Bit();
|
WXDLLIMPEXP_BASE bool wxIsPlatform64Bit();
|
||||||
|
|
||||||
|
#ifdef __LINUX__
|
||||||
|
// Get linux-distro informations
|
||||||
|
WXDLLIMPEXP_BASE wxLinuxDistributionInfo wxGetLinuxDistributionInfo();
|
||||||
|
#endif
|
||||||
|
|
||||||
// Return a string with the current date/time
|
// Return a string with the current date/time
|
||||||
WXDLLIMPEXP_BASE wxString wxNow();
|
WXDLLIMPEXP_BASE wxString wxNow();
|
||||||
|
|
||||||
|
@ -107,6 +107,24 @@ enum wxEndianness
|
|||||||
wxENDIAN_MAX
|
wxENDIAN_MAX
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
A structure containing informations about a Linux distribution as returned
|
||||||
|
by the @c lsb_release utility.
|
||||||
|
|
||||||
|
See wxGetLinuxDistributionInfo() or wxPlatformInfo::GetLinuxDistributionInfo()
|
||||||
|
for more info.
|
||||||
|
*/
|
||||||
|
struct wxLinuxDistributionInfo
|
||||||
|
{
|
||||||
|
wxString Id; //!< The id of the distribution; e.g. "Ubuntu"
|
||||||
|
wxString Release; //!< The version of the distribution; e.g. "9.04"
|
||||||
|
wxString CodeName; //!< The code name of the distribution; e.g. "jaunty"
|
||||||
|
wxString Description; //!< The description of the distribution; e.g. "Ubuntu 9.04"
|
||||||
|
|
||||||
|
bool operator==(const wxLinuxDistributionInfo& ldi) const;
|
||||||
|
bool operator!=(const wxLinuxDistributionInfo& ldi) const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@class wxPlatformInfo
|
@class wxPlatformInfo
|
||||||
@ -117,8 +135,16 @@ enum wxEndianness
|
|||||||
This class does not only have @e getters for the informations above, it also has
|
This class does not only have @e getters for the informations above, it also has
|
||||||
@e setters. This allows you to e.g. save the current platform informations in a
|
@e setters. This allows you to e.g. save the current platform informations in a
|
||||||
data file (maybe in string form) so that when you later load it, you can easily
|
data file (maybe in string form) so that when you later load it, you can easily
|
||||||
retrieve (see the static getters for string->enum conversion functions) the
|
retrieve (see the static getters for string->enum conversion functions) and store
|
||||||
signature of the system which generated it.
|
inside a wxPlatformInfo instance (using its setters) the signature of the system
|
||||||
|
which generated it.
|
||||||
|
|
||||||
|
In general however you only need to use the static Get() function and then
|
||||||
|
access the various informations for the current platform:
|
||||||
|
@code
|
||||||
|
wxLogMessage("This application is running under %s.",
|
||||||
|
wxPlatformInfo::Get().GetOperatingSystemIdName());
|
||||||
|
@endcode
|
||||||
|
|
||||||
@library{wxbase}
|
@library{wxbase}
|
||||||
@category{cfg}
|
@category{cfg}
|
||||||
@ -285,6 +311,13 @@ public:
|
|||||||
static wxString GetPortIdShortName(wxPortId port,
|
static wxString GetPortIdShortName(wxPortId port,
|
||||||
bool usingUniversal);
|
bool usingUniversal);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the operating system directory.
|
||||||
|
|
||||||
|
See wxGetOSDirectory() for more info.
|
||||||
|
*/
|
||||||
|
static wxString GetOperatingSystemDirectory();
|
||||||
|
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
|
|
||||||
@ -323,11 +356,32 @@ public:
|
|||||||
Returns the operating system ID of this wxPlatformInfo instance.
|
Returns the operating system ID of this wxPlatformInfo instance.
|
||||||
*/
|
*/
|
||||||
wxOperatingSystemId GetOperatingSystemId() const;
|
wxOperatingSystemId GetOperatingSystemId() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the description of the operating system of this wxPlatformInfo instance.
|
||||||
|
|
||||||
|
See wxGetOSDescription() for more info.
|
||||||
|
*/
|
||||||
|
wxString GetOperatingSystemDescription() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the wxWidgets port ID associated with this wxPlatformInfo instance.
|
Returns the wxWidgets port ID associated with this wxPlatformInfo instance.
|
||||||
*/
|
*/
|
||||||
wxPortId GetPortId() const;
|
wxPortId GetPortId() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the Linux distribution info associated with this wxPlatformInfo instance.
|
||||||
|
|
||||||
|
See wxGetLinuxDistributionInfo() for more info.
|
||||||
|
*/
|
||||||
|
wxLinuxDistributionInfo GetLinuxDistributionInfo() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns the desktop environment associated with this wxPlatformInfo instance.
|
||||||
|
|
||||||
|
See wxAppTraits::GetDesktopEnvironment() for more info.
|
||||||
|
*/
|
||||||
|
wxString GetDesktopEnvironment() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the run-time major version of the toolkit associated with this
|
Returns the run-time major version of the toolkit associated with this
|
||||||
@ -436,8 +490,22 @@ public:
|
|||||||
Sets the version of the toolkit associated with this wxPlatformInfo instance.
|
Sets the version of the toolkit associated with this wxPlatformInfo instance.
|
||||||
*/
|
*/
|
||||||
void SetToolkitVersion(int major, int minor);
|
void SetToolkitVersion(int major, int minor);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Sets the operating system description associated with this wxPlatformInfo instance.
|
||||||
|
*/
|
||||||
|
void SetOperatingSystemDescription(const wxString& desc);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Sets the desktop environment associated with this wxPlatformInfo instance.
|
||||||
|
*/
|
||||||
|
void SetDesktopEnvironment(const wxString& de);
|
||||||
|
|
||||||
|
/**
|
||||||
|
Sets the linux distribution info associated with this wxPlatformInfo instance.
|
||||||
|
*/
|
||||||
|
void SetLinuxDistributionInfo(const wxLinuxDistributionInfo& di);
|
||||||
|
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -684,6 +684,23 @@ bool wxIsPlatform64Bit();
|
|||||||
*/
|
*/
|
||||||
bool wxIsPlatformLittleEndian();
|
bool wxIsPlatformLittleEndian();
|
||||||
|
|
||||||
|
/**
|
||||||
|
Returns a structure containing informations about the currently running
|
||||||
|
Linux distribution.
|
||||||
|
|
||||||
|
This function uses the @c lsb_release utility which is part of the
|
||||||
|
<tt>Linux Standard Base Core</tt> specification
|
||||||
|
(see http://refspecs.linux-foundation.org/lsb.shtml) since the very first LSB
|
||||||
|
release 1.0 (released in 2001).
|
||||||
|
The @c lsb_release utility is very common on modern Linux distributions but in
|
||||||
|
case it's not available, then this function will return a ::wxLinuxDistributionInfo
|
||||||
|
structure containing empty strings.
|
||||||
|
|
||||||
|
This function is Linux-specific and is only available when the @c __LINUX__
|
||||||
|
symbol is defined.
|
||||||
|
*/
|
||||||
|
wxLinuxDistributionInfo wxGetLinuxDistributionInfo();
|
||||||
|
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,8 +105,8 @@ static const wxChar* const wxEndiannessNames[] =
|
|||||||
// local functions
|
// local functions
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
// returns log in base 2 of the value, this maps the enum values to the
|
// returns the logarithm in base 2 of 'value'; this maps the enum values to the
|
||||||
// corresponding indices
|
// corresponding indexes of the string arrays above
|
||||||
static unsigned wxGetIndexFromEnumValue(int value)
|
static unsigned wxGetIndexFromEnumValue(int value)
|
||||||
{
|
{
|
||||||
wxCHECK_MSG( value, (unsigned)-1, _T("invalid enum value") );
|
wxCHECK_MSG( value, (unsigned)-1, _T("invalid enum value") );
|
||||||
@ -159,6 +159,9 @@ bool wxPlatformInfo::operator==(const wxPlatformInfo &t) const
|
|||||||
m_osVersionMajor == t.m_osVersionMajor &&
|
m_osVersionMajor == t.m_osVersionMajor &&
|
||||||
m_osVersionMinor == t.m_osVersionMinor &&
|
m_osVersionMinor == t.m_osVersionMinor &&
|
||||||
m_os == t.m_os &&
|
m_os == t.m_os &&
|
||||||
|
m_osDesc == t.m_osDesc &&
|
||||||
|
m_ldi == t.m_ldi &&
|
||||||
|
m_desktopEnv == t.m_desktopEnv &&
|
||||||
m_port == t.m_port &&
|
m_port == t.m_port &&
|
||||||
m_usingUniversal == t.m_usingUniversal &&
|
m_usingUniversal == t.m_usingUniversal &&
|
||||||
m_arch == t.m_arch &&
|
m_arch == t.m_arch &&
|
||||||
@ -182,11 +185,18 @@ void wxPlatformInfo::InitForCurrentPlatform()
|
|||||||
{
|
{
|
||||||
m_port = traits->GetToolkitVersion(&m_tkVersionMajor, &m_tkVersionMinor);
|
m_port = traits->GetToolkitVersion(&m_tkVersionMajor, &m_tkVersionMinor);
|
||||||
m_usingUniversal = traits->IsUsingUniversalWidgets();
|
m_usingUniversal = traits->IsUsingUniversalWidgets();
|
||||||
|
m_desktopEnv = traits->GetDesktopEnvironment();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_os = wxGetOsVersion(&m_osVersionMajor, &m_osVersionMinor);
|
m_os = wxGetOsVersion(&m_osVersionMajor, &m_osVersionMinor);
|
||||||
|
m_osDesc = wxGetOsDescription();
|
||||||
m_endian = wxIsPlatformLittleEndian() ? wxENDIAN_LITTLE : wxENDIAN_BIG;
|
m_endian = wxIsPlatformLittleEndian() ? wxENDIAN_LITTLE : wxENDIAN_BIG;
|
||||||
m_arch = wxIsPlatform64Bit() ? wxARCH_64 : wxARCH_32;
|
m_arch = wxIsPlatform64Bit() ? wxARCH_64 : wxARCH_32;
|
||||||
|
|
||||||
|
#ifdef __LINUX__
|
||||||
|
m_ldi = wxGetLinuxDistributionInfo();
|
||||||
|
#endif
|
||||||
|
// else: leave m_ldi empty
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
@ -202,6 +212,12 @@ const wxPlatformInfo& wxPlatformInfo::Get()
|
|||||||
return gs_platInfo;
|
return gs_platInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* static */
|
||||||
|
wxString wxPlatformInfo::GetOperatingSystemDirectory()
|
||||||
|
{
|
||||||
|
return wxGetOSDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -873,6 +873,25 @@ bool wxIsPlatform64Bit()
|
|||||||
machine.Contains(wxT("alpha"));
|
machine.Contains(wxT("alpha"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef __LINUX__
|
||||||
|
wxLinuxDistributionInfo wxGetLinuxDistributionInfo()
|
||||||
|
{
|
||||||
|
const wxString id = wxGetCommandOutput(wxT("lsb_release --id"));
|
||||||
|
const wxString desc = wxGetCommandOutput(wxT("lsb_release --description"));
|
||||||
|
const wxString rel = wxGetCommandOutput(wxT("lsb_release --release"));
|
||||||
|
const wxString codename = wxGetCommandOutput(wxT("lsb_release --codename"));
|
||||||
|
|
||||||
|
wxLinuxDistributionInfo ret;
|
||||||
|
|
||||||
|
id.StartsWith("Distributor ID:\t", &ret.Id);
|
||||||
|
desc.StartsWith("Description:\t", &ret.Description);
|
||||||
|
rel.StartsWith("Release:\t", &ret.Release);
|
||||||
|
codename.StartsWith("Codename:\t", &ret.CodeName);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// these functions are in src/osx/utilsexc_base.cpp for wxMac
|
// these functions are in src/osx/utilsexc_base.cpp for wxMac
|
||||||
#ifndef __WXMAC__
|
#ifndef __WXMAC__
|
||||||
|
|
||||||
|
@ -113,6 +113,18 @@ void FontTestCase::GetSet()
|
|||||||
// consider adding another branch to this #if
|
// consider adding another branch to this #if
|
||||||
#if defined(__WXMSW__) || defined(__WXOSX__)
|
#if defined(__WXMSW__) || defined(__WXOSX__)
|
||||||
static const char *knownGoodFaceName = "Arial";
|
static const char *knownGoodFaceName = "Arial";
|
||||||
|
#elif defined(__LINUX__)
|
||||||
|
static const char *knownGoodFaceName;
|
||||||
|
wxString distroname = wxGetLinuxDistributionInfo().Id;
|
||||||
|
|
||||||
|
if (distroname.Contains("Ubuntu"))
|
||||||
|
knownGoodFaceName = "FreeSerif";
|
||||||
|
// ttf-freefont and ttf-dejavu packages are installed by default on [X,K]Ubuntu systems
|
||||||
|
else if (distroname == "Debian")
|
||||||
|
knownGoodFaceName = "Fixed";
|
||||||
|
else
|
||||||
|
knownGoodFaceName = "DejaVu Sans";
|
||||||
|
// this is very popular in many linux distro...
|
||||||
#else
|
#else
|
||||||
static const char *knownGoodFaceName = "Fixed";
|
static const char *knownGoodFaceName = "Fixed";
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user