Modified TagsDialog.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Fri, 5 Nov 2010 13:56:38 +0000 (15:56 +0200)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Fri, 5 Nov 2010 13:56:38 +0000 (15:56 +0200)
33 files changed:
src/engine/engine.cpp
src/situareservice/database.cpp
src/situareservice/database.h
src/situareservice/message.cpp
src/situareservice/message.h
src/situareservice/situareservice.cpp
src/situareservice/situareservice.h
src/src.pro
src/ui/listitem.cpp
src/ui/listitem.h
src/ui/listview.cpp
src/ui/listview.h
src/ui/mainwindow.cpp
src/ui/mainwindow.h
src/ui/meetpeoplepanel.cpp
src/ui/meetpeoplepanel.h
src/ui/messagelistitem.cpp
src/ui/messagepanel.cpp
src/ui/personlistitem.cpp
src/ui/personlistitem.h
src/ui/tagcompletion.cpp [new file with mode: 0644]
src/ui/tagcompletion.h [new file with mode: 0644]
src/ui/tagsdialog.cpp
src/ui/tagsdialog.h
src/ui/userinfo.cpp
tests/stubs/extendedlistitem.h
tests/stubs/listitem.h
tests/stubs/listview.h
tests/stubs/personlistitem.h
tests/stubs/personlistview.h
tests/ui/listview/listview.pro [new file with mode: 0644]
tests/ui/listview/testlistview.cpp [new file with mode: 0644]
tests/ui/meetpeoplepanel/meetpeoplepanel.pro

index 35fe815..561e857 100644 (file)
@@ -859,8 +859,8 @@ void SituareEngine::signalsFromSituareService()
     connect(m_situareService, SIGNAL(updateWasSuccessful(SituareService::SuccessfulMethod)),
             m_ui, SIGNAL(clearUpdateLocationDialogData()));
 
-    connect(m_situareService, SIGNAL(interestingPeopleReceived(QList<User>&)),
-            m_ui, SIGNAL(interestingPeopleReceived(QList<User>&)));
+    connect(m_situareService, SIGNAL(interestingPeopleReceived(QList<User>&,QList<User>&)),
+            m_ui, SIGNAL(interestingPeopleReceived(QList<User>&,QList<User>&)));
 
     connect(m_situareService, SIGNAL(messagesReceived(QList<Message>&, QList<Message> &)),
             m_ui, SIGNAL(messagesReceived(QList<Message>&, QList<Message>&)));
