sync code

This commit is contained in:
klve 2023-04-04 15:04:20 +08:00
parent 36c052f99a
commit 6a746dc87b
129 changed files with 7653 additions and 2207 deletions

View File

@ -11,7 +11,11 @@ HEADERS += \
$$PWD/katabbutton.h \
$$PWD/kdriveinfoitem.h \
$$PWD/kinfolistitem.h \
$$PWD/loadingwidget.h
$$PWD/loadingwidget.h \
$$PWD/../src/imageutil.h \
$$PWD/../src/util.h \
$$PWD/../src/loadwidget.h \
SOURCES += \
$$PWD/kabuttonproxystyle.cpp \
$$PWD/kagroupbutton.cpp \
@ -22,4 +26,7 @@ SOURCES += \
$$PWD/katabbutton.cpp \
$$PWD/kdriveinfoitem.cpp \
$$PWD/kinfolistitem.cpp \
$$PWD/loadingwidget.cpp
$$PWD/loadingwidget.cpp \
$$PWD/../src/imageutil.cpp \
$$PWD/../src/util.cpp \
$$PWD/../src/loadwidget.cpp

View File

@ -49,6 +49,7 @@ void KAInfoTitle::setText(QString strTitle)
{
m_strTitle = strTitle;
m_labelTitle->setText(m_strTitle);
m_labelTitle->setWordWrap(true);
}
void KAInfoTitle::paintEvent(QPaintEvent *event)
@ -95,7 +96,9 @@ void KAInfoTitle::paintEvent(QPaintEvent *event)
QPainterPath path1;
path1.addRect(rectBlue);
path1.setFillRule(Qt::WindingFill);
painter.setBrush(QColor("#3790FA"));
QPalette pal = this->palette();
QColor highlight = pal.color(QPalette::Active, QPalette::Highlight);
painter.setBrush(highlight);
painter.setPen(Qt::transparent);
painter.drawPath(path1);

View File

@ -39,6 +39,7 @@
#include <QDebug>
#include "../../src/commondef.h"
#include "../src/imageutil.h"
KDriveInfoItem::KDriveInfoItem(QString strTitle, QString strIcon, QString strDriveName, QString strDriveVer, bool isOdd, QWidget *parent)
: QFrame(parent)
@ -97,23 +98,17 @@ void KDriveInfoItem::initUI()
m_mainLayout->addSpacing(22);
if (!m_strIcon.isEmpty()) {
m_labelIcon = new QLabel();
QIcon icon;
if (m_strIcon.contains("/")) {
QFileInfo fileInfo(m_strIcon);
if (fileInfo.exists()) {
icon = QIcon(m_strIcon);
}
} else {
icon = QIcon::fromTheme(m_strIcon);
}
m_labelIcon->setPixmap(icon.pixmap(16,16));
m_mainLayout->addWidget(m_labelIcon, 0, Qt::AlignHCenter);
m_mainLayout->addSpacing(12);
}
m_labelIcon = new QLabel();
m_mainLayout->addWidget(m_labelIcon, 0, Qt::AlignHCenter);
m_mainLayout->addSpacing(12);
m_labelTitle = new QLabel();
m_labelTitle->setText(m_strTitle);
QFontMetrics fontWidth(m_labelTitle->font());
QString ShowValue = fontWidth.elidedText(m_strTitle, Qt::ElideRight, 150);
m_labelTitle->setText(ShowValue);
m_labelTitle->setToolTip(m_strTitle);
m_labelTitle->setFixedWidth(150);
m_mainLayout->addWidget(m_labelTitle, 2, Qt::AlignLeft);
m_labelDriveName = new QLabel();
m_labelDriveName->setText(m_strDriveName);
@ -130,12 +125,42 @@ void KDriveInfoItem::initUI()
m_mainLayout->addStretch();
m_rkeyMenu = new QMenu(this);
QAction *copyAction = new QAction(QIcon::fromTheme("edit-copy-symbolic"), tr("Copy"), this);
connect(copyAction, &QAction::triggered, this, &KDriveInfoItem::onCopyContent);
m_rkeyMenu->addAction(copyAction);
// QAction *copyAction = new QAction(QIcon::fromTheme("edit-copy-symbolic"), tr("Copy"), this);
// connect(copyAction, &QAction::triggered, this, &KDriveInfoItem::onCopyContent);
// m_rkeyMenu->addAction(copyAction);
this->setLayout(m_mainLayout);
initStyleTheme();
setIcon(m_strIcon);
}
void KDriveInfoItem::setIcon(QString &m_strIcon)
{
QPixmap pixmap;
if (!m_strIcon.isEmpty()) {
QIcon icon;
if (m_strIcon.contains("/")) {
QFileInfo fileInfo(m_strIcon);
if (fileInfo.exists()) {
icon = QIcon(m_strIcon);
}
} else {
icon = QIcon::fromTheme(m_strIcon);
if (m_strThemeName == "ukui-dark" || m_strThemeName == "ukui-black") {
pixmap = ImageUtil::drawSymbolicColoredPixmap(icon.pixmap(16,16),"white");
} else { // "ukui-default" "ukui-white" "ukui-light" "ukui"
pixmap = ImageUtil::drawSymbolicColoredPixmap(icon.pixmap(16,16),"black");
}
}
}
if (!pixmap.isNull()) {
m_labelIcon->setPixmap(pixmap);
m_labelIcon->show();
} else {
m_labelIcon->hide();
}
}
void KDriveInfoItem::initStyleTheme()
@ -155,6 +180,8 @@ void KDriveInfoItem::initStyleTheme()
} else {
m_alternateBase = QColor(COLOR_ALTERNATEBASE_LIGHT);
}
m_strThemeName = styleName;
setIcon(m_strIcon);
repaint();
}
}
@ -167,6 +194,7 @@ void KDriveInfoItem::initStyleTheme()
} else {
m_alternateBase = QColor(COLOR_ALTERNATEBASE_LIGHT);
}
m_strThemeName = styleName;
}
}
}

View File

@ -49,6 +49,7 @@ protected:
private:
void initStyleTheme();
void setIcon(QString &m_strIcon);
private:
QHBoxLayout *m_mainLayout = nullptr;
@ -63,6 +64,7 @@ private:
QString m_strIcon;
QString m_strDriveName;
QString m_strDriveVersion;
QString m_strThemeName = "";
bool m_isOdd = false;
QGSettings *m_styleSettings = nullptr;

View File

@ -38,6 +38,7 @@
#include <QMouseEvent>
#include <QDebug>
#include "../src/imageutil.h"
#include "../../src/commondef.h"
KInfoListItem::KInfoListItem(QString strTitle, QString strIcon, QString strDetail, bool isOdd, QWidget *parent)
@ -91,20 +92,13 @@ void KInfoListItem::initUI()
m_mainLayout->addSpacing(22);
initStyleTheme();
if (!m_strIcon.isEmpty()) {
m_labelIcon = new QLabel();
QIcon icon;
if (m_strIcon.contains("/")) {
QFileInfo fileInfo(m_strIcon);
if (fileInfo.exists()) {
icon = QIcon(m_strIcon);
}
} else {
icon = QIcon::fromTheme(m_strIcon);
}
m_labelIcon->setPixmap(icon.pixmap(16,16));
m_mainLayout->addWidget(m_labelIcon, 0, Qt::AlignHCenter);
m_mainLayout->addSpacing(12);
setIcon(m_strIcon);
}
m_labelTitle = new KALabel();
m_labelTitle->setText(m_strTitle);
@ -114,16 +108,26 @@ void KInfoListItem::initUI()
m_labelDetail->setText(m_strDetail);
m_labelDetail->setFixedWidth(460);
//m_labelDetail->setWordWrap(true);
m_mainLayout->addWidget(m_labelDetail, 0, Qt::AlignLeft);
if (m_strTitle == "") {
m_labelTitle->setFixedWidth(0);
m_labelDetail->setAlignment(Qt::AlignCenter);
m_mainLayout->insertStretch(0);
m_mainLayout->setAlignment(m_labelDetail, Qt::AlignCenter);
m_mainLayout->addSpacing(22);
m_mainLayout->setSpacing(0);
}
m_mainLayout->addStretch();
m_rkeyMenu = new QMenu(this);
QAction *copyAction = new QAction(QIcon::fromTheme("edit-copy-symbolic"), tr("Copy"), this);
connect(copyAction, &QAction::triggered, this, &KInfoListItem::onCopyContent);
m_rkeyMenu->addAction(copyAction);
m_rkeyMenu = new QMenu(this);
// QAction *copyAction = new QAction(QIcon::fromTheme("edit-copy-symbolic"), tr("Copy"), this);
// connect(copyAction, &QAction::triggered, this, &KInfoListItem::onCopyContent);
// m_rkeyMenu->addAction(copyAction);
this->setLayout(m_mainLayout);
initStyleTheme();
// initStyleTheme();
}
void KInfoListItem::initStyleTheme()
@ -143,6 +147,10 @@ void KInfoListItem::initStyleTheme()
} else {
m_alternateBase = QColor(COLOR_ALTERNATEBASE_LIGHT);
}
m_strThemeName = styleName;
if (!m_strIcon.isEmpty()) {
setIcon(m_strIcon);
}
repaint();
}
}
@ -155,6 +163,7 @@ void KInfoListItem::initStyleTheme()
} else {
m_alternateBase = QColor(COLOR_ALTERNATEBASE_LIGHT);
}
m_strThemeName = styleName;
}
}
}
@ -173,8 +182,44 @@ void KInfoListItem::mousePressEvent(QMouseEvent *event)
QFrame::mousePressEvent(event);
}
// 复制单行
// void KInfoListItem::onCopyContent()
// {
// QClipboard *clipboard = QApplication::clipboard();
// clipboard->setText(m_strTitle+":"+m_strDetail);
// }
void KInfoListItem::onCopyContent()
{
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(m_strTitle+":"+m_strDetail);
}
void KInfoListItem::setIcon(QString &m_strIcon)
{
QPixmap pixmap;
if (!m_strIcon.isEmpty()) {
QIcon icon;
if (m_strIcon.contains("/")) {
QFileInfo fileInfo(m_strIcon);
if (fileInfo.exists()) {
icon = QIcon(m_strIcon);
}
} else {
icon = QIcon::fromTheme(m_strIcon);
if (m_strThemeName == "ukui-dark" || m_strThemeName == "ukui-black") {
pixmap = ImageUtil::drawSymbolicColoredPixmap(icon.pixmap(16,16),"white");
} else { // "ukui-default" "ukui-white" "ukui-light" "ukui"
pixmap = ImageUtil::drawSymbolicColoredPixmap(icon.pixmap(16,16),"black");
}
}
}
if (!pixmap.isNull()) {
m_labelIcon->setPixmap(pixmap);
m_labelIcon->show();
} else {
m_labelIcon->hide();
}
}

View File

@ -50,6 +50,7 @@ protected:
private:
void initStyleTheme();
void setIcon(QString &m_strIcon);
private:
QHBoxLayout *m_mainLayout = nullptr;
@ -61,6 +62,7 @@ private:
QString m_strTitle;
QString m_strIcon;
QString m_strDetail;
QString m_strThemeName = "";
bool m_isOdd = false;
QGSettings *m_styleSettings = nullptr;

View File

@ -35,10 +35,23 @@ void LoadingWidget::initUI()
m_vLayout->setContentsMargins(0,0,0,0);
m_vLayout->setSpacing(0);
if(QGSettings::isSchemaInstalled("org.ukui.style")){
settings = new QGSettings("org.ukui.style");
connect(settings,&QGSettings::changed,this,&LoadingWidget::slot_SettingsChange);
}
m_labelLoadIcon = new QLabel();
QPixmap pixmap;
pixmap.load(":/imgres/img_res/ukui-occupation-map.svg");
pixmap.scaled(290,262);
QString key = settings->get("styleName").toString();
if("" != key){
if(key == "ukui-black" || key == "ukui-dark"){
pixmap.load(":/imgres/img_res/ukui-occupation-map-dark.png");
}else{
pixmap.load(":/imgres/img_res/ukui-occupation-map.png");
}
}
pixmap = pixmap.scaled(128,128,Qt::KeepAspectRatio);
m_labelLoadIcon->setPixmap(pixmap);
m_labelLoadText = new QLabel();
@ -53,3 +66,20 @@ void LoadingWidget::initUI()
m_hLayout->addLayout(m_vLayout);
this->setLayout(m_hLayout);
}
void LoadingWidget::slot_SettingsChange(const QString &key)
{
if(key == "styleName"){
if(settings->get("styleName").toString() == "ukui-black" || settings->get("styleName").toString() == "ukui-dark"){
QPixmap pixmap;
pixmap.load(":/imgres/img_res/ukui-occupation-map-dark.png");
pixmap = pixmap.scaled(128,128,Qt::KeepAspectRatio);
m_labelLoadIcon->setPixmap(pixmap);
}else{
QPixmap pixmap;
pixmap.load(":/imgres/img_res/ukui-occupation-map.png");
pixmap = pixmap.scaled(128,128,Qt::KeepAspectRatio);
m_labelLoadIcon->setPixmap(pixmap);
}
}
}

View File

@ -25,6 +25,8 @@
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGSettings/QGSettings>
#include <QVariant>
class LoadingWidget : public QWidget
{
@ -39,6 +41,10 @@ private:
QHBoxLayout *m_hLayout = nullptr;
QLabel *m_labelLoadIcon = nullptr;
QLabel *m_labelLoadText = nullptr;
QGSettings *settings;
private slots:
void slot_SettingsChange(const QString &key);
};
#endif // LOADINGWIDGET_H

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 178 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 179 KiB

View File

Before

Width:  |  Height:  |  Size: 63 KiB

After

Width:  |  Height:  |  Size: 63 KiB

View File

Before

Width:  |  Height:  |  Size: 70 KiB

After

Width:  |  Height:  |  Size: 70 KiB

View File

Before

Width:  |  Height:  |  Size: 71 KiB

After

Width:  |  Height:  |  Size: 71 KiB

View File

@ -0,0 +1,24 @@
# Toolkit
The toolkit provides the functions of machine information, hardware parameters, hardware monitoring and drive management.
<br>
## Complete machine information
The whole machine information interface can view the basic information and hardware information of the machine, including processor, motherboard, hard disk, network card, video card, sound card, etc.
![Figure 1 Complete machine information](image/1.png)
<br>
## Hardware parameters
The hardware parameter interface allows you to view the details of the processor, memory, video card, motherboard, network card, hard disk, display, sound card, keyboard, mouse, optical drive, and Bluetooth.
![Figure 2 Hardware Parameters](image/2.png)
<br>
## Hardware monitoring
In the hardware monitoring interface, the device detection interface can view the hardware device temperature and utilization rate in real time.
![Figure 3 Hardware Monitoring](image/3.png)
<br>
## Drive management
Drive management can view various driver information in the computer for later driver update.
![Figure 4 Drive management](image/4.png)
<br>

View File

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

View File

Before

Width:  |  Height:  |  Size: 46 KiB

After

Width:  |  Height:  |  Size: 46 KiB

View File

Before

Width:  |  Height:  |  Size: 55 KiB

After

Width:  |  Height:  |  Size: 55 KiB

View File

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

View File

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 47 KiB

View File

@ -0,0 +1,32 @@
# 工具箱
工具箱提供了整机信息,硬件参数,硬件监测、驱动管理的功能。
<br>
## 整机信息
整机信息界面可查看本机基本信息和本机硬件信息,包括处理器、主板、硬盘、网卡、显卡、声卡等。
![图 1 整机信息-big](image/1.png)
<br>
## 硬件参数
硬件参数界面可查看本机处理器、内存、显卡、主板、网卡、硬盘、显示器、声卡、键盘、鼠标、光驱、蓝牙的详细信息。
![图 2 硬件参数-big](image/2.png)
<br>
## 硬件监测
硬件监测界面中,设备检测界面可实时查看硬件设备温度和使用率
![图 3 硬件监测-big](image/3.png)
<br>
## 驱动管理
驱动管理可查看计算机中的各个驱动信息,便于后期更新驱动程序。
![图 4 驱动管理-big](image/4.png)
<br>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 68 KiB

View File

@ -1,50 +0,0 @@
# ToolKit
## Overview
ToolKit provides some extended functions and users can query the hardware details of the current computer. The main interface as shown in Fig 1.
![Fig 1 ToolKit-big](image/1.png)
<br>
## MachineInformation
As shown in Figure 2, the general information of the whole machine is displayed.
![Fig 2 Machine Information-big](image/1.png)
<br>
## HardwareParameters
1 Processor: displays details of the computer's processor.
![Fig 3 Processor-big](image/2.png)
2Memory: displays details of the computer's memory.
![Fig 4 Memory-big](image/3.png)
3Click other items to switch to the hardware details tab.
![Fig 5 MotherBoard-big](image/4.png)
<br>
## HardwareMonitoring
1Equipment monitoring, users can view the temperature and utilization of hardware equipment.
![Fig 6 Device Monitor-big](image/5.png)
2CPU frequency modulation, user can set CPU management policy.
(Note: CPU management policies may be different under different machines, the following content is for reference only)
![Fig 7 CPU FM-big](image/6.png)
<br>
## DriveManager
The interface is shown in Figure 9, which displays each driver information in the computer.
![Fig 9 Drive Manager-big](image/8.png)
<br>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 51 KiB

View File

@ -1,52 +0,0 @@
# 工具箱
## 概 述
工具箱提供了整机信息硬件参数硬件监测等功能。主界面如图1所示。
![图 1 工具箱-big](image/1.png)
<br>
## 整机信息
如图2所示展示整机的概要信息。
![图 2 整机信息-big](image/1.png)
<br>
## 硬件参数
1处理器显示计算机处理器的详细信息。
![图 3 处理器-big](image/2.png)
2内存显示计算机内存的详细信息。
![图 4 内存-big](image/3.png)
3点击其他项目切换到该硬件的详细信息标签页。
![图 5 主板-big](image/4.png)
<br>
## 硬件监测
1设备监测用户可查看硬件设备温度和使用率。
![图 6 设备监测-big](image/5.png)
2CPU调频用户可设置CPU管理策略。
注意不同机器下CPU管理策略可能有差异以下内容仅供参考
![图 7 CPU调频-big](image/6.png)
自定义模式如图8所示。
![图 8 自定义模式](image/7.png)
<br>
## 驱动管理
界面如图9所示显示了计算机中的各个驱动信息。
![图 9 驱动管理-big](image/8.png)
<br>

View File

@ -1135,3 +1135,83 @@ bool DataWorker::exitSessionDaemonDbus()
}
return false;
}
void DataWorker::disableBluetooth()
{
initDbusInterface(&m_dbusHardwareInfo, DBUSPATH_HARDWAREINFO);
if (m_dbusHardwareInfo && m_dbusHardwareInfo->isValid()) {
QDBusPendingCall asyncCall = m_dbusHardwareInfo->asyncCall("disableBluetooth");
if (!asyncCall.isError()) {
getBluetoothInfo();
}
} else {
qWarning()<<"call hardwareinfo dbus failed!!";
}
}
void DataWorker::enableBluetooth()
{
initDbusInterface(&m_dbusHardwareInfo, DBUSPATH_HARDWAREINFO);
if (m_dbusHardwareInfo && m_dbusHardwareInfo->isValid()) {
QDBusPendingCall asyncCall = m_dbusHardwareInfo->asyncCall("enableBluetooth");
if (!asyncCall.isError()) {
getBluetoothInfo();
}
} else {
qWarning()<<"call hardwareinfo dbus failed!!";
}
}
void DataWorker::disableSoundCard(QString strProduct,QString sysPciPath)
{
QString productAndPci = strProduct+"|"+sysPciPath;
initDbusInterface(&m_dbusHardwareInfo, DBUSPATH_HARDWAREINFO);
if (m_dbusHardwareInfo && m_dbusHardwareInfo->isValid()) {
QDBusReply<QString> reply = m_dbusHardwareInfo->call("disableAudioAdaptor",productAndPci);
if (reply.isValid()) {
qWarning()<<"call disableSoundCard dbus failed!!";
}
} else {
qWarning()<<"call hardwareinfo dbus failed!!";
}
}
void DataWorker::enableSoundCard(QString productAndPci)
{
initDbusInterface(&m_dbusHardwareInfo, DBUSPATH_HARDWAREINFO);
if (m_dbusHardwareInfo && m_dbusHardwareInfo->isValid()) {
QDBusReply<QString> reply = m_dbusHardwareInfo->call("enableAudioAdaptor",productAndPci);
if (reply.isValid()) {
qWarning()<<"call enableSoundCard dbus failed!!";
}
} else {
qWarning()<<"call hardwareinfo dbus failed!!";
}
}
void DataWorker::enableNetCard(QString productAndPci)
{
initDbusInterface(&m_dbusHardwareInfo, DBUSPATH_HARDWAREINFO);
if (m_dbusHardwareInfo && m_dbusHardwareInfo->isValid()) {
QDBusReply<QString> reply = m_dbusHardwareInfo->call("enableNetworkAdaptor",productAndPci);
if (reply.isValid()) {
qWarning()<<"call enableNetworkAdaptor dbus failed!!";
}
} else {
qWarning()<<"call hardwareinfo dbus failed!!";
}
}
void DataWorker::disableNetCard(QString strProduct,QString sysPciPath)
{
QString productAndPci = strProduct+"|"+sysPciPath;
initDbusInterface(&m_dbusHardwareInfo, DBUSPATH_HARDWAREINFO);
if (m_dbusHardwareInfo && m_dbusHardwareInfo->isValid()) {
QDBusReply<QString> reply = m_dbusHardwareInfo->call("disableNetworkAdaptor",productAndPci);
if (reply.isValid()) {
qWarning()<<"call disableNetworkAdaptor dbus failed!!";
}
} else {
qWarning()<<"call hardwareinfo dbus failed!!";
}
}

View File

@ -63,6 +63,13 @@ public:
bool exitSystemDaemonDbus(); //退出dbus
bool exitSessionDaemonDbus(); //退出sessiondbus
void disableBluetooth();
void enableBluetooth();
void disableSoundCard(QString strProduct,QString sysPciPath);
void enableSoundCard(QString productAndPci);
void disableNetCard(QString strProduct,QString sysPciPath);
void enableNetCard(QString productAndPci);
public slots:
// 异步获取接口
void getCpuFMInfo();

2
debian/control vendored
View File

