Merge branch 'master' into zoom_button_drag
[situare] / src / ui / mainwindow.cpp
index fe9b120..8b58426 100644 (file)
@@ -5,6 +5,8 @@
       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 <QtWebKit>
 
 #ifdef Q_WS_MAEMO_5
 #include <QtMaemo5/QMaemo5InformationBox>
 #endif // Q_WS_MAEMO_5
 
-#include "mainwindow.h"
-#include "mapviewscreen.h"
-#include "settingsdialog.h"
+#include "common.h"
 #include "facebookservice/facebookauthentication.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),
-    m_email(),
-    m_loginUrl(),
+    m_drawOwnLocationCrosshair(false),
+    m_loggedIn(false),
+    m_refresh(false),
+    m_email(),    
     m_password(),
-    m_refresh(0),
+    m_loginUrl(),
     m_webView(0)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_mapViewScreen = new MapViewScreen(this);
-    setCentralWidget(m_mapViewScreen);
-    createMenus();
-    setWindowTitle(tr("Situare"));
-       show();
+    buildMap();
 
-    m_locationDialog = new UpdateLocationDialog(this);
+    // build main layout
+    QHBoxLayout *layout = new QHBoxLayout;
+    layout->addWidget(m_mapView);
+    layout->setMargin(0);
+    setCentralWidget(new QWidget());
+    centralWidget()->setLayout(layout);
 
-    connect(this, SIGNAL(reverseGeoReady(QString)),
-            m_locationDialog, SLOT(setAddress(QString)));
-    connect(m_locationDialog, SIGNAL(statusUpdate(QString,bool)), this,
-            SIGNAL(statusUpdate(QString,bool)));
+    buildFriendListPanel();
+    buildUserInfoPanel();
 
-    connect(this, SIGNAL(userLocationReady(User*)),
-            m_mapViewScreen, SIGNAL(userLocationReady(User*)));
-    connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
-            m_mapViewScreen, SIGNAL(friendsLocationsReady(QList<User*>&)));
+    createMenus();
+    setWindowTitle(tr("Situare"));
 
-    connect(this, SIGNAL(enableAutoCentering(bool)),
-            m_mapViewScreen, SLOT(enableAutoCentering(bool)));
-    connect(this, SIGNAL(positionReceived(QPointF)),
-            m_mapViewScreen, SLOT(positionReceived(QPointF)));
+    // 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);
 
     this->toggleProgressIndicator(true);
+
+    grabZoomKeys(true);
+
+    // set screen size in desktop matching N900 screen size
+    resize(N900_APP_WIDTH, N900_APP_HEIGHT);
 }
 
 MainWindow::~MainWindow()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
+    grabZoomKeys(false);
+
     if(m_webView)
         delete m_webView;
 }
 
-void MainWindow::toggleProgressIndicator(bool value)
+void MainWindow::buildFriendListPanel()
 {
     qDebug() << __PRETTY_FUNCTION__;
-#ifdef Q_WS_MAEMO_5
-    setAttribute(Qt::WA_Maemo5ShowProgressIndicator, value);
-#else
-    Q_UNUSED(value);
-#endif // Q_WS_MAEMO_5
+
+    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__;
 
+    // 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()));
+
+    // GPS
     m_gpsToggleAct = new QAction(tr("GPS"), this);
     m_gpsToggleAct->setCheckable(true);
-    m_gpsToggleAct->setChecked(true);
-    connect(m_gpsToggleAct, SIGNAL(toggled(bool)),
-        this, SLOT(gpsActionToggled(bool)));
+
+    connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
+            this, SIGNAL(gpsTriggered(bool)));
+
+    // automatic centering
     m_autoCenteringAct = new QAction(tr("Auto centering"), this);
     m_autoCenteringAct->setCheckable(true);
-    m_autoCenteringAct->setChecked(true);
-    connect(m_autoCenteringAct, SIGNAL(toggled(bool)),
-        this, SLOT(autoCenteringToggled(bool)));    
-       
-       m_viewMenu = menuBar()->addMenu(tr("Main"));
+    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->addAction(m_gpsToggleAct);
+    m_viewMenu->addAction(m_gpsToggleAct);
     m_viewMenu->addAction(m_autoCenteringAct);
     m_viewMenu->setObjectName(tr("Menu"));
 }
 
-void MainWindow::openLocationUpdateDialog()
+void MainWindow::drawOsmLicense(const QSize &size)
 {
-    qDebug() << __PRETTY_FUNCTION__;
+    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());
 
-    emit requestReverseGeo();
-    m_locationDialog->exec();
 }
 