index 82b78d3..29190b1 100644 (file)
@@ -25,12 +25,19 @@ bool Database::addTag(qulonglong userId, const QString &tag)
 
     if (m_database.isOpen()) {
         QSqlQuery tagQuery;
-        ret = tagQuery.exec(QString("SELECT id FROM tag WHERE name = '%1'")
+        ret = tagQuery.exec(QString("SELECT id, count FROM tag WHERE name = '%1'")
                          .arg(tag));
 
         //Tag already exists
         if (ret && tagQuery.next()) {
+            qWarning() << tagQuery.value(1).toInt();
+            int count = tagQuery.value(1).toInt() + 1;
+            qWarning() << count;
+            QSqlQuery tagUpdateQuery;
+            tagUpdateQuery.exec(QString("UPDATE tag SET count = '%1' WHERE id = '%2'")
+                             .arg(count).arg(tagQuery.value(0).toString()));
             tagId = tagQuery.value(0).toULongLong();
+            qWarning() << tagUpdateQuery.lastQuery();
         }
         else {
             QSqlQuery tagInsertQuery;
@@ -142,11 +149,16 @@ QByteArray Database::getInterestingPeopleByTag(qulonglong userId, const QString
 {
     qDebug() << __PRETTY_FUNCTION__;
 
+    //People start
+    QString result;
+    result.append("{\"people\": {");
+
     QHash<QString, QString> tags;
 
+    //Get tags
     QSqlQuery tagQuery(QString("SELECT DISTINCT usertag.userid, tag.name FROM usertag, tag WHERE "
-                               "usertag.tagid = tag.id AND usertag.userid != '%1' AND "
-                               "tag.name LIKE '%2'").arg(userId).arg(tag));
+                                   "usertag.tagid = tag.id AND usertag.userid != '%1' AND "
+                                   "tag.name LIKE '\%%2\%'").arg(userId).arg(tag));
 
     while (tagQuery.next()) {
         QString userId = tagQuery.value(0).toString();
@@ -167,25 +179,72 @@ QByteArray Database::getInterestingPeopleByTag(qulonglong userId, const QString
     while (i.hasNext())
         userIds.append(i.next().key());
 
-    QSqlQuery userQuery(QString("SELECT user.id, user.name, user.image_url FROM user WHERE "
-                                "user.id IN (") + userIds.join(", ") + QString(")"));
-    QString result;
-    result.append("{\"people\": [");
+    //Get friends
+    result.append("\"friends\": [");
+
+    QSqlQuery friendQuery(QString("SELECT user.id, user.name, user.image_url, user.latitude, "
+                                  "user.longitude FROM user WHERE "
+                                  "user.id IN (") + userIds.join(", ") + QString(") AND "
+                                  "user.id IN "
+                                  "(SELECT friend.uid2 FROM friend WHERE friend.uid1 = '%1' "
+                                  "UNION "
+                                  "SELECT friend.uid1 FROM friend WHERE friend.uid2 = '%1')")
+                .arg(userId));
+
+    bool friendRemoveLast = false;
 
-    while (userQuery.next()) {
+    while (friendQuery.next()) {
+        friendRemoveLast = true;
         result.append("{");
-        result.append("\"uid\": \"" + userQuery.value(0).toString() + "\",");
-        result.append("\"name\": \"" + userQuery.value(1).toString() + "\",");
-        result.append("\"image_url\": \"" + userQuery.value(2).toString() + "\",");
-        result.append("\"tags\": [" + tags.value(userQuery.value(0).toString()) + "]");
+        result.append("\"uid\": \"" + friendQuery.value(0).toString() + "\",");
+        result.append("\"name\": \"" + friendQuery.value(1).toString() + "\",");
+        result.append("\"image_url\": \"" + friendQuery.value(2).toString() + "\",");
+        result.append("\"latitude\": \"" + friendQuery.value(3).toString() + "\",");
+        result.append("\"longitude\": \"" + friendQuery.value(4).toString() + "\",");
+        result.append("\"tags\": [" + tags.value(friendQuery.value(0).toString()) + "]");
         result.append("},");
     }
 
-    int lastComma = result.lastIndexOf(",");
-    if (lastComma != -1)
-        result.remove(result.lastIndexOf(","), 1);
+    if (friendRemoveLast) {
+        int friendLastComma = result.lastIndexOf(",");
+        if (friendLastComma != -1)
+            result.remove(result.lastIndexOf(","), 1);
+    }
+
+    result.append("],");
+
+    //Get others
+    result.append("\"others\": [");
+
+    QSqlQuery otherQuery(QString("SELECT user.id, user.name, user.image_url FROM user WHERE "
+                                  "user.id IN (") + userIds.join(", ") + QString(") AND "
+                                  "user.id NOT IN "
+                                  "(SELECT friend.uid2 FROM friend WHERE friend.uid1 = '%1' "
+                                  "UNION "
+                                  "SELECT friend.uid1 FROM friend WHERE friend.uid2 = '%1')")
+                .arg(userId));
 
-    result.append("]}");
+    bool otherRemoveLast = false;
+
+    while (otherQuery.next()) {
+        otherRemoveLast = true;
+        result.append("{");
+        result.append("\"uid\": \"" + otherQuery.value(0).toString() + "\",");
+        result.append("\"name\": \"" + otherQuery.value(1).toString() + "\",");
+        result.append("\"image_url\": \"" + otherQuery.value(2).toString() + "\",");;
+        result.append("\"tags\": [" + tags.value(otherQuery.value(0).toString()) + "]");
+        result.append("},");
+    }
+
+    if (otherRemoveLast) {
+        int otherLastComma = result.lastIndexOf(",");
+        if (otherLastComma != -1)
+            result.remove(result.lastIndexOf(","), 1);
+    }
+
+    result.append("]");
+
+    result.append("}}");
 
     return result.toUtf8();
 }
@@ -203,7 +262,7 @@ QByteArray Database::getInterestingPeople(qulonglong userId,
 
     QHash<QString, QString> tags;
 
-    //Get all
+    //Get tags
     QSqlQuery tagQuery(QString("SELECT usertag.userid, tag.name FROM usertag, tag WHERE "
                                "usertag.tagid IN (SELECT usertag.tagid FROM usertag WHERE "
                                "usertag.userid = '%1') AND usertag.userid != '%2' "
@@ -223,63 +282,83 @@ QByteArray Database::getInterestingPeople(qulonglong userId,
         }
     }
 
-    QStringList friendIds;
+    QStringList userIds;
     QHashIterator<QString, QString> i(tags);
     while (i.hasNext())
-        friendIds.append(i.next().key());
+        userIds.append(i.next().key());
 
+    //Get friends
     result.append("\"friends\": [");
 
-    //Get friends
-    //(SELECT friend.uid2 FROM friend WHERE friend.uid1 = 613374451
-    //UNION
-    //SELECT friend.uid1 FROM friend WHERE friend.uid2 = 613374451)
-
-    QSqlQuery friendQuery(QString("SELECT user.id, user.name, user.image_url FROM user WHERE "
-                                "user.id IN (") + friendIds.join(", ") + QString(") AND "
-                                "user.latitude >= '%1' AND user.latitude < '%2' AND "
-                                "user.longitude >= '%3' AND user.longitude < '%4'")
+    QSqlQuery friendQuery(QString("SELECT user.id, user.name, user.image_url, user.latitude, "
+                                  "user.longitude FROM user WHERE "
+                                  "user.id IN (") + userIds.join(", ") + QString(") AND "
+                                  "user.latitude >= '%1' AND user.latitude < '%2' AND "
+                                  "user.longitude >= '%3' AND user.longitude < '%4' AND user.id IN "
+                                  "(SELECT friend.uid2 FROM friend WHERE friend.uid1 = '%5' "
+                                  "UNION "
+                                  "SELECT friend.uid1 FROM friend WHERE friend.uid2 = '%5')")
                 .arg(southWestCoordinates.latitude()).arg(northEastCoordinates.latitude())
-                .arg(southWestCoordinates.longitude()).arg(northEastCoordinates.longitude()));
+                .arg(southWestCoordinates.longitude()).arg(northEastCoordinates.longitude())
+                .arg(userId));
+
+    bool friendRemoveLast = false;
 
     while (friendQuery.next()) {
+        friendRemoveLast = true;
         result.append("{");
         result.append("\"uid\": \"" + friendQuery.value(0).toString() + "\",");
         result.append("\"name\": \"" + friendQuery.value(1).toString() + "\",");
         result.append("\"image_url\": \"" + friendQuery.value(2).toString() + "\",");
+        result.append("\"latitude\": \"" + friendQuery.value(3).toString() + "\",");
+        result.append("\"longitude\": \"" + friendQuery.value(4).toString() + "\",");
         result.append("\"tags\": [" + tags.value(friendQuery.value(0).toString()) + "]");
         result.append("},");
     }
 
-    int friendLastComma = result.lastIndexOf(",");
-    if (friendLastComma != -1)
-        result.remove(result.lastIndexOf(","), 1);
+    if (friendRemoveLast) {
+        int friendLastComma = result.lastIndexOf(",");
+        if (friendLastComma != -1)
+            result.remove(result.lastIndexOf(","), 1);
+    }
 
     result.append("],");
 
-    QSqlQuery othersQuery(QString("SELECT user.id, user.name, user.image_url FROM user WHERE "
-                                "user.id IN (") + friendIds.join(", ") + QString(") AND "
-                                "user.latitude >= '%1' AND user.latitude < '%2' AND "
-                                "user.longitude >= '%3' AND user.longitude < '%4'")
+    //Get others
+    result.append("\"others\": [");
+
+    QSqlQuery otherQuery(QString("SELECT user.id, user.name, user.image_url FROM user WHERE "
+                                  "user.id IN (") + userIds.join(", ") + QString(") AND "
+                                  "user.latitude >= '%1' AND user.latitude < '%2' AND "
+                                  "user.longitude >= '%3' AND user.longitude < '%4' AND user.id "
+                                  "NOT IN "
+                                  "(SELECT friend.uid2 FROM friend WHERE friend.uid1 = '%5' "
+                                  "UNION "
+                                  "SELECT friend.uid1 FROM friend WHERE friend.uid2 = '%5')")
                 .arg(southWestCoordinates.latitude()).arg(northEastCoordinates.latitude())
-                .arg(southWestCoordinates.longitude()).arg(northEastCoordinates.longitude()));
+                .arg(southWestCoordinates.longitude()).arg(northEastCoordinates.longitude())
+                .arg(userId));
 
-    while (othersQuery.next()) {
+    bool otherRemoveLast = false;
+
+    while (otherQuery.next()) {
+        otherRemoveLast = true;
         result.append("{");
-        result.append("\"uid\": \"" + othersQuery.value(0).toString() + "\",");
-        result.append("\"name\": \"" + othersQuery.value(1).toString() + "\",");
-        result.append("\"image_url\": \"" + othersQuery.value(2).toString() + "\",");
-        result.append("\"tags\": [" + tags.value(othersQuery.value(0).toString()) + "]");
+        result.append("\"uid\": \"" + otherQuery.value(0).toString() + "\",");
+        result.append("\"name\": \"" + otherQuery.value(1).toString() + "\",");
+        result.append("\"image_url\": \"" + otherQuery.value(2).toString() + "\",");;
+        result.append("\"tags\": [" + tags.value(otherQuery.value(0).toString()) + "]");
         result.append("},");
     }
 
-    int friendLastComma = result.lastIndexOf(",");
-    if (friendLastComma != -1)
-        result.remove(result.lastIndexOf(","), 1);
+    if (otherRemoveLast) {
+        int otherLastComma = result.lastIndexOf(",");
+        if (otherLastComma != -1)
+            result.remove(result.lastIndexOf(","), 1);
+    }
 
     result.append("]");
 
-    //People end
     result.append("}}");
 
     return result.toUtf8();
@@ -304,7 +383,10 @@ QByteArray Database::getNotifications(qulonglong userId)
 
     result.append("\"received\": [");
 
+    bool receivedRemoveLast = false;
+
     while (receivedQuery.next()) {
+        receivedRemoveLast = true;
         result.append("{");
         result.append("\"id\": \"" + receivedQuery.value(0).toString() + "\",");
         result.append("\"sender_id\": \"" + receivedQuery.value(1).toString() + "\",");
@@ -313,14 +395,17 @@ QByteArray Database::getNotifications(qulonglong userId)
         result.append("\"image_url\": \"" + receivedQuery.value(4).toString() + "\",");
         result.append("\"timestamp\": \"" + receivedQuery.value(5).toString() + "\",");
         result.append("\"text\": \"" + receivedQuery.value(6).toString() + "\",");
+        result.append("\"address\": \"" + QString("Address 13, Oulu") + "\",");
         result.append("\"latitude\": \"" + receivedQuery.value(7).toString() + "\",");
         result.append("\"longitude\": \"" + receivedQuery.value(8).toString() + "\"");
         result.append("},");
     }
 
-    int receivedLastComma = result.lastIndexOf(",");
-    if (receivedLastComma != -1)
-        result.remove(result.lastIndexOf(","), 1);
+    if (receivedRemoveLast) {
+        int receivedLastComma = result.lastIndexOf(",");
+        if (receivedLastComma != -1)
+            result.remove(result.lastIndexOf(","), 1);
+    }
 
     result.append("],");
 
@@ -336,7 +421,10 @@ QByteArray Database::getNotifications(qulonglong userId)
 
     result.append("\"sent\": [");
 
+    bool sentRemoveLast = false;
+
     while (sentQuery.next()) {
+        sentRemoveLast = true;
         result.append("{");
         result.append("\"id\": \"" + sentQuery.value(0).toString() + "\",");
         result.append("\"sender_id\": \"" + sentQuery.value(1).toString() + "\",");
@@ -345,19 +433,47 @@ QByteArray Database::getNotifications(qulonglong userId)
         result.append("\"image_url\": \"" + sentQuery.value(4).toString() + "\",");
         result.append("\"timestamp\": \"" + sentQuery.value(5).toString() + "\",");
         result.append("\"text\": \"" + sentQuery.value(6).toString() + "\",");
+        result.append("\"address\": \"" + QString("Address 13, Oulu") + "\",");
         result.append("\"latitude\": \"" + sentQuery.value(7).toString() + "\",");
         result.append("\"longitude\": \"" + sentQuery.value(8).toString() + "\"");
         result.append("},");
     }
 
+    if (sentRemoveLast) {
+        int lastComma = result.lastIndexOf(",");
+        if (lastComma != -1)
+            result.remove(result.lastIndexOf(","), 1);
+    }
+
+    result.append("]");
+
+    result.append("}}");
+
+    return result.toUtf8();
+}
+
+QByteArray Database::getPopularTags()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QSqlQuery query(QString("SELECT tag.id, tag.name FROM tag ORDER BY count DESC LIMIT 10"));
+
+    QString result;
+    result.append("{\"popular_tags\": [");
+
+    while (query.next()) {
+        result.append("{");
+        result.append("\"id\": \"" + query.value(0).toString() + "\",");
+        result.append("\"name\": \"" + query.value(1).toString() + "\"");
+        result.append("},");
+    }
+
     int lastComma = result.lastIndexOf(",");
     if (lastComma != -1)
         result.remove(result.lastIndexOf(","), 1);
 
     result.append("]");
 
-    result.append("}}");
-
     return result.toUtf8();
 }
 
index 59e09d9..8c13aed 100644 (file)
@@ -20,6 +20,7 @@ public:
 
     bool addTag(qulonglong userId, const QString &tag);
     QByteArray getNotifications(qulonglong userId);
+    QByteArray getPopularTags();
     QHash<QString, QString> getTags(qulonglong userId);
     QByteArray getInterestingPeople(qulonglong userId,
                                      const GeoCoordinate &southWestCoordinates,
index 0c3923c..0652600 100644 (file)
@@ -4,6 +4,7 @@
 
 Message::Message(const Type type)
     : m_timestamp(QDateTime()),
+      m_address(QString()),
       m_id(QString()),
       m_image(QPixmap()),
       m_receiverId(QString()),
@@ -17,6 +18,13 @@ Message::Message(const Type type)
     qDebug() << __PRETTY_FUNCTION__;
 }
 
+const QString &Message::address() const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_address;
+}
+
 const GeoCoordinate &Message::coordinates() const
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -60,6 +68,13 @@ const QString &Message::senderName() const
     return m_senderName;
 }
 
+void Message::setAddress(const QString &address)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_address = address;
+}
+
 void Message::setCoordinates(const GeoCoordinate &coordinates)
 {
     qDebug() << __PRETTY_FUNCTION__;
index c8c2516..6fc8b1e 100644 (file)
@@ -51,6 +51,13 @@ public:
  ******************************************************************************/
  public:
     /**
+    * @brief Returns message's address
+    *
+    * @return message's address
+    */
+    const QString &address() const;
+
+    /**
     * @brief Returns message's coordinates
     *
     * @return message's coordinates as GeoCoordinate
@@ -93,6 +100,13 @@ public:
     const QString &senderName() const;
 
     /**
+    * @brief Sets message's address
+    *
+    * @param address message's address
+    */
+    void setAddress(const QString &address);
+
+    /**
     * @brief Sets message's coordinates
     *
     * @param coordinates message's coordinates
@@ -195,6 +209,7 @@ public:
  ******************************************************************************/
 private:
     QDateTime m_timestamp;          ///< message's timestamp
+    QString m_address;              ///< message's address
     QString m_id;                   ///< message's ID
     QPixmap m_image;                ///< message's image
     QString m_receiverId;           ///< message receiver's ID
index d00ddbc..6493ad3 100644 (file)
@@ -99,6 +99,15 @@ void SituareService::fetchPeopleWithSimilarInterest(const GeoCoordinate &southWe
     parseInterestingPeopleData(arr);
 }
 
+void SituareService::fetchPopularTags()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QByteArray arr = m_database->getPopularTags();
+
+    parsePopularTagsData(arr);
+}
+
 void SituareService::fetchLocations()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -342,9 +351,12 @@ void SituareService::parseInterestingPeopleData(const QByteArray &jsonReply)
         emit error(ErrorContext::SITUARE, SituareError::INVALID_JSON);
         return;
     } else {
-        QList<User> interestingPeople;
+        QVariant people = result["people"];
+
+        QList<User> friends;
+        QList<User> others;
 
-        foreach (QVariant personVariant, result["people"].toList()) {
+        foreach (QVariant personVariant, people.toMap().value("friends").toList()) {
             User user;
             QMap<QString, QVariant> person = personVariant.toMap();
             user.setUserId(person["uid"].toString());
@@ -353,13 +365,38 @@ void SituareService::parseInterestingPeopleData(const QByteArray &jsonReply)
                     QPixmap(":/res/images/empty_avatar.png"), AvatarImage::Small));
             user.setProfileImageUrl(person["image_url"].toUrl());
             user.setTags(person["tags"].toList());
-            interestingPeople.append(user);
+
+            bool latOk;
+            qreal latitude = person["latitude"].toReal(&latOk);
+            bool lonOk;
+            qreal longitude = person["longitude"].toReal(&lonOk);
+
+            if (latOk && lonOk)
+                user.setCoordinates(GeoCoordinate(latitude, longitude));
+
+            friends.append(user);
 
             //Remove comment when the actual server is used
             //emit fetchImage(user.userId(), user.profileImageUrl());
         }
 
-        emit interestingPeopleReceived(interestingPeople);
+        foreach (QVariant personVariant, people.toMap().value("others").toList()) {
+            User user;
+            QMap<QString, QVariant> person = personVariant.toMap();
+            user.setUserId(person["uid"].toString());
+            user.setName(person["name"].toString());
+            user.setProfileImage(AvatarImage::create(
+                    QPixmap(":/res/images/empty_avatar.png"), AvatarImage::Small));
+            user.setProfileImageUrl(person["image_url"].toUrl());
+            user.setTags(person["tags"].toList());
+
+            others.append(user);
+
+            //Remove comment when the actual server is used
+            //emit fetchImage(user.userId(), user.profileImageUrl());
+        }
+
+        emit interestingPeopleReceived(friends, others);
     }
 }
 
