From 0570c3fa3864d1e8447bbac68fd608fef6abe236 Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 26 Feb 2019 15:05:00 +0100 Subject: [PATCH] fixed context menu --- retroshare-gui/src/gui/MessagesDialog.cpp | 106 +++++++++---------- retroshare-gui/src/gui/MessagesDialog.h | 2 +- retroshare-gui/src/gui/msgs/MessageModel.cpp | 6 +- 3 files changed, 56 insertions(+), 58 deletions(-) diff --git a/retroshare-gui/src/gui/MessagesDialog.cpp b/retroshare-gui/src/gui/MessagesDialog.cpp index 3c4c6644f..211c9faa2 100644 --- a/retroshare-gui/src/gui/MessagesDialog.cpp +++ b/retroshare-gui/src/gui/MessagesDialog.cpp @@ -541,40 +541,31 @@ int MessagesDialog::getSelectedMessages(QList& mid) return mid.size(); } -int MessagesDialog::getSelectedMsgCount (QList *items, QList *itemsRead, QList *itemsUnread, QList *itemsStar) +int MessagesDialog::getSelectedMsgCount (QList *items, QList *itemsRead, QList *itemsUnread, QList *itemsStar) { -#ifdef TODO + QModelIndexList qmil = ui.messageTreeWidget->selectionModel()->selectedRows(); + if (items) items->clear(); if (itemsRead) itemsRead->clear(); if (itemsUnread) itemsUnread->clear(); if (itemsStar) itemsStar->clear(); - //To check if the selection has more than one row. - QList selectedMessages; - getSelectedMessages(selectedMessages); - - foreach (const QString&, selectedMessages) + foreach(const QModelIndex& m, qmil) { - if (items || itemsRead || itemsUnread || itemsStar) { - if (items) items->append(item); + if (items) + items->append(m); - if (item->data(COLUMN_DATA, ROLE_UNREAD).toBool()) { - if (itemsUnread) itemsUnread->append(item); - } else { - if (itemsRead) itemsRead->append(item); - } + if (m.data(RsMessageModel::UnreadRole).toBool()) + if (itemsUnread) + itemsUnread->append(m); + else if(itemsRead) + itemsRead->append(m); - if (itemsStar) { - if (item->data(COLUMN_DATA, ROLE_MSGFLAGS).toInt() & RS_MSG_STAR) { - itemsStar->append(item); - } - } - } + if (itemsStar && m.data(RsMessageModel::MsgFlagsRole).toInt() & RS_MSG_STAR) + itemsStar->append(m); } - return selectedItems.size(); -#endif - return 0; + return qmil.size(); } bool MessagesDialog::isMessageRead(const QModelIndex& index) @@ -608,9 +599,10 @@ void MessagesDialog::messageTreeWidgetCustomPopupMenu(QPoint /*point*/) if(!rsMail->getMessage(mid, msgInfo)) return ; - QList itemsRead; - QList itemsUnread; - QList itemsStar; + QList itemsRead; + QList itemsUnread; + QList itemsStar; + int nCount = getSelectedMsgCount (NULL, &itemsRead, &itemsUnread, &itemsStar); /** Defines the actions for the context menu */ @@ -1438,47 +1430,51 @@ void MessagesDialog::updateCurrentMessage() { } -void MessagesDialog::setMsgAsReadUnread(const QList &items, bool read) -{ - LockUpdate Lock (this, false); - - foreach (QTreeWidgetItem *item, items) { - std::string mid = item->data(COLUMN_DATA, RsMessageModel::MsgIdRole).toString().toStdString(); - - if (rsMail->MessageRead(mid, !read)) { - int msgFlag = item->data(COLUMN_DATA, RsMessageModel::MsgFlagsRole).toInt(); - msgFlag &= ~RS_MSG_NEW; - - if (read) { - msgFlag &= ~RS_MSG_UNREAD_BY_USER; - } else { - msgFlag |= RS_MSG_UNREAD_BY_USER; - } - - item->setData(COLUMN_DATA, RsMessageModel::MsgFlagsRole, msgFlag); - - InitIconAndFont(item); - } - } - - // LockUpdate -} +// void MessagesDialog::setMsgAsReadUnread(const QList &items, bool read) +// { +// LockUpdate Lock (this, false); +// +// foreach (QTreeWidgetItem *item, items) { +// std::string mid = item->data(COLUMN_DATA, RsMessageModel::MsgIdRole).toString().toStdString(); +// +// if (rsMail->MessageRead(mid, !read)) { +// int msgFlag = item->data(COLUMN_DATA, RsMessageModel::MsgFlagsRole).toInt(); +// msgFlag &= ~RS_MSG_NEW; +// +// if (read) { +// msgFlag &= ~RS_MSG_UNREAD_BY_USER; +// } else { +// msgFlag |= RS_MSG_UNREAD_BY_USER; +// } +// +// item->setData(COLUMN_DATA, RsMessageModel::MsgFlagsRole, msgFlag); +// +// InitIconAndFont(item); +// } +// } +// +// // LockUpdate +// } void MessagesDialog::markAsRead() { - QList itemsUnread; + QList itemsUnread; getSelectedMsgCount (NULL, NULL, &itemsUnread, NULL); - setMsgAsReadUnread (itemsUnread, true); + foreach(const QModelIndex& index,itemsUnread) + mMessageModel->setMsgReadStatus(index,true); + updateMessageSummaryList(); } void MessagesDialog::markAsUnread() { - QList itemsRead; + QList itemsRead; getSelectedMsgCount (NULL, &itemsRead, NULL, NULL); - setMsgAsReadUnread (itemsRead, false); + foreach(const QModelIndex& index,itemsRead) + mMessageModel->setMsgReadStatus(index,false); + updateMessageSummaryList(); } diff --git a/retroshare-gui/src/gui/MessagesDialog.h b/retroshare-gui/src/gui/MessagesDialog.h index d178f77c1..1926c23dc 100644 --- a/retroshare-gui/src/gui/MessagesDialog.h +++ b/retroshare-gui/src/gui/MessagesDialog.h @@ -130,7 +130,7 @@ private: bool getCurrentMsg(std::string &cid, std::string &mid); void setMsgAsReadUnread(const QList &items, bool read); - int getSelectedMsgCount (QList *items, QList *itemsRead, QList *itemsUnread, QList *itemsStar); + int getSelectedMsgCount (QList *items, QList *itemsRead, QList *itemsUnread, QList *itemsStar); bool isMessageRead(const QModelIndex &index); bool hasMessageStar(const QModelIndex &index); diff --git a/retroshare-gui/src/gui/msgs/MessageModel.cpp b/retroshare-gui/src/gui/msgs/MessageModel.cpp index f85503dbc..cd32dd05a 100644 --- a/retroshare-gui/src/gui/msgs/MessageModel.cpp +++ b/retroshare-gui/src/gui/msgs/MessageModel.cpp @@ -652,14 +652,16 @@ void RsMessageModel::setMsgReadStatus(const QModelIndex& i,bool read_status) preMods(); rsMsgs->MessageRead(i.data(MsgIdRole).toString().toStdString(),!read_status); - postMods(); + + emit dataChanged(i.sibling(i.row(),0),i.sibling(i.row(),COLUMN_THREAD_NB_COLUMNS-1)); } void RsMessageModel::setMsgStar(const QModelIndex& i,bool star) { preMods(); rsMsgs->MessageStar(i.data(MsgIdRole).toString().toStdString(),star); - postMods(); + + emit dataChanged(i.sibling(i.row(),0),i.sibling(i.row(),COLUMN_THREAD_NB_COLUMNS-1)); } QModelIndex RsMessageModel::getIndexOfMessage(const std::string& mid) const