1
0
Fork 0
forked from blue/squawk

download files error handling

This commit is contained in:
Blue 2019-09-18 16:27:47 +03:00
parent cc54c6393a
commit 2089d6af86
13 changed files with 199 additions and 9 deletions

View file

@ -290,6 +290,11 @@ void Conversation::responseDownloadProgress(const QString& messageId, qreal prog
line->responseDownloadProgress(messageId, progress);
}
void Conversation::downloadError(const QString& messageId, const QString& error)
{
line->downloadError(messageId, error);
}
void Conversation::responseLocalFile(const QString& messageId, const QString& path)
{
line->responseLocalFile(messageId, path);

View file

@ -72,6 +72,7 @@ public:
void responseArchive(const std::list<Shared::Message> list);
void showEvent(QShowEvent * event) override;
void responseLocalFile(const QString& messageId, const QString& path);
void downloadError(const QString& messageId, const QString& error);
void responseDownloadProgress(const QString& messageId, qreal progress);
signals:

View file

@ -38,10 +38,12 @@ Message::Message(const Shared::Message& source, bool outgoing, const QString& p_
file(0),
progress(0),
fileComment(new QLabel()),
errorText(""),
hasDownloadButton(false),
hasProgress(false),
hasFile(false),
commentAdded(false)
commentAdded(false),
errorDownloadingFile(false)
{
body->setBackgroundRole(QPalette::AlternateBase);
body->setAutoFillBackground(true);
@ -117,7 +119,12 @@ void Message::addDownloadDialog()
}
downloadButton = new QPushButton(QIcon::fromTheme("download"), "Download");
downloadButton->setToolTip("<a href=\"" + msg.getOutOfBandUrl() + "\">" + msg.getOutOfBandUrl() + "</a>");
fileComment->setText(sender->text() + " is offering you to download a file");
if (errorDownloadingFile) {
fileComment->setWordWrap(true);
fileComment->setText("Error downloading file: " + errorText + "\nYou can try again");
} else {
fileComment->setText(sender->text() + " is offering you to download a file");
}
fileComment->show();
connect(downloadButton, SIGNAL(clicked()), this, SLOT(onDownload()));
bodyLayout->insertWidget(2, fileComment);
@ -208,6 +215,7 @@ void Message::hideDownload()
downloadButton->deleteLater();
downloadButton = 0;
hasDownloadButton = false;
errorDownloadingFile = false;
}
}
@ -228,3 +236,10 @@ void Message::hideProgress()
hasProgress = false;;
}
}
void Message::showError(const QString& error)
{
errorDownloadingFile = true;
errorText = error;
addDownloadDialog();
}

View file

@ -49,6 +49,7 @@ public:
void addDownloadDialog();
void showFile(const QString& path);
void showError(const QString& error);
void setProgress(qreal value);
signals:
@ -66,10 +67,12 @@ private:
QLabel* file;
QProgressBar* progress;
QLabel* fileComment;
QString errorText;
bool hasDownloadButton;
bool hasProgress;
bool hasFile;
bool commentAdded;
bool errorDownloadingFile;
private slots:
void onDownload();

View file

@ -246,3 +246,14 @@ void MessageLine::responseLocalFile(const QString& messageId, const QString& pat
}
}
}
void MessageLine::downloadError(const QString& messageId, const QString& error)
{
Index::const_iterator itr = messageIndex.find(messageId);
if (itr == messageIndex.end()) {
} else {
itr->second->showError(error);
}
}

View file

@ -53,6 +53,7 @@ public:
void showBusyIndicator();
void hideBusyIndicator();
void responseLocalFile(const QString& messageId, const QString& path);
void downloadError(const QString& messageId, const QString& error);
void responseDownloadProgress(const QString& messageId, qreal progress);
signals: