Skip to content

Commit

Permalink
fix: Optimize command line acquisition parameters
Browse files Browse the repository at this point in the history
Optimize command line acquisition parameters

Log: Optimize command line acquisition parameters
Task: https://pms.uniontech.com/task-view-362613.html
  • Loading branch information
lzwind authored and deepin-bot[bot] committed Sep 24, 2024
1 parent ef2f97b commit 732c3c6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 33 deletions.
18 changes: 12 additions & 6 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,16 +409,22 @@ void Utils::getAllWindowInfo(const quint32 winId, const int width, const int hei

bool Utils::checkCpuIsZhaoxin()
{
QStringList options;
options << "-c";
options << "lscpu | grep 'CentaurHauls'";
QProcess process;
process.start("bash", options);
process.start("lscpu");
process.waitForFinished();
process.waitForReadyRead();
QString str_output = process.readAllStandardOutput();
QString comStr = process.readAllStandardOutput();
process.close();
if (str_output.length() == 0) {
QStringList lines = comStr.split('\n');
QStringList filteredLines;

// 过滤包含指定关键字的行
for (const QString &line : lines) {
if (line.contains("CentaurHauls", Qt::CaseInsensitive)) {
filteredLines.append(line);
}
}
if (filteredLines.isEmpty()) {
return false;
}
return true;
Expand Down
26 changes: 20 additions & 6 deletions src/utils/audioutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,31 @@ QString AudioUtils::currentAudioChannel()
);
if (defaultSink->isValid()) {
QString sinkName = defaultSink->name();
QStringList options;
options << "-c";
options << QString("pacmd list-sources | grep -PB 1 %1 | head -n 1 | perl -pe 's/.* //g'").arg(sinkName);
QString command = QString("pacmd list-sources");

QProcess process;
process.start("bash", options);
process.start(command);
process.waitForFinished();
process.waitForReadyRead();
QString str_output = process.readAllStandardOutput();
qDebug() << options << str_output;
return str_output;

QStringList lines = str_output.split("\n");
QString targetLine;
for (int i = 0; i < lines.size(); i++) {
if (lines[i].contains(sinkName)) {
if (i > 0) {
targetLine = lines[i - 1];
break;
}
}
}

if (!targetLine.isEmpty()) {
targetLine.remove(QRegExp(".* "));
}

qDebug() << command << targetLine;
return targetLine;
}
return "";
}
Expand Down
26 changes: 18 additions & 8 deletions src/waylandrecord/avinputstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,16 +605,26 @@ bool CAVInputStream::GetAudioSCardInputInfo(AVSampleFormat &sample_fmt, int &sa

QString CAVInputStream::currentAudioChannel()
{
QStringList options;
options << QString(QStringLiteral("-c"));
options << QString(QStringLiteral("pacmd list-sources | grep -PB 1 'analog.*monitor>' | head -n 1 | perl -pe 's/.* //g'"));
QString command = QString("pacmd list-sources");
QProcess process;
process.start(QString(QStringLiteral("bash")), options);
process.start(command);
process.waitForFinished();
process.waitForReadyRead();
QByteArray tempArray = process.readAllStandardOutput();
char *charTemp = tempArray.data();
QString str_output = QString(QLatin1String(charTemp));
QString str_output = process.readAllStandardOutput();

QStringList lines = str_output.split("\n");
QString targetLine;
for (int i = 0; i < lines.size(); i++) {
if (lines[i].contains("analog") && lines[i].contains("monitor")) {
targetLine = lines[i];
break;
}
}

if (!targetLine.isEmpty()) {
targetLine.remove(QRegExp(".* "));
}

process.close();
return str_output;
return targetLine;
}
18 changes: 5 additions & 13 deletions src/waylandrecord/waylandintegration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,27 +376,19 @@ int WaylandIntegration::WaylandIntegrationPrivate::getProductType()
return Utils::specialRecordingScreenMode;
}
qInfo() << "Special screen recording mode is not supported!";
QStringList options;
options << QString(QStringLiteral("-c"));
options << QString(QStringLiteral("dmidecode -s system-product-name|awk '{print $NF}'"));
QProcess process;
process.start(QString(QStringLiteral("bash")), options);
process.start("dmidecode", QStringList() << "-s" << "system-product-name");
process.waitForFinished();
process.waitForReadyRead();
QByteArray tempArray = process.readAllStandardOutput();
char *charTemp = tempArray.data();
QString str_output = QString(QLatin1String(charTemp));
process.close();
QByteArray tempArray = process.readAllStandardOutput();
QString str_output = QString(QLatin1String(tempArray.data()));
qInfo() << "system-product-name: " << str_output;

options.clear();
options << QString(QStringLiteral("-c"));
options << QString(QStringLiteral("dmidecode | grep -i \"String 4\""));
process.start(QString(QStringLiteral("bash")), options);
process.start("dmidecode");
process.waitForFinished();
process.waitForReadyRead();
QString str_output1 = QString(QLatin1String(process.readAllStandardOutput().data()));
qInfo() << "dmidecode | grep -i \"String 4\": " << str_output1;
qInfo() << "dmidecode: " << str_output1;

if (str_output.contains("KLVV", Qt::CaseInsensitive) ||
str_output.contains("KLVU", Qt::CaseInsensitive) ||
Expand Down

0 comments on commit 732c3c6

Please sign in to comment.