Modified search interesting people by tag to use maximum distance
[situare] / src / ui / mainwindow.cpp
index 85daf47..71ad6bc 100644 (file)
    USA.
 */
 
+#include <QtAlgorithms>
+#include <QtWebKit>
+
 #include <QAction>
 #include <QApplication>
 #include <QMenuBar>
 #include <QMessageBox>
-#include <QtAlgorithms>
-#include <QtWebKit>
 
-///< @todo sort
-#include "facebookservice/facebookauthentication.h"
-#include "map/mapcommon.h"
-#include "map/mapview.h"
 #include "common.h"
+#include "engine/updatelocation.h"
 #include "error.h"
 #include "friendlistpanel.h"
 #include "fullscreenbutton.h"
 #include "indicatorbuttonpanel.h"
-#include "logindialog.h"
+#include "locationsearchpanel.h"
+#include "map/mapcommon.h"
+#include "map/mapview.h"
 #include "mapscale.h"
+#include "meetpeoplepanel.h"
+#include "messagedialog.h"
+#include "messagepanel.h"
 #include "panelcommon.h"
 #include "routingpanel.h"
-#include "tabbedpanel.h"
 #include "searchdialog.h"
 #include "settingsdialog.h"
+#include "situareservice/situarecommon.h"
+#include "tabbedpanel.h"
+#include "updatelocation/updatelocationdialog.h"
 #include "userinfopanel.h"
 #include "zoombuttonpanel.h"
 
-
 #include "mainwindow.h"
 
 // These MUST BE HERE, compiling for Maemo fails if moved
 #include <QtGui/QX11Info>
 #include <X11/Xatom.h>
 #include <X11/Xlib.h>
-#include "ossoabookdialog.h"
 #endif // Q_WS_MAEMO_5
 
+#if defined(Q_WS_MAEMO_5) & defined(ARMEL)
+#include "ossoabookdialog.h"
+#endif
+
 MainWindow::MainWindow(QWidget *parent)
     : QMainWindow(parent),
       m_errorShown(false),
@@ -69,14 +76,11 @@ MainWindow::MainWindow(QWidget *parent)
       m_refresh(false),
       m_mapCenterHorizontalShifting(0),
       m_progressIndicatorCount(0),
+      m_loginDialog(0),
       m_crosshair(0),
-      m_email(), ///< @todo WTF?!?!?!?
-      m_password(),
-      m_webView(0),
       m_fullScreenButton(0),
       m_indicatorButtonPanel(0),
-      m_mapScale(0),
-      m_cookieJar(0)
+      m_mapScale(0)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -92,11 +96,13 @@ MainWindow::MainWindow(QWidget *parent)
     setWindowTitle(tr("Situare"));
 
     // set stacking order of widgets (from top to bottom)
-    // if the fullscreen button exists, then it is the topmost one, otherwise the tabbed panel is
+    // m_tabbedPanel is the topmost one
     if (m_fullScreenButton) {
-        m_tabbedPanel->stackUnder(m_fullScreenButton);
+        m_fullScreenButton->stackUnder(m_tabbedPanel);
+        m_crosshair->stackUnder(m_fullScreenButton);
+    } else {
+        m_crosshair->stackUnder(m_tabbedPanel);
     }
-    m_crosshair->stackUnder(m_tabbedPanel);
     m_zoomButtonPanel->stackUnder(m_crosshair);
     m_indicatorButtonPanel->stackUnder(m_zoomButtonPanel);
     m_osmLicense->stackUnder(m_indicatorButtonPanel);
@@ -110,6 +116,12 @@ MainWindow::MainWindow(QWidget *parent)
 #ifdef Q_WS_MAEMO_5
     setAttribute(Qt::WA_Maemo5StackedWindow);
 #endif
+
+    m_updateLocationController = new UpdateLocation(this);
+
+    connect(this, SIGNAL(updateWasSuccessful()), m_updateLocationController, SLOT(clear()));
+    connect(m_updateLocationController, SIGNAL(locationUpdate(QString,bool)),
+            this, SIGNAL(locationUpdate(QString,bool)));
 }
 
 MainWindow::~MainWindow()
@@ -118,9 +130,6 @@ MainWindow::~MainWindow()
 
     grabZoomKeys(false);
 
-    if(m_webView)
-        delete m_webView;
-
     qDeleteAll(m_queue.begin(), m_queue.end());
     m_queue.clear();
 
@@ -135,7 +144,7 @@ void MainWindow::automaticUpdateDialogFinished(int result)
     if (result == QMessageBox::Yes) {
         readAutomaticLocationUpdateSettings();
     } else {
-        QSettings settings(DIRECTORY_NAME, FILE_NAME);
+        QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
         settings.setValue(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false);
         readAutomaticLocationUpdateSettings();
     }
@@ -176,14 +185,17 @@ void MainWindow::buildFriendListPanel()
     connect(m_friendsListPanel, SIGNAL(findFriend(GeoCoordinate)),
             this, SIGNAL(centerToCoordinates(GeoCoordinate)));
 
-    connect(this, SIGNAL(friendImageReady(User*)),
-            m_friendsListPanel, SLOT(friendImageReady(User*)));
+    connect(this, SIGNAL(friendImageReady(QString,QPixmap)),
+            m_friendsListPanel, SLOT(friendImageReady(QString,QPixmap)));
 
     connect(m_friendsListPanel, SIGNAL(routeToFriend(const GeoCoordinate&)),
             this, SIGNAL(routeTo(const GeoCoordinate&)));
 
     connect(m_friendsListPanel, SIGNAL(requestContactDialog(const QString &)),
             this, SIGNAL(requestContactDialog(const QString &)));
+
+    connect(m_friendsListPanel, SIGNAL(requestMessageDialog(QPair<QString, QString>)),
+            this, SIGNAL(requestMessageDialog(QPair<QString, QString>)));
 }
 
 void MainWindow::buildFullScreenButton()
@@ -254,6 +266,50 @@ void MainWindow::buildInformationBox(const QString &message, bool modal)
     queueDialog(msgBox);
 }
 
+void MainWindow::buildLocationSearchPanel()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_locationSearchPanel = new LocationSearchPanel(this);
+
+    connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
+            m_locationSearchPanel, SLOT(populateLocationListView(const QList<Location>&)));
+
+    connect(m_locationSearchPanel, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
+            this, SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
+
+    connect(m_locationSearchPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
+            this, SIGNAL(routeTo(const GeoCoordinate&)));
+
+    connect(m_locationSearchPanel, SIGNAL(requestSearchLocation()),
+            this, SLOT(startLocationSearch()));
+
+    connect(this, SIGNAL(searchForLocation(QString)),
+            m_locationSearchPanel, SLOT(prependSearchHistory(QString)));
+
+    connect(m_locationSearchPanel, SIGNAL(searchHistoryItemClicked(QString)),
+            this, SIGNAL(searchHistoryItemClicked(QString)));
+}
+
+void MainWindow::buildLoginDialog(QWebView *browser)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (!m_loginDialog) {
+        m_loginDialog = new QDialog(this);
+        if (m_loginDialog) {
+            m_loginDialog->setWindowTitle(tr("Login"));
+            m_loginDialog->setLayout(new QVBoxLayout());
+            m_loginDialog->layout()->addWidget(browser);
+            m_loginDialog->layout()->setContentsMargins(QMargins()); // zero margins
+            connect(m_loginDialog, SIGNAL(rejected()), this, SLOT(destroyLoginDialog()));
+        }
+    }
+
+    if (m_loginDialog)
+        m_loginDialog->show();
+}
+
 void MainWindow::buildMap()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -302,6 +358,59 @@ void MainWindow::buildMapScale()
             m_mapScale, SLOT(updateMapResolution(qreal)));
 }
 
