summaryrefslogtreecommitdiffstats
path: root/src/UiGuiSystemInfo.cpp
blob: 5456519602767cf32453a545e9c621e11cc32ad5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
/***************************************************************************
 *   Copyright (C) 2006-2012 by Thomas Schweitzer                          *
 *   thomas-schweitzer(at)arcor.de                                         *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License version 2.0 as   *
 *   published by the Free Software Foundation.                            *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program in the file LICENSE.GPL; if not, write to the *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#include "UiGuiSystemInfo.h"

#include <tntqstring.h>
#include <tqsysinfo.h>
#include <tntqprocess.h>
#include <tntqfile.h>

UiGuiSystemInfo::UiGuiSystemInfo()
{
}

/*!
    \brief Returns the operating system UiGUI is currently running on as one string.

    The String contains name and version of the os. E.g. Linux Ubuntu 9.04.
 */
TQString UiGuiSystemInfo::getOperatingSystem()
{
	TQString operatingSystemString = "";

#if defined (Q_WS_WIN)
	switch (TQSysInfo::WindowsVersion)
	{
		case TQSysInfo::WV_32s:
		{
			operatingSystemString = "Windows 3.1 with Win 32s";
			break;
		}

		case TQSysInfo::WV_95:
		{
			operatingSystemString = "Windows 95";
			break;
		}

		case TQSysInfo::WV_98:
		{
			operatingSystemString = "Windows 98";
			break;
		}

		case TQSysInfo::WV_Me:
		{
			operatingSystemString = "Windows Me";
			break;
		}

		case TQSysInfo::WV_NT:
		{
			operatingSystemString = "Windows NT (operating system version 4.0)";
			break;
		}

		case TQSysInfo::WV_2000:
		{
			operatingSystemString = "Windows 2000 (operating system version 5.0)";
			break;
		}

		case TQSysInfo::WV_XP:
		{
			operatingSystemString = "Windows XP (operating system version 5.1)";
			break;
		}

		case TQSysInfo::WV_2003:
		{
			operatingSystemString =
			        "Windows Server 2003, Windows Server 2003 R2, Windows Home Server, Windows XP Professional x64 Edition (operating system version 5.2)";
			break;
		}

		case TQSysInfo::WV_VISTA:
		{
			operatingSystemString = "Windows Vista, Windows Server 2008 (operating system version 6.0)";
			break;
		}

		case TQSysInfo::WV_WINDOWS7:
		{
			operatingSystemString = "Windows 7 (operating system version 6.1)";
			break;
		}

		case TQSysInfo::WV_CE:
		{
			operatingSystemString = "Windows CE";
			break;
		}

		case TQSysInfo::WV_CENET:
		{
			operatingSystemString = "Windows CE .NET";
			break;
		}

		case TQSysInfo::WV_CE_5:
		{
			operatingSystemString = "Windows CE 5.x";
			break;
		}

		case TQSysInfo::WV_CE_6:
		{
			operatingSystemString = "Windows CE 6.x";
			break;
		}

		default:
		{
			operatingSystemString = "Unknown Windows operating system.";
			break;
		}
	}
#elif defined (Q_WS_MAC)
	switch (TQSysInfo::MacintoshVersion)
	{
		case TQSysInfo::MV_9:
		{
			operatingSystemString = "Mac OS 9 (unsupported)";
			break;
		}

		case TQSysInfo::MV_10_0:
		{
			operatingSystemString = "Mac OS X 10.0 Cheetah (unsupported)";
			break;
		}

		case TQSysInfo::MV_10_1:
		{
			operatingSystemString = "Mac OS X 10.1 Puma (unsupported)";
			break;
		}

		case TQSysInfo::MV_10_2:
		{
			operatingSystemString = "Mac OS X 10.2 Jaguar (unsupported)";
			break;
		}

		case TQSysInfo::MV_10_3:
		{
			operatingSystemString = "Mac OS X 10.3 Panther";
			break;
		}

		case TQSysInfo::MV_10_4:
		{
			operatingSystemString = "Mac OS X 10.4 Tiger";
			break;
		}

		case TQSysInfo::MV_10_5:
		{
			operatingSystemString = "Mac OS X 10.5 Leopard";
			break;
		}

		case TQSysInfo::MV_10_6:
		{
			operatingSystemString = "Mac OS X 10.6 Snow Leopard";
			break;
		}

		case TQSysInfo::MV_Unknown:
		{
			operatingSystemString = "An unknown and currently unsupported platform";
			break;
		}

		default:
		{
			operatingSystemString = "Unknown Mac operating system.";
			break;
		}
	}
#else
	//TODO: Detect Unix, Linux etc. distro as described on
	// http://www.novell.com/coolsolutions/feature/11251.html
	operatingSystemString = "Linux";
	TQProcess process;

	process.start("uname -s");
	bool     result = process.waitForFinished(1000);
	TQString os     = process.readAllStandardOutput().trimmed();

	process.start("uname -r");
	result = process.waitForFinished(1000);
	TQString rev = process.readAllStandardOutput().trimmed();

	process.start("uname -m");
	result = process.waitForFinished(1000);
	TQString mach = process.readAllStandardOutput().trimmed();

	if (os == "SunOS")
	{
		os = "Solaris";

		process.start("uname -p");
		result = process.waitForFinished(1000);
		TQString arch = process.readAllStandardOutput().trimmed();

		process.start("uname -v");
		result = process.waitForFinished(1000);
		TQString timestamp = process.readAllStandardOutput().trimmed();

		operatingSystemString = os + " " + rev + " (" + arch + " " + timestamp + ")";
	}
	else if (os == "AIX")
	{
		process.start("oslevel -r");
		result = process.waitForFinished(1000);
		TQString oslevel = process.readAllStandardOutput().trimmed();

		operatingSystemString = os + "oslevel " + oslevel;
	}
	else if (os == "Linux")
	{
		TQString dist;
		TQString pseudoname;
		TQString kernel = rev;

		if (TQFile::exists("/etc/redhat-release"))
		{
			dist = "RedHat";

			process.start("sh -c \"cat /etc/redhat-release | sed s/.*\\(// | sed s/\\)//\"");
			result     = process.waitForFinished(1000);
			pseudoname = process.readAllStandardOutput().trimmed();

			process.start("sh -c \"cat /etc/redhat-release | sed s/.*release\\ // | sed s/\\ .*//\"");
			result = process.waitForFinished(1000);
			rev    = process.readAllStandardOutput().trimmed();
		}
		else if (TQFile::exists("/etc/SUSE-release"))
		{
			process.start("sh -c \"cat /etc/SUSE-release | tr '\\n' ' '| sed s/VERSION.*//\"");
			result = process.waitForFinished(1000);
			dist   = process.readAllStandardOutput().trimmed();

			process.start("sh -c \"cat /etc/SUSE-release | tr '\\n' ' ' | sed s/.*=\\ //\"");
			result = process.waitForFinished(1000);
			rev    = process.readAllStandardOutput().trimmed();
		}
		else if (TQFile::exists("/etc/mandrake-release"))
		{
			dist = "Mandrake";

			process.start("sh -c \"cat /etc/mandrake-release | sed s/.*\\(// | sed s/\\)//\"");
			result     = process.waitForFinished(1000);
			pseudoname = process.readAllStandardOutput().trimmed();

			process.start("sh -c \"cat /etc/mandrake-release | sed s/.*release\\ // | sed s/\\ .*//\"");
			result = process.waitForFinished(1000);
			rev    = process.readAllStandardOutput().trimmed();
		}
		else if (TQFile::exists("/etc/lsb-release"))
		{
			dist = "Ubuntu";

			TQString processCall =
			        "sh -c \"cat /etc/lsb-release | tr '\\n' ' ' | sed s/.*DISTRIB_RELEASE=// | sed s/\\ .*//\"";
			process.start(processCall);
			result = process.waitForFinished(1000);
			rev    = process.readAllStandardOutput().trimmed();
			TQString errorStr = process.readAllStandardError();

			process.start(
				"sh -c \"cat /etc/lsb-release | tr '\\n' ' ' | sed s/.*DISTRIB_CODENAME=// | sed s/\\ .*//\"");
			result     = process.waitForFinished(1000);
			pseudoname = process.readAllStandardOutput().trimmed();
		}
		else if (TQFile::exists("/etc/debian_version"))
		{
			dist = "Debian";

			process.start("cat /etc/debian_version");
			result = process.waitForFinished(1000);
			dist  += process.readAllStandardOutput().trimmed();

			rev = "";
		}

		if (TQFile::exists("/etc/UnitedLinux-release"))
		{
			process.start("sh -c \"cat /etc/UnitedLinux-release | tr '\\n' ' ' | sed s/VERSION.*//\"");
			result = process.waitForFinished(1000);
			dist  += process.readAllStandardOutput().trimmed();
		}

		operatingSystemString = os + " " + dist + " " + rev + " (" + pseudoname + " " + kernel + " " +
		        mach + ")";
	}
#endif

	return operatingSystemString;
}