Fix Message Delete Button.

Now, frame is cleared and next message selected.
This commit is contained in:
Phenom 2020-04-14 14:29:37 +02:00
parent b6c5e2f188
commit 2dc2b3598d
6 changed files with 93 additions and 24 deletions

View File

@ -132,6 +132,7 @@ MessageWidget::MessageWidget(bool controlled, QWidget *parent, Qt::WindowFlags f
isControlled = controlled; isControlled = controlled;
isWindow = false; isWindow = false;
currMsgFlags = 0; currMsgFlags = 0;
expandFiles = false;
ui.actionTextBesideIcon->setData(Qt::ToolButtonTextBesideIcon); ui.actionTextBesideIcon->setData(Qt::ToolButtonTextBesideIcon);
ui.actionIconOnly->setData(Qt::ToolButtonIconOnly); ui.actionIconOnly->setData(Qt::ToolButtonIconOnly);
@ -281,10 +282,7 @@ void MessageWidget::processSettings(const QString &settingsGroup, bool load)
// load settings // load settings
// expandFiles // expandFiles
bool value = Settings->value("expandFiles", false).toBool(); expandFiles = Settings->value("expandFiles", false).toBool();
ui.expandFilesButton->setChecked(value);
ui.msgList->setVisible(value);
togglefileview();
// toolbar button style // toolbar button style
Qt::ToolButtonStyle style = (Qt::ToolButtonStyle) Settings->value("ToolButon_Style", Qt::ToolButtonTextBesideIcon).toInt(); Qt::ToolButtonStyle style = (Qt::ToolButtonStyle) Settings->value("ToolButon_Style", Qt::ToolButtonTextBesideIcon).toInt();
@ -293,7 +291,7 @@ void MessageWidget::processSettings(const QString &settingsGroup, bool load)
// save settings // save settings
// expandFiles // expandFiles
Settings->setValue("expandFiles", ui.expandFilesButton->isChecked()); Settings->setValue("expandFiles", expandFiles);
//toolbar button style //toolbar button style
Settings->setValue("ToolButon_Style", ui.replyButton->toolButtonStyle()); Settings->setValue("ToolButon_Style", ui.replyButton->toolButtonStyle());
@ -322,7 +320,7 @@ void MessageWidget::msgfilelistWidgetCostumPopupMenu( QPoint /*point*/ )
contextMnu.exec(QCursor::pos()); contextMnu.exec(QCursor::pos());
} }
void MessageWidget::togglefileview() void MessageWidget::togglefileview(bool noUpdate/*=false*/)
{ {
/* if msg header visible -> change icon and tooltip /* if msg header visible -> change icon and tooltip
* three widgets... * three widgets...
@ -335,6 +333,10 @@ void MessageWidget::togglefileview()
ui.expandFilesButton->setIcon(QIcon(QString(":/icons/png/up-arrow.png"))); ui.expandFilesButton->setIcon(QIcon(QString(":/icons/png/up-arrow.png")));
ui.expandFilesButton->setToolTip(tr("Show the attachment pane")); ui.expandFilesButton->setToolTip(tr("Show the attachment pane"));
} }
if (!noUpdate)
expandFiles = ui.expandFilesButton->isChecked();
ui.msgList->setVisible(ui.expandFilesButton->isChecked());
} }
/* download the recommendations... */ /* download the recommendations... */
@ -426,13 +428,10 @@ void MessageWidget::messagesChanged()
void MessageWidget::clearTagLabels() void MessageWidget::clearTagLabels()
{ {
/* clear all tags */ /* clear all tags */
while (tagLabels.size()) { qDeleteAll(tagLabels);
delete tagLabels.front(); tagLabels.clear();
tagLabels.pop_front();
} misc::clearLayout(ui.tagLayout);
while (ui.tagLayout->count()) {
delete ui.tagLayout->takeAt(0);
}
ui.tagsLabel->setVisible(false); ui.tagsLabel->setVisible(false);
} }
@ -510,6 +509,16 @@ void MessageWidget::fill(const std::string &msgId)
clearTagLabels(); clearTagLabels();
ui.inviteFrame->hide();
ui.expandFilesButton->setChecked(false);
togglefileview(true);
ui.replyButton->setEnabled(false);
ui.replyallButton->setEnabled(false);
ui.forwardButton->setEnabled(false);
ui.deleteButton->setEnabled(false);
ui.moreButton->setEnabled(false);
currMsgFlags = 0; currMsgFlags = 0;
return; return;
@ -517,6 +526,13 @@ void MessageWidget::fill(const std::string &msgId)
clearTagLabels(); clearTagLabels();
ui.replyButton->setEnabled(true);
ui.replyallButton->setEnabled(true);
ui.forwardButton->setEnabled(true);
ui.deleteButton->setEnabled(true);
ui.moreButton->setEnabled(true);
MessageInfo msgInfo; MessageInfo msgInfo;
if (rsMail->getMessage(currMsgId, msgInfo) == false) { if (rsMail->getMessage(currMsgId, msgInfo) == false) {
std::cerr << "MessageWidget::fill() Couldn't find Msg" << std::endl; std::cerr << "MessageWidget::fill() Couldn't find Msg" << std::endl;
@ -549,6 +565,8 @@ void MessageWidget::fill(const std::string &msgId)
/* add the items in! */ /* add the items in! */
ui.msgList->insertTopLevelItems(0, items); ui.msgList->insertTopLevelItems(0, items);
ui.expandFilesButton->setChecked(expandFiles && (items.count()>0) );
togglefileview(true);
/* iterate through the sources */ /* iterate through the sources */
RetroShareLink link; RetroShareLink link;
@ -688,8 +706,15 @@ void MessageWidget::remove()
if (isWindow) { if (isWindow) {
window()->close(); window()->close();
} else { } else {
deleteLater(); if (isControlled) {
currMsgId.clear();
fill(currMsgId);
} else {
deleteLater();
}
} }
emit messageRemoved();
} }
void MessageWidget::print() void MessageWidget::print()

View File

@ -58,6 +58,8 @@ public:
QString subject(bool noEmpty); QString subject(bool noEmpty);
signals:
void messageRemoved();
private slots: private slots:
void reply(); void reply();
@ -75,7 +77,7 @@ private slots:
void messagesTagsChanged(); void messagesTagsChanged();
void messagesChanged(); void messagesChanged();
void togglefileview(); void togglefileview(bool noUpdate = false);
void getcurrentrecommended(); void getcurrentrecommended();
void getallrecommended(); void getallrecommended();
@ -94,6 +96,7 @@ private:
bool isWindow; bool isWindow;
std::string currMsgId; std::string currMsgId;
unsigned int currMsgFlags; unsigned int currMsgFlags;
bool expandFiles;
QList<QLabel*> tagLabels; QList<QLabel*> tagLabels;

View File

@ -124,9 +124,11 @@ MessagesDialog::MessagesDialog(QWidget *parent)
inProcessSettings = false; inProcessSettings = false;
inChange = false; inChange = false;
lockUpdate = 0; lockUpdate = 0;
lastSelectedIndex = QModelIndex();
msgWidget = new MessageWidget(true, this); msgWidget = new MessageWidget(true, this);
ui.msgLayout->addWidget(msgWidget); ui.msgLayout->addWidget(msgWidget);
connect(msgWidget, SIGNAL(messageRemoved()), this, SLOT(messageRemoved()));
connectActions(); connectActions();
@ -695,6 +697,7 @@ void MessagesDialog::openAsWindow()
} }
msgWidget->activateWindow(); msgWidget->activateWindow();
connect(msgWidget, SIGNAL(messageRemoved()), this, SLOT(messageRemoved()));
/* window will destroy itself! */ /* window will destroy itself! */
} }
@ -714,6 +717,7 @@ void MessagesDialog::openAsTab()
ui.tabWidget->addTab(msgWidget, msgWidget->subject(true)); ui.tabWidget->addTab(msgWidget, msgWidget->subject(true));
ui.tabWidget->setCurrentWidget(msgWidget); ui.tabWidget->setCurrentWidget(msgWidget);
connect(msgWidget, SIGNAL(messageRemoved()), this, SLOT(messageRemoved()));
/* window will destroy itself! */ /* window will destroy itself! */
} }
@ -860,7 +864,8 @@ void MessagesDialog::clicked(const QModelIndex& proxy_index)
case RsMessageModel::COLUMN_THREAD_READ: case RsMessageModel::COLUMN_THREAD_READ:
{ {
mMessageModel->setMsgReadStatus(real_index, !isMessageRead(proxy_index)); mMessageModel->setMsgReadStatus(real_index, !isMessageRead(proxy_index));
insertMsgTxtAndFiles(proxy_index); //Already updated by currentChanged
//insertMsgTxtAndFiles(proxy_index);
updateMessageSummaryList(); updateMessageSummaryList();
return; return;
} }
@ -871,8 +876,9 @@ void MessagesDialog::clicked(const QModelIndex& proxy_index)
} }
} }
// show current message directly // show current message directly
insertMsgTxtAndFiles(proxy_index); //Already updated by currentChanged
//insertMsgTxtAndFiles(proxy_index);
} }
// double click in messageTreeWidget // double click in messageTreeWidget
@ -953,14 +959,20 @@ void MessagesDialog::insertMsgTxtAndFiles(const QModelIndex& proxy_index)
QModelIndex real_index = mMessageProxyModel->mapToSource(proxy_index); QModelIndex real_index = mMessageProxyModel->mapToSource(proxy_index);
if(!real_index.isValid()) if(!real_index.isValid())
{ {
mCurrMsgId.clear(); mCurrMsgId.clear();
msgWidget->fill(mCurrMsgId); msgWidget->fill(mCurrMsgId);
updateInterface(); updateInterface();
lastSelectedIndex = QModelIndex();
return; return;
} }
mid = real_index.data(RsMessageModel::MsgIdRole).toString().toStdString();
lastSelectedIndex = proxy_index;
if (!ui.messageTreeWidget->indexBelow(proxy_index).isValid())
lastSelectedIndex = ui.messageTreeWidget->indexAbove(proxy_index);
mid = real_index.data(RsMessageModel::MsgIdRole).toString().toStdString();
/* Save the Data.... for later */ /* Save the Data.... for later */
@ -1025,6 +1037,12 @@ void MessagesDialog::removemessage()
mMessageModel->updateMessages(); mMessageModel->updateMessages();
updateMessageSummaryList(); updateMessageSummaryList();
messageRemoved();
}
void MessagesDialog::messageRemoved()
{
ui.messageTreeWidget->setCurrentIndex(lastSelectedIndex);
} }
void MessagesDialog::undeletemessage() void MessagesDialog::undeletemessage()

