From: Jussi Laitinen Date: Fri, 5 Nov 2010 13:56:38 +0000 (+0200) Subject: Modified TagsDialog. X-Git-Url: https://vcs.maemo.org/git/?a=commitdiff_plain;ds=sidebyside;h=6c328fe11deae627473a9685ed826bba6e892d53;p=situare Modified TagsDialog. --- diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 35fe815..561e857 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -859,8 +859,8 @@ void SituareEngine::signalsFromSituareService() connect(m_situareService, SIGNAL(updateWasSuccessful(SituareService::SuccessfulMethod)), m_ui, SIGNAL(clearUpdateLocationDialogData())); - connect(m_situareService, SIGNAL(interestingPeopleReceived(QList&)), - m_ui, SIGNAL(interestingPeopleReceived(QList&))); + connect(m_situareService, SIGNAL(interestingPeopleReceived(QList&,QList&)), + m_ui, SIGNAL(interestingPeopleReceived(QList&,QList&))); connect(m_situareService, SIGNAL(messagesReceived(QList&, QList &)), m_ui, SIGNAL(messagesReceived(QList&, QList&))); diff --git a/src/situareservice/database.cpp b/src/situareservice/database.cpp index 82b78d3..29190b1 100644 --- a/src/situareservice/database.cpp +++ b/src/situareservice/database.cpp @@ -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 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 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 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(); } diff --git a/src/situareservice/database.h b/src/situareservice/database.h index 59e09d9..8c13aed 100644 --- a/src/situareservice/database.h +++ b/src/situareservice/database.h @@ -20,6 +20,7 @@ public: bool addTag(qulonglong userId, const QString &tag); QByteArray getNotifications(qulonglong userId); + QByteArray getPopularTags(); QHash getTags(qulonglong userId); QByteArray getInterestingPeople(qulonglong userId, const GeoCoordinate &southWestCoordinates, diff --git a/src/situareservice/message.cpp b/src/situareservice/message.cpp index 0c3923c..0652600 100644 --- a/src/situareservice/message.cpp +++ b/src/situareservice/message.cpp @@ -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__; diff --git a/src/situareservice/message.h b/src/situareservice/message.h index c8c2516..6fc8b1e 100644 --- a/src/situareservice/message.h +++ b/src/situareservice/message.h @@ -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 diff --git a/src/situareservice/situareservice.cpp b/src/situareservice/situareservice.cpp index d00ddbc..6493ad3 100644 --- a/src/situareservice/situareservice.cpp +++ b/src/situareservice/situareservice.cpp @@ -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 interestingPeople; + QVariant people = result["people"]; + + QList friends; + QList others; - foreach (QVariant personVariant, result["people"].toList()) { + foreach (QVariant personVariant, people.toMap().value("friends").toList()) { User user; QMap 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 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 popularTags; + + foreach (QVariant tagVariant, result["popular_tags"].toList()) { + QMap 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) diff --git a/src/situareservice/situareservice.h b/src/situareservice/situareservice.h index 6923c7b..b676067 100644 --- a/src/situareservice/situareservice.h +++ b/src/situareservice/situareservice.h @@ -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 &interestingPeople); + void interestingPeopleReceived(QList &friends, QList &others); /** * @brief Signal when fetchMessages request is finished diff --git a/src/src.pro b/src/src.pro index 2a83d8f..a9850c1 100644 --- a/src/src.pro +++ b/src/src.pro @@ -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 diff --git a/src/ui/listitem.cpp b/src/ui/listitem.cpp index d8ab074..fab9907 100644 --- a/src/ui/listitem.cpp +++ b/src/ui/listitem.cpp @@ -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__; diff --git a/src/ui/listitem.h b/src/ui/listitem.h index cf59961..b84bc2b 100644 --- a/src/ui/listitem.h +++ b/src/ui/listitem.h @@ -92,7 +92,7 @@ public: * * @return item's title */ - QString title() const; + QString title(); /** * @brief Toggles selection. diff --git a/src/ui/listview.cpp b/src/ui/listview.cpp index e429a74..8fde959 100644 --- a/src/ui/listview.cpp +++ b/src/ui/listview.cpp @@ -23,7 +23,6 @@ #include "listitem.h" #include "listview.h" -#include "friendlistitem.h" ListView::ListView(QWidget *parent) : QListWidget(parent), diff --git a/src/ui/listview.h b/src/ui/listview.h index eaf32fb..e1dbdf4 100644 --- a/src/ui/listview.h +++ b/src/ui/listview.h @@ -42,6 +42,11 @@ class ListView : public QListWidget public: /** + * @brief Unit test class + */ + friend class TestListView; + + /** * @brief Constructor. * * @param parent QWidget diff --git a/src/ui/mainwindow.cpp b/src/ui/mainwindow.cpp index 5311205..6b7d5e7 100644 --- a/src/ui/mainwindow.cpp +++ b/src/ui/mainwindow.cpp @@ -345,8 +345,8 @@ void MainWindow::buildMeetPeoplePanel() connect(this, SIGNAL(friendImageReady(QString,QPixmap)), m_meetPeoplePanel, SLOT(setImage(QString,QPixmap))); - connect(this, SIGNAL(interestingPeopleReceived(QList&)), - m_meetPeoplePanel, SLOT(populateInterestingPeopleListView(QList&))); + connect(this, SIGNAL(interestingPeopleReceived(QList&,QList&)), + m_meetPeoplePanel, SLOT(populateInterestingPeopleListView(QList&,QList&))); connect(m_meetPeoplePanel, SIGNAL(requestInterestingPeople()), this, SIGNAL(requestInterestingPeople())); diff --git a/src/ui/mainwindow.h b/src/ui/mainwindow.h index bee4a6a..7f9d040 100644 --- a/src/ui/mainwindow.h +++ b/src/ui/mainwindow.h @@ -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 &interestingPeople); + void interestingPeopleReceived(QList &friends, QList &others); /** * @brief Signal for friend location ready. diff --git a/src/ui/meetpeoplepanel.cpp b/src/ui/meetpeoplepanel.cpp index 5c0ada4..4f63670 100644 --- a/src/ui/meetpeoplepanel.cpp +++ b/src/ui/meetpeoplepanel.cpp @@ -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(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(m_personListView->selectedItem()); - if (personItem) + + if (personItem) { + m_personListView->clearItemSelection(); emit requestMessageDialog(QPair(personItem->facebookId(), personItem->title())); + } } void MeetPeoplePanel::setImage(const QString &id, const QPixmap &image) @@ -104,34 +134,45 @@ void MeetPeoplePanel::showFriend() PersonListItem *personItem = dynamic_cast(m_personListView->selectedItem()); if (personItem) { + m_personListView->clearItemSelection(); QList userIds; userIds.append(personItem->facebookId()); emit requestShowFriend(userIds); } } -void MeetPeoplePanel::populateInterestingPeopleListView(QList &interestingPeople) +void MeetPeoplePanel::populateInterestingPeopleListView(QList &friends, QList &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(); diff --git a/src/ui/meetpeoplepanel.h b/src/ui/meetpeoplepanel.h index 77a7ae8..8407d83 100644 --- a/src/ui/meetpeoplepanel.h +++ b/src/ui/meetpeoplepanel.h @@ -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 &friends, QList &others); + +private: + /** + * @brief Inits item delegates for message list view. */ - void populateInterestingPeopleListView(QList &interestingPeople); + void initItemDelegates(); signals: /** @@ -135,8 +151,11 @@ signals: void requestShowFriend(const QList &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 diff --git a/src/ui/messagelistitem.cpp b/src/ui/messagelistitem.cpp index 4690585..59e8e9c 100644 --- a/src/ui/messagelistitem.cpp +++ b/src/ui/messagelistitem.cpp @@ -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")); } diff --git a/src/ui/messagepanel.cpp b/src/ui/messagepanel.cpp index 518513f..10a3e41 100644 --- a/src/ui/messagepanel.cpp +++ b/src/ui/messagepanel.cpp @@ -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( m_messageListView->selectedItem()); - if (messageItem) + if (messageItem) { + m_messageListView->clearItemSelection(); emit requestMessageDialog(QPair(messageItem->receiverId(), messageItem->title())); + } } void MessagePanel::populateMessageListView(QList &received, QList &sent) diff --git a/src/ui/personlistitem.cpp b/src/ui/personlistitem.cpp index dad016b..897886b 100644 --- a/src/ui/personlistitem.cpp +++ b/src/ui/personlistitem.cpp @@ -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, diff --git a/src/ui/personlistitem.h b/src/ui/personlistitem.h index 95213b8..fe7b0e0 100644 --- a/src/ui/personlistitem.h +++ b/src/ui/personlistitem.h @@ -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 index 0000000..83f569f --- /dev/null +++ b/src/ui/tagcompletion.cpp @@ -0,0 +1,138 @@ +#include +#include +#include +#include +#include +#include +#include + +#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(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 index 0000000..0390ab5 --- /dev/null +++ b/src/ui/tagcompletion.h @@ -0,0 +1,30 @@ +#ifndef TAGCOMPLETION_H +#define TAGCOMPLETION_H + +#include + +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 diff --git a/src/ui/tagsdialog.cpp b/src/ui/tagsdialog.cpp index ec0e2bf..a101a49 100644 --- a/src/ui/tagsdialog.cpp +++ b/src/ui/tagsdialog.cpp @@ -5,35 +5,53 @@ #include #include #include +#include + +#include "tagcompletion.h" #include "tagsdialog.h" -TagsDialog::TagsDialog(const QHash &tags) +TagsDialog::TagsDialog(const QHash &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 &tags) connect(deleteButton, SIGNAL(clicked()), this, SLOT(deleteTagFromList())); + + populateUserTags(tags); } void TagsDialog::addTagToList() { qDebug() << __PRETTY_FUNCTION__; - QList findItems = m_tagsView->findItems(m_addTagEdit->text(), + QList 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 selectedItems = m_tagsView->selectedItems(); + QList 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 &popularTags) +{ + m_popularTagsView->clear(); + + foreach (QString tag, popularTags) + m_popularTagsView->addItem(tag); +} + +void TagsDialog::populateUserTags(const QHash &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); +} diff --git a/src/ui/tagsdialog.h b/src/ui/tagsdialog.h index 9550de8..ef46cb5 100644 --- a/src/ui/tagsdialog.h +++ b/src/ui/tagsdialog.h @@ -52,7 +52,7 @@ public: * * @param parent Instance of parent widget */ - TagsDialog(const QHash &tags); + TagsDialog(const QHash &tags, QWidget *parent = 0); /******************************************************************************* * MEMBER FUNCTIONS AND SLOTS @@ -73,6 +73,11 @@ public: */ QStringList removedTags(); +public slots: + void populateUserTags(const QHash &userTags); + + void populatePopularTags(const QHash &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 diff --git a/src/ui/userinfo.cpp b/src/ui/userinfo.cpp index 6546e5d..06f20c6 100644 --- a/src/ui/userinfo.cpp +++ b/src/ui/userinfo.cpp @@ -312,7 +312,7 @@ void UserInfo::setExpanded(bool expanded) void UserInfo::setTags(const QHash &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(); diff --git a/tests/stubs/extendedlistitem.h b/tests/stubs/extendedlistitem.h index 88c6044..b217b57 100644 --- a/tests/stubs/extendedlistitem.h +++ b/tests/stubs/extendedlistitem.h @@ -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("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 - diff --git a/tests/stubs/listitem.h b/tests/stubs/listitem.h index 08fd6e9..5d85864 100644 --- a/tests/stubs/listitem.h +++ b/tests/stubs/listitem.h @@ -26,66 +26,65 @@ #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 params; - params.append(new Parameter(image)); + params.append(new Parameter(image)); stubMethodEntered("setImage", params); } -void ListViewStub::setTitle(const QString &name) +void ListItemStub::setTitle(const QString &name) { QList params; params.append(new Parameter(name)); stubMethodEntered("setTitle", params); } -void ListViewStub::setSize(const QSize &size) +void ListItemStub::setSize(const QSize &size) { QList params; params.append(new Parameter(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 params; params.append(new Parameter(text)); params.append(new Parameter(textWidth)); - params.append(new Parameter(textSize)); + params.append(new Parameter(textSize)); stubMethodEntered("shortenText", params); return stubReturnValue("shortenText"); } -QString ListViewStub::title() const +QString ListItemStub::title() { return stubReturnValue("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(); } diff --git a/tests/stubs/listview.h b/tests/stubs/listview.h index cf44964..371d48e 100644 --- a/tests/stubs/listview.h +++ b/tests/stubs/listview.h @@ -22,6 +22,8 @@ #ifndef LISTVIEWSTUB_H #define LISTVIEWSTUB_H +#include + #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("listItemClicked"); } +void ListViewStub::listItemClicked(QListWidgetItem *item) +{ + QList params; + params.append(new Parameter(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 &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 diff --git a/tests/stubs/personlistitem.h b/tests/stubs/personlistitem.h index 1070b1f..ceaf73e 100644 --- a/tests/stubs/personlistitem.h +++ b/tests/stubs/personlistitem.h @@ -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 params; - params.append(new Parameter(image)); + params.append(new Parameter(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(); } diff --git a/tests/stubs/personlistview.h b/tests/stubs/personlistview.h index 627d47e..6052819 100644 --- a/tests/stubs/personlistview.h +++ b/tests/stubs/personlistview.h @@ -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 index 0000000..9c74647 --- /dev/null +++ b/tests/ui/listview/listview.pro @@ -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 index 0000000..e81e1af --- /dev/null +++ b/tests/ui/listview/testlistview.cpp @@ -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 +#include + +#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" + diff --git a/tests/ui/meetpeoplepanel/meetpeoplepanel.pro b/tests/ui/meetpeoplepanel/meetpeoplepanel.pro index 9cb7d4c..e3673da 100644 --- a/tests/ui/meetpeoplepanel/meetpeoplepanel.pro +++ b/tests/ui/meetpeoplepanel/meetpeoplepanel.pro @@ -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 \