const QString DIRECTORY_NAME = "Ixonos";
const QString FILE_NAME = "Situare";
+// QSettings common values
+const QString COOKIES = "cookies";
+const QString EMPTY = "";
+
const QColor COLOR_GRAY = QColor(152, 152, 152); ///< Gray color
const QFont NOKIA_FONT_NORMAL = QFont("Nokia Sans", 18, QFont::Normal); ///< Normal font
const QFont NOKIA_FONT_SMALL = QFont("Nokia Sans", 13, QFont::Normal); ///< Small font
+// Facobook login page pieces
+const QString FACEBOOK_LOGINBASE = "http://www.facebook.com/login.php?";
+const QString SITUARE_PUBLIC_FACEBOOKAPI_KEY = "api_key=4197c64da2fb6b927236feaea32d7d81";
+const QString SITUARE_DEVELOPER_FACEBOOK_APIKEY = "api_key=cf77865a5070f2c2ba3b52cbf3371579";
+const QString INTERVAL1 = "&connect_display=popup&v=1.0&next=";
+const QString SITUARE_LOGIN_SUCCESS = "http://www.facebook.com/connect/login_success.html";
+const QString INTERVAL2 = "&cancel_url=";
+const QString SITUARE_LOGIN_FAILURE = "http://www.facebook.com/connect/login_failure.html";
+const QString FACEBOOK_LOGIN_ENDING = "&fbconnect=true&return_session=true&";
+
#endif // COMMON_H
qDebug() << __PRETTY_FUNCTION__;
m_facebookAuthenticator->clearAccountInformation(true); // keep username = true
- m_facebookAuthenticator->start();
+ //m_facebookAuthenticator->start();
+ m_ui->loginUsingCookies();
}
void SituareEngine::loginActionPressed()
connect(m_facebookAuthenticator, SIGNAL(loginFailure()),
m_ui, SLOT(loginFailed()));
+
+ connect(m_facebookAuthenticator, SIGNAL(saveCookiesRequest()),
+ m_ui, SLOT(saveCookies()));
+
+ connect(m_facebookAuthenticator, SIGNAL(loginUsingCookies()),
+ m_ui, SLOT(loginUsingCookies()));
}
void SituareEngine::signalsFromGPS()
{
qDebug() << __PRETTY_FUNCTION__;
- if (!verifyCredentials(m_loginCredentials)) {
+ if(!verifyCredentials(m_loginCredentials)) {
QStringList list;
list.append(FACEBOOK_LOGINBASE);
list.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
list.append(SITUARE_LOGIN_FAILURE);
list.append(FACEBOOK_LOGIN_ENDING);
- emit newLoginRequest(formLoginPageUrl(list));
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+
+ QString cookies = settings.value(COOKIES, EMPTY).toString();
+ if(!cookies.isEmpty()) {
+ emit loginUsingCookies();
+ }
+ else {
+ emit newLoginRequest(formLoginPageUrl(list));
+ }
}
else {
emit credentialsReady(false, m_loginCredentials);
}
}
found = true;
+ emit saveCookiesRequest();
}
writeCredentials(m_loginCredentials);
emit credentialsReady(true, m_loginCredentials);
QSettings settings(DIRECTORY_NAME, FILE_NAME);
if(!keepUsername) {
settings.remove(USERNAME);
+ settings.remove(COOKIES);
}
settings.remove(USER_ID);
settings.remove(SESSION_KEY);
settings.remove(SESSION_SECRET);
settings.remove(EXPIRES);
- settings.remove(SIGNATURE);
+ settings.remove(SIGNATURE);
emit credentialsChanged(m_loginCredentials);
}
*/
void loginFailure();
+ void loginUsingCookies();
+
/**
* @brief Signals when credentials are invalid new login is needed
*
*/
void newLoginRequest(const QUrl &url);
+ void saveCookiesRequest();
+
/*******************************************************************************
* DATA MEMBERS
******************************************************************************/
#include <QString>
-// Facobook login page pieces
-const QString FACEBOOK_LOGINBASE = "http://www.facebook.com/login.php?";
-const QString SITUARE_PUBLIC_FACEBOOKAPI_KEY = "api_key=4197c64da2fb6b927236feaea32d7d81";
-const QString SITUARE_DEVELOPER_FACEBOOK_APIKEY = "api_key=cf77865a5070f2c2ba3b52cbf3371579";
-const QString INTERVAL1 = "&connect_display=popup&v=1.0&next=";
-const QString SITUARE_LOGIN_SUCCESS = "http://www.facebook.com/connect/login_success.html";
-const QString INTERVAL2 = "&cancel_url=";
-const QString SITUARE_LOGIN_FAILURE = "http://www.facebook.com/connect/login_failure.html";
-const QString FACEBOOK_LOGIN_ENDING = "&fbconnect=true&return_session=true&";
-
-const QString EMPTY = "";
const QString ERROR = "Error";
// Facebook webView font size
--- /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 "networkcookiejar.h"
+#include <QDebug>
+
+NetworkCookieJar::NetworkCookieJar(QObject *parent) :
+ QNetworkCookieJar(parent)
+{
+ m_cookieList.clear();
+}
+
+void NetworkCookieJar::setAllCookies(const QList<QNetworkCookie> &cookieList)
+{
+ m_cookieList = cookieList;
+}
+
+QList<QNetworkCookie> NetworkCookieJar::allCookies() const
+{
+ return m_cookieList;
+}
+
+bool NetworkCookieJar::setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url)
+{
+ Q_UNUSED(url);
+
+ QList<QNetworkCookie> cookies = allCookies();
+ foreach(QNetworkCookie cookie, cookieList) {
+ cookies += cookie;
+ //qDebug() << cookie.toRawForm(QNetworkCookie::Full);
+ }
+ setAllCookies(cookies);
+
+ return true;
+}
+
+QList<QNetworkCookie> NetworkCookieJar::cookiesForUrl ( const QUrl & url ) const
+{
+ Q_UNUSED(url);
+ return m_cookieList;
+}
--- /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 NETWORKCOOKIEJAR_H
+#define NETWORKCOOKIEJAR_H
+
+#include <QNetworkCookieJar>
+
+/**
+* @brief Sub-class of QNetworkCookieJar, needed for cookie saving
+*
+* @author Henri Lampela
+*/
+class NetworkCookieJar : public QNetworkCookieJar
+{
+ Q_OBJECT
+
+public:
+
+ /**
+ * @brief Constructor
+ *
+ * @param parent Instance of parent
+ */
+ explicit NetworkCookieJar(QObject *parent = 0);
+
+/*******************************************************************************
+ * BASE CLASS INHERITED AND REIMPLEMENTED MEMBER FUNCTIONS
+ ******************************************************************************/
+
+ /**
+ * @brief Sets all network cookies
+ *
+ * @param cookieList Network cookie list
+ */
+ void setAllCookies ( const QList<QNetworkCookie> & cookieList );
+
+ /**
+ * @brief Gets all networks cookies
+ *
+ * @return QList<QNetworkCookie> Network cookie list
+ */
+ QList<QNetworkCookie> allCookies() const;
+
+ /**
+ * @brief Sets network cookies from url
+ *
+ * @param cookieList Network cookie list
+ * @param url Url
+ * @return bool Return value
+ */
+ bool setCookiesFromUrl(const QList<QNetworkCookie> &cookieList, const QUrl &url);
+
+ /**
+ * @brief Empty implementation
+ *
+ * @param url Url
+ * @return QList<QNetworkCookie> Network cookie list
+ */
+ QList<QNetworkCookie> cookiesForUrl(const QUrl & url) const;
+
+/*******************************************************************************
+ * DATA MEMBERS
+ ******************************************************************************/
+
+private:
+
+ QList<QNetworkCookie> m_cookieList; ///< Placeholder for network cookies
+
+};
+
+#endif // NETWORKCOOKIEJAR_H
map/gpslocationitem.cpp \
ui/zoombuttonpanel.cpp \
ui/userinfo.cpp \
- ui/sidepanel.cpp
+ ui/sidepanel.cpp \
+ networkcookiejar.cpp
HEADERS += ui/mainwindow.h \
map/mapengine.h \
map/mapview.h \
ui/zoombuttonpanel.h \
common.h \
ui/userinfo.h \
- ui/sidepanel.h
+ ui/sidepanel.h \
+ networkcookiejar.h
QT += network \
webkit
-DEFINES += QT_NO_DEBUG_OUTPUT
+#DEFINES += QT_NO_DEBUG_OUTPUT
maemo5 | simulator {
SOURCES += gps/gpspositionprivate.cpp
connect(connectButton, SIGNAL(clicked()),
this, SLOT(connectPressed()));
+// connect(cancelButton, SIGNAL(clicked()),
+// this, SLOT(reject()));
connect(cancelButton, SIGNAL(clicked()),
- this, SLOT(reject()));
+ this, SLOT(cancelPressed()));
setLayout(gridLayout);
}
+void LoginDialog::cancelPressed()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ this->deleteLater();
+ reject();
+}
+
void LoginDialog::connectPressed()
{
qDebug() << __PRETTY_FUNCTION__;
emit loginDialogDone(m_emailEdit->text(), m_passwordEdit->text());
-
+ this->deleteLater();
accept();
}
qDebug() << __PRETTY_FUNCTION__;
m_passwordEdit->clearFocus();
- m_emailEdit->setText(""); // clear() method bugging in Qt 4.6.0, it leaves "dead" cursor
+ m_emailEdit->setText(""); // clear() method bugging in Qt 4.6, it leaves "dead" cursor
m_emailEdit->setFocus(Qt::OtherFocusReason);
m_passwordEdit->setText("");
*/
void connectPressed();
+ void cancelPressed();
+
signals:
/**
const int N900_APP_WIDTH = 800;
const int N900_APP_HEIGHT = 449;
+
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),
m_drawOwnLocationCrosshair(false),
m_refresh(false),
m_email(),
m_password(),
- m_loginUrl(),
- m_webView(0)
+ m_webView(0),
+ m_cookieJar(0)
{
qDebug() << __PRETTY_FUNCTION__;
m_friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
}
+void MainWindow::buildLoginDialog()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_loginDialog = new LoginDialog(this);
+
+ connect(m_loginDialog, SIGNAL(loginDialogDone(QString,QString)),
+ this, SLOT(loginDialogDone(QString,QString)));
+}
+
void MainWindow::buildManualLocationCrosshair()
{
qDebug() << __PRETTY_FUNCTION__;
m_userPanel, SLOT(screenResized(QSize)));
}
+void MainWindow::buildWebView()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if(!m_webView) {
+ qDebug() << "create webview";
+ m_webView = new QWebView;
+
+ connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
+ this, SIGNAL(updateCredentials(QUrl)));
+ connect(m_webView, SIGNAL(loadFinished(bool)),
+ this, SLOT(loadDone(bool)));
+
+ m_webView->hide();
+ }
+}
+
void MainWindow::buildZoomButtonPanel()
{
qDebug() << __PRETTY_FUNCTION__;
m_zoomButtonPanel, SLOT(disableZoomOutButton()));
}
+void MainWindow::clearCookieJar()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ buildWebView();
+
+ if(!m_cookieJar) {
+ m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
+ qDebug() << "create cookie jar";
+ }
+ QList<QNetworkCookie> emptyList;
+ emptyList.clear();
+
+ m_cookieJar->setAllCookies(emptyList);
+ m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
+}
+
void MainWindow::createMenus()
{
qDebug() << __PRETTY_FUNCTION__;
QWidget::keyPressEvent(event);
}
+void MainWindow::loadCookies()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+
+ QString cookies = settings.value(COOKIES, EMPTY).toString();
+ if(!cookies.isEmpty()) {
+ QStringList list = cookies.split("|");
+ QList<QNetworkCookie> cookieList;
+
+ for(int i=0;i<list.count();i++) {
+ QNetworkCookie tmpCookie;
+ QList<QNetworkCookie> parserList = tmpCookie.parseCookies(list.at(i).toAscii());
+ cookieList.append(parserList.at(0));
+ }
+ if(!m_cookieJar) {
+ m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
+ qDebug() << "create cookie jar";
+ }
+
+ m_cookieJar->setAllCookies(cookieList);
+ m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
+ }
+}
+
void MainWindow::loadDone(bool done)
{
qDebug() << __PRETTY_FUNCTION__;
m_loginAct->setText(tr("Logout"));
}
else {
+ clearCookieJar();
+ m_email.clear();
+ m_password.clear();
+
+// if(m_loginDialog)
+// m_loginDialog->clearTextFields();
+
m_loginAct->setText(tr("Login"));
}
showPanels(m_loggedIn);
{
qDebug() << __PRETTY_FUNCTION__;
- m_email.clear();
- m_password.clear();
-
toggleProgressIndicator(false);
#ifdef Q_WS_MAEMO_5
#endif // Q_WS_MAEMO_5
+ buildLoginDialog();
+
if(!m_email.isEmpty()) {
m_loginDialog->setEmailField(m_email);
}
else {
// re-load login page for webview
toggleProgressIndicator(true);
- m_webView->load(m_loginUrl);
+
+ // connect webview signals again since they might have been disconnected
+ connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
+ this, SIGNAL(updateCredentials(QUrl)));
+ connect(m_webView, SIGNAL(loadFinished(bool)),
+ this, SLOT(loadDone(bool)));
+
+ 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);
+
+ m_webView->load(QUrl(urlParts.join(EMPTY)));
}
}
+void MainWindow::loginUsingCookies()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ buildWebView();
+ loadCookies();
+
+ 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);
+
+ m_webView->load(QUrl(urlParts.join(EMPTY)));
+
+}
+
void MainWindow::openSettingsDialog()
{
qDebug() << __PRETTY_FUNCTION__;
dialog->show();
}
+void MainWindow::saveCookies()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if(!m_cookieJar)
+ m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
+
+ QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
+ QStringList list;
+
+ for(int i=0;i<cookieList.count();i++) {
+ QNetworkCookie cookie = cookieList.at(i);
+ QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
+ list.append(QString(byteArray));
+ }
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+
+ settings.setValue(COOKIES, list.join("|"));
+}
+
void MainWindow::setAutoCenteringButtonEnabled(bool enabled)
{
qDebug() << __PRETTY_FUNCTION__;
{
qDebug() << __PRETTY_FUNCTION__;
- m_loginUrl = url;
- m_webView = new QWebView;
- m_loginDialog = new LoginDialog(this);
+ buildWebView();
+ buildLoginDialog();
+// if(!m_webView)
+// m_webView = new QWebView;
- connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
- this, SIGNAL(updateCredentials(QUrl)));
- connect(m_webView, SIGNAL(loadFinished(bool)),
- this, SLOT(loadDone(bool)));
+// if(!m_loginDialog)
+// m_loginDialog = new LoginDialog(this);
- connect(m_loginDialog, SIGNAL(loginDialogDone(QString,QString)),
- this, SLOT(loginDialogDone(QString,QString)));
- m_webView->hide();
+
+// 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();
emit fetchUsernameFromSettings();
+ if(!m_cookieJar)
+ m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
+
+ m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
+
if(!m_email.isEmpty()) {
m_loginDialog->setEmailField(m_email);
}
emit cancelLoginProcess();
}
else {
- m_webView->load(m_loginUrl);
+ // connect webview signals again since they might have been disconnected
+ connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
+ this, SIGNAL(updateCredentials(QUrl)));
+ connect(m_webView, SIGNAL(loadFinished(bool)),
+ this, SLOT(loadDone(bool)));
+
+ m_webView->load(url);
toggleProgressIndicator(true);
m_refresh = true;
}
#include <QtGui/QMainWindow>
#include <QUrl>
+#include "networkcookiejar.h"
#include "panelsidebar.h"
class QGraphicsScene;
*/
void loginFailed();
+ void loginUsingCookies();
+
/**
* @brief Public slot, which open settings dialog
*/
*/
void buildFriendListPanel();
+ void buildLoginDialog();
+
/**
* @brief Build manual location setting cross hair and connect slots
*/
*/
void buildUserInfoPanel();
+ void buildWebView();
+
/**
* @brief Build zoom button panel and connect slots
*/
void buildZoomButtonPanel();
+ void clearCookieJar();
+
/**
* @brief Private method to create the Menu items
*/
*/
void gpsTimeout();
+ void loadCookies();
+
/**
* @brief Slot to intercept signal when webview has finished loading webpage
*
*/
void loadDone(bool done);
+ void saveCookies();
+
/**
* @brief Set correnct view port size to datamembers
*
QString m_email; ///< Placeholder for email
QString m_password; ///< Placeholder for password
- QUrl m_loginUrl; ///< Placeholder for login page url
-
QWebView *m_webView; ///< Shows facebook login page
FriendListPanel *m_friendsListPanel; ///< Instance of friends list panel
LoginDialog *m_loginDialog; ///< Login dialog
MapView *m_mapView; ///< Instance of the map view
+ NetworkCookieJar *m_cookieJar;
PanelSideBar *m_userPanelSidebar; ///< User panel side bar
PanelSideBar *m_friendsListPanelSidebar;///< Friends panel side bar
UserInfoPanel *m_userPanel; ///< Instance of the user information panel