Modified search interesting people by tag to use maximum distance
[situare] / src / ui / mainwindow.cpp
index aeaedac..71ad6bc 100644 (file)
@@ -33,6 +33,7 @@
 #include <QMessageBox>
 
 #include "common.h"
+#include "engine/updatelocation.h"
 #include "error.h"
 #include "friendlistpanel.h"
 #include "fullscreenbutton.h"
@@ -41,6 +42,9 @@
 #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 "searchdialog.h"
@@ -76,8 +80,7 @@ MainWindow::MainWindow(QWidget *parent)
       m_crosshair(0),
       m_fullScreenButton(0),
       m_indicatorButtonPanel(0),
-      m_mapScale(0),
-      m_updateLocation(0)
+      m_mapScale(0)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -113,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()
@@ -126,16 +135,6 @@ MainWindow::~MainWindow()
 
     qDeleteAll(m_error_queue.begin(), m_error_queue.end());
     m_error_queue.clear();
-
-    QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
-
-    if (!m_backupMessage.isEmpty()) {
-        settings.setValue(USER_UNSEND_MESSAGE, m_backupMessage.toAscii());
-        settings.setValue(USER_UNSEND_MESSAGE_PUBLISH, m_backupFacebookPublishPolicity);
-    } else {
-        settings.remove(USER_UNSEND_MESSAGE);
-        settings.remove(USER_UNSEND_MESSAGE_PUBLISH);
-    }
 }
 
 void MainWindow::automaticUpdateDialogFinished(int result)
@@ -153,14 +152,6 @@ void MainWindow::automaticUpdateDialogFinished(int result)
     m_automaticUpdateLocationDialog->deleteLater();
 }
 
-void MainWindow::backupUpdateLocationDialogData(const QString &status, bool publish)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_backupMessage = status;
-    m_backupFacebookPublishPolicity = publish;
-}
-
 void MainWindow::buildCrosshair()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -194,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()
@@ -299,7 +293,7 @@ void MainWindow::buildLocationSearchPanel()
 
 void MainWindow::buildLoginDialog(QWebView *browser)
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     if (!m_loginDialog) {
         m_loginDialog = new QDialog(this);
@@ -364,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__;
@@ -388,6 +435,8 @@ void MainWindow::buildPanels()
     buildFriendListPanel();
     buildLocationSearchPanel();
     buildRoutingPanel();
+    buildMeetPeoplePanel();
+    buildMessagePanel();
 
     m_tabbedPanel = new TabbedPanel(this);
 
@@ -397,8 +446,12 @@ void MainWindow::buildPanels()
     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_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)));
@@ -430,7 +483,16 @@ void MainWindow::buildPanels()
     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)));
 
@@ -439,6 +501,12 @@ void MainWindow::buildPanels()
 
     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()
@@ -477,6 +545,24 @@ void MainWindow::buildUserInfoPanel()
 
     connect(m_userInfoPanel, SIGNAL(updateLocationMessageButtonClicked()),
             this, SLOT(showUpdateLocationDialog()));
+
+    connect(this, SIGNAL(userImageReady(QString,QPixmap)),
+            m_userInfoPanel, SLOT(setImage(QString,QPixmap)));
+
+    connect(m_userInfoPanel, SIGNAL(addTags(QStringList)),
+            this, SIGNAL(addTags(QStringList)));
+
+    connect(m_userInfoPanel, SIGNAL(removeTags(QStringList)),
+            this, SIGNAL(removeTags(QStringList)));
+
+    connect(this, SIGNAL(popularTagsReceived(QHash<QString,QString>&)),
+            m_userInfoPanel, SLOT(populatePopularTags(QHash<QString,QString>&)));
+
+    connect(m_userInfoPanel, SIGNAL(requestPopularTags()),
+            this, SIGNAL(requestPopularTags()));
+
+    connect(this, SIGNAL(userTagsReceived(QHash<QString,QString>&)),
+            m_userInfoPanel, SLOT(userTagsReceived(QHash<QString,QString>&)));
 }
 
 void MainWindow::buildZoomButtonPanel()
@@ -507,14 +593,6 @@ void MainWindow::buildZoomButtonPanel()
             this, SIGNAL(draggingModeTriggered()));
 }
 
