-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlicensedialog.cpp
More file actions
219 lines (179 loc) · 7.25 KB
/
licensedialog.cpp
File metadata and controls
219 lines (179 loc) · 7.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include "licensedialog.h"
#include "licensemanager.h"
#include "macosstylemanager.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGroupBox>
#include <QClipboard>
#include <QApplication>
#include <QMessageBox>
#include <QFont>
#include <QFrame>
#include <QTimer>
#include <QSpacerItem>
LicenseDialog::LicenseDialog(LicenseManager *manager, QWidget *parent)
: QDialog(parent)
, m_licenseManager(manager)
, m_activated(false)
{
setWindowTitle("License Activation");
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setFixedSize(480, 380);
setModal(true);
// Apply macOS style
MacOSStyleManager::instance().applyToDialog(this);
setupUi();
updateStatus();
}
void LicenseDialog::setupUi()
{
auto &style = MacOSStyleManager::instance();
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->setSpacing(12);
mainLayout->setContentsMargins(20, 16, 20, 16);
// Title - compact
QLabel *titleLabel = new QLabel("Claude Code Balance");
titleLabel->setStyleSheet(QString("font-size: 18px; font-weight: 600; color: %1;")
.arg(style.textColor().name()));
titleLabel->setAlignment(Qt::AlignCenter);
mainLayout->addWidget(titleLabel);
// Machine ID Group - compact
QGroupBox *machineGroup = new QGroupBox("MACHINE ID");
QVBoxLayout *machineLayout = new QVBoxLayout(machineGroup);
machineLayout->setSpacing(6);
machineLayout->setContentsMargins(10, 12, 10, 10);
QHBoxLayout *machineIdLayout = new QHBoxLayout;
machineIdLayout->setSpacing(6);
m_machineIdEdit = new QLineEdit;
m_machineIdEdit->setReadOnly(true);
m_machineIdEdit->setText(m_licenseManager->getMachineId());
m_machineIdEdit->setFont(QFont("SF Mono", 11));
m_machineIdEdit->setFixedHeight(30);
m_copyBtn = new QPushButton("Copy");
m_copyBtn->setFixedSize(60, 30);
connect(m_copyBtn, &QPushButton::clicked, this, &LicenseDialog::onCopyMachineId);
machineIdLayout->addWidget(m_machineIdEdit, 1);
machineIdLayout->addWidget(m_copyBtn);
machineLayout->addLayout(machineIdLayout);
mainLayout->addWidget(machineGroup);
// License Key Group - compact
QGroupBox *licenseGroup = new QGroupBox("LICENSE KEY");
QVBoxLayout *licenseLayout = new QVBoxLayout(licenseGroup);
licenseLayout->setSpacing(8);
licenseLayout->setContentsMargins(10, 12, 10, 10);
m_licenseEdit = new QLineEdit;
m_licenseEdit->setPlaceholderText("XXXXX-XXXXX-XXXXX-XXXXX-XXXXX-X");
m_licenseEdit->setFont(QFont("SF Mono", 11));
m_licenseEdit->setFixedHeight(30);
licenseLayout->addWidget(m_licenseEdit);
m_activateBtn = new QPushButton("Activate");
m_activateBtn->setFixedHeight(32);
m_activateBtn->setStyleSheet(style.getAccentButtonStyle());
connect(m_activateBtn, &QPushButton::clicked, this, &LicenseDialog::onActivateClicked);
licenseLayout->addWidget(m_activateBtn);
mainLayout->addWidget(licenseGroup);
// Status Group - compact
QGroupBox *statusGroup = new QGroupBox("STATUS");
QVBoxLayout *statusLayout = new QVBoxLayout(statusGroup);
statusLayout->setSpacing(4);
statusLayout->setContentsMargins(10, 12, 10, 10);
m_statusLabel = new QLabel("Not activated");
m_statusLabel->setStyleSheet(QString("font-weight: 500; font-size: 12px; color: %1;")
.arg(style.dangerColor().name()));
statusLayout->addWidget(m_statusLabel);
m_expirationLabel = new QLabel("");
m_expirationLabel->setStyleSheet(QString("color: %1; font-size: 11px;")
.arg(style.secondaryTextColor().name()));
statusLayout->addWidget(m_expirationLabel);
mainLayout->addWidget(statusGroup);
// Spacer
mainLayout->addStretch(1);
// Bottom Button
QHBoxLayout *buttonLayout = new QHBoxLayout;
buttonLayout->addStretch(1);
m_exitBtn = new QPushButton("Exit");
m_exitBtn->setFixedSize(90, 30);
connect(m_exitBtn, &QPushButton::clicked, this, &LicenseDialog::onExitClicked);
buttonLayout->addWidget(m_exitBtn);
mainLayout->addLayout(buttonLayout);
}
void LicenseDialog::updateStatus()
{
auto &style = MacOSStyleManager::instance();
if (m_licenseManager->isLicenseValid()) {
m_statusLabel->setText("Activated");
m_statusLabel->setStyleSheet(QString("font-weight: 500; font-size: 12px; color: %1;")
.arg(style.successColor().name()));
int days = m_licenseManager->getDaysRemaining();
QDate expDate = m_licenseManager->getExpirationDate();
m_expirationLabel->setText(QString("Expires: %1 (%2 days)")
.arg(expDate.toString("yyyy-MM-dd"))
.arg(days));
if (days <= 7) {
m_expirationLabel->setStyleSheet(QString("color: %1; font-size: 11px;")
.arg(style.warningColor().name()));
} else {
m_expirationLabel->setStyleSheet(QString("color: %1; font-size: 11px;")
.arg(style.secondaryTextColor().name()));
}
m_activated = true;
m_activateBtn->setText("Re-Activate");
m_exitBtn->setText("Continue");
} else {
m_statusLabel->setText("Not activated");
m_statusLabel->setStyleSheet(QString("font-weight: 500; font-size: 12px; color: %1;")
.arg(style.dangerColor().name()));
QString error = m_licenseManager->getLastError();
if (!error.isEmpty()) {
m_expirationLabel->setText(error);
m_expirationLabel->setStyleSheet(QString("color: %1; font-size: 11px;")
.arg(style.dangerColor().name()));
} else {
m_expirationLabel->setText("Enter a valid license key");
m_expirationLabel->setStyleSheet(QString("color: %1; font-size: 11px;")
.arg(style.secondaryTextColor().name()));
}
m_activated = false;
m_activateBtn->setText("Activate");
m_exitBtn->setText("Exit");
}
}
void LicenseDialog::onActivateClicked()
{
QString licenseKey = m_licenseEdit->text().trimmed();
if (licenseKey.isEmpty()) {
QMessageBox::warning(this, "Error", "Please enter a license key.");
return;
}
if (m_licenseManager->activateLicense(licenseKey)) {
QMessageBox::information(this, "Success",
QString("License activated successfully!\n\nExpires: %1")
.arg(m_licenseManager->getExpirationDate().toString("yyyy-MM-dd")));
updateStatus();
} else {
QMessageBox::critical(this, "Activation Failed",
QString("Failed to activate license:\n\n%1")
.arg(m_licenseManager->getLastError()));
updateStatus();
}
}
void LicenseDialog::onCopyMachineId()
{
auto &style = MacOSStyleManager::instance();
QClipboard *clipboard = QApplication::clipboard();
clipboard->setText(m_machineIdEdit->text());
m_copyBtn->setText("OK");
m_copyBtn->setStyleSheet(style.getAccentButtonStyle());
QTimer::singleShot(1200, this, [this]() {
m_copyBtn->setText("Copy");
m_copyBtn->setStyleSheet(MacOSStyleManager::instance().getPrimaryButtonStyle());
});
}
void LicenseDialog::onExitClicked()
{
if (m_activated) {
accept();
} else {
reject();
}
}