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

@ -369,6 +369,25 @@ void Squawk::downloadFileProgress(const QString& messageId, qreal value)
}
}
void Squawk::downloadFileError(const QString& messageId, const QString& error)
{
std::map<QString, std::set<Models::Roster::ElId>>::const_iterator itr = requestedFiles.find(messageId);
if (itr == requestedFiles.end()) {
qDebug() << "downloadFileError in UI Squawk but there is nobody waiting for that id" << messageId << ", skipping";
return;
} else {
const std::set<Models::Roster::ElId>& convs = itr->second;
for (std::set<Models::Roster::ElId>::const_iterator cItr = convs.begin(), cEnd = convs.end(); cItr != cEnd; ++cItr) {
const Models::Roster::ElId& id = *cItr;
Conversations::const_iterator c = conversations.find(id);
if (c != conversations.end()) {
c->second->downloadError(messageId, error);
}
}
requestedFiles.erase(itr);
}
}
void Squawk::fileLocalPathResponse(const QString& messageId, const QString& path)
{
std::map<QString, std::set<Models::Roster::ElId>>::const_iterator itr = requestedFiles.find(messageId);
@ -376,8 +395,7 @@ void Squawk::fileLocalPathResponse(const QString& messageId, const QString& path
qDebug() << "fileLocalPathResponse in UI Squawk but there is nobody waiting for that path, skipping";
return;
} else {
std::set<Models::Roster::ElId> convs = itr->second;
requestedFiles.erase(itr);
const std::set<Models::Roster::ElId>& convs = itr->second;
for (std::set<Models::Roster::ElId>::const_iterator cItr = convs.begin(), cEnd = convs.end(); cItr != cEnd; ++cItr) {
const Models::Roster::ElId& id = *cItr;
Conversations::const_iterator c = conversations.find(id);
@ -385,6 +403,8 @@ void Squawk::fileLocalPathResponse(const QString& messageId, const QString& path
c->second->responseLocalFile(messageId, path);
}
}
requestedFiles.erase(itr);
}
}

View file

@ -91,6 +91,7 @@ public slots:
void changeRoomParticipant(const QString& account, const QString& jid, const QString& name, const QMap<QString, QVariant>& data);
void removeRoomParticipant(const QString& account, const QString& jid, const QString& name);
void fileLocalPathResponse(const QString& messageId, const QString& path);
void downloadFileError(const QString& messageId, const QString& error);
void downloadFileProgress(const QString& messageId, qreal value);
private:

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: