Connected get tag and fetch people with similar interest to
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Fri, 27 Aug 2010 11:47:58 +0000 (14:47 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Fri, 27 Aug 2010 11:47:58 +0000 (14:47 +0300)
MeetPeoplePanel.

16 files changed:
images.qrc
src/engine/engine.cpp
src/situareservice/database.cpp
src/situareservice/database.h
src/situareservice/situareservice.cpp
src/situareservice/situareservice.h
src/ui/mainwindow.cpp
src/ui/mainwindow.h
src/ui/meetpeoplepanel.cpp
src/ui/meetpeoplepanel.h
src/ui/userinfo.cpp
src/ui/userinfo.h
src/ui/userinfopanel.cpp
src/ui/userinfopanel.h
src/user/user.cpp
src/user/user.h

index 31d7570..e160f76 100644 (file)
@@ -58,7 +58,9 @@
         <file>res/images/zoom_in.png</file>
         <file>res/images/zoom_out.png</file>
         <file>res/images/meet_people.png</file>
-        <file>res/images/chat_button.png</file>
-        <file>res/images/chat_button_s.png</file>
+        <file>res/images/tag.png</file>
+        <file>res/images/tag_btn_d.png</file>
+        <file>res/images/tag_btn_s.png</file>
+        <file>res/images/tag_btn.png</file>
     </qresource>
 </RCC>
index 4f0359e..9df2d70 100644 (file)
@@ -755,6 +755,9 @@ void SituareEngine::signalsFromSituareService()
 
     connect(m_situareService, SIGNAL(updateWasSuccessful()),
             m_ui, SIGNAL(clearUpdateLocationDialogData()));
+
+    connect(m_situareService, SIGNAL(interestingPeopleReceived(QList<User*>&)),
+            m_ui, SIGNAL(interestingPeopleReceived(QList<User*>&)));
 }
 
 void SituareEngine::startAutomaticUpdate()
index 24cfe41..2873656 100644 (file)
@@ -16,12 +16,12 @@ Database::~Database()
     qDebug() << __PRETTY_FUNCTION__;
 }
 
-bool Database::addTag(int userId, const QString &tag)
+bool Database::addTag(qulonglong userId, const QString &tag)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     bool ret = false;
-    int tagId = -1;
+    qulonglong tagId = 0;
 
     if (m_database.isOpen()) {
         QSqlQuery tagQuery;
@@ -30,7 +30,7 @@ bool Database::addTag(int userId, const QString &tag)
 
         //Tag already exists
         if (ret && tagQuery.next()) {
-            tagId = tagQuery.value(0).toInt();
+            tagId = tagQuery.value(0).toULongLong();
         }
         else {
             QSqlQuery tagInsertQuery;
@@ -38,11 +38,11 @@ bool Database::addTag(int userId, const QString &tag)
                              .arg(tag));
 
             if (ret) {
-                tagId = tagInsertQuery.lastInsertId().toInt();
+                tagId = tagInsertQuery.lastInsertId().toULongLong();
             }
         }
 
-        if (ret && (tagId != -1)) {
+        if (ret && (tagId != 0)) {
             QSqlQuery userTagQuery;
 
             ret = userTagQuery.exec(QString("INSERT INTO usertag VALUES('%1', '%2')")
@@ -91,7 +91,7 @@ bool Database::createUserTagTable()
     return created;
 }
 
-QStringList Database::getInterestingPeople(int userId)
+QStringList Database::getInterestingPeople(qulonglong userId)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -107,7 +107,7 @@ QStringList Database::getInterestingPeople(int userId)
     return interestingPeopleId;
 }
 
-QStringList Database::getTags(int userId)
+QStringList Database::getTags(qulonglong userId)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -135,25 +135,3 @@ bool Database::openDatabase()
 
     return m_database.open();
 }
-
-void Database::test()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    bool ret = false;
-
-    QSqlQuery tagQuery(QString("SELECT * from tag"));
-    qWarning() << tagQuery.lastError().text();
-    qWarning() << "id" << "name";
-    while (tagQuery.next()) {
-         qWarning() << tagQuery.value(0).toString() << tagQuery.value(1).toString();
-     }
-
-    QSqlQuery userTagQuery(QString("SELECT * from usertag"));
-    qWarning() << userTagQuery.lastError().text();
-    qWarning() << "id" << "userid" << "tagid";
-    while (userTagQuery.next()) {
-         qWarning() << userTagQuery.value(0).toString() <<
-                 userTagQuery.value(1).toString() << userTagQuery.value(2).toString();
-     }
-}
index e4b1483..ad2434e 100644 (file)
@@ -15,13 +15,12 @@ public:
     Database(QObject *parent = 0);
     ~Database();
 
-    bool addTag(int userId, const QString &tag);
-    QStringList getTags(int userId);
-    QStringList getInterestingPeople(int userId);
+    bool addTag(qulonglong userId, const QString &tag);
+    QStringList getTags(qulonglong userId);
+    QStringList getInterestingPeople(qulonglong userId);
     bool openDatabase();
     bool createTagTable();
     bool createUserTagTable();
-    void test();
 
 private:
     QSqlDatabase m_database;
index 470cc90..a98f201 100644 (file)
@@ -76,7 +76,7 @@ void SituareService::fetchPeopleWithSimilarInterest()
     qDebug() << __PRETTY_FUNCTION__;
 
     QList<User *> interestingPeople;
-    QStringList userIds = m_database->getInterestingPeople(m_user->userId());
+    QStringList userIds = m_database->getInterestingPeople(m_user->userId().toULongLong());
 
     foreach (User *user, m_friendsList) {
         if (userIds.contains(user->userId()))
@@ -443,7 +443,7 @@ void SituareService::parseUserData(const QByteArray &jsonReply)
             }
             tmpFriendsList.clear();
 
-            //get user tags and set tags to the user
+            //REMOVE WHEN NOT NEEDED! get user tags and set tags to the user
             m_user->setTags(getTags(m_user->userId()));
 
             emit userDataChanged(m_user, m_friendsList);
@@ -454,6 +454,9 @@ void SituareService::parseUserData(const QByteArray &jsonReply)
 
             addProfileImages(imageUrlList);
             imageUrlList.clear();
