example/AuthApp/src/baseDialog.cpp
changeset 17 106a4bfcb866
parent 14 a469c0e6e7fb
child 26 83d6a149c755
equal deleted inserted replaced
16:b78fa4cdbf2b 17:106a4bfcb866
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 * Base class of All dialogs
    15 * Base class of All dialogs
    16 */
    16 */
    17 
    17 
       
    18 #define EMULATORTESTING // UnComment for Emulator build
    18 
    19 
    19 #include <QNetworkCookie>
    20 #include <QNetworkCookie>
    20 #include <QNetworkRequest>
    21 #include <QNetworkRequest>
    21 #include <QNetworkReply>
    22 #include <QNetworkReply>
    22 #include <QWebFrame>
    23 #include <QWebFrame>
    62     
    63     
    63     
    64     
    64     progressbar = new QProgressBar(this);
    65     progressbar = new QProgressBar(this);
    65     
    66     
    66     layout->addWidget(iWebView);
    67     layout->addWidget(iWebView);
    67     layout->addWidget(progressbar);
    68     //layout->addWidget(progressbar);
    68     
    69     
    69     setLayout(layout);
    70     setLayout(layout);
    70     
    71     
    71     progressbar->setOrientation(Qt::Horizontal);
    72     progressbar->setOrientation(Qt::Horizontal);
    72     
    73     
    85     connect (iWebView->page()->networkAccessManager(),SIGNAL( proxyAuthenticationRequired(QNetworkProxy&, QAuthenticator*)),this,SLOT( slotproxyAuthenticationRequired(QNetworkProxy&, QAuthenticator*)) );
    86     connect (iWebView->page()->networkAccessManager(),SIGNAL( proxyAuthenticationRequired(QNetworkProxy&, QAuthenticator*)),this,SLOT( slotproxyAuthenticationRequired(QNetworkProxy&, QAuthenticator*)) );
    86     
    87     
    87 }
    88 }
    88 QString FBDialog::generateURL( const QString& aUrl, const QHash<QString, QString>& aParams) const
    89 QString FBDialog::generateURL( const QString& aUrl, const QHash<QString, QString>& aParams) const
    89 {
    90 {
       
    91 	qDebug()<<"Inside FBDialog::generateURL()";
    90     QString url ( aUrl );
    92     QString url ( aUrl );
    91 
    93 
    92     QStringList pairs;
    94     QStringList pairs;
    93     QHashIterator<QString, QString> i(aParams);
    95     QHashIterator<QString, QString> i(aParams);
    94 
    96 
   109 
   111 
   110 }
   112 }
   111 
   113 
   112 QByteArray FBDialog::generatePostBody (const QHash<QString, QString>& aParams) const
   114 QByteArray FBDialog::generatePostBody (const QHash<QString, QString>& aParams) const
   113 {
   115 {
       
   116 	qDebug()<<"Inside FBDialog::generatePostBody()";
   114     QByteArray body;
   117     QByteArray body;
   115 
   118 
   116     if (!aParams.count())
   119     if (!aParams.count())
   117         return body;
   120         return body;
   118 
   121 
   141     //accept();
   144     //accept();
   142     // could also be reject()?
   145     // could also be reject()?
   143 }
   146 }
   144 
   147 
   145 void FBDialog::dismiss (bool /*aAnimated*/) {
   148 void FBDialog::dismiss (bool /*aAnimated*/) {
       
   149 	qDebug()<<"Inside FBDialog::dismiss()";
   146     dialogWillDisappear();
   150     dialogWillDisappear();
   147     iLoadingUrl.clear();
   151     iLoadingUrl.clear();
   148 
   152 
   149     //todo: do some animations if aAnimated == true !
   153     //todo: do some animations if aAnimated == true !
   150     postDismissCleanup();
   154     postDismissCleanup();
   151 }
   155 }
   152 
   156 
   153 
   157 
   154 void FBDialog::dismissWithSuccess( bool aSuccess, bool aAnimated)
   158 void FBDialog::dismissWithSuccess( bool aSuccess, bool aAnimated)
   155 {
   159 {
       
   160 	qDebug()<<"Inside FBDialog::dismissWithSuccess()";
   156   if (aSuccess) {
   161   if (aSuccess) {
   157         emit dialogDidSucceed();
   162         emit dialogDidSucceed();
   158   } else {
   163   } else {
   159         emit dialogDidCancel();
   164         emit dialogDidCancel();
   160   }
   165   }
   162   dismiss(aAnimated);
   167   dismiss(aAnimated);
   163 }
   168 }
   164 
   169 
   165 void FBDialog::dismissWithError (const FBError& aError, bool aAnimated)
   170 void FBDialog::dismissWithError (const FBError& aError, bool aAnimated)
   166 {
   171 {
       
   172 	qDebug()<<"Inside FBDialog::dismissWithError()";
   167   emit dialogDidFailWithError( aError );
   173   emit dialogDidFailWithError( aError );
   168   dismiss(aAnimated);
   174   dismiss(aAnimated);
   169 }
   175 }
   170 void FBDialog::slotAuthenticationRequired( QNetworkReply* reply, QAuthenticator* authenticator )
   176 void FBDialog::slotAuthenticationRequired( QNetworkReply* reply, QAuthenticator* authenticator )
   171 	{
   177 	{
   186 		msgbox.setText(msg);
   192 		msgbox.setText(msg);
   187 	}
   193 	}
   188 void FBDialog::cancel()
   194 void FBDialog::cancel()
   189 {}
   195 {}
   190 
   196 
   191 void FBDialog::load() {}
   197 void FBDialog::load() {
       
   198 	qDebug()<<"Inside FBDialog::load()";
       
   199 }
   192 
   200 
   193 void FBDialog::show()
   201 void FBDialog::show()
   194 {
   202 {
   195 
   203 	qDebug()<<"Inside FBDialog::show()";
   196     load();
   204     load();
   197     showMaximized();
   205     showMaximized();
   198     dialogWillAppear();
   206     dialogWillAppear();
   199 
   207 
   200 }
   208 }
   201 
   209 
   202 void FBDialog::loadURL(const QString& aUrl, QNetworkAccessManager::Operation aMethod, const QHash<QString, QString>& aGetParams, const QHash<QString, QString>&  aPostParams)
   210 void FBDialog::loadURL(const QString& aUrl, QNetworkAccessManager::Operation aMethod, const QHash<QString, QString>& aGetParams, const QHash<QString, QString>&  aPostParams)
   203 {   
   211 {   
       
   212 	qDebug()<<"Inside FBDialog::loadURL()";
   204     //proxysettings();
   213     //proxysettings();
   205     iIgnorePageLoadCompleteEvent = false;
   214     iIgnorePageLoadCompleteEvent = false;
   206 
   215 
   207     QNetworkCookieJar* cookieJar = iWebView->page()->networkAccessManager()->cookieJar();
   216     QNetworkCookieJar* cookieJar = iWebView->page()->networkAccessManager()->cookieJar();
   208     QByteArray body;
   217     QByteArray body;
   226     {
   235     {
   227         const QString contentType = "multipart/form-data; boundary=" + kStringBoundary;
   236         const QString contentType = "multipart/form-data; boundary=" + kStringBoundary;
   228         request.setHeader (QNetworkRequest::ContentTypeHeader, contentType);
   237         request.setHeader (QNetworkRequest::ContentTypeHeader, contentType);
   229         body = generatePostBody (aPostParams);
   238         body = generatePostBody (aPostParams);
   230     }
   239     }
   231 	#ifdef __WINSCW__ 
       
   232     proxysettings();
   240     proxysettings();
   233 	#endif
       
   234     
   241     
   235     qDebug()<< "Check URL : " << iLoadingUrl;
   242     qDebug()<< "Check URL : " << iLoadingUrl;
   236 
   243 
   237     iWebView->load ( request, aMethod, body);
   244     iWebView->load ( request, aMethod, body);
   238 
   245     
   239 }
   246 }
   240 void FBDialog::proxysettings()
   247 void FBDialog::proxysettings()
   241 {
   248 {
   242 
   249 #ifdef EMULATORTESTING
   243 	qDebug()<<"proxysettings";
   250 	qDebug()<<"proxysettings";
       
   251 	
       
   252 	// Reading the keys, CSM Stubbed - START
       
   253 	QFile file("c:\\data\\DoNotShare.txt");
       
   254 	if (!file.open(QIODevice::ReadOnly))
       
   255 		{
       
   256 		qDebug()<<"File to read the windows username and password could not be opened, returning!!!";
       
   257 		return;
       
   258 		}
       
   259 	
       
   260 	QByteArray arr = file.readAll();
       
   261 	QList<QByteArray> list = arr.split(' ');
       
   262 	file.close();
       
   263 	
       
   264 	QString username(list[0]);
       
   265 	QString password(list[1]);
       
   266 	
   244     QString httpProxy = "10.1.0.214";//ipwproxy.sasken.com
   267     QString httpProxy = "10.1.0.214";//ipwproxy.sasken.com
   245     QString httpPort = "3128";
   268     QString httpPort = "3128";
   246 
   269 
   247     QString httpUser ="";/* This could be taken thru an QDialog implmentation to remove the Hard coding */
   270     QString httpUser =username;/* This could be taken thru an QDialog implmentation to remove the Hard coding */
   248     QString httpPass ="";/* This could be taken thru an QDialog implmentation to remove the Hard coding */
   271     QString httpPass =password;/* This could be taken thru an QDialog implmentation to remove the Hard coding */
   249 
   272 
   250     /*==Classes used from Network Module==*/
   273     /*==Classes used from Network Module==*/
   251     QNetworkProxy proxy;
   274     QNetworkProxy proxy;
   252 
   275 
   253     proxy.setType(QNetworkProxy::HttpProxy);
   276     proxy.setType(QNetworkProxy::HttpProxy);
   255     proxy.setPort(httpPort.toInt());
   278     proxy.setPort(httpPort.toInt());
   256     proxy.setUser(httpUser);
   279     proxy.setUser(httpUser);
   257     proxy.setPassword(httpPass);
   280     proxy.setPassword(httpPass);
   258 
   281 
   259     QNetworkProxy::setApplicationProxy(proxy);
   282     QNetworkProxy::setApplicationProxy(proxy);
   260 
   283 #endif
   261 }
   284 }
   262 void FBDialog::dialogWillAppear() {}
   285 void FBDialog::dialogWillAppear() {}
   263 
   286 
   264 void FBDialog::dialogWillDisappear() {}
   287 void FBDialog::dialogWillDisappear() {}
   265 
   288 
   270 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
   293 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
   271 void FBDialog::linkClicked ( const QUrl & url )
   294 void FBDialog::linkClicked ( const QUrl & url )
   272  {
   295  {
   273 
   296 
   274         qDebug() << "Loading the url: " <<  url;
   297         qDebug() << "Loading the url: " <<  url;
       
   298         
   275         proxysettings();
   299         proxysettings();
       
   300 			
   276         iWebView->load(url);
   301         iWebView->load(url);
   277 }
   302 }
   278 
   303 
   279 void FBDialog::loadStarted()
   304 void FBDialog::loadStarted()
   280 {
   305 {
   281     qDebug() << "Load started: " << iWebView->url();
   306     qDebug() << "Load started: " << iWebView->url();
       
   307     layout->addWidget(progressbar);
   282     progressbar->setVisible(true);
   308     progressbar->setVisible(true);
   283 }
   309 }
   284 void FBDialog::loadProgress(int progress)
   310 void FBDialog::loadProgress(int progress)
   285 {
   311 {
   286 	progressbar->setValue(progress);
   312 	progressbar->setValue(progress);
   287 }
   313 }
   288 void FBDialog::GetSessionKey(const QUrl& aUrl)
   314 void FBDialog::GetSessionKey(const QUrl& aUrl)
       
   315 {
       
   316 
       
   317 }
       
   318 void FBDialog::FetchKeyFromUrl(const QUrl& aUrl)
   289 {
   319 {
   290 
   320 
   291 }
   321 }
   292 void FBDialog::loadFinished ( bool ok )
   322 void FBDialog::loadFinished ( bool ok )
   293 {
   323 {
   294     qDebug() << "Load " << (ok ? "" : "un") << "successfull for: " << iWebView->url();
   324     qDebug() << "Load " << (ok ? "" : "un") << "successfull for: " << iWebView->url();
   295     progressbar->setVisible(false);
   325     progressbar->setVisible(false);
       
   326     layout->removeWidget(progressbar);
   296     if (ok)
   327     if (ok)
   297     {
   328     {
   298 		QString PAth = iWebView->url().toString();
   329 		QString PAth = iWebView->url().toString();
   299 		PAth = PAth.mid(0,PAth.indexOf("?"));
   330 		PAth = PAth.mid(0,PAth.indexOf("?"));
   300 		
   331 		
   305 			QByteArray URL = iWebView->url().encodedQuery();
   336 			QByteArray URL = iWebView->url().encodedQuery();
   306 			qDebug() << "Encoded Query is : " << URL;
   337 			qDebug() << "Encoded Query is : " << URL;
   307 			
   338 			
   308 			if(URL.contains("auth_token"))
   339 			if(URL.contains("auth_token"))
   309 				{
   340 				{
       
   341 					qDebug() << "URL contains auth token";
   310 					iWebView->setHidden(true);
   342 					iWebView->setHidden(true);
   311 					QMessageBox msgbox;
   343 					QMessageBox msgbox;
   312 					QString msg ("Logged in Success!!!Complete the Authorization?");
   344 					QString msg ("Logged in Success!!!Complete the Authorization?");
   313 					msgbox.setText(msg);
   345 					msgbox.setText(msg);
   314 					if(msgbox.exec() == QMessageBox::Ok){
   346 					if(msgbox.exec() == QMessageBox::Ok){
   315 						GetSessionKey(iWebView->url());
   347 						GetSessionKey(iWebView->url());
   316 					}else{
   348 					}else{
   317 						
   349 						
   318 					}
   350 					}
   319 				}
   351 				}
       
   352 			else if(URL.contains("session_key") && URL.contains("uid"))
       
   353 				{
       
   354 					FetchKeyFromUrl(iWebView->url());
       
   355 				}
   320 			else
   356 			else
   321 				{
   357 				{
       
   358 					qDebug() << "URL doesnt have auth_token field";
   322 					iWebView->setHidden(true);
   359 					iWebView->setHidden(true);
   323 					QMessageBox msgbox;
   360 					QMessageBox msgbox;
   324 					QString msg ("Permissions Success!!!continue login?");
   361 					QString msg ("Permissions Success!!!continue login?");
   325 					msgbox.setText(msg);
   362 					msgbox.setText(msg);
   326 					if(msgbox.exec() == QMessageBox::Ok){
   363 					if(msgbox.exec() == QMessageBox::Ok){