@@ -397,8 +434,10 @@ void SituareService::parseMessagesData(const QByteArray &jsonReply)
             bool lonOk;
             qreal longitude = messageMap["longitude"].toReal(&lonOk);
 
-            if (latOk && lonOk)
+            if (latOk && lonOk) {
+                message.setAddress(messageMap["address"].toString());
                 message.setCoordinates(GeoCoordinate(latitude, longitude));
+            }
 
             received.append(message);
 
@@ -423,8 +462,10 @@ void SituareService::parseMessagesData(const QByteArray &jsonReply)
             bool lonOk;
             qreal longitude = messageMap["longitude"].toReal(&lonOk);
 
-            if (latOk && lonOk)
+            if (latOk && lonOk) {
+                message.setAddress(messageMap["address"].toString());
                 message.setCoordinates(GeoCoordinate(latitude, longitude));
+            }
 
             sent.append(message);
 
@@ -435,6 +476,31 @@ void SituareService::parseMessagesData(const QByteArray &jsonReply)
     }
 }
 
+void SituareService::parsePopularTagsData(const QByteArray &jsonReply)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QJson::Parser parser;
+    bool ok;
+
+    QVariantMap result = parser.parse(jsonReply, &ok).toMap();
+
+    if (!ok) {
+        emit error(ErrorContext::SITUARE, SituareError::INVALID_JSON);
+        return;
+    } else {
+        QHash<QString, QString> popularTags;
+
+        foreach (QVariant tagVariant, result["popular_tags"].toList()) {
+            QMap<QString, QVariant> tag = tagVariant.toMap();
+            popularTags.insert(tag["id"].toString(), tag["name"].toString());
+        }
+
+        emit interestingPeopleReceived(friends, others);
+    }
+}
+
+
 void SituareService::parseUserData(const QByteArray &jsonReply)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -667,13 +733,10 @@ void SituareService::addTags(const QStringList &tags)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    bool retVal = false;
-
     foreach (QString tag, tags)
-        retVal = m_database->addTag(613374451, tag);
+        m_database->addTag(613374451, tag);
 
-    if (retVal)
-        emit updateWasSuccessful(SituareService::SuccessfulAddTags);
+    emit updateWasSuccessful(SituareService::SuccessfulAddTags);
 }
 
 void SituareService::searchPeopleByTag(const QString &tag)
index 6923c7b..b676067 100644 (file)
@@ -121,6 +121,13 @@ public slots:
     void fetchMessages();
 
     /**
+    * @brief Retrieves popular tags.
+    *
+    * Tags are fetch from local database instead of Situare server.
+    */
+    void fetchPopularTags();
+
+    /**
     * @brief Public slot, to clear user data
     *
     */
@@ -241,6 +248,12 @@ private:
     */
     void parseMessagesData(const QByteArray &jsonReply);
 
+    /**
+    * @brief Parses popular tags data from JSON string
+    *
+    * @param jsonReply JSON string
+    */
+    void parsePopularTagsData(const QByteArray &jsonReply);
 
     /**
     * @brief Parses user and friend data from JSON string
@@ -305,9 +318,10 @@ signals:
     /**
     * @brief Signal when fetchPeopleWithSimilarInterest request is finished
     *
-    * @param interestingPeople list of interesting people
+    * @param friends list of friends
+    * @param others list of other people
     */
-    void interestingPeopleReceived(QList<User> &interestingPeople);
+    void interestingPeopleReceived(QList<User> &friends, QList<User> &others);
 
     /**
     * @brief Signal when fetchMessages request is finished
index 2a83d8f..a9850c1 100644 (file)
@@ -97,7 +97,8 @@ SOURCES += main.cpp \
     situareservice/message.cpp \
     ui/personlistitem.cpp \
     ui/personlistview.cpp \
-    ui/messagedialog.cpp
+    ui/messagedialog.cpp \
+    ui/tagcompletion.cpp
 HEADERS += application.h \
     common.h \
     coordinates/geocoordinate.h \
@@ -196,7 +197,8 @@ HEADERS += application.h \
     situareservice/message.h \
     ui/personlistitem.h \
     ui/personlistview.h \
-    ui/messagedialog.h
+    ui/messagedialog.h \
+    ui/tagcompletion.h
 QT += network \
     webkit \
     sql
index d8ab074..fab9907 100644 (file)
@@ -36,7 +36,7 @@ ListItem::ListItem(QListWidget *parent, int type)
     setSize(QSize(ITEM_WIDTH, ITEM_MIN_HEIGHT));
 }
 
-QString ListItem::title() const
+QString ListItem::title()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
index cf59961..b84bc2b 100644 (file)
@@ -92,7 +92,7 @@ public:
     *
     * @return item's title
     */
-    QString title() const;
+    QString title();
 
     /**
     * @brief Toggles selection.
index e429a74..8fde959 100644 (file)
@@ -23,7 +23,6 @@
 
 #include "listitem.h"
 #include "listview.h"
-#include "friendlistitem.h"
 
 ListView::ListView(QWidget *parent)
     : QListWidget(parent),
index eaf32fb..e1dbdf4 100644 (file)
@@ -42,6 +42,11 @@ class ListView : public QListWidget
 
 public:
     /**
+    * @brief Unit test class
+    */
+    friend class TestListView;
+
+    /**
     * @brief Constructor.
     *
     * @param parent QWidget
index 5311205..6b7d5e7 100644 (file)
@@ -345,8 +345,8 @@ void MainWindow::buildMeetPeoplePanel()
     connect(this, SIGNAL(friendImageReady(QString,QPixmap)),
             m_meetPeoplePanel, SLOT(setImage(QString,QPixmap)));
 
-    connect(this, SIGNAL(interestingPeopleReceived(QList<User>&)),
-            m_meetPeoplePanel, SLOT(populateInterestingPeopleListView(QList<User>&)));
+    connect(this, SIGNAL(interestingPeopleReceived(QList<User>&,QList<User>&)),
+            m_meetPeoplePanel, SLOT(populateInterestingPeopleListView(QList<User>&,QList<User>&)));
 
     connect(m_meetPeoplePanel, SIGNAL(requestInterestingPeople()),
             this, SIGNAL(requestInterestingPeople()));
index bee4a6a..7f9d040 100644 (file)
@@ -544,9 +544,10 @@ signals:
     /**
     * @brief Signal when fetchPeopleWithSimilarInterest request is finished
     *
-    * @param interestingPeople list of interesting people
+    * @param friends list of friends
+    * @param others list of other people
     */
-    void interestingPeopleReceived(QList<User> &interestingPeople);
+    void interestingPeopleReceived(QList<User> &friends, QList<User> &others);
 
     /**
      * @brief Signal for friend location ready.
index 5c0ada4..4f63670 100644 (file)
@@ -12,7 +12,8 @@
 #include "meetpeoplepanel.h"
 
 MeetPeoplePanel::MeetPeoplePanel(QWidget *parent)
-    : PanelBase(parent)
+    : PanelBase(parent),
+      m_headerListItemDelegate(0)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -22,9 +23,10 @@ MeetPeoplePanel::MeetPeoplePanel(QWidget *parent)
     setLayout(meetPeopleLayout);
 
     m_personListView = new PersonListView(this);
-    m_personListView->setItemDelegate(new ExtendedListItemDelegate(this));
+    m_personListItemDelegate = new ExtendedListItemDelegate(this);
+    initItemDelegates();
     connect(m_personListView, SIGNAL(listItemSelectionChanged()),
-            this, SLOT(onListItemSelectionChanged()));
+            this, SLOT(listItemSelectionHandler()));
     connect(m_personListView, SIGNAL(personItemClicked(GeoCoordinate)),
             this, SIGNAL(findPerson(GeoCoordinate)));
 
@@ -45,10 +47,10 @@ MeetPeoplePanel::MeetPeoplePanel(QWidget *parent)
     connect(searchPeopleButton, SIGNAL(clicked()),
             this, SIGNAL(requestInterestingPeopleSearch()));
 
-    ImageButton *friendListButton = new ImageButton(":/res/images/friend_list_btn.png",
+    m_friendListButton = new ImageButton(":/res/images/friend_list_btn.png",
                                                  ":/res/images/friend_list_btn_s.png",
                                                  ":/res/images/friend_list_btn_d.png", this);
-    connect(friendListButton, SIGNAL(clicked()),
+    connect(m_friendListButton, SIGNAL(clicked()),
             this, SLOT(showFriend()));
 
     ImageButton *messageButton = new ImageButton(":/res/images/chat_btn.png",
@@ -59,7 +61,7 @@ MeetPeoplePanel::MeetPeoplePanel(QWidget *parent)
 
     m_genericButtonsLayout->addWidget(refreshInterestingPeopleButton);
     m_genericButtonsLayout->addWidget(searchPeopleButton);
-    m_itemButtonsLayout->addWidget(friendListButton);
+    m_itemButtonsLayout->addWidget(m_friendListButton);
     m_itemButtonsLayout->addWidget(messageButton);
 }
 
@@ -79,14 +81,42 @@ void MeetPeoplePanel::hideEvent(QHideEvent *event)
     m_personListView->clearItemSelection();
 }
 
+void MeetPeoplePanel::initItemDelegates()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_personListView->setItemDelegate(m_personListItemDelegate);
+
+    if (m_headerListItemDelegate)
+        delete m_headerListItemDelegate;
+    m_headerListItemDelegate = new HeaderListItemDelegate(this);
+}
+
+void MeetPeoplePanel::listItemSelectionHandler()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    PersonListItem *personItem = dynamic_cast<PersonListItem*>(m_personListView->selectedItem());
+
+    if (personItem && !personItem->isFriend())
+        m_friendListButton->setDisabled(true);
+    else
+        m_friendListButton->setEnabled(true);
+
+    onListItemSelectionChanged();
+}
+
 void MeetPeoplePanel::messageButtonPressed()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     PersonListItem *personItem = dynamic_cast<PersonListItem*>(m_personListView->selectedItem());
-    if (personItem)
+
+    if (personItem) {
+        m_personListView->clearItemSelection();
         emit requestMessageDialog(QPair<QString, QString>(personItem->facebookId(),
                                                           personItem->title()));
+    }
 }
 
 void MeetPeoplePanel::setImage(const QString &id, const QPixmap &image)
@@ -104,34 +134,45 @@ void MeetPeoplePanel::showFriend()
 
     PersonListItem *personItem = dynamic_cast<PersonListItem*>(m_personListView->selectedItem());
     if (personItem) {
+        m_personListView->clearItemSelection();
         QList<QString> userIds;
         userIds.append(personItem->facebookId());
         emit requestShowFriend(userIds);
     }
 }
 
-void MeetPeoplePanel::populateInterestingPeopleListView(QList<User> &interestingPeople)
+void MeetPeoplePanel::populateInterestingPeopleListView(QList<User> &friends, QList<User> &others)
 {
     qDebug() << __PRETTY_FUNCTION__ ;
 
     m_personListView->clearList();
-
-    for (int i = 0; i < interestingPeople.count(); ++i) {
-        if (i == 0) {
-            m_personListView->setItemDelegateForRow(i, new HeaderListItemDelegate(this));
-            ExtendedListItem *item = new ExtendedListItem(0, QListWidgetItem::UserType);
-            item->setTitle(tr("Friends:"));
-            m_personListView->addListItem(QString("header") + QString::number(i), item);
+    initItemDelegates();
+
+    if (friends.count() > 0) {
+        m_personListView->setItemDelegateForRow(0, m_headerListItemDelegate);
+        ExtendedListItem *friendsHeaderItem = new ExtendedListItem(0, QListWidgetItem::UserType);
+        friendsHeaderItem->setTitle(tr("Friends:"));
+        m_personListView->addListItem(QString("friendsHeader"), friendsHeaderItem);
+
+        foreach (User user, friends) {
+            PersonListItem *item = new PersonListItem();
+            item->setPersonData(user, true);
+            m_personListView->addListItem(user.userId(), item);
         }
-        else if (i == 2) {
-            m_personListView->setItemDelegateForRow(i+1, new HeaderListItemDelegate(this));
-            ExtendedListItem *item = new ExtendedListItem(0, QListWidgetItem::UserType);
-            item->setTitle(tr("Others:"));
-            m_personListView->addListItem(QString("header") + QString::number(i), item);
+    }
+
+    if (others.count() > 0) {
+        m_personListView->setItemDelegateForRow(m_personListView->count(),
+                                                m_headerListItemDelegate);
+        ExtendedListItem *othersHeaderItem = new ExtendedListItem(0, QListWidgetItem::UserType);
+        othersHeaderItem->setTitle(tr("Others:"));
+        m_personListView->addListItem(QString("othersHeader"), othersHeaderItem);
+
+        foreach (User user, others) {
+            PersonListItem *item = new PersonListItem();
+            item->setPersonData(user, false);
+            m_personListView->addListItem(user.userId(), item);
         }
-        PersonListItem *item = new PersonListItem();
-        item->setPersonData(interestingPeople.at(i));
-        m_personListView->addListItem(interestingPeople.at(i).userId(), item);
     }
 
     m_personListView->scrollToTop();
index 77a7ae8..8407d83 100644 (file)
@@ -28,7 +28,9 @@
 
 class QUrl;
 
+class ExtendedListItemDelegate;
 class GeoCoordinate;
+class HeaderListItemDelegate;
 class ImageButton;
 class PersonListView;
 class User;
@@ -72,6 +74,13 @@ private slots:
     void anyPanelClosed();
 
     /**
+    * @brief Handles list item selection.
+    *
+    * Sets item releated buttons enabled
+    */
+    void listItemSelectionHandler();
+
+    /**
     * @brief Called when message button is pressed.
     *
     * Calls requestMessageDialog with message receiver's ID and name
@@ -96,9 +105,16 @@ private slots:
     /**
     * @brief Populates interesting people list view.
     *
-    * @param interestingPeople list of interesting people
+    * @param friends list of friends
+    * @param others list of other people
+    */
+    void populateInterestingPeopleListView(QList<User> &friends, QList<User> &others);
+
+private:
+    /**
+    * @brief Inits item delegates for message list view.
     */
