支持读取本地内核

This commit is contained in:
2024-04-23 22:08:52 +08:00
parent fd07edc739
commit 9909e472d5
5 changed files with 62 additions and 1 deletions

View File

@@ -55,6 +55,11 @@ QString KernelInformation::get_des(int value) const
return get_kernelData(value).value("Des").toString().replace("\\n", "\n");
}
QString KernelInformation::get_ver(int value) const
{
return get_kernelData(value).value("Ver").toString();
}
QStringList KernelInformation::get_pkgName(int value) const
{
QJsonArray list = get_kernelData(value).value("PkgName").toArray();
@@ -87,3 +92,14 @@ QStringList KernelInformation::get_arch(int value) const
}
return result;
}
QString KernelInformation::localKernelName() const
{
QProcess process;
process.start("uname", QStringList() << "-r");
process.waitForStarted();
process.waitForFinished();
QString result = process.readAllStandardOutput().replace("\n", "").replace(" ", "");
process.close();
return result;
}

View File

@@ -12,6 +12,8 @@
#include <QJsonArray>
#include <QJsonObject>
#include <QProcess>
class KernelInformation : public QObject
{
Q_OBJECT
@@ -25,10 +27,13 @@ public:
QString get_name(int value) const;
QString get_author(int value) const;
QString get_des(int value) const;
QString get_ver(int value) const;
QStringList get_pkgName(int value) const;
QStringList get_system(int value) const;
QStringList get_arch(int value) const;
QString localKernelName() const;
signals:
void loadFinished(QNetworkReply *reply);

View File

@@ -10,6 +10,7 @@
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
#ifdef __linux__
// 风险提示
if(!QFile::exists(QDir::homePath() + "/.config/gxde-kernel-manager/read_already")) {
QMessageBox::warning(NULL, QObject::tr("Waring"), QObject::tr("It is danger because it may make your system unboot.\nPress 'OK' to countinue"));
@@ -17,4 +18,11 @@ int main(int argc, char *argv[])
MainWindow w;
w.show();
return a.exec();
#else
// 其它系统不支持该工具
QMessageBox::critical(NULL, QObject::tr("Error"), QObject::tr("It unsupport Windows"));
return a.exec();
#endif
}

View File

@@ -16,6 +16,7 @@ MainWindow::MainWindow(QWidget *parent)
void MainWindow::RefreshKernelList()
{
KernelInformation *information = new KernelInformation();
ui->m_nowKernel->setText(tr("Kernel: ") + information->localKernelName());
connect(information, &KernelInformation::loadFinished, this, [this, information](){
qDebug() << information->get_listData();
RefreshKernelListView(information);

View File

@@ -11,13 +11,44 @@
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
<string>Kerne Manager</string>
</property>
<widget class="QWidget" name="centralwidget">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTableView" name="m_kernelShow"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="m_nowKernel">
<property name="text">
<string>TextLabel</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>PushButton</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menubar">