fixed toggling read/unread and star status

This commit is contained in:
csoler 2019-02-26 14:45:48 +01:00
parent 875d0a15da
commit 5cbff98e40
No known key found for this signature in database
GPG key ID: 7BCA522266C0804C
4 changed files with 39 additions and 69 deletions

View file

@ -577,22 +577,20 @@ int MessagesDialog::getSelectedMsgCount (QList<QTreeWidgetItem*> *items, QList<Q
return 0; return 0;
} }
bool MessagesDialog::isMessageRead(QTreeWidgetItem *item) bool MessagesDialog::isMessageRead(const QModelIndex& index)
{ {
if (!item) { if (!index.isValid())
return true; return true;
return !index.data(RsMessageModel::UnreadRole).toBool();
} }
return !item->data(COLUMN_DATA, RsMessageModel::UnreadRole).toBool(); bool MessagesDialog::hasMessageStar(const QModelIndex& index)
}
bool MessagesDialog::hasMessageStar(QTreeWidgetItem *item)
{ {
if (!item) { if (!index.isValid())
return false; return false;
}
return item->data(COLUMN_DATA, RsMessageModel::MsgFlagsRole).toInt() & RS_MSG_STAR; return index.data(RsMessageModel::MsgFlagsRole).toInt() & RS_MSG_STAR;
} }
void MessagesDialog::messageTreeWidgetCustomPopupMenu(QPoint /*point*/) void MessagesDialog::messageTreeWidgetCustomPopupMenu(QPoint /*point*/)
@ -1378,25 +1376,21 @@ void MessagesDialog::clicked(const QModelIndex& index)
if(!index.isValid()) if(!index.isValid())
return; return;
// switch (index.column()) switch (index.column())
// { {
// case COLUMN_UNREAD: case COLUMN_UNREAD:
// { {
// QList<QModelIndex> items; mMessageModel->setMsgReadStatus(index, !isMessageRead(index));
// items.append(item); insertMsgTxtAndFiles(index);
// setMsgAsReadUnread(items, !isMessageRead(item)); updateMessageSummaryList();
// insertMsgTxtAndFiles(item, false); return;
// updateMessageSummaryList(); }
// return; case COLUMN_STAR:
// } {
// case COLUMN_STAR: mMessageModel->setMsgStar(index, !hasMessageStar(index));
// { return;
// QList<QTreeWidgetItem*> items; }
// items.append(item); }
// setMsgStar(items, !hasMessageStar(item));
// return;
// }
// }
#ifdef TODO #ifdef TODO
timer->stop(); timer->stop();
timerIndex = ui.messageTreeWidget->indexOfTopLevelItem(item); timerIndex = ui.messageTreeWidget->indexOfTopLevelItem(item);
@ -1490,39 +1484,13 @@ void MessagesDialog::markAsUnread()
void MessagesDialog::markWithStar(bool checked) void MessagesDialog::markWithStar(bool checked)
{ {
QList<QTreeWidgetItem*> items; QModelIndexList lst = ui.messageTreeWidget->selectionModel()->selectedRows();
getSelectedMsgCount (&items, NULL, NULL, NULL);
setMsgStar(items, checked); foreach(const QModelIndex& index,lst)
mMessageModel->setMsgStar(index, checked);
} }
void MessagesDialog::setMsgStar(const QList<QTreeWidgetItem*> &items, bool star)
{
LockUpdate Lock (this, false);
foreach (QTreeWidgetItem *item, items) {
std::string mid = item->data(COLUMN_DATA, RsMessageModel::MsgIdRole).toString().toStdString();
if (rsMail->MessageStar(mid, star)) {
int msgFlag = item->data(COLUMN_DATA, RsMessageModel::MsgFlagsRole).toInt();
msgFlag &= ~RS_MSG_STAR;
if (star) {
msgFlag |= RS_MSG_STAR;
} else {
msgFlag &= ~RS_MSG_STAR;
}
item->setData(COLUMN_DATA, RsMessageModel::MsgFlagsRole, msgFlag);
InitIconAndFont(item);
Lock.setUpdate(true);
}
}
// LockUpdate
}
void MessagesDialog::insertMsgTxtAndFiles(const QModelIndex& index) void MessagesDialog::insertMsgTxtAndFiles(const QModelIndex& index)
{ {

View file

@ -129,11 +129,10 @@ private:
bool getCurrentMsg(std::string &cid, std::string &mid); bool getCurrentMsg(std::string &cid, std::string &mid);
void setMsgAsReadUnread(const QList<QTreeWidgetItem *> &items, bool read); void setMsgAsReadUnread(const QList<QTreeWidgetItem *> &items, bool read);
void setMsgStar(const QList<QTreeWidgetItem *> &items, bool mark);
int getSelectedMsgCount (QList<QTreeWidgetItem *> *items, QList<QTreeWidgetItem *> *itemsRead, QList<QTreeWidgetItem *> *itemsUnread, QList<QTreeWidgetItem *> *itemsStar); int getSelectedMsgCount (QList<QTreeWidgetItem *> *items, QList<QTreeWidgetItem *> *itemsRead, QList<QTreeWidgetItem *> *itemsUnread, QList<QTreeWidgetItem *> *itemsStar);
bool isMessageRead(QTreeWidgetItem *item); bool isMessageRead(const QModelIndex &index);
bool hasMessageStar(QTreeWidgetItem *item); bool hasMessageStar(const QModelIndex &index);
void processSettings(bool load); void processSettings(bool load);

View file

@ -58,7 +58,7 @@ void RsMessageModel::preMods()
} }
void RsMessageModel::postMods() void RsMessageModel::postMods()
{ {
emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(0,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL)); emit dataChanged(createIndex(0,0,(void*)NULL), createIndex(mMessages.size()-1,COLUMN_THREAD_NB_COLUMNS-1,(void*)NULL));
} }
// void RsGxsForumModel::setSortMode(SortMode mode) // void RsGxsForumModel::setSortMode(SortMode mode)
@ -651,15 +651,14 @@ void RsMessageModel::setMsgReadStatus(const QModelIndex& i,bool read_status)
return ; return ;
preMods(); preMods();
rsMsgs->MessageRead(i.data(MsgIdRole).toString().toStdString(),!read_status);
postMods();
}
quintptr ref = i.internalId(); void RsMessageModel::setMsgStar(const QModelIndex& i,bool star)
uint32_t index = 0; {
preMods();
if(!convertInternalIdToMsgIndex(ref,index) || index >= mMessages.size()) rsMsgs->MessageStar(i.data(MsgIdRole).toString().toStdString(),star);
return ;
rsMsgs->MessageRead(mMessages[index].msgId,!read_status);
postMods(); postMods();
} }
@ -685,3 +684,4 @@ void RsMessageModel::debug_dump() const
std::cerr << "Id: " << it->msgId << ": from " << it->srcId << ": flags=" << it->msgflags << ": title=\"" << it->title << "\"" << std::endl; std::cerr << "Id: " << it->msgId << ": from " << it->srcId << ": flags=" << it->msgflags << ": title=\"" << it->title << "\"" << std::endl;
} }

View file

@ -85,7 +85,6 @@ public:
void updateMessages(); void updateMessages();
const RsMessageId& currentMessageId() const; const RsMessageId& currentMessageId() const;
void setMsgReadStatus(const QModelIndex& i, bool read_status);
void setFilter(int column, const QStringList& strings, uint32_t &count) ; void setFilter(int column, const QStringList& strings, uint32_t &count) ;
int rowCount(const QModelIndex& parent = QModelIndex()) const override; int rowCount(const QModelIndex& parent = QModelIndex()) const override;
@ -122,6 +121,10 @@ public:
*/ */
void debug_dump() const; void debug_dump() const;
// 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) ;
signals: signals:
void messagesLoaded(); // emitted after the messages have been set. Can be used to updated the UI. void messagesLoaded(); // emitted after the messages have been set. Can be used to updated the UI.