Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/framework/cloud/qml/Muse/Cloud/AccountPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ FocusScope {
navigationSection: navSec

onSignInRequested: function (cloudCode) {
cloudsModel.signIn(cloudCode)
Qt.callLater(cloudsModel.signIn, cloudCode)
}

onSignOutRequested: function (cloudCode) {
cloudsModel.signOut(cloudCode)
Qt.callLater(cloudsModel.signOut, cloudCode)
}

onCreateAccountRequested: function (cloudCode) {
cloudsModel.createAccount(cloudCode)
Qt.callLater(cloudsModel.createAccount, cloudCode)
}
}
}
2 changes: 1 addition & 1 deletion src/framework/global/types/version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static std::array<int, 3> parseVersion(const muse::String& versionString, bool&
if (componentIdx < result.size()) {
result.at(componentIdx) = curNum;
} else {
LOGW() << "Ignoring everything after third point";
LOGW() << "Ignoring everything after third point: " << versionString;
}

ok = true;
Expand Down
4 changes: 2 additions & 2 deletions src/framework/learn/internal/learnservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void LearnService::refreshPlaylists()
{
auto startedPlaylistCallBack = [this](const RetVal<Playlist>& result) {
if (!result.ret) {
LOGW() << result.ret.toString();
LOGE() << "Unable to get started playlist: " << result.ret.toString();
return;
}

Expand All @@ -65,7 +65,7 @@ void LearnService::refreshPlaylists()

auto advancedPlaylistCallBack = [this](const RetVal<Playlist>& result) {
if (!result.ret) {
LOGW() << result.ret.toString();
LOGE() << "Unable to get advanced playlist: " << result.ret.toString();
return;
}

Expand Down
86 changes: 20 additions & 66 deletions src/framework/network/internal/networkmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,19 @@

#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QTimer>
#include <QEventLoop>
#include <QUrl>

#include "log.h"
#include "networkerrors.h"

using namespace muse;
using namespace muse::network;

static constexpr int NET_TIMEOUT_MS = 60000;

NetworkManager::NetworkManager(QObject* parent)
: QObject(parent)
{
m_manager = new QNetworkAccessManager(this);
m_manager->setTransferTimeout(); // Use Qt's default timeout (30s)
}

NetworkManager::~NetworkManager()
Expand Down Expand Up @@ -81,8 +78,6 @@ Ret NetworkManager::del(const QUrl& url, IncomingDevice* incomingData, const Req
Ret NetworkManager::execRequest(RequestType requestType, const QUrl& url, IncomingDevice* incomingData, OutgoingDevice* outgoingData,
const RequestHeaders& headers)
{
LOGI() << "Start: " << requestTypeToString(requestType) << ", url: " << url.toString();

if (outgoingData && outgoingData->device()) {
if (!openDevice(outgoingData->device(), QIODevice::ReadOnly)) {
return make_ret(Err::FiledOpenIODeviceRead);
Expand All @@ -104,12 +99,12 @@ Ret NetworkManager::execRequest(RequestType requestType, const QUrl& url, Incomi
_headers = configuration()->defaultHeaders();
}

for (QNetworkRequest::KnownHeaders knownHeader: _headers.knownHeaders.keys()) {
request.setHeader(knownHeader, _headers.knownHeaders[knownHeader]);
for (auto it = _headers.knownHeaders.cbegin(); it != _headers.knownHeaders.cend(); ++it) {
request.setHeader(it.key(), it.value());
}

for (const QByteArray& rawHeader: _headers.rawHeaders.keys()) {
request.setRawHeader(rawHeader, _headers.rawHeaders[rawHeader]);
for (auto it = _headers.rawHeaders.cbegin(); it != _headers.rawHeaders.cend(); ++it) {
request.setRawHeader(it.key(), it.value());
}

m_progress.start();
Expand All @@ -124,11 +119,7 @@ Ret NetworkManager::execRequest(RequestType requestType, const QUrl& url, Incomi
prepareReplyReceive(reply, m_incomingData);
}

Ret ret = waitForReplyFinished(reply, NET_TIMEOUT_MS);
if (!ret) {
LOGE() << ret.toString();
}

Ret ret = waitForReplyFinished(reply);
m_progress.finish(ret);

if (reply) {
Expand All @@ -142,8 +133,6 @@ Ret NetworkManager::execRequest(RequestType requestType, const QUrl& url, Incomi
closeDevice(m_incomingData);
m_incomingData = nullptr;

LOGI() << "Finish: " << requestTypeToString(requestType) << ", url: " << url.toString();

return ret;
}

Expand Down Expand Up @@ -179,6 +168,7 @@ QNetworkReply* NetworkManager::receiveReply(RequestType requestType, const QNetw
}
}

UNREACHABLE;
return nullptr;
}

Expand All @@ -193,7 +183,6 @@ void NetworkManager::abort()
m_reply->abort();
}

m_isAborted = true;
m_progress.finish(make_ret(Err::Abort));
}

Expand All @@ -217,11 +206,6 @@ void NetworkManager::closeDevice(QIODevice* device)
}
}

bool NetworkManager::isAborted() const
{
return m_isAborted;
}

void NetworkManager::prepareReplyReceive(QNetworkReply* reply, IncomingDevice* incomingData)
{
if (incomingData) {
Expand All @@ -246,48 +230,28 @@ void NetworkManager::prepareReplyReceive(QNetworkReply* reply, IncomingDevice* i

void NetworkManager::prepareReplyTransmit(QNetworkReply* reply)
{
connect(reply, &QNetworkReply::uploadProgress, [this](const qint64 curr, const qint64 total) {
connect(reply, &QNetworkReply::uploadProgress, this, [this](qint64 curr, qint64 total) {
m_progress.progress(curr, total);
});
}

Ret NetworkManager::waitForReplyFinished(QNetworkReply* reply, int timeoutMs)
Ret NetworkManager::waitForReplyFinished(QNetworkReply* reply)
{
QTimer timeoutTimer;
timeoutTimer.setSingleShot(true);
m_isAborted = false;

bool isTimeout = false;
connect(&timeoutTimer, &QTimer::timeout, this, [this, &isTimeout]() {
isTimeout = true;
abort();
});

auto restartTimeoutTimer = [&timeoutTimer, &isTimeout](qint64, qint64) {
if (!isTimeout) {
timeoutTimer.start();
}
};
IF_ASSERT_FAILED(reply) {
return make_ret(Err::UnknownError);
}

connect(reply, &QNetworkReply::downloadProgress, this, restartTimeoutTimer);
connect(reply, &QNetworkReply::uploadProgress, this, restartTimeoutTimer);
if (reply->isFinished()) {
return errorFromReply(reply);
}

QEventLoop loop;
connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);

m_reply = reply;
timeoutTimer.start(timeoutMs);
loop.exec();
m_reply = nullptr;

if (isTimeout) {
return make_ret(Err::Timeout);
}

if (isAborted()) {
return make_ret(Err::Abort);
}

return errorFromReply(reply);
}

Expand All @@ -299,7 +263,11 @@ Ret NetworkManager::errorFromReply(const QNetworkReply* reply) const

Ret ret = muse::make_ok();

if (reply->error() != QNetworkReply::NoError) {
if (reply->error() == QNetworkReply::TimeoutError) {
ret = make_ret(Err::Timeout);
} else if (reply->error() == QNetworkReply::OperationCanceledError) {
ret = make_ret(Err::Abort);
} else if (reply->error() != QNetworkReply::NoError) {
ret.setCode(static_cast<int>(Err::NetworkError));
}

Expand All @@ -315,17 +283,3 @@ Ret NetworkManager::errorFromReply(const QNetworkReply* reply) const

return ret;
}

String NetworkManager::requestTypeToString(RequestType type)
{
switch (type) {
case GET_REQUEST: return u"GET";
case HEAD_REQUEST: return u"HEAD";
case POST_REQUEST: return u"POST";
case PUT_REQUEST: return u"PUT";
case PATCH_REQUEST: return u"PATCH";
case DELETE_REQUEST: return u"DELETE";
}

return String();
}
8 changes: 1 addition & 7 deletions src/framework/network/internal/networkmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,22 +76,16 @@ class NetworkManager : public QObject, public INetworkManager, public Injectable
bool openDevice(QIODevice* device, QIODevice::OpenModeFlag flags);
void closeDevice(QIODevice* device);

bool isAborted() const;

void prepareReplyReceive(QNetworkReply* reply, IncomingDevice* incomingData);
void prepareReplyTransmit(QNetworkReply* reply);

Ret waitForReplyFinished(QNetworkReply* reply, int timeoutMs);
Ret waitForReplyFinished(QNetworkReply* reply);
Ret errorFromReply(const QNetworkReply* reply) const;

static String requestTypeToString(RequestType type);

QNetworkAccessManager* m_manager = nullptr;
IncomingDevice* m_incomingData = nullptr;
QNetworkReply* m_reply = nullptr;
Progress m_progress;

bool m_isAborted = false;
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/framework/update/internal/updatescenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ muse::async::Promise<Ret> UpdateScenario::checkForUpdate(bool manual)

const bool noUpdate = res.ret.code() == static_cast<int>(Err::NoUpdate);
if (!noUpdate && !res.ret) {
LOGE() << "Unable to check for update, error: " << res.ret.toString();
LOGE() << "Unable to check for app update, error: " << res.ret.toString();
ret = muse::make_ret(Ret::Code::UnknownError);

if (manual) {
Expand Down
3 changes: 2 additions & 1 deletion src/musesounds/internal/musesamplercheckupdatescenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void MuseSamplerCheckUpdateScenario::checkAndShowUpdateIfNeed()
return;
}

LOGI() << "Checking for MuseSampler update...";
m_alreadyChecked = true;

if (service()->incompatibleLocalVersion()) {
Expand All @@ -47,7 +48,7 @@ void MuseSamplerCheckUpdateScenario::checkAndShowUpdateIfNeed()
auto promise = service()->checkForUpdate();
promise.onResolve(this, [this](const muse::RetVal<bool>& res) {
if (!res.ret) {
LOGE() << res.ret.toString();
LOGE() << "Unable to check for MuseSampler update: " << res.ret.toString();
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/musesounds/internal/musesoundscheckupdatescenario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ muse::async::Promise<Ret> MuseSoundsCheckUpdateScenario::checkForUpdate(bool man
};

if (!res.ret) {
LOGE() << "Unable to check for update, error: " << res.ret.toString();
LOGE() << "Unable to check for MuseSounds update, error: " << res.ret.toString();
ret = muse::make_ret(Ret::Code::UnknownError);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Rectangle {
}

onCloseRequested: {
notationSwitchModel.closeNotation(index)
Qt.callLater(notationSwitchModel.closeNotation, index)
}

onContextMenuItemsRequested: {
Expand Down
Loading