-    void populateInterestingPeopleListView(QList<User> &interestingPeople);
+    void initItemDelegates();
 
 signals:
     /**
@@ -135,8 +151,11 @@ signals:
     void requestShowFriend(const QList<QString> &userIDs);
 
 private:
-    PersonListView *m_personListView;   ///< Interesting people list view
-    ImageButton *m_chatButton;          ///< Chat button
+    ExtendedListItemDelegate *m_personListItemDelegate;    ///< Person list item delegate
+    HeaderListItemDelegate *m_headerListItemDelegate;       ///< Header list item delegate
+    ImageButton *m_chatButton;                              ///< Chat button
+    ImageButton *m_friendListButton;                        ///< Friend list button
+    PersonListView *m_personListView;                       ///< Interesting people list view
 };
 
 #endif // MEETPEOPLEPANEL_H
index 4690585..59e8e9c 100644 (file)
@@ -61,4 +61,7 @@ void MessageListItem::setMessageData(const Message &message)
     icon.load(":/res/images/chat.png");
     addSubItem(message.text(), icon);
     addSubItem(message.timestamp().toString(), QPixmap(":/res/images/calendar.png"));
+
+    if (m_coordinates.isValid())
+        addSubItem(message.address(), QPixmap(":/res/images/compass.png"));
 }
index 518513f..10a3e41 100644 (file)
@@ -33,7 +33,8 @@
 #include "messagepanel.h"
 
 MessagePanel::MessagePanel(QWidget *parent)
-    : PanelBase(parent)
+    : PanelBase(parent),
+      m_headerListItemDelegate(0)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -114,7 +115,9 @@ void MessagePanel::initItemDelegates()
     qDebug() << __PRETTY_FUNCTION__;
 
     m_messageListView->setItemDelegate(m_messageListItemDelegate);
-    delete m_headerListItemDelegate;
+
+    if (m_headerListItemDelegate)
+        delete m_headerListItemDelegate;
     m_headerListItemDelegate = new HeaderListItemDelegate(this);
 
 }
@@ -126,9 +129,11 @@ void MessagePanel::messageButtonPressed()
     MessageListItem *messageItem = dynamic_cast<MessageListItem*>(
             m_messageListView->selectedItem());
 
-    if (messageItem)
+    if (messageItem) {
+        m_messageListView->clearItemSelection();
         emit requestMessageDialog(QPair<QString, QString>(messageItem->receiverId(),
                                                           messageItem->title()));
+    }
 }
 
 void MessagePanel::populateMessageListView(QList<Message> &received, QList<Message> &sent)
index dad016b..897886b 100644 (file)
@@ -29,6 +29,7 @@
 #include "personlistitem.h"
 
 PersonListItem::PersonListItem()
+    : m_isFriend(false)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -49,9 +50,18 @@ GeoCoordinate PersonListItem::coordinates() const
 
 QString PersonListItem::facebookId() const
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     return m_facebookId;
 }
 
+bool PersonListItem::isFriend() const
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_isFriend;
+}
+
 void PersonListItem::setAvatarImage(const QPixmap &image)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -74,10 +84,18 @@ void PersonListItem::setFacebookId(const QString &facebookId)
     m_facebookId = facebookId;
 }
 
-void PersonListItem::setPersonData(const User &user)
+void PersonListItem::setIsFriend(bool isFriend)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_isFriend = isFriend;
+}
+
+void PersonListItem::setPersonData(const User &user, bool isFriend)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
+    setIsFriend(isFriend);
     setFacebookId(user.userId());
 
     setTitle(shortenText(user.name(), NAME_TEXT_MAX_WIDTH - MARGIN * 3,
index 95213b8..fe7b0e0 100644 (file)
@@ -67,6 +67,13 @@ public:
     QString facebookId() const;
 
     /**
+    * @brief Returns is this item friend.
+    *
+    * @return true if friend, false otherwise
+    */
+    bool isFriend() const;
+
+    /**
     * @brief Sets avatar image for this item.
     *
     * @param image image
@@ -81,11 +88,18 @@ public:
     void setCoordinates(const GeoCoordinate &coordinates);
 
     /**
+    * @brief Sets is friend flag.
+    *
+    * @param isFriend true if friend, false otherwise
+    */
+    void setIsFriend(bool isFriend);
+
+    /**
     * @brief Set person data for this item.
     *
     * @param user User
     */
-    void setPersonData(const User &user);
+    void setPersonData(const User &user, bool isFriend = true);
 
 private:
     /**
@@ -99,6 +113,8 @@ private:
 * DATA MEMBERS
 ******************************************************************************/
 private:
+    bool m_isFriend;                ///< Is friend flag
+
     QString m_facebookId;           ///< User's Facebook ID
 
     GeoCoordinate m_coordinates;    ///< User coordinates
