diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp index 3a1d4f507..ce28e9191 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp @@ -258,13 +258,8 @@ QVariant RsGxsForumModel::data(const QModelIndex &index, int role) const switch(role) { - case Qt::SizeHintRole: return sizeHintRole(index.column()) ; - case Qt::FontRole: - case Qt::TextAlignmentRole: - case Qt::TextColorRole: - case Qt::WhatsThisRole: - case Qt::EditRole: - case Qt::StatusTipRole: return QVariant(); + case Qt::SizeHintRole: return sizeHintRole(index.column()) ; + case Qt::StatusTipRole:return QVariant(); default: break; } @@ -297,7 +292,7 @@ QVariant RsGxsForumModel::data(const QModelIndex &index, int role) const { QFont font ; - font.setBold(IS_MSG_UNREAD(fmpe.mMsgStatus)); + font.setBold(fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_HAS_UNREAD_CHILDREN); return QVariant(font); } @@ -311,6 +306,7 @@ QVariant RsGxsForumModel::data(const QModelIndex &index, int role) const case Qt::DecorationRole: return decorationRole(fmpe,index.column()) ; case Qt::ToolTipRole: return toolTipRole (fmpe,index.column()) ; case Qt::UserRole: return userRole (fmpe,index.column()) ; + case Qt::TextColorRole: return textColorRole (fmpe,index.column()) ; case ThreadPinnedRole: return pinnedRole (fmpe,index.column()) ; case MissingRole: return missingRole (fmpe,index.column()) ; @@ -320,6 +316,14 @@ QVariant RsGxsForumModel::data(const QModelIndex &index, int role) const } } +QVariant RsGxsForumModel::textColorRole(const ForumModelPostEntry& fmpe,int column) const +{ + if( (fmpe.mPostFlags & ForumModelPostEntry::FLAG_POST_HAS_UNREAD_CHILDREN) && !IS_MSG_UNREAD(fmpe.mMsgStatus)) + return QVariant(mTextColorUnreadChildren); + + return QVariant(); +} + QVariant RsGxsForumModel::statusRole(const ForumModelPostEntry& fmpe,int column) const { if(column != COLUMN_THREAD_DATA) @@ -476,6 +480,9 @@ void RsGxsForumModel::setPosts(const RsGxsForumGroup& group, const std::vector= mPosts.size()) + return ; + + bool has_unread_below,has_read_below; + recursSetMsgReadStatus(entry,read_status,with_children) ; + recursUpdateReadStatus(0,has_unread_below,has_read_below); +} + +void RsGxsForumModel::recursSetMsgReadStatus(ForumModelIndex i,bool read_status,bool with_children) +{ + if(read_status) + mPosts[i].mMsgStatus = 0; + else + mPosts[i].mMsgStatus = GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD; + + uint32_t token; + rsGxsForums->setMessageReadStatus(token,std::make_pair( mForumGroup.mMeta.mGroupId, mPosts[i].mMsgId ), read); + + if(!with_children) + return; + + for(uint32_t j=0;j& entries,For { const ForumModelPostEntry& e(entries[index]); - std::cerr << std::string(depth*2,' ') << e.mAuthorId.toStdString() << " " << QString("%1").arg((uint32_t)e.mPostFlags,8,16,QChar('0')).toStdString() - << " " << QDateTime::fromSecsSinceEpoch(e.mPublishTs).toString().toStdString() << " \"" << e.mTitle << "\"" << std::endl; + std::cerr << std::string(depth*2,' ') << e.mAuthorId.toStdString() << " " + << QString("%1").arg((uint32_t)e.mPostFlags,8,16,QChar('0')).toStdString() << " " + << QString("%1").arg((uint32_t)e.mMsgStatus,8,16,QChar('0')).toStdString() << " " + << QDateTime::fromSecsSinceEpoch(e.mPublishTs).toString().toStdString() << " \"" << e.mTitle << "\"" << std::endl; for(uint32_t i=0;i +#include // This class holds the actual hierarchy of posts, represented by identifiers // It is responsible for auto-updating when necessary and holds a mutex to allow the Model to @@ -77,9 +78,19 @@ public: StatusRole = Qt::UserRole+4, }; + QModelIndex root() const{ return createIndex(0,0,(void*)NULL) ;} + // This method will asynchroneously update the data void setForum(const RsGxsGroupId& forumGroup); + void setTextColorRead (QColor color) { mTextColorRead = color;} + void setTextColorUnread (QColor color) { mTextColorUnread = color;} + void setTextColorUnreadChildren(QColor color) { mTextColorUnreadChildren = color;} + void setTextColorNotSubscribed (QColor color) { mTextColorNotSubscribed = color;} + void setTextColorMissing (QColor color) { mTextColorMissing = color;} + + void setMsgReadStatus(const QModelIndex &i, bool read_status, bool with_children); + int rowCount(const QModelIndex& parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override; bool hasChildren(const QModelIndex &parent = QModelIndex()) const override; @@ -104,6 +115,7 @@ public: QVariant authorRole (const ForumModelPostEntry& fmpe, int col) const; QVariant sortRole (const ForumModelPostEntry& fmpe, int col) const; QVariant fontRole (const ForumModelPostEntry& fmpe, int col) const; + QVariant textColorRole(const ForumModelPostEntry& fmpe, int col) const; /*! * \brief debug_dump @@ -128,6 +140,7 @@ private: void update_posts(const RsGxsGroupId &group_id); void setForumMessageSummary(const std::vector& messages); void recursUpdateReadStatus(ForumModelIndex i,bool& has_unread_below,bool& has_read_below); + void recursSetMsgReadStatus(ForumModelIndex i,bool read_status,bool with_children); static void generateMissingItem(const RsGxsMessageId &msgId,ForumModelPostEntry& entry); static ForumModelIndex addEntry(std::vector& posts,const ForumModelPostEntry& entry,ForumModelIndex parent); @@ -138,4 +151,10 @@ private: void initEmptyHierarchy(std::vector& posts); std::vector mPosts ; // store the list of posts updated from rsForums. + + QColor mTextColorRead ; + QColor mTextColorUnread ; + QColor mTextColorUnreadChildren; + QColor mTextColorNotSubscribed ; + QColor mTextColorMissing ; }; diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp index 3d62a2982..44c530ed6 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.cpp @@ -170,7 +170,7 @@ public: QPixmap pix = icon.pixmap(r.size()); - return QSize(pix.width() + fm.width(str),fm.height()); + return QSize(pix.width() + fm.width(str),1.2*fm.height()); } virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex& index) const override @@ -215,6 +215,12 @@ public: } }; +void GxsForumThreadWidget::setTextColorRead (QColor color) { mTextColorRead = color; mThreadModel->setTextColorRead (color);} +void GxsForumThreadWidget::setTextColorUnread (QColor color) { mTextColorUnread = color; mThreadModel->setTextColorUnread (color);} +void GxsForumThreadWidget::setTextColorUnreadChildren(QColor color) { mTextColorUnreadChildren = color; mThreadModel->setTextColorUnreadChildren(color);} +void GxsForumThreadWidget::setTextColorNotSubscribed (QColor color) { mTextColorNotSubscribed = color; mThreadModel->setTextColorNotSubscribed (color);} +void GxsForumThreadWidget::setTextColorMissing (QColor color) { mTextColorMissing = color; mThreadModel->setTextColorMissing (color);} + GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget *parent) : GxsMessageFrameWidget(rsGxsForums, parent), ui(new Ui::GxsForumThreadWidget) @@ -234,6 +240,7 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget setUpdateWhenInvisible(true); +#ifdef TODO /* Setup UI helper */ mStateHelper->addWidget(mTokenTypeGroupData, ui->subscribeToolButton); mStateHelper->addWidget(mTokenTypeGroupData, ui->newthreadButton); @@ -257,6 +264,7 @@ GxsForumThreadWidget::GxsForumThreadWidget(const RsGxsGroupId &forumId, QWidget mStateHelper->addLoadPlaceholder(mTokenTypeMessageData, ui->postText); //mStateHelper->addLoadPlaceholder(mTokenTypeMessageData, ui->threadTitle); +#endif mSubscribeFlags = 0; mSignFlags = 0; @@ -583,14 +591,21 @@ void GxsForumThreadWidget::updateDisplay(bool complete) } } -bool GxsForumThreadWidget::getCurrentPost(ForumModelPostEntry& fmpe) const +QModelIndex GxsForumThreadWidget::GxsForumThreadWidget::getCurrentIndex() const { QModelIndexList selectedIndexes = ui->threadTreeWidget->selectionModel()->selectedIndexes(); if(selectedIndexes.size() != RsGxsForumModel::COLUMN_THREAD_NB_COLUMNS) // check that a single row is selected - return false; + return QModelIndex(); - QModelIndex index = *selectedIndexes.begin(); + return *selectedIndexes.begin(); +} +bool GxsForumThreadWidget::getCurrentPost(ForumModelPostEntry& fmpe) const +{ + QModelIndex index = getCurrentIndex() ; + + if(!index.isValid()) + return false ; return mThreadModel->getPostData(index,fmpe); } @@ -1882,25 +1897,22 @@ void GxsForumThreadWidget::insertMessageData(const RsGxsForumMsg &msg) bool setToReadOnActive = Settings->getForumMsgSetToReadOnActivate(); uint32_t status = msg.mMeta.mMsgStatus ;//item->data(RsGxsForumModel::COLUMN_THREAD_DATA, ROLE_THREAD_STATUS).toUInt(); -#ifdef TODO - QList row; - row.append(item); + QModelIndex index = getCurrentIndex(); if (IS_MSG_NEW(status)) { if (setToReadOnActive) { /* set to read */ - setMsgReadStatus(row, true); + mThreadModel->setMsgReadStatus(index,true,false); } else { /* set to unread by user */ - setMsgReadStatus(row, false); + mThreadModel->setMsgReadStatus(index,false,false); } } else { if (setToReadOnActive && IS_MSG_UNREAD(status)) { /* set to read */ - setMsgReadStatus(row, true); + mThreadModel->setMsgReadStatus(index, true,false); } } -#endif ui->time_label->setText(DateTime::formatLongDateTime(msg.mMeta.mPublishTs)); ui->by_label->setId(msg.mMeta.mAuthorId); @@ -2045,6 +2057,7 @@ int GxsForumThreadWidget::getSelectedMsgCount(QList *rows, QLi void GxsForumThreadWidget::setMsgReadStatus(QList &rows, bool read) { + #ifdef TODO QList::iterator row; std::list changedItems; @@ -2132,11 +2145,25 @@ void GxsForumThreadWidget::showInPeopleTab() void GxsForumThreadWidget::markMsgAsReadUnread (bool read, bool children, bool forum) { -#ifdef TODO if (groupId().isNull() || !IS_GROUP_SUBSCRIBED(mSubscribeFlags)) { return; } + if(forum) + mThreadModel->setMsgReadStatus(mThreadModel->root(),read,children); + else + { + QModelIndexList selectedIndexes = ui->threadTreeWidget->selectionModel()->selectedIndexes(); + + if(selectedIndexes.size() != RsGxsForumModel::COLUMN_THREAD_NB_COLUMNS) // check that a single row is selected + return ; + + QModelIndex index = *selectedIndexes.begin(); + + mThreadModel->setMsgReadStatus(index,read,children); + } + +#ifdef TODO /* get selected messages */ QList rows; if (forum) { diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h index 3f5a5c92f..b32296d65 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h +++ b/retroshare-gui/src/gui/gxsforums/GxsForumThreadWidget.h @@ -59,11 +59,11 @@ public: QColor textColorNotSubscribed() const { return mTextColorNotSubscribed; } QColor textColorMissing() const { return mTextColorMissing; } - void setTextColorRead(QColor color) { mTextColorRead = color; } - void setTextColorUnread(QColor color) { mTextColorUnread = color; } - void setTextColorUnreadChildren(QColor color) { mTextColorUnreadChildren = color; } - void setTextColorNotSubscribed(QColor color) { mTextColorNotSubscribed = color; } - void setTextColorMissing(QColor color) { mTextColorMissing = color; } + void setTextColorRead (QColor color) ; + void setTextColorUnread (QColor color) ; + void setTextColorUnreadChildren(QColor color) ; + void setTextColorNotSubscribed (QColor color) ; + void setTextColorMissing (QColor color) ; /* GxsMessageFrameWidget */ virtual void groupIdChanged(); @@ -151,6 +151,7 @@ private slots: private: void insertMessageData(const RsGxsForumMsg &msg); bool getCurrentPost(ForumModelPostEntry& fmpe) const ; + QModelIndex getCurrentIndex() const; void insertMessage(); void insertGroupData();