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) bool p3Forums::locked_eventNewMsg(GroupInfo *grp, RsDistribMsg *msg, std::string id)
{ {
std::string grpId = msg->grpId; getPqiNotify()->AddFeedItem(RS_FEED_ITEM_FORUM_MSG, msg->grpId, msg->msgId, msg->personalSignature.keyId);
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, false); ForumMsgItem *fm = new ForumMsgItem(this, NEWSFEED_FORUMMSGLIST, fi.mId1, fi.mId2, fi.mId3, false);
/* store in forum list */ /* store in forum list */

View File

@ -25,17 +25,24 @@
#include "FeedHolder.h" #include "FeedHolder.h"
#include <retroshare/rsforums.h> #include <retroshare/rsforums.h>
#include <retroshare/rsmsgs.h>
#include <retroshare/rspeers.h>
#include "gui/notifyqt.h"
#include "gui/forums/CreateForumMsg.h" #include "gui/forums/CreateForumMsg.h"
#include "gui/chat/HandleRichText.h" #include "gui/chat/HandleRichText.h"
#include <algorithm>
/**** /****
* #define DEBUG_ITEM 1 * #define DEBUG_ITEM 1
****/ ****/
/** Constructor */ /** 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), :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);
@ -51,9 +58,12 @@ ForumMsgItem::ForumMsgItem(FeedHolder *parent, uint32_t feedId, std::string foru
connect( unsubscribeButton, SIGNAL( clicked( void ) ), this, SLOT( unsubscribeForum ( void ) ) ); connect( unsubscribeButton, SIGNAL( clicked( void ) ), this, SLOT( unsubscribeForum ( void ) ) );
connect( replyButton, SIGNAL( clicked( void ) ), this, SLOT( replyToPost ( void ) ) ); connect( replyButton, SIGNAL( clicked( void ) ), this, SLOT( replyToPost ( void ) ) );
connect(NotifyQt::getInstance(), SIGNAL(peerHasNewAvatar(const QString&)), this, SLOT(updateAvatar(const QString&)));
small(); small();
updateItemStatic(); updateItemStatic();
updateItem(); updateItem();
showAvatar("");
} }
@ -111,8 +121,18 @@ void ForumMsgItem::updateItemStatic()
mIsTop = true; mIsTop = true;
} }
if (rsPeers->getPeerName(msg.srcId) !="")
{
namelabel->setText(QString::fromStdString(rsPeers->getPeerName(msg.srcId)));
}
else
{
namelabel->setText(tr("Anonymous"));
}
if (mIsTop) if (mIsTop)
{ {
prevSHLabel->setText("Subject: "); 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));
@ -141,6 +161,16 @@ void ForumMsgItem::updateItemStatic()
{ {
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) !="")
{
nextnamelabel->setText(QString::fromStdString(rsPeers->getPeerName(msgParent.srcId)));
}
else
{
nextnamelabel->setText(tr("Anonymous"));
}
} }
else 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

@ -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, bool isHome); ForumMsgItem(FeedHolder *parent, uint32_t feedId, std::string forumId, std::string postId, std::string gpgId, bool isHome);
/** Default Destructor */ /** Default Destructor */
@ -51,13 +51,17 @@ private slots:
void replyToPost(); void replyToPost();
void updateItem(); void updateItem();
void updateAvatar(const QString &peer_id);
private: private:
void showAvatar(const std::string &peer_id);
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;
bool mIsHome; bool mIsHome;
bool mIsTop; bool mIsTop;
}; };

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>716</width> <width>764</width>
<height>270</height> <height>319</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -305,14 +305,47 @@ border-radius: 10px}</string>
</item> </item>
<item row="2" column="0" colspan="2"> <item row="2" column="0" colspan="2">
<widget class="QFrame" name="prevFrame"> <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"> <property name="frameShape">
<enum>QFrame::StyledPanel</enum> <enum>QFrame::StyledPanel</enum>
</property> </property>
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<layout class="QVBoxLayout"> <layout class="QGridLayout" name="gridLayout_4">
<item> <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"> <layout class="QHBoxLayout">
<item> <item>
<widget class="QLabel" name="prevSHLabel"> <widget class="QLabel" name="prevSHLabel">
@ -364,7 +397,20 @@ border-radius: 10px}</string>
</item> </item>
</layout> </layout>
</item> </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"> <layout class="QHBoxLayout">
<item> <item>
<widget class="QLabel" name="prevMsgLabel"> <widget class="QLabel" name="prevMsgLabel">
@ -408,31 +454,48 @@ border-radius: 10px}</string>
</item> </item>
<item row="3" column="0" colspan="2"> <item row="3" column="0" colspan="2">
<widget class="QFrame" name="nextFrame"> <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"> <property name="frameShape">
<enum>QFrame::StyledPanel</enum> <enum>QFrame::StyledPanel</enum>
</property> </property>
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<layout class="QVBoxLayout"> <layout class="QGridLayout" name="gridLayout_5">
<item> <item row="0" column="0" rowspan="3">
<layout class="QHBoxLayout"> <widget class="QLabel" name="nextavatarlabel">
<item> <property name="minimumSize">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property>
<property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>32</width>
<height>20</height> <height>32</height>
</size> </size>
</property> </property>
</spacer> <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>
<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> <item>
<widget class="QLabel" name="label_9"> <widget class="QLabel" name="label_9">
<property name="sizePolicy"> <property name="sizePolicy">
@ -467,24 +530,21 @@ border-radius: 10px}</string>
</item> </item>
</layout> </layout>
</item> </item>
<item> <item row="3" column="0">
<layout class="QHBoxLayout"> <spacer name="verticalSpacer_2">
<item>
<spacer>
<property name="orientation"> <property name="orientation">
<enum>Qt::Horizontal</enum> <enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Preferred</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>20</width>
<height>20</height> <height>27</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="2" column="1" rowspan="2">
<layout class="QHBoxLayout">
<item> <item>
<widget class="QLabel" name="nextMsgLabel"> <widget class="QLabel" name="nextMsgLabel">
<property name="sizePolicy"> <property name="sizePolicy">