From 7a3370ae0f0f6de86814463580ebf16c28e02c32 Mon Sep 17 00:00:00 2001 From: Phenom Date: Thu, 28 Jan 2021 10:37:25 +0100 Subject: [PATCH] Fix Message Quick View --- retroshare-gui/src/gui/msgs/MessageModel.cpp | 109 ++++++++++--------- retroshare-gui/src/gui/msgs/MessageModel.h | 16 +-- 2 files changed, 65 insertions(+), 60 deletions(-) diff --git a/retroshare-gui/src/gui/msgs/MessageModel.cpp b/retroshare-gui/src/gui/msgs/MessageModel.cpp index 49a0d1c70..038cbb816 100644 --- a/retroshare-gui/src/gui/msgs/MessageModel.cpp +++ b/retroshare-gui/src/gui/msgs/MessageModel.cpp @@ -373,14 +373,16 @@ uint32_t RsMessageModel::updateFilterStatus(ForumModelIndex /*i*/,int /*column*/ void RsMessageModel::setFilter(FilterType filter_type, const QStringList& strings) { - std::cerr << "Setting filter to filter_type=" << int(filter_type) << " and strings to " ; - foreach(const QString& str,strings) - std::cerr << "\"" << str.toStdString() << "\" " ; - std::cerr << std::endl; +#ifdef DEBUG_MESSAGE_MODEL + std::cerr << "Setting filter to filter_type=" << int(filter_type) << " and strings to " ; + foreach(const QString& str,strings) + std::cerr << "\"" << str.toStdString() << "\" " ; + std::cerr << std::endl; +#endif - preMods(); + preMods(); - mFilterType = filter_type; + mFilterType = filter_type; mFilterStrings = strings; postMods(); @@ -388,7 +390,7 @@ void RsMessageModel::setFilter(FilterType filter_type, const QStringList& string QVariant RsMessageModel::toolTipRole(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const { - if(column == COLUMN_THREAD_AUTHOR) + if(column == COLUMN_THREAD_AUTHOR) { QString str,comment ; QList icons; @@ -460,45 +462,44 @@ QVariant RsMessageModel::displayRole(const Rs::Msgs::MsgInfoSummary& fmpe,int co { switch(col) { - case COLUMN_THREAD_SUBJECT: return QVariant(QString::fromUtf8(fmpe.title.c_str())); - case COLUMN_THREAD_ATTACHMENT:return QVariant(QString::number(fmpe.count)); + case COLUMN_THREAD_SUBJECT: return QVariant(QString::fromUtf8(fmpe.title.c_str())); + case COLUMN_THREAD_ATTACHMENT:return QVariant(QString::number(fmpe.count)); - case COLUMN_THREAD_STAR: - case COLUMN_THREAD_SPAM: - case COLUMN_THREAD_READ:return QVariant(); - case COLUMN_THREAD_DATE:{ - QDateTime qtime; - qtime.setTime_t(fmpe.ts); + case COLUMN_THREAD_STAR: + case COLUMN_THREAD_SPAM: + case COLUMN_THREAD_READ:return QVariant(); + case COLUMN_THREAD_DATE:{ + QDateTime qtime; + qtime.setTime_t(fmpe.ts); - return QVariant(DateTime::formatDateTime(qtime)); - } + return QVariant(DateTime::formatDateTime(qtime)); + } - case COLUMN_THREAD_TAGS:{ - // Tags - Rs::Msgs::MsgTagInfo tagInfo; - rsMsgs->getMessageTag(fmpe.msgId, tagInfo); + case COLUMN_THREAD_TAGS:{ + // Tags + Rs::Msgs::MsgTagInfo tagInfo; + rsMsgs->getMessageTag(fmpe.msgId, tagInfo); - Rs::Msgs::MsgTagType Tags; - rsMsgs->getMessageTagTypes(Tags); + Rs::Msgs::MsgTagType Tags; + rsMsgs->getMessageTagTypes(Tags); - QString text; + QString text; - // build tag names - std::map >::iterator Tag; - for (auto tagit = tagInfo.tagIds.begin(); tagit != tagInfo.tagIds.end(); ++tagit) - { - if (!text.isNull()) - text += ","; + // build tag names + for (auto tagit = tagInfo.tagIds.begin(); tagit != tagInfo.tagIds.end(); ++tagit) + { + if (!text.isNull()) + text += ","; - auto Tag = Tags.types.find(*tagit); + auto Tag = Tags.types.find(*tagit); - if (Tag != Tags.types.end()) - text += TagDefs::name(Tag->first, Tag->second.first); - else - std::cerr << "(WW) unknown tag " << (int)Tag->first << " in message " << fmpe.msgId << std::endl; - } - return text; - } + if (Tag != Tags.types.end()) + text += TagDefs::name(Tag->first, Tag->second.first); + else + RS_WARN("Unknown tag ", (int)Tag->first, " in message ", fmpe.msgId); + } + return text; + } case COLUMN_THREAD_AUTHOR:{ QString name; RsGxsId id = RsGxsId(fmpe.srcId.toStdString()); @@ -510,11 +511,10 @@ QVariant RsMessageModel::displayRole(const Rs::Msgs::MsgInfoSummary& fmpe,int co return QVariant(tr("[Unknown]")); } - default: + default: return QVariant("[ TODO ]"); } - return QVariant("[ERROR]"); } @@ -614,23 +614,24 @@ void RsMessageModel::setMessages(const std::list& msgs void RsMessageModel::setCurrentBox(BoxName bn) { - if(mCurrentBox != bn) - { + if(mCurrentBox != bn) + { mCurrentBox = bn; - updateMessages(); - } + updateMessages(); + } } void RsMessageModel::setQuickViewFilter(QuickViewFilter fn) { - if(fn != mQuickViewFilter) - { - std::cerr << "Changing new quickview filter to " << fn << std::endl; + if(fn != mQuickViewFilter) + { +#ifdef DEBUG_MESSAGE_MODEL + std::cerr << "Changing new quickview filter to " << fn << std::endl; +#endif - preMods(); - mQuickViewFilter = fn ; - postMods(); - } + mQuickViewFilter = fn ; + updateMessages(); + } } void RsMessageModel::getMessageSummaries(BoxName box,std::list& msgs) @@ -717,8 +718,10 @@ QModelIndex RsMessageModel::getIndexOfMessage(const std::string& mid) const return createIndex(it->second,0,ref); } +#ifdef DEBUG_MESSAGE_MODEL void RsMessageModel::debug_dump() const { - for(auto it(mMessages.begin());it!=mMessages.end();++it) - std::cerr << "Id: " << it->msgId << ": from " << it->srcId << ": flags=" << it->msgflags << ": title=\"" << it->title << "\"" << std::endl; + for(auto& it : mMessages) + std::cerr << "Id: " << it.msgId << ": from " << it.srcId << ": flags=" << it.msgflags << ": title=\"" << it.title << "\"" << std::endl; } +#endif diff --git a/retroshare-gui/src/gui/msgs/MessageModel.h b/retroshare-gui/src/gui/msgs/MessageModel.h index 8a74ed4b3..efb0cbf53 100644 --- a/retroshare-gui/src/gui/msgs/MessageModel.h +++ b/retroshare-gui/src/gui/msgs/MessageModel.h @@ -140,15 +140,17 @@ public: QVariant textColorRole (const Rs::Msgs::MsgInfoSummary& fmpe, int col) const; QVariant backgroundRole(const Rs::Msgs::MsgInfoSummary& fmpe, int col) const; - /*! - * \brief debug_dump - * Dumps the hierarchy of posts in the terminal, to allow checking whether the internal representation is correct. - */ - void debug_dump() const; +#ifdef DEBUG_MESSAGE_MODEL + /*! + * \brief debug_dump + * Dumps the hierarchy of posts in the terminal, to allow checking whether the internal representation is correct. + */ + void debug_dump() const; +#endif - // control over message flags and so on. This is handled by the model because it will allow it to update accordingly + // control over message flags and so on. This is handled by the model because it will allow it to update accordingly void setMsgReadStatus(const QModelIndex& i, bool read_status); - void setMsgStar(const QModelIndex& index,bool star) ; + void setMsgStar(const QModelIndex& index,bool star) ; void setMsgJunk(const QModelIndex& index,bool junk) ; public slots: