Implemented username saving to settings and loading. Saved username store_username
authorlampehe-local <henri.lampela@ixonos.com>
Wed, 19 May 2010 10:18:59 +0000 (13:18 +0300)
committerlampehe-local <henri.lampela@ixonos.com>
Wed, 19 May 2010 10:18:59 +0000 (13:18 +0300)
is shown in login dialog when it is needed.
Reviewed by: Kaj Wallin

src/engine/engine.cpp
src/engine/engine.h
src/facebookservice/facebookauthentication.cpp
src/facebookservice/facebookauthentication.h
src/facebookservice/facebookcommon.h
src/situareservice/situareservice.cpp
src/situareservice/situareservice.h
src/ui/logindialog.cpp
src/ui/logindialog.h
src/ui/mainwindow.cpp
src/ui/mainwindow.h

index 6cfa817..1f98ae3 100644 (file)
@@ -55,12 +55,15 @@ SituareEngine::SituareEngine(QMainWindow *parent)
 #endif
     m_gps->setMode(GPSPositionInterface::Default);
 
-    connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
-            m_situareService, SLOT(credentialsReady(FacebookCredentials)));
-    connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
-            this, SLOT(loginOk()));
+
+    connect(m_facebookAuthenticator, SIGNAL(credentialsReady(bool, FacebookCredentials)),
+            m_situareService, SLOT(credentialsReady(bool, FacebookCredentials)));
+    connect(m_facebookAuthenticator, SIGNAL(credentialsReady(bool, FacebookCredentials)),
+            this, SLOT(loginOk(bool)));
     connect(m_ui, SIGNAL(cancelLoginProcess()),
             this, SLOT(loginProcessCancelled()));
+    connect(m_ui, SIGNAL(fetchUsernameFromSettings()),
+            this, SLOT(fetchUsernameFromSettings()));
 
     connect(m_ui, SIGNAL(requestReverseGeo()),
             this, SLOT(requestAddress()));
@@ -143,10 +146,13 @@ void SituareEngine::error(const QString &error)
     // ToDo: signal UI?
 }
 
-void SituareEngine::loginOk()
+void SituareEngine::loginOk(bool freshLogin)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
+    if(freshLogin) {
+        m_facebookAuthenticator->saveUsername(m_ui->username());
+    }
     m_ui->show();
     m_situareService->fetchLocations(); // request user locations
 }
@@ -247,3 +253,9 @@ void SituareEngine::receiveOwnLocation(QPointF ownLocation)
     qDebug() << __PRETTY_FUNCTION__;
     m_latestLocation = ownLocation;
 }
+
+void SituareEngine::fetchUsernameFromSettings()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+    m_ui->setUsername(m_facebookAuthenticator->loadUsername());
+}
index 3e7df39..074ad0d 100644 (file)
@@ -69,9 +69,17 @@ public slots:
     void error(const QString &error);
 
     /**
+    * @brief Slot to intercept signal when username is fetched from settings
+    *
+    */
+    void fetchUsernameFromSettings();
+
+    /**
     * @brief Slot to intercept signal from successful login
+    *
+    * @param freshLogin Was login done via login dialog
     */
-    void loginOk();
+    void loginOk(bool freshLogin);
 
     /**
     * @brief Slot to receive location of crosshair
index b28fc63..e8c9ef2 100644 (file)
@@ -33,7 +33,7 @@
 
 #include "facebookauthentication.h"
 #include "facebookcommon.h"
-#include "common.h"
+#include "../common.h"
 #include "parser.h"
 
 FacebookAuthentication::FacebookAuthentication(QObject *parent)
@@ -63,7 +63,7 @@ void FacebookAuthentication::start()
         emit newLoginRequest(formLoginPageUrl(list));
     }
     else
-        emit credentialsReady(m_loginCredentials);
+        emit credentialsReady(false, m_loginCredentials);
 }
 
 bool FacebookAuthentication::updateCredentials(const QUrl &url)
@@ -125,7 +125,7 @@ bool FacebookAuthentication::updateCredentials(const QUrl &url)
                 found = true;
             }
             writeCredentials(m_loginCredentials);
-            emit credentialsReady(m_loginCredentials);
+            emit credentialsReady(true, m_loginCredentials);
         }
         else if ( callbackUrl.indexOf(LOGIN_FAILURE_REPLY) == 0){
             qWarning() << "login failure" << endl;
@@ -218,3 +218,19 @@ void FacebookAuthentication::readCredentials(FacebookCredentials &credentialsFro
 
     return QUrl(urlParts.join(EMPTY));
  }
+
+ void FacebookAuthentication::saveUsername(const QString &username)
+ {
+     qDebug() << __PRETTY_FUNCTION__;
+
+     QSettings settings(DIRECTORY_NAME, FILE_NAME);
+     settings.setValue(USERNAME, username);
+ }
+
+ const QString FacebookAuthentication::loadUsername()
+ {
+     qDebug() << __PRETTY_FUNCTION__;
+
+     QSettings settings(DIRECTORY_NAME, FILE_NAME);
+     return settings.value(USERNAME, EMPTY).toString();
+ }
index bf2201a..e4c5883 100644 (file)
@@ -62,6 +62,20 @@ public:
 public slots:
 
     /**
+    * @brief Loads username from settings
+    *
+    * @return QString Loaded username
+    */
+    const QString loadUsername();
+
+    /**
+    * @brief Saves username to settings
+    *
+    * @param username Username to be saved
+    */
+    void saveUsername(const QString &username);
+
+    /**
     * @brief Shows the m_webView and loads page that is specified in the m_facebookLoginPage
     *        variable. Specifies font size for the page.
     *    
@@ -103,6 +117,7 @@ private:
     void writeCredentials(const FacebookCredentials &credentials);
 
 private slots:
+
     /**
     * @brief  Search credentials from URL that is given as parameter.
     *         If credentials are found thay are stored to loginCredentials variable.
@@ -124,9 +139,10 @@ signals:
     *        Signal is also emitted at the beginning of the program if there is valid credentials
     *        in the file.
     *
+    * @param freshLogin Was login done via login dialog
     * @param credentials New credentials
     */
