Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // QWaitCondition returnCondition;
- // QMutex mutex;
- static uint password_retries = 0;
- const char * thread_password_cb(const char *prompt, http_t *http, const char *method, const char *resource, void *user_data)
- {
- Q_UNUSED(prompt)
- Q_UNUSED(http)
- Q_UNUSED(method)
- Q_UNUSED(resource)
- kDebug() << "-----------thread_password_cb------"<< "password_retries" << password_retries;
- kDebug() << QThread::currentThreadId();
- if (password_retries == 3) {
- // cancel the authentication
- cupsSetUser(NULL);
- return NULL;
- }
- // QPointer<KPasswordDialog> dlg = new KPasswordDialog(0, KPasswordDialog::ShowUsernameLine);
- // dlg->setPrompt(i18n("Enter an username and a password to complete the task"));
- // dlg->setUsername(QString::fromUtf8(cupsUser()));
- // // check if the password retries is more than 0 and show an error
- bool showErrorMessage = false;
- if (password_retries++) {
- showErrorMessage = true;
- // dlg->showErrorMessage(QString(), KPasswordDialog::UsernameError);
- // dlg->showErrorMessage(i18n("Wrong username or password"), KPasswordDialog::PasswordError);
- }
- CupsThreadRequest *thread = static_cast<CupsThreadRequest*>(user_data);
- bool returnBool = false;
- kDebug() <<QMetaObject::invokeMethod(NCups::instance(),
- "showPasswordDlg",
- Qt::QueuedConnection,
- Q_ARG(bool*, &returnBool),
- Q_ARG(QString, QString::fromUtf8(cupsUser())),
- Q_ARG(bool, showErrorMessage));
- // mutex.lock();
- kDebug() << "~~~~~~WAIT";
- while (returnBool == false) {
- sleep(1);
- // kDebug() << "~~~~~~WAIT 1";
- }
- while (returnBool == true) {
- sleep(1);
- kDebug() << "~~~~~~WAIT 2";
- }
- // returnCondition.wait(&mutex);
- kDebug() << "~~~~~~RELEASED";
- // mutex.unlock();
- if (thread->property("canceled").toBool()) {
- // the dialog was canceled
- password_retries = -1;
- cupsSetUser(NULL);
- return NULL;
- } else {
- QString username = thread->property("username").toString();
- QString password = thread->property("password").toString();
- cupsSetUser(username.toUtf8());
- return password.toUtf8();
- }
- }
- void CupsThreadRequest::run()
- {
- kDebug() << QThread::currentThreadId();
- cupsSetPasswordCB2(thread_password_cb, this);
- req = new Request();
- exec();
- }
- void NCups::showPasswordDlg(bool *returnBool,
- const QString &username,
- bool showErrorMessage)
- {
- // mutex.lock();
- kDebug() << QThread::currentThreadId();
- // KPasswordDialog *dlg = new KPasswordDialog(0, KPasswordDialog::ShowUsernameLine);
- dlg->setPrompt(i18n("Enter an username and a password to complete the task"));
- dlg->setUsername(username);
- if (showErrorMessage) {
- dlg->showErrorMessage(QString(), KPasswordDialog::UsernameError);
- dlg->showErrorMessage(i18n("Wrong username or password"), KPasswordDialog::PasswordError);
- }
- dlg->setModal(true);
- dlg->exec();
- *returnBool = true;
- kDebug()<< "----------------- Finish2";
- // if (dlg->exec()) {
- // setProperty("username", dlg->username());
- // setProperty("password", dlg->password());
- // setProperty("canceled", false);
- // delete dlg;
- // kDebug()<< "Finish1";
- // returnCondition.wakeAll();
- // } else {
- // // the dialog was canceled
- // delete dlg;
- // setProperty("username", QString());
- // setProperty("password", QString());
- // setProperty("canceled", true);
- // kDebug()<< "Finish2";
- // returnCondition.wakeAll();
- // }
- setProperty("username", QString("root"));
- setProperty("password", QString("getapan81"));
- setProperty("canceled", false);
- // returnCondition.wakeAll();
- // mutex.unlock();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement