some progress on upload
This commit is contained in:
parent
3f710e26d0
commit
a6e48599aa
9 changed files with 117 additions and 63 deletions
|
@ -38,12 +38,10 @@ 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),
|
||||
errorDownloadingFile(false)
|
||||
commentAdded(false)
|
||||
{
|
||||
body->setBackgroundRole(QPalette::AlternateBase);
|
||||
body->setAutoFillBackground(true);
|
||||
|
@ -101,12 +99,17 @@ QString Message::getId() const
|
|||
return msg.getId();
|
||||
}
|
||||
|
||||
QString Message::getFileUrl() const
|
||||
{
|
||||
return msg.getOutOfBandUrl();
|
||||
}
|
||||
|
||||
void Message::setSender(const QString& p_sender)
|
||||
{
|
||||
sender->setText(p_sender);
|
||||
}
|
||||
|
||||
void Message::addDownloadDialog()
|
||||
void Message::addButton(const QIcon& icon, const QString& buttonText, const QString& comment)
|
||||
{
|
||||
hideFile();
|
||||
hideProgress();
|
||||
|
@ -116,16 +119,14 @@ void Message::addDownloadDialog()
|
|||
text->setText("");
|
||||
text->hide();
|
||||
}
|
||||
downloadButton = new QPushButton(QIcon::fromTheme("download"), tr("Download"));
|
||||
downloadButton = new QPushButton(icon, buttonText);
|
||||
downloadButton->setToolTip("<a href=\"" + msg.getOutOfBandUrl() + "\">" + msg.getOutOfBandUrl() + "</a>");
|
||||
if (errorDownloadingFile) {
|
||||
if (comment.size() != 0) {
|
||||
fileComment->setWordWrap(true);
|
||||
fileComment->setText(tr("Error downloading file: %1\nYou can try again").arg(QCoreApplication::translate("NetworkErrors", errorText.toLatin1())));
|
||||
} else {
|
||||
fileComment->setText(tr("%1 is offering you to download a file").arg(sender->text()));
|
||||
fileComment->setText(comment);
|
||||
fileComment->show();
|
||||
}
|
||||
fileComment->show();
|
||||
connect(downloadButton, &QPushButton::clicked, this, &Message::onDownload);
|
||||
connect(downloadButton, &QPushButton::clicked, this, &Message::downloadFile);
|
||||
bodyLayout->insertWidget(2, fileComment);
|
||||
bodyLayout->insertWidget(3, downloadButton);
|
||||
hasDownloadButton = true;
|
||||
|
@ -133,12 +134,7 @@ void Message::addDownloadDialog()
|
|||
}
|
||||
}
|
||||
|
||||
void Message::onDownload()
|
||||
{
|
||||
emit downloadFile(msg.getId(), msg.getOutOfBandUrl());
|
||||
}
|
||||
|
||||
void Message::setProgress(qreal value)
|
||||
void Message::setProgress(qreal value, const QString& label)
|
||||
{
|
||||
hideFile();
|
||||
hideDownload();
|
||||
|
@ -150,7 +146,9 @@ void Message::setProgress(qreal value)
|
|||
}
|
||||
progress = new QProgressBar();
|
||||
progress->setRange(0, 100);
|
||||
fileComment->setText("Downloading...");
|
||||
if (label.size() != 0) {
|
||||
fileComment->setText(label);
|
||||
}
|
||||
fileComment->show();
|
||||
bodyLayout->insertWidget(2, progress);
|
||||
bodyLayout->insertWidget(3, fileComment);
|
||||
|
@ -214,7 +212,6 @@ void Message::hideDownload()
|
|||
downloadButton->deleteLater();
|
||||
downloadButton = 0;
|
||||
hasDownloadButton = false;
|
||||
errorDownloadingFile = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -235,10 +232,3 @@ void Message::hideProgress()
|
|||
hasProgress = false;;
|
||||
}
|
||||
}
|
||||
|
||||
void Message::showError(const QString& error)
|
||||
{
|
||||
errorDownloadingFile = true;
|
||||
errorText = error;
|
||||
addDownloadDialog();
|
||||
}
|
||||
|
|
|
@ -30,9 +30,9 @@
|
|||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
|
||||
#include "../../global.h"
|
||||
#include "../utils/resizer.h"
|
||||
#include "../utils/image.h"
|
||||
#include "global.h"
|
||||
#include "resizer.h"
|
||||
#include "image.h"
|
||||
|
||||
/**
|
||||
* @todo write docs
|
||||
|
@ -46,14 +46,14 @@ public:
|
|||
|
||||
void setSender(const QString& sender);
|
||||
QString getId() const;
|
||||
QString getFileUrl() const;
|
||||
|
||||
void addDownloadDialog();
|
||||
void addButton(const QIcon& icon, const QString& buttonText, const QString& comment = "");
|
||||
void showFile(const QString& path);
|
||||
void showError(const QString& error);
|
||||
void setProgress(qreal value);
|
||||
void setProgress(qreal value, const QString& label = "");
|
||||
|
||||
signals:
|
||||
void downloadFile(const QString& messageId, const QString& url);
|
||||
void downloadFile();
|
||||
|
||||
private:
|
||||
Shared::Message msg;
|
||||
|
@ -67,15 +67,10 @@ private:
|
|||
QLabel* file;
|
||||
QProgressBar* progress;
|
||||
QLabel* fileComment;
|
||||
QString errorText;
|
||||
bool hasDownloadButton;
|
||||
bool hasProgress;
|
||||
bool hasFile;
|
||||
bool commentAdded;
|
||||
bool errorDownloadingFile;
|
||||
|
||||
private slots:
|
||||
void onDownload();
|
||||
|
||||
private:
|
||||
void hideDownload();
|
||||
|
|
|
@ -26,10 +26,13 @@ MessageLine::MessageLine(bool p_room, QWidget* parent):
|
|||
messageOrder(),
|
||||
myMessages(),
|
||||
palMessages(),
|
||||
uploadPaths(),
|
||||
layout(new QVBoxLayout(this)),
|
||||
myName(),
|
||||
palNames(),
|
||||
views(),
|
||||
uploading(),
|
||||
downloading(),
|
||||
room(p_room),
|
||||
busyShown(false),
|
||||
progress()
|
||||
|
@ -125,14 +128,27 @@ MessageLine::Position MessageLine::message(const Shared::Message& msg)
|
|||
layout->insertLayout(index, message);
|
||||
}
|
||||
|
||||
if (msg.hasOutOfBandUrl()) {\
|
||||
if (msg.hasOutOfBandUrl()) {
|
||||
emit requestLocalFile(msg.getId(), msg.getOutOfBandUrl());
|
||||
connect(message, &Message::downloadFile, this, &MessageLine::downloadFile);
|
||||
connect(message, &Message::downloadFile, this, &MessageLine::onDownload);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void MessageLine::onDownload()
|
||||
{
|
||||
Message* msg = static_cast<Message*>(sender());
|
||||
QString messageId = msg->getId();
|
||||
Index::const_iterator itr = downloading.find(messageId);
|
||||
if (itr == downloading.end()) {
|
||||
downloading.insert(std::make_pair(messageId, msg));
|
||||
emit downloadFile(messageId, msg->getFileUrl());
|
||||
} else {
|
||||
qDebug() << "An attempt to initiate download for already downloading file" << msg->getFileUrl() << ", skipping";
|
||||
}
|
||||
}
|
||||
|
||||
void MessageLine::setMyName(const QString& name)
|
||||
{
|
||||
myName = name;
|
||||
|
@ -192,13 +208,18 @@ void MessageLine::hideBusyIndicator()
|
|||
}
|
||||
}
|
||||
|
||||
void MessageLine::responseDownloadProgress(const QString& messageId, qreal progress)
|
||||
void MessageLine::fileProgress(const QString& messageId, qreal progress)
|
||||
{
|
||||
Index::const_iterator itr = messageIndex.find(messageId);
|
||||
if (itr == messageIndex.end()) {
|
||||
|
||||
Index::const_iterator itr = downloading.find(messageId);
|
||||
if (itr == downloading.end()) {
|
||||
Index::const_iterator itr = uploading.find(messageId);
|
||||
if (itr == uploading.end()) {
|
||||
//TODO may be some logging, that's not normal
|
||||
} else {
|
||||
itr->second->setProgress(progress, tr("Uploading..."));
|
||||
}
|
||||
} else {
|
||||
itr->second->setProgress(progress);
|
||||
itr->second->setProgress(progress, tr("Downloading..."));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,18 +232,31 @@ void MessageLine::responseLocalFile(const QString& messageId, const QString& pat
|
|||
if (path.size() > 0) {
|
||||
itr->second->showFile(path);
|
||||
} else {
|
||||
itr->second->addDownloadDialog();
|
||||
itr->second->addButton(QIcon::fromTheme("download"), tr("Download"), tr("Push the button to daownload the file"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MessageLine::downloadError(const QString& messageId, const QString& error)
|
||||
void MessageLine::fileError(const QString& messageId, const QString& error)
|
||||
{
|
||||
Index::const_iterator itr = messageIndex.find(messageId);
|
||||
if (itr == messageIndex.end()) {
|
||||
|
||||
Index::const_iterator itr = downloading.find(messageId);
|
||||
if (itr == downloading.end()) {
|
||||
Index::const_iterator itr = uploading.find(messageId);
|
||||
if (itr == uploading.end()) {
|
||||
//TODO may be some logging, that's not normal
|
||||
} else {
|
||||
//itr->second->showError(error);
|
||||
//itr->second->addDownloadDialog();
|
||||
}
|
||||
} else {
|
||||
itr->second->showError(error);
|
||||
itr->second->addButton(QIcon::fromTheme("download"), tr("Download"),
|
||||
tr("Error downloading file: %1\nYou can try again").arg(QCoreApplication::translate("NetworkErrors", error.toLatin1())));
|
||||
}
|
||||
}
|
||||
|
||||
void MessageLine::appendMessageWithUpload(const Shared::Message& msg, const QString& path)
|
||||
{
|
||||
message(msg);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -50,17 +50,22 @@ 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);
|
||||
void fileError(const QString& messageId, const QString& error);
|
||||
void fileProgress(const QString& messageId, qreal progress);
|
||||
void appendMessageWithUpload(const Shared::Message& message, const QString& path);
|
||||
|
||||
signals:
|
||||
void resize(int amount);
|
||||
void downloadFile(const QString& messageId, const QString& url);
|
||||
void uploadFile(const Shared::Message& msg, const QString& path);
|
||||
void requestLocalFile(const QString& messageId, const QString& url);
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent * event) override;
|
||||
|
||||
protected:
|
||||
void onDownload();
|
||||
|
||||
private:
|
||||
struct Comparator {
|
||||
bool operator()(const Shared::Message& a, const Shared::Message& b) const {
|
||||
|
@ -76,11 +81,14 @@ private:
|
|||
Order messageOrder;
|
||||
Index myMessages;
|
||||
std::map<QString, Index> palMessages;
|
||||
std::map<QString, QString> uploadPaths;
|
||||
QVBoxLayout* layout;
|
||||
|
||||
QString myName;
|
||||
std::map<QString, QString> palNames;
|
||||
std::deque<QHBoxLayout*> views;
|
||||
Index uploading;
|
||||
Index downloading;
|
||||
bool room;
|
||||
bool busyShown;
|
||||
Progress progress;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue