2013-03-15 17:02:43 -04:00
|
|
|
/*
|
|
|
|
* Retroshare Gxs Feed Item
|
2013-03-11 16:53:15 -04:00
|
|
|
*
|
2013-03-15 17:02:43 -04:00
|
|
|
* Copyright 2012-2013 by Robert Fernie.
|
2013-03-11 16:53:15 -04:00
|
|
|
*
|
2013-03-15 17:02:43 -04:00
|
|
|
* 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.
|
2013-03-11 16:53:15 -04:00
|
|
|
*
|
2013-03-15 17:02:43 -04:00
|
|
|
* 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.
|
2013-03-11 16:53:15 -04:00
|
|
|
*
|
2013-03-15 17:02:43 -04:00
|
|
|
* 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".
|
|
|
|
*
|
|
|
|
*/
|
2013-03-11 16:53:15 -04:00
|
|
|
|
|
|
|
#include <QTimer>
|
|
|
|
#include <QFileInfo>
|
|
|
|
|
|
|
|
#include "rshare.h"
|
|
|
|
#include "GxsChannelPostItem.h"
|
2014-05-05 19:34:28 -04:00
|
|
|
#include "ui_GxsChannelPostItem.h"
|
2013-03-11 16:53:15 -04:00
|
|
|
|
|
|
|
#include "FeedHolder.h"
|
|
|
|
#include "SubFileItem.h"
|
|
|
|
#include "util/misc.h"
|
|
|
|
#include "gui/RetroShareLink.h"
|
|
|
|
#include "util/HandleRichText.h"
|
|
|
|
#include "util/DateTime.h"
|
|
|
|
|
2014-04-04 09:55:00 -04:00
|
|
|
#include <iostream>
|
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
/****
|
|
|
|
* #define DEBUG_ITEM 1
|
|
|
|
****/
|
|
|
|
|
|
|
|
#define COLOR_NORMAL QColor(248, 248, 248)
|
|
|
|
#define COLOR_NEW QColor(220, 236, 253)
|
|
|
|
|
2014-08-01 10:49:58 -04:00
|
|
|
GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsGroupId &groupId, const RsGxsMessageId &messageId, bool isHome, bool autoUpdate) :
|
2014-11-17 19:49:21 -05:00
|
|
|
GxsFeedItem(feedHolder, feedId, groupId, messageId, isHome, rsGxsChannels, autoUpdate)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
|
|
|
setup();
|
2014-11-17 19:49:21 -05:00
|
|
|
|
|
|
|
requestGroup();
|
|
|
|
requestMessage();
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelGroup &group, const RsGxsChannelPost &post, bool isHome, bool autoUpdate) :
|
|
|
|
GxsFeedItem(feedHolder, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsGxsChannels, autoUpdate)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
2014-11-17 19:49:21 -05:00
|
|
|
#ifdef DEBUG_ITEM
|
2013-03-15 17:02:43 -04:00
|
|
|
std::cerr << "GxsChannelPostItem::GxsChannelPostItem() Direct Load";
|
|
|
|
std::cerr << std::endl;
|
2014-11-17 19:49:21 -05:00
|
|
|
#endif
|
2013-03-11 16:53:15 -04:00
|
|
|
|
|
|
|
setup();
|
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
setGroup(group, false);
|
|
|
|
setPost(post);
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelPost &post, bool isHome, bool autoUpdate) :
|
|
|
|
GxsFeedItem(feedHolder, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsGxsChannels, autoUpdate)
|
2014-07-27 14:29:35 -04:00
|
|
|
{
|
2014-11-17 19:49:21 -05:00
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "GxsChannelPostItem::GxsChannelPostItem() Direct Load";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2014-05-06 16:19:04 -04:00
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
setup();
|
2014-05-06 16:19:04 -04:00
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
requestGroup();
|
|
|
|
setPost(post);
|
2014-05-06 16:19:04 -04:00
|
|
|
}
|
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
GxsChannelPostItem::~GxsChannelPostItem()
|
|
|
|
{
|
|
|
|
delete(ui);
|
|
|
|
}
|
2013-03-11 16:53:15 -04:00
|
|
|
|
|
|
|
void GxsChannelPostItem::setup()
|
|
|
|
{
|
|
|
|
/* Invoke the Qt Designer generated object setup routine */
|
2014-05-05 19:25:17 -04:00
|
|
|
ui = new Ui::GxsChannelPostItem;
|
|
|
|
ui->setupUi(this);
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
setAttribute(Qt::WA_DeleteOnClose, true);
|
|
|
|
|
|
|
|
mInFill = false;
|
2014-11-19 07:40:42 -05:00
|
|
|
mCloseOnRead = false;
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
/* clear ui */
|
|
|
|
ui->titleLabel->setText(tr("Loading"));
|
|
|
|
ui->subjectLabel->clear();
|
|
|
|
ui->datetimelabel->clear();
|
|
|
|
ui->filelabel->clear();
|
2013-03-11 16:53:15 -04:00
|
|
|
|
|
|
|
/* general ones */
|
2014-11-17 19:49:21 -05:00
|
|
|
connect(ui->expandButton, SIGNAL(clicked()), this, SLOT(toggle()));
|
|
|
|
connect(ui->clearButton, SIGNAL(clicked()), this, SLOT(removeItem()));
|
2013-03-11 16:53:15 -04:00
|
|
|
|
|
|
|
/* specific */
|
2014-05-05 19:25:17 -04:00
|
|
|
connect(ui->readAndClearButton, SIGNAL(clicked()), this, SLOT(readAndClearItem()));
|
2014-11-17 19:49:21 -05:00
|
|
|
connect(ui->unsubscribeButton, SIGNAL(clicked()), this, SLOT(unsubscribeChannel()));
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
connect(ui->downloadButton, SIGNAL(clicked()), this, SLOT(download()));
|
2013-03-11 16:53:15 -04:00
|
|
|
// HACK FOR NOW.
|
2014-11-17 19:49:21 -05:00
|
|
|
connect(ui->commentButton, SIGNAL(clicked()), this, SLOT(loadComments()));
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
connect(ui->playButton, SIGNAL(clicked()), this, SLOT(play(void)));
|
|
|
|
connect(ui->copyLinkButton, SIGNAL(clicked()), this, SLOT(copyMessageLink()));
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
connect(ui->readButton, SIGNAL(toggled(bool)), this, SLOT(readToggled(bool)));
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
//connect(ui-> voteUpButton, SIGNAL(clicked()), this, SLOT(makeUpVote()));
|
|
|
|
//connect(ui->voteDownButton, SIGNAL(clicked()), this, SLOT(makeDownVote()));
|
2014-04-04 09:55:00 -04:00
|
|
|
|
2015-02-16 14:23:31 -05:00
|
|
|
ui->scoreLabel->hide();
|
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->downloadButton->hide();
|
|
|
|
ui->playButton->hide();
|
|
|
|
ui->warn_image_label->hide();
|
|
|
|
ui->warning_label->hide();
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->titleLabel->setMinimumWidth(100);
|
|
|
|
ui->subjectLabel->setMinimumWidth(100);
|
|
|
|
ui->warning_label->setMinimumWidth(100);
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->frame->setProperty("state", "");
|
|
|
|
QPalette palette = ui->frame->palette();
|
|
|
|
palette.setColor(ui->frame->backgroundRole(), COLOR_NORMAL);
|
|
|
|
ui->frame->setPalette(palette);
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->expandFrame->hide();
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
bool GxsChannelPostItem::setGroup(const RsGxsChannelGroup &group, bool doFill)
|
|
|
|
{
|
|
|
|
if (groupId() != group.mMeta.mGroupId) {
|
|
|
|
std::cerr << "GxsChannelPostItem::setGroup() - Wrong id, cannot set post";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mGroup = group;
|
|
|
|
|
|
|
|
if (doFill) {
|
|
|
|
fill();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GxsChannelPostItem::setPost(const RsGxsChannelPost &post, bool doFill)
|
|
|
|
{
|
|
|
|
if (groupId() != post.mMeta.mGroupId || messageId() != post.mMeta.mMsgId) {
|
|
|
|
std::cerr << "GxsChannelPostItem::setPost() - Wrong id, cannot set post";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mPost = post;
|
|
|
|
|
|
|
|
if (doFill) {
|
|
|
|
fill();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateItem();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-11-19 07:40:42 -05:00
|
|
|
QString GxsChannelPostItem::getTitleLabel()
|
|
|
|
{
|
|
|
|
return QString::fromUtf8(mPost.mMeta.mMsgName.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
QString GxsChannelPostItem::getMsgLabel()
|
|
|
|
{
|
|
|
|
return RsHtml().formatText(NULL, QString::fromUtf8(mPost.mMsg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS);
|
|
|
|
}
|
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
QString GxsChannelPostItem::groupName()
|
|
|
|
{
|
|
|
|
return QString::fromUtf8(mGroup.mMeta.mGroupName.c_str());
|
|
|
|
}
|
|
|
|
|
2013-03-15 17:02:43 -04:00
|
|
|
void GxsChannelPostItem::loadComments()
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
2013-03-15 17:02:43 -04:00
|
|
|
QString title = QString::fromUtf8(mPost.mMeta.mMsgName.c_str());
|
|
|
|
comments(title);
|
|
|
|
}
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
void GxsChannelPostItem::loadGroup(const uint32_t &token)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "GxsChannelGroupItem::loadGroup()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
std::vector<RsGxsChannelGroup> groups;
|
|
|
|
if (!rsGxsChannels->getGroupData(token, groups))
|
|
|
|
{
|
|
|
|
std::cerr << "GxsChannelGroupItem::loadGroup() ERROR getting data";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (groups.size() != 1)
|
|
|
|
{
|
|
|
|
std::cerr << "GxsChannelGroupItem::loadGroup() Wrong number of Items";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
setGroup(groups[0]);
|
|
|
|
}
|
|
|
|
|
2013-03-15 17:02:43 -04:00
|
|
|
void GxsChannelPostItem::loadMessage(const uint32_t &token)
|
|
|
|
{
|
2014-11-17 19:49:21 -05:00
|
|
|
#ifdef DEBUG_ITEM
|
2013-03-15 17:02:43 -04:00
|
|
|
std::cerr << "GxsChannelPostItem::loadMessage()";
|
|
|
|
std::cerr << std::endl;
|
2014-11-17 19:49:21 -05:00
|
|
|
#endif
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2013-03-15 17:02:43 -04:00
|
|
|
std::vector<RsGxsChannelPost> posts;
|
|
|
|
if (!rsGxsChannels->getPostData(token, posts))
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
2013-03-15 17:02:43 -04:00
|
|
|
std::cerr << "GxsChannelPostItem::loadMessage() ERROR getting data";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return;
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
2013-03-15 17:02:43 -04:00
|
|
|
|
|
|
|
if (posts.size() != 1)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
2013-03-15 17:02:43 -04:00
|
|
|
std::cerr << "GxsChannelPostItem::loadMessage() Wrong number of Items";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return;
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
setPost(posts[0]);
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
void GxsChannelPostItem::fill()
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
|
|
|
/* fill in */
|
2014-05-06 16:19:04 -04:00
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
if (isLoading()) {
|
|
|
|
/* Wait for all requests */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
#ifdef DEBUG_ITEM
|
2014-11-17 19:49:21 -05:00
|
|
|
std::cerr << "GxsChannelPostItem::fill()";
|
2013-03-11 16:53:15 -04:00
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
mInFill = true;
|
2013-03-15 17:02:43 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
QString title;
|
|
|
|
|
|
|
|
if (!mIsHome)
|
|
|
|
{
|
2014-11-19 07:40:42 -05:00
|
|
|
if (mCloseOnRead && !IS_MSG_NEW(mPost.mMeta.mMsgStatus)) {
|
|
|
|
removeItem();
|
|
|
|
}
|
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
title = tr("Channel Feed") + ": ";
|
|
|
|
RetroShareLink link;
|
2014-11-17 19:49:21 -05:00
|
|
|
link.createGxsGroupLink(RetroShareLink::TYPE_CHANNEL, mPost.mMeta.mGroupId, groupName());
|
2013-03-11 16:53:15 -04:00
|
|
|
title += link.toHtml();
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->titleLabel->setText(title);
|
2014-11-17 19:49:21 -05:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
RetroShareLink msgLink;
|
2014-11-17 19:49:21 -05:00
|
|
|
msgLink.createGxsMessageLink(RetroShareLink::TYPE_CHANNEL, mPost.mMeta.mGroupId, mPost.mMeta.mMsgId, messageName());
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->subjectLabel->setText(msgLink.toHtml());
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
if (IS_GROUP_SUBSCRIBED(mGroup.mMeta.mSubscribeFlags) || IS_GROUP_ADMIN(mGroup.mMeta.mSubscribeFlags))
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->unsubscribeButton->setEnabled(true);
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->unsubscribeButton->setEnabled(false);
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->readButton->hide();
|
2014-05-06 16:55:30 -04:00
|
|
|
ui->newLabel->hide();
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->copyLinkButton->hide();
|
2014-11-19 07:40:42 -05:00
|
|
|
|
|
|
|
if (IS_MSG_NEW(mPost.mMeta.mMsgStatus)) {
|
|
|
|
mCloseOnRead = true;
|
|
|
|
}
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* subject */
|
2014-11-17 19:49:21 -05:00
|
|
|
ui->titleLabel->setText(QString::fromUtf8(mPost.mMeta.mMsgName.c_str()));
|
|
|
|
ui->subjectLabel->setText(RsHtml().formatText(NULL, QString::fromUtf8(mPost.mMsg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
|
2014-04-04 09:55:00 -04:00
|
|
|
|
|
|
|
//QString score = QString::number(post.mTopScore);
|
|
|
|
// scoreLabel->setText(score);
|
2013-03-11 16:53:15 -04:00
|
|
|
|
|
|
|
/* disable buttons: deletion facility not enabled with cache services yet */
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->clearButton->setEnabled(false);
|
|
|
|
ui->unsubscribeButton->setEnabled(false);
|
|
|
|
ui->clearButton->hide();
|
|
|
|
ui->readAndClearButton->hide();
|
|
|
|
ui->unsubscribeButton->hide();
|
|
|
|
ui->copyLinkButton->show();
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
if (IS_GROUP_SUBSCRIBED(mGroup.mMeta.mSubscribeFlags) || IS_GROUP_ADMIN(mGroup.mMeta.mSubscribeFlags))
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->readButton->setVisible(true);
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
setReadStatus(IS_MSG_NEW(mPost.mMeta.mMsgStatus), IS_MSG_UNREAD(mPost.mMeta.mMsgStatus) || IS_MSG_NEW(mPost.mMeta.mMsgStatus));
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->readButton->setVisible(false);
|
2014-05-06 16:55:30 -04:00
|
|
|
ui->newLabel->setVisible(false);
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
2014-11-19 07:40:42 -05:00
|
|
|
|
|
|
|
mCloseOnRead = false;
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
2014-04-04 09:55:00 -04:00
|
|
|
|
|
|
|
// differences between Feed or Top of Comment.
|
2014-08-01 10:49:58 -04:00
|
|
|
if (mFeedHolder)
|
2014-04-04 09:55:00 -04:00
|
|
|
{
|
2014-11-17 19:49:21 -05:00
|
|
|
if (mIsHome) {
|
|
|
|
ui->commentButton->show();
|
|
|
|
} else {
|
|
|
|
ui->commentButton->hide();
|
|
|
|
}
|
2014-04-04 09:55:00 -04:00
|
|
|
|
2014-04-07 09:12:57 -04:00
|
|
|
// THIS CODE IS doesn't compile - disabling until fixed.
|
|
|
|
#if 0
|
2014-04-04 09:55:00 -04:00
|
|
|
if (post.mComments)
|
|
|
|
{
|
|
|
|
QString commentText = QString::number(post.mComments);
|
|
|
|
commentText += " ";
|
|
|
|
commentText += tr("Comments");
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->commentButton->setText(commentText);
|
2014-04-04 09:55:00 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->commentButton->setText(tr("Comment"));
|
2014-04-04 09:55:00 -04:00
|
|
|
}
|
2014-04-07 09:12:57 -04:00
|
|
|
#endif
|
|
|
|
|
2014-04-04 09:55:00 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->commentButton->hide();
|
2014-04-04 09:55:00 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// disable voting buttons - if they have already voted.
|
|
|
|
/*if (post.mMeta.mMsgStatus & GXS_SERV::GXS_MSG_STATUS_VOTE_MASK)
|
|
|
|
{
|
|
|
|
voteUpButton->setEnabled(false);
|
|
|
|
voteDownButton->setEnabled(false);
|
|
|
|
}*/
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
ui->msgLabel->setText(RsHtml().formatText(NULL, QString::fromUtf8(mPost.mMsg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
|
|
|
|
ui->msgFrame->setVisible(!mPost.mMsg.empty());
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
ui->datetimelabel->setText(DateTime::formatLongDateTime(mPost.mMeta.mPublishTs));
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
ui->filelabel->setText(QString("(%1 %2) %3").arg(mPost.mCount).arg(tr("Files")).arg(misc::friendlyUnit(mPost.mSize)));
|
2013-03-11 16:53:15 -04:00
|
|
|
|
|
|
|
if (mFileItems.empty() == false) {
|
|
|
|
std::list<SubFileItem *>::iterator it;
|
2014-10-21 18:33:02 -04:00
|
|
|
for(it = mFileItems.begin(); it != mFileItems.end(); ++it)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
|
|
|
delete(*it);
|
|
|
|
}
|
|
|
|
mFileItems.clear();
|
|
|
|
}
|
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
std::list<RsGxsFile>::const_iterator it;
|
2014-11-17 19:49:21 -05:00
|
|
|
for(it = mPost.mFiles.begin(); it != mPost.mFiles.end(); ++it)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
|
|
|
/* add file */
|
2013-03-12 20:33:14 -04:00
|
|
|
std::string path;
|
2014-03-17 16:56:06 -04:00
|
|
|
SubFileItem *fi = new SubFileItem(it->mHash, it->mName, path, it->mSize, SFI_STATE_REMOTE | SFI_TYPE_CHANNEL, RsPeerId());
|
2013-03-11 16:53:15 -04:00
|
|
|
mFileItems.push_back(fi);
|
|
|
|
|
|
|
|
/* check if the file is a media file */
|
2014-12-23 11:02:00 -05:00
|
|
|
if (!misc::isPreviewable(QFileInfo(QString::fromUtf8(it->mName.c_str())).suffix()))
|
|
|
|
{
|
|
|
|
fi->mediatype();
|
|
|
|
/* check if the file is not a media file and change text */
|
|
|
|
ui->playButton->setText(tr("Open"));
|
|
|
|
ui->playButton->setToolTip(tr("Open File"));
|
|
|
|
} else {
|
|
|
|
ui->playButton->setText(tr("Play"));
|
|
|
|
ui->playButton->setToolTip(tr("Play Media"));
|
|
|
|
}
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
QLayout *layout = ui->expandFrame->layout();
|
2013-03-11 16:53:15 -04:00
|
|
|
layout->addWidget(fi);
|
|
|
|
}
|
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
if(mPost.mThumbnail.mData != NULL)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
|
|
|
QPixmap thumbnail;
|
2014-11-17 19:49:21 -05:00
|
|
|
thumbnail.loadFromData(mPost.mThumbnail.mData, mPost.mThumbnail.mSize, "PNG");
|
2013-03-15 17:02:43 -04:00
|
|
|
// Wiping data - as its been passed to thumbnail.
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->logoLabel->setPixmap(thumbnail);
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
2013-03-15 17:02:43 -04:00
|
|
|
|
2014-11-17 19:49:21 -05:00
|
|
|
mInFill = false;
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
|
2014-07-26 19:52:45 -04:00
|
|
|
QString GxsChannelPostItem::messageName()
|
|
|
|
{
|
|
|
|
return QString::fromUtf8(mPost.mMeta.mMsgName.c_str());
|
|
|
|
}
|
|
|
|
|
2014-05-06 16:55:30 -04:00
|
|
|
void GxsChannelPostItem::setReadStatus(bool isNew, bool isUnread)
|
|
|
|
{
|
|
|
|
if (isUnread)
|
|
|
|
{
|
|
|
|
ui->readButton->setChecked(true);
|
|
|
|
ui->readButton->setIcon(QIcon(":/images/message-state-unread.png"));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ui->readButton->setChecked(false);
|
|
|
|
ui->readButton->setIcon(QIcon(":/images/message-state-read.png"));
|
|
|
|
}
|
|
|
|
|
|
|
|
ui->newLabel->setVisible(isNew);
|
|
|
|
|
|
|
|
/* unpolish widget to clear the stylesheet's palette cache */
|
|
|
|
ui->frame->style()->unpolish(ui->frame);
|
|
|
|
|
|
|
|
QPalette palette = ui->frame->palette();
|
2014-08-01 10:49:58 -04:00
|
|
|
palette.setColor(ui->frame->backgroundRole(), isNew ? COLOR_NEW : COLOR_NORMAL); // QScrollArea
|
|
|
|
palette.setColor(QPalette::Base, isNew ? COLOR_NEW : COLOR_NORMAL); // QTreeWidget
|
2014-05-06 16:55:30 -04:00
|
|
|
ui->frame->setPalette(palette);
|
|
|
|
|
|
|
|
ui->frame->setProperty("new", isNew);
|
|
|
|
Rshare::refreshStyleSheet(ui->frame, false);
|
|
|
|
}
|
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
void GxsChannelPostItem::setFileCleanUpWarning(uint32_t time_left)
|
|
|
|
{
|
|
|
|
int hours = (int)time_left/3600;
|
|
|
|
int minutes = (time_left - hours*3600)%60;
|
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->warning_label->setText(tr("Warning! You have less than %1 hours and %2 minute before this file is deleted Consider saving it.").arg(
|
2013-03-11 16:53:15 -04:00
|
|
|
QString::number(hours)).arg(QString::number(minutes)));
|
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
QFont warnFont = ui->warning_label->font();
|
2013-03-11 16:53:15 -04:00
|
|
|
warnFont.setBold(true);
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->warning_label->setFont(warnFont);
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->warn_image_label->setVisible(true);
|
|
|
|
ui->warning_label->setVisible(true);
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GxsChannelPostItem::updateItem()
|
|
|
|
{
|
|
|
|
/* fill in */
|
2014-05-05 19:25:17 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "GxsChannelPostItem::updateItem()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
2014-11-17 19:49:21 -05:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
int msec_rate = 10000;
|
|
|
|
|
|
|
|
int downloadCount = 0;
|
|
|
|
int downloadStartable = 0;
|
|
|
|
int playCount = 0;
|
|
|
|
int playStartable = 0;
|
|
|
|
bool startable;
|
|
|
|
bool loopAgain = false;
|
|
|
|
|
|
|
|
/* Very slow Tick to check when all files are downloaded */
|
|
|
|
std::list<SubFileItem *>::iterator it;
|
2014-10-21 18:33:02 -04:00
|
|
|
for(it = mFileItems.begin(); it != mFileItems.end(); ++it)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
|
|
|
SubFileItem *item = *it;
|
|
|
|
|
|
|
|
if (item->isDownloadable(startable)) {
|
2014-10-21 18:33:02 -04:00
|
|
|
++downloadCount;
|
2013-03-11 16:53:15 -04:00
|
|
|
if (startable) {
|
2014-10-21 18:33:02 -04:00
|
|
|
++downloadStartable;
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (item->isPlayable(startable)) {
|
2014-10-21 18:33:02 -04:00
|
|
|
++playCount;
|
2013-03-11 16:53:15 -04:00
|
|
|
if (startable) {
|
2014-10-21 18:33:02 -04:00
|
|
|
++playStartable;
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!item->done())
|
|
|
|
{
|
|
|
|
/* loop again */
|
|
|
|
loopAgain = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (downloadCount) {
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->downloadButton->show();
|
2013-03-11 16:53:15 -04:00
|
|
|
|
|
|
|
if (downloadStartable) {
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->downloadButton->setEnabled(true);
|
2013-03-11 16:53:15 -04:00
|
|
|
} else {
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->downloadButton->setEnabled(false);
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
} else {
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->downloadButton->hide();
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
if (playCount) {
|
|
|
|
/* one file is playable */
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->playButton->show();
|
2013-03-11 16:53:15 -04:00
|
|
|
|
|
|
|
if (playStartable == 1) {
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->playButton->setEnabled(true);
|
2013-03-11 16:53:15 -04:00
|
|
|
} else {
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->playButton->setEnabled(false);
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
} else {
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->playButton->hide();
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (loopAgain) {
|
2014-05-05 19:25:17 -04:00
|
|
|
QTimer::singleShot( msec_rate, this, SLOT(updateItem(void)));
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// HACK TO DISPLAY COMMENT BUTTON FOR NOW.
|
2013-03-15 17:02:43 -04:00
|
|
|
//downloadButton->show();
|
|
|
|
//downloadButton->setEnabled(true);
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
|
2014-08-01 10:49:58 -04:00
|
|
|
void GxsChannelPostItem::expand(bool open)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
2014-08-01 10:49:58 -04:00
|
|
|
if (mFeedHolder)
|
2013-03-15 17:02:43 -04:00
|
|
|
{
|
2014-08-01 10:49:58 -04:00
|
|
|
mFeedHolder->lockLayout(this, true);
|
2013-03-15 17:02:43 -04:00
|
|
|
}
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-08-01 10:49:58 -04:00
|
|
|
if (open)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->expandFrame->show();
|
|
|
|
ui->expandButton->setIcon(QIcon(QString(":/images/edit_remove24.png")));
|
|
|
|
ui->expandButton->setToolTip(tr("Hide"));
|
2013-03-11 16:53:15 -04:00
|
|
|
|
|
|
|
readToggled(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->expandFrame->hide();
|
|
|
|
ui->expandButton->setIcon(QIcon(QString(":/images/edit_add24.png")));
|
|
|
|
ui->expandButton->setToolTip(tr("Expand"));
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
|
2014-08-01 10:49:58 -04:00
|
|
|
emit sizeChanged(this);
|
|
|
|
|
|
|
|
if (mFeedHolder)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
2014-08-01 10:49:58 -04:00
|
|
|
mFeedHolder->lockLayout(this, false);
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-01 10:49:58 -04:00
|
|
|
void GxsChannelPostItem::toggle()
|
|
|
|
{
|
|
|
|
expand(ui->expandFrame->isHidden());
|
|
|
|
}
|
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
/*********** SPECIFIC FUNCTIONS ***********************/
|
|
|
|
|
|
|
|
void GxsChannelPostItem::readAndClearItem()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "GxsChannelPostItem::readAndClearItem()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
readToggled(false);
|
|
|
|
removeItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GxsChannelPostItem::unsubscribeChannel()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "GxsChannelPostItem::unsubscribeChannel()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2013-03-15 17:02:43 -04:00
|
|
|
unsubscribe();
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GxsChannelPostItem::download()
|
|
|
|
{
|
|
|
|
std::list<SubFileItem *>::iterator it;
|
2014-10-21 18:33:02 -04:00
|
|
|
for(it = mFileItems.begin(); it != mFileItems.end(); ++it)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
|
|
|
(*it)->download();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GxsChannelPostItem::play()
|
|
|
|
{
|
|
|
|
std::list<SubFileItem *>::iterator it;
|
2014-10-21 18:33:02 -04:00
|
|
|
for(it = mFileItems.begin(); it != mFileItems.end(); ++it)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
|
|
|
bool startable;
|
|
|
|
if ((*it)->isPlayable(startable) && startable) {
|
|
|
|
(*it)->play();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GxsChannelPostItem::readToggled(bool checked)
|
|
|
|
{
|
2014-11-17 19:49:21 -05:00
|
|
|
if (mInFill) {
|
2013-03-11 16:53:15 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-11-19 07:40:42 -05:00
|
|
|
mCloseOnRead = false;
|
|
|
|
|
2014-05-06 16:55:30 -04:00
|
|
|
RsGxsGrpMsgIdPair msgPair = std::make_pair(groupId(), messageId());
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-05-06 16:55:30 -04:00
|
|
|
uint32_t token;
|
|
|
|
rsGxsChannels->setMessageReadStatus(token, msgPair, !checked);
|
|
|
|
|
|
|
|
setReadStatus(false, checked);
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
|
2014-04-04 09:55:00 -04:00
|
|
|
void GxsChannelPostItem::makeDownVote()
|
|
|
|
{
|
|
|
|
RsGxsGrpMsgIdPair msgId;
|
|
|
|
msgId.first = mPost.mMeta.mGroupId;
|
|
|
|
msgId.second = mPost.mMeta.mMsgId;
|
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->voteUpButton->setEnabled(false);
|
|
|
|
ui->voteDownButton->setEnabled(false);
|
2014-04-04 09:55:00 -04:00
|
|
|
|
|
|
|
emit vote(msgId, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GxsChannelPostItem::makeUpVote()
|
|
|
|
{
|
|
|
|
RsGxsGrpMsgIdPair msgId;
|
|
|
|
msgId.first = mPost.mMeta.mGroupId;
|
|
|
|
msgId.second = mPost.mMeta.mMsgId;
|
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->voteUpButton->setEnabled(false);
|
|
|
|
ui->voteDownButton->setEnabled(false);
|
2014-04-04 09:55:00 -04:00
|
|
|
|
|
|
|
emit vote(msgId, true);
|
|
|
|
}
|