更新UI+新增磁盘文件添加/导出/删除功能

This commit is contained in:
gfdgd xi 2023-04-29 17:09:09 +08:00
parent 5443654791
commit 466a7c5596
3 changed files with 71 additions and 28 deletions

View File

@ -215,13 +215,21 @@ void MainWindow::on_addQemuDisk_triggered()
if(path == ""){ if(path == ""){
return; return;
} }
QDir dir(QDir::homePath() + "/Qemu/Windows/Windows.qcow2"); QDir dir(QDir::homePath() + "/Qemu/Windows");
if(!dir.exists()){ if(!dir.exists()){
dir.mkpath(QDir::homePath() + "/Qemu/Windows/Windows.qcow2"); dir.mkpath(QDir::homePath() + "/Qemu/Windows");
} }
if(!QFile::remove(QDir::homePath() + "/Qemu/Windows/Windows.qcow2") | !QFile::copy(path, QDir::homePath() + "/Qemu/Windows/Windows.qcow2")){ if(QFile::exists(QDir::homePath() + "/Qemu/Windows/Windows.qcow2")){
QMessageBox::critical(this, "提示", "添加错误!"); if(!QFile::remove(QDir::homePath() + "/Qemu/Windows/Windows.qcow2") | !QFile::copy(path, QDir::homePath() + "/Qemu/Windows/Windows.qcow2")){
return; QMessageBox::critical(this, "提示", "添加错误!");
return;
}
}
else{
if(!QFile::copy(path, QDir::homePath() + "/Qemu/Windows/Windows.qcow2")){
QMessageBox::critical(this, "提示", "添加错误!");
return;
}
} }
QMessageBox::information(this, "提示", "添加完成!"); QMessageBox::information(this, "提示", "添加完成!");
} }
@ -234,3 +242,29 @@ void MainWindow::on_delQemuDisk_triggered()
} }
std::system(("xdg-open \"" + QDir::homePath() + "/Qemu/Windows/\"").toUtf8()); std::system(("xdg-open \"" + QDir::homePath() + "/Qemu/Windows/\"").toUtf8());
} }
void MainWindow::on_addQemuDiskButton_clicked()
{
MainWindow::on_addQemuDisk_triggered();
}
void MainWindow::on_saveQemuDiskButton_clicked()
{
MainWindow::on_delQemuDisk_triggered();
}
void MainWindow::on_delQemuDiskButton_clicked()
{
if(!QFile::exists(QDir::homePath() + "/Qemu/Windows/Windows.qcow2")){
QMessageBox::information(this, "提示", "不存在磁盘文件,无法移除");
return;
}
if(QMessageBox::question(this, "提示", "是否删除?\n删除后将无法恢复!") == QMessageBox::No){
return;
}
if(!QFile::remove(QDir::homePath() + "/Qemu/Windows/Windows.qcow2")){
QMessageBox::critical(this, "提示", "移除失败");
return;
}
QMessageBox::information(this, "提示", "移除成功");
}

View File

@ -38,6 +38,12 @@ private slots:
void on_delQemuDisk_triggered(); void on_delQemuDisk_triggered();
void on_addQemuDiskButton_clicked();
void on_saveQemuDiskButton_clicked();
void on_delQemuDiskButton_clicked();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
long m_cpuAll; long m_cpuAll;

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>807</width> <width>1058</width>
<height>429</height> <height>512</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -25,7 +25,7 @@
<enum>QTabWidget::Rounded</enum> <enum>QTabWidget::Rounded</enum>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>2</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="tab"> <widget class="QWidget" name="tab">
<attribute name="title"> <attribute name="title">
@ -142,6 +142,13 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="QPushButton" name="getQemu">
<property name="text">
<string>安装 Qemu</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QPushButton" name="qemuSetting"> <widget class="QPushButton" name="qemuSetting">
<property name="text"> <property name="text">
@ -150,9 +157,23 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QPushButton" name="getQemu"> <widget class="QPushButton" name="addQemuDiskButton">
<property name="text"> <property name="text">
<string>安装 Qemu</string> <string>添加/覆盖Qemu磁盘</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="saveQemuDiskButton">
<property name="text">
<string>导出Qemu磁盘</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="delQemuDiskButton">
<property name="text">
<string>移除Qemu磁盘</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -374,24 +395,6 @@ p, li { white-space: pre-wrap; }
<string/> <string/>
</property> </property>
</widget> </widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>807</width>
<height>36</height>
</rect>
</property>
<widget class="QMenu" name="menuQemu">
<property name="title">
<string>Qemu磁盘镜像</string>
</property>
<addaction name="addQemuDisk"/>
<addaction name="delQemuDisk"/>
</widget>
<addaction name="menuQemu"/>
</widget>
<action name="action"> <action name="action">
<property name="text"> <property name="text">
<string>退出</string> <string>退出</string>