@ -27,6 +27,8 @@ Build-Depends: debhelper (>= 9),
libkf5screen-dev,
libkf5screen-bin,
libkysdk-waylandhelper-dev,
libkysdk-qtwidgets-dev (>= 1.0.0kylin12+0422),
libkysdk-utils-dev (>= 1.2.0.5),
Standards-Version: 4.5.0
Rules-Requires-Root: no
Homepage: https://github.com/ubuntukylin/youker-assistant

2
debian/install vendored
View File

@ -1,3 +1,3 @@
data/toolkit/ /usr/share/kylin-user-guide/data/guide/
man/*.1 /usr/share/man/man1/
src/translation/*.qm /usr/share/youker-assistant/translations/
data/kylin-assistant/ /usr/share/kylin-user-guide/data/guide/

View File

@ -1,2 +1,2 @@
man/kylin-assistant-systemdaemon.1
man/kylin-assistant.1
man/kylin-assistant-systemdaemon.1

13
debian/kylin-assistant.postinst vendored Normal file
View File

@ -0,0 +1,13 @@
#!/bin/sh
set -e
#判断命令是否存在
if [ -x /usr/share/kylin-system-updater/kylin-reboot-required ]; then
#执行请求重启提示
/usr/share/kylin-system-updater/kylin-reboot-required
fi

1
debian/source/options vendored Normal file
View File

@ -0,0 +1 @@
include-binaries

View File

@ -28,6 +28,7 @@ import re
import json
import subprocess
import time
from pprint import pprint
@ -67,7 +68,7 @@ class AudioAdaptor():
def getAudioAdaptorInfo(self):
summary = {"list":[]}
index = 0
self.cmdTool.loadInfoFromLshw(False)
self.cmdTool.loadInfoFromLshw(True)
audioAdaptorList = self.cmdTool.lshwMultimediaList
adaptorList = self.cmdTool.loadInfoFromHwinfo("--sound")["list"]
length = len(audioAdaptorList)
@ -212,10 +213,11 @@ class AudioAdaptor():
if len(words) == 2 :
keyWord = words[0].strip()
valWord = words[1].strip()
if keyWord == "Status" :
result = re.findall("[\s]*([0-9]+MHz)-.*", valWord)
if result and len(result) > 0 :
pciStatusClock = result[0]
# 采用lshw 里面的声卡时钟频率不采用pci里面的
# if keyWord == "Status" :
# result = re.findall("[\s]*([0-9]+MHz)-.*", valWord)
# if result and len(result) > 0 :
# pciStatusClock = result[0]
if len(pciStatusClock) > 0 :
summary["list"][index][AudioAdaptor_Clock] = pciStatusClock
@ -272,9 +274,59 @@ class AudioAdaptor():
# pci bus devices have been parsed
# other bus device is unsupported
pass
# 添加集成声卡信息集成方案
# 非990/9A0机型采用此方案
if not Judgment_HW990() and not Judgment_HW9A0() and not Judgment_PANGUW():
sound_card_paths = glob.glob('/sys/class/sound/card*')
for sound_card_path in sound_card_paths:
card_num = sound_card_path.split('/')[-1][4:]
uevent_path = sound_card_path + '/device/uevent'
if os.path.exists(uevent_path):
#飞腾集成声卡无pci信息通过uevent进行筛选
with open(uevent_path, 'r', encoding="utf-8") as f:
lines = f.readlines()
if 'PCI_ID' in "".join(lines):
continue
else:
driver = ''
vendor = ''
model = ''
for line in lines:
if line.startswith('DRIVER='):
driver = line.strip().split('=', 1)[-1]
vendor, model = self.cmdTool.getSoundVendorProduct(card_num)
if ''!=vendor and ''!=model and ''!=driver:
summary["list"].append({
AudioAdaptor_Driver:driver,
AudioAdaptor_Manufacturer:vendor,
AudioAdaptor_Model:model})
# ## 添加集成声卡信息集成方案
# pacmdSoundList = self.cmdTool.loadSoundInfoFromPacmd(False);
# for mapInfo in pacmdSoundList :
# if len(mapInfo) > 0 :
# if "sound_busaddr" in mapInfo:
# # 判断当前信息是否已经放入声卡信息中
# if mapInfo["sound_busaddr"].replace("-","@") in [mapInfo[AudioAdaptor_Businfo] for mapInfo in summary["list"]]:
# continue;
# else:
# soundDict = {};
# if "sound_vendor" in mapInfo:
# soundDict[AudioAdaptor_Manufacturer] = mapInfo["sound_vendor"];
# if "sound_driver" in mapInfo:
# soundDict[AudioAdaptor_Driver] = mapInfo["sound_driver"];
# if "sound_busaddr" in mapInfo:
# soundDict[AudioAdaptor_Businfo] = mapInfo["sound_busaddr"];
# if "sound_name" in mapInfo:
# soundDict[AudioAdaptor_Product] = mapInfo["sound_name"];
# if "sound_model" in mapInfo:
# soundDict[AudioAdaptor_Manufacturer] = mapInfo["sound_model"];
# if len(soundDict) > 0:
# summary["list"].append(soundDict);
if len(summary["list"]) == 0 :
return ""
return json.dumps(summary)
return json.dumps(summary)
@ -301,6 +353,85 @@ class AudioAdaptor():
nIndex = nIndex + 1
return outLine
#禁用声卡设备
def disableSoundCard(self,strProductAndPath) :
print(strProductAndPath)
# try:
if("|" in strProductAndPath):
strProduct,pciPath = strProductAndPath.split("|")
sysPciPath = "/sys/devices/pci0000:00/"
if not os.path.exists(sysPciPath+pciPath+"/remove") :
return False
youkerConfigDir = "/etc/youker-assistant"
if os.path.exists(youkerConfigDir):
pass
else:
os.mkdir(youkerConfigDir)
#写文件
if not os.path.exists(youkerConfigDir+"/"+"soundCard"):
os.popen('touch %s'%(youkerConfigDir+"/"+"soundCard"))
os.popen('echo "%s|%s" >> %s'%(strProduct,pciPath,youkerConfigDir+"/"+"soundCard"))
print('echo "%s|%s" >> %s'%(strProduct,pciPath,youkerConfigDir+"/"+"soundCard"))
#保存设备名称和pci写到文件中 设备名称+pci地址 而且要做区分
os.popen('echo 1 > %s'%(sysPciPath+pciPath+"/remove"))
# except Exception as e:
# print(e)
return True
#启用声卡设备
def enableSoundCard(self, productAndPci) :
configFile = "/etc/youker-assistant/soundCard"
youkerConfigDir = "/etc/youker-assistant"
sysPciRescanPath = "/sys/bus/pci/rescan"
if not os.path.exists(sysPciRescanPath) or not os.path.exists(configFile) :
return False
# 去除禁用信息
allData = []
with open(configFile,'r')as fd:
print(fd.readlines)
#with open(configFile,'r') as fd:
file = open(configFile,'r')
allInfo = file.readlines()
for info in allInfo:
#info = fd.readline()
if '' != info:
if productAndPci in info:
pass
else:
allData.append(info)
fw = open(configFile, 'w')
fw.writelines(allData)
fw.close()
# os.popen('sed -i "s/%s//g" %s'%(productAndPci,configFile))
# os.popen('echo 1 > %s'%(sysPciRescanPath))
subprocess.Popen("echo 1 > %s"%(sysPciRescanPath), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# 扫描当前所有需要禁用的设备
disableList = ["netCard","soundCard"]
commands = []
for item in disableList:
if os.path.exists(youkerConfigDir + "/" + item):
with open(youkerConfigDir + "/" + item, "r" ,encoding="utf-8") as file:
allLines = file.readlines()
for line in set(allLines):
line = line.strip()
if "|" in line :
strProduct,pciPath = line.strip().split("|")
sysPciPath = "/sys/devices/pci0000:00/"
count = 0
while True and count < 30 :
if os.path.exists(sysPciPath+pciPath.strip()+"/remove"):
break
time.sleep(1)
count += 1
if not os.path.exists(sysPciPath+pciPath.strip()+"/remove") :
return False
commands.append("echo 1 > %s"%(sysPciPath+pciPath.strip()+"/remove"))
# subprocess.Popen("echo 1 > %s"%(sysPciPath+pciPath.strip()+"/remove"), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# os.popen('echo 1 > %s'%(sysPciPath+pciPath.strip()+"/remove"))
# 遍历命令列表,并逐一执行
for cmd in commands: subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
return True
if __name__ == "__main__":
cmdTool = KACmdTool()
cmdTool.loadInfoFromLshw()

View File

@ -138,9 +138,9 @@ class KABatteryInfo():
batOne[BTI_MODEL] = batModel
if len(batOne) > 0 and batSupply :
if len(sysProductName) > 0 :
if "TN140A2" in sysProductName : ##长城笔记本
batOne[BTI_MANUFACTURER] = "飞毛腿(福建)电子有限公司"
batOne[BTI_MODEL] = "SNGW001"
if "TN140A2" in sysProductName or "TN133A2" in sysProductName : ##长城笔记本
# batOne[BTI_MANUFACTURER] = "飞毛腿(福建)电子有限公司"
# batOne[BTI_MODEL] = "SNGW001"
batOne[BTI_ENERGY] = ""
batOne[BTI_ENERGYFULL] = "60Wh"
elif "F860-T1" in sysProductName : ##清华同方笔记本

View File

@ -45,6 +45,7 @@ class KABluetoothInfo():
baseList = self.cmdTool.loadInfoFromHciconfig()
hwinfoList = self.cmdTool.loadInfoFromHwinfo("--usb")["list"]
bThwinfoList = self.cmdTool.loadInfoFromHwinfo("--bluetooth")["list"]
length = len(baseList)
for i in range(length) :
if len(baseList[i]) == 0 :
@ -125,6 +126,9 @@ class KABluetoothInfo():
##型号
if "Model" in mapInfo :
summary["list"][index][BLI_DEVMODEL] = mapInfo["Model"].strip("\"")
#优化获取方案 hwinfo --bluetooth获取
elif index < len(bThwinfoList) and "Model" in bThwinfoList[index]:
summary["list"][index][BLI_DEVMODEL] = bThwinfoList[index]["Model"].strip("\"")
##驱动
if "Driver" in mapInfo :
@ -204,6 +208,34 @@ class KABluetoothInfo():
outLine += " / " + info[BLI_DEVMODEL]
nIndex = nIndex + 1
return outLine
#禁用蓝牙驱动
def disableBluetoothDriver(self) :
blacklistPath = "/etc/modprobe.d/blacklist.conf"
if not os.path.exists(blacklistPath) :
return False
os.popen('modprobe -r btusb')
os.popen('modprobe -r rtk_btusb')
# 将驱动写入黑名单 - 追加方式
# /etc/modprobe.d/blacklist.conf
# blacklist rtk_btusb
os.popen('echo "blacklist rtk_btusb" >> %s'%(blacklistPath))
os.popen('echo "blacklist btusb" >> %s'%(blacklistPath))
return True
#启用蓝牙驱动
def enableBluetoothDriver(self) :
blacklistPath = "/etc/modprobe.d/blacklist.conf"
if not os.path.exists(blacklistPath) :
return False
os.popen('modprobe btusb')
os.popen('modprobe rtk_btusb')
# sed -i "s/alidata/data/g" test.txt
os.popen('sed -i "s/blacklist rtk_btusb//g" %s'%(blacklistPath))
os.popen('sed -i "s/blacklist btusb//g" %s'%(blacklistPath))
os.popen('sed "/^$/d" %s'%(blacklistPath))
return True
if __name__ == "__main__":
cmdtool = KACmdTool()

View File

@ -80,6 +80,77 @@ class KACmdTool():
if add :
summary["list"].append(mapInfo)
def loadHwinfoUsbMouseinfo(self, param):
summary = {"list":[]}
args = ["hwinfo", param]
pipe = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = pipe.stdout.readlines()
allinfo = ""
for l in output:
result = bytes.decode(l, "utf-8", "ignore")
if result :
allinfo += result
infoList = allinfo.split("\n\n")
for info in infoList:
if len(info) != 0 :
mapInfo = {}
infoLines = info.split("\n")
for line in infoLines:
words = line.split(": ")
if len(words) != 2 :
continue
keyInfo = words[0].strip()
if keyInfo in mapInfo:
mapInfo[keyInfo] += " "
result = re.findall(".*\"(.*)\".*", words[1])
if result and len(result) > 0 :
key = keyInfo
value = result[0]
##这里是为了防止 "usb-storage", "sr" -》 usb-storage", "sr
if key == "Driver" :
value = value.replace("\"", "");
if key in mapInfo :
mapInfo[key] += value;
else :
mapInfo[key] = value;
else :
if keyInfo == "Resolution" and keyInfo in mapInfo :
mapInfo[keyInfo] += words[1].strip();
else :
mapInfo[keyInfo] = words[1].strip();
if "Vendor" == keyInfo :
result = re.findall("usb 0x([0-9]*)", words[1])
if result and len(result) > 0 :
mapInfo["usb_vendor"] = result[0]
elif "Device" == keyInfo :
result = re.findall("usb 0x([0-9]*)", words[1])
if result and len(result) > 0 :
mapInfo["usb_device"] = result[0]
if "--usb" == param :
add = False
for item in summary:
if "SysFS BusID" in item:
curBus = item["SysFS BusID"]
newBus = mapInfo["SysFS BusID"]
curBus = re.sub("\\.[0-9]{1,2}$", "", curBus)
newBus = re.sub("\\.[0-9]{1,2}$", "", newBus)
if curBus == newBus :
add = False
break
## 鼠标信息
if "mouse".lower() in info.lower() :
add = True
if add :
summary["list"].append(mapInfo)
return summary
def loadInfoFromHwinfo(self, param):
summary = {"list":[]}
@ -389,6 +460,27 @@ class KACmdTool():
self.getInfoFromLshw(item, mapInfo)
self.lshwCDRomList.append(mapInfo)
elif item.startswith("virtio") :
#从hwinfo里面获取
args = ["hwinfo","--network"]
pipe = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = pipe.stdout.readlines()
busLink = ""
for l in output:
line = bytes.decode(l.strip(),"utf-8","ignore")
if line.find("SysFS Device Link") >= 0:
if ":" in line:
busLink = line.split("/")[-1]
netBusLink = ''
for netItem in self.lshwNetworkList:
if 'bus info' in netItem:
netBusLink = netItem['bus info'].replace('pci@','')
if netBusLink in netItem['bus info']:
result = re.findall("logical name: (\S+)", item)
if result and len(result) > 0 and '/dev/' not in result:
netItem['logical name'] = result[0]
break
def loadNetworkInfoFromIfconfig(self):
args = ["ifconfig"]
pipe = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@ -476,6 +568,8 @@ class KACmdTool():
words = pair.strip().split(": ")
if len(words) == 2 :
mapInfo[words[0].strip()] = words[1].strip()
# 增加默认蓝牙驱动 btusb 已确认蓝牙内嵌外接都为usb方式
mapInfo["driver"] = "btusb";
self.loadBluetoothInfo(mapInfo)
if len(mapInfo) > 0 :
infoList.append(mapInfo)
@ -750,6 +844,21 @@ class KACmdTool():
product = retProduct[0]
return vendor,product
def getSoundVendorProduct(self, cardNum) :
vendor,model = '',''
if not os.path.exists("/proc/asound/card"+str(cardNum)+"/codec#0") :
return vendor,model
cmd = ["cat","/proc/asound/card"+str(cardNum)+"/codec#0","|","grep","Codec"]
# Codec: Realtek ALC257
# Codec: Intel Kabylake HDMI
fp = os.popen(" ".join(cmd))
msg = fp.read()
if ":" in msg:
tmp = msg.strip().split(':', 1)[-1].strip()
if " " in tmp:
vendor,model = tmp.split(' ', 1)
return vendor,model
if __name__ == "__main__":
cc = KACmdTool()

View File

@ -153,6 +153,18 @@ class KACpuFM(dbus.service.Object):
origin = {Cpufm_Average_Corefreq:""}
if(not os.path.exists("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq")):
# 存在机型没有开启动态调频默认为cpu频率方案移植
if(Judgment_3A5000() or Judgment_SW()):
args = ["cat /proc/cpuinfo | grep -i 'cpu MHz'"]
pipe = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE , shell=True)
output = pipe.stdout.readlines()
cpuFreq = ""
if len(output) != 0:
cpuFreq = bytes.decode(output[0],"utf-8","ignore")
if "cpu mhz" in cpuFreq.lower():
cpuFreq = cpuFreq.split(":")[-1].strip()
origin[Cpufm_Average_Corefreq] = self.num_convert(str(int(float(cpuFreq)*1000)));
return origin
v = 0

View File

@ -95,10 +95,9 @@ class KADevMonitor(dbus.service.Object):
return strJson
def chkCpuUsageTimer(self):
cmd = "cat " + CPUSTAT_FILE
fp = os.popen(cmd)
msg = fp.read()
fp.close()
msg = ""
with open ("/proc/stat" , "r" ) as f:
msg = "".join(f.readlines())
result = re.findall('cpu\s*(\S+)\s*(\S+)\s*(\S+)\s*(\S+)\s*(\S+)\s*(\S+)\s*(\S+)\s*(\S+)\s*(\S+)\s*(\S+)', msg);
self.preTotalTime = self.totalTime
self.preWorkTime = self.workTime

View File

@ -60,9 +60,13 @@ class KAGraphicsCardInfo() :
wayland_sock = glob.glob('/run/user/*/wayland-0')[0]
xdg_runtime_dir = wayland_sock[:-10] # /run/user/1000
gpuinfo_env = {'XDG_RUNTIME_DIR' : xdg_runtime_dir}
process = subprocess.run('gpuinfo', env=gpuinfo_env, capture_output=True)
output = process.stdout.decode()
ret = process.returncode
# 判断是否有gpuinfo命令
try:
process = subprocess.run('gpuinfo', env=gpuinfo_env, capture_output=True)
output = process.stdout.decode()
ret = process.returncode
except:
ret = 0
if ret == 1: ## ???
lines = output.strip().split('\n')
for line in lines:
@ -147,7 +151,7 @@ class KAGraphicsCardInfo() :
# JJW显卡的特殊处理
tmpVendor = mapInfo["vendor"]
if tmpVendor.find("JJM") != -1:
if str(tmpVendor).lower().find("jingjia") != -1:
isJJM = True
tmpResult = get_interface(subsystem_id, subsystem_id_re)
summary["list"][index][GSI_NAME] = tmpResult.strip()
@ -226,47 +230,60 @@ class KAGraphicsCardInfo() :
if (GSI_NAME in summary["list"][index] and "X100" in summary["list"][index][GSI_NAME]) or \
(GSI_MANUFACTURER in summary["list"][index] and "X100" in summary["list"][index][GSI_MANUFACTURER]): ## X100
args3 = ["lspci", "-n"]
pipe3 = subprocess.Popen(args3, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output3 = pipe3.stdout.readlines()
totalMem = 0
for line in [ bytes.decode(l.strip(),"utf-8","ignore") for l in output3]:
if "1db7:dc20" not in line and "1db7:dc21" not in line and "1db7:dc22" not in line :
continue
infoItems = line.split(" ")
if len(infoItems) != 3 :
continue
args4 = ["lspci", "-vs"]
args4.append(infoItems[0].strip())
pipe4 = subprocess.Popen(args4, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output4 = pipe4.stdout.readlines()
singleMem = 0
for line1 in [ bytes.decode(l.strip(),"utf-8","ignore") for l in output4]:
if "Memory" not in line1:
continue
results = [ v.strip().strip("\)") for v in line1.split() ]
if "prefetchable" in results :
## Memory at a0000000 (64-bit, prefetchable) [size=256M]
for session in results :
if "size" not in session :
continue
strMem = session.strip("[").strip("]").split("=")
if len(strMem) == 2 :
sizeN = re.findall("([0-9]+)M.*",strMem[1])
if sizeN and len(sizeN) > 0 and sizeN[0].isdigit() :
if int(sizeN[0]) > singleMem :
singleMem = int(sizeN[0])
sizeN = re.findall("([0-9]+)G.*",strMem[1])
if sizeN and len(sizeN) > 0 and sizeN[0].isdigit() :
if int(sizeN[0])*1024 > singleMem :
singleMem = int(sizeN[0])*1024
totalMem += singleMem
if totalMem > 0 :
if os.path.exists("/sys/kernel/debug/pvr/physical_vram_size"):
args3 = ["cat", "/sys/kernel/debug/pvr/physical_vram_size"]
pipe3 = subprocess.Popen(args3, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output3 = pipe3.stdout.readlines()
totalMem = 0
for line in [ bytes.decode(l.strip(),"utf-8","ignore") for l in output3]:
if line.strip().isdigit():
totalMem = int(line)
if totalMem > 0 :
# 单位为字节 转换成 MB
totalMem /= 1024*1024
if totalMem > 1024 :
summary["list"][index][GSI_CAPCITY] = str(float("%0.1f"%(float(totalMem)/1024)))+"GB"
else :
summary["list"][index][GSI_CAPCITY] = str(totalMem)+"MB"
else:
totalMem = 0
for line in [ bytes.decode(l.strip(),"utf-8","ignore") for l in output3]:
if "1db7:dc20" not in line and "1db7:dc21" not in line and "1db7:dc22" not in line :
continue
infoItems = line.split(" ")
if len(infoItems) != 3 :
continue
args4 = ["lspci", "-vs"]
args4.append(infoItems[0].strip())
pipe4 = subprocess.Popen(args4, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output4 = pipe4.stdout.readlines()
singleMem = 0
for line1 in [ bytes.decode(l.strip(),"utf-8","ignore") for l in output4]:
if "Memory" not in line1:
continue
results = [ v.strip().strip("\)") for v in line1.split() ]
if "prefetchable" in results :
## Memory at a0000000 (64-bit, prefetchable) [size=256M]
for session in results :
if "size" not in session :
continue
strMem = session.strip("[").strip("]").split("=")
if len(strMem) == 2 :
sizeN = re.findall("([0-9]+)M.*",strMem[1])
if sizeN and len(sizeN) > 0 and sizeN[0].isdigit() :
if int(sizeN[0]) > singleMem :
singleMem = int(sizeN[0])
sizeN = re.findall("([0-9]+)G.*",strMem[1])
if sizeN and len(sizeN) > 0 and sizeN[0].isdigit() :
if int(sizeN[0])*1024 > singleMem :
singleMem = int(sizeN[0])*1024
totalMem += singleMem
if totalMem > 0 :
if totalMem > 1024 :
summary["list"][index][GSI_CAPCITY] = str(float("%0.1f"%(float(totalMem)/1024)))+"GB"
else :
summary["list"][index][GSI_CAPCITY] = str(totalMem)+"MB"
if GSI_CAPCITY not in summary["list"][index] :
if "size" in mapInfo and len(mapInfo["size"]) > 0:
@ -325,10 +342,11 @@ class KAGraphicsCardInfo() :
valWord = words[1].strip()
if keyWord == "Subsystem" :
subSystemInfo = valWord
elif keyWord == "Status" :
result = re.findall("[\s]*([0-9]+MHz)-.*", valWord)
if result and len(result) > 0 :
pciStatusClock = result[0]
# 采用lshw 里面的显卡时钟频率不采用pci里面的
# elif keyWord == "Status" :
# result = re.findall("[\s]*([0-9]+MHz)-.*", valWord)
# if result and len(result) > 0 :
# pciStatusClock = result[0]
if len(subSystemInfo) > 0 :
summary["list"][index][GSI_SUBSYSTEM] = subSystemInfo
if len(pciStatusClock) > 0 :
@ -341,6 +359,12 @@ class KAGraphicsCardInfo() :
if GSI_MANUFACTURER in summary["list"][index] and \
summary["list"][index][GSI_MANUFACTURER] != summary["list"][index][GSI_NAME] :
summary["list"][index][GSI_MODEL] = summary["list"][index][GSI_NAME]
if "vendor" in mapInfo:
# subsytem 放到 product里面Jingjia Microelectronics Co Ltd JM7201--- 根据制造商裁剪型号,作为设备名称和型号
if get_url(mapInfo["vendor"],mapInfo["vendor"]).find("jingjia") != -1:
tmpName = summary["list"][index][GSI_SUBSYSTEM].split(summary["list"][index][GSI_MANUFACTURER])[-1].strip();
summary["list"][index][GSI_NAME] = tmpName;
summary["list"][index][GSI_MODEL] = tmpName;
else :
if GSI_NAME in summary["list"][index] :
summary["list"][index][GSI_MODEL] = summary["list"][index][GSI_NAME]

View File

@ -154,12 +154,13 @@ class KAHarddiskInfo() :
and mapInfo["dev_name"] in diskList["list"][i]["Device File"] :
diskList["list"][i].update(mapInfo)
flag = Judgment_HW990()
flag9A0 = Judgment_HW9A0()
# 判断是否为联想定制
customedType = Judgment_LENOVO()
for diskInfo in diskList["list"] :
disk = {}
DiskProduct,DiskVendor,DiskCapacity,DiskName,DiskFw,DiskSerial,DiskRota,DiskInterface = '','','','','','','',''
DiskProduct,DiskVendor,DiskCapacity,DiskName,DiskFw,DiskSerial,DiskRota,DiskInterface,DiskUFS = '','','','','','','','',''
devName = ""
IsRemoveable = False
if "dev_name" in diskInfo :
@ -181,7 +182,8 @@ class KAHarddiskInfo() :
if result and len(result) > 0:
if result[0].isdigit() :
jinzhi = 1000.0
if majorId[0] == "252" :
# 判断是否为虚拟机
if Judgment_Virt():
jinzhi = 1024.0
size = float(result[0])/jinzhi/jinzhi/jinzhi
if size >= jinzhi :
@ -211,6 +213,9 @@ class KAHarddiskInfo() :
DiskCapacity = result[0]
if DiskCapacity.startswith("0") or DiskCapacity == "" :
continue
#优化 sw /dev/ram*设备挂载分区为空
if "" == devName:
continue;
DiskName = ("/dev/" + devName)
IsMainDisk = self.chkIsMainDisk(DiskName)
IsSSD = "0"
@ -304,8 +309,63 @@ class KAHarddiskInfo() :
disk[HDI_ROTA] = DiskRota
if len(DiskInterface) > 0:
disk[HDI_INTERFACE] = DiskInterface
# 联想定制
if(1 == customedType):
# 990/9A0 特殊处理
if (flag or flag9A0) and len(DiskCapacity) > 0 :
def transHumanReadableSize(disSize):
diffMap = {}
destList = [1, 2, 4, 8, 16, 32, 64, 80, 100, 120, 128, 160, 256, 320, 500, 512, 750]
for size in destList:
diffMap[abs(disSize - size)] = destList.index(size)
return destList[diffMap.get(min(diffMap.keys()))]
if DiskCapacity.find(".") < 0 : # 非浮点数值
result = re.findall("([0-9]+)", DiskCapacity)
if result and len(result) > 0 :
originInfo = result[0]
humanReadableSize = transHumanReadableSize(int(originInfo))
disk[HDI_CAPACITY] = DiskCapacity.replace(originInfo, str(humanReadableSize))
# if IsSSD == "1" :
# if flag :
# disk[HDI_UFS] = "UFS 3.0"
# elif flag9A0 :
# disk[HDI_UFS] = "UFS 3.1"
# 当读取cat /sys/devices/platform/f8200000.ufs/host0/scsi_host/host0/wb_en中数值为true
# 且cat /sys/block/sdd/device/spec_version中数值为310时显示UFS 3.1,
if IsSSD == "1" :
if flag9A0:
disk[HDI_UFS] = "UFS 3.1"
# 990
elif flag:
# 非L410为UFS3.0
if not Judgment_L410():
disk[HDI_UFS] = "UFS 3.0"
else:
disk[HDI_UFS] = "UFS 3.0"
ufsPath = "/sys/devices/platform/f8200000.ufs/host0/scsi_host/host0/wb_en"
ufsVersion = "/sys/block/sdd/device/spec_version"
if os.path.exists(ufsPath) and os.path.exists(ufsVersion):
args = ["cat", ufsPath]
pipe = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = pipe.stdout.readlines()
for l in output:
line = bytes.decode(l.strip(),"utf-8","ignore")
if line.find("true") >= 0:
args1 = ["cat", ufsVersion]
pipe1 = subprocess.Popen(args1, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output1 = pipe1.stdout.readlines()
for l in output1:
line = bytes.decode(l.strip(),"utf-8","ignore")
if line.find("310") >= 0:
disk[HDI_UFS] = "UFS 3.1"
else:
disk[HDI_UFS] = "UFS 3.0"
else:
disk[HDI_UFS] = "UFS 3.0"
else:
disk[HDI_UFS] = "UFS 3.0"
# 联想定制 DATANG不走定制
if(1 == customedType and HDI_MANUFACTURER in disk and "DATANG" not in disk[HDI_MANUFACTURER]):
disk[HDI_MODEL] = self.exchangeModel([disk])
disklist.append(disk)
@ -378,4 +438,4 @@ if __name__ == "__main__":
# print(capacityTmp)
# print(capacityTmp[-1].split(" "))
# # capacity = capacityTmp[0].split(".")[0] + ".00"+" TB"
# #print(capacity)
# #print(capacity)

View File

@ -217,6 +217,52 @@ class HardwareInfo(dbus.service.Object):
bluetoothInfo = KABluetoothInfo(self.cmdtool)
return bluetoothInfo.getBluetoothInfo()
# 禁用蓝牙驱动
@dbus.service.method(INTERFACE, in_signature='', out_signature='s', sender_keyword='sender')
def disableBluetooth(self, sender=None):
bluetoothInfo = KABluetoothInfo(self.cmdtool)
bluetoothInfo.disableBluetoothDriver()
return "true"
# 启用蓝牙驱动
@dbus.service.method(INTERFACE, in_signature='', out_signature='s', sender_keyword='sender')
def enableBluetooth(self, sender=None):
bluetoothInfo = KABluetoothInfo(self.cmdtool)
bluetoothInfo.enableBluetoothDriver()
return "true"
# 禁用声卡设备
@dbus.service.method(INTERFACE, in_signature='s', out_signature='s', sender_keyword='sender')
def disableAudioAdaptor(self, strProductAndPath, sender=None):
print(strProductAndPath)
audioAdaptorInfo = AudioAdaptor(self.cmdtool)
audioAdaptorInfo.disableSoundCard(strProductAndPath)
return "true"
# 启用声卡设备
@dbus.service.method(INTERFACE, in_signature='s', out_signature='s', sender_keyword='sender')
def enableAudioAdaptor(self, strProductAndPath, sender=None):
print(strProductAndPath)
audioAdaptorInfo = AudioAdaptor(self.cmdtool)
audioAdaptorInfo.enableSoundCard(strProductAndPath)
return "true"
# 禁用网卡设备
@dbus.service.method(INTERFACE, in_signature='s', out_signature='s', sender_keyword='sender')
def disableNetworkAdaptor(self, strProductAndPath, sender=None):
print(strProductAndPath)
networkAdaptorInfo = NetworkAdaptor(self.cmdtool)
networkAdaptorInfo.disableNetCard(strProductAndPath)
return "true"
# 启用网卡设备
@dbus.service.method(INTERFACE, in_signature='s', out_signature='s', sender_keyword='sender')
def enableNetworkAdaptor(self, strProductAndPath, sender=None):
print(strProductAndPath)
networkAdaptorInfo = NetworkAdaptor(self.cmdtool)
networkAdaptorInfo.enableNetCard(strProductAndPath)
return "true"
#keyboard info
@dbus.service.signal(INTERFACE, signature='us')
def signalKBUpdateInfo(self, status, msg):
@ -244,7 +290,7 @@ class HardwareInfo(dbus.service.Object):
@dbus.service.method(INTERFACE, in_signature='', out_signature='s', sender_keyword='sender')
def readMNInfo(self, sender=None):
monitorInfo = KAMonitor()
monitorInfo = KAMonitor(self.cmdtool)
return monitorInfo.getMonitorsInfo()
#cddrive info
@ -411,6 +457,9 @@ class HardwareInfo(dbus.service.Object):
if os.path.exists(path):
return True
else:
#判断3A500机器 - 动态调频没有的情况下走/proc/cpuinfo
if(Judgment_3A5000() or Judgment_SW()):
return True
return False
@dbus.service.signal(INTERFACE, signature='')

View File

@ -114,6 +114,7 @@ HDI_READSPEED = "read_speed" #磁盘读取速度
HDI_WRITESPEED = "write_speed" #磁盘写入速度
HDI_FIRMWAREVER = "firmware_ver" #固件版本
HDI_ROTA = "rota" #机械转速
HDI_UFS = "disk_ufs" #UFS 版本
###DEV MONITOR
DEVMONITOR_ROOT = "device_monitor" #设备监测

View File

@ -57,8 +57,8 @@ class KAKeyboardInfo():
else :
kbName = mapInfo["Device"]
##AT Raw键盘
if "AT Raw" in kbName:
##蓝牙设备 手机,耳机
if "(AVRCP)" in kbName:
continue;
##panguw键盘
if "lsadc" in kbName:

View File

@ -281,6 +281,14 @@ class KAMachineInfo():
platValue = front
elif os.path.exists("/etc/os-release"):
tmp = tmp1 = ""
# 优先获取version 和 控制面板保持一致
with open("/etc/os-release", "r" ,encoding="utf-8") as fsys:
for line in fsys:
if line.startswith("VERSION"):
tmp = line
if tmp != "":
platValue = tmp.split('=')[1].replace('"', '').replace('\n', '');
return platValue
with open("/etc/os-release", "r") as fsys:
for line in fsys:
if line.startswith("NAME"):
@ -409,7 +417,7 @@ class KAMachineInfo():
summary[MI_HARDDISK] = harddiskInfo.getOutline(customedType)
graphicsCardInfo = KAGraphicsCardInfo(self.cmdTool)
summary[MI_GRAPHICSCARD] = graphicsCardInfo.getOutline(customedType)
monitorInfo = KAMonitor()
monitorInfo = KAMonitor(self.cmdTool)
summary[MI_MONITOR] = monitorInfo.getOutline()
networkInfo = NetworkAdaptor(self.cmdTool)
summary[MI_NETWORKCARD] = networkInfo.getOutline()

View File

@ -38,7 +38,8 @@ from utils import *
class KAMonitor() :
def __init__(self):
def __init__(self, cmdtool):
self.cmdTool = cmdtool
pass
def getMonitorsInfo(self) :
@ -47,13 +48,25 @@ class KAMonitor() :
if os.path.exists("/tmp/youker-assistant-monitorinfo.dat"):
status, xrandrDat = subprocess.getstatusoutput('cat /tmp/youker-assistant-monitorinfo.dat')
value = re.findall("(.*) connected", xrandrDat)
connectList =[]
hwinfoList = self.cmdTool.loadInfoFromHwinfo("--monitor")["list"]
for monitor in value :
p = re.compile(r'%s connected' % monitor)
if Judgment_HW990():
if "eDP-1" == monitor:
continue
p = re.compile(r'\n%s connected' % monitor)
nIndex = 0
for m in p.finditer(xrandrDat):
#去重
connectInterface=m.group()
if connectInterface in connectList:
continue
else:
connectList.append(connectInterface)
monitorOne = {}
mnManufacturer,mnName,mnSize,mnRatio,mnResolution,mnMaxResolution,mnIsMain,mnGamma,mnInterface, \
mnModel,mnVisibleArea,mnYear,mnWeek,mnSerial = "","","","","","","","","","","","","",""
localinfo = xrandrDat.split("%s connected" % monitor)[1].split("connected")[0]
localinfo = xrandrDat.split("\n%s connected" % monitor)[1].split("connected")[0]
mnInterface = monitor
if "primary" in localinfo :
mnIsMain = "1"
@ -64,6 +77,12 @@ class KAMonitor() :
curResolutionWidth = int(curResolution[0][0])
curResolutionHeight = int(curResolution[0][1])
mnResolution = str(curResolutionWidth)+"X"+str(curResolutionHeight)
# 新增分辨率
refreshRate = re.findall('(\d*).(\d*)\*', localinfo)
if refreshRate:
for item in refreshRate :
if item[0].isdigit() and item[1].isdigit():
mnResolution += "@"+item[0]+"."+item[1]+"Hz"
if curResolutionHeight > 0 :
ratio = int(curResolutionWidth*100/curResolutionHeight)
if ratio == 125 : #5:4
@ -82,6 +101,7 @@ class KAMonitor() :
fp.write(edidinfoline)
# 1920x1080 59.93*+
result = re.findall('\s*(\d*)x(\d*)\s\s\s', localinfo)
refreshRateMax = ""
if result:
nMaxRes = 0
for item in result :
@ -89,10 +109,32 @@ class KAMonitor() :
tempRes = int(item[0])*int(item[1])
if tempRes > nMaxRes :
nMaxRes = tempRes
for line in localinfo.split('\n'):
if line.strip().startswith(item[0]+"x"+item[1]):
tmp = line.strip().split(" ")
tmp = [i for i in tmp if i != '']
if(len(tmp) > 1):
refreshRateMax = tmp[1]
mnMaxResolution = (item[0] + "X" + item[1])
if refreshRateMax != "":
if "+" in refreshRateMax:
refreshRateMax = refreshRateMax.replace("+","")
if "*" in refreshRateMax:
refreshRateMax = refreshRateMax.replace("*","")
mnMaxResolution += "@"+refreshRateMax+"Hz"
is323F = Judgment_323F()
if os.path.exists("/tmp/edid.dat"):
status, ediddecret = subprocess.getstatusoutput('/usr/bin/edid-decode /tmp/edid.dat')
if is323F and os.path.exists("/sys/class/drm"):
dirList = os.listdir("/sys/class/drm")
monDir = ""
for dirItem in dirList:
if (r"-"+mnInterface) in dirItem:
monDir = dirItem
break
if "" != monDir and os.path.exists("/sys/class/drm/"+monDir+"/edid"):
status, ediddecret = subprocess.getstatusoutput('/usr/bin/edid-decode %s' % ("/sys/class/drm/"+monDir+"/edid"))
#Display Product Name: LEN T2224rbA
#Manufacturer: LEN Model 24810 Serial Number 16843009
result_bak = re.findall("Manufacturer:\s*(\w*)\s*Model\s*(\w*)", ediddecret)
@ -119,18 +161,27 @@ class KAMonitor() :
if len(result[0]) > 0 :
mnManufacturer = result[0]
if len(result) >= 2 and len(result[1]) > 0 :
mnName = result[1]
#CEC model 和 Alphanumeric Data String 不一致
if result_bak and result[0] in result_bak[0] or "CEC" in result[0]:
mnName = result[1]
else:
#Alphanumeric Data String: N140HCE-EN2
#Alphanumeric Data String: CMN
#Alphanumeric Data String: N140HCE-EN2
mnManufacturer = result[1]
mnName = result[0]
#Maximum image size: 48 cm x 27 cm
result = re.findall("Maximum image size:\s*(\d*)\s*cm\s*x\s*(\d*)\s*cm", ediddecret)
result2 = re.findall("Detailed mode: Clock (\d*\.\d*) MHz,\s*(\d*)\s*mm\s*x\s*(\d*)\s*mm", ediddecret)
isTN133A2 = Judgment_TN133A2()
is323F = Judgment_323F()
if result2:
mx = float(result2[0][1]); my = float(result2[0][2])
md = math.sqrt(mx**2 + my**2)/25.4
mnVisibleArea = (str(mx) + " X " + str(my) + " cm")
mnVisibleArea = (str(mx) + " X " + str(my) + " mm")
# 熊猫华星笔记本屏幕尺寸
if md > 13 and md <= 14 and len(mnName) > 0 and True != isTN133A2:
if md > 13 and md <= 14 and len(mnName) > 0 and True != isTN133A2 and True != is323F:
md = 14
mnSize = str("%.1f" %md)
elif result:
@ -138,7 +189,7 @@ class KAMonitor() :
md = math.sqrt(mx**2 + my**2)/2.54
mnVisibleArea = (str(mx) + " X " + str(my) + " cm")
# 熊猫华星笔记本屏幕尺寸
if md > 13 and md <= 14 and len(mnName) > 0 and True != isTN133A2:
if md > 13 and md <= 14 and len(mnName) > 0 and True != isTN133A2 and True != is323F :
md = 14
mnSize = str("%.1f" %md)
@ -166,6 +217,16 @@ class KAMonitor() :
monitorOne[MNI_NAME] = mnName
if len(mnSize) > 0 :
monitorOne[MNI_SIZE] = mnSize
# hwinfo 有可能获取不到显示器信息hwinfo只是用于最后做一个优化
if len(hwinfoList) > nIndex:
mapInfo = hwinfoList[nIndex]
if "Model" in mapInfo :
mnModel = mapInfo["Model"].split("\"")
if len(mnModel) > 1 :
mnModel = mnModel[0]
else :
mnModel = mapInfo["Model"]
monitorOne[MNI_NAME] = mnModel
if len(mnRatio) > 0 :
monitorOne[MNI_RATIO] = mnRatio
if len(mnResolution) > 0 :
@ -189,13 +250,15 @@ class KAMonitor() :
if len(mnSerial) > 0 :
monitorOne[MNI_SERIALNUM] = mnSerial
nIndex = nIndex + 1
if len(monitorOne) > 0 :
infoList["list"].append(monitorOne)
if Judgment_HW990():
for i in range(len(infoList["list"])-1, -1, -1):
if MNI_MANUFACTURER not in infoList["list"][i] :
infoList["list"].pop(i)
# for i in range(len(infoList["list"])-1, -1, -1):
# if MNI_MANUFACTURER not in infoList["list"][i] :
# infoList["list"].pop(i)
if os.path.exists("/sys/class/drm"):
edid_files = glob.glob("/sys/class/drm/*/edid")
@ -226,8 +289,15 @@ class KAMonitor() :
outLine += info[MNI_NAME]
else :
outLine += " / " + info[MNI_NAME]
# 华为机型如果没有型号则用厂商+屏幕尺寸
elif Judgment_PANGUW() or Judgment_HW990() or Judgment_HW9A0():
if MNI_MANUFACTURER in info:
if nIndex == 0 :
outLine += info[MNI_MANUFACTURER]
else:
outLine += " / " + info[MNI_MANUFACTURER]
if MNI_SIZE in info :
outLine += "("+info[MNI_SIZE]+")"
outLine += "("+info[MNI_SIZE]+")"
nIndex = nIndex + 1
return outLine

View File

@ -33,6 +33,7 @@ from pprint import pprint
from kajsondef import *
from kathread import *
from utils import *
class KAMouseInfo():
@ -43,7 +44,15 @@ class KAMouseInfo():
def getMouseInfo(self):
summary = {"list":[]}
hwinfoList = self.cmdTool.loadInfoFromHwinfo("--mouse")["list"]
customedType = Judgment_m70zg1ts()
hwinfoList = []
if 1 == customedType:
hwinfoList = self.cmdTool.loadHwinfoUsbMouseinfo("--usb")["list"]
else:
hwinfoList = self.cmdTool.loadInfoFromHwinfo("--mouse")["list"]
for mapInfo in hwinfoList :
if len(mapInfo) == 0 :
continue

View File

@ -134,6 +134,19 @@ class DetailInfo:
corePerSocket = line.split(":", 1)[1].strip()
if line.startswith("Thread(s) per core:"):
thread = line.split(":", 1)[1].strip()
#采用读取/proc/cpuinfo作为备选
if Pro_Product not in info or "" == info[Pro_Product]:
args = ["cat", "/proc/cpuinfo"]
# command = "cat /proc/cpuinfo | grep 'model name'"
extPipe = subprocess.Popen(args, env={'LANGUAGE':'en:'}, stdout=subprocess.PIPE)
extOutput = extPipe.stdout.readlines()
for extLine in extOutput:
extLine = bytes.decode(extLine.strip(),"utf-8","ignore")
if "model name" in extLine:
# print(extLine.split(":", 1)[1].strip() if info[Pro_Product] == "" else "")
info[Pro_Product] = extLine.split(":", 1)[1].strip() if info[Pro_Product] == "" else ""
break
if socket != "" and corePerSocket != "" and thread != "" and info[Pro_Cores] != "" and \
socket.isdigit() and corePerSocket.isdigit() and thread.isdigit() and info[Pro_Cores].isdigit() :

View File

@ -29,6 +29,7 @@ import json
import subprocess
from pprint import pprint
from string import digits
from kajsondef import *
from kathread import *
@ -332,6 +333,24 @@ class MemoryInfo():
summary["list"][index][MMI_TOTALCAPACITY] = str(float("%.1f" % size))+"GB"
else :
summary["list"][index][MMI_TOTALCAPACITY] = tempSize
elif MMI_TOTALCAPACITY in summary["list"][index]:
# 判断lshw和dmi获取的大小比较
dmiSize = summary["list"][index][MMI_TOTALCAPACITY].replace(" ","").upper()
lshwSize = mapInfo["size"]
lshwSize = lshwSize.replace("GiB","GB")
lshwSize = lshwSize.replace("MiB","MB")
units = ["B","KB","MB","GB","TB"]
tempTable= str.maketrans('', '', digits)
size_1 = [float(s) for s in re.findall(r'-?\d+\.?\d*', lshwSize)][0] * 1024 ** units.index(lshwSize.translate(tempTable))
size_2 = [float(s) for s in re.findall(r'-?\d+\.?\d*', dmiSize)][0] * 1024 ** units.index(dmiSize.translate(tempTable))
if(size_1 > size_2):
if "MB" in lshwSize :
lshwSize = lshwSize.replace("MB","")
if lshwSize.isdigit() :
size = float(lshwSize)/1024.0
summary["list"][index][MMI_TOTALCAPACITY] = str(float("%.1f" % size))+"GB"
else :
summary["list"][index][MMI_TOTALCAPACITY] = lshwSize
if "vendor" in mapInfo and MMI_MANUFACTURER not in summary["list"][index]:
summary["list"][index][MMI_MANUFACTURER] = mapInfo["vendor"]
if "product" in mapInfo and MMI_PARTNUMBER not in summary["list"][index]:

View File

@ -29,6 +29,7 @@ import json
import subprocess
import copy
import utils
import time
from pprint import pprint
@ -74,7 +75,7 @@ class NetworkAdaptor():
def getNetworkAdaptorInfo(self):
summary = {"list":[]}
self.cmdTool.loadInfoFromLshw(False)
self.cmdTool.loadInfoFromLshw(True)
networkAdaptorList = copy.deepcopy(self.cmdTool.lshwNetworkList)
for usbNetwork in self.cmdTool.lshwUsbList :
if "capabilities" in usbNetwork and "Bluetooth".lower() not in usbNetwork["capabilities"].lower() and \
@ -112,6 +113,16 @@ class NetworkAdaptor():
##名称
if "product" in mapInfo :
summary["list"][index][NetAdaptor_Product] = mapInfo["product"]
elif "bus info" in mapInfo:
if "usb" in mapInfo["bus info"] and "NetMac" in mapInfo:
# usb网卡用mac去检索hwinfo --usb
usbNetMac = mapInfo["NetMac"]
usbNetList = self.cmdTool.loadInfoFromHwinfo("--usb")["list"]
for usbItem in usbNetList:
if "HW Address" in usbItem:
if usbNetMac == usbItem["HW Address"]:
summary["list"][index][NetAdaptor_Product] = usbItem["Device"]
break
##制造商
if "Vendor" in mapInfo :
@ -120,6 +131,17 @@ class NetworkAdaptor():
summary["list"][index][NetAdaptor_Manufacturer] = hwVendor[1]
else :
summary["list"][index][NetAdaptor_Manufacturer] = mapInfo["Vendor"]
elif "bus info" in mapInfo:
if "usb" in mapInfo["bus info"] and "NetMac" in mapInfo:
# usb网卡用mac去检索hwinfo --usb
usbNetMac = mapInfo["NetMac"]
usbNetList = self.cmdTool.loadInfoFromHwinfo("--usb")["list"]
for usbItem in usbNetList:
if "HW Address" in usbItem:
if usbNetMac == usbItem["HW Address"]:
summary["list"][index][NetAdaptor_Manufacturer] = usbItem["Vendor"]
break
if "SubVendor" in mapInfo :
hwVendor = mapInfo["SubVendor"].split("\"")
if len(hwVendor) > 1 :
@ -285,6 +307,101 @@ class NetworkAdaptor():
nIndex = nIndex + 1
return outLine
#禁用网卡设备
def disableNetCard(self, strProductAndPath) :
print(strProductAndPath)
# try:
if("|" in strProductAndPath):
strProduct,pciPath = strProductAndPath.split("|")
sysPciPath = "/sys/devices/pci0000:00/"
if Judgment_SW():
if not os.path.exists("/sys/devices/pci0000:02/"+pciPath+"/remove") :
return False
else:
if not os.path.exists(sysPciPath+pciPath+"/remove") :
return False
youkerConfigDir = "/etc/youker-assistant"
if os.path.exists(youkerConfigDir):
pass
else:
os.mkdir(youkerConfigDir)
#写文件
if not os.path.exists(youkerConfigDir+"/"+"netCard"):
os.popen('touch %s'%(youkerConfigDir+"/"+"netCard"))
if Judgment_SW():
os.popen('echo "%s|%s" >> %s'%(strProduct,pciPath,youkerConfigDir+"/"+"netCard"))
os.popen('echo 1 > %s'%("/sys/devices/pci0000:02/"+pciPath+"/remove"))
else:
os.popen('echo "%s|%s" >> %s'%(strProduct,pciPath,youkerConfigDir+"/"+"netCard"))
#保存设备名称和pci写到文件中 设备名称+pci地址 而且要做区分
os.popen('echo 1 > %s'%(sysPciPath+pciPath+"/remove"))
# except Exception as e:
# print(e)
return True
#启用网卡设备
def enableNetCard(self, productAndPci) :
print('------------------------------------')
print(productAndPci)
configFile = "/etc/youker-assistant/netCard"
sysPciRescanPath = "/sys/bus/pci/rescan"
youkerConfigDir = "/etc/youker-assistant"
if not os.path.exists(sysPciRescanPath) or not os.path.exists(configFile) :
return False
# 去除禁用信息
allData = []
with open(configFile,'r')as fd:
print(fd.readlines)
#with open(configFile,'r') as fd:
file = open(configFile,'r')
allInfo = file.readlines()
print(allInfo)
print('====================')
for info in allInfo:
#info = fd.readline()
if '' != info:
if productAndPci in info:
pass
else:
allData.append(info)
fw = open(configFile, 'w')
fw.writelines(allData)
fw.close()
# os.popen('sed -i "s/%s//g" %s'%(productAndPci,configFile))
# os.popen('echo 1 > %s'%(sysPciRescanPath))
subprocess.Popen("echo 1 > %s"%(sysPciRescanPath), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
# 扫描当前所有需要禁用的设备
disableList = ["netCard","soundCard"]
commands = []
for item in disableList:
print('-----------------disableList-------------------')
print(os.path.exists(youkerConfigDir + "/" + item))
print(youkerConfigDir + "/" + item)
if os.path.exists(youkerConfigDir + "/" + item):
with open(youkerConfigDir + "/" + item, "r" ,encoding="utf-8") as file:
allLines = file.readlines()
for line in set(allLines):
line = line.strip()
print(line)
if "|" in line :
sysPciPath = "/sys/devices/pci0000:00/"
if Judgment_SW():
sysPciPath = "/sys/devices/pci0000:02/"
strProduct,pciPath = line.strip().split("|")
count = 0
while True and count < 30 :
if os.path.exists(sysPciPath+pciPath.strip()+"/remove"):
break
time.sleep(1)
count += 1
if not os.path.exists(sysPciPath+pciPath.strip()+"/remove") :
return False
print('echo 1 > %s'%(sysPciPath+pciPath.strip()+"/remove"))
commands.append("echo 1 > %s"%(sysPciPath+pciPath.strip()+"/remove"))
# 遍历命令列表,并逐一执行
for cmd in commands: subprocess.call(cmd, shell=True)
return True
if __name__ == "__main__":
cmdTool = KACmdTool()
cmdTool.loadInfoFromLshw()

View File

@ -4,6 +4,7 @@ import os
import re
import binascii
from systemboardthread import *
import platform
KILOBYTE_FACTOR = 1000.0
MEGABYTE_FACTOR = (1000.0 * 1000.0)
@ -21,6 +22,16 @@ def Judgment_LENOVO():
customedType = 1
return customedType
def Judgment_m70zg1ts():
sysBoardInfo = SystemBoard()
sysInfo = sysBoardInfo.getSystemInfo()
baseBoardInfo = sysBoardInfo.getBaseBoardInfo()
customedType = 0 ## 0 通用1 联想 主板名称:
if Board_Manufacturer in baseBoardInfo and "lenovo" in baseBoardInfo[Board_Manufacturer].lower() \
and Board_Product in baseBoardInfo and ("3157" in baseBoardInfo[Board_Product]) :
customedType = 1
return customedType
def Judgment_TN133A2():
# getSystemInfo
sysBoardInfo = SystemBoard()
@ -29,6 +40,17 @@ def Judgment_TN133A2():
return True
return False
def Judgment_323F():
# getSystemInfo
args = ["dmidecode","--type","11"]
pipe = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = pipe.stdout.readlines()
for l in output:
line = bytes.decode(l.strip(),"utf-8","ignore")
if line.find("323F") >= 0:
return True
return False
def Judgment_PANGUW():
args = ["lscpu"]
pipe = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@ -39,11 +61,21 @@ def Judgment_PANGUW():
return True
return False
def Judgment_L410():
args = ["dmidecode", "|","grep","'String 4'"]
pipe = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = pipe.stdout.readlines()
for l in output:
line = bytes.decode(l.strip(),"utf-8","ignore")
if line.find("KVK90") >= 0 or line.find("KVK90A"):
return True
return False
def Judgment_HW990():
if os.path.exists("/proc/hardware"):
with open("/proc/hardware",'r') as fd:
info = fd.readline()
if info.find("HUAWEI Kirin 990") >= 0 or info.find("kirin990") >= 0 or info.find("HUAWEI Kirin 9006C") >= 0:
if re.findall("kirin.*990", info.lower()) or info.find("HUAWEI Kirin 990") >= 0 or info.find("kirin990") >= 0 or info.find("HUAWEI Kirin 9006C") >= 0:
return True
else:
return False
@ -54,13 +86,37 @@ def Judgment_HW9A0():
if os.path.exists("/proc/hardware"):
with open("/proc/hardware",'r') as fd:
info = fd.readline()
if info.find("HUAWEI Kirin 9006C") >= 0:
if re.findall("kirin.*9006c", info.lower()) or info.find("HUAWEI Kirin 9006C") >= 0:
return True
else:
return False
else:
return False
def Judgment_Virt():
args = ["systemd-detect-virt"]
pipe = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output = pipe.stdout.readlines()
for l in output:
line = bytes.decode(l.strip(),"utf-8","ignore")
if "none" == line:
return False
return True
def Judgment_3A5000():
arch = platform.machine()
if "loongarch64" == arch:
return True
else:
return False
def Judgment_SW():
arch = platform.machine()
if "sw_64" == arch:
return True
else:
return False
def myctoascii(buf):
ch = bytes(buf.encode('utf-8'))
asci = binascii.b2a_hex(ch)
@ -313,4 +369,4 @@ def exchangeManufacturer(manufacturer) :
return manufacturer
if __name__ == "__main__":
Judgment_TN133A2();
Judgment_TN133A2();

View File

@ -33,6 +33,8 @@
#include <QJsonDocument>
#include <QJsonArray>
#include <QScrollBar>
#include <QClipboard>
#include <QApplication>
DriveInfoPage::DriveInfoPage(QWidget *parent)
: QWidget(parent)
@ -63,10 +65,38 @@ void DriveInfoPage::initUI()
m_scrollFrame->setWidgetResizable(true);
m_scrollFrame->setWidget(m_listFrame);
m_rkeyMenu = new QMenu(this);
QAction *copyAction = new QAction(tr("CopyAll"), this);
connect(copyAction, &QAction::triggered, this, [=](){DriveInfoPage::onCopyContent(m_strPageInfo);});
m_rkeyMenu->addAction(copyAction);
m_mainLayout->addWidget(m_scrollFrame);
this->setLayout(m_mainLayout);
}
void DriveInfoPage::onCopyContent(QString strPageInfo)
{
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(strPageInfo);
}
int DriveInfoPage::getBlankNum(){
QString locale = QLocale::system().name();
if(locale == "zh_CN"){
return BLANKNUM;
}else{
return BLANKNUM_EN;
}
}
void DriveInfoPage::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
m_rkeyMenu->popup(event->globalPos());
}
// KABaseInfoPage::mousePressEvent(event);
}
void DriveInfoPage::clearInfoItems()
{
QMap<unsigned, QList<KDriveInfoItem*>>::iterator itDriveInfoItems = m_mapItems.begin();
@ -99,33 +129,37 @@ void DriveInfoPage::refreshInfoItems()
driveInfo.strType == "USB controller" ||
driveInfo.strType == "PCI bridge" ||
driveInfo.strType == "SA bridge") { // 主板
itemIcon = ":/imgres/img_res/mother-board.svg";
itemIcon = "ukui-mother-board-symbolic";
itemName = tr("Motherboard");
uType = DRIVEINFOTYPE_MOTHERBOCARD;
} else if (driveInfo.strType == "VGA compatible controller") { // 显卡
itemIcon = ":/imgres/img_res/graphics-card.svg";
itemIcon = "ukui-graphics-card-symbolic";
itemName = tr("Graphics Card");
uType = DRIVEINFOTYPE_GRPHICS;
} else if (driveInfo.strType == "Ethernet controller") { // 网卡
itemIcon = ":/imgres/img_res/wired.svg";
itemIcon = "network-wired-symbolic";
itemName = tr("Wired Network Card");
uType = DRIVEINFOTYPE_NETWORK;
} else if (driveInfo.strType == "Audio device") { // 声卡
itemIcon = ":/imgres/img_res/soundcard.svg";
itemIcon = "audio-volume-high-symbolic";
itemName = tr("Sound Card");
uType = DRIVEINFOTYPE_AUDIO;
} else if (driveInfo.strType == "Network controller") { //无线网卡
itemIcon = ":/imgres/img_res/wireless.svg";
itemIcon = "network-wireless-signal-excellent-symbolic";
itemName = tr("Wireless Network Card");
uType = DRIVEINFOTYPE_WIFI;
} else if (driveInfo.strType == "Bluetooth Device") { //蓝牙
itemIcon = "bluetooth-symbolic";
itemName = tr("Bluetooth");
uType = DRIVEINFOTYPE_BLUETOOTH;
} else if (driveInfo.strType == "RAM memory" ||
driveInfo.strType == "SATA controller" ||
driveInfo.strType == "SMBus") { // 其他
itemIcon = ":/imgres/img_res/monitor.svg";
itemIcon = "computer-symbolic";
itemName = tr("Other");
uType = DRIVEINFOTYPE_OTHER;
} else {
itemIcon = ":/imgres/img_res/monitor.svg";
itemIcon = "computer-symbolic";
itemName = tr("Other");
uType = DRIVEINFOTYPE_OTHER;
}
@ -141,6 +175,28 @@ void DriveInfoPage::refreshInfoItems()
m_mapItems[uType] = listItems;
}
nCurIndex++;
if(driveInfo.strVersion.isEmpty()){
mapPageInfo.insert(std::pair<QString, QString>(QString::number(nCurIndex,10),itemName+"|"+driveInfo.strName));
}else{
mapPageInfo.insert(std::pair<QString, QString>(QString::number(nCurIndex,10),itemName+"|"+driveInfo.strName+" "+driveInfo.strVersion));
}
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(nCurIndex,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(nCurIndex,10));
}
}
}
// 利用UID实现有序
m_strPageInfo.clear();
for(int i=0;i<vecIndex.size();i++){
if(mapPageInfo.count(vecIndex[i])!=0){
QString tmpTitle = mapPageInfo[vecIndex[i]].split("|")[0];
QString tmpContent = mapPageInfo[vecIndex[i]].split("|")[1];
int length = tmpTitle.length();
m_strPageInfo.append(tmpTitle);
for(int i = length; i < DriveInfoPage::getBlankNum(); i++){
m_strPageInfo.append(" ");
}
m_strPageInfo.append(tmpContent+"\n");
}
}
}
@ -161,6 +217,8 @@ DI_TYPE DriveInfoPage::getDriveType(QString strType)
return DRIVEINFOTYPE_AUDIO;
} else if (strType == "Network controller") { //无线网卡
return DRIVEINFOTYPE_WIFI;
} else if (strType == "Bluetooth Device") { //蓝牙
return DRIVEINFOTYPE_BLUETOOTH;
} else if (strType == "RAM memory" ||
strType == "SATA controller" ||
strType == "SMBus") { // 其他

View File

@ -20,6 +20,8 @@
#ifndef DRIVEINFOPAGE_H
#define DRIVEINFOPAGE_H
#define BLANKNUM 10
#define BLANKNUM_EN 20
#include <QWidget>
#include <QFrame>
@ -28,6 +30,12 @@
#include <QScrollArea>
#include <QList>
#include <QMap>
#include <QMenu>
#include <QAction>
#include <QEvent>
#include <map>
#include <vector>
#include <QMouseEvent>
#include "kdriveinfoitem.h"
#include "../../src/commondef.h"
@ -39,6 +47,7 @@ enum DI_TYPE{
DRIVEINFOTYPE_NETWORK, // 有线网卡
DRIVEINFOTYPE_AUDIO, // 声卡
DRIVEINFOTYPE_WIFI, // 无线网卡
DRIVEINFOTYPE_BLUETOOTH, // 蓝牙
DRIVEINFOTYPE_OTHER, // 其他
};
@ -59,9 +68,14 @@ public:
void initConnections();
void updateInfoItems(QString strInfoJson);
int getBlankNum();
public slots:
void onUpdateInfo(QString strInfoJson);
void onCopyContent(QString strPageInfo);
protected:
void mousePressEvent(QMouseEvent *event);
private:
void clearInfoItems();
@ -70,6 +84,9 @@ private:
private:
QString m_strInfoJson;
QString m_strPageInfo;
std::vector<QString> vecIndex;
std::map<QString, QString> mapPageInfo;
QHBoxLayout *m_mainLayout = nullptr;
QFrame *m_listFrame = nullptr;
@ -78,6 +95,7 @@ private:
QMap<unsigned, QList<KDriveInfoItem*>> m_mapItems;
QMap<DI_TYPE, QList<DriveInfo>> m_mapDriveInfo;
QMenu *m_rkeyMenu = nullptr;
};
#endif // DRIVEINFOPAGE_H

