QTfrontend/ui/page/pagefeedback.cpp
changeset 8250 ebaec8186e4a
parent 6952 7f70f37bbf08
child 8252 db3bccd784c9
equal deleted inserted replaced
8247:d7cf4a9ce685 8250:ebaec8186e4a
    18 
    18 
    19 #include <QHBoxLayout>
    19 #include <QHBoxLayout>
    20 #include <QLineEdit>
    20 #include <QLineEdit>
    21 #include <QTextBrowser>
    21 #include <QTextBrowser>
    22 #include <QLabel>
    22 #include <QLabel>
       
    23 #include <QSysInfo>
       
    24 #include <QApplication>
       
    25 #include <QDesktopWidget>
       
    26 #include <string>
       
    27 
       
    28 #ifndef Q_WS_WIN
       
    29 #include <unistd.h>
       
    30 #endif
       
    31 
       
    32 #ifdef Q_WS_WIN
       
    33 #define WINVER 0x0500
       
    34 #include <windows.h>
       
    35 #endif
       
    36 
       
    37 #ifdef Q_WS_MAC
       
    38      #include <sys/types.h>
       
    39      #include <sys/sysctl.h>
       
    40 #endif
    23 
    41 
    24 #include "pagefeedback.h"
    42 #include "pagefeedback.h"
    25 #include "hwconsts.h"
    43 #include "hwconsts.h"
    26 
    44 
    27 QLayout * PageFeedback::bodyLayoutDefinition()
    45 QLayout * PageFeedback::bodyLayoutDefinition()
    50 
    68 
    51     label_description = new QLabel();
    69     label_description = new QLabel();
    52     label_description->setText(QLabel::tr("Description"));
    70     label_description->setText(QLabel::tr("Description"));
    53     pageLayout->addWidget(label_description, 0, Qt::AlignHCenter);
    71     pageLayout->addWidget(label_description, 0, Qt::AlignHCenter);
    54     description = new QTextBrowser();
    72     description = new QTextBrowser();
       
    73     QDesktopWidget* screen = QApplication::desktop();
       
    74     QString os_version = "Operating system: ";
       
    75     QString qt_version = QString("Qt version: ") + QT_VERSION_STR + QString("\n");
       
    76     QString total_ram = "Total RAM: unknown\n";
       
    77     QString available_ram = "Available RAM: unknown\n";
       
    78     QString number_of_cores = "Number of cores: unknown";
       
    79     QString screen_size = "Size of the screen(s): " +
       
    80         QString::number(screen->width()) + "x" + QString::number(screen->height()) + "\n";
       
    81     QString number_of_screens = "Number of screens: " +
       
    82         QString::number(screen->screenCount()) + "\n";
       
    83 #ifdef Q_WS_MACX
       
    84     number_of_cores = "Number of cores: " +
       
    85     QString::number(sysconf(_SC_NPROCESSORS_ONLN));
       
    86 
       
    87     uint64_t memsize, memavail;
       
    88     size_t len = sizeof(memsize);
       
    89     static int mib_s[2] = { CTL_HW, HW_MEMSIZE };
       
    90     static int mib_a[2] = { CTL_HW, HW_USERMEM };
       
    91     if (sysctl (mib_s, 2, &memsize, &len, NULL, 0) == 0)
       
    92         total_ram = "Total RAM: " + QString::number(memsize/1024/1024) + " MB\n";
       
    93     else
       
    94         total_ram = "Error getting total RAM information\n";
       
    95     if (sysctl (mib_a, 2, &memavail, &len, NULL, 0) == 0)    
       
    96         available_ram = "Available RAM: " + QString::number(memavail/1024/1024) + " MB\n";
       
    97     else
       
    98         available_ram = "Error getting available RAM information\n";
       
    99     
       
   100         int mib[] = {CTL_KERN, KERN_OSRELEASE};
       
   101     sysctl(mib, sizeof mib / sizeof(int), NULL, &len, NULL, 0);
       
   102 
       
   103     char *kernelVersion = (char *)malloc(sizeof(char)*len);
       
   104     sysctl(mib, sizeof mib / sizeof(int), kernelVersion, &len, NULL, 0);
       
   105 
       
   106     QString kernelVersionStr = QString(kernelVersion);
       
   107     free(kernelVersion);
       
   108     int major_version = kernelVersionStr.split(".").first().toUInt() - 4;
       
   109     int minor_version = kernelVersionStr.split(".").at(1).toUInt();
       
   110     os_version += QString("Mac OS X 10.%1.%2").arg(major_version).arg(minor_version) + " ";
       
   111 
       
   112     switch(major_version)
       
   113     {
       
   114         case 4:  os_version += "\"Tiger\"\n"; break;
       
   115         case 5:  os_version += "\"Leopard\"\n"; break;
       
   116         case 6:  os_version += "\"Snow Leopard\"\n"; break;
       
   117         case 7:  os_version += "\"Lion\"\n"; break;
       
   118         case 8:  os_version += "\"Mountain Lion\"\n"; break;
       
   119         default: os_version += "\"Unknown version\"\n"; break;
       
   120     }
       
   121 #endif
       
   122 #ifdef Q_WS_WIN
       
   123     SYSTEM_INFO sysinfo;
       
   124     GetSystemInfo(&sysinfo);
       
   125     number_of_cores = "Number of cores: " + QString::number(sysinfo.dwNumberOfProcessors) + "\n";
       
   126     MEMORYSTATUSEX status;
       
   127     status.dwLength = sizeof(status);
       
   128     GlobalMemoryStatusEx(&status);
       
   129     total_ram = QString::number(status.ullTotalPhys);
       
   130 
       
   131     switch(QSysInfo::WinVersion())
       
   132     {
       
   133         case QSysInfo::WV_2000: 
       
   134             os_version += "Windows 2000\n";
       
   135             break;
       
   136         case QSysInfo::WV_XP: 
       
   137             os_version += "Windows XP\n";
       
   138             break;
       
   139         case QSysInfo::WV_VISTA: 
       
   140             os_version += "Windows Vista\n";
       
   141             break;
       
   142         case QSysInfo::WV_WINDOWS7: 
       
   143             os_version += "Windows 7\n";
       
   144             break;
       
   145         default:
       
   146             os_version += "Windows\n";
       
   147     }
       
   148 #endif
       
   149 #ifdef Q_WS_X11
       
   150     number_of_cores = "Number of cores: " + QString::number(sysconf(_SC_NPROCESSORS_ONLN)) + "\n";
       
   151     long pages = sysconf(_SC_PHYS_PAGES),
       
   152          available_pages = sysconf(_SC_AVPHYS_PAGES),
       
   153          page_size = sysconf(_SC_PAGE_SIZE);
       
   154     total_ram = "Total RAM: " + QString::number(pages * page_size) + "\n";
       
   155     available_ram = "Available RAM: " + QString::number(available_pages * page_size) + "\n";
       
   156     os_version += "Linux\n";
       
   157 #endif
       
   158     
       
   159     /* Get the processor's type string using the CPUID instruction. */
       
   160     std::string processor_name = "Processor: ";
       
   161     uint32_t registers[4];
       
   162     unsigned i;
       
   163 
       
   164     i = 0x80000002;
       
   165     asm volatile
       
   166       ("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3])
       
   167        : "a" (i), "c" (0));
       
   168     processor_name += std::string((const char *)&registers[0], 4);
       
   169     processor_name += std::string((const char *)&registers[1], 4);
       
   170     processor_name += std::string((const char *)&registers[2], 4);
       
   171     processor_name += std::string((const char *)&registers[3], 4);
       
   172     i = 0x80000003;
       
   173     asm volatile
       
   174       ("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3])
       
   175        : "a" (i), "c" (0));
       
   176     processor_name += std::string((const char *)&registers[0], 4);
       
   177     processor_name += std::string((const char *)&registers[1], 4);
       
   178     processor_name += std::string((const char *)&registers[2], 4);
       
   179     processor_name += std::string((const char *)&registers[3], 4);
       
   180     i = 0x80000004;
       
   181     asm volatile
       
   182       ("cpuid" : "=a" (registers[0]), "=b" (registers[1]), "=c" (registers[2]), "=d" (registers[3])
       
   183        : "a" (i), "c" (0));
       
   184     processor_name += std::string((const char *)&registers[0], 4);
       
   185     processor_name += std::string((const char *)&registers[1], 4);
       
   186     processor_name += std::string((const char *)&registers[2], 4);
       
   187     processor_name += std::string((const char *)&registers[3], 3);
       
   188     
       
   189     QString processor_bits = "Number of bits: unknown";
       
   190     
       
   191     if(sizeof(void*) == 4)
       
   192         processor_bits = "Number of bits: 32 (probably)";
       
   193     else
       
   194         if(sizeof(void*) == 8)
       
   195             processor_bits = "Number of bits: 64 (probably)";
       
   196     
       
   197     description->setText(
       
   198         "\n\n\n"
       
   199         "System information:\n"
       
   200         + qt_version
       
   201         + os_version
       
   202         + total_ram
       
   203         + available_ram
       
   204         + screen_size
       
   205         + number_of_screens
       
   206         + number_of_cores
       
   207         + QString::fromStdString(processor_name + "\n")
       
   208         + processor_bits
       
   209     );
    55     description->setReadOnly(false);
   210     description->setReadOnly(false);
    56     pageLayout->addWidget(description);
   211     pageLayout->addWidget(description);
    57 
   212 
    58     return pageLayout;
   213     return pageLayout;
    59 }
   214 }