支持内核卸载
This commit is contained in:
parent
8a362b0548
commit
aab5b67836
@ -10,5 +10,6 @@
|
||||
<file>icon/dialog-question.svg</file>
|
||||
<file>icon/dialog-warning.svg</file>
|
||||
<file>icon/icon.svg</file>
|
||||
<file>shell/kernel-installer-remove-template.sh</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -109,3 +109,9 @@ QString KernelInformation::localKernelName() const
|
||||
process.close();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool KernelInformation::get_installedAlready(int value) const
|
||||
{
|
||||
QString pkgName = this->get_pkgName(value).at(0);
|
||||
return QFile::exists("/var/lib/dpkg/info/" + pkgName + ".list");
|
||||
}
|
||||
|
@ -14,6 +14,8 @@
|
||||
|
||||
#include <QProcess>
|
||||
|
||||
#include <QFile>
|
||||
|
||||
class KernelInformation : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -31,6 +33,7 @@ public:
|
||||
QStringList get_pkgName(int value) const;
|
||||
QStringList get_system(int value) const;
|
||||
QStringList get_arch(int value) const;
|
||||
bool get_installedAlready(int value) const;
|
||||
|
||||
QString localKernelName() const;
|
||||
|
||||
|
@ -10,17 +10,25 @@
|
||||
#define MAX_TMP_NUM 1024
|
||||
#define MIN_TMP_NUM 0
|
||||
|
||||
KernelInstaller::KernelInstaller(QStringList kernelList, QWidget *parent) :
|
||||
KernelInstaller::KernelInstaller(Option option, QStringList kernelList, QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::KernelInstaller)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
runOption = option;
|
||||
// 修改提示文本
|
||||
QString kernel = "";
|
||||
foreach (QString name, kernelList) {
|
||||
kernel += name + " ";
|
||||
}
|
||||
ui->m_status->setText(tr("Try to install ") + kernel);
|
||||
|
||||
switch(runOption) {
|
||||
case Option::Install:
|
||||
ui->m_status->setText(tr("Try to install ") + kernel);
|
||||
case Option::Remove:
|
||||
ui->m_status->setText(tr("Try to remove ") + kernel);
|
||||
}
|
||||
|
||||
|
||||
this->kernelList = kernelList;
|
||||
terminal = new QTermWidget(0);
|
||||
@ -63,7 +71,15 @@ QString KernelInstaller::BuildKernelInstallerBash(QStringList kernelList, QStrin
|
||||
foreach (QString name, kernelList) {
|
||||
kernel += name + " ";
|
||||
}
|
||||
QFile file(":/shell/kernel-installer-template.sh");
|
||||
QString filePath = ":/shell/kernel-installer-template.sh";
|
||||
switch(runOption) {
|
||||
case Option::Install:
|
||||
filePath = ":/shell/kernel-installer-template.sh";
|
||||
case Option::Remove:
|
||||
filePath = ":/shell/kernel-installer-remove-template.sh";
|
||||
}
|
||||
|
||||
QFile file(filePath);
|
||||
file.open(QFile::ReadOnly);
|
||||
QString data = file.readAll();
|
||||
data = data.replace("${KernelList}", kernel);
|
||||
|
@ -14,13 +14,20 @@ class KernelInstaller : public QMainWindow
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit KernelInstaller(QStringList kernelList, QWidget *parent = nullptr);
|
||||
enum Option {
|
||||
Install,
|
||||
Remove
|
||||
};
|
||||
|
||||
explicit KernelInstaller(Option option, QStringList kernelList, QWidget *parent = nullptr);
|
||||
~KernelInstaller();
|
||||
|
||||
|
||||
signals:
|
||||
void InstallFinished(int status);
|
||||
|
||||
private:
|
||||
Option runOption;
|
||||
Ui::KernelInstaller *ui;
|
||||
QTermWidget *terminal;
|
||||
QStringList kernelList;
|
||||
|
@ -31,12 +31,13 @@ void MainWindow::RefreshKernelListView(KernelInformation *info)
|
||||
// 更新列表
|
||||
int count = info->get_count();
|
||||
QStandardItemModel *model = new QStandardItemModel();
|
||||
model->setHorizontalHeaderLabels(QStringList() << tr("ID") << tr("Kernel Name") << tr("Author") << tr("Arch"));
|
||||
model->setHorizontalHeaderLabels(QStringList() << tr("ID") << tr("Kernel Name") << tr("Author") << tr("Arch") << tr("Installed"));
|
||||
for(int i = 0; i < count; i++) {
|
||||
model->setItem(i, 0, new QStandardItem(QString::number(i)));
|
||||
model->setItem(i, 1, new QStandardItem(info->get_name(i)));
|
||||
model->setItem(i, 2, new QStandardItem(info->get_author(i)));
|
||||
model->setItem(i, 3, new QStandardItem(info->get_arch(i).at(0)));
|
||||
model->setItem(i, 4, new QStandardItem((QStringList() << "" << "Y").at(info->get_installedAlready(i))));
|
||||
}
|
||||
ui->m_kernelShow->setModel(model);
|
||||
}
|
||||
@ -66,7 +67,7 @@ void MainWindow::on_m_installButton_clicked()
|
||||
QModelIndex index = ui->m_kernelShow->model()->index(row, 0);
|
||||
int id = ui->m_kernelShow->model()->data(index).toUInt();
|
||||
// 获取选中行
|
||||
KernelInstaller *installer = new KernelInstaller(kernelInformation->get_pkgName(id));
|
||||
KernelInstaller *installer = new KernelInstaller(KernelInstaller::Option::Install, kernelInformation->get_pkgName(id));
|
||||
installer->show();
|
||||
}
|
||||
|
||||
@ -95,3 +96,21 @@ void MainWindow::on_actionGithub_triggered()
|
||||
QDesktopServices::openUrl(QUrl("https://github.com/GXDE-OS/gxde-kernel-manager"));
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_m_removeButton_clicked()
|
||||
{
|
||||
QModelIndex list = ui->m_kernelShow->selectionModel()->currentIndex();
|
||||
int row = list.row();
|
||||
if(row <= 0) {
|
||||
// 未选中任何内容
|
||||
QMessageBox::critical(this, tr("Error"), tr("Nothing to choose"));
|
||||
return;
|
||||
}
|
||||
// 获取 ID
|
||||
QModelIndex index = ui->m_kernelShow->model()->index(row, 0);
|
||||
int id = ui->m_kernelShow->model()->data(index).toUInt();
|
||||
// 获取选中行
|
||||
KernelInstaller *installer = new KernelInstaller(KernelInstaller::Option::Remove, kernelInformation->get_pkgName(id));
|
||||
installer->show();
|
||||
}
|
||||
|
||||
|
@ -31,6 +31,8 @@ private slots:
|
||||
|
||||
void on_actionGithub_triggered();
|
||||
|
||||
void on_m_removeButton_clicked();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
KernelInformation *kernelInformation;
|
||||
|
@ -71,6 +71,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="m_removeButton">
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
5
shell/kernel-installer-remove-template.sh
Normal file
5
shell/kernel-installer-remove-template.sh
Normal file
@ -0,0 +1,5 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
rm /tmp/gxde-kernel-manager-installer-status -f
|
||||
apt purge ${KernelList} -y
|
||||
rm -f "${kernelInstallerShellTempPath}"
|
Loading…
x
Reference in New Issue
Block a user