is shown in login dialog when it is needed.
Reviewed by: Kaj Wallin
#endif
m_gps->setMode(GPSPositionInterface::Default);
- connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
- m_situareService, SLOT(credentialsReady(FacebookCredentials)));
- connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
- this, SLOT(loginOk()));
+
+ connect(m_facebookAuthenticator, SIGNAL(credentialsReady(bool, FacebookCredentials)),
+ m_situareService, SLOT(credentialsReady(bool, FacebookCredentials)));
+ connect(m_facebookAuthenticator, SIGNAL(credentialsReady(bool, FacebookCredentials)),
+ this, SLOT(loginOk(bool)));
connect(m_ui, SIGNAL(cancelLoginProcess()),
this, SLOT(loginProcessCancelled()));
+ connect(m_ui, SIGNAL(fetchUsernameFromSettings()),
+ this, SLOT(fetchUsernameFromSettings()));
connect(m_ui, SIGNAL(requestReverseGeo()),
this, SLOT(requestAddress()));
// ToDo: signal UI?
}
-void SituareEngine::loginOk()
+void SituareEngine::loginOk(bool freshLogin)
{
qDebug() << __PRETTY_FUNCTION__;
+ if(freshLogin) {
+ m_facebookAuthenticator->saveUsername(m_ui->username());
+ }
m_ui->show();
m_situareService->fetchLocations(); // request user locations
}
qDebug() << __PRETTY_FUNCTION__;
m_latestLocation = ownLocation;
}
+
+void SituareEngine::fetchUsernameFromSettings()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ m_ui->setUsername(m_facebookAuthenticator->loadUsername());
+}
void error(const QString &error);
/**
+ * @brief Slot to intercept signal when username is fetched from settings
+ *
+ */
+ void fetchUsernameFromSettings();
+
+ /**
* @brief Slot to intercept signal from successful login
+ *
+ * @param freshLogin Was login done via login dialog
*/
- void loginOk();
+ void loginOk(bool freshLogin);
/**
* @brief Slot to receive location of crosshair
#include "facebookauthentication.h"
#include "facebookcommon.h"
-#include "common.h"
+#include "../common.h"
#include "parser.h"
FacebookAuthentication::FacebookAuthentication(QObject *parent)
emit newLoginRequest(formLoginPageUrl(list));
}
else
- emit credentialsReady(m_loginCredentials);
+ emit credentialsReady(false, m_loginCredentials);
}
bool FacebookAuthentication::updateCredentials(const QUrl &url)
found = true;
}
writeCredentials(m_loginCredentials);
- emit credentialsReady(m_loginCredentials);
+ emit credentialsReady(true, m_loginCredentials);
}
else if ( callbackUrl.indexOf(LOGIN_FAILURE_REPLY) == 0){
qWarning() << "login failure" << endl;
return QUrl(urlParts.join(EMPTY));
}
+
+ void FacebookAuthentication::saveUsername(const QString &username)
+ {
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+ settings.setValue(USERNAME, username);
+ }
+
+ const QString FacebookAuthentication::loadUsername()
+ {
+ qDebug() << __PRETTY_FUNCTION__;
+
+ QSettings settings(DIRECTORY_NAME, FILE_NAME);
+ return settings.value(USERNAME, EMPTY).toString();
+ }
public slots:
/**
+ * @brief Loads username from settings
+ *
+ * @return QString Loaded username
+ */
+ const QString loadUsername();
+
+ /**
+ * @brief Saves username to settings
+ *
+ * @param username Username to be saved
+ */
+ void saveUsername(const QString &username);
+
+ /**
* @brief Shows the m_webView and loads page that is specified in the m_facebookLoginPage
* variable. Specifies font size for the page.
*
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.
* Signal is also emitted at the beginning of the program if there is valid credentials
* in the file.
*
+ * @param freshLogin Was login done via login dialog
* @param credentials New credentials
*/
- void credentialsReady(const FacebookCredentials &credentials);
+ void credentialsReady(bool freshLogin, const FacebookCredentials &credentials);
/**
* @brief This signal is emitted if updateCredentials method can't find credentials from URL
private:
+ int m_loginAttempts; ///< Indicates login attempts
+
/**
* @brief Dataclass that contains authorization to use facebook. Dataclass is composed of five
* QStrings and setters and getters.
* @var m_loginCredentials
*/
FacebookCredentials m_loginCredentials;
-
- int m_loginAttempts; ///< Indicates login attempts
};
#endif // FACEBOOKAUTHENTICATION_H
// Facebook webView font size
const double FACEBOOK_LOGINPAGE_FONT_SIZE = 1.2;
-// Facebook callback url indentifiers
+// Facebook callback url indentifiers and setting items
const QString SESSION_KEY = "session_key";
const QString USER_ID = "uid";
const QString EXPIRES = "expires";
const QString SESSION_SECRET = "secret";
const QString SIGNATURE = "sig";
+// Login setting items
+const QString USERNAME = "username";
+
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=";
reply->deleteLater();
}
-void SituareService::credentialsReady(const FacebookCredentials &credentials)
+void SituareService::credentialsReady(bool freshLogin, const FacebookCredentials &credentials)
{
qDebug() << __PRETTY_FUNCTION__;
+ Q_UNUSED(freshLogin);
m_credentials = credentials;
}
/**
* @brief Public slot, which indicates when facebook credentials are ready
*
+ * @param freshLogin Was login done via login dialog
* @param credentials New credentials
*/
- void credentialsReady(const FacebookCredentials &credentials);
+ void credentialsReady(bool freshLogin, const FacebookCredentials &credentials);
private:
accept();
}
+
+void LoginDialog::setEmailField(const QString &email)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ if(!email.isEmpty()) {
+ m_emailEdit->setText(email);
+ m_passwordEdit->setFocus(Qt::OtherFocusReason);
+ }
+}
* MEMBER FUNCTIONS AND SLOTS
******************************************************************************/
+public slots:
+
+ /**
+ * @brief Sets email address to emailEdit field
+ *
+ * @param email E-mail address to be set
+ */
+ void setEmailField(const QString &email);
+
private slots:
/**
QLineEdit *m_emailEdit; ///< Pointer to email line edit
QLineEdit *m_passwordEdit; ///< Pointer to password line edit
-
};
setWindowTitle(tr("Situare"));
show();
- m_locationDialog = new UpdateLocationDialog(this);
-
connect(this, SIGNAL(reverseGeoReady(QString)),
m_mapViewScreen, SIGNAL(reverseGeoReady(QString)));
connect(m_mapViewScreen, SIGNAL(statusUpdate(QString,bool)),
m_webView->hide();
+ emit fetchUsernameFromSettings();
+
+ if(!m_email.isEmpty()) {
+ m_loginDialog->setEmailField(m_email);
+ }
+
if(m_loginDialog->exec() != QDialog::Accepted) {
// if login dialog was canceled we need to stop processing webview
// stop and disconnect m_webView;
#endif // Q_WS_MAEMO_5
+ if(!m_email.isEmpty()) {
+ m_loginDialog->setEmailField(m_email);
+ }
+
if(m_loginDialog->exec() != QDialog::Accepted) {
// if login dialog was canceled we need to stop processing webview
// stop and disconnect m_webView;
}
QWidget::keyPressEvent(event);
}
+
+const QString MainWindow::username()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ return m_email;
+}
+
+void MainWindow::setUsername(const QString &username)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+ m_email = username;
+}
#include "facebookservice/facebookauthentication.h"
#include "situareservice/situareservice.h"
#include "mapviewscreen.h"
-#include "updatelocation/updatelocationdialog.h"
#include "ui/logindialog.h"
class QLabel;
*/
void setGPSButton(bool enabled);
+ /**
+ * @brief Gets the username from member variable for saving purposes
+ *
+ * @return QString Username
+ */
+ const QString username();
+
public slots:
/**
* @brief Slot for auto centering enabling.
void openSettingsDialog();
/**
+ * @brief Sets username to member variable for login dialog
+ *
+ * @param username Username to be set
+ */
+ void setUsername(const QString &username);
+
+ /**
* @brief Public slot to intercept signal when old cerdentials are invalid or credentials
* doesn't exist yet
*
******************************************************************************/
signals:
/**
- * @brief Signal that indicates when user has cancelled login process
+ * @brief Signal for map auto centering
*
+ * @param enabled true if map should auto center to gps location
*/
- void cancelLoginProcess();
+ void autoCentering(bool enabled);
/**
- * @brief Signal for map auto centering
+ * @brief Signal that indicates when user has cancelled login process
*
- * @param enabled true if map should auto center to gps location
*/
- void autoCentering(bool enabled);
+ void cancelLoginProcess();
/**
* @brief Signal for gps enabling.
void enableAutoCentering(bool enabled);
/**
+ * @brief Signal for requesting username from settings
+ *
+ */
+ void fetchUsernameFromSettings();
+
+ /**
* @brief Signal for friend location ready.
*
* @param friendsList
QAction *m_autoCenteringAct; ///< Action to auto center map using gps position
QString m_email; ///< Placeholder for email
QAction *m_gpsToggleAct; ///< Action to trigger gps toggle
- UpdateLocationDialog *m_locationDialog; ///< Message dialog
LoginDialog *m_loginDialog; ///< Login dialog
QUrl m_loginUrl; ///< Placeholder for login page url
MapViewScreen *m_mapViewScreen; ///< Instance of the map view