+void MainWindow::buildMeetPeoplePanel()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_meetPeoplePanel = new MeetPeoplePanel(this);
+
+    connect(this, SIGNAL(friendImageReady(QString,QPixmap)),
+            m_meetPeoplePanel, SLOT(setImage(QString,QPixmap)));
+
+    connect(this, SIGNAL(interestingPeopleReceived(QList<User>&,QList<User>&)),
+            m_meetPeoplePanel, SLOT(populateInterestingPeopleListView(QList<User>&,QList<User>&)));
+
+    connect(m_meetPeoplePanel, SIGNAL(requestInterestingPeople()),
+            this, SIGNAL(requestInterestingPeople()));
+
+    connect(m_meetPeoplePanel, SIGNAL(requestInterestingPeopleSearch()),
+            this, SLOT(startPeopleSearch()));
+
+    connect(m_meetPeoplePanel, SIGNAL(findPerson(GeoCoordinate)),
+            this, SIGNAL(centerToCoordinates(GeoCoordinate)));
+
+    connect(m_meetPeoplePanel, SIGNAL(requestMessageDialog(QPair<QString, QString>)),
+            this, SIGNAL(requestMessageDialog(QPair<QString, QString>)));
+
+    connect(m_meetPeoplePanel, SIGNAL(requestShowFriend(QList<QString>)),
+            m_friendsListPanel, SLOT(showFriendsInList(QList<QString>)));
+}
+
+void MainWindow::buildMessagePanel()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_messagePanel = new MessagePanel(this);
+
+    connect(this, SIGNAL(messagesReceived(QList<Message>&, QList<Message>&)),
+            m_messagePanel, SLOT(populateMessageListView(QList<Message>&, QList<Message>&)));
+
+    connect(m_messagePanel, SIGNAL(requestMessages()),
+            this, SIGNAL(requestMessages()));
+
+    connect(this, SIGNAL(friendImageReady(QString,QPixmap)),
+            m_messagePanel, SLOT(setImage(QString,QPixmap)));
+
+    connect(m_messagePanel, SIGNAL(requestRemoveMessage(QString)),
+            this, SIGNAL(requestRemoveMessage(QString)));
+
+    connect(m_messagePanel, SIGNAL(findFriend(GeoCoordinate)),
+            this, SIGNAL(centerToCoordinates(GeoCoordinate)));
+
+    connect(m_messagePanel, SIGNAL(requestMessageDialog(QPair<QString, QString>)),
+            this, SIGNAL(requestMessageDialog(QPair<QString, QString>)));
+}
+
 void MainWindow::buildOsmLicense()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -324,21 +433,34 @@ void MainWindow::buildPanels()
 
     buildUserInfoPanel();
     buildFriendListPanel();
+    buildLocationSearchPanel();
     buildRoutingPanel();
+    buildMeetPeoplePanel();
+    buildMessagePanel();
 
     m_tabbedPanel = new TabbedPanel(this);
-    m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png"));
-    m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png"));
-    m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
+
+    //Save Situare related tab indexes so tabs can be enabled/disabled when logged in/out
+    m_situareTabsIndexes.append(
+            m_tabbedPanel->addTab(m_userInfoPanel, QIcon(":/res/images/user_info.png")));
+    m_situareTabsIndexes.append(
+            m_tabbedPanel->addTab(m_friendsListPanel, QIcon(":/res/images/friend_list.png")));
+
+//    m_tabbedPanel->addTab(m_locationSearchPanel, QIcon(":/res/images/location_search.png"));
+//    m_tabbedPanel->addTab(m_routingPanel, QIcon(":/res/images/routing.png"));
+    m_situareTabsIndexes.append(
+            m_tabbedPanel->addTab(m_meetPeoplePanel, QIcon(":/res/images/meet_people.png")));
+    m_situareTabsIndexes.append(
+            m_tabbedPanel->addTab(m_messagePanel, QIcon(":/res/images/message.png")));
 
     connect(m_mapView, SIGNAL(viewResized(QSize)),
             m_tabbedPanel, SLOT(resizePanel(QSize)));
 
-    connect(m_friendsListPanel, SIGNAL(showPanelRequested(QWidget*)),
-            m_tabbedPanel, SLOT(showPanel(QWidget*)));
+    connect(m_friendsListPanel, SIGNAL(openPanelRequested(QWidget*)),
+            m_tabbedPanel, SLOT(openPanel(QWidget*)));
 
-    connect(m_routingPanel, SIGNAL(showPanelRequested(QWidget*)),
-            m_tabbedPanel, SLOT(showPanel(QWidget*)));
+    connect(m_routingPanel, SIGNAL(openPanelRequested(QWidget*)),
+            m_tabbedPanel, SLOT(openPanel(QWidget*)));
 
     connect(m_tabbedPanel, SIGNAL(panelClosed()),
             m_friendsListPanel, SLOT(anyPanelClosed()));
@@ -354,6 +476,37 @@ void MainWindow::buildPanels()
 
     connect(m_tabbedPanel, SIGNAL(panelOpened()),
             m_mapView, SLOT(enableCenterShift()));
+
+    connect(m_tabbedPanel, SIGNAL(panelClosed()),
+            m_userInfoPanel, SIGNAL(collapse()));
+
+    connect(m_tabbedPanel, SIGNAL(currentChanged(int)),
+            m_userInfoPanel, SIGNAL(collapse()));
+
+    connect(m_tabbedPanel, SIGNAL(panelClosed()),
+            m_meetPeoplePanel, SLOT(anyPanelClosed()));
+
+    connect(m_tabbedPanel, SIGNAL(panelClosed()),
+            m_messagePanel, SLOT(anyPanelClosed()));
+
+    // signals for showing and hiding list item context buttons
+    connect(m_userInfoPanel, SIGNAL(listItemSelectionChanged(bool)),
+            m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
+
+    connect(m_friendsListPanel, SIGNAL(listItemSelectionChanged(bool)),
+            m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
+
+    connect(m_locationSearchPanel, SIGNAL(listItemSelectionChanged(bool)),
+            m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
+
+    connect(m_routingPanel, SIGNAL(listItemSelectionChanged(bool)),
+            m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
+
+    connect(m_meetPeoplePanel, SIGNAL(listItemSelectionChanged(bool)),
+            m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
+
+    connect(m_messagePanel, SIGNAL(listItemSelectionChanged(bool)),
+            m_tabbedPanel, SIGNAL(listItemSelectionChanged(bool)));
 }
 
 void MainWindow::buildRoutingPanel()
@@ -362,16 +515,8 @@ void MainWindow::buildRoutingPanel()
 
     m_routingPanel = new RoutingPanel(this);
 
-    connect(this, SIGNAL(locationDataParsed(const QList<Location>&)),
-            m_routingPanel, SLOT(populateLocationListView(const QList<Location>&)));
-
-    connect(m_routingPanel,
-            SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
-            this,
-            SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)));
-
-    connect(m_routingPanel, SIGNAL(routeToLocation(const GeoCoordinate&)),
-            this, SIGNAL(routeTo(const GeoCoordinate&)));
+    connect(m_routingPanel, SIGNAL(routeToCursor()),
+            this, SIGNAL(routeToCursor()));
 
     connect(this, SIGNAL(routeParsed(Route&)),
             m_routingPanel, SLOT(setRoute(Route&)));
@@ -379,8 +524,8 @@ void MainWindow::buildRoutingPanel()
     connect(m_routingPanel, SIGNAL(routeWaypointItemClicked(GeoCoordinate)),
             this, SIGNAL(centerToCoordinates(GeoCoordinate)));
 
-    connect(m_routingPanel, SIGNAL(requestSearchLocation()),
-            this, SLOT(startLocationSearch()));
+    connect(m_routingPanel, SIGNAL(clearRoute()),
+            this, SIGNAL(clearRoute()));
 }
 
 void MainWindow::buildUserInfoPanel()
@@ -392,49 +537,32 @@ void MainWindow::buildUserInfoPanel()
     connect(this, SIGNAL(userLocationReady(User*)),
             m_userInfoPanel, SLOT(userDataReceived(User*)));
 
-    connect(this, SIGNAL(reverseGeoReady(QString)),
-            m_userInfoPanel, SIGNAL(reverseGeoReady(QString)));
-
-    connect(this, SIGNAL(clearUpdateLocationDialogData()),
-            m_userInfoPanel, SIGNAL(clearUpdateLocationDialogData()));
-
     connect(m_userInfoPanel, SIGNAL(findUser(GeoCoordinate)),
             this, SIGNAL(centerToCoordinates(GeoCoordinate)));
 
-    connect(m_userInfoPanel, SIGNAL(requestReverseGeo()),
-            this, SIGNAL(requestReverseGeo()));
-
-    connect(m_userInfoPanel, SIGNAL(statusUpdate(QString,bool)),
-            this, SIGNAL(statusUpdate(QString,bool)));
-
     connect(m_userInfoPanel, SIGNAL(refreshUserData()),
             this, SIGNAL(refreshUserData()));
 
-    connect(m_userInfoPanel, SIGNAL(notificateUpdateFailing(QString, bool)),
-            this, SLOT(buildInformationBox(QString, bool)));
-}
+    connect(m_userInfoPanel, SIGNAL(updateLocationMessageButtonClicked()),
+            this, SLOT(showUpdateLocationDialog()));
 
