#include "wx/string.h"
// ----------------------------------------------------------------------------
-// wxPlatformInfo
+// wxPlatformInfo enums & structs
// ----------------------------------------------------------------------------
// VERY IMPORTANT: when changing these enum values, also change the relative
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
static wxString GetArchName(wxArchitecture arch);
static wxString GetEndiannessName(wxEndianness end);
+
// getters
// -----------------
wxOperatingSystemId GetOperatingSystemId() const
{ return m_os; }
+ wxLinuxDistributionInfo GetLinuxDistributionInfo() const
+ { return m_ldi; }
wxPortId GetPortId() const
{ return m_port; }
wxArchitecture GetArchitecture() const
{ 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
// -----------------
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
// -----------------
{
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
}
// Operating system ID.
wxOperatingSystemId m_os;
+
+ // Operating system description.
+ wxString m_osDesc;
+
+
+ // linux-specific
+ // -----------------
+
+ wxString m_desktopEnv;
+ wxLinuxDistributionInfo m_ldi;
// toolkit
// others
// -----------------
- // architecture of the OS
+ // architecture of the OS/machine
wxArchitecture m_arch;
// endianness of the machine
// wxLongLong
#include "wx/longlong.h"
-// need for wxOperatingSystemId
+// needed for wxOperatingSystemId, wxLinuxDistributionInfo
#include "wx/platinfo.h"
#ifdef __WATCOMC__
// 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();
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
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}
static wxString GetPortIdShortName(wxPortId port,
bool usingUniversal);
+ /**
+ Returns the operating system directory.
+
+ See wxGetOSDirectory() for more info.
+ */
+ static wxString GetOperatingSystemDirectory();
+
//@}
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
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);
+ //@}
};
*/
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();
+
//@}
// 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") );
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 &&
{
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 */
return gs_platInfo;
}
+/* static */
+wxString wxPlatformInfo::GetOperatingSystemDirectory()
+{
+ return wxGetOSDirectory();
+}
+
// ----------------------------------------------------------------------------
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__
// 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