-    void credentialsReady(const FacebookCredentials &credentials);
+    void credentialsReady(bool freshLogin, const FacebookCredentials &credentials);
 
     /**
     * @brief This signal is emitted if updateCredentials method can't find credentials from URL
@@ -147,6 +163,8 @@ signals:
 
 private:
 
+    int m_loginAttempts; ///< Indicates login attempts
+
     /**
     * @brief Dataclass that contains authorization to use facebook. Dataclass is composed of five
     *        QStrings and setters and getters.
@@ -154,8 +172,6 @@ private:
     * @var m_loginCredentials
     */
     FacebookCredentials m_loginCredentials;
-
-    int m_loginAttempts; ///< Indicates login attempts
 };
 
 #endif // FACEBOOKAUTHENTICATION_H
index 7758978..3b95c5d 100644 (file)
@@ -40,13 +40,16 @@ const QString ERROR = "Error";
 // Facebook webView font size
 const double FACEBOOK_LOGINPAGE_FONT_SIZE = 1.2;
 
-// Facebook callback url indentifiers
+// Facebook callback url indentifiers and setting items
 const QString SESSION_KEY = "session_key";
 const QString USER_ID = "uid";
 const QString EXPIRES = "expires";
 const QString SESSION_SECRET = "secret";
 const QString SIGNATURE = "sig";
 
+// Login setting items
+const QString USERNAME = "username";
+
 const QString LOGIN_SUCCESS_REPLY = "http://www.facebook.com/connect/login_success.html";
 const QString LOGIN_FAILURE_REPLY = "https://login.facebook.com/login.php?login_attempt=";
 const QString LOGIN_PAGE = "http://www.facebook.com/login.php?api_key=";
index 7e319e9..009b073 100644 (file)
@@ -289,9 +289,10 @@ void SituareService::requestFinished(QNetworkReply *reply)
     reply->deleteLater();
 }
 
-void SituareService::credentialsReady(const FacebookCredentials &credentials)
+void SituareService::credentialsReady(bool freshLogin, const FacebookCredentials &credentials)
 {
     qDebug() << __PRETTY_FUNCTION__;
+    Q_UNUSED(freshLogin);
     m_credentials = credentials;
     
 }
index 35f38bd..179d6b8 100644 (file)
@@ -97,9 +97,10 @@ public slots:
     /**
     * @brief Public slot, which indicates when facebook credentials are ready
     *
+    * @param freshLogin Was login done via login dialog
     * @param credentials New credentials
     */
-    void credentialsReady(const FacebookCredentials &credentials);
+    void credentialsReady(bool freshLogin, const FacebookCredentials &credentials);
 
 private:
 
index 6870c7c..6cadf64 100644 (file)
@@ -64,3 +64,12 @@ void LoginDialog::connectPressed()
 
     accept();
 }
+
+void LoginDialog::setEmailField(const QString &email)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+    if(!email.isEmpty()) {
+        m_emailEdit->setText(email);
+        m_passwordEdit->setFocus(Qt::OtherFocusReason);
+    }
+}
index 6d180e6..a518c7f 100644 (file)
@@ -52,6 +52,15 @@ public:
  * MEMBER FUNCTIONS AND SLOTS
  ******************************************************************************/
 
