ChatLobbyToaster::ChatLobbyToaster(const std::string &peerId, const QString &name, const QString &message) : QWidget(NULL) { /* Invoke the Qt Designer generated object setup routine */ ui.setupUi(this); this->peerId = peerId; connect(ui.toasterButton, SIGNAL(clicked()), SLOT(chatButtonSlot())); connect(ui.closeButton, SIGNAL(clicked()), SLOT(hide())); /* set informations */ ui.textLabel->setText(RsHtml().formatText(NULL, message, RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_CLEANSTYLE)); ui.avatarWidget->setFrameType(AvatarWidget::NORMAL_FRAME); ui.avatarWidget->setDefaultAvatar(":images/chat_64.png"); QString lobbyName = RsHtml::plainText(name); std::list<ChatLobbyInfo> linfos; rsMsgs->getChatLobbyList(linfos); ChatLobbyId lobbyId; if (rsMsgs->isLobbyId(peerId, lobbyId)) { for (std::list<ChatLobbyInfo>::const_iterator it(linfos.begin()); it != linfos.end(); ++it) { if ((*it).lobby_id == lobbyId) { lobbyName += "@" + RsHtml::plainText(it->lobby_name); break; } } } ui.toasterLabel->setText(lobbyName); }
void FriendsDialog::addChatMsg(bool incoming, bool history, const QString &name, const QDateTime &sendTime, const QDateTime &recvTime, const QString &message) { unsigned int formatTextFlag = RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_OPTIMIZE; // embed smileys ? if (Settings->valueFromGroup("Chat", "Emoteicons_GroupChat", true).toBool()) { formatTextFlag |= RSHTML_FORMATTEXT_EMBED_SMILEYS; } // Always fix colors formatTextFlag |= RSHTML_FORMATTEXT_FIX_COLORS; qreal desiredContrast = Settings->valueFromGroup("Chat", "MinimumContrast", 4.5).toDouble(); QColor backgroundColor = ui.groupChatTab->palette().base().color(); // Remove font name, size, bold, italics? if (!Settings->valueFromGroup("Chat", "EnableCustomFonts", true).toBool()) { formatTextFlag |= RSHTML_FORMATTEXT_REMOVE_FONT_FAMILY; } if (!Settings->valueFromGroup("Chat", "EnableCustomFontSize", true).toBool()) { formatTextFlag |= RSHTML_FORMATTEXT_REMOVE_FONT_SIZE; } if (!Settings->valueFromGroup("Chat", "EnableBold", true).toBool()) { formatTextFlag |= RSHTML_FORMATTEXT_REMOVE_FONT_WEIGHT; } if (!Settings->valueFromGroup("Chat", "EnableItalics", true).toBool()) { formatTextFlag |= RSHTML_FORMATTEXT_REMOVE_FONT_STYLE; } ChatStyle::enumFormatMessage type; if (incoming) { if (history) { type = ChatStyle::FORMATMSG_HINCOMING; } else { type = ChatStyle::FORMATMSG_INCOMING; } } else { if (history) { type = ChatStyle::FORMATMSG_HOUTGOING; } else { type = ChatStyle::FORMATMSG_OUTGOING; } } QString formattedMessage = RsHtml().formatText(ui.msgText->document(), message, formatTextFlag, backgroundColor, desiredContrast); QString formatMsg = style.formatMessage(type, name, incoming ? recvTime : sendTime, formattedMessage); ui.msgText->append(formatMsg); }
void ChatWidget::updatePeersCustomStateString(const QString& peer_id, const QString& status_string) { std::string stdPeerId = peer_id.toStdString(); QString status_text; if (stdPeerId == peerId) { // the peers status string has changed if (status_string.isEmpty()) { ui->statusMessageLabel->hide(); } else { ui->statusMessageLabel->show(); status_text = RsHtml().formatText(NULL, status_string, RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS); ui->statusMessageLabel->setText(status_text); } } }
GroupChatToaster::GroupChatToaster(const RsPeerId &peerId, const QString &message) : QWidget(NULL) { /* Invoke the Qt Designer generated object setup routine */ ui.setupUi(this); this->peerId = peerId; connect(ui.toasterButton, SIGNAL(clicked()), SLOT(chatButtonSlot())); connect(ui.closeButton, SIGNAL(clicked()), SLOT(hide())); /* set informations */ ui.textLabel->setText(RsHtml().formatText(NULL, message, RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_CLEANSTYLE)); ui.toasterLabel->setText(QString::fromUtf8(rsPeers->getPeerName(peerId).c_str())); ui.avatarWidget->setFrameType(AvatarWidget::STATUS_FRAME); ui.avatarWidget->setDefaultAvatar(":/images/user/personal64.png"); ui.avatarWidget->setId(ChatId(peerId)); }
void ChatMsgItem::insertChat(const std::string &message) { #ifdef DEBUG_ITEM std::cerr << "ChatMsgItem::insertChat(): " << msg << std::endl; #endif timestampLabel->setText(DateTime::formatLongDateTime(QDateTime::currentDateTime())); QString formatMsg = QString::fromUtf8(message.c_str()); unsigned int formatFlag = RSHTML_FORMATTEXT_EMBED_LINKS; // embed smileys ? if (Settings->valueFromGroup(QString("Chat"), QString::fromUtf8("Emoteicons_GroupChat"), true).toBool()) { formatFlag |= RSHTML_FORMATTEXT_EMBED_SMILEYS; } formatMsg = RsHtml().formatText(NULL, formatMsg, formatFlag); chatTextlabel->setText(formatMsg); }
ChatLobbyToaster::ChatLobbyToaster(const ChatLobbyId &lobby_id, const QString &name, const QString &message): QWidget(NULL), mLobbyId(lobby_id) { /* Invoke the Qt Designer generated object setup routine */ ui.setupUi(this); connect(ui.toasterButton, SIGNAL(clicked()), SLOT(chatButtonSlot())); connect(ui.closeButton, SIGNAL(clicked()), SLOT(hide())); /* set informations */ ui.textLabel->setText(RsHtml().formatText(NULL, message, RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_CLEANSTYLE)); ui.avatarWidget->setFrameType(AvatarWidget::NORMAL_FRAME); ui.avatarWidget->setDefaultAvatar(":images/chat_64.png"); QString lobbyName = RsHtml::plainText(name); ChatLobbyInfo clinfo ; if(rsMsgs->getChatLobbyInfo(mLobbyId,clinfo)) lobbyName += "@" + RsHtml::plainText(clinfo.lobby_name); ui.toasterLabel->setText(lobbyName); }
void ImHistoryBrowser::fillItem(QListWidgetItem *itemWidget, HistoryMsg& msg) { unsigned int formatTextFlag = RSHTML_FORMATTEXT_EMBED_LINKS; if (embedSmileys) { formatTextFlag |= RSHTML_FORMATTEXT_EMBED_SMILEYS; } ChatStyle::enumFormatMessage type; if (msg.incoming) { type = ChatStyle::FORMATMSG_INCOMING; } else { type = ChatStyle::FORMATMSG_OUTGOING; } QString messageText = RsHtml().formatText(NULL, QString::fromUtf8(msg.message.c_str()), formatTextFlag); QString name; if (m_chatId.isLobbyId() || m_chatId.isGxsId()) { RsIdentityDetails details; if (rsIdentity->getIdDetails(RsGxsId(msg.peerName), details)) name = QString::fromUtf8(details.mNickname.c_str()); else name = QString::fromUtf8(msg.peerName.c_str()); } else { name = QString::fromUtf8(msg.peerName.c_str()); } QString formatMsg = style.formatMessage(type, name, QDateTime::fromTime_t(msg.sendTime), messageText); itemWidget->setData(Qt::DisplayRole, qVariantFromValue(IMHistoryItemPainter(formatMsg))); itemWidget->setData(ROLE_MSGID, msg.msgId); /* calculate plain text */ QTextDocument doc; doc.setHtml(messageText); itemWidget->setData(ROLE_PLAINTEXT, doc.toPlainText()); }
void MsgItem::fillExpandFrame() { msgLabel->setText(RsHtml().formatText(NULL, mMsg, RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS)); }
void MsgItem::updateItemStatic() { /* fill in */ #ifdef DEBUG_ITEM std::cerr << "MsgItem::updateItemStatic()"; std::cerr << std::endl; #endif MessageInfo mi; if (!rsMsgs) return; if (!rsMsgs->getMessage(mMsgId, mi)) return; /* get peer Id */ mPeerId = mi.srcId; avatar->setId(mPeerId, false); QString title; QString srcName; if ((mi.msgflags & RS_MSG_SYSTEM) && mi.srcId == rsPeers->getOwnId()) { srcName = "RetroShare"; } else { srcName = QString::fromUtf8(rsPeers->getPeerName(mi.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::fromStdWString(mi.title)); msgLabel->setText(RsHtml().formatText(NULL, QString::fromStdWString(mi.msg), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS)); 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.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(); } else { //deleteButton->setEnabled(false); } }
void ChatWidget::addChatMsg(bool incoming, const QString &name, const QDateTime &sendTime, const QDateTime &recvTime, const QString &message, enumChatType chatType) { #ifdef CHAT_DEBUG std::cout << "ChatWidget::addChatMsg message : " << message.toStdString() << std::endl; #endif unsigned int formatTextFlag = RSHTML_FORMATTEXT_EMBED_LINKS | RSHTML_FORMATTEXT_OPTIMIZE; unsigned int formatFlag = 0; // embed smileys ? if (Settings->valueFromGroup(QString("Chat"), QString::fromUtf8("Emoteicons_PrivatChat"), true).toBool()) { formatTextFlag |= RSHTML_FORMATTEXT_EMBED_SMILEYS; } // Always fix colors formatTextFlag |= RSHTML_FORMATTEXT_FIX_COLORS; qreal desiredContrast = Settings->valueFromGroup("Chat", "MinimumContrast", 4.5).toDouble(); QColor backgroundColor = ui->textBrowser->palette().base().color(); // Remove font name, size, bold, italics? if (!Settings->valueFromGroup("Chat", "EnableCustomFonts", true).toBool()) { formatTextFlag |= RSHTML_FORMATTEXT_REMOVE_FONT_FAMILY; } if (!Settings->valueFromGroup("Chat", "EnableCustomFontSize", true).toBool()) { formatTextFlag |= RSHTML_FORMATTEXT_REMOVE_FONT_SIZE; } if (!Settings->valueFromGroup("Chat", "EnableBold", true).toBool()) { formatTextFlag |= RSHTML_FORMATTEXT_REMOVE_FONT_WEIGHT; } if (!Settings->valueFromGroup("Chat", "EnableItalics", true).toBool()) { formatTextFlag |= RSHTML_FORMATTEXT_REMOVE_FONT_STYLE; } ChatStyle::enumFormatMessage type; if (chatType == TYPE_OFFLINE) { type = ChatStyle::FORMATMSG_OOUTGOING; } else if (chatType == TYPE_SYSTEM) { type = ChatStyle::FORMATMSG_SYSTEM; } else if (chatType == TYPE_HISTORY) { type = incoming ? ChatStyle::FORMATMSG_HINCOMING : ChatStyle::FORMATMSG_HOUTGOING; } else { type = incoming ? ChatStyle::FORMATMSG_INCOMING : ChatStyle::FORMATMSG_OUTGOING; } if (chatType == TYPE_SYSTEM) { formatFlag |= CHAT_FORMATMSG_SYSTEM; } QString formattedMessage = RsHtml().formatText(ui->textBrowser->document(), message, formatTextFlag, backgroundColor, desiredContrast); QString formatMsg = chatStyle.formatMessage(type, name, incoming ? sendTime : recvTime, formattedMessage, formatFlag); ui->textBrowser->append(formatMsg); resetStatusBar(); if (incoming && chatType == TYPE_NORMAL) { emit newMessage(this); if (!isActive()) { newMessages = true; } emit infoChanged(this); } }
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())); ui->subjectLabel->setText(RsHtml().formatText(NULL, QString::fromUtf8(mPost.mMsg.c_str()), 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 { 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->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()); 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; }
QString GxsChannelPostItem::getMsgLabel() { return RsHtml().formatText(NULL, QString::fromUtf8(mPost.mMsg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS); }
void GxsChannelPostItem::fillExpandFrame() { ui->msgLabel->setText(RsHtml().formatText(NULL, QString::fromUtf8(mPost.mMsg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS)); }
void GxsChannelPostItem::loadPost(const RsGxsChannelPost &post) { /* fill in */ #ifdef DEBUG_ITEM std::cerr << "GxsChannelPostItem::loadPost()"; std::cerr << std::endl; #endif m_inUpdateItemStatic = true; mPost = post; QString title; if (!mIsHome) { title = tr("Channel Feed") + ": "; RetroShareLink link; link.createChannel(post.mMeta.mGroupId, ""); title += link.toHtml(); titleLabel->setText(title); RetroShareLink msgLink; msgLink.createChannel(post.mMeta.mGroupId, post.mMeta.mMsgId); subjectLabel->setText(msgLink.toHtml()); if (IS_GROUP_SUBSCRIBED(mSubscribeFlags) || IS_GROUP_ADMIN(mSubscribeFlags)) { unsubscribeButton->setEnabled(true); } else { unsubscribeButton->setEnabled(false); } readButton->hide(); //newLabel->hide(); copyLinkButton->hide(); } else { /* subject */ titleLabel->setText(QString::fromUtf8(post.mMeta.mMsgName.c_str())); subjectLabel->setText(RsHtml().formatText(NULL, QString::fromUtf8(post.mMsg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS)); /* disable buttons: deletion facility not enabled with cache services yet */ clearButton->setEnabled(false); unsubscribeButton->setEnabled(false); clearButton->hide(); readAndClearButton->hide(); unsubscribeButton->hide(); copyLinkButton->show(); if (IS_GROUP_SUBSCRIBED(mGroupMeta.mSubscribeFlags) || IS_GROUP_ADMIN(mGroupMeta.mSubscribeFlags)) { readButton->setVisible(true); #if 0 uint32_t status = 0; rsChannels->getMessageStatus(mChanId, mMsgId, status); #endif if (IS_MSG_UNREAD(post.mMeta.mMsgStatus) || IS_MSG_NEW(post.mMeta.mMsgStatus)) { readButton->setChecked(true); readButton->setIcon(QIcon(":/images/message-state-unread.png")); } else { readButton->setChecked(false); readButton->setIcon(QIcon(":/images/message-state-read.png")); } bool newState; QColor color; if (!IS_MSG_UNREAD(post.mMeta.mMsgStatus)) { //newLabel->setVisible(false); newState = false; color = COLOR_NORMAL; } else { //newLabel->setVisible(true); newState = true; color = COLOR_NEW; } /* unpolish widget to clear the stylesheet's palette cache */ frame->style()->unpolish(frame); QPalette palette = frame->palette(); palette.setColor(frame->backgroundRole(), color); frame->setPalette(palette); frame->setProperty("new", newState); Rshare::refreshStyleSheet(frame, false); } else { readButton->setVisible(false); //newLabel->setVisible(false); } } msgLabel->setText(RsHtml().formatText(NULL, QString::fromUtf8(post.mMsg.c_str()), RSHTML_FORMATTEXT_EMBED_SMILEYS | RSHTML_FORMATTEXT_EMBED_LINKS)); msgFrame->setVisible(!post.mMsg.empty()); datetimelabel->setText(DateTime::formatLongDateTime(post.mMeta.mPublishTs)); filelabel->setText(QString("(%1 %2) %3").arg(post.mCount).arg(tr("Files")).arg(misc::friendlyUnit(post.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 = post.mFiles.begin(); it != post.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, ""); 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(); QLayout *layout = expandFrame->layout(); layout->addWidget(fi); } if(post.mThumbnail.mData != NULL) { QPixmap thumbnail; thumbnail.loadFromData(post.mThumbnail.mData, post.mThumbnail.mSize, "PNG"); // Wiping data - as its been passed to thumbnail. logoLabel->setPixmap(thumbnail); } m_inUpdateItemStatic = false; }