+
+            //REMOVE WHEN NOT NEEDED! get interesting people
+            fetchPeopleWithSimilarInterest();
         } else {
             QVariant address = result.value("address");
             if(!address.toString().isEmpty()) {
index 56938b0..38c625f 100644 (file)
@@ -95,9 +95,10 @@ public:
     * @brief Updates tags to the Situare server
     *
     * CURRENTLY TAGS ARE UPDATED TO THE LOCAL DATABASE, NOT SITUARE SERVER
+    * @param userId user ID
     * @param tags list of user's tags
     */
-    void updateTags(const QStringList &tags);
+    void updateTags(const QString &userId, const QStringList &tags);
 
 public slots:
 
index b452c6a..9db3292 100644 (file)
@@ -304,11 +304,11 @@ void MainWindow::buildMeetPeoplePanel()
 {
     m_meetPeoplePanel = new MeetPeoplePanel(this);
 
-    connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
-            m_meetPeoplePanel, SLOT(populateNearbyFriendListView(QList<User*>&)));
-
     connect(this, SIGNAL(friendImageReady(User*)),
             m_meetPeoplePanel, SLOT(friendImageReady(User*)));
+
+    connect(this, SIGNAL(interestingPeopleReceived(QList<User*>&)),
+            m_meetPeoplePanel, SLOT(populateInterestingPeopleListView(QList<User*>&)));
 }
 
 void MainWindow::buildOsmLicense()
index 2f884e4..b165004 100644 (file)
@@ -499,6 +499,13 @@ signals:
     void gpsTriggered(bool enabled);
 
     /**
+    * @brief Signal when fetchPeopleWithSimilarInterest request is finished
+    *
+    * @param interestingPeople list of interesting people
+    */
+    void interestingPeopleReceived(QList<User *> &interestingPeople);
+
+    /**
      * @brief Signal for friend location ready.
      *
      * @param friendsList
index 1dfeb2d..189e40a 100644 (file)
@@ -28,16 +28,6 @@ MeetPeoplePanel::MeetPeoplePanel(QWidget *parent)
                                        PANEL_MARGIN_RIGHT, PANEL_MARGIN_BOTTOM);
     listViewLayout->addWidget(m_nearbyFriendListView);
     meetPeopleLayout->addLayout(listViewLayout);
-
-    ImageButton *searchPeopleButton = new ImageButton(0, ":/res/images/search.png",
-                                                             ":/res/images/search_s.png");
-    m_contextButtonList.append(searchPeopleButton);
-
-    m_chatButton = new ImageButton(0, ":/res/images/chat_button", ":/res/images/chat_button_s.png");
-    m_contextButtonList.append(m_chatButton);
-
-    connect(m_nearbyFriendListView, SIGNAL(listItemSelectionChanged()),
-            this, SLOT(setChatButtonDisabled()));
 }
 
 void MeetPeoplePanel::friendImageReady(User *user)
@@ -51,14 +41,14 @@ void MeetPeoplePanel::friendImageReady(User *user)
         item->setAvatarImage(user->profileImage());
 }
 
-void MeetPeoplePanel::populateNearbyFriendListView(QList<User *> &nearbyFriendList)
+void MeetPeoplePanel::populateInterestingPeopleListView(QList<User *> &interestingPeople)
 {
-    qDebug() << __PRETTY_FUNCTION__;
+    qWarning() << __PRETTY_FUNCTION__ ;
 
-    foreach (User *nearbyFriend, nearbyFriendList) {
+    foreach (User *interestingPerson, interestingPeople) {
         FriendListItem *item = new FriendListItem();
-        item->setUserData(nearbyFriend);
-        m_nearbyFriendListView->addListItem(nearbyFriend->userId(), item);
+        item->setUserData(interestingPerson);
+        m_nearbyFriendListView->addListItem(interestingPerson->userId(), item);
     }
 
     m_nearbyFriendListView->scrollToTop();
@@ -68,5 +58,5 @@ void MeetPeoplePanel::setChatButtonDisabled()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_chatButton->setDisabled(m_nearbyFriendListView->selectedItems().isEmpty());
+    //
 }
index 29c55c9..9af1c7b 100644 (file)
@@ -28,11 +28,11 @@ private slots:
     void friendImageReady(User *user);
 
     /**
-    * @brief Populates nearby friends list view.
+    * @brief Populates interesting people list view.
     *
-    * @param nearbyFriendList list of nearby friends
+    * @param interestingPeople list of interesting people
     */
-    void populateNearbyFriendListView(QList<User *> &nearbyFriendList);
+    void populateInterestingPeopleListView(QList<User *> &interestingPeople);
 
     /**
     * @brief Sets chat button disabled.
index d7e8f33..d05361d 100644 (file)
@@ -81,6 +81,10 @@ UserInfo::UserInfo(QWidget *parent)
     clockLabel->setPixmap(QPixmap(":/res/images/clock.png"));
     clockLabel->setContentsMargins(0, 0, MARGIN, 0);
     clockLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
+    QLabel *tagsLabel = new QLabel();
+    tagsLabel->setPixmap(QPixmap(":/res/images/tag.png"));
+    tagsLabel->setContentsMargins(0, 0, MARGIN, 0);
+    tagsLabel->setFixedSize(ICON_WIDTH + MARGIN, ICON_HEIGHT);
 
     m_findButton = new ImageButton();
 
@@ -93,10 +97,13 @@ UserInfo::UserInfo(QWidget *parent)
     m_locationLabel->setWordWrap(true);
     m_updatedLabel = new QLabel();
     m_updatedLabel->setWordWrap(true);
+    m_tagsTextLabel = new QLabel();
+    m_tagsTextLabel->setWordWrap(true);
 
     infoLayout->addRow(envelopeLabel, m_statusTextLabel);
     infoLayout->addRow(compassLabel, m_locationLabel);
     infoLayout->addRow(clockLabel, m_updatedLabel);
+    infoLayout->addRow(tagsLabel, m_tagsTextLabel);
 
     verticalLayout->addWidget(m_findButton, 0, Qt::AlignHCenter);
     verticalLayout->addWidget(m_nameLabel, 0, Qt::AlignHCenter);
@@ -181,6 +188,18 @@ void UserInfo::setProfileImage(const QPixmap &image)
         m_findButton->setButtonIcon(image);
 }
 
+void UserInfo::setTags(const QStringList &tags)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QString tagsText;
+
+    foreach (QString tag, tags)
+        tagsText.append("[" + tag + "] ");
+
+    m_tagsTextLabel->setText(tagsText);
+}
+
 void UserInfo::setTime(const QString &time)
 {
     qDebug() << __PRETTY_FUNCTION__;
index 7a90a64..64ef144 100644 (file)
@@ -107,6 +107,13 @@ public:
     void setProfileImage(const QPixmap &image);
 
     /**
+     * @brief Sets the user tags
+     *
+     * @param tags list of tags
+     */
+    void setTags(const QStringList &tags);
+
+    /**
      * @brief Sets the time of updated message
      *
      * @param time Reference to time when message was sent.
@@ -230,6 +237,7 @@ private:
     QLabel *m_locationLabel;                ///< Location label
     QLabel *m_nameLabel;                    ///< Name label
     QLabel *m_statusTextLabel;              ///< Status text label
+    QLabel *m_tagsTextLabel;                ///< Tags text label
     QLabel *m_updatedLabel;                 ///< Updated label
 
     QPixmap m_backgroundBottomImage;        ///< Bottom background image
index af8670a..60b0283 100644 (file)
@@ -86,14 +86,30 @@ UserInfoPanel::UserInfoPanel(QWidget *parent)
                                                              ":/res/images/send_position_s.png",
                                                              "", this);
 
+    ImageButton *tagButton = new ImageButton(":/res/images/tag_btn.png",
+                                                       ":/res/images/tag_btn_s.png",
+                                                       "/res/images/tag_btn_d", this);
+
+
     m_contextButtonLayout->addWidget(updateFriendsButton);
     m_contextButtonLayout->addWidget(updateStatusMessageButton);
+    m_contextButtonLayout->addWidget(tagButton);
 
     connect(updateFriendsButton, SIGNAL(clicked()),
             this, SIGNAL(refreshUserData()));
 
     connect(updateStatusMessageButton, SIGNAL(clicked()),
             m_userInfo, SLOT(messageUpdate()));
+
+    connect(tagButton, SIGNAL(clicked()),
+            this, SLOT(showTagDialog()));
+}
+
+void UserInfoPanel::showTagDialog()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+
 }
 
 void UserInfoPanel::userDataReceived(User *user)
@@ -107,5 +123,6 @@ void UserInfoPanel::userDataReceived(User *user)
         m_userInfo->setAddress(user->address());
         m_userInfo->setTime(user->timestamp());
         m_userInfo->setCoordinates(user->coordinates());
+        m_userInfo->setTags(user->tags());
     }
 }
index 47bdfc9..32f1567 100644 (file)
@@ -110,6 +110,9 @@ signals:
      */
     void clearUpdateLocationDialogData();
 
+private slots:
+    void showTagDialog();
+
 /*******************************************************************************
  * DATA MEMBERS
  ******************************************************************************/
index 351a353..bb1cab2 100644 (file)
@@ -24,7 +24,7 @@
 User::User(const QString &address, const GeoCoordinate &coordinates, const QString &name,
            const QString &note, const QUrl &imageUrl, const QString &timestamp, const bool &type,
            const QString &userId, const QString &units, const double &value,
-           const QStringList &tags = QStringList())
+           const QStringList &tags)
                : m_address(address)
                , m_coordinates(coordinates)
                , m_name(name)
index b24c9a1..f16c2d1 100644 (file)
@@ -45,7 +45,7 @@ public:
     User(const QString &address, const GeoCoordinate &coordinates, const QString &name,
          const QString &note, const QUrl &imageUrl, const QString &timestamp,
          const bool &type, const QString &userId, const QString &units = 0,
-         const double &value = 0);
+         const double &value = 0, const QStringList &tags = QStringList());
 
     /**
     * @brief Default constructor, initializes member data as NULL/0