70 lines
1.9 KiB
C++
70 lines
1.9 KiB
C++
#include "AuthView.h"
|
|
#include "ui_AuthView.h"
|
|
#include "AuthManager.h"
|
|
#include "AuthConfig.h"
|
|
#include "StyledMessageBox.h"
|
|
#include <QClipboard>
|
|
#include <QApplication>
|
|
|
|
#pragma execution_character_set("utf-8")
|
|
|
|
AuthView::AuthView(QWidget *parent)
|
|
: QDialog(parent)
|
|
, ui(new Ui::AuthView)
|
|
{
|
|
ui->setupUi(this);
|
|
setWindowTitle("软件授权");
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
|
|
// 显示机器码
|
|
std::string machineCode = AuthManager::GetMachineCode();
|
|
ui->editMachineCode->setText(QString::fromStdString(machineCode));
|
|
ui->editMachineCode->setReadOnly(true);
|
|
}
|
|
|
|
AuthView::~AuthView()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
bool AuthView::CheckAndShow(QWidget *parent)
|
|
{
|
|
if (AuthManager::CheckLicenseValid()) {
|
|
return true;
|
|
}
|
|
|
|
AuthView dialog(parent);
|
|
return dialog.exec() == QDialog::Accepted;
|
|
}
|
|
|
|
void AuthView::on_btnActivate_clicked()
|
|
{
|
|
std::string licenseKey = ui->editLicenseKey->text().toStdString();
|
|
if (licenseKey.empty()) {
|
|
StyledMessageBox::warning(this, "提示", "请输入授权码");
|
|
return;
|
|
}
|
|
|
|
// 验证授权码
|
|
std::string expireDate;
|
|
if (!AuthManager::ValidateLicenseKey(licenseKey, expireDate)) {
|
|
StyledMessageBox::warning(this, "提示", "授权码无效");
|
|
return;
|
|
}
|
|
|
|
// 保存授权信息
|
|
if (AuthManager::SaveLicenseInfo(licenseKey, expireDate)) {
|
|
StyledMessageBox::information(this, "提示", "授权成功");
|
|
accept();
|
|
} else {
|
|
StyledMessageBox::warning(this, "提示", "保存授权信息失败");
|
|
}
|
|
}
|
|
|
|
void AuthView::on_btnCopy_clicked()
|
|
{
|
|
QClipboard *clipboard = QApplication::clipboard();
|
|
clipboard->setText(ui->editMachineCode->text());
|
|
StyledMessageBox::information(this, "提示", "机器码已复制到剪贴板");
|
|
}
|