diff --git a/src/ui/tagcompletion.cpp b/src/ui/tagcompletion.cpp
new file mode 100644 (file)
index 0000000..83f569f
--- /dev/null
@@ -0,0 +1,138 @@
+#include <QDebug>
+#include <QEvent>
+#include <QKeyEvent>
+#include <QTreeWidget>
+#include <QLineEdit>
+#include <QHeaderView>
+#include <QTimer>
+
+#include "tagcompletion.h"
+
+TagCompletion::TagCompletion(QLineEdit *parent) :
+    QObject(parent), m_parentLineEdit(parent)
+{
+    m_popup = new QTreeWidget;
+    m_popup->setWindowFlags(Qt::Popup);
+    m_popup->setFocusPolicy(Qt::NoFocus);
+    m_popup->setFocusProxy(parent);
+    m_popup->setColumnCount(2);
+    m_popup->setUniformRowHeights(true);
+    m_popup->setRootIsDecorated(false);
+    m_popup->setEditTriggers(QTreeWidget::NoEditTriggers);
+    m_popup->setSelectionBehavior(QTreeWidget::SelectRows);
+    m_popup->setFrameStyle(QFrame::Box | QFrame::Plain);
+    m_popup->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+    m_popup->header()->hide();
+
+    m_popup->installEventFilter(this);
+
+    connect(m_popup, SIGNAL(itemClicked(QTreeWidgetItem*,int)),
+            this, SLOT(doneCompletion()));
+
+    connect(m_parentLineEdit, SIGNAL(textEdited(QString)),
+            this, SLOT(requestChoices(QString)));
+}
+
+TagCompletion::~TagCompletion()
+{
+    delete m_popup;
+}
+
+void TagCompletion::doneCompletion()
+{
+    m_popup->hide();
+    m_parentLineEdit->setFocus();
+    QTreeWidgetItem *item = m_popup->currentItem();
+    if (item) {
+        m_parentLineEdit->setText(item->text(0));
+        QMetaObject::invokeMethod(m_parentLineEdit, "returnPressed");
+    }
+
+}
+
+bool TagCompletion::eventFilter(QObject *obj, QEvent *ev)
+{
+    if (obj != m_popup)
+        return false;
+
+    if (ev->type() == QEvent::MouseButtonPress) {
+        m_popup->hide();
+        m_parentLineEdit->setFocus();
+        return true;
+    }
+
+    if (ev->type() == QEvent::KeyPress) {
+        bool consumed = false;
+        int key = static_cast<QKeyEvent*>(ev)->key();
+        switch (key) {
+            case Qt::Key_Enter:
+            case Qt::Key_Return:
+                doneCompletion();
+                consumed = true;
+
+            case Qt::Key_Escape:
+                m_parentLineEdit->setFocus();
+                m_popup->hide();
+                consumed = true;
+
+            case Qt::Key_Up:
+            case Qt::Key_Down:
+            case Qt::Key_Home:
+            case Qt::Key_End:
+            case Qt::Key_PageUp:
+            case Qt::Key_PageDown:
+                break;
+
+            default:
+                m_parentLineEdit->setFocus();
+                m_parentLineEdit->event(ev);
+                //m_popup->hide();
+                break;
+        }
+
+        return consumed;
+    }
+
+    return false;
+}
+
+void TagCompletion::requestChoices(const QString &text)
+{
+    qWarning() << __PRETTY_FUNCTION__ << text;
+
+    QStringList choices;
+    choices.append("aaa");
+    choices.append("bbb");
+    choices.append("ccc");
+
+    showCompletion(choices);
+}
+
+void TagCompletion::showCompletion(const QStringList &choices)
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    m_popup->setUpdatesEnabled(false);
+    m_popup->clear();
+    for (int i = 0; i < choices.count(); ++i) {
+        QTreeWidgetItem * item;
+        item = new QTreeWidgetItem(m_popup);
+        item->setText(0, choices[i]);
+        item->setText(1, "123");
+        item->setTextAlignment(1, Qt::AlignRight);
+    }
+    m_popup->setCurrentItem(m_popup->topLevelItem(0));
+    m_popup->resizeColumnToContents(0);
+    m_popup->resizeColumnToContents(1);
+    m_popup->adjustSize();
+    m_popup->setUpdatesEnabled(true);
+
+    int h = m_popup->sizeHintForRow(0) * qMin(7, choices.count()) + 3;
+    m_popup->resize(m_popup->width(), h);
+
+    m_popup->move(m_parentLineEdit->mapToGlobal(
+            QPoint(0, m_parentLineEdit->height())));
+    m_popup->setFocus();
+    m_popup->show();
+
+}
diff --git a/src/ui/tagcompletion.h b/src/ui/tagcompletion.h
new file mode 100644 (file)
index 0000000..0390ab5
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef TAGCOMPLETION_H
+#define TAGCOMPLETION_H
+
+#include <QObject>
+
+class QLineEdit;
+class QTimer;
+class QTreeWidget;
+
+class TagCompletion : public QObject
+{
+    Q_OBJECT
+public:
+    TagCompletion(QLineEdit *parent = 0);
+    ~TagCompletion();
+
+    bool eventFilter(QObject *obj, QEvent *ev);
+    void showCompletion(const QStringList &choices);
+
+public slots:
+    void requestChoices(const QString &text);
+    void doneCompletion();
+
+private:
+    QLineEdit *m_parentLineEdit;
+    QTimer *timer;
+    QTreeWidget *m_popup;
+};
+
+#endif // TAGCOMPLETION_H
index ec0e2bf..a101a49 100644 (file)
@@ -5,35 +5,53 @@
 #include <QListWidget>
 #include <QListWidgetItem>
 #include <QPushButton>
+#include <QLabel>
+
+#include "tagcompletion.h"
 
 #include "tagsdialog.h"
 
-TagsDialog::TagsDialog(const QHash<QString, QString> &tags)
+TagsDialog::TagsDialog(const QHash<QString, QString> &tags, QWidget *parent)
+    : QDialog(parent)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     setWindowTitle(tr("Edit tags"));
 
-    QGridLayout *gridLayout = new QGridLayout;
+#ifdef Q_WS_MAEMO_5
+    setAttribute(Qt::WA_Maemo5StackedWindow);
+    setWindowFlags(Qt::Window);
+#endif
+
+    QVBoxLayout *mainLayout = new QVBoxLayout;
+    QHBoxLayout *lineEditLayout = new QHBoxLayout;
+    QGridLayout *listLayout = new QGridLayout;
+
     m_addTagEdit = new QLineEdit("");
-    QDialogButtonBox *buttonBox = new QDialogButtonBox(Qt::Vertical);
+    QPushButton *addButton = new QPushButton(tr("Add"));
+    lineEditLayout->addWidget(m_addTagEdit);
+    lineEditLayout->addWidget(addButton);
 
-    QPushButton *addButton = buttonBox->addButton(tr("Add"), QDialogButtonBox::ActionRole);
-    QPushButton *deleteButton = buttonBox->addButton(tr("Delete"),
-                                                     QDialogButtonBox::ActionRole);
-    QPushButton *cancelButton = buttonBox->addButton(QDialogButtonBox::Cancel);
-    QPushButton *okButton = buttonBox->addButton(tr("Ok"), QDialogButtonBox::AcceptRole);
+    QPushButton *deleteButton = new QPushButton(tr("Delete"));
+    QPushButton *cancelButton = new QPushButton(tr("Cancel"));
+    QPushButton *okButton = new QPushButton(tr("Update"));
 
-    m_tagsView = new QListWidget(this);
+    QLabel *yourTagsLabel = new QLabel(tr("Your tags:"));
+    yourTagsLabel->setAlignment(Qt::AlignCenter);
+    QLabel *popularTagsLabel = new QLabel(tr("Popular tags:"));
+    popularTagsLabel->setAlignment(Qt::AlignCenter);
+    m_userTagsView = new QListWidget();
+    m_popularTagsView = new QListWidget();
 
-    gridLayout->addWidget(m_addTagEdit, 0, 0, 1, 1);
-    gridLayout->addWidget(m_tagsView, 1, 0, 2, 1);
-    gridLayout->addWidget(buttonBox, 0, 1, 2, 1);
+    listLayout->addWidget(yourTagsLabel, 0, 0);
+    listLayout->addWidget(popularTagsLabel, 0, 1);
+    listLayout->addWidget(m_userTagsView, 1, 0);
+    listLayout->addWidget(m_userTagsView, 1, 1);
 
-    foreach (QString tag, tags)
-        m_tagsView->addItem(tag);
+    mainLayout->addLayout(lineEditLayout);
+    mainLayout->addLayout(listLayout);
 
-    setLayout(gridLayout);
+    setLayout(mainLayout);
 
     connect(okButton, SIGNAL(clicked()),
             this, SLOT(accept()));
@@ -46,17 +64,19 @@ TagsDialog::TagsDialog(const QHash<QString, QString> &tags)
 
     connect(deleteButton, SIGNAL(clicked()),
             this, SLOT(deleteTagFromList()));
