example/TwitterAuthApp/inc/baseDialog.h
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 * Narasimhulu Kavadapu, Sasken Communication Technologies Ltd - Initial contribution
       
    11 *
       
    12 * Contributors:
       
    13 * Siddhartha Chandra, Sasken Communication Technologies Ltd
       
    14 * Description:
       
    15 * Base class of All dialogs
       
    16 */
       
    17 
       
    18 #ifndef FB_DIALOG_H_
       
    19 #define FB_DIALOH_H_
       
    20 
       
    21 #include <QDialog>
       
    22 #include <QWebView>
       
    23 #include <qprogressbar.h>
       
    24 #include <qboxlayout.h>
       
    25 #include "authAppConstants.h"
       
    26 
       
    27 // FORWARD DECLARATIONS
       
    28 class FBSession;
       
    29 class FBError;
       
    30 class QNetworkReply;
       
    31 
       
    32 /**
       
    33   * The base Dialoggg
       
    34   */
       
    35 class FBDialog : public QWidget
       
    36 {
       
    37     Q_OBJECT
       
    38 
       
    39 protected:
       
    40 
       
    41     /**
       
    42     * The session for which the login is taking place.
       
    43     */
       
    44     FBSession*	iSession;
       
    45     QWebView*	iWebView;
       
    46     QString	iLoadingUrl;
       
    47     bool        iIgnorePageLoadCompleteEvent;
       
    48     QProgressBar* progressbar;
       
    49     QVBoxLayout* layout;
       
    50 
       
    51 signals:
       
    52 
       
    53     /**
       
    54      * Called when the dialog succeeds and is about to be dismissed.
       
    55      */
       
    56     void dialogDidSucceed ();
       
    57 
       
    58     /**
       
    59      * Called when the dialog is cancelled and is about to be dismissed.
       
    60      */
       
    61     void dialogDidCancel();
       
    62 
       
    63     /**
       
    64      * Called when dialog failed to load due to an error.
       
    65      */
       
    66     void dialogDidFailWithError ( const FBError& error );
       
    67 
       
    68 
       
    69 	
       
    70 private slots:
       
    71     void cancel();
       
    72 
       
    73     /* slots for signals from QWebView.page() */
       
    74     void linkClicked ( const QUrl & url );
       
    75     void loadStarted ();
       
    76     void loadProgress(int progress);
       
    77     void loadFinished ( bool ok );
       
    78     
       
    79     //Network Error Slots
       
    80     void slotAuthenticationRequired( QNetworkReply* reply, QAuthenticator* authenticator );
       
    81     void slotsslErrors( QNetworkReply* reply, const QList<QSslError>& errors  );
       
    82     void slotproxyAuthenticationRequired( const QNetworkProxy& proxy, QAuthenticator* authenticator  );
       
    83 
       
    84 public:
       
    85 	
       
    86 	void proxysettings();
       
    87     /**
       
    88     * Creates the view but does not display it.
       
    89     */
       
    90     FBDialog(FBSession* aSession);
       
    91     FBDialog();
       
    92 
       
    93     /**
       
    94     * Displays the view with an animation.
       
    95     *
       
    96     * The view will be added to the top of the current key window.
       
    97     */
       
    98     void show();
       
    99 	
       
   100     /** Displays the first page of the dialog.
       
   101      *
       
   102      * Do not ever call this directly.  It is intended to be overriden by subclasses.
       
   103      */
       
   104     virtual void load ();
       
   105 	
       
   106     /**
       
   107      * Displays a URL in the dialog.
       
   108      */
       
   109     void loadURL(const QString& aUrl, QNetworkAccessManager::Operation aMethod, const QHash<QString, QString>& aGetParams,
       
   110                  const QHash<QString, QString>&  aPostParams);
       
   111 
       
   112 
       
   113     void dismiss(bool aAnimated);
       
   114 
       
   115     /**
       
   116      * Hides the view and notifies delegates of success or cancellation.
       
   117      */
       
   118     void dismissWithSuccess (bool aSuccess, bool aAnimated);
       
   119 
       
   120     /**
       
   121     * Hides the view and notifies delegates of an error.
       
   122     */
       
   123     void dismissWithError (const FBError& aError, bool aAnimated);
       
   124 
       
   125     /**
       
   126     * Subclasses may override to perform actions just prior to showing the dialog.
       
   127     */
       
   128     virtual void dialogWillAppear();
       
   129 
       
   130     /**
       
   131      * Subclasses may override to perform actions just after the dialog is hidden.
       
   132      */
       
   133     virtual void dialogWillDisappear();
       
   134 
       
   135     /**
       
   136      * Subclasses should override to process data returned from the server in a 'fbconnect' url.
       
   137      *
       
   138      * Implementations must call dismissWithSuccess:YES at some point to hide the dialog.
       
   139      */
       
   140     virtual void dialogDidSucceed(const QUrl& aUrl);
       
   141 	
       
   142     QString title() const;
       
   143     void setTitle ( const QString& aTitle );
       
   144     
       
   145     virtual void GetSessionKey(const QUrl& aUrl);
       
   146     virtual void FetchKeyFromUrl(const QUrl& aUrl);
       
   147 private:
       
   148     void createControls();
       
   149     QString generateURL( const QString& aUrl, const QHash<QString, QString>& aParams) const;
       
   150     QByteArray generatePostBody (const QHash<QString, QString>& aParams) const;
       
   151 
       
   152     void postDismissCleanup();
       
   153 
       
   154 public:
       
   155     virtual void GetAccessToken();
       
   156  };
       
   157 #endif