Merge branch 'master' into zoom_button_drag
[situare] / src / ui / mainwindow.cpp
index 0202682..8b58426 100644 (file)
@@ -4,6 +4,9 @@
 
       Henri Lampela - henri.lampela@ixonos.com
       Kaj Wallin - kaj.wallin@ixonos.com
+      Jussi Laitinen jussi.laitinen@ixonos.com
+      Sami Rämö - sami.ramo@ixonos.com
+      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
 */
 
 #include <QtGui>
-#include "mainwindow.h"
-#include "listviewscreen.h"
-#include "mapviewscreen.h"
-#include "settingsdialog.h"
+#include <QtWebKit>
+
+#ifdef Q_WS_MAEMO_5
+#include <QtMaemo5/QMaemo5InformationBox>
+#endif // Q_WS_MAEMO_5
+
+#include "common.h"
 #include "facebookservice/facebookauthentication.h"
-#include "situareservice/situareservice.h"
+#include "friendlistpanel.h"
+#include "logindialog.h"
+#include "map/mapview.h"
+#include "settingsdialog.h"
+#include "userinfopanel.h"
+#include "zoombuttonpanel.h"
+
+#include "mainwindow.h"
+
+#include <QtGui/QX11Info>
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+
+// values for setting screen size in desktop matching N900 screen size
+const int N900_APP_WIDTH = 800;
+const int N900_APP_HEIGHT = 449;
 
 MainWindow::MainWindow(QWidget *parent)
-    : QMainWindow(parent)
+    : QMainWindow(parent),
+    m_drawOwnLocationCrosshair(false),
+    m_loggedIn(false),
+    m_refresh(false),
+    m_email(),    
+    m_password(),
+    m_loginUrl(),
+    m_webView(0)
 {
     qDebug() << __PRETTY_FUNCTION__;
-    m_loggedIn = false;
-    createViews();
-    setCentralWidget(m_situareViews);
+
+    buildMap();
+
+    // build main layout
+    QHBoxLayout *layout = new QHBoxLayout;
+    layout->addWidget(m_mapView);
+    layout->setMargin(0);
+    setCentralWidget(new QWidget());
+    centralWidget()->setLayout(layout);
+
+    buildFriendListPanel();
+    buildUserInfoPanel();
+
     createMenus();
-    setWindowTitle(tr("List view"));
-    this->hide();
+    setWindowTitle(tr("Situare"));
 
-    //m_facebookAuthenticator = new FacebookAuthentication(this);
-    //connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)), this, SLOT(loginOK()));
-    //connect(m_facebookAuthenticator, SIGNAL(userExit()), this, SLOT(loginScreenClosed()));
-   // m_facebookAuthenticator->start();
+    // set stacking order of widgets
+    m_zoomButtonPanel->stackUnder(m_userPanel);
+    m_osmLicense->stackUnder(m_zoomButtonPanel);
+    m_ownLocationCrosshair->stackUnder(m_osmLicense);
+    m_mapView->stackUnder(m_ownLocationCrosshair);
 
-    m_locationDialog = new UpdateLocationDialog(this);
-    connect(m_listViewScreen->m_personalInfo,SIGNAL(launchMessageUpdate()),
-            this,SLOT(openLocationUpdateDialog()));
+    this->toggleProgressIndicator(true);
 
-    connect(this, SIGNAL(reverseGeoReady(QString)), m_locationDialog, SLOT(setAddress(QString)));
-    connect(m_locationDialog, SIGNAL(statusUpdate(QString,bool)), this,
-            SIGNAL(statusUpdate(QString,bool)));
-    
-    m_networkManager = new QNetworkAccessManager;
-    m_situareService = new SituareService(this,m_networkManager);
+    grabZoomKeys(true);
 
-    connect(this, SIGNAL(userLocationReady(User*)),
-            m_mapViewScreen, SLOT(userLocationReady(User*)));
-    connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
-            m_mapViewScreen, SLOT(friendsLocationsReady(QList<User*>&)));
+    // set screen size in desktop matching N900 screen size
+    resize(N900_APP_WIDTH, N900_APP_HEIGHT);
 }
 
 MainWindow::~MainWindow()
 {
     qDebug() << __PRETTY_FUNCTION__;
-    delete m_toListViewAct;
-    delete m_toMapViewAct;
-    delete m_toSettingsAct;
-    delete m_situareViews;
+
+    grabZoomKeys(false);
+
+    if(m_webView)
+        delete m_webView;
+}
+
+void MainWindow::buildFriendListPanel()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_friendsListPanel = new FriendListPanel(this);
+    m_friendsListPanelSidebar = new PanelSideBar(this, RIGHT);
+
+    m_friendsListPanel->stackUnder(m_friendsListPanelSidebar);
+
+    connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
+            m_friendsListPanel, SLOT(friendInfoReceived(QList<User*>&)));
+
+    connect(m_friendsListPanel, SIGNAL(findFriend(QPointF)),
+            this, SIGNAL(findFriend(QPointF)));
+
+    connect(m_mapView, SIGNAL(viewResized(QSize)),
+            m_friendsListPanel, SLOT(screenResized(QSize)));
+
+    connect(this, SIGNAL(locationItemClicked(QList<QString>)),
+            m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
+
+    connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
+            m_friendsListPanelSidebar, SLOT(reDrawSidebar(int, int)));
+}
+
+void MainWindow::buildManualLocationCrosshair()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_ownLocationCrosshair = new QLabel(this);
+    QPixmap crosshairImage(":/res/images/sight.png");
+    m_ownLocationCrosshair->setPixmap(crosshairImage);
+    m_ownLocationCrosshair->setFixedSize(crosshairImage.size());
+    m_ownLocationCrosshair->hide();
+    m_ownLocationCrosshair->setAttribute(Qt::WA_TransparentForMouseEvents, true);
+
+    connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
+            this, SLOT(drawOwnLocationCrosshair(int, int)));
+}
+
+void MainWindow::buildMap()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_mapView = new MapView(this);
+
+    buildZoomButtonPanel();
+
+    m_ownLocationCrosshair = 0;
+    buildOsmLicense();
+    buildManualLocationCrosshair();
+
+    connect(m_mapView, SIGNAL(viewScrolled(QPoint)),
+            this, SIGNAL(mapViewScrolled(QPoint)));
+
+    connect(this, SIGNAL(centerToSceneCoordinates(QPoint)),
+            m_mapView, SLOT(centerToSceneCoordinates(QPoint)));
+
+    connect(m_mapView, SIGNAL(viewResized(QSize)),
+            this, SIGNAL(mapViewResized(QSize)));
+
+    connect(m_mapView, SIGNAL(viewResizedNewSize(int, int)),
+             this, SLOT(setViewPortSize(int, int)));
+
+    connect(this, SIGNAL(zoomLevelChanged(int)),
+            m_mapView, SLOT(setZoomLevel(int)));
+
+    connect(m_mapView, SIGNAL(viewZoomFinished()),
+            this, SIGNAL(viewZoomFinished()));
+}
+
+void MainWindow::buildOsmLicense()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_osmLicense = new QLabel(this);
+    m_osmLicense->setAttribute(Qt::WA_TranslucentBackground, true);
+    m_osmLicense->setAttribute(Qt::WA_TransparentForMouseEvents, true);
+    m_osmLicense->setText("<font color='black'>" + OSM_LICENSE + "</font>");
+    m_osmLicense->setFont(QFont("Nokia Sans", 9));
+    m_osmLicense->resize(m_osmLicense->fontMetrics().width(OSM_LICENSE),
+                         m_osmLicense->fontMetrics().height());
+
+    connect(m_mapView, SIGNAL(viewResized(QSize)),
+            this, SLOT(drawOsmLicense(QSize)));
+}
+
+void MainWindow::buildUserInfoPanel()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_userPanel = new UserInfoPanel(this);
+    m_userPanelSidebar = new PanelSideBar(this, LEFT);
+
+    m_userPanelSidebar->stackUnder(m_friendsListPanel);
+    m_userPanel->stackUnder(m_userPanelSidebar);
+
+    connect(m_userPanel, SIGNAL(findUser(QPointF)),
+            this, SIGNAL(findUser(QPointF)));
+
+    connect(this, SIGNAL(userLocationReady(User*)),
+            m_userPanel, SLOT(userDataReceived(User*)));
+
+    connect(m_userPanel, SIGNAL(requestReverseGeo()),
+            this, SIGNAL(requestReverseGeo()));
+
+    connect(this, SIGNAL(reverseGeoReady(QString)),
+            m_userPanel, SIGNAL(reverseGeoReady(QString)));
+
+    connect(m_userPanel, SIGNAL(statusUpdate(QString,bool)),
+            this, SIGNAL(statusUpdate(QString,bool)));
+
+    connect(m_userPanel, SIGNAL(refreshUserData()),
+            this, SIGNAL(refreshUserData()));
+
+    connect(m_mapView, SIGNAL(viewResized(QSize)),
+            m_userPanel, SLOT(screenResized(QSize)));
+}
+
+void MainWindow::buildZoomButtonPanel()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_zoomButtonPanel = new ZoomButtonPanel(this);
+
+    connect(m_zoomButtonPanel->zoomInButton(), SIGNAL(clicked()),
+            this, SIGNAL(zoomIn()));
+
+    connect(m_zoomButtonPanel->zoomOutButton(), SIGNAL(clicked()),
+            this, SIGNAL(zoomOut()));
+
+    connect(this, SIGNAL(zoomLevelChanged(int)),
+            m_zoomButtonPanel, SLOT(resetButtons()));
+
+    connect(this, SIGNAL(maxZoomLevelReached()),
+            m_zoomButtonPanel, SLOT(disableZoomInButton()));
+
+    connect(this, SIGNAL(minZoomLevelReached()),
+            m_zoomButtonPanel, SLOT(disableZoomOutButton()));
+
+    connect(m_mapView, SIGNAL(viewResized(QSize)),
+            m_zoomButtonPanel, SLOT(screenResized(QSize)));
 }
 
 void MainWindow::createMenus()
 {
     qDebug() << __PRETTY_FUNCTION__;
-    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()));
+
+    // login/logout
+    m_loginAct = new QAction(tr("Login"), this);
+    connect(m_loginAct, SIGNAL(triggered()),
+            this, SIGNAL(loginActionPressed()));
+
+    // settings
     m_toSettingsAct = new QAction(tr("Settings"), this);
