qDebug() << __PRETTY_FUNCTION__;
m_ui = new MainWindow;
- m_ui->updateItemVisibility();
+ m_ui->updateItemVisibility(false);
Application *application = static_cast<Application *>(qApp);
application->registerWindow(m_ui->winId());
break;
case SituareError::SESSION_EXPIRED:
m_ui->buildInformationBox(tr("Session expired. Please login again"), true);
- m_facebookAuthenticator->clearAccountInformation(true); // keep username = true
- m_situareService->clearUserData();
- m_ui->loggedIn(false);
- m_ui->loginFailed();
- break;
- case SituareError::LOGIN_FAILED:
- m_ui->toggleProgressIndicator(false);
- m_ui->buildInformationBox(tr("Invalid E-mail address or password"), true);
- m_ui->loginFailed();
+ m_facebookAuthenticator->logOut();
+ m_facebookAuthenticator->login();
break;
case SituareError::UPDATE_FAILED:
m_ui->toggleProgressIndicator(false);
{
qDebug() << __PRETTY_FUNCTION__;
- if (m_networkAccessManager->isConnected()) {
- if(m_ui->loginState()) {
- logout();
- m_situareService->clearUserData();
- } else {
- m_facebookAuthenticator->login();
- }
- }
- else {
+ if (m_facebookAuthenticator->isLoggedIn())
+ m_facebookAuthenticator->logOut();
+ else if (m_networkAccessManager->isConnected())
+ m_facebookAuthenticator->login();
+ else
error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
- }
}
-void SituareEngine::loginOk()
+void SituareEngine::onLogin()
{
- /// @ OLD CODE, REFACTOR! loggedIn -> FB authenticator etc.
qDebug() << __PRETTY_FUNCTION__;
m_ui->loggedIn(true);
- m_ui->show();
- m_situareService->fetchLocations(); // request user locations
+ m_situareService->fetchLocations();
if (m_gps->isRunning())
m_ui->readAutomaticLocationUpdateSettings();
}
-void SituareEngine::loginProcessCancelled()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_ui->toggleProgressIndicator(false);
- m_ui->updateItemVisibility();
-}
-
-void SituareEngine::logout()
+void SituareEngine::onLogout()
{
qDebug() << __PRETTY_FUNCTION__;
m_ui, SIGNAL(clearUpdateLocationDialogData()));
emit clearUpdateLocationDialogData();
- m_facebookAuthenticator->clearAccountInformation(); // clear all
+ m_situareService->updateSession(""); // empty session string means logged out
+
m_automaticUpdateFirstStart = true;
}
m_gps->start();
m_gps->requestLastPosition();
- if(m_ui->loginState())
+ if(m_facebookAuthenticator->isLoggedIn())
m_ui->readAutomaticLocationUpdateSettings();
}
else if (!enabled && m_gps->isRunning()) {
m_situareService, SLOT(updateSession(QString)));
connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString)),
- this, SLOT(loginOk()));
+ this, SLOT(onLogin()));
+
+ connect(m_facebookAuthenticator, SIGNAL(loggedOut()), this, SLOT(onLogout()));
}
void SituareEngine::signalsFromGeocodingService()
connect(m_ui, SIGNAL(gpsTriggered(bool)),
this, SLOT(setGPS(bool)));
- //signals from dialogs
- connect(m_ui, SIGNAL(cancelLoginProcess()),
- this, SLOT(loginProcessCancelled()));
-
connect(m_ui, SIGNAL(requestReverseGeo()),
this, SLOT(requestAddress()));
* @brief Slot to intercept signal from successful login
*
*/
- void loginOk();
-
- /**
- * @brief Slot to intercept signal when user has cancelled login process
- */
- void loginProcessCancelled();
+ void onLogin();
/**
* @brief Changes application state when logged out
*
*/
- void logout();
+ void onLogout();
/**
* @brief Calls reverseGeo from SituareService to translate coordinates to street address
ERROR_GENERAL = 0, // an unknown/unspecified error
ERROR_MISSING_ARGUMENT, // missing mandatory argument for requested action
SESSION_EXPIRED = 10, // situare session credentials expired
- LOGIN_FAILED, // login to situare service failed
UPDATE_FAILED, // location update to situare failed
DATA_RETRIEVAL_FAILED, // user/friends list retrieval failed
ADDRESS_RETRIEVAL_FAILED, // reversegeo request failed
FacebookAuthentication::FacebookAuthentication(MainWindow *mainWindow, QObject *parent)
: QObject(parent),
+ m_loggedIn(false),
m_browser(0),
m_mainWindow(mainWindow)
{
{
qDebug() << __PRETTY_FUNCTION__;
- ///< @todo (HIGH) clear session from SituareService
QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
if(!keepUsername) {
m_browser->deleteLater();
}
+bool FacebookAuthentication::isLoggedIn()
+{
+ qWarning() << __PRETTY_FUNCTION__;
+
+ return m_loggedIn;
+}
+
void FacebookAuthentication::login()
{
qWarning() << __PRETTY_FUNCTION__;
connect(m_browser, SIGNAL(destroyed(QObject*)),
this, SLOT(browserDestroyed()));
+ connect(m_browser->page()->networkAccessManager(),
+ SIGNAL(sslErrors(QNetworkReply*, QList<QSslError>)),
+ this, SLOT(sslErrors(QNetworkReply*, QList<QSslError>)));
+
connect(m_browser->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
this, SLOT(networkReplyHandler(QNetworkReply*)));
}
}
}
+void FacebookAuthentication::logOut()
+{
+ qWarning() << __PRETTY_FUNCTION__;
+
+ clearAccountInformation();
+ m_loggedIn = false;
+ emit loggedOut();
+}
+
void FacebookAuthentication::networkReplyHandler(QNetworkReply *reply)
{
qWarning() <<__PRETTY_FUNCTION__;
return QString();
}
+void FacebookAuthentication::sslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
+{
+ qWarning() << __PRETTY_FUNCTION__;
+
+ Q_UNUSED(errors);
+ reply->ignoreSslErrors();
+}
+
void FacebookAuthentication::urlChanged(const QUrl &url)
{
qWarning() << __PRETTY_FUNCTION__ << url.toString();
qWarning() << __PRETTY_FUNCTION__ << "login finished, parsed session:" << session;
if (!session.isEmpty()) {
destroyLogin();
+ m_loggedIn = true;
emit loggedIn(session);
}
}
#include <QUrl>
class QNetworkReply;
+class QSslError;
class QWebView;
class MainWindow;
/*******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
-public:
+public slots:
+ /**
+ * @brief Clears account information from settings
+ *
+ * @param keepUsername keep = true, false otherwise
+ */
+ void clearAccountInformation(bool keepUsername = false);
+
+ /**
+ * @brief Is the user currently logged in
+ *
+ * @returns True if the user is logged in, otherwise false
+ */
+ bool isLoggedIn();
+
/**
* @brief Initiate login process
*
*/
void login();
-public slots:
-
/**
- * @brief Clears account information from settings
- *
- * @param keepUsername keep = true, false otherwise
- */
- void clearAccountInformation(bool keepUsername = false);
+ * @brief Log out
+ */
+ void logOut();
private:
/**
void networkReplyHandler(QNetworkReply *reply);
/**
+ * @brief Handler for SSL errors, ignores the error
+ */
+ void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
+
+ /**
* @brief Handler for browser URL changes
*
* Does check the new URL and based on that invokes the login dialog with visible browser view
/**
* @brief Emitted when logged in successfully
*
+ * All login related actions should be connected to this signal.
+ *
* @param session Session data
*/
void loggedIn(const QString session);
+ /**
+ * @brief Emitted when logged out
+ *
+ * All logout related actions should be connected to this signal.
+ */
+ void loggedOut();
+
/*******************************************************************************
* DATA MEMBERS
******************************************************************************/
private:
+ bool m_loggedIn; ///< Is the user currently logged in
QWebView *m_browser; ///< Login browser
MainWindow *m_mainWindow; ///< MainWindow
};
m_session = session;
- foreach (QString request, m_requestsWaitingAccessToken) {
- appendAccessToken(request);
- sendRequest(request);
+ if (!m_session.isEmpty()) {
+ foreach (QString request, m_requestsWaitingAccessToken) {
+ appendAccessToken(request);
+ sendRequest(request);
+ }
+ }
+ else {
+ clearUserData();
}
m_requestsWaitingAccessToken.clear();
ui/locationlistview.cpp \
ui/indicatorbuttonpanel.cpp \
ui/locationsearchpanel.cpp \
- ui/logindialog.cpp \
ui/mainwindow.cpp \
ui/mapscale.cpp \
ui/panelbar.cpp \
ui/listview.h \
ui/listitem.h \
ui/listitemdelegate.h \
- ui/logindialog.h \
ui/locationlistitem.h \
ui/locationlistview.h \
ui/locationsearchpanel.h \
+++ /dev/null
-/*
- 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 <QDialogButtonBox>
-#include <QFormLayout>
-#include <QLabel>
-#include <QLineEdit>
-#include <QPushButton>
-
-#include "logindialog.h"
-
-LoginDialog::LoginDialog(QWidget *parent)
- : QDialog(parent)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- setWindowTitle(tr("Login to Situare with Facebook account"));
-
- m_emailEdit = new QLineEdit();
- m_passwordEdit = new QLineEdit();
- m_passwordEdit->setEchoMode(QLineEdit::Password);
-
- QGridLayout *gridLayout = new QGridLayout(this);
- QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
- QPushButton *connectButton = buttonBox->addButton(QDialogButtonBox::Ok);
- QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
- connectButton->setText(tr("Login"));
-
- QFormLayout *form = new QFormLayout();
- form->addRow(new QLabel(tr("E-mail:")), m_emailEdit);
- form->addRow(new QLabel(tr("Password:")), m_passwordEdit);
-
- gridLayout->addLayout(form, 0, 0, 2, 1);
- gridLayout->addWidget(buttonBox, 0, 1, 1, 1);
-
- connect(connectButton, SIGNAL(clicked()),
- this, SLOT(accept()));
- connect(cancelButton, SIGNAL(clicked()),
- this, SLOT(reject()));
-
- setLayout(gridLayout);
-}
-
-void LoginDialog::setEmailField(const QString &email)
-{
- qDebug() << __PRETTY_FUNCTION__;
- if(!email.isEmpty()) {
- m_emailEdit->setText(email);
- m_passwordEdit->setFocus(Qt::OtherFocusReason);
- }
-}
-
-void LoginDialog::clearTextFields()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_passwordEdit->clearFocus();
- m_emailEdit->setText(""); // clear() method bugging in Qt 4.6, it leaves "dead" cursor
- m_emailEdit->setFocus(Qt::OtherFocusReason);
- m_passwordEdit->setText("");
-
-}
-
-void LoginDialog::userInput(QString &email, QString &password)
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- email = m_emailEdit->text();
- password = m_passwordEdit->text();
-}
+++ /dev/null
-/*
- 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 LOGINDIALOG_H
-#define LOGINDIALOG_H
-
-#include <QDialog>
-
-class QDialogButtonBox;
-class QLabel;
-class QLineEdit;
-class QPushButton;
-
-/**
-* @brief Custom login dialog. Email and password inserted into dialog will be forwarded to webview
-* Email and password will not be saved.
-*
-* @author Henri Lampela
-*/
-class LoginDialog : public QDialog
-{
- Q_OBJECT
-
-public:
-
- /**
- * @brief Default constructor
- *
- * @param parent Instance of parent widget
- */
- LoginDialog(QWidget *parent = 0);
-
- /**
- * @brief Gets email and password
- *
- * @param email Email address
- * @param password Password
- */
- void userInput(QString &email, QString &password);
-
-/*******************************************************************************
- * 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);
-
- /**
- * @brief Clears line edits
- *
- */
- void clearTextFields();
-
-/*******************************************************************************
- * DATA MEMBERS
- ******************************************************************************/
-
-private:
-
- QLineEdit *m_emailEdit; ///< Pointer to email line edit
- QLineEdit *m_passwordEdit; ///< Pointer to password line edit
-};
-
-#endif // LOGINDIALOG_H
#include "fullscreenbutton.h"
#include "indicatorbuttonpanel.h"
#include "locationsearchpanel.h"
-#include "logindialog.h"
#include "map/mapcommon.h"
#include "map/mapview.h"
#include "mapscale.h"
m_progressIndicatorCount(0),
m_loginDialog(0),
m_crosshair(0),
- m_email(), ///< @todo WTF?!?!?!?
- m_password(),
m_fullScreenButton(0),
m_indicatorButtonPanel(0),
m_mapScale(0)
void MainWindow::loggedIn(bool logged)
{
- /// @todo OLD CODE
qDebug() << __PRETTY_FUNCTION__;
m_loggedIn = logged;
if(logged) {
m_loginAct->setText(tr("Logout"));
} else {
-// clearCookieJar();
- m_email.clear();
- m_password.clear();
-
m_loginAct->setText(tr("Login"));
m_userInfoPanel->showUserInfo(false);
}
- updateItemVisibility();
-}
-
-void MainWindow::loginFailed()
-{
- /// @todo OLD CODE
- qDebug() << __PRETTY_FUNCTION__;
-
-// clearCookieJar();
- startLoginProcess();
-}
-
-bool MainWindow::loginState()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- return m_loggedIn;
+ updateItemVisibility(logged);
}
void MainWindow::mapCenterHorizontalShiftingChanged(int shifting)
queueDialog(searchDialog);
}
-void MainWindow::startLoginProcess()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- LoginDialog *loginDialog = new LoginDialog();
-
- emit fetchUsernameFromSettings();
-
- loginDialog->clearTextFields();
-
- if(!m_email.isEmpty())
- loginDialog->setEmailField(m_email);
-
- queueDialog(loginDialog);
-}
-
void MainWindow::toggleFullScreen()
{
qDebug() << __PRETTY_FUNCTION__;
#endif // Q_WS_MAEMO_5
}
-void MainWindow::updateItemVisibility()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_tabbedPanel->setTabsEnabled(m_situareTabsIndexes, m_loggedIn);
-}
-
-const QString MainWindow::username()
+void MainWindow::updateItemVisibility(bool loggedIn)
{
qDebug() << __PRETTY_FUNCTION__;
- return m_email;
+ m_tabbedPanel->setTabsEnabled(m_situareTabsIndexes, loggedIn);
}
void loggedIn(bool logged);
/**
- * @brief Gets the login state (logged in/logged out)
- *
- * @return bool Login state
- */
- bool loginState();
-
- /**
* @brief Reads automatic location update settings.
*/
void readAutomaticLocationUpdateSettings();
*/
void showEnableAutomaticUpdateLocationDialog(const QString &text);
- /**
- * @brief Gets the username from member variable for saving purposes
- *
- * @return QString Username
- */
- const QString username();
-
public slots:
/**
* @brief Builds information box with message.
void destroyLoginDialog();
/**
- * @brief Slot for failed login
- */
- void loginFailed();
-
- /**
* @brief Public slot, which open settings dialog
*/
void openSettingsDialog();
void showContactDialog(const QString &guid);
/**
- * @brief Public slot to intercept signal when old cerdentials are invalid or credentials
- * doesn't exist yet
- */
- void startLoginProcess();
-
- /**
* @brief Toggle progress indicator.
*
* @param state true if progress indicator should be shown, false otherwise
void toggleProgressIndicator(bool state);
/**
- * @brief Shows / hides Situare related UI items
+ * @brief Shows / hides Situare related UI items based on login state
*
+ * @param loggedIn Is the user currently logged in
*/
- void updateItemVisibility();
+ void updateItemVisibility(bool loggedIn);
private:
/**
void autoCenteringTriggered(bool enabled);
/**
- * @brief Signal that indicates when user has cancelled login process
- *
- */
- void cancelLoginProcess();
-
- /**
* @brief Signal for centering to coordinates.
*
* @param coordinates geo coordinates to center to.
void error(const int context, const int error);
/**
- * @brief Signal for requesting username from settings
- *
- */
- void fetchUsernameFromSettings();
-
- /**
* @brief Signals when friend's profile image is ready
*
* @param user Friend
QMessageBox *m_automaticUpdateLocationDialog; ///< Automatic update location dialog
- QString m_email; ///< Placeholder for email
- QString m_password; ///< Placeholder for password
-
FriendListPanel *m_friendsListPanel; ///< Instance of friends list panel
FullScreenButton *m_fullScreenButton; ///< Instance of the fullscreen toggle button
IndicatorButtonPanel *m_indicatorButtonPanel; ///< Instance of direction indicator button