first implementation of image only download

This commit is contained in:
Blue 2019-09-17 18:16:09 +03:00
parent 59f539c460
commit 94a3766aaf
10 changed files with 359 additions and 22 deletions

View file

@ -338,7 +338,35 @@ void Squawk::onConversationClosed(QObject* parent)
void Squawk::onConversationDownloadFile(const QString& messageId, const QString& url)
{
Conversation* conv = static_cast<Conversation*>(sender());
std::map<QString, std::set<Models::Roster::ElId>>::iterator itr = requestedFiles.find(messageId);
bool created = false;
if (itr == requestedFiles.end()) {
itr = requestedFiles.insert(std::make_pair(messageId, std::set<Models::Roster::ElId>())).first;
created = true;
}
itr->second.insert(Models::Roster::ElId(conv->getAccount(), conv->getJid()));
if (created) {
emit downloadFileRequest(messageId, url);
}
}
void Squawk::downloadFileProgress(const QString& messageId, qreal value)
{
std::map<QString, std::set<Models::Roster::ElId>>::const_iterator itr = requestedFiles.find(messageId);
if (itr == requestedFiles.end()) {
qDebug() << "downloadFileProgress 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->responseDownloadProgress(messageId, value);
}
}
}
}
void Squawk::fileLocalPathResponse(const QString& messageId, const QString& path)
@ -348,7 +376,8 @@ 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 {
const std::set<Models::Roster::ElId>& convs = itr->second;
std::set<Models::Roster::ElId> convs = itr->second;
requestedFiles.erase(itr);
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);
@ -356,7 +385,6 @@ void Squawk::fileLocalPathResponse(const QString& messageId, const QString& path
c->second->responseLocalFile(messageId, path);
}
}
requestedFiles.erase(itr);
}
}

View file

@ -67,6 +67,7 @@ signals:
void addRoomRequest(const QString& account, const QString& jid, const QString& nick, const QString& password, bool autoJoin);
void removeRoomRequest(const QString& account, const QString& jid);
void fileLocalPathRequest(const QString& messageId, const QString& url);
void downloadFileRequest(const QString& messageId, const QString& url);
public slots:
void newAccount(const QMap<QString, QVariant>& account);
@ -90,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 downloadFileProgress(const QString& messageId, qreal value);
private:
typedef std::map<Models::Roster::ElId, Conversation*> Conversations;

View file

@ -34,6 +34,7 @@ Message::Message(const Shared::Message& source, bool outgoing, const QString& p_
downloadButton(0),
file(0),
progress(0),
fileComment(0),
hasDownloadButton(false),
hasProgress(false),
hasFile(false)
@ -110,9 +111,15 @@ void Message::addDownloadDialog()
hasProgress = false;;
}
if (!hasDownloadButton) {
if (msg.getBody() == msg.getOutOfBandUrl()) {
text->setText("");
text->hide();
}
downloadButton = new QPushButton(QIcon::fromTheme("download"), "Download");
fileComment = new QLabel(sender->text() + " is offering you to download a file");
connect(downloadButton, SIGNAL(clicked()), this, SLOT(onDownload()));
bodyLayout->insertWidget(2, downloadButton);
bodyLayout->insertWidget(2, fileComment);
bodyLayout->insertWidget(3, downloadButton);
hasDownloadButton = true;
}
}
@ -131,10 +138,16 @@ void Message::setProgress(qreal value)
}
if (hasDownloadButton) {
downloadButton->deleteLater();
fileComment->deleteLater();
downloadButton = 0;
fileComment = 0;
hasDownloadButton = false;
}
if (!hasProgress) {
if (msg.getBody() == msg.getOutOfBandUrl()) {
text->setText("");
text->hide();
}
progress = new QLabel(std::to_string(value).c_str());
bodyLayout->insertWidget(2, progress);
hasProgress = true;
@ -145,16 +158,25 @@ void Message::showFile(const QString& path)
{
if (hasDownloadButton) {
downloadButton->deleteLater();
fileComment->deleteLater();
downloadButton = 0;
fileComment = 0;
hasDownloadButton = false;
}
if (hasProgress) {
progress->deleteLater();
progress = 0;
hasProgress = false;;
hasProgress = false;
}
if (!hasFile) {
file = new QLabel(path);
if (msg.getBody() == msg.getOutOfBandUrl()) {
text->setText("");
text->hide();
}
//file = new QLabel("<img src=\"" + path + "\">");
file = new QLabel();
file->setPixmap(QPixmap(path));
//file->setScaledContents(true);
bodyLayout->insertWidget(2, file);
hasFile = true;
}

View file

@ -59,6 +59,7 @@ private:
QPushButton* downloadButton;
QLabel* file;
QLabel* progress;
QLabel* fileComment;
bool hasDownloadButton;
bool hasProgress;
bool hasFile;