-void MainWindow::openSettingsDialog()
+void MainWindow::drawOwnLocationCrosshair(int width, int height)
 {
     qDebug() << __PRETTY_FUNCTION__;
-    SettingsDialog *dialog = new SettingsDialog(this);
-    dialog->show();
+
+    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::gpsActionToggled(bool checked)
+void MainWindow::gpsError(const QString &message)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (checked) {
-        emit enableGPS(true);
-        showMaemoInformationBox(tr("GPS enabled"));
-        m_autoCenteringAct->setVisible(true);
-    }
-    else {
-        emit enableGPS(false);
-        showMaemoInformationBox(tr("GPS disabled"));
-        m_autoCenteringAct->setVisible(false);
-
-    }
+    showMaemoInformationBox(message);
 }
 
 void MainWindow::gpsTimeout()
@@ -152,72 +314,108 @@ void MainWindow::gpsTimeout()
     showMaemoInformationBox(tr("GPS timeout"));
 }
 
-void MainWindow::gpsError(const QString &message)
+void MainWindow::grabZoomKeys(bool grab)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    showMaemoInformationBox(message);
+#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::autoCenteringToggled(bool checked)
+void MainWindow::keyPressEvent(QKeyEvent* event)
 {
-    qDebug() << __PRETTY_FUNCTION__ << " " << checked;
+    qDebug() << __PRETTY_FUNCTION__;
 
-    if (checked) {
-        emit enableAutoCentering(true);
-        showMaemoInformationBox(tr("Auto centering enabled"));
-    }
-    else {
-        emit enableAutoCentering(false);
-        showMaemoInformationBox(tr("Auto centering disabled"));
+    switch (event->key()) {
+    case Qt::Key_F7:
+        event->accept();
+        emit zoomIn();
+        break;
+
+    case Qt::Key_F8:
+        event->accept();
+        emit zoomOut();
+        break;
     }
+    QWidget::keyPressEvent(event);
 }
 
-void MainWindow::showMaemoInformationBox(const QString &message)
+void MainWindow::loadDone(bool done)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-#ifdef Q_WS_MAEMO_5
-    QMaemo5InformationBox::information(this, message, QMaemo5InformationBox::DefaultTimeout);
-#else
-    Q_UNUSED(message);
-#endif
-}
-
-void MainWindow::startLoginProcess(const QUrl &url)
-{
-    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;
+    }
 
-    m_loginUrl = url;
-    m_webView = new QWebView;
-    m_loginDialog = new LoginDialog(this);
+    if (done)
+    {
+        QWebFrame* frame = m_webView->page()->currentFrame();
+        if (frame!=NULL)
+        {
+            // set email box
+            QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
 
-    connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
-            this, SIGNAL(updateCredentials(QUrl)));
-    connect(m_webView, SIGNAL(loadFinished(bool)),
-            this, SLOT(loadDone(bool)));
+            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());
 
-    connect(m_loginDialog, SIGNAL(loginDialogDone(QString,QString)),
-            this, SLOT(loginDialogDone(QString,QString)));
+                // 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);
+            }
+        }
+    }
+}
 
-    m_webView->hide();
+void MainWindow::loggedIn(bool logged)
+{
+    qDebug() << __PRETTY_FUNCTION__;
 
-    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 &)));
+    m_loggedIn = logged;
 
-        emit cancelLoginProcess();
+    if(logged) {
+        m_loginAct->setText(tr("Logout"));
     }
     else {
-        m_webView->load(m_loginUrl);
-        toggleProgressIndicator(true);
-        m_refresh = true;
+        m_loginAct->setText(tr("Login"));
     }
+    showPanels(m_loggedIn);
 }
 
 void MainWindow::loginDialogDone(const QString &email, const QString &password)
@@ -243,6 +441,10 @@ void MainWindow::loginFailed()
 
 #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;
@@ -261,46 +463,154 @@ void MainWindow::loginFailed()
     }
 }
 
-void MainWindow::loadDone(bool done)
+void MainWindow::openSettingsDialog()
 {
     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;
+    SettingsDialog *dialog = new SettingsDialog(this);
+    if(!m_loggedIn) {
+        dialog->disableSituareSettings();
     }
+    dialog->show();
+}
 
-    if (done)
-    {
-        QWebFrame* frame = m_webView->page()->currentFrame();
-        if (frame!=NULL)
-        {
-            // set email box
-            QWebElementCollection emailCollection = frame->findAllElements("input[name=email]");
+void MainWindow::setAutoCenteringButtonEnabled(bool enabled)
+{
+    qDebug() << __PRETTY_FUNCTION__;
 
-            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());
+    m_autoCenteringAct->setChecked(enabled);
+}
 
-                // 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::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 {
+        m_ownLocationCrosshair->hide();
+        m_drawOwnLocationCrosshair = false;
+    }
+}
+
+void MainWindow::setUsername(const QString &username)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+    m_email = username;
+}
+
+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;
 }