Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ bool ControlInterface::enable(const QString &hclass, const QString &name, const

// 先从数据库中查找路径,防止设备更换usb接口
QString sPath = EnableSqlManager::getInstance()->authorizedPath(value);
if (sPath.isEmpty()) {
sPath = path;
}
sPath = path;

// 判断是内置设备,还是外设,内置设备通过remove文件禁用,外设通过authorized文件禁用
bool res = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,20 @@
}
}

void EnableSqlManager::insertDataToAuthorizedTable(const QString &hclass, const QString &name, const QString &path, const QString &unique_id, bool exist, const QString &strDriver)

Check warning on line 52 in deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/enablesqlmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'insertDataToAuthorizedTable' is never used.
{
// 数据库已经存在该设备记录
if (uniqueIDExistedEX(unique_id)) {
if (uniqueIDExistedEX(unique_id, path)) {
return;
}

// 数据库没有该设备记录,则直接插入
// QString sql = QString("INSERT INTO %1 (class, name, path, unique_id, exist, driver) VALUES (%2, %3, %4, %5, %6, %7);")
// .arg(DB_TABLE_AUTHORIZED).arg(":hclass").arg(":name").arg(":path").arg(":unique_id").arg(":exist").arg(":strDriver");
if(!m_sqlQuery.prepare("INSERT INTO authorized (class, name, path, unique_id, exist, driver) VALUES (:hclass, :name, :path, :unique_id, :exist, :strDriver);")) return;
if(!m_sqlQuery.prepare("INSERT INTO authorized (class, name, path, unique_id, exist, driver) VALUES (:hclass, :name, :path, :unique_id, :exist, :strDriver);")){
qDebug() << "insert data to authorized table failed";
return;
}
m_sqlQuery.bindValue(":hclass", QVariant(hclass));
m_sqlQuery.bindValue(":name", QVariant(name));
m_sqlQuery.bindValue(":path", QVariant(path));
Expand Down Expand Up @@ -124,24 +127,30 @@
}
}

bool EnableSqlManager::uniqueIDExisted(const QString &key)
bool EnableSqlManager::uniqueIDExisted(const QString &key, const QString path)

Check warning on line 130 in deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/enablesqlmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Parameter 'path' is passed by value. It could be passed as a const reference which is usually faster and recommended in C++.
{
qCDebug(appLog) << "Checking if unique ID exists:" << key;
QString sql = QString("SELECT COUNT(*) FROM %1 WHERE unique_id=%2;").arg(DB_TABLE_AUTHORIZED).arg(":param");
if (!path.isEmpty()){
sql = QString("SELECT COUNT(*) FROM %1 WHERE unique_id=%2 and path=%3;").arg(DB_TABLE_AUTHORIZED).arg(":param").arg(":path");
}
if(!m_sqlQuery.prepare(sql)) return false;
m_sqlQuery.bindValue(":param", QVariant(key));
if (!path.isEmpty()){
m_sqlQuery.bindValue(":path", QVariant(path));
}
if (m_sqlQuery.exec() && m_sqlQuery.next()) {
return m_sqlQuery.value(0).toInt() > 0;
}
return false;
}

bool EnableSqlManager::uniqueIDExistedEX(const QString &key)
bool EnableSqlManager::uniqueIDExistedEX(const QString &key, const QString path)

Check warning on line 148 in deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/enablesqlmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Parameter 'path' is passed by value. It could be passed as a const reference which is usually faster and recommended in C++.
{
return uniqueIDExisted(key);
return uniqueIDExisted(key, path);
}

bool EnableSqlManager::isUniqueIdEnabled(const QString &key)

