allow to use bundled downloader to download attachments

This commit is contained in:
Martin Rotter 2022-04-06 09:27:42 +02:00
parent 4e20727ba6
commit fd722f6a4d
14 changed files with 141 additions and 203 deletions

View file

@ -26,7 +26,7 @@
<url type="donation">https://github.com/sponsors/martinrotter</url> <url type="donation">https://github.com/sponsors/martinrotter</url>
<content_rating type="oars-1.1" /> <content_rating type="oars-1.1" />
<releases> <releases>
<release version="4.2.1" date="2022-04-04"/> <release version="4.2.1" date="2022-04-06"/>
</releases> </releases>
<content_rating type="oars-1.0"> <content_rating type="oars-1.0">
<content_attribute id="violence-cartoon">none</content_attribute> <content_attribute id="violence-cartoon">none</content_attribute>

View file

@ -289,8 +289,6 @@ set(SOURCES
services/gmail/gui/emailrecipientcontrol.h services/gmail/gui/emailrecipientcontrol.h
services/gmail/gui/formaddeditemail.cpp services/gmail/gui/formaddeditemail.cpp
services/gmail/gui/formaddeditemail.h services/gmail/gui/formaddeditemail.h
services/gmail/gui/formdownloadattachment.cpp
services/gmail/gui/formdownloadattachment.h
services/gmail/gui/formeditgmailaccount.cpp services/gmail/gui/formeditgmailaccount.cpp
services/gmail/gui/formeditgmailaccount.h services/gmail/gui/formeditgmailaccount.h
services/gmail/gui/gmailaccountdetails.cpp services/gmail/gui/gmailaccountdetails.cpp
@ -541,7 +539,6 @@ set(UI_FILES
services/abstract/gui/formfeeddetails.ui services/abstract/gui/formfeeddetails.ui
services/feedly/gui/feedlyaccountdetails.ui services/feedly/gui/feedlyaccountdetails.ui
services/gmail/gui/formaddeditemail.ui services/gmail/gui/formaddeditemail.ui
services/gmail/gui/formdownloadattachment.ui
services/gmail/gui/gmailaccountdetails.ui services/gmail/gui/gmailaccountdetails.ui
services/gmail/gui/emailpreviewer.ui services/gmail/gui/emailpreviewer.ui
services/greader/gui/greaderaccountdetails.ui services/greader/gui/greaderaccountdetails.ui

View file

@ -166,6 +166,7 @@ void WebEngineViewer::bindToBrowser(WebBrowser* browser) {
browser->m_actionReload = pageAction(QWebEnginePage::WebAction::Reload); browser->m_actionReload = pageAction(QWebEnginePage::WebAction::Reload);
browser->m_actionStop = pageAction(QWebEnginePage::WebAction::Stop); browser->m_actionStop = pageAction(QWebEnginePage::WebAction::Stop);
// NOTE: Just forwar QtWebEngine signals, it's all there.
connect(this, &QWebEngineView::loadStarted, this, &WebEngineViewer::loadStarted); connect(this, &QWebEngineView::loadStarted, this, &WebEngineViewer::loadStarted);
connect(this, &QWebEngineView::loadProgress, this, &WebEngineViewer::loadProgress); connect(this, &QWebEngineView::loadProgress, this, &WebEngineViewer::loadProgress);
connect(this, &QWebEngineView::loadFinished, this, &WebEngineViewer::loadFinished); connect(this, &QWebEngineView::loadFinished, this, &WebEngineViewer::loadFinished);

View file

@ -23,10 +23,13 @@
#include <QMimeData> #include <QMimeData>
#include <QSettings> #include <QSettings>
DownloadItem::DownloadItem(QNetworkReply* reply, QWidget* parent) : QWidget(parent), DownloadItem::DownloadItem(QNetworkReply* reply,
m_ui(new Ui::DownloadItem), m_reply(reply), const QString& preferred_file_name,
m_bytesReceived(0), m_requestFileName(false), m_startedSaving(false), m_finishedDownloading(false), const std::function<void (DownloadItem*)>& run_on_finish,
m_gettingFileName(false), m_canceledFileSelect(false) { QWidget* parent) : QWidget(parent),
m_ui(new Ui::DownloadItem), m_reply(reply), m_preferredFileName(preferred_file_name),
m_runOnFinish(run_on_finish), m_bytesReceived(0), m_requestFileName(false), m_startedSaving(false),
m_finishedDownloading(false), m_gettingFileName(false), m_canceledFileSelect(false) {
m_ui->setupUi(this); m_ui->setupUi(this);
m_ui->m_btnTryAgain->hide(); m_ui->m_btnTryAgain->hide();
m_requestFileName = qApp->settings()->value(GROUP(Downloads), SETTING(Downloads::AlwaysPromptForFilename)).toBool(); m_requestFileName = qApp->settings()->value(GROUP(Downloads), SETTING(Downloads::AlwaysPromptForFilename)).toBool();
@ -40,6 +43,7 @@ DownloadItem::DownloadItem(QNetworkReply* reply, QWidget* parent) : QWidget(pare
connect(m_ui->m_btnOpenFile, &QPushButton::clicked, this, &DownloadItem::openFile); connect(m_ui->m_btnOpenFile, &QPushButton::clicked, this, &DownloadItem::openFile);
connect(m_ui->m_btnTryAgain, &QPushButton::clicked, this, &DownloadItem::tryAgain); connect(m_ui->m_btnTryAgain, &QPushButton::clicked, this, &DownloadItem::tryAgain);
connect(m_ui->m_btnOpenFolder, &QPushButton::clicked, this, &DownloadItem::openFolder); connect(m_ui->m_btnOpenFolder, &QPushButton::clicked, this, &DownloadItem::openFolder);
init(); init();
} }
@ -151,7 +155,10 @@ QString DownloadItem::saveFileName(const QString& directory) const {
} }
} }
if (path.isEmpty()) { if (!m_preferredFileName.isEmpty()) {
path = m_preferredFileName;
}
else if (path.isEmpty()) {
path = m_url.path(); path = m_url.path();
} }
@ -181,6 +188,11 @@ QString DownloadItem::saveFileName(const QString& directory) const {
return name; return name;
} }
const QFile& DownloadItem::output() const
{
return m_output;
}
void DownloadItem::stop() { void DownloadItem::stop() {
setUpdatesEnabled(false); setUpdatesEnabled(false);
m_ui->m_btnStopDownload->setEnabled(false); m_ui->m_btnStopDownload->setEnabled(false);
@ -205,11 +217,11 @@ void DownloadItem::openFolder() {
if (m_output.exists()) { if (m_output.exists()) {
if (!SystemFactory::openFolderFile(m_output.fileName())) { if (!SystemFactory::openFolderFile(m_output.fileName())) {
MsgBox::show(this, MsgBox::show(this,
QMessageBox::Icon::Warning, QMessageBox::Icon::Warning,
tr("Cannot open directory"), tr("Cannot open directory"),
tr("Cannot open output directory. Open it manually."), tr("Cannot open output directory. Open it manually."),
QString(), QString(),
m_output.fileName()); m_output.fileName());
} }
} }
} }
@ -413,6 +425,10 @@ void DownloadItem::finished() {
emit statusChanged(); emit statusChanged();
emit downloadFinished(); emit downloadFinished();
if (m_runOnFinish) {
m_runOnFinish(this);
}
if (downloadedSuccessfully()) { if (downloadedSuccessfully()) {
qApp->showGuiMessage(Notification::Event::GeneralEvent, { qApp->showGuiMessage(Notification::Event::GeneralEvent, {
tr("Download finished"), tr("Download finished"),
@ -487,9 +503,11 @@ int DownloadManager::downloadProgress() const {
} }
} }
void DownloadManager::download(const QNetworkRequest& request) { void DownloadManager::download(const QNetworkRequest& request,
const QString& preferred_file_name,
const std::function<void (DownloadItem*)>& run_on_finish) {
if (!request.url().isEmpty()) { if (!request.url().isEmpty()) {
handleUnsupportedContent(m_networkManager->get(request)); handleUnsupportedContent(m_networkManager->get(request), preferred_file_name, run_on_finish);
} }
} }
@ -497,7 +515,9 @@ void DownloadManager::download(const QUrl& url) {
download(QNetworkRequest(url)); download(QNetworkRequest(url));
} }
void DownloadManager::handleUnsupportedContent(QNetworkReply* reply) { void DownloadManager::handleUnsupportedContent(QNetworkReply* reply,
const QString& preferred_file_name,
const std::function<void (DownloadItem*)>& run_on_finish) {
if (reply == nullptr || reply->url().isEmpty()) { if (reply == nullptr || reply->url().isEmpty()) {
return; return;
} }
@ -510,7 +530,7 @@ void DownloadManager::handleUnsupportedContent(QNetworkReply* reply) {
return; return;
} }
auto* item = new DownloadItem(reply, this); auto* item = new DownloadItem(reply, preferred_file_name, run_on_finish, this);
addItem(item); addItem(item);
@ -660,7 +680,7 @@ void DownloadManager::load() {
bool done = settings->value(GROUP(Downloads), QString(Downloads::ItemDone).arg(i), true).toBool(); bool done = settings->value(GROUP(Downloads), QString(Downloads::ItemDone).arg(i), true).toBool();
if (!url.isEmpty() && !file_name.isEmpty()) { if (!url.isEmpty() && !file_name.isEmpty()) {
auto* item = new DownloadItem(nullptr, this); auto* item = new DownloadItem(nullptr, {}, {}, this);
item->m_output.setFileName(file_name); item->m_output.setFileName(file_name);
item->m_url = url; item->m_url = url;
@ -670,6 +690,7 @@ void DownloadManager::load() {
item->m_ui->m_btnTryAgain->setVisible(!done); item->m_ui->m_btnTryAgain->setVisible(!done);
item->m_ui->m_btnTryAgain->setEnabled(!done); item->m_ui->m_btnTryAgain->setEnabled(!done);
item->m_ui->m_progressDownload->setVisible(false); item->m_ui->m_progressDownload->setVisible(false);
addItem(item); addItem(item);
} }

View file

@ -25,7 +25,10 @@ class DownloadItem : public QWidget {
friend class DownloadModel; friend class DownloadModel;
public: public:
explicit DownloadItem(QNetworkReply* reply = 0, QWidget* parent = nullptr); explicit DownloadItem(QNetworkReply* reply = nullptr,
const QString& preferred_file_name = {},
const std::function<void (DownloadItem*)>& run_on_finish = {},
QWidget* parent = nullptr);
virtual ~DownloadItem(); virtual ~DownloadItem();
bool downloading() const; bool downloading() const;
@ -35,6 +38,7 @@ class DownloadItem : public QWidget {
qint64 bytesReceived() const; qint64 bytesReceived() const;
double remainingTime() const; double remainingTime() const;
double currentSpeed() const; double currentSpeed() const;
const QFile& output() const;
private slots: private slots:
void stop(); void stop();
@ -64,6 +68,8 @@ class DownloadItem : public QWidget {
QUrl m_url; QUrl m_url;
QFile m_output; QFile m_output;
QNetworkReply* m_reply; QNetworkReply* m_reply;
QString m_preferredFileName;
std::function<void (DownloadItem*)> m_runOnFinish;
qint64 m_bytesReceived; qint64 m_bytesReceived;
QElapsedTimer m_downloadTime; QElapsedTimer m_downloadTime;
QTime m_lastProgressTime; QTime m_lastProgressTime;
@ -113,9 +119,10 @@ class DownloadManager : public TabContent {
static QString dataString(qint64 size); static QString dataString(qint64 size);
public slots: public slots:
void download(const QNetworkRequest& request); void download(const QNetworkRequest& request,
const QString& preferred_file_name = {},
const std::function<void(DownloadItem*)>& run_on_finish = {});
void download(const QUrl& url); void download(const QUrl& url);
void handleUnsupportedContent(QNetworkReply* reply);
void cleanup(); void cleanup();
private slots: private slots:
@ -133,6 +140,9 @@ class DownloadManager : public TabContent {
void downloadFinished(); void downloadFinished();
private: private:
void handleUnsupportedContent(QNetworkReply* reply,
const QString& preferred_file_name,
const std::function<void (DownloadItem*)>& run_on_finish);
void addItem(DownloadItem* item); void addItem(DownloadItem* item);
QScopedPointer<Ui::DownloadManager> m_ui; QScopedPointer<Ui::DownloadManager> m_ui;

View file

@ -147,6 +147,20 @@ void GmailNetworkFactory::setDownloadOnlyUnreadMessages(bool download_only_unrea
m_downloadOnlyUnreadMessages = download_only_unread_messages; m_downloadOnlyUnreadMessages = download_only_unread_messages;
} }
QNetworkRequest GmailNetworkFactory::requestForAttachment(const QString& email_id, const QString& attachment_id) {
QString target_url = QSL(GMAIL_API_GET_ATTACHMENT).arg(email_id, attachment_id);
QNetworkRequest req(target_url);
QByteArray bearer = m_oauth2->bearer().toLocal8Bit();
if (bearer.isEmpty()) {
throw NetworkException(QNetworkReply::NetworkError::AuthenticationRequiredError);
}
req.setRawHeader(QSL(HTTP_HEADERS_AUTHORIZATION).toLocal8Bit(), bearer);
return req;
}
void GmailNetworkFactory::setOauth(OAuth2Service* oauth) { void GmailNetworkFactory::setOauth(OAuth2Service* oauth) {
m_oauth2 = oauth; m_oauth2 = oauth;
} }
@ -155,29 +169,6 @@ void GmailNetworkFactory::setUsername(const QString& username) {
m_username = username; m_username = username;
} }
Downloader* GmailNetworkFactory::downloadAttachment(const QString& msg_id,
const QString& attachment_id,
const QNetworkProxy& custom_proxy) {
QString bearer = m_oauth2->bearer().toLocal8Bit();
if (bearer.isEmpty()) {
return nullptr;
}
else {
auto* downloader = new Downloader();
QString target_url = QSL(GMAIL_API_GET_ATTACHMENT).arg(msg_id, attachment_id);
if (custom_proxy.type() != QNetworkProxy::ProxyType::DefaultProxy) {
downloader->setProxy(custom_proxy);
}
downloader->appendRawHeader(QSL(HTTP_HEADERS_AUTHORIZATION).toLocal8Bit(), bearer.toLocal8Bit());
downloader->downloadFile(target_url);
return downloader;
}
}
QList<Message> GmailNetworkFactory::messages(const QString& stream_id, QList<Message> GmailNetworkFactory::messages(const QString& stream_id,
const QHash<ServiceRoot::BagOfMessages, QStringList>& stated_messages, const QHash<ServiceRoot::BagOfMessages, QStringList>& stated_messages,
Feed::Status& error, Feed::Status& error,

View file

@ -40,8 +40,8 @@ class GmailNetworkFactory : public QObject {
void setDownloadOnlyUnreadMessages(bool download_only_unread_messages); void setDownloadOnlyUnreadMessages(bool download_only_unread_messages);
// API methods. // API methods.
QNetworkRequest requestForAttachment(const QString& email_id, const QString& attachment_id);
QString sendEmail(Mimesis::Message msg, const QNetworkProxy& custom_proxy, Message* reply_to_message = nullptr); QString sendEmail(Mimesis::Message msg, const QNetworkProxy& custom_proxy, Message* reply_to_message = nullptr);
Downloader* downloadAttachment(const QString& msg_id, const QString& attachment_id, const QNetworkProxy& custom_proxy);
QList<Message> messages(const QString& stream_id, const QHash<ServiceRoot::BagOfMessages, QStringList>& stated_messages, QList<Message> messages(const QString& stream_id, const QHash<ServiceRoot::BagOfMessages, QStringList>& stated_messages,
Feed::Status& error, const QNetworkProxy& custom_proxy); Feed::Status& error, const QNetworkProxy& custom_proxy);
QNetworkReply::NetworkError markMessagesRead(RootItem::ReadStatus status, QNetworkReply::NetworkError markMessagesRead(RootItem::ReadStatus status,

View file

@ -14,7 +14,6 @@
#include "services/gmail/gmailnetworkfactory.h" #include "services/gmail/gmailnetworkfactory.h"
#include "services/gmail/gui/emailpreviewer.h" #include "services/gmail/gui/emailpreviewer.h"
#include "services/gmail/gui/formaddeditemail.h" #include "services/gmail/gui/formaddeditemail.h"
#include "services/gmail/gui/formdownloadattachment.h"
#include "services/gmail/gui/formeditgmailaccount.h" #include "services/gmail/gui/formeditgmailaccount.h"
#include <QFileDialog> #include <QFileDialog>
@ -106,7 +105,7 @@ bool GmailServiceRoot::wantsBaggedIdsOfExistingMessages() const {
CustomMessagePreviewer* GmailServiceRoot::customMessagePreviewer() { CustomMessagePreviewer* GmailServiceRoot::customMessagePreviewer() {
if (m_emailPreview.isNull()) { if (m_emailPreview.isNull()) {
m_emailPreview = new EmailPreviewer(); m_emailPreview = new EmailPreviewer(this);
} }
return m_emailPreview.data(); return m_emailPreview.data();

View file

@ -2,10 +2,19 @@
#include "services/gmail/gui/emailpreviewer.h" #include "services/gmail/gui/emailpreviewer.h"
#include "exceptions/networkexception.h"
#include "gui/messagebox.h"
#include "miscellaneous/application.h" #include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h" #include "miscellaneous/iconfactory.h"
#include "network-web/oauth2service.h"
#include "services/gmail/definitions.h"
#include "services/gmail/gmailnetworkfactory.h"
#include "services/gmail/gmailserviceroot.h"
EmailPreviewer::EmailPreviewer(QWidget* parent) : CustomMessagePreviewer(parent), m_webView(new WebBrowser(nullptr, this)) { #include <QJsonObject>
EmailPreviewer::EmailPreviewer(GmailServiceRoot* account, QWidget* parent)
: CustomMessagePreviewer(parent), m_account(account), m_webView(new WebBrowser(nullptr, this)) {
m_ui.setupUi(this); m_ui.setupUi(this);
m_ui.m_mainLayout->addWidget(dynamic_cast<QWidget*>(m_webView.data()), 3, 0, 1, -1); m_ui.m_mainLayout->addWidget(dynamic_cast<QWidget*>(m_webView.data()), 3, 0, 1, -1);
@ -13,22 +22,13 @@ EmailPreviewer::EmailPreviewer(QWidget* parent) : CustomMessagePreviewer(parent)
m_ui.m_btnForward->setIcon(qApp->icons()->fromTheme(QSL("mail-forward"))); m_ui.m_btnForward->setIcon(qApp->icons()->fromTheme(QSL("mail-forward")));
m_ui.m_btnReply->setIcon(qApp->icons()->fromTheme(QSL("mail-reply-sender"))); m_ui.m_btnReply->setIcon(qApp->icons()->fromTheme(QSL("mail-reply-sender")));
QMenu* menu_attachments = new QMenu(this);
m_ui.m_btnAttachments->setMenu(menu_attachments);
m_webView->setNavigationBarVisible(false); m_webView->setNavigationBarVisible(false);
// TODO: stahovani attachmentu connect(menu_attachments, &QMenu::triggered, this, &EmailPreviewer::downloadAttachment);
/*
if (!file.isEmpty() && parts.size() == 3) {
Downloader* down = network()->downloadAttachment(parts.at(1), parts.at(2), networkProxy());
FormDownloadAttachment form(file, down, qApp->mainFormWidget());
form.exec();
return true;
}
else {
return false;
}
*/
} }
EmailPreviewer::~EmailPreviewer() { EmailPreviewer::~EmailPreviewer() {
@ -40,10 +40,59 @@ void EmailPreviewer::clear() {
} }
void EmailPreviewer::loadMessage(const Message& msg, RootItem* selected_item) { void EmailPreviewer::loadMessage(const Message& msg, RootItem* selected_item) {
Q_UNUSED(selected_item)
m_message = msg;
m_webView->setHtml(msg.m_contents); m_webView->setHtml(msg.m_contents);
m_ui.m_tbFrom->setText(msg.m_author); m_ui.m_tbFrom->setText(msg.m_author);
m_ui.m_tbSubject->setText(msg.m_title); m_ui.m_tbSubject->setText(msg.m_title);
// TODO: todo
m_ui.m_tbTo->setText(QSL("-")); m_ui.m_tbTo->setText(QSL("-"));
m_ui.m_btnAttachments->menu()->clear();
for (const Enclosure& att : msg.m_enclosures) {
const QStringList att_id_name = att.m_url.split(QSL(GMAIL_ATTACHMENT_SEP));
m_ui.m_btnAttachments->menu()->addAction(att.m_mimeType)->setData(att_id_name);
}
m_ui.m_btnAttachments->setDisabled(m_ui.m_btnAttachments->menu()->isEmpty());
}
void EmailPreviewer::downloadAttachment(QAction* act) {
const QString attachment_id = act->data().toStringList().at(1);
const QString file_name = act->data().toStringList().at(0);
try {
const QNetworkRequest req = m_account->network()->requestForAttachment(m_message.m_customId, attachment_id);
qApp->downloadManager()->download(req, file_name, [this](DownloadItem* it) {
if (it->downloadedSuccessfully()) {
const QByteArray raw_json = IOFactory::readFile(it->output().fileName());
const QString data = QJsonDocument::fromJson(raw_json).object()[QSL("data")].toString();
if (!data.isEmpty()) {
IOFactory::writeFile(it->output().fileName(),
QByteArray::fromBase64(data.toLocal8Bit(),
QByteArray::Base64Option::Base64UrlEncoding));
}
}
});
}
catch (const NetworkException&) {
MsgBox::show({},
QMessageBox::Icon::Critical,
tr("Cannot download attachment"),
tr("Attachment cannot be downloaded because you are not logged-in."));
}
catch (const ApplicationException& ex) {
MsgBox::show({},
QMessageBox::Icon::Critical,
tr("Cannot download attachment"),
tr("Attachment cannot be downloaded because some general error happened."),
{},
ex.message());
}
} }

View file

@ -9,19 +9,26 @@
#include "ui_emailpreviewer.h" #include "ui_emailpreviewer.h"
class GmailServiceRoot;
class EmailPreviewer : public CustomMessagePreviewer { class EmailPreviewer : public CustomMessagePreviewer {
Q_OBJECT Q_OBJECT
public: public:
explicit EmailPreviewer(QWidget* parent = nullptr); explicit EmailPreviewer(GmailServiceRoot* account, QWidget* parent = nullptr);
virtual ~EmailPreviewer(); virtual ~EmailPreviewer();
virtual void clear(); virtual void clear();
virtual void loadMessage(const Message& msg, RootItem* selected_item); virtual void loadMessage(const Message& msg, RootItem* selected_item);
private slots:
void downloadAttachment(QAction* act);
private: private:
Ui::EmailPreviewer m_ui; Ui::EmailPreviewer m_ui;
GmailServiceRoot* m_account;
QScopedPointer<WebBrowser> m_webView; QScopedPointer<WebBrowser> m_webView;
Message m_message;
}; };
#endif // EMAILPREVIEWER_H #endif // EMAILPREVIEWER_H

View file

@ -64,9 +64,6 @@
<property name="toolButtonStyle"> <property name="toolButtonStyle">
<enum>Qt::ToolButtonTextBesideIcon</enum> <enum>Qt::ToolButtonTextBesideIcon</enum>
</property> </property>
<property name="arrowType">
<enum>Qt::DownArrow</enum>
</property>
</widget> </widget>
</item> </item>
<item> <item>

View file

@ -1,53 +0,0 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#include "formdownloadattachment.h"
#include "gui/guiutilities.h"
#include "miscellaneous/application.h"
#include "miscellaneous/iconfactory.h"
#include "miscellaneous/iofactory.h"
#include "network-web/downloader.h"
#include <QDialogButtonBox>
#include <QJsonDocument>
#include <QJsonObject>
FormDownloadAttachment::FormDownloadAttachment(const QString& target_file, Downloader* downloader, QWidget* parent) : QDialog(parent) {
m_ui.setupUi(this);
GuiUtilities::applyDialogProperties(*this, qApp->icons()->fromTheme(QSL("mail-attachment")), tr("Downloading attachment..."));
connect(m_ui.m_btnBox->button(QDialogButtonBox::StandardButton::Abort), &QPushButton::clicked, downloader, &Downloader::cancel);
connect(downloader,
&Downloader::completed,
this,
[this, downloader, target_file](QNetworkReply::NetworkError status, const QByteArray& contents) {
if (status == QNetworkReply::NetworkError::NoError) {
QString data = QJsonDocument::fromJson(contents).object()[QSL("data")].toString();
if (!data.isEmpty()) {
IOFactory::writeFile(target_file, QByteArray::fromBase64(data.toLocal8Bit(),
QByteArray::Base64Option::Base64UrlEncoding));
}
}
downloader->deleteLater();
close();
});
connect(downloader, &Downloader::progress, this, [this](qint64 bytes_received, qint64 bytes_total) {
m_ui.m_lblInfo->setText(tr("Downloaded: %1 kB").arg(bytes_received / 1000.0));
if (m_ui.m_progressBar->maximum() == 0) {
return;
}
if (bytes_total <= 0) {
m_ui.m_progressBar->setMinimum(0);
m_ui.m_progressBar->setMaximum(0);
m_ui.m_progressBar->setValue(0);
}
else {
m_ui.m_progressBar->setValue(int((bytes_received * 100.0) / bytes_total));
}
});
}

View file

@ -1,26 +0,0 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#ifndef FORMDOWNLOADATTACHMENT_H
#define FORMDOWNLOADATTACHMENT_H
#include <QDialog>
#include "ui_formdownloadattachment.h"
namespace Ui {
class FormDownloadAttachment;
}
class Downloader;
class FormDownloadAttachment : public QDialog {
Q_OBJECT
public:
explicit FormDownloadAttachment(const QString& target_file, Downloader* downloader, QWidget* parent = nullptr);
private:
Ui::FormDownloadAttachment m_ui;
};
#endif // FORMDOWNLOADATTACHMENT_H

View file

@ -1,55 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FormDownloadAttachment</class>
<widget class="QDialog" name="FormDownloadAttachment">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>275</width>
<height>106</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0" colspan="2">
<widget class="QProgressBar" name="m_progressBar">
<property name="value">
<number>0</number>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>100</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0" colspan="2">
<widget class="QDialogButtonBox" name="m_btnBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Abort</set>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QLabel" name="m_lblInfo">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>