-void MainWindow::clearUpdateLocationDialogData()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_backupMessage.clear();
-    m_backupFacebookPublishPolicity = false;
-}
-
 void MainWindow::createMenus()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -546,7 +624,7 @@ void MainWindow::createMenus()
 
 void MainWindow::destroyLoginDialog()
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     if (m_loginDialog) {
         m_loginDialog->hide();
@@ -561,10 +639,20 @@ void MainWindow::dialogFinished(int status)
 
     QDialog *dialog = m_queue.takeFirst();
     SearchDialog *searchDialog = qobject_cast<SearchDialog *>(dialog);
-    if ((searchDialog) && (status != 0))
-        emit searchForLocation(searchDialog->input());
-
-    dialog->deleteLater();
+    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();
+    }
 
     if(!m_error_queue.isEmpty() && m_errorShown == false) {
         showErrorInformationBox();
@@ -684,6 +772,7 @@ void MainWindow::loggedIn(bool logged)
     } else {
         m_loginAct->setText(tr("Login"));
         m_userInfoPanel->showUserInfo(false);
+        m_updateLocationController->clear();
     }
     updateItemVisibility(logged);
 }
@@ -753,15 +842,6 @@ void MainWindow::readAutomaticLocationUpdateSettings()
     }
 }
 
-void MainWindow::restoreUnsendMessage()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
-    m_backupMessage = settings.value(USER_UNSEND_MESSAGE).toString();
-    m_backupFacebookPublishPolicity = settings.value(USER_UNSEND_MESSAGE_PUBLISH, false).toBool();
-}
-
 void MainWindow::setCrosshairVisibility(bool visibility)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -814,6 +894,14 @@ void MainWindow::showContactDialog(const QString &guid)
 #endif
 }
 
+void MainWindow::showMessageDialog(const QPair<QString, QString> &receiver)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    MessageDialog *messageDialog = new MessageDialog(receiver.first, receiver.second);
+    queueDialog(messageDialog);
+}
+
 void MainWindow::showEnableAutomaticUpdateLocationDialog(const QString &text)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -857,42 +945,41 @@ void MainWindow::showUpdateLocationDialog()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    delete m_updateLocation;
-    m_updateLocation = new UpdateLocationDialog(m_backupMessage, m_backupFacebookPublishPolicity,
-                                                this);
+    UpdateLocationDialog *updateLocationDialog
+            = new UpdateLocationDialog(m_updateLocationController, this);
 
     connect(this, SIGNAL(reverseGeoReady(QString)),
-            m_updateLocation, SLOT(setAddress(QString)));
-
-    connect(m_updateLocation, SIGNAL(statusUpdate(QString, bool)),
-            this, SIGNAL(statusUpdate(QString, bool)));
+            updateLocationDialog, SLOT(setAddress(QString)));
 
-    connect(m_updateLocation, SIGNAL(statusUpdate(QString, bool)),
-            this, SLOT(backupUpdateLocationDialogData(QString, bool)));
-
-    connect(m_updateLocation, SIGNAL(finished(int)),
-            this, SLOT(updateLocationDialogFinished(int)));
-
-    m_updateLocation->show();
+    updateLocationDialog->show();
 
     emit requestReverseGeo();
 }
 
-void MainWindow::sslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
+void MainWindow::startLocationSearch()
 {
-    qWarning() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
-    reply->ignoreSslErrors();
+    SearchDialog *searchDialog = new SearchDialog(SearchDialog::Location);
+    queueDialog(searchDialog);
 }
 
-void MainWindow::startLocationSearch()
+void MainWindow::startPeopleSearch()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    SearchDialog *searchDialog = new SearchDialog();
+    SearchDialog *searchDialog = new SearchDialog(SearchDialog::PeopleTag);
     queueDialog(searchDialog);
 }
 
+void MainWindow::sslErrors(QNetworkReply *reply, const QList<QSslError> &errors)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    Q_UNUSED(errors)
+    reply->ignoreSslErrors();
+}
+
 void MainWindow::toggleFullScreen()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -929,27 +1016,3 @@ void MainWindow::updateItemVisibility(bool loggedIn)
 
     m_tabbedPanel->setTabsEnabled(m_situareTabsIndexes, loggedIn);
 }
-
-void MainWindow::updateLocationDialogFinished(int reason)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    Q_UNUSED(reason);
-
-    if (m_updateLocation) {
-        disconnect(this, SIGNAL(reverseGeoReady(QString)),
-                m_updateLocation, SLOT(setAddress(QString)));
-
-        disconnect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
-                this, SIGNAL(statusUpdate(QString,bool)));
-
-        disconnect(m_updateLocation, SIGNAL(statusUpdate(QString,bool)),
-                this, SLOT(backupUpdateLocationDialogData(QString,bool)));
-
-        disconnect(m_updateLocation, SIGNAL(finished(int)),
-                this, SLOT(updateLocationDialogFinished(int)));
-
-        m_updateLocation->deleteLater();
-        m_updateLocation = 0;
-    }
-}