example/LinkedInAuthApp/AuthApp.cpp
changeset 26 83d6a149c755
equal deleted inserted replaced
25:a180113055cb 26:83d6a149c755
       
     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 * Siddhartha Chandra, Sasken Communication Technologies Ltd - Initial contribution
       
    11 *
       
    12 * Contributors:
       
    13 * Siddhartha Chandra, Satish Kanteti Sasken Communication Technologies Ltd
       
    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 	qDebug()<<"Inside AuthApp::AuthApp()";
       
    29 	ui->setupUi(this);
       
    30 	iFBSession = FBSession::sessionForApplication(kConsumerKey,kConsumerSecret, QString());
       
    31 	connect (iFBSession,SIGNAL(sessionDidLogin(QString)), this, SLOT(sessionDidLogin(QString)));
       
    32     connect (iFBSession, SIGNAL(sessionDidLogout()), this, SLOT(sessionDidLogout()));
       
    33     
       
    34     //CheckforLogin();
       
    35 }
       
    36 
       
    37 AuthApp::~AuthApp()
       
    38 {
       
    39 	delete iFBSession;
       
    40 	delete ui;
       
    41 }
       
    42 
       
    43 void AuthApp::changeEvent(QEvent *e)
       
    44 {
       
    45     QMainWindow::changeEvent(e);
       
    46     switch (e->type()) {
       
    47     case QEvent::LanguageChange:
       
    48         ui->retranslateUi(this);
       
    49         break;
       
    50     default:
       
    51         break;
       
    52     }
       
    53 }
       
    54 void AuthApp::CheckforLogin()
       
    55 {
       
    56 	qDebug()<<"Inside AuthApp::CheckforLogin()";
       
    57 	iLoginDialog = NULL;
       
    58 	if ( !( iFBSession->resume() ) ){
       
    59 		ui->buttonForget->setDisabled(true);
       
    60 		ui->pushButton->setEnabled(true);
       
    61 	}
       
    62 }
       
    63 void AuthApp::on_pushButton_clicked()
       
    64 {
       
    65 	qDebug()<<"Inside AuthApp::on_pushButton_clicked()";
       
    66 	iLoginDialog = new FBLoginDialog();
       
    67 	//iLoginDialog->connectToGetToken();
       
    68 	iLoginDialog->show();
       
    69 }
       
    70 void AuthApp::sessionDidLogin(QString sessionkey)
       
    71 {
       
    72 	Q_UNUSED(sessionkey)
       
    73 	qDebug()<<"Inside AuthApp::sessionDidLogin()";
       
    74     if (iLoginDialog )
       
    75     {
       
    76 		QMessageBox msgbox;
       
    77 		QString msg ("Authorization completes!!");
       
    78 		msgbox.setText(msg);
       
    79 		msgbox.exec();
       
    80 		
       
    81         iLoginDialog->deleteLater();;
       
    82         iLoginDialog = NULL;
       
    83     }else{
       
    84 		QMessageBox msgbox;
       
    85 		QString msg ("your already authorized,Please logout and Login again for new authorization!!");
       
    86 		msgbox.setText(msg);
       
    87 		msgbox.exec();
       
    88     }
       
    89     
       
    90     ui->pushButton->setDisabled(true);
       
    91     ui->buttonForget->setEnabled(true);
       
    92 }
       
    93 
       
    94 void AuthApp::sessionDidLogout()
       
    95 {
       
    96 	qDebug()<<"Inside AuthApp::sessionDidLogout()";
       
    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 	qDebug()<<"Inside AuthApp::on_buttonForget_clicked()";
       
   113     iFBSession->logout();
       
   114 }