新增.h文件
This commit is contained in:
parent
cbb7510d99
commit
fed4a8edef
34
aptpkginfo.cpp
Normal file
34
aptpkginfo.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include "aptpkginfo.h"
|
||||
|
||||
AptPkgInfo::AptPkgInfo()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QStringList AptPkgInfo::GetAptPackageList(QString name)
|
||||
{
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
env.insert("LANG", "en");
|
||||
QString data = GetCommandResult("apt", QStringList() << "list" << name, env);
|
||||
QStringList lineData = data.split("\n");
|
||||
QStringList result = {};
|
||||
for(QString i: lineData) {
|
||||
if(i.contains("Listing...")) {
|
||||
continue;
|
||||
}
|
||||
result.append(i.split("/").at(0));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QByteArray AptPkgInfo::GetCommandResult(QString command, QStringList argv, QProcessEnvironment env)
|
||||
{
|
||||
QProcess process;
|
||||
process.setProcessEnvironment(env);
|
||||
process.start(command, argv);
|
||||
process.waitForStarted();
|
||||
process.waitForFinished();
|
||||
QByteArray result = process.readAllStandardOutput();
|
||||
process.close();
|
||||
return result;
|
||||
}
|
17
aptpkginfo.h
Normal file
17
aptpkginfo.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef APTPKGINFO_H
|
||||
#define APTPKGINFO_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QProcess>
|
||||
|
||||
class AptPkgInfo: QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
AptPkgInfo(QString pkgName);
|
||||
|
||||
QStringList GetAptPackageList(QString name);
|
||||
QByteArray GetCommandResult(QString command, QStringList argv, QProcessEnvironment env = QProcessEnvironment::systemEnvironment());
|
||||
};
|
||||
|
||||
#endif // APTPKGINFO_H
|
@ -10,6 +10,7 @@ CONFIG += c++17
|
||||
|
||||
SOURCES += \
|
||||
aboutwindow.cpp \
|
||||
aptpkginfo.cpp \
|
||||
kernelinformation.cpp \
|
||||
kernelinstaller.cpp \
|
||||
main.cpp \
|
||||
@ -17,6 +18,7 @@ SOURCES += \
|
||||
|
||||
HEADERS += \
|
||||
aboutwindow.h \
|
||||
aptpkginfo.h \
|
||||
kernelinformation.h \
|
||||
kernelinstaller.h \
|
||||
mainwindow.h
|
||||
|
@ -7,38 +7,13 @@ KernelInformation::KernelInformation()
|
||||
|
||||
}
|
||||
|
||||
QStringList KernelInformation::GetAptPackageList(QString name)
|
||||
{
|
||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||
env.insert("LANG", "en");
|
||||
QString data = GetCommandResult("apt", QStringList() << "list" << name, env);
|
||||
QStringList lineData = data.split("\n");
|
||||
QStringList result = {};
|
||||
for(QString i: lineData) {
|
||||
if(i.contains("Listing...")) {
|
||||
continue;
|
||||
}
|
||||
result.append(i.split("/").at(0));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QByteArray KernelInformation::GetCommandResult(QString command, QStringList argv, QProcessEnvironment env)
|
||||
{
|
||||
QProcess process;
|
||||
process.setProcessEnvironment(env);
|
||||
process.start(command, argv);
|
||||
process.waitForStarted();
|
||||
process.waitForFinished();
|
||||
QByteArray result = process.readAllStandardOutput();
|
||||
process.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
void KernelInformation::LoadInfo()
|
||||
{
|
||||
// 从 apt 获取信息
|
||||
qDebug() << this->GetAptPackageList("linux-*");
|
||||
//QStringList data = this->GetAptPackageList("linux-*");
|
||||
/*for(QString i: data) {
|
||||
|
||||
}*/
|
||||
// 从 Github 拉取信息
|
||||
QUrl url(this->url);
|
||||
QUrlQuery query;
|
||||
|
@ -47,8 +47,7 @@ private:
|
||||
QString url = "http://info.kernel.gxde.gfdgdxi.top/information.json";
|
||||
QJsonArray listData;
|
||||
|
||||
QStringList GetAptPackageList(QString name);
|
||||
QByteArray GetCommandResult(QString command, QStringList argv, QProcessEnvironment env = QProcessEnvironment::systemEnvironment());
|
||||
|
||||
};
|
||||
|
||||
#endif // KERNELINFORMATION_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user