-void MainWindow::buildWebView()
-{
-    qDebug() << __PRETTY_FUNCTION__;
+    connect(this, SIGNAL(userImageReady(QString,QPixmap)),
+            m_userInfoPanel, SLOT(setImage(QString,QPixmap)));
 
-    if(!m_webView) {
-        m_webView = new QWebView;
+    connect(m_userInfoPanel, SIGNAL(addTags(QStringList)),
+            this, SIGNAL(addTags(QStringList)));
 
-        if(!m_cookieJar)
-            m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
+    connect(m_userInfoPanel, SIGNAL(removeTags(QStringList)),
+            this, SIGNAL(removeTags(QStringList)));
 
-        m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
+    connect(this, SIGNAL(popularTagsReceived(QHash<QString,QString>&)),
+            m_userInfoPanel, SLOT(populatePopularTags(QHash<QString,QString>&)));
 
-        connect(m_webView->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*)),
-                this, SLOT(webViewRequestFinished(QNetworkReply*)));
-        connect(m_webView, SIGNAL(urlChanged(const QUrl &)),
-                this, SIGNAL(updateCredentials(QUrl)));
-        connect(m_webView, SIGNAL(loadFinished(bool)),
-                this, SLOT(loadDone(bool)));
+    connect(m_userInfoPanel, SIGNAL(requestPopularTags()),
+            this, SIGNAL(requestPopularTags()));
 
-        m_webView->hide();
-    }
+    connect(this, SIGNAL(userTagsReceived(QHash<QString,QString>&)),
+            m_userInfoPanel, SLOT(userTagsReceived(QHash<QString,QString>&)));
 }
 
 void MainWindow::buildZoomButtonPanel()
@@ -465,24 +593,6 @@ void MainWindow::buildZoomButtonPanel()
             this, SIGNAL(draggingModeTriggered()));
 }
 
-void MainWindow::clearCookieJar()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    buildWebView();
-
-    m_webView->stop();
-
-    if(!m_cookieJar) {
-        m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
-    }
-    QList<QNetworkCookie> emptyList;
-    emptyList.clear();
-
-    m_cookieJar->setAllCookies(emptyList);
-    m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
-}
-
 void MainWindow::createMenus()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -512,42 +622,38 @@ void MainWindow::createMenus()
     m_viewMenu->setObjectName(tr("Menu"));
 }
 
+void MainWindow::destroyLoginDialog()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (m_loginDialog) {
+        m_loginDialog->hide();
+        m_loginDialog->deleteLater();
+        m_loginDialog = 0;
+    }
+}
+
 void MainWindow::dialogFinished(int status)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     QDialog *dialog = m_queue.takeFirst();
-    LoginDialog *loginDialog = qobject_cast<LoginDialog *>(dialog);
     SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
