Changed implementation
authorlampehe-local <henri.lampela@ixonos.com>
Mon, 7 Jun 2010 09:06:51 +0000 (12:06 +0300)
committerlampehe-local <henri.lampela@ixonos.com>
Mon, 7 Jun 2010 09:06:51 +0000 (12:06 +0300)
src/engine/engine.cpp
src/facebookservice/facebookauthentication.cpp
src/facebookservice/facebookauthentication.h
src/notedata.cpp [deleted file]
src/notedata.h [deleted file]
src/src.pro
src/ui/mainwindow.cpp
src/ui/mainwindow.h

index 4e8ad90..a5e37f8 100644 (file)
@@ -89,10 +89,10 @@ SituareEngine::SituareEngine(QMainWindow *parent)
     m_mapEngine->init();
     m_ui->show();
 
-    initializeGpsAndAutocentering();
-
     m_facebookAuthenticator->start();
 
+    initializeGpsAndAutocentering();
+
     m_automaticUpdateIntervalTimer = new QTimer(this);
     connect(m_automaticUpdateIntervalTimer, SIGNAL(timeout()),
             this, SLOT(automaticUpdateIntervalTimerTimeout()));
@@ -133,7 +133,7 @@ void SituareEngine::disableAutoCentering()
     qDebug() << __PRETTY_FUNCTION__;
 
     changeAutoCenteringSetting(false);
-    m_ui->queueInformationBox(tr("Auto centering disabled"));
+    m_ui->buildInformationBox(tr("Auto centering disabled"));
 }
 
 void SituareEngine::enableAutoCentering(bool enabled)
@@ -184,7 +184,7 @@ void SituareEngine::error(const QString &error)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_ui->queueInformationBox(error, true);
+    m_ui->buildInformationBox(error, true);
 
     if(error.compare(SESSION_EXPIRED) == 0) {
         m_facebookAuthenticator->clearAccountInformation(true); // keep username = true
@@ -216,17 +216,17 @@ void SituareEngine::initializeGpsAndAutocentering()
         changeAutoCenteringSetting(true);
         enableGPS(true);
 
-        m_ui->queueInformationBox(tr("GPS enabled"));
-        m_ui->queueInformationBox(tr("Auto centering enabled"));
+        m_ui->buildInformationBox(tr("GPS enabled"));
+        m_ui->buildInformationBox(tr("Auto centering enabled"));
     } else { // Normal start
         changeAutoCenteringSetting(autoCenteringEnabled.toBool());
         enableGPS(gpsEnabled.toBool());
 
         if (gpsEnabled.toBool())
-            m_ui->queueInformationBox(tr("GPS enabled"));
+            m_ui->buildInformationBox(tr("GPS enabled"));
 
         if (gpsEnabled.toBool() && autoCenteringEnabled.toBool())
-            m_ui->queueInformationBox(tr("Auto centering enabled"));
+            m_ui->buildInformationBox(tr("Auto centering enabled"));
     } 
 }
 
@@ -350,8 +350,8 @@ void SituareEngine::signalsFromFacebookAuthenticator()
     connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
             this, SLOT(loginOk()));
 
-    connect(m_facebookAuthenticator, SIGNAL(newLoginRequest(QUrl)),
-            m_ui, SLOT(startLoginProcess(QUrl)));
+    connect(m_facebookAuthenticator, SIGNAL(newLoginRequest()),
+            m_ui, SLOT(startLoginProcess()));
 
     connect(m_facebookAuthenticator, SIGNAL(loginFailure()),
             m_ui, SLOT(loginFailed()));
index f376d1f..cba99ed 100644 (file)
@@ -93,17 +93,7 @@ void FacebookAuthentication::start()
     }
     else {
         m_freshLogin = true;
-
-        QStringList list;
-        list.append(FACEBOOK_LOGINBASE);
-        list.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
-        list.append(INTERVAL1);
-        list.append(SITUARE_LOGIN_SUCCESS);
-        list.append(INTERVAL2);
-        list.append(SITUARE_LOGIN_FAILURE);
-        list.append(FACEBOOK_LOGIN_ENDING);
-
-        emit newLoginRequest(list.join(EMPTY));
+        emit newLoginRequest();
     }
 }
 
index 8a296da..6f37c71 100644 (file)
@@ -139,9 +139,8 @@ signals:
     /**
     * @brief Signals when credentials are invalid new login is needed
     *
-    * @param url Login page url
     */
-    void newLoginRequest(const QUrl &url);
+    void newLoginRequest();
 
     /**
     * @brief This signal is emitted when new cookies need to be saved.
diff --git a/src/notedata.cpp b/src/notedata.cpp
deleted file mode 100644 (file)
index 61c471f..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
-   Situare - A location system for Facebook
-   Copyright (C) 2010  Ixonos Plc. Authors:
-
-       Henri Lampela - henri.lampela@ixonos.com
-
-   Situare is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as published by the Free Software Foundation.
-
-   Situare is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with Situare; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
-   USA.
-*/
-
-#include <QDebug>
-#include "notedata.h"
-
-NoteData::NoteData(const QString &message, bool modal)
-    : m_message(message),
-    m_modal(modal)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-}
-
-QString NoteData::message() const
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    return m_message;
-}
-
-bool NoteData::modal() const
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    return m_modal;
-}
diff --git a/src/notedata.h b/src/notedata.h
deleted file mode 100644 (file)
index 184a2f7..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
-   Situare - A location system for Facebook
-   Copyright (C) 2010  Ixonos Plc. Authors:
-
-       Henri Lampela - henri.lampela@ixonos.com
-
-   Situare is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License
-   version 2 as published by the Free Software Foundation.
-
-   Situare is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with Situare; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
-   USA.
-*/
-
-#ifndef NOTEDATA_H
-#define NOTEDATA_H
-
-#include <QString>
-
-class NoteData
-{
-public:
-    NoteData(const QString &message, bool modal);
-
-    QString message() const;
-
-    bool modal() const;
-
-private:
-
-    QString m_message;
-    bool m_modal;
-
-};
-
-#endif // NOTEDATA_H
index 3d881da..2b065e2 100644 (file)
@@ -46,8 +46,7 @@ SOURCES += main.cpp \
     network/networkaccessmanager.cpp \
     network/networkhandler.cpp \
     network/networkcookiejar.cpp \
-    network/networkreply.cpp \
-    notedata.cpp
+    network/networkreply.cpp
 HEADERS += ui/mainwindow.h \
     map/mapengine.h \
     map/mapview.h \
@@ -93,8 +92,7 @@ HEADERS += ui/mainwindow.h \
     network/networkaccessmanager.h \
     network/networkhandler.h \
     network/networkcookiejar.h \
-    network/networkreply.h \
-    notedata.h
+    network/networkreply.h
 QT += network \
     webkit
 #DEFINES += QT_NO_DEBUG_OUTPUT
index c52aa47..d2e0421 100644 (file)
@@ -153,6 +153,32 @@ void MainWindow::buildFriendListPanel()
             m_friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
 }
 
+void MainWindow::buildInformationBox(const QString &message, bool modal)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+#ifdef Q_WS_MAEMO_5
+    QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
+    QLabel *label = new QLabel(msgBox);
+    label->setAlignment(Qt::AlignCenter);
+    label->setText(message);
+    msgBox->setWidget(label);
+
+    if(modal) {
+        msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
+    } else {
+        msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
+    }
+#else
+    QMessageBox *msgBox = new QMessageBox(this);
+    msgBox->button(QMessageBox::Ok);
+    msgBox->setText(message);
+    msgBox->setModal(modal);
+#endif
+
+    queueDialog(msgBox);
+}
+
 void MainWindow::buildManualLocationCrosshair()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -342,6 +368,46 @@ void MainWindow::createMenus()
     m_viewMenu->setObjectName(tr("Menu"));
 }
 
