支持显示内核
This commit is contained in:
@@ -4,3 +4,86 @@ KernelInformation::KernelInformation()
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void KernelInformation::LoadInfo()
|
||||||
|
{
|
||||||
|
QUrl url(this->url);
|
||||||
|
QUrlQuery query;
|
||||||
|
query.addQueryItem("format", "j1");
|
||||||
|
url.setQuery(query.toString(QUrl::FullyEncoded));
|
||||||
|
qDebug() << url;
|
||||||
|
QNetworkRequest request(url);
|
||||||
|
QNetworkAccessManager *m_http = new QNetworkAccessManager(this);
|
||||||
|
QNetworkReply *reply = m_http->get(request);
|
||||||
|
connect(reply, &QNetworkReply::finished, this, [this, m_http](){
|
||||||
|
QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender());
|
||||||
|
QByteArray data = reply->readAll();
|
||||||
|
qDebug() << data;
|
||||||
|
qDebug() << reply->error();
|
||||||
|
this->listData = QJsonDocument::fromJson(data).array();
|
||||||
|
emit loadFinished(reply);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonArray KernelInformation::get_listData() const
|
||||||
|
{
|
||||||
|
return this->listData;
|
||||||
|
}
|
||||||
|
|
||||||
|
int KernelInformation::get_count() const
|
||||||
|
{
|
||||||
|
return this->listData.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
QJsonObject KernelInformation::get_kernelData(int value) const
|
||||||
|
{
|
||||||
|
return this->listData.at(value).toObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString KernelInformation::get_name(int value) const
|
||||||
|
{
|
||||||
|
return get_kernelData(value).value("Name").toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString KernelInformation::get_author(int value) const
|
||||||
|
{
|
||||||
|
return get_kernelData(value).value("Author").toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString KernelInformation::get_des(int value) const
|
||||||
|
{
|
||||||
|
return get_kernelData(value).value("Des").toString().replace("\\n", "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList KernelInformation::get_pkgName(int value) const
|
||||||
|
{
|
||||||
|
QJsonArray list = get_kernelData(value).value("PkgName").toArray();
|
||||||
|
int count = list.count();
|
||||||
|
QStringList result;
|
||||||
|
for(int i = 0; i <= count; i++) {
|
||||||
|
result << list.at(i).toString();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList KernelInformation::get_system(int value) const
|
||||||
|
{
|
||||||
|
QJsonArray list = get_kernelData(value).value("System").toArray();
|
||||||
|
int count = list.count();
|
||||||
|
QStringList result;
|
||||||
|
for(int i = 0; i <= count; i++) {
|
||||||
|
result << list.at(i).toString();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList KernelInformation::get_arch(int value) const
|
||||||
|
{
|
||||||
|
QJsonArray list = get_kernelData(value).value("Arch").toArray();
|
||||||
|
int count = list.count();
|
||||||
|
QStringList result;
|
||||||
|
for(int i = 0; i <= count; i++) {
|
||||||
|
result << list.at(i).toString();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,11 +1,41 @@
|
|||||||
#ifndef KERNELINFORMATION_H
|
#ifndef KERNELINFORMATION_H
|
||||||
#define KERNELINFORMATION_H
|
#define KERNELINFORMATION_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
class KernelInformation
|
#include <QUrlQuery>
|
||||||
|
#include <QNetworkReply>
|
||||||
|
#include <QNetworkRequest>
|
||||||
|
#include <QNetworkAccessManager>
|
||||||
|
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonArray>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
class KernelInformation : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
KernelInformation();
|
KernelInformation();
|
||||||
|
void LoadInfo();
|
||||||
|
QJsonArray get_listData() const;
|
||||||
|
QJsonObject get_kernelData(int value) const;
|
||||||
|
int get_count() const;
|
||||||
|
QString get_name(int value) const;
|
||||||
|
QString get_author(int value) const;
|
||||||
|
QString get_des(int value) const;
|
||||||
|
QStringList get_pkgName(int value) const;
|
||||||
|
QStringList get_system(int value) const;
|
||||||
|
QStringList get_arch(int value) const;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void loadFinished(QNetworkReply *reply);
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString url = "http://127.0.0.1:8000/information.json";
|
||||||
|
QJsonArray listData;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KERNELINFORMATION_H
|
#endif // KERNELINFORMATION_H
|
||||||
|
|||||||
@@ -1,11 +1,38 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
|
||||||
|
#include "kernelinformation.h"
|
||||||
|
|
||||||
|
#include <QStandardItemModel>
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: QMainWindow(parent)
|
: QMainWindow(parent)
|
||||||
, ui(new Ui::MainWindow)
|
, ui(new Ui::MainWindow)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
RefreshKernelList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::RefreshKernelList()
|
||||||
|
{
|
||||||
|
KernelInformation *information = new KernelInformation();
|
||||||
|
connect(information, &KernelInformation::loadFinished, this, [this, information](){
|
||||||
|
qDebug() << information->get_listData();
|
||||||
|
RefreshKernelListView(information);
|
||||||
|
delete information;
|
||||||
|
});
|
||||||
|
information->LoadInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::RefreshKernelListView(KernelInformation *info)
|
||||||
|
{
|
||||||
|
// 更新列表
|
||||||
|
int count = info->get_count();
|
||||||
|
QStandardItemModel *model = new QStandardItemModel();
|
||||||
|
for(int i = 0; i <= count; i++) {
|
||||||
|
model->setItem(0, i, new QStandardItem(info->get_name(i)));
|
||||||
|
}
|
||||||
|
ui->m_kernelShow->setModel(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include <QMainWindow>
|
||||||
|
#include "kernelinformation.h"
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
namespace Ui { class MainWindow; }
|
namespace Ui { class MainWindow; }
|
||||||
@@ -17,5 +18,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::MainWindow *ui;
|
Ui::MainWindow *ui;
|
||||||
|
void RefreshKernelList();
|
||||||
|
void RefreshKernelListView(KernelInformation *info);
|
||||||
};
|
};
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
@@ -13,8 +13,23 @@
|
|||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>MainWindow</string>
|
<string>MainWindow</string>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="centralwidget"/>
|
<widget class="QWidget" name="centralwidget">
|
||||||
<widget class="QMenuBar" name="menubar"/>
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QTableView" name="m_kernelShow"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>800</width>
|
||||||
|
<height>23</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusbar"/>
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
|||||||
Reference in New Issue
Block a user