*.orig
doc/doxygen/*
situare
-testtabs
+mainwindow_test
--- /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 <QStringList>
+#include "cookiehandler.h"
+
+CookieHandler::CookieHandler()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+}
+
+CookieHandler::~CookieHandler()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+}
+
+QString CookieHandler::formCookie(const QString &apiKeyValue, QString expiresValue,
+ QString userValue, QString sessionKeyValue,
+ QString sessionSecretValue, const QString &signatureValue,
+ const QString &localeValue)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QString cookie;
+ QString apiKey;
+ QString user;
+ QString expires;
+ QString sessionKey;
+ QString sessionSecret;
+ QString locale;
+ QString variable;
+ QString signature = EQUAL_MARK;
+ QStringList variableList;
+
+ signature.append(signatureValue);
+ apiKey.append(apiKeyValue);
+ apiKey.append(UNDERLINE_MARK);
+
+ user.append(USER);
+ user.append(EQUAL_MARK);
+ expires.append(EXPIRES);
+ expires.append(EQUAL_MARK);
+ sessionKey.append(SESSION_KEY);
+ sessionKey.append(EQUAL_MARK);
+ sessionSecret.append(SESSION_SECRET);
+ sessionSecret.append(EQUAL_MARK);
+ locale.append(LOCALE);
+ locale.append(EQUAL_MARK);
+ locale.append(localeValue);
+
+ variableList.append(expires.append(expiresValue.append(BREAK_MARK)));
+ variableList.append(sessionKey.append(sessionKeyValue.append(BREAK_MARK)));
+ variableList.append(user.append(userValue).append(BREAK_MARK));
+ variableList.append(sessionSecret.append(sessionSecretValue.append(BREAK_MARK)));
+
+ cookie.append(BREAK_MARK);
+
+ foreach(variable, variableList) {
+ cookie.append(apiKey);
+ cookie.append(variable);
+ }
+ apiKey.remove(UNDERLINE_MARK);
+ cookie.append(apiKey);
+ cookie.append(signature);
+ cookie.append(BREAK_MARK);
+ cookie.append(locale);
+
+ qDebug() << cookie;
+
+ return cookie;
+}
--- /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 COOKIEHANDLER_H
+#define COOKIEHANDLER_H
+
+#include <QString>
+#include "../situareservice/situarecommon.h"
+
+/**
+* @brief Class for cookie cretion.
+*
+* @author Henri Lampela
+* @class CookieHandler cookiehandler.h "cookiehandler/cookiehandler.h"
+*/
+class CookieHandler
+{
+public:
+
+ /**
+ * @brief Default constructor
+ *
+ */
+ CookieHandler();
+
+ /**
+ * @brief Destructor
+ *
+ */
+ ~CookieHandler();
+
+ /**
+ * @brief Forms a http cookie
+ *
+ * @param apiKeyValue application key
+ * @param expiresValue session expire date&time from Facebook
+ * @param userValue user id from Facebook
+ * @param sessionKeyValue session key from Facebook
+ * @param sessionSecretValue session secret from Facebook
+ * @param signatureValue md5 generated signature
+ * @param localeValue used locale
+ * @return QString formed cookie
+ */
+ QString formCookie(const QString &apiKeyValue, QString expiresValue, QString userValue,
+ QString sessionKeyValue, QString sessionSecretValue,
+ const QString &signatureValue, const QString &localeValue);
+
+};
+
+#endif // COOKIEHANDLER_H
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Ville Tiensuu - ville.tiensuu@ixonos.com
+ Kaj Wallin - kaj.wallin@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 <QtGui>
+#include <QtDebug>
+#include <QDateTime>
+#include "facebookauthentication.h"
+#include "facebookcommon.h"
+
+FacebookAuthentication::FacebookAuthentication(QWidget *parent)
+ : QMainWindow(parent)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_webView = new QWebView;
+ m_mainlayout = new QHBoxLayout;
+
+ m_facebookLoginPage = formLoginPage(FACEBOOK_LOGINBASE, SITUARE_PUBLIC_FACEBOOKAPI_KEY,
+ INTERVAL1, SITUARE_LOGIN_SUCCESS, INTERVAL2,
+ SITUARE_LOGIN_FAILURE, FACEBOOK_LOGIN_ENDING);
+
+ connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
+ this, SLOT(updateCredentials(const QUrl &)));
+
+ readCredentials(m_loginCredentials);
+
+ if (!verifyCredentials(m_loginCredentials))
+ start();
+ else
+ emit credentialsReady();
+}
+
+FacebookAuthentication::~FacebookAuthentication()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ delete m_webView;
+ delete m_mainlayout;
+}
+
+void FacebookAuthentication::start()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_webView->setZoomFactor(FACEBOOK_LOGINPAGE_FONT_SIZE);
+ m_webView->load(m_facebookLoginPage);
+ setCentralWidget(m_webView);
+}
+
+
+bool FacebookAuthentication::updateCredentials(const QUrl &url)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ bool foundSessionKey = FALSE;
+ bool foundUserID = FALSE;
+ bool foundExpires = FALSE;
+ bool foundSessionSecret = FALSE;
+ bool foundSig = FALSE;
+
+ if (url.isValid()){
+ qDebug() << "url is valid" << endl;
+
+ QString callbackUrl = url.toString();
+ QString urlEdit(callbackUrl);
+ qDebug() << "callbackUrl: " << endl << callbackUrl.toAscii() << endl;
+
+ if ( callbackUrl.indexOf(LOGIN_SUCCESS_REPLY) == 0 ){
+ qDebug() << "login success" << endl;
+
+ // let's find out session key
+ int indexOfCredential = callbackUrl.indexOf(SESSION_KEY);
+
+ if (indexOfCredential != -1){
+ foundSessionKey = TRUE;
+
+ indexOfCredential += 14; //lenght of SESSION_KEY
+ urlEdit.remove(0,indexOfCredential);
+ indexOfCredential = urlEdit.indexOf(USER_ID);
+ urlEdit.remove(indexOfCredential, urlEdit.length());
+ urlEdit.remove("\",\"");
+
+ qDebug() << "Session Key" << endl << urlEdit.toAscii() << endl;
+ m_loginCredentials.setSessionKey(urlEdit);
+ }
+
+ // let's find out uid
+ urlEdit = callbackUrl;
+ indexOfCredential = callbackUrl.indexOf(USER_ID);
+
+ if (indexOfCredential != -1){
+ foundUserID = TRUE;
+
+ indexOfCredential += 5; //length of USER_ID:
+ urlEdit.remove(0,indexOfCredential);
+ indexOfCredential = urlEdit.indexOf(EXPIRES);
+ urlEdit.remove(indexOfCredential, urlEdit.length());
+ urlEdit.remove(",\"");
+
+ qDebug() << "userID" << endl << urlEdit.toAscii() << endl;
+ m_loginCredentials.setUserID(urlEdit);
+ }
+
+ // let's find out expires
+ urlEdit = callbackUrl;
+ indexOfCredential = callbackUrl.indexOf(EXPIRES);
+
+ if (indexOfCredential != -1){
+ foundExpires = TRUE;
+
+ indexOfCredential += 9; //length of EXPIRES
+ urlEdit.remove(0,indexOfCredential);
+ indexOfCredential = urlEdit.indexOf(SESSION_SECRET);
+ urlEdit.remove(indexOfCredential, urlEdit.length());
+ urlEdit.remove(",\"");
+
+ qDebug() << "Expires" << endl << urlEdit.toAscii() << endl;
+ m_loginCredentials.setExpires(urlEdit);
+ }
+
+ // let's find out sessionsecret
+ urlEdit = callbackUrl;
+ indexOfCredential = callbackUrl.indexOf(SESSION_SECRET);
+
+ if (indexOfCredential != -1){
+ foundSessionSecret = TRUE;
+
+ indexOfCredential += 9; //" length of SESSION_SECRET
+ urlEdit.remove(0,indexOfCredential);
+ indexOfCredential = urlEdit.indexOf(SIGNATURE);
+ urlEdit.remove(indexOfCredential, urlEdit.length());
+ urlEdit.remove("\",\"");
+
+ qDebug() << "Session Secret" << endl << urlEdit.toAscii() << endl;
+ m_loginCredentials.setSessionSecret(urlEdit);
+ }
+
+ // let's find out sig
+ urlEdit = callbackUrl;
+ indexOfCredential = callbackUrl.indexOf(SIGNATURE);
+
+ if (indexOfCredential != -1){
+ foundSig = TRUE;
+
+ indexOfCredential += 6; //" length of SIGNATURE
+ urlEdit.remove(0,indexOfCredential);
+ urlEdit.remove("\"}");
+
+ qDebug() << "Signature" << endl << urlEdit.toAscii() << endl;
+ m_loginCredentials.setSig(urlEdit);
+ }
+
+ m_webView->hide();
+ emit credentialsReady();
+ writeCredentials(m_loginCredentials);
+ }
+
+ else if ( callbackUrl.indexOf(LOGIN_FAILURE_REPLY) == 0){
+ qWarning() << "login failure" << endl;
+ emit loginFailure();
+ }
+
+ else if ( callbackUrl.indexOf(LOGIN_PAGE) == 0){
+ qDebug() << "correct loginPage";
+ }
+
+ else {
+ qDebug() << "totally wrong webPage";
+ emit loginFailure();
+ start();
+ }
+ }
+
+ else {
+ qDebug() << " Loading of page failed invalid URL" << endl;
+ emit loginFailure();
+ return FALSE;
+ }
+
+
+ return (foundSessionKey && foundUserID && foundExpires && foundSessionSecret && foundSig);
+}
+
+void FacebookAuthentication::writeCredentials(const FacebookCredentials &credentials)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+
+ settings.setValue("Session Key", credentials.sessionKey());
+ settings.setValue("User ID", credentials.userID());
+ settings.setValue("Expires", credentials.expires());
+ settings.setValue("Session Secret", credentials.sessionSecret());
+ settings.setValue("Sig", credentials.sig());
+}
+
+void FacebookAuthentication::readCredentials(FacebookCredentials &credentialsFromFile)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+
+ credentialsFromFile.setSessionKey(settings.value("Session Key", "Error").toString());
+ credentialsFromFile.setUserID(settings.value("User ID", "Error").toString());
+ credentialsFromFile.setExpires(settings.value("Expires", "Error").toString());
+ credentialsFromFile.setSessionSecret(settings.value("Session Secret", "Error").toString());
+ credentialsFromFile.setSig(settings.value("Sig", "Error").toString());
+}
+
+ FacebookCredentials FacebookAuthentication::loginCredentials() const
+ {
+ qDebug() << __PRETTY_FUNCTION__;
+ return m_loginCredentials;
+ }
+
+ bool FacebookAuthentication::verifyCredentials(const FacebookCredentials &credentials) const
+ {
+ qDebug() << __PRETTY_FUNCTION__;
+ QString expires = credentials.expires();
+ QDateTime expireTime;
+ expireTime.setTime_t(expires.toInt());
+ QString expiresString = expireTime.toString("dd.MM.yyyy hh:mm:ss");
+ qDebug() << expiresString.toAscii();
+
+ QDateTime currentTime;
+ currentTime = QDateTime::currentDateTime();
+ QString currentTimeString = currentTime.toString("dd.MM.yyyy hh:mm:ss");
+ qDebug() << currentTimeString.toAscii();
+
+ return currentTime < expireTime;
+ }
+
+ void FacebookAuthentication::closeEvent(QCloseEvent *event)
+ {
+ qDebug() << __PRETTY_FUNCTION__;
+ int eventNumber = 0;
+ eventNumber = event->registerEventType();
+ qDebug() << "event number" << eventNumber;
+ emit userExit();
+ event->accept();
+ }
+
+ QString FacebookAuthentication::formLoginPage(const QString & part1, const QString & part2,
+ const QString & part3, const QString & part4,
+ const QString & part5, const QString & part6,
+ const QString & part7) const
+ {
+ QString loginPage;
+ loginPage.append(part1);
+ loginPage.append(part2);
+ loginPage.append(part3);
+ loginPage.append(part4);
+ loginPage.append(part5);
+ loginPage.append(part5);
+ loginPage.append(part6);
+ loginPage.append(part7);
+
+ return loginPage;
+ }
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Ville Tiensuu - ville.tiensuu@ixonos.com
+ Kaj Wallin - kaj.wallin@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 FACEBOOKAUTHENTICATION_H
+#define FACEBOOKAUTHENTICATION_H
+
+#include <QtGui>
+#include <QtWebKit>
+#include <QString>
+#include <QLayout>
+#include "facebookcredentials.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.
+*
+* @author Ville Tiensuu
+* @class FacebookAuthentication facebookauthentication.h "facebookauthentication.h"
+*/
+class FacebookAuthentication : public QMainWindow
+{
+ Q_OBJECT
+
+public:
+ /**
+ * @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
+ *
+ * @param parent instance of parent
+ */
+ FacebookAuthentication(QWidget *parent = 0);
+
+ /**
+ * @brief Releases allocated memory for m_webView and m_mainlayout
+ *
+ */
+ ~FacebookAuthentication();
+
+ /**
+ * @brief Getter for m_loginCredentials
+ *
+ * @return FacebookCredentials
+ */
+ FacebookCredentials loginCredentials() const;
+
+public slots:
+ /**
+ * @brief Shows the m_webView and loads page that is specified in the m_facebookLoginPage
+ * variable. Specifies font size for the page.
+ *
+ */
+ void start();
+
+private:
+
+ /**
+ * @brief Program cames to this method when user closes login screen by pressing X.
+ * method sends userExit() signal in this function
+ *
+ * @param event without parameter program does not come to this function when user exits by
+ * pressing X.
+ */
+ void closeEvent(QCloseEvent *event);
+
+ /**
+ * @brief Appends given parts to returned string. Method is used to form facebook login page
+ from given parts.
+ *
+ * @param part1 first part of the formed string
+ * @param part2 second part of the formed string
+ * @param part3 third part of the formed string
+ * @param part4 fouth part of the formed string
+ * @param part5 fifth part of the formed string
+ * @param part6 sixth part of the formed string
+ * @param part7 sevents part of the formed string
+ */
+ QString formLoginPage(const QString & part1, const QString & part2, const QString & part3,
+ const QString & part4, const QString & part5, const QString & part6,
+ const QString & part7) const;
+
+ /**
+ * @brief Reads previous stored credentials from file.
+ *
+ * @param credentialsFromFile This dataclass is the place where method stores credentials.
+ * Corrent parameter here is m_loginCredentials
+ */
+ void readCredentials(FacebookCredentials &credentialsFromFile);
+
+ /**
+ * @brief Checks expiration time of credentials and compares it to current time.
+ *
+ * @param credentials this parameter represents credentials that will be verified.
+ * @return bool returns true if expiration time is after current time. in other cases returns
+ * false.
+ */
+ bool verifyCredentials(const FacebookCredentials &credentials) const;
+
+ /**
+ * @brief Writes credentials to File
+ *
+ * @param credentials Contents of this dataclass is stored to file
+ */
+ 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.
+ *
+ * @param url URL where this method tries to find credentials.
+ * @return bool if credentials are found returns true,
+ * if credentials are not found returns false.
+ */
+ bool updateCredentials(const QUrl & url);
+
+signals:
+
+ /**
+ * @brief This signal is emitted if updateCredentials method finds credentials from URL.
+ * Signal is also emitted at the beginning of the program if there is valid credentials
+ * in the file.
+ *
+ */
+ void credentialsReady();
+
+ /**
+ * @brief This signal is emitted if updateCredentials method can't find credentials from URL
+ *
+ */
+ void loginFailure();
+
+ /**
+ * @brief This signal is emitted if user exits logging in by pressing X
+ *
+ */
+ void userExit();
+
+private:
+
+ /**
+ * @brief String that contantains URL of facebook loginpage.
+ *
+ * @var m_facebookLoginPage
+ */
+ QString m_facebookLoginPage;
+
+ /**
+ * @brief Dataclass that contains authorization to use facebook. Dataclass is composed of five
+ * QStrings and setters and getters.
+ *
+ * @var m_loginCredentials
+ */
+ FacebookCredentials m_loginCredentials;
+
+ /**
+ * @brief Lays out m_webView in window.
+ *
+ * @var m_mainlayout
+ */
+ QHBoxLayout *m_mainlayout;
+
+ /**
+ * @brief Shows facebook login page.
+ *
+ * @var m_webView
+ */
+ QWebView *m_webView;
+};
+
+#endif // FACEBOOKAUTHENTICATION_H
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Ville Tiensuu - ville.tiensuu@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 FACEBOOKCOMMON_H
+#define FACEBOOKCOMMON_H
+
+#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&";
+
+// Facebook webView font size
+const double FACEBOOK_LOGINPAGE_FONT_SIZE = 1.2;
+
+// Facebook callback url indentifiers
+const QString SESSION_KEY = "session_key";
+const QString USER_ID = "uid";
+const QString EXPIRES = "expires";
+const QString SESSION_SECRET = "secret";
+const QString SIGNATURE = "sig";
+
+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=";
+
+// QSettings identifiers
+const QString DIRECTORY_NAME = "Ixonos";
+const QString FILE_NAME = "Situare";
+
+
+
+
+
+
+
+#endif // FACEBOOKCOMMON_H
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Ville Tiensuu - ville.tiensuu@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 <QtGlobal>
+#include "facebookcredentials.h"
+
+FacebookCredentials::FacebookCredentials()
+{
+}
+
+void FacebookCredentials::setSessionKey(const QString & sessionKeyParameter)
+{
+ m_sessionKey = sessionKeyParameter;
+}
+
+void FacebookCredentials::setSessionSecret(const QString & sessionSecretParameter)
+{
+ m_sessionSecret = sessionSecretParameter;
+}
+
+
+void FacebookCredentials::setExpires (const QString & expiresParameter)
+{
+ m_expires = expiresParameter;
+}
+
+void FacebookCredentials::setUserID (const QString & userIDParameter)
+{
+ m_userID = userIDParameter;
+}
+
+void FacebookCredentials::setSig(const QString & sigParameter)
+{
+ m_sig = sigParameter;
+}
+
+QString FacebookCredentials::sessionKey() const
+{
+ return m_sessionKey;
+}
+
+QString FacebookCredentials::sessionSecret() const
+{
+ return m_sessionSecret;
+}
+
+QString FacebookCredentials::expires() const
+{
+ return m_expires;
+}
+
+QString FacebookCredentials::userID() const
+{
+ return m_userID;
+}
+
+QString FacebookCredentials::sig() const
+{
+ return m_sig;
+}
+
+bool FacebookCredentials::operator==(const FacebookCredentials &credentials)
+{
+ bool expireBool = (m_expires == credentials.expires());
+ bool sessionKeyBool = (m_sessionKey == credentials.sessionKey());
+ bool sessionSecretBool = (m_sessionSecret == credentials.sessionSecret());
+ bool sigBool = (m_sig == credentials.sig());
+ bool userIdBool = (m_userID == credentials.userID());
+
+ return expireBool && sessionKeyBool && sessionSecretBool && sigBool && userIdBool;
+}
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Ville Tiensuu - ville.tiensuu@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 FACEBOOKCREDENTIALS_H
+#define FACEBOOKCREDENTIALS_H
+
+#include <QString>
+
+/**
+* @brief Class is used to integrate facebook credentials together.
+*
+* @author Ville Tiensuu
+* @class FacebookCredentials facebookcredentials.h "situare/src/facebookservice/facebookcredentials.h"
+*/
+class FacebookCredentials
+{
+public:
+ /**
+ * @brief Default constructor
+ *
+ */
+ FacebookCredentials();
+
+ /**
+ * @brief Set funtion for m_expires member
+ *
+ * @param expiresParameter value of parameter is set to m_expires member
+ */
+ void setExpires (const QString & expiresParameter);
+
+ /**
+ * @brief Set function for m_sessionKey member
+ *
+ * @param sessionKeyParameter value of parameter is set to m_sessionKey member
+ */
+ void setSessionKey(const QString & sessionKeyParameter);
+
+ /**
+ * @brief Set function for m_sessionSecret member
+ *
+ * @param sessionSecretParameter value of parameter is set to m_sessionSecret member
+ */
+ void setSessionSecret(const QString & sessionSecretParameter);
+
+ /**
+ * @brief Set funtion for m_sig member
+ *
+ * @param sigParameter value of parameter is set to m_sig member
+ */
+ void setSig(const QString & sigParameter);
+
+ /**
+ * @brief Set function for m_userID member
+ *
+ * @param userIDParameter value of parameter is set to m_userID member
+ */
+ void setUserID(const QString & userIDParameter);
+
+ /**
+ * @brief Get function for m_expires member
+ *
+ * @return QString m_expires
+ */
+ QString expires() const;
+
+ /**
+ * @brief Get function for m_sessionKey member
+ *
+ * @return QString m_sessionKey
+ */
+ QString sessionKey() const;
+
+ /**
+ * @brief Get funtion for m_sessionSecret member
+ *
+ * @return QString m_sessionSecret
+ */
+ QString sessionSecret() const;
+
+ /**
+ * @brief Get function for m_sig member
+ *
+ * @return QString m_sig
+ */
+ QString sig() const;
+
+ /**
+ * @brief Get function for m_userID member
+ *
+ * @return QString m_userID
+ */
+ QString userID() const;
+
+ /**
+ * @brief Overloaded operator == is used to compare two FacebookCredentials.
+ *
+ * @param credentials to be checked
+ * @return bool returns true if all members are same, else returns false
+ */
+ bool operator==(const FacebookCredentials& credentials);
+
+private:
+
+ /**
+ * @brief String for storing expires
+ *
+ * @var m_expires
+ */
+ QString m_expires;
+
+ /**
+ * @brief String for storing sessionKey
+ *
+ * @var m_sessionKey
+ */
+ QString m_sessionKey;
+
+ /**
+ * @brief String for storing sessionSecret
+ *
+ * @var m_sessionSecret
+ */
+ QString m_sessionSecret;
+
+ /**
+ * @brief String for storing sig
+ *
+ * @var m_sig
+ */
+ QString m_sig;
+
+ /**
+ * @brief String for storing userID
+ *
+ * @var m_userID
+ */
+ QString m_userID;
+};
+
+#endif // FACEBOOKCREDENTIALS_H
{
QApplication a(argc, argv);
MainWindow w;
- w.show();
- return a.exec();
+ int appRet = a.exec();
+ return appRet;
}
--- /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 SITUARECOMMON_H
+#define SITUARECOMMON_H
+
+#include <QString>
+
+// Situare server constants
+const QString SITUARE_URL = "http://client.situare.net/";
+const QString API_KEY = "4197c64da2fb6b927236feaea32d7d81";
+
+// Test server constants
+const QString SITUARE_TEST_URL = "http://emmerichgn.facebook.joyent.us/";
+const QString TEST_API_KEY = "cf77865a5070f2c2ba3b52cbf3371579";
+
+// Situare PHP scripts
+const QString UPDATE_LOCATION = "updateLocation.php";
+const QString REVERSE_GEO = "reversegeo.php";
+
+// Cookies
+const QString COOKIE = "Cookie";
+const QString USER = "user";
+const QString EXPIRES = "expires";
+const QString SESSION_KEY = "session_key";
+const QString SESSION_SECRET = "ss";
+
+const QString USER_AGENT = "User-Agent";
+const QString AGENT = "Agent";
+
+// Locales
+const QString LOCALE = "locale";
+const QString EN_LOCALE = "en_EN";
+
+// Common marks
+const QString QUESTION_MARK = "?";
+const QString AMBERSAND_MARK = "&";
+const QString EQUAL_MARK = "=";
+const QString UNDERLINE_MARK = "_";
+const QString BREAK_MARK = ";";
+
+// Coordinates
+const QString LATITUDE = "lat";
+const QString LONGTITUDE = "lon";
+
+// Url parameters
+const QString PUBLISH = "publish";
+const QString PUBLISH_TRUE = "true";
+const QString PUBLISH_FALSE = "false";
+const QString DATA = "data";
+
+// Situare error messages
+const QString ERROR_LAT = "Wrong lat value: . Latitude must be between -90 and 90!";
+const QString ERROR_LON = "Wrong lon value: . Longitude must be between -180 and 180!";
+const QString ERROR_SESSION = "<br />\n<b>Fatal error</b>:"; // starts with
+
+#endif // SITUARECOMMON_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 <QtGlobal>
+#include <QStringList>
+#include "situareservice.h"
+#include "situarecommon.h"
+#include "../cookiehandler/cookiehandler.h"
+
+SituareService::SituareService(QObject *parent, QNetworkAccessManager *manager)
+ : QObject(parent), m_networkManager(manager)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ connect(&m_facebookAuthentication, SIGNAL(credentialsReady()), SLOT(credentialsReady()));
+
+ connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(requestFinished(QNetworkReply*)));
+
+ m_credentials = m_facebookAuthentication.loginCredentials();
+}
+
+SituareService::~SituareService()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ delete m_networkManager;
+}
+
+void SituareService::updateLocation(const QPointF &coordinates, const QString &status,
+ const bool &publish)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ CookieHandler cookieHandler;
+
+ QString cookie = cookieHandler.formCookie(API_KEY, m_credentials.expires(), m_credentials.userID(),
+ m_credentials.sessionKey(), m_credentials.sessionSecret(),
+ m_credentials.sig(), EN_LOCALE);
+
+
+ QString publishValue;
+ if(publish) {
+ publishValue = PUBLISH_TRUE;
+ }
+ else {
+ publishValue = PUBLISH_FALSE;
+ }
+ QString urlParameters = formUrlParameters(coordinates, status, publishValue);
+ QUrl url = formUrl(SITUARE_URL, UPDATE_LOCATION, urlParameters);
+
+ sendRequest(url, COOKIE, cookie);
+}
+
+void SituareService::reverseGeo(const QPointF &coordinates)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ CookieHandler cookieHandler;
+
+ QString cookie = cookieHandler.formCookie(API_KEY, m_credentials.expires(), m_credentials.userID(),
+ m_credentials.sessionKey(), m_credentials.sessionSecret(),
+ m_credentials.sig(), EN_LOCALE);
+
+ QString urlParameters = formUrlParameters(coordinates);
+ QUrl url = formUrl(SITUARE_URL, REVERSE_GEO, urlParameters);
+
+ sendRequest(url, COOKIE, cookie);
+}
+
+QUrl SituareService::formUrl(const QString &baseUrl, const QString &phpScript, QString urlParameters)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QString urlString;
+
+ urlString.append(baseUrl);
+ urlString.append(phpScript);
+ if(urlParameters != NULL)
+ urlString.append(urlParameters);
+
+ QUrl url = QUrl(urlString);
+
+ qDebug() << url;
+
+ return url;
+}
+
+QString SituareService::formUrlParameters(const QPointF &coordinates, QString status, QString publish)
+{
+ QString parameters;
+
+ parameters.append(QUESTION_MARK);
+ parameters.append(LATITUDE);
+ parameters.append(EQUAL_MARK);
+ parameters.append(QString::number(coordinates.x()));
+ parameters.append(AMBERSAND_MARK);
+ parameters.append(LONGTITUDE);
+ parameters.append(EQUAL_MARK);
+ parameters.append(QString::number(coordinates.y()));
+
+ if(publish.compare(PUBLISH_TRUE) == 0) {
+ parameters.append(AMBERSAND_MARK);
+ parameters.append(PUBLISH);
+ parameters.append(EQUAL_MARK);
+ parameters.append(PUBLISH_TRUE);
+ }
+ else if(publish.compare(PUBLISH_FALSE) == 0) {
+ parameters.append(AMBERSAND_MARK);
+ parameters.append(PUBLISH);
+ parameters.append(EQUAL_MARK);
+ parameters.append(PUBLISH_FALSE);
+ }
+
+ if(status != NULL) {
+ parameters.append(AMBERSAND_MARK);
+ parameters.append(DATA);
+ parameters.append(EQUAL_MARK);
+ parameters.append(status);
+ }
+
+ return parameters;
+}
+
+void SituareService::sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie)
+{
+ qDebug() << __PRETTY_FUNCTION__ << "url: " << url;
+
+ QNetworkRequest request;
+
+ request.setUrl(url);
+ request.setRawHeader(cookieType.toAscii(), cookie.toUtf8());
+
+ QNetworkReply *reply = m_networkManager->get(request);
+
+ m_currentRequests.append(reply);
+}
+
+void SituareService::requestFinished(QNetworkReply *reply)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QUrl url = reply->url();
+ qDebug() << "BytesAvailable: " << reply->bytesAvailable();
+ if (reply->error()) {
+ qDebug() << reply->errorString();
+ emit error(reply->errorString());
+ // ToDo: some general http error handling etc, signal UI?
+ }
+ else {
+ qint64 max = reply->size();
+ QByteArray replyArray = reply->read(max);
+ qDebug() << "Reply from: " << url << "reply " << replyArray;
+ // ToDo: results handling includes Situare's errors
+ // works like situare's error handling i.e. both lat & lon are missing/wrong
+ // -> we get only error for wrong lon
+ if(replyArray == ERROR_LAT.toAscii()) {
+ qDebug() << "Error: " << ERROR_LAT;
+ // ToDo: signal UI?
+ emit error(replyArray);
+ }
+ else if(replyArray == ERROR_LON.toAscii()) {
+ qDebug() << "Error: " << ERROR_LON;
+ // ToDo: signal UI?
+ emit error(replyArray);
+ }
+ else if(replyArray.contains(ERROR_SESSION.toAscii())) {
+ qDebug() << "Error: " << ERROR_SESSION;
+ // ToDo: signal UI?
+ emit error(replyArray);
+ }
+ else {
+ // no error -> update was successful
+ // ToDo: signal UI?
+ qDebug() << reply->read(max);
+ }
+ }
+
+ m_currentRequests.removeAll(reply);
+ reply->deleteLater();
+}
+
+void SituareService::credentialsReady()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ m_credentials = m_facebookAuthentication.loginCredentials();
+}
--- /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 SITUARESERVICE_H
+#define SITUARESERVICE_H
+
+#include <QObject>
+#include <QPointF>
+#include <QNetworkAccessManager>
+#include <QNetworkRequest>
+#include <QNetworkReply>
+#include <QUrl>
+#include "../facebookservice/facebookauthentication.h"
+#include "../facebookservice/facebookcredentials.h"
+
+/**
+* @brief SituareService class for communicating with Situare server
+*
+* @author Henri Lampela
+* @class SituareService situareservice.h "situareservice/situareservice.h"
+*/
+class SituareService : public QObject
+{
+ Q_OBJECT
+
+public:
+
+ /**
+ * @brief Default constructor
+ *
+ * @param parent instance of parent
+ * @param manager instance of QNetworkAccessManager
+ */
+ SituareService(QObject *parent = 0, QNetworkAccessManager *manager = 0);
+
+ /**
+ * @brief Destructor
+ *
+ */
+ ~SituareService();
+
+ /**
+ * @brief Updates location to the Situare server
+ *
+ * @param coordinates current cordinates
+ * @param status message
+ * @param publish publish location on Facebook wall (true/false)
+ */
+ void updateLocation(const QPointF &coordinates, const QString &status, const bool &publish);
+
+ /**
+ * @brief Translates coordinates to street address via Situare server
+ *
+ * @param coordinates coordinates to be translated
+ */
+ void reverseGeo(const QPointF &coordinates);
+
+public slots:
+
+ /**
+ * @brief Public slot, which indicates when http request has been completed
+ *
+ * @param reply storage for http reply
+ */
+ void requestFinished(QNetworkReply *reply);
+
+
+ /**
+ * @brief Public slot, which indicates when facebook credentials are ready
+ *
+ */
+ void credentialsReady();
+
+private:
+
+ /**
+ * @brief Forms a http url
+ *
+ * @param baseUrl Server url
+ * @param phpScript Server script
+ * @param urlParameters optional parameters for url
+ * @return QUrl formed url
+ */
+ QUrl formUrl(const QString &baseUrl, const QString &phpScript, QString urlParameters = 0);
+
+ /**
+ * @brief Forms url parameters
+ *
+ * @param coordinates current coordinates
+ * @param status optional status message
+ * @param publish optional publish location on Facebook wall (true/false)
+ * @return QString
+ */
+ QString formUrlParameters(const QPointF &coordinates, QString status = 0, QString publish = 0);
+
+ /**
+ * @brief Sends http request
+ *
+ * @param url destination
+ * @param cookieType type of the cookie
+ * @param cookie http cookie
+ */
+ void sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie);
+
+signals:
+
+ /**
+ * @brief Signals error
+ *
+ * @param error error message
+ */
+ void error(const QString &error);
+
+private:
+
+ FacebookCredentials m_credentials; ///< handle for FacebookCredentials
+ QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
+ FacebookAuthentication m_facebookAuthentication; ///< Pointer to FacebookAuthentication
+ QNetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
+};
+
+#endif // SITUARESERVICE_H
ui/mainwindow.cpp \
ui/mapviewscreen.cpp \
ui/listviewscreen.cpp \
+ situareservice/situareservice.cpp \
+ cookiehandler/cookiehandler.cpp \
+ facebookservice/facebookcredentials.cpp \
+ facebookservice/facebookauthentication.cpp \
map/mapengine.cpp \
map/mapview.cpp \
map/mapscene.cpp \
map/maptile.cpp \
map/mapfetcher.cpp \
ui/pixmap.cpp \
- ui/infotab.cpp
+ ui/infotab.cpp \
+ ui/updatelocation/updatelocationdialog.cpp \
+ ui/updatelocation/texteditautoresizer.cpp
HEADERS += ui/mainwindow.h \
ui/mapviewscreen.h \
ui/listviewscreen.h \
map/mapfetcher.h \
map/mapcommon.h \
ui/pixmap.h \
- ui/infotab.h
+ ui/infotab.h \
+ ui/updatelocation/updatelocationdialog.h \
+ ui/updatelocation/texteditautoresizer.h \
+ situareservice/situareservice.h \
+ situareservice/situarecommon.h \
+ cookiehandler/cookiehandler.h \
+ facebookservice/facebookcredentials.h \
+ facebookservice/facebookauthentication.h \
+ facebookservice/facebookcommon.h
QT += network \
webkit
QLabel *m_clockLabel = new QLabel;
QLabel *m_envelopeLabel = new QLabel;
QLabel *m_compassLabel = new QLabel;
- QToolButton *sendLocationButton = new QToolButton;
+ QToolButton *updateFriendsButton = new QToolButton;
QToolButton *updateStatusMessageButton = new QToolButton;
- sendLocationButton->setIcon(QIcon(QPixmap(":/resources/reload_icon.png")));
+ updateFriendsButton->setIcon(QIcon(QPixmap(":/resources/reload_icon.png")));
updateStatusMessageButton->setIcon(QIcon(QPixmap(":/resources/sendPosition_icon.png")));
m_clockLabel->setPixmap(QPixmap(":/resources/clock_small.png"));
m_layout->addWidget(m_timeLabel,1,2,1,1);
m_layout->addWidget(m_messageLabel,2,2,1,1);
m_layout->addWidget(m_addressLabel,3,2,1,1);
- m_layout->addWidget(sendLocationButton,0,3,2,1);
+ m_layout->addWidget(updateFriendsButton,0,3,2,1);
m_layout->addWidget(updateStatusMessageButton,1,3,2,1);
+ connect(updateStatusMessageButton,SIGNAL(clicked()),this,SLOT(messageUpdate()));
+ connect(updateFriendsButton,SIGNAL(clicked()),this,SLOT(updateFriendsStatus()));
}
InfoTab::~InfoTab()
m_time = tim;
m_timeLabel->setText(m_time);
}
+
+void InfoTab::messageUpdate()
+{
+ emit launchMessageUpdate();
+ qDebug() << __PRETTY_FUNCTION__;
+}
+
+void InfoTab::updateFriendsStatus()
+{
+ emit launchUpdateFriendsStatus();
+ qDebug() << __PRETTY_FUNCTION__;
+}
* @param usernam Reference to user name
*/
void setUserName(const QString &usernam);
+private slots:
+ /**
+ * @brief Slot function to forward messageUpdate launch signal
+ *
+ */
+ void messageUpdate();
+ /**
+ * @brief Slot function to forward friends status update signal
+ *
+ */
+ void updateFriendsStatus();
+signals:
+ /**
+ * @brief Signal to launch manual message update dialog
+ *
+ */
+ void launchMessageUpdate();
+ /**
+ * @brief Signal to refresh friends statuses
+ * @todo: Connect to friends lists when ready
+ */
+ void launchUpdateFriendsStatus();
private:
QLabel *m_userPicture; ///< Shows the user's avatar
QLabel *m_userNameLabel; ///< Shows the user's name
#include <QGraphicsProxyWidget>
#include <QStateMachine>
#include "listviewscreen.h"
-#include "pixmap.h"
-#include "infotab.h"
#include <QDebug>
ListViewScreen::ListViewScreen(QWidget *parent)
: QWidget(parent)
{
+
m_arrowbutton = new Pixmap(QPixmap(":/resources/arrow_right.png"));
m_personalInfo = new InfoTab;
m_personalInfo->setTime("1 hour ago");
m_personalInfo->setAddress("Kiviharjunlenkki 1E, 91910 Oulu");
+ m_locationDialog = new UpdateLocationDialog(this);
m_widgetProxy = new QGraphicsProxyWidget();
m_widgetProxy->setWidget(m_personalInfo);
m_vbox = new QVBoxLayout(this);
m_vbox->addWidget(view);
m_vbox->setMargin(0);
+
+ connect(m_personalInfo,SIGNAL(launchMessageUpdate()),this,SLOT(updateMessage()));
}
ListViewScreen::~ListViewScreen()
if (m_vbox)
delete m_vbox;
}
+
+void ListViewScreen::updateMessage()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ m_locationDialog->exec();
+}
#include <QtGui>
#include "infotab.h"
#include "pixmap.h"
+#include "updatelocation/updatelocationdialog.h"
/**
* @brief List View class. Used for displaying List of friends
*/
class ListViewScreen : public QWidget
{
+Q_OBJECT
public:
/**
* @brief Constructor
*
*/
~ListViewScreen();
+public slots:
+ void updateMessage();
private:
QVBoxLayout *m_vbox; ///< Holds the graphics view
InfoTab *m_personalInfo; ///< Personal info tab
QPropertyAnimation *m_anim2; ///< Animation for arrowbutton from hidden to visible
QPropertyAnimation *m_anim3; ///< Animation for infotab from visible to hidden
QPropertyAnimation *m_anim4; ///< Animation for arrowbutton from visible to hidden
+ UpdateLocationDialog *m_locationDialog; ///< Message dialog
};
#endif // LISTVIEWTAB_H
#include "mainwindow.h"
#include "listviewscreen.h"
#include "mapviewscreen.h"
+#include "facebookservice/facebookauthentication.h"
+#include "situareservice/situareservice.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
qDebug() << __PRETTY_FUNCTION__;
+ m_loggedIn = false;
createViews();
- setCentralWidget(situareViews);
+ setCentralWidget(m_situareViews);
createMenus();
- setWindowTitle(tr("View"));
+ setWindowTitle(tr("List view"));
+ this->hide();
+
+ FBAuth = new FacebookAuthentication(this);
+ FBAuth->show();
+ FBAuth->start();
+
+ m_networkManager = new QNetworkAccessManager;
+ m_situareService = new SituareService(this,m_networkManager);
+
+ connect(FBAuth, SIGNAL(credentialsReady()), this, SLOT(loginOK()));
+ connect(FBAuth, SIGNAL(userExit()), this, SLOT(loginScreenClosed()));
}
MainWindow::~MainWindow()
{
qDebug() << __PRETTY_FUNCTION__;
- delete toListViewAct;
- delete toMapViewAct;
- delete situareViews;
+ delete m_toListViewAct;
+ delete m_toMapViewAct;
+ delete m_situareViews;
}
void MainWindow::createMenus()
{
qDebug() << __PRETTY_FUNCTION__;
- toListViewAct = new QAction(tr("List"), this);
- connect(toListViewAct, SIGNAL(triggered()), this, SLOT(toListView()));
- toMapViewAct = new QAction(tr("Map"), this);
- connect(toMapViewAct, SIGNAL(triggered()), this, SLOT(toMapView()));
- viewMenu = menuBar()->addMenu(tr("View"));
- viewMenu->addAction(toListViewAct);
- viewMenu->addAction(toMapViewAct);
+ m_toListViewAct = new QAction(tr("List"), this);
+ m_toListViewAct->setObjectName(tr("List"));
+ connect(m_toListViewAct, SIGNAL(triggered()), this, SLOT(toListView()));
+ m_toMapViewAct = new QAction(tr("Map"), this);
+ m_toMapViewAct->setObjectName(tr("Map"));
+ connect(m_toMapViewAct, SIGNAL(triggered()), this, SLOT(toMapView()));
+ m_viewMenu = menuBar()->addMenu(tr("View"));
+ m_viewMenu->addAction(m_toListViewAct);
+ m_viewMenu->addAction(m_toMapViewAct);
+ m_viewMenu->setObjectName(tr("View Menu"));
}
void MainWindow::createViews()
{
qDebug() << __PRETTY_FUNCTION__;
- situareViews = new QStackedWidget;
- situareViews->addWidget(new ListViewScreen);
- situareViews->addWidget(new MapViewScreen);
+ m_situareViews = new QStackedWidget;
+ m_situareViews->addWidget(new ListViewScreen);
+ m_situareViews->addWidget(new MapViewScreen);
}
void MainWindow::toListView()
{
qDebug() << __PRETTY_FUNCTION__ << ":" << nextIndex;
if (nextIndex < 0 || nextIndex > 1) {
- qDebug() << tr("Illegal parameter value in MainWindow::switchView");
+ qDebug() << "Illegal parameter value in MainWindow::switchView";
return;
}
- situareViews->setCurrentIndex(nextIndex);
- switch (situareViews->currentIndex()) {
+ m_situareViews->setCurrentIndex(nextIndex);
+ switch (m_situareViews->currentIndex()) {
case 0:
- setWindowTitle(tr("List"));
+ setWindowTitle(tr("List view"));
break;
case 1:
- setWindowTitle(tr("Map"));
+ setWindowTitle(tr("Map view"));
break;
default:
- qDebug() << tr("Illegal switch value in MainWindow::switchView");
+ qDebug() << "Illegal switch value in MainWindow::switchView";
break;
}
}
-int MainWindow::getViewIndex()
+void MainWindow::loginScreenClosed()
+{
+ qDebug() << __PRETTY_FUNCTION__ << m_loggedIn;
+ if (m_loggedIn) {
+ this->show();
+ return;
+ }
+ else {
+ this->close();
+ }
+}
+
+void MainWindow::loginOK()
{
- return situareViews->currentIndex();
+ qDebug() << __PRETTY_FUNCTION__ << m_loggedIn;
+ m_loggedIn = true;
+ FBAuth->close();
}
#include <QtGui/QMainWindow>
#include <QWidget>
#include <QDebug>
+#include "facebookservice/facebookauthentication.h"
+#include "situareservice/situareservice.h"
+#include <QNetworkAccessManager>
class QLabel;
class QStackedWidget;
/**
-* @Main Window Class
+* @brief Main Window Class
*
* @class MainWindow mainwindow.h "src/ui/mainwindow.h"
*/
Q_OBJECT
public:
- MainWindow(QWidget *parent = 0);
- ~MainWindow();
-
/**
- * @brief Public method to get current index of the view. Used for Unit testing
+ * @brief Constructor
*
- * @fn getViewIndex
+ * @param parent Parent
*/
- int getViewIndex();
+ MainWindow(QWidget *parent = 0);
-private:
/**
- * @brief Private method to create List and Map views as a stacked widget
- *
- * @fn createViews
+ * @brief Destructor
*/
- void createViews();
+ ~MainWindow();
+
+public slots:
/**
- * @brief Widget Stack object for the List and Map Views
- *
- * @var situareViews
+ * @brief Public slot, which initiates toListViewAct action to switch view
*/
- QStackedWidget *situareViews;
+ void toListView();
/**
- * @brief Private method to create the Menu items
- *
- * @fn createMenus
+ * @brief Public slot, which initiates toMapViewAct action to switch view
*/
- void createMenus();
- QMenu *viewMenu;
+ void toMapView();
+private:
/**
- * @brief Action item for changing view to List View
- *
- * @var toListViewAct
+ * @brief Private method to create the Menu items w.show();
*/
- QAction *toListViewAct;
+ void createMenus();
+
/**
- * @brief Action item for changing view to Map View
- *
- * @var toMapViewAct
+ * @brief Private method to create List and Map views as a stacked widget
*/
- QAction *toMapViewAct;
+ void createViews();
/**
* @brief Method used to switch active view.
*
- * @fn switchView
- * @param int 0 for listview, 1 for mapview
+ * @param nextIndex 0 for listview, 1 for mapview
*/
void switchView(int);
-public slots:
+private:
+ FacebookAuthentication *FBAuth;
+ QNetworkAccessManager *m_networkManager;
+ SituareService *m_situareService;
+ bool m_loggedIn; ///< Boolean value to indicate whether login has been successfull or not
+ QStackedWidget *m_situareViews; ///< Stacked widget that hold both view widgets
+ QAction *m_toListViewAct; ///< Action to trigger switch to list view
+ QAction *m_toMapViewAct; ///< Action to trigger switch to map view
+ QMenu *m_viewMenu; ///< Object that hold the view menu items
+
+private slots:
/**
- * @brief Public slot, which initiates toListViewAct action to switch view
- *
- * @fn toListView
+ * @brief Slot to change value of m_loggedIn to true
*/
- void toListView();
+ void loginOK();
+
/**
- * @brief Public slot, which initiates toMapViewAct action to switch view
- *
- * @fn toMapView
+ * @brief Slot to check login status and exits if necessary
*/
- void toMapView();
+ void loginScreenClosed();
};
#endif // MAINWINDOW_H
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Katri Kaikkonen - katri.kaikkonen@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 <QtGui>
+#include "texteditautoresizer.h"
+
+TextEditAutoResizer::TextEditAutoResizer(QWidget *parent)
+ : QObject(parent)
+ , m_edit(qobject_cast<QFrame *>(parent))
+ , m_plainTextEdit(qobject_cast<QPlainTextEdit *>(parent))
+ , m_textEdit(qobject_cast<QTextEdit *>(parent))
+ {
+ //parent must either inherit QPlainTextEdit or QTextEdit!
+ Q_ASSERT(m_plainTextEdit || m_textEdit);
+
+ connect(parent, SIGNAL(textChanged()), this, SLOT(textEditChanged()));
+ connect(parent, SIGNAL(cursorPositionChanged()), this, SLOT(textEditChanged()));
+ }
+
+void TextEditAutoResizer::textEditChanged()
+{
+ QTextDocument *document = m_textEdit ? m_textEdit->document() : m_plainTextEdit->document();
+ QRect cursor = m_textEdit ? m_textEdit->cursorRect() : m_plainTextEdit->cursorRect();
+
+ QSize size = document->size().toSize();
+ if (m_plainTextEdit)
+ size.setHeight((size.height() + 1) * m_edit->fontMetrics().lineSpacing());
+
+ const QRect frameRect = m_edit->frameRect();
+ const QRect contentsRect = m_edit->contentsRect();
+
+ m_edit->setMinimumHeight(qMax(70, size.height() + (frameRect.height()
+ - contentsRect.height() - 1)));
+
+ // make sure the cursor is visible in case we have a QAbstractScrollArea parent
+ QPoint position = m_edit->pos();
+ QWidget *parentWidget = m_edit->parentWidget();
+ while (parentWidget) {
+ #ifdef Q_WS_MAEMO_5
+ if (parentWidget->parentWidget()) {
+ if (QAbstractScrollArea *area = qobject_cast<QAbstractScrollArea *>(
+ parentWidget->parentWidget()->parentWidget())) {
+ if (QAbstractKineticScroller * scroller=
+ area->property("kineticScroller").value<QAbstractKineticScroller *>()) {
+ scroller->ensureVisible(position + cursor.center(), 10 + cursor.width(),
+ 2 * cursor.height());
+ }
+ break;
+ }
+ }
+ #endif
+ position = parentWidget->mapToParent(position);
+ parentWidget = parentWidget->parentWidget();
+ }
+}
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Katri Kaikkonen - katri.kaikkonen@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 TEXTEDITAUTORESIZER_H
+#define TEXTEDITAUTORESIZER_H
+
+#include <QtGui>
+#ifdef Q_WS_MAEMO_5
+#include <QAbstractKineticScroller>
+#endif // Q_WS_MAEMO_5
+
+/**
+* @brief TextEditAutoResizer class
+*
+* @class TextEditAutoResizer class is used to automatically resize the QTextEdit once the contents
+* become too large.
+*/
+class TextEditAutoResizer : public QObject
+{
+Q_OBJECT
+
+public:
+ /**
+ * @brief Default constructor
+ *
+ * @param parent
+ */
+ TextEditAutoResizer(QWidget *parent = 0);
+
+private slots:
+ /**
+ * @brief Private slot which indicate when textEdit has been changed
+ *
+ * @fn textEditChanged
+ */
+ void textEditChanged();
+
+private:
+ QFrame *m_edit; ///< Pointer to Frame
+ QPlainTextEdit *m_plainTextEdit; ///< Pointer to PlainTextEdit
+ QTextEdit *m_textEdit; ///< Pointer to TextEdit
+};
+
+#endif // TEXTEDITAUTORESIZER_H
+
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Katri Kaikkonen - katri.kaikkonen@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 <QtGui>
+#include <QDebug>
+#include "updatelocationdialog.h"
+
+UpdateLocationDialog::UpdateLocationDialog(QWidget *parent)
+ : QDialog(parent)
+{
+ setWindowTitle(tr("Update Location"));
+
+ QScrollArea *scrollArea = new QScrollArea(this);
+ QGridLayout *gridLayout = new QGridLayout(this);
+ QGroupBox *groupBox = new QGroupBox(scrollArea);
+
+ QTextEdit *m_textEdit = new QTextEdit;
+ QLineEdit *m_lineEdit = new QLineEdit;
+ QCheckBox *m_checkBox = new QCheckBox(tr("Publish in Fabebook"));
+
+ QPushButton *m_okButton = new QPushButton(tr("Send"));
+ QDialogButtonBox *m_buttonBox = new QDialogButtonBox(Qt::Vertical);
+ m_buttonBox->addButton(m_okButton, QDialogButtonBox::ActionRole);
+
+ QFormLayout *form = new QFormLayout();
+ form->addRow(new QLabel(tr("Location:")), m_lineEdit);
+ form->addRow(new QLabel(tr("Message:")), m_textEdit);
+ form->addWidget(m_checkBox);
+
+ new TextEditAutoResizer(m_textEdit);
+
+ groupBox->setLayout(form);
+ scrollArea->setWidget(groupBox);
+ scrollArea->setWidgetResizable(true);
+ gridLayout->addWidget(scrollArea, 0, 0, 2, 1);
+ gridLayout->addWidget(m_buttonBox, 0, 1, 1, 1);
+ setLayout(gridLayout);
+
+ scrollArea->show();
+}
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Katri Kaikkonen - katri.kaikkonen@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 UPDATELOCATIONDIALOG_H
+#define UPDATELOCATIONDIALOG_H
+
+#include <QDialog>
+#include <QtGui>
+#ifdef Q_WS_MAEMO_5
+#include <QAbstractKineticScroller>
+#endif // Q_WS_MAEMO_5
+#include "texteditautoresizer.h"
+
+class QCheckBox;
+class QDialogButtonBox;
+class QGroupBox;
+class QLabel;
+class QLineEdit;
+class QTextEdit;
+class QPushButton;
+class QScrollArea;
+
+/**
+* @brief Update Location UI
+*
+* @class UI for update location functionality.
+*/
+class UpdateLocationDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ /**
+ * @brief Default constructor
+ *
+ * @param parent
+ */
+ UpdateLocationDialog(QWidget *parent = 0);
+
+private slots:
+
+private:
+ QDialogButtonBox *m_buttonBox; ///< Pointer to DialogButtonBox
+ QCheckBox *m_checkBox; ///< Pointer to CheckBox
+ QLineEdit *m_lineEdit; ///< Pointer to LineEdit
+ QPushButton *m_okButton; ///< Pointer to PushButton
+ QTextEdit *m_textEdit; ///< Pointer to TextEdit
+};
+
+#endif // UPDATELOCATIONDIALOG_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 <QtTest/QtTest>
+#include <QtCore>
+
+
+#include "../../src/cookiehandler/cookiehandler.h"
+#include "../../src/situareservice/situarecommon.h"
+
+
+class testCookieHandler : public QObject
+{
+ Q_OBJECT
+private:
+ CookieHandler *cookieHandler;
+
+private slots:
+
+ void testFormCookie();
+
+};
+
+void testCookieHandler::testFormCookie()
+{
+ const QString apiKey = "1";
+ const QString expires = "2";
+ const QString sessionKey = "3";
+ const QString user = "4";
+ const QString sessionSecret = "5";
+ const QString signature = "6";
+ const QString locale = "7";
+
+ QString cookie = cookieHandler->formCookie(apiKey, expires, user, sessionKey, sessionSecret, signature, locale);
+
+ QCOMPARE(QString(";1_expires=2;1_session_key=3;1_user=4;1_ss=5;1=6;locale=7"), cookie);
+}
+
+QTEST_MAIN(testCookieHandler)
+#include "testcookiehandler.moc"
--- /dev/null
+######################################################################
+# Automatically generated by qmake (2.01a) Fri Apr 9 13:34:34 2010
+######################################################################
+
+CONFIG += qtestlib
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+HEADERS += ../../src/cookiehandler/cookiehandler.h \
+ ../../src/situareservice/situarecommon.h
+SOURCES += testcookiehandler.cpp \
+ ../../src/cookiehandler/cookiehandler.cpp
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Henri Lampela - henri.lampela@ixonos.com
+ Jussi Laitinen - jussi.laitinen@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 <QBuffer>
+#include "networkaccessmanagermock.h"
+
+NetworkAccessManagerMock::NetworkAccessManagerMock(QNetworkAccessManager *manager, QObject *parent)
+ : QNetworkAccessManager(parent)
+ , mode(0)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+}
+
+NetworkReplyMock *NetworkAccessManagerMock::createRequest(Operation op, const QNetworkRequest &request,
+ QIODevice *outgoingData)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ reply = new NetworkReplyMock(this);
+ this->request = request;
+
+ switch (this->mode) {
+
+ case NetworkAccessManagerMock::CORRECT:
+ QTimer::singleShot(0, this, SLOT(generateCorrectReply()));
+ break;
+ case NetworkAccessManagerMock::INCORRECT:
+ QTimer::singleShot(0, this, SLOT(generateError()));
+ break;
+ case NetworkAccessManagerMock::DELAYED_CORRECT:
+ QTimer::singleShot(0, this, SLOT(generateDelayedCorrectReply()));
+ break;
+ default:
+ QTimer::singleShot(0, this, SLOT(generateCorrectReply()));
+ break;
+ }
+ return reply;
+}
+
+NetworkAccessManagerMock::~NetworkAccessManagerMock()
+{
+ delete reply;
+}
+
+NetworkReplyMock *NetworkAccessManagerMock::get(const QNetworkRequest &request)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ this->request = request;
+
+ return reply;
+}
+
+void NetworkAccessManagerMock::setMode(int mode)
+{
+ this->mode = mode;
+}
+
+void NetworkAccessManagerMock::generateError()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ reply->setUrl(request.url());
+ reply->setError(QNetworkReply::HostNotFoundError, "Host not found");
+ emit QNetworkAccessManager::finished(reply);
+}
+
+void NetworkAccessManagerMock::generateCorrectReply()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ reply->setUrl(request.url());
+ reply->setError(QNetworkReply::NoError, "No error");
+// QImage image;
+// if (!image.load(":testTile.png", 0)) {
+// qDebug() << "could not load image";
+// image = QImage();
+// }
+// else
+// qDebug() << "image loaded";
+//
+// QByteArray array;
+// QBuffer buffer(&array);
+// buffer.open(QBuffer::WriteOnly);
+// if (image.save(&buffer, "PNG"))
+// qDebug() << "image saved";
+// buffer.close();
+// reply->setData(array);
+ emit QNetworkAccessManager::finished(reply);
+}
+
+void NetworkAccessManagerMock::generateDelayedCorrectReply()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QTimer::singleShot(4000, this, SLOT(generateCorrectReply()));
+}
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Henri Lampela - henri.lampela@ixonos.com
+ Jussi Laitinen - jussi.laitinen@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 NETWORKACCESSMANAGERMOCK_H
+#define NETWORKACCESSMANAGERMOCK_H
+
+#include <QNetworkAccessManager>
+#include <QNetworkRequest>
+#include <QTimer>
+#include "networkreplymock.h"
+
+
+class NetworkAccessManagerMock : public QNetworkAccessManager
+{
+ Q_OBJECT
+public:
+ NetworkAccessManagerMock(QNetworkAccessManager *manager = 0, QObject *parent = 0);
+
+ ~NetworkAccessManagerMock();
+
+ NetworkReplyMock *get(const QNetworkRequest &request);
+
+ void setMode(int mode);
+
+
+ enum {CORRECT, INCORRECT, DELAYED_CORRECT};
+
+protected:
+ NetworkReplyMock *createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData);
+
+signals:
+ void finished(NetworkReplyMock *reply);
+
+ private slots:
+ void generateError();
+ void generateCorrectReply();
+ void generateDelayedCorrectReply();
+
+private:
+ NetworkReplyMock *reply;
+ QNetworkRequest request;
+ int mode;
+};
+
+#endif // NETWORKACCESSMANAGERMOCK_H
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Henri Lampela - henri.lampela@ixonos.com
+ Jussi Laitinen - jussi.laitinen@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 <QNetworkRequest>
+#include <QDebug>
+#include "networkreplymock.h"
+
+NetworkReplyMock::NetworkReplyMock(QObject *parent)
+ : QNetworkReply(parent)
+ , m_offset(0)
+{
+}
+
+void NetworkReplyMock::setError(NetworkError errorCode, const QString &errorString)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QNetworkReply::setError(errorCode, errorString);
+}
+
+
+qint64 NetworkReplyMock::readData(char *data, qint64 maxLen)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ if (m_offset < m_content.size()) {
+ qint64 number = qMin(maxLen, m_content.size() - m_offset);
+ memcpy(data, m_content.constData() + m_offset, number);
+ m_offset += number;
+ return number;
+ }
+ else {
+ return -1;
+ }
+}
+
+QByteArray NetworkReplyMock::readAll()
+{
+ return m_content;
+}
+
+qint64 NetworkReplyMock::bytesAvailable() const
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ return m_content.size() - m_offset;
+}
+
+void NetworkReplyMock::setUrl(const QUrl &url)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ QNetworkReply::setUrl(url);
+}
+
+void NetworkReplyMock::abort()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+}
+
+void NetworkReplyMock::test()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+}
+
+void NetworkReplyMock::setData(const QByteArray &content)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+// setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/png"));
+// setHeader(QNetworkRequest::ContentLengthHeader, QVariant(this->m_content.size()));
+ m_content.append(content);
+ qDebug() << "Content size: " << m_content.size();
+}
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Henri Lampela - henri.lampela@ixonos.com
+ Jussi Laitinen - jussi.laitinen@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 NETWORKREPLYMOCK_H
+#define NETWORKREPLYMOCK_H
+
+#include <QNetworkReply>
+#include <QUrl>
+
+
+class NetworkReplyMock : public QNetworkReply
+{
+ Q_OBJECT
+public:
+ NetworkReplyMock(QObject *parent = 0);
+ void abort();
+ qint64 bytesAvailable() const;
+
+ bool isSequential() const
+ {
+ return true;
+ }
+ void setError(NetworkError errorCode, const QString &errorString);
+ void setData(const QByteArray &content);
+ void setUrl(const QUrl &url);
+ void test();
+ QByteArray readAll();
+
+protected:
+ qint64 readData(char *data, qint64 maxlen);
+
+private:
+ QByteArray m_content;
+ qint64 m_offset;
+};
+
+#endif // NETWORKREPLYMOCK_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 <QtTest/QtTest>
+#include <QtCore>
+#include <QPointF>
+#include <QNetworkAccessManager>
+
+
+#include "../../../src/situareservice/situareservice.h"
+#include "../../../src/situareservice/situarecommon.h"
+#include "networkaccessmanagermock.h"
+#include "networkreplymock.h"
+
+
+class testLocationUpdate : public QObject
+{
+ Q_OBJECT
+public:
+ ~testLocationUpdate();
+private:
+ SituareService *situare;
+ NetworkAccessManagerMock *managerMock;
+ QList<QNetworkReply *> currentRequests;
+ FacebookAuthentication fbAuthentication;
+ FacebookCredentials credentials;
+
+private slots:
+
+ //void testIncorrectUrl();
+ //void testCorrectUrl();
+ void testLocationUpdateCase();
+};
+
+testLocationUpdate::~testLocationUpdate()
+{
+ delete situare;
+ delete managerMock;
+}
+
+
+//void testLocationUpdate::testIncorrectUrl()
+//{
+// QNetworkAccessManager *manager = new QNetworkAccessManager();
+// managerMock = new NetworkAccessManagerMock(manager, this);
+// situare = new SituareService(this, manager);
+//
+// managerMock->setMode(NetworkAccessManagerMock::INCORRECT);
+//
+// QSignalSpy receivedErrorSpy(situare, SIGNAL(error(QString)));
+//
+// QVERIFY(receivedErrorSpy.isValid());
+//
+// // incorrect url
+//
+// situare->sendRequest(QUrl("http://client.situare.nett"), COOKIE, QString(""));
+// QTest::qWait(1000);
+// QCOMPARE(receivedErrorSpy.count(), 1);
+//
+// delete manager;
+//}
+
+//void testLocationUpdate::testCorrectUrl()
+//{
+// QNetworkAccessManager *manager = new QNetworkAccessManager();
+// managerMock = new NetworkAccessManagerMock(manager, this);
+// situare = new SituareService(this, manager);
+//
+// managerMock->setMode(NetworkAccessManagerMock::CORRECT);
+//
+// QSignalSpy receivedErrorSpy(situare, SIGNAL(error(QString)));
+//
+// QVERIFY(receivedErrorSpy.isValid());
+//
+// QUrl url = QUrl("http://client.situare.net");
+//
+// situare->sendRequest(url, COOKIE, QString(""));
+// QTest::qWait(1000);
+//
+// QCOMPARE(receivedErrorSpy.count(), 0);
+//
+// delete manager;
+//}
+
+void testLocationUpdate::testLocationUpdateCase()
+{
+ QNetworkAccessManager *manager = new QNetworkAccessManager();
+ managerMock = new NetworkAccessManagerMock(manager, this);
+ situare = new SituareService(this, manager);
+
+ managerMock->setMode(NetworkAccessManagerMock::CORRECT);
+
+ QSignalSpy receivedErrorSpy(situare, SIGNAL(error(QString)));
+
+ QPointF coordinates(65.3, 25.5);
+ bool publish = true;
+ QString status = "unit-test";
+
+ situare->updateLocation(coordinates, status, publish);
+ QTest::qWait(1000);
+
+ QCOMPARE(receivedErrorSpy.count(), 0);
+
+ delete manager;
+}
+
+
+QTEST_MAIN(testLocationUpdate)
+#include "testlocationupdate.moc"
--- /dev/null
+# #####################################################################
+# Automatically generated by qmake (2.01a) Wed Apr 7 16:44:14 2010
+# #####################################################################
+CONFIG += qtestlib
+TEMPLATE = app
+TARGET =
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+HEADERS += ../../../src/situareservice/situareservice.h \
+ ../../../src/facebookservice/facebookauthentication.h \
+ ../../../src/facebookservice/facebookcredentials.h \
+ ../../../src/cookiehandler/cookiehandler.h \
+ testlocationupdate.moc \
+ networkreplymock.h \
+ networkaccessmanagermock.h
+SOURCES += testlocationupdate.cpp \
+ ../../../src/situareservice/situareservice.cpp \
+ ../../../src/facebookservice/facebookauthentication.cpp \
+ ../../../src/facebookservice/facebookcredentials.cpp \
+ ../../../src/cookiehandler/cookiehandler.cpp \
+ networkreplymock.cpp \
+ networkaccessmanagermock.cpp
+QT += core \
+ network \
+ webkit
--- /dev/null
+/*
+ Situare - A location system for Facebook
+ Copyright (C) 2010 Ixonos Plc. Authors:
+
+ Kaj Wallin - kaj.wallin@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 <QtTest/QtTest>
+#include <QtCore>
+#include <QtGui>
+
+#include "ui/mapviewscreen.h"
+#include "ui/listviewscreen.h"
+#include "ui/mainwindow.h"
+//#include "facebook_service/fbauthentication/fbauthentication.h"
+
+class testMainWindow : public QObject
+{
+ Q_OBJECT
+private slots:
+ void testViewSwitch();
+ void verifyStackItems();
+// void verifyMenuItems(); //NON-WORKING
+};
+
+void testMainWindow::testViewSwitch()
+{
+ MainWindow mainwindow;
+ QStackedWidget *m_testStack = dynamic_cast<QStackedWidget*>(mainwindow.centralWidget());
+ mainwindow.toListView();
+ QCOMPARE(m_testStack->currentIndex(), 0);
+ QCOMPARE(mainwindow.windowTitle(),QString(tr("List view")));
+ mainwindow.toMapView();
+ QCOMPARE(m_testStack->currentIndex(), 1);
+ QCOMPARE(mainwindow.windowTitle(),QString(tr("Map view")));
+ mainwindow.toMapView();
+ QCOMPARE(m_testStack->currentIndex(), 1);
+ QCOMPARE(mainwindow.windowTitle(),QString(tr("Map view")));
+ mainwindow.toListView();
+ QCOMPARE(m_testStack->currentIndex(), 0);
+ QCOMPARE(mainwindow.windowTitle(),QString(tr("List view")));
+}
+void testMainWindow::verifyStackItems()
+{
+ MainWindow mainwindow;
+ QStackedWidget *m_testStack = dynamic_cast<QStackedWidget*>(mainwindow.centralWidget());
+ QCOMPARE(m_testStack->count(), 2);
+ QCOMPARE(m_testStack->widget(0)->objectName(),QString(tr("List view")));
+ QCOMPARE(m_testStack->widget(1)->objectName(),QString(tr("Map view")));
+}
+
+/* NON-WORKING TEST
+void testMainWindow::verifyMenuItems()
+{
+ MainWindow mainwindow;
+ QWidget *m_testMenu = mainwindow.menuWidget();
+ qDebug() << m_testMenu->actions();
+}
+*/
+
+QTEST_MAIN(testMainWindow)
+#include "mainwindow_test.moc"
--- /dev/null
+CONFIG += qtestlib
+TEMPLATE = app
+TARGET = mainwindow_test
+DEPENDPATH += .
+INCLUDEPATH += . \
+ ../../../src/
+SOURCES += mainwindow_test.cpp \
+ ../../../src/map/mapview.cpp \
+ ../../../src/map/maptile.cpp \
+ ../../../src/map/mapscene.cpp \
+ ../../../src/map/mapfetcher.cpp \
+ ../../../src/map/mapengine.cpp \
+ ../../../src/ui/mapviewscreen.cpp \
+ ../../../src/ui/mainwindow.cpp \
+ ../../../src/ui/listviewscreen.cpp
+HEADERS += ../../../src/map/mapview.h \
+ ../../../src/map/maptile.h \
+ ../../../src/map/mapscene.h \
+ ../../../src/map/mapfetcher.h \
+ ../../../src/map/mapengine.h \
+ ../../../src/ui/mapviewscreen.h \
+ ../../../src/ui/mainwindow.h \
+ ../../../src/ui/listviewscreen.h
+
+QT += webkit \
+ network