+
+    populateUserTags(tags);
 }
 
 void TagsDialog::addTagToList()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QList<QListWidgetItem *> findItems = m_tagsView->findItems(m_addTagEdit->text(),
+    QList<QListWidgetItem *> findItems = m_userTagsView->findItems(m_addTagEdit->text(),
                                                                Qt::MatchExactly);
 
     if (findItems.isEmpty()) {
-        m_tagsView->insertItem(0, m_addTagEdit->text());
+        m_userTagsView->insertItem(0, m_addTagEdit->text());
         m_newTags.append(m_addTagEdit->text());
     }
 
@@ -67,11 +87,11 @@ void TagsDialog::deleteTagFromList()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QList<QListWidgetItem *> selectedItems = m_tagsView->selectedItems();
+    QList<QListWidgetItem *> selectedItems = m_userTagsView->selectedItems();
 
     if (!selectedItems.isEmpty()) {
         QListWidgetItem *selectedItem = selectedItems.at(0);
-        m_tagsView->takeItem(m_tagsView->row(selectedItem));
+        m_userTagsView->takeItem(m_userTagsView->row(selectedItem));
 
         if (m_newTags.contains(selectedItem->text()))
             m_newTags.removeOne(selectedItem->text());
@@ -93,3 +113,24 @@ QStringList TagsDialog::removedTags()
 
     return m_removedTags;
 }
+
+void TagsDialog::populatePopularTags(const QHash<QString, QString> &popularTags)
+{
+    m_popularTagsView->clear();
+
+    foreach (QString tag, popularTags)
+        m_popularTagsView->addItem(tag);
+}
+
+void TagsDialog::populateUserTags(const QHash<QString, QString> &userTags)
+{
+    m_userTagsView->clear();
+
+    foreach (QString tag, m_newTags) {
+        if (!userTags.values().contains(tag))
+            m_userTagsView->addItem(tag);
+    }
+
+    foreach (QString tag, userTags)
+        m_userTagsView->addItem(tag);
+}
index 9550de8..ef46cb5 100644 (file)
@@ -52,7 +52,7 @@ public:
     *
     * @param parent Instance of parent widget
     */
-    TagsDialog(const QHash<QString, QString> &tags);
+    TagsDialog(const QHash<QString, QString> &tags, QWidget *parent = 0);
 
 /*******************************************************************************
  * MEMBER FUNCTIONS AND SLOTS
@@ -73,6 +73,11 @@ public:
     */
     QStringList removedTags();
 
+public slots:
+    void populateUserTags(const QHash<QString, QString> &userTags);
+
+    void populatePopularTags(const QHash<QString, QString> &popularTags);
+
 private slots:
     /**
     * @brief Adds tag to the list.
@@ -88,12 +93,13 @@ private slots:
  * DATA MEMBERS
  ******************************************************************************/
 private:
-    QLineEdit *m_addTagEdit;    ///< Add tag line edit
+    QLineEdit *m_addTagEdit;            ///< Add tag line edit
 
-    QListWidget *m_tagsView;    ///< Tag list view
+    QListWidget *m_userTagsView;        ///< User tag list view
+    QListWidget *m_popularTagsView;     ///< Popular tag list view
 
-    QStringList m_newTags;      ///< List of new tags
-    QStringList m_removedTags;  ///< Removed tags
+    QStringList m_newTags;              ///< List of new tags
+    QStringList m_removedTags;          ///< Removed tags
 };
 
 #endif // LOGINDIALOG_H
index 6546e5d..06f20c6 100644 (file)
@@ -312,7 +312,7 @@ void UserInfo::setExpanded(bool expanded)
 
 void UserInfo::setTags(const QHash<QString, QString> &tags)
 {
-qDebug() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__;
 
     m_userTags = tags;
 
@@ -325,6 +325,9 @@ qDebug() << __PRETTY_FUNCTION__;
     }
 
     m_tagsTextLabel->setText(tagsText);
+
+    if (m_tagsDialog)
+        m_tagsDialog->populateUserTags(m_userTags);
 }
 
 void UserInfo::setTime(const QString &time)
@@ -348,7 +351,7 @@ void UserInfo::showTagsDialog()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_tagsDialog = new TagsDialog(m_userTags);
+    m_tagsDialog = new TagsDialog(m_userTags, this);
     connect(m_tagsDialog, SIGNAL(finished(int)),
              this, SLOT(tagsDialogFinished(int)));
     m_tagsDialog->show();
index 88c6044..b217b57 100644 (file)
@@ -36,7 +36,6 @@ public:
     virtual void setSelected(bool selected);
     virtual void setSubitemTextWidth(int width);
     virtual bool toggleSelection();
-
 };
 
 void ExtendedListItemStub::ExtendedListItemConstructor(QListWidget *parent, int type)
@@ -72,9 +71,11 @@ void ExtendedListItemStub::setSubitemTextWidth(int width)
     stubMethodEntered("setSubitemTextWidth", params);
 }
 
-QString ExtendedListItemStub::toggleSelection()
+bool ExtendedListItemStub::toggleSelection()
 {
     stubMethodEntered("toggleSelection");
+
+    return stubReturnValue<bool>("toggleSelection");
 }
 
 //Create a stub instance
@@ -87,30 +88,34 @@ ExtendedListItem::ExtendedListItem(QListWidget *parent, int type)
     extendedListItemStub->ExtendedListItemConstructor(parent, type);
 }
 
-void ExtendedListItemStub::addSubItem(const QString &text, const QPixmap &icon)
+ExtendedListItem::~ExtendedListItem()
+{
+
+}
+
+void ExtendedListItem::addSubItem(const QString &text, const QPixmap &icon)
 {
     extendedListItemStub->addSubItem(text, icon);
 }
 
-void ExtendedListItemStub::clearSubItems()
+void ExtendedListItem::clearSubItems()
 {
     extendedListItemStub->clearSubItems();
 }
 
-void ExtendedListItemStub::setSelected(bool selected)
+void ExtendedListItem::setSelected(bool selected)
 {
     extendedListItemStub->setSelected(selected);
 }
 
-void ExtendedListItemStub::setSubitemTextWidth(int width)
+void ExtendedListItem::setSubitemTextWidth(int width)
 {
     extendedListItemStub->setSubitemTextWidth(width);
 }
 
-void ExtendedListItemStub::toggleSelection()
+bool ExtendedListItem::toggleSelection()
 {
-    extendedListItemStub->toggleSelection();
+    return extendedListItemStub->toggleSelection();
 }
 
 #endif // EXTENDEDLISTITEMSTUB_H
-
index 08fd6e9..5d85864 100644 (file)
 #include "../../src/coordinates/geocoordinate.h"
 #include "stubbase.h"
 
-class ListViewStub : public StubBase
+class ListItemStub : public StubBase
 {
 public:
-    virtual void ListItemConstructor(QListWidget *parent = 0, int type = Type);
+    virtual void ListItemConstructor(QListWidget *parent = 0,
+                                     int type = QListWidgetItem::Type);
     enum TextSize{TEXT_SIZE_NORMAL, TEXT_SIZE_SMALL};
     virtual void setImage(const QPixmap &image);
     virtual void setTitle(const QString &name);
-    virtual void setSelected(bool selected) = 0;
     virtual void setSize(const QSize &size);
-    virtual QString shortenText(const QString &text, int textWidth, TextSize textSize);
-    virtual QString title() const;
-    virtual bool toggleSelection() = 0;
+    virtual QString shortenText(const QString &text, int textWidth, ListItem::TextSize textSize);
+    virtual QString title();
 };
 
-void ListViewStub::ListItemConstructor(QListWidget *parent, int type)
+void ListItemStub::ListItemConstructor(QListWidget *parent, int type)
 {
     Q_UNUSED(parent)
     Q_UNUSED(type)
 }
 
-void ListViewStub::setImage(const QPixmap &image)
+void ListItemStub::setImage(const QPixmap &image)
 {
     QList<ParameterBase *> params;
-    params.append(new Parameter<const QPixmap *>(image));
+    params.append(new Parameter<const QPixmap &>(image));
     stubMethodEntered("setImage", params);
 }
 
-void ListViewStub::setTitle(const QString &name)
+void ListItemStub::setTitle(const QString &name)
 {
     QList<ParameterBase *> params;
     params.append(new Parameter<const QString &>(name));
     stubMethodEntered("setTitle", params);
 }
 
-void ListViewStub::setSize(const QSize &size)
+void ListItemStub::setSize(const QSize &size)
 {
     QList<ParameterBase *> params;
     params.append(new Parameter<const QSize &>(size));
     stubMethodEntered("setSize", params);
 }
 
-QString ListViewStub::shortenText(const QString &text, int textWidth, TextSize textSize)
+QString ListItemStub::shortenText(const QString &text, int textWidth, ListItem::TextSize textSize)
 {
     QList<ParameterBase *> params;
     params.append(new Parameter<const QString &>(text));
     params.append(new Parameter<int>(textWidth));
-    params.append(new Parameter<TextSize>(textSize));
+    params.append(new Parameter<ListItem::TextSize>(textSize));
     stubMethodEntered("shortenText", params);
 
     return stubReturnValue<QString>("shortenText");
 }
 
