qDebug() << __PRETTY_FUNCTION__;
}
-QString CookieHandler::formCookie(QString apiKeyValue, QString expiresValue, QString userValue, QString sessionKeyValue, QString sessionSecretValue, QString signatureValue, QString localeValue)
+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, apiKey, user, expires, sessionKey, sessionSecret, locale, variable;
+ QString cookie;
+ QString apiKey;
+ QString user;
+ QString expires;
+ QString sessionKey;
+ QString sessionSecret;
+ QString locale;
+ QString variable;
QString signature = EQUAL_MARK;
QStringList variableList;
#include "../situareservice/situarecommon.h"
/**
-* @brief
+* @brief Class for cookie cretion.
*
* @author Henri Lampela
* @class CookieHandler cookiehandler.h "cookiehandler/cookiehandler.h"
* @param localeValue used locale
* @return QString formed cookie
*/
- QString formCookie(QString apiKeyValue, QString expiresValue, QString userValue, QString sessionKeyValue, QString sessionSecretValue, QString signatureValue, QString localeValue);
+ QString formCookie(const QString &apiKeyValue, QString expiresValue, QString userValue,
+ QString sessionKeyValue, QString sessionSecretValue,
+ const QString &signatureValue, const QString &localeValue);
};
#include "../cookiehandler/cookiehandler.h"
SituareService::SituareService(QObject *parent, QNetworkAccessManager *manager)
- : QObject(parent), networkManager(manager)
+ : QObject(parent), m_networkManager(manager)
{
qDebug() << __PRETTY_FUNCTION__;
- connect(&facebookAuthentication, SIGNAL(credentialsReady()), SLOT(credentialsReady()));
+ connect(&m_facebookAuthentication, SIGNAL(credentialsReady()), SLOT(credentialsReady()));
- connect(networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(requestFinished(QNetworkReply*)));
+ connect(m_networkManager, SIGNAL(finished(QNetworkReply*)), SLOT(requestFinished(QNetworkReply*)));
- credentials = facebookAuthentication.loginCredentials();
+ m_credentials = m_facebookAuthentication.loginCredentials();
}
SituareService::~SituareService()
{
qDebug() << __PRETTY_FUNCTION__;
- delete networkManager;
+ delete m_networkManager;
}
-void SituareService::updateLocation(QPointF coordinates, QString status, bool publish)
+void SituareService::updateLocation(const QPointF &coordinates, const QString &status,
+ const bool &publish)
{
qDebug() << __PRETTY_FUNCTION__;
CookieHandler cookieHandler;
- QString cookie = cookieHandler.formCookie(API_KEY, credentials.expires(), credentials.userID(), credentials.sessionKey(),
- credentials.sessionSecret(), credentials.sig(), EN_LOCALE);
+ 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;
sendRequest(url, COOKIE, cookie);
}
-void SituareService::reverseGeo(QPointF coordinates)
+void SituareService::reverseGeo(const QPointF &coordinates)
{
qDebug() << __PRETTY_FUNCTION__;
CookieHandler cookieHandler;
- QString cookie = cookieHandler.formCookie(API_KEY, credentials.expires(), credentials.userID(), credentials.sessionKey(),
- credentials.sessionSecret(), credentials.sig(), EN_LOCALE);
+ 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)
+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) // ToDo: check this better
+ if(urlParameters != NULL)
urlString.append(urlParameters);
QUrl url = QUrl(urlString);
return url;
}
-QString SituareService::formUrlParameters(QPointF coordinates, QString status, QString publish)
+QString SituareService::formUrlParameters(const QPointF &coordinates, QString status, QString publish)
{
QString parameters;
return parameters;
}
-void SituareService::sendRequest(QUrl url, const QString cookieType, QString cookie)
+void SituareService::sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie)
{
qDebug() << __PRETTY_FUNCTION__ << "url: " << url;
request.setUrl(url);
request.setRawHeader(cookieType.toAscii(), cookie.toUtf8());
- QNetworkReply *reply = networkManager->get(request);
+ QNetworkReply *reply = m_networkManager->get(request);
- currentRequests.append(reply);
+ m_currentRequests.append(reply);
}
void SituareService::requestFinished(QNetworkReply *reply)
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
+ // 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?
}
}
- currentRequests.removeAll(reply);
+ m_currentRequests.removeAll(reply);
reply->deleteLater();
}
void SituareService::credentialsReady()
{
qDebug() << __PRETTY_FUNCTION__;
- credentials = facebookAuthentication.loginCredentials();
+ m_credentials = m_facebookAuthentication.loginCredentials();
}
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QUrl>
-
-#include "../facebookservice/facebookauthentication.h" // not final
-#include "../facebookservice/facebookcredentials.h" // not final
+#include "../facebookservice/facebookauthentication.h"
+#include "../facebookservice/facebookcredentials.h"
/**
* @brief SituareService class for communicating with Situare server
* @param status message
* @param publish publish location on Facebook wall (true/false)
*/
- void updateLocation(QPointF coordinates, QString status, bool publish);
+ 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(QPointF coordinates);
+ 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:
* @param urlParameters optional parameters for url
* @return QUrl formed url
*/
- QUrl formUrl(const QString baseUrl, const QString phpScript, QString urlParameters = 0);
+ QUrl formUrl(const QString &baseUrl, const QString &phpScript, QString urlParameters = 0);
/**
* @brief Forms url parameters
* @param publish optional publish location on Facebook wall (true/false)
* @return QString
*/
- QString formUrlParameters(QPointF coordinates, QString status = 0, QString publish = 0);
+ QString formUrlParameters(const QPointF &coordinates, QString status = 0, QString publish = 0);
/**
* @brief Sends http request
* @param cookieType type of the cookie
* @param cookie http cookie
*/
- void sendRequest(QUrl url, const QString cookieType, QString cookie);
+ void sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie);
signals:
*/
void error(const QString &error);
-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:
- FacebookCredentials credentials; ///< FacebookCredentials
- QList<QNetworkReply *> currentRequests; ///< List of current http requests
- FacebookAuthentication facebookAuthentication; ///< Pointer to FacebookAuthentication
- QNetworkAccessManager *networkManager; ///< Pointer to QNetworkAccessManager
+ 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
+++ /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 "../../../src/situareservice/situareservice.h"
-#include "../../../src/situareservice/situarecommon.h"
-
-
-class testStringFormations : public QObject
-{
- Q_OBJECT
-private:
- SituareService *situare;
-
-private slots:
-
- void testWithNoPublishNoStatus(); // part 1 of testFormUrlParameters
- void testWithStatusNoPublish(); // part 2 of testFormUrlParameters
- void testWithPublishTrueNoStatus(); // part 3 of testFormUrlParameters
- void testWithStatusPublishTrue(); // part 4 of testFormUrlParameters
- void testWithStatusPublishFalse(); // part 5 of testFormUrlParameters
- void testWithPublishFalseNoStatus(); // part 6 of testFormUrlParameters
-
- void testFormUpdateLocationUrl(); // updateLocation url test
- void testFormReverseGeoUrl(); // reverseGeo url test
-
-};
-
-void testStringFormations::testWithNoPublishNoStatus()
-{
- QPointF coordinates(65.3, 25.5);
- QString publish = "";
- QString status = "";
- QString params = situare->formUrlParameters(coordinates, status, publish);
-
- QCOMPARE(QString("?lat=65.3&lon=25.5"), params);
-}
-
-void testStringFormations::testWithStatusNoPublish()
-{
- QPointF coordinates(65.3, 25.5);
- QString publish = "";
- QString status = "testing";
- QString params = situare->formUrlParameters(coordinates, status, publish);
-
- QCOMPARE(QString("?lat=65.3&lon=25.5&data=testing"), params);
-}
-
-void testStringFormations::testWithPublishTrueNoStatus()
-{
- QPointF coordinates(65.3, 25.5);
- QString publish = "true";
- QString status = "";
- QString params = situare->formUrlParameters(coordinates, status, publish);
-
- QCOMPARE(QString("?lat=65.3&lon=25.5&publish=true"), params);
-}
-
-void testStringFormations::testWithStatusPublishTrue()
-{
- QPointF coordinates(65.3, 25.5);
- QString publish = "true";
- QString status = "testing";
- QString params = situare->formUrlParameters(coordinates, status, publish);
-
- QCOMPARE(QString("?lat=65.3&lon=25.5&publish=true&data=testing"), params);
-}
-
-void testStringFormations::testWithStatusPublishFalse()
-{
- QPointF coordinates(65.3, 25.5);
- QString publish = "false";
- QString status = "testing";
- QString params = situare->formUrlParameters(coordinates, status, publish);
-
- QCOMPARE(QString("?lat=65.3&lon=25.5&publish=false&data=testing"), params);
-}
-
-void testStringFormations::testWithPublishFalseNoStatus()
-{
- QPointF coordinates(65.3, 25.5);
- QString publish = "false";
- QString status = "";
- QString params = situare->formUrlParameters(coordinates, status, publish);
-
- QCOMPARE(QString("?lat=65.3&lon=25.5&publish=false"), params);
-}
-
-void testStringFormations::testFormUpdateLocationUrl()
-{
- QString urlParameters = "?lat=65.3&lon=25.5&publish=false";
- QUrl url = situare->formUrl(SITUARE_URL, UPDATE_LOCATION, urlParameters);
-
- QCOMPARE(QString("http://client.situare.net/updateLocation.php?lat=65.3&lon=25.5&publish=false"), url.toString());
-}
-
-void testStringFormations::testFormReverseGeoUrl()
-{
- QPointF coordinates(65.3, 25.5);
-
- QString params = situare->formUrlParameters(coordinates);
-
- QUrl url = situare->formUrl(SITUARE_URL, REVERSE_GEO, params);
-
- QCOMPARE(QString("http://client.situare.net/reversegeo.php?lat=65.3&lon=25.5"), url.toString());
-}
-
-
-QTEST_MAIN(testStringFormations)
-#include "teststringformations.moc"
+++ /dev/null
-# #####################################################################
-# Automatically generated by qmake (2.01a) Thu Apr 8 14:56:57 2010
-# #####################################################################
-CONFIG += qtestlib
-TEMPLATE = app
-TARGET =
-DEPENDPATH += .
-INCLUDEPATH += .
-
-# Input
-HEADERS += ../../../src/situareservice/situareservice.h \
- ../../../src/cookiehandler/cookiehandler.h \
- ../../../src/facebookservice/facebookauthentication.h \
- ../../../src/facebookservice/facebookcredentials.h
-
-SOURCES += teststringformations.cpp \
- ../../../src/situareservice/situareservice.cpp \
- ../../../src/cookiehandler/cookiehandler.cpp \
- ../../../src/facebookservice/facebookauthentication.cpp \
- ../../../src/facebookservice/facebookcredentials.cpp
-QT = core \
- gui \
- network \
- webkit