Work on getting attachments - gui.
This commit is contained in:
parent
fc1f821144
commit
c037f89aaf
@ -333,7 +333,8 @@ HEADERS += src/core/feeddownloader.h \
|
||||
src/services/tt-rss/ttrssfeed.h \
|
||||
src/services/tt-rss/ttrssserviceentrypoint.h \
|
||||
src/services/tt-rss/ttrssserviceroot.h \
|
||||
src/network-web/httpresponse.h
|
||||
src/network-web/httpresponse.h \
|
||||
src/services/gmail/gui/formdownloadattachment.h
|
||||
|
||||
SOURCES += src/core/feeddownloader.cpp \
|
||||
src/core/feedsmodel.cpp \
|
||||
@ -465,7 +466,8 @@ SOURCES += src/core/feeddownloader.cpp \
|
||||
src/services/tt-rss/ttrssfeed.cpp \
|
||||
src/services/tt-rss/ttrssserviceentrypoint.cpp \
|
||||
src/services/tt-rss/ttrssserviceroot.cpp \
|
||||
src/network-web/httpresponse.cpp
|
||||
src/network-web/httpresponse.cpp \
|
||||
src/services/gmail/gui/formdownloadattachment.cpp
|
||||
|
||||
mac {
|
||||
OBJECTIVE_SOURCES += src/miscellaneous/disablewindowtabbing.mm
|
||||
@ -496,7 +498,8 @@ FORMS += src/gui/dialogs/formabout.ui \
|
||||
src/services/owncloud/gui/formeditowncloudaccount.ui \
|
||||
src/services/standard/gui/formstandardcategorydetails.ui \
|
||||
src/services/standard/gui/formstandardimportexport.ui \
|
||||
src/services/tt-rss/gui/formeditttrssaccount.ui
|
||||
src/services/tt-rss/gui/formeditttrssaccount.ui \
|
||||
src/services/gmail/gui/formdownloadattachment.ui
|
||||
|
||||
equals(USE_WEBENGINE, true) {
|
||||
HEADERS += src/gui/locationlineedit.h \
|
||||
|
@ -261,6 +261,7 @@ void Downloader::runGetRequest(const QNetworkRequest& request) {
|
||||
m_activeReply->setProperty("protected", m_targetProtected);
|
||||
m_activeReply->setProperty("username", m_targetUsername);
|
||||
m_activeReply->setProperty("password", m_targetPassword);
|
||||
|
||||
connect(m_activeReply, &QNetworkReply::downloadProgress, this, &Downloader::progressInternal);
|
||||
connect(m_activeReply, &QNetworkReply::finished, this, &Downloader::finished);
|
||||
}
|
||||
|
@ -10,11 +10,11 @@
|
||||
#include "services/gmail/definitions.h"
|
||||
#include "services/gmail/gmailentrypoint.h"
|
||||
#include "services/gmail/gmailfeed.h"
|
||||
#include "services/gmail/gui/formdownloadattachment.h"
|
||||
#include "services/gmail/gui/formeditgmailaccount.h"
|
||||
#include "services/gmail/network/gmailnetworkfactory.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QFileDialog>
|
||||
|
||||
GmailServiceRoot::GmailServiceRoot(GmailNetworkFactory* network, RootItem* parent) : ServiceRoot(parent),
|
||||
CacheForServiceRoot(), m_serviceMenu(QList<QAction*>()), m_network(network) {
|
||||
@ -108,20 +108,15 @@ bool GmailServiceRoot::downloadAttachmentOnMyOwn(const QUrl& url) const {
|
||||
QString str_url = url.toString();
|
||||
QString attachment_id = str_url.mid(str_url.indexOf(QL1C('?')) + 1);
|
||||
QStringList parts = attachment_id.split(QL1S(GMAIL_ATTACHMENT_SEP));
|
||||
QString file = QFileDialog::getSaveFileName(qApp->mainFormWidget(), tr("Select attachment destination file"),
|
||||
qApp->homeFolder() + QDir::separator() + parts.at(0));
|
||||
|
||||
if (!file.isEmpty()) {
|
||||
Downloader* down = network()->downloadAttachment(parts.at(1));
|
||||
FormDownloadAttachment form(file, down, qApp->mainFormWidget());
|
||||
|
||||
connect(down, &Downloader::completed, [parts, down](QNetworkReply::NetworkError status, QByteArray contents) {
|
||||
if (status == QNetworkReply::NetworkError::NoError) {
|
||||
QString data = QJsonDocument::fromJson(contents).object()["data"].toString();
|
||||
|
||||
if (!data.isEmpty()) {
|
||||
IOFactory::writeFile(parts.at(0), QByteArray::fromBase64(data.toLocal8Bit(),
|
||||
QByteArray::Base64Option::Base64UrlEncoding));
|
||||
form.exec();
|
||||
}
|
||||
}
|
||||
|
||||
down->deleteLater();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
48
src/services/gmail/gui/formdownloadattachment.cpp
Executable file
48
src/services/gmail/gui/formdownloadattachment.cpp
Executable file
@ -0,0 +1,48 @@
|
||||
// For license of this file, see <object-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, [downloader, target_file](QNetworkReply::NetworkError status, QByteArray contents) {
|
||||
if (status == QNetworkReply::NetworkError::NoError) {
|
||||
QString data = QJsonDocument::fromJson(contents).object()["data"].toString();
|
||||
|
||||
if (!data.isEmpty()) {
|
||||
IOFactory::writeFile(target_file, QByteArray::fromBase64(data.toLocal8Bit(),
|
||||
QByteArray::Base64Option::Base64UrlEncoding));
|
||||
}
|
||||
}
|
||||
|
||||
downloader->deleteLater();
|
||||
});
|
||||
connect(downloader, &Downloader::completed, this, &FormDownloadAttachment::close);
|
||||
connect(downloader, &Downloader::progress, [this](qint64 bytes_received, qint64 bytes_total) {
|
||||
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));
|
||||
}
|
||||
});
|
||||
}
|
26
src/services/gmail/gui/formdownloadattachment.h
Executable file
26
src/services/gmail/gui/formdownloadattachment.h
Executable file
@ -0,0 +1,26 @@
|
||||
// For license of this file, see <object-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
|
51
src/services/gmail/gui/formdownloadattachment.ui
Executable file
51
src/services/gmail/gui/formdownloadattachment.ui
Executable file
@ -0,0 +1,51 @@
|
||||
<?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>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</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="1" 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="2" 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>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
Loading…
x
Reference in New Issue
Block a user