+public slots:
+
+    /**
+    * @brief Sets email address to emailEdit field
+    *
+    * @param email E-mail address to be set
+    */
+    void setEmailField(const QString &email);
+
 private slots:
 
     /**
@@ -78,7 +87,6 @@ private:
 
     QLineEdit *m_emailEdit; ///< Pointer to email line edit
     QLineEdit *m_passwordEdit; ///< Pointer to password line edit
-
 };
 
 
index bcd4992..17c170e 100644 (file)
@@ -53,8 +53,6 @@ MainWindow::MainWindow(QWidget *parent)
     setWindowTitle(tr("Situare"));
     show();
 
-    m_locationDialog = new UpdateLocationDialog(this);
-
     connect(this, SIGNAL(reverseGeoReady(QString)),
             m_mapViewScreen, SIGNAL(reverseGeoReady(QString)));
     connect(m_mapViewScreen, SIGNAL(statusUpdate(QString,bool)),
@@ -256,6 +254,12 @@ void MainWindow::startLoginProcess(const QUrl &url)
 
     m_webView->hide();
 
+    emit fetchUsernameFromSettings();
+
+    if(!m_email.isEmpty()) {
+        m_loginDialog->setEmailField(m_email);
+    }
+
     if(m_loginDialog->exec() != QDialog::Accepted) {
         // if login dialog was canceled we need to stop processing webview
         // stop and disconnect m_webView;
@@ -297,6 +301,10 @@ void MainWindow::loginFailed()
 
 #endif // Q_WS_MAEMO_5
 
+    if(!m_email.isEmpty()) {
+        m_loginDialog->setEmailField(m_email);
+    }
+
     if(m_loginDialog->exec() != QDialog::Accepted) {
         // if login dialog was canceled we need to stop processing webview
         // stop and disconnect m_webView;
@@ -402,3 +410,15 @@ void MainWindow::keyPressEvent(QKeyEvent* event)
     }
     QWidget::keyPressEvent(event);
 }
+
+const QString MainWindow::username()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+    return m_email;
+}
+
+void MainWindow::setUsername(const QString &username)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+    m_email = username;
+}
index fe91142..4f10b01 100644 (file)
@@ -33,7 +33,6 @@
 #include "facebookservice/facebookauthentication.h"
 #include "situareservice/situareservice.h"
 #include "mapviewscreen.h"
-#include "updatelocation/updatelocationdialog.h"
 #include "ui/logindialog.h"
 
 class QLabel;
@@ -95,6 +94,13 @@ public:
     */
     void setGPSButton(bool enabled);
 
+    /**
+    * @brief Gets the username from member variable for saving purposes
+    *
+    * @return QString Username
+    */
+    const QString username();
+
 public slots:
     /**
     * @brief Slot for auto centering enabling.
@@ -135,6 +141,13 @@ public slots:
     void openSettingsDialog();
 
     /**
+    * @brief Sets username to member variable for login dialog
+    *
+    * @param username Username to be set
+    */
+    void setUsername(const QString &username);
+
+    /**
     * @brief Public slot to intercept signal when old cerdentials are invalid or credentials
     *        doesn't exist yet
     *
@@ -196,17 +209,17 @@ private slots:
  ******************************************************************************/
 signals:
     /**
-    * @brief Signal that indicates when user has cancelled login process
+    * @brief Signal for map auto centering
     *
+    * @param enabled true if map should auto center to gps location
     */
-    void cancelLoginProcess();
+    void autoCentering(bool enabled);
 
     /**
-    * @brief Signal for map auto centering
+    * @brief Signal that indicates when user has cancelled login process
     *
-    * @param enabled true if map should auto center to gps location
     */
-    void autoCentering(bool enabled);
+    void cancelLoginProcess();
 
     /**
     * @brief Signal for gps enabling.
@@ -223,6 +236,12 @@ signals:
     void enableAutoCentering(bool enabled);
 
     /**
+    * @brief Signal for requesting username from settings
+    *
+    */
+    void fetchUsernameFromSettings();
+
+    /**
     * @brief Signal for friend location ready.
     *
     * @param friendsList
@@ -306,7 +325,6 @@ private:
     QAction *m_autoCenteringAct;    ///< Action to auto center map using gps position
     QString m_email; ///< Placeholder for email
     QAction *m_gpsToggleAct;    ///< Action to trigger gps toggle
-    UpdateLocationDialog *m_locationDialog; ///< Message dialog
     LoginDialog *m_loginDialog; ///< Login dialog
     QUrl m_loginUrl; ///< Placeholder for login page url
     MapViewScreen *m_mapViewScreen; ///< Instance of the map view