Formatting
This commit is contained in:
@@ -11,33 +11,35 @@
|
|||||||
|
|
||||||
namespace Managers
|
namespace Managers
|
||||||
{
|
{
|
||||||
class ActionManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ActionManager(char**, int);
|
|
||||||
|
|
||||||
Models::IcarusAction retrieveIcarusAction() const;
|
class ActionManager
|
||||||
private:
|
{
|
||||||
constexpr std::array<const char*, 12> supportedFlags() noexcept;
|
public:
|
||||||
constexpr std::array<const char*, 4> supportedActions() noexcept;
|
ActionManager(char**, int);
|
||||||
|
|
||||||
bool isNumber(const std::string_view) noexcept;
|
Models::IcarusAction retrieveIcarusAction() const;
|
||||||
|
private:
|
||||||
|
constexpr std::array<const char*, 12> supportedFlags() noexcept;
|
||||||
|
constexpr std::array<const char*, 4> supportedActions() noexcept;
|
||||||
|
|
||||||
void initialize();
|
bool isNumber(const std::string_view) noexcept;
|
||||||
void validateFlags();
|
|
||||||
|
|
||||||
std::vector<std::string> parsedFlags();
|
void initialize();
|
||||||
|
void validateFlags();
|
||||||
|
|
||||||
void printAction() noexcept;
|
std::vector<std::string> parsedFlags();
|
||||||
void printFlags() noexcept;
|
|
||||||
|
|
||||||
std::string action;
|
void printAction() noexcept;
|
||||||
|
void printFlags() noexcept;
|
||||||
std::vector<Models::Flags> flags;
|
|
||||||
|
std::string action;
|
||||||
|
|
||||||
|
std::vector<Models::Flags> flags;
|
||||||
|
|
||||||
|
char **params;
|
||||||
|
int paramCount;
|
||||||
|
};
|
||||||
|
|
||||||
char **params;
|
|
||||||
int paramCount;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -10,40 +10,42 @@
|
|||||||
|
|
||||||
namespace Managers
|
namespace Managers
|
||||||
{
|
{
|
||||||
class CommitManager
|
|
||||||
|
class CommitManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CommitManager(Models::IcarusAction&);
|
||||||
|
|
||||||
|
void commitAction();
|
||||||
|
|
||||||
|
enum class RetrieveTypes
|
||||||
{
|
{
|
||||||
public:
|
songs
|
||||||
CommitManager(Models::IcarusAction&);
|
|
||||||
|
|
||||||
void commitAction();
|
|
||||||
|
|
||||||
enum class RetrieveTypes
|
|
||||||
{
|
|
||||||
songs
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
|
||||||
enum class ActionValues;
|
|
||||||
|
|
||||||
std::map<std::string, ActionValues> mapActions() noexcept;
|
|
||||||
|
|
||||||
Models::Token parseToken(Models::API);
|
|
||||||
|
|
||||||
void deleteSong();
|
|
||||||
void downloadSong();
|
|
||||||
void retrieveObjects();
|
|
||||||
void uploadSong();
|
|
||||||
|
|
||||||
enum class ActionValues
|
|
||||||
{
|
|
||||||
deleteAct,
|
|
||||||
downloadAct,
|
|
||||||
retrieveAct,
|
|
||||||
uploadAct
|
|
||||||
};
|
|
||||||
|
|
||||||
Models::IcarusAction icaAction;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
enum class ActionValues;
|
||||||
|
|
||||||
|
std::map<std::string, ActionValues> mapActions() noexcept;
|
||||||
|
|
||||||
|
Models::Token parseToken(Models::API);
|
||||||
|
|
||||||
|
void deleteSong();
|
||||||
|
void downloadSong();
|
||||||
|
void retrieveObjects();
|
||||||
|
void uploadSong();
|
||||||
|
|
||||||
|
enum class ActionValues
|
||||||
|
{
|
||||||
|
deleteAct,
|
||||||
|
downloadAct,
|
||||||
|
retrieveAct,
|
||||||
|
uploadAct
|
||||||
|
};
|
||||||
|
|
||||||
|
Models::IcarusAction icaAction;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -5,25 +5,27 @@
|
|||||||
|
|
||||||
namespace Managers
|
namespace Managers
|
||||||
{
|
{
|
||||||
class FileManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
FileManager();
|
|
||||||
FileManager(std::string);
|
|
||||||
|
|
||||||
void saveFile(std::string);
|
class FileManager
|
||||||
void modifyFilePath(std::string);
|
{
|
||||||
|
public:
|
||||||
|
FileManager();
|
||||||
|
FileManager(std::string);
|
||||||
|
|
||||||
char* retrieveFileBuffer() const;
|
void saveFile(std::string);
|
||||||
int retrieveFileBufferLength() const;
|
void modifyFilePath(std::string);
|
||||||
private:
|
|
||||||
void readFile();
|
char* retrieveFileBuffer() const;
|
||||||
|
int retrieveFileBufferLength() const;
|
||||||
|
private:
|
||||||
|
void readFile();
|
||||||
|
|
||||||
|
std::string filePath;
|
||||||
|
char* fileBuffer;
|
||||||
|
bool fileRead;
|
||||||
|
int fileBufferLength;
|
||||||
|
};
|
||||||
|
|
||||||
std::string filePath;
|
|
||||||
char* fileBuffer;
|
|
||||||
bool fileRead;
|
|
||||||
int fileBufferLength;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -7,17 +7,19 @@
|
|||||||
|
|
||||||
namespace Managers
|
namespace Managers
|
||||||
{
|
{
|
||||||
class TokenManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
TokenManager(const Models::User&);
|
|
||||||
TokenManager(const Models::User&, Models::API&);
|
|
||||||
|
|
||||||
Models::Token requestToken();
|
class TokenManager
|
||||||
private:
|
{
|
||||||
Models::API api;
|
public:
|
||||||
Models::User user;
|
TokenManager(const Models::User&);
|
||||||
};
|
TokenManager(const Models::User&, Models::API&);
|
||||||
|
|
||||||
|
Models::Token requestToken();
|
||||||
|
private:
|
||||||
|
Models::API api;
|
||||||
|
Models::User user;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -8,19 +8,21 @@
|
|||||||
|
|
||||||
namespace Managers
|
namespace Managers
|
||||||
{
|
{
|
||||||
class UserManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
UserManager(Models::User);
|
|
||||||
UserManager(const Models::IcarusAction);
|
|
||||||
|
|
||||||
Models::User retrieveUser() const;
|
class UserManager
|
||||||
private:
|
{
|
||||||
void parseUserFromActions();
|
public:
|
||||||
|
UserManager(Models::User);
|
||||||
|
UserManager(const Models::IcarusAction);
|
||||||
|
|
||||||
|
Models::User retrieveUser() const;
|
||||||
|
private:
|
||||||
|
void parseUserFromActions();
|
||||||
|
|
||||||
|
Models::User user;
|
||||||
|
Models::IcarusAction icaAction;
|
||||||
|
};
|
||||||
|
|
||||||
Models::User user;
|
|
||||||
Models::IcarusAction icaAction;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -5,12 +5,15 @@
|
|||||||
|
|
||||||
namespace Models
|
namespace Models
|
||||||
{
|
{
|
||||||
struct API
|
|
||||||
{
|
class API
|
||||||
std::string url;
|
{
|
||||||
std::string endpoint;
|
public:
|
||||||
std::string version;
|
std::string url;
|
||||||
};
|
std::string endpoint;
|
||||||
|
std::string version;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -5,11 +5,13 @@
|
|||||||
|
|
||||||
namespace Models
|
namespace Models
|
||||||
{
|
{
|
||||||
struct Flags
|
|
||||||
{
|
struct Flags
|
||||||
std::string flag;
|
{
|
||||||
std::string value;
|
std::string flag;
|
||||||
};
|
std::string value;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -8,11 +8,13 @@
|
|||||||
|
|
||||||
namespace Models
|
namespace Models
|
||||||
{
|
{
|
||||||
struct IcarusAction
|
|
||||||
{
|
struct IcarusAction
|
||||||
std::string action;
|
{
|
||||||
std::vector<Flags> flags;
|
std::string action;
|
||||||
};
|
std::vector<Flags> flags;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+15
-13
@@ -6,19 +6,21 @@
|
|||||||
|
|
||||||
namespace Models
|
namespace Models
|
||||||
{
|
{
|
||||||
struct Song
|
|
||||||
{
|
struct Song
|
||||||
int id;
|
{
|
||||||
std::string title;
|
int id;
|
||||||
std::string artist;
|
std::string title;
|
||||||
std::string album;
|
std::string artist;
|
||||||
std::string genre;
|
std::string album;
|
||||||
int year;
|
std::string genre;
|
||||||
int duration;
|
int year;
|
||||||
int track;
|
int duration;
|
||||||
std::string data;
|
int track;
|
||||||
std::string songPath;
|
std::string data;
|
||||||
};
|
std::string songPath;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -5,12 +5,14 @@
|
|||||||
|
|
||||||
namespace Models
|
namespace Models
|
||||||
{
|
{
|
||||||
struct Token
|
|
||||||
{
|
struct Token
|
||||||
std::string accessToken;
|
{
|
||||||
std::string tokenType;
|
std::string accessToken;
|
||||||
int expiration;
|
std::string tokenType;
|
||||||
};
|
int expiration;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,11 +6,13 @@
|
|||||||
|
|
||||||
namespace Models
|
namespace Models
|
||||||
{
|
{
|
||||||
struct UploadForm
|
|
||||||
{
|
struct UploadForm
|
||||||
std::string url;
|
{
|
||||||
std::string filePath;
|
std::string url;
|
||||||
};
|
std::string filePath;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -5,11 +5,13 @@
|
|||||||
|
|
||||||
namespace Models
|
namespace Models
|
||||||
{
|
{
|
||||||
struct User
|
|
||||||
{
|
struct User
|
||||||
std::string username;
|
{
|
||||||
std::string password;
|
std::string username;
|
||||||
};
|
std::string password;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+12
-10
@@ -6,18 +6,20 @@
|
|||||||
|
|
||||||
namespace Parsers
|
namespace Parsers
|
||||||
{
|
{
|
||||||
class APIParser
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
APIParser(Models::IcarusAction);
|
|
||||||
|
|
||||||
Models::API retrieveAPI() const;
|
class APIParser
|
||||||
private:
|
{
|
||||||
void parseAPI();
|
public:
|
||||||
|
APIParser(Models::IcarusAction);
|
||||||
|
|
||||||
|
Models::API retrieveAPI() const;
|
||||||
|
private:
|
||||||
|
void parseAPI();
|
||||||
|
|
||||||
|
Models::API api;
|
||||||
|
Models::IcarusAction icaAct;
|
||||||
|
};
|
||||||
|
|
||||||
Models::API api;
|
|
||||||
Models::IcarusAction icaAct;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -9,15 +9,17 @@
|
|||||||
|
|
||||||
namespace Syncers
|
namespace Syncers
|
||||||
{
|
{
|
||||||
class Delete : SyncerBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Delete(Models::API);
|
|
||||||
|
|
||||||
void deleteSong(const Models::Token, Models::Song);
|
class Delete : SyncerBase
|
||||||
private:
|
{
|
||||||
std::string retrieveUrl(Models::Song);
|
public:
|
||||||
};
|
Delete(Models::API);
|
||||||
|
|
||||||
|
void deleteSong(const Models::Token, Models::Song);
|
||||||
|
private:
|
||||||
|
std::string retrieveUrl(Models::Song);
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+14
-12
@@ -12,20 +12,22 @@
|
|||||||
|
|
||||||
namespace Syncers
|
namespace Syncers
|
||||||
{
|
{
|
||||||
class Download : SyncerBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Download();
|
|
||||||
Download(Models::API);
|
|
||||||
Download(std::string);
|
|
||||||
|
|
||||||
void downloadSong(const Models::Token token, Models::Song);
|
class Download : SyncerBase
|
||||||
private:
|
{
|
||||||
std::string retrieveUrl(Models::Song);
|
public:
|
||||||
|
Download();
|
||||||
|
Download(Models::API);
|
||||||
|
Download(std::string);
|
||||||
|
|
||||||
|
void downloadSong(const Models::Token token, Models::Song);
|
||||||
|
private:
|
||||||
|
std::string retrieveUrl(Models::Song);
|
||||||
|
|
||||||
|
std::string downloadFilePath;
|
||||||
|
void saveSong(Models::Song&);
|
||||||
|
};
|
||||||
|
|
||||||
std::string downloadFilePath;
|
|
||||||
void saveSong(Models::Song&);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -8,19 +8,21 @@
|
|||||||
|
|
||||||
namespace Syncers
|
namespace Syncers
|
||||||
{
|
{
|
||||||
class RetrieveRecords: public SyncerBase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
RetrieveRecords();
|
|
||||||
RetrieveRecords(Models::API, Models::Token);
|
|
||||||
|
|
||||||
void retrieve(Managers::CommitManager::RetrieveTypes);
|
class RetrieveRecords: public SyncerBase
|
||||||
private:
|
{
|
||||||
void fetchSongs();
|
public:
|
||||||
|
RetrieveRecords();
|
||||||
|
RetrieveRecords(Models::API, Models::Token);
|
||||||
|
|
||||||
|
void retrieve(Managers::CommitManager::RetrieveTypes);
|
||||||
|
private:
|
||||||
|
void fetchSongs();
|
||||||
|
|
||||||
|
Models::API api;
|
||||||
|
Models::Token token;
|
||||||
|
};
|
||||||
|
|
||||||
Models::API api;
|
|
||||||
Models::Token token;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -7,21 +7,23 @@
|
|||||||
|
|
||||||
namespace Syncers
|
namespace Syncers
|
||||||
{
|
{
|
||||||
class SyncerBase
|
|
||||||
{
|
|
||||||
protected:
|
|
||||||
Models::API api;
|
|
||||||
const int OK = 200;
|
|
||||||
const int UNAUTHORIZED = 401;
|
|
||||||
const int NOTFOUND = 404;
|
|
||||||
|
|
||||||
enum class Result
|
class SyncerBase
|
||||||
{
|
{
|
||||||
OK = 200,
|
protected:
|
||||||
UNAUTHORIZED = 401,
|
Models::API api;
|
||||||
NOTFOUND = 404
|
const int OK = 200;
|
||||||
};
|
const int UNAUTHORIZED = 401;
|
||||||
|
const int NOTFOUND = 404;
|
||||||
|
|
||||||
|
enum class Result
|
||||||
|
{
|
||||||
|
OK = 200,
|
||||||
|
UNAUTHORIZED = 401,
|
||||||
|
NOTFOUND = 404
|
||||||
};
|
};
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+22
-20
@@ -18,31 +18,33 @@ namespace fs = std::filesystem;
|
|||||||
|
|
||||||
namespace Syncers
|
namespace Syncers
|
||||||
{
|
{
|
||||||
class Upload
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Upload();
|
|
||||||
Upload(Models::API);
|
|
||||||
|
|
||||||
Models::Song uploadSong(const Models::Token&, Models::Song&);
|
class Upload
|
||||||
void uploadSongsFromDirectory(const Models::Token&,
|
{
|
||||||
const std::string&, const bool, bool);
|
public:
|
||||||
private:
|
Upload();
|
||||||
Managers::FileManager fMgr;
|
Upload(Models::API);
|
||||||
Models::API api;
|
|
||||||
Models::Song song;
|
|
||||||
|
|
||||||
std::vector<Models::Song> retrieveAllSongsFromDirectory(const std::string&,
|
Models::Song uploadSong(const Models::Token&, Models::Song&);
|
||||||
bool);
|
void uploadSongsFromDirectory(const Models::Token&,
|
||||||
|
const std::string&, const bool, bool);
|
||||||
|
private:
|
||||||
|
Managers::FileManager fMgr;
|
||||||
|
Models::API api;
|
||||||
|
Models::Song song;
|
||||||
|
|
||||||
std::string retrieveUrl();
|
std::vector<Models::Song> retrieveAllSongsFromDirectory(const std::string&,
|
||||||
|
bool);
|
||||||
|
|
||||||
Models::Song retrieveSongPath(fs::directory_entry&);
|
std::string retrieveUrl();
|
||||||
|
|
||||||
|
Models::Song retrieveSongPath(fs::directory_entry&);
|
||||||
|
|
||||||
|
void printSongDetails();
|
||||||
|
void printSongDetails(std::vector<Models::Song>&);
|
||||||
|
void printJsonData(const nlohmann::json&);
|
||||||
|
};
|
||||||
|
|
||||||
void printSongDetails();
|
|
||||||
void printSongDetails(std::vector<Models::Song>&);
|
|
||||||
void printJsonData(const nlohmann::json&);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+15
-13
@@ -13,22 +13,24 @@
|
|||||||
|
|
||||||
namespace UI
|
namespace UI
|
||||||
{
|
{
|
||||||
class AboutWindow: public QDialog, public CommonWindow
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
|
||||||
AboutWindow(QWidget* parent=0);
|
|
||||||
~AboutWindow() = default;
|
|
||||||
|
|
||||||
private:
|
class AboutWindow: public QDialog, public CommonWindow
|
||||||
void connections();
|
{
|
||||||
void setupWindow();
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
AboutWindow(QWidget* parent=0);
|
||||||
|
~AboutWindow() = default;
|
||||||
|
|
||||||
std::unique_ptr<QLabel> appName;
|
private:
|
||||||
|
void connections();
|
||||||
|
void setupWindow();
|
||||||
|
|
||||||
|
std::unique_ptr<QLabel> appName;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void closeWindow();
|
||||||
|
};
|
||||||
|
|
||||||
private slots:
|
|
||||||
void closeWindow();
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -10,6 +10,9 @@
|
|||||||
#include<QPushButton>
|
#include<QPushButton>
|
||||||
|
|
||||||
|
|
||||||
|
namespace UI
|
||||||
|
{
|
||||||
|
|
||||||
class CommonWindow
|
class CommonWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -24,4 +27,7 @@ protected:
|
|||||||
std::unique_ptr<QVBoxLayout> subLayoutTwoQt;
|
std::unique_ptr<QVBoxLayout> subLayoutTwoQt;
|
||||||
int windowHeight, windowWidth;
|
int windowHeight, windowWidth;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+45
-43
@@ -22,61 +22,63 @@
|
|||||||
|
|
||||||
namespace UI
|
namespace UI
|
||||||
{
|
{
|
||||||
class MainWindow: public QMainWindow, public CommonWindow
|
|
||||||
{
|
class MainWindow: public QMainWindow, public CommonWindow
|
||||||
Q_OBJECT
|
{
|
||||||
public:
|
Q_OBJECT
|
||||||
MainWindow();
|
public:
|
||||||
~MainWindow() = default;
|
MainWindow();
|
||||||
private:
|
~MainWindow() = default;
|
||||||
void configureDownloadSection();
|
private:
|
||||||
void configureUploadSection();
|
void configureDownloadSection();
|
||||||
void configureWindowDimensions();
|
void configureUploadSection();
|
||||||
void configureWindowProperties();
|
void configureWindowDimensions();
|
||||||
void connections();
|
void configureWindowProperties();
|
||||||
void createMenus();
|
void connections();
|
||||||
void setupMainWidget();
|
void createMenus();
|
||||||
void setupMainWindow();
|
void setupMainWidget();
|
||||||
void setupWindowLists();
|
void setupMainWindow();
|
||||||
|
void setupWindowLists();
|
||||||
|
|
||||||
|
|
||||||
std::unique_ptr<QStackedWidget> widgetStack;
|
std::unique_ptr<QStackedWidget> widgetStack;
|
||||||
|
|
||||||
std::unique_ptr<QVBoxLayout> stackLayout;
|
std::unique_ptr<QVBoxLayout> stackLayout;
|
||||||
|
|
||||||
std::unique_ptr<QHBoxLayout> urlPortion;
|
std::unique_ptr<QHBoxLayout> urlPortion;
|
||||||
std::unique_ptr<QHBoxLayout> songPathPortion;
|
std::unique_ptr<QHBoxLayout> songPathPortion;
|
||||||
|
|
||||||
std::unique_ptr<QWidget> mainWidgetQt;
|
std::unique_ptr<QWidget> mainWidgetQt;
|
||||||
std::unique_ptr<QWidget> uploadSongWidgetQt;
|
std::unique_ptr<QWidget> uploadSongWidgetQt;
|
||||||
|
|
||||||
std::unique_ptr<QDockWidget> MainDockWidgetQt;
|
std::unique_ptr<QDockWidget> MainDockWidgetQt;
|
||||||
|
|
||||||
std::unique_ptr<QComboBox> windowComboBox;
|
std::unique_ptr<QComboBox> windowComboBox;
|
||||||
|
|
||||||
std::unique_ptr<QPushButton> uploadSongQt;
|
std::unique_ptr<QPushButton> uploadSongQt;
|
||||||
|
|
||||||
std::unique_ptr<QTextEdit> urlQt;
|
std::unique_ptr<QTextEdit> urlQt;
|
||||||
std::unique_ptr<QTextEdit> sourceFilePathQt;
|
std::unique_ptr<QTextEdit> sourceFilePathQt;
|
||||||
|
|
||||||
std::unique_ptr<QLabel> urlLabel;
|
std::unique_ptr<QLabel> urlLabel;
|
||||||
std::unique_ptr<QLabel> songPath;
|
std::unique_ptr<QLabel> songPath;
|
||||||
|
|
||||||
std::unique_ptr<QMenu> fileMenuQt;
|
std::unique_ptr<QMenu> fileMenuQt;
|
||||||
std::unique_ptr<QMenu> editMenuQt;
|
std::unique_ptr<QMenu> editMenuQt;
|
||||||
std::unique_ptr<QMenu> helpMenuQt;
|
std::unique_ptr<QMenu> helpMenuQt;
|
||||||
|
|
||||||
std::unique_ptr<QAction> closeApplicationQt;
|
std::unique_ptr<QAction> closeApplicationQt;
|
||||||
std::unique_ptr<QAction> aboutApplicationQt;
|
std::unique_ptr<QAction> aboutApplicationQt;
|
||||||
|
|
||||||
|
std::unique_ptr<AboutWindow> aboutWindow;
|
||||||
|
signals:
|
||||||
|
private slots:
|
||||||
|
void uploadSong();
|
||||||
|
void exitApplication();
|
||||||
|
void displaySoftwareInformation();
|
||||||
|
void setCurrentIndex(int);
|
||||||
|
};
|
||||||
|
|
||||||
std::unique_ptr<AboutWindow> aboutWindow;
|
|
||||||
signals:
|
|
||||||
private slots:
|
|
||||||
void uploadSong();
|
|
||||||
void exitApplication();
|
|
||||||
void displaySoftwareInformation();
|
|
||||||
void setCurrentIndex(int);
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,17 +6,19 @@
|
|||||||
|
|
||||||
namespace Utilities
|
namespace Utilities
|
||||||
{
|
{
|
||||||
class Conversions
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Conversions();
|
|
||||||
|
|
||||||
void initializeValues();
|
class Conversions
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Conversions();
|
||||||
|
|
||||||
|
void initializeValues();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void printValue(T);
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void printValue(T);
|
|
||||||
private:
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+107
-106
@@ -16,130 +16,131 @@ using Models::IcarusAction;
|
|||||||
|
|
||||||
namespace Managers
|
namespace Managers
|
||||||
{
|
{
|
||||||
#pragma
|
|
||||||
ActionManager::ActionManager(char **param, int paramCount) :
|
#pragma region Constructors
|
||||||
params(std::move(param)), paramCount(paramCount)
|
ActionManager::ActionManager(char **param, int paramCount) :
|
||||||
{
|
params(std::move(param)), paramCount(paramCount)
|
||||||
initialize();
|
{
|
||||||
}
|
initialize();
|
||||||
#pragma Constructors
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
|
||||||
#pragma
|
#pragma region Functions
|
||||||
IcarusAction ActionManager::retrieveIcarusAction() const
|
IcarusAction ActionManager::retrieveIcarusAction() const
|
||||||
{
|
{
|
||||||
IcarusAction icarusAction;
|
IcarusAction icarusAction;
|
||||||
icarusAction.flags = flags;
|
icarusAction.flags = flags;
|
||||||
icarusAction.action = action;
|
icarusAction.action = action;
|
||||||
|
|
||||||
return icarusAction;
|
return icarusAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
constexpr std::array<const char*, 12> ActionManager::supportedFlags() noexcept
|
constexpr std::array<const char*, 12> ActionManager::supportedFlags() noexcept
|
||||||
{
|
{
|
||||||
constexpr std::array<const char*, 12> allFlags{"-u", "-p", "-t", "-h", "-s",
|
constexpr std::array<const char*, 12> allFlags{"-u", "-p", "-t", "-h", "-s",
|
||||||
"-sd", "-sr", "-d", "-D", "-b", "-rt", "-nc"};
|
"-sd", "-sr", "-d", "-D", "-b", "-rt", "-nc"};
|
||||||
|
|
||||||
return allFlags;
|
return allFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ActionManager::isNumber(string_view val) noexcept
|
bool ActionManager::isNumber(string_view val) noexcept
|
||||||
{
|
{
|
||||||
return !val.empty() && std::find_if(val.begin(),
|
return !val.empty() && std::find_if(val.begin(),
|
||||||
val.end(), [](char c)
|
val.end(), [](char c)
|
||||||
{
|
|
||||||
return !std::isdigit(c);
|
|
||||||
}) == val.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ActionManager::initialize()
|
|
||||||
{
|
|
||||||
validateFlags();
|
|
||||||
|
|
||||||
action = std::move(string{params[1]});
|
|
||||||
transform(action.begin(), action.end(),
|
|
||||||
action.begin(), ::tolower);
|
|
||||||
}
|
|
||||||
void ActionManager::validateFlags()
|
|
||||||
{
|
|
||||||
cout<<"Validating flags"<<endl;
|
|
||||||
|
|
||||||
auto flagVals = parsedFlags();
|
|
||||||
|
|
||||||
Flags flg{};
|
|
||||||
|
|
||||||
auto allSupportedFlags = supportedFlags();
|
|
||||||
|
|
||||||
for (auto flag : flagVals)
|
|
||||||
{
|
{
|
||||||
if (flag.compare("-nc") == 0)
|
return !std::isdigit(c);
|
||||||
{
|
}) == val.end();
|
||||||
flg.flag = flag;
|
}
|
||||||
flags.push_back(flg);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (flag.size() > 3 || isNumber(flag))
|
|
||||||
{
|
|
||||||
flg.value = flag;
|
|
||||||
//cout<<"flag value "<<flg.value<<endl;
|
|
||||||
flags.push_back(flg);
|
|
||||||
flg = Flags{};
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (std::any_of(allSupportedFlags.begin(), allSupportedFlags.end(),
|
void ActionManager::initialize()
|
||||||
[&](const char *val)
|
{
|
||||||
{
|
validateFlags();
|
||||||
return !flag.compare(val);
|
|
||||||
}))
|
action = std::move(string{params[1]});
|
||||||
{
|
transform(action.begin(), action.end(),
|
||||||
//cout<<"flag "<<flag<<endl;
|
action.begin(), ::tolower);
|
||||||
flg.flag = flag;
|
}
|
||||||
}
|
void ActionManager::validateFlags()
|
||||||
else
|
{
|
||||||
{
|
cout<<"Validating flags"<<endl;
|
||||||
cout<<"Flag is not valid"<<endl;
|
|
||||||
exit(1);
|
auto flagVals = parsedFlags();
|
||||||
}
|
|
||||||
|
Flags flg{};
|
||||||
|
|
||||||
|
auto allSupportedFlags = supportedFlags();
|
||||||
|
|
||||||
|
for (auto flag : flagVals)
|
||||||
|
{
|
||||||
|
if (flag.compare("-nc") == 0)
|
||||||
|
{
|
||||||
|
flg.flag = flag;
|
||||||
|
flags.push_back(flg);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
if (flag.size() > 3 || isNumber(flag))
|
||||||
|
|
||||||
vector<string> ActionManager::parsedFlags()
|
|
||||||
{
|
|
||||||
auto parsed = vector<string>();
|
|
||||||
|
|
||||||
for (auto i = 2; i < paramCount; ++i)
|
|
||||||
{
|
{
|
||||||
const std::string flag(std::move(*(params + i)));
|
flg.value = flag;
|
||||||
parsed.push_back(std::move(flag));
|
|
||||||
|
flags.push_back(flg);
|
||||||
|
flg = Flags{};
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parsed;
|
if (std::any_of(allSupportedFlags.begin(), allSupportedFlags.end(),
|
||||||
}
|
[&](const char *val)
|
||||||
|
{
|
||||||
#pragma
|
return !flag.compare(val);
|
||||||
void ActionManager::printAction() noexcept
|
}))
|
||||||
{
|
|
||||||
if (action.empty())
|
|
||||||
{
|
{
|
||||||
printf("Action is empty\n");
|
flg.flag = flag;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cout<<"Action is "<<action<<endl;
|
cout<<"Flag is not valid"<<endl;
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ActionManager::printFlags() noexcept
|
}
|
||||||
{
|
|
||||||
cout<<"\nPrinting flags..."<<endl;
|
vector<string> ActionManager::parsedFlags()
|
||||||
for (auto flag: flags)
|
{
|
||||||
{
|
auto parsed = vector<string>();
|
||||||
cout<<"flag "<<flag.flag<<endl;
|
|
||||||
cout<<"value "<<flag.value<<endl;
|
for (auto i = 2; i < paramCount; ++i)
|
||||||
}
|
{
|
||||||
}
|
const std::string flag(std::move(*(params + i)));
|
||||||
#pragma Testing
|
parsed.push_back(std::move(flag));
|
||||||
#pragma Functions
|
}
|
||||||
|
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma region Testing
|
||||||
|
void ActionManager::printAction() noexcept
|
||||||
|
{
|
||||||
|
if (action.empty())
|
||||||
|
{
|
||||||
|
printf("Action is empty\n");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout<<"Action is "<<action<<endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void ActionManager::printFlags() noexcept
|
||||||
|
{
|
||||||
|
cout<<"\nPrinting flags..."<<endl;
|
||||||
|
for (auto flag: flags)
|
||||||
|
{
|
||||||
|
cout<<"flag "<<flag.flag<<endl;
|
||||||
|
cout<<"value "<<flag.value<<endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#pragma endregion
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+191
-189
@@ -33,197 +33,199 @@ using Syncers::Upload;
|
|||||||
|
|
||||||
namespace Managers
|
namespace Managers
|
||||||
{
|
{
|
||||||
#pragma
|
|
||||||
CommitManager::CommitManager(IcarusAction& icaAct) : icaAction(std::move(icaAct))
|
#pragma region Constructors
|
||||||
{ }
|
CommitManager::CommitManager(IcarusAction& icaAct) : icaAction(std::move(icaAct))
|
||||||
#pragma Constructors
|
{ }
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
|
||||||
#pragma
|
#pragma region Functions
|
||||||
void CommitManager::commitAction()
|
void CommitManager::commitAction()
|
||||||
{
|
{
|
||||||
auto action = icaAction.action;
|
auto action = icaAction.action;
|
||||||
cout<<"Commiting "<<action<<" action"<<endl;
|
cout<<"Commiting "<<action<<" action"<<endl;
|
||||||
switch (mapActions()[action])
|
switch (mapActions()[action])
|
||||||
{
|
|
||||||
case ActionValues::deleteAct:
|
|
||||||
deleteSong();
|
|
||||||
break;
|
|
||||||
case ActionValues::downloadAct:
|
|
||||||
downloadSong();
|
|
||||||
break;
|
|
||||||
case ActionValues::retrieveAct:
|
|
||||||
retrieveObjects();
|
|
||||||
break;
|
|
||||||
case ActionValues::uploadAct:
|
|
||||||
uploadSong();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
enum class ActionValues;
|
|
||||||
|
|
||||||
std::map<std::string, CommitManager::ActionValues>
|
|
||||||
CommitManager::mapActions() noexcept
|
|
||||||
{
|
{
|
||||||
const std::map<std::string, ActionValues> actions{
|
case ActionValues::deleteAct:
|
||||||
{"delete", ActionValues::deleteAct},
|
deleteSong();
|
||||||
{"download", ActionValues::downloadAct},
|
break;
|
||||||
{"retrieve", ActionValues::retrieveAct},
|
case ActionValues::downloadAct:
|
||||||
{"upload", ActionValues::uploadAct}
|
downloadSong();
|
||||||
};
|
break;
|
||||||
|
case ActionValues::retrieveAct:
|
||||||
return actions;
|
retrieveObjects();
|
||||||
|
break;
|
||||||
|
case ActionValues::uploadAct:
|
||||||
|
uploadSong();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Token CommitManager::parseToken(API api)
|
|
||||||
{
|
enum class ActionValues;
|
||||||
cout<<"fetching token"<<endl;
|
|
||||||
UserManager usrMgr{icaAction};
|
std::map<std::string, CommitManager::ActionValues>
|
||||||
auto user = usrMgr.retrieveUser();
|
CommitManager::mapActions() noexcept
|
||||||
|
{
|
||||||
TokenManager tk{user, api};
|
const std::map<std::string, ActionValues> actions{
|
||||||
|
{"delete", ActionValues::deleteAct},
|
||||||
return tk.requestToken();
|
{"download", ActionValues::downloadAct},
|
||||||
}
|
{"retrieve", ActionValues::retrieveAct},
|
||||||
|
{"upload", ActionValues::uploadAct}
|
||||||
void CommitManager::deleteSong()
|
};
|
||||||
{
|
|
||||||
APIParser apiPrs{icaAction};
|
return actions;
|
||||||
auto api = apiPrs.retrieveAPI();
|
}
|
||||||
|
|
||||||
auto token = parseToken(api);
|
|
||||||
|
Token CommitManager::parseToken(API api)
|
||||||
Song song{};
|
{
|
||||||
|
cout<<"fetching token"<<endl;
|
||||||
for (auto arg : icaAction.flags)
|
UserManager usrMgr{icaAction};
|
||||||
{
|
auto user = usrMgr.retrieveUser();
|
||||||
auto flag = arg.flag;
|
|
||||||
auto value = arg.value;
|
TokenManager tk{user, api};
|
||||||
|
|
||||||
if (flag.compare("-D") == 0)
|
return tk.requestToken();
|
||||||
{
|
}
|
||||||
song.id = atoi(value.c_str());
|
|
||||||
}
|
void CommitManager::deleteSong()
|
||||||
}
|
{
|
||||||
|
APIParser apiPrs{icaAction};
|
||||||
Delete del{api};
|
auto api = apiPrs.retrieveAPI();
|
||||||
cout<<"Deleting song..."<<endl;
|
|
||||||
del.deleteSong(token, song);
|
auto token = parseToken(api);
|
||||||
}
|
|
||||||
void CommitManager::downloadSong()
|
Song song{};
|
||||||
{
|
|
||||||
cout<<"Starting downloading process..."<<endl;
|
for (auto arg : icaAction.flags)
|
||||||
|
{
|
||||||
APIParser apiPrs{icaAction};
|
auto flag = arg.flag;
|
||||||
auto api = apiPrs.retrieveAPI();
|
auto value = arg.value;
|
||||||
|
|
||||||
auto token = parseToken(api);
|
if (flag.compare("-D") == 0)
|
||||||
|
{
|
||||||
Song song{};
|
song.id = atoi(value.c_str());
|
||||||
|
}
|
||||||
for (auto arg : icaAction.flags)
|
}
|
||||||
{
|
|
||||||
auto flag = arg.flag;
|
Delete del{api};
|
||||||
auto value = arg.value;
|
cout<<"Deleting song..."<<endl;
|
||||||
|
del.deleteSong(token, song);
|
||||||
if (flag.compare("-d") == 0)
|
}
|
||||||
{
|
void CommitManager::downloadSong()
|
||||||
song.songPath.assign(arg.value);
|
{
|
||||||
}
|
cout<<"Starting downloading process..."<<endl;
|
||||||
if (flag.compare("-b") == 0)
|
|
||||||
{
|
APIParser apiPrs{icaAction};
|
||||||
song.id = atoi(value.c_str());
|
auto api = apiPrs.retrieveAPI();
|
||||||
}
|
|
||||||
}
|
auto token = parseToken(api);
|
||||||
|
|
||||||
Download dnld{api};
|
Song song{};
|
||||||
cout<<"downloading song"<<endl;
|
|
||||||
dnld.downloadSong(token, song);
|
for (auto arg : icaAction.flags)
|
||||||
}
|
{
|
||||||
void CommitManager::retrieveObjects()
|
auto flag = arg.flag;
|
||||||
{
|
auto value = arg.value;
|
||||||
cout<<"Starting retrieve process..."<<endl;
|
|
||||||
|
if (flag.compare("-d") == 0)
|
||||||
APIParser apiPrs{icaAction};
|
{
|
||||||
auto api = apiPrs.retrieveAPI();
|
song.songPath.assign(arg.value);
|
||||||
|
}
|
||||||
auto token = parseToken(api);
|
if (flag.compare("-b") == 0)
|
||||||
RetrieveTypes retrieveType;
|
{
|
||||||
|
song.id = atoi(value.c_str());
|
||||||
for (auto arg : icaAction.flags)
|
}
|
||||||
{
|
}
|
||||||
auto flag = arg.flag;
|
|
||||||
auto value = arg.value;
|
Download dnld{api};
|
||||||
|
cout<<"downloading song"<<endl;
|
||||||
if (flag.compare("-rt") == 0)
|
dnld.downloadSong(token, song);
|
||||||
{
|
}
|
||||||
if (value.compare("songs") == 0)
|
void CommitManager::retrieveObjects()
|
||||||
{
|
{
|
||||||
retrieveType = RetrieveTypes::songs;
|
cout<<"Starting retrieve process..."<<endl;
|
||||||
break;
|
|
||||||
}
|
APIParser apiPrs{icaAction};
|
||||||
}
|
auto api = apiPrs.retrieveAPI();
|
||||||
}
|
|
||||||
|
auto token = parseToken(api);
|
||||||
RetrieveRecords songs{api, token};
|
RetrieveTypes retrieveType;
|
||||||
songs.retrieve(retrieveType);
|
|
||||||
|
for (auto arg : icaAction.flags)
|
||||||
}
|
{
|
||||||
void CommitManager::uploadSong()
|
auto flag = arg.flag;
|
||||||
{
|
auto value = arg.value;
|
||||||
auto uploadSingleSong = true;
|
|
||||||
auto recursiveDirectory = false;
|
if (flag.compare("-rt") == 0)
|
||||||
auto noConfirm = false;
|
{
|
||||||
string songDirectory;
|
if (value.compare("songs") == 0)
|
||||||
APIParser apiPrs{icaAction};
|
{
|
||||||
auto api = apiPrs.retrieveAPI();
|
retrieveType = RetrieveTypes::songs;
|
||||||
|
break;
|
||||||
auto token = parseToken(api);
|
}
|
||||||
|
}
|
||||||
Song song;
|
}
|
||||||
|
|
||||||
for (auto& arg : icaAction.flags)
|
RetrieveRecords songs{api, token};
|
||||||
{
|
songs.retrieve(retrieveType);
|
||||||
auto flag = arg.flag;
|
|
||||||
auto value = arg.value;
|
}
|
||||||
|
void CommitManager::uploadSong()
|
||||||
if (flag.compare("-s") == 0)
|
{
|
||||||
{
|
auto uploadSingleSong = true;
|
||||||
song.songPath.assign(arg.value);
|
auto recursiveDirectory = false;
|
||||||
}
|
auto noConfirm = false;
|
||||||
else if (flag.compare("-sd") == 0)
|
string songDirectory;
|
||||||
{
|
APIParser apiPrs{icaAction};
|
||||||
songDirectory = value;
|
auto api = apiPrs.retrieveAPI();
|
||||||
uploadSingleSong = false;
|
|
||||||
}
|
auto token = parseToken(api);
|
||||||
else if (flag.compare("-sr") == 0)
|
|
||||||
{
|
Song song;
|
||||||
songDirectory = value;
|
|
||||||
uploadSingleSong = false;
|
for (auto& arg : icaAction.flags)
|
||||||
recursiveDirectory = true;
|
{
|
||||||
}
|
auto flag = arg.flag;
|
||||||
else if (flag.compare("-nc") == 0)
|
auto value = arg.value;
|
||||||
{
|
|
||||||
noConfirm = true;
|
if (flag.compare("-s") == 0)
|
||||||
}
|
{
|
||||||
}
|
song.songPath.assign(arg.value);
|
||||||
|
}
|
||||||
Upload upld{api};
|
else if (flag.compare("-sd") == 0)
|
||||||
if (uploadSingleSong)
|
{
|
||||||
{
|
songDirectory = value;
|
||||||
cout<<"Uploading song..."<<endl;
|
uploadSingleSong = false;
|
||||||
upld.uploadSong(token, song);
|
}
|
||||||
}
|
else if (flag.compare("-sr") == 0)
|
||||||
else
|
{
|
||||||
{
|
songDirectory = value;
|
||||||
cout<<"Uploading songs from " << songDirectory << endl;
|
uploadSingleSong = false;
|
||||||
upld.uploadSongsFromDirectory(token, songDirectory, noConfirm, recursiveDirectory);
|
recursiveDirectory = true;
|
||||||
}
|
}
|
||||||
}
|
else if (flag.compare("-nc") == 0)
|
||||||
#pragma Functions
|
{
|
||||||
|
noConfirm = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Upload upld{api};
|
||||||
|
if (uploadSingleSong)
|
||||||
|
{
|
||||||
|
cout<<"Uploading song..."<<endl;
|
||||||
|
upld.uploadSong(token, song);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cout<<"Uploading songs from " << songDirectory << endl;
|
||||||
|
upld.uploadSongsFromDirectory(token, songDirectory, noConfirm, recursiveDirectory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,56 +11,63 @@ using std::string;
|
|||||||
|
|
||||||
namespace Managers
|
namespace Managers
|
||||||
{
|
{
|
||||||
FileManager::FileManager() {}
|
|
||||||
FileManager::FileManager(string filePath)
|
#pragma region Constructors
|
||||||
{
|
FileManager::FileManager() {}
|
||||||
this->filePath = filePath;
|
FileManager::FileManager(string filePath)
|
||||||
|
{
|
||||||
|
this->filePath = filePath;
|
||||||
|
readFile();
|
||||||
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
|
||||||
|
#pragma region Functions
|
||||||
|
void FileManager::saveFile(string newFilePath)
|
||||||
|
{
|
||||||
|
if (!fileRead)
|
||||||
readFile();
|
readFile();
|
||||||
}
|
|
||||||
|
|
||||||
|
ofstream of{newFilePath, ofstream::binary};
|
||||||
void FileManager::saveFile(string newFilePath)
|
of.write(fileBuffer, fileBufferLength);
|
||||||
{
|
of.close();
|
||||||
if (!fileRead)
|
}
|
||||||
readFile();
|
|
||||||
|
void FileManager::readFile()
|
||||||
ofstream of{newFilePath, ofstream::binary};
|
{
|
||||||
of.write(fileBuffer, fileBufferLength);
|
ifstream is{filePath, ifstream::binary};
|
||||||
of.close();
|
if (is)
|
||||||
}
|
{
|
||||||
|
is.seekg (0, is.end);
|
||||||
void FileManager::readFile()
|
fileBufferLength = is.tellg();
|
||||||
{
|
is.seekg (0, is.beg);
|
||||||
ifstream is{filePath, ifstream::binary};
|
|
||||||
if (is)
|
fileBuffer = new char [fileBufferLength];
|
||||||
{
|
|
||||||
is.seekg (0, is.end);
|
cout<< "Reading "<<fileBufferLength<<" characters... "<<endl;;
|
||||||
fileBufferLength = is.tellg();
|
is.read (fileBuffer,fileBufferLength);
|
||||||
is.seekg (0, is.beg);
|
|
||||||
|
if (is)
|
||||||
fileBuffer = new char [fileBufferLength];
|
cout<<"all characters read successfully.";
|
||||||
|
else
|
||||||
cout<< "Reading "<<fileBufferLength<<" characters... "<<endl;;
|
cout<<"error: only "<<is.gcount()<<" could be read";
|
||||||
is.read (fileBuffer,fileBufferLength);
|
cout<<endl;
|
||||||
|
is.close();
|
||||||
if (is)
|
fileRead = true;
|
||||||
cout<<"all characters read successfully.";
|
}
|
||||||
else
|
}
|
||||||
cout<<"error: only "<<is.gcount()<<" could be read";
|
void FileManager::modifyFilePath(string filePath)
|
||||||
cout<<endl;
|
{
|
||||||
is.close();
|
this->filePath = filePath;
|
||||||
fileRead = true;
|
}
|
||||||
}
|
|
||||||
}
|
char* FileManager::retrieveFileBuffer() const
|
||||||
void FileManager::modifyFilePath(string filePath)
|
{
|
||||||
{
|
return fileBuffer;
|
||||||
this->filePath = filePath;
|
}
|
||||||
}
|
|
||||||
|
int FileManager::retrieveFileBufferLength() const { return fileBufferLength; }
|
||||||
char* FileManager::retrieveFileBuffer() const
|
|
||||||
{
|
#pragma endregion
|
||||||
return fileBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
int FileManager::retrieveFileBufferLength() const { return fileBufferLength; }
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,44 +17,46 @@ using Models::User;
|
|||||||
|
|
||||||
namespace Managers
|
namespace Managers
|
||||||
{
|
{
|
||||||
#pragma
|
|
||||||
TokenManager::TokenManager(const User& user)
|
|
||||||
{
|
|
||||||
this->user = user;
|
|
||||||
}
|
|
||||||
TokenManager::TokenManager(const User& user, API& api)
|
|
||||||
{
|
|
||||||
this->user = user;
|
|
||||||
this->api = api;
|
|
||||||
this->api.endpoint = "api/" + api.version
|
|
||||||
+ "/login";
|
|
||||||
}
|
|
||||||
#pragma Constructors
|
|
||||||
|
|
||||||
|
#pragma region Constructors
|
||||||
#pragma
|
TokenManager::TokenManager(const User& user)
|
||||||
Token TokenManager::requestToken()
|
{
|
||||||
{
|
this->user = user;
|
||||||
Token token{};
|
}
|
||||||
json usrObj;
|
TokenManager::TokenManager(const User& user, API& api)
|
||||||
|
{
|
||||||
usrObj["username"] = user.username;
|
this->user = user;
|
||||||
usrObj["password"] = user.password;
|
this->api = api;
|
||||||
|
this->api.endpoint = "api/" + api.version
|
||||||
cout<<"Sending request for token"<<endl;
|
+ "/login";
|
||||||
auto url = api.url + api.endpoint;
|
}
|
||||||
cout<<url<<endl;
|
#pragma endregion
|
||||||
auto r = cpr::Post(cpr::Url{url},
|
|
||||||
cpr::Body{usrObj.dump()},
|
|
||||||
cpr::Header{{"Content-Type", "application/json"}});
|
#pragma region Functions
|
||||||
|
Token TokenManager::requestToken()
|
||||||
json res = json::parse(r.text);
|
{
|
||||||
token.accessToken = res["token"];
|
Token token{};
|
||||||
token.tokenType = res["token_type"];
|
json usrObj;
|
||||||
|
|
||||||
cout<<"status code "<<r.status_code<<endl;
|
usrObj["username"] = user.username;
|
||||||
|
usrObj["password"] = user.password;
|
||||||
return token;
|
|
||||||
}
|
cout<<"Sending request for token"<<endl;
|
||||||
#pragma Functions
|
auto url = api.url + api.endpoint;
|
||||||
|
cout<<url<<endl;
|
||||||
|
auto r = cpr::Post(cpr::Url{url},
|
||||||
|
cpr::Body{usrObj.dump()},
|
||||||
|
cpr::Header{{"Content-Type", "application/json"}});
|
||||||
|
|
||||||
|
json res = json::parse(r.text);
|
||||||
|
token.accessToken = res["token"];
|
||||||
|
token.tokenType = res["token_type"];
|
||||||
|
|
||||||
|
cout<<"status code "<<r.status_code<<endl;
|
||||||
|
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,42 +12,44 @@ using Models::User;
|
|||||||
|
|
||||||
namespace Managers
|
namespace Managers
|
||||||
{
|
{
|
||||||
#pragma
|
|
||||||
UserManager::UserManager(User user)
|
#pragma region Constructors
|
||||||
{
|
UserManager::UserManager(User user)
|
||||||
this->user = user;
|
{
|
||||||
}
|
this->user = user;
|
||||||
UserManager::UserManager(const IcarusAction icaAct)
|
}
|
||||||
{
|
UserManager::UserManager(const IcarusAction icaAct)
|
||||||
this->icaAction = icaAct;
|
{
|
||||||
this->user = User{};
|
this->icaAction = icaAct;
|
||||||
parseUserFromActions();
|
this->user = User{};
|
||||||
}
|
parseUserFromActions();
|
||||||
#pragma Constructors
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
|
||||||
#pragma
|
#pragma region Functions
|
||||||
User UserManager::retrieveUser() const
|
User UserManager::retrieveUser() const
|
||||||
{
|
{
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserManager::parseUserFromActions()
|
void UserManager::parseUserFromActions()
|
||||||
{
|
{
|
||||||
auto args = icaAction.flags;
|
auto args = icaAction.flags;
|
||||||
|
|
||||||
for (auto arg : args)
|
for (auto arg : args)
|
||||||
|
{
|
||||||
|
auto flag = arg.flag;
|
||||||
|
if (flag.compare("-u") == 0)
|
||||||
{
|
{
|
||||||
auto flag = arg.flag;
|
user.username = arg.value;
|
||||||
if (flag.compare("-u") == 0)
|
}
|
||||||
{
|
if (flag.compare("-p") == 0)
|
||||||
user.username = arg.value;
|
{
|
||||||
}
|
user.password = arg.value;
|
||||||
if (flag.compare("-p") == 0)
|
|
||||||
{
|
|
||||||
user.password = arg.value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#pragma Functions
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+37
-35
@@ -1,6 +1,6 @@
|
|||||||
#include"Parsers/APIParser.h"
|
#include "Parsers/APIParser.h"
|
||||||
|
|
||||||
#include<iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
@@ -10,43 +10,45 @@ using Models::IcarusAction;
|
|||||||
|
|
||||||
namespace Parsers
|
namespace Parsers
|
||||||
{
|
{
|
||||||
#pragma
|
|
||||||
APIParser::APIParser(IcarusAction icaAct) : icaAct(icaAct)
|
#pragma region Constructors
|
||||||
|
APIParser::APIParser(IcarusAction icaAct) : icaAct(icaAct)
|
||||||
|
{
|
||||||
|
api = API{};
|
||||||
|
parseAPI();
|
||||||
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
|
||||||
|
#pragma region Functions
|
||||||
|
API APIParser::retrieveAPI() const
|
||||||
|
{
|
||||||
|
return api;
|
||||||
|
}
|
||||||
|
|
||||||
|
void APIParser::parseAPI()
|
||||||
|
{
|
||||||
|
auto flags = icaAct.flags;
|
||||||
|
cout << "Parsing api" << endl;
|
||||||
|
|
||||||
|
for (auto i =0; i < flags.size(); ++i)
|
||||||
{
|
{
|
||||||
api = API{};
|
auto arg = flags[i].flag;
|
||||||
parseAPI();
|
auto value = flags[i].value;
|
||||||
}
|
|
||||||
#pragma endregion
|
|
||||||
|
|
||||||
|
if (arg.compare("-h") == 0)
|
||||||
#pragma
|
|
||||||
API APIParser::retrieveAPI() const
|
|
||||||
{
|
|
||||||
return api;
|
|
||||||
}
|
|
||||||
|
|
||||||
void APIParser::parseAPI()
|
|
||||||
{
|
|
||||||
auto flags = icaAct.flags;
|
|
||||||
cout<<"Parsing api"<<endl;
|
|
||||||
|
|
||||||
for (auto i =0; i < flags.size(); ++i)
|
|
||||||
{
|
{
|
||||||
auto arg = flags[i].flag;
|
api.url = (value[value.size()-1] == '/') ? value : value + "/";
|
||||||
auto value = flags[i].value;
|
break;
|
||||||
|
|
||||||
if (arg.compare("-h") == 0)
|
|
||||||
{
|
|
||||||
api.url = (value[value.size()-1] == '/') ? value : value + "/";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: For now I will hard code
|
|
||||||
// the api version since I am only
|
|
||||||
// on version 1
|
|
||||||
api.version = "v1";
|
|
||||||
}
|
}
|
||||||
#pragma functions
|
|
||||||
|
// TODO: For now I will hard code
|
||||||
|
// the api version since I am only
|
||||||
|
// on version 1
|
||||||
|
api.version = "v1";
|
||||||
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+48
-46
@@ -1,9 +1,9 @@
|
|||||||
#include"Syncers/Delete.h"
|
#include "Syncers/Delete.h"
|
||||||
|
|
||||||
#include<exception>
|
#include <exception>
|
||||||
#include<iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include<cpr/cpr.h>
|
#include <cpr/cpr.h>
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
@@ -16,47 +16,49 @@ using Models::Token;
|
|||||||
|
|
||||||
namespace Syncers
|
namespace Syncers
|
||||||
{
|
{
|
||||||
#pragma
|
|
||||||
Delete::Delete(API api)
|
|
||||||
{
|
|
||||||
this->api = api;
|
|
||||||
this->api.endpoint = "song/data";
|
|
||||||
}
|
|
||||||
#pragma Constructors
|
|
||||||
|
|
||||||
|
#pragma region Constructors
|
||||||
#pragma
|
Delete::Delete(API api)
|
||||||
void Delete::deleteSong(const Token token, Song song)
|
{
|
||||||
{
|
this->api = api;
|
||||||
try
|
this->api.endpoint = "song/data";
|
||||||
{
|
}
|
||||||
auto url = retrieveUrl(song);
|
#pragma endregion
|
||||||
string auth{token.tokenType};
|
|
||||||
auth.append(" " + token.accessToken);
|
|
||||||
auto r = cpr::Delete(cpr::Url(url),
|
#pragma region Functions
|
||||||
cpr::Header{{"authorization", auth}});
|
void Delete::deleteSong(const Token token, Song song)
|
||||||
|
{
|
||||||
auto statusCode = r.status_code;
|
try
|
||||||
|
{
|
||||||
cout<<"Status code "<<statusCode<<endl;
|
auto url = retrieveUrl(song);
|
||||||
}
|
string auth{token.tokenType};
|
||||||
catch (exception e)
|
auth.append(" " + token.accessToken);
|
||||||
{
|
auto r = cpr::Delete(cpr::Url(url),
|
||||||
auto msg = e.what();
|
cpr::Header{{"authorization", auth}});
|
||||||
cout<<msg<<endl;
|
|
||||||
}
|
auto statusCode = r.status_code;
|
||||||
cout<<"Finished"<<endl;
|
|
||||||
}
|
cout<<"Status code "<<statusCode<<endl;
|
||||||
|
}
|
||||||
string Delete::retrieveUrl(Song song)
|
catch (exception e)
|
||||||
{
|
{
|
||||||
string url{api.url + "api/" + api.version + "/" +
|
auto msg = e.what();
|
||||||
api.endpoint + "/"};
|
cout<<msg<<endl;
|
||||||
|
}
|
||||||
url.append(std::to_string(song.id));
|
cout<<"Finished"<<endl;
|
||||||
cout<<"url "<<url<<endl;
|
}
|
||||||
|
|
||||||
return url;
|
string Delete::retrieveUrl(Song song)
|
||||||
}
|
{
|
||||||
#pragma Functions
|
string url{api.url + "api/" + api.version + "/" +
|
||||||
|
api.endpoint + "/"};
|
||||||
|
|
||||||
|
url.append(std::to_string(song.id));
|
||||||
|
cout<<"url "<<url<<endl;
|
||||||
|
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+76
-74
@@ -1,10 +1,10 @@
|
|||||||
#include"Syncers/Download.h"
|
#include "Syncers/Download.h"
|
||||||
|
|
||||||
#include<exception>
|
#include <exception>
|
||||||
#include<iostream>
|
#include <iostream>
|
||||||
#include<fstream>
|
#include <fstream>
|
||||||
|
|
||||||
#include<cpr/cpr.h>
|
#include <cpr/cpr.h>
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
@@ -18,74 +18,76 @@ using Models::Token;
|
|||||||
|
|
||||||
namespace Syncers
|
namespace Syncers
|
||||||
{
|
{
|
||||||
#pragma
|
|
||||||
Download::Download() { }
|
|
||||||
Download::Download(API api)
|
|
||||||
{
|
|
||||||
this->api = api;
|
|
||||||
this->api.endpoint = "song/data";
|
|
||||||
}
|
|
||||||
Download::Download(string filePath)
|
|
||||||
{
|
|
||||||
downloadFilePath = filePath;
|
|
||||||
}
|
|
||||||
#pragma Constructors
|
|
||||||
|
|
||||||
|
#pragma region Constructors
|
||||||
#pragma
|
Download::Download() { }
|
||||||
void Download::downloadSong(const Token token, Song song)
|
Download::Download(API api)
|
||||||
{
|
{
|
||||||
try
|
this->api = api;
|
||||||
{
|
this->api.endpoint = "song/data";
|
||||||
string url = retrieveUrl(song);
|
}
|
||||||
song.songPath.append("track.mp3");
|
Download::Download(string filePath)
|
||||||
cout<<"song path "<<song.songPath<<endl;
|
{
|
||||||
string auth{token.tokenType};
|
downloadFilePath = filePath;
|
||||||
auth.append(" " + token.accessToken);
|
}
|
||||||
|
#pragma endregion
|
||||||
auto r = cpr::Get(cpr::Url(url),
|
|
||||||
cpr::Header{{"Content-type", "audio/mpeg"},
|
|
||||||
{"Authorization", auth}});
|
#pragma region Functions
|
||||||
|
void Download::downloadSong(const Token token, Song song)
|
||||||
|
{
|
||||||
int statusCode = r.status_code;
|
try
|
||||||
|
{
|
||||||
if (statusCode == OK) {
|
string url = retrieveUrl(song);
|
||||||
song.data = r.text;
|
song.songPath.append("track.mp3");
|
||||||
saveSong(song);
|
cout<<"song path "<<song.songPath<<endl;
|
||||||
}
|
string auth{token.tokenType};
|
||||||
|
auth.append(" " + token.accessToken);
|
||||||
|
|
||||||
cout<<"finsihed with status code "<<statusCode<<endl;
|
auto r = cpr::Get(cpr::Url(url),
|
||||||
}
|
cpr::Header{{"Content-type", "audio/mpeg"},
|
||||||
catch (exception e)
|
{"Authorization", auth}});
|
||||||
{
|
|
||||||
auto msg = e.what();
|
|
||||||
cout<<msg<<endl;
|
int statusCode = r.status_code;
|
||||||
}
|
|
||||||
}
|
if (statusCode == OK) {
|
||||||
|
song.data = r.text;
|
||||||
string Download::retrieveUrl(Song song)
|
saveSong(song);
|
||||||
{
|
}
|
||||||
string url{api.url + "api/" + api.version + "/" +
|
|
||||||
api.endpoint + "/"};
|
|
||||||
|
cout<<"finsihed with status code "<<statusCode<<endl;
|
||||||
url.append(std::to_string(song.id));
|
}
|
||||||
cout<<"url "<<url<<endl;
|
catch (exception e)
|
||||||
|
{
|
||||||
return url;
|
auto msg = e.what();
|
||||||
}
|
cout<<msg<<endl;
|
||||||
|
}
|
||||||
void Download::saveSong(Song& song)
|
}
|
||||||
{
|
|
||||||
cout<<"\nSaving song to: "<<song.songPath<<endl;
|
string Download::retrieveUrl(Song song)
|
||||||
int bufferLength = song.data.length();
|
{
|
||||||
const char *data = song.data.c_str();
|
string url{api.url + "api/" + api.version + "/" +
|
||||||
cout<<"buff length "<<bufferLength<<endl;
|
api.endpoint + "/"};
|
||||||
|
|
||||||
ofstream saveSong{song.songPath, std::ios::binary};
|
url.append(std::to_string(song.id));
|
||||||
saveSong.write(data, bufferLength);
|
cout<<"url "<<url<<endl;
|
||||||
saveSong.close();
|
|
||||||
}
|
return url;
|
||||||
#pragma Functions
|
}
|
||||||
|
|
||||||
|
void Download::saveSong(Song& song)
|
||||||
|
{
|
||||||
|
cout<<"\nSaving song to: "<<song.songPath<<endl;
|
||||||
|
int bufferLength = song.data.length();
|
||||||
|
const char *data = song.data.c_str();
|
||||||
|
cout<<"buff length "<<bufferLength<<endl;
|
||||||
|
|
||||||
|
ofstream saveSong{song.songPath, std::ios::binary};
|
||||||
|
saveSong.write(data, bufferLength);
|
||||||
|
saveSong.close();
|
||||||
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,43 +20,48 @@ using Utilities::Conversions;
|
|||||||
namespace Syncers
|
namespace Syncers
|
||||||
{
|
{
|
||||||
|
|
||||||
RetrieveRecords::RetrieveRecords() { }
|
#pragma region Constructors
|
||||||
RetrieveRecords::RetrieveRecords(API api, Token token)
|
RetrieveRecords::RetrieveRecords() { }
|
||||||
: token(token), api(api) { }
|
RetrieveRecords::RetrieveRecords(API api, Token token)
|
||||||
|
: token(token), api(api) { }
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
void RetrieveRecords::retrieve(CommitManager::RetrieveTypes type)
|
#pragma region Functions
|
||||||
|
void RetrieveRecords::retrieve(CommitManager::RetrieveTypes type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
{
|
{
|
||||||
switch (type)
|
case CommitManager::RetrieveTypes::songs:
|
||||||
{
|
fetchSongs();
|
||||||
case CommitManager::RetrieveTypes::songs:
|
break;
|
||||||
fetchSongs();
|
default:
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void RetrieveRecords::fetchSongs()
|
|
||||||
{
|
|
||||||
cout<<"fetching songs"<<endl;
|
|
||||||
auto url = api.url + "api/" + api.version + "/" + "song";
|
|
||||||
|
|
||||||
auto auth = token.tokenType;
|
|
||||||
auth.append(" " + token.accessToken);
|
|
||||||
auto r = cpr::Get(cpr::Url{url},
|
|
||||||
cpr::Header{{"authorization", auth},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (r.status_code != (int)Result::OK) {
|
|
||||||
cout<<"something went wrong\n";
|
|
||||||
cout<<"status code: "<<r.status_code<<endl;
|
|
||||||
cout<<"message: "<<r.text<<endl;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
auto songData = nlohmann::json::parse(r.text);
|
|
||||||
|
|
||||||
ofstream writeData{};
|
|
||||||
writeData.open("songs.json");
|
|
||||||
writeData<<songData.dump(4);
|
|
||||||
writeData.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
void RetrieveRecords::fetchSongs()
|
||||||
|
{
|
||||||
|
cout<<"fetching songs"<<endl;
|
||||||
|
auto url = api.url + "api/" + api.version + "/" + "song";
|
||||||
|
|
||||||
|
auto auth = token.tokenType;
|
||||||
|
auth.append(" " + token.accessToken);
|
||||||
|
auto r = cpr::Get(cpr::Url{url},
|
||||||
|
cpr::Header{{"authorization", auth},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (r.status_code != (int)Result::OK) {
|
||||||
|
cout<<"something went wrong\n";
|
||||||
|
cout<<"status code: "<<r.status_code<<endl;
|
||||||
|
cout<<"message: "<<r.text<<endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
auto songData = nlohmann::json::parse(r.text);
|
||||||
|
|
||||||
|
ofstream writeData{};
|
||||||
|
writeData.open("songs.json");
|
||||||
|
writeData<<songData.dump(4);
|
||||||
|
writeData.close();
|
||||||
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
+159
-154
@@ -24,154 +24,171 @@ using namespace cpr;
|
|||||||
|
|
||||||
namespace Syncers
|
namespace Syncers
|
||||||
{
|
{
|
||||||
Upload::Upload() { }
|
|
||||||
Upload::Upload(API api) : api(api)
|
#pragma region Constructors
|
||||||
|
Upload::Upload() { }
|
||||||
|
Upload::Upload(API api) : api(api)
|
||||||
|
{
|
||||||
|
this->api.endpoint = "song/data";
|
||||||
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
|
|
||||||
|
#pragma region Functions
|
||||||
|
Song Upload::uploadSong(const Models::Token& token, Song& song)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
this->api.endpoint = "song/data";
|
auto url = retrieveUrl();
|
||||||
}
|
|
||||||
|
|
||||||
|
cout<<"url "<<url<<endl;
|
||||||
|
string auth{token.tokenType};
|
||||||
|
auth.append(" " + token.accessToken);
|
||||||
|
auto r = cpr::Post(cpr::Url{url},
|
||||||
|
cpr::Multipart{{"key", "small value"},
|
||||||
|
{"file", cpr::File{song.songPath}}},
|
||||||
|
cpr::Header{{"authorization", auth}}
|
||||||
|
);
|
||||||
|
|
||||||
Song Upload::uploadSong(const Models::Token& token, Song& song)
|
cout << "status code: " << r.status_code<< std::endl;
|
||||||
{
|
cout << r.text << endl;
|
||||||
try
|
auto result = nlohmann::json::parse(r.text);
|
||||||
{
|
cout<<"Finished"<<endl;
|
||||||
auto url = retrieveUrl();
|
song.id = result["id"].get<int>();
|
||||||
|
song.title = result["title"].get<std::string>();
|
||||||
cout<<"url "<<url<<endl;
|
song.artist = result["artist"].get<std::string>();
|
||||||
string auth{token.tokenType};
|
song.album = result["album"].get<std::string>();
|
||||||
auth.append(" " + token.accessToken);
|
song.genre = result["genre"].get<std::string>();
|
||||||
auto r = cpr::Post(cpr::Url{url},
|
song.year = result["year"].get<int>();
|
||||||
cpr::Multipart{{"key", "small value"},
|
song.duration = result["duration"].get<int>();
|
||||||
{"file", cpr::File{song.songPath}}},
|
song.track = result["track"].get<int>();
|
||||||
cpr::Header{{"authorization", auth}}
|
|
||||||
);
|
|
||||||
|
|
||||||
cout << "status code: " << r.status_code<< std::endl;
|
|
||||||
cout << r.text << endl;
|
|
||||||
auto result = nlohmann::json::parse(r.text);
|
|
||||||
cout<<"Finished"<<endl;
|
|
||||||
song.id = result["id"].get<int>();
|
|
||||||
song.title = result["title"].get<std::string>();
|
|
||||||
song.artist = result["artist"].get<std::string>();
|
|
||||||
song.album = result["album"].get<std::string>();
|
|
||||||
song.genre = result["genre"].get<std::string>();
|
|
||||||
song.year = result["year"].get<int>();
|
|
||||||
song.duration = result["duration"].get<int>();
|
|
||||||
song.track = result["track"].get<int>();
|
|
||||||
|
|
||||||
return song;
|
|
||||||
}
|
|
||||||
catch (exception& e)
|
|
||||||
{
|
|
||||||
auto msg = e.what();
|
|
||||||
cout<<msg<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
catch (exception& e)
|
||||||
void Upload::uploadSongsFromDirectory(const Models::Token& token,
|
|
||||||
const std::string& directory,
|
|
||||||
const bool noConfirm, bool recursive = false)
|
|
||||||
{
|
{
|
||||||
try
|
auto msg = e.what();
|
||||||
|
cout<<msg<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return song;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Upload::uploadSongsFromDirectory(const Models::Token& token,
|
||||||
|
const std::string& directory,
|
||||||
|
const bool noConfirm, bool recursive = false)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
auto songs = retrieveAllSongsFromDirectory(directory, recursive);
|
||||||
|
auto confirmUpload = true;
|
||||||
|
|
||||||
|
while (!noConfirm)
|
||||||
{
|
{
|
||||||
auto songs = retrieveAllSongsFromDirectory(directory, recursive);
|
auto answer = 'a';
|
||||||
auto confirmUpload = true;
|
cout << "are you sure you want to upload " << songs.size() << " songs? [y/n]";
|
||||||
|
cin >> answer;
|
||||||
|
|
||||||
while (!noConfirm)
|
if (answer == 'y' || answer == 'Y')
|
||||||
{
|
{
|
||||||
auto answer = 'a';
|
confirmUpload = true;
|
||||||
cout << "are you sure you want to upload " << songs.size() << " songs? [y/n]";
|
break;
|
||||||
cin >> answer;
|
}
|
||||||
|
else if (answer == 'n' || answer == 'N')
|
||||||
if (answer == 'y' || answer == 'Y')
|
|
||||||
{
|
|
||||||
confirmUpload = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
else if (answer == 'n' || answer == 'N')
|
|
||||||
{
|
|
||||||
confirmUpload = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!confirmUpload)
|
|
||||||
{
|
{
|
||||||
cout << "exiting...\n";
|
confirmUpload = false;
|
||||||
std::exit(-1);
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
cout << "uploading songs\n";
|
|
||||||
for (auto& song: songs)
|
|
||||||
{
|
|
||||||
song = uploadSong(token, song);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (exception& e)
|
|
||||||
|
if (!confirmUpload)
|
||||||
{
|
{
|
||||||
cout<<e.what()<<endl;
|
cout << "exiting...\n";
|
||||||
|
std::exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "uploading songs\n";
|
||||||
|
for (auto& song: songs)
|
||||||
|
{
|
||||||
|
song = uploadSong(token, song);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (exception& e)
|
||||||
|
{
|
||||||
|
cout<<e.what()<<endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<Song> Upload::retrieveAllSongsFromDirectory(const std::string& directory,
|
||||||
|
bool recursive)
|
||||||
|
{
|
||||||
|
std::vector<Song> allSongs;
|
||||||
|
if (recursive)
|
||||||
|
{
|
||||||
|
for (auto p: fs::recursive_directory_iterator(directory))
|
||||||
|
{
|
||||||
|
auto song = retrieveSongPath(p);
|
||||||
|
if (!song.songPath.empty())
|
||||||
|
allSongs.push_back(song);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (auto p: fs::directory_iterator(directory))
|
||||||
|
{
|
||||||
|
auto song = retrieveSongPath(p);
|
||||||
|
if (!song.songPath.empty())
|
||||||
|
allSongs.push_back(song);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return allSongs;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Song> Upload::retrieveAllSongsFromDirectory(const std::string& directory,
|
|
||||||
bool recursive)
|
string Upload::retrieveUrl()
|
||||||
|
{
|
||||||
|
const string url{api.url + "api/" + api.version + "/" +
|
||||||
|
api.endpoint};
|
||||||
|
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Song Upload::retrieveSongPath(fs::directory_entry& dirEntry)
|
||||||
|
{
|
||||||
|
constexpr auto mp3Ext = ".mp3";
|
||||||
|
Song song;
|
||||||
|
if (fs::is_regular_file(dirEntry.path()))
|
||||||
{
|
{
|
||||||
std::vector<Song> allSongs;
|
const auto ext = dirEntry.path().extension().string();
|
||||||
if (recursive)
|
if (ext.compare(mp3Ext) == 0)
|
||||||
{
|
{
|
||||||
for (auto p: fs::recursive_directory_iterator(directory))
|
cout << "found mp3 file" << endl;
|
||||||
{
|
song.songPath = dirEntry.path().string();
|
||||||
auto song = retrieveSongPath(p);
|
|
||||||
if (!song.songPath.empty())
|
|
||||||
allSongs.push_back(song);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
for (auto p: fs::directory_iterator(directory))
|
|
||||||
{
|
|
||||||
auto song = retrieveSongPath(p);
|
|
||||||
if (!song.songPath.empty())
|
|
||||||
allSongs.push_back(song);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return allSongs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return song;
|
||||||
string Upload::retrieveUrl()
|
}
|
||||||
{
|
|
||||||
const string url{api.url + "api/" + api.version + "/" +
|
|
||||||
api.endpoint};
|
|
||||||
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Song Upload::retrieveSongPath(fs::directory_entry& dirEntry)
|
#pragma region Testing
|
||||||
{
|
void Upload::printSongDetails()
|
||||||
constexpr auto mp3Ext = ".mp3";
|
{
|
||||||
Song song;
|
cout<<"Song details: "<<endl;
|
||||||
if (fs::is_regular_file(dirEntry.path()))
|
cout<<"Id: "<<song.id<<endl;
|
||||||
{
|
cout<<"Title: "<<song.title<<endl;
|
||||||
const auto ext = dirEntry.path().extension().string();
|
cout<<"Artist: "<<song.artist<<endl;
|
||||||
if (ext.compare(mp3Ext) == 0)
|
cout<<"Album: "<<song.album<<endl;
|
||||||
{
|
cout<<"Genre: "<<song.genre<<endl;
|
||||||
cout << "found mp3 file" << endl;
|
cout<<"Year: "<<song.year<<endl;
|
||||||
song.songPath = dirEntry.path().string();
|
cout<<"Duration: "<<song.duration<<endl;
|
||||||
}
|
}
|
||||||
}
|
void Upload::printSongDetails(std::vector<Song>& songs)
|
||||||
|
{
|
||||||
return song;
|
for (auto& song: songs)
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#pragma
|
|
||||||
void Upload::printSongDetails()
|
|
||||||
{
|
{
|
||||||
cout<<"Song details: "<<endl;
|
cout<<"Song details: "<<endl;
|
||||||
cout<<"Id: "<<song.id<<endl;
|
cout<<"Id: "<<song.id<<endl;
|
||||||
@@ -181,36 +198,24 @@ namespace Syncers
|
|||||||
cout<<"Genre: "<<song.genre<<endl;
|
cout<<"Genre: "<<song.genre<<endl;
|
||||||
cout<<"Year: "<<song.year<<endl;
|
cout<<"Year: "<<song.year<<endl;
|
||||||
cout<<"Duration: "<<song.duration<<endl;
|
cout<<"Duration: "<<song.duration<<endl;
|
||||||
|
cout<<"Path: "<<song.songPath<<endl;
|
||||||
}
|
}
|
||||||
void Upload::printSongDetails(std::vector<Song>& songs)
|
}
|
||||||
{
|
void Upload::printJsonData(const json& obj)
|
||||||
for (auto& song: songs)
|
{
|
||||||
{
|
cout<<endl<<endl<<"JSon data: "<<endl;
|
||||||
cout<<"Song details: "<<endl;
|
cout<<"id: "<<obj["id"]<<endl;
|
||||||
cout<<"Id: "<<song.id<<endl;
|
cout<<"title: "<<obj["title"]<<endl;
|
||||||
cout<<"Title: "<<song.title<<endl;
|
cout<<"artist: "<<obj["artist"]<<endl;
|
||||||
cout<<"Artist: "<<song.artist<<endl;
|
cout<<"album: "<<obj["album"]<<endl;
|
||||||
cout<<"Album: "<<song.album<<endl;
|
cout<<"genre: "<<obj["genre"]<<endl;
|
||||||
cout<<"Genre: "<<song.genre<<endl;
|
cout<<"year: "<<obj["year"]<<endl;
|
||||||
cout<<"Year: "<<song.year<<endl;
|
cout<<"duration: "<<obj["duration"]<<endl;
|
||||||
cout<<"Duration: "<<song.duration<<endl;
|
cout<<"song_data: "<<obj["song_data"]<<endl;
|
||||||
cout<<"Path: "<<song.songPath<<endl;
|
|
||||||
}
|
cout<<endl<<endl;;
|
||||||
}
|
}
|
||||||
void Upload::printJsonData(const json& obj)
|
#pragma endregion
|
||||||
{
|
#pragma endregion
|
||||||
cout<<endl<<endl<<"JSon data: "<<endl;
|
|
||||||
cout<<"id: "<<obj["id"]<<endl;
|
|
||||||
cout<<"title: "<<obj["title"]<<endl;
|
|
||||||
cout<<"artist: "<<obj["artist"]<<endl;
|
|
||||||
cout<<"album: "<<obj["album"]<<endl;
|
|
||||||
cout<<"genre: "<<obj["genre"]<<endl;
|
|
||||||
cout<<"year: "<<obj["year"]<<endl;
|
|
||||||
cout<<"duration: "<<obj["duration"]<<endl;
|
|
||||||
cout<<"song_data: "<<obj["song_data"]<<endl;
|
|
||||||
|
|
||||||
cout<<endl<<endl;;
|
|
||||||
}
|
|
||||||
#pragma Testing
|
|
||||||
#pragma Functions
|
|
||||||
}
|
}
|
||||||
|
|||||||
+46
-41
@@ -1,47 +1,52 @@
|
|||||||
#include"UI/AboutWindow.h"
|
#include "UI/AboutWindow.h"
|
||||||
|
|
||||||
using std::unique_ptr;
|
using std::unique_ptr;
|
||||||
|
|
||||||
namespace UI
|
namespace UI
|
||||||
{
|
{
|
||||||
AboutWindow::AboutWindow(QWidget* parent): QDialog(parent)
|
#pragma region Constructors
|
||||||
{
|
AboutWindow::AboutWindow(QWidget* parent): QDialog(parent)
|
||||||
setupWindow();
|
{
|
||||||
}
|
setupWindow();
|
||||||
|
}
|
||||||
|
#pragma endregion
|
||||||
void AboutWindow::setupWindow()
|
|
||||||
{
|
|
||||||
windowWidth = 250;
|
#pragma region Functions
|
||||||
windowHeight = 300;
|
void AboutWindow::setupWindow()
|
||||||
|
{
|
||||||
mainLayoutQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
windowWidth = 250;
|
||||||
|
windowHeight = 300;
|
||||||
appName = unique_ptr<QLabel>{new QLabel(tr("IcarusDownloadManager"))};
|
|
||||||
actionButtonQt = unique_ptr<QPushButton>{new QPushButton(tr("Close"))};
|
mainLayoutQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
||||||
|
|
||||||
mainLayoutQt->addWidget(appName.get());
|
appName = unique_ptr<QLabel>{new QLabel(tr("IcarusDownloadManager"))};
|
||||||
mainLayoutQt->addWidget(actionButtonQt.get());
|
actionButtonQt = unique_ptr<QPushButton>{new QPushButton(tr("Close"))};
|
||||||
|
|
||||||
|
mainLayoutQt->addWidget(appName.get());
|
||||||
setFixedWidth(windowWidth);
|
mainLayoutQt->addWidget(actionButtonQt.get());
|
||||||
setFixedHeight(windowHeight);
|
|
||||||
|
|
||||||
setLayout(mainLayoutQt.get());
|
setFixedWidth(windowWidth);
|
||||||
|
setFixedHeight(windowHeight);
|
||||||
setWindowTitle("About");
|
|
||||||
|
setLayout(mainLayoutQt.get());
|
||||||
connections();
|
|
||||||
}
|
setWindowTitle("About");
|
||||||
void AboutWindow::connections()
|
|
||||||
{
|
connections();
|
||||||
QObject::connect(actionButtonQt.get(), SIGNAL(clicked()), this,
|
}
|
||||||
SLOT(closeWindow()));
|
void AboutWindow::connections()
|
||||||
}
|
{
|
||||||
|
QObject::connect(actionButtonQt.get(), SIGNAL(clicked()), this,
|
||||||
|
SLOT(closeWindow()));
|
||||||
void AboutWindow::closeWindow()
|
}
|
||||||
{
|
|
||||||
this->hide();
|
|
||||||
}
|
void AboutWindow::closeWindow()
|
||||||
|
{
|
||||||
|
this->hide();
|
||||||
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+165
-159
@@ -1,11 +1,11 @@
|
|||||||
#include"UI/MainWindow.h"
|
#include "UI/MainWindow.h"
|
||||||
|
|
||||||
#include<iostream>
|
#include <iostream>
|
||||||
#include<string>
|
#include <string>
|
||||||
|
|
||||||
#include"Models/UploadForm.h"
|
#include "Models/UploadForm.h"
|
||||||
#include"Syncers/Upload.h"
|
#include "Syncers/Upload.h"
|
||||||
#include"Utilities/Conversions.h"
|
#include "Utilities/Conversions.h"
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
@@ -17,158 +17,164 @@ using Syncers::Upload;
|
|||||||
|
|
||||||
namespace UI
|
namespace UI
|
||||||
{
|
{
|
||||||
MainWindow::MainWindow()
|
|
||||||
{
|
|
||||||
setupMainWindow();
|
|
||||||
aboutWindow = unique_ptr<AboutWindow>{new AboutWindow};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#pragma region Constructors
|
||||||
void MainWindow::configureDownloadSection()
|
MainWindow::MainWindow()
|
||||||
{
|
{
|
||||||
}
|
setupMainWindow();
|
||||||
void MainWindow::configureUploadSection()
|
aboutWindow = unique_ptr<AboutWindow>{new AboutWindow};
|
||||||
{
|
}
|
||||||
uploadSongQt = unique_ptr<QPushButton>{new QPushButton(tr("Upload"))};
|
#pragma endregion
|
||||||
urlQt = unique_ptr<QTextEdit>{new QTextEdit()};
|
|
||||||
sourceFilePathQt = unique_ptr<QTextEdit>{new QTextEdit()};
|
|
||||||
|
#pragma region Functions
|
||||||
urlLabel = unique_ptr<QLabel>{new QLabel(tr("URL"))};
|
void MainWindow::configureDownloadSection()
|
||||||
songPath = unique_ptr<QLabel>{new QLabel(tr("Song Path"))};
|
{
|
||||||
|
}
|
||||||
urlPortion = unique_ptr<QHBoxLayout>{new QHBoxLayout};
|
void MainWindow::configureUploadSection()
|
||||||
songPathPortion = unique_ptr<QHBoxLayout>{new QHBoxLayout};
|
{
|
||||||
|
uploadSongQt = unique_ptr<QPushButton>{new QPushButton(tr("Upload"))};
|
||||||
urlPortion.get()->addWidget(urlLabel.get());
|
urlQt = unique_ptr<QTextEdit>{new QTextEdit()};
|
||||||
urlPortion.get()->addWidget(urlQt.get());
|
sourceFilePathQt = unique_ptr<QTextEdit>{new QTextEdit()};
|
||||||
|
|
||||||
songPathPortion->addWidget(songPath.get());
|
urlLabel = unique_ptr<QLabel>{new QLabel(tr("URL"))};
|
||||||
songPathPortion->addWidget(sourceFilePathQt.get());
|
songPath = unique_ptr<QLabel>{new QLabel(tr("Song Path"))};
|
||||||
|
|
||||||
subLayoutOneQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
urlPortion = unique_ptr<QHBoxLayout>{new QHBoxLayout};
|
||||||
subLayoutOneQt.get()->addLayout(urlPortion.get());
|
songPathPortion = unique_ptr<QHBoxLayout>{new QHBoxLayout};
|
||||||
subLayoutOneQt->addLayout(songPathPortion.get());
|
|
||||||
mainLayoutQt.get()->addLayout(subLayoutOneQt.get());
|
urlPortion.get()->addWidget(urlLabel.get());
|
||||||
}
|
urlPortion.get()->addWidget(urlQt.get());
|
||||||
void MainWindow::configureWindowDimensions()
|
|
||||||
{
|
songPathPortion->addWidget(songPath.get());
|
||||||
windowWidth = 450;
|
songPathPortion->addWidget(sourceFilePathQt.get());
|
||||||
windowHeight = 450;
|
|
||||||
}
|
subLayoutOneQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
||||||
void MainWindow::configureWindowProperties()
|
subLayoutOneQt.get()->addLayout(urlPortion.get());
|
||||||
{
|
subLayoutOneQt->addLayout(songPathPortion.get());
|
||||||
setWindowTitle("IcarusDownloadManager");
|
mainLayoutQt.get()->addLayout(subLayoutOneQt.get());
|
||||||
setFixedHeight(windowHeight);
|
}
|
||||||
setFixedWidth(windowWidth);
|
void MainWindow::configureWindowDimensions()
|
||||||
}
|
{
|
||||||
void MainWindow::connections()
|
windowWidth = 450;
|
||||||
{
|
windowHeight = 450;
|
||||||
QObject::connect(uploadSongQt.get(), SIGNAL(clicked()), this, SLOT(uploadSong()));
|
}
|
||||||
QObject::connect(closeApplicationQt.get(), SIGNAL(triggered()), this,
|
void MainWindow::configureWindowProperties()
|
||||||
SLOT(exitApplication()));
|
{
|
||||||
QObject::connect(aboutApplicationQt.get(), SIGNAL(triggered()), this,
|
setWindowTitle("IcarusDownloadManager");
|
||||||
SLOT(displaySoftwareInformation()));
|
setFixedHeight(windowHeight);
|
||||||
QObject::connect(windowComboBox.get(), SIGNAL(activated(int)),
|
setFixedWidth(windowWidth);
|
||||||
this, SLOT(setCurrentIndex(int)));
|
}
|
||||||
}
|
void MainWindow::connections()
|
||||||
void MainWindow::createMenus()
|
{
|
||||||
{
|
QObject::connect(uploadSongQt.get(), SIGNAL(clicked()), this, SLOT(uploadSong()));
|
||||||
fileMenuQt = unique_ptr<QMenu>{menuBar()->addMenu(tr("File"))};
|
QObject::connect(closeApplicationQt.get(), SIGNAL(triggered()), this,
|
||||||
editMenuQt = unique_ptr<QMenu>{menuBar()->addMenu(tr("Edit"))};
|
SLOT(exitApplication()));
|
||||||
helpMenuQt = unique_ptr<QMenu>{menuBar()->addMenu(tr("Help"))};
|
QObject::connect(aboutApplicationQt.get(), SIGNAL(triggered()), this,
|
||||||
|
SLOT(displaySoftwareInformation()));
|
||||||
closeApplicationQt = unique_ptr<QAction>{new QAction(new QObject(nullptr))};
|
QObject::connect(windowComboBox.get(), SIGNAL(activated(int)),
|
||||||
closeApplicationQt->setText("Exit Application");
|
this, SLOT(setCurrentIndex(int)));
|
||||||
|
}
|
||||||
aboutApplicationQt = unique_ptr<QAction>{new QAction(new QObject(nullptr))};
|
void MainWindow::createMenus()
|
||||||
aboutApplicationQt->setText("About");
|
{
|
||||||
|
fileMenuQt = unique_ptr<QMenu>{menuBar()->addMenu(tr("File"))};
|
||||||
fileMenuQt->addAction(closeApplicationQt.get());
|
editMenuQt = unique_ptr<QMenu>{menuBar()->addMenu(tr("Edit"))};
|
||||||
helpMenuQt->addAction(aboutApplicationQt.get());
|
helpMenuQt = unique_ptr<QMenu>{menuBar()->addMenu(tr("Help"))};
|
||||||
|
|
||||||
}
|
closeApplicationQt = unique_ptr<QAction>{new QAction(new QObject(nullptr))};
|
||||||
void MainWindow::setupMainWidget()
|
closeApplicationQt->setText("Exit Application");
|
||||||
{
|
|
||||||
mainWidgetQt = unique_ptr<QWidget>{new QWidget};
|
aboutApplicationQt = unique_ptr<QAction>{new QAction(new QObject(nullptr))};
|
||||||
|
aboutApplicationQt->setText("About");
|
||||||
windowComboBox = unique_ptr<QComboBox>{new QComboBox};
|
|
||||||
setupWindowLists();
|
fileMenuQt->addAction(closeApplicationQt.get());
|
||||||
|
helpMenuQt->addAction(aboutApplicationQt.get());
|
||||||
|
|
||||||
stackLayout = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
}
|
||||||
stackLayout->addWidget(windowComboBox.get());
|
void MainWindow::setupMainWidget()
|
||||||
|
{
|
||||||
uploadSongWidgetQt = unique_ptr<QWidget>{new QWidget};
|
mainWidgetQt = unique_ptr<QWidget>{new QWidget};
|
||||||
uploadSongWidgetQt->setLayout(mainLayoutQt.get());
|
|
||||||
|
windowComboBox = unique_ptr<QComboBox>{new QComboBox};
|
||||||
stackLayout->addWidget(uploadSongWidgetQt.get());
|
setupWindowLists();
|
||||||
|
|
||||||
mainWidgetQt->setLayout(stackLayout.get());
|
|
||||||
}
|
stackLayout = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
||||||
void MainWindow::setupMainWindow()
|
stackLayout->addWidget(windowComboBox.get());
|
||||||
{
|
|
||||||
configureWindowDimensions();
|
uploadSongWidgetQt = unique_ptr<QWidget>{new QWidget};
|
||||||
|
uploadSongWidgetQt->setLayout(mainLayoutQt.get());
|
||||||
mainLayoutQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
|
||||||
widgetStack = unique_ptr<QStackedWidget>{new QStackedWidget};
|
stackLayout->addWidget(uploadSongWidgetQt.get());
|
||||||
|
|
||||||
configureUploadSection();
|
mainWidgetQt->setLayout(stackLayout.get());
|
||||||
|
}
|
||||||
setupMainWidget();
|
void MainWindow::setupMainWindow()
|
||||||
|
{
|
||||||
widgetStack->addWidget(mainWidgetQt.get());
|
configureWindowDimensions();
|
||||||
|
|
||||||
MainDockWidgetQt = unique_ptr<QDockWidget>{new QDockWidget};
|
mainLayoutQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
||||||
MainDockWidgetQt.get()->setWindowTitle(tr("Music Manager"));
|
widgetStack = unique_ptr<QStackedWidget>{new QStackedWidget};
|
||||||
MainDockWidgetQt->setWidget(widgetStack.get());
|
|
||||||
MainDockWidgetQt.get()->setFeatures(QDockWidget::NoDockWidgetFeatures);
|
configureUploadSection();
|
||||||
|
|
||||||
setCentralWidget(MainDockWidgetQt.get());
|
setupMainWidget();
|
||||||
|
|
||||||
createMenus();
|
widgetStack->addWidget(mainWidgetQt.get());
|
||||||
|
|
||||||
configureWindowProperties();
|
MainDockWidgetQt = unique_ptr<QDockWidget>{new QDockWidget};
|
||||||
|
MainDockWidgetQt.get()->setWindowTitle(tr("Music Manager"));
|
||||||
connections();
|
MainDockWidgetQt->setWidget(widgetStack.get());
|
||||||
}
|
MainDockWidgetQt.get()->setFeatures(QDockWidget::NoDockWidgetFeatures);
|
||||||
void MainWindow::setupWindowLists()
|
|
||||||
{
|
setCentralWidget(MainDockWidgetQt.get());
|
||||||
windowComboBox->addItem(tr("Upload song"));
|
|
||||||
windowComboBox->addItem(tr("Download song"));
|
createMenus();
|
||||||
windowComboBox->addItem(tr("Display all songs"));
|
|
||||||
windowComboBox->addItem(tr("Display songs"));
|
configureWindowProperties();
|
||||||
}
|
|
||||||
|
connections();
|
||||||
|
}
|
||||||
void MainWindow::exitApplication()
|
void MainWindow::setupWindowLists()
|
||||||
{
|
{
|
||||||
exit(0);
|
windowComboBox->addItem(tr("Upload song"));
|
||||||
}
|
windowComboBox->addItem(tr("Download song"));
|
||||||
void MainWindow::displaySoftwareInformation()
|
windowComboBox->addItem(tr("Display all songs"));
|
||||||
{
|
windowComboBox->addItem(tr("Display songs"));
|
||||||
aboutWindow->show();
|
}
|
||||||
}
|
|
||||||
void MainWindow::setCurrentIndex(int index)
|
|
||||||
{
|
void MainWindow::exitApplication()
|
||||||
cout<<"index "<<index<<endl;
|
{
|
||||||
QString qText = windowComboBox->itemText(index);
|
exit(0);
|
||||||
auto cnvert = Utilities::Conversions(qText);
|
}
|
||||||
auto convertedStr = cnvert.convertQStringToString();
|
void MainWindow::displaySoftwareInformation()
|
||||||
cout<<"item text"<<endl;
|
{
|
||||||
}
|
aboutWindow->show();
|
||||||
void MainWindow::uploadSong()
|
}
|
||||||
{
|
void MainWindow::setCurrentIndex(int index)
|
||||||
uploadSongQt->setEnabled(false);
|
{
|
||||||
|
cout<<"index "<<index<<endl;
|
||||||
string url = urlQt->toPlainText().toUtf8().constData();
|
QString qText = windowComboBox->itemText(index);
|
||||||
string filePath = sourceFilePathQt->toPlainText().toUtf8().constData();
|
auto cnvert = Utilities::Conversions(qText);
|
||||||
cout<<"URL endpoint: "<<url<<endl;
|
auto convertedStr = cnvert.convertQStringToString();
|
||||||
cout<<"Music file path: "<<filePath<<endl;
|
cout<<"item text"<<endl;
|
||||||
UploadForm formData{url, filePath};
|
}
|
||||||
|
void MainWindow::uploadSong()
|
||||||
Upload upld{formData};
|
{
|
||||||
upld.uploadSong();
|
uploadSongQt->setEnabled(false);
|
||||||
|
|
||||||
uploadSongQt->setEnabled(true);
|
string url = urlQt->toPlainText().toUtf8().constData();
|
||||||
}
|
string filePath = sourceFilePathQt->toPlainText().toUtf8().constData();
|
||||||
|
cout<<"URL endpoint: "<<url<<endl;
|
||||||
|
cout<<"Music file path: "<<filePath<<endl;
|
||||||
|
UploadForm formData{url, filePath};
|
||||||
|
|
||||||
|
Upload upld{formData};
|
||||||
|
upld.uploadSong();
|
||||||
|
|
||||||
|
uploadSongQt->setEnabled(true);
|
||||||
|
}
|
||||||
|
#pragma endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +1,26 @@
|
|||||||
#include"Utilities/Conversions.h"
|
#include "Utilities/Conversions.h"
|
||||||
|
|
||||||
#include<iostream>
|
#include <iostream>
|
||||||
|
|
||||||
using std::string;
|
using std::string;
|
||||||
using std::unique_ptr;
|
using std::unique_ptr;
|
||||||
|
|
||||||
namespace Utilities
|
namespace Utilities
|
||||||
{
|
{
|
||||||
Conversions::Conversions()
|
|
||||||
{
|
|
||||||
initializeValues();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Conversions::initializeValues()
|
Conversions::Conversions()
|
||||||
{
|
{
|
||||||
}
|
initializeValues();
|
||||||
template <typename T>
|
}
|
||||||
void Conversions::printValue(T val)
|
|
||||||
{
|
void Conversions::initializeValues()
|
||||||
std::cout<<"going to print value"<<std::endl;
|
{
|
||||||
std::cout<<val<<std::endl;
|
}
|
||||||
}
|
template <typename T>
|
||||||
|
void Conversions::printValue(T val)
|
||||||
|
{
|
||||||
|
std::cout<<"going to print value"<<std::endl;
|
||||||
|
std::cout<<val<<std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user