example/FlickrAuthApp/AuthApp.cpp
changeset 17 106a4bfcb866
child 26 83d6a149c755
equal deleted inserted replaced
16:b78fa4cdbf2b 17:106a4bfcb866
       
     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 *
       
    14 * Description:
       
    15 * UI Class of Authentication Application
       
    16 */
       
    17 
       
    18 #include "AuthApp.h"
       
    19 #include <QDebug>
       
    20 #include <QMessageBox>
       
    21 
       
    22 #include "keys.h"
       
    23 
       
    24 AuthApp::AuthApp(QWidget *parent)
       
    25     : QMainWindow(parent),
       
    26     ui(new Ui::AuthAppClass)
       
    27 {
       
    28 	ui->setupUi(this);
       
    29     //iFBSession = FBSession::sessionForApplication("df51def3e750a350ddb961a70b5ab5ab", "3b86a756f77967dea4674f080fa5d345", QString());
       
    30     //iFBSession = FBSession::sessionForApplication("114354298600019", "fb10f1c758fc285b2a6113344ef4c893", QString());		//Facebook keys
       
    31 	//iFBSession = FBSession::sessionForApplication("697207f5f3610334e02d828450e66589", "520edd7afff9b79f", QString());		//Flickr Mobile Based 
       
    32 	//iFBSession = FBSession::sessionForApplication("2d03ca48309291ee6815410c3a5bb278", "1bb754981c7c6974", QString());		//Flickr Web based
       
    33 	iFBSession = FBSession::sessionForApplication(kApiKey,kApiSecret, QString());		//Flickr Web based
       
    34     connect (iFBSession, SIGNAL(sessionDidLogout()), this, SLOT(sessionDidLogout()));
       
    35     connect (iFBSession,SIGNAL(sessionDidLogin(QString)), this, SLOT(sessionDidLogin(QString)));
       
    36 
       
    37     //CheckforLogin();
       
    38 }
       
    39 
       
    40 AuthApp::~AuthApp()
       
    41 {
       
    42 	delete iFBSession;
       
    43 	delete ui;
       
    44 }
       
    45 
       
    46 void AuthApp::changeEvent(QEvent *e)
       
    47 {
       
    48     QMainWindow::changeEvent(e);
       
    49     switch (e->type()) {
       
    50     case QEvent::LanguageChange:
       
    51         ui->retranslateUi(this);
       
    52         break;
       
    53     default:
       
    54         break;
       
    55     }
       
    56 }
       
    57 void AuthApp::CheckforLogin()
       
    58 {
       
    59 	iLoginDialog = NULL;
       
    60 	if ( !( iFBSession->resume() ) ){
       
    61 		ui->buttonForget->setDisabled(true);
       
    62 		ui->pushButton->setEnabled(true);
       
    63 	}
       
    64 }
       
    65 void AuthApp::on_pushButton_clicked()
       
    66 {
       
    67 	qDebug()<<"Inside AuthApp::on_pushButton_clicked";
       
    68         iLoginDialog = new FBLoginDialog();
       
    69         iLoginDialog->connecttoGetFrob();
       
    70     
       
    71 }
       
    72 void AuthApp::sessionDidLogin(QString Token)
       
    73 {
       
    74 
       
    75     if (iLoginDialog )
       
    76     {
       
    77 		QMessageBox msgbox;
       
    78 		QString msg ("Authorization completes!!");
       
    79 		msgbox.setText(msg);
       
    80 		msgbox.exec();
       
    81 		
       
    82         iLoginDialog->deleteLater();
       
    83         iLoginDialog = NULL;
       
    84     }else{
       
    85 		QMessageBox msgbox;
       
    86 		QString msg ("your already authorized,Please logout and Login again for new authorization!!");
       
    87 		msgbox.setText(msg);
       
    88 		msgbox.exec();
       
    89     }
       
    90     
       
    91     ui->pushButton->setDisabled(true);
       
    92     ui->buttonForget->setEnabled(true);
       
    93 }
       
    94 
       
    95 void AuthApp::sessionDidLogout()
       
    96 {
       
    97     QMessageBox msgbox;
       
    98     msgbox.setText("logged out successfully!!");
       
    99     msgbox.exec();
       
   100     
       
   101     ui->pushButton->setEnabled(true);
       
   102     ui->buttonForget->setDisabled(true);
       
   103     
       
   104 }
       
   105 void AuthApp::requestFailedWithFacebookError ( const FBError& aError )
       
   106 {
       
   107     qDebug() << "facebook error is " << aError.code() << " - " << aError.description();
       
   108 }
       
   109 
       
   110 void AuthApp::on_buttonForget_clicked()
       
   111 {
       
   112     iFBSession->logout();
       
   113 }