Advertisement
Guest User

Untitled

a guest
May 19th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.08 KB | None | 0 0
  1. // QWaitCondition returnCondition;
  2. // QMutex mutex;
  3. static uint password_retries = 0;
  4. const char * thread_password_cb(const char *prompt, http_t *http, const char *method, const char *resource, void *user_data)
  5. {
  6.     Q_UNUSED(prompt)
  7.     Q_UNUSED(http)
  8.     Q_UNUSED(method)
  9.     Q_UNUSED(resource)
  10.  
  11.     kDebug() << "-----------thread_password_cb------"<< "password_retries" << password_retries;
  12.     kDebug() << QThread::currentThreadId();
  13.  
  14.     if (password_retries == 3) {
  15.         // cancel the authentication
  16.         cupsSetUser(NULL);
  17.         return NULL;
  18.     }
  19. //     QPointer<KPasswordDialog> dlg = new KPasswordDialog(0, KPasswordDialog::ShowUsernameLine);
  20. //     dlg->setPrompt(i18n("Enter an username and a password to complete the task"));
  21. //     dlg->setUsername(QString::fromUtf8(cupsUser()));
  22. //     // check if the password retries is more than 0 and show an error
  23.     bool showErrorMessage = false;
  24.     if (password_retries++) {
  25.         showErrorMessage = true;
  26. //         dlg->showErrorMessage(QString(), KPasswordDialog::UsernameError);
  27. //         dlg->showErrorMessage(i18n("Wrong username or password"), KPasswordDialog::PasswordError);
  28.     }
  29.    
  30.     CupsThreadRequest *thread = static_cast<CupsThreadRequest*>(user_data);
  31.     bool returnBool = false;
  32.     kDebug() <<QMetaObject::invokeMethod(NCups::instance(),
  33.                               "showPasswordDlg",
  34.                               Qt::QueuedConnection,
  35.                               Q_ARG(bool*, &returnBool),
  36.                               Q_ARG(QString, QString::fromUtf8(cupsUser())),
  37.                               Q_ARG(bool, showErrorMessage));
  38. //     mutex.lock();
  39.     kDebug() << "~~~~~~WAIT";
  40.     while (returnBool == false) {
  41.         sleep(1);
  42. //         kDebug() << "~~~~~~WAIT 1";
  43.        
  44.     }
  45.  
  46.     while (returnBool == true) {
  47.         sleep(1);
  48.         kDebug() << "~~~~~~WAIT 2";
  49.  
  50.     }
  51.    
  52. //     returnCondition.wait(&mutex);
  53.     kDebug() << "~~~~~~RELEASED";
  54. //     mutex.unlock();
  55.  
  56.     if (thread->property("canceled").toBool()) {
  57.         // the dialog was canceled
  58.         password_retries = -1;
  59.         cupsSetUser(NULL);
  60.         return NULL;
  61.     } else {
  62.         QString username = thread->property("username").toString();
  63.         QString password = thread->property("password").toString();
  64.         cupsSetUser(username.toUtf8());
  65.         return password.toUtf8();
  66.     }
  67. }
  68.  
  69. void CupsThreadRequest::run()
  70. {
  71.     kDebug() << QThread::currentThreadId();
  72.     cupsSetPasswordCB2(thread_password_cb, this);
  73.     req = new Request();
  74.     exec();
  75. }
  76.  
  77. void NCups::showPasswordDlg(bool *returnBool,
  78.                                         const QString &username,
  79.                                         bool showErrorMessage)
  80. {
  81. //     mutex.lock();
  82.     kDebug() << QThread::currentThreadId();
  83. //     KPasswordDialog *dlg = new KPasswordDialog(0, KPasswordDialog::ShowUsernameLine);
  84.     dlg->setPrompt(i18n("Enter an username and a password to complete the task"));
  85.     dlg->setUsername(username);
  86.     if (showErrorMessage) {
  87.         dlg->showErrorMessage(QString(), KPasswordDialog::UsernameError);
  88.         dlg->showErrorMessage(i18n("Wrong username or password"), KPasswordDialog::PasswordError);
  89.     }
  90.     dlg->setModal(true);
  91.     dlg->exec();
  92.     *returnBool = true;
  93.     kDebug()<< "----------------- Finish2";
  94. //     if (dlg->exec()) {
  95. //         setProperty("username", dlg->username());
  96. //         setProperty("password", dlg->password());
  97. //         setProperty("canceled", false);
  98. //         delete dlg;
  99. //         kDebug()<< "Finish1";
  100. //         returnCondition.wakeAll();
  101. //     } else {
  102. //         // the dialog was canceled
  103. //         delete dlg;
  104. //         setProperty("username", QString());
  105. //         setProperty("password", QString());
  106. //         setProperty("canceled", true);
  107. //         kDebug()<< "Finish2";
  108. //         returnCondition.wakeAll();
  109. //     }
  110. setProperty("username", QString("root"));
  111.         setProperty("password", QString("getapan81"));
  112.         setProperty("canceled", false);
  113. //         returnCondition.wakeAll();
  114.  
  115. //     mutex.unlock();
  116.  
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement