From 16cae622e3c4acc2f3f6d4e22f03d9223b25e7a5 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 26 Feb 2019 10:46:32 +0100 Subject: [PATCH] fixed icons in attachment and read columns --- libretroshare/src/retroshare/rsmsgs.h | 6 +- retroshare-gui/src/gui/MessagesDialog.cpp | 201 ++++++------------- retroshare-gui/src/gui/msgs/MessageModel.cpp | 164 +++++++++++++-- retroshare-gui/src/gui/msgs/MessageModel.h | 44 +--- 4 files changed, 223 insertions(+), 192 deletions(-) diff --git a/libretroshare/src/retroshare/rsmsgs.h b/libretroshare/src/retroshare/rsmsgs.h index ad189e03f..4893bb6c6 100644 --- a/libretroshare/src/retroshare/rsmsgs.h +++ b/libretroshare/src/retroshare/rsmsgs.h @@ -93,8 +93,8 @@ const ChatLobbyFlags RS_CHAT_LOBBY_FLAGS_PGP_SIGNED ( 0x00000010 ) ; // requi typedef uint64_t ChatLobbyId ; typedef uint64_t ChatLobbyMsgId ; typedef std::string ChatLobbyNickName ; - -typedef uint64_t MessageId ; +typedef std::string RsMailMessageId; // should be uint32_t !! +typedef uint64_t MessageId ; namespace Rs @@ -237,7 +237,7 @@ struct MsgInfoSummary : RsSerializable MsgInfoSummary() : msgflags(0), count(0), ts(0) {} virtual ~MsgInfoSummary() = default; - std::string msgId; + RsMailMessageId msgId; RsPeerId srcId; uint32_t msgflags; diff --git a/retroshare-gui/src/gui/MessagesDialog.cpp b/retroshare-gui/src/gui/MessagesDialog.cpp index 684c08de9..32159c946 100644 --- a/retroshare-gui/src/gui/MessagesDialog.cpp +++ b/retroshare-gui/src/gui/MessagesDialog.cpp @@ -66,20 +66,14 @@ #define COLUMN_SUBJECT 2 #define COLUMN_UNREAD 3 #define COLUMN_FROM 4 -#define COLUMN_SIGNATURE 5 -#define COLUMN_DATE 6 -#define COLUMN_CONTENT 7 -#define COLUMN_TAGS 8 -#define COLUMN_COUNT 9 +//#define COLUMN_SIGNATURE 5 +#define COLUMN_DATE 5 +#define COLUMN_CONTENT 6 +#define COLUMN_TAGS 7 +#define COLUMN_COUNT 8 #define COLUMN_DATA 0 // column for storing the userdata like msgid and srcid -#define ROLE_SORT Qt::UserRole -#define ROLE_MSGID Qt::UserRole + 1 -#define ROLE_SRCID Qt::UserRole + 2 -#define ROLE_UNREAD Qt::UserRole + 3 -#define ROLE_MSGFLAGS Qt::UserRole + 4 - #define ROLE_QUICKVIEW_TYPE Qt::UserRole #define ROLE_QUICKVIEW_ID Qt::UserRole + 1 #define ROLE_QUICKVIEW_TEXT Qt::UserRole + 2 @@ -195,7 +189,7 @@ MessagesDialog::MessagesDialog(QWidget *parent) mMessageProxyModel->setSortRole(RsMessageModel::SortRole); ui.messageTreeWidget->setModel(mMessageProxyModel); - mMessageModel->updateMessages(); + changeBox(RsMessageModel::BOX_INBOX); mMessageProxyModel->setFilterRole(RsMessageModel::FilterRole); mMessageProxyModel->setFilterRegExp(QRegExp(QString(RsMessageModel::FilterString))) ; @@ -235,13 +229,13 @@ MessagesDialog::MessagesDialog(QWidget *parent) #endif mMessageCompareRole = new RSTreeWidgetItemCompareRole; - mMessageCompareRole->setRole(COLUMN_SUBJECT, ROLE_SORT); - mMessageCompareRole->setRole(COLUMN_UNREAD, ROLE_SORT); - mMessageCompareRole->setRole(COLUMN_FROM, ROLE_SORT); - mMessageCompareRole->setRole(COLUMN_DATE, ROLE_SORT); - mMessageCompareRole->setRole(COLUMN_TAGS, ROLE_SORT); - mMessageCompareRole->setRole(COLUMN_ATTACHEMENTS, ROLE_SORT); - mMessageCompareRole->setRole(COLUMN_STAR, ROLE_SORT); + mMessageCompareRole->setRole(COLUMN_SUBJECT, RsMessageModel::ROLE_SORT); + mMessageCompareRole->setRole(COLUMN_UNREAD, RsMessageModel::ROLE_SORT); + mMessageCompareRole->setRole(COLUMN_FROM, RsMessageModel::ROLE_SORT); + mMessageCompareRole->setRole(COLUMN_DATE, RsMessageModel::ROLE_SORT); + mMessageCompareRole->setRole(COLUMN_TAGS, RsMessageModel::ROLE_SORT); + mMessageCompareRole->setRole(COLUMN_ATTACHEMENTS, RsMessageModel::ROLE_SORT); + mMessageCompareRole->setRole(COLUMN_STAR, RsMessageModel::ROLE_SORT); RSElidedItemDelegate *itemDelegate = new RSElidedItemDelegate(this); itemDelegate->setSpacing(QSize(0, 2)); @@ -256,12 +250,14 @@ MessagesDialog::MessagesDialog(QWidget *parent) Shortcut = new QShortcut(QKeySequence (Qt::SHIFT | Qt::Key_Delete), ui.messageTreeWidget, 0, 0, Qt::WidgetShortcut); connect(Shortcut, SIGNAL(activated()), this, SLOT( removemessage ())); + QFontMetricsF fm(font()); + /* Set initial section sizes */ QHeaderView * msgwheader = ui.messageTreeWidget->header () ; - msgwheader->resizeSection (COLUMN_ATTACHEMENTS, 24); + msgwheader->resizeSection (COLUMN_ATTACHEMENTS, fm.width('0')); msgwheader->resizeSection (COLUMN_SUBJECT, 250); msgwheader->resizeSection (COLUMN_FROM, 140); - msgwheader->resizeSection (COLUMN_SIGNATURE, 24); + //msgwheader->resizeSection (COLUMN_SIGNATURE, 24); msgwheader->resizeSection (COLUMN_DATE, 140); QHeaderView_setSectionResizeModeColumn(msgwheader, COLUMN_STAR, QHeaderView::Fixed); @@ -306,9 +302,9 @@ MessagesDialog::MessagesDialog(QWidget *parent) QHeaderView_setSectionResizeModeColumn(msgwheader, COLUMN_ATTACHEMENTS, QHeaderView::Fixed); QHeaderView_setSectionResizeModeColumn(msgwheader, COLUMN_DATE, QHeaderView::Interactive); QHeaderView_setSectionResizeModeColumn(msgwheader, COLUMN_UNREAD, QHeaderView::Fixed); - QHeaderView_setSectionResizeModeColumn(msgwheader, COLUMN_SIGNATURE, QHeaderView::Fixed); + //QHeaderView_setSectionResizeModeColumn(msgwheader, COLUMN_SIGNATURE, QHeaderView::Fixed); msgwheader->resizeSection (COLUMN_UNREAD, 24); - msgwheader->resizeSection (COLUMN_SIGNATURE, 24); + //msgwheader->resizeSection (COLUMN_SIGNATURE, 24); msgwheader->resizeSection (COLUMN_STAR, 24); QHeaderView_setSectionResizeModeColumn(msgwheader, COLUMN_STAR, QHeaderView::Fixed); msgwheader->setStretchLastSection(false); @@ -543,7 +539,7 @@ int MessagesDialog::getSelectedMessages(QList& mid) QModelIndexList qmil = ui.messageTreeWidget->selectionModel()->selectedRows(); foreach(const QModelIndex& m, qmil) - mid.push_back(m.sibling(m.row(),COLUMN_DATA).data(ROLE_MSGID).toString()) ; + mid.push_back(m.sibling(m.row(),COLUMN_DATA).data(RsMessageModel::ROLE_MSGID).toString()) ; return mid.size(); } @@ -590,7 +586,7 @@ bool MessagesDialog::isMessageRead(QTreeWidgetItem *item) return true; } - return !item->data(COLUMN_DATA, ROLE_UNREAD).toBool(); + return !item->data(COLUMN_DATA, RsMessageModel::ROLE_UNREAD).toBool(); } bool MessagesDialog::hasMessageStar(QTreeWidgetItem *item) @@ -599,7 +595,7 @@ bool MessagesDialog::hasMessageStar(QTreeWidgetItem *item) return false; } - return item->data(COLUMN_DATA, ROLE_MSGFLAGS).toInt() & RS_MSG_STAR; + return item->data(COLUMN_DATA, RsMessageModel::ROLE_MSGFLAGS).toInt() & RS_MSG_STAR; } void MessagesDialog::messageTreeWidgetCustomPopupMenu(QPoint /*point*/) @@ -609,7 +605,10 @@ void MessagesDialog::messageTreeWidgetCustomPopupMenu(QPoint /*point*/) MessageInfo msgInfo; if (!getCurrentMsg(cid, mid)) + { + std::cerr << "No current message!" << std::endl; return ; + } if(!rsMail->getMessage(mid, msgInfo)) return ; @@ -895,68 +894,6 @@ void MessagesDialog::messagesTagsChanged() static void InitIconAndFont(QTreeWidgetItem *item) { - int msgFlags = item->data(COLUMN_DATA, ROLE_MSGFLAGS).toInt(); - - // show the real "New" state - if (msgFlags & RS_MSG_NEW) { - item->setIcon(COLUMN_SUBJECT, QIcon(":/images/message-state-new.png")); - } else { - if (msgFlags & RS_MSG_USER_REQUEST) { - item->setIcon(COLUMN_SUBJECT, QIcon(":/images/user/user_request16.png")); - } else if (msgFlags & RS_MSG_FRIEND_RECOMMENDATION) { - item->setIcon(COLUMN_SUBJECT, QIcon(":/images/user/friend_suggestion16.png")); - } else if (msgFlags & RS_MSG_PUBLISH_KEY) { - item->setIcon(COLUMN_SUBJECT, QIcon(":/images/share-icon-16.png")); - } else if (msgFlags & RS_MSG_UNREAD_BY_USER) { - if ((msgFlags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == RS_MSG_REPLIED) { - item->setIcon(COLUMN_SUBJECT, QIcon(":/images/message-mail-replied.png")); - } else if ((msgFlags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == RS_MSG_FORWARDED) { - item->setIcon(COLUMN_SUBJECT, QIcon(":/images/message-mail-forwarded.png")); - } else if ((msgFlags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == (RS_MSG_REPLIED | RS_MSG_FORWARDED)) { - item->setIcon(COLUMN_SUBJECT, QIcon(":/images/message-mail-replied-forw.png")); - } else { - item->setIcon(COLUMN_SUBJECT, QIcon(":/images/message-mail.png")); - } - } else { - if ((msgFlags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == RS_MSG_REPLIED) { - item->setIcon(COLUMN_SUBJECT, QIcon(":/images/message-mail-replied-read.png")); - } else if ((msgFlags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == RS_MSG_FORWARDED) { - item->setIcon(COLUMN_SUBJECT, QIcon(":/images/message-mail-forwarded-read.png")); - } else if ((msgFlags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == (RS_MSG_REPLIED | RS_MSG_FORWARDED)) { - item->setIcon(COLUMN_SUBJECT, QIcon(":/images/message-mail-replied-forw-read.png")); - } else { - item->setIcon(COLUMN_SUBJECT, QIcon(":/images/message-mail-read.png")); - } - } - } - - if (msgFlags & RS_MSG_STAR) { - item->setIcon(COLUMN_STAR, QIcon(IMAGE_STAR_ON)); - item->setData(COLUMN_STAR, ROLE_SORT, 1); - } else { - item->setIcon(COLUMN_STAR, QIcon(IMAGE_STAR_OFF)); - item->setData(COLUMN_STAR, ROLE_SORT, 0); - } - - bool isNew = msgFlags & (RS_MSG_NEW | RS_MSG_UNREAD_BY_USER); - - // set icon - if (isNew) { - item->setIcon(COLUMN_UNREAD, QIcon(":/images/message-state-unread.png")); - item->setData(COLUMN_UNREAD, ROLE_SORT, 1); - } else { - item->setIcon(COLUMN_UNREAD, QIcon(":/images/message-state-read.png")); - item->setData(COLUMN_UNREAD, ROLE_SORT, 0); - } - - // set font - for (int i = 0; i < COLUMN_COUNT; ++i) { - QFont qf = item->font(i); - qf.setBold(isNew); - item->setFont(i, qf); - } - - item->setData(COLUMN_DATA, ROLE_UNREAD, isNew); } #ifdef TO_REMOVE @@ -1519,10 +1456,10 @@ void MessagesDialog::setMsgAsReadUnread(const QList &items, bo LockUpdate Lock (this, false); foreach (QTreeWidgetItem *item, items) { - std::string mid = item->data(COLUMN_DATA, ROLE_MSGID).toString().toStdString(); + std::string mid = item->data(COLUMN_DATA, RsMessageModel::ROLE_MSGID).toString().toStdString(); if (rsMail->MessageRead(mid, !read)) { - int msgFlag = item->data(COLUMN_DATA, ROLE_MSGFLAGS).toInt(); + int msgFlag = item->data(COLUMN_DATA, RsMessageModel::ROLE_MSGFLAGS).toInt(); msgFlag &= ~RS_MSG_NEW; if (read) { @@ -1531,7 +1468,7 @@ void MessagesDialog::setMsgAsReadUnread(const QList &items, bo msgFlag |= RS_MSG_UNREAD_BY_USER; } - item->setData(COLUMN_DATA, ROLE_MSGFLAGS, msgFlag); + item->setData(COLUMN_DATA, RsMessageModel::ROLE_MSGFLAGS, msgFlag); InitIconAndFont(item); } @@ -1571,10 +1508,10 @@ void MessagesDialog::setMsgStar(const QList &items, bool star) LockUpdate Lock (this, false); foreach (QTreeWidgetItem *item, items) { - std::string mid = item->data(COLUMN_DATA, ROLE_MSGID).toString().toStdString(); + std::string mid = item->data(COLUMN_DATA, RsMessageModel::ROLE_MSGID).toString().toStdString(); if (rsMail->MessageStar(mid, star)) { - int msgFlag = item->data(COLUMN_DATA, ROLE_MSGFLAGS).toInt(); + int msgFlag = item->data(COLUMN_DATA, RsMessageModel::ROLE_MSGFLAGS).toInt(); msgFlag &= ~RS_MSG_STAR; if (star) { @@ -1583,7 +1520,7 @@ void MessagesDialog::setMsgStar(const QList &items, bool star) msgFlag &= ~RS_MSG_STAR; } - item->setData(COLUMN_DATA, ROLE_MSGFLAGS, msgFlag); + item->setData(COLUMN_DATA, RsMessageModel::ROLE_MSGFLAGS, msgFlag); InitIconAndFont(item); @@ -1606,7 +1543,7 @@ void MessagesDialog::insertMsgTxtAndFiles(QTreeWidgetItem *item, bool bSetToRead updateInterface(); return; } - mid = item->data(COLUMN_DATA, ROLE_MSGID).toString().toStdString(); + mid = item->data(COLUMN_DATA, RsMessageModel::ROLE_MSGID).toString().toStdString(); int nCount = getSelectedMsgCount (NULL, NULL, NULL, NULL); if (nCount == 1) { @@ -1682,8 +1619,8 @@ bool MessagesDialog::getCurrentMsg(std::string &cid, std::string &mid) if(!indx.isValid()) return false ; - cid = indx.sibling(indx.row(),COLUMN_DATA).data(ROLE_SRCID).toString().toStdString(); - mid = indx.sibling(indx.row(),COLUMN_DATA).data(ROLE_MSGID).toString().toStdString(); + cid = indx.sibling(indx.row(),COLUMN_DATA).data(RsMessageModel::ROLE_SRCID).toString().toStdString(); + mid = indx.sibling(indx.row(),COLUMN_DATA).data(RsMessageModel::ROLE_MSGID).toString().toStdString(); return true; } @@ -1720,12 +1657,11 @@ void MessagesDialog::undeletemessage() { LockUpdate Lock (this, true); - QList items; - getSelectedMsgCount (&items, NULL, NULL, NULL); - foreach (QTreeWidgetItem *item, items) { - QString mid = item->data(COLUMN_DATA, ROLE_MSGID).toString(); - rsMail->MessageToTrash(mid.toStdString(), false); - } + QList msgids; + getSelectedMessages(msgids); + + foreach (const QString& s, msgids) + rsMail->MessageToTrash(s.toStdString(), false); // LockUpdate -> insertMessages(); } @@ -1990,14 +1926,11 @@ void MessagesDialog::tagAboutToShow() // activate actions from the first selected row MsgTagInfo tagInfo; - QList items; - getSelectedMsgCount (&items, NULL, NULL, NULL); + QList msgids; + getSelectedMessages(msgids); - if (items.size()) { - std::string msgId = items.front()->data(COLUMN_DATA, ROLE_MSGID).toString().toStdString(); - - rsMail->getMessageTag(msgId, tagInfo); - } + if(!msgids.empty()) + rsMail->getMessageTag(msgids.front().toStdString(), tagInfo); menu->activateActions(tagInfo.tagIds); } @@ -2006,12 +1939,12 @@ void MessagesDialog::tagRemoveAll() { LockUpdate Lock (this, false); - QList items; - getSelectedMsgCount (&items, NULL, NULL, NULL); - foreach (QTreeWidgetItem *item, items) { - std::string msgId = item->data(COLUMN_DATA, ROLE_MSGID).toString().toStdString(); + QList msgids; + getSelectedMessages(msgids); - rsMail->setMessageTag(msgId, 0, false); + foreach(const QString& s, msgids) + { + rsMail->setMessageTag(s.toStdString(), 0, false); Lock.setUpdate(true); } @@ -2026,32 +1959,23 @@ void MessagesDialog::tagSet(int tagId, bool set) LockUpdate Lock (this, false); - QList items; - getSelectedMsgCount (&items, NULL, NULL, NULL); - foreach (QTreeWidgetItem *item, items) { - std::string msgId = item->data(COLUMN_DATA, ROLE_MSGID).toString().toStdString(); + QList msgids; + getSelectedMessages(msgids); - if (rsMail->setMessageTag(msgId, tagId, set)) { + foreach (const QString& s, msgids) + if (rsMail->setMessageTag(s.toStdString(), tagId, set)) Lock.setUpdate(true); - } - } - - // LockUpdate -> insertMessages(); } void MessagesDialog::emptyTrash() { LockUpdate Lock (this, true); - std::list msgList; - rsMail->getMessageSummaries(msgList); + std::list msgs ; + mMessageModel->getMessageSummaries(RsMessageModel::BOX_TRASH,msgs); - std::list::const_iterator it; - for (it = msgList.begin(); it != msgList.end(); ++it) { - if (it->msgflags & RS_MSG_TRASH) { - rsMail->MessageDelete(it->msgId); - } - } + for(auto it(msgs.begin());it!=msgs.end();++it) + rsMail->MessageDelete(it->msgId); // LockUpdate -> insertMessages(); } @@ -2142,13 +2066,16 @@ void MessagesDialog::updateInterface() int tab = ui.tabWidget->currentIndex(); - if (tab == 0) { - count = getSelectedMsgCount(NULL, NULL, NULL, NULL); - } else { + if (tab == 0) + { + QList msgs; + count = getSelectedMessages(msgs); + } + else + { MessageWidget *msg = dynamic_cast(ui.tabWidget->widget(tab)); - if (msg && msg->msgId().empty() == false) { + if (msg && msg->msgId().empty() == false) count = 1; - } } ui.replymessageButton->setEnabled(count == 1); diff --git a/retroshare-gui/src/gui/msgs/MessageModel.cpp b/retroshare-gui/src/gui/msgs/MessageModel.cpp index 47430fab3..55fb89e42 100644 --- a/retroshare-gui/src/gui/msgs/MessageModel.cpp +++ b/retroshare-gui/src/gui/msgs/MessageModel.cpp @@ -26,17 +26,20 @@ #include #include +#include "gui/common/TagDefs.h" #include "util/HandleRichText.h" #include "util/DateTime.h" #include "gui/gxs/GxsIdDetails.h" #include "MessageModel.h" #include "retroshare/rsexpr.h" +#include "retroshare/rsmsgs.h" //#define DEBUG_MESSAGE_MODEL -#define IS_MESSAGE_UNREAD(flags) (flags & RS_MSG_UNREAD_BY_USER) +#define IS_MESSAGE_UNREAD(flags) (flags & (RS_MSG_NEW | RS_MSG_UNREAD_BY_USER)) #define IMAGE_STAR_ON ":/images/star-on-16.png" +#define IMAGE_STAR_OFF ":/images/star-off-16.png" std::ostream& operator<<(std::ostream& o, const QModelIndex& i);// defined elsewhere @@ -46,6 +49,7 @@ RsMessageModel::RsMessageModel(QObject *parent) : QAbstractItemModel(parent) { mFilteringEnabled=false; + mCurrentBox = BOX_NONE; } void RsMessageModel::preMods() @@ -174,11 +178,25 @@ QVariant RsMessageModel::headerData(int section, Qt::Orientation orientation, in switch(section) { case COLUMN_THREAD_STAR: return QIcon(IMAGE_STAR_ON); - case COLUMN_THREAD_READ: return QIcon(":/images/message-state-read.png"); + case COLUMN_THREAD_READ: return QIcon(":/images/message-state-header.png"); + case COLUMN_THREAD_ATTACHMENT: return QIcon(":/images/attachment.png"); default: return QVariant(); } + if(role == Qt::ToolTipRole) + switch(section) + { + case COLUMN_THREAD_ATTACHMENT: return tr("Click to sort by attachments"); + case COLUMN_THREAD_SUBJECT: return tr("Click to sort by subject"); + case COLUMN_THREAD_READ: return tr("Click to sort by read"); + case COLUMN_THREAD_AUTHOR: return tr("Click to sort by from"); + case COLUMN_THREAD_DATE: return tr("Click to sort by date"); + case COLUMN_THREAD_TAGS: return tr("Click to sort by tags"); + case COLUMN_THREAD_STAR: return tr("Click to sort by star"); + default: + return QVariant(); + } return QVariant(); } @@ -226,7 +244,8 @@ QVariant RsMessageModel::data(const QModelIndex &index, int role) const if(role == Qt::FontRole) { QFont font ; -// font.setBold( (fmpe.mPostFlags & (ForumModelPostEntry::FLAG_POST_HAS_UNREAD_CHILDREN | ForumModelPostEntry::FLAG_POST_IS_PINNED)) || IS_MSG_UNREAD(fmpe.mMsgStatus)); + font.setBold(fmpe.msgflags & (RS_MSG_NEW | RS_MSG_UNREAD_BY_USER)); + return QVariant(font); } @@ -356,6 +375,14 @@ QVariant RsMessageModel::authorRole(const Rs::Msgs::MsgInfoSummary& fmpe,int col return QVariant(); } +// QVariant RsMessageModel::unreadRole(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const +// { +// if(column == COLUMN_THREAD_UNREAD) +// return QVariant(); +// lconst Rs::Msgs::MsgInfoSummary& fmpe,int column) const +// +// } + QVariant RsMessageModel::sortRole(const Rs::Msgs::MsgInfoSummary& fmpe,int column) const { switch(column) @@ -371,6 +398,8 @@ QVariant RsMessageModel::sortRole(const Rs::Msgs::MsgInfoSummary& fmpe,int colum return QVariant(str); } + case COLUMN_THREAD_STAR: return QVariant((fmpe.msgflags & RS_MSG_STAR)? 1:0); + default: return displayRole(fmpe,column); } @@ -380,21 +409,48 @@ 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_SUBJECT: return QVariant(QString::fromUtf8(fmpe.title.c_str())); + case COLUMN_THREAD_ATTACHMENT:return QVariant(QString::number(fmpe.count)); - case COLUMN_THREAD_READ:return QVariant(); - case COLUMN_THREAD_DATE:{ - QDateTime qtime; - qtime.setTime_t(fmpe.ts); + 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_AUTHOR: return QVariant(); + case COLUMN_THREAD_TAGS:{ + // Tags + Rs::Msgs::MsgTagInfo tagInfo; + rsMsgs->getMessageTag(fmpe.msgId, tagInfo); - default: - return QVariant("[ TODO ]"); - } + Rs::Msgs::MsgTagType Tags; + rsMsgs->getMessageTagTypes(Tags); + + QString text; + + // build tag names + std::map >::iterator Tag; + for (auto tagit = tagInfo.tagIds.begin(); tagit != tagInfo.tagIds.end(); ++tagit) + { + if (!text.isNull()) + text += ","; + + 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; + } + case COLUMN_THREAD_AUTHOR: return QVariant(); + + default: + return QVariant("[ TODO ]"); + } return QVariant("[ERROR]"); @@ -413,10 +469,43 @@ QVariant RsMessageModel::userRole(const Rs::Msgs::MsgInfoSummary& fmpe,int col) QVariant RsMessageModel::decorationRole(const Rs::Msgs::MsgInfoSummary& fmpe,int col) const { + if(col == COLUMN_THREAD_READ) + if(fmpe.msgflags & (RS_MSG_NEW | RS_MSG_UNREAD_BY_USER)) + return QIcon(":/images/message-state-unread.png"); + else + return QIcon(":/images/message-state-read.png"); + + if(col == COLUMN_THREAD_SUBJECT) + { + if(fmpe.msgflags & RS_MSG_NEW ) return QIcon(":/images/message-state-new.png"); + if(fmpe.msgflags & RS_MSG_USER_REQUEST) return QIcon(":/images/user/user_request16.png"); + if(fmpe.msgflags & RS_MSG_FRIEND_RECOMMENDATION) return QIcon(":/images/user/friend_suggestion16.png"); + if(fmpe.msgflags & RS_MSG_PUBLISH_KEY) return QIcon(":/images/share-icon-16.png"); + + if(fmpe.msgflags & RS_MSG_UNREAD_BY_USER) + { + if((fmpe.msgflags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == RS_MSG_REPLIED) return QIcon(":/images/message-mail-replied.png"); + if((fmpe.msgflags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == RS_MSG_FORWARDED) return QIcon(":/images/message-mail-forwarded.png"); + if((fmpe.msgflags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == (RS_MSG_REPLIED | RS_MSG_FORWARDED)) return QIcon(":/images/message-mail-replied-forw.png"); + + return QIcon(":/images/message-mail.png"); + } + if((fmpe.msgflags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == RS_MSG_REPLIED) return QIcon(":/images/message-mail-replied-read.png"); + if((fmpe.msgflags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == RS_MSG_FORWARDED) return QIcon(":/images/message-mail-forwarded-read.png"); + if((fmpe.msgflags & (RS_MSG_REPLIED | RS_MSG_FORWARDED)) == (RS_MSG_REPLIED | RS_MSG_FORWARDED)) return QIcon(":/images/message-mail-replied-forw-read.png"); + + return QIcon(":/images/message-mail-read.png"); + } + + if(col == COLUMN_THREAD_STAR) + return QIcon((fmpe.msgflags & RS_MSG_STAR) ? (IMAGE_STAR_ON ): (IMAGE_STAR_OFF)); + + bool isNew = fmpe.msgflags & (RS_MSG_NEW | RS_MSG_UNREAD_BY_USER); + if(col == COLUMN_THREAD_READ) - return QVariant(IS_MESSAGE_UNREAD(fmpe.msgflags)); - else - return QVariant(); + return QIcon(isNew ? ":/images/message-state-unread.png": ":/images/message-state-read.png"); + + return QVariant(); } void RsMessageModel::clear() @@ -455,11 +544,48 @@ void RsMessageModel::setMessages(const std::list& msgs emit messagesLoaded(); } +void RsMessageModel::setCurrentBox(BoxName bn) +{ + if(mCurrentBox != bn) + { + mCurrentBox = bn; + updateMessages(); + } +} + +void RsMessageModel::getMessageSummaries(BoxName box,std::list& msgs) +{ + rsMsgs->getMessageSummaries(msgs); + + // filter out messages that are not in the right box. + + for(auto it(msgs.begin());it!=msgs.end();) + { + bool ok = false; + + switch(box) + { + case BOX_INBOX : ok = (it->msgflags & RS_MSG_BOXMASK) == RS_MSG_INBOX ; break ; + case BOX_SENT : ok = (it->msgflags & RS_MSG_BOXMASK) == RS_MSG_SENTBOX; break ; + case BOX_OUTBOX : ok = (it->msgflags & RS_MSG_BOXMASK) == RS_MSG_OUTBOX ; break ; + case BOX_DRAFTS : ok = (it->msgflags & RS_MSG_BOXMASK) == RS_MSG_DRAFTBOX ; break ; + case BOX_TRASH : ok = (it->msgflags & RS_MSG_TRASH) ; break ; + default: + continue; + } + + if(ok) + ++it; + else + it = msgs.erase(it) ; + } +} + void RsMessageModel::updateMessages() { - std::list msgs ; + std::list msgs; - rsMsgs->getMessageSummaries(msgs); + getMessageSummaries(mCurrentBox,msgs); setMessages(msgs); } diff --git a/retroshare-gui/src/gui/msgs/MessageModel.h b/retroshare-gui/src/gui/msgs/MessageModel.h index 438a3aa5f..db777612a 100644 --- a/retroshare-gui/src/gui/msgs/MessageModel.h +++ b/retroshare-gui/src/gui/msgs/MessageModel.h @@ -33,34 +33,6 @@ typedef uint32_t ForumModelIndex; -struct ForumModelPostEntry -{ - ForumModelPostEntry() : mPublishTs(0),mMostRecentTsInThread(0),mPostFlags(0),mReputationWarningLevel(0),mMsgStatus(0),prow(0) {} - - enum { // flags for display of posts. To be used in mPostFlags - FLAG_POST_IS_PINNED = 0x0001, - FLAG_POST_IS_MISSING = 0x0002, - FLAG_POST_IS_REDACTED = 0x0004, - FLAG_POST_HAS_UNREAD_CHILDREN = 0x0008, - FLAG_POST_HAS_READ_CHILDREN = 0x0010, - FLAG_POST_PASSES_FILTER = 0x0020, - FLAG_POST_CHILDREN_PASSES_FILTER = 0x0040, - }; - - std::string mTitle ; - RsGxsId mAuthorId ; - RsGxsMessageId mMsgId; - uint32_t mPublishTs; - uint32_t mMostRecentTsInThread; - uint32_t mPostFlags; - int mReputationWarningLevel; - int mMsgStatus; - - std::vector mChildren; - ForumModelIndex mParent; - int prow ; // parent row -}; - // This class is the item model used by Qt to display the information class RsMessageModel : public QAbstractItemModel @@ -71,6 +43,14 @@ public: explicit RsMessageModel(QObject *parent = NULL); ~RsMessageModel(){} + enum Role { + ROLE_SORT = Qt::UserRole, + ROLE_MSGID = Qt::UserRole + 1, + ROLE_SRCID = Qt::UserRole + 2, + ROLE_UNREAD = Qt::UserRole + 3, + ROLE_MSGFLAGS = Qt::UserRole + 4 + }; + enum BoxName { BOX_NONE = 0x00, BOX_INBOX = 0x01, @@ -102,10 +82,11 @@ public: QModelIndex getIndexOfMessage(const std::string &mid) const; static const QString FilterString ; + static void getMessageSummaries(BoxName box,std::list& msgs); // This method will asynchroneously update the data - void setCurrentBox(BoxName bn) {} + void setCurrentBox(BoxName bn) ; void updateMessages(); const RsMessageId& currentMessageId() const; @@ -162,13 +143,9 @@ private: static bool convertMsgIndexToInternalId(uint32_t entry,quintptr& ref); static bool convertInternalIdToMsgIndex(quintptr ref,uint32_t& index); - static void computeReputationLevel(uint32_t forum_sign_flags, ForumModelPostEntry& entry); uint32_t updateFilterStatus(ForumModelIndex i,int column,const QStringList& strings); - static void generateMissingItem(const RsGxsMessageId &msgId,ForumModelPostEntry& entry); - static ForumModelIndex addEntry(std::vector& posts,const ForumModelPostEntry& entry,ForumModelIndex parent); - void setMessages(const std::list& msgs); QColor mTextColorRead ; @@ -177,5 +154,6 @@ private: QColor mTextColorNotSubscribed ; QColor mTextColorMissing ; + BoxName mCurrentBox ; std::vector mMessages; };