Check warning on line 153 in deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/enablesqlmanager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'isUniqueIdEnabled' is never used.
{
qCDebug(appLog) << "Checking if unique ID is enabled:" << key;
QString sql = QString("SELECT enable FROM %1 WHERE unique_id='%2';").arg(DB_TABLE_AUTHORIZED).arg(":key");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@
* @param key
* @return
*/
bool uniqueIDExisted(const QString &key);
bool uniqueIDExisted(const QString &key, const QString path = "");

Check warning on line 93 in deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/enablesqlmanager.h

View workflow job for this annotation

GitHub Actions / cppcheck

Parameter 'path' is passed by value. It could be passed as a const reference which is usually faster and recommended in C++.

/**
* @brief uniqueIDExistedForEnable
* @param key
* @return
*/
bool uniqueIDExistedEX(const QString &key);
bool uniqueIDExistedEX(const QString &key, const QString path = "");

Check warning on line 100 in deepin-devicemanager-server/deepin-devicecontrol/src/enablecontrol/enablesqlmanager.h

View workflow job for this annotation

GitHub Actions / cppcheck

Parameter 'path' is passed by value. It could be passed as a const reference which is usually faster and recommended in C++.

/**
* @brief isUniqueIdEnabled 判断设备是否被禁用了
Expand Down
2 changes: 1 addition & 1 deletion deepin-devicemanager/src/DeviceManager/DeviceAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ const QString &DeviceAudio::driver() const
const QString &DeviceAudio::uniqueID() const
{
qCDebug(appLog) << "DeviceAudio::uniqueID called.";
return m_SysPath;
return m_UniqueID;
}
EnableDeviceStatus DeviceAudio::setEnable(bool e)
{
Expand Down
10 changes: 10 additions & 0 deletions deepin-devicemanager/src/DeviceManager/DeviceInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1487,3 +1487,13 @@ void DeviceBaseInfo::generatorTranslate()
<< tr("Vendor") \
<< tr("Processor");
}

void DeviceBaseInfo::setSysPath(const QString &newSysPath)
{
m_SysPath = newSysPath;
}

void DeviceBaseInfo::setUniqueID(const QString &UniqueID)
{
m_UniqueID = UniqueID;
}
3 changes: 3 additions & 0 deletions deepin-devicemanager/src/DeviceManager/DeviceInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ class DeviceBaseInfo : public QObject
*/
TomlFixMethod setInfoFromTomlBase(const QMap<QString, QString> &mapInfo);

void setUniqueID(const QString &UniqueID);
void setSysPath(const QString &newSysPath);

protected:
/**
* @brief:初始化过滤信息
Expand Down
78 changes: 67 additions & 11 deletions deepin-devicemanager/src/DeviceManager/DeviceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
#include "DDLog.h"

// Qt库文件
#include <QLoggingCategory>

Check warning on line 10 in deepin-devicemanager/src/DeviceManager/DeviceManager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QLoggingCategory> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QFile>

Check warning on line 11 in deepin-devicemanager/src/DeviceManager/DeviceManager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QFile> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QFileInfo>

Check warning on line 12 in deepin-devicemanager/src/DeviceManager/DeviceManager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QFileInfo> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QMutexLocker>

Check warning on line 13 in deepin-devicemanager/src/DeviceManager/DeviceManager.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QMutexLocker> not found. Please note: Cppcheck does not need standard library headers to get proper results.

// 其它头文件
#include "DeviceCpu.h"
Expand Down Expand Up @@ -1233,22 +1234,77 @@
void DeviceManager::deleteDisableDuplicate_AudioDevice(void)
{
qCDebug(appLog) << "Deleting disable duplicate audio device";
if (m_ListDeviceAudio.size() > 0) {
for (QList<DeviceBaseInfo *>::iterator it = m_ListDeviceAudio.begin(); it != m_ListDeviceAudio.end(); ++it) {
DeviceAudio *audio_1 = dynamic_cast<DeviceAudio *>(*it);
//QString tpath = audio_1->uniqueID();
// 判断该设备是否已经存在,
if (!audio_1->enable()) {
for (QList<DeviceBaseInfo *>::iterator it2 = m_ListDeviceAudio.begin(); it2 != m_ListDeviceAudio.end(); ++it2) {
DeviceAudio *audio_2 = dynamic_cast<DeviceAudio *>(*it2);
if (audio_2->name() == audio_1->name())
if (audio_2->enable())
m_ListDeviceAudio.removeOne(audio_2);
QHash<QString, DeviceAudio*> enabledDevices;
QHash<QString, int> enableDevicePriority;
for (auto it = m_ListDeviceAudio.begin(); it != m_ListDeviceAudio.end(); ++it) {
DeviceAudio* audio = dynamic_cast<DeviceAudio*>(*it);
if (!audio) {
continue;
}
if (audio->enable() || !enabledDevices.contains(audio->uniqueID())) {
enabledDevices[audio->uniqueID()] = audio;
if (!enableDevicePriority.contains(audio->uniqueID())) {
if (audio->enable() || ! audio->driver().contains("usb")) {
enableDevicePriority.insert(audio->uniqueID(), 2);
} else {
enableDevicePriority.insert(audio->uniqueID(), 1);
}
} else {
enableDevicePriority[audio->uniqueID()] = enableDevicePriority[audio->uniqueID()] + 1;
}
} else {
if (enabledDevices.contains(audio->uniqueID()) && enabledDevices[audio->uniqueID()]->enable()) {
if (!enableDevicePriority.contains(audio->uniqueID())) {
if (audio->enable()) {
enableDevicePriority.insert(audio->uniqueID(), 2);
} else {
enableDevicePriority.insert(audio->uniqueID(), 1);
}
} else {
enableDevicePriority[audio->uniqueID()] = enableDevicePriority[audio->uniqueID()] + 1;
}
audio->setSysPath(enabledDevices[audio->uniqueID()]->sysPath());
delete enabledDevices[audio->uniqueID()];
enabledDevices[audio->uniqueID()] = audio;
}
}
}
qWarning()<<"delete before: "<< m_ListDeviceAudio.size();
qWarning() << enableDevicePriority;
m_ListDeviceAudio.clear();
for(auto it : enabledDevices.keys()){
if (enableDevicePriority.value(it) <= 1) {
continue;
}
m_ListDeviceAudio.push_back(enabledDevices.value(it));

setAudioDeviceEnable(enabledDevices.value(it), enabledDevices.value(it)->enable());
}
qWarning()<<"delete after: "<< m_ListDeviceAudio.size();
}

void DeviceManager::setAudioDeviceEnable(DeviceAudio * const devivce, bool enable)
{
EnableDeviceStatus status ;

int i = 0;
do{
status = devivce->setEnable(enable);
if (status == EDS_Success) {
break;
}
qWarning() << "retry: " << ++i;
}while (i < 3);

qWarning() << [](EnableDeviceStatus status) {
switch(status) {
case EDS_Cancle: return "Device enable operation was cancelled";
case EDS_NoSerial: return "Device enable failed: No serial number available";
case EDS_Faild: return "-----Device enable failed due to unknown error";
case EDS_Success: return "Device enabled successfully";
default: return "Unknown device enable status";
}
}(status);
}

DeviceBaseInfo *DeviceManager::getAudioDevice(const QString &path)
Expand Down
2 changes: 2 additions & 0 deletions deepin-devicemanager/src/DeviceManager/DeviceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ class DeviceManager : public QObject
*/
void deleteDisableDuplicate_AudioDevice(void);

void setAudioDeviceEnable(DeviceAudio *const devivce, bool enable);

/**
* @brief getAudioDevice 获取音频设备
* @param path
Expand Down
2 changes: 1 addition & 1 deletion deepin-devicemanager/src/GenerateDevice/CmdTool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ void CmdTool::getMulHwinfoInfo(const QString &info)
}
QMap<QString, QString> mapInfo;
getMapInfoFromHwinfo(item, mapInfo);
if (mapInfo["Hardware Class"] == "sound" || mapInfo["Device"].contains("USB Audio")) {
if (mapInfo["Hardware Class"] == "sound" || (mapInfo["Device"].contains("USB Audio") && mapInfo["Device"].contains("snd-usb-audio"))) {
qCDebug(appLog) << "Found sound device.";
// mapInfo["Device"].contains("USB Audio") 是为了处理未识别的USB声卡 Bug-118773
addMapInfo("hwinfo_sound", mapInfo);
Expand Down
8 changes: 6 additions & 2 deletions deepin-devicemanager/src/GenerateDevice/DeviceGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -889,18 +889,22 @@ void DeviceGenerator::getAudioInfoFromHwinfo()

QString path = pciPath(*it);
DeviceAudio *device = dynamic_cast<DeviceAudio *>(DeviceManager::instance()->getAudioDevice(path));
if (device) {
if (device && (*it).size() != 5) {
// qCDebug(appLog) << "Found existing audio device, setting enable value to false.";
device->setEnableValue(false);
continue;
}

device = new DeviceAudio();
device->setInfoFromHwinfo(*it);
if ((*it).size() == 5 && (*it).find("unique_id") != (*it).end()) {
device->setEnableValue(false);
device->setUniqueID((*it)["unique_id"]);
}
DeviceManager::instance()->addAudioDevice(device);
addBusIDFromHwinfo((*it)["SysFS BusID"]);
}
DeviceManager::instance()->deleteDisableDuplicate_AudioDevice();
// DeviceManager::instance()->deleteDisableDuplicate_AudioDevice();
qCDebug(appLog) << "DeviceGenerator::getAudioInfoFromHwinfo end";
}

Expand Down
2 changes: 1 addition & 1 deletion deepin-devicemanager/src/Page/PageListView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ PageListView::PageListView(DWidget *parent)
hLayout->setContentsMargins(0, 0, 0, 0);
setLayout(hLayout);

this->setFixedWidth(152);
this->setFixedWidth(172);
// 初始化右键菜单
mp_ListView->setContextMenuPolicy(Qt::CustomContextMenu);
connect(mp_ListView, SIGNAL(customContextMenuRequested(const QPoint &)),
Expand Down
2 changes: 1 addition & 1 deletion deepin-devicemanager/translations/deepin-devicemanager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@
<location filename="../src/DeviceManager/DeviceManager.cpp" line="227"/>
<location filename="../src/DeviceManager/DeviceManager.cpp" line="277"/>
<source>Mouse</source>
<translation>Mouse</translation>
<translation>Mouse and Pointer Devices</translation>
</message>
<message>
<location filename="../src/DeviceManager/DeviceManager.cpp" line="232"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@
<location filename="../src/DeviceManager/DeviceManager.cpp" line="227"/>
<location filename="../src/DeviceManager/DeviceManager.cpp" line="277"/>
<source>Mouse</source>
<translation>鼠标</translation>
<translation>鼠标与指针设备</translation>
</message>
<message>
<location filename="../src/DeviceManager/DeviceManager.cpp" line="232"/>
Expand Down