1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2014 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================
#ifndef __LOGINMANAGER_H__
#define __LOGINMANAGER_H__
#include "config.h"
namespace Ms {
class ApiRequest;
//---------------------------------------------------------
// LoginManager
//---------------------------------------------------------
class LoginManager : public QObject
{
Q_OBJECT
enum class RequestType
{
LOGIN,
LOGIN_REFRESH,
GET_USER_INFO,
GET_SCORE_INFO,
UPLOAD_SCORE,
GET_MEDIA_URL,
};
static constexpr int MAX_UPLOAD_TRY_COUNT = 5;
static constexpr int MAX_REFRESH_LOGIN_RETRY_COUNT = 2;
QNetworkAccessManager* _networkManager;
QAction* _uploadAudioMenuAction = nullptr;
QString _accessToken;
QString _refreshToken;
QString _userName;
int _uid = -1;
QString _mediaUrl;
QFile* _mp3File;
int _uploadTryCount = 0;
QProgressDialog* _progressDialog;
void onReplyFinished(ApiRequest*, RequestType);
void handleReply(QNetworkReply*, RequestType);
static QString getErrorString(QNetworkReply*, const QJsonObject&);
void onGetUserReply(QNetworkReply* reply, int code, const QJsonObject& replyContent);
void onLoginReply(QNetworkReply* reply, int code, const QJsonObject& replyContent);
void onLoginRefreshReply(QNetworkReply* reply, int code, const QJsonObject& replyContent);
void onUploadReply(QNetworkReply* reply, int code, const QJsonObject& replyContent);
void onGetScoreInfoReply(QNetworkReply* reply, int code, const QJsonObject& replyContent);
void onGetMediaUrlReply(QNetworkReply* reply, int code, const QJsonObject& replyContent);
ApiRequest* buildLoginRefreshRequest() const;
signals:
void loginError(const QString& error);
void loginSuccess();
void getUserError(const QString& error);
void getUserSuccess();
void getScoreError(const QString& error);
void getScoreSuccess(const QString &title, const QString &description, bool priv, const QString& license, const QString& tags, const QString& url);
void uploadError(const QString& error);
void uploadSuccess(const QString& url, const QString& nid, const QString& vid);
void tryLoginSuccess();
void displaySuccess();
private slots:
void uploadMedia();
void mediaUploadFinished();
void mediaUploadProgress(qint64, qint64);
void onTryLoginSuccess();
void onTryLoginError(const QString&);
public slots:
void tryLogin();
public:
LoginManager(QAction* uploadAudioMenuAction, QObject* parent = 0);
void login(QString login, QString password);
#ifdef USE_WEBENGINE
void loginInteractive();
#endif
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();
void getUser();
void getScoreInfo(int nid);
void getMediaUrl(const QString& nid, const QString& vid, const QString& format);
bool save();
bool load();
bool logout();
QString userName() { return _userName; }
int uid() { return _uid; }
};
}
#endif
|