mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-01-15 09:27:09 -05:00
bugfix in MessageDialog, rs could crash when removing two or more messages at once
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3057 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
5264f46f9e
commit
08ea7232f7
@ -156,6 +156,23 @@ protected:
|
||||
}
|
||||
};
|
||||
|
||||
MessagesDialog::LockUpdate::LockUpdate (MessagesDialog *pDialog, bool bUpdate)
|
||||
{
|
||||
m_pDialog = pDialog;
|
||||
m_bUpdate = bUpdate;
|
||||
|
||||
m_pDialog->m_nLockUpdate++;
|
||||
}
|
||||
|
||||
MessagesDialog::LockUpdate::~LockUpdate ()
|
||||
{
|
||||
m_pDialog->m_nLockUpdate = qMax (--m_pDialog->m_nLockUpdate, 0);
|
||||
|
||||
if (m_bUpdate && m_pDialog->m_nLockUpdate == 0) {
|
||||
m_pDialog->insertMessages();
|
||||
}
|
||||
}
|
||||
|
||||
static int FilterColumnFromComboBox(int nIndex)
|
||||
{
|
||||
switch (nIndex) {
|
||||
@ -205,6 +222,7 @@ MessagesDialog::MessagesDialog(QWidget *parent)
|
||||
|
||||
m_bProcessSettings = false;
|
||||
m_bInChange = false;
|
||||
m_nLockUpdate = 0;
|
||||
m_pConfig = new RSettings (CONFIG_FILE);
|
||||
|
||||
connect( ui.messagestreeView, SIGNAL( customContextMenuRequested( QPoint ) ), this, SLOT( messageslistWidgetCostumPopupMenu( QPoint ) ) );
|
||||
@ -1216,6 +1234,10 @@ static void InitIconAndFont(RSettings *pConfig, QStandardItem *pItem [COLUMN_COU
|
||||
|
||||
void MessagesDialog::insertMessages()
|
||||
{
|
||||
if (m_nLockUpdate) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::cerr <<"MessagesDialog::insertMessages called";
|
||||
fflush(0);
|
||||
|
||||
@ -1914,6 +1936,8 @@ bool MessagesDialog::getCurrentMsg(std::string &cid, std::string &mid)
|
||||
|
||||
void MessagesDialog::removemessage()
|
||||
{
|
||||
LockUpdate Lock (this, true);
|
||||
|
||||
QList<QModelIndex> selectedIndexList= ui.messagestreeView->selectionModel() -> selectedIndexes ();
|
||||
QList<int> rowList;
|
||||
QModelIndex selectedIndex;
|
||||
@ -1928,7 +1952,7 @@ void MessagesDialog::removemessage()
|
||||
}
|
||||
|
||||
bool bDelete = false;
|
||||
int listrow = ui.listWidget -> currentRow();
|
||||
int listrow = ui.listWidget->currentRow();
|
||||
if (listrow == ROW_TRASHBOX) {
|
||||
bDelete = true;
|
||||
} else {
|
||||
@ -1937,8 +1961,10 @@ void MessagesDialog::removemessage()
|
||||
}
|
||||
}
|
||||
|
||||
for(QList<int>::const_iterator it1(rowList.begin());it1!=rowList.end();++it1) {
|
||||
QString mid = MessagesModel->item((*it1),COLUMN_MSGID)->text();
|
||||
for(QList<int>::const_iterator it1 = rowList.begin(); it1 != rowList.end(); it1++) {
|
||||
QStandardItem *pItem = MessagesModel->item((*it1), COLUMN_MSGID);
|
||||
if (pItem) {
|
||||
QString mid = pItem->text();
|
||||
if (bDelete) {
|
||||
rsMsgs->MessageDelete(mid.toStdString());
|
||||
|
||||
@ -1955,12 +1981,15 @@ void MessagesDialog::removemessage()
|
||||
rsMsgs->MessageToTrash(mid.toStdString(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
insertMessages();
|
||||
// LockUpdate -> insertMessages();
|
||||
}
|
||||
|
||||
void MessagesDialog::undeletemessage()
|
||||
{
|
||||
LockUpdate (this, true);
|
||||
|
||||
QList<int> Rows;
|
||||
getSelectedMsgCount (&Rows, NULL, NULL);
|
||||
for (int nRow = 0; nRow < Rows.size(); nRow++) {
|
||||
@ -1968,7 +1997,7 @@ void MessagesDialog::undeletemessage()
|
||||
rsMsgs->MessageToTrash(mid.toStdString(), false);
|
||||
}
|
||||
|
||||
insertMessages();
|
||||
// LockUpdate -> insertMessages();
|
||||
}
|
||||
|
||||
void MessagesDialog::print()
|
||||
|
@ -123,6 +123,17 @@ private slots:
|
||||
#endif
|
||||
|
||||
private:
|
||||
class LockUpdate
|
||||
{
|
||||
public:
|
||||
LockUpdate (MessagesDialog *pDialog, bool bUpdate);
|
||||
~LockUpdate ();
|
||||
|
||||
private:
|
||||
MessagesDialog *m_pDialog;
|
||||
bool m_bUpdate;
|
||||
};
|
||||
|
||||
class QStandardItemModel *MessagesModel;
|
||||
QSortFilterProxyModel *proxyModel;
|
||||
|
||||
@ -147,6 +158,7 @@ private:
|
||||
#endif
|
||||
bool m_bProcessSettings;
|
||||
bool m_bInChange;
|
||||
int m_nLockUpdate; // use with LockUpdate
|
||||
|
||||
enum { LIST_NOTHING,
|
||||
LIST_BOX,
|
||||
|
Loading…
Reference in New Issue
Block a user