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;
}
bool MessagesDialog::isMessageRead(QTreeWidgetItem *item)
bool MessagesDialog::isMessageRead(const QModelIndex& index)
{
if (!item) {
if (!index.isValid())
return true;
}
return !item->data(COLUMN_DATA, RsMessageModel::UnreadRole).toBool();
return !index.data(RsMessageModel::UnreadRole).toBool();
}
bool MessagesDialog::hasMessageStar(QTreeWidgetItem *item)
bool MessagesDialog::hasMessageStar(const QModelIndex& index)
{
if (!item) {
if (!index.isValid())
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*/)
@ -1378,25 +1376,21 @@ void MessagesDialog::clicked(const QModelIndex& index)
if(!index.isValid())
return;
// switch (index.column())
// {
// case COLUMN_UNREAD:
// {
// QList<QModelIndex> items;
// items.append(item);
// setMsgAsReadUnread(items, !isMessageRead(item));
// insertMsgTxtAndFiles(item, false);
// updateMessageSummaryList();
// return;
// }
// case COLUMN_STAR:
// {
// QList<QTreeWidgetItem*> items;
// items.append(item);
// setMsgStar(items, !hasMessageStar(item));
// return;
// }
// }
switch (index.column())
{
case COLUMN_UNREAD:
{
mMessageModel->setMsgReadStatus(index, !isMessageRead(index));
insertMsgTxtAndFiles(index);
updateMessageSummaryList();
return;
}
case COLUMN_STAR:
{
mMessageModel->setMsgStar(index, !hasMessageStar(index));
return;
}
}
#ifdef TODO
timer->stop();
timerIndex = ui.messageTreeWidget->indexOfTopLevelItem(item);
@ -1490,39 +1484,13 @@ void MessagesDialog::markAsUnread()
void MessagesDialog::markWithStar(bool checked)
{
QList<QTreeWidgetItem*> items;
getSelectedMsgCount (&items, NULL, NULL, NULL);
QModelIndexList lst = ui.messageTreeWidget->selectionModel()->selectedRows();
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)
{

View File

@ -129,11 +129,10 @@ private:
bool getCurrentMsg(std::string &cid, std::string &mid);
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);
bool isMessageRead(QTreeWidgetItem *item);
bool hasMessageStar(QTreeWidgetItem *item);
bool isMessageRead(const QModelIndex &index);
bool hasMessageStar(const QModelIndex &index);
void processSettings(bool load);

View File

@ -58,7 +58,7 @@ void RsMessageModel::preMods()
}
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)
@ -651,15 +651,14 @@ void RsMessageModel::setMsgReadStatus(const QModelIndex& i,bool read_status)
return ;
preMods();
rsMsgs->MessageRead(i.data(MsgIdRole).toString().toStdString(),!read_status);
postMods();
}
quintptr ref = i.internalId();
uint32_t index = 0;
if(!convertInternalIdToMsgIndex(ref,index) || index >= mMessages.size())
return ;
rsMsgs->MessageRead(mMessages[index].msgId,!read_status);
void RsMessageModel::setMsgStar(const QModelIndex& i,bool star)
{
preMods();
rsMsgs->MessageStar(i.data(MsgIdRole).toString().toStdString(),star);
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;
}

View File

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