|
1 /** |
|
2 * Copyright (c) 2010 Sasken Communication Technologies Ltd. |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the "{License}" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "{LicenseUrl}". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Narasimhulu Kavadapu, Sasken Communication Technologies Ltd - Initial contribution |
|
11 * |
|
12 * Contributors: |
|
13 * Siddhartha Chandra, Sasken Communication Technologies Ltd |
|
14 * Description: |
|
15 * Login Dialog class of Authentication Application |
|
16 */ |
|
17 |
|
18 #include "authAppConstants.h" |
|
19 #include "sessionSP.h" |
|
20 #include "errorCodes.h" |
|
21 #include "loginDialog.h" |
|
22 #include <qdebug.h> |
|
23 |
|
24 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
25 // global |
|
26 |
|
27 static const QString kLoginURL = "http://www.last.fm/api/auth/";//http://www.flickr.com/services/auth/"; |
|
28 //static const QString kLoginURL = "http://www.flickr.com/auth-72157623913597531"; |
|
29 |
|
30 |
|
31 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
32 void FBLoginDialog::connectToGetSession() |
|
33 { |
|
34 if(iGetSessionRequest == NULL ){ |
|
35 |
|
36 iGetSessionRequest = FBRequest::requestWithSession(iSession); |
|
37 |
|
38 //connect(iGetSessionRequest, SIGNAL(requestDidLoad(QVariant)), this, SLOT(requestDidLoad(QVariant))); |
|
39 //connect(iGetSessionRequest, SIGNAL(requestFailedWithNetworkError(QNetworkReply::NetworkError)), this, SLOT(requestFailedWithNetworkError(QNetworkReply::NetworkError))); |
|
40 //connect(iGetSessionRequest, SIGNAL(requestFailedWithFlickrError(FBError)), this, SLOT(requestFailedWithFlickrError(FBError))); |
|
41 |
|
42 } |
|
43 |
|
44 iGetSessionRequest->callforToken(); |
|
45 } |
|
46 void FBLoginDialog::connecttoGetFrob() |
|
47 { |
|
48 qDebug()<<"Inside FBLoginDialog::connecttoGetFrob"; |
|
49 iGetSessionRequest = FBRequest::requestWithSession(iSession); |
|
50 |
|
51 connect(iGetSessionRequest, SIGNAL(requestDidLoad(QVariant)), this, SLOT(requestDidLoad(QVariant))); |
|
52 connect(iGetSessionRequest, SIGNAL(requestFailedWithNetworkError(QNetworkReply::NetworkError)), this, SLOT(requestFailedWithNetworkError(QNetworkReply::NetworkError))); |
|
53 connect(iGetSessionRequest, SIGNAL(requestFailedWithFlickrError(FBError)), this, SLOT(requestFailedWithFacebookError(FBError))); |
|
54 |
|
55 Dictionary params; |
|
56 |
|
57 iGetSessionRequest->call("auth.getToken", params); |
|
58 |
|
59 } |
|
60 void FBLoginDialog::loadLoginPage() |
|
61 { |
|
62 Dictionary getParams, postParams; |
|
63 |
|
64 getParams["api_key"] = iSession->apiKey(); |
|
65 getParams["token"] = iSession->apiToken(); |
|
66 QString fullURL; |
|
67 fullURL = kLoginURL; |
|
68 |
|
69 loadURL(fullURL,QNetworkAccessManager::GetOperation, getParams, postParams); |
|
70 |
|
71 } |
|
72 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
73 |
|
74 FBLoginDialog::FBLoginDialog() : FBDialog () {} |
|
75 |
|
76 FBLoginDialog::FBLoginDialog(FBSession* aSession) : FBDialog(aSession) {} |
|
77 |
|
78 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
79 // FBDialog |
|
80 |
|
81 void FBLoginDialog::load() |
|
82 { |
|
83 loadLoginPage(); |
|
84 } |
|
85 /////////////////////////////////////////////////////////////////////////////////////////////////// |
|
86 // slots for signals from FBRequest |
|
87 |
|
88 void FBLoginDialog::requestDidLoad(const QVariant& aResult) |
|
89 { |
|
90 qDebug()<<"Inside FBLoginDialog::requestDidLoad"; |
|
91 QVariantHash object = aResult.toHash(); |
|
92 |
|
93 QString mytoken = object.value("token").toString(); |
|
94 if(mytoken.length()){ |
|
95 iSession->SaveToken(mytoken); |
|
96 show(); |
|
97 } |
|
98 qDebug()<<"Token = "<<mytoken; |
|
99 qDebug() << "Root Object key : " << object.keys().takeFirst() << endl; |
|
100 |
|
101 if(object.keys().takeFirst().compare("session") == 0); |
|
102 { |
|
103 |
|
104 QVariantHash childobject = object.value("session").toHash(); |
|
105 qDebug() << "Child Object data : " << childobject << endl; |
|
106 QString userName = childobject.value("name").toString(); |
|
107 QString sessionKey = childobject.value("key").toString(); |
|
108 qDebug() << "Session Key value : " << sessionKey << endl; |
|
109 if(sessionKey.length()){ |
|
110 iSession->SaveSession(sessionKey,userName); |
|
111 } |
|
112 |
|
113 } |
|
114 } |
|
115 /*void FBLoginDialog::requestDidLoadSession(const QVariant& aResult) |
|
116 { |
|
117 qDebug()<<"Inside FBLoginDialog::requestDidLoadSession"; |
|
118 bool conversionError = false; |
|
119 QVariantHash object = aResult.toHash(); |
|
120 QVariantHash tagName = object.value("session").toHash(); |
|
121 QString mySession = tagName.value("key").toString(); |
|
122 if(mySession.length()){ |
|
123 iSession->SaveFrobKey(mySession); |
|
124 show(); |
|
125 } |
|
126 qDebug()<<"Session Key = "<<mySession; |
|
127 qDebug() << "Root Object key : " << object.keys().takeFirst() << endl; |
|
128 |
|
129 if(object.keys().takeFirst().compare("Session") == 0); |
|
130 { |
|
131 |
|
132 QVariantHash childobject = object.value("Session").toHash(); |
|
133 qDebug() << "Child Object data : " << childobject << endl; |
|
134 QString ses = childobject.value("key").toString(); |
|
135 qDebug() << "Read Token value : " << ses << endl; |
|
136 if(ses.length()){ |
|
137 iSession->Savetoken(ses); |
|
138 } |
|
139 |
|
140 } |
|
141 }*/ |
|
142 void FBLoginDialog::requestFailedWithFlickrError (const FBError& aCode ) |
|
143 { |
|
144 dismissWithError(aCode); |
|
145 } |
|
146 |
|
147 void FBLoginDialog::requestFailedWithNetworkError( QNetworkReply::NetworkError aCode ) |
|
148 { |
|
149 dismissWithError(aCode); |
|
150 } |