View File

@ -185,6 +185,16 @@ QStringList DriveManage::getDeviceDriveInfo()
}
}
}
// 判断是否有蓝牙设备,存在蓝牙设备则添加驱动 btusb
QString btcmd = "hciconfig -a";
QProcess *btp = new QProcess();
btp->start(btcmd);
btp->waitForFinished();
if(btp->canReadLine()){
deviceMsgList.append("Bluetooth Device: btusb;driver in use: btusb");
}
if(tmps != ""){
deviceMsgList.append(tmps);
}

View File

@ -1,5 +1,5 @@
QT += widgets dbus x11extras charts
QT += widgets dbus x11extras charts svg
TEMPLATE = lib
CONFIG += plugin \

View File

@ -1,5 +1,5 @@
QT += widgets dbus x11extras charts
QT += widgets dbus x11extras charts svg
TEMPLATE = lib
CONFIG += plugin \

View File

@ -58,10 +58,23 @@ void BatteryInfo::initUI()
m_scrollFrame->setWidgetResizable(true);
m_scrollFrame->setWidget(m_listFrame);
m_rkeyMenu = new QMenu(this);
QAction *copyAction = new QAction(tr("CopyAll"), this);
connect(copyAction, &QAction::triggered, this, [=](){KABaseInfoPage::onCopyContent(m_strPageInfo);});
m_rkeyMenu->addAction(copyAction);
m_mainLayout->addWidget(m_scrollFrame);
this->setLayout(m_mainLayout);
}
void BatteryInfo::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
m_rkeyMenu->popup(event->globalPos());
}
KABaseInfoPage::mousePressEvent(event);
}
void BatteryInfo::onUpdateInfo(QString strInfoJson)
{
m_strInfoJson = strInfoJson;
@ -88,6 +101,9 @@ void BatteryInfo::clearInfoItems()
}
itMapInfoItems.value().clear();
}
mapPageInfo.clear();
vecItems.clear();
vecMapItems.clear();
m_mapInfoItems.clear();
}
@ -116,13 +132,33 @@ void BatteryInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle,
listItem->setFixedWidth(666);
m_listLayout->addWidget(listItem);
itMapInfoItems.value()[uId] = listItem;
m_strPageInfo.append("|"+strTitle+"|"+strContent+"\n");
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
}
} else {
QMap<unsigned, QWidget*> mapItems;
if (bMulti) {
KAInfoTitle *infoTitle = new KAInfoTitle(QString("%1%2").arg(tr("Battery")).arg(m_mapInfoItems.size()+1));
infoTitle->setMinimumHeight(30);
infoTitle->setMinimumHeight(50);
infoTitle->setFixedWidth(666);
m_listLayout->addWidget(infoTitle);
mapItems[BATTERYINFO_TITLE] = infoTitle;
@ -133,7 +169,48 @@ void BatteryInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle,
m_listLayout->addWidget(listItem);
mapItems[uId] = listItem;
m_mapInfoItems[uGroup] = mapItems;
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
// 利用UID实现有序
m_strPageInfo.clear();
for(int j=0;j<vecMapItems.size();j++){
if(vecMapItems.size()>1){
m_strPageInfo.append(QString("%1%2").arg(tr("Battery")).arg(j+1)+"\n");
}
std::map<QString, QString> temMap = vecMapItems[j];
for(int i=0;i<vecItems[j].size();i++){
if(temMap.count(vecItems[j][i])!=0){
QString tmpTitle = temMap[vecItems[j][i]].split("|")[0];
QString tmpContent = temMap[vecItems[j][i]].split("|")[1];
int length = tmpTitle.length();
m_strPageInfo.append(tmpTitle);
for(int i = length; i < KABaseInfoPage::getBlankNum(); i++){
m_strPageInfo.append(" ");
}
m_strPageInfo.append(tmpContent+"\n");
}
}
m_strPageInfo.append("\n");
}
m_strPageInfo.chop(1);
}
void BatteryInfo::updateInfoItems(QString strInfoJson)

View File

@ -26,6 +26,12 @@
#include <QScrollArea>
#include <QVBoxLayout>
#include <QMap>
#include <QMenu>
#include <QAction>
#include <QEvent>
#include <map>
#include <vector>
#include <QMouseEvent>
#include "../../src/kajsondef.h"
#include "kainfotitle.h"
@ -60,17 +66,26 @@ public slots:
void onUpdateInfo(QString strInfoJson) override;
void onRefreshInfo() override;
protected:
void mousePressEvent(QMouseEvent *event);
private:
void addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, QString strContent, bool bMulti);
void clearInfoItems();
private:
QString m_strInfoJson;
QString m_strPageInfo;
std::vector<QString> vecIndex;
std::vector<std::vector<QString>> vecItems;
std::map<QString, QString> mapPageInfo;
std::vector<std::map<QString, QString>> vecMapItems;
QVBoxLayout *m_mainLayout = nullptr;
QFrame *m_listFrame = nullptr;
QVBoxLayout *m_listLayout = nullptr;
QScrollArea *m_scrollFrame = nullptr;
QMenu *m_rkeyMenu = nullptr;
QMap<unsigned,QMap<unsigned, QWidget*>> m_mapInfoItems;
};

View File

@ -58,10 +58,23 @@ void BluetoothInfo::initUI()
m_scrollFrame->setWidgetResizable(true);
m_scrollFrame->setWidget(m_listFrame);
m_rkeyMenu = new QMenu(this);
QAction *copyAction = new QAction(tr("CopyAll"), this);
connect(copyAction, &QAction::triggered, this, [=](){KABaseInfoPage::onCopyContent(m_strPageInfo);});
m_rkeyMenu->addAction(copyAction);
m_mainLayout->addWidget(m_scrollFrame);
this->setLayout(m_mainLayout);
}
void BluetoothInfo::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
m_rkeyMenu->popup(event->globalPos());
}
KABaseInfoPage::mousePressEvent(event);
}
void BluetoothInfo::onUpdateInfo(QString strInfoJson)
{
m_strInfoJson = strInfoJson;
@ -89,6 +102,9 @@ void BluetoothInfo::clearInfoItems()
}
itMapInfoItems.value().clear();
}
mapPageInfo.clear();
vecItems.clear();
vecMapItems.clear();
m_mapInfoItems.clear();
}
@ -114,13 +130,33 @@ void BluetoothInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle
listItem->setFixedWidth(666);
m_listLayout->addWidget(listItem);
itMapInfoItems.value()[uId] = listItem;
m_strPageInfo.append("|"+strTitle+"|"+strContent+"\n");
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
}
} else {
QMap<unsigned, QWidget*> mapItems;
if (bMulti) {
KAInfoTitle *infoTitle = new KAInfoTitle(QString("%1%2").arg(tr("Bluetooth")).arg(m_mapInfoItems.size()+1));
infoTitle->setMinimumHeight(30);
infoTitle->setMinimumHeight(50);
infoTitle->setFixedWidth(666);
m_listLayout->addWidget(infoTitle);
mapItems[BLUETOOTHINFO_TITLE] = infoTitle;
@ -131,13 +167,92 @@ void BluetoothInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle
m_listLayout->addWidget(listItem);
mapItems[uId] = listItem;
m_mapInfoItems[uGroup] = mapItems;
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
// 利用UID实现有序
m_strPageInfo.clear();
for(int j=0;j<vecMapItems.size();j++){
if(vecMapItems.size()>1){
m_strPageInfo.append(QString("%1%2").arg(tr("Bluetooth")).arg(j+1)+"\n");
}
std::map<QString, QString> temMap = vecMapItems[j];
for(int i=0;i<vecItems[j].size();i++){
if(temMap.count(vecItems[j][i])!=0){
QString tmpTitle = temMap[vecItems[j][i]].split("|")[0];
QString tmpContent = temMap[vecItems[j][i]].split("|")[1];
int length = tmpTitle.length();
m_strPageInfo.append(tmpTitle);
for(int i = length; i < KABaseInfoPage::getBlankNum(); i++){
m_strPageInfo.append(" ");
}
m_strPageInfo.append(tmpContent+"\n");
}
}
m_strPageInfo.append("\n");
}
m_strPageInfo.chop(1);
}
void BluetoothInfo::updateInfoItems(QString strInfoJson)
{
if (strInfoJson.isEmpty())
return;
// m_rkeyMenu->clear();
if(KABaseInfoPage::bluetoothExist()){
// 禁/启用状态判断
bool needAdd = true;
if(KABaseInfoPage::bluetoothStatus().contains("disable")){
QAction *enableAction = new QAction(tr("Enable "), this);
connect(enableAction, &QAction::triggered, this, [=](){enableBluetooth();});
QList<QAction *> actList = m_rkeyMenu->actions();
for(int i = 0; i < actList.length(); i++){
if((tr("Enable "))==actList[i]->text()){
needAdd = false;
}
if((tr("Disable "))==actList[i]->text()){
m_rkeyMenu->removeAction(actList[i]);
}
}
if(needAdd){
m_rkeyMenu->addAction(enableAction);
}
}else{
QAction *disableAction = new QAction(tr("Disable "), this);
connect(disableAction, &QAction::triggered, this, [=](){disableBluetooth();});
QList<QAction *> actList = m_rkeyMenu->actions();
for(int i = 0; i < actList.length(); i++){
if((tr("Disable "))==actList[i]->text()){
needAdd = false;
}
if((tr("Enable "))==actList[i]->text()){
m_rkeyMenu->removeAction(actList[i]);
}
}
if(needAdd){
m_rkeyMenu->addAction(disableAction);
}
}
}
qInfo()<<"Cur info:"<<strInfoJson;
QJsonParseError jsonParseErr;
QJsonDocument rootDoc = QJsonDocument::fromJson(strInfoJson.toUtf8(), &jsonParseErr);//字符串格式化为JSON
@ -276,6 +391,83 @@ void BluetoothInfo::chkNoDevice()
infoSize += itMapInfoItems.value().size();
}
if (infoSize == 0) {
addInfoItems(0, BLUETOOTHINFO_INVALID, "", tr("Device not exitst or Get Device is Empty"), false);
QList<QAction *> actList = m_rkeyMenu->actions();
// 0表示禁用1表示启用2表示启用中
int btStatus = 1;
for(int i = 0;i<actList.length();i++){
if((tr("Enable "))==actList[i]->text()){
btStatus = 0;
break;
}else if ((tr("Disable "))==actList[i]->text())
{
btStatus = 2;
break;
}
}
if(0 == btStatus || 2 == btStatus){
if(!KABaseInfoPage::bluetoothExist()){
addInfoItems(0, BLUETOOTHINFO_INVALID, "", tr("Device not exitst or Get Device is Empty"), false);
}else{
addInfoItems(0, BLUETOOTHINFO_INVALID, "", tr("Bluetooth Disable"), false);
}
}else{
addInfoItems(0, BLUETOOTHINFO_INVALID, "", tr("Device not exitst or Get Device is Empty"), false);
}
}
}
void BluetoothInfo::enterLoadingPage()
{
m_scrollFrame->hide();
m_loadWidget = new LoadWidget(m_strDevStatus);
m_loadWidget->setModal(true);
m_loadWidget->show();
m_refreshInfoTimer->stop();
}
void BluetoothInfo::exitLoadingPage()
{
m_scrollFrame->show();
m_loadWidget->close();
m_refreshInfoTimer->stop();
}
void BluetoothInfo::disableBluetooth(){
m_strInfoLastJson = m_strInfoJson;
m_strDevStatus = "disable";
if(nullptr == m_refreshInfoTimer){
m_refreshInfoTimer = new QTimer();
}
enterLoadingPage();
DataWorker::getInstance()->disableBluetooth();
QObject::connect(m_refreshInfoTimer, &QTimer::timeout, [&]() {
if("" == m_strDevStatus || nullptr == m_strDevStatus || m_strInfoLastJson != m_strInfoJson ){
exitLoadingPage();
m_strInfoLastJson = m_strInfoJson;
m_strDevStatus = "";
}
onRefreshInfo();
});
m_refreshInfoTimer->start(1000); // Start timer with 1 second interval
}
void BluetoothInfo::enableBluetooth(){
m_strInfoLastJson = m_strInfoJson;
m_strDevStatus = "enable";
if(nullptr == m_refreshInfoTimer){
m_refreshInfoTimer = new QTimer();
}
enterLoadingPage();
DataWorker::getInstance()->enableBluetooth();
QObject::connect(m_refreshInfoTimer, &QTimer::timeout, [&]() {
if("" == m_strDevStatus || nullptr == m_strDevStatus || m_strInfoLastJson != m_strInfoJson ){
exitLoadingPage();
m_strInfoLastJson = m_strInfoJson;
m_strDevStatus = "";
}
onRefreshInfo();
});
m_refreshInfoTimer->start(1000); // Start timer with 1 second interval
}

View File

@ -26,10 +26,17 @@
#include <QScrollArea>
#include <QVBoxLayout>
#include <QMap>
#include <QMenu>
#include <QAction>
#include <QEvent>
#include <map>
#include <vector>
#include <QMouseEvent>
#include "../../src/kajsondef.h"
#include "kainfotitle.h"
#include "kabaseinfopage.h"
#include "../../src/loadwidget.h"
enum BLI_INDEX{
BLUETOOTHINFO_TITLE,
@ -75,20 +82,37 @@ public slots:
void onUpdateInfo(QString strInfoJson) override;
void onRefreshInfo() override;
protected:
void mousePressEvent(QMouseEvent *event);
private:
void addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, QString strContent, bool bMulti);
void clearInfoItems();
void chkNoDevice();
void disableBluetooth();
void enableBluetooth();
void enterLoadingPage();
void exitLoadingPage();
private:
QString m_strInfoJson;
QString m_strPageInfo;
QString m_strInfoLastJson;
QString m_strDevStatus = nullptr;
std::vector<QString> vecIndex;
std::vector<std::vector<QString>> vecItems;
std::map<QString, QString> mapPageInfo;
std::vector<std::map<QString, QString>> vecMapItems;
QVBoxLayout *m_mainLayout = nullptr;
QFrame *m_listFrame = nullptr;
QVBoxLayout *m_listLayout = nullptr;
QScrollArea *m_scrollFrame = nullptr;
QMenu *m_rkeyMenu = nullptr;
LoadWidget *m_loadWidget = nullptr;
QMap<unsigned,QMap<unsigned, QWidget*>> m_mapInfoItems;
QTimer *m_refreshInfoTimer = nullptr;
};
#endif // BLUETOOTHINFO_H

View File

@ -58,10 +58,23 @@ void CameraInfo::initUI()
m_scrollFrame->setWidgetResizable(true);
m_scrollFrame->setWidget(m_listFrame);
m_rkeyMenu = new QMenu(this);
QAction *copyAction = new QAction(tr("CopyAll"), this);
connect(copyAction, &QAction::triggered, this, [=](){KABaseInfoPage::onCopyContent(m_strPageInfo);});
m_rkeyMenu->addAction(copyAction);
m_mainLayout->addWidget(m_scrollFrame);
this->setLayout(m_mainLayout);
}
void CameraInfo::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
m_rkeyMenu->popup(event->globalPos());
}
KABaseInfoPage::mousePressEvent(event);
}
void CameraInfo::onUpdateInfo(QString strInfoJson)
{
m_strInfoJson = strInfoJson;
@ -88,6 +101,9 @@ void CameraInfo::clearInfoItems()
}
itMapInfoItems.value().clear();
}
mapPageInfo.clear();
vecItems.clear();
vecMapItems.clear();
m_mapInfoItems.clear();
}
@ -113,13 +129,33 @@ void CameraInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, Q
listItem->setFixedWidth(666);
m_listLayout->addWidget(listItem);
itMapInfoItems.value()[uId] = listItem;
m_strPageInfo.append("|"+strTitle+"|"+strContent+"\n");
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
}
} else {
QMap<unsigned, QWidget*> mapItems;
if (bMulti) {
KAInfoTitle *infoTitle = new KAInfoTitle(QString("%1%2").arg(tr("Camera")).arg(m_mapInfoItems.size()+1));
infoTitle->setMinimumHeight(30);
infoTitle->setMinimumHeight(50);
infoTitle->setFixedWidth(666);
m_listLayout->addWidget(infoTitle);
mapItems[CAMERAINFO_TITLE] = infoTitle;
@ -130,7 +166,48 @@ void CameraInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, Q
m_listLayout->addWidget(listItem);
mapItems[uId] = listItem;
m_mapInfoItems[uGroup] = mapItems;
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
// 利用UID实现有序
m_strPageInfo.clear();
for(int j=0;j<vecMapItems.size();j++){
if(vecMapItems.size()>1){
m_strPageInfo.append(QString("%1%2").arg(tr("Camera")).arg(j+1)+"\n");
}
std::map<QString, QString> temMap = vecMapItems[j];
for(int i=0;i<vecItems[j].size();i++){
if(temMap.count(vecItems[j][i])!=0){
QString tmpTitle = temMap[vecItems[j][i]].split("|")[0];
QString tmpContent = temMap[vecItems[j][i]].split("|")[1];
int length = tmpTitle.length();
m_strPageInfo.append(tmpTitle);
for(int i = length; i < KABaseInfoPage::getBlankNum(); i++){
m_strPageInfo.append(" ");
}
m_strPageInfo.append(tmpContent+"\n");
}
}
m_strPageInfo.append("\n");
}
m_strPageInfo.chop(1);
}
void CameraInfo::updateInfoItems(QString strInfoJson)

View File

@ -26,6 +26,12 @@
#include <QScrollArea>
#include <QVBoxLayout>
#include <QMap>
#include <QMenu>
#include <QAction>
#include <QEvent>
#include <map>
#include <vector>
#include <QMouseEvent>
#include "../../src/kajsondef.h"
#include "kainfotitle.h"
@ -60,17 +66,26 @@ public slots:
void onUpdateInfo(QString strInfoJson) override;
void onRefreshInfo() override;
protected:
void mousePressEvent(QMouseEvent *event);
private:
void addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, QString strContent, bool bMulti);
void clearInfoItems();
private:
QString m_strInfoJson;
QString m_strPageInfo;
std::vector<QString> vecIndex;
std::vector<std::vector<QString>> vecItems;
std::map<QString, QString> mapPageInfo;
std::vector<std::map<QString, QString>> vecMapItems;
QVBoxLayout *m_mainLayout = nullptr;
QFrame *m_listFrame = nullptr;
QVBoxLayout *m_listLayout = nullptr;
QScrollArea *m_scrollFrame = nullptr;
QMenu *m_rkeyMenu = nullptr;
QMap<unsigned,QMap<unsigned, QWidget*>> m_mapInfoItems;
};

View File

@ -58,10 +58,23 @@ void CDRomInfo::initUI()
m_scrollFrame->setWidgetResizable(true);
m_scrollFrame->setWidget(m_listFrame);
m_rkeyMenu = new QMenu(this);
QAction *copyAction = new QAction(tr("CopyAll"), this);
connect(copyAction, &QAction::triggered, this, [=](){KABaseInfoPage::onCopyContent(m_strPageInfo);});
m_rkeyMenu->addAction(copyAction);
m_mainLayout->addWidget(m_scrollFrame);
this->setLayout(m_mainLayout);
}
void CDRomInfo::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
m_rkeyMenu->popup(event->globalPos());
}
KABaseInfoPage::mousePressEvent(event);
}
void CDRomInfo::onUpdateInfo(QString strInfoJson)
{
m_strInfoJson = strInfoJson;
@ -89,6 +102,9 @@ void CDRomInfo::clearInfoItems()
}
itMapInfoItems.value().clear();
}
mapPageInfo.clear();
vecItems.clear();
vecMapItems.clear();
m_mapInfoItems.clear();
}
@ -117,13 +133,33 @@ void CDRomInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, QS
listItem->setFixedWidth(666);
m_listLayout->addWidget(listItem);
itMapInfoItems.value()[uId] = listItem;
m_strPageInfo.append("|"+strTitle+"|"+strContent+"\n");
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
}
} else {
QMap<unsigned, QWidget*> mapItems;
if (bMulti) {
KAInfoTitle *infoTitle = new KAInfoTitle(QString("%1%2").arg(tr("CD-ROM")).arg(m_mapInfoItems.size()+1));
infoTitle->setMinimumHeight(30);
infoTitle->setMinimumHeight(50);
infoTitle->setFixedWidth(666);
m_listLayout->addWidget(infoTitle);
mapItems[CDROMINFO_TITLE] = infoTitle;
@ -134,7 +170,48 @@ void CDRomInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, QS
m_listLayout->addWidget(listItem);
mapItems[uId] = listItem;
m_mapInfoItems[uGroup] = mapItems;
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
// 利用UID实现有序
m_strPageInfo.clear();
for(int j=0;j<vecMapItems.size();j++){
if(vecMapItems.size()>1){
m_strPageInfo.append(QString("%1%2").arg(tr("CD-ROM")).arg(j+1)+"\n");
}
std::map<QString, QString> temMap = vecMapItems[j];
for(int i=0;i<vecItems[j].size();i++){
if(temMap.count(vecItems[j][i])!=0){
QString tmpTitle = temMap[vecItems[j][i]].split("|")[0];
QString tmpContent = temMap[vecItems[j][i]].split("|")[1];
int length = tmpTitle.length();
m_strPageInfo.append(tmpTitle);
for(int i = length; i < KABaseInfoPage::getBlankNum(); i++){
m_strPageInfo.append(" ");
}
m_strPageInfo.append(tmpContent+"\n");
}
}
m_strPageInfo.append("\n");
}
m_strPageInfo.chop(1);
}
void CDRomInfo::updateInfoItems(QString strInfoJson)

View File

@ -26,6 +26,12 @@
#include <QScrollArea>
#include <QVBoxLayout>
#include <QMap>
#include <QMenu>
#include <QAction>
#include <QEvent>
#include <map>
#include <vector>
#include <QMouseEvent>
#include "../../src/kajsondef.h"
#include "kainfotitle.h"
@ -60,6 +66,9 @@ public slots:
void onUpdateInfo(QString strInfoJson) override;
void onRefreshInfo() override;
protected:
void mousePressEvent(QMouseEvent *event);
private:
void addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, QString strContent, bool bMulti);
void clearInfoItems();
@ -67,11 +76,17 @@ private:
private:
QString m_strInfoJson;
QString m_strPageInfo;
std::vector<QString> vecIndex;
std::vector<std::vector<QString>> vecItems;
std::map<QString, QString> mapPageInfo;
std::vector<std::map<QString, QString>> vecMapItems;
QVBoxLayout *m_mainLayout = nullptr;
QFrame *m_listFrame = nullptr;
QVBoxLayout *m_listLayout = nullptr;
QScrollArea *m_scrollFrame = nullptr;
QMenu *m_rkeyMenu = nullptr;
QMap<unsigned,QMap<unsigned, QWidget*>> m_mapInfoItems;
};

View File

@ -58,11 +58,24 @@ void FanInfo::initUI()
m_scrollFrame->setWidgetResizable(true);
m_scrollFrame->setWidget(m_listFrame);
m_rkeyMenu = new QMenu(this);
QAction *copyAction = new QAction(tr("CopyAll"), this);
connect(copyAction, &QAction::triggered, this, [=](){KABaseInfoPage::onCopyContent(m_strPageInfo);});
m_rkeyMenu->addAction(copyAction);
m_mainLayout->addWidget(m_scrollFrame);
this->setLayout(m_mainLayout);
m_refreshInfoTimer = new QTimer(this);
}
void FanInfo::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
m_rkeyMenu->popup(event->globalPos());
}
KABaseInfoPage::mousePressEvent(event);
}
void FanInfo::onUpdateInfo(QString strInfoJson)
{
m_strInfoJson = strInfoJson;
@ -92,6 +105,9 @@ void FanInfo::clearInfoItems()
}
itMapInfoItems.value().clear();
}
mapPageInfo.clear();
vecItems.clear();
vecMapItems.clear();
m_mapInfoItems.clear();
}
@ -117,13 +133,33 @@ void FanInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, QStr
listItem->setFixedWidth(666);
m_listLayout->addWidget(listItem);
itMapInfoItems.value()[uId] = listItem;
m_strPageInfo.append("|"+strTitle+"|"+strContent+"\n");
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
}
} else {
QMap<unsigned, QWidget*> mapItems;
if (bMulti) {
KAInfoTitle *infoTitle = new KAInfoTitle(QString("%1%2").arg(tr("Fan")).arg(m_mapInfoItems.size()+1));
infoTitle->setMinimumHeight(30);
infoTitle->setMinimumHeight(50);
infoTitle->setFixedWidth(666);
m_listLayout->addWidget(infoTitle);
mapItems[FANINFO_TITLE] = infoTitle;
@ -134,7 +170,48 @@ void FanInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, QStr
m_listLayout->addWidget(listItem);
mapItems[uId] = listItem;
m_mapInfoItems[uGroup] = mapItems;
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
// 利用UID实现有序
m_strPageInfo.clear();
for(int j=0;j<vecMapItems.size();j++){
if(vecMapItems.size()>1){
m_strPageInfo.append(QString("%1%2").arg(tr("Network Card")).arg(j+1)+"\n");
}
std::map<QString, QString> temMap = vecMapItems[j];
for(int i=0;i<vecItems[j].size();i++){
if(temMap.count(vecItems[j][i])!=0){
QString tmpTitle = temMap[vecItems[j][i]].split("|")[0];
QString tmpContent = temMap[vecItems[j][i]].split("|")[1];
int length = tmpTitle.length();
m_strPageInfo.append(tmpTitle);
for(int i = length; i < KABaseInfoPage::getBlankNum(); i++){
m_strPageInfo.append(" ");
}
m_strPageInfo.append(tmpContent+"\n");
}
}
m_strPageInfo.append("\n");
}
m_strPageInfo.chop(1);
}
void FanInfo::updateInfoItems(QString strInfoJson)

View File

@ -27,6 +27,12 @@
#include <QVBoxLayout>
#include <QMap>
#include <QTimer>
#include <QMenu>
#include <QAction>
#include <QEvent>
#include <map>
#include <vector>
#include <QMouseEvent>
#include "../../src/kajsondef.h"
#include "kainfotitle.h"
@ -53,6 +59,9 @@ public slots:
void onUpdateInfo(QString strInfoJson) override;
void onRefreshInfo() override;
protected:
void mousePressEvent(QMouseEvent *event);
private:
void addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, QString strContent, bool bMulti);
void clearInfoItems();
@ -60,11 +69,17 @@ private:
private:
QString m_strInfoJson;
QString m_strPageInfo;
std::vector<QString> vecIndex;
std::vector<std::vector<QString>> vecItems;
std::map<QString, QString> mapPageInfo;
std::vector<std::map<QString, QString>> vecMapItems;
QVBoxLayout *m_mainLayout = nullptr;
QFrame *m_listFrame = nullptr;
QVBoxLayout *m_listLayout = nullptr;
QScrollArea *m_scrollFrame = nullptr;
QMenu *m_rkeyMenu = nullptr;
QMap<unsigned,QMap<unsigned, QWidget*>> m_mapInfoItems;
QTimer *m_refreshInfoTimer = nullptr;

View File

@ -20,6 +20,7 @@
#include "graphicscardinfo.h"
#include "dataworker.h"
#include "../../src/util.h"
#include <QDebug>
#include <QTimer>
@ -28,6 +29,7 @@
#include <QJsonDocument>
#include <QJsonArray>
#include <QScrollBar>
#include <kysdk/kysdk-base/kyutils.h>
// 格兰菲显存获取方案
#include <epoxy/gl.h>
@ -67,10 +69,23 @@ void GraphicsCardInfo::initUI()
m_scrollFrame->setWidgetResizable(true);
m_scrollFrame->setWidget(m_listFrame);
m_rkeyMenu = new QMenu(this);
QAction *copyAction = new QAction(tr("CopyAll"), this);
connect(copyAction, &QAction::triggered, this, [=](){KABaseInfoPage::onCopyContent(m_strPageInfo);});
m_rkeyMenu->addAction(copyAction);
m_mainLayout->addWidget(m_scrollFrame);
this->setLayout(m_mainLayout);
}
void GraphicsCardInfo::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
m_rkeyMenu->popup(event->globalPos());
}
KABaseInfoPage::mousePressEvent(event);
}
void GraphicsCardInfo::onUpdateInfo(QString strInfoJson)
{
m_strInfoJson = strInfoJson;
@ -98,6 +113,9 @@ void GraphicsCardInfo::clearInfoItems()
}
itMapInfoItems.value().clear();
}
mapPageInfo.clear();
vecItems.clear();
vecMapItems.clear();
m_mapInfoItems.clear();
}
@ -125,13 +143,33 @@ void GraphicsCardInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTi
listItem->setFixedWidth(666);
m_listLayout->addWidget(listItem);
itMapInfoItems.value()[uId] = listItem;
m_strPageInfo.append("|"+strTitle+"|"+strContent+"\n");
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
}
} else {
QMap<unsigned, QWidget*> mapItems;
if (bMulti) {
KAInfoTitle *infoTitle = new KAInfoTitle(QString("%1%2").arg(tr("Graphics Card")).arg(m_mapInfoItems.size()+1));
infoTitle->setMinimumHeight(30);
infoTitle->setMinimumHeight(50);
infoTitle->setFixedWidth(666);
m_listLayout->addWidget(infoTitle);
mapItems[GRAPHICSCARDINFO_TITLE] = infoTitle;
@ -142,7 +180,48 @@ void GraphicsCardInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTi
m_listLayout->addWidget(listItem);
mapItems[uId] = listItem;
m_mapInfoItems[uGroup] = mapItems;
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
// 利用UID实现有序
m_strPageInfo.clear();
for(int j=0;j<vecMapItems.size();j++){
if(vecMapItems.size()>1){
m_strPageInfo.append(QString("%1%2").arg(tr("Graphics Card")).arg(j+1)+"\n");
}
std::map<QString, QString> temMap = vecMapItems[j];
for(int i=0;i<vecItems[j].size();i++){
if(temMap.count(vecItems[j][i])!=0){
QString tmpTitle = temMap[vecItems[j][i]].split("|")[0];
QString tmpContent = temMap[vecItems[j][i]].split("|")[1];
int length = tmpTitle.length();
m_strPageInfo.append(tmpTitle);
for(int i = length; i < KABaseInfoPage::getBlankNum(); i++){
m_strPageInfo.append(" ");
}
m_strPageInfo.append(tmpContent+"\n");
}
}
m_strPageInfo.append("\n");
}
m_strPageInfo.chop(1);
}
void GraphicsCardInfo::updateInfoItems(QString strInfoJson)
@ -210,11 +289,29 @@ void GraphicsCardInfo::updateInfoItems(QString strInfoJson)
}
} else {
printf("GLX_MESA_query_renderer not supported!\n");
addInfoItems(n, GRAPHICSCARDINFO_CAPCITY, tr("Video Memory"), subItemValue.toString(), bMulti);
QString data = subItemValue.toString();
char result_data[128] = {0};
KDKVolumeBaseType unit = Util::getVolumeUnit(data);
char* volume = Util::getVolume(data,unit);
if(kdkVolumeBaseCharacterConvert(volume, unit, result_data) == KDK_NOERR){
addInfoItems(n, GRAPHICSCARDINFO_CAPCITY, tr("Video Memory"), QString::fromUtf8(result_data), bMulti);
}else{
addInfoItems(n, GRAPHICSCARDINFO_CAPCITY, tr("Video Memory"), subItemValue.toString(), bMulti);
}
}
}else{
addInfoItems(n, GRAPHICSCARDINFO_CAPCITY, tr("Video Memory"), subItemValue.toString(), bMulti);
QString data = subItemValue.toString();
char result_data[128] = {0};
KDKVolumeBaseType unit = Util::getVolumeUnit(data);
char* volume = Util::getVolume(data,unit);
if(kdkVolumeBaseCharacterConvert(volume, unit, result_data) == KDK_NOERR){
addInfoItems(n, GRAPHICSCARDINFO_CAPCITY, tr("Video Memory"), QString::fromUtf8(result_data), bMulti);
}else{
addInfoItems(n, GRAPHICSCARDINFO_CAPCITY, tr("Video Memory"), subItemValue.toString(), bMulti);
}
}
}
subItemValue = subItemObj.value(GSI_MEMTYPE);

View File

@ -26,6 +26,12 @@
#include <QScrollArea>
#include <QVBoxLayout>
#include <QMap>
#include <QMenu>
#include <QAction>
#include <QEvent>
#include <map>
#include <vector>
#include <QMouseEvent>
#include "../../src/kajsondef.h"
#include "kainfotitle.h"
@ -72,6 +78,9 @@ public slots:
void onUpdateInfo(QString strInfoJson) override;
void onRefreshInfo() override;
protected:
void mousePressEvent(QMouseEvent *event);
private:
void addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, QString strContent, bool bMulti);
void clearInfoItems();
@ -79,11 +88,17 @@ private:
private:
QString m_strInfoJson;
QString m_strPageInfo;
std::vector<QString> vecIndex;
std::vector<std::vector<QString>> vecItems;
std::map<QString, QString> mapPageInfo;
std::vector<std::map<QString, QString>> vecMapItems;
QVBoxLayout *m_mainLayout = nullptr;
QFrame *m_listFrame = nullptr;
QVBoxLayout *m_listLayout = nullptr;
QScrollArea *m_scrollFrame = nullptr;
QMenu *m_rkeyMenu = nullptr;
QMap<unsigned,QMap<unsigned, QWidget*>> m_mapInfoItems;
};

View File

@ -20,6 +20,7 @@
#include "harddiskinfo.h"
#include "dataworker.h"
#include "../../src/util.h"
#include <QDebug>
#include <QTimer>
@ -28,6 +29,7 @@
#include <QJsonDocument>
#include <QJsonArray>
#include <QScrollBar>
#include <kysdk/kysdk-base/kyutils.h>
HardDiskInfo::HardDiskInfo(QWidget *parent)
: KABaseInfoPage(parent)
@ -58,10 +60,23 @@ void HardDiskInfo::initUI()
m_scrollFrame->setWidgetResizable(true);
m_scrollFrame->setWidget(m_listFrame);
m_rkeyMenu = new QMenu(this);
QAction *copyAction = new QAction(tr("CopyAll"), this);
connect(copyAction, &QAction::triggered, this, [=](){KABaseInfoPage::onCopyContent(m_strPageInfo);});
m_rkeyMenu->addAction(copyAction);
m_mainLayout->addWidget(m_scrollFrame);
this->setLayout(m_mainLayout);
}
void HardDiskInfo::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
m_rkeyMenu->popup(event->globalPos());
}
KABaseInfoPage::mousePressEvent(event);
}
void HardDiskInfo::onUpdateInfo(QString strInfoJson)
{
m_strInfoJson = strInfoJson;
@ -89,6 +104,9 @@ void HardDiskInfo::clearInfoItems()
}
itMapInfoItems.value().clear();
}
mapPageInfo.clear();
vecItems.clear();
vecMapItems.clear();
m_mapInfoItems.clear();
}
@ -116,13 +134,33 @@ void HardDiskInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle,
listItem->setFixedWidth(666);
m_listLayout->addWidget(listItem);
itMapInfoItems.value()[uId] = listItem;
m_strPageInfo.append("|"+strTitle+"|"+strContent+"\n");
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
}
} else {
QMap<unsigned, QWidget*> mapItems;
if (bMulti) {
KAInfoTitle *infoTitle = new KAInfoTitle(QString("%1%2").arg(tr("Hard Disk Info")).arg(m_mapInfoItems.size()+1));
infoTitle->setMinimumHeight(30);
infoTitle->setMinimumHeight(50);
infoTitle->setFixedWidth(666);
m_listLayout->addWidget(infoTitle);
mapItems[HARDDISKINFO_TITLE] = infoTitle;
@ -133,7 +171,48 @@ void HardDiskInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle,
m_listLayout->addWidget(listItem);
mapItems[uId] = listItem;
m_mapInfoItems[uGroup] = mapItems;
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
// 利用UID实现有序
m_strPageInfo.clear();
for(int j=0;j<vecMapItems.size();j++){
if(vecMapItems.size()>1){
m_strPageInfo.append(QString("%1%2").arg(tr("Hard Disk Info")).arg(j+1)+"\n");
}
std::map<QString, QString> temMap = vecMapItems[j];
for(int i=0;i<vecItems[j].size();i++){
if(temMap.count(vecItems[j][i])!=0){
QString tmpTitle = temMap[vecItems[j][i]].split("|")[0];
QString tmpContent = temMap[vecItems[j][i]].split("|")[1];
int length = tmpTitle.length();
m_strPageInfo.append(tmpTitle);
for(int i = length; i < KABaseInfoPage::getBlankNum(); i++){
m_strPageInfo.append(" ");
}
m_strPageInfo.append(tmpContent+"\n");
}
}
m_strPageInfo.append("\n");
}
m_strPageInfo.chop(1);
}
void HardDiskInfo::updateInfoItems(QString strInfoJson)
@ -173,7 +252,16 @@ void HardDiskInfo::updateInfoItems(QString strInfoJson)
}
subItemValue = subItemObj.value(HDI_CAPACITY);
if (subItemValue.isString()) {
addInfoItems(n, HARDDISKINFO_CAPACITY, tr("Capacity"), subItemValue.toString(), bMulti);
QString data = subItemValue.toString();
char result_data[128] = {0};
KDKVolumeBaseType unit = Util::getVolumeUnit(data);
char* volume = Util::getVolume(data,unit);
if(kdkVolumeBaseCharacterConvert(volume, unit, result_data) == KDK_NOERR){
addInfoItems(n, HARDDISKINFO_CAPACITY, tr("Capacity"), QString::fromUtf8(result_data), bMulti);
}else{
addInfoItems(n, HARDDISKINFO_CAPACITY, tr("Capacity"), subItemValue.toString(), bMulti);
}
}
subItemValue = subItemObj.value(HDI_USEDTIMES);
if (subItemValue.isString()) {

View File

@ -26,6 +26,12 @@
#include <QScrollArea>
#include <QVBoxLayout>
#include <QMap>
#include <QMenu>
#include <QAction>
#include <QEvent>
#include <map>
#include <vector>
#include <QMouseEvent>
#include "../../src/kajsondef.h"
#include "kainfotitle.h"
@ -64,6 +70,9 @@ public slots:
void onUpdateInfo(QString strInfoJson) override;
void onRefreshInfo() override;
protected:
void mousePressEvent(QMouseEvent *event);
private:
void addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, QString strContent, bool bMulti);
void clearInfoItems();
@ -71,11 +80,17 @@ private:
private:
QString m_strInfoJson;
QString m_strPageInfo;
std::vector<QString> vecIndex;
std::vector<std::vector<QString>> vecItems;
std::map<QString, QString> mapPageInfo;
std::vector<std::map<QString, QString>> vecMapItems;
QVBoxLayout *m_mainLayout = nullptr;
QFrame *m_listFrame = nullptr;
QVBoxLayout *m_listLayout = nullptr;
QScrollArea *m_scrollFrame = nullptr;
QMenu *m_rkeyMenu = nullptr;
QMap<unsigned,QMap<unsigned, QWidget*>> m_mapInfoItems;
};

View File

@ -1,5 +1,5 @@
QT += widgets dbus x11extras KScreen
QT += widgets dbus x11extras KScreen svg
TEMPLATE = lib
CONFIG += plugin \
@ -23,8 +23,10 @@ LIBS += -lXrandr
LIBS += -ludev
LIBS += -lepoxy
LIBS += -lSDL2
LIBS += -lpthread
PKGCONFIG += gsettings-qt
PKGCONFIG += kysdk-utils
SOURCES += \
batteryinfo.cpp \

View File

@ -19,6 +19,12 @@
*/
#include "kabaseinfopage.h"
#include <QClipboard>
#include <QApplication>
#include <QDebug>
#include "dataworker.h"
#include <QRegExp>
#include <QFile>
KABaseInfoPage::KABaseInfoPage(QWidget *parent)
: QWidget(parent)
@ -41,3 +47,154 @@ void KABaseInfoPage::onUpdateInfo(unsigned uStatus, QString strInfoJson)
Q_UNUSED(uStatus);
onUpdateInfo(strInfoJson);
}
void KABaseInfoPage::onCopyContent(QString strPageInfo)
{
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(strPageInfo);
}
void KABaseInfoPage::disableMouse(QString strProduct)
{
QString mouseId = queryMouseId(strProduct);
if(""!=mouseId){
QProcess p(0);
p.start("xinput disable "+mouseId);
p.waitForStarted();
p.waitForFinished();
}else{
disableTooltip();
// 该设备禁用失败
}
// 刷新页面
onRefreshInfo();
}
void KABaseInfoPage::enableMouse(QString strProduct)
{
QString mouseId = queryMouseId(strProduct);
if(""!=mouseId){
QProcess p(0);
p.start("xinput enable "+mouseId);
p.waitForStarted();
p.waitForFinished();
}else{
// 该设备启用失败
disableTooltip();
}
// 刷新页面
onRefreshInfo();
}
QString KABaseInfoPage::mouseStatus(QString strProduct)
{
QString status = "";
QString mouseId = queryMouseId(strProduct);
if(""!=mouseId){
QProcess p(0);
p.start("xinput list-props "+mouseId);
p.waitForStarted();
p.waitForFinished();
QString strTemp=QString::fromLocal8Bit(p.readAllStandardOutput()); //获得输出
QStringList strList = strTemp.split("\n");
for(int i=0;i<strList.length();i++){
if(strList.at(i).contains("Device Enabled")){
// 设备device id获取
if(strList.at(i).contains(":")){
// Device Enabled (169): 1
status = strList.at(i).split(":")[1];
break;
}
}
}
}
return status;
}
QString KABaseInfoPage::queryMouseId(QString strProduct)
{
QClipboard *clipboard = QApplication::clipboard();
QProcess p(0);
QString cmd = "xinput list";
QString mouseId = "";
p.start(cmd);
p.waitForStarted();
p.waitForFinished();
QString strTemp=QString::fromLocal8Bit(p.readAllStandardOutput()); //获得输出
QStringList strList = strTemp.split("\n");
for(int i=0;i<strList.length();i++){
if(strList.at(i).contains(strProduct)){
// 设备device id获取
if(strList.at(i).contains("id=")){
// "⎜ ↳ USB OPTICAL MOUSE \tid=10\t[slave pointer (2)]"
mouseId = strList.at(i).split("id=")[1].split("\t")[0];
break;
}
}
}
return mouseId;
}
bool KABaseInfoPage::bluetoothExist()
{
QProcess p(0);
p.start("lsusb -vv");
p.waitForStarted();
p.waitForFinished();
QString strTemp=QString::fromLocal8Bit(p.readAllStandardOutput()); //获得输出
if(strTemp.contains("Bluetooth")){
return true;
}
return false;
}
QString KABaseInfoPage::bluetoothStatus()
{
QString status = "enable";
QProcess p(0);
p.start("hciconfig -a");
p.waitForStarted();
p.waitForFinished();
QString strTemp=QString::fromLocal8Bit(p.readAllStandardOutput()); //获得输出
if("" == strTemp){
status = "disable";
}
return status;
}
void KABaseInfoPage::disableTooltip()
{
QDBusInterface iface("org.freedesktop.Notifications",
"/org/freedesktop/Notifications",
"org.freedesktop.Notifications",
QDBusConnection::sessionBus());
QList<QVariant> args;
QStringList actions; //跳转动作
QMap<QString, QVariant> hints;
args<<QString(tr("kylin-assistant")) //应用名
<<((unsigned int) 0) //替换ID若不替换则填0
<<QString("kylin-assistant") //应用主题图标名
<<QString(tr("kylin-assistant info")) //通知主题
<<QString(tr("Disable failed")) //通知正文
<<actions //跳转动作
<<hints
<<(int)-1; //驻留时间: -1默认显示时间由通知中心决定 0消息常驻 其他:显示相应时长(由应用决定单位ms)
QDBusMessage response = iface.callWithArgumentList(QDBus::AutoDetect,"Notify",args);
if (response.type() == QDBusMessage::ReplyMessage)//判断method的返回值
{
qDebug() << "发送成功!通知ID:" << response.arguments().takeFirst().toString();
uint m_notifyId = response.arguments().takeFirst().toUInt(); //返回的是通知中心为该条消息分配的ID
} else {
qDebug() << "发送失败:" << response.type();
}
}
int KABaseInfoPage::getBlankNum(){
QString locale = QLocale::system().name();
if(locale == "zh_CN"){
return BLANKNUM;
}else{
return BLANKNUM_EN;
}
}

View File

@ -21,18 +21,31 @@
#ifndef KABASEINFOPAGE_H
#define KABASEINFOPAGE_H
#define BLANKNUM 10
#define BLANKNUM_EN 20
#include <QWidget>
#include <QProcess>
class KABaseInfoPage : public QWidget
{
Q_OBJECT
public:
explicit KABaseInfoPage(QWidget *parent = nullptr);
int getBlankNum();
public slots:
virtual void onRefreshInfo();
virtual void onUpdateInfo(QString strInfoJson);
virtual void onUpdateInfo(unsigned uStatus, QString strInfoJson);
void onCopyContent(QString strPageInfo);
void disableMouse(QString strProduct);
void enableMouse(QString strProduct);
QString queryMouseId(QString strProduct);
QString mouseStatus(QString strProduct);
QString bluetoothStatus();
bool bluetoothExist();
void disableTooltip();
};
#endif // KABASEINFOPAGE_H

View File

@ -58,10 +58,23 @@ void KeyboardInfo::initUI()
m_scrollFrame->setWidgetResizable(true);
m_scrollFrame->setWidget(m_listFrame);
m_rkeyMenu = new QMenu(this);
QAction *copyAction = new QAction(tr("CopyAll"), this);
connect(copyAction, &QAction::triggered, this, [=](){KABaseInfoPage::onCopyContent(m_strPageInfo);});
m_rkeyMenu->addAction(copyAction);
m_mainLayout->addWidget(m_scrollFrame);
this->setLayout(m_mainLayout);
}
void KeyboardInfo::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
m_rkeyMenu->popup(event->globalPos());
}
KABaseInfoPage::mousePressEvent(event);
}
void KeyboardInfo::onUpdateInfo(QString strInfoJson)
{
m_strInfoJson = strInfoJson;
@ -89,6 +102,9 @@ void KeyboardInfo::clearInfoItems()
}
itMapInfoItems.value().clear();
}
mapPageInfo.clear();
vecItems.clear();
vecMapItems.clear();
m_mapInfoItems.clear();
}
@ -117,13 +133,33 @@ void KeyboardInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle,
listItem->setFixedWidth(666);
m_listLayout->addWidget(listItem);
itMapInfoItems.value()[uId] = listItem;
m_strPageInfo.append("|"+strTitle+"|"+strContent+"\n");
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
}
} else {
QMap<unsigned, QWidget*> mapItems;
if (bMulti) {
KAInfoTitle *infoTitle = new KAInfoTitle(QString("%1%2").arg(tr("Keyboard")).arg(m_mapInfoItems.size()+1));
infoTitle->setMinimumHeight(30);
infoTitle->setMinimumHeight(50);
infoTitle->setFixedWidth(666);
m_listLayout->addWidget(infoTitle);
mapItems[KEYBOARDINFO_TITLE] = infoTitle;
@ -134,7 +170,48 @@ void KeyboardInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle,
m_listLayout->addWidget(listItem);
mapItems[uId] = listItem;
m_mapInfoItems[uGroup] = mapItems;
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
// 利用UID实现有序
m_strPageInfo.clear();
for(int j=0;j<vecMapItems.size();j++){
if(vecMapItems.size()>1){
m_strPageInfo.append(QString("%1%2").arg(tr("Keyboard")).arg(j+1)+"\n");
}
std::map<QString, QString> temMap = vecMapItems[j];
for(int i=0;i<vecItems[j].size();i++){
if(temMap.count(vecItems[j][i])!=0){
QString tmpTitle = temMap[vecItems[j][i]].split("|")[0];
QString tmpContent = temMap[vecItems[j][i]].split("|")[1];
int length = tmpTitle.length();
m_strPageInfo.append(tmpTitle);
for(int i = length; i < KABaseInfoPage::getBlankNum(); i++){
m_strPageInfo.append(" ");
}
m_strPageInfo.append(tmpContent+"\n");
}
}
m_strPageInfo.append("\n");
}
m_strPageInfo.chop(1);
}
void KeyboardInfo::updateInfoItems(QString strInfoJson)

View File

@ -26,6 +26,12 @@
#include <QScrollArea>
#include <QVBoxLayout>
#include <QMap>
#include <QMenu>
#include <QAction>
#include <QEvent>
#include <map>
#include <vector>
#include <QMouseEvent>
#include "../../src/kajsondef.h"
#include "kainfotitle.h"
@ -58,6 +64,9 @@ public slots:
void onUpdateInfo(QString strInfoJson) override;
void onRefreshInfo() override;
protected:
void mousePressEvent(QMouseEvent *event);
private:
void addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, QString strContent, bool bMulti);
void clearInfoItems();
@ -65,11 +74,17 @@ private:
private:
QString m_strInfoJson;
QString m_strPageInfo;
std::vector<QString> vecIndex;
std::vector<std::vector<QString>> vecItems;
std::map<QString, QString> mapPageInfo;
std::vector<std::map<QString, QString>> vecMapItems;
QVBoxLayout *m_mainLayout = nullptr;
QFrame *m_listFrame = nullptr;
QVBoxLayout *m_listLayout = nullptr;
QScrollArea *m_scrollFrame = nullptr;
QMenu *m_rkeyMenu = nullptr;
QMap<unsigned,QMap<unsigned, QWidget*>> m_mapInfoItems;
};