-    m_toSettingsAct->setObjectName(tr("Settings"));
-    connect(m_toSettingsAct, SIGNAL(triggered()), this, SLOT(openSettingsDialog()));
-    m_viewMenu = menuBar()->addMenu(tr("View"));
-    m_viewMenu->addAction(m_toListViewAct);
-    m_viewMenu->addAction(m_toMapViewAct);
+    connect(m_toSettingsAct, SIGNAL(triggered()),
+        this, SLOT(openSettingsDialog()));
+
+    // GPS
+    m_gpsToggleAct = new QAction(tr("GPS"), this);
+    m_gpsToggleAct->setCheckable(true);
+
+    connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
+            this, SIGNAL(gpsTriggered(bool)));
+
+    // automatic centering
+    m_autoCenteringAct = new QAction(tr("Auto centering"), this);
+    m_autoCenteringAct->setCheckable(true);
+    connect(m_autoCenteringAct, SIGNAL(triggered(bool)),
+        this, SIGNAL(autoCenteringTriggered(bool)));
+
+    // build the actual menu
+    m_viewMenu = menuBar()->addMenu(tr("Main"));
+    m_viewMenu->addAction(m_loginAct);
     m_viewMenu->addAction(m_toSettingsAct);
-    m_viewMenu->setObjectName(tr("View Menu"));
+    m_viewMenu->addAction(m_gpsToggleAct);
+    m_viewMenu->addAction(m_autoCenteringAct);
+    m_viewMenu->setObjectName(tr("Menu"));
+}
+
+void MainWindow::drawOsmLicense(const QSize &size)
+{
+    qDebug() << __PRETTY_FUNCTION__ << size.width() << "x" << size.height();
+
+    m_osmLicense->move(size.width() - m_osmLicense->fontMetrics().width(OSM_LICENSE)
+                       - PANEL_PEEK_AMOUNT,
+                       size.height() - m_osmLicense->fontMetrics().height());
+
 }
 
-void MainWindow::createViews()
+void MainWindow::drawOwnLocationCrosshair(int width, int height)
 {
     qDebug() << __PRETTY_FUNCTION__;
-    m_listViewScreen = new ListViewScreen(this);
-    m_mapViewScreen = new MapViewScreen(this);
 
-    m_situareViews = new QStackedWidget;
-    m_situareViews->addWidget(m_listViewScreen);
-    m_situareViews->addWidget(m_mapViewScreen);
+    if (m_drawOwnLocationCrosshair && m_ownLocationCrosshair != 0) {
+        m_ownLocationCrosshair->move(width/2 - m_ownLocationCrosshair->pixmap()->width()/2,
+                            height/2 - m_ownLocationCrosshair->pixmap()->height()/2);
+    }
 }
 
-void MainWindow::toListView()
+void MainWindow::gpsError(const QString &message)
 {
     qDebug() << __PRETTY_FUNCTION__;
-    switchView(0);
+
+    showMaemoInformationBox(message);
 }
 
