初步支持从apt源获取数据(暂不可用)
This commit is contained in:
parent
fed4a8edef
commit
3c1b2ae424
@ -1,11 +1,86 @@
|
|||||||
#include "aptpkginfo.h"
|
#include "aptpkginfo.h"
|
||||||
|
#include <QFile>
|
||||||
|
#include <QDir>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
AptPkgInfo::AptPkgInfo()
|
AptPkgInfo::AptPkgInfo(QString pkgName)
|
||||||
{
|
{
|
||||||
|
SetPkgName(pkgName);
|
||||||
|
ReadAptData();
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList AptPkgInfo::GetAptPackageList(QString name)
|
void AptPkgInfo::ReadAptData()
|
||||||
|
{
|
||||||
|
this->aptData = "";
|
||||||
|
QDir dir("/var/lib/apt/lists/");
|
||||||
|
QStringList list = dir.entryList();
|
||||||
|
for(QString i: list) {
|
||||||
|
// 除去 . 和 ..
|
||||||
|
if(i == "." || i == "..") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// TODO: bug
|
||||||
|
if(i.mid(-10, -1) != "_Packages") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
QFile file(dir.path() + "/" + i);
|
||||||
|
file.open(QFile::ReadOnly);
|
||||||
|
aptData += file.readAll() + "\n";
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
qDebug() << aptData;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AptPkgInfo::SetPkgName(QString pkgName)
|
||||||
|
{
|
||||||
|
this->pkgName = pkgName;
|
||||||
|
pkgInfo = GetPkgInfo(pkgName);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString AptPkgInfo::GetPkgInfo(QString pkgName) const
|
||||||
|
{
|
||||||
|
if(pkgName == NULL) {
|
||||||
|
pkgName = this->pkgName;
|
||||||
|
}
|
||||||
|
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||||
|
env.insert("LANG", "en");
|
||||||
|
return this->GetCommandResult("apt", QStringList() << "list" << pkgName, env);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString AptPkgInfo::get_package() const
|
||||||
|
{
|
||||||
|
QStringList list = pkgInfo.split("\n");
|
||||||
|
for(QString i: list) {
|
||||||
|
if(i.contains("Package: ")) {
|
||||||
|
return i.replace("Package: ", "").replace(" ", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString AptPkgInfo::get_version() const
|
||||||
|
{
|
||||||
|
QStringList list = pkgInfo.split("\n");
|
||||||
|
for(QString i: list) {
|
||||||
|
if(i.contains("Maintainer: ")) {
|
||||||
|
return i.replace("Maintainer: ", "").replace(" ", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString AptPkgInfo::get_maintainer() const
|
||||||
|
{
|
||||||
|
QStringList list = pkgInfo.split("\n");
|
||||||
|
for(QString i: list) {
|
||||||
|
if(i.contains("Version: ")) {
|
||||||
|
return i.replace("Version: ", "").replace(" ", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList AptPkgInfo::GetAptPackageList(QString name) const
|
||||||
{
|
{
|
||||||
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
|
||||||
env.insert("LANG", "en");
|
env.insert("LANG", "en");
|
||||||
@ -21,7 +96,7 @@ QStringList AptPkgInfo::GetAptPackageList(QString name)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray AptPkgInfo::GetCommandResult(QString command, QStringList argv, QProcessEnvironment env)
|
QByteArray AptPkgInfo::GetCommandResult(QString command, QStringList argv, QProcessEnvironment env) const
|
||||||
{
|
{
|
||||||
QProcess process;
|
QProcess process;
|
||||||
process.setProcessEnvironment(env);
|
process.setProcessEnvironment(env);
|
||||||
|
18
aptpkginfo.h
18
aptpkginfo.h
@ -10,8 +10,22 @@ class AptPkgInfo: QObject
|
|||||||
public:
|
public:
|
||||||
AptPkgInfo(QString pkgName);
|
AptPkgInfo(QString pkgName);
|
||||||
|
|
||||||
QStringList GetAptPackageList(QString name);
|
void SetPkgName(QString pkgName);
|
||||||
QByteArray GetCommandResult(QString command, QStringList argv, QProcessEnvironment env = QProcessEnvironment::systemEnvironment());
|
QStringList GetAptPackageList(QString name) const;
|
||||||
|
QByteArray GetCommandResult(QString command, QStringList argv, QProcessEnvironment env = QProcessEnvironment::systemEnvironment()) const;
|
||||||
|
|
||||||
|
QString GetPkgInfo(QString pkgName=NULL) const;
|
||||||
|
|
||||||
|
QString get_package() const;
|
||||||
|
QString get_version() const;
|
||||||
|
QString get_maintainer() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString pkgName;
|
||||||
|
QString pkgInfo;
|
||||||
|
QString aptData;
|
||||||
|
|
||||||
|
void ReadAptData();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // APTPKGINFO_H
|
#endif // APTPKGINFO_H
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "kernelinformation.h"
|
#include "kernelinformation.h"
|
||||||
|
#include "aptpkginfo.h"
|
||||||
|
|
||||||
#include <QProcess>
|
#include <QProcess>
|
||||||
|
|
||||||
@ -14,6 +15,19 @@ void KernelInformation::LoadInfo()
|
|||||||
/*for(QString i: data) {
|
/*for(QString i: data) {
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
AptPkgInfo info = AptPkgInfo("");
|
||||||
|
QJsonArray array;
|
||||||
|
QStringList list = info.GetAptPackageList("linux-base");
|
||||||
|
for(QString i: list) {
|
||||||
|
QJsonObject object;
|
||||||
|
info.SetPkgName(i);
|
||||||
|
object.insert("Name", i);
|
||||||
|
object.insert("Author", info.get_maintainer());
|
||||||
|
array.append(object);
|
||||||
|
}
|
||||||
|
this->listData = array;
|
||||||
|
emit loadFinished(NULL);
|
||||||
|
return;
|
||||||
// 从 Github 拉取信息
|
// 从 Github 拉取信息
|
||||||
QUrl url(this->url);
|
QUrl url(this->url);
|
||||||
QUrlQuery query;
|
QUrlQuery query;
|
||||||
|
@ -50,8 +50,8 @@ void MainWindow::RefreshKernelListView(KernelInformation *info, bool showLocalAr
|
|||||||
model->setItem(line, 0, new QStandardItem(QString::number(i)));
|
model->setItem(line, 0, new QStandardItem(QString::number(i)));
|
||||||
model->setItem(line, 1, new QStandardItem(info->get_name(i)));
|
model->setItem(line, 1, new QStandardItem(info->get_name(i)));
|
||||||
model->setItem(line, 2, new QStandardItem(info->get_author(i)));
|
model->setItem(line, 2, new QStandardItem(info->get_author(i)));
|
||||||
model->setItem(line, 3, new QStandardItem(kernelArch));
|
//model->setItem(line, 3, new QStandardItem(kernelArch));
|
||||||
model->setItem(line, 4, new QStandardItem((QStringList() << "" << "Y").at(info->get_installedAlready(i))));
|
//model->setItem(line, 4, new QStandardItem((QStringList() << "" << "Y").at(info->get_installedAlready(i))));
|
||||||
line++;
|
line++;
|
||||||
}
|
}
|
||||||
ui->m_kernelShow->setModel(model);
|
ui->m_kernelShow->setModel(model);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user