UniversalIndentGUI 1.2.0
UiGuiSystemInfo.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2006-2012 by Thomas Schweitzer                          *
00003  *   thomas-schweitzer(at)arcor.de                                         *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License version 2.0 as   *
00007  *   published by the Free Software Foundation.                            *
00008  *                                                                         *
00009  *   This program is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU General Public License for more details.                          *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU General Public License     *
00015  *   along with this program in the file LICENSE.GPL; if not, write to the *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00018  ***************************************************************************/
00019 
00020 #include "UiGuiSystemInfo.h"
00021 
00022 #include <QString>
00023 #include <QSysInfo>
00024 #include <QProcess>
00025 #include <QFile>
00026 
00027 UiGuiSystemInfo::UiGuiSystemInfo() {
00028 }
00029 
00030 
00036 QString UiGuiSystemInfo::getOperatingSystem() {
00037     QString operatingSystemString = "";
00038 
00039 #if defined(Q_WS_WIN)
00040     switch ( QSysInfo::WindowsVersion ) {
00041         case QSysInfo::WV_32s :
00042             operatingSystemString = "Windows 3.1 with Win 32s";
00043             break;
00044         case QSysInfo::WV_95 :
00045             operatingSystemString = "Windows 95";
00046             break;
00047         case QSysInfo::WV_98 :
00048             operatingSystemString = "Windows 98";
00049             break;
00050         case QSysInfo::WV_Me :
00051             operatingSystemString = "Windows Me";
00052             break;
00053         case QSysInfo::WV_NT :
00054             operatingSystemString = "Windows NT (operating system version 4.0)";
00055             break;
00056         case QSysInfo::WV_2000 :
00057             operatingSystemString = "Windows 2000 (operating system version 5.0)";
00058             break;
00059         case QSysInfo::WV_XP :
00060             operatingSystemString = "Windows XP (operating system version 5.1)";
00061             break;
00062         case QSysInfo::WV_2003 :
00063             operatingSystemString = "Windows Server 2003, Windows Server 2003 R2, Windows Home Server, Windows XP Professional x64 Edition (operating system version 5.2)";
00064             break;
00065         case QSysInfo::WV_VISTA :
00066             operatingSystemString = "Windows Vista, Windows Server 2008 (operating system version 6.0)";
00067             break;
00068         case QSysInfo::WV_WINDOWS7 :
00069             operatingSystemString = "Windows 7 (operating system version 6.1)";
00070             break;
00071         case QSysInfo::WV_CE :
00072             operatingSystemString = "Windows CE";
00073             break;
00074         case QSysInfo::WV_CENET :
00075             operatingSystemString = "Windows CE .NET";
00076             break;
00077         case QSysInfo::WV_CE_5 :
00078             operatingSystemString = "Windows CE 5.x";
00079             break;
00080         case QSysInfo::WV_CE_6 :
00081             operatingSystemString = "Windows CE 6.x";
00082             break;
00083         default :
00084             operatingSystemString = "Unknown Windows operating system.";
00085             break;
00086     }
00087 #elif defined(Q_WS_MAC)
00088     switch ( QSysInfo::MacintoshVersion ) {
00089         case QSysInfo::MV_9 :
00090             operatingSystemString = "Mac OS 9 (unsupported)";
00091             break;
00092         case QSysInfo::MV_10_0 :
00093             operatingSystemString = "Mac OS X 10.0 Cheetah (unsupported)";
00094             break;
00095         case QSysInfo::MV_10_1 :
00096             operatingSystemString = "Mac OS X 10.1 Puma (unsupported)";
00097             break;
00098         case QSysInfo::MV_10_2 :
00099             operatingSystemString = "Mac OS X 10.2 Jaguar (unsupported)";
00100             break;
00101         case QSysInfo::MV_10_3 :
00102             operatingSystemString = "Mac OS X 10.3 Panther";
00103             break;
00104         case QSysInfo::MV_10_4 :
00105             operatingSystemString = "Mac OS X 10.4 Tiger";
00106             break;
00107         case QSysInfo::MV_10_5 :
00108             operatingSystemString = "Mac OS X 10.5 Leopard";
00109             break;
00110         case QSysInfo::MV_10_6 :
00111             operatingSystemString = "Mac OS X 10.6 Snow Leopard";
00112             break;
00113         case QSysInfo::MV_Unknown :
00114             operatingSystemString = "An unknown and currently unsupported platform";
00115             break;
00116         default :
00117             operatingSystemString = "Unknown Mac operating system.";
00118             break;
00119     }
00120 #else
00121     //TODO: Detect Unix, Linux etc. distro as described on http://www.novell.com/coolsolutions/feature/11251.html
00122     operatingSystemString = "Linux";
00123     QProcess process;
00124 
00125     process.start("uname -s");
00126     bool result = process.waitForFinished(1000);
00127     QString os = process.readAllStandardOutput().trimmed();
00128 
00129     process.start("uname -r");
00130     result = process.waitForFinished(1000);
00131     QString rev = process.readAllStandardOutput().trimmed();
00132 
00133     process.start("uname -m");
00134     result = process.waitForFinished(1000);
00135     QString mach = process.readAllStandardOutput().trimmed();
00136 
00137     if ( os == "SunOS" ) {
00138         os = "Solaris";
00139 
00140         process.start("uname -p");
00141         result = process.waitForFinished(1000);
00142         QString arch = process.readAllStandardOutput().trimmed();
00143 
00144         process.start("uname -v");
00145         result = process.waitForFinished(1000);
00146         QString timestamp = process.readAllStandardOutput().trimmed();
00147 
00148         operatingSystemString = os + " " + rev + " (" + arch + " " + timestamp + ")";
00149     }
00150     else if ( os == "AIX" ) {
00151         process.start("oslevel -r");
00152         result = process.waitForFinished(1000);
00153         QString oslevel = process.readAllStandardOutput().trimmed();
00154 
00155         operatingSystemString = os + "oslevel " + oslevel;
00156     }
00157     else if ( os == "Linux" ) {
00158         QString dist;
00159         QString pseudoname;
00160         QString kernel = rev;
00161 
00162         if ( QFile::exists("/etc/redhat-release") ) {
00163             dist = "RedHat";
00164 
00165             process.start("sh -c \"cat /etc/redhat-release | sed s/.*\\(// | sed s/\\)//\"");
00166             result = process.waitForFinished(1000);
00167             pseudoname = process.readAllStandardOutput().trimmed();
00168 
00169             process.start("sh -c \"cat /etc/redhat-release | sed s/.*release\\ // | sed s/\\ .*//\"");
00170             result = process.waitForFinished(1000);
00171             rev = process.readAllStandardOutput().trimmed();
00172         }
00173         else if ( QFile::exists("/etc/SUSE-release") ) {
00174             process.start("sh -c \"cat /etc/SUSE-release | tr '\\n' ' '| sed s/VERSION.*//\"");
00175             result = process.waitForFinished(1000);
00176             dist = process.readAllStandardOutput().trimmed();
00177 
00178             process.start("sh -c \"cat /etc/SUSE-release | tr '\\n' ' ' | sed s/.*=\\ //\"");
00179             result = process.waitForFinished(1000);
00180             rev = process.readAllStandardOutput().trimmed();
00181         }
00182         else if ( QFile::exists("/etc/mandrake-release") ) {
00183             dist = "Mandrake";
00184 
00185             process.start("sh -c \"cat /etc/mandrake-release | sed s/.*\\(// | sed s/\\)//\"");
00186             result = process.waitForFinished(1000);
00187             pseudoname = process.readAllStandardOutput().trimmed();
00188 
00189             process.start("sh -c \"cat /etc/mandrake-release | sed s/.*release\\ // | sed s/\\ .*//\"");
00190             result = process.waitForFinished(1000);
00191             rev = process.readAllStandardOutput().trimmed();
00192         }
00193         else if ( QFile::exists("/etc/lsb-release") ) {
00194             dist = "Ubuntu";
00195 
00196             QString processCall = "sh -c \"cat /etc/lsb-release | tr '\\n' ' ' | sed s/.*DISTRIB_RELEASE=// | sed s/\\ .*//\"";
00197             process.start( processCall );
00198             result = process.waitForFinished(1000);
00199             rev = process.readAllStandardOutput().trimmed();
00200             QString errorStr = process.readAllStandardError();
00201 
00202             process.start("sh -c \"cat /etc/lsb-release | tr '\\n' ' ' | sed s/.*DISTRIB_CODENAME=// | sed s/\\ .*//\"");
00203             result = process.waitForFinished(1000);
00204             pseudoname = process.readAllStandardOutput().trimmed();
00205         }
00206         else if ( QFile::exists("/etc/debian_version") ) {
00207             dist = "Debian";
00208 
00209             process.start("cat /etc/debian_version");
00210             result = process.waitForFinished(1000);
00211             dist += process.readAllStandardOutput().trimmed();
00212 
00213             rev = "";
00214         }
00215 
00216         if ( QFile::exists("/etc/UnitedLinux-release") ) {
00217             process.start("sh -c \"cat /etc/UnitedLinux-release | tr '\\n' ' ' | sed s/VERSION.*//\"");
00218             result = process.waitForFinished(1000);
00219             dist += process.readAllStandardOutput().trimmed();
00220         }
00221 
00222         operatingSystemString = os + " " + dist + " " + rev + " (" + pseudoname + " " + kernel + " " + mach + ")";
00223     }
00224 #endif
00225 
00226     return operatingSystemString;
00227 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines