#endif // Q_WS_MAEMO_5
#include "common.h"
-#include "error.h"
+#include "../error.h"
#include "network/networkcookiejar.h"
#include "situareservice/situarecommon.h"
#include "ui/mainwindow.h"
FacebookAuthentication::FacebookAuthentication(MainWindow *mainWindow, QObject *parent)
: QObject(parent),
+ m_loggedIn(false),
m_browser(0),
m_mainWindow(mainWindow)
{
{
qWarning() << __PRETTY_FUNCTION__;
+ m_mainWindow->toggleProgressIndicator(false);
m_browser = 0;
}
-void FacebookAuthentication::clearAccountInformation(bool keepUsername)
+void FacebookAuthentication::clearAccountInformation(bool clearUserInformation)
{
- qDebug() << __PRETTY_FUNCTION__;
+ qWarning() << __PRETTY_FUNCTION__ << "clearUserInformation:" << clearUserInformation;
- ///< @todo (HIGH) clear session from SituareService
QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
- if(!keepUsername) {
+ settings.remove(USER_UNSEND_MESSAGE);
+ settings.remove(USER_UNSEND_MESSAGE_PUBLISH);
+
+ if (clearUserInformation) {
+ NetworkCookieJar::clearCookiesSetting();
settings.remove(SETTINGS_AUTOMATIC_UPDATE_ENABLED);
settings.remove(SETTINGS_AUTOMATIC_UPDATE_INTERVAL);
}
+}
- settings.remove(USER_UNSEND_MESSAGE);
- settings.remove(USER_UNSEND_MESSAGE_PUBLISH);
+void FacebookAuthentication::destroyLogin()
+{
+ qWarning() << __PRETTY_FUNCTION__;
- NetworkCookieJar::clearCookiesSetting();
+ m_mainWindow->destroyLoginDialog();
+ m_browser->deleteLater();
}
-void FacebookAuthentication::loadFinished(bool ok)
+bool FacebookAuthentication::isLoggedIn() const
{
- qWarning() << __PRETTY_FUNCTION__ << ok;
+ qWarning() << __PRETTY_FUNCTION__;
- ///< @todo show browsed window if url != redirect url
+ return m_loggedIn;
}
void FacebookAuthentication::login()
if (m_browser) {
m_browser->page()->networkAccessManager()->setCookieJar(new NetworkCookieJar());
- connect(m_browser, SIGNAL(loadFinished(bool)),
- this, SLOT(loadFinished(bool)));
-
connect(m_browser, SIGNAL(urlChanged(QUrl)),
this, SLOT(urlChanged(QUrl)));
connect(m_browser, SIGNAL(destroyed(QObject*)),
this, SLOT(browserDestroyed()));
+ connect(m_browser->page()->networkAccessManager(),
+ SIGNAL(sslErrors(QNetworkReply*, QList<QSslError>)),
+ this, SLOT(sslErrors(QNetworkReply*, QList<QSslError>)));
+
connect(m_browser->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
this, SLOT(networkReplyHandler(QNetworkReply*)));
}
url.append("req_perms=publish_stream");
m_browser->load(QUrl(url));
+
+ m_mainWindow->toggleProgressIndicator(true);
}
}
+void FacebookAuthentication::logOut(bool clearUserInformation)
+{
+ qWarning() << __PRETTY_FUNCTION__;
+
+ clearAccountInformation(clearUserInformation);
+ m_loggedIn = false;
+ emit loggedOut();
+}
+
void FacebookAuthentication::networkReplyHandler(QNetworkReply *reply)
{
qWarning() <<__PRETTY_FUNCTION__;
- if (reply->error() != QNetworkReply::NoError) {
+ if ((reply->error() != QNetworkReply::NoError)
+ && (reply->error() != QNetworkReply::OperationCanceledError)) {
+
qCritical() << __PRETTY_FUNCTION__ << "error:" << reply->error() << reply->errorString();
- /// @todo Emit error signal
+ emit error(ErrorContext::NETWORK, reply->error());
+ destroyLogin();
}
}
return QString();
}
+void FacebookAuthentication::sslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
+{
+ qWarning() << __PRETTY_FUNCTION__;
+
+ Q_UNUSED(errors);
+ reply->ignoreSslErrors();
+}
+
void FacebookAuthentication::urlChanged(const QUrl &url)
{
qWarning() << __PRETTY_FUNCTION__ << url.toString();
const QString session = parseSession(url);
qWarning() << __PRETTY_FUNCTION__ << "login finished, parsed session:" << session;
if (!session.isEmpty()) {
- m_mainWindow->destroyLoginDialog();
- m_browser->deleteLater();
+ destroyLogin();
+ m_loggedIn = true;
emit loggedIn(session);
}
}