From 9909e472d59350726e769d4783e67dbfdafe087d Mon Sep 17 00:00:00 2001 From: gfdgd_xi <3025613752@qq.com> Date: Tue, 23 Apr 2024 22:08:52 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=AF=BB=E5=8F=96=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E5=86=85=E6=A0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernelinformation.cpp | 16 ++++++++++++++++ kernelinformation.h | 5 +++++ main.cpp | 8 ++++++++ mainwindow.cpp | 1 + mainwindow.ui | 33 ++++++++++++++++++++++++++++++++- 5 files changed, 62 insertions(+), 1 deletion(-) diff --git a/kernelinformation.cpp b/kernelinformation.cpp index af85d30..bb61d83 100644 --- a/kernelinformation.cpp +++ b/kernelinformation.cpp @@ -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; +} diff --git a/kernelinformation.h b/kernelinformation.h index 5b072c4..309bac3 100644 --- a/kernelinformation.h +++ b/kernelinformation.h @@ -12,6 +12,8 @@ #include #include +#include + 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); diff --git a/main.cpp b/main.cpp index 43b49ba..73de6e5 100644 --- a/main.cpp +++ b/main.cpp @@ -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 + + } diff --git a/mainwindow.cpp b/mainwindow.cpp index ba74971..f4bda58 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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); diff --git a/mainwindow.ui b/mainwindow.ui index 6a62532..5931443 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -11,13 +11,44 @@ - MainWindow + Kerne Manager + + + + + + TextLabel + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + PushButton + + + + +