Fixed display of the names and avatars in ForumMsgItem.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3985 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2011-01-26 21:36:13 +00:00
parent 9263710f9e
commit c2a81daf01
4 changed files with 74 additions and 47 deletions

View File

@ -580,7 +580,11 @@ bool p3Forums::locked_eventDuplicateMsg(GroupInfo *grp, RsDistribMsg *msg, std::
bool p3Forums::locked_eventNewMsg(GroupInfo *grp, RsDistribMsg *msg, std::string id) bool p3Forums::locked_eventNewMsg(GroupInfo *grp, RsDistribMsg *msg, std::string id)
{ {
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_FORUM_MSG, msg->grpId, msg->msgId, msg->personalSignature.keyId); std::string grpId = msg->grpId;
std::string msgId = msg->msgId;
std::string nullId;
getPqiNotify()->AddFeedItem(RS_FEED_ITEM_FORUM_MSG, grpId, msgId, nullId);
return true; return true;
} }

View File

@ -330,7 +330,7 @@ void NewsFeed::addFeedItemForumUpdate(RsFeedItem &fi)
void NewsFeed::addFeedItemForumMsg(RsFeedItem &fi) void NewsFeed::addFeedItemForumMsg(RsFeedItem &fi)
{ {
/* make new widget */ /* make new widget */
ForumMsgItem *fm = new ForumMsgItem(this, NEWSFEED_FORUMMSGLIST, fi.mId1, fi.mId2, fi.mId3, false); ForumMsgItem *fm = new ForumMsgItem(this, NEWSFEED_FORUMMSGLIST, fi.mId1, fi.mId2, false);
/* store in forum list */ /* store in forum list */

View File

@ -40,9 +40,8 @@
****/ ****/
/** Constructor */ /** Constructor */
ForumMsgItem::ForumMsgItem(FeedHolder *parent, uint32_t feedId, std::string forumId, std::string postId, std::string gpgId, bool isHome) ForumMsgItem::ForumMsgItem(FeedHolder *parent, uint32_t feedId, const std::string &forumId, const std::string &postId, bool isHome)
:QWidget(NULL), mParent(parent), mFeedId(feedId), :QWidget(NULL), mParent(parent), mFeedId(feedId), mForumId(forumId), mPostId(postId), mIsHome(isHome), mIsTop(false)
mForumId(forumId), mPostId(postId), mGpgId(gpgId), mIsHome(isHome), mIsTop(false)
{ {
/* Invoke the Qt Designer generated object setup routine */ /* Invoke the Qt Designer generated object setup routine */
setupUi(this); setupUi(this);
@ -63,7 +62,6 @@ ForumMsgItem::ForumMsgItem(FeedHolder *parent, uint32_t feedId, std::string foru
small(); small();
updateItemStatic(); updateItemStatic();
updateItem(); updateItem();
showAvatar("");
} }
@ -72,7 +70,6 @@ void ForumMsgItem::updateItemStatic()
if (!rsForums) if (!rsForums)
return; return;
/* fill in */ /* fill in */
#ifdef DEBUG_ITEM #ifdef DEBUG_ITEM
std::cerr << "ForumMsgItem::updateItemStatic()"; std::cerr << "ForumMsgItem::updateItemStatic()";
@ -121,6 +118,10 @@ void ForumMsgItem::updateItemStatic()
mIsTop = true; mIsTop = true;
} }
if (mIsTop)
{
mGpgIdPrev = msg.srcId;
if (rsPeers->getPeerName(msg.srcId) !="") if (rsPeers->getPeerName(msg.srcId) !="")
{ {
namelabel->setText(QString::fromStdString(rsPeers->getPeerName(msg.srcId))); namelabel->setText(QString::fromStdString(rsPeers->getPeerName(msg.srcId)));
@ -130,10 +131,6 @@ void ForumMsgItem::updateItemStatic()
namelabel->setText(tr("Anonymous")); namelabel->setText(tr("Anonymous"));
} }
if (mIsTop)
{
prevSHLabel->setText("Subject: ");
prevSubLabel->setText(QString::fromStdWString(msg.title)); prevSubLabel->setText(QString::fromStdWString(msg.title));
prevMsgLabel->setText(RsHtml::formatText(QString::fromStdWString(msg.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS)); prevMsgLabel->setText(RsHtml::formatText(QString::fromStdWString(msg.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
@ -146,6 +143,17 @@ void ForumMsgItem::updateItemStatic()
} }
else else
{ {
mGpgIdNext = msg.srcId;
if (rsPeers->getPeerName(msg.srcId) !="")
{
nextnamelabel->setText(QString::fromStdString(rsPeers->getPeerName(msg.srcId)));
}
else
{
nextnamelabel->setText(tr("Anonymous"));
}
nextSubLabel->setText(QString::fromStdWString(msg.title)); nextSubLabel->setText(QString::fromStdWString(msg.title));
nextMsgLabel->setText(RsHtml::formatText(QString::fromStdWString(msg.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS)); nextMsgLabel->setText(RsHtml::formatText(QString::fromStdWString(msg.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
@ -159,18 +167,19 @@ void ForumMsgItem::updateItemStatic()
ForumMsgInfo msgParent; ForumMsgInfo msgParent;
if (rsForums->getForumMessage(mForumId, msg.parentId, msgParent)) if (rsForums->getForumMessage(mForumId, msg.parentId, msgParent))
{ {
mGpgIdPrev = msgParent.srcId;
prevSubLabel->setText(QString::fromStdWString(msgParent.title)); prevSubLabel->setText(QString::fromStdWString(msgParent.title));
prevMsgLabel->setText(RsHtml::formatText(QString::fromStdWString(msgParent.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS)); prevMsgLabel->setText(RsHtml::formatText(QString::fromStdWString(msgParent.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
if (rsPeers->getPeerName(msgParent.srcId) !="") if (rsPeers->getPeerName(msgParent.srcId) !="")
{ {
nextnamelabel->setText(QString::fromStdString(rsPeers->getPeerName(msgParent.srcId))); namelabel->setText(QString::fromStdString(rsPeers->getPeerName(msgParent.srcId)));
} }
else else
{ {
nextnamelabel->setText(tr("Anonymous")); namelabel->setText(tr("Anonymous"));
} }
} }
else else
{ {
@ -195,6 +204,9 @@ void ForumMsgItem::updateItemStatic()
} }
unsubscribeButton->hide(); unsubscribeButton->hide();
showAvatar("", true);
showAvatar("", false);
} }
@ -306,44 +318,54 @@ void ForumMsgItem::replyToPost()
void ForumMsgItem::updateAvatar(const QString &peer_id) void ForumMsgItem::updateAvatar(const QString &peer_id)
{ {
if (mGpgId.empty()) { if (mGpgIdPrev.empty() == false) {
/* Message is not signed */
return;
}
/* Is this one of the ssl ids of the gpg id ? */ /* Is this one of the ssl ids of the gpg id ? */
std::list<std::string> sslIds; std::list<std::string> sslIds;
if (rsPeers->getSSLChildListOfGPGId(mGpgId, sslIds) == false) { if (rsPeers->getSSLChildListOfGPGId(mGpgIdPrev, sslIds) == false) {
return; return;
} }
if (std::find(sslIds.begin(), sslIds.end(), peer_id.toStdString()) == sslIds.end()) { if (std::find(sslIds.begin(), sslIds.end(), peer_id.toStdString()) != sslIds.end()) {
/* Not one of the ssl ids of the gpg id */ /* One of the ssl ids of the gpg id */
showAvatar(peer_id.toStdString(), false);
}
}
if (mGpgIdNext.empty() == false) {
/* Is this one of the ssl ids of the gpg id ? */
std::list<std::string> sslIds;
if (rsPeers->getSSLChildListOfGPGId(mGpgIdNext, sslIds) == false) {
return; return;
} }
showAvatar(peer_id.toStdString()); if (std::find(sslIds.begin(), sslIds.end(), peer_id.toStdString()) != sslIds.end()) {
/* One of the ssl ids of the gpg id */
showAvatar(peer_id.toStdString(), true);
}
}
} }
void ForumMsgItem::showAvatar(const std::string &peer_id) void ForumMsgItem::showAvatar(const std::string &peer_id, bool next)
{ {
if (mGpgId.empty()) { std::string gpgId = next ? mGpgIdNext : mGpgIdPrev;
/* Message is not signed */ QLabel *avatar = next ? nextavatarlabel : avatarlabel;
avatarlabel->setPixmap(QPixmap(":/images/user/personal64.png"));
if (gpgId.empty()) {
avatar->setPixmap(QPixmap(":/images/user/personal64.png"));
return; return;
} }
unsigned char *data = NULL; unsigned char *data = NULL;
int size = 0 ; int size = 0 ;
if (mGpgId == rsPeers->getGPGOwnId()) { if (gpgId == rsPeers->getGPGOwnId()) {
/* Its me */ /* Its me */
rsMsgs->getOwnAvatarData(data,size); rsMsgs->getOwnAvatarData(data,size);
} else { } else {
if (peer_id.empty()) { if (peer_id.empty()) {
/* Show the first available avatar of one of the ssl ids */ /* Show the first available avatar of one of the ssl ids */
std::list<std::string> sslIds; std::list<std::string> sslIds;
if (rsPeers->getSSLChildListOfGPGId(mGpgId, sslIds) == false) { if (rsPeers->getSSLChildListOfGPGId(gpgId, sslIds) == false) {
return; return;
} }
@ -363,9 +385,9 @@ void ForumMsgItem::showAvatar(const std::string &peer_id)
// set the image // set the image
QPixmap pix ; QPixmap pix ;
pix.loadFromData(data,size,"PNG") ; pix.loadFromData(data,size,"PNG") ;
avatarlabel->setPixmap(pix); avatar->setPixmap(pix);
delete[] data ; delete[] data ;
} else { } else {
avatarlabel->setPixmap(QPixmap(":/images/user/personal64.png")); avatar->setPixmap(QPixmap(":/images/user/personal64.png"));
} }
} }

View File

@ -33,7 +33,7 @@ class ForumMsgItem : public QWidget, private Ui::ForumMsgItem
public: public:
/** Default Constructor */ /** Default Constructor */
ForumMsgItem(FeedHolder *parent, uint32_t feedId, std::string forumId, std::string postId, std::string gpgId, bool isHome); ForumMsgItem(FeedHolder *parent, uint32_t feedId, const std::string &forumId, const std::string &postId, bool isHome);
/** Default Destructor */ /** Default Destructor */
@ -54,14 +54,15 @@ private slots:
void updateAvatar(const QString &peer_id); void updateAvatar(const QString &peer_id);
private: private:
void showAvatar(const std::string &peer_id); void showAvatar(const std::string &peer_id, bool next);
FeedHolder *mParent; FeedHolder *mParent;
uint32_t mFeedId; uint32_t mFeedId;
std::string mForumId; std::string mForumId;
std::string mPostId; std::string mPostId;
std::string mGpgId; std::string mGpgIdPrev;
std::string mGpgIdNext;
bool mIsHome; bool mIsHome;
bool mIsTop; bool mIsTop;
}; };