m_situareService = new SituareService(this);
- m_facebookAuthenticator = new FacebookAuthentication();
+ m_facebookAuthenticator = new FacebookAuthentication(this);
#ifdef Q_WS_MAEMO_5
m_gps = new GPSPosition(this);
m_situareService, SLOT(credentialsReady(FacebookCredentials)));
connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
this, SLOT(loginOk()));
- connect(m_facebookAuthenticator, SIGNAL(quitSituare()),
- this, SLOT(quitApplication()));
+ connect(m_ui, SIGNAL(cancelLoginProcess()),
+ this, SLOT(loginProcessCancelled()));
connect(m_ui, SIGNAL(requestReverseGeo()),
this, SLOT(requestAddress()));
connect(m_gps, SIGNAL(position(QPointF)),
m_ui, SIGNAL(positionReceived(QPointF)));
+ connect(m_facebookAuthenticator, SIGNAL(newLoginRequest(QUrl)),
+ m_ui, SLOT(startLoginProcess(QUrl)));
+ connect(m_ui, SIGNAL(updateCredentials(QUrl)),
+ m_facebookAuthenticator, SLOT(updateCredentials(QUrl)));
+ connect(m_facebookAuthenticator, SIGNAL(loginFailure()),
+ m_ui, SLOT(loginFailed()));
+
m_facebookAuthenticator->start();
}
delete m_ui;
}
-void SituareEngine::quitApplication()
+void SituareEngine::loginProcessCancelled()
{
qDebug() << __PRETTY_FUNCTION__;
- m_facebookAuthenticator->setAttribute(Qt::WA_DeleteOnClose);
- m_facebookAuthenticator->close();
+ m_ui->show();
+ m_ui->toggleProgressIndicator(false);
+ //ToDo: do something
}
void SituareEngine::error(const QString &error)
{
qDebug() << __PRETTY_FUNCTION__;
- m_facebookAuthenticator->setAttribute(Qt::WA_DeleteOnClose);
- m_facebookAuthenticator->close();
m_ui->show();
m_situareService->fetchLocations(); // request user locations
*/
void enableGPS(bool enabled);
- /**
+ /**
* @brief Slot to intercept signal when user has cancelled login process
*
*/
- void quitApplication();
+ void loginProcessCancelled();
/*******************************************************************************
* SIGNALS
USA.
*/
-#include <QtGui>
#include <QtDebug>
#include <QDateTime>
+#include <QSettings>
+#include <QStringList>
+#include <QVariantMap>
#ifdef Q_WS_MAEMO_5
#include <QMaemo5InformationBox>
#include "facebookcommon.h"
#include "parser.h"
-FacebookAuthentication::FacebookAuthentication(QWidget *parent)
- : QMainWindow(parent),
- m_email(),
- m_loginAttempts(0),
- m_password(),
- m_refresh(0),
- m_webView(0)
+FacebookAuthentication::FacebookAuthentication(QObject *parent)
+ : QObject(parent),
+ m_loginAttempts(0)
+
{
qDebug() << __PRETTY_FUNCTION__;
- m_mainlayout = new QHBoxLayout;
-
connect(this, SIGNAL(loginFailure()),
this, SLOT(loginFailed()));
readCredentials(m_loginCredentials);
}
-FacebookAuthentication::~FacebookAuthentication()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- if(m_webView)
- delete m_webView;
-
- delete m_mainlayout;
-}
-
-void FacebookAuthentication::loginDialogDone(const QString &email, const QString &password)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_email = email;
- m_password = password;
-}
-
void FacebookAuthentication::start()
{
qDebug() << __PRETTY_FUNCTION__;
if (!verifyCredentials(m_loginCredentials)) {
-
- m_webView = new QWebView;
- m_loginDialog = new LoginDialog(this);
-
- connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
- this, SLOT(updateCredentials(const QUrl &)));
- connect(m_webView, SIGNAL(loadFinished(bool)),
- this, SLOT(loadDone(bool)));
-
- connect(m_loginDialog, SIGNAL(loginDialogDone(QString,QString)),
- this, SLOT(loginDialogDone(QString,QString)));
-
- if(m_loginDialog->exec() != QDialog::Accepted) {
- // if login dialog was canceled we need to stop processing webview
- // stop and disconnect m_webView;
- m_webView->stop();
- disconnect(m_webView, SIGNAL(loadFinished(bool)),
- this, SLOT(loadDone(bool)));
- disconnect(m_webView, SIGNAL(urlChanged(const QUrl &)),
- this, SLOT(updateCredentials(const QUrl &)));
-
- emit quitSituare();
- }
QStringList list;
list.append(FACEBOOK_LOGINBASE);
list.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
list.append(SITUARE_LOGIN_FAILURE);
list.append(FACEBOOK_LOGIN_ENDING);
- m_webView->load(formLoginPageUrl(list));
- toggleProgressIndicator(true);
- m_refresh = true;
- setCentralWidget(m_webView);
- m_webView->hide();
- this->show();
+ emit newLoginRequest(formLoginPageUrl(list));
}
else
emit credentialsReady(m_loginCredentials);
}
-void FacebookAuthentication::loadDone(bool done)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- // for the first time the login page is opened, we need to refresh it to get cookies working
- if(m_refresh) {
- 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);
-
- m_webView->load(formLoginPageUrl(list));
- m_refresh = false;
- }
-
- if (done)
- {
- QWebFrame* frame = m_webView->page()->currentFrame();
- if (frame!=NULL)
- {
- // set email box
- QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
-
- foreach (QWebElement element, emailCollection) {
- element.setAttribute("value", m_email.toAscii());
- }
- // set password box
- QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
- foreach (QWebElement element, passwordCollection) {
- element.setAttribute("value", m_password.toAscii());
- }
- // find connect button
- QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
- foreach (QWebElement element, buttonCollection)
- {
- QPoint pos(element.geometry().center());
-
- // send a mouse click event to the web page
- QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
- Qt::NoModifier);
- QApplication::sendEvent(m_webView->page(), &event0);
- QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
- Qt::NoModifier);
- QApplication::sendEvent(m_webView->page(), &event1);
- }
- }
- }
-}
-
-void FacebookAuthentication::loginFailed()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_email.clear();
- m_password.clear();
-
- toggleProgressIndicator(false);
-
-#ifdef Q_WS_MAEMO_5
- QMaemo5InformationBox::information(this, tr("Invalid E-mail address or password"),
- QMaemo5InformationBox::NoTimeout);
-
-#endif // Q_WS_MAEMO_5
-
- if(m_loginDialog->exec() != QDialog::Accepted) {
- // if login dialog was canceled we need to stop processing webview
- // stop and disconnect m_webView;
- m_webView->stop();
- disconnect(m_webView, SIGNAL(loadFinished(bool)),
- this, SLOT(loadDone(bool)));
- disconnect(m_webView, SIGNAL(urlChanged(const QUrl &)),
- this, SLOT(updateCredentials(const QUrl &)));
-
- emit quitSituare();
- }
- else {
- // re-load login page for webview
- toggleProgressIndicator(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);
-
- m_webView->load(formLoginPageUrl(list));
- }
-}
-
bool FacebookAuthentication::updateCredentials(const QUrl &url)
{
qDebug() << __PRETTY_FUNCTION__;
if (callbackUrl.indexOf(LOGIN_SUCCESS_REPLY) == 0) {
qDebug() << "login success";
- disconnect(m_webView, SIGNAL(loadFinished(bool)),
- this, SLOT(loadDone(bool)));
- disconnect(m_webView, SIGNAL(urlChanged(const QUrl &)),
- this, SLOT(updateCredentials(const QUrl &)));
-
// let's find out session credentials
if(callbackUrl.contains(SESSION_KEY)) {
return QUrl(urlParts.join(EMPTY));
}
-
- void FacebookAuthentication::toggleProgressIndicator(bool value)
- {
- qDebug() << __PRETTY_FUNCTION__;
- #ifdef Q_WS_MAEMO_5
- setAttribute(Qt::WA_Maemo5ShowProgressIndicator, value);
- #else
- Q_UNUSED(value);
- #endif // Q_WS_MAEMO_5
- }
#ifndef FACEBOOKAUTHENTICATION_H
#define FACEBOOKAUTHENTICATION_H
-#include <QtGui>
-#include <QtWebKit>
-#include <QString>
-#include <QLayout>
-
+#include <QUrl>
#include "facebookcredentials.h"
-#include "ui/logindialog.h"
/**
-* @brief FacebookAuthentication class takes care of transmitting username and password to facebook.
-* And it also receives credentials from Facebook. Other components of Situare application
-* needs credentials to communicate with facebook.
+* @brief FacebookAuthentication class takes care of parsing and handling of credentials for
+* Facebook. Other components of Situare application needs credentials to communicate with
+* facebook.
*
* @author Ville Tiensuu
-* @class FacebookAuthentication facebookauthentication.h "facebookauthentication.h"
*/
-class FacebookAuthentication : public QMainWindow
+class FacebookAuthentication : public QObject
{
Q_OBJECT
/**
* @brief FacebookAuthentication constructor
*
- * -Composes Loginpage from pieces of strings.
- * -Checks if there is valid credentials stored on the file. If there is emits signal. If not it
- * calls start method.
- * -Connects signal from m_webView to UpdateCredentials() method. With this feature it is
- * verified that class tries always update credentials when web page changes.
- * -Allocates memory for m_webView and m_mainlayout
+ * -Checks if there is valid credentials stored on the file. If there is emits signal.
*
* @param parent instance of parent
*/
- FacebookAuthentication(QWidget *parent = 0);
-
- /**
- * @brief Releases allocated memory for m_webView and m_mainlayout
- *
- */
- ~FacebookAuthentication();
+ FacebookAuthentication(QObject *parent = 0);
/*******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
*/
void start();
- /**
- * @brief Slot to intercept signal when user has pressed connect button from loginDialog
- *
- * @param email E-mail
- * @param password Password
- */
- void loginDialogDone(const QString &email, const QString &password);
-
- /**
- * @brief Toggle progress indicator.
- *
- * @param state true if progress indicator should be shown, false otherwise
- */
- void toggleProgressIndicator(bool state);
-
private:
/**
*/
bool updateCredentials(const QUrl & url);
- /**
- * @brief Slot to intercept signal when webview has finished loading webpage
- *
- * @param done Status of the loading
- */
- void loadDone(bool done);
-
- /**
- * @brief Slot to intercept signal when login has failed (loginFailure signal)
- *
- */
- void loginFailed();
-
/*******************************************************************************
* SIGNALS
******************************************************************************/
void loginFailure();
/**
- * @brief Signal that indicates when user has cancelled login process
+ * @brief Signals when credentials are invalid new login is needed
*
+ * @param url Login page url
*/
- void quitSituare();
+ void newLoginRequest(const QUrl &url);
/*******************************************************************************
* DATA MEMBERS
*/
FacebookCredentials m_loginCredentials;
- QString m_email; ///< Placeholder for email
int m_loginAttempts; ///< Indicates login attempts
- LoginDialog *m_loginDialog; ///< Login dialog
- QHBoxLayout *m_mainlayout; ///< Lays out m_webView in window.
- QString m_password; ///< Placeholder for password
- bool m_refresh; ///< Indicates when webpage is refreshed
- QWebView *m_webView; ///< Shows facebook login page.
};
#endif // FACEBOOKAUTHENTICATION_H
#include "mapviewscreen.h"
#include "settingsdialog.h"
#include "facebookservice/facebookauthentication.h"
-#include "situareservice/situareservice.h"
MainWindow::MainWindow(QWidget *parent)
- : QMainWindow(parent)
+ : QMainWindow(parent),
+ m_email(),
+ m_loginUrl(),
+ m_password(),
+ m_refresh(0),
+ m_webView(0)
{
qDebug() << __PRETTY_FUNCTION__;
setCentralWidget(m_mapViewScreen);
createMenus();
setWindowTitle(tr("Situare"));
- hide();
m_locationDialog = new UpdateLocationDialog(this);
connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
m_mapViewScreen, SIGNAL(friendsLocationsReady(QList<User*>&)));
- connect(this, SIGNAL(enableAutoCentering(bool)),
+ connect(this, SIGNAL(enableAutoCentering(bool)),
m_mapViewScreen, SLOT(enableAutoCentering(bool)));
connect(this, SIGNAL(positionReceived(QPointF)),
m_mapViewScreen, SLOT(positionReceived(QPointF)));
this->toggleProgressIndicator(true);
}
+MainWindow::~MainWindow()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if(m_webView)
+ delete m_webView;
+}
+
void MainWindow::toggleProgressIndicator(bool value)
{
qDebug() << __PRETTY_FUNCTION__;
m_toSettingsAct = new QAction(tr("Settings"), this);
m_toSettingsAct->setObjectName(tr("Settings"));
- connect(m_toSettingsAct, SIGNAL(triggered()), this, SLOT(openSettingsDialog()));
- m_gpsToggleAct = new QAction(tr("GPS enabled"), this);
+ connect(m_toSettingsAct, SIGNAL(triggered()),
+ this, SLOT(openSettingsDialog()));
+ m_gpsToggleAct = new QAction(tr("GPS enabled"), this);
m_gpsToggleAct->setCheckable(true);
m_gpsToggleAct->setChecked(true);
- connect(m_gpsToggleAct, SIGNAL(toggled(bool)), this, SLOT(gpsActionToggled(bool)));
+ connect(m_gpsToggleAct, SIGNAL(toggled(bool)),
+ this, SLOT(gpsActionToggled(bool)));
m_autoCenteringAct = new QAction(tr("Auto centering enabled"), this);
m_autoCenteringAct->setCheckable(true);
m_autoCenteringAct->setChecked(true);
- connect(m_autoCenteringAct, SIGNAL(toggled(bool)), this, SLOT(autoCenteringToggled(bool)));
+ connect(m_autoCenteringAct, SIGNAL(toggled(bool)),
+ this, SLOT(autoCenteringToggled(bool)));
- m_viewMenu = menuBar()->addMenu(tr("Main"));
+ m_viewMenu = menuBar()->addMenu(tr("Main"));
m_viewMenu->addAction(m_toSettingsAct);
- m_viewMenu->addAction(m_gpsToggleAct);
+ m_viewMenu->addAction(m_gpsToggleAct);
m_viewMenu->addAction(m_autoCenteringAct);
m_viewMenu->setObjectName(tr("Menu"));
}
Q_UNUSED(message);
#endif
}
+
+void MainWindow::startLoginProcess(const QUrl &url)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_loginUrl = url;
+ m_webView = new QWebView;
+ m_loginDialog = new LoginDialog(this);
+
+ connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
+ this, SIGNAL(updateCredentials(QUrl)));
+ connect(m_webView, SIGNAL(loadFinished(bool)),
+ this, SLOT(loadDone(bool)));
+
+ connect(m_loginDialog, SIGNAL(loginDialogDone(QString,QString)),
+ this, SLOT(loginDialogDone(QString,QString)));
+
+ m_webView->hide();
+ this->show();
+
+ if(m_loginDialog->exec() != QDialog::Accepted) {
+ // if login dialog was canceled we need to stop processing webview
+ // stop and disconnect m_webView;
+ m_webView->stop();
+ disconnect(m_webView, SIGNAL(loadFinished(bool)),
+ this, SLOT(loadDone(bool)));
+ disconnect(m_webView, SIGNAL(urlChanged(const QUrl &)),
+ this, SLOT(updateCredentials(const QUrl &)));
+
+ emit cancelLoginProcess();
+ }
+ else {
+ m_webView->load(m_loginUrl);
+ toggleProgressIndicator(true);
+ m_refresh = true;
+ }
+}
+
+void MainWindow::loginDialogDone(const QString &email, const QString &password)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_email = email;
+ m_password = password;
+}
+
+void MainWindow::loginFailed()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_email.clear();
+ m_password.clear();
+
+ toggleProgressIndicator(false);
+
+#ifdef Q_WS_MAEMO_5
+ QMaemo5InformationBox::information(this, tr("Invalid E-mail address or password"),
+ QMaemo5InformationBox::NoTimeout);
+
+#endif // Q_WS_MAEMO_5
+
+ if(m_loginDialog->exec() != QDialog::Accepted) {
+ // if login dialog was canceled we need to stop processing webview
+ // stop and disconnect m_webView;
+ m_webView->stop();
+ disconnect(m_webView, SIGNAL(loadFinished(bool)),
+ this, SLOT(loadDone(bool)));
+ disconnect(m_webView, SIGNAL(urlChanged(const QUrl &)),
+ this, SLOT(updateCredentials(const QUrl &)));
+
+ emit cancelLoginProcess();
+ }
+ else {
+ // re-load login page for webview
+ toggleProgressIndicator(true);
+ m_webView->load(m_loginUrl);
+ }
+}
+
+void MainWindow::loadDone(bool done)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ // for the first time the login page is opened, we need to refresh it to get cookies working
+ if(m_refresh) {
+ m_webView->reload();
+ m_refresh = false;
+ }
+
+ if (done)
+ {
+ QWebFrame* frame = m_webView->page()->currentFrame();
+ if (frame!=NULL)
+ {
+ // set email box
+ QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
+
+ foreach (QWebElement element, emailCollection) {
+ element.setAttribute("value", m_email.toAscii());
+ }
+ // set password box
+ QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
+ foreach (QWebElement element, passwordCollection) {
+ element.setAttribute("value", m_password.toAscii());
+ }
+ // find connect button
+ QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
+ foreach (QWebElement element, buttonCollection)
+ {
+ QPoint pos(element.geometry().center());
+
+ // send a mouse click event to the web page
+ QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
+ Qt::NoModifier);
+ QApplication::sendEvent(m_webView->page(), &event0);
+ QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
+ Qt::NoModifier);
+ QApplication::sendEvent(m_webView->page(), &event1);
+ }
+ }
+ }
+}
#include <QtGui/QMainWindow>
#include <QWidget>
+#include <QtWebKit>
#include <QDebug>
#include <QObject>
+#include <QNetworkAccessManager>
#include "facebookservice/facebookauthentication.h"
#include "situareservice/situareservice.h"
-#include <QNetworkAccessManager>
#include "mapviewscreen.h"
#include "updatelocation/updatelocationdialog.h"
-#include "ui/mainwindow.h"
+#include "ui/logindialog.h"
class QLabel;
*/
MainWindow(QWidget *parent = 0);
+ /**
+ * @brief Destructor
+ *
+ */
+ ~MainWindow();
+
/*******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
public slots:
- /**
+ /**
* @brief Slot for auto centering enabling.
*
* @param checked true if button state is checked, false otherwise
void autoCenteringToggled(bool checked);
/**
+ * @brief Slot to intercept signal when user has pressed connect button from loginDialog
+ *
+ * @param email E-mail
+ * @param password Password
+ */
+ void loginDialogDone(const QString &email, const QString &password);
+
+ /**
+ * @brief Slot to intercept signal when login has failed (loginFailure signal)
+ *
+ */
+ void loginFailed();
+
+ /**
* @brief Public slot, which open settings dialog
*/
void openSettingsDialog();
/**
+ * @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);
+
+ /**
* @brief Toggle progress indicator.
*
* @param state true if progress indicator should be shown, false otherwise
void showMaemoInformationBox(const QString &message);
private slots:
- /**
+ /**
* @brief Slot for gps enabling.
*
* @param checked true if button state is checked, false otherwise
void gpsError(const QString &message);
/**
+ * @brief Slot to intercept signal when webview has finished loading webpage
+ *
+ * @param done Status of the loading
+ */
+ void loadDone(bool done);
+
+ /**
* @brief Private slot, which starts UpdateLocationDialog
*
*/
* SIGNALS
******************************************************************************/
signals:
- /**
+ /**
* @brief Signal for map auto centering
*
* @param enabled true if map should auto center to gps location
*/
void enableAutoCentering(bool enabled);
- /**
+ /**
* @brief Signal for gps enabling.
*
* @param enabled true if gps should be enabled
*/
void enableGPS(bool enabled);
- /**
+ /**
* @brief Signal for friend location ready.
*
* @param friendsList
*/
void friendsLocationsReady(QList<User *> &friendsList);
- /**
+ /**
* @brief Signal for gps position.
*
* @param position longitude and latitude values
*/
void positionReceived(QPointF position);
- /**
+ /**
* @brief Signal for refreshing user data.
*
*/
void statusUpdate(const QString &status, const bool &publish);
/**
+ * @brief Signals when webview's urlChanged signal is emitted
+ *
+ * @param url New url
+ */
+ void updateCredentials(const QUrl &url);
+
+ /**
* @brief Signal for use location ready.
*
* @param user User object
*/
void userLocationReady(User *user);
+ /**
+ * @brief Signal that indicates when user has cancelled login process
+ *
+ */
+ void cancelLoginProcess();
+
/*******************************************************************************
* DATA MEMBERS
******************************************************************************/
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
- QAction *m_autoCenteringAct; ///< Action to auto center map using gps position
- QAction *m_gpsToggleAct; ///< Action to trigger gps toggle
- QAction *m_toSettingsAct; ///< Action to trigger switch to settings dialog
+ QString m_password; ///< Placeholder for password
+ bool m_refresh; ///< Indicates when webpage is refreshed
+ QAction *m_toSettingsAct; ///< Action to trigger switch to settings dialog
QMenu *m_viewMenu; ///< Object that hold the view menu items
+ QWebView *m_webView; ///< Shows facebook login page
};
#endif // MAINWINDOW_H