View File

@ -20,6 +20,7 @@
#include "memoryinfo.h"
#include "dataworker.h"
#include "../../src/util.h"
#include <QDebug>
#include <QTimer>
@ -28,6 +29,7 @@
#include <QJsonDocument>
#include <QJsonArray>
#include <QScrollBar>
#include <kysdk/kysdk-base/kyutils.h>
MemoryInfo::MemoryInfo(QWidget *parent)
: KABaseInfoPage(parent)
@ -58,10 +60,23 @@ void MemoryInfo::initUI()
m_scrollFrame->setWidgetResizable(true);
m_scrollFrame->setWidget(m_listFrame);
m_rkeyMenu = new QMenu(this);
QAction *copyAction = new QAction(tr("CopyAll"), this);
connect(copyAction, &QAction::triggered, this, [=](){KABaseInfoPage::onCopyContent(m_strPageInfo);});
m_rkeyMenu->addAction(copyAction);
m_mainLayout->addWidget(m_scrollFrame);
this->setLayout(m_mainLayout);
}
void MemoryInfo::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
m_rkeyMenu->popup(event->globalPos());
}
KABaseInfoPage::mousePressEvent(event);
}
void MemoryInfo::onUpdateInfo(QString strInfoJson)
{
m_strInfoJson = strInfoJson;
@ -89,6 +104,9 @@ void MemoryInfo::clearInfoItems()
}
itMapInfoItems.value().clear();
}
mapPageInfo.clear();
vecItems.clear();
vecMapItems.clear();
m_mapInfoItems.clear();
}
@ -114,13 +132,33 @@ void MemoryInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, Q
listItem->setFixedWidth(666);
m_listLayout->addWidget(listItem);
itMapInfoItems.value()[uId] = listItem;
m_strPageInfo.append("|"+strTitle+"|"+strContent+"\n");
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
}
} else {
QMap<unsigned, QWidget*> mapItems;
if (bMulti) {
KAInfoTitle *infoTitle = new KAInfoTitle(QString("%1%2").arg(tr("Memory Info")).arg(m_mapInfoItems.size()+1));
infoTitle->setMinimumHeight(30);
infoTitle->setMinimumHeight(50);
infoTitle->setFixedWidth(666);
m_listLayout->addWidget(infoTitle);
mapItems[MEMORYINFO_TITLE] = infoTitle;
@ -131,7 +169,48 @@ void MemoryInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, Q
m_listLayout->addWidget(listItem);
mapItems[uId] = listItem;
m_mapInfoItems[uGroup] = mapItems;
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
// 利用UID实现有序
m_strPageInfo.clear();
for(int j=0;j<vecMapItems.size();j++){
if(vecMapItems.size()>1){
m_strPageInfo.append(QString("%1%2").arg(tr("Memory Info")).arg(j+1)+"\n");
}
std::map<QString, QString> temMap = vecMapItems[j];
for(int i=0;i<vecItems[j].size();i++){
if(temMap.count(vecItems[j][i])!=0){
QString tmpTitle = temMap[vecItems[j][i]].split("|")[0];
QString tmpContent = temMap[vecItems[j][i]].split("|")[1];
int length = tmpTitle.length();
m_strPageInfo.append(tmpTitle);
for(int i = length; i < KABaseInfoPage::getBlankNum(); i++){
m_strPageInfo.append(" ");
}
m_strPageInfo.append(tmpContent+"\n");
}
}
m_strPageInfo.append("\n");
}
m_strPageInfo.chop(1);
}
void MemoryInfo::updateInfoItems(QString strInfoJson)
@ -179,7 +258,16 @@ void MemoryInfo::updateInfoItems(QString strInfoJson)
}
subItemValue = subItemObj.value(MMI_TOTALCAPACITY);
if (subItemValue.isString()) {
addInfoItems(n, MEMORYINFO_TOTALCAPACITY, tr("Total Capacity"), subItemValue.toString(), bMulti);
QString data = subItemValue.toString();
char result_data[128] = {0};
KDKVolumeBaseType unit = Util::getVolumeUnit(data);
char* volume = Util::getVolume(data,unit);
if(kdkVolumeBaseCharacterConvert(volume, unit, result_data) == KDK_NOERR){
addInfoItems(n, MEMORYINFO_TOTALCAPACITY, tr("Total Capacity"), QString::fromUtf8(result_data), bMulti);
}else{
addInfoItems(n, MEMORYINFO_TOTALCAPACITY, tr("Total Capacity"), subItemValue.toString(), bMulti);
}
}
subItemValue = subItemObj.value(MMI_USEDCAPACITY);
if (subItemValue.isString()) {

View File

@ -26,6 +26,12 @@
#include <QScrollArea>
#include <QVBoxLayout>
#include <QMap>
#include <QMenu>
#include <QAction>
#include <QEvent>
#include <map>
#include <vector>
#include <QMouseEvent>
#include "../../src/kajsondef.h"
#include "kainfotitle.h"
@ -68,6 +74,9 @@ public slots:
void onUpdateInfo(QString strInfoJson) override;
void onRefreshInfo() override;
protected:
void mousePressEvent(QMouseEvent *event);
private:
void addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, QString strContent, bool bMulti);
void clearInfoItems();
@ -75,11 +84,17 @@ private:
private:
QString m_strInfoJson;
QString m_strPageInfo;
std::vector<QString> vecIndex;
std::vector<std::vector<QString>> vecItems;
std::map<QString, QString> mapPageInfo;
std::vector<std::map<QString, QString>> vecMapItems;
QVBoxLayout *m_mainLayout = nullptr;
QFrame *m_listFrame = nullptr;
QVBoxLayout *m_listLayout = nullptr;
QScrollArea *m_scrollFrame = nullptr;
QMenu *m_rkeyMenu = nullptr;
QMap<unsigned,QMap<unsigned, QWidget*>> m_mapInfoItems;
};

View File

@ -71,14 +71,21 @@ void MonitorInfo::initUI()
m_scrollFrame->setWidgetResizable(true);
m_scrollFrame->setWidget(m_listFrame);
m_rkeyMenu = new QMenu(this);
QAction *copyAction = new QAction(tr("CopyAll"), this);
connect(copyAction, &QAction::triggered, this, [=](){KABaseInfoPage::onCopyContent(m_strPageInfo);});
m_rkeyMenu->addAction(copyAction);
m_mainLayout->addWidget(m_scrollFrame);
this->setLayout(m_mainLayout);
}
// QObject::connect(new KScreen::GetConfigOperation(), &KScreen::GetConfigOperation::finished,
// [&](KScreen::ConfigOperation *op) {
// this->setConfig(qobject_cast<KScreen::GetConfigOperation *>(op)->config());
// });
void MonitorInfo::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
m_rkeyMenu->popup(event->globalPos());
}
KABaseInfoPage::mousePressEvent(event);
}
void MonitorInfo::onUpdateInfo(QString strInfoJson)
@ -160,6 +167,9 @@ void MonitorInfo::clearInfoItems()
}
itMapInfoItems.value().clear();
}
mapPageInfo.clear();
vecItems.clear();
vecMapItems.clear();
m_mapInfoItems.clear();
}
@ -187,13 +197,33 @@ void MonitorInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle,
listItem->setFixedWidth(666);
m_listLayout->addWidget(listItem);
itMapInfoItems.value()[uId] = listItem;
m_strPageInfo.append("|"+strTitle+"|"+strContent+"\n");
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
}
} else {
QMap<unsigned, QWidget*> mapItems;
if (bMulti) {
KAInfoTitle *infoTitle = new KAInfoTitle(QString("%1%2").arg(tr("Monitor")).arg(m_mapInfoItems.size()+1));
infoTitle->setMinimumHeight(30);
infoTitle->setMinimumHeight(50);
infoTitle->setFixedWidth(666);
m_listLayout->addWidget(infoTitle);
mapItems[MONITORINFO_TITLE] = infoTitle;
@ -204,7 +234,48 @@ void MonitorInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle,
m_listLayout->addWidget(listItem);
mapItems[uId] = listItem;
m_mapInfoItems[uGroup] = mapItems;
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
// 利用UID实现有序
m_strPageInfo.clear();
for(int j=0;j<vecMapItems.size();j++){
if(vecMapItems.size()>1){
m_strPageInfo.append(QString("%1%2").arg(tr("Monitor")).arg(j+1)+"\n");
}
std::map<QString, QString> temMap = vecMapItems[j];
for(int i=0;i<vecItems[j].size();i++){
if(temMap.count(vecItems[j][i])!=0){
QString tmpTitle = temMap[vecItems[j][i]].split("|")[0];
QString tmpContent = temMap[vecItems[j][i]].split("|")[1];
int length = tmpTitle.length();
m_strPageInfo.append(tmpTitle);
for(int i = length; i < KABaseInfoPage::getBlankNum(); i++){
m_strPageInfo.append(" ");
}
m_strPageInfo.append(tmpContent+"\n");
}
}
m_strPageInfo.append("\n");
}
m_strPageInfo.chop(1);
}
void MonitorInfo::updateInfoItems(QString strInfoJson)

View File

@ -27,6 +27,12 @@
#include <QVBoxLayout>
#include <QMap>
#include <QAbstractNativeEventFilter>
#include <QMenu>
#include <QAction>
#include <QEvent>
#include <map>
#include <vector>
#include <QMouseEvent>
#include "../../src/kajsondef.h"
#include "kainfotitle.h"
@ -74,6 +80,7 @@ private Q_SLOTS:
protected:
virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
void mousePressEvent(QMouseEvent *event);
private:
void addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, QString strContent, bool bMulti);
@ -85,6 +92,11 @@ private:
private:
QString m_strInfoJson;
QString m_strPageInfo;
std::vector<QString> vecIndex;
std::vector<std::vector<QString>> vecItems;
std::map<QString, QString> mapPageInfo;
std::vector<std::map<QString, QString>> vecMapItems;
QVBoxLayout *m_mainLayout = nullptr;
QFrame *m_listFrame = nullptr;
@ -94,7 +106,7 @@ private:
QMap<unsigned,QMap<unsigned, QWidget*>> m_mapInfoItems;
int m_xrrEventBase = 0;
int m_xrrErrorBase = 0;
QMenu *m_rkeyMenu = nullptr;
#if QT_VERSION <= QT_VERSION_CHECK(5, 12, 0)
KScreen::ConfigPtr mConfig;
KScreen::ConfigPtr mPrevConfig;
@ -104,7 +116,6 @@ private:
KScreen::ConfigPtr mPrevConfig = nullptr;
KScreen::OutputPtr res = nullptr;
#endif
};
#endif // MONITORINFO_H

View File

@ -57,10 +57,23 @@ void MotherBoardInfo::initUI()
m_scrollFrame->setWidgetResizable(true);
m_scrollFrame->setWidget(m_listFrame);
m_rkeyMenu = new QMenu(this);
QAction *copyAction = new QAction(tr("CopyAll"), this);
connect(copyAction, &QAction::triggered, this, [=](){KABaseInfoPage::onCopyContent(m_strPageInfo);});
m_rkeyMenu->addAction(copyAction);
m_mainLayout->addWidget(m_scrollFrame);
this->setLayout(m_mainLayout);
}
void MotherBoardInfo::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
m_rkeyMenu->popup(event->globalPos());
}
KABaseInfoPage::mousePressEvent(event);
}
void MotherBoardInfo::onUpdateInfo(QString strInfoJson)
{
m_strInfoJson = strInfoJson;
@ -99,6 +112,24 @@ void MotherBoardInfo::addInfoItems(unsigned uId, QString strTitle, QString strCo
listItem->setFixedWidth(666);
m_listLayout->addWidget(listItem);
m_mapItem[uId] = listItem;
mapPageInfo.insert(std::pair<QString, QString>( QString::number(uId,10),strTitle+"|"+strContent));
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
}
// 利用UID实现有序
m_strPageInfo.clear();
for(int i=0;i<vecIndex.size();i++){
if(mapPageInfo.count(vecIndex[i])!=0){
QString tmpTitle = mapPageInfo[vecIndex[i]].split("|")[0];
QString tmpContent = mapPageInfo[vecIndex[i]].split("|")[1];
int length = tmpTitle.length();
m_strPageInfo.append(tmpTitle);
for(int i = length; i < KABaseInfoPage::getBlankNum(); i++){
m_strPageInfo.append(" ");
}
m_strPageInfo.append(tmpContent+"\n");
}
}
}

View File

@ -26,6 +26,12 @@
#include <QScrollArea>
#include <QVBoxLayout>
#include <QMap>
#include <QMenu>
#include <QAction>
#include <QEvent>
#include <map>
#include <vector>
#include <QMouseEvent>
#include "../../src/kajsondef.h"
#include "kabaseinfopage.h"
@ -57,6 +63,9 @@ public slots:
void onUpdateInfo(QString strInfoJson) override;
void onRefreshInfo() override;
protected:
void mousePressEvent(QMouseEvent *event);
private:
void addInfoItems(unsigned uId, QString strTitle, QString strContent);
void clearInfoItems();
@ -64,6 +73,9 @@ private:
private:
QString m_strInfoJson;
QString m_strPageInfo;
std::vector<QString> vecIndex;
std::map<QString, QString> mapPageInfo;
QVBoxLayout *m_mainLayout = nullptr;
QFrame *m_listFrame = nullptr;
@ -71,6 +83,7 @@ private:
QScrollArea *m_scrollFrame = nullptr;
QMap<unsigned, KInfoListItem*> m_mapItem;
QMenu *m_rkeyMenu = nullptr;
};
#endif // MOTHERBOARDINFO_H

View File

@ -58,10 +58,23 @@ void MouseInfo::initUI()
m_scrollFrame->setWidgetResizable(true);
m_scrollFrame->setWidget(m_listFrame);
m_rkeyMenu = new QMenu(this);
QAction *copyAction = new QAction(tr("CopyAll"), this);
connect(copyAction, &QAction::triggered, this, [=](){KABaseInfoPage::onCopyContent(m_strPageInfo);});
m_rkeyMenu->addAction(copyAction);
m_mainLayout->addWidget(m_scrollFrame);
this->setLayout(m_mainLayout);
}
void MouseInfo::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
m_rkeyMenu->popup(event->globalPos());
}
KABaseInfoPage::mousePressEvent(event);
}
void MouseInfo::onUpdateInfo(QString strInfoJson)
{
m_strInfoJson = strInfoJson;
@ -89,6 +102,9 @@ void MouseInfo::clearInfoItems()
}
itMapInfoItems.value().clear();
}
mapPageInfo.clear();
vecItems.clear();
vecMapItems.clear();
m_mapInfoItems.clear();
}
@ -117,13 +133,33 @@ void MouseInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, QS
listItem->setFixedWidth(666);
m_listLayout->addWidget(listItem);
itMapInfoItems.value()[uId] = listItem;
m_strPageInfo.append("|"+strTitle+"|"+strContent+"\n");
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
}
} else {
QMap<unsigned, QWidget*> mapItems;
if (bMulti) {
KAInfoTitle *infoTitle = new KAInfoTitle(QString("%1%2").arg(tr("Mouse")).arg(m_mapInfoItems.size()+1));
infoTitle->setMinimumHeight(30);
infoTitle->setMinimumHeight(50);
infoTitle->setFixedWidth(666);
m_listLayout->addWidget(infoTitle);
mapItems[MOUSEINFO_TITLE] = infoTitle;
@ -134,11 +170,56 @@ void MouseInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, QS
m_listLayout->addWidget(listItem);
mapItems[uId] = listItem;
m_mapInfoItems[uGroup] = mapItems;
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
// 利用UID实现有序
m_strPageInfo.clear();
for(int j=0;j<vecMapItems.size();j++){
if(vecMapItems.size()>1){
m_strPageInfo.append(QString("%1%2").arg(tr("Mouse")).arg(j+1)+"\n");
}
std::map<QString, QString> temMap = vecMapItems[j];
for(int i=0;i<vecItems[j].size();i++){
if(temMap.count(vecItems[j][i])!=0){
QString tmpTitle = temMap[vecItems[j][i]].split("|")[0];
QString tmpContent = temMap[vecItems[j][i]].split("|")[1];
int length = tmpTitle.length();
m_strPageInfo.append(tmpTitle);
for(int i = length; i < KABaseInfoPage::getBlankNum(); i++){
m_strPageInfo.append(" ");
}
m_strPageInfo.append(tmpContent+"\n");
}
}
m_strPageInfo.append("\n");
}
m_strPageInfo.chop(1);
}
void MouseInfo::updateInfoItems(QString strInfoJson)
{
m_rkeyMenu->clear();
QAction *copyAction = new QAction(tr("CopyAll"), this);
connect(copyAction, &QAction::triggered, this, [=](){KABaseInfoPage::onCopyContent(m_strPageInfo);});
m_rkeyMenu->addAction(copyAction);
if (strInfoJson.isEmpty())
return;
qInfo()<<"Cur info:"<<strInfoJson;
@ -166,6 +247,41 @@ void MouseInfo::updateInfoItems(QString strInfoJson)
QJsonObject subItemObj = arrayJson.at(n).toObject();
QJsonValue subItemValue = subItemObj.value(MSI_NAME);
if (subItemValue.isString()) {
QString strTitle= tr("Name");
QString strContent= subItemValue.toString();
if(tr("Name")==strTitle){
bool needAdd = true;
if(KABaseInfoPage::mouseStatus(strContent).contains("0")){
QAction *enableAction = new QAction(tr("Enable ")+strContent, this);
connect(enableAction, &QAction::triggered, this, [=](){KABaseInfoPage::enableMouse(strContent);});
QList<QAction *> actList = m_rkeyMenu->actions();
for(int i=0;i<actList.length();i++){
if((tr("Enable ")+strContent)==actList[i]->text()){
needAdd = false;
break;
}
}
if(needAdd){
m_rkeyMenu->addAction(enableAction);
}
continue;
}else{
QAction *disableAction = new QAction(tr("Disabled ")+strContent, this);
connect(disableAction, &QAction::triggered, this, [=](){KABaseInfoPage::disableMouse(strContent);});
QList<QAction *> actList = m_rkeyMenu->actions();
for(int i=0;i<actList.length();i++){
if((tr("Disabled ")+strContent)==actList[i]->text()){
needAdd = false;
break;
}
}
if(needAdd){
m_rkeyMenu->addAction(disableAction);
}
}
}
addInfoItems(n, MOUSEINFO_NAME, tr("Name"), subItemValue.toString(), bMulti);
}
// subItemValue = subItemObj.value(MSI_DEVTYPE);
@ -178,7 +294,11 @@ void MouseInfo::updateInfoItems(QString strInfoJson)
}
subItemValue = subItemObj.value(MSI_MANUFACTURER);
if (subItemValue.isString()) {
addInfoItems(n, MOUSEINFO_MANUFACTURER, tr("Manufacurer"), subItemValue.toString(), bMulti);
if(QString::fromLocal8Bit("0x0911") == subItemValue.toString() ){
addInfoItems(n, MOUSEINFO_MANUFACTURER, tr("Manufacurer"), QString::fromLocal8Bit("Hantick"), bMulti);
}else{
addInfoItems(n, MOUSEINFO_MANUFACTURER, tr("Manufacurer"), subItemValue.toString(), bMulti);
}
}
subItemValue = subItemObj.value(MSI_INTERFACE);
if (subItemValue.isString()) {
@ -211,6 +331,19 @@ void MouseInfo::chkNoDevice()
infoSize += itMapInfoItems.value().size();
}
if (infoSize == 0) {
addInfoItems(0, MOUSEINFO_INVALID, "", tr("Device not exitst or Get Device is Empty"), false);
QList<QAction *> actList = m_rkeyMenu->actions();
// 0表示Disabled 1表示Enable 2表示Enable 中
int btStatus = 1;
for(int i=0;i<actList.length();i++){
if(actList[i]->text().contains(tr("Enable "))){
btStatus = 0;
break;
}
}
if( 0 == btStatus ){
addInfoItems(0, MOUSEINFO_INVALID, "", tr("Mouse device disabled"), false);
}else{
addInfoItems(0, MOUSEINFO_INVALID, "", tr("Device not exitst or Get Device is Empty"), false);
}
}
}

View File

@ -26,6 +26,12 @@
#include <QScrollArea>
#include <QVBoxLayout>
#include <QMap>
#include <QMenu>
#include <QAction>
#include <QEvent>
#include <map>
#include <vector>
#include <QMouseEvent>
#include "../../src/kajsondef.h"
#include "kainfotitle.h"
@ -58,6 +64,9 @@ public slots:
void onUpdateInfo(QString strInfoJson) override;
void onRefreshInfo() override;
protected:
void mousePressEvent(QMouseEvent *event);
private:
void addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, QString strContent, bool bMulti);
void clearInfoItems();
@ -65,6 +74,11 @@ private:
private:
QString m_strInfoJson;
QString m_strPageInfo;
std::vector<QString> vecIndex;
std::vector<std::vector<QString>> vecItems;
std::map<QString, QString> mapPageInfo;
std::vector<std::map<QString, QString>> vecMapItems;
QVBoxLayout *m_mainLayout = nullptr;
QFrame *m_listFrame = nullptr;
@ -72,6 +86,7 @@ private:
QScrollArea *m_scrollFrame = nullptr;
QMap<unsigned,QMap<unsigned, QWidget*>> m_mapInfoItems;
QMenu *m_rkeyMenu = nullptr;
};
#endif // MOUSEINFO_H

View File

