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"
|
2014-05-05 19:34:28 -04:00
|
|
|
//#include "gui/notifyqt.h"
|
2013-03-11 16:53:15 -04:00
|
|
|
#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-05-05 19:25:17 -04:00
|
|
|
#define SELF_LOAD 1
|
|
|
|
#define DATA_PROVIDED 2
|
2013-03-11 16:53:15 -04:00
|
|
|
|
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) :
|
|
|
|
GxsFeedItem(feedHolder, feedId, groupId, messageId, isHome, rsGxsChannels, true, autoUpdate)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
|
|
|
mMode = SELF_LOAD;
|
|
|
|
|
|
|
|
setup();
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Constructor */
|
2014-08-01 10:49:58 -04:00
|
|
|
GxsChannelPostItem::GxsChannelPostItem(FeedHolder *feedHolder, uint32_t feedId, const RsGxsChannelPost &post, uint32_t subFlags, bool isHome, bool autoUpdate) :
|
|
|
|
GxsFeedItem(feedHolder, feedId, post.mMeta.mGroupId, post.mMeta.mMsgId, isHome, rsGxsChannels, false, autoUpdate)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
2013-03-15 17:02:43 -04:00
|
|
|
std::cerr << "GxsChannelPostItem::GxsChannelPostItem() Direct Load";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
mMode = DATA_PROVIDED;
|
2014-05-05 19:25:17 -04:00
|
|
|
mGroupMeta.mSubscribeFlags = subFlags;
|
2013-03-11 16:53:15 -04:00
|
|
|
|
|
|
|
setup();
|
|
|
|
|
2013-03-15 17:02:43 -04:00
|
|
|
// is it because we are in the constructor?
|
2013-03-11 16:53:15 -04:00
|
|
|
loadPost(post);
|
|
|
|
}
|
|
|
|
|
2014-07-27 14:29:35 -04:00
|
|
|
void GxsChannelPostItem::setContent(const QVariant &content)
|
|
|
|
{
|
|
|
|
if (!content.canConvert<RsGxsChannelPost>()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
RsGxsChannelPost post = content.value<RsGxsChannelPost>();
|
|
|
|
setContent(post);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GxsChannelPostItem::setContent(const RsGxsChannelPost &post)
|
2014-05-06 16:19:04 -04:00
|
|
|
{
|
|
|
|
if (groupId() != post.mMeta.mGroupId || messageId() != post.mMeta.mMsgId) {
|
|
|
|
std::cerr << "GxsChannelPostItem::setPost() - Wrong id, cannot set post";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
loadPost(post);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
setAttribute ( Qt::WA_DeleteOnClose, true );
|
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
mInUpdateItemStatic = false;
|
2013-03-11 16:53:15 -04:00
|
|
|
|
|
|
|
/* general ones */
|
2014-05-05 19:25:17 -04:00
|
|
|
connect(ui->expandButton, SIGNAL(clicked(void)), this, SLOT(toggle(void)));
|
|
|
|
connect(ui->clearButton, SIGNAL(clicked(void)), this, SLOT(removeItem(void)));
|
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()));
|
|
|
|
connect(ui->unsubscribeButton, SIGNAL(clicked(void)), this, SLOT(unsubscribeChannel(void)));
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
connect(ui->downloadButton, SIGNAL(clicked(void)), this, SLOT(download(void)));
|
2013-03-11 16:53:15 -04:00
|
|
|
// HACK FOR NOW.
|
2014-05-05 19:25:17 -04:00
|
|
|
connect(ui->commentButton, SIGNAL(clicked(void)), this, SLOT(loadComments(void)));
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
connect(ui->playButton, SIGNAL(clicked(void)), this, SLOT( play(void)));
|
|
|
|
connect(ui->copyLinkButton, SIGNAL(clicked(void)), this, SLOT(copyLink(void)));
|
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)));
|
|
|
|
//connect(NotifyQt::getInstance(), SIGNAL(channelMsgReadSatusChanged(QString,QString,int)), this, SLOT(channelMsgReadSatusChanged(QString,QString,int)), Qt::QueuedConnection);
|
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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2013-03-15 17:02:43 -04:00
|
|
|
void GxsChannelPostItem::loadMessage(const uint32_t &token)
|
|
|
|
{
|
|
|
|
std::cerr << "GxsChannelPostItem::loadMessage()";
|
|
|
|
std::cerr << std::endl;
|
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
|
|
|
}
|
|
|
|
|
2013-03-15 17:02:43 -04:00
|
|
|
loadPost(posts[0]);
|
2013-03-12 20:33:14 -04:00
|
|
|
|
2013-03-15 17:02:43 -04:00
|
|
|
updateItem();
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void GxsChannelPostItem::loadPost(const RsGxsChannelPost &post)
|
|
|
|
{
|
|
|
|
/* fill in */
|
2014-05-06 16:19:04 -04:00
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
#ifdef DEBUG_ITEM
|
|
|
|
std::cerr << "GxsChannelPostItem::loadPost()";
|
|
|
|
std::cerr << std::endl;
|
|
|
|
#endif
|
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
mInUpdateItemStatic = true;
|
2013-03-15 17:02:43 -04:00
|
|
|
|
|
|
|
mPost = post;
|
|
|
|
|
2013-03-11 16:53:15 -04:00
|
|
|
QString title;
|
|
|
|
|
|
|
|
if (!mIsHome)
|
|
|
|
{
|
|
|
|
title = tr("Channel Feed") + ": ";
|
|
|
|
RetroShareLink link;
|
2014-07-26 19:52:45 -04:00
|
|
|
link.createGxsGroupLink(RetroShareLink::TYPE_CHANNEL, post.mMeta.mGroupId, "");
|
2013-03-11 16:53:15 -04:00
|
|
|
title += link.toHtml();
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->titleLabel->setText(title);
|
2013-03-11 16:53:15 -04:00
|
|
|
RetroShareLink msgLink;
|
2014-07-26 19:52:45 -04:00
|
|
|
msgLink.createGxsMessageLink(RetroShareLink::TYPE_CHANNEL, post.mMeta.mGroupId, post.mMeta.mMsgId, QString::fromUtf8(post.mMeta.mMsgName.c_str()));
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->subjectLabel->setText(msgLink.toHtml());
|
2013-03-11 16:53:15 -04:00
|
|
|
|
|
|
|
if (IS_GROUP_SUBSCRIBED(mSubscribeFlags) || IS_GROUP_ADMIN(mSubscribeFlags))
|
|
|
|
{
|
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();
|
2013-03-11 16:53:15 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* subject */
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->titleLabel->setText(QString::fromUtf8(post.mMeta.mMsgName.c_str()));
|
|
|
|
ui->subjectLabel->setText(RsHtml().formatText(NULL, QString::fromUtf8(post.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
|
|
|
|
2013-03-15 17:02:43 -04:00
|
|
|
if (IS_GROUP_SUBSCRIBED(mGroupMeta.mSubscribeFlags) || IS_GROUP_ADMIN(mGroupMeta.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-05-06 16:55:30 -04:00
|
|
|
setReadStatus(IS_MSG_NEW(post.mMeta.mMsgStatus), IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.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-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-05-05 19:25:17 -04:00
|
|
|
ui->commentButton->show();
|
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-05-05 19:25:17 -04:00
|
|
|
ui->msgLabel->setText(RsHtml().formatText(NULL, QString::fromUtf8(post.mMsg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
|
|
|
|
ui->msgFrame->setVisible(!post.mMsg.empty());
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->datetimelabel->setText(DateTime::formatLongDateTime(post.mMeta.mPublishTs));
|
2013-03-11 16:53:15 -04:00
|
|
|
|
2014-05-05 19:25:17 -04:00
|
|
|
ui->filelabel->setText(QString("(%1 %2) %3").arg(post.mCount).arg(tr("Files")).arg(misc::friendlyUnit(post.mSize)));
|
2013-03-11 16:53:15 -04:00
|
|
|
|
|
|
|
if (mFileItems.empty() == false) {
|
|
|
|
std::list<SubFileItem *>::iterator it;
|
|
|
|
for(it = mFileItems.begin(); it != mFileItems.end(); it++)
|
|
|
|
{
|
|
|
|
delete(*it);
|
|
|
|
}
|
|
|
|
mFileItems.clear();
|
|
|
|
}
|
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
std::list<RsGxsFile>::const_iterator it;
|
|
|
|
for(it = post.mFiles.begin(); it != post.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 */
|
2013-03-12 20:33:14 -04:00
|
|
|
if (!misc::isPreviewable(QFileInfo(QString::fromUtf8(it->mName.c_str())).suffix()))
|
2014-05-05 19:34:28 -04:00
|
|
|
fi->mediatype();
|
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);
|
|
|
|
}
|
|
|
|
|
2013-03-12 20:33:14 -04:00
|
|
|
if(post.mThumbnail.mData != NULL)
|
2013-03-11 16:53:15 -04:00
|
|
|
{
|
|
|
|
QPixmap thumbnail;
|
2013-03-12 20:33:14 -04:00
|
|
|
thumbnail.loadFromData(post.mThumbnail.mData, post.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-05-05 19:25:17 -04:00
|
|
|
mInUpdateItemStatic = 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
|
|
|
|
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;
|
|
|
|
for(it = mFileItems.begin(); it != mFileItems.end(); it++)
|
|
|
|
{
|
|
|
|
SubFileItem *item = *it;
|
|
|
|
|
|
|
|
if (item->isDownloadable(startable)) {
|
|
|
|
downloadCount++;
|
|
|
|
if (startable) {
|
|
|
|
downloadStartable++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (item->isPlayable(startable)) {
|
|
|
|
playCount++;
|
|
|
|
if (startable) {
|
|
|
|
playStartable++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
updateItemStatic();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GxsChannelPostItem::download()
|
|
|
|
{
|
|
|
|
std::list<SubFileItem *>::iterator it;
|
|
|
|
for(it = mFileItems.begin(); it != mFileItems.end(); it++)
|
|
|
|
{
|
|
|
|
(*it)->download();
|
|
|
|
}
|
|
|
|
|
|
|
|
updateItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GxsChannelPostItem::play()
|
|
|
|
{
|
|
|
|
std::list<SubFileItem *>::iterator it;
|
|
|
|
for(it = mFileItems.begin(); it != mFileItems.end(); it++)
|
|
|
|
{
|
|
|
|
bool startable;
|
|
|
|
if ((*it)->isPlayable(startable) && startable) {
|
|
|
|
(*it)->play();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GxsChannelPostItem::readToggled(bool checked)
|
|
|
|
{
|
2014-05-05 19:25:17 -04:00
|
|
|
if (mInUpdateItemStatic) {
|
2013-03-11 16:53:15 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void GxsChannelPostItem::channelMsgReadSatusChanged(const QString& channelId, const QString& msgId, int status)
|
|
|
|
{
|
2013-03-15 17:02:43 -04:00
|
|
|
#if 0
|
2013-03-11 16:53:15 -04:00
|
|
|
if (channelId.toStdString() == mChanId && msgId.toStdString() == mMsgId) {
|
|
|
|
if (!mIsHome) {
|
|
|
|
if (status & CHANNEL_MSG_STATUS_READ) {
|
|
|
|
close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
updateItemStatic();
|
|
|
|
}
|
2013-03-15 17:02:43 -04:00
|
|
|
#endif
|
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);
|
|
|
|
}
|