Beispiel #1
0
void MsgItem::updateItemStatic()
{
    /* fill in */
#ifdef DEBUG_ITEM
    std::cerr << "MsgItem::updateItemStatic()";
    std::cerr << std::endl;
#endif

    MessageInfo mi;

    if (!rsMail)
        return;

    if (!rsMail->getMessage(mMsgId, mi))
        return;

    /* get peer Id */

    if(mi.msgflags & RS_MSG_SIGNED)
        avatar->setGxsId(mi.rsgxsid_srcId);
    else
        avatar->setId(ChatId(mi.rspeerid_srcId));

    QString title;
    QString srcName;

    if ((mi.msgflags & RS_MSG_SYSTEM) && mi.rspeerid_srcId == rsPeers->getOwnId())
        srcName = "RetroShare";
    else
    {
        if(mi.msgflags & RS_MSG_SIGNED)
        {
            RsIdentityDetails details ;
            rsIdentity->getIdDetails(mi.rsgxsid_srcId, details) ;

            srcName = QString::fromUtf8(details.mNickname.c_str());
        }
        else
            srcName = QString::fromUtf8(rsPeers->getPeerName(mi.rspeerid_srcId).c_str());
    }

    timestampLabel->setText(DateTime::formatLongDateTime(mi.ts));

    if (!mIsHome)
    {
        title = tr("Message From") + ": ";
    }
    else
    {
        /* subject */
        uint32_t box = mi.msgflags & RS_MSG_BOXMASK;
        switch(box)
        {
        case RS_MSG_SENTBOX:
            title = tr("Sent Msg") + ": ";
            replyButton->setEnabled(false);
            break;
        case RS_MSG_DRAFTBOX:
            title = tr("Draft Msg") + ": ";
            replyButton->setEnabled(false);
            break;
        case RS_MSG_OUTBOX:
            title = tr("Pending Msg") + ": ";
            //deleteButton->setEnabled(false);
            replyButton->setEnabled(false);
            break;
        default:
        case RS_MSG_INBOX:
            title = "";
            break;
        }
    }
    title += srcName;

    titleLabel->setText(title);
    subjectLabel->setText(QString::fromUtf8(mi.title.c_str()));
    mMsg = QString::fromUtf8(mi.msg.c_str());

    if (wasExpanded() || expandFrame->isVisible()) {
        fillExpandFrame();
    }

    std::list<FileInfo>::iterator it;
    for(it = mi.files.begin(); it != mi.files.end(); ++it)
    {
        /* add file */
        SubFileItem *fi = new SubFileItem(it->hash, it->fname, it->path, it->size, SFI_STATE_REMOTE, mi.rspeerid_srcId);
        mFileItems.push_back(fi);

        QLayout *layout = expandFrame->layout();
        layout->addWidget(fi);
    }

    playButton->setEnabled(false);

    if (mIsHome)
    {
        /* disable buttons */
        clearButton->setEnabled(false);
        //gotoButton->setEnabled(false);

        /* hide buttons */
        clearButton->hide();
    }
}
void GxsChannelPostItem::fill()
{
	/* fill in */

	if (isLoading()) {
		/* Wait for all requests */
		return;
	}

#ifdef DEBUG_ITEM
	std::cerr << "GxsChannelPostItem::fill()";
	std::cerr << std::endl;
#endif

	mInFill = true;

	QString title;

	if (!mIsHome)
	{
		if (mCloseOnRead && !IS_MSG_NEW(mPost.mMeta.mMsgStatus)) {
			removeItem();
		}

		title = tr("Channel Feed") + ": ";
		RetroShareLink link;
		link.createGxsGroupLink(RetroShareLink::TYPE_CHANNEL, mPost.mMeta.mGroupId, groupName());
		title += link.toHtml();
		ui->titleLabel->setText(title);

		RetroShareLink msgLink;
		msgLink.createGxsMessageLink(RetroShareLink::TYPE_CHANNEL, mPost.mMeta.mGroupId, mPost.mMeta.mMsgId, messageName());
		ui->subjectLabel->setText(msgLink.toHtml());

		if (IS_GROUP_SUBSCRIBED(mGroup.mMeta.mSubscribeFlags) || IS_GROUP_ADMIN(mGroup.mMeta.mSubscribeFlags))
		{
			ui->unsubscribeButton->setEnabled(true);
		}
		else 
		{
			ui->unsubscribeButton->setEnabled(false);
		}
		ui->readButton->hide();
		ui->newLabel->hide();
		ui->copyLinkButton->hide();

		if (IS_MSG_NEW(mPost.mMeta.mMsgStatus)) {
			mCloseOnRead = true;
		}
	}
	else
	{
		/* subject */
		ui->titleLabel->setText(QString::fromUtf8(mPost.mMeta.mMsgName.c_str()));

		// fill first 4 lines of message
		ui->subjectLabel->setText(RsHtml().formatText(NULL, RsStringUtil::CopyLines(QString::fromUtf8(mPost.mMsg.c_str()), 4), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS));
		
		//QString score = QString::number(post.mTopScore);
		// scoreLabel->setText(score); 

		/* disable buttons: deletion facility not enabled with cache services yet */
		ui->clearButton->setEnabled(false);
		ui->unsubscribeButton->setEnabled(false);
		ui->clearButton->hide();
		ui->readAndClearButton->hide();
		ui->unsubscribeButton->hide();
		ui->copyLinkButton->show();

		if (IS_GROUP_SUBSCRIBED(mGroup.mMeta.mSubscribeFlags) || IS_GROUP_ADMIN(mGroup.mMeta.mSubscribeFlags))
		{
			ui->readButton->setVisible(true);

			setReadStatus(IS_MSG_NEW(mPost.mMeta.mMsgStatus), IS_MSG_UNREAD(mPost.mMeta.mMsgStatus) || IS_MSG_NEW(mPost.mMeta.mMsgStatus));
		} 
		else 
		{
			ui->readButton->setVisible(false);
			ui->newLabel->setVisible(false);
		}

		mCloseOnRead = false;
	}
	
	// differences between Feed or Top of Comment.
	if (mFeedHolder)
	{
		if (mIsHome) {
			ui->commentButton->show();
		} else if (ui->commentButton->icon().isNull()){
			//Icon is seted if a comment received.
			ui->commentButton->hide();
		}

// THIS CODE IS doesn't compile - disabling until fixed.
#if 0
		if (post.mComments)
		{
			QString commentText = QString::number(post.mComments);
			commentText += " ";
			commentText += tr("Comments");
			ui->commentButton->setText(commentText);
		}
		else
		{
			ui->commentButton->setText(tr("Comment"));
		}
#endif

	}
	else
	{
		ui->commentButton->hide();
	}
	
	// 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);
	}*/

	ui->msgFrame->setVisible(!mPost.mMsg.empty());
	if (wasExpanded() || ui->expandFrame->isVisible()) {
		fillExpandFrame();
	}

	ui->datetimelabel->setText(DateTime::formatLongDateTime(mPost.mMeta.mPublishTs));

	ui->filelabel->setText(QString("(%1 %2) %3").arg(mPost.mCount).arg(tr("Files")).arg(misc::friendlyUnit(mPost.mSize)));

	if (mFileItems.empty() == false) {
		std::list<SubFileItem *>::iterator it;
		for(it = mFileItems.begin(); it != mFileItems.end(); ++it)
		{
			delete(*it);
		}
		mFileItems.clear();
	}

	std::list<RsGxsFile>::const_iterator it;
	for(it = mPost.mFiles.begin(); it != mPost.mFiles.end(); ++it)
	{
		/* add file */
		std::string path;
		SubFileItem *fi = new SubFileItem(it->mHash, it->mName, path, it->mSize, SFI_STATE_REMOTE | SFI_TYPE_CHANNEL, RsPeerId());
		mFileItems.push_back(fi);
		
		/* check if the file is a media file */
		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"));
    }

		QLayout *layout = ui->expandFrame->layout();
		layout->addWidget(fi);
	}

	if(mPost.mThumbnail.mData != NULL)
	{
		QPixmap thumbnail;
		thumbnail.loadFromData(mPost.mThumbnail.mData, mPost.mThumbnail.mSize, "PNG");
		// Wiping data - as its been passed to thumbnail.
		ui->logoLabel->setPixmap(thumbnail);
	}

	mInFill = false;
}