fixed crash when canceling DL from channel files list

This commit is contained in:
csoler 2023-02-17 23:56:35 +01:00
parent 9442d87644
commit f6c584183b
4 changed files with 30 additions and 16 deletions

View file

@ -33,8 +33,8 @@
#include "retroshare/rsfiles.h" #include "retroshare/rsfiles.h"
GxsChannelFilesStatusWidget::GxsChannelFilesStatusWidget(const RsGxsFile &file, QWidget *parent) : GxsChannelFilesStatusWidget::GxsChannelFilesStatusWidget(const RsGxsFile &file, QWidget *parent,bool used_as_editor) :
QWidget(parent), mFile(file), ui(new Ui::GxsChannelFilesStatusWidget) QWidget(parent), mFile(file), mUsedAsEditor(used_as_editor),ui(new Ui::GxsChannelFilesStatusWidget)
{ {
ui->setupUi(this); ui->setupUi(this);
@ -306,6 +306,7 @@ void GxsChannelFilesStatusWidget::resume()
void GxsChannelFilesStatusWidget::cancel() void GxsChannelFilesStatusWidget::cancel()
{ {
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) { 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; return;
} }
@ -327,7 +328,11 @@ void GxsChannelFilesStatusWidget::openFolder()
QDir dir = QFileInfo(QString::fromUtf8(fileInfo.path.c_str())).absoluteDir(); QDir dir = QFileInfo(QString::fromUtf8(fileInfo.path.c_str())).absoluteDir();
if (dir.exists()) { if (dir.exists()) {
if (!RsUrlHandler::openUrl(QUrl::fromLocalFile(dir.absolutePath()))) { if (!RsUrlHandler::openUrl(QUrl::fromLocalFile(dir.absolutePath()))) {
if(!mUsedAsEditor)
QMessageBox::warning(this, "", QString("%1 %2").arg(tr("Can't open folder"), dir.absolutePath())); 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 +352,12 @@ void GxsChannelFilesStatusWidget::openFile()
std::cerr << "GxsChannelFilesStatusWidget(): can't open file " << fileInfo.path << std::endl; std::cerr << "GxsChannelFilesStatusWidget(): can't open file " << fileInfo.path << std::endl;
} }
}else{ }else{
if(!mUsedAsEditor)
QMessageBox::information(this, tr("Play File"), QMessageBox::information(this, tr("Play File"),
tr("File %1 does not exist at location.").arg(fileInfo.path.c_str())); tr("File %1 does not exist at location.").arg(fileInfo.path.c_str()));
else
RsErr() << "File " << fileInfo.path << " does not exist at location." ;
return; return;
} }
} }

View file

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

View file

@ -284,8 +284,10 @@ QWidget *ChannelPostFilesDelegate::createEditor(QWidget *parent, const QStyleOpt
if(index.column() == RsGxsChannelPostFilesModel::COLUMN_FILES_FILE) if(index.column() == RsGxsChannelPostFilesModel::COLUMN_FILES_FILE)
{ {
GxsChannelFilesStatusWidget* w = new GxsChannelFilesStatusWidget(file,parent); GxsChannelFilesStatusWidget* w = new GxsChannelFilesStatusWidget(file,parent,true);
w->setFocusPolicy(Qt::StrongFocus);
connect(w,SIGNAL(onButtonClick()),this->parent(),SLOT(updateDAll_PB())); connect(w,SIGNAL(onButtonClick()),this->parent(),SLOT(updateDAll_PB()));
return w; return w;
} }
else else