SituareEngine::SituareEngine(QMainWindow *parent)
: QObject(parent),
- m_autoCenteringEnabled(false)
+ m_autoCenteringEnabled(false),
+ m_loggedIn(false)
{
qDebug() << __PRETTY_FUNCTION__;
m_ui = new MainWindow;
m_ui->setUsername(m_facebookAuthenticator->loadUsername());
}
-void SituareEngine::loginOk(bool freshLogin)
+void SituareEngine::loginOk(bool freshLogin, const FacebookCredentials &credentials)
{
qDebug() << __PRETTY_FUNCTION__;
+ m_loggedIn = true;
+ m_ui->loggedIn(m_loggedIn);
+
if(freshLogin) {
m_facebookAuthenticator->saveUsername(m_ui->username());
}
m_ui->show();
+ m_situareService->credentialsReady(credentials);
m_situareService->fetchLocations(); // request user locations
}
+void SituareEngine::loginPressed()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ if(m_loggedIn) {
+ logout();
+ m_situareService->clearUserData();
+ }
+ else {
+ m_facebookAuthenticator->start();
+ }
+}
+
void SituareEngine::loginProcessCancelled()
{
qDebug() << __PRETTY_FUNCTION__;
m_ui->toggleProgressIndicator(false);
- //ToDo: do something
+ m_ui->showPanels(m_loggedIn);
+}
+
+void SituareEngine::logout()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_loggedIn = false;
+ m_ui->loggedIn(m_loggedIn);
+ m_facebookAuthenticator->clearAccountInformation();
}
void SituareEngine::refreshUserData()
{
qDebug() << __PRETTY_FUNCTION__;
- connect(m_facebookAuthenticator, SIGNAL(credentialsReady(bool, FacebookCredentials)),
- m_situareService, SLOT(credentialsReady(bool, FacebookCredentials)));
+ connect(m_facebookAuthenticator, SIGNAL(credentialsChanged(FacebookCredentials)),
+ m_situareService, SLOT(credentialsReady(FacebookCredentials)));
connect(m_facebookAuthenticator, SIGNAL(credentialsReady(bool, FacebookCredentials)),
- this, SLOT(loginOk(bool)));
+ this, SLOT(loginOk(bool, FacebookCredentials)));
connect(m_facebookAuthenticator, SIGNAL(newLoginRequest(QUrl)),
m_ui, SLOT(startLoginProcess(QUrl)));
{
qDebug() << __PRETTY_FUNCTION__;
+ connect(m_ui, SIGNAL(loginPressed()),
+ this, SLOT(loginPressed()));
+
connect(m_ui, SIGNAL(updateCredentials(QUrl)),
m_facebookAuthenticator, SLOT(updateCredentials(QUrl)));
{
qDebug() << __PRETTY_FUNCTION__;
+ connect(m_situareService, SIGNAL(error(QString)),
+ this, SLOT(error(QString)));
+
+ connect(m_situareService, SIGNAL(invalidSessionCredentials()),
+ m_facebookAuthenticator, SLOT(start()));
+
connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
m_ui, SIGNAL(reverseGeoReady(QString)));
connect(m_situareService, SIGNAL(userDataChanged(User*, QList<User*>&)),
this, SLOT(userDataChanged(User*, QList<User*>&)));
- connect(m_situareService, SIGNAL(error(QString)),
- this, SLOT(error(QString)));
-
connect(m_situareService, SIGNAL(updateWasSuccessful()),
this, SLOT(updateWasSuccessful()));
}
class QMainWindow;
class FacebookAuthentication;
+class FacebookCredentials;
class GPSPosition;
class MainWindow;
class MapEngine;
* @brief Slot to intercept signal from successful login
*
* @param freshLogin Was login done via login dialog
+ * @param credentials Facebook credentials
*/
- void loginOk(bool freshLogin);
+ void loginOk(bool freshLogin, const FacebookCredentials &credentials);
+
+ /**
+ * @brief Slot to intercept signal when Login/Logout action is pressed
+ *
+ */
+ void loginPressed();
/**
* @brief Slot to intercept signal when user has cancelled login process
void loginProcessCancelled();
/**
+ * @brief Changes application state when logged out
+ *
+ */
+ void logout();
+
+ /**
* @brief Calls reverseGeo from SituareService to translate coordinates to street address
*
*/
******************************************************************************/
private:
bool m_autoCenteringEnabled; ///< Auto centering enabled
+ bool m_loggedIn; ///< Login state
FacebookAuthentication *m_facebookAuthenticator; ///< Instance for facebook authenticator
GPSPosition *m_gps; ///< Instance of the gps position
MainWindow *m_ui; ///< Instance of the MainWindow UI
MapEngine *m_mapEngine; ///< MapEngine
SituareService *m_situareService; ///< Instance of the situare server communication service
+
};
#endif // ENGINE_H
emit newLoginRequest(formLoginPageUrl(list));
}
- else
+ else {
emit credentialsReady(false, m_loginCredentials);
+ }
+
}
bool FacebookAuthentication::updateCredentials(const QUrl &url)
QSettings settings(DIRECTORY_NAME, FILE_NAME);
return settings.value(USERNAME, EMPTY).toString();
}
+
+ void FacebookAuthentication::clearAccountInformation()
+ {
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_loginCredentials.clearCredentials();
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+ settings.remove(USERNAME);
+ settings.remove(USER_ID);
+ settings.remove(SESSION_KEY);
+ settings.remove(SESSION_SECRET);
+ settings.remove(EXPIRES);
+ settings.remove(SIGNATURE);
+
+ emit credentialsChanged(m_loginCredentials);
+ }
*/
void start();
+ /**
+ * @brief Clears account iformation from settings
+ *
+ */
+ void clearAccountInformation();
+
private:
/**
void credentialsReady(bool freshLogin, const FacebookCredentials &credentials);
/**
+ * @brief Signals changed credentials
+ *
+ * @param credentials New credentials
+ */
+ void credentialsChanged(const FacebookCredentials &credentials);
+
+ /**
* @brief This signal is emitted if updateCredentials method can't find credentials from URL
*
*/
return expireBool && sessionKeyBool && sessionSecretBool && sigBool && userIdBool;
}
+
+void FacebookCredentials::clearCredentials()
+{
+ m_expires.clear();
+ m_sessionKey.clear();
+ m_sessionSecret.clear();
+ m_sig.clear();
+ m_userID.clear();
+}
FacebookCredentials();
/**
+ * @brief Clears credentials
+ *
+ */
+ void clearCredentials();
+
+ /**
* @brief Set funtion for m_expires member
*
* @param expiresParameter value of parameter is set to m_expires member
{
qDebug() << __PRETTY_FUNCTION__;
- QPoint newPosition = convertLatLonToSceneCoordinate(user->coordinates());
- if (m_ownLocation->pos().toPoint() != newPosition) {
- m_ownLocation->setPos(newPosition);
- }
+ if(user) {
+ QPoint newPosition = convertLatLonToSceneCoordinate(user->coordinates());
+ if (m_ownLocation->pos().toPoint() != newPosition) {
+ m_ownLocation->setPos(newPosition);
+ }
- if (!m_ownLocation->isVisible())
- m_ownLocation->show();
+ if (!m_ownLocation->isVisible())
+ m_ownLocation->show();
+ }
+ else {
+ m_ownLocation->hide();
+ }
}
QGraphicsScene* MapEngine::scene()
#include "ui/avatarimage.h"
SituareService::SituareService(QObject *parent)
- : QObject(parent)
+ : QObject(parent),
+ m_user(0)
{
qDebug() << __PRETTY_FUNCTION__;
connect(m_imageFetcher, SIGNAL(imageReceived(QUrl,QPixmap)), this,
SLOT(imageReceived(QUrl, QPixmap)));
connect(m_imageFetcher, SIGNAL(error(QString)), this, SIGNAL(error(QString)));
-
- m_user = 0;
}
SituareService::~SituareService()
emit updateWasSuccessful();
}
else {
- // server error!
+ // session credentials are invalid
+ emit invalidSessionCredentials();
}
}
else {
reply->deleteLater();
}
-void SituareService::credentialsReady(bool freshLogin, const FacebookCredentials &credentials)
+void SituareService::credentialsReady(const FacebookCredentials &credentials)
{
qDebug() << __PRETTY_FUNCTION__;
- Q_UNUSED(freshLogin);
- m_credentials = credentials;
-
+
+ m_credentials = credentials;
}
void SituareService::parseUserData(const QByteArray &jsonReply)
}
}
}
+
+void SituareService::clearUserData()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ qDeleteAll(m_friendsList.begin(), m_friendsList.end());
+ m_friendsList.clear();
+
+ if(m_user) {
+ delete m_user;
+ m_user = 0;
+ }
+
+ emit userDataChanged(m_user, m_friendsList);
+}
public slots:
/**
- * @brief Public slot, which indicates when http request has been completed
+ * @brief Public slot, to clear user data
*
- * @param reply storage for http reply
*/
- void requestFinished(QNetworkReply *reply);
+ void clearUserData();
/**
* @brief Public slot, which indicates when facebook credentials are ready
*
- * @param freshLogin Was login done via login dialog
* @param credentials New credentials
*/
- void credentialsReady(bool freshLogin, const FacebookCredentials &credentials);
+ void credentialsReady(const FacebookCredentials &credentials);
+
+ /**
+ * @brief Public slot, which indicates when http request has been completed
+ *
+ * @param reply storage for http reply
+ */
+ void requestFinished(QNetworkReply *reply);
private:
/**
+ * @brief Requests ImageFetcher if user/friend has a profile image
+ * uses members: m_user and m_friendsList
+ *
+ */
+ void addProfileImages();
+
+ /**
* @brief Forms a http cookie
*
* @param apiKeyValue application key
* @param urlParameters optional parameters for url
* @return QUrl formed url
*/
- QUrl formUrl(const QString &baseUrl, const QString &phpScript, QString urlParameters = QString());
+ QUrl formUrl(const QString &baseUrl, const QString &phpScript,
+ QString urlParameters = QString());
/**
* @brief Forms url parameters
* @param publish optional publish location on Facebook wall (true/false)
* @return QString
*/
- QString formUrlParameters(const QPointF &coordinates, QString status = QString(), QString publish = QString());
+ QString formUrlParameters(const QPointF &coordinates, QString status = QString(),
+ QString publish = QString());
/**
* @brief Parses user and friend data from JSON string
*/
void sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie);
- /**
- * @brief Requests ImageFetcher if user/friend has a profile image
- * uses members: m_user and m_friendsList
- *
- */
- void addProfileImages();
-
private slots:
/**
void fetchImage(const QUrl &url);
/**
+ * @brief Signals when credentials are invalid
+ *
+ */
+ void invalidSessionCredentials();
+
+ /**
* @brief Signals when address data is retrieved
*
* @param address Street address
private:
- FacebookCredentials m_credentials; ///< handle for FacebookCredentials
- QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
- QNetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
- ImageFetcher *m_imageFetcher; ///< Instance of the image fetcher
+ int m_nbrOfImages; ///< Indicates number of friends whose images has been downloaded
+ int m_visited; ///< Indicates number of friends with images
+
+ bool m_defaultImage; ///< Indicates if some of the friends/user doesn't have a image
+
+ QList<QNetworkReply *> m_currentRequests; ///< List of current http requests
+ QList<User *> m_friendsList; ///< List of friends(User)
+
+ QNetworkAccessManager *m_networkManager; ///< Pointer to QNetworkAccessManager
+
+ FacebookCredentials m_credentials; ///< handle for FacebookCredentials
+ ImageFetcher *m_imageFetcher; ///< Instance of the image fetcher
+ User *m_user; ///< Pointer to User
+
+
- User *m_user; ///< Pointer to User
- QList<User *> m_friendsList; ///< List of friends(User)
- int m_visited; ///< Indicates number of friends with profile images
- int m_nbrOfImages; ///< Indicates number of friends whose profile images have been downloaded
- bool m_defaultImage; ///< Indicates if some of the friends or the user does not have a profile image
};
#endif // SITUARESERVICE_H
m_passwordEdit->setFocus(Qt::OtherFocusReason);
}
}
+
+void LoginDialog::clearTextFields()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_passwordEdit->clearFocus();
+ m_emailEdit->setText(""); // clear() method bugging in Qt 4.6.0, it leaves "dead" cursor
+ m_emailEdit->setFocus(Qt::OtherFocusReason);
+ m_passwordEdit->setText("");
+
+}
*/
void setEmailField(const QString &email);
+ /**
+ * @brief Clears line edits
+ *
+ */
+ void clearTextFields();
+
private slots:
/**
#include "friendlistpanel.h"
#include "logindialog.h"
#include "map/mapview.h"
-#include "panelsidebar.h"
#include "settingsdialog.h"
#include "userinfopanel.h"
#include "zoombuttonpanel.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent),
m_drawOwnLocationCrosshair(false),
+ m_loggedIn(false),
m_refresh(false),
m_email(),
m_password(),
qDebug() << __PRETTY_FUNCTION__;
m_friendsListPanel = new FriendListPanel(this);
- PanelSideBar *friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
+ m_friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
- m_friendsListPanel->stackUnder(friendsListPanelSidebar);
+ m_friendsListPanel->stackUnder(m_friendsListPanelSidebar);
connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
m_friendsListPanel, SLOT(screenResized(QSize)));
connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
- friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
+ m_friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
}
void MainWindow::buildManualLocationCrosshair()
qDebug() << __PRETTY_FUNCTION__;
m_userPanel = new UserInfoPanel(this);
- PanelSideBar *userPanelSidebar = new PanelSideBar(this, LEFT);
+ m_userPanelSidebar = new PanelSideBar(this, LEFT);
- userPanelSidebar->stackUnder(m_friendsListPanel);
- m_userPanel->stackUnder(userPanelSidebar);
+ m_userPanelSidebar->stackUnder(m_friendsListPanel);
+ m_userPanel->stackUnder(m_userPanelSidebar);
connect(this, SIGNAL(userLocationReady(User*)),
m_userPanel, SLOT(userDataReceived(User*)));
{
qDebug() << __PRETTY_FUNCTION__;
+ // login/logout
+ m_loginAct = new QAction(tr("Login"), this);
+ connect(m_loginAct, SIGNAL(triggered()),
+ this, SIGNAL(loginPressed()));
+
// settings
m_toSettingsAct = new QAction(tr("Settings"), this);
m_toSettingsAct->setObjectName(tr("Settings"));
// build the actual menu
m_viewMenu = menuBar()->addMenu(tr("Main"));
+ m_viewMenu->addAction(m_loginAct);
m_viewMenu->addAction(m_toSettingsAct);
m_viewMenu->addAction(m_gpsToggleAct);
m_viewMenu->addAction(m_autoCenteringAct);
}
}
+void MainWindow::loggedIn(bool logged)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_loggedIn = logged;
+
+ if(m_loginAct) {
+ if(logged) {
+ m_loginAct->setText(tr("Logout"));
+ }
+ else {
+ m_loginAct->setText(tr("Login"));
+ }
+ showPanels(m_loggedIn);
+ }
+}
+
void MainWindow::loginDialogDone(const QString &email, const QString &password)
{
qDebug() << __PRETTY_FUNCTION__;
qDebug() << __PRETTY_FUNCTION__;
SettingsDialog *dialog = new SettingsDialog(this);
+ if(!m_loggedIn) {
+ dialog->disableSituareSettings();
+ }
dialog->show();
}
#endif
}
+void MainWindow::showPanels(bool show)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ if(show) {
+ // ToDo: opening panels when needed
+ m_friendsListPanel->show();
+ m_friendsListPanelSidebar->show();
+ m_userPanel->show();
+ m_userPanelSidebar->show();
+ }
+ else {
+ m_friendsListPanel->hide();
+ m_friendsListPanelSidebar->hide();
+ m_userPanel->hide();
+ m_userPanelSidebar->hide();
+ }
+}
+
void MainWindow::startLoginProcess(const QUrl &url)
{
qDebug() << __PRETTY_FUNCTION__;
#include <QtGui/QMainWindow>
#include <QUrl>
+#include "panelsidebar.h"
+
class QGraphicsScene;
class QLabel;
class QWebView;
******************************************************************************/
public:
/**
+ * @brief
+ *
+ * @param logged
+ */
+ void loggedIn(bool logged);
+
+ /**
* @brief Enable / disable auto centering button.
*
* @param enabled true if shoud be enabled, false otherwise
void setUsername(const QString &username);
/**
+ * @brief
+ *
+ * @param show
+ */
+ void showPanels(bool show);
+
+ /**
* @brief Public slot to intercept signal when old cerdentials are invalid or credentials
* doesn't exist yet
*
void friendsLocationsReady(QList<User *> &friendsList);
/**
+ * @brief Signals when Login/Logout action is pressed
+ *
+ */
+ void loginPressed();
+
+ /**
* @brief MapView has been resized
*
* @param size view size
private:
bool m_drawOwnLocationCrosshair; ///< Flag for making ownLocationCrosshair visible or not
+ bool m_loggedIn; ///< Indicates login state
bool m_refresh; ///< Indicates when webpage is refreshed
int m_viewPortHeight; ///< Height of view port
QAction *m_autoCenteringAct; ///< Action to auto center map using gps position
QAction *m_gpsToggleAct; ///< Action to trigger gps toggle
+ QAction *m_loginAct; ///< Action to Login/Logout
QAction *m_toSettingsAct; ///< Action to trigger switch to settings dialog
QLabel *m_osmLicense; ///< Label for Open Street Map license
FriendListPanel *m_friendsListPanel; ///< Instance of friends list panel
LoginDialog *m_loginDialog; ///< Login dialog
MapView *m_mapView; ///< Instance of the map view
+ PanelSideBar *m_userPanelSidebar; ///< User panel side bar
+ PanelSideBar *m_friendsListPanelSidebar;///< Friends panel side bar
UserInfoPanel *m_userPanel; ///< Instance of the user information panel
ZoomButtonPanel *m_zoomButtonPanel; ///< Instance of zoom button panel
};
void SettingsDialog::saveValues()
{
qDebug() << __PRETTY_FUNCTION__;
-// QSettings settings(DIRECTORY_NAME, FILE_NAME);
-// settings.setValue(AUTOMATIC_LOCATION_UPDATE, m_automaticLocationUpdate->isChecked());
+
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+ settings.setValue(AUTOMATIC_LOCATION_UPDATE, m_automaticLocationUpdate->isChecked());
accept();
+}
+
+void SettingsDialog::disableSituareSettings()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ m_automaticLocationUpdate->setDisabled(true);
}
*/
~SettingsDialog();
+ /**
+ * @brief Disables Situare related settings from settings dialog
+ *
+ */
+ void disableSituareSettings();
+
/*******************************************************************************
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
void UserInfoPanel::userDataReceived(User *user)
{
- qDebug() << __PRETTY_FUNCTION__ << " " << user->name();
+ qDebug() << __PRETTY_FUNCTION__;
- m_userInfo->setUserName(user->name());
- m_userInfo->setAvatar(user->profileImage());
- m_userInfo->setMessageText(user->note());
- m_userInfo->setAddress(user->address());
- m_userInfo->setTime(user->timestamp());
+ if(user) {
+ m_userInfo->setUserName(user->name());
+ m_userInfo->setAvatar(user->profileImage());
+ m_userInfo->setMessageText(user->note());
+ m_userInfo->setAddress(user->address());
+ m_userInfo->setTime(user->timestamp());
+ }
}