+void MainWindow::dialogFinished(int status)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+    qDebug() << status;
+    QDialog *dialog = m_queue.takeFirst();
+    if(!dialog->objectName().isEmpty()) {
+        buildWebView();
+        if(status != 0) {
+            static_cast<LoginDialog *>(dialog)->userInput(m_email, m_password);
+
+            if(!m_cookieJar)
+                m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
+
+            m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
+
+            QStringList urlParts;
+            urlParts.append(FACEBOOK_LOGINBASE);
+            urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
+            urlParts.append(INTERVAL1);
+            urlParts.append(SITUARE_LOGIN_SUCCESS);
+            urlParts.append(INTERVAL2);
+            urlParts.append(SITUARE_LOGIN_FAILURE);
+            urlParts.append(FACEBOOK_LOGIN_ENDING);
+
+            emit saveUsername(m_email);
+            m_webView->load(QUrl(urlParts.join(EMPTY)));
+            toggleProgressIndicator(true);
+            m_refresh = true;
+        } else {
+            m_webView->stop();
+            emit cancelLoginProcess();
+        }
+    }
+
+    dialog->deleteLater();
+
+    if(!m_queue.isEmpty())
+        showInformationBox();
+}
+
 void MainWindow::drawFullScreenButton(const QSize &size)
 {
     qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
@@ -376,7 +442,7 @@ void MainWindow::gpsTimeout()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    queueInformationBox(tr("GPS timeout"));
+    buildInformationBox(tr("GPS timeout"));
 }
 
 void MainWindow::grabZoomKeys(bool grab)
@@ -517,27 +583,7 @@ void MainWindow::loginFailed()
 
     toggleProgressIndicator(false);
 
-    QStringList urlParts;
-    urlParts.append(FACEBOOK_LOGINBASE);
-    urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
-    urlParts.append(INTERVAL1);
-    urlParts.append(SITUARE_LOGIN_SUCCESS);
-    urlParts.append(INTERVAL2);
-    urlParts.append(SITUARE_LOGIN_FAILURE);
-    urlParts.append(FACEBOOK_LOGIN_ENDING);
-
-    startLoginProcess(urlParts.join(EMPTY));
-}
-
-void MainWindow::noteFinished()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    NoteData *data = m_queue.takeFirst();
-    delete data;
-
-    if(!m_queue.isEmpty())
-        showInformationBox();
+    startLoginProcess();
 }
 
 void MainWindow::loginUsingCookies()
@@ -568,16 +614,18 @@ void MainWindow::openSettingsDialog()
     m_settingsDialog->show();
 }
 
-void MainWindow::queueInformationBox(const QString &message, bool modal)
+void MainWindow::queueDialog(QDialog *dialog)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    NoteData *data = new NoteData(message, modal);
-
-    m_queue.append(data);
+    if(dialog->isModal()) {
+        m_queue.insert(0, dialog);
+    } else {
+        m_queue.append(dialog);
+    }
 
     if(m_queue.count() == 1)
-        showInformationBox();
+        this->showInformationBox();
 }
 
 void MainWindow::saveCookies()
@@ -670,67 +718,29 @@ void MainWindow::showInformationBox()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    NoteData *data = m_queue.takeFirst();
-
-#ifdef Q_WS_MAEMO_5
-    QMaemo5InformationBox *msgBox = new QMaemo5InformationBox(this);
-    QLabel *label = new QLabel(msgBox);
-    label->setAlignment(Qt::AlignCenter);
-    label->setText(data->message());
-
-    if(data->modal()) {
-        msgBox->setTimeout(QMaemo5InformationBox::NoTimeout);
-    } else {
-        msgBox->setTimeout(QMaemo5InformationBox::DefaultTimeout);
-    }
-#else
-    QMessageBox *msgBox = new QMessageBox(this);
-    msgBox->button(QMessageBox::Ok);
-    msgBox->setText(data->message());
-    msgBox->setModal(data->modal());
-#endif
-
-    connect(msgBox, SIGNAL(finished(int)),
-            this, SLOT(noteFinished()));
-
-    msgBox->show();
-
-    m_queue.insert(0, data);
-
+    QDialog *dialog = m_queue.takeFirst();
+    connect(dialog, SIGNAL(finished(int)),
+            this, SLOT(dialogFinished(int)));
+    dialog->show();
+    m_queue.insert(0, dialog);
 }
 
