1 /*************************************************************************** 2 ** ** 3 ** Polyphone, a soundfont editor ** 4 ** Copyright (C) 2013-2019 Davy Triponney ** 5 ** ** 6 ** This program is free software: you can redistribute it and/or modify ** 7 ** it under the terms of the GNU General Public License as published by ** 8 ** the Free Software Foundation, either version 3 of the License, or ** 9 ** (at your option) any later version. ** 10 ** ** 11 ** This program is distributed in the hope that it will be useful, ** 12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** 13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** 14 ** GNU General Public License for more details. ** 15 ** ** 16 ** You should have received a copy of the GNU General Public License ** 17 ** along with this program. If not, see http://www.gnu.org/licenses/. ** 18 ** ** 19 **************************************************************************** 20 ** Author: Davy Triponney ** 21 ** Website/Contact: https://www.polyphone-soundfonts.com ** 22 ** Date: 01.01.2013 ** 23 ***************************************************************************/ 24 25 #ifndef USERMANAGER_H 26 #define USERMANAGER_H 27 28 #include <QObject> 29 #include <QMutex> 30 class UrlReaderJson; 31 32 class UserManager: public QObject 33 { 34 Q_OBJECT 35 36 public: 37 enum ConnectionState 38 { 39 DISCONNECTED, 40 PENDING, 41 CONNECTED, 42 CONNECTED_PREMIUM, 43 CONNECTED_ADMIN, 44 BANNED, 45 FAILED 46 }; 47 48 // Singleton: get the instance of the object and finally kill it 49 static UserManager * getInstance(); 50 static void kill(); 51 52 /// Initialize the connection 53 void login(); 54 55 /// Cut the connection 56 void logout(); 57 58 /// Get the current state 59 ConnectionState getConnectionState(); 60 61 /// Get the error if the state is FAILED 62 QString error(); 63 64 /// Get the current user name getUsername()65 QString getUsername() { return _username; } 66 67 /// Get the current user id getUserId()68 int getUserId() { return _userId; } 69 70 signals: 71 void connectionStateChanged(UserManager::ConnectionState state); 72 73 private slots: 74 void userDataAvailable(QString error); 75 76 private: 77 UserManager(); 78 ~UserManager(); 79 80 ConnectionState _connectionState; 81 QString _error; 82 QMutex _mutex; 83 UrlReaderJson * _userReaderJson; 84 QString _username; 85 int _userId; 86 static UserManager * s_instance; 87 }; 88 89 #endif // USERMANAGER_H 90