@ -20,6 +20,7 @@
#include "netcardinfo.h"
#include "dataworker.h"
#include "../../src/util.h"
#include <QDebug>
#include <QTimer>
@ -28,11 +29,13 @@
#include <QJsonDocument>
#include <QJsonArray>
#include <QScrollBar>
#include <kysdk/kysdk-base/kyutils.h>
NetCardInfo::NetCardInfo(QWidget *parent)
: KABaseInfoPage(parent)
{
m_strInfoJson = "";
m_strInfoLastJson = "";
initUI();
initConnections();
}
@ -58,8 +61,22 @@ void NetCardInfo::initUI()
m_scrollFrame->setWidgetResizable(true);
m_scrollFrame->setWidget(m_listFrame);
m_rkeyMenu = new QMenu(this);
QAction *copyAction = new QAction(tr("CopyAll"), this);
connect(copyAction, &QAction::triggered, this, [=](){KABaseInfoPage::onCopyContent(m_strPageInfo);});
m_rkeyMenu->addAction(copyAction);
m_mainLayout->addWidget(m_scrollFrame);
this->setLayout(m_mainLayout);
m_refreshInfoTimer = new QTimer(this);
}
void NetCardInfo::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
m_rkeyMenu->popup(event->globalPos());
}
KABaseInfoPage::mousePressEvent(event);
}
void NetCardInfo::onUpdateInfo(QString strInfoJson)
@ -89,6 +106,9 @@ void NetCardInfo::clearInfoItems()
}
itMapInfoItems.value().clear();
}
mapPageInfo.clear();
vecItems.clear();
vecMapItems.clear();
m_mapInfoItems.clear();
}
@ -114,13 +134,33 @@ void NetCardInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle,
listItem->setFixedWidth(666);
m_listLayout->addWidget(listItem);
itMapInfoItems.value()[uId] = listItem;
m_strPageInfo.append("|"+strTitle+"|"+strContent+"\n");
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
}
} else {
QMap<unsigned, QWidget*> mapItems;
if (bMulti) {
KAInfoTitle *infoTitle = new KAInfoTitle(QString("%1%2").arg(tr("Network Card")).arg(m_mapInfoItems.size()+1));
infoTitle->setMinimumHeight(30);
infoTitle->setMinimumHeight(50);
infoTitle->setFixedWidth(666);
m_listLayout->addWidget(infoTitle);
mapItems[NETCARDINFO_TITLE] = infoTitle;
@ -131,13 +171,84 @@ void NetCardInfo::addInfoItems(unsigned uGroup, unsigned uId, QString strTitle,
m_listLayout->addWidget(listItem);
mapItems[uId] = listItem;
m_mapInfoItems[uGroup] = mapItems;
if (vecMapItems.size() <= int(uGroup)){
mapPageInfo[QString::number(uId,10)] = strTitle+"|"+strContent;
vecMapItems.push_back(mapPageInfo);
}else{
vecMapItems[int(uGroup)][QString::number(uId,10)] = strTitle+"|"+strContent;
}
if(vecItems.size()==0){
vecItems.push_back(vecIndex);
}
if(vecItems.size() == int(uGroup)+1){
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
vecItems[int(uGroup)]=vecIndex;
}else{
vecIndex.clear();
vecIndex.push_back(QString::number(uId,10));
vecItems.push_back(vecIndex);
}
}
// 利用UID实现有序
m_strPageInfo.clear();
for(int j=0;j<vecMapItems.size();j++){
if(vecMapItems.size()>1){
m_strPageInfo.append(QString("%1%2").arg(tr("Network Card")).arg(j+1)+"\n");
}
std::map<QString, QString> temMap = vecMapItems[j];
for(int i=0;i<vecItems[j].size();i++){
if(temMap.count(vecItems[j][i])!=0){
QString tmpTitle = temMap[vecItems[j][i]].split("|")[0];
QString tmpContent = temMap[vecItems[j][i]].split("|")[1];
int length = tmpTitle.length();
m_strPageInfo.append(tmpTitle);
for(int i = length; i < KABaseInfoPage::getBlankNum(); i++){
m_strPageInfo.append(" ");
}
m_strPageInfo.append(tmpContent+"\n");
}
}
m_strPageInfo.append("\n");
}
m_strPageInfo.chop(1);
}
void NetCardInfo::updateInfoItems(QString strInfoJson)
{
if (strInfoJson.isEmpty())
return;
QStringList disableList = NetCardInfo::netCardStatus();
if(disableList.size() > 0 ){
for(int i = 0 ; i < disableList.size() ; i++){
if(disableList[i].contains("|")){
QString strProduct = disableList[i].split("|")[0];
QString strPciPath = disableList[i].split("|")[1];
if(!strProduct.isEmpty()){
bool needAdd = true;
QAction *disableAction = new QAction(tr("Enable ") + strProduct, this);
qDebug()<<"---------------------------------------"<<endl;
qDebug()<<strProduct<<endl;
connect(disableAction, &QAction::triggered, this, [=](){NetCardInfo::enableNetCard(disableList[i]);});
QList<QAction *> actList = m_rkeyMenu->actions();
for(int i = 0 ; i < actList.length() ; i++){
if((tr("Enable ") + strProduct) == actList[i]->text()){
needAdd = false;
}
if((tr("Disable ") + strProduct) == actList[i]->text()){
m_rkeyMenu->removeAction(actList[i]);
}
}
if(needAdd){
m_rkeyMenu->addAction(disableAction);
}
// addInfoItems(0, VOICECARDINFO_NAME, tr("Name"), strProduct, true);
// onRefreshInfo();
}
}
}
}
qInfo()<<"Cur info:"<<strInfoJson;
QJsonParseError jsonParseErr;
QJsonDocument rootDoc = QJsonDocument::fromJson(strInfoJson.toUtf8(), &jsonParseErr);//字符串格式化为JSON
@ -163,6 +274,26 @@ void NetCardInfo::updateInfoItems(QString strInfoJson)
QJsonObject subItemObj = arrayJson.at(n).toObject();
QJsonValue subItemValue = subItemObj.value(NWI_NAME);
if (subItemValue.isString()) {
QString strTitle= tr("Name");
QString strContent= subItemValue.toString();
if(tr("Name")==strTitle){
bool needAdd = true;
QAction *disableAction = new QAction(tr("Disable ")+strContent, this);
connect(disableAction, &QAction::triggered, this, [=](){NetCardInfo::disableNetCard(strContent);});
QList<QAction *> actList = m_rkeyMenu->actions();
for(int i=0;i<actList.length();i++){
if((tr("Disable ")+strContent)==actList[i]->text()){
needAdd = false;
}
if((tr("Enable ")+strContent)==actList[i]->text()){
m_rkeyMenu->removeAction(actList[i]);
}
}
if(needAdd){
m_rkeyMenu->addAction(disableAction);
}
}
addInfoItems(n, NETCARDINFO_NAME, tr("Name"), subItemValue.toString(), bMulti);
}
subItemValue = subItemObj.value(NWI_TYPE);
@ -222,11 +353,29 @@ void NetCardInfo::updateInfoItems(QString strInfoJson)
}
subItemValue = subItemObj.value(NWI_RECVBYTES);
if (subItemValue.isString()) {
addInfoItems(n, NETCARDINFO_RECVBYTES, tr("Bytes Received"), subItemValue.toString(), bMulti);
QString data = subItemValue.toString();
char result_data[128] = {0};
KDKVolumeBaseType unit = Util::getVolumeUnit(data);
char* volume = Util::getVolume(data,unit);
if(kdkVolumeBaseCharacterConvert(volume, unit, result_data) == KDK_NOERR){
addInfoItems(n, NETCARDINFO_RECVBYTES, tr("Bytes Received"), QString::fromUtf8(result_data), bMulti);
}else{
addInfoItems(n, NETCARDINFO_RECVBYTES, tr("Bytes Received"), subItemValue.toString(), bMulti);
}
}
subItemValue = subItemObj.value(NWI_SENDBYTES);
if (subItemValue.isString()) {
addInfoItems(n, NETCARDINFO_SENDBYTES, tr("Bytes Sent"), subItemValue.toString(), bMulti);
QString data = subItemValue.toString();
char result_data[128] = {0};
KDKVolumeBaseType unit = Util::getVolumeUnit(data);
char* volume = Util::getVolume(data,unit);
if(kdkVolumeBaseCharacterConvert(volume, unit, result_data) == KDK_NOERR){
addInfoItems(n, NETCARDINFO_SENDBYTES, tr("Bytes Sent"), QString::fromUtf8(result_data), bMulti);
}else{
addInfoItems(n, NETCARDINFO_SENDBYTES, tr("Bytes Sent"), subItemValue.toString(), bMulti);
}
}
}
}
@ -247,6 +396,168 @@ void NetCardInfo::chkNoDevice()
infoSize += itMapInfoItems.value().size();
}
if (infoSize == 0) {
addInfoItems(0, NETCARDINFO_INVALID, "", tr("Device not exitst or Get Device is Empty"), false);
QStringList disableList = NetCardInfo::netCardStatus();
if(disableList.size() > 0 ){
for(int i = 0 ; i < disableList.size() ; i++){
if(disableList[i].contains("|")){
QString strProduct = disableList[i].split("|")[0];
QString strPciPath = disableList[i].split("|")[1];
if(!strProduct.isEmpty()){
bool needAdd = true;
QAction *disableAction = new QAction(tr("Enable ") + strProduct, this);
connect(disableAction, &QAction::triggered, this, [=](){NetCardInfo::enableNetCard(disableList[i]);});
QList<QAction *> actList = m_rkeyMenu->actions();
for(int i = 0 ; i < actList.length() ; i++){
if((tr("Enable ") + strProduct) == actList[i]->text()){
needAdd = false;
}
if((tr("Disable ") + strProduct) == actList[i]->text()){
m_rkeyMenu->removeAction(actList[i]);
}
}
if(needAdd){
m_rkeyMenu->addAction(disableAction);
}
// addInfoItems(0, VOICECARDINFO_NAME, tr("Name"), strProduct, true);
// onRefreshInfo();
}
}
}
addInfoItems(0, NETCARDINFO_INVALID, "", tr("Network card device is disabled"), false);
}else{
addInfoItems(0, NETCARDINFO_INVALID, "", tr("Device not exitst or Get Device is Empty"), false);
}
}
}
void NetCardInfo::enterLoadingPage()
{
m_refreshInfoTimer->stop();
m_scrollFrame->hide();
m_loadWidget = new LoadWidget(m_strDevStatus);
m_loadWidget->setModal(true);
m_loadWidget->show();
}
void NetCardInfo::exitLoadingPage()
{
m_refreshInfoTimer->stop();
m_scrollFrame->show();
m_loadWidget->close();
}
void NetCardInfo::disableNetCard(QString strProduct)
{
m_strInfoLastJson = m_strInfoJson;
m_strDevStatus = "disable";
// 拉起加载中后重置status
enterLoadingPage();
m_strDevStatus = "";
qDebug()<<"--------------------"<<endl;
qDebug()<<strProduct<<endl;
QProcess p(0);
p.start("hwinfo --network");
p.waitForStarted();
p.waitForFinished();
QString sysPciPath = "";
QString strTemp=QString::fromLocal8Bit(p.readAllStandardOutput()); //获得输出
QStringList strList = strTemp.split("\n");
for(int i=0;i < strList.length();i++){
if(strList.at(i).contains(strProduct)){
// bus info 获取
qDebug()<<strList.at(i+1)<<endl;
if(strList.at(i+1).contains("SysFS Device Link")){
sysPciPath = ((QString)strList.at(i+1));
// /devices/pci0000:00/0000:00:14.3
if(sysPciPath.contains("/devices/pci0000:00") and !(sysPciPath.contains("usb"))){
sysPciPath = sysPciPath.replace(" SysFS Device Link: /devices/pci0000:00/","");
DataWorker::getInstance()->disableNetCard(strProduct,sysPciPath);
m_strDevStatus = "disable";
}else{
// sw架构单独处理
QProcess p(0);
p.start("uname -a");
p.waitForStarted();
p.waitForFinished();
QString strArchTemp=QString::fromLocal8Bit(p.readAllStandardOutput());
if(strArchTemp.contains("sw_64") and sysPciPath.contains("/devices/pci0000:02") and !(sysPciPath.contains("usb"))){
sysPciPath = sysPciPath.replace(" SysFS Device Link: /devices/pci0000:02/","");
DataWorker::getInstance()->disableNetCard(strProduct,sysPciPath);
m_strDevStatus = "disable";
}else{
break;
}
}
}else{
break;
}
qDebug()<<sysPciPath<<endl;
break;
}
}
qDebug() << ".......................";
qDebug() << m_strInfoLastJson;
// 当数据和上一次数据不同时,表示刷新完成
if(nullptr == m_refreshInfoTimer){
m_refreshInfoTimer = new QTimer();
}
if("" != m_strDevStatus){
QObject::connect(m_refreshInfoTimer, &QTimer::timeout, [&]() {
if( nullptr == m_strDevStatus || m_strInfoLastJson != m_strInfoJson ){
exitLoadingPage();
m_strInfoLastJson = m_strInfoJson;
m_strDevStatus = "";
}
onRefreshInfo();
});
m_refreshInfoTimer->start(5000); // Start timer with 1 second interval
//exitLoadingPage();
}else{
disableTooltip();
exitLoadingPage();
}
}
void NetCardInfo::enableNetCard(QString strProductAndPci)
{
m_strInfoLastJson = m_strInfoJson;
m_strDevStatus = "enable";
enterLoadingPage();
if(!strProductAndPci.isEmpty()){
DataWorker::getInstance()->enableNetCard(strProductAndPci);
// m_strDevStatus = "enable";
}
// 当数据和上一次数据不同时,表示刷新完成
// QTimer *timer = new QTimer();
if(nullptr == m_refreshInfoTimer){
m_refreshInfoTimer = new QTimer();
}
QObject::connect(m_refreshInfoTimer, &QTimer::timeout, [&]() {
if("" == m_strDevStatus || nullptr == m_strDevStatus || m_strInfoLastJson != m_strInfoJson ){
exitLoadingPage();
m_strInfoLastJson = m_strInfoJson;
m_strDevStatus = "";
}
onRefreshInfo();
});
m_refreshInfoTimer->start(5000); // Start timer with 1 second interval
}
/*
*/
QStringList NetCardInfo::netCardStatus()
{
QStringList disableList;
QProcess p(0);
p.start("cat /etc/youker-assistant/netCard");
p.waitForStarted();
p.waitForFinished();
QString strTemp=QString::fromLocal8Bit(p.readAllStandardOutput()); //获得输出
if(strTemp.isEmpty() || strTemp.contains("/etc/youker-assistant/netCard")){
return disableList;
}
disableList = strTemp.split("\n");
return disableList;
}

View File

@ -26,10 +26,17 @@
#include <QScrollArea>
#include <QVBoxLayout>
#include <QMap>
#include <QMenu>
#include <QAction>
#include <QEvent>
#include <map>
#include <vector>
#include <QMouseEvent>
#include "../../src/kajsondef.h"
#include "kainfotitle.h"
#include "kabaseinfopage.h"
#include "../../src/loadwidget.h"
enum NWI_INDEX{
NETCARDINFO_TITLE,
@ -66,20 +73,38 @@ public slots:
void onUpdateInfo(QString strInfoJson) override;
void onRefreshInfo() override;
protected:
void mousePressEvent(QMouseEvent *event);
private:
void addInfoItems(unsigned uGroup, unsigned uId, QString strTitle, QString strContent, bool bMulti);
void clearInfoItems();
void chkNoDevice();
void enterLoadingPage();
void exitLoadingPage();
void disableNetCard(QString strProduct);
void enableNetCard(QString strProduct);
QStringList netCardStatus();
private:
QString m_strInfoJson;
QString m_strPageInfo;
QString m_strInfoLastJson;
QString m_strDevStatus = nullptr;
std::vector<QString> vecIndex;
std::vector<std::vector<QString>> vecItems;
std::map<QString, QString> mapPageInfo;
std::vector<std::map<QString, QString>> vecMapItems;
QVBoxLayout *m_mainLayout = nullptr;
QFrame *m_listFrame = nullptr;
QVBoxLayout *m_listLayout = nullptr;
QScrollArea *m_scrollFrame = nullptr;
LoadWidget *m_loadWidget = nullptr;
QMap<unsigned,QMap<unsigned, QWidget*>> m_mapInfoItems;
QMenu *m_rkeyMenu = nullptr;
QTimer *m_refreshInfoTimer = nullptr;
};
#endif // NETCARDINFO_H

View File

@ -20,6 +20,7 @@
#include "processorinfo.h"
#include "dataworker.h"
#include "../../src/util.h"
#include <QDebug>
#include <QTimer>
@ -27,6 +28,7 @@
#include <QJsonObject>
#include <QJsonDocument>
#include <QScrollBar>
#include <kysdk/kysdk-base/kyutils.h>
ProcessorInfo::ProcessorInfo(QWidget *parent)
: KABaseInfoPage(parent)
@ -57,10 +59,23 @@ void ProcessorInfo::initUI()
m_scrollFrame->setWidgetResizable(true);
m_scrollFrame->setWidget(m_listFrame);
m_rkeyMenu = new QMenu(this);
QAction *copyAction = new QAction(tr("CopyAll"), this);
connect(copyAction, &QAction::triggered, this, [=](){KABaseInfoPage::onCopyContent(m_strPageInfo);});
m_rkeyMenu->addAction(copyAction);
m_mainLayout->addWidget(m_scrollFrame);
this->setLayout(m_mainLayout);
}
void ProcessorInfo::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::RightButton) {
m_rkeyMenu->popup(event->globalPos());
}
KABaseInfoPage::mousePressEvent(event);
}
void ProcessorInfo::onUpdateInfo(QString strInfoJson)
{
m_strInfoJson = strInfoJson;
@ -98,6 +113,24 @@ void ProcessorInfo::addInfoItems(unsigned uId, QString strTitle, QString strCont
listItem->setFixedWidth(666);
m_listLayout->addWidget(listItem);
m_mapItem[uId] = listItem;
mapPageInfo.insert(std::pair<QString, QString>( QString::number(uId,10),strTitle+"|"+strContent));
if (!(std::find(vecIndex.begin(),vecIndex.end(),QString::number(uId,10))!=vecIndex.end())){
vecIndex.push_back(QString::number(uId,10));
}
}
// 利用UID实现有序
m_strPageInfo.clear();
for(int i=0;i<vecIndex.size();i++){
if(mapPageInfo.count(vecIndex[i])!=0){
QString tmpTitle = mapPageInfo[vecIndex[i]].split("|")[0];
QString tmpContent = mapPageInfo[vecIndex[i]].split("|")[1];
int length = tmpTitle.length();
m_strPageInfo.append(tmpTitle);
for(int i = length; i < KABaseInfoPage::getBlankNum(); i++){
m_strPageInfo.append(" ");
}
m_strPageInfo.append(tmpContent+"\n");
}
}
}
@ -160,19 +193,55 @@ void ProcessorInfo::updateInfoItems(QString strInfoJson)
}
valJson = rootObj.value(PSI_L1DCACHE);
if (valJson.isString()) {
addInfoItems(PROCESSORINFO_L1DCACHE, tr("L1d Cache"), valJson.toString());
QString data = valJson.toString();
char result_data[128] = {0};
KDKVolumeBaseType unit = Util::getVolumeUnit(data);
char* volume = Util::getVolume(data,unit);
if(kdkVolumeBaseCharacterConvert(volume, unit, result_data) == KDK_NOERR){
addInfoItems(PROCESSORINFO_L1DCACHE, tr("L1d Cache"), QString::fromUtf8(result_data));
}else{
addInfoItems(PROCESSORINFO_L1DCACHE, tr("L1d Cache"), valJson.toString());
}
}
valJson = rootObj.value(PSI_L1ICACHE);
if (valJson.isString()) {
addInfoItems(PROCESSORINFO_L1ICACHE, tr("L1i Cache"), valJson.toString());
QString data = valJson.toString();
char result_data[128] = {0};
KDKVolumeBaseType unit = Util::getVolumeUnit(data);
char* volume = Util::getVolume(data,unit);
if(kdkVolumeBaseCharacterConvert(volume, unit, result_data) == KDK_NOERR){
addInfoItems(PROCESSORINFO_L1ICACHE, tr("L1i Cache"), QString::fromUtf8(result_data));
}else{
addInfoItems(PROCESSORINFO_L1ICACHE, tr("L1i Cache"), valJson.toString());
}
}
valJson = rootObj.value(PSI_L2CACHE);
if (valJson.isString()) {
addInfoItems(PROCESSORINFO_L2CACHE, tr("L2 Cache"), valJson.toString());
QString data = valJson.toString();
char result_data[128] = {0};
KDKVolumeBaseType unit = Util::getVolumeUnit(data);
char* volume = Util::getVolume(data,unit);
if(kdkVolumeBaseCharacterConvert(volume, unit, result_data) == KDK_NOERR){
addInfoItems(PROCESSORINFO_L2CACHE, tr("L2 Cache"), QString::fromUtf8(result_data));
}else{
addInfoItems(PROCESSORINFO_L2CACHE, tr("L2 Cache"), valJson.toString());
}
}
valJson = rootObj.value(PSI_L3CACHE);
if (valJson.isString()) {
addInfoItems(PROCESSORINFO_L3CACHE, tr("L3 Cache"), valJson.toString());
QString data = valJson.toString();
char result_data[128] = {0};
KDKVolumeBaseType unit = Util::getVolumeUnit(data);
char* volume = Util::getVolume(data,unit);
if(kdkVolumeBaseCharacterConvert(volume, unit, result_data) == KDK_NOERR){
addInfoItems(PROCESSORINFO_L3CACHE, tr("L3 Cache"), QString::fromUtf8(result_data));
}else{
addInfoItems(PROCESSORINFO_L3CACHE, tr("L3 Cache"), valJson.toString());
}
}
valJson = rootObj.value(PSI_INSTSET);
if (valJson.isString()) {

View File

@ -26,6 +26,12 @@
#include <QScrollArea>
#include <QVBoxLayout>
#include <QMap>
#include <QMenu>
#include <QAction>
#include <QEvent>
#include <map>
#include <vector>
#include <QMouseEvent>
#include "../../src/kajsondef.h"
#include "kabaseinfopage.h"
@ -65,12 +71,18 @@ public slots:
void onUpdateInfo(QString strInfoJson) override;
void onRefreshInfo() override;
protected:
void mousePressEvent(QMouseEvent *event);
private:
void addInfoItems(unsigned uId, QString strTitle, QString strContent);
void clearInfoItems();
private:
QString m_strInfoJson;
QString m_strPageInfo;
std::vector<QString> vecIndex;
std::map<QString, QString> mapPageInfo;
QVBoxLayout *m_mainLayout = nullptr;
QFrame *m_listFrame = nullptr;
@ -78,6 +90,7 @@ private:
QScrollArea *m_scrollFrame = nullptr;
QMap<unsigned, KInfoListItem*> m_mapItem;
QMenu *m_rkeyMenu = nullptr;
};
#endif // PROCESSORINFO_H

Some files were not shown because too many files have changed in this diff Show More