-    if(loginDialog) {
-        if(status != 0) {
-            buildWebView();
-            loginDialog->userInput(m_email, m_password);
-
-            QStringList urlParts;
-            urlParts.append(FACEBOOK_LOGINBASE);
-            urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
-            urlParts.append(INTERVAL1);
-            urlParts.append(SITUARE_LOGIN_SUCCESS);
-            urlParts.append(INTERVAL2);
-            urlParts.append(SITUARE_LOGIN_FAILURE);
-            urlParts.append(FACEBOOK_LOGIN_ENDING);
-
-            emit saveUsername(m_email);
-            m_refresh = true;
-            m_webView->load(QUrl(urlParts.join(EMPTY)));
-            toggleProgressIndicator(true);
-        } else {
-            emit cancelLoginProcess();
-        }
-    } else if(searchDialog) {
-        if(status != 0) {
+    MessageDialog *messageDialog = qobject_cast<MessageDialog *>(dialog);    
+
+    if ((searchDialog) && (status != 0)) {
+        if (searchDialog->type() == SearchDialog::Location)
             emit searchForLocation(searchDialog->input());
-        }
+        else if (searchDialog->type() == SearchDialog::PeopleTag)
+            emit requestSearchPeopleByTag(searchDialog->input());
+
+        searchDialog->deleteLater();
+    } else if ((messageDialog) && (status != 0)) {
+        emit sendMessage(messageDialog->input().first, messageDialog->input().second,
+                         messageDialog->isAddCoordinatesSelected());
+        messageDialog->deleteLater();
     }
 
-    dialog->deleteLater();
-
     if(!m_error_queue.isEmpty() && m_errorShown == false) {
         showErrorInformationBox();
     } else {
@@ -655,72 +761,6 @@ void MainWindow::keyPressEvent(QKeyEvent* event)
     QWidget::keyPressEvent(event);
 }
 
-void MainWindow::loadCookies()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    QSettings settings(DIRECTORY_NAME, FILE_NAME);
-
-    QStringList list = settings.value(COOKIES, EMPTY).toStringList();
-
-    if(!list.isEmpty()) {
-        QList<QNetworkCookie> cookieList;
-        for(int i=0;i<list.count();i++) {
-            cookieList.append(QNetworkCookie::parseCookies(list.at(i).toAscii()));
-        }
-
-        if(!m_cookieJar)
-               m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
-
-        m_cookieJar->setAllCookies(cookieList);
-        m_webView->page()->networkAccessManager()->setCookieJar(m_cookieJar);
-    }
-}
-
-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__;
@@ -730,50 +770,11 @@ void MainWindow::loggedIn(bool logged)
     if(logged) {
         m_loginAct->setText(tr("Logout"));
     } else {
-        clearCookieJar();
-        m_email.clear();
-        m_password.clear();
-
         m_loginAct->setText(tr("Login"));
+        m_userInfoPanel->showUserInfo(false);
+        m_updateLocationController->clear();
     }
-    updateItemVisibility();
-}
-
-void MainWindow::loginFailed()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    clearCookieJar();
-    startLoginProcess();
-}
-
-bool MainWindow::loginState()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    return m_loggedIn;
-}
-
-void MainWindow::loginUsingCookies()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    toggleProgressIndicator(true);
-
-    buildWebView();
-    loadCookies();
-
-    QStringList urlParts;
-    urlParts.append(FACEBOOK_LOGINBASE);
-    urlParts.append(SITUARE_PUBLIC_FACEBOOKAPI_KEY);
-    urlParts.append(INTERVAL1);
-    urlParts.append(SITUARE_LOGIN_SUCCESS);
-    urlParts.append(INTERVAL2);
-    urlParts.append(SITUARE_LOGIN_FAILURE);
-    urlParts.append(FACEBOOK_LOGIN_ENDING);
-
-    m_webView->load(QUrl(urlParts.join(EMPTY)));
-
+    updateItemVisibility(logged);
 }
 
 void MainWindow::mapCenterHorizontalShiftingChanged(int shifting)
@@ -828,7 +829,7 @@ void MainWindow::readAutomaticLocationUpdateSettings()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QSettings settings(DIRECTORY_NAME, FILE_NAME);
+    QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
     bool automaticUpdateEnabled = settings.value(SETTINGS_AUTOMATIC_UPDATE_ENABLED, false).toBool();
     QTime automaticUpdateInterval = settings.value(SETTINGS_AUTOMATIC_UPDATE_INTERVAL, QTime())
                                       .toTime();
@@ -841,27 +842,6 @@ void MainWindow::readAutomaticLocationUpdateSettings()
     }
 }
 
-void MainWindow::saveCookies()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    if(!m_cookieJar)
-        m_cookieJar = new NetworkCookieJar(new QNetworkCookieJar(this));
-
-    QList<QNetworkCookie> cookieList = m_cookieJar->allCookies();
-    QStringList list;
-
-    for(int i=0;i<cookieList.count();i++) {
-        QNetworkCookie cookie = cookieList.at(i);
-        QByteArray byteArray = cookie.toRawForm(QNetworkCookie::Full);
-        list.append(QString(byteArray));
-    }
-    list.removeDuplicates();
-
-    QSettings settings(DIRECTORY_NAME, FILE_NAME);
-    settings.setValue(COOKIES, list);
-}
-
 void MainWindow::setCrosshairVisibility(bool visibility)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -902,20 +882,24 @@ void MainWindow::settingsDialogAccepted()
     readAutomaticLocationUpdateSettings();
 }
 
