Advertisement
Guest User

Untitled

a guest
Feb 9th, 2013
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.72 KB | None | 0 0
  1. void TrelloApi::onTemporaryTokenReceived(QString token, QString tokenSecret)
  2. {
  3.     qDebug() << "Temporary token received: " << token << tokenSecret;
  4.  
  5.     QUrl userAuthURL("https://Trello.com/1/OAuthAuthorizeToken");
  6.  
  7.     if( oauthManager->lastError() == KQOAuthManager::NoError) {
  8.         qDebug() << "Asking for user's permission to access protected resources. Opening URL: " << userAuthURL;
  9.         QUrl openUrl = oauthManager->getUserAuthorization(userAuthURL);
  10.         emit urlReady(openUrl);
  11.     }
  12.  
  13. }
  14.  
  15. void TrelloApi::onAuthorizationReceived(QString token, QString verifier) {
  16.     qDebug() << "User authorization received: " << token << verifier;
  17.  
  18.     oauthManager->getUserAccessTokens(QUrl("https://Trello.com/1/OAuthGetAccessToken"));
  19.     if( oauthManager->lastError() != KQOAuthManager::NoError) {
  20.         emit loginComplete(false);
  21.     }
  22. }
  23.  
  24. void TrelloApi::onAccessTokenReceived(QString token, QString tokenSecret) {
  25.     qDebug() << "Access token received: " << token << tokenSecret;
  26.  
  27.     disconnect(oauthManager, SIGNAL(accessTokenReceived(QString,QString)), this, SLOT(onAccessTokenReceived(QString,QString)));
  28.  
  29.     if(token == NULL) {
  30.         emit loginComplete(false);
  31.         return;
  32.     }
  33.     oauthSettings.setValue("oauth_token", token);
  34.     oauthSettings.setValue("oauth_token_secret", tokenSecret);
  35.  
  36.     emit loginComplete(token.length() > 0);
  37.     qDebug() << "Access tokens now stored.";
  38. }
  39.  
  40. void TrelloApi::onAuthorizedRequestDone() {
  41.     qDebug() << "Request sent to Trello!";
  42. }
  43.  
  44. void TrelloApi::onRequestReady(QByteArray response) {
  45.     qDebug() << "Response from the service: " << response;
  46.     switch(oauthManager->lastError()){
  47.     case KQOAuthManager::NoError:
  48.         break;
  49.     default:
  50.         qDebug() << "There was an error";
  51.         break;
  52.     }
  53.     disconnect(oauthManager, SIGNAL(requestReady(QByteArray)), this, SLOT(onRequestReady(QByteArray)));
  54. }
  55.  
  56. void TrelloApi::getAccess()
  57. {
  58.     connect(oauthManager, SIGNAL(temporaryTokenReceived(QString,QString)), this, SLOT(onTemporaryTokenReceived(QString, QString)));
  59.     connect(oauthManager, SIGNAL(authorizationReceived(QString,QString)), this, SLOT( onAuthorizationReceived(QString, QString)));
  60.     connect(oauthManager, SIGNAL(accessTokenReceived(QString,QString)), this, SLOT(onAccessTokenReceived(QString,QString)));
  61.     connect(oauthManager, SIGNAL(requestReady(QByteArray)), this, SLOT(onRequestReady(QByteArray)));
  62.  
  63.     oauthRequest->initRequest(KQOAuthRequest::TemporaryCredentials, QUrl("https://Trello.com/1/OAuthGetRequestToken"));
  64.     oauthRequest->setConsumerKey(CONSUMER_KEY);
  65.     oauthRequest->setConsumerSecretKey(CONSUMER_SECRET);
  66.     oauthManager->setHandleUserAuthorization(true);
  67.     oauthManager->executeRequest(oauthRequest);
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement