mirror of
https://github.com/iDescriptor/iDescriptor.git
synced 2026-06-21 19:35:49 +08:00
move login dialog
This commit is contained in:
+3
-103
@@ -4,6 +4,7 @@
|
||||
#include "appdownloaddialog.h"
|
||||
#include "appinstalldialog.h"
|
||||
#include "libipatool-go.h"
|
||||
#include "logindialog.h"
|
||||
#include <QAction>
|
||||
#include <QApplication>
|
||||
#include <QBuffer>
|
||||
@@ -44,29 +45,8 @@
|
||||
#include <QWidget>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
// 2FA callback for login
|
||||
static char *getAuthCodeCallback()
|
||||
{
|
||||
static QByteArray buffer;
|
||||
QString code;
|
||||
QMetaObject::invokeMethod(
|
||||
qApp,
|
||||
[&]() {
|
||||
bool ok;
|
||||
code = QInputDialog::getText(
|
||||
nullptr, "Two-Factor Authentication",
|
||||
"Enter the 2FA code:", QLineEdit::Normal, QString(), &ok);
|
||||
},
|
||||
Qt::BlockingQueuedConnection);
|
||||
|
||||
if (code.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
buffer = code.toUtf8();
|
||||
return buffer.data();
|
||||
}
|
||||
|
||||
// Callback: void(QPixmap)
|
||||
// TODO : move to utils
|
||||
void fetchAppIconFromApple(const QString &bundleId,
|
||||
std::function<void(const QPixmap &)> callback,
|
||||
QObject *context)
|
||||
@@ -121,70 +101,6 @@ void fetchAppIconFromApple(const QString &bundleId,
|
||||
});
|
||||
}
|
||||
|
||||
// LoginDialog Implementation
|
||||
LoginDialog::LoginDialog(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
setWindowTitle("Login to App Store");
|
||||
setModal(true);
|
||||
// setFixedSize(400, 250);
|
||||
setFixedWidth(400);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
layout->setSpacing(15);
|
||||
layout->setContentsMargins(20, 20, 20, 20);
|
||||
|
||||
// Title
|
||||
QLabel *titleLabel = new QLabel("Sign in to continue");
|
||||
titleLabel->setStyleSheet(
|
||||
"font-size: 18px; font-weight: bold; color: #333;");
|
||||
titleLabel->setAlignment(Qt::AlignCenter);
|
||||
layout->addWidget(titleLabel);
|
||||
|
||||
// Email
|
||||
QLabel *emailLabel = new QLabel("Email:");
|
||||
emailLabel->setStyleSheet("font-size: 14px; color: #555;");
|
||||
layout->addWidget(emailLabel);
|
||||
|
||||
m_emailEdit = new QLineEdit();
|
||||
m_emailEdit->setPlaceholderText("Enter your email");
|
||||
m_emailEdit->setStyleSheet("padding: 8px; border: 1px solid #ddd; "
|
||||
"border-radius: 4px; font-size: 14px;");
|
||||
layout->addWidget(m_emailEdit);
|
||||
|
||||
// Password
|
||||
QLabel *passwordLabel = new QLabel("Password:");
|
||||
passwordLabel->setStyleSheet("font-size: 14px; color: #555;");
|
||||
layout->addWidget(passwordLabel);
|
||||
|
||||
m_passwordEdit = new QLineEdit();
|
||||
m_passwordEdit->setPlaceholderText("Enter your password");
|
||||
m_passwordEdit->setEchoMode(QLineEdit::Password);
|
||||
m_passwordEdit->setStyleSheet("padding: 8px; border: 1px solid #ddd; "
|
||||
"border-radius: 4px; font-size: 14px;");
|
||||
layout->addWidget(m_passwordEdit);
|
||||
|
||||
// Buttons
|
||||
QDialogButtonBox *buttonBox =
|
||||
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
buttonBox->button(QDialogButtonBox::Ok)->setText("Sign In");
|
||||
buttonBox->setStyleSheet(
|
||||
"QPushButton { padding: 8px 16px; font-size: 14px; border-radius: 4px; "
|
||||
"}"
|
||||
"QPushButton[text='Sign In'] { background-color: #007AFF; color: "
|
||||
"white; border: none; }"
|
||||
"QPushButton[text='Sign In']:hover { background-color: #0056CC; }"
|
||||
"QPushButton[text='Cancel'] { background-color: #f0f0f0; color: #333; "
|
||||
"border: 1px solid #ddd; }");
|
||||
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
|
||||
layout->addWidget(buttonBox);
|
||||
}
|
||||
|
||||
QString LoginDialog::getEmail() const { return m_emailEdit->text(); }
|
||||
QString LoginDialog::getPassword() const { return m_passwordEdit->text(); }
|
||||
|
||||
AppsWidget::AppsWidget(QWidget *parent) : QWidget(parent), m_isLoggedIn(false)
|
||||
{
|
||||
// m_searchProcess = new QProcess(this);
|
||||
@@ -510,23 +426,6 @@ void AppsWidget::onLoginClicked()
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
QString email = dialog.getEmail();
|
||||
QString password = dialog.getPassword();
|
||||
if (email.isEmpty() || password.isEmpty()) {
|
||||
QMessageBox::warning(this, "Login Failed",
|
||||
"Email and password cannot be empty.");
|
||||
return;
|
||||
}
|
||||
int result = IpaToolLoginWithCallback(email.toUtf8().data(),
|
||||
password.toUtf8().data(),
|
||||
getAuthCodeCallback);
|
||||
if (result == 0) {
|
||||
m_isLoggedIn = true;
|
||||
m_loginButton->setText("Sign Out");
|
||||
m_statusLabel->setText("Signed in as " + email);
|
||||
} else {
|
||||
QMessageBox::warning(
|
||||
this, "Login Failed",
|
||||
"Login failed. Please check your credentials and 2FA code.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -562,6 +461,7 @@ void AppsWidget::performSearch()
|
||||
|
||||
auto searchFn = [searchTerm]() -> QString {
|
||||
char *resultsCStr = IpaToolSearch(searchTerm.toUtf8().data(), 20);
|
||||
qDebug() << "Search results C string:" << resultsCStr;
|
||||
if (!resultsCStr) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
@@ -18,19 +18,6 @@
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
|
||||
class LoginDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LoginDialog(QWidget *parent = nullptr);
|
||||
QString getEmail() const;
|
||||
QString getPassword() const;
|
||||
|
||||
private:
|
||||
QLineEdit *m_emailEdit;
|
||||
QLineEdit *m_passwordEdit;
|
||||
};
|
||||
|
||||
class AppsWidget : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
#include "logindialog.h"
|
||||
#include "libipatool-go.h"
|
||||
#include <QApplication>
|
||||
#include <QDialogButtonBox>
|
||||
#include <QInputDialog>
|
||||
#include <QLabel>
|
||||
#include <QLineEdit>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
#include <QtConcurrent/QtConcurrent>
|
||||
|
||||
// 2FA callback for login
|
||||
static char *getAuthCodeCallback()
|
||||
{
|
||||
static QByteArray buffer;
|
||||
QString code;
|
||||
QMetaObject::invokeMethod(
|
||||
qApp,
|
||||
[&]() {
|
||||
bool ok;
|
||||
code = QInputDialog::getText(
|
||||
nullptr, "Two-Factor Authentication",
|
||||
"Enter the 2FA code:", QLineEdit::Normal, QString(), &ok);
|
||||
},
|
||||
Qt::BlockingQueuedConnection);
|
||||
|
||||
if (code.isEmpty()) {
|
||||
return nullptr;
|
||||
}
|
||||
buffer = code.toUtf8();
|
||||
return buffer.data();
|
||||
}
|
||||
|
||||
LoginDialog::LoginDialog(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
setWindowTitle("Login to App Store");
|
||||
setModal(true);
|
||||
// setFixedSize(400, 250);
|
||||
setFixedWidth(400);
|
||||
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
layout->setSpacing(15);
|
||||
layout->setContentsMargins(20, 20, 20, 20);
|
||||
|
||||
// Title
|
||||
QLabel *titleLabel = new QLabel("Sign in to continue");
|
||||
titleLabel->setStyleSheet(
|
||||
"font-size: 18px; font-weight: bold; color: #333;");
|
||||
titleLabel->setAlignment(Qt::AlignCenter);
|
||||
layout->addWidget(titleLabel);
|
||||
|
||||
// Email
|
||||
QLabel *emailLabel = new QLabel("Email:");
|
||||
emailLabel->setStyleSheet("font-size: 14px; color: #555;");
|
||||
layout->addWidget(emailLabel);
|
||||
|
||||
m_emailEdit = new QLineEdit();
|
||||
m_emailEdit->setPlaceholderText("Enter your email");
|
||||
m_emailEdit->setStyleSheet("padding: 8px; border: 1px solid #ddd; "
|
||||
"border-radius: 4px; font-size: 14px;");
|
||||
layout->addWidget(m_emailEdit);
|
||||
|
||||
// Password
|
||||
QLabel *passwordLabel = new QLabel("Password:");
|
||||
passwordLabel->setStyleSheet("font-size: 14px; color: #555;");
|
||||
layout->addWidget(passwordLabel);
|
||||
|
||||
m_passwordEdit = new QLineEdit();
|
||||
m_passwordEdit->setPlaceholderText("Enter your password");
|
||||
m_passwordEdit->setEchoMode(QLineEdit::Password);
|
||||
m_passwordEdit->setStyleSheet("padding: 8px; border: 1px solid #ddd; "
|
||||
"border-radius: 4px; font-size: 14px;");
|
||||
layout->addWidget(m_passwordEdit);
|
||||
|
||||
// Buttons
|
||||
QDialogButtonBox *buttonBox =
|
||||
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
buttonBox->button(QDialogButtonBox::Ok)->setText("Sign In");
|
||||
buttonBox->setStyleSheet(
|
||||
"QPushButton { padding: 8px 16px; font-size: 14px; border-radius: 4px; "
|
||||
"}"
|
||||
"QPushButton[text='Sign In'] { background-color: #007AFF; color: "
|
||||
"white; border: none; }"
|
||||
"QPushButton[text='Sign In']:hover { background-color: #0056CC; }"
|
||||
"QPushButton[text='Cancel'] { background-color: #f0f0f0; color: #333; "
|
||||
"border: 1px solid #ddd; }");
|
||||
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, this, &LoginDialog::signIn);
|
||||
// connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept);
|
||||
connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
||||
|
||||
layout->addWidget(buttonBox);
|
||||
}
|
||||
|
||||
QString LoginDialog::getEmail() const { return m_emailEdit->text(); }
|
||||
QString LoginDialog::getPassword() const { return m_passwordEdit->text(); }
|
||||
|
||||
void LoginDialog::signIn()
|
||||
{
|
||||
QString email = getEmail();
|
||||
QString password = getPassword();
|
||||
if (email.isEmpty() || password.isEmpty()) {
|
||||
QMessageBox::warning(this, "Login Failed",
|
||||
"Email and password cannot be empty.");
|
||||
return;
|
||||
}
|
||||
QFuture<int> f = QtConcurrent::run([email, password]() {
|
||||
return IpaToolLoginWithCallback(email.toUtf8().data(),
|
||||
password.toUtf8().data(),
|
||||
getAuthCodeCallback);
|
||||
});
|
||||
|
||||
QFutureWatcher<int> *watcher = new QFutureWatcher<int>(this);
|
||||
connect(watcher, &QFutureWatcher<int>::finished, this, [this, watcher]() {
|
||||
int result = watcher->future().result();
|
||||
if (result == 0) {
|
||||
accept();
|
||||
} else {
|
||||
QMessageBox::warning(
|
||||
this, "Login Failed",
|
||||
"Login failed. Please check your credentials and 2FA code.");
|
||||
}
|
||||
watcher->deleteLater();
|
||||
});
|
||||
// int result = IpaToolLoginWithCallback(
|
||||
// email.toUtf8().data(), password.toUtf8().data(),
|
||||
// getAuthCodeCallback);
|
||||
// if (result == 0) {
|
||||
// accept();
|
||||
// // m_isLoggedIn = true;
|
||||
// // m_loginButton->setText("Sign Out");
|
||||
// // m_statusLabel->setText("Signed in as " + email);
|
||||
// } else {
|
||||
// QMessageBox::warning(
|
||||
// this, "Login Failed",
|
||||
// "Login failed. Please check your credentials and 2FA code.");
|
||||
// }
|
||||
|
||||
// Perform login logic here
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef LOGINDIALOG_H
|
||||
#define LOGINDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QLineEdit>
|
||||
|
||||
class LoginDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LoginDialog(QWidget *parent = nullptr);
|
||||
QString getEmail() const;
|
||||
QString getPassword() const;
|
||||
|
||||
private:
|
||||
QLineEdit *m_emailEdit;
|
||||
QLineEdit *m_passwordEdit;
|
||||
void signIn();
|
||||
};
|
||||
|
||||
#endif // LOGINDIALOG_H
|
||||
Reference in New Issue
Block a user