Skip to content

Commit

Permalink
fix #279328: uploading custom audio failed
Browse files Browse the repository at this point in the history
Reapplied a843cb4

Changed setWindowModality() for upload progress dialog to Qt::NonModal. This fixes glitch which blocks both async processes put() request and uploadProgress() call.

I could not reproduce the case on simple project, so the problem is in MuseScore event processing itself.

See Qt reference: "Warning: If the progress dialog is modal (see QProgressDialog::QProgressDialog()), setValue() calls QApplication::processEvents(), so take care that this does not cause undesirable re-entrancy in your code. For example, don't use a QProgressDialog inside a paintEvent()!"

Disable "Upload Score" menu item when uploading custom audio

Reapplied c7e4130

To prevent uploading different scores at the same time with slow internet connection speed.
  • Loading branch information
anatoly-os committed Dec 12, 2018
1 parent 01e2f04 commit 20b6e83
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 25 deletions.
10 changes: 7 additions & 3 deletions mscore/loginmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ static const char* MUSESCORE_HOST = "api.musescore.com";
// LoginManager
//---------------------------------------------------------

LoginManager::LoginManager(QObject* parent)
: QObject(parent)
LoginManager::LoginManager(QAction* uploadAudioMenuAction, QObject* parent)
: QObject(parent),
_uploadAudioMenuAction(uploadAudioMenuAction)
{
_oauthManager = new KQOAuthManager(this);
connect(_oauthManager, SIGNAL(accessTokenReceived(QString, QString)),
Expand Down Expand Up @@ -59,7 +60,7 @@ LoginManager::LoginManager(QObject* parent)
load();
_progressDialog = new QProgressDialog(mscore);
_progressDialog->setWindowFlags(Qt::WindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowTitleHint));
_progressDialog->setWindowModality(Qt::ApplicationModal);
_progressDialog->setWindowModality(Qt::NonModal);
_progressDialog->reset(); // required for Qt 5.5, see QTBUG-47042
}

Expand Down Expand Up @@ -420,6 +421,7 @@ void LoginManager::uploadMedia()
{
if (_mediaUrl.isEmpty()) {
_progressDialog->hide();
_uploadAudioMenuAction->setEnabled(true);
return;
}
if (!_mp3File->exists()) {
Expand All @@ -434,6 +436,7 @@ void LoginManager::uploadMedia()
_progressDialog->setCancelButtonText(tr("Cancel"));
_progressDialog->show();
_uploadTryCount++;
_uploadAudioMenuAction->setEnabled(false);
QNetworkReply *reply = mscore->networkManager()->put(request, _mp3File);
connect(_progressDialog, SIGNAL(canceled()), reply, SLOT(abort()));
connect(reply, SIGNAL(finished()), this, SLOT(mediaUploadFinished()));
Expand All @@ -447,6 +450,7 @@ void LoginManager::uploadMedia()

void LoginManager::mediaUploadFinished()
{
_uploadAudioMenuAction->setEnabled(true);
QNetworkReply* reply = static_cast<QNetworkReply*>(QObject::sender());
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QNetworkReply::NetworkError e = reply->error();
Expand Down
5 changes: 3 additions & 2 deletions mscore/loginmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class LoginManager : public QObject

static const int MAX_UPLOAD_TRY_COUNT = 5;

KQOAuthManager* _oauthManager;
KQOAuthManager* _oauthManager = nullptr;
QAction* _uploadAudioMenuAction = nullptr;
QString _consumerKey = 0;
QString _consumerSecret = 0;
QString _accessToken = 0;
Expand Down Expand Up @@ -73,7 +74,7 @@ class LoginManager : public QObject
void tryLogin();

public:
LoginManager(QObject* parent = 0);
LoginManager(QAction* uploadAudioMenuAction, QObject* parent = 0);
void login(QString login, QString password);
void upload(const QString& path, int nid, const QString& title, const QString& description, const QString& priv, const QString& license, const QString& tags, const QString& changes);
bool hasAccessToken();
Expand Down
26 changes: 6 additions & 20 deletions mscore/musescore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ static constexpr double SCALE_MAX = 16.0;
static constexpr double SCALE_MIN = 0.05;
static constexpr double SCALE_STEP = 1.7;

static const char* saveOnlineMenuItem = "file-save-online";
//---------------------------------------------------------
// cmdInsertMeasure
//---------------------------------------------------------
Expand Down Expand Up @@ -1014,24 +1015,6 @@ MuseScore::MuseScore()
pluginManager = new PluginManager(0);
#endif

if (!converterMode && !pluginMode) {
_loginManager = new LoginManager(this);
#if 0
// initialize help engine
QString lang = mscore->getLocaleISOCode();
if (lang == "en_US") // HACK
lang = "en";

QString s = getSharePath() + "manual/doc_" + lang + ".qhc";
_helpEngine = new QHelpEngine(s, this);
if (!_helpEngine->setupData()) {
qDebug("cannot setup data for help engine: %s", qPrintable(_helpEngine->error()));
delete _helpEngine;
_helpEngine = 0;
}
#endif
}

_positionLabel = new QLabel;
_positionLabel->setObjectName("decoration widget"); // this prevents animations

Expand Down Expand Up @@ -1283,7 +1266,7 @@ MuseScore::MuseScore()
"file-save-as",
"file-save-a-copy",
"file-save-selection",
"file-save-online",
saveOnlineMenuItem,
"file-export",
"file-part-export",
"file-import-pdf",
Expand Down Expand Up @@ -1905,6 +1888,9 @@ MuseScore::MuseScore()
#endif
connect(this, SIGNAL(musescoreWindowWasShown()), this, SLOT(checkForUpdates()),
Qt::ConnectionType(Qt::QueuedConnection | Qt::UniqueConnection));

if (!converterMode && !pluginMode)
_loginManager = new LoginManager(getAction(saveOnlineMenuItem), this);
}

MuseScore::~MuseScore()
Expand Down Expand Up @@ -5760,7 +5746,7 @@ void MuseScore::cmd(QAction* a, const QString& cmd)
loadFiles();
else if (cmd == "file-save")
saveFile();
else if (cmd == "file-save-online")
else if (cmd == saveOnlineMenuItem)
showUploadScoreDialog();
else if (cmd == "file-export")
exportFile();
Expand Down

0 comments on commit 20b6e83

Please sign in to comment.