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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
|
#include "lock.h"
#include "ui_lock.h"
#include "X11/XKBlib.h" // keep this header at bottom
Lock::Lock(QWidget *parent) : QWidget(parent), ui(new Ui::Lock) {
ui->setupUi(this);
ui->setPass->setEnabled(false);
ui->wrong->hide();
MoreApps *moreApps =
new MoreApps(this, nullptr, "keshavnrj",
QUrl("https://raw.githubusercontent.com/keshavbhatt/appdata/"
"main/moreapps.txt"),
false);
moreApps->setWindowTitle("More Applications by developer");
moreApps->setFixedHeight(98);
ui->moreAppsLayout->addWidget(moreApps);
passcodeLoginAction = ui->passcodeLogin->addAction(
QIcon(":/icons/green_arrow-right-line.png"), QLineEdit::TrailingPosition);
passcodeLoginAction->setEnabled(false);
connect(
passcodeLoginAction, &QAction::triggered, passcodeLoginAction, [this]() {
QString password = QByteArray::fromBase64(SettingsManager::instance()
.settings()
.value("asdfg")
.toByteArray());
if (ui->passcodeLogin->text() == password && check_password_set()) {
isLocked = false;
this->animateOut();
emit unLocked();
} else {
ui->wrong->show();
}
});
QGraphicsOpacityEffect *eff = new QGraphicsOpacityEffect(this);
ui->centerWidget->setGraphicsEffect(eff);
animateIn();
if (SettingsManager::instance().settings().value("asdfg").isValid() ==
false) {
signUp();
} else {
lock_app();
}
checkCaps();
QString capsStyle = QString(R"(background-color: palette(window);
padding: 4px;
border-radius: 2px;
color: palette(window-text);)");
ui->caps1->setStyleSheet(capsStyle);
ui->caps2->setStyleSheet(capsStyle);
ui->signup_warning->setStyleSheet(capsStyle);
ui->wrong->setStyleSheet(capsStyle);
foreach (QLineEdit *le, this->findChildren<QLineEdit *>()) {
le->setStyleSheet(R"(QLineEdit[echoMode="2"]{
lineedit-password-character: 9899;
})");
}
}
void Lock::signUp() {
isLocked = false;
ui->signup->show();
ui->login->hide();
animateIn();
ui->passcode1->setFocus();
}
void Lock::animateIn() {
ui->centerWidget->hide();
QPropertyAnimation *a =
new QPropertyAnimation(ui->centerWidget->graphicsEffect(), "opacity");
a->setDuration(500);
a->setStartValue(0);
a->setEndValue(1);
a->setEasingCurve(QEasingCurve::InCubic);
a->start(QPropertyAnimation::DeleteWhenStopped);
ui->centerWidget->show();
}
void Lock::animateOut() {
ui->centerWidget->show();
QPropertyAnimation *a =
new QPropertyAnimation(ui->centerWidget->graphicsEffect(), "opacity");
a->setDuration(500);
a->setStartValue(1);
a->setEndValue(0);
a->setEasingCurve(QEasingCurve::OutCubic);
connect(a, &QPropertyAnimation::finished, this, [=] {
ui->login->hide();
ui->signup->hide();
ui->passcodeLogin->clear();
ui->centerWidget->hide();
this->hide();
});
a->start(QPropertyAnimation::DeleteWhenStopped);
}
void Lock::applyThemeQuirks() {
QString lblStyle = QString(R"(color: #c2c5d1;
padding: 0px 8px 0px 8px;
background: transparent;)");
ui->label_4->setStyleSheet(lblStyle);
ui->label_3->setStyleSheet(lblStyle);
ui->login->setStyleSheet(R"(QWidget#login {
background-color: palette(window);
background-image: url(":/icons/wa_bg.png");
})");
ui->signup->setStyleSheet(R"(QWidget#signup {
background-color: palette(window);
background-image: url(":/icons/wa_bg.png");
})");
ui->widget_2->setStyleSheet(R"(QWidget#widget_2 {
border-top-left-radius: 4px;
border-top-right-radius: 4px;
background-image: url(":/icons/texture.png");
background-color: palette(shadow);
})");
ui->widget->setStyleSheet(R"(QWidget#widget{
border-top-left-radius: 4px;
border-top-right-radius: 4px;
background-image:url(":/icons/texture.png");
background-color:palette(shadow);
})");
ui->centerWidget->setStyleSheet(R"(QWidget#centerWidget {
background-image: url(":/icons/wa_bg.png");
})");
// little quirks
QString border = "border-bottom-right-radius: 4px;"
"border-bottom-left-radius: 4px;";
QString lightBg = "background-color: rgb(37, 211, 102);";
QString darkBg = "background-color: rgb(0, 117, 96);";
if (QString::compare(SettingsManager::instance()
.settings()
.value("windowTheme", "light")
.toString(),
"dark", Qt::CaseInsensitive) == 0) { // light
ui->bottomLine->setStyleSheet(darkBg + border);
ui->bottomLine_2->setStyleSheet(darkBg + border);
} else { // dark
ui->bottomLine->setStyleSheet(lightBg + border);
ui->bottomLine_2->setStyleSheet(lightBg + border);
}
}
Lock::~Lock() { delete ui; }
void Lock::checkCaps() {
if (getCapsLockOn()) {
ui->caps1->show();
ui->caps2->show();
} else {
ui->caps1->hide();
ui->caps2->hide();
}
}
void Lock::keyReleaseEvent(QKeyEvent *event) {
if (event->key() == Qt::Key_CapsLock) {
checkCaps();
}
}
bool Lock::event(QEvent *e) { return QWidget::event(e); }
bool Lock::getIsLocked() const { return isLocked; }
void Lock::on_passcode1_textChanged(const QString &arg1) {
if (arg1.contains(" ")) {
ui->passcode1->setText(arg1.simplified());
}
ui->setPass->setEnabled(arg1.length() > 3 && arg1 == ui->passcode2->text());
}
void Lock::on_passcode2_textChanged(const QString &arg1) {
if (arg1.contains(" ")) {
ui->passcode2->setText(arg1.simplified());
}
ui->setPass->setEnabled(arg1.length() > 3 && arg1 == ui->passcode1->text());
}
void Lock::on_setPass_clicked() {
QString pass1, pass2;
pass1 = ui->passcode1->text().trimmed();
pass2 = ui->passcode2->text().trimmed();
if (pass1 == pass2) {
SettingsManager::instance().settings().setValue(
"asdfg", QByteArray(pass1.toUtf8()).toBase64());
SettingsManager::instance().settings().setValue("lockscreen", true);
ui->passcode1->clear();
ui->passcode2->clear();
emit passwordSet();
if (check_password_set()) {
ui->signup->hide();
ui->login->show();
ui->passcodeLogin->setFocus();
}
}
}
bool Lock::check_password_set() {
return SettingsManager::instance().settings().value("asdfg").isValid();
}
void Lock::on_passcodeLogin_textChanged(const QString &arg1) {
if (arg1.contains(" ")) {
ui->passcodeLogin->setText(arg1.simplified());
}
ui->wrong->hide();
passcodeLoginAction->setEnabled(arg1.length() > 3);
}
void Lock::lock_app() {
checkCaps();
ui->wrong->hide();
ui->signup->hide();
ui->login->show();
this->show();
isLocked = ui->login->isVisible();
animateIn();
ui->passcodeLogin->setFocus();
}
void Lock::on_passcodeLogin_returnPressed() { passcodeLoginAction->trigger(); }
bool Lock::getCapsLockOn() {
Display *d = XOpenDisplay(nullptr);
bool caps_state = false;
if (d) {
unsigned n;
XkbGetIndicatorState(d, XkbUseCoreKbd, &n);
caps_state = (n & 0x01) == 1;
XCloseDisplay(d);
}
return caps_state;
}
void Lock::on_cancelSetting_clicked() {
isLocked = false;
emit passwordNotSet();
this->hide();
}
|