-void MainWindow::toMapView()
+void MainWindow::gpsTimeout()
 {
     qDebug() << __PRETTY_FUNCTION__;
-    switchView(1);
+
+    showMaemoInformationBox(tr("GPS timeout"));
 }
 
-void MainWindow::switchView(int nextIndex)
+void MainWindow::grabZoomKeys(bool grab)
 {
-    qDebug() << __PRETTY_FUNCTION__ << ":" << nextIndex;
-    if (nextIndex < 0 || nextIndex > 1) {
-        qDebug() << "Illegal parameter value in MainWindow::switchView";
+    qDebug() << __PRETTY_FUNCTION__;
+
+#ifdef Q_WS_MAEMO_5
+    // Can't grab keys unless we have a window id
+    if (!winId())
+        return;
+
+    unsigned long val = (grab) ? 1 : 0;
+    Atom atom = XInternAtom(QX11Info::display(), "_HILDON_ZOOM_KEY_ATOM", False);
+    if (!atom)
         return;
+
+    XChangeProperty (QX11Info::display(),
+                     winId(),
+                     atom,
+                     XA_INTEGER,
+                     32,
+                     PropModeReplace,
+                     reinterpret_cast<unsigned char *>(&val),
+                     1);
+#else
+    Q_UNUSED(grab);
+#endif // Q_WS_MAEMO_5
+}
+
+void MainWindow::keyPressEvent(QKeyEvent* event)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    switch (event->key()) {
+    case Qt::Key_F7:
+        event->accept();
+        emit zoomIn();
+        break;
+
+    case Qt::Key_F8:
+        event->accept();
+        emit zoomOut();
+        break;
     }
-    m_situareViews->setCurrentIndex(nextIndex);
-    switch (m_situareViews->currentIndex()) {
-        case 0:
-            setWindowTitle(tr("List view"));
-            break;
-        case 1:
-            setWindowTitle(tr("Map view"));
-            break;
-        default:
-            qDebug() << "Illegal switch value in MainWindow::switchView";
-            break;
+    QWidget::keyPressEvent(event);
+}
+
+void MainWindow::loadDone(bool done)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    // for the first time the login page is opened, we need to refresh it to get cookies working
+    if(m_refresh) {
+        m_webView->reload();
+        m_refresh = false;
     }
+
+    if (done)
+    {
+        QWebFrame* frame = m_webView->page()->currentFrame();
+        if (frame!=NULL)
+        {
+            // set email box
+            QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
+
+            foreach (QWebElement element, emailCollection) {
+                element.setAttribute("value", m_email.toAscii());
+            }
+            // set password box
+            QWebElementCollection passwordCollection = frame->findAllElements("input[name=pass]");
+            foreach (QWebElement element, passwordCollection) {
+                element.setAttribute("value", m_password.toAscii());
+            }
+            // find connect button
+            QWebElementCollection buttonCollection = frame->findAllElements("input[name=login]");
+            foreach (QWebElement element, buttonCollection)
+            {
+                QPoint pos(element.geometry().center());
+
+                // send a mouse click event to the web page
+                QMouseEvent event0(QEvent::MouseButtonPress, pos, Qt::LeftButton, Qt::LeftButton,
+                                   Qt::NoModifier);
+                QApplication::sendEvent(m_webView->page(), &event0);
+                QMouseEvent event1(QEvent::MouseButtonRelease, pos, Qt::LeftButton, Qt::LeftButton,
+                                   Qt::NoModifier);
+                QApplication::sendEvent(m_webView->page(), &event1);
+            }
+        }
+    }
+}
+
+void MainWindow::loggedIn(bool logged)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_loggedIn = logged;
+
+    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__;
+
+    m_email = email;
+    m_password = password;
 }
 
-void MainWindow::openLocationUpdateDialog()
+void MainWindow::loginFailed()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    emit requestReverseGeo();
-    m_locationDialog->exec();
+    m_email.clear();
+    m_password.clear();
+
+    toggleProgressIndicator(false);
+
+#ifdef Q_WS_MAEMO_5
+    QMaemo5InformationBox::information(this, tr("Invalid E-mail address or password"),
+                                       QMaemo5InformationBox::NoTimeout);
+
+#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;
+        m_webView->stop();
+        disconnect(m_webView, SIGNAL(loadFinished(bool)),
+                   this, SLOT(loadDone(bool)));
+        disconnect(m_webView, SIGNAL(urlChanged(const QUrl &)),
+                   this, SLOT(updateCredentials(const QUrl &)));
+
+        emit cancelLoginProcess();
+    }
+    else {
+        // re-load login page for webview
+        toggleProgressIndicator(true);
+        m_webView->load(m_loginUrl);
+    }
 }
 
 void MainWindow::openSettingsDialog()
 {
     qDebug() << __PRETTY_FUNCTION__;
+
     SettingsDialog *dialog = new SettingsDialog(this);
+    if(!m_loggedIn) {
+        dialog->disableSituareSettings();
+    }
     dialog->show();
 }
 
