完善设置功能

This commit is contained in:
gfdgd xi 2023-04-16 22:06:38 +08:00
parent db5cee1345
commit 620cea5136
4 changed files with 132 additions and 36 deletions

View File

@ -197,7 +197,7 @@ void MainWindow::on_vmChooser_currentIndexChanged(int index)
void MainWindow::on_qemuSetting_clicked()
{
QemuSetting show;
show.show();
show.exec();
QemuSetting *show = new QemuSetting();
show->show();
}

View File

@ -3,12 +3,60 @@
#include <QMessageBox>
#include <QDesktopServices>
#include <QUrl>
#include <QJsonObject>
#include <QJsonDocument>
#include <QFile>
#include "infoutils.h"
#include <QDir>
#include <sys/sysinfo.h>
QemuSetting::QemuSetting(QWidget *parent) :
QDialog(parent),
QWidget(parent),
ui(new Ui::QemuSetting)
{
ui->setupUi(this);
// 设置变量
if(QFile::exists(QDir::homePath() + "/.config/deepin-wine-runner/QemuSetting.json")){
// 读取配置文件
QFile file(QDir::homePath() + "/.config/deepin-wine-runner/QemuSetting.json");
file.open(QIODevice::ReadOnly);
QJsonParseError error;
QJsonDocument document = QJsonDocument::fromJson(file.readAll(), &error);
file.close();
if(error.error != QJsonParseError::NoError){
QMessageBox::critical(this, "错误", error.errorString());
}
else {
QJsonObject object = document.object();
qDebug() << QJsonDocument(object).toJson();
ui->enableKvm->setChecked(object.value("EnableKVM").toBool());
ui->enableRdp->setChecked(object.value("EnableRDP").toBool());
ui->enableVnc->setChecked(object.value("EnableVNC").toBool());
ui->enableSound->setChecked(object.value("EnableSound").toBool());
ui->memoryNumber->setValue(object.value("Memory").toInt());
ui->vncNumber->setValue(object.value("VNC").toInt());
ui->cpuNumber->setValue(object.value("CPU").toInt());
}
}
else {
// 默认
this->SetDefaultValue();
}
}
void QemuSetting::SetDefaultValue(){
long memory = 0;
long memoryAll = 0;
long swap = 0;
long swapAll = 0;
infoUtils::memoryRate(memory, memoryAll, swap, swapAll);
ui->memoryNumber->setValue(memoryAll / 3 / 1024);
ui->vncNumber->setValue(5);
ui->cpuNumber->setValue(get_nprocs());
ui->enableKvm->setChecked(true);
ui->enableRdp->setChecked(true);
ui->enableVnc->setChecked(true);
ui->enableSound->setChecked(true);
}
QemuSetting::~QemuSetting()
@ -24,12 +72,27 @@ void QemuSetting::on_buttonBox_accepted()
void QemuSetting::on_save_clicked()
{
QJsonParseError error;
QJsonDocument document = QJsonDocument::fromJson("{}", &error);
if(error.error != QJsonParseError::NoError){
QMessageBox::critical(this, "错误", error.errorString());
return;
}
QJsonObject object = document.object();
//object.insert("1", QJsonValue("aa"));
object.insert("EnableKVM", ui->enableKvm->isChecked());
object.insert("EnableRDP", ui->enableRdp->isChecked());
object.insert("EnableVNC", ui->enableVnc->isChecked());
object.insert("EnableSound", ui->enableSound->isChecked());
object.insert("Memory", ui->memoryNumber->value());
object.insert("VNC", ui->vncNumber->value());
object.insert("CPU", ui->cpuNumber->value());
qDebug() << QJsonDocument(object).toJson();
}
void QemuSetting::on_cancel_clicked()
{
accept();
delete this;
}
void QemuSetting::on_getrunner_clicked()

View File

@ -1,13 +1,15 @@
#ifndef QEMUSETTING_H
#define QEMUSETTING_H
#include <QDialog>
#include <QWidget>
#include <QCheckBox>
#include <QSpinBox>
namespace Ui {
class QemuSetting;
}
class QemuSetting : public QDialog
class QemuSetting : public QWidget
{
Q_OBJECT
@ -15,6 +17,7 @@ public:
explicit QemuSetting(QWidget *parent = nullptr);
~QemuSetting();
private slots:
void on_buttonBox_accepted();
@ -25,6 +28,7 @@ private slots:
void on_getrunner_clicked();
private:
void SetDefaultValue();
Ui::QemuSetting *ui;
};

View File

@ -1,22 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QemuSetting</class>
<widget class="QDialog" name="QemuSetting">
<widget class="QWidget" name="QemuSetting">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<width>496</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>设置</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="8" column="1">
<item row="9" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -29,17 +29,24 @@
</property>
</spacer>
</item>
<item row="5" column="0">
<item row="4" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>&lt;h3&gt;远程服务&lt;/h3&gt;</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>VNC服务端口</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<item row="5" column="1">
<widget class="QCheckBox" name="enableRdp">
<property name="text">
<string>&lt;h3&gt;远程服务&lt;/h3&gt;</string>
<string>开启 rdp 服务映射</string>
</property>
</widget>
</item>
@ -50,7 +57,14 @@
</property>
</widget>
</item>
<item row="7" column="1">
<item row="1" column="1">
<widget class="QSpinBox" name="memoryNumber">
<property name="maximum">
<number>999999999</number>
</property>
</widget>
</item>
<item row="8" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -63,26 +77,13 @@
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spinBox"/>
</item>
<item row="4" column="1">
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>开启 rdp 服务映射</string>
<item row="6" column="1">
<widget class="QSpinBox" name="vncNumber">
<property name="maximum">
<number>9999</number>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="checkBox_2">
<property name="text">
<string>开启VNC服务</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QSpinBox" name="spinBox_2"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
@ -90,13 +91,41 @@
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="checkBox_3">
<item row="5" column="0">
<widget class="QCheckBox" name="enableVnc">
<property name="text">
<string>开启VNC服务</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="enableKvm">
<property name="text">
<string>开启 kvm 加速</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>CPU核心数</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="cpuNumber">
<property name="maximum">
<number>999999999</number>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="enableSound">
<property name="text">
<string>开启声音</string>
</property>
</widget>
</item>
</layout>
</item>
<item>