added to display avatars and author names for ForumMsgItem

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3984 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
defnax 2011-01-26 09:34:48 +00:00
parent e57f8836e4
commit 9263710f9e
5 changed files with 208 additions and 53 deletions

View File

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

View File

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

View File

@ -25,17 +25,24 @@
#include "FeedHolder.h"
#include <retroshare/rsforums.h>
#include <retroshare/rsmsgs.h>
#include <retroshare/rspeers.h>
#include "gui/notifyqt.h"
#include "gui/forums/CreateForumMsg.h"
#include "gui/chat/HandleRichText.h"
#include <algorithm>
/****
* #define DEBUG_ITEM 1
****/
/** Constructor */
ForumMsgItem::ForumMsgItem(FeedHolder *parent, uint32_t feedId, std::string forumId, std::string postId, bool isHome)
ForumMsgItem::ForumMsgItem(FeedHolder *parent, uint32_t feedId, std::string forumId, std::string postId, std::string gpgId, bool isHome)
: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 */
setupUi(this);
@ -51,9 +58,12 @@ ForumMsgItem::ForumMsgItem(FeedHolder *parent, uint32_t feedId, std::string foru
connect( unsubscribeButton, SIGNAL( clicked( void ) ), this, SLOT( unsubscribeForum ( void ) ) );
connect( replyButton, SIGNAL( clicked( void ) ), this, SLOT( replyToPost ( void ) ) );
connect(NotifyQt::getInstance(), SIGNAL(peerHasNewAvatar(const QString&)), this, SLOT(updateAvatar(const QString&)));
small();
updateItemStatic();
updateItem();
showAvatar("");
}
@ -111,8 +121,18 @@ void ForumMsgItem::updateItemStatic()
mIsTop = true;
}
if (rsPeers->getPeerName(msg.srcId) !="")
{
namelabel->setText(QString::fromStdString(rsPeers->getPeerName(msg.srcId)));
}
else
{
namelabel->setText(tr("Anonymous"));
}
if (mIsTop)
{
prevSHLabel->setText("Subject: ");
prevSubLabel->setText(QString::fromStdWString(msg.title));
prevMsgLabel->setText(RsHtml::formatText(QString::fromStdWString(msg.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
@ -141,6 +161,16 @@ void ForumMsgItem::updateItemStatic()
{
prevSubLabel->setText(QString::fromStdWString(msgParent.title));
prevMsgLabel->setText(RsHtml::formatText(QString::fromStdWString(msgParent.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
if (rsPeers->getPeerName(msgParent.srcId) !="")
{
nextnamelabel->setText(QString::fromStdString(rsPeers->getPeerName(msgParent.srcId)));
}
else
{
nextnamelabel->setText(tr("Anonymous"));
}
}
else
{
@ -274,3 +304,68 @@ void ForumMsgItem::replyToPost()
}
void ForumMsgItem::updateAvatar(const QString &peer_id)
{
if (mGpgId.empty()) {
/* Message is not signed */
return;
}
/* Is this one of the ssl ids of the gpg id ? */
std::list<std::string> sslIds;
if (rsPeers->getSSLChildListOfGPGId(mGpgId, sslIds) == false) {
return;
}
if (std::find(sslIds.begin(), sslIds.end(), peer_id.toStdString()) == sslIds.end()) {
/* Not one of the ssl ids of the gpg id */
return;
}
showAvatar(peer_id.toStdString());
}
void ForumMsgItem::showAvatar(const std::string &peer_id)
{
if (mGpgId.empty()) {
/* Message is not signed */
avatarlabel->setPixmap(QPixmap(":/images/user/personal64.png"));
return;
}
unsigned char *data = NULL;
int size = 0 ;
if (mGpgId == rsPeers->getGPGOwnId()) {
/* Its me */
rsMsgs->getOwnAvatarData(data,size);
} else {
if (peer_id.empty()) {
/* Show the first available avatar of one of the ssl ids */
std::list<std::string> sslIds;
if (rsPeers->getSSLChildListOfGPGId(mGpgId, sslIds) == false) {
return;
}
std::list<std::string>::iterator sslId;
for (sslId = sslIds.begin(); sslId != sslIds.end(); sslId++) {
rsMsgs->getAvatarData(*sslId,data,size);
if (size) {
break;
}
}
} else {
rsMsgs->getAvatarData(peer_id,data,size);
}
}
if(size != 0) {
// set the image
QPixmap pix ;
pix.loadFromData(data,size,"PNG") ;
avatarlabel->setPixmap(pix);
delete[] data ;
} else {
avatarlabel->setPixmap(QPixmap(":/images/user/personal64.png"));
}
}

View File

@ -32,10 +32,10 @@ class ForumMsgItem : public QWidget, private Ui::ForumMsgItem
Q_OBJECT
public:
/** Default Constructor */
ForumMsgItem(FeedHolder *parent, uint32_t feedId, std::string forumId, std::string postId, bool isHome);
/** Default Constructor */
ForumMsgItem(FeedHolder *parent, uint32_t feedId, std::string forumId, std::string postId, std::string gpgId, bool isHome);
/** Default Destructor */
/** Default Destructor */
void updateItemStatic();
void small();
@ -51,13 +51,17 @@ private slots:
void replyToPost();
void updateItem();
void updateAvatar(const QString &peer_id);
private:
void showAvatar(const std::string &peer_id);
FeedHolder *mParent;
uint32_t mFeedId;
std::string mForumId;
std::string mPostId;
std::string mGpgId;
bool mIsHome;
bool mIsTop;
};

View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>716</width>
<height>270</height>
<width>764</width>
<height>319</height>
</rect>
</property>
<property name="windowTitle">
@ -305,14 +305,47 @@ border-radius: 10px}</string>
</item>
<item row="2" column="0" colspan="2">
<widget class="QFrame" name="prevFrame">
<property name="styleSheet">
<string notr="true">QFrame#prevFrame{border: 2px solid black;
border-radius: 10px}</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout">
<item>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="0" rowspan="2">
<widget class="QLabel" name="avatarlabel">
<property name="minimumSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="namelabel">
<property name="text">
<string>Friend Name</string>
</property>
</widget>
</item>
<item row="1" column="1" rowspan="2">
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="prevSHLabel">
@ -364,7 +397,20 @@ border-radius: 10px}</string>
</item>
</layout>
</item>
<item>
<item row="2" column="0" rowspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>9</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="1">
<layout class="QHBoxLayout">
<item>
<widget class="QLabel" name="prevMsgLabel">
@ -408,31 +454,48 @@ border-radius: 10px}</string>
</item>
<item row="3" column="0" colspan="2">
<widget class="QFrame" name="nextFrame">
<property name="styleSheet">
<string notr="true">QFrame#nextFrame{border: 2px solid black;
border-radius: 10px}</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout">
<item>
<layout class="QGridLayout" name="gridLayout_5">
<item row="0" column="0" rowspan="3">
<widget class="QLabel" name="nextavatarlabel">
<property name="minimumSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>32</width>
<height>32</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="scaledContents">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="nextnamelabel">
<property name="text">
<string>Next Name</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout">
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label_9">
<property name="sizePolicy">
@ -467,24 +530,21 @@ border-radius: 10px}</string>
</item>
</layout>
</item>
<item>
<item row="3" column="0">
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>27</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1" rowspan="2">
<layout class="QHBoxLayout">
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="nextMsgLabel">
<property name="sizePolicy">