##// END OF EJS Templates
Amda provider (2)...
Alexandre Leroux -
r350:0abce98e1e41
parent child
Show More
@@ -29,6 +29,8 private:
29
29
30 private slots:
30 private slots:
31 void httpFinished() noexcept;
31 void httpFinished() noexcept;
32 void httpDownloadFinished() noexcept;
33 void httpDownloadReadyRead() noexcept;
32 };
34 };
33
35
34 #endif // SCIQLOP_AMDAPROVIDER_H
36 #endif // SCIQLOP_AMDAPROVIDER_H
@@ -3,6 +3,7
3
3
4 #include <QNetworkAccessManager>
4 #include <QNetworkAccessManager>
5 #include <QNetworkReply>
5 #include <QNetworkReply>
6 #include <QTemporaryFile>
6
7
7 Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider")
8 Q_LOGGING_CATEGORY(LOG_AmdaProvider, "AmdaProvider")
8
9
@@ -74,5 +75,49 void AmdaProvider::retrieveData(QUuid token, const DataProviderParameters &param
74
75
75 void AmdaProvider::httpFinished() noexcept
76 void AmdaProvider::httpFinished() noexcept
76 {
77 {
77 /// @todo ALX
78 // ////////////////////// //
79 // Gets download file url //
80 // ////////////////////// //
81
82 auto downloadFileUrl = QUrl{QString{impl->m_Reply->readAll()}};
83
84 // ///////////////////////////////////// //
85 // Executes request for downloading file //
86 // ///////////////////////////////////// //
87
88 // Deletes old reply
89 impl->m_Reply->deleteLater();
90 impl->m_Reply = nullptr;
91
92 // Creates destination file
93 impl->m_File = std::make_unique<QTemporaryFile>();
94 if (impl->m_File->open()) {
95 qCDebug(LOG_AmdaProvider()) << "Temp file: " << impl->m_File->fileName();
96
97 // Executes request
98 impl->m_AccessManager = std::make_unique<QNetworkAccessManager>();
99 impl->m_Reply = impl->m_AccessManager->get(QNetworkRequest{downloadFileUrl});
100 connect(impl->m_Reply, &QNetworkReply::finished, this,
101 &AmdaProvider::httpDownloadReadyRead);
102 connect(impl->m_Reply, &QNetworkReply::finished, this, &AmdaProvider::httpDownloadFinished);
103 }
104 }
105
106 void AmdaProvider::httpDownloadFinished() noexcept
107 {
108 if (impl->m_File) {
109 impl->m_File->close();
110 impl->m_File = nullptr;
111 }
112
113 // Deletes reply
114 impl->m_Reply->deleteLater();
115 impl->m_Reply = nullptr;
116 }
117
118 void AmdaProvider::httpDownloadReadyRead() noexcept
119 {
120 if (impl->m_File) {
121 impl->m_File->write(impl->m_Reply->readAll());
122 }
78 }
123 }
General Comments 0
You need to be logged in to leave comments. Login now