();
)
KCMMemory::KCMMemory(QWidget *parent, const QVariantList &) :
KCModule(parent) {
KAboutData *about = new KAboutData(i18n("kcm_memory"),
i18n("KDE Panel Memory Information Control Module"),
QString(), QString(), KAboutLicense::GPL,
i18n("(c) 1998 - 2002 Helge Deller"));
about->addAuthor(i18n("Helge Deller"), QString(), QStringLiteral("deller@gmx.de"));
setAboutData(about);
QString title, initial_str;
setButtons(Help);
QVBoxLayout *top = new QVBoxLayout(this);
- top->setMargin(0);
+ top->setContentsMargins(0, 0, 0, 0);
top->setSpacing(1);
QGroupBox* informationGroup = initializeText();
top->addWidget(informationGroup, 1);
// Now the Graphics
QGroupBox* graphicsGroup = initializeCharts();
top->addWidget(graphicsGroup, 2);
timer = new QTimer(this);
timer->start(100);
connect(timer, &QTimer::timeout, this, &KCMMemory::updateDatas);
updateDatas();
}
KCMMemory::~KCMMemory() {
/* stop the timer */
timer->stop();
}
QString KCMMemory::quickHelp() const {
return i18n("This display shows you the current memory usage of your system."
" The values are updated on a regular basis and give you an"
" overview of the physical and virtual memory being used.");
}
QGroupBox* KCMMemory::initializeText() {
QGroupBox* informationGroup = new QGroupBox(i18n("Memory"));
QHBoxLayout *hbox = new QHBoxLayout(informationGroup);
/* stretch the left side */
hbox->addStretch();
QString title;
//TODO Use the more smart QGridLayout !!!
/* first create the Informationtext-Widget */
QVBoxLayout *vbox = new QVBoxLayout();
hbox->addLayout(vbox);
vbox->setSpacing(0);
for (int i = TOTAL_MEM; i < MEM_LAST_ENTRY; ++i) {
switch (i) {
case TOTAL_MEM:
title = i18n("Total physical memory:");
break;
case FREE_MEM:
title = i18n("Free physical memory:");
break;
#if !defined(__svr4__) || !defined(sun)
#if !defined(__NetBSD__) && !defined(__OpenBSD__)
case SHARED_MEM:
title = i18n("Shared memory:");
break;
case BUFFER_MEM:
title = i18n("Disk buffers:");
break;
#else
case ACTIVE_MEM:
title = i18n("Active memory:");
break;
case INACTIVE_MEM:
title = i18n("Inactive memory:");
break;
#endif
#endif
case CACHED_MEM:
title = i18n("Disk cache:");
break;
case SWAP_MEM:
vbox->addSpacing(SPACING);
title = i18n("Total swap memory:");
break;
case FREESWAP_MEM:
title = i18n("Free swap memory:");
break;
default:
title = QLatin1String("");
break;
};
QLabel* labelWidget = new QLabel(title, this);
labelWidget->setTextInteractionFlags(Qt::TextSelectableByMouse);
labelWidget->setAlignment(Qt::AlignLeft);
vbox->addWidget(labelWidget);
}
vbox->addStretch();
/* then the memory-content-widgets */
for (int j = 0; j < 2; j++) {
vbox = new QVBoxLayout();
hbox->addLayout(vbox);
vbox->setSpacing(0);
for (int i = TOTAL_MEM; i < MEM_LAST_ENTRY; ++i) {
if (i == SWAP_MEM)
vbox->addSpacing(SPACING);
QLabel* labelWidget = new QLabel(this);
labelWidget->setTextInteractionFlags(Qt::TextSelectableByMouse);
labelWidget->setAlignment(Qt::AlignRight);
memorySizeLabels[i][j] = labelWidget;
vbox->addWidget(labelWidget);
}
vbox->addStretch();
}
/* stretch the right side */
hbox->addStretch();
return informationGroup;
}
QGroupBox* KCMMemory::initializeCharts() {
QGroupBox* chartsGroup = new QGroupBox(i18n("Charts"));
QHBoxLayout* chartsLayout = new QHBoxLayout(chartsGroup);
chartsLayout->setSpacing(1);
chartsLayout->setMargin(1);
//chartsLayout->addStretch(1);
totalMemory = new ChartWidget(i18n("Total Memory"),
i18n("This graph gives you an overview of the "
"total sum of physical and virtual memory "
"in your system."),
new TotalMemoryChart(this), this);
chartsLayout->addWidget(totalMemory);
chartsLayout->addSpacing(SPACING);
physicalMemory = new ChartWidget(i18n("Physical Memory"),
i18n("This graph gives you an overview of "
"the usage of physical memory in your system."
"Most operating systems (including Linux) "
"will use as much of the available physical "
"memory as possible as disk cache, "
"to speed up the system performance.
"
"This means that if you have a small amount "
"of Free Physical Memory and a large amount of "
"Disk Cache Memory, your system is well "
"configured.
"),
new PhysicalMemoryChart(this), this);
chartsLayout->addWidget(physicalMemory);
chartsLayout->addSpacing(SPACING);
swapMemory = new ChartWidget(i18n("Swap Space"),
i18n("The swap space is the virtual memory "
"available to the system.
"
"It will be used on demand and is provided "
"through one or more swap partitions and/or swap files.
"),
new SwapMemoryChart(this), this);
chartsLayout->addWidget(swapMemory);
//chartsLayout->addStretch(1);
return chartsGroup;
}
void KCMMemory::updateDatas() {
/* get the Information from memory_linux, memory_fbsd */
fetchValues();
updateMemoryText();
updateMemoryGraphics();
}
void KCMMemory::updateMemoryText() {
/* update the byte-strings */
for (int i = TOTAL_MEM; i < MEM_LAST_ENTRY; i++) {
QLabel* label = memorySizeLabels[i][0];
if (memoryInfos[i] == NO_MEMORY_INFO)
label->clear();
else
label->setText(i18np("1 byte =", "%1 bytes =", memoryInfos[i]));
}
/* update the MB-strings */
for (int i = TOTAL_MEM; i < MEM_LAST_ENTRY; i++) {
QLabel* label = memorySizeLabels[i][1];
label->setText((memoryInfos[i] != NO_MEMORY_INFO) ? Chart::formattedUnit(memoryInfos[i]) : i18n("Not available."));
}
}
void KCMMemory::updateMemoryGraphics() {
totalMemory->setMemoryInfos(memoryInfos);
totalMemory->refresh();
physicalMemory->setMemoryInfos(memoryInfos);
physicalMemory->refresh();
swapMemory->setMemoryInfos(memoryInfos);
swapMemory->refresh();
}
/* Include system-specific code */
#ifdef __linux__
#include "memory_linux.cpp"
#elif defined(__APPLE__)
#include "memory_osx.cpp"
#elif defined(sgi) && sgi
#include "memory_sgi.cpp"
#elif defined(__svr4__) && defined(sun)
#include "memory_solaris.cpp"
#elif defined(__FreeBSD__) || defined(__DragonFly__)
#include "memory_fbsd.cpp"
#elif defined(__hpux)
#include "memory_hpux.cpp"
#elif defined(__NetBSD__) || defined(__OpenBSD__)
#include "memory_netbsd.cpp"
#elif defined(__osf__)
#include "memory_tru64.cpp"
#else
/* Default for unsupported systems */
void KCMMemory::fetchValues() {
int i;
for (i = TOTAL_MEM; i < MEM_LAST_ENTRY; ++i) {
memoryInfos[i] = NO_MEMORY_INFO;
}
}
#endif
#include "memory.moc"
diff --git a/Modules/nics/nic.cpp b/Modules/nics/nic.cpp
index 6fae68f..90cedcd 100644
--- a/Modules/nics/nic.cpp
+++ b/Modules/nics/nic.cpp
@@ -1,314 +1,314 @@
/*
* nic.cpp
*
* Copyright (C) 2001 Alexander Neundorf
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "nic.h"
#include
#include
#include
#include
#include
#include
#include
#include "config-nic.h"
#ifdef HAVE_SYS_SOCKIO_H
#include
#endif
#include
#include
#include
#include
#include
#include
#include
#ifdef USE_SOLARIS
/* net/if.h is incompatible with STL on Solaris 2.6 - 2.8, redefine
map in the header file because we don't need it. -- Simon Josefsson */
#define map junkmap
#endif
# include
#ifdef USE_SOLARIS
#undef map
#endif
#include
#include
#include
#ifndef HAVE_STRUCT_SOCKADDR_SA_LEN
#undef HAVE_GETNAMEINFO
#undef HAVE_GETIFADDRS
#endif
#if defined(HAVE_GETNAMEINFO) && defined(HAVE_GETIFADDRS)
#include
#include
QString flags_tos (unsigned int flags);
#endif
K_PLUGIN_FACTORY(KCMNicFactory,
registerPlugin();
)
struct MyNIC {
QString name;
QString addr;
QString netmask;
QString state;
QString type;
QString HWaddr;
};
QList findNICs();
KCMNic::KCMNic(QWidget *parent, const QVariantList &) :
KCModule(parent) {
QVBoxLayout *box=new QVBoxLayout(this);
- box->setMargin(0);
+ box->setContentsMargins(0, 0, 0, 0);
m_list=new QTreeWidget(this);
m_list->setRootIsDecorated(false);
box->addWidget(m_list);
QStringList columns;
columns<setHeaderLabels(columns);
QHBoxLayout *hbox=new QHBoxLayout();
box->addItem(hbox);
m_updateButton=new QPushButton(i18n("&Update"),this);
hbox->addStretch(1);
hbox->addWidget(m_updateButton);
QTimer* timer=new QTimer(this);
timer->start(60000);
connect(m_updateButton, &QPushButton::clicked, this, &KCMNic::update);
connect(timer, &QTimer::timeout, this, &KCMNic::update);
update();
KAboutData *about = new KAboutData(i18n("kcminfo"),
i18n("System Information Control Module"),
QString(), QString(), KAboutLicense::GPL,
i18n("(c) 2001 - 2002 Alexander Neundorf"));
about->addAuthor(i18n("Alexander Neundorf"), QString(), QStringLiteral("neundorf@kde.org"));
setAboutData(about);
}
void KCMNic::update() {
m_list->clear();
QList nics=findNICs();
foreach(MyNIC* tmp, nics) {
QStringList lst;
lst << tmp->name<addr<netmask<type<state<HWaddr;
new QTreeWidgetItem(m_list,lst);
delete tmp;
}
nics.clear();
}
static QString HWaddr2String(const char *hwaddr) {
QString ret;
for (int i=0; i<6; i++, hwaddr++) {
int v = (*hwaddr & 0xff);
QString num = QStringLiteral("%1").arg(v, 0, 16);
if (num.length() < 2)
num.prepend(QStringLiteral("0"));
if (i>0)
ret.append(QStringLiteral(":"));
ret.append(num);
}
return ret;
}
QList findNICs() {
QString upMessage(i18nc("State of network card is connected", "Up") );
QString downMessage(i18nc("State of network card is disconnected", "Down") );
QList nl;
#if !defined(HAVE_GETIFADDRS) || !defined(HAVE_GETNAMEINFO)
int sockfd = socket(AF_INET, SOCK_DGRAM, 0);
char buf[8*1024];
struct ifconf ifc;
ifc.ifc_len = sizeof(buf);
ifc.ifc_req = (struct ifreq *) buf;
int result=ioctl(sockfd, SIOCGIFCONF, &ifc);
for (char* ptr = buf; ptr < buf + ifc.ifc_len;) {
struct ifreq *ifr =(struct ifreq *) ptr;
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
int len = sizeof(struct sockaddr);
if (ifr->ifr_addr.sa_len > len)
len = ifr->ifr_addr.sa_len; /* length > 16 */
ptr += sizeof(ifr->ifr_name) + len; /* for next one in buffer */
#else
ptr += sizeof(*ifr); /* for next one in buffer */
#endif
int flags;
struct sockaddr_in *sinptr;
MyNIC *tmp=nullptr;
switch (ifr->ifr_addr.sa_family) {
case AF_INET:
sinptr = (struct sockaddr_in *) &ifr->ifr_addr;
flags=0;
struct ifreq ifcopy;
ifcopy=*ifr;
result=ioctl(sockfd, SIOCGIFFLAGS, &ifcopy);
flags=ifcopy.ifr_flags;
tmp=new MyNIC;
tmp->name=ifr->ifr_name;
tmp->state= ((flags & IFF_UP) == IFF_UP) ? upMessage : downMessage;
if ((flags & IFF_BROADCAST) == IFF_BROADCAST)
tmp->type=i18nc("@item:intext Mode of network card", "Broadcast");
else if ((flags & IFF_POINTOPOINT) == IFF_POINTOPOINT)
tmp->type=i18nc("@item:intext Mode of network card", "Point to Point");
#ifndef _AIX
else if ((flags & IFF_MULTICAST) == IFF_MULTICAST)
tmp->type=i18nc("@item:intext Mode of network card", "Multicast");
#endif
else if ((flags & IFF_LOOPBACK) == IFF_LOOPBACK)
tmp->type=i18nc("@item:intext Mode of network card", "Loopback");
else
tmp->type=i18nc("@item:intext Mode of network card", "Unknown");
tmp->addr=inet_ntoa(sinptr->sin_addr);
ifcopy=*ifr;
result=ioctl(sockfd, SIOCGIFNETMASK, &ifcopy);
if (result==0) {
sinptr = (struct sockaddr_in *) &ifcopy.ifr_addr;
tmp->netmask=inet_ntoa(sinptr->sin_addr);
} else
tmp->netmask=i18nc("Unknown network mask", "Unknown");
ifcopy=*ifr;
result=-1; // if none of the two #ifs below matches, ensure that result!=0 so that "Unknown" is returned as result
#ifdef SIOCGIFHWADDR
result=ioctl(sockfd, SIOCGIFHWADDR, &ifcopy);
if (result==0) {
char *n = &ifcopy.ifr_ifru.ifru_hwaddr.sa_data[0];
tmp->HWaddr = HWaddr2String(n);
}
#elif defined SIOCGENADDR
result=ioctl(sockfd,SIOCGENADDR,&ifcopy);
if (result==0)
{
char *n = &ifcopy.ifr_ifru.ifru_enaddr[0];
tmp->HWaddr = HWaddr2String(n);
}
#endif
if (result!=0) {
tmp->HWaddr = i18nc("Unknown HWaddr", "Unknown");
}
nl.append(tmp);
break;
default:
break;
}
}
#else
struct ifaddrs *ifap, *ifa;
if (getifaddrs(&ifap) != 0) {
return nl;
}
MyNIC *tmp=0;
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
switch (ifa->ifa_addr->sa_family) {
case AF_INET6:
case AF_INET: {
tmp = new MyNIC;
tmp->name = ifa->ifa_name;
char buf[128];
bzero(buf, 128);
getnameinfo(ifa->ifa_addr, ifa->ifa_addr->sa_len, buf, 127, 0, 0, NI_NUMERICHOST);
tmp->addr = buf;
if (ifa->ifa_netmask != nullptr) {
bzero(buf, 128);
getnameinfo(ifa->ifa_netmask, ifa->ifa_netmask->sa_len, buf, 127, 0, 0, NI_NUMERICHOST);
tmp->netmask = buf;
}
tmp->state= (ifa->ifa_flags & IFF_UP) ? upMessage : downMessage;
tmp->type = flags_tos(ifa->ifa_flags);
nl.append(tmp);
break;
}
default:
break;
}
}
freeifaddrs(ifap);
#endif
return nl;
}
#if defined(HAVE_GETNAMEINFO) && defined(HAVE_GETIFADDRS)
QString flags_tos (unsigned int flags)
{
QString tmp;
if (flags & IFF_POINTOPOINT) {
tmp += i18n("Point to Point");
}
if (flags & IFF_BROADCAST) {
if (tmp.length()) {
tmp += QLatin1String(", ");
}
tmp += i18n("Broadcast");
}
if (flags & IFF_MULTICAST) {
if (tmp.length()) {
tmp += QLatin1String(", ");
}
tmp += i18n("Multicast");
}
if (flags & IFF_LOOPBACK) {
if (tmp.length()) {
tmp += QLatin1String(", ");
}
tmp += i18n("Loopback");
}
return tmp;
}
#endif
#include "nic.moc"
diff --git a/Modules/opengl/opengl.cpp b/Modules/opengl/opengl.cpp
index 750cf91..847e9c5 100644
--- a/Modules/opengl/opengl.cpp
+++ b/Modules/opengl/opengl.cpp
@@ -1,1036 +1,1036 @@
/*
* opengl.cpp
*
* Copyright (C) 2008 Ivo Anjo
* Copyright (C) 2004 Ilya Korniyko
* Adapted from Brian Paul's glxinfo from Mesa demos (http://www.mesa3d.org)
* Copyright (C) 1999-2002 Brian Paul
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "opengl.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
// X11 includes
#include
#include
#include
#if KCM_HAVE_EGL
#include
#endif
#ifdef KCM_ENABLE_OPENGLES
#include
#endif
#if KCM_HAVE_GLX
// GLU includes
#include
// OpenGL includes
#include
#include
#include
#endif
#if defined(Q_OS_LINUX)
#include
#include
#include
#endif
K_PLUGIN_FACTORY(KCMOpenGLFactory,
registerPlugin();
)
// FIXME: Temporary!
bool GetInfo_OpenGL(QTreeWidget *treeWidget);
KCMOpenGL::KCMOpenGL(QWidget *parent, const QVariantList &)
: KCModule(parent)
{
setupUi(this);
- layout()->setMargin(0);
+ layout()->setContentsMargins(0, 0, 0, 0);
GetInfo_OpenGL(glinfoTreeWidget);
// Watch for expanded and collapsed events, to resize columns
connect(glinfoTreeWidget, &QTreeWidget::expanded, this, &KCMOpenGL::treeWidgetChanged);
connect(glinfoTreeWidget, &QTreeWidget::collapsed, this, &KCMOpenGL::treeWidgetChanged);
KAboutData *about =
new KAboutData(i18n("kcmopengl"),
i18n("KCM OpenGL Information"),
QString(), QString(), KAboutLicense::GPL,
i18n("(c) 2008 Ivo Anjo\n(c) 2004 Ilya Korniyko\n(c) 1999-2002 Brian Paul"));
about->addAuthor(i18n("Ivo Anjo"), QString(), QStringLiteral("knuckles@gmail.com"));
about->addAuthor(i18n("Ilya Korniyko"), QString(), QStringLiteral("k_ilya@ukr.net"));
about->addCredit(i18n("Helge Deller"), i18n("Original Maintainer"), QStringLiteral("deller@gmx.de"));
about->addCredit(i18n("Brian Paul"), i18n("Author of glxinfo Mesa demos (http://www.mesa3d.org)"));
setAboutData(about);
}
void KCMOpenGL::treeWidgetChanged() {
glinfoTreeWidget->resizeColumnToContents(0);
glinfoTreeWidget->resizeColumnToContents(1);
}
QTreeWidgetItem *newItem(QTreeWidgetItem *parent, QTreeWidgetItem *preceding, const QString &textCol1, const QString &textCol2 = QString()) {
QTreeWidgetItem *newItem;
if ((parent == nullptr) && (preceding == nullptr)) {
newItem = new QTreeWidgetItem();
} else if (preceding == nullptr) {
newItem = new QTreeWidgetItem(parent);
} else {
newItem = new QTreeWidgetItem(parent, preceding);
}
newItem->setText(0, textCol1);
if (!textCol2.isNull()) {
newItem->setText(1, textCol2);
}
newItem->setFlags(Qt::ItemIsEnabled);
return newItem;
}
QTreeWidgetItem *newItem(QTreeWidgetItem *parent, const QString &textCol1, const QString &textCol2 = QString()) {
return newItem(parent, NULL, textCol1, textCol2);
}
static bool IsDirect;
static struct glinfo {
#if KCM_HAVE_GLX
const char *serverVendor;
const char *serverVersion;
const char *serverExtensions;
const char *clientVendor;
const char *clientVersion;
const char *clientExtensions;
const char *glxExtensions;
#endif
#if KCM_HAVE_EGL
const char *eglVendor;
const char *eglVersion;
const char *eglExtensions;
#endif
const char *glVendor;
const char *glRenderer;
const char *glVersion;
const char *glExtensions;
#if KCM_HAVE_GLX
const char *gluVersion;
const char *gluExtensions;
#endif
char *displayName;
} gli;
static struct {
QString module,
pci,
vendor,
device,
subvendor,
rev;
} dri_info;
static int ReadPipe(const QString &FileName, QStringList &list)
{
QProcess pipe;
pipe.start(FileName, QIODevice::ReadOnly);
if (!pipe.waitForFinished()) {
// something went wrong, f.e. command not found
return 0;
}
QTextStream t(&pipe);
while (!t.atEnd()) list.append(t.readLine());
return list.count();
}
#if defined(Q_OS_LINUX)
static QString get_sysfs_link_name(const QString& path)
{
const QString target = QFileInfo(path).symLinkTarget();
const int index = target.lastIndexOf(QChar('/'));
if (index == -1)
return QString();
return target.mid(index + 1);
}
static bool get_drm_device_sysfs()
{
struct stat fileInfo;
if (::stat("/dev/dri/card0", &fileInfo) != 0)
return false;
if ((fileInfo.st_mode & S_IFCHR) != S_IFCHR)
return false;
const uint16_t devMajor = major(fileInfo.st_rdev);
const uint16_t devMinor = minor(fileInfo.st_rdev);
QString sysPath = QStringLiteral("/sys/dev/char/%1:%2/device").arg(devMajor).arg(devMinor);
dri_info.pci = get_sysfs_link_name(sysPath);
dri_info.module = get_sysfs_link_name(sysPath + QStringLiteral("/driver"));
return (dri_info.pci.size() && dri_info.module.size());
}
#define INFO_DRI QStringLiteral("/proc/dri/0/name")
static bool get_dri_device_proc()
{
QFile file;
file.setFileName(INFO_DRI);
if (!file.exists() || !file.open(QIODevice::ReadOnly))
return false;
QTextStream stream(&file);
QString line = stream.readLine();
if (line.isEmpty())
return false;
dri_info.module = line.mid(0, line.indexOf(0x20));
// possible formats, for regression testing
// line = " PCI:01:00:0";
// line = " pci:0000:01:00.0"
QRegExp rx = QRegExp("\\b[Pp][Cc][Ii][:]([0-9a-fA-F]+[:])?([0-9a-fA-F]+[:][0-9a-fA-F]+[:.][0-9a-fA-F]+)\\b");
if (rx.indexIn(line)>0) {
dri_info.pci = rx.cap(2);
int end = dri_info.pci.lastIndexOf(':');
int end2 = dri_info.pci.lastIndexOf('.');
if (end2>end) end=end2;
dri_info.pci[end]='.';
return true;
}
return false;
}
static bool get_dri_device()
{
if (!get_drm_device_sysfs() && !get_dri_device_proc())
return false;
QString cmd = QStringLiteral("lspci -m -v -s ") + dri_info.pci;
QStringList pci_info;
int num;
if (((num = ReadPipe(cmd, pci_info)) ||
(num = ReadPipe("/sbin/"+cmd, pci_info)) ||
(num = ReadPipe("/usr/sbin/"+cmd, pci_info)) ||
(num = ReadPipe("/usr/local/sbin/"+cmd, pci_info))) && num>=7) {
QString line;
for (int i=2; i<=6; i++) {
line = pci_info[i];
line.remove(QRegExp("[^:]*:[ ]*"));
switch (i){
case 2: dri_info.vendor = line; break;
case 3: dri_info.device = line; break;
case 4: dri_info.subvendor = line; break;
case 6: dri_info.rev = line; break;
}
}
return true;
}
return false;
}
#elif defined(Q_OS_FREEBSD)
static bool get_dri_device() {
QStringList pci_info;
if (ReadPipe("sysctl -n hw.dri.0.name",pci_info)) {
dri_info.module = pci_info[0].mid(0, pci_info[0].indexOf(0x20));
}
return false;
}
#else
static bool get_dri_device() { return false; }
#endif
#if KCM_HAVE_GLX
static void
mesa_hack(Display *dpy, int scrnum)
{
static const int attribs[] = {
GLX_RGBA,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_DEPTH_SIZE, 1,
GLX_STENCIL_SIZE, 1,
GLX_ACCUM_RED_SIZE, 1,
GLX_ACCUM_GREEN_SIZE, 1,
GLX_ACCUM_BLUE_SIZE, 1,
GLX_ACCUM_ALPHA_SIZE, 1,
GLX_DOUBLEBUFFER,
None
};
XVisualInfo *visinfo;
visinfo = glXChooseVisual(dpy, scrnum, const_cast(attribs));
if (visinfo)
XFree(visinfo);
}
#endif
static void
print_extension_list(const char *ext, QTreeWidgetItem *l1)
{
int i, j;
if (!ext || !ext[0])
return;
QString qext = QString::fromLatin1(ext);
QTreeWidgetItem *l2 = nullptr;
i = j = 0;
while (1) {
if (ext[j] == ' ' || ext[j] == 0) {
/* found end of an extension name */
const int len = j - i;
/* print the extension name between ext[i] and ext[j] */
if (!l2) l2 = newItem(l1, qext.mid(i, len));
else l2 = newItem(l1, l2, qext.mid(i, len));
i=j;
if (ext[j] == 0) {
break;
}
else {
i++;
j++;
if (ext[j] == 0)
break;
}
}
j++;
}
}
#if KCM_HAVE_GLX
#if defined(GLX_ARB_get_proc_address) && defined(__GLXextFuncPtr)
extern "C" {
extern __GLXextFuncPtr glXGetProcAddressARB (const GLubyte *);
}
#endif
static void
print_limits(QTreeWidgetItem *l1, const char * glExtensions, bool getProcAddress)
{
/* TODO
GL_SAMPLE_BUFFERS
GL_SAMPLES
GL_COMPRESSED_TEXTURE_FORMATS
*/
if (!glExtensions)
return;
struct token_name {
GLuint type; // count and flags, !!! count must be <=2 for now
GLenum token;
const QString name;
};
struct token_group {
int count;
int type;
const token_name *group;
const QString descr;
const char *ext;
};
QTreeWidgetItem *l2 = nullptr, *l3 = nullptr;
#if defined(PFNGLGETPROGRAMIVARBPROC)
PFNGLGETPROGRAMIVARBPROC kcm_glGetProgramivARB = nullptr;
#endif
#define KCMGL_FLOAT 128
#define KCMGL_PROG 256
#define KCMGL_COUNT_MASK(x) (x & 127)
#define KCMGL_SIZE(x) (sizeof(x)/sizeof(x[0]))
const struct token_name various_limits[] = {
{ 1, GL_MAX_LIGHTS, i18n("Max. number of light sources") },
{ 1, GL_MAX_CLIP_PLANES, i18n("Max. number of clipping planes") },
{ 1, GL_MAX_PIXEL_MAP_TABLE, i18n("Max. pixel map table size") },
{ 1, GL_MAX_LIST_NESTING, i18n("Max. display list nesting level") },
{ 1, GL_MAX_EVAL_ORDER, i18n("Max. evaluator order") },
{ 1, GL_MAX_ELEMENTS_VERTICES, i18n("Max. recommended vertex count") },
{ 1, GL_MAX_ELEMENTS_INDICES, i18n("Max. recommended index count") },
#ifdef GL_QUERY_COUNTER_BITS
{ 1, GL_QUERY_COUNTER_BITS, i18n("Occlusion query counter bits")},
#endif
#ifdef GL_MAX_VERTEX_UNITS_ARB
{ 1, GL_MAX_VERTEX_UNITS_ARB, i18n("Max. vertex blend matrices") },
#endif
#ifdef GL_MAX_PALETTE_MATRICES_ARB
{ 1, GL_MAX_PALETTE_MATRICES_ARB, i18n("Max. vertex blend matrix palette size") },
#endif
{0,0,QString()}
};
const struct token_name texture_limits[] = {
{ 1, GL_MAX_TEXTURE_SIZE, i18n("Max. texture size") },
{ 1, GL_MAX_TEXTURE_UNITS_ARB, i18n("No. of texture units") },
{ 1, GL_MAX_3D_TEXTURE_SIZE, i18n("Max. 3D texture size") },
{ 1, GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, i18n("Max. cube map texture size") },
#ifdef GL_MAX_RECTANGLE_TEXTURE_SIZE_NV
{ 1, GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, i18n("Max. rectangular texture size") },
#endif
{ 1 | KCMGL_FLOAT, GL_MAX_TEXTURE_LOD_BIAS_EXT, i18n("Max. texture LOD bias") },
{ 1, GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, i18n("Max. anisotropy filtering level") },
{ 1, GL_NUM_COMPRESSED_TEXTURE_FORMATS_ARB, i18n("No. of compressed texture formats") },
{0,0,QString()}
};
const struct token_name float_limits[] = {
{ 2 | KCMGL_FLOAT, GL_ALIASED_POINT_SIZE_RANGE, "ALIASED_POINT_SIZE_RANGE" },
{ 2 | KCMGL_FLOAT, GL_SMOOTH_POINT_SIZE_RANGE, "SMOOTH_POINT_SIZE_RANGE" },
{ 1 | KCMGL_FLOAT, GL_SMOOTH_POINT_SIZE_GRANULARITY,"SMOOTH_POINT_SIZE_GRANULARITY"},
{ 2 | KCMGL_FLOAT, GL_ALIASED_LINE_WIDTH_RANGE, "ALIASED_LINE_WIDTH_RANGE" },
{ 2 | KCMGL_FLOAT, GL_SMOOTH_LINE_WIDTH_RANGE, "SMOOTH_LINE_WIDTH_RANGE" },
{ 1 | KCMGL_FLOAT, GL_SMOOTH_LINE_WIDTH_GRANULARITY,"SMOOTH_LINE_WIDTH_GRANULARITY"},
{0,0,QString()}
};
const struct token_name stack_depth[] = {
{ 1, GL_MAX_MODELVIEW_STACK_DEPTH, "MAX_MODELVIEW_STACK_DEPTH" },
{ 1, GL_MAX_PROJECTION_STACK_DEPTH, "MAX_PROJECTION_STACK_DEPTH" },
{ 1, GL_MAX_TEXTURE_STACK_DEPTH, "MAX_TEXTURE_STACK_DEPTH" },
{ 1, GL_MAX_NAME_STACK_DEPTH, "MAX_NAME_STACK_DEPTH" },
{ 1, GL_MAX_ATTRIB_STACK_DEPTH, "MAX_ATTRIB_STACK_DEPTH" },
{ 1, GL_MAX_CLIENT_ATTRIB_STACK_DEPTH, "MAX_CLIENT_ATTRIB_STACK_DEPTH" },
{ 1, GL_MAX_COLOR_MATRIX_STACK_DEPTH, "MAX_COLOR_MATRIX_STACK_DEPTH" },
#ifdef GL_MAX_MATRIX_PALETTE_STACK_DEPTH_ARB
{ 1, GL_MAX_MATRIX_PALETTE_STACK_DEPTH_ARB,"MAX_MATRIX_PALETTE_STACK_DEPTH"},
#endif
{0,0,QString()}
};
#ifdef GL_ARB_fragment_program
const struct token_name arb_fp[] = {
{ 1, GL_MAX_TEXTURE_COORDS_ARB, "MAX_TEXTURE_COORDS" },
{ 1, GL_MAX_TEXTURE_IMAGE_UNITS_ARB, "MAX_TEXTURE_IMAGE_UNITS" },
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, "MAX_PROGRAM_ENV_PARAMETERS" },
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, "MAX_PROGRAM_LOCAL_PARAMETERS" },
{ 1, GL_MAX_PROGRAM_MATRICES_ARB, "MAX_PROGRAM_MATRICES" },
{ 1, GL_MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB, "MAX_PROGRAM_MATRIX_STACK_DEPTH" },
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_INSTRUCTIONS_ARB, "MAX_PROGRAM_INSTRUCTIONS" },
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_ALU_INSTRUCTIONS_ARB, "MAX_PROGRAM_ALU_INSTRUCTIONS" },
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_TEX_INSTRUCTIONS_ARB, "MAX_PROGRAM_TEX_INSTRUCTIONS" },
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_TEX_INDIRECTIONS_ARB, "MAX_PROGRAM_TEX_INDIRECTIONS" },
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_TEMPORARIES_ARB, "MAX_PROGRAM_TEMPORARIES" },
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_PARAMETERS_ARB, "MAX_PROGRAM_PARAMETERS" },
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_ATTRIBS_ARB, "MAX_PROGRAM_ATTRIBS" },
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, "MAX_PROGRAM_NATIVE_INSTRUCTIONS" },
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS_ARB, "MAX_PROGRAM_NATIVE_ALU_INSTRUCTIONS" },
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS_ARB, "MAX_PROGRAM_NATIVE_TEX_INSTRUCTIONS" },
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS_ARB, "MAX_PROGRAM_NATIVE_TEX_INDIRECTIONS" },
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, "MAX_PROGRAM_NATIVE_TEMPORARIES" },
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, "MAX_PROGRAM_NATIVE_PARAMETERS" },
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB, "MAX_PROGRAM_NATIVE_ATTRIBS" },
{0,0,QString()}
};
#endif
#ifdef GL_ARB_vertex_program
const struct token_name arb_vp[] = {
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB,"MAX_PROGRAM_ENV_PARAMETERS"},
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB,"MAX_PROGRAM_LOCAL_PARAMETERS"},
{ 1, GL_MAX_VERTEX_ATTRIBS_ARB, "MAX_VERTEX_ATTRIBS"},
{ 1, GL_MAX_PROGRAM_MATRICES_ARB,"MAX_PROGRAM_MATRICES"},
{ 1, GL_MAX_PROGRAM_MATRIX_STACK_DEPTH_ARB,"MAX_PROGRAM_MATRIX_STACK_DEPTH"},
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_INSTRUCTIONS_ARB,"MAX_PROGRAM_INSTRUCTIONS"},
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_TEMPORARIES_ARB,"MAX_PROGRAM_TEMPORARIES"},
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_PARAMETERS_ARB,"MAX_PROGRAM_PARAMETERS"},
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_ATTRIBS_ARB,"MAX_PROGRAM_ATTRIBS"},
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_ADDRESS_REGISTERS_ARB,"MAX_PROGRAM_ADDRESS_REGISTERS"},
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB,"MAX_PROGRAM_NATIVE_INSTRUCTIONS"},
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB,"MAX_PROGRAM_NATIVE_TEMPORARIES"},
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB,"MAX_PROGRAM_NATIVE_PARAMETERS"},
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_NATIVE_ATTRIBS_ARB,"MAX_PROGRAM_NATIVE_ATTRIBS"},
{ 1 | KCMGL_PROG, GL_MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB ,"MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS"},
{0,0,QString()}
};
#endif
#ifdef GL_ARB_vertex_shader
const struct token_name arb_vs[] = {
{ 1, GL_MAX_VERTEX_ATTRIBS_ARB,"MAX_VERTEX_ATTRIBS"},
{ 1, GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB,"MAX_VERTEX_UNIFORM_COMPONENTS"},
{ 1, GL_MAX_VARYING_FLOATS_ARB,"MAX_VARYING_FLOATS"},
{ 1, GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB,"MAX_COMBINED_TEXTURE_IMAGE_UNITS"},
{ 1, GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB,"MAX_VERTEX_TEXTURE_IMAGE_UNITS"},
{ 1, GL_MAX_TEXTURE_IMAGE_UNITS_ARB,"MAX_TEXTURE_IMAGE_UNITS"},
{ 1, GL_MAX_TEXTURE_COORDS_ARB,"MAX_TEXTURE_COORDS"},
{0,0,QString()}
};
#endif
#ifdef GL_ARB_fragment_shader
const struct token_name arb_fs[] = {
{ 1, GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB,"MAX_FRAGMENT_UNIFORM_COMPONENTS"},
{ 1, GL_MAX_TEXTURE_IMAGE_UNITS_ARB,"MAX_TEXTURE_IMAGE_UNITS"},
{ 1, GL_MAX_TEXTURE_COORDS_ARB,"MAX_TEXTURE_COORDS"},
{0,0,QString()}
};
#endif
const struct token_name frame_buffer_props[] = {
{ 2, GL_MAX_VIEWPORT_DIMS, i18n("Max. viewport dimensions") },
{ 1, GL_SUBPIXEL_BITS, i18n("Subpixel bits") },
{ 1, GL_AUX_BUFFERS, i18n("Aux. buffers")},
{0,0,QString()}
};
const struct token_group groups[] =
{
{KCMGL_SIZE(frame_buffer_props), 0, frame_buffer_props, i18n("Frame buffer properties"), NULL},
{KCMGL_SIZE(various_limits), 0, texture_limits, i18n("Texturing"), NULL},
{KCMGL_SIZE(various_limits), 0, various_limits, i18n("Various limits"), NULL},
{KCMGL_SIZE(float_limits), 0, float_limits, i18n("Points and lines"), NULL},
{KCMGL_SIZE(stack_depth), 0, stack_depth, i18n("Stack depth limits"), NULL},
#ifdef GL_ARB_vertex_program
{KCMGL_SIZE(arb_vp), GL_VERTEX_PROGRAM_ARB, arb_vp, "ARB_vertex_program", "GL_ARB_vertex_program"},
#endif
#ifdef GL_ARB_fragment_program
{KCMGL_SIZE(arb_fp), GL_FRAGMENT_PROGRAM_ARB, arb_fp, "ARB_fragment_program", "GL_ARB_fragment_program"},
#endif
#ifdef GL_ARB_vertex_shader
{KCMGL_SIZE(arb_vs), 0, arb_vs, "ARB_vertex_shader", "GL_ARB_vertex_shader"},
#endif
#ifdef GL_ARB_fragment_shader
{KCMGL_SIZE(arb_fs), 0, arb_fs, "ARB_fragment_shader", "GL_ARB_fragment_shader"},
#endif
};
#if defined(GLX_ARB_get_proc_address) && defined(PFNGLGETPROGRAMIVARBPROC)
if (getProcAddress && strstr(glExtensions, "GL_ARB_vertex_program"))
kcm_glGetProgramivARB = (PFNGLGETPROGRAMIVARBPROC) glXGetProcAddressARB((const GLubyte *)"glGetProgramivARB");
#else
Q_UNUSED(getProcAddress);
#endif
for (uint i = 0; itype; cur_token++) {
bool tfloat = cur_token->type & KCMGL_FLOAT;
int count = KCMGL_COUNT_MASK(cur_token->type);
GLint max[2]={0,0};
GLfloat fmax[2]={0.0,0.0};
#if defined(PFNGLGETPROGRAMIVARBPROC) && defined(GL_ARB_vertex_program)
bool tprog = cur_token->type & KCMGL_PROG;
if (tprog && kcm_glGetProgramivARB)
kcm_glGetProgramivARB(groups[i].type, cur_token->token, max);
else
#endif
if (tfloat) glGetFloatv(cur_token->token, fmax);
else glGetIntegerv(cur_token->token, max);
if (glGetError() == GL_NONE) {
QString s;
if (!tfloat && count == 1) s = QString::number(max[0]); else
if (!tfloat && count == 2) s = QStringLiteral("%1, %2").arg(max[0]).arg(max[1]); else
if (tfloat && count == 2) s = QStringLiteral("%1 - %2").arg(fmax[0],0,'f',6).arg(fmax[1],0,'f',6); else
if (tfloat && count == 1) s = QString::number(fmax[0],'f',6);
if (l3) l3 = newItem(l2, l3, cur_token->name, s);
else l3 = newItem(l2, cur_token->name, s);
}
}
}
}
#endif
static QTreeWidgetItem *print_screen_info(QTreeWidgetItem *l1, QTreeWidgetItem *after, const QString &title)
{
QTreeWidgetItem *l2 = nullptr, *l3 = nullptr;
if (after) {
l1 = newItem(l1, after, title);
} else {
l1 = newItem(l1, title);
}
if (IsDirect) {
if (get_dri_device()) {
l2 = newItem(l1, i18n("3D Accelerator"));
l2->setExpanded(true);
l3 = newItem(l2, l3, i18n("Vendor"), dri_info.vendor);
l3 = newItem(l2, l3, i18n("Device"), dri_info.device);
l3 = newItem(l2, l3, i18n("Subvendor"), dri_info.subvendor);
l3 = newItem(l2, l3, i18n("Revision"), dri_info.rev);
} else {
l2 = newItem(l1, l2, i18n("3D Accelerator"), i18n("unknown"));
}
}
if (l2) {
l2 = newItem(l1, l2, i18n("Driver"));
}else{
l2 = newItem(l1, i18n("Driver"));
}
l2->setExpanded(true);
l3 = newItem(l2, i18n("Vendor"), gli.glVendor);
l3 = newItem(l2, l3, i18n("Renderer"), gli.glRenderer);
#ifdef KCM_ENABLE_OPENGLES
l3 = newItem(l2, l3, i18n("OpenGL ES version"), gli.glVersion);
#else
l3 = newItem(l2, l3, i18n("OpenGL version"), gli.glVersion);
#endif
if (IsDirect) {
if (dri_info.module.isEmpty()) dri_info.module = i18n("unknown");
l3 = newItem(l2, l3, i18n("Kernel module"), dri_info.module);
}
#ifdef KCM_ENABLE_OPENGLES
l3 = newItem(l2, l3, i18n("OpenGL ES extensions"));
#else
l3 = newItem(l2, l3, i18n("OpenGL extensions"));
#endif
print_extension_list(gli.glExtensions, l3);
#if KCM_HAVE_GLX
if (QGuiApplication::platformName() == QStringLiteral("xcb")) {
l3 = newItem(l2, l3, i18n("Implementation specific"));
print_limits(l3, gli.glExtensions, strstr(gli.clientExtensions, "GLX_ARB_get_proc_address") != nullptr);
}
#endif
return l1;
}
#if KCM_HAVE_GLX
void print_glx_glu(QTreeWidgetItem *l1, QTreeWidgetItem *l2)
{
QTreeWidgetItem *l3;
l2 = newItem(l1, l2, i18n("GLX"));
l3 = newItem(l2, i18n("server GLX vendor"), gli.serverVendor);
l3 = newItem(l2, l3, i18n("server GLX version"), gli.serverVersion);
l3 = newItem(l2, l3, i18n("server GLX extensions"));
print_extension_list(gli.serverExtensions, l3);
l3 = newItem(l2, l3, i18n("client GLX vendor") ,gli.clientVendor);
l3 = newItem(l2, l3, i18n("client GLX version"), gli.clientVersion);
l3 = newItem(l2, l3, i18n("client GLX extensions"));
print_extension_list(gli.clientExtensions, l3);
l3 = newItem(l2, l3, i18n("GLX extensions"));
print_extension_list(gli.glxExtensions, l3);
l2 = newItem(l1, l2, i18n("GLU"));
l3 = newItem(l2, i18n("GLU version"), gli.gluVersion);
l3 = newItem(l2, l3, i18n("GLU extensions"));
print_extension_list(gli.gluExtensions, l3);
}
#endif
#if KCM_HAVE_EGL
void print_egl(QTreeWidgetItem *l1, QTreeWidgetItem *l2)
{
QTreeWidgetItem *l3;
l2 = newItem(l1, l2, i18n("EGL"));
l3 = newItem(l2, i18n("EGL Vendor"), gli.eglVendor);
l3 = newItem(l2, l3, i18n("EGL Version"), gli.eglVersion);
l3 = newItem(l2, l3, i18n("EGL Extensions"));
print_extension_list(gli.eglExtensions, l3);
}
#endif
#if KCM_HAVE_GLX
static QTreeWidgetItem *get_gl_info_glx(Display *dpy, int scrnum, Bool allowDirect, QTreeWidgetItem *l1, QTreeWidgetItem *after)
{
Window win;
XSetWindowAttributes attr;
unsigned long mask;
Window root;
XVisualInfo *visinfo;
int width = 100, height = 100;
QTreeWidgetItem *result = after;
root = RootWindow(dpy, scrnum);
const int attribSingle[] = {
GLX_RGBA,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
None };
const int attribDouble[] = {
GLX_RGBA,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_DOUBLEBUFFER,
None };
GLXContext ctx;
visinfo = glXChooseVisual(dpy, scrnum, const_cast(attribSingle));
if (!visinfo) {
visinfo = glXChooseVisual(dpy, scrnum, const_cast(attribDouble));
if (!visinfo) {
qDebug() << "Error: couldn't find RGB GLX visual\n";
return result;
}
}
attr.background_pixel = 0;
attr.border_pixel = 0;
attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
attr.event_mask = StructureNotifyMask | ExposureMask;
mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
win = XCreateWindow(dpy, root, 0, 0, width, height,
0, visinfo->depth, InputOutput,
visinfo->visual, mask, &attr);
ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect );
if (!ctx) {
qDebug() << "Error: glXCreateContext failed\n";
XDestroyWindow(dpy, win);
XFree(visinfo);
return result;
}
if (glXMakeCurrent(dpy, win, ctx)) {
gli.serverVendor = glXQueryServerString(dpy, scrnum, GLX_VENDOR);
gli.serverVersion = glXQueryServerString(dpy, scrnum, GLX_VERSION);
gli.serverExtensions = glXQueryServerString(dpy, scrnum, GLX_EXTENSIONS);
gli.clientVendor = glXGetClientString(dpy, GLX_VENDOR);
gli.clientVersion = glXGetClientString(dpy, GLX_VERSION);
gli.clientExtensions = glXGetClientString(dpy, GLX_EXTENSIONS);
gli.glxExtensions = glXQueryExtensionsString(dpy, scrnum);
gli.glVendor = (const char *) glGetString(GL_VENDOR);
gli.glRenderer = (const char *) glGetString(GL_RENDERER);
gli.glVersion = (const char *) glGetString(GL_VERSION);
gli.glExtensions = (const char *) glGetString(GL_EXTENSIONS);
gli.displayName = nullptr;
gli.gluVersion = (const char *) gluGetString(GLU_VERSION);
gli.gluExtensions = (const char *) gluGetString(GLU_EXTENSIONS);
IsDirect = glXIsDirect(dpy, ctx);
result = print_screen_info(l1, after, IsDirect ? i18n("Direct Rendering (GLX)") : i18n("Indirect Rendering (GLX)"));
}
else {
qDebug() << "Error: glXMakeCurrent failed\n";
}
glXMakeCurrent(dpy, GL_NONE, nullptr);
glXDestroyContext(dpy, ctx);
XDestroyWindow(dpy, win);
XFree(visinfo);
return result;
}
#endif
#if KCM_HAVE_EGL
static QTreeWidgetItem *get_gl_info_egl(Display *dpy, int scrnum, QTreeWidgetItem *l1, QTreeWidgetItem *after)
{
Window win;
XSetWindowAttributes attr;
unsigned long mask;
Window root;
XVisualInfo *visinfo;
int width = 100, height = 100;
QTreeWidgetItem *result = after;
root = RootWindow(dpy, scrnum);
static const EGLint attribs[] = {
EGL_RED_SIZE, 1,
EGL_GREEN_SIZE, 1,
EGL_BLUE_SIZE, 1,
EGL_DEPTH_SIZE, 1,
EGL_NONE
};
static const EGLint ctx_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
XVisualInfo visTemplate;
int num_visuals;
EGLDisplay egl_dpy;
EGLSurface surf;
EGLContext ctx;
EGLConfig config;
EGLint num_configs;
EGLint vid, major, minor;
egl_dpy = eglGetDisplay(dpy);
if (!egl_dpy) {
qDebug() << "Error: eglGetDisplay() failed\n";
return result;
}
if (!eglInitialize(egl_dpy, &major, &minor)) {
qDebug() << "Error: eglInitialize() failed\n";
return result;
}
if (!eglChooseConfig(egl_dpy, attribs, &config, 1, &num_configs)) {
qDebug() << "Error: couldn't get an EGL visual config\n";
return result;
}
if (!eglGetConfigAttrib(egl_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) {
qDebug() << "Error: eglGetConfigAttrib() failed\n";
return result;
}
visTemplate.visualid = vid;
visinfo = XGetVisualInfo(dpy, VisualIDMask, &visTemplate, &num_visuals);
if (!visinfo) {
qDebug() << "Error: couldn't get X visual\n";
return result;
}
attr.background_pixel = 0;
attr.border_pixel = 0;
attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
attr.event_mask = StructureNotifyMask | ExposureMask;
mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
win = XCreateWindow(dpy, root, 0, 0, width, height,
0, visinfo->depth, InputOutput,
visinfo->visual, mask, &attr);
#ifdef KCM_ENABLE_OPENGLES
eglBindAPI(EGL_OPENGL_ES_API);
#else
eglBindAPI(EGL_OPENGL_API);
#endif
ctx = eglCreateContext(egl_dpy, config, EGL_NO_CONTEXT, ctx_attribs);
if (!ctx) {
qDebug() << "Error: eglCreateContext failed\n";
XDestroyWindow(dpy, win);
XFree(visinfo);
return result;
}
surf = eglCreateWindowSurface(egl_dpy, config, win, NULL);
if (!surf) {
qDebug() << "Error: eglCreateWindowSurface failed\n";
eglDestroyContext(egl_dpy, ctx);
XDestroyWindow(dpy, win);
XFree(visinfo);
return result;
}
if (eglMakeCurrent(egl_dpy, surf, surf, ctx)) {
gli.eglVendor = eglQueryString(egl_dpy, EGL_VENDOR);
gli.eglVersion = eglQueryString(egl_dpy, EGL_VERSION);
gli.eglExtensions = eglQueryString(egl_dpy, EGL_EXTENSIONS);
gli.glVendor = (const char *) glGetString(GL_VENDOR);
gli.glRenderer = (const char *) glGetString(GL_RENDERER);
gli.glVersion = (const char *) glGetString(GL_VERSION);
gli.glExtensions = (const char *) glGetString(GL_EXTENSIONS);
gli.displayName = nullptr;
result = print_screen_info(l1, after, i18n("Direct Rendering (EGL)"));
}
else {
qDebug() <<"Error: eglMakeCurrent() failed\n";
}
eglMakeCurrent(egl_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
eglDestroyContext(egl_dpy, ctx);
eglDestroySurface(egl_dpy, surf);
XDestroyWindow(dpy, win);
XFree(visinfo);
return result;
}
static QTreeWidgetItem *get_gl_info_egl_qt(QTreeWidgetItem *l1, QTreeWidgetItem *after, QSurfaceFormat::OpenGLContextProfile profile, const QString &title)
{
QTreeWidgetItem *result = after;
QOffscreenSurface surface;
surface.create();
QOpenGLContext context;
QSurfaceFormat format;
format.setProfile(profile);
context.setFormat(format);
if (!context.create()) {
qDebug() << "Could not create QOpenGLContext";
return result;
}
if (context.format().profile() != profile) {
qDebug() << "Could not get requested OpenGL profile, requested" << profile << "got" << context.format().profile();
return result;
}
if (context.makeCurrent(&surface)) {
EGLDisplay egl_dpy = eglGetCurrentDisplay();
gli.eglVendor = eglQueryString(egl_dpy, EGL_VENDOR);
gli.eglVersion = eglQueryString(egl_dpy, EGL_VERSION);
gli.eglExtensions = eglQueryString(egl_dpy, EGL_EXTENSIONS);
gli.glVendor = (const char *) glGetString(GL_VENDOR);
gli.glRenderer = (const char *) glGetString(GL_RENDERER);
gli.glVersion = (const char *) glGetString(GL_VERSION);
gli.glExtensions = (const char *) glGetString(GL_EXTENSIONS);
gli.displayName = nullptr;
result = print_screen_info(l1, after, title);
}
else {
qDebug() <<"Error: eglMakeCurrent() failed\n";
}
context.doneCurrent();
return result;
}
#endif
bool GetInfo_OpenGL(QTreeWidget *treeWidget)
{
QTreeWidgetItem *l1, *l2 = nullptr;
static bool isX11 = QGuiApplication::platformName() == QStringLiteral("xcb");
static bool isWayland = QGuiApplication::platformName().contains(QStringLiteral("wayland"));
QTreeWidgetItem *header = new QTreeWidgetItem();
header->setText(0, i18n("Information"));
header->setText(1, i18n("Value"));
treeWidget->setHeaderItem(header);
treeWidget->setRootIsDecorated(false);
l1 = new QTreeWidgetItem(treeWidget);
if (isX11) {
char *displayName = nullptr;
Display *dpy;
int numScreens, scrnum;
dpy = XOpenDisplay(displayName);
if (!dpy) {
// qDebug() << "Error: unable to open display " << displayName;
return false;
}
l1->setText(0, i18n("Name of the Display"));
l1->setText(1, QString::fromLatin1(DisplayString(dpy)));
l1->setExpanded(true);
l1->setFlags(Qt::ItemIsEnabled);
numScreens = ScreenCount(dpy);
scrnum = 0;
#ifdef KCMGL_MANY_SCREENS
for (; scrnum < numScreens; scrnum++)
#endif
{
#if KCM_HAVE_GLX
mesa_hack(dpy, scrnum);
l2 = get_gl_info_glx(dpy, scrnum, true, l1, l2);
if (l2) l2->setExpanded(true);
#endif
#if KCM_HAVE_EGL
l2 = get_gl_info_egl(dpy, scrnum, l1, l2);
if (l2)
l2->setExpanded(true);
#endif
// TODO print_visual_info(dpy, scrnum, mode);
}
#if KCM_HAVE_GLX
if (l2)
print_glx_glu(l1, l2);
else
KMessageBox::error(0, i18n("Could not initialize OpenGL/GLX"));
#endif
XCloseDisplay(dpy);
}
if (isWayland) {
IsDirect = true;
l1->setText(0, i18n("Name of the Display"));
l1->setText(1, QString::fromLatin1(qgetenv("WAYLAND_DISPLAY")));
l1->setExpanded(true);
l1->setFlags(Qt::ItemIsEnabled);
#if KCM_HAVE_EGL
l2 = get_gl_info_egl_qt(l1, l2, QSurfaceFormat::NoProfile, i18n("OpenGL"));
if (l2)
l2->setExpanded(true);
l2 = get_gl_info_egl_qt(l1, l2, QSurfaceFormat::CoreProfile, i18n("Core Profile"));
if (l2)
l2->setExpanded(true);
l2 = get_gl_info_egl_qt(l1, l2, QSurfaceFormat::CompatibilityProfile, i18n("Compatibility Profile"));
if (l2)
l2->setExpanded(true);
#endif
}
#if KCM_HAVE_EGL
if (l2)
print_egl(l1, l2);
else
KMessageBox::error(0, i18n("Could not initialize OpenGL (ES)/EGL "));
#endif
treeWidget->resizeColumnToContents(0);
treeWidget->resizeColumnToContents(1);
return true;
}
#include "opengl.moc"
diff --git a/Modules/pci/kcm_pci.cpp b/Modules/pci/kcm_pci.cpp
index 2c49609..6cb5c8a 100644
--- a/Modules/pci/kcm_pci.cpp
+++ b/Modules/pci/kcm_pci.cpp
@@ -1,85 +1,85 @@
/*
* Copyright (C) 2008 Nicolas Ternisien
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "kcm_pci.h"
#include
#include
#include
#include
#include
#include
#include
#include
K_PLUGIN_FACTORY(KCMPciFactory,
registerPlugin();
)
KCMPci::KCMPci(QWidget *parent, const QVariantList &) :
KCModule(parent) {
KAboutData *about = new KAboutData(i18n("kcm_pci"),
i18n("PCI Devices"),
QString(), QString(), KAboutLicense::GPL,
i18n( "(c) 2008 Nicolas Ternisien"
"(c) 1998 - 2002 Helge Deller"));
about->addAuthor(i18n("Nicolas Ternisien"), QString(), QStringLiteral("nicolas.ternisien@gmail.com"));
about->addAuthor(i18n("Helge Deller"), QString(), QStringLiteral("deller@gmx.de"));
setAboutData(about);
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setSpacing(0);
- layout->setMargin(0);
+ layout->setContentsMargins(0, 0, 0, 0);
tree = new QTreeWidget(this);
layout->addWidget(tree);
tree->setSelectionMode(QAbstractItemView::ExtendedSelection);
tree->setAllColumnsShowFocus(true);
tree->setRootIsDecorated(false);
tree->setWhatsThis(i18n("This list displays PCI information.") );
}
KCMPci::~KCMPci() {
}
void KCMPci::load() {
//qDebug() << "Loading PCI information..." << endl;
GetInfo_PCI(tree);
//Resize the column width to the maximum needed
tree->expandAll();
tree->resizeColumnToContents( 0 );
tree->collapseAll();
}
QString KCMPci::quickHelp() const {
return i18n("This display shows information about your computer's PCI slots and the related connected devices.");
}
#include "kcm_pci.moc"
diff --git a/Modules/samba/main.cpp b/Modules/samba/main.cpp
index 14af0b2..5451993 100644
--- a/Modules/samba/main.cpp
+++ b/Modules/samba/main.cpp
@@ -1,105 +1,105 @@
/*
* main.cpp for the samba kcontrol module
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include
#include
#include
#include
#include
#include "kcmsambaimports.h"
#include "kcmsambalog.h"
#include "kcmsambastatistics.h"
#include "ksmbstatus.h"
#include
class SambaContainer : public KCModule {
Q_OBJECT
public:
SambaContainer(QWidget *parent=nullptr, const QVariantList &list = QVariantList());
virtual ~SambaContainer();
void load() override;
void save() override;
private:
KConfig config;
QTabWidget tabs;
NetMon status;
ImportsView imports;
LogView logView;
StatisticsView statisticsView;
};
K_PLUGIN_FACTORY(SambaFactory,
registerPlugin();
)
SambaContainer::SambaContainer(QWidget *parent, const QVariantList&) :
KCModule(parent), config(QStringLiteral("kcmsambarc")), tabs(this), status(&tabs, &config), imports(&tabs, &config), logView(&tabs, &config), statisticsView(&tabs, &config) {
QVBoxLayout *layout = new QVBoxLayout( this );
- layout->setMargin(0);
+ layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(&tabs);
tabs.addTab(&status, i18n("&Exports"));
tabs.addTab(&imports, i18n("&Imports"));
tabs.addTab(&logView, i18n("&Log"));
tabs.addTab(&statisticsView, i18n("&Statistics"));
connect(&logView, &LogView::contentsChanged, &statisticsView, &StatisticsView::setListInfo);
setButtons(Help);
setQuickHelp(i18n("The Samba and NFS Status Monitor is a front end to the programs"
" smbstatus and showmount. Smbstatus reports on current"
" Samba connections, and is part of the suite of Samba tools, which"
" implements the SMB (Session Message Block) protocol, also called the"
" NetBIOS or LanManager protocol. This protocol can be used to provide"
" printer sharing or drive sharing services on a network including"
" machines running the various flavors of Microsoft Windows.
"));
KAboutData *about = new KAboutData(i18n("kcmsamba"),
i18n("System Information Control Module"),
QString(), QString(), KAboutLicense::GPL,
i18n("(c) 2002 KDE Information Control Module Samba Team"));
about->addAuthor(i18n("Michael Glauche"), QString(), QStringLiteral("glauche@isa.rwth-aachen.de"));
about->addAuthor(i18n("Matthias Hoelzer"), QString(), QStringLiteral("hoelzer@kde.org"));
about->addAuthor(i18n("David Faure"), QString(), QStringLiteral("faure@kde.org"));
about->addAuthor(i18n("Harald Koschinski"), QString(), QStringLiteral("Harald.Koschinski@arcormail.de"));
about->addAuthor(i18n("Wilco Greven"), QString(), QStringLiteral("greven@kde.org"));
about->addAuthor(i18n("Alexander Neundorf"), QString(), QStringLiteral("neundorf@kde.org"));
setAboutData(about);
}
SambaContainer::~SambaContainer() {
save();
}
void SambaContainer::load() {
status.loadSettings();
imports.loadSettings();
logView.loadSettings();
statisticsView.loadSettings();
}
void SambaContainer::save() {
status.saveSettings();
imports.saveSettings();
logView.saveSettings();
statisticsView.saveSettings();
config.sync();
}
#include "main.moc"
diff --git a/Modules/usbview/kcmusb.cpp b/Modules/usbview/kcmusb.cpp
index f34b7c1..3f0c909 100644
--- a/Modules/usbview/kcmusb.cpp
+++ b/Modules/usbview/kcmusb.cpp
@@ -1,175 +1,175 @@
/***************************************************************************
* Copyright (C) 2001 by Matthias Hoelzer-Kluepfel *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "kcmusb.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "usbdevices.h"
K_PLUGIN_FACTORY(USBFactory,
registerPlugin();
)
USBViewer::USBViewer(QWidget *parent, const QVariantList &) :
KCModule(parent) {
setQuickHelp(i18n("This module allows you to see"
" the devices attached to your USB bus(es)."));
QHBoxLayout *mainLayout = new QHBoxLayout(this);
- mainLayout->setMargin(0);
+ mainLayout->setContentsMargins(0, 0, 0, 0);
mainLayout->setSpacing(0);
QSplitter *splitter = new QSplitter(this);
splitter->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
mainLayout->addWidget(splitter);
_devices = new QTreeWidget(splitter);
QStringList headers;
headers << i18n("Device");
_devices->setHeaderLabels(headers);
_devices->setRootIsDecorated(true);
_devices->header()->hide();
//_devices->setColumnWidthMode(0, Q3ListView::Maximum);
QList sizes;
sizes.append(200);
splitter->setSizes(sizes);
_details = new QTextEdit(splitter);
_details->setReadOnly(true);
QTimer *refreshTimer = new QTimer(this);
// 1 sec seems to be a good compromise between latency and polling load.
refreshTimer->start(1000);
connect(refreshTimer, &QTimer::timeout, this, &USBViewer::refresh);
connect(_devices, &QTreeWidget::currentItemChanged, this, &USBViewer::selectionChanged);
KAboutData *about = new KAboutData(i18n("kcmusb"), i18n("USB Devices"),
QString(), QString(), KAboutLicense::GPL,
i18n("(c) 2001 Matthias Hoelzer-Kluepfel"));
about->addAuthor(i18n("Matthias Hoelzer-Kluepfel"), QString(), QStringLiteral("mhk@kde.org"));
about->addCredit(i18n("Leo Savernik"), i18n("Live Monitoring of USB Bus"), QStringLiteral("l.savernik@aon.at"));
setAboutData(about);
}
void USBViewer::load() {
_items.clear();
_devices->clear();
refresh();
}
static quint32 key(USBDevice &dev) {
return dev.bus()*256 + dev.device();
}
static quint32 key_parent(USBDevice &dev) {
return dev.bus()*256 + dev.parent();
}
static void delete_recursive(QTreeWidgetItem *item, const QMap &new_items) {
if (!item)
return;
QTreeWidgetItemIterator it(item, QTreeWidgetItemIterator::All);
while ( *it != nullptr ) {
QTreeWidgetItem* currentItem = *it;
if (new_items.contains(currentItem->text(1).toUInt()) == false) {
delete_recursive(currentItem->child(0), new_items);
delete currentItem;
}
++it;
}
}
void USBViewer::refresh() {
QMap new_items;
if (!USBDevice::parse(QStringLiteral("/proc/bus/usb/devices")))
USBDevice::parseSys(QStringLiteral("/sys/bus/usb/devices"));
int level = 0;
bool found = true;
while (found) {
found = false;
foreach(USBDevice* usbDevice, USBDevice::devices()) {
if (usbDevice->level() == level) {
quint32 k = key(*usbDevice);
if (level == 0) {
QTreeWidgetItem* item = _items.value(k);
if (!item) {
QStringList itemContent;
itemContent << usbDevice->product() << QString::number(k);
item = new QTreeWidgetItem(_devices, itemContent);
}
new_items.insert(k, item);
found = true;
} else {
QTreeWidgetItem *parent = new_items.value(key_parent(*usbDevice));
if (parent) {
QTreeWidgetItem *item = _items.value(k);
if (!item) {
QStringList itemContent;
itemContent << usbDevice->product() << QString::number(k);
item = new QTreeWidgetItem(parent, itemContent);
}
new_items.insert(k, item);
parent->setExpanded(true);
found = true;
}
}
}
}
++level;
}
// recursive delete all items not in new_items
delete_recursive(_devices->topLevelItem(0), new_items);
_items = new_items;
if (_devices->selectedItems().isEmpty() == true)
selectionChanged(_devices->topLevelItem(0));
}
void USBViewer::selectionChanged(QTreeWidgetItem *item) {
if (item) {
quint32 busdev = item->text(1).toUInt();
USBDevice *dev = USBDevice::find(busdev>>8, busdev&255);
if (dev) {
_details->setHtml(dev->dump());
return;
}
}
_details->clear();
}
#include "kcmusb.moc"
diff --git a/Modules/view1394/view1394.cpp b/Modules/view1394/view1394.cpp
index 500b9a1..cac55a3 100644
--- a/Modules/view1394/view1394.cpp
+++ b/Modules/view1394/view1394.cpp
@@ -1,312 +1,312 @@
/*
* view1394.cpp
*
* Copyright (C) 2003 Alexander Neundorf
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "view1394.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define CONFIGROM_BASE 0x00
#define CONFIGROM_CAP 0x08
#define CONFIGROM_GUID_HI 0x0c
#define CONFIGROM_GUID_LO 0x10
#define MAX_1394_PORTS 16
int my_reset_handler(raw1394handle_t handle, unsigned int) {
View1394* view1394=(View1394*)raw1394_get_userdata(handle);
if (view1394)
view1394->rescanBus();
return 0;
}
K_PLUGIN_FACTORY(View1394Factory, registerPlugin();)
View1394::View1394(QWidget *parent, const QVariantList &) :
KCModule(parent), m_insideRescanBus(false) {
setQuickHelp(i18n("Here you can see some information about "
"your IEEE 1394 configuration. "
"The meaning of the columns:"
""
"- Name: port or node name, the number can change with each bus reset
"
"- GUID: the 64 bit GUID of the node
"
"- Local: checked if the node is an IEEE 1394 port of your computer
"
"- IRM: checked if the node is isochronous resource manager capable
"
"- CRM: checked if the node is cycle master capable
"
"- ISO: checked if the node supports isochronous transfers
"
"- BM: checked if the node is bus manager capable
"
"- PM: checked if the node is power management capable
"
"- Acc: the cycle clock accuracy of the node, valid from 0 to 100
"
"- Speed: the speed of the node
"
"- Vendor: the vendor of the device
"
"
"
));
m_ouiDb=new OuiDb();
QVBoxLayout *box=new QVBoxLayout(this);
- box->setMargin(0);
+ box->setContentsMargins(0, 0, 0, 0);
m_view=new View1394Widget(this);
/*
for (int i=2; i<8; i++)
m_view->m_listview->setColumnAlignment(i, Qt::AlignHCenter);
m_view->m_listview->setColumnAlignment(8, Qt::AlignRight);
m_view->m_listview->setColumnAlignment(9, Qt::AlignRight);
*/
box->addWidget(m_view);
- m_view->layout()->setMargin(0);
+ m_view->layout()->setContentsMargins(0, 0, 0, 0);
connect(m_view->m_busResetPb, &QPushButton::clicked, this, &View1394::generateBusReset);
connect(&m_rescanTimer, &QTimer::timeout, this, &View1394::rescanBus);
rescanBus();
}
View1394::~View1394() {
foreach(QSocketNotifier* notifier, m_notifiers) {
delete notifier;
}
m_notifiers.clear();
delete m_ouiDb;
}
bool View1394::readConfigRom(raw1394handle_t handle, nodeid_t nodeid, quadlet_t& firstQuad, quadlet_t& cap, octlet_t& guid) {
quadlet_t q=0;
firstQuad=0;
cap=0;
guid=0;
nodeaddr_t addr=CSR_REGISTER_BASE + CSR_CONFIG_ROM + CONFIGROM_BASE;
for (int count=0; count<5; count++) {
struct timeval tv;
q=0;
int res=raw1394_read(handle, nodeid|0xffc0, addr, sizeof(q), &q);
if (res==0) {
firstQuad=ntohl(q);
break;
}
tv.tv_sec=0;
tv.tv_usec=10*1000;
select(0, nullptr, nullptr, nullptr, &tv);
}
if (firstQuad==0)
return false;
addr=CSR_REGISTER_BASE + CSR_CONFIG_ROM + CONFIGROM_CAP;
if (raw1394_read(handle, nodeid|0xffc0, addr, sizeof(q), &q)!=0)
return false;
cap=ntohl(q);
addr=CSR_REGISTER_BASE + CSR_CONFIG_ROM + CONFIGROM_GUID_HI;
if (raw1394_read(handle, nodeid|0xffc0, addr, sizeof(q), &q)!=0)
return false;
guid=octlet_t(ntohl(q))<<32;
addr=CSR_REGISTER_BASE + CSR_CONFIG_ROM + CONFIGROM_GUID_LO;
if (raw1394_read(handle, nodeid|0xffc0, addr, sizeof(q), &q)!=0)
return false;
guid=guid|ntohl(q);
return true;
}
void View1394::callRaw1394EventLoop(int fd) {
for (QList::iterator it= m_handles.begin(); it!=m_handles.end(); ++it)
if (raw1394_get_fd(*it)==fd) {
raw1394_loop_iterate(*it);
break;
}
}
void View1394::rescanBus() {
if (m_insideRescanBus) {
m_rescanTimer.setSingleShot(true);
m_rescanTimer.start(100);
return;
}
m_insideRescanBus=true;
// static int depth=0;
// depth++;
m_notifiers.clear();
for (QList::iterator it=m_handles.begin(); it!=m_handles.end(); ++it)
raw1394_destroy_handle(*it);
m_handles.clear();
m_view->m_listview->clear();
raw1394handle_t handle=raw1394_new_handle();
if (handle==nullptr) {
m_insideRescanBus=false;
return;
}
//now search for new stuff
struct raw1394_portinfo p_info[MAX_1394_PORTS];
int num_of_cards=raw1394_get_port_info(handle, p_info, MAX_1394_PORTS);
raw1394_destroy_handle(handle);
//iterate over all cards
for (int i=0; im_listview, cardContents);
int num_of_nodes=raw1394_get_nodecount(handle);
int localNodeId=raw1394_get_local_id(handle);
//iterate over all nodes connected to this card
for (int j=0; j>24) & 0xff)==1) {
QString guidStr=QString::number(firstQuad, 16);
guidStr="0x"+guidStr.rightJustified(6, QLatin1Char('0'));
QStringList romList;
romList << nodeStr << guidStr;
new QTreeWidgetItem(card, romList);
}
//general config rom
else {
QString guidStr;
char buf[32];
snprintf(buf, 32, "%lX", guid);
guidStr=buf;
guidStr="0x"+guidStr.rightJustified(16, QLatin1Char('0'));
QString local=((j | 0xffc0) == localNodeId) ? QStringLiteral("X") : QString();
QString irmStr=(cap & 0x80000000) ? QStringLiteral("X") : QString();
QString cmStr=(cap & 0x40000000) ? QStringLiteral("X") : QString();
QString isStr=(cap & 0x20000000) ? QStringLiteral("X") : QString();
QString bmStr=(cap & 0x10000000) ? QStringLiteral("X") : QString();
QString pmStr=(cap & 0x08000000) ? QStringLiteral("X") : QString();
QString accStr=QString::number((cap &0x00ff0000)>>16);
int speed=(cap & 0x00000007);
QString speedStr;
switch (speed) {
case (3):
speedStr=QStringLiteral("800");
break;
case (2):
speedStr=QStringLiteral("400");
break;
case (1):
speedStr=QStringLiteral("200");
break;
case (0):
default:
speedStr=QStringLiteral("100");
break;
}
QStringList nodeContents;
nodeContents << nodeStr << guidStr << local << irmStr << cmStr << isStr << bmStr << pmStr << accStr << speedStr << m_ouiDb->vendor(guid);
new QTreeWidgetItem(card, nodeContents);
}
}
card->setExpanded(true);
}
// depth--;
m_insideRescanBus=false;
}
void View1394::generateBusReset() {
for (QList::iterator it=m_handles.begin(); it!=m_handles.end(); ++it)
raw1394_reset_bus(*it);
}
OuiDb::OuiDb() {
QString filename=QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kcmview1394/oui.db"));
if (filename.isEmpty())
return;
QFile f(filename);
if (!f.open(QIODevice::ReadOnly))
return;
QByteArray ba=f.readAll();
int bytesLeft=ba.size();
char* data=ba.data();
while (bytesLeft>8) {
char *eol=(char*)memchr((const void*)data, '\n', bytesLeft);
if (eol==0)
break;
if ((eol-data)<8)
break;
data[6]='\0';
*eol='\0';
m_vendorIds.insert(QLatin1String(data), QString::fromUtf8(data+7));
bytesLeft-=(eol+1-data);
data=eol+1;
}
f.close();
}
QString OuiDb::vendor(octlet_t guid) {
guid=(guid & 0xffffff0000000000LL)>>40;
QString key=QString::number((unsigned int)(guid), 16);
key=key.rightJustified(6, '0').toUpper();
QString v=m_vendorIds[key];
if (v.isEmpty())
v=i18n("Unknown");
return v;
}
// ------------------------------------------------------------------------
#include "view1394.moc"