diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2008-06-21 10:28:10 +0000 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2008-06-21 10:28:10 +0000 |
commit | 1876a0bcf227a41956c30d513c5d486b69cc2a99 (patch) | |
tree | df4b68808e603e91f5b57c006553e03177ba8288 | |
parent | 5b2d06ad513f2aa0c03726cd7d9465e70e0ae22b (diff) | |
download | rockbox-1876a0bcf227a41956c30d513c5d486b69cc2a99.tar.gz rockbox-1876a0bcf227a41956c30d513c5d486b69cc2a99.zip |
Add System Info screen showing some values that could be helpful in case of problems using rbutil. Most noteable is showing the permission level of the user on windows.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17736 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | rbutil/rbutilqt/autodetection.cpp | 140 | ||||
-rw-r--r-- | rbutil/rbutilqt/icons/view-refresh.png | bin | 0 -> 912 bytes | |||
-rw-r--r-- | rbutil/rbutilqt/rbutilqt.cpp | 9 | ||||
-rw-r--r-- | rbutil/rbutilqt/rbutilqt.h | 1 | ||||
-rw-r--r-- | rbutil/rbutilqt/rbutilqt.pro | 11 | ||||
-rw-r--r-- | rbutil/rbutilqt/rbutilqt.qrc | 1 | ||||
-rw-r--r-- | rbutil/rbutilqt/rbutilqtfrm.ui | 14 | ||||
-rw-r--r-- | rbutil/rbutilqt/sysinfo.cpp | 54 | ||||
-rw-r--r-- | rbutil/rbutilqt/sysinfo.h | 42 | ||||
-rw-r--r-- | rbutil/rbutilqt/sysinfofrm.ui | 66 | ||||
-rw-r--r-- | rbutil/rbutilqt/utils.cpp | 221 | ||||
-rw-r--r-- | rbutil/rbutilqt/utils.h | 9 |
12 files changed, 435 insertions, 133 deletions
diff --git a/rbutil/rbutilqt/autodetection.cpp b/rbutil/rbutilqt/autodetection.cpp index 3684d55908..f257f5c0c9 100644 --- a/rbutil/rbutilqt/autodetection.cpp +++ b/rbutil/rbutilqt/autodetection.cpp | |||
@@ -40,6 +40,7 @@ | |||
40 | #include <windows.h> | 40 | #include <windows.h> |
41 | #include <setupapi.h> | 41 | #include <setupapi.h> |
42 | #endif | 42 | #endif |
43 | #include "utils.h" | ||
43 | 44 | ||
44 | Autodetection::Autodetection(QObject* parent): QObject(parent) | 45 | Autodetection::Autodetection(QObject* parent): QObject(parent) |
45 | { | 46 | { |
@@ -265,132 +266,27 @@ bool Autodetection::detectUsb() | |||
265 | QMap<int, QString> usbincompat = settings->usbIdIncompatMap(); | 266 | QMap<int, QString> usbincompat = settings->usbIdIncompatMap(); |
266 | 267 | ||
267 | // usb pid detection | 268 | // usb pid detection |
268 | #if defined(Q_OS_LINUX) | defined(Q_OS_MACX) | 269 | QList<uint32_t> attached; |
269 | usb_init(); | 270 | attached = listUsbIds(); |
270 | usb_find_busses(); | 271 | |
271 | usb_find_devices(); | 272 | int i = attached.size(); |
272 | struct usb_bus *b; | 273 | while(i--) { |
273 | b = usb_get_busses(); | 274 | if(usbids.contains(attached.at(i))) { |
274 | 275 | m_device = usbids.value(attached.at(i)); | |
275 | while(b) { | 276 | qDebug() << "[USB] detected supported player" << m_device; |
276 | qDebug() << "bus:" << b->dirname << b->devices; | 277 | return true; |
277 | if(b->devices) { | ||
278 | qDebug() << "devices present."; | ||
279 | struct usb_device *u; | ||
280 | u = b->devices; | ||
281 | while(u) { | ||
282 | uint32_t id; | ||
283 | id = u->descriptor.idVendor << 16 | u->descriptor.idProduct; | ||
284 | m_usbconid.append(id); | ||
285 | qDebug("%x", id); | ||
286 | |||
287 | if(usbids.contains(id)) { | ||
288 | m_device = usbids.value(id); | ||
289 | return true; | ||
290 | } | ||
291 | if(usberror.contains(id)) { | ||
292 | m_errdev = usberror.value(id); | ||
293 | // we detected something, so return true | ||
294 | qDebug() << "detected device with problems via usb!"; | ||
295 | return true; | ||
296 | } | ||
297 | if(usbincompat.contains(id)) { | ||
298 | m_incompat = usbincompat.value(id); | ||
299 | qDebug() << "detected incompatible player variant"; | ||
300 | return true; | ||
301 | } | ||
302 | u = u->next; | ||
303 | } | ||
304 | } | 278 | } |
305 | b = b->next; | 279 | if(usberror.contains(attached.at(i))) { |
306 | } | 280 | m_errdev = usberror.value(attached.at(i)); |
307 | #endif | 281 | qDebug() << "[USB] detected problem with player" << m_errdev; |
308 | 282 | return true; | |
309 | #if defined(Q_OS_WIN32) | ||
310 | HDEVINFO deviceInfo; | ||
311 | SP_DEVINFO_DATA infoData; | ||
312 | DWORD i; | ||
313 | |||
314 | // Iterate over all devices | ||
315 | // by doing it this way it's unneccessary to use GUIDs which might be not | ||
316 | // present in current MinGW. It also seemed to be more reliably than using | ||
317 | // a GUID. | ||
318 | // See KB259695 for an example. | ||
319 | deviceInfo = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT); | ||
320 | |||
321 | infoData.cbSize = sizeof(SP_DEVINFO_DATA); | ||
322 | |||
323 | for(i = 0; SetupDiEnumDeviceInfo(deviceInfo, i, &infoData); i++) { | ||
324 | DWORD data; | ||
325 | LPTSTR buffer = NULL; | ||
326 | DWORD buffersize = 0; | ||
327 | |||
328 | // get device desriptor first | ||
329 | // for some reason not doing so results in bad things (tm) | ||
330 | while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData, | ||
331 | SPDRP_DEVICEDESC,&data, (PBYTE)buffer, buffersize, &buffersize)) { | ||
332 | if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) { | ||
333 | if(buffer) free(buffer); | ||
334 | // double buffer size to avoid problems as per KB888609 | ||
335 | buffer = (LPTSTR)malloc(buffersize * 2); | ||
336 | } | ||
337 | else { | ||
338 | break; | ||
339 | } | ||
340 | } | 283 | } |
341 | 284 | if(usbincompat.contains(attached.at(i))) { | |
342 | // now get the hardware id, which contains PID and VID. | 285 | m_incompat = usbincompat.value(attached.at(i)); |
343 | while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData, | 286 | qDebug() << "[USB] detected incompatible player" << m_incompat; |
344 | SPDRP_HARDWAREID,&data, (PBYTE)buffer, buffersize, &buffersize)) { | 287 | return true; |
345 | if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) { | ||
346 | if(buffer) free(buffer); | ||
347 | // double buffer size to avoid problems as per KB888609 | ||
348 | buffer = (LPTSTR)malloc(buffersize * 2); | ||
349 | } | ||
350 | else { | ||
351 | break; | ||
352 | } | ||
353 | } | ||
354 | |||
355 | unsigned int vid, pid, rev; | ||
356 | if(_stscanf(buffer, _TEXT("USB\\Vid_%x&Pid_%x&Rev_%x"), &vid, &pid, &rev) != 3) { | ||
357 | qDebug() << "Error getting USB ID -- possibly no USB device"; | ||
358 | } | 288 | } |
359 | else { | ||
360 | uint32_t id; | ||
361 | id = vid << 16 | pid; | ||
362 | m_usbconid.append(id); | ||
363 | qDebug("VID: %04x PID: %04x", vid, pid); | ||
364 | if(usbids.contains(id)) { | ||
365 | m_device = usbids.value(id); | ||
366 | if(buffer) free(buffer); | ||
367 | SetupDiDestroyDeviceInfoList(deviceInfo); | ||
368 | qDebug() << "detectUsb: Got" << m_device; | ||
369 | return true; | ||
370 | } | ||
371 | if(usberror.contains(id)) { | ||
372 | m_errdev = usberror.value(id); | ||
373 | // we detected something, so return true | ||
374 | if(buffer) free(buffer); | ||
375 | SetupDiDestroyDeviceInfoList(deviceInfo); | ||
376 | qDebug() << "detectUsb: Got" << m_device; | ||
377 | qDebug() << "detected device with problems via usb!"; | ||
378 | return true; | ||
379 | } | ||
380 | if(usbincompat.contains(id)) { | ||
381 | m_incompat = usbincompat.value(id); | ||
382 | // we detected an incompatible player variant | ||
383 | if(buffer) free(buffer); | ||
384 | SetupDiDestroyDeviceInfoList(deviceInfo); | ||
385 | qDebug() << "detectUsb: detected incompatible variant"; | ||
386 | return true; | ||
387 | } | ||
388 | } | ||
389 | if(buffer) free(buffer); | ||
390 | } | 289 | } |
391 | SetupDiDestroyDeviceInfoList(deviceInfo); | ||
392 | |||
393 | #endif | ||
394 | return false; | 290 | return false; |
395 | } | 291 | } |
396 | 292 | ||
diff --git a/rbutil/rbutilqt/icons/view-refresh.png b/rbutil/rbutilqt/icons/view-refresh.png new file mode 100644 index 0000000000..3fd71d6e59 --- /dev/null +++ b/rbutil/rbutilqt/icons/view-refresh.png | |||
Binary files differ | |||
diff --git a/rbutil/rbutilqt/rbutilqt.cpp b/rbutil/rbutilqt/rbutilqt.cpp index c1523cb92e..a669949aa9 100644 --- a/rbutil/rbutilqt/rbutilqt.cpp +++ b/rbutil/rbutilqt/rbutilqt.cpp | |||
@@ -34,6 +34,8 @@ | |||
34 | #include "browseof.h" | 34 | #include "browseof.h" |
35 | #include "utils.h" | 35 | #include "utils.h" |
36 | #include "rbzip.h" | 36 | #include "rbzip.h" |
37 | #include "sysinfo.h" | ||
38 | |||
37 | 39 | ||
38 | #if defined(Q_OS_LINUX) | 40 | #if defined(Q_OS_LINUX) |
39 | #include <stdio.h> | 41 | #include <stdio.h> |
@@ -101,6 +103,7 @@ RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent) | |||
101 | connect(ui.actionCreate_Talk_Files, SIGNAL(triggered()), this, SLOT(createTalkFiles())); | 103 | connect(ui.actionCreate_Talk_Files, SIGNAL(triggered()), this, SLOT(createTalkFiles())); |
102 | connect(ui.actionRemove_bootloader, SIGNAL(triggered()), this, SLOT(uninstallBootloader())); | 104 | connect(ui.actionRemove_bootloader, SIGNAL(triggered()), this, SLOT(uninstallBootloader())); |
103 | connect(ui.actionUninstall_Rockbox, SIGNAL(triggered()), this, SLOT(uninstall())); | 105 | connect(ui.actionUninstall_Rockbox, SIGNAL(triggered()), this, SLOT(uninstall())); |
106 | connect(ui.action_System_Info, SIGNAL(triggered()), this, SLOT(sysinfo())); | ||
104 | 107 | ||
105 | #if !defined(STATIC) | 108 | #if !defined(STATIC) |
106 | ui.actionInstall_Rockbox_Utility_on_player->setEnabled(false); | 109 | ui.actionInstall_Rockbox_Utility_on_player->setEnabled(false); |
@@ -115,6 +118,12 @@ RbUtilQt::RbUtilQt(QWidget *parent) : QMainWindow(parent) | |||
115 | } | 118 | } |
116 | 119 | ||
117 | 120 | ||
121 | void RbUtilQt::sysinfo(void) | ||
122 | { | ||
123 | Sysinfo *info = new Sysinfo(this); | ||
124 | info->show(); | ||
125 | } | ||
126 | |||
118 | void RbUtilQt::updateTabs(int count) | 127 | void RbUtilQt::updateTabs(int count) |
119 | { | 128 | { |
120 | switch(count) { | 129 | switch(count) { |
diff --git a/rbutil/rbutilqt/rbutilqt.h b/rbutil/rbutilqt/rbutilqt.h index 8de5ea0113..3c6cbd0784 100644 --- a/rbutil/rbutilqt/rbutilqt.h +++ b/rbutil/rbutilqt/rbutilqt.h | |||
@@ -66,6 +66,7 @@ class RbUtilQt : public QMainWindow | |||
66 | private slots: | 66 | private slots: |
67 | void about(void); | 67 | void about(void); |
68 | void help(void); | 68 | void help(void); |
69 | void sysinfo(void); | ||
69 | void configDialog(void); | 70 | void configDialog(void); |
70 | void updateDevice(void); | 71 | void updateDevice(void); |
71 | void updateSettings(void); | 72 | void updateSettings(void); |
diff --git a/rbutil/rbutilqt/rbutilqt.pro b/rbutil/rbutilqt/rbutilqt.pro index a10d06591e..9e9e8c4976 100644 --- a/rbutil/rbutilqt/rbutilqt.pro +++ b/rbutil/rbutilqt/rbutilqt.pro | |||
@@ -62,7 +62,8 @@ SOURCES += rbutilqt.cpp \ | |||
62 | createvoicewindow.cpp \ | 62 | createvoicewindow.cpp \ |
63 | rbsettings.cpp \ | 63 | rbsettings.cpp \ |
64 | rbunzip.cpp \ | 64 | rbunzip.cpp \ |
65 | rbzip.cpp | 65 | rbzip.cpp \ |
66 | sysinfo.cpp | ||
66 | 67 | ||
67 | HEADERS += rbutilqt.h \ | 68 | HEADERS += rbutilqt.h \ |
68 | install.h \ | 69 | install.h \ |
@@ -109,7 +110,8 @@ HEADERS += rbutilqt.h \ | |||
109 | createvoicewindow.h \ | 110 | createvoicewindow.h \ |
110 | rbsettings.h \ | 111 | rbsettings.h \ |
111 | rbunzip.h \ | 112 | rbunzip.h \ |
112 | rbzip.h | 113 | rbzip.h \ |
114 | sysinfo.h | ||
113 | 115 | ||
114 | # Needed by QT on Win | 116 | # Needed by QT on Win |
115 | INCLUDEPATH = . irivertools zip zlib ../ipodpatcher ../sansapatcher ../../tools/rbspeex ../../tools | 117 | INCLUDEPATH = . irivertools zip zlib ../ipodpatcher ../sansapatcher ../../tools/rbspeex ../../tools |
@@ -145,7 +147,8 @@ FORMS += rbutilqtfrm.ui \ | |||
145 | encexescfgfrm.ui \ | 147 | encexescfgfrm.ui \ |
146 | ttsexescfgfrm.ui \ | 148 | ttsexescfgfrm.ui \ |
147 | sapicfgfrm.ui \ | 149 | sapicfgfrm.ui \ |
148 | createvoicefrm.ui | 150 | createvoicefrm.ui \ |
151 | sysinfofrm.ui | ||
149 | 152 | ||
150 | RESOURCES += rbutilqt.qrc | 153 | RESOURCES += rbutilqt.qrc |
151 | win32 { | 154 | win32 { |
@@ -164,7 +167,7 @@ win32 { | |||
164 | SOURCES += ../ipodpatcher/ipodio-win32.c | 167 | SOURCES += ../ipodpatcher/ipodio-win32.c |
165 | SOURCES += ../sansapatcher/sansaio-win32.c | 168 | SOURCES += ../sansapatcher/sansaio-win32.c |
166 | RC_FILE = rbutilqt.rc | 169 | RC_FILE = rbutilqt.rc |
167 | LIBS += -lsetupapi | 170 | LIBS += -lsetupapi -lnetapi32 |
168 | } | 171 | } |
169 | 172 | ||
170 | unix { | 173 | unix { |
diff --git a/rbutil/rbutilqt/rbutilqt.qrc b/rbutil/rbutilqt/rbutilqt.qrc index 694836c781..62a804180c 100644 --- a/rbutil/rbutilqt/rbutilqt.qrc +++ b/rbutil/rbutilqt/rbutilqt.qrc | |||
@@ -31,6 +31,7 @@ | |||
31 | <file>icons/talkfile_btn.png</file> | 31 | <file>icons/talkfile_btn.png</file> |
32 | <file>icons/themes_btn.png</file> | 32 | <file>icons/themes_btn.png</file> |
33 | <file>icons/user-trash-full.png</file> | 33 | <file>icons/user-trash-full.png</file> |
34 | <file>icons/view-refresh.png</file> | ||
34 | <file>icons/wizard.xpm</file> | 35 | <file>icons/wizard.xpm</file> |
35 | </qresource> | 36 | </qresource> |
36 | <qresource prefix="/ini" > | 37 | <qresource prefix="/ini" > |
diff --git a/rbutil/rbutilqt/rbutilqtfrm.ui b/rbutil/rbutilqt/rbutilqtfrm.ui index 90018a3301..804856414f 100644 --- a/rbutil/rbutilqt/rbutilqtfrm.ui +++ b/rbutil/rbutilqt/rbutilqtfrm.ui | |||
@@ -94,9 +94,9 @@ | |||
94 | <item row="0" column="1" > | 94 | <item row="0" column="1" > |
95 | <widget class="QLabel" name="labelDevice" > | 95 | <widget class="QLabel" name="labelDevice" > |
96 | <property name="text" > | 96 | <property name="text" > |
97 | <string><html><head><meta name="qrichtext" content="1" /><style type="text/css"> | 97 | <string><html><head><meta name="qrichtext" content="1" /><style type="text/css">
 |
98 | p, li { white-space: pre-wrap; } | 98 | p, li { white-space: pre-wrap; }
 |
99 | </style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;"> | 99 | </style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
 |
100 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">none</span> at <span style=" font-weight:600;">unknown</span></p></body></html></string> | 100 | <p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">none</span> at <span style=" font-weight:600;">unknown</span></p></body></html></string> |
101 | </property> | 101 | </property> |
102 | </widget> | 102 | </widget> |
@@ -539,7 +539,7 @@ p, li { white-space: pre-wrap; } | |||
539 | <item row="1" column="1" > | 539 | <item row="1" column="1" > |
540 | <widget class="QLabel" name="labelCreateVoice" > | 540 | <widget class="QLabel" name="labelCreateVoice" > |
541 | <property name="text" > | 541 | <property name="text" > |
542 | <string><b>Create Voice file</b><br/>Voice files are needed to make Rockbox speak the user interface. Speaking is enabled by default, so | 542 | <string><b>Create Voice file</b><br/>Voice files are needed to make Rockbox speak the user interface. Speaking is enabled by default, so
 |
543 | if you installed the voice file Rockbox will speak.</string> | 543 | if you installed the voice file Rockbox will speak.</string> |
544 | </property> | 544 | </property> |
545 | <property name="wordWrap" > | 545 | <property name="wordWrap" > |
@@ -806,6 +806,7 @@ p, li { white-space: pre-wrap; } | |||
806 | <addaction name="action_About" /> | 806 | <addaction name="action_About" /> |
807 | <addaction name="actionAbout_Qt" /> | 807 | <addaction name="actionAbout_Qt" /> |
808 | <addaction name="separator" /> | 808 | <addaction name="separator" /> |
809 | <addaction name="action_System_Info" /> | ||
809 | <addaction name="action_Help" /> | 810 | <addaction name="action_Help" /> |
810 | </widget> | 811 | </widget> |
811 | <widget class="QMenu" name="menuA_ctions" > | 812 | <widget class="QMenu" name="menuA_ctions" > |
@@ -1022,6 +1023,11 @@ p, li { white-space: pre-wrap; } | |||
1022 | <string>Create Voice File</string> | 1023 | <string>Create Voice File</string> |
1023 | </property> | 1024 | </property> |
1024 | </action> | 1025 | </action> |
1026 | <action name="action_System_Info" > | ||
1027 | <property name="text" > | ||
1028 | <string>&System Info</string> | ||
1029 | </property> | ||
1030 | </action> | ||
1025 | </widget> | 1031 | </widget> |
1026 | <tabstops> | 1032 | <tabstops> |
1027 | <tabstop>tabWidget</tabstop> | 1033 | <tabstop>tabWidget</tabstop> |
diff --git a/rbutil/rbutilqt/sysinfo.cpp b/rbutil/rbutilqt/sysinfo.cpp new file mode 100644 index 0000000000..413494c679 --- /dev/null +++ b/rbutil/rbutilqt/sysinfo.cpp | |||
@@ -0,0 +1,54 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2007 by Dominik Riebeling | ||
10 | * $Id$ | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include <QtGui> | ||
21 | #include "sysinfo.h" | ||
22 | #include "ui_sysinfofrm.h" | ||
23 | #include "utils.h" | ||
24 | |||
25 | |||
26 | Sysinfo::Sysinfo(QWidget *parent) : QDialog(parent) | ||
27 | { | ||
28 | ui.setupUi(this); | ||
29 | this->setModal(true); | ||
30 | |||
31 | updateSysinfo(); | ||
32 | connect(ui.buttonOk, SIGNAL(clicked()), this, SLOT(close())); | ||
33 | connect(ui.buttonRefresh, SIGNAL(clicked()), this, SLOT(updateSysinfo())); | ||
34 | } | ||
35 | |||
36 | |||
37 | void Sysinfo::updateSysinfo(void) | ||
38 | { | ||
39 | QString info; | ||
40 | info += tr("<b>OS</b><br/>") + getOsVersionString() + "<hr/>"; | ||
41 | info += tr("<b>Username:</b><br/>%1<hr/>").arg(getUserName()); | ||
42 | #if defined(Q_OS_WIN32) | ||
43 | info += tr("<b>Permissions:</b><br/>%1<hr/>").arg(getUserPermissionsString()); | ||
44 | #endif | ||
45 | info += tr("<b>Attached USB devices:</b><br/>"); | ||
46 | QList<uint32_t> usbids = listUsbIds(); | ||
47 | for(int i = 0; i < usbids.size(); i++) | ||
48 | info += tr("VID: %1 PID: %2<br/>") | ||
49 | .arg((usbids.at(i)&0xffff0000)>>16, 4, 16, QChar('0')) | ||
50 | .arg(usbids.at(i)&0xffff, 4, 16, QChar('0')); | ||
51 | |||
52 | ui.textBrowser->setHtml(info); | ||
53 | } | ||
54 | |||
diff --git a/rbutil/rbutilqt/sysinfo.h b/rbutil/rbutilqt/sysinfo.h new file mode 100644 index 0000000000..a3dbed9941 --- /dev/null +++ b/rbutil/rbutilqt/sysinfo.h | |||
@@ -0,0 +1,42 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2007 by Dominik Riebeling | ||
10 | * $Id$ | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #ifndef SYSINFO_H | ||
21 | #define SYSINFO_H | ||
22 | |||
23 | #include <QtGui> | ||
24 | #include "ui_sysinfofrm.h" | ||
25 | |||
26 | class Sysinfo : public QDialog | ||
27 | { | ||
28 | Q_OBJECT | ||
29 | |||
30 | public: | ||
31 | Sysinfo(QWidget *parent = 0); | ||
32 | |||
33 | private: | ||
34 | Ui::SysinfoFrm ui; | ||
35 | |||
36 | private slots: | ||
37 | void updateSysinfo(void); | ||
38 | |||
39 | }; | ||
40 | |||
41 | #endif | ||
42 | |||
diff --git a/rbutil/rbutilqt/sysinfofrm.ui b/rbutil/rbutilqt/sysinfofrm.ui new file mode 100644 index 0000000000..b2340a6310 --- /dev/null +++ b/rbutil/rbutilqt/sysinfofrm.ui | |||
@@ -0,0 +1,66 @@ | |||
1 | <ui version="4.0" > | ||
2 | <class>SysinfoFrm</class> | ||
3 | <widget class="QWidget" name="SysinfoFrm" > | ||
4 | <property name="geometry" > | ||
5 | <rect> | ||
6 | <x>0</x> | ||
7 | <y>0</y> | ||
8 | <width>400</width> | ||
9 | <height>300</height> | ||
10 | </rect> | ||
11 | </property> | ||
12 | <property name="windowTitle" > | ||
13 | <string>System Info</string> | ||
14 | </property> | ||
15 | <layout class="QGridLayout" > | ||
16 | <item row="0" column="0" colspan="3" > | ||
17 | <widget class="QTextBrowser" name="textBrowser" /> | ||
18 | </item> | ||
19 | <item row="1" column="0" > | ||
20 | <widget class="QPushButton" name="buttonRefresh" > | ||
21 | <property name="text" > | ||
22 | <string>&Refresh</string> | ||
23 | </property> | ||
24 | <property name="icon" > | ||
25 | <iconset resource="rbutilqt.qrc" >:/icons/view-refresh.png</iconset> | ||
26 | </property> | ||
27 | </widget> | ||
28 | </item> | ||
29 | <item row="1" column="1" > | ||
30 | <spacer> | ||
31 | <property name="orientation" > | ||
32 | <enum>Qt::Horizontal</enum> | ||
33 | </property> | ||
34 | <property name="sizeHint" > | ||
35 | <size> | ||
36 | <width>40</width> | ||
37 | <height>20</height> | ||
38 | </size> | ||
39 | </property> | ||
40 | </spacer> | ||
41 | </item> | ||
42 | <item row="1" column="2" > | ||
43 | <widget class="QPushButton" name="buttonOk" > | ||
44 | <property name="text" > | ||
45 | <string>&OK</string> | ||
46 | </property> | ||
47 | <property name="icon" > | ||
48 | <iconset resource="rbutilqt.qrc" >:/icons/go-next.png</iconset> | ||
49 | </property> | ||
50 | <property name="default" > | ||
51 | <bool>true</bool> | ||
52 | </property> | ||
53 | </widget> | ||
54 | </item> | ||
55 | </layout> | ||
56 | </widget> | ||
57 | <tabstops> | ||
58 | <tabstop>buttonOk</tabstop> | ||
59 | <tabstop>buttonRefresh</tabstop> | ||
60 | <tabstop>textBrowser</tabstop> | ||
61 | </tabstops> | ||
62 | <resources> | ||
63 | <include location="rbutilqt.qrc" /> | ||
64 | </resources> | ||
65 | <connections/> | ||
66 | </ui> | ||
diff --git a/rbutil/rbutilqt/utils.cpp b/rbutil/rbutilqt/utils.cpp index a552b5cd5e..c95c5cf0eb 100644 --- a/rbutil/rbutilqt/utils.cpp +++ b/rbutil/rbutilqt/utils.cpp | |||
@@ -19,9 +19,10 @@ | |||
19 | 19 | ||
20 | #include "utils.h" | 20 | #include "utils.h" |
21 | 21 | ||
22 | #include <QtCore> | ||
23 | #include <QDebug> | ||
22 | #include <cstdlib> | 24 | #include <cstdlib> |
23 | 25 | #include <stdio.h> | |
24 | #include <QDir> | ||
25 | 26 | ||
26 | #if defined(Q_OS_WIN32) | 27 | #if defined(Q_OS_WIN32) |
27 | #if defined(UNICODE) | 28 | #if defined(UNICODE) |
@@ -29,8 +30,29 @@ | |||
29 | #endif | 30 | #endif |
30 | #include <windows.h> | 31 | #include <windows.h> |
31 | #include <tchar.h> | 32 | #include <tchar.h> |
33 | #include <lm.h> | ||
34 | #endif | ||
35 | #if defined(Q_OS_LINUX) || defined(Q_OS_MACX) | ||
36 | #include <usb.h> | ||
37 | #include <sys/utsname.h> | ||
38 | #include <unistd.h> | ||
39 | #endif | ||
40 | #if defined(Q_OS_LINUX) | ||
41 | #include <mntent.h> | ||
42 | #endif | ||
43 | #if defined(Q_OS_MACX) | ||
44 | #include <sys/param.h> | ||
45 | #include <sys/ucred.h> | ||
46 | #include <sys/mount.h> | ||
47 | #endif | ||
48 | #if defined(Q_OS_WIN32) | ||
49 | #if defined(UNICODE) | ||
50 | #define _UNICODE | ||
51 | #endif | ||
52 | #include <tchar.h> | ||
53 | #include <windows.h> | ||
54 | #include <setupapi.h> | ||
32 | #endif | 55 | #endif |
33 | #include <QDebug> | ||
34 | 56 | ||
35 | // recursive function to delete a dir with files | 57 | // recursive function to delete a dir with files |
36 | bool recRmdir( const QString &dirName ) | 58 | bool recRmdir( const QString &dirName ) |
@@ -157,3 +179,196 @@ QString installedVersion(QString mountpoint) | |||
157 | return ""; | 179 | return ""; |
158 | } | 180 | } |
159 | 181 | ||
182 | |||
183 | QString getUserName(void) | ||
184 | { | ||
185 | #if defined(Q_OS_WIN32) | ||
186 | wchar_t userbuf[UNLEN]; | ||
187 | DWORD usersize = UNLEN; | ||
188 | BOOL status; | ||
189 | |||
190 | status = GetUserNameW(userbuf, &usersize); | ||
191 | |||
192 | return QString::fromWCharArray(userbuf); | ||
193 | #endif | ||
194 | #if defined(Q_OS_LINUX) || defined(Q_OS_MACX) | ||
195 | return QString(getlogin()); | ||
196 | #endif | ||
197 | } | ||
198 | |||
199 | |||
200 | #if defined(Q_OS_WIN32) | ||
201 | enum userlevel getUserPermissions(void) | ||
202 | { | ||
203 | LPUSER_INFO_1 buf; | ||
204 | NET_API_STATUS napistatus; | ||
205 | wchar_t userbuf[UNLEN]; | ||
206 | DWORD usersize = UNLEN; | ||
207 | BOOL status; | ||
208 | enum userlevel result; | ||
209 | |||
210 | status = GetUserNameW(userbuf, &usersize); | ||
211 | if(!status) | ||
212 | return ERR; | ||
213 | |||
214 | napistatus = NetUserGetInfo(NULL, userbuf, (DWORD)1, (LPBYTE*)&buf); | ||
215 | |||
216 | switch(buf->usri1_priv) { | ||
217 | case USER_PRIV_GUEST: | ||
218 | result = GUEST; | ||
219 | break; | ||
220 | case USER_PRIV_USER: | ||
221 | result = USER; | ||
222 | break; | ||
223 | case USER_PRIV_ADMIN: | ||
224 | result = ADMIN; | ||
225 | break; | ||
226 | default: | ||
227 | result = ERR; | ||
228 | break; | ||
229 | } | ||
230 | NetApiBufferFree(buf); | ||
231 | |||
232 | return result; | ||
233 | } | ||
234 | |||
235 | QString getUserPermissionsString(void) | ||
236 | { | ||
237 | QString result; | ||
238 | int perm = getUserPermissions(); | ||
239 | switch(perm) { | ||
240 | case GUEST: | ||
241 | result = tr("Guest"); | ||
242 | break; | ||
243 | case ADMIN: | ||
244 | result = tr("Admin"); | ||
245 | break; | ||
246 | case USER: | ||
247 | result = tr("User"); | ||
248 | break; | ||
249 | default: | ||
250 | result = tr("Error"); | ||
251 | break; | ||
252 | } | ||
253 | return result; | ||
254 | } | ||
255 | #endif | ||
256 | |||
257 | QString getOsVersionString(void) | ||
258 | { | ||
259 | QString result; | ||
260 | #if defined(Q_OS_WIN32) | ||
261 | OSVERSIONINFO osvi; | ||
262 | ZeroMemory(&osvi, sizeof(OSVERSIONINFO)); | ||
263 | osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); | ||
264 | GetVersionEx(&osvi); | ||
265 | |||
266 | result = QString("Windows version %1.%2, ").arg(osvi.dwMajorVersion).arg(osvi.dwMinorVersion); | ||
267 | result += QString("build %1 (%2)").arg(osvi.dwBuildNumber).arg(QString::fromWCharArray(osvi.szCSDVersion)); | ||
268 | #endif | ||
269 | #if defined(Q_OS_LINUX) || defined(Q_OS_MACX) | ||
270 | struct utsname u; | ||
271 | int ret; | ||
272 | ret = uname(&u); | ||
273 | |||
274 | result = QString("CPU: %1<br/>System: %2<br/>Release: %3<br/>Version: %4") | ||
275 | .arg(u.machine).arg(u.sysname).arg(u.release).arg(u.version); | ||
276 | #endif | ||
277 | return result; | ||
278 | |||
279 | } | ||
280 | |||
281 | /** @brief detect devices based on usb pid / vid. | ||
282 | * @return list with usb VID / PID values. | ||
283 | */ | ||
284 | QList<uint32_t> listUsbIds(void) | ||
285 | { | ||
286 | QList<uint32_t> usbids; | ||
287 | // usb pid detection | ||
288 | #if defined(Q_OS_LINUX) | defined(Q_OS_MACX) | ||
289 | usb_init(); | ||
290 | usb_find_busses(); | ||
291 | usb_find_devices(); | ||
292 | struct usb_bus *b; | ||
293 | b = usb_busses; | ||
294 | |||
295 | while(b) { | ||
296 | qDebug() << "bus:" << b->dirname << b->devices; | ||
297 | if(b->devices) { | ||
298 | qDebug() << "devices present."; | ||
299 | struct usb_device *u; | ||
300 | u = b->devices; | ||
301 | while(u) { | ||
302 | uint32_t id; | ||
303 | id = u->descriptor.idVendor << 16 | u->descriptor.idProduct; | ||
304 | if(id) usbids.append(id); | ||
305 | u = u->next; | ||
306 | } | ||
307 | } | ||
308 | b = b->next; | ||
309 | } | ||
310 | #endif | ||
311 | |||
312 | #if defined(Q_OS_WIN32) | ||
313 | HDEVINFO deviceInfo; | ||
314 | SP_DEVINFO_DATA infoData; | ||
315 | DWORD i; | ||
316 | |||
317 | // Iterate over all devices | ||
318 | // by doing it this way it's unneccessary to use GUIDs which might be not | ||
319 | // present in current MinGW. It also seemed to be more reliably than using | ||
320 | // a GUID. | ||
321 | // See KB259695 for an example. | ||
322 | deviceInfo = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT); | ||
323 | |||
324 | infoData.cbSize = sizeof(SP_DEVINFO_DATA); | ||
325 | |||
326 | for(i = 0; SetupDiEnumDeviceInfo(deviceInfo, i, &infoData); i++) { | ||
327 | DWORD data; | ||
328 | LPTSTR buffer = NULL; | ||
329 | DWORD buffersize = 0; | ||
330 | |||
331 | // get device desriptor first | ||
332 | // for some reason not doing so results in bad things (tm) | ||
333 | while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData, | ||
334 | SPDRP_DEVICEDESC,&data, (PBYTE)buffer, buffersize, &buffersize)) { | ||
335 | if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) { | ||
336 | if(buffer) free(buffer); | ||
337 | // double buffer size to avoid problems as per KB888609 | ||
338 | buffer = (LPTSTR)malloc(buffersize * 2); | ||
339 | } | ||
340 | else { | ||
341 | break; | ||
342 | } | ||
343 | } | ||
344 | |||
345 | // now get the hardware id, which contains PID and VID. | ||
346 | while(!SetupDiGetDeviceRegistryProperty(deviceInfo, &infoData, | ||
347 | SPDRP_HARDWAREID,&data, (PBYTE)buffer, buffersize, &buffersize)) { | ||
348 | if(GetLastError() == ERROR_INSUFFICIENT_BUFFER) { | ||
349 | if(buffer) free(buffer); | ||
350 | // double buffer size to avoid problems as per KB888609 | ||
351 | buffer = (LPTSTR)malloc(buffersize * 2); | ||
352 | } | ||
353 | else { | ||
354 | break; | ||
355 | } | ||
356 | } | ||
357 | |||
358 | unsigned int vid, pid, rev; | ||
359 | if(_stscanf(buffer, _TEXT("USB\\Vid_%x&Pid_%x&Rev_%x"), &vid, &pid, &rev) != 3) { | ||
360 | qDebug() << "Error getting USB ID -- possibly no USB device"; | ||
361 | } | ||
362 | else { | ||
363 | uint32_t id; | ||
364 | id = vid << 16 | pid; | ||
365 | usbids.append(id); | ||
366 | qDebug("VID: %04x PID: %04x", vid, pid); | ||
367 | } | ||
368 | if(buffer) free(buffer); | ||
369 | } | ||
370 | SetupDiDestroyDeviceInfoList(deviceInfo); | ||
371 | |||
372 | #endif | ||
373 | return usbids; | ||
374 | } | ||
diff --git a/rbutil/rbutilqt/utils.h b/rbutil/rbutilqt/utils.h index 9b0b026921..a7be093520 100644 --- a/rbutil/rbutilqt/utils.h +++ b/rbutil/rbutilqt/utils.h | |||
@@ -24,6 +24,15 @@ | |||
24 | #include <QString> | 24 | #include <QString> |
25 | #include <QUrl> | 25 | #include <QUrl> |
26 | 26 | ||
27 | #if defined(Q_OS_WIN32) | ||
28 | enum userlevel { ERR, GUEST, USER, ADMIN }; | ||
29 | enum userlevel getUserPermissions(void); | ||
30 | QString getUserPermissionsString(void); | ||
31 | #endif | ||
32 | QString getUserName(void); | ||
33 | QString getOsVersionString(void); | ||
34 | QList<uint32_t> listUsbIds(void); | ||
35 | |||
27 | bool recRmdir( const QString &dirName ); | 36 | bool recRmdir( const QString &dirName ); |
28 | QString resolvePathCase(QString path); | 37 | QString resolvePathCase(QString path); |
29 | 38 | ||