diff --git a/Resource.qrc b/Resource.qrc index a8001f1..b08bc43 100644 --- a/Resource.qrc +++ b/Resource.qrc @@ -13,5 +13,6 @@ <file>shell/kernel-installer-remove-template.sh</file> <file>translation/gxde-kernel-manager_zh_CN.qm</file> <file>shell/kernel-installer-reconfigure-template.sh</file> + <file>shell/kernel-installer-update-template.sh</file> </qresource> </RCC> diff --git a/kernelinstaller.cpp b/kernelinstaller.cpp index 2cd82e4..a92a375 100644 --- a/kernelinstaller.cpp +++ b/kernelinstaller.cpp @@ -32,6 +32,9 @@ KernelInstaller::KernelInstaller(Option option, QStringList kernelList, QWidget case Option::Reconfigure: ui->m_status->setText(tr("Try to reconfigure ") + kernel); break; + case Option::Update: + ui->m_status->setText(tr("Try to update apt cache")); + break; } @@ -63,7 +66,7 @@ void KernelInstaller::StartInstaller() terminal->startShellProgram(); processID = terminal->getShellPID(); // 使用 QTimer 用于判断内核是否安装完成 - QTimer *runStatusTimer = new QTimer(); + runStatusTimer = new QTimer(); runStatusTimer->setInterval(100); connect(runStatusTimer, &QTimer::timeout, this, &KernelInstaller::CheckInstallerStatusTimer); runStatusTimer->start(); @@ -87,6 +90,9 @@ QString KernelInstaller::BuildKernelInstallerBash(QStringList kernelList, QStrin case Option::Reconfigure: filePath = ":/shell/kernel-installer-reconfigure-template.sh"; break; + case Option::Update: + filePath = ":/shell/kernel-installer-update-template.sh"; + break; } QFile file(filePath); @@ -136,6 +142,8 @@ void KernelInstaller::CheckInstallerStatusTimer() if(status == -1) { return; } + // 关闭 Timer 防止一直发送错误的信号 + runStatusTimer->stop(); emit InstallFinished(status); // 安装完成 if(status == 0) { diff --git a/kernelinstaller.h b/kernelinstaller.h index 735d653..105fac6 100644 --- a/kernelinstaller.h +++ b/kernelinstaller.h @@ -17,7 +17,8 @@ public: enum Option { Install, Remove, - Reconfigure + Reconfigure, + Update }; explicit KernelInstaller(Option option, QStringList kernelList, QWidget *parent = nullptr); @@ -28,6 +29,7 @@ signals: void InstallFinished(int status); private: + QTimer *runStatusTimer; Option runOption; Ui::KernelInstaller *ui; QTermWidget *terminal; diff --git a/mainwindow.cpp b/mainwindow.cpp index 905cd1f..2831bad 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -58,6 +58,7 @@ void MainWindow::RefreshKernelListView(KernelInformation *info, bool showLocalAr line++; } ui->m_kernelShow->setModel(model); + ui->m_kernelShow->resizeColumnsToContents(); } MainWindow::~MainWindow() @@ -160,3 +161,13 @@ void MainWindow::on_m_reconfigureButton_clicked() installer->show(); } + +void MainWindow::on_actionUpdate_apt_cache_triggered() +{ + KernelInstaller *installer = new KernelInstaller(KernelInstaller::Option::Update, QStringList()); + connect(installer, &KernelInstaller::InstallFinished, this, [this, installer](){ + RefreshKernelList(); + }); + installer->show(); +} + diff --git a/mainwindow.h b/mainwindow.h index b7765e0..4336838 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -37,6 +37,8 @@ private slots: void on_m_reconfigureButton_clicked(); + void on_actionUpdate_apt_cache_triggered(); + private: Ui::MainWindow *ui; KernelInformation *kernelInformation; diff --git a/mainwindow.ui b/mainwindow.ui index db92900..4a1b973 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -27,9 +27,15 @@ <property name="selectionBehavior"> <enum>QAbstractItemView::SelectRows</enum> </property> + <property name="sortingEnabled"> + <bool>true</bool> + </property> <property name="wordWrap"> <bool>true</bool> </property> + <attribute name="horizontalHeaderCascadingSectionResizes"> + <bool>false</bool> + </attribute> <attribute name="verticalHeaderVisible"> <bool>false</bool> </attribute> @@ -112,6 +118,8 @@ <property name="title"> <string>Program</string> </property> + <addaction name="actionUpdate_apt_cache"/> + <addaction name="separator"/> <addaction name="actionExit"/> </widget> <widget class="QMenu" name="menuHelp"> @@ -147,6 +155,11 @@ <string>Github</string> </property> </action> + <action name="actionUpdate_apt_cache"> + <property name="text"> + <string>Update apt cache</string> + </property> + </action> </widget> <resources> <include location="Resource.qrc"/> diff --git a/shell/kernel-installer-template.sh b/shell/kernel-installer-template.sh index 95b02b2..736aee8 100644 --- a/shell/kernel-installer-template.sh +++ b/shell/kernel-installer-template.sh @@ -1,6 +1,12 @@ #!/bin/bash set -e rm /tmp/gxde-kernel-manager-installer-status -f -apt update -apt install ${KernelList} -y +aptPath="apt" +which aptss > /dev/null +if [[ $? == 0 ]]; then + # 如果 aptss 存在,则使用 aptss + aptPath="aptss" +fi +$aptPath update +$aptPath install ${KernelList} -y rm -f "${kernelInstallerShellTempPath}" \ No newline at end of file diff --git a/shell/kernel-installer-update-template.sh b/shell/kernel-installer-update-template.sh new file mode 100644 index 0000000..88b6249 --- /dev/null +++ b/shell/kernel-installer-update-template.sh @@ -0,0 +1,11 @@ +#!/bin/bash +set -e +rm /tmp/gxde-kernel-manager-installer-status -f +aptPath="apt" +which aptss > /dev/null +if [[ $? == 0 ]]; then + # 如果 aptss 存在,则使用 aptss + aptPath="aptss" +fi +$aptPath update +rm -f "${kernelInstallerShellTempPath}" \ No newline at end of file