-void MainWindow::startLoginProcess(const QUrl &url)
+void MainWindow::startLoginProcess()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    buildWebView();
+    LoginDialog *loginDialog = new LoginDialog();
 
-    LoginDialog loginDialog;
+    loginDialog->setObjectName(QString("loginDialog"));
 
     emit fetchUsernameFromSettings();
 
-    if(!m_cookieJar)
-        m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
-
-    m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
-
-    loginDialog.clearTextFields();
+    loginDialog->clearTextFields();
 
     if(!m_email.isEmpty())
-        loginDialog.setEmailField(m_email);
-
-    if(loginDialog.exec() != QDialog::Accepted) {
-        // if login dialog was canceled we need to stop processing webview
-        m_webView->stop();
+        loginDialog->setEmailField(m_email);
 
-        emit cancelLoginProcess();
-    } else {
-        loginDialog.userInput(m_email, m_password);
-        emit saveUsername(m_email);
-        m_webView->load(url);
-        toggleProgressIndicator(true);
-        m_refresh = true;
-    }
+    queueDialog(loginDialog);
 }
 
 void MainWindow::toggleProgressIndicator(bool value)
index bf4a250..a496e9e 100644 (file)
@@ -29,7 +29,6 @@
 
 #include "network/networkcookiejar.h"
 #include "panelsidebar.h"
-#include "notedata.h"
 
 class QGraphicsScene;
 class QLabel;
@@ -81,6 +80,14 @@ private:
  ******************************************************************************/
 public:
     /**
+    * @brief Builds information box with message.
+    *
+    * @param message Information message
+    * @param modal Modal = true, non-modal false
+    */
+    void buildInformationBox(const QString &message, bool modal=false);
+
+    /**
     * @brief Clears cookie jar
     *
     */
@@ -94,14 +101,6 @@ public:
     void loggedIn(bool logged);
 
     /**
-    * @brief Queues information box with message.
-    *
-    * @param message Information message
-    * @param modal Modal = true, non-modal false
-    */
-    void queueInformationBox(const QString &message, bool modal=false);
-
-    /**
     * @brief Enable / disable auto centering button.
     *
     * @param enabled true if shoud be enabled, false otherwise
@@ -160,9 +159,8 @@ public slots:
     * @brief Public slot to intercept signal when old cerdentials are invalid or credentials
     *        doesn't exist yet
     *
-    * @param url Login page url
     */
-    void startLoginProcess(const QUrl &url);
+    void startLoginProcess();
 
     /**
     * @brief Toggle progress indicator.
@@ -233,6 +231,13 @@ private:
     void grabZoomKeys(bool grab);
 
     /**
+    * @brief Queues dialog/information box
+    *
+    * @param dialog Dialog to be added into queue
+    */
+    void queueDialog(QDialog *dialog);
+
+    /**
       * @brief Set own location crosshair visibility
       *
       * @param visible
@@ -248,6 +253,13 @@ private:
 
 private slots:
     /**
+    * @brief Slot to intercept signal when dialog/information note is processed
+    *
+    * @param status Status of the dialog
+    */
+    void dialogFinished(int status);
+
+    /**
     * @brief Slot for drawing the fullscreen toggle button
     *
     * @param size Size of the screen
@@ -290,12 +302,6 @@ private slots:
     void loadDone(bool done);
 
     /**
-    * @brief Slot to intercept signal when information note is processed
-    *
-    */
-    void noteFinished();
-
-    /**
     * @brief Slot to save cookies to settings
     *
     */
@@ -523,7 +529,7 @@ private:
 
     SettingsDialog *m_settingsDialog;       ///< Settings dialog
 
-    QList<NoteData *> m_queue;              ///< List type queue for information boxes
+    QList<QDialog *> m_queue;
 };
 
 #endif // MAINWINDOW_H