2012-07-01 23:05:03 +00:00
|
|
|
/*
|
|
|
|
* Retroshare Posted Plugin.
|
|
|
|
*
|
|
|
|
* Copyright 2012-2012 by Robert Fernie.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License Version 2.1 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QMouseEvent>
|
|
|
|
#include <QBuffer>
|
2012-07-28 09:25:10 +00:00
|
|
|
#include <time.h>
|
2012-07-01 23:05:03 +00:00
|
|
|
|
|
|
|
#include "PostedItem.h"
|
|
|
|
|
2012-10-21 19:45:35 +00:00
|
|
|
#include <retroshare/rsposted.h>
|
2012-07-01 23:05:03 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
|
|
/** Constructor */
|
2013-03-15 21:02:43 +00:00
|
|
|
|
|
|
|
PostedItem::PostedItem(FeedHolder *parent, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome)
|
|
|
|
:GxsFeedItem(parent, feedId, groupId, messageId, isHome, rsPosted, true)
|
2012-07-01 23:05:03 +00:00
|
|
|
{
|
2013-03-15 21:02:43 +00:00
|
|
|
setup();
|
|
|
|
}
|
2012-07-01 23:05:03 +00:00
|
|
|
|
2013-03-15 21:02:43 +00:00
|
|
|
PostedItem::PostedItem(FeedHolder *parent, uint32_t feedId, const RsPostedPost &post, bool isHome)
|
|
|
|
:GxsFeedItem(parent, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsPosted, false),
|
|
|
|
mPost(post)
|
|
|
|
{
|
|
|
|
setup();
|
|
|
|
|
|
|
|
setContent(mPost);
|
|
|
|
}
|
2012-12-09 22:38:49 +00:00
|
|
|
|
|
|
|
|
2013-03-15 21:02:43 +00:00
|
|
|
void PostedItem::setup()
|
|
|
|
{
|
|
|
|
setupUi(this);
|
|
|
|
setAttribute ( Qt::WA_DeleteOnClose, true );
|
|
|
|
|
|
|
|
connect( commentButton, SIGNAL( clicked() ), this, SLOT( loadComments() ) );
|
|
|
|
connect( voteUpButton, SIGNAL(clicked()), this, SLOT(makeUpVote()));
|
|
|
|
connect( voteDownButton, SIGNAL(clicked()), this, SLOT( makeDownVote()));
|
|
|
|
|
|
|
|
return;
|
2012-12-09 22:38:49 +00:00
|
|
|
}
|
|
|
|
|
2013-03-15 21:02:43 +00:00
|
|
|
|
|
|
|
void PostedItem::loadMessage(const uint32_t &token)
|
|
|
|
{
|
|
|
|
std::vector<RsPostedPost> posts;
|
|
|
|
if (!rsPosted->getPostData(token, posts))
|
|
|
|
{
|
|
|
|
std::cerr << "GxsChannelPostItem::loadMessage() ERROR getting data";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (posts.size() != 1)
|
|
|
|
{
|
|
|
|
std::cerr << "GxsChannelPostItem::loadMessage() Wrong number of Items";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPost = posts[0];
|
|
|
|
setContent(mPost);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2012-12-09 22:38:49 +00:00
|
|
|
void PostedItem::setContent(const RsPostedPost &post)
|
|
|
|
{
|
2013-03-15 21:02:43 +00:00
|
|
|
mPost = post;
|
|
|
|
QDateTime qtime;
|
|
|
|
qtime.setTime_t(mPost.mMeta.mPublishTs);
|
|
|
|
QString timestamp = qtime.toString("dd.MMMM yyyy hh:mm");
|
|
|
|
dateLabel->setText(timestamp);
|
|
|
|
fromLabel->setText(QString::fromUtf8(post.mMeta.mAuthorId.c_str()));
|
|
|
|
titleLabel->setText("<a href=" + QString::fromStdString(post.mLink) +
|
|
|
|
"><span style=\" text-decoration: underline; color:#0000ff;\">" +
|
|
|
|
QString::fromStdString(post.mMeta.mMsgName) + "</span></a>");
|
|
|
|
siteLabel->setText("<a href=" + QString::fromStdString(post.mLink) +
|
|
|
|
"><span style=\" text-decoration: underline; color:#0000ff;\">" +
|
|
|
|
QString::fromStdString(post.mLink) + "</span></a>");
|
|
|
|
|
|
|
|
uint32_t up, down, nComments;
|
2012-12-08 21:50:13 +00:00
|
|
|
|
2013-03-11 20:53:15 +00:00
|
|
|
#if 0
|
2013-03-15 21:02:43 +00:00
|
|
|
bool ok = rsPosted->retrieveScores(mPost.mMeta.mServiceString, up, down, nComments);
|
|
|
|
|
|
|
|
if(ok)
|
|
|
|
{
|
|
|
|
int32_t vote = up - down;
|
|
|
|
scoreLabel->setText(QString::number(vote));
|
|
|
|
|
|
|
|
numCommentsLabel->setText("<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px;"
|
|
|
|
"margin-right:0px; -qt-block-indent:0; text-indent:0px;\"><span"
|
|
|
|
"style=\" font-size:10pt; font-weight:600;\">#</span><span "
|
|
|
|
"style=\" font-size:8pt; font-weight:600;\"> Comments: "
|
|
|
|
+ QString::number(nComments) + "</span></p>");
|
|
|
|
}
|
2013-03-11 20:53:15 +00:00
|
|
|
#endif
|
2012-08-01 01:47:53 +00:00
|
|
|
|
2012-07-01 23:05:03 +00:00
|
|
|
}
|
|
|
|
|
2012-11-22 22:40:31 +00:00
|
|
|
RsPostedPost PostedItem::getPost() const
|
|
|
|
{
|
2013-03-15 21:02:43 +00:00
|
|
|
return mPost;
|
2012-11-22 22:40:31 +00:00
|
|
|
}
|
2012-07-01 23:05:03 +00:00
|
|
|
|
2012-12-05 22:45:44 +00:00
|
|
|
void PostedItem::makeDownVote()
|
|
|
|
{
|
2013-03-15 21:02:43 +00:00
|
|
|
RsGxsGrpMsgIdPair msgId;
|
|
|
|
msgId.first = mPost.mMeta.mGroupId;
|
|
|
|
msgId.second = mPost.mMeta.mMsgId;
|
|
|
|
emit vote(msgId, false);
|
2012-12-05 22:45:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PostedItem::makeUpVote()
|
|
|
|
{
|
2013-03-15 21:02:43 +00:00
|
|
|
RsGxsGrpMsgIdPair msgId;
|
|
|
|
msgId.first = mPost.mMeta.mGroupId;
|
|
|
|
msgId.second = mPost.mMeta.mMsgId;
|
|
|
|
emit vote(msgId, true);
|
2012-12-05 22:45:44 +00:00
|
|
|
}
|
|
|
|
|
2012-08-01 01:47:53 +00:00
|
|
|
void PostedItem::loadComments()
|
|
|
|
{
|
2013-03-15 21:02:43 +00:00
|
|
|
std::cerr << "PostedItem::loadComments()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
if (mParent)
|
|
|
|
{
|
|
|
|
QString title = QString::fromUtf8(mPost.mMeta.mMsgName.c_str());
|
|
|
|
mParent->openComments(0, mPost.mMeta.mGroupId, mPost.mMeta.mMsgId, title);
|
|
|
|
}
|
2012-08-01 01:47:53 +00:00
|
|
|
}
|
2013-03-15 21:02:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|