diff --git a/include/wx/platinfo.h b/include/wx/platinfo.h index 2a4e8621cf..cb2de2f3fd 100644 --- a/include/wx/platinfo.h +++ b/include/wx/platinfo.h @@ -15,7 +15,7 @@ #include "wx/string.h" // ---------------------------------------------------------------------------- -// wxPlatformInfo +// wxPlatformInfo enums & structs // ---------------------------------------------------------------------------- // VERY IMPORTANT: when changing these enum values, also change the relative @@ -114,6 +114,31 @@ enum wxEndianness 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 // platform and architecture info class WXDLLIMPEXP_BASE wxPlatformInfo @@ -161,6 +186,7 @@ public: static wxString GetArchName(wxArchitecture arch); static wxString GetEndiannessName(wxEndianness end); + // getters // ----------------- @@ -196,6 +222,8 @@ public: wxOperatingSystemId GetOperatingSystemId() const { return m_os; } + wxLinuxDistributionInfo GetLinuxDistributionInfo() const + { return m_ldi; } wxPortId GetPortId() const { return m_port; } wxArchitecture GetArchitecture() const @@ -219,6 +247,16 @@ public: { return GetArchName(m_arch); } wxString GetEndiannessName() const { 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 // ----------------- @@ -230,12 +268,20 @@ public: void SetOperatingSystemId(wxOperatingSystemId n) { m_os = n; } + void SetOperatingSystemDescription(const wxString& desc) + { m_osDesc = desc; } void SetPortId(wxPortId n) { m_port = n; } void SetArchitecture(wxArchitecture n) { m_arch = n; } void SetEndianness(wxEndianness n) { m_endian = n; } + + void SetDesktopEnvironment(const wxString& de) + { m_desktopEnv = de; } + void SetLinuxDistributionInfo(const wxLinuxDistributionInfo& di) + { m_ldi = di; } + // miscellaneous // ----------------- @@ -244,9 +290,13 @@ public: { return m_osVersionMajor != -1 && m_osVersionMinor != -1 && m_os != wxOS_UNKNOWN && + !m_osDesc.IsEmpty() && m_tkVersionMajor != -1 && m_tkVersionMinor != -1 && 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. wxOperatingSystemId m_os; + + // Operating system description. + wxString m_osDesc; + + + // linux-specific + // ----------------- + + wxString m_desktopEnv; + wxLinuxDistributionInfo m_ldi; // toolkit @@ -288,7 +348,7 @@ protected: // others // ----------------- - // architecture of the OS + // architecture of the OS/machine wxArchitecture m_arch; // endianness of the machine diff --git a/include/wx/utils.h b/include/wx/utils.h index 37927b4e1e..dbd88a6342 100644 --- a/include/wx/utils.h +++ b/include/wx/utils.h @@ -32,7 +32,7 @@ class WXDLLIMPEXP_FWD_BASE wxArrayInt; // wxLongLong #include "wx/longlong.h" -// need for wxOperatingSystemId +// needed for wxOperatingSystemId, wxLinuxDistributionInfo #include "wx/platinfo.h" #ifdef __WATCOMC__ @@ -116,6 +116,11 @@ WXDLLIMPEXP_BASE bool wxIsPlatformLittleEndian(); // Get platform architecture WXDLLIMPEXP_BASE bool wxIsPlatform64Bit(); +#ifdef __LINUX__ +// Get linux-distro informations +WXDLLIMPEXP_BASE wxLinuxDistributionInfo wxGetLinuxDistributionInfo(); +#endif + // Return a string with the current date/time WXDLLIMPEXP_BASE wxString wxNow(); diff --git a/interface/wx/platinfo.h b/interface/wx/platinfo.h index 88b6a68d86..b32f810f0c 100644 --- a/interface/wx/platinfo.h +++ b/interface/wx/platinfo.h @@ -107,6 +107,24 @@ enum wxEndianness 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 @@ -117,8 +135,16 @@ enum wxEndianness 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 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 - signature of the system which generated it. + retrieve (see the static getters for string->enum conversion functions) and store + 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} @category{cfg} @@ -285,6 +311,13 @@ public: static wxString GetPortIdShortName(wxPortId port, 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. */ 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. */ 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 @@ -436,8 +490,22 @@ public: Sets the version of the toolkit associated with this wxPlatformInfo instance. */ 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); //@} - }; diff --git a/interface/wx/utils.h b/interface/wx/utils.h index d8a7bdd01c..08b6a55037 100644 --- a/interface/wx/utils.h +++ b/interface/wx/utils.h @@ -684,6 +684,23 @@ bool wxIsPlatform64Bit(); */ 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 + Linux Standard Base Core 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(); + //@} diff --git a/src/common/platinfo.cpp b/src/common/platinfo.cpp index fbb27bfd94..a687a47862 100644 --- a/src/common/platinfo.cpp +++ b/src/common/platinfo.cpp @@ -105,8 +105,8 @@ static const wxChar* const wxEndiannessNames[] = // local functions // ---------------------------------------------------------------------------- -// returns log in base 2 of the value, this maps the enum values to the -// corresponding indices +// returns the logarithm in base 2 of 'value'; this maps the enum values to the +// corresponding indexes of the string arrays above static unsigned wxGetIndexFromEnumValue(int 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_osVersionMinor == t.m_osVersionMinor && 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_usingUniversal == t.m_usingUniversal && m_arch == t.m_arch && @@ -182,11 +185,18 @@ void wxPlatformInfo::InitForCurrentPlatform() { m_port = traits->GetToolkitVersion(&m_tkVersionMajor, &m_tkVersionMinor); m_usingUniversal = traits->IsUsingUniversalWidgets(); + m_desktopEnv = traits->GetDesktopEnvironment(); } m_os = wxGetOsVersion(&m_osVersionMajor, &m_osVersionMinor); + m_osDesc = wxGetOsDescription(); m_endian = wxIsPlatformLittleEndian() ? wxENDIAN_LITTLE : wxENDIAN_BIG; m_arch = wxIsPlatform64Bit() ? wxARCH_64 : wxARCH_32; + +#ifdef __LINUX__ + m_ldi = wxGetLinuxDistributionInfo(); +#endif + // else: leave m_ldi empty } /* static */ @@ -202,6 +212,12 @@ const wxPlatformInfo& wxPlatformInfo::Get() return gs_platInfo; } +/* static */ +wxString wxPlatformInfo::GetOperatingSystemDirectory() +{ + return wxGetOSDirectory(); +} + // ---------------------------------------------------------------------------- diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index 1c92ba8982..3153216e62 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -873,6 +873,25 @@ bool wxIsPlatform64Bit() 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 #ifndef __WXMAC__ diff --git a/tests/font/fonttest.cpp b/tests/font/fonttest.cpp index 7ba623bd55..69df21a2f5 100644 --- a/tests/font/fonttest.cpp +++ b/tests/font/fonttest.cpp @@ -113,6 +113,18 @@ void FontTestCase::GetSet() // consider adding another branch to this #if #if defined(__WXMSW__) || defined(__WXOSX__) 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 static const char *knownGoodFaceName = "Fixed"; #endif