-void MainWindow::setUsername(const QString &username)
+void MainWindow::showContactDialog(const QString &guid)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_email = username;
+#if defined(Q_WS_MAEMO_5) & defined(ARMEL)
+    OssoABookDialog::showContactDialog(guid);
+#else
+    Q_UNUSED(guid);
+    buildInformationBox(tr("Contact dialog works only on phone!"), true);
+#endif
 }
 
-void MainWindow::showContactDialog(const QString &guid)
+void MainWindow::showMessageDialog(const QPair<QString, QString> &receiver)
 {
-    qDebug() << __PRETTY_FUNCTION__ << guid;
+    qDebug() << __PRETTY_FUNCTION__;
 
-#if defined(Q_WS_MAEMO_5) & defined(ARMEL)
-    OssoABookDialog::showContactDialog(guid);
-#endif
+    MessageDialog *messageDialog = new MessageDialog(receiver.first, receiver.second);
+    queueDialog(messageDialog);
 }
 
 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
@@ -957,47 +941,43 @@ void MainWindow::showInformationBox()
     }
 }
 
-void MainWindow::showPanels()
+void MainWindow::showUpdateLocationDialog()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-///< @todo check how this is called and can this method be removed
+    UpdateLocationDialog *updateLocationDialog
+            = new UpdateLocationDialog(m_updateLocationController, this);
 
-//    if(m_loggedIn) {
-//        if(!m_friendsListPanel->isVisible()) {
-//            m_friendsListPanel->show();
-//            m_friendsListPanelSidebar->show();
-//        }
+    connect(this, SIGNAL(reverseGeoReady(QString)),
+            updateLocationDialog, SLOT(setAddress(QString)));
+
+    updateLocationDialog->show();
 
-//        if(!m_userPanel->isVisible()) {
-//            m_userPanel->show();
-//            m_userPanelSidebar->show();
-//        }
-//    }
+    emit requestReverseGeo();
 }
 
 void MainWindow::startLocationSearch()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    SearchDialog *searchDialog = new SearchDialog();
+    SearchDialog *searchDialog = new SearchDialog(SearchDialog::Location);
     queueDialog(searchDialog);
 }
 
-void MainWindow::startLoginProcess()
+void MainWindow::startPeopleSearch()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    LoginDialog *loginDialog = new LoginDialog();
-
-    emit fetchUsernameFromSettings();
-
-    loginDialog->clearTextFields();
+    SearchDialog *searchDialog = new SearchDialog(SearchDialog::PeopleTag);
+    queueDialog(searchDialog);
+}
 
-    if(!m_email.isEmpty())
-        loginDialog->setEmailField(m_email);
+void MainWindow::sslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
+{
+    qDebug() << __PRETTY_FUNCTION__;
 
-    queueDialog(loginDialog);
+    Q_UNUSED(errors)
+    reply->ignoreSslErrors();
 }
 
 void MainWindow::toggleFullScreen()
@@ -1030,38 +1010,9 @@ void MainWindow::toggleProgressIndicator(bool value)
 #endif // Q_WS_MAEMO_5
 }
 
-void MainWindow::updateItemVisibility()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-///< @todo can this be removed?
-
-//    if(!m_loggedIn) {
-//        m_friendsListPanel->closePanel();
-//        m_friendsListPanel->hide();
-//        m_friendsListPanelSidebar->hide();
-
-//        m_userPanel->closePanel();
-//        m_userPanel->hide();
-//        m_userPanelSidebar->hide();
-//    }
-}
-
-const QString MainWindow::username()
+void MainWindow::updateItemVisibility(bool loggedIn)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    return m_email;
-}
-
-void MainWindow::webViewRequestFinished(QNetworkReply *reply)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    // omit QNetworkReply::OperationCanceledError due to it's nature to be called when ever
-    // qwebview starts to load a new page while the current page loading is not finished
-    if(reply->error() != QNetworkReply::OperationCanceledError &&
-       reply->error() != QNetworkReply::NoError) {
-        emit error(ErrorContext::NETWORK, reply->error());
-    }
+    m_tabbedPanel->setTabsEnabled(m_situareTabsIndexes, loggedIn);
 }