OfficeAssistant_Win10/OfficeAssistant_msvc/settingsscreen.cpp

57 lines
1.9 KiB
C++

#include "settingsscreen.h"
#include "config.h"
#include <QCryptographicHash>
#include "netio.h"
SettingsScreen::SettingsScreen(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
autoStart = new SwitchButton(ADD_AUTOSTART,this);
addDesktopLink = new QPushButton(this);
addDesktopLink->setText(QString::fromLocal8Bit("创建桌面快捷方式"));
connect(addDesktopLink, &QPushButton::pressed, this, &SettingsScreen::createShortCut);
layout = new QHBoxLayout(this);
left = new QVBoxLayout(this);
addDesktopLink_label = new QLabel(QString::fromLocal8Bit("添加桌面快捷方式"),this);
autoStart_label = new QLabel(QString::fromLocal8Bit("开机启动"),this);
autoStart->setMaximumSize(100, 50);
autoStart->setMinimumSize(50, 25);
left->addWidget(autoStart_label);
left->addWidget(autoStart);
left->addWidget(addDesktopLink_label);
left->addWidget(addDesktopLink);
left->setAlignment(Qt::AlignCenter);
left->setMargin(0);
layout->addLayout(left);
information = new QLabel;
QString device_id = QCryptographicHash::hash(getMachineGUID().toUtf8(), QCryptographicHash::Md5).toHex();
QString inf_str = QString::fromLocal8Bit("硬件ID:\n");
inf_str += device_id;
information->setText(inf_str);
layout->addWidget(information);
}
void SettingsScreen::createShortCut() {
QString deskTopPath = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
deskTopPath = deskTopPath + QString::fromLocal8Bit("/办公助手.lnk");
QString srcFile = QApplication::applicationFilePath();
QFile::link(srcFile, deskTopPath);
}
SettingsScreen::~SettingsScreen()
{
left->removeWidget(autoStart);
left->removeWidget(addDesktopLink);
left->removeWidget(addDesktopLink_label);
left->removeWidget(autoStart_label);
delete autoStart;
delete addDesktopLink;
delete addDesktopLink_label;
delete autoStart_label;
layout->removeItem(left);
delete left;
layout->removeWidget(information);
delete information;
delete layout;
}