-QString ListViewStub::title() const
+QString ListItemStub::title()
 {
     return stubReturnValue<QString>("title");
 }
 
 //Create a stub instance
-ListViewStub defaultListItemStub;
-ListViewStub *listItemStub = &defaultListItemStub;
+ListItemStub defaultListItemStub;
+ListItemStub *listItemStub = &defaultListItemStub;
 
 ListItem::ListItem(QListWidget *parent, int type)
     : QListWidgetItem(parent, type)
@@ -93,27 +92,27 @@ ListItem::ListItem(QListWidget *parent, int type)
     listItemStub->ListItemConstructor(parent, type);
 }
 
-void ListViewStub::setImage(const QPixmap &image)
+void ListItem::setImage(const QPixmap &image)
 {
     listItemStub->setImage(image);
 }
 
-void ListViewStub::setTitle(const QString &name)
+void ListItem::setTitle(const QString &name)
 {
     listItemStub->setTitle(name);
 }
 
-void ListViewStub::setSize(const QSize &size)
+void ListItem::setSize(const QSize &size)
 {
     listItemStub->setSize(size);
 }
 
-QString ListViewStub::shortenText(const QString &text, int textWidth, TextSize textSize)
+QString ListItem::shortenText(const QString &text, int textWidth, ListItem::TextSize textSize)
 {
     return listItemStub->shortenText(text, textWidth, textSize);
 }
 
-QString ListViewStub::title()
+QString ListItem::title()
 {
     return listItemStub->title();
 }
index cf44964..371d48e 100644 (file)
@@ -22,6 +22,8 @@
 #ifndef LISTVIEWSTUB_H
 #define LISTVIEWSTUB_H
 
+#include <QListWidget>
+
 #include "../../src/ui/personlistview.h"
 #include "listitem.h"
 #include "stubbase.h"
@@ -46,12 +48,11 @@ public:
     virtual void removeLastItem();
     virtual ListItem *selectedItem();
     virtual void setSelectedItem(ListItem *item);
-
-protected:
     virtual bool listItemClicked(ListItem *clickedItem);
+    virtual void listItemClicked(QListWidgetItem *item);
 };
 
-ListViewStub::ListViewConstructor(QWidget *parent)
+void ListViewStub::ListViewConstructor(QWidget *parent)
 {
     Q_UNUSED(parent)
 }
@@ -177,6 +178,13 @@ bool ListViewStub::listItemClicked(ListItem *clickedItem)
     return stubReturnValue<bool>("listItemClicked");
 }
 
+void ListViewStub::listItemClicked(QListWidgetItem *item)
+{
+    QList<ParameterBase *> params;
+    params.append(new Parameter<QListWidgetItem *>(item));
+    stubMethodEntered("listItemClicked", params);
+}
+
 ListViewStub defaultListViewStub;
 ListViewStub *listViewStub = &defaultListViewStub;
 
@@ -186,6 +194,11 @@ ListView::ListView(QWidget *parent)
     listViewStub->ListViewConstructor(parent);
 }
 
+ListView::~ListView()
+{
+
+}
+
 void ListView::addListItem(const QString &key, ListItem *item)
 {
     listViewStub->addListItem(key, item);
@@ -216,9 +229,9 @@ void ListView::clearList()
     listViewStub->clearList();
 }
 
-void ListView::contains(const QString &userID)
+bool ListView::contains(const QString &userID)
 {
-    listViewStub->contains(userID);
+    return listViewStub->contains(userID);
 }
 
 void ListView::filter(const QList<QString> &itemIDs)
@@ -268,7 +281,12 @@ void ListView::setSelectedItem(ListItem *item)
 
 bool ListView::listItemClicked(ListItem *clickedItem)
 {
-    listViewStub->listItemClicked(clickedItem);
+    return listViewStub->listItemClicked(clickedItem);
+}
+
+void ListView::listItemClicked(QListWidgetItem *item)
+{
+    listViewStub->listItemClicked(item);
 }
 
 #endif // LISTVIEWSTUB_H
index 1070b1f..ceaf73e 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "../../src/ui/personlistitem.h"
 #include "../../src/coordinates/geocoordinate.h"
+#include "extendedlistitem.h"
 #include "stubbase.h"
 
 class PersonListItemStub : public StubBase
@@ -55,7 +56,7 @@ QString PersonListItemStub::facebookId() const
 void PersonListItemStub::setAvatarImage(const QPixmap &image)
 {
     QList<ParameterBase *> params;
-    params.append(new Parameter<const QPixmap *>(image));
+    params.append(new Parameter<const QPixmap &>(image));
     stubMethodEntered("setAvatarImage", params);
 }
 
@@ -83,12 +84,17 @@ PersonListItem::PersonListItem()
     personListItemStub->PersonListItemConstructor();
 }
 
+PersonListItem::~PersonListItem()
+{
+
+}
+
 GeoCoordinate PersonListItem::coordinates() const
 {
     return personListItemStub->coordinates();
 }
 
-GeoCoordinate PersonListItem::facebookId() const
+QString PersonListItem::facebookId() const
 {
     return personListItemStub->facebookId();
 }
index 627d47e..6052819 100644 (file)
@@ -59,7 +59,7 @@ PersonListView::PersonListView(QWidget *parent)
 
 bool PersonListView::listItemClicked(ListItem *item)
 {
-    personListViewStub->listItemClicked(item);
+    return personListViewStub->listItemClicked(item);
 }
 
 #endif // PERSONLISTVIEWSTUB_H
diff --git a/tests/ui/listview/listview.pro b/tests/ui/listview/listview.pro
new file mode 100644 (file)
index 0000000..9c74647
--- /dev/null
@@ -0,0 +1,14 @@
+CONFIG += qtestlib
+DEFINES += QT_NO_DEBUG_OUTPUT
+
+INCLUDEPATH += /home/jupe/Desktop/sbhome/projects/situare/tests/stubs/
+
+HEADERS += \
+    ../../stubs/stubbase.h \
+    ../../stubs/listitem.h \
+    ../../../src/ui/listview.h
+
+SOURCES += \
+    ../../stubs/stubbase.cpp \
+    ../../../src/ui/listview.cpp \
+    testlistview.cpp
diff --git a/tests/ui/listview/testlistview.cpp b/tests/ui/listview/testlistview.cpp
new file mode 100644 (file)
index 0000000..e81e1af
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+   Situare - A location system for Facebook
+   Copyright (C) 2010  Ixonos Plc. Authors:
+
+       Jussi Laitinen - jussi.laitinen@ixonos.com
+
+   Situare is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   version 2 as published by the Free Software Foundation.
+
+   Situare is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with Situare; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
+   USA.
+*/
+
+#include <QtTest>
+#include <QtGui>
+
+#include "../../../src/ui/listview.h"
+
+class TestListView: public QObject
+{
+    Q_OBJECT
+
+private slots:
+    void cleanup();
+    void init();
+
+private:
+    ListView *m_listView;
+};
+
+void TestListView::cleanup()
+{
+    delete m_listView;
+}
+
+void TestListView::init()
+{
+    m_listView = new ListView();
+    QVERIFY(m_listView);
+}
+
+QTEST_MAIN(TestListView)
+#include "testlistview.moc"
+
index 9cb7d4c..e3673da 100644 (file)
@@ -4,12 +4,14 @@ DEFINES += QT_NO_DEBUG_OUTPUT
 INCLUDEPATH += ../../stubs/
 
 HEADERS += \
+    ../../stubs/stubbase.h \
     ../../stubs/personlistview.h \
     ../../stubs/personlistitem.h \
     ../../stubs/listview.h \
     ../../stubs/listitem.h \
     ../../stubs/extendedlistitem.h \
     ../../../src/ui/extendedlistitemdelegate.h \
+    ../../../src/ui/headerlistitemdelegate.h \
     ../../../src/ui/listitemdelegate.h \
     ../../../src/ui/meetpeoplepanel.h \
     ../../../src/coordinates/geocoordinate.h \
@@ -24,9 +26,11 @@ HEADERS += \
     ../../../src/user/user.h
 
 SOURCES += \
+    ../../stubs/stubbase.cpp \
     ../../../src/ui/meetpeoplepanel.cpp \
     ../../../src/user/user.cpp \
     ../../../src/ui/extendedlistitemdelegate.cpp \
+    ../../../src/ui/headerlistitemdelegate.cpp \
     ../../../src/ui/listitemdelegate.cpp \
     ../../../src/ui/imagebutton.cpp \
     ../../../src/ui/panelbase.cpp \