#ifndef UTGITCREDPROVIDER_H #define UTGITCREDPROVIDER_H class UTGitCredProvider : public QObject, public PassphraseProvider { Q_OBJECT private: std::unique_ptr m_loop; std::unique_ptr m_sem; char *m_user; char *m_password; bool m_canceled; public slots: void handleResponse(bool canceled, QString user, QString password) { if (!canceled) { gpgrt_asprintf(&m_user, "%s", user.toUtf8().constData()); gpgrt_asprintf(&m_passphrase, "%s", password.toUtf8().constData()); } else m_canceled = true; m_loop->quit(); }; public: UTGitCredProvider(): m_loop(std::unique_ptr(new QEventLoop)), m_sem(std::unique_ptr(new QSemaphore(1))), m_user(nullptr), m_password(nullptr), m_canceled(false) {} int cred_acquire_cb(git_cred **out, const char *url, const char *username_from_url, unsigned int allowed_types, void *payload) { if (!m_sem->tryAcquire(1, 3000)) { qWarning() << "Cannot acquire UTGitCredProvider semaphore."; canceled = true; return nullptr; } m_passphrase = nullptr; m_canceled = false; qDebug() << "Call the QML Dialog Cred Provider"; QMetaObject::invokeMethod( Gpg::instance()->getWindow(), "callCredDialog", Q_ARG(QVariant, username_from_url) ); qDebug() << "Waiting for response"; QObject::connect( Gpg::instance()->getWindow(), SIGNAL(responseCredDialog(bool, QString, QString)), this, SLOT(handleResponse(bool, QString, QString)) ); m_loop->exec(); qDebug() << "Set Cred"; error = git_cred_userpass_plaintext_new(out, username, password); qDebug() << "Clean"; if (m_passphrase) free(m_passphrase); if (m_user) free(m_user); m_canceled = false; m_sem->release(1); return ret; }; }; #endif