-void MainWindow::loginScreenClosed()
+void MainWindow::setAutoCenteringButtonEnabled(bool enabled)
 {
-    qDebug() << __PRETTY_FUNCTION__ << m_loggedIn;
-    if (m_loggedIn) {
-        this->show();
-        return;
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_autoCenteringAct->setChecked(enabled);
+}
+
+void MainWindow::setGPSButtonEnabled(bool enabled)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_gpsToggleAct->setChecked(enabled);
+    setOwnLocationCrosshairVisibility(!enabled);
+    m_autoCenteringAct->setVisible(enabled);
+}
+
+void MainWindow::setMapViewScene(QGraphicsScene *scene)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_mapView->setScene(scene);
+}
+
+void MainWindow::setOwnLocationCrosshairVisibility(bool visibility)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (visibility) {
+        m_ownLocationCrosshair->show();
+        m_drawOwnLocationCrosshair = true;
+        drawOwnLocationCrosshair(m_viewPortWidth, m_viewPortHeight);
     }
     else {
-        this->close();
+        m_ownLocationCrosshair->hide();
+        m_drawOwnLocationCrosshair = false;
     }
 }
 
-void MainWindow::loginOK()
+void MainWindow::setUsername(const QString &username)
 {
-    qDebug() << __PRETTY_FUNCTION__ << m_loggedIn;
-    m_loggedIn = true;
-    //m_facebookAuthenticator->close();
+    qDebug() << __PRETTY_FUNCTION__;
+    m_email = username;
 }
 
-//void MainWindow::userLocationReady(User &user)
-//{
-//    emit userLocationReady(user);
-//}
-//
-//void MainWindow::friendsLocationsReady(QList<User *>friendsList)
-//{
-//    emit friendsLocationsReady(friendsList);
-//}
+void MainWindow::setViewPortSize(int width, int height)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_viewPortWidth = width;
+    m_viewPortHeight = height;
+}
+
+void MainWindow::showMaemoInformationBox(const QString &message)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+#ifdef Q_WS_MAEMO_5
+    QMaemo5InformationBox::information(this, message, QMaemo5InformationBox::DefaultTimeout);
+#else
+    Q_UNUSED(message);
+#endif
+}
+
+void MainWindow::showPanels(bool show)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+    if(show) {
+        m_friendsListPanel->show();
+        m_friendsListPanelSidebar->show();
+        m_userPanel->show();
+        m_userPanelSidebar->show();
+    }
+    else {
+        m_friendsListPanel->closePanel();
+        m_friendsListPanel->hide();
+        m_friendsListPanelSidebar->hide();
+        m_userPanel->closePanel();
+        m_userPanel->hide();
+        m_userPanelSidebar->hide();
+    }
+}
 
+void MainWindow::startLoginProcess(const QUrl &url)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_loginUrl = url;
+    m_webView = new QWebView;
+    m_loginDialog = new LoginDialog(this);
+
+    connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
+            this, SIGNAL(updateCredentials(QUrl)));
+    connect(m_webView, SIGNAL(loadFinished(bool)),
+            this, SLOT(loadDone(bool)));
+
+    connect(m_loginDialog, SIGNAL(loginDialogDone(QString,QString)),
+            this, SLOT(loginDialogDone(QString,QString)));
+
+    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;
+        m_webView->stop();
+        disconnect(m_webView, SIGNAL(loadFinished(bool)),
+                   this, SLOT(loadDone(bool)));
+        disconnect(m_webView, SIGNAL(urlChanged(const QUrl &)),
+                   this, SLOT(updateCredentials(const QUrl &)));
+
+        emit cancelLoginProcess();
+    }
+    else {
+        m_webView->load(m_loginUrl);
+        toggleProgressIndicator(true);
+        m_refresh = true;
+    }
+}
+
+void MainWindow::toggleProgressIndicator(bool value)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+#ifdef Q_WS_MAEMO_5
+    setAttribute(Qt::WA_Maemo5ShowProgressIndicator, value);
+#else
+    Q_UNUSED(value);
+#endif // Q_WS_MAEMO_5
+}
+
+const QString MainWindow::username()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+    return m_email;
+}