View File

@ -57,10 +57,6 @@ public:
void setTextColorInbox(QColor color) { mTextColorInbox = color; } void setTextColorInbox(QColor color) { mTextColorInbox = color; }
signals:
void messagesAboutToLoad();
void messagesLoaded();
protected: protected:
virtual UserNotify *createUserNotify(QObject *parent) override; virtual UserNotify *createUserNotify(QObject *parent) override;
bool eventFilter(QObject *obj, QEvent *ev); bool eventFilter(QObject *obj, QEvent *ev);
@ -69,6 +65,7 @@ protected:
public slots: public slots:
//void insertMessages(); //void insertMessages();
void messagesTagsChanged(); void messagesTagsChanged();
void messageRemoved();
void preModelUpdate(); void preModelUpdate();
void postModelUpdate(); void postModelUpdate();
@ -156,6 +153,7 @@ private:
Ui::MessagesDialog ui; Ui::MessagesDialog ui;
QList<QString> mTmpSavedSelectedIds; QList<QString> mTmpSavedSelectedIds;
QModelIndex lastSelectedIndex;
}; };
#endif #endif

View File

@ -405,3 +405,23 @@ QString misc::getExistingDirectory(QWidget *parent, const QString &caption, cons
return QFileDialog::getExistingDirectory(parent, caption, dir, QFileDialog::DontUseNativeDialog | QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); return QFileDialog::getExistingDirectory(parent, caption, dir, QFileDialog::DontUseNativeDialog | QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
#endif #endif
} }
/*!
* Clear a Layout content
* \param layout: Layout to Clear
*/
void misc::clearLayout(QLayout * layout) {
if (! layout)
return;
while (auto item = layout->takeAt(0))
{
if (auto *widget = item->widget())
widget->deleteLater();
if (auto *spacer = item->spacerItem())
delete spacer;
clearLayout(item->layout());
delete item;
}
}

View File

@ -27,6 +27,7 @@
#include <QPair> #include <QPair>
#include <QThread> #include <QThread>
#include <QFileDialog> #include <QFileDialog>
#include <QLayout>
#include "gui/settings/rsharesettings.h" #include "gui/settings/rsharesettings.h"
@ -182,6 +183,10 @@ class misc : public QObject
static QString getExistingDirectory(QWidget *parent = nullptr static QString getExistingDirectory(QWidget *parent = nullptr
, const QString &caption = QString() , const QString &caption = QString()
, const QString &dir = QString()); , const QString &dir = QString());
//Clear QLayout
static void clearLayout(QLayout *layout);
}; };
// Trick to get a portable sleep() function // Trick to get a portable sleep() function