diff --git a/src/appswidget.cpp b/src/appswidget.cpp index 3593bdf..e0c4cc6 100644 --- a/src/appswidget.cpp +++ b/src/appswidget.cpp @@ -4,6 +4,7 @@ #include "appdownloaddialog.h" #include "appinstalldialog.h" #include "libipatool-go.h" +#include "logindialog.h" #include #include #include @@ -44,29 +45,8 @@ #include #include -// 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 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(); } diff --git a/src/appswidget.h b/src/appswidget.h index 137329c..1378c18 100644 --- a/src/appswidget.h +++ b/src/appswidget.h @@ -18,19 +18,6 @@ #include #include -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 diff --git a/src/logindialog.cpp b/src/logindialog.cpp new file mode 100644 index 0000000..b2a7fed --- /dev/null +++ b/src/logindialog.cpp @@ -0,0 +1,141 @@ +#include "logindialog.h" +#include "libipatool-go.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// 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 f = QtConcurrent::run([email, password]() { + return IpaToolLoginWithCallback(email.toUtf8().data(), + password.toUtf8().data(), + getAuthCodeCallback); + }); + + QFutureWatcher *watcher = new QFutureWatcher(this); + connect(watcher, &QFutureWatcher::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 +} \ No newline at end of file diff --git a/src/logindialog.h b/src/logindialog.h new file mode 100644 index 0000000..a6b640a --- /dev/null +++ b/src/logindialog.h @@ -0,0 +1,21 @@ +#ifndef LOGINDIALOG_H +#define LOGINDIALOG_H + +#include +#include + +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