Merge pull request #2684 from csoler/v0.6-BugFixing_25

fixed crash when canceling DL from channel files list
This commit is contained in:
csoler 2023-02-18 20:48:07 +01:00 committed by GitHub
commit 01c63a6d41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 56 additions and 21 deletions

View File

@ -33,8 +33,8 @@
#include "retroshare/rsfiles.h"
GxsChannelFilesStatusWidget::GxsChannelFilesStatusWidget(const RsGxsFile &file, QWidget *parent) :
QWidget(parent), mFile(file), ui(new Ui::GxsChannelFilesStatusWidget)
GxsChannelFilesStatusWidget::GxsChannelFilesStatusWidget(const RsGxsFile &file, QWidget *parent,bool used_as_editor) :
QWidget(parent), mFile(file), mUsedAsEditor(used_as_editor),ui(new Ui::GxsChannelFilesStatusWidget)
{
ui->setupUi(this);
@ -46,7 +46,7 @@ GxsChannelFilesStatusWidget::GxsChannelFilesStatusWidget(const RsGxsFile &file,
connect(ui->downloadPushButton, SIGNAL(clicked()), this, SLOT(download()));
connect(ui->resumeToolButton, SIGNAL(clicked()), this, SLOT(resume()));
connect(ui->pauseToolButton, SIGNAL(clicked()), this, SLOT(pause()));
connect(ui->cancelToolButton, SIGNAL(clicked()), this, SLOT(cancel()));
connect(ui->cancelToolButton, SIGNAL(clicked()), this, SLOT(cancel()));
connect(ui->openFilePushButton, SIGNAL(clicked()), this, SLOT(openFile()));
ui->downloadPushButton->setIcon(FilesDefs::getIconFromQtResourcePath(":/icons/png/download.png"));
@ -306,14 +306,19 @@ void GxsChannelFilesStatusWidget::resume()
void GxsChannelFilesStatusWidget::cancel()
{
if ((QMessageBox::question(this, "", tr("Are you sure that you want to cancel and delete the file?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No)) == QMessageBox::No) {
return;
}
// When QMessgeBox asks for cancel confirmtion, this makes the widget lose focus => since it is an editor widget,
// it gets destroyed by the parent list widget => subsequent code after the QMessageBox runs over a deleted object => crash
// In summary: no QMessageBox here when the Status widget is used as an editor.
if(!mUsedAsEditor)
if ((QMessageBox::question(this, "", tr("Are you sure that you want to cancel and delete the file?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No)) == QMessageBox::No) {
return;
}
rsFiles->FileCancel(mFile.mHash);
emit onButtonClick();// Signals the parent widget to e.g. update the downloadable file count
check();
check();
}
void GxsChannelFilesStatusWidget::openFolder()
@ -327,8 +332,12 @@ void GxsChannelFilesStatusWidget::openFolder()
QDir dir = QFileInfo(QString::fromUtf8(fileInfo.path.c_str())).absoluteDir();
if (dir.exists()) {
if (!RsUrlHandler::openUrl(QUrl::fromLocalFile(dir.absolutePath()))) {
QMessageBox::warning(this, "", QString("%1 %2").arg(tr("Can't open folder"), dir.absolutePath()));
}
if(!mUsedAsEditor)
QMessageBox::warning(this, "", QString("%1 %2").arg(tr("Can't open folder"), dir.absolutePath()));
else
RsErr() << "Can't open folder " << dir.absolutePath().toStdString() ;
}
}
}
@ -347,8 +356,12 @@ void GxsChannelFilesStatusWidget::openFile()
std::cerr << "GxsChannelFilesStatusWidget(): can't open file " << fileInfo.path << std::endl;
}
}else{
QMessageBox::information(this, tr("Play File"),
tr("File %1 does not exist at location.").arg(fileInfo.path.c_str()));
return;
if(!mUsedAsEditor)
QMessageBox::information(this, tr("Play File"),
tr("File %1 does not exist at location.").arg(fileInfo.path.c_str()));
else
RsErr() << "File " << fileInfo.path << " does not exist at location." ;
return;
}
}

View File

@ -34,9 +34,10 @@ class GxsChannelFilesStatusWidget : public QWidget
Q_OBJECT
public:
explicit GxsChannelFilesStatusWidget(const RsGxsFile &file, QWidget *parent = 0);
explicit GxsChannelFilesStatusWidget(const RsGxsFile &file, QWidget *parent = 0,bool used_as_editor=false);
~GxsChannelFilesStatusWidget();
bool usedAsEditor() const { return mUsedAsEditor; }
signals:
void onButtonClick();
@ -73,6 +74,8 @@ private:
uint64_t mSize;
uint64_t mDivisor;
bool mUsedAsEditor;
Ui::GxsChannelFilesStatusWidget *ui;
};

View File

@ -295,7 +295,7 @@ void RsGxsChannelPostFilesModel::setFilter(const QStringList& strings, uint32_t&
{
preMods();
initEmptyHierarchy();
mFilteredFiles.clear();
if(strings.empty())
{
@ -317,8 +317,6 @@ void RsGxsChannelPostFilesModel::setFilter(const QStringList& strings, uint32_t&
}
count = mFilteredFiles.size();
std::cerr << "After filtering: " << count << " posts remain." << std::endl;
if (rowCount()>0)
{
beginInsertRows(QModelIndex(),0,rowCount()-1);

View File

@ -284,8 +284,10 @@ QWidget *ChannelPostFilesDelegate::createEditor(QWidget *parent, const QStyleOpt
if(index.column() == RsGxsChannelPostFilesModel::COLUMN_FILES_FILE)
{
GxsChannelFilesStatusWidget* w = new GxsChannelFilesStatusWidget(file,parent);
connect(w,SIGNAL(onButtonClick()),this->parent(),SLOT(updateDAll_PB()));
GxsChannelFilesStatusWidget* w = new GxsChannelFilesStatusWidget(file,parent,true);
w->setFocusPolicy(Qt::StrongFocus);
connect(w,SIGNAL(onButtonClick()),this->parent(),SLOT(updateDAll_PB()));
return w;
}
else
@ -416,6 +418,8 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
connect(ui->postsTree->selectionModel(),SIGNAL(selectionChanged(const QItemSelection&,const QItemSelection&)),this,SLOT(showPostDetails()));
connect(ui->postsTree,SIGNAL(customContextMenuRequested(const QPoint&)),this,SLOT(postContextMenu(const QPoint&)));
connect(ui->channel_TW,SIGNAL(currentChanged(int)),this,SLOT(currentTabChanged(int)));
connect(mChannelPostsModel,SIGNAL(channelPostsLoaded()),this,SLOT(postChannelPostLoad()));
ui->postName_LB->hide();
@ -501,6 +505,22 @@ GxsChannelPostsWidgetWithModel::GxsChannelPostsWidgetWithModel(const RsGxsGroupI
}, mEventHandlerId, RsEventType::GXS_CHANNELS );
}
void GxsChannelPostsWidgetWithModel::currentTabChanged(int t)
{
switch(t)
{
case CHANNEL_TABS_DETAILS:
case CHANNEL_TABS_FILES:
ui->showUnread_TB->setHidden(true);
ui->viewType_TB->setHidden(true);
break;
case CHANNEL_TABS_POSTS:
ui->showUnread_TB->setHidden(false);
ui->viewType_TB->setHidden(false);
break;
}
}
void GxsChannelPostsWidgetWithModel::updateZoomFactor(bool zoom_or_unzoom)
{
mChannelPostsDelegate->zoom(zoom_or_unzoom);

View File

@ -47,7 +47,7 @@ class ChannelPostFilesDelegate: public QStyledItemDelegate
Q_OBJECT
public:
ChannelPostFilesDelegate(QObject *parent=0) : QStyledItemDelegate(parent){}
ChannelPostFilesDelegate(QObject *parent=0) : QStyledItemDelegate(parent){}
virtual ~ChannelPostFilesDelegate(){}
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
@ -160,6 +160,7 @@ private slots:
void markMessageUnread();
public slots:
void currentTabChanged(int t);
void sortColumnFiles(int col,Qt::SortOrder so);
void sortColumnPostFiles(int col,Qt::SortOrder so);
void updateCommentsCount(int n);

View File

@ -194,7 +194,7 @@
<item>
<widget class="QTabWidget" name="channel_TW">
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="tab_3">
<attribute name="title">
@ -402,7 +402,7 @@
<string notr="true">&lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.0//EN&quot; &quot;http://www.w3.org/TR/REC-html40/strict.dtd&quot;&gt;
&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Ubuntu'; font-size:11pt; font-weight:400; font-style:normal;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;&lt;span style=&quot; font-family:'MS Shell Dlg 2'; font-size:8pt;&quot;&gt;Description&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textInteractionFlags">