Refactored useless method.

This commit is contained in:
Martin Rotter 2017-10-04 06:52:44 +02:00
parent d929bc3b6a
commit f677b6fc80
5 changed files with 32 additions and 45 deletions

View File

@ -89,6 +89,9 @@
#define EXTERNAL_TOOL_SEPARATOR "###"
#define EXTERNAL_TOOL_PARAM_SEPARATOR "|||"
#define HTTP_HEADERS_ACCEPT "Accept"
#define HTTP_HEADERS_AUTHORIZATION "Authorization"
#define MAX_ZOOM_FACTOR 5.0f
#define MIN_ZOOM_FACTOR 0.25f
#define DEFAULT_ZOOM_FACTOR 1.0f

View File

@ -170,6 +170,8 @@ Downloader* NetworkFactory::performAsyncNetworkOperation(const QString& url, int
const QString& password, bool set_basic_header) {
Downloader* downloader = new Downloader();
QObject::connect(downloader, &Downloader::completed, downloader, &Downloader::deleteLater);
if (!input_content_type.isEmpty()) {
downloader->appendRawHeader("Content-Type", input_content_type.toLocal8Bit());
}
@ -213,24 +215,3 @@ NetworkResult NetworkFactory::performNetworkOperation(const QString& url, int ti
result.second = downloader.lastContentType();
return result;
}
NetworkResult NetworkFactory::downloadFeedFile(const QString& url, int timeout,
QByteArray& output, bool protected_contents,
const QString& username, const QString& password) {
// Here, we want to achieve "synchronous" approach because we want synchronout download API for
// some use-cases too.
Downloader downloader;
QEventLoop loop;
NetworkResult result;
downloader.appendRawHeader("Accept", ACCEPT_HEADER_FOR_FEED_DOWNLOADER);
// We need to quit event loop when the download finishes.
QObject::connect(&downloader, &Downloader::completed, &loop, &QEventLoop::quit);
downloader.downloadFile(url, timeout, protected_contents, username, password);
loop.exec();
output = downloader.lastOutputData();
result.first = downloader.lastOutputError();
result.second = downloader.lastContentType();
return result;
}

View File

@ -55,9 +55,6 @@ class NetworkFactory {
QNetworkAccessManager::Operation operation,
bool protected_contents = false, const QString& username = QString(),
const QString& password = QString(), bool set_basic_header = false);
static NetworkResult downloadFeedFile(const QString& url, int timeout, QByteArray& output,
bool protected_contents = false, const QString& username = QString(),
const QString& password = QString());
};
#endif // NETWORKFACTORY_H

View File

@ -332,8 +332,6 @@ void OwnCloudNetworkFactory::markMessagesRead(RootItem::ReadStatus status, const
QNetworkAccessManager::PutOperation,
true, m_authUsername, m_authPassword,
true);
QObject::connect(downloader, &Downloader::completed, downloader, &Downloader::deleteLater);
}
void OwnCloudNetworkFactory::markMessagesStarred(RootItem::Importance importance,
@ -360,16 +358,14 @@ void OwnCloudNetworkFactory::markMessagesStarred(RootItem::Importance importance
json["items"] = ids;
Downloader* downloader = NetworkFactory::performAsyncNetworkOperation(final_url,
qApp->settings()->value(GROUP(Feeds),
SETTING(Feeds::UpdateTimeout)).toInt(),
QJsonDocument(json).toJson(QJsonDocument::Compact),
CONTENT_TYPE,
QNetworkAccessManager::PutOperation,
true, m_authUsername, m_authPassword,
true);
QObject::connect(downloader, &Downloader::completed, downloader, &Downloader::deleteLater);
NetworkFactory::performAsyncNetworkOperation(final_url,
qApp->settings()->value(GROUP(Feeds),
SETTING(Feeds::UpdateTimeout)).toInt(),
QJsonDocument(json).toJson(QJsonDocument::Compact),
CONTENT_TYPE,
QNetworkAccessManager::PutOperation,
true, m_authUsername, m_authPassword,
true);
}
int OwnCloudNetworkFactory::batchSize() const {

View File

@ -173,13 +173,16 @@ QPair<StandardFeed*, QNetworkReply::NetworkError> StandardFeed::guessFeed(const
QPair<StandardFeed*, QNetworkReply::NetworkError> result;
result.first = nullptr;
QByteArray feed_contents;
NetworkResult network_result = NetworkFactory::downloadFeedFile(url,
qApp->settings()->value(GROUP(Feeds),
SETTING(Feeds::UpdateTimeout)).toInt(),
feed_contents,
!username.isEmpty(),
username,
password);
NetworkResult network_result = NetworkFactory::performNetworkOperation(url,
qApp->settings()->value(GROUP(Feeds),
SETTING(Feeds::UpdateTimeout)).toInt(),
QByteArray(),
QString(),
feed_contents,
QNetworkAccessManager::GetOperation,
!username.isEmpty(),
username,
password);
result.second = network_result.first;
@ -431,8 +434,15 @@ QList<Message> StandardFeed::obtainNewMessages(bool* error_during_obtaining) {
QByteArray feed_contents;
int download_timeout = qApp->settings()->value(GROUP(Feeds), SETTING(Feeds::UpdateTimeout)).toInt();
m_networkError = NetworkFactory::downloadFeedFile(url(), download_timeout, feed_contents,
passwordProtected(), username(), password()).first;
m_networkError = NetworkFactory::performNetworkOperation(url(),
download_timeout,
QByteArray(),
QString(),
feed_contents,
QNetworkAccessManager::GetOperation,
!username().isEmpty(),
username(),
password()).first;
if (m_networkError != QNetworkReply::NoError) {
qWarning("Error during fetching of new messages for feed '%s' (id %d).", qPrintable(url()), id());