MuseScore  3.4
Music composition and notation
loginmanager.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2014 Werner Schweer
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENCE.GPL
11 //=============================================================================
12 
13 #ifndef __LOGINMANAGER_H__
14 #define __LOGINMANAGER_H__
15 
16 #include "config.h"
17 
18 namespace Ms {
19 
20 class ApiRequest;
21 
22 //---------------------------------------------------------
23 // LoginManager
24 //---------------------------------------------------------
25 
26 class LoginManager : public QObject
27  {
28  Q_OBJECT
29 
30  enum class RequestType
31  {
32  LOGIN,
38  };
39 
40  static constexpr int MAX_UPLOAD_TRY_COUNT = 5;
41  static constexpr int MAX_REFRESH_LOGIN_RETRY_COUNT = 2;
42 
43  QNetworkAccessManager* _networkManager;
44 
45  QAction* _uploadAudioMenuAction = nullptr;
46  QString _accessToken;
47  QString _refreshToken;
48  QString _userName;
49  QUrl _avatar;
50  int _uid = -1;
51 
53 
54  QString _mediaUrl;
55  QFile* _mp3File;
56  int _uploadTryCount = 0;
57 
58  QProgressDialog* _progressDialog;
59 
61  void handleReply(QNetworkReply*, RequestType);
62  static QString getErrorString(QNetworkReply*, const QJsonObject&);
63 
64  void onGetUserReply(QNetworkReply* reply, int code, const QJsonObject& replyContent);
65  void onLoginReply(QNetworkReply* reply, int code, const QJsonObject& replyContent);
66  void onLoginRefreshReply(QNetworkReply* reply, int code, const QJsonObject& replyContent);
67  void onUploadReply(QNetworkReply* reply, int code, const QJsonObject& replyContent);
68  void onGetScoreInfoReply(QNetworkReply* reply, int code, const QJsonObject& replyContent);
69  void onGetMediaUrlReply(QNetworkReply* reply, int code, const QJsonObject& replyContent);
70 
72 
73  signals:
74  void loginError(const QString& error);
75  void loginSuccess();
76  void getUserError(const QString& error);
77  void getUserSuccess();
78  void getScoreError(const QString& error);
79  void getScoreSuccess(const QString &title, const QString &description, bool priv, const QString& license, const QString& tags, const QString& url);
80  void uploadError(const QString& error);
81  void uploadSuccess(const QString& url, const QString& nid, const QString& vid);
82  void tryLoginSuccess();
83  void mediaUploadSuccess();
84 
85  private slots:
86  void uploadMedia();
87  void mediaUploadFinished();
88  void mediaUploadProgress(qint64, qint64);
89 
90  void onTryLoginSuccess();
91  void onTryLoginError(const QString&);
92 
93  public slots:
94  void tryLogin();
95 
96  public:
97  LoginManager(QAction* uploadAudioMenuAction, QObject* parent = 0);
98  void login(QString login, QString password);
99 #ifdef USE_WEBENGINE
100  void loginInteractive();
101 #endif
102  void upload(const QString& path, int nid, const QString& title);
103  void updateScoreData(const QString& nid, bool newScore);
104  bool hasAccessToken();
105  void getUser();
106  void getScoreInfo(int nid);
107  void getMediaUrl(const QString& nid, const QString& vid, const QString& format);
108 
109  bool save();
110  bool load();
111 
112  bool logout();
113 
114  const QString& userName() const { return _userName; }
115  int uid() const { return _uid; }
116  const QUrl& avatar() const { return _avatar; }
117  };
118 }
119 
120 #endif
121 
void upload(const QString &path, int nid, const QString &title)
Definition: loginmanager.cpp:704
void onGetMediaUrlReply(QNetworkReply *reply, int code, const QJsonObject &replyContent)
Definition: loginmanager.cpp:603
ApiRequest * buildLoginRefreshRequest() const
Definition: loginmanager.cpp:427
void getScoreInfo(int nid)
Definition: loginmanager.cpp:525
QString _userName
Definition: loginmanager.h:48
LoginManager(QAction *uploadAudioMenuAction, QObject *parent=0)
Definition: loginmanager.cpp:154
void onLoginRefreshReply(QNetworkReply *reply, int code, const QJsonObject &replyContent)
Definition: loginmanager.cpp:462
static constexpr int MAX_UPLOAD_TRY_COUNT
Definition: loginmanager.h:40
void onGetScoreInfoReply(QNetworkReply *reply, int code, const QJsonObject &replyContent)
Definition: loginmanager.cpp:549
void mediaUploadFinished()
Definition: loginmanager.cpp:660
void onLoginReply(QNetworkReply *reply, int code, const QJsonObject &replyContent)
Definition: loginmanager.cpp:442
bool save()
Definition: loginmanager.cpp:169
void getUser()
Definition: loginmanager.cpp:481
bool hasAccessToken()
Definition: loginmanager.cpp:805
Definition: loginmanager_p.h:79
QString _updateScoreDataPath
Definition: loginmanager.h:52
void mediaUploadProgress(qint64, qint64)
Definition: loginmanager.cpp:691
QString _accessToken
Definition: loginmanager.h:46
Definition: loginmanager.h:26
bool logout()
Definition: loginmanager.cpp:814
void getScoreSuccess(const QString &title, const QString &description, bool priv, const QString &license, const QString &tags, const QString &url)
const QUrl & avatar() const
Definition: loginmanager.h:116
void tryLoginSuccess()
static QString getErrorString(QNetworkReply *, const QJsonObject &)
Definition: loginmanager.cpp:289
static constexpr int MAX_REFRESH_LOGIN_RETRY_COUNT
Definition: loginmanager.h:41
int _uid
Definition: loginmanager.h:50
void mediaUploadSuccess()
bool load()
Definition: loginmanager.cpp:189
void getScoreError(const QString &error)
QProgressDialog * _progressDialog
Definition: loginmanager.h:58
QNetworkAccessManager * _networkManager
Definition: loginmanager.h:43
void uploadSuccess(const QString &url, const QString &nid, const QString &vid)
RequestType
Definition: loginmanager.h:30
void loginError(const QString &error)
void updateScoreData(const QString &nid, bool newScore)
Definition: loginmanager.cpp:776
Definition: aeolus.cpp:26
void tryLogin()
Definition: loginmanager.cpp:304
void uploadMedia()
Definition: loginmanager.cpp:629
QString _refreshToken
Definition: loginmanager.h:47
QFile * _mp3File
Definition: loginmanager.h:55
QUrl _avatar
Definition: loginmanager.h:49
int _uploadTryCount
Definition: loginmanager.h:56
void uploadError(const QString &error)
void getMediaUrl(const QString &nid, const QString &vid, const QString &format)
Definition: loginmanager.cpp:583
void onReplyFinished(ApiRequest *, RequestType)
Definition: loginmanager.cpp:207
void handleReply(QNetworkReply *, RequestType)
Definition: loginmanager.cpp:248
QString _mediaUrl
Definition: loginmanager.h:54
void onUploadReply(QNetworkReply *reply, int code, const QJsonObject &replyContent)
Definition: loginmanager.cpp:754
QAction * _uploadAudioMenuAction
Definition: loginmanager.h:45
const QString & userName() const
Definition: loginmanager.h:114
void onGetUserReply(QNetworkReply *reply, int code, const QJsonObject &replyContent)
Definition: loginmanager.cpp:504
void onTryLoginError(const QString &)
Definition: loginmanager.cpp:327
void getUserError(const QString &error)
int uid() const
Definition: loginmanager.h:115
void login(QString login, QString password)
Definition: loginmanager.cpp:405
void onTryLoginSuccess()
Definition: loginmanager.cpp:316