diff --git a/include/Managers/ActionManager.h b/include/Managers/ActionManager.h index 51f638e..9661c5c 100644 --- a/include/Managers/ActionManager.h +++ b/include/Managers/ActionManager.h @@ -12,78 +12,80 @@ namespace Managers { - class ActionManager + + + +class ActionManager +{ +public: + ActionManager(char**, int); + + Models::IcarusAction retrieveIcarusAction() const; +private: + constexpr std::array supportedFlags() noexcept { - public: - ActionManager(char**, int); + constexpr std::array allFlags{"-u", "-p", "-t", "-h", "-s", + "-sd", "-sr", "-d", "-D", "-b", "-rt", "-nc", + "-m", "-ca", "-smca", "-t"}; - Models::IcarusAction retrieveIcarusAction() const; - private: - constexpr std::array supportedFlags() noexcept + return allFlags; + } + constexpr std::array supportedActions() noexcept; + + void initialize(); + void validateFlags(); + // Checks to see if the flag is valid + template + bool isValidFlag(const Str flag) + { + const auto flags = supportedFlags(); + const auto i = std::find_if(flags.begin(), flags.end(), [&](const Str &f) { - constexpr std::array allFlags{"-u", "-p", "-t", "-h", "-s", - "-sd", "-sr", "-d", "-D", "-b", "-rt", "-nc", - "-m", "-ca", "-smca", "-t"}; + return f.compare(flag) == 0 ? true : false; + }); - return allFlags; - } - constexpr std::array supportedActions() noexcept; + auto result = i != flags.end() ? true : false; - void initialize(); - void validateFlags(); - // Checks to see if the flag is valid - template - bool isValidFlag(const Str flag) + return result; + } + + template + bool doesFlagHaveValue(const Str flag) + { + const auto flags = parsedFlags(); + auto i = std::find_if(flags.begin(), flags.end(), [&](const Str &f) { - const auto flags = supportedFlags(); - const auto i = std::find_if(flags.begin(), flags.end(), [&](const Str &f) - { - return f.compare(flag) == 0 ? true : false; - }); + return f.compare(flag) == 0 ? true : false; + }); - auto result = i != flags.end() ? true : false; - - return result; - } - - template - bool doesFlagHaveValue(const Str flag) + if (i != flags.end()) { - const auto flags = parsedFlags(); - auto i = std::find_if(flags.begin(), flags.end(), [&](const Str &f) + if (++i != flags.end() && !isValidFlag(*i)) { - return f.compare(flag) == 0 ? true : false; - }); - - if (i != flags.end()) - { - if (++i != flags.end() && !isValidFlag(*i)) - { - return true; - } - else - { - return false; - } + return true; } else { return false; } } + else + { + return false; + } + } - std::vector parsedFlags(); + void printAction() noexcept; + void printFlags() noexcept; - void printAction() noexcept; - void printFlags() noexcept; + std::string action; + + std::vector flags; - std::string action; - - std::vector flags; + char **params; + int paramCount; +}; - char **params; - int paramCount; - }; } #endif diff --git a/include/Managers/CommitManager.h b/include/Managers/CommitManager.h index 73ff50f..f4826b6 100644 --- a/include/Managers/CommitManager.h +++ b/include/Managers/CommitManager.h @@ -14,197 +14,199 @@ namespace Managers { - class CommitManager + +class CommitManager +{ +public: + CommitManager(Models::IcarusAction&); + + void commitAction(); + + + enum class RetrieveTypes + { + songs + }; + + // Used for parsing songs from the metadata file + class Album { public: - CommitManager(Models::IcarusAction&); + Album() = default; - void commitAction(); - - enum class RetrieveTypes - { - songs - }; - - // Used for parsing songs from the metadata file - class Album - { - public: - Album() = default; - - void printInfo(); - - - std::string album; - std::string albumArtist; - std::string genre; - int year; - int trackCount; - int discCount; - std::vector songs; - }; - - private: - enum class ActionValues; - - std::map mapActions() noexcept; - - Models::Token parseToken(Models::API); - - void deleteSong(); - void downloadSong(); - void retrieveObjects(); - void uploadSong(); - // Uploads a single song. The song is constructed from a metadata file that contains - // information about the album the song is from. Also, the cover art of the song must - // be present. - // - // Expects - // * Song - mp3 file path - // * TrackID - track number to chose from when retrieving metadata. "1" and "1:1" are similar - // * Metadata - Source file containing metadata of the song - // * Cover art - path to image cover art - void uploadSongWithMetadata(); - - // Expects the song path, trackID, metadata file path, and cover path - void singTargetUpload(const std::string &songPath, const std::string &trackID, - const std::string &metaPath, const std::string &coverPath); - // Expects the source directory that contains songs, a metadata file, and cover image - // Disc and Track is retrieved from the filename if the filename conforms to a standard. - // If not, then the disc and track will default to 1 - // - // Standards - // * track01.mp3 - Disc 1, Track 1 - // * track05d02.mp3 - Disc 2, Track 5 - void multiTargetUpload(const std::string &sourcePath); - - // Standards - // * track01.mp3 - Disc 1, Track 1 - // * track05d02.mp3 - Disc 2, Track 5 - template - void initializeDiscAndTrack(Song &song) - { - auto disc = 1; - auto track = 1; - // If 1 go with first standard, if 2 go with the second, if 0 then will default to 1 for disc and track - auto mode = 0; - const Str &songPath = song.songPath; - - auto trd = song.songPath.find("trackd"); - auto tr = song.songPath.find("track"); - - if (tr != Str::npos) - { - mode = 1; - } - - if (trd != Str::npos) - { - mode = 2; - } - - auto dl = [](char c, char t){ return c == t; }; - auto d = Utilities::Checks::itemIterInContainer(songPath, 'd', dl); - auto k = Utilities::Checks::itemIterInContainer(songPath, 'k', dl); - auto dot = Utilities::Checks::itemIterInContainer(songPath, '.', dl); - - switch(mode) - { - case 1: - { - if (k != songPath.end() && dot != songPath.end()) - { - auto tStr = std::string(++k, dot); - std::cout << "TStr: " << tStr<<"\n"; - - if (Utilities::Checks::isNumber(tStr)) - { - track = std::atoi(tStr.c_str()); - } - } - break; - } - case 2: - { - if (k != songPath.end() && dot != songPath.end() && d != songPath.end()) - { - auto tStr = std::string(++k, d); - auto dStr = std::string(++d, dot); - std::cout<<"DStr: "< - void parseDiscAndTrack(Song &song, const Str &trackID) - { - auto sep = [](char c, char t) { return c == t; }; - auto separator = Utilities::Checks::itemIterInContainer(trackID, ':', sep); - - if (separator != trackID.end()) - { - auto dStr = Str(trackID.begin(), separator); - auto tStr = Str(++separator, trackID.end()); - - song.disc = std::atoi(dStr.c_str()); - song.track = std::atoi(tStr.c_str()); - } - else - { - auto isNumber = Utilities::Checks::isNumber(trackID); - if (isNumber) - { - song.track = std::atoi(trackID.c_str()); - } - } - } - - - // Checks for the no confirm flag. Used when uploading songs from a directory - bool checkForNoConfirm() - { - for (const auto &arg: this->icaAction.flags) - { - if (arg.flag.compare("-nc") == 0) - { - return true; - } - } - - return false; - } - - - Album retrieveMetadata(const std::string_view path); - std::string retrieveFileContent(const std::string_view path); - - enum class ActionValues - { - deleteAct, - downloadAct, - retrieveAct, - uploadAct, - UPLOAD_SONG_WITH_METADATA // Uploads the song with metadata, including cover art - }; - - - Models::IcarusAction icaAction; + std::string album; + std::string albumArtist; + std::string genre; + int year; + int trackCount; + int discCount; + std::vector songs; }; + +private: + enum class ActionValues; + + std::map mapActions() noexcept; + + void deleteSong(); + void downloadSong(); + void retrieveObjects(); + void uploadSong(); + // Uploads a single song. The song is constructed from a metadata file that contains + // information about the album the song is from. Also, the cover art of the song must + // be present. + // + // Expects + // * Song - mp3 file path + // * TrackID - track number to chose from when retrieving metadata. "1" and "1:1" are similar + // * Metadata - Source file containing metadata of the song + // * Cover art - path to image cover art + void uploadSongWithMetadata(); + + // Expects the song path, trackID, metadata file path, and cover path + void singTargetUpload(const std::string &songPath, const std::string &trackID, + const std::string &metaPath, const std::string &coverPath); + // Expects the source directory that contains songs, a metadata file, and cover image + // Disc and Track is retrieved from the filename if the filename conforms to a standard. + // If not, then the disc and track will default to 1 + // + // Standards + // * track01.mp3 - Disc 1, Track 1 + // * track05d02.mp3 - Disc 2, Track 5 + void multiTargetUpload(const std::string &sourcePath); + + // Standards + // * track01.mp3 - Disc 1, Track 1 + // * track05d02.mp3 - Disc 2, Track 5 + template + void initializeDiscAndTrack(Song &song) + { + auto disc = 1; + auto track = 1; + // If 1 go with first standard, if 2 go with the second, if 0 then will default to 1 for disc and track + auto mode = 0; + const Str &songPath = song.songPath; + + auto trd = song.songPath.find("trackd"); + auto tr = song.songPath.find("track"); + + if (tr != Str::npos) + { + mode = 1; + } + + if (trd != Str::npos) + { + mode = 2; + } + + auto dl = [](char c, char t){ return c == t; }; + auto d = Utilities::Checks::itemIterInContainer(songPath, 'd', dl); + auto k = Utilities::Checks::itemIterInContainer(songPath, 'k', dl); + auto dot = Utilities::Checks::itemIterInContainer(songPath, '.', dl); + + switch(mode) + { + case 1: + { + if (k != songPath.end() && dot != songPath.end()) + { + auto tStr = std::string(++k, dot); + std::cout << "TStr: " << tStr<<"\n"; + + if (Utilities::Checks::isNumber(tStr)) + { + track = std::atoi(tStr.c_str()); + } + } + break; + } + case 2: + { + if (k != songPath.end() && dot != songPath.end() && d != songPath.end()) + { + auto tStr = std::string(++k, d); + auto dStr = std::string(++d, dot); + std::cout<<"DStr: "< + void parseDiscAndTrack(Song &song, const Str &trackID) + { + auto sep = [](char c, char t) { return c == t; }; + auto separator = Utilities::Checks::itemIterInContainer(trackID, ':', sep); + + if (separator != trackID.end()) + { + auto dStr = Str(trackID.begin(), separator); + auto tStr = Str(++separator, trackID.end()); + + song.disc = std::atoi(dStr.c_str()); + song.track = std::atoi(tStr.c_str()); + } + else + { + auto isNumber = Utilities::Checks::isNumber(trackID); + if (isNumber) + { + song.track = std::atoi(trackID.c_str()); + } + } + } + + + // Checks for the no confirm flag. Used when uploading songs from a directory + bool checkForNoConfirm() + { + for (const auto &arg: this->icaAction.flags) + { + if (arg.flag.compare("-nc") == 0) + { + return true; + } + } + + return false; + } + + + Album retrieveMetadata(const std::string_view path); + std::string retrieveFileContent(const std::string_view path); + + enum class ActionValues + { + deleteAct, + downloadAct, + retrieveAct, + uploadAct, + UPLOAD_SONG_WITH_METADATA // Uploads the song with metadata, including cover art + }; + + + Models::IcarusAction icaAction; + +}; + } #endif diff --git a/include/Managers/FileManager.h b/include/Managers/FileManager.h index db0fc68..675950c 100644 --- a/include/Managers/FileManager.h +++ b/include/Managers/FileManager.h @@ -5,25 +5,27 @@ namespace Managers { - class FileManager - { - public: - FileManager(); - FileManager(std::string); - void saveFile(std::string); - void modifyFilePath(std::string); +class FileManager +{ +public: + FileManager(); + FileManager(std::string); - char* retrieveFileBuffer() const; - int retrieveFileBufferLength() const; - private: - void readFile(); + void saveFile(std::string); + void modifyFilePath(std::string); + + 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 diff --git a/include/Managers/TokenManager.h b/include/Managers/TokenManager.h index 9f07556..4e42632 100644 --- a/include/Managers/TokenManager.h +++ b/include/Managers/TokenManager.h @@ -7,17 +7,19 @@ namespace Managers { - class TokenManager - { - public: - TokenManager(const Models::User&); - TokenManager(const Models::User&, Models::API&); - Models::Token requestToken(); - private: - Models::API api; - Models::User user; - }; +class TokenManager +{ +public: + TokenManager(const Models::User&); + TokenManager(const Models::User&, Models::API&); + + Models::Token requestToken(); +private: + Models::API api; + Models::User user; +}; + } #endif diff --git a/include/Managers/UserManager.h b/include/Managers/UserManager.h index 21b9755..423e938 100644 --- a/include/Managers/UserManager.h +++ b/include/Managers/UserManager.h @@ -8,19 +8,21 @@ namespace Managers { - class UserManager - { - public: - UserManager(Models::User); - UserManager(const Models::IcarusAction); - Models::User retrieveUser() const; - private: - void parseUserFromActions(); +class UserManager +{ +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 diff --git a/include/Models/API.h b/include/Models/API.h index cd7a5cd..7c72fc2 100644 --- a/include/Models/API.h +++ b/include/Models/API.h @@ -5,12 +5,15 @@ namespace Models { - struct API - { - std::string url; - std::string endpoint; - std::string version; - }; + +class API +{ +public: + std::string url; + std::string endpoint; + std::string version; +}; + } #endif diff --git a/include/Models/Flags.h b/include/Models/Flags.h index 7f7c557..aa03c4d 100644 --- a/include/Models/Flags.h +++ b/include/Models/Flags.h @@ -5,12 +5,21 @@ namespace Models { - class Flags - { - public: - std::string flag; - std::string value; - }; + +class Flags +{ +public: + std::string flag; + std::string value; +}; + + +struct Flags +{ + std::string flag; + std::string value; +}; + } #endif diff --git a/include/Models/IcarusAction.h b/include/Models/IcarusAction.h index c6f8d1a..031886d 100644 --- a/include/Models/IcarusAction.h +++ b/include/Models/IcarusAction.h @@ -11,41 +11,43 @@ namespace Models { - class IcarusAction + +class IcarusAction +{ +public: + std::string retrieveFlagValue(const std::string_view flag) { - public: - std::string retrieveFlagValue(const std::string_view flag) + std::string value; + + const auto fg = std::find_if(flags.begin(), flags.end(), [&](Flags f) { - std::string value; + return f.flag.compare(flag) == 0 ? true : false; + }); - const auto fg = std::find_if(flags.begin(), flags.end(), [&](Flags f) - { - return f.flag.compare(flag) == 0 ? true : false; - }); - - if (fg != flags.end()) - { - value.assign(fg->value); - } - - return value; - } - void print_action_and_flags() noexcept + if (fg != flags.end()) { - std::cout<<"Action: "<action<<"\n"; - std::cout<<"Flag count: "<flags.size()<<"\n"; - - for (const auto &flag : this->flags) - { - std::cout<<"flag "<value); } - std::string action; - std::vector flags; - }; + return value; + } + void print_action_and_flags() noexcept + { + std::cout<<"Action: "<action<<"\n"; + std::cout<<"Flag count: "<flags.size()<<"\n"; + + for (const auto &flag : this->flags) + { + std::cout<<"flag "< flags; +}; + } #endif diff --git a/include/Models/Song.h b/include/Models/Song.h index 4cafbe3..8512666 100644 --- a/include/Models/Song.h +++ b/include/Models/Song.h @@ -7,40 +7,42 @@ namespace Models { - class Song + +class Song +{ +public: + Song() = default; + + void printInfo() { - public: - Song() = default; + std::cout<<"Title: "<title<<"\n"; + std::cout<<"\n"; + } - void printInfo() - { - std::cout<<"Title: "<title<<"\n"; - std::cout<<"\n"; - } + std::string toMetadataJson(); - std::string toMetadataJson(); - - int id; - std::string title; - std::string artist; - std::string album; - std::string genre; - int year; - int duration; - int track; - int disc; - std::string data; - std::string songPath; - }; + int id; + std::string title; + std::string artist; + std::string album; + std::string genre; + int year; + int duration; + int track; + int disc; + std::string data; + std::string songPath; +}; + +class CoverArt +{ +public: + int id; + std::string title; + std::string path; +}; - class CoverArt - { - public: - int id; - std::string title; - std::string path; - }; } #endif diff --git a/include/Models/Token.h b/include/Models/Token.h index cc66a54..eeb0338 100644 --- a/include/Models/Token.h +++ b/include/Models/Token.h @@ -5,12 +5,14 @@ namespace Models { - struct Token - { - std::string accessToken; - std::string tokenType; - int expiration; - }; + +struct Token +{ + std::string accessToken; + std::string tokenType; + int expiration; +}; + } #endif diff --git a/include/Models/UploadForm.h b/include/Models/UploadForm.h index cbdf950..b65b957 100644 --- a/include/Models/UploadForm.h +++ b/include/Models/UploadForm.h @@ -6,11 +6,13 @@ namespace Models { - struct UploadForm - { - std::string url; - std::string filePath; - }; + +struct UploadForm +{ + std::string url; + std::string filePath; +}; + } #endif diff --git a/include/Models/User.h b/include/Models/User.h index b64523a..aed560d 100644 --- a/include/Models/User.h +++ b/include/Models/User.h @@ -5,11 +5,13 @@ namespace Models { - struct User - { - std::string username; - std::string password; - }; + +struct User +{ + std::string username; + std::string password; +}; + } #endif diff --git a/include/Parsers/APIParser.h b/include/Parsers/APIParser.h index ca24801..51aa22b 100644 --- a/include/Parsers/APIParser.h +++ b/include/Parsers/APIParser.h @@ -6,18 +6,20 @@ namespace Parsers { - class APIParser - { - public: - APIParser(Models::IcarusAction); - Models::API retrieveAPI() const; - private: - void parseAPI(); +class APIParser +{ +public: + APIParser(Models::IcarusAction); + + Models::API retrieveAPI() const; +private: + void parseAPI(); + + Models::API api; + Models::IcarusAction icaAct; +}; - Models::API api; - Models::IcarusAction icaAct; - }; } #endif diff --git a/include/Syncers/Delete.h b/include/Syncers/Delete.h index 0546578..b927f64 100644 --- a/include/Syncers/Delete.h +++ b/include/Syncers/Delete.h @@ -9,15 +9,17 @@ namespace Syncers { - class Delete : SyncerBase - { - public: - Delete(Models::API); - void deleteSong(const Models::Token, Models::Song); - private: - std::string retrieveUrl(Models::Song); - }; +class Delete : SyncerBase +{ +public: + Delete(Models::API); + + void deleteSong(const Models::Token, Models::Song); +private: + std::string retrieveUrl(Models::Song); +}; + } #endif diff --git a/include/Syncers/Download.h b/include/Syncers/Download.h index c5685fd..7c0fcb6 100644 --- a/include/Syncers/Download.h +++ b/include/Syncers/Download.h @@ -12,20 +12,22 @@ namespace Syncers { - class Download : SyncerBase - { - public: - Download(); - Download(Models::API); - Download(std::string); - void downloadSong(const Models::Token token, Models::Song); - private: - std::string retrieveUrl(Models::Song); +class Download : SyncerBase +{ +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 diff --git a/include/Syncers/RetrieveRecords.h b/include/Syncers/RetrieveRecords.h index 6f1709a..72fa807 100644 --- a/include/Syncers/RetrieveRecords.h +++ b/include/Syncers/RetrieveRecords.h @@ -8,19 +8,21 @@ namespace Syncers { - class RetrieveRecords: public SyncerBase - { - public: - RetrieveRecords(); - RetrieveRecords(Models::API, Models::Token); - void retrieve(Managers::CommitManager::RetrieveTypes); - private: - void fetchSongs(); +class RetrieveRecords: public SyncerBase +{ +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 diff --git a/include/Syncers/SyncerBase.h b/include/Syncers/SyncerBase.h index 12d36e4..6948a42 100644 --- a/include/Syncers/SyncerBase.h +++ b/include/Syncers/SyncerBase.h @@ -7,21 +7,23 @@ namespace Syncers { - class SyncerBase - { - protected: - Models::API api; - const int OK = 200; - const int UNAUTHORIZED = 401; - const int NOTFOUND = 404; - enum class Result - { - OK = 200, - UNAUTHORIZED = 401, - NOTFOUND = 404 - }; +class SyncerBase +{ +protected: + Models::API api; + const int OK = 200; + const int UNAUTHORIZED = 401; + const int NOTFOUND = 404; + + enum class Result + { + OK = 200, + UNAUTHORIZED = 401, + NOTFOUND = 404 }; +}; + } #endif diff --git a/include/Syncers/Upload.h b/include/Syncers/Upload.h index 527300b..993f0c0 100644 --- a/include/Syncers/Upload.h +++ b/include/Syncers/Upload.h @@ -19,34 +19,36 @@ namespace fs = std::filesystem; namespace Syncers { - class Upload + +class Upload +{ +public: + Upload(Models::API api, Models::Token token) : m_token(token), api(api) { - public: - Upload(Models::API api, Models::Token token) : m_token(token), api(api) - { - this->api.endpoint = "song/data"; - } + this->api.endpoint = "song/data"; + } - Models::Song uploadSong(Models::Song&); - void uploadSongsFromDirectory(const std::string&, const bool, bool); - void uploadSongWithMetadata(Managers::CommitManager::Album&, Models::Song&, Models::CoverArt&); - private: - Managers::FileManager fMgr; - Models::API api; - Models::Song song; - Models::Token m_token; + Models::Song uploadSong(Models::Song&); + void uploadSongsFromDirectory(const std::string&, const bool, bool); + void uploadSongWithMetadata(Managers::CommitManager::Album&, Models::Song&, Models::CoverArt&); +private: + Managers::FileManager fMgr; + Models::API api; + Models::Song song; + Models::Token m_token; - std::vector retrieveAllSongsFromDirectory(const std::string&, - bool); + std::vector retrieveAllSongsFromDirectory(const std::string&, + bool); - std::string retrieveUrl(); + std::string retrieveUrl(); - Models::Song retrieveSongPath(fs::directory_entry&); + Models::Song retrieveSongPath(fs::directory_entry&); + + void printSongDetails(); + void printSongDetails(std::vector&); + void printJsonData(const nlohmann::json&); +}; - void printSongDetails(); - void printSongDetails(std::vector&); - void printJsonData(const nlohmann::json&); - }; } #endif diff --git a/include/UI/AboutWindow.h b/include/UI/AboutWindow.h index e47194c..15e5593 100644 --- a/include/UI/AboutWindow.h +++ b/include/UI/AboutWindow.h @@ -13,22 +13,24 @@ namespace UI { - class AboutWindow: public QDialog, public CommonWindow - { - Q_OBJECT - public: - AboutWindow(QWidget* parent=0); - ~AboutWindow() = default; - private: - void connections(); - void setupWindow(); +class AboutWindow: public QDialog, public CommonWindow +{ + Q_OBJECT +public: + AboutWindow(QWidget* parent=0); + ~AboutWindow() = default; - std::unique_ptr appName; +private: + void connections(); + void setupWindow(); + + std::unique_ptr appName; + +private slots: + void closeWindow(); +}; - private slots: - void closeWindow(); - }; } #endif diff --git a/include/UI/CommonWindow.h b/include/UI/CommonWindow.h index 5b9fdd6..f3a5413 100644 --- a/include/UI/CommonWindow.h +++ b/include/UI/CommonWindow.h @@ -10,6 +10,9 @@ #include +namespace UI +{ + class CommonWindow { public: @@ -24,4 +27,7 @@ protected: std::unique_ptr subLayoutTwoQt; int windowHeight, windowWidth; }; + +} + #endif diff --git a/include/UI/MainWindow.h b/include/UI/MainWindow.h index 7c32369..0460b1e 100644 --- a/include/UI/MainWindow.h +++ b/include/UI/MainWindow.h @@ -22,61 +22,63 @@ namespace UI { - class MainWindow: public QMainWindow, public CommonWindow - { - Q_OBJECT - public: - MainWindow(); - ~MainWindow() = default; - private: - void configureDownloadSection(); - void configureUploadSection(); - void configureWindowDimensions(); - void configureWindowProperties(); - void connections(); - void createMenus(); - void setupMainWidget(); - void setupMainWindow(); - void setupWindowLists(); + +class MainWindow: public QMainWindow, public CommonWindow +{ + Q_OBJECT +public: + MainWindow(); + ~MainWindow() = default; +private: + void configureDownloadSection(); + void configureUploadSection(); + void configureWindowDimensions(); + void configureWindowProperties(); + void connections(); + void createMenus(); + void setupMainWidget(); + void setupMainWindow(); + void setupWindowLists(); - std::unique_ptr widgetStack; + std::unique_ptr widgetStack; - std::unique_ptr stackLayout; + std::unique_ptr stackLayout; - std::unique_ptr urlPortion; - std::unique_ptr songPathPortion; + std::unique_ptr urlPortion; + std::unique_ptr songPathPortion; - std::unique_ptr mainWidgetQt; - std::unique_ptr uploadSongWidgetQt; + std::unique_ptr mainWidgetQt; + std::unique_ptr uploadSongWidgetQt; - std::unique_ptr MainDockWidgetQt; + std::unique_ptr MainDockWidgetQt; - std::unique_ptr windowComboBox; - - std::unique_ptr uploadSongQt; + std::unique_ptr windowComboBox; + + std::unique_ptr uploadSongQt; - std::unique_ptr urlQt; - std::unique_ptr sourceFilePathQt; + std::unique_ptr urlQt; + std::unique_ptr sourceFilePathQt; - std::unique_ptr urlLabel; - std::unique_ptr songPath; + std::unique_ptr urlLabel; + std::unique_ptr songPath; - std::unique_ptr fileMenuQt; - std::unique_ptr editMenuQt; - std::unique_ptr helpMenuQt; + std::unique_ptr fileMenuQt; + std::unique_ptr editMenuQt; + std::unique_ptr helpMenuQt; - std::unique_ptr closeApplicationQt; - std::unique_ptr aboutApplicationQt; + std::unique_ptr closeApplicationQt; + std::unique_ptr aboutApplicationQt; + + std::unique_ptr aboutWindow; +signals: +private slots: + void uploadSong(); + void exitApplication(); + void displaySoftwareInformation(); + void setCurrentIndex(int); +}; - std::unique_ptr aboutWindow; - signals: - private slots: - void uploadSong(); - void exitApplication(); - void displaySoftwareInformation(); - void setCurrentIndex(int); - }; } #endif diff --git a/include/Utilities/Conversions.h b/include/Utilities/Conversions.h index 1e89994..f56abf2 100644 --- a/include/Utilities/Conversions.h +++ b/include/Utilities/Conversions.h @@ -6,26 +6,24 @@ namespace Utilities { - class Conversions + +class Conversions +{ +public: + Conversions(); + + static void toLowerChar(char &c) { - public: - Conversions(); - - - static void toLowerChar(char &c) + if (std::isalpha(c)) { - if (std::isalpha(c)) - { - c = std::tolower(c); - } + c = std::tolower(c); } + } - void initializeValues(); + void initializeValues(); +private: +}; - template - void printValue(T); - private: - }; } #endif diff --git a/src/Managers/ActionManager.cpp b/src/Managers/ActionManager.cpp index 04e7bcf..a27f325 100644 --- a/src/Managers/ActionManager.cpp +++ b/src/Managers/ActionManager.cpp @@ -16,103 +16,111 @@ using Models::IcarusAction; namespace Managers { - #pragma - ActionManager::ActionManager(char **param, int paramCount) : - params(std::move(param)), paramCount(paramCount) - { - initialize(); - } - #pragma Constructors + +#pragma region Constructors +ActionManager::ActionManager(char **param, int paramCount) : + params(std::move(param)), paramCount(paramCount) +{ + initialize(); +} +#pragma endregion - #pragma - IcarusAction ActionManager::retrieveIcarusAction() const - { - IcarusAction icarusAction; - icarusAction.flags = flags; - icarusAction.action = action; +#pragma region Functions +IcarusAction ActionManager::retrieveIcarusAction() const +{ + IcarusAction icarusAction; + icarusAction.flags = flags; + icarusAction.action = action; - return icarusAction; - } + return icarusAction; +} + +bool ActionManager::isNumber(string_view val) noexcept +{ + return !val.empty() && std::find_if(val.begin(), + val.end(), [](char c) + { + return !std::isdigit(c); + }) == val.end(); +} +void ActionManager::initialize() +{ + validateFlags(); - void ActionManager::initialize() - { - validateFlags(); - - action = std::move(string{params[1]}); - transform(action.begin(), action.end(), - action.begin(), ::tolower); - } - - void ActionManager::validateFlags() - { + action = std::move(string{params[1]}); + transform(action.begin(), action.end(), + action.begin(), ::tolower); +} +void ActionManager::validateFlags() +{ cout<<"Validating flags\n"; - const auto flagVals = parsedFlags(); + const auto flagVals = parsedFlags(); - for (auto flag = flagVals.begin(); flag != flagVals.end(); ++flag) - { - Flags flg; - cout<<"Value: "<<*flag<<"\n"; - - if (isValidFlag(*flag) && doesFlagHaveValue(*flag)) - { - cout<<"Flag has value\n"; - flg.flag = *flag; - flg.value = *(++flag); - } - else if (isValidFlag(*flag)) - { - cout<<"Flag does not have a value\n"; - flg.flag = *flag; - } - else - { - cout<<"Flag "<<*flag<<" is not valid"< ActionManager::parsedFlags() + for (auto flag = flagVals.begin(); flag != flagVals.end(); ++flag) { - vector parsed; - parsed.reserve(paramCount); - - for (auto i = 2; i < paramCount; ++i) + Flags flg; + cout<<"Value: "<<*flag<<"\n"; + + if (isValidFlag(*flag) && doesFlagHaveValue(*flag)) { - const std::string flag(std::move(*(params + i))); - parsed.emplace_back(std::move(flag)); + cout<<"Flag has value\n"; + flg.flag = *flag; + flg.value = *(++flag); } - - return parsed; - } - - #pragma - void ActionManager::printAction() noexcept - { - if (action.empty()) + else if (isValidFlag(*flag)) { - printf("Action is empty\n"); + cout<<"Flag does not have a value\n"; + flg.flag = *flag; } else { - cout<<"Action is "< ActionManager::parsedFlags() +{ + auto parsed = vector(); + + for (auto i = 2; i < paramCount; ++i) + { + const std::string flag(std::move(*(params + i))); + parsed.push_back(std::move(flag)); + } + + return parsed; +} + +#pragma region Testing +void ActionManager::printAction() noexcept +{ + if (action.empty()) + { + printf("Action is empty\n"); + } + else + { + cout<<"Action is "< - CommitManager::mapActions() noexcept + switch (mapActions()[action]) { - const std::map actions{ - {"delete", ActionValues::deleteAct}, - {"download", ActionValues::downloadAct}, - {"retrieve", ActionValues::retrieveAct}, - {"upload", ActionValues::uploadAct}, - {"upload-meta", ActionValues::UPLOAD_SONG_WITH_METADATA} - }; - - return actions; + case ActionValues::deleteAct: + deleteSong(); + break; + case ActionValues::downloadAct: + downloadSong(); + break; + case ActionValues::retrieveAct: + retrieveObjects(); + break; + case ActionValues::uploadAct: + uploadSong(); + break; + case ActionValues::UPLOAD_SONG_WITH_METADATA: + uploadSongWithMetadata(); + break; + default: + break; } - - - Token CommitManager::parseToken(API api) - { - cout<<"fetching token\n"; - UserManager usrMgr{icaAction}; - auto user = usrMgr.retrieveUser(); - - TokenManager tk{user, api}; - - return tk.requestToken(); - } - - void CommitManager::deleteSong() - { - APIParser apiPrs{icaAction}; - auto api = apiPrs.retrieveAPI(); - - auto token = parseToken(api); - - Song song{}; - - for (auto arg : icaAction.flags) - { - auto flag = arg.flag; - auto value = arg.value; - - if (flag.compare("-D") == 0) - { - song.id = atoi(value.c_str()); - } - } - - Delete del{api}; - cout<<"Deleting song..."<icaAction.retrieveFlagValue("-s"); - const auto metadataPath = this->icaAction.retrieveFlagValue("-m"); - const auto coverPath = this->icaAction.retrieveFlagValue("-ca"); - const auto trackID = this->icaAction.retrieveFlagValue("-t"); - const auto singleTarget = !songPath.empty() && !metadataPath.empty() && - !coverPath.empty() && !trackID.empty() ? true : false; - - const auto uni = this->icaAction.retrieveFlagValue("-smca"); - const auto multiTarget = !uni.empty() ? true : false; - - if (singleTarget && multiTarget) - { - cout<<"Cannot upload from source and directory\n"; - return; - } - - cout<<"Song path: "<(song, trackID); - - auto c = [](const Song &songA, const Song &songB) { return songA.track == songB.track && songA.disc == songB.disc; }; - auto sng = Utilities::Checks::itemIterInContainer>(album.songs, song, c); - - if (sng == album.songs.end()) - { - cout<<"Not found with disc "< songs; - Models::CoverArt cover; - string metadataPath; - - for (auto &p: fs::directory_iterator(sourcePath)) - { - const auto &pp = p.path(); - const auto stem = pp.stem(); - const auto file = pp.filename(); - const auto extension = pp.extension(); - - cout<<"Stem "<(song); - - songs.emplace_back(std::move(song)); - } - else if (extension.compare(".jpg") == 0 || extension.compare(".png") == 0) - { - cover.path.assign(pp.string()); - } - else if (extension.compare(".json") == 0) - { - metadataPath.assign(pp.string()); - } - } - - auto album = retrieveMetadata(metadataPath); - - Upload up(api, token); - - for (auto &song : songs) - { - up.uploadSongWithMetadata(album, song, cover); - } - } - - #pragma region private - CommitManager::Album CommitManager::retrieveMetadata(const std::string_view path) - { - CommitManager::Album album; - const auto fileContent = retrieveFileContent(path); - cout<<"Parsing...\n"; - auto serialized = nlohmann::json::parse(fileContent); - cout<<"Parsed\n"; - - album.album = serialized["album"].get(); - album.albumArtist = serialized["album_artist"].get(); - album.genre = serialized["genre"].get(); - album.year = serialized["year"].get(); - album.trackCount = serialized["track_count"].get(); - album.discCount = serialized["disc_count"].get(); - album.songs.reserve(album.trackCount); - - for (auto &j : serialized["tracks"]) - { - Song song; - song.title = j["title"].get(); - song.track = j["track"].get(); - song.disc = j["disc"].get(); - song.artist = j["artist"].get(); - song.album = album.album; - song.year = album.year; - song.genre = album.genre; - - album.songs.push_back(song); - } - - return album; - } - - string CommitManager::retrieveFileContent(const std::string_view path) - { - string path_str(path); - string value; - - std::stringstream buffer; - std::fstream file(path_str, std::ios::in); - buffer<album<<"\n"; - std::cout<<"Album Artist: "<albumArtist<<"\n"; - std::cout<<"Genre: "<genre<<"\n"; - std::cout<<"Year: "<year<<"\n"; - std::cout<<"Track count: "<trackCount<<"\n"; - std::cout<<"Disc count: "<discCount<<"\n"; - std::cout<<"\n"; - } - - #pragma Functions +} + + + + + + +std::map + CommitManager::mapActions() noexcept +{ + const std::map actions{ + {"delete", ActionValues::deleteAct}, + {"download", ActionValues::downloadAct}, + {"retrieve", ActionValues::retrieveAct}, + {"upload", ActionValues::uploadAct}, + {"upload-meta", ActionValues::UPLOAD_SONG_WITH_METADATA} + }; + + return actions; +} + + + + +Token CommitManager::parseToken(API api) +{ + cout<<"fetching token\n"; + UserManager usrMgr{icaAction}; + auto user = usrMgr.retrieveUser(); + + TokenManager tk{user, api}; + + return tk.requestToken(); +} + +void CommitManager::deleteSong() +{ + APIParser apiPrs{icaAction}; + auto api = apiPrs.retrieveAPI(); + + auto token = parseToken(api); + + Song song{}; + + for (auto arg : icaAction.flags) + { + auto flag = arg.flag; + auto value = arg.value; + + if (flag.compare("-D") == 0) + { + song.id = atoi(value.c_str()); + } + } + + Delete del{api}; + cout<<"Deleting song..."<icaAction.retrieveFlagValue("-s"); + const auto metadataPath = this->icaAction.retrieveFlagValue("-m"); + const auto coverPath = this->icaAction.retrieveFlagValue("-ca"); + const auto trackID = this->icaAction.retrieveFlagValue("-t"); + const auto singleTarget = !songPath.empty() && !metadataPath.empty() && + !coverPath.empty() && !trackID.empty() ? true : false; + + const auto uni = this->icaAction.retrieveFlagValue("-smca"); + const auto multiTarget = !uni.empty() ? true : false; + + if (singleTarget && multiTarget) + { + cout<<"Cannot upload from source and directory\n"; + return; + } + + cout<<"Song path: "<(song, trackID); + + auto c = [](const Song &songA, const Song &songB) { return songA.track == songB.track && songA.disc == songB.disc; }; + auto sng = Utilities::Checks::itemIterInContainer>(album.songs, song, c); + + if (sng == album.songs.end()) + { + cout<<"Not found with disc "< songs; + Models::CoverArt cover; + string metadataPath; + + for (auto &p: fs::directory_iterator(sourcePath)) + { + const auto &pp = p.path(); + const auto stem = pp.stem(); + const auto file = pp.filename(); + const auto extension = pp.extension(); + + cout<<"Stem "<(song); + + songs.emplace_back(std::move(song)); + } + else if (extension.compare(".jpg") == 0 || extension.compare(".png") == 0) + { + cover.path.assign(pp.string()); + } + else if (extension.compare(".json") == 0) + { + metadataPath.assign(pp.string()); + } + } + + auto album = retrieveMetadata(metadataPath); + + Upload up(api, token); + + for (auto &song : songs) + { + up.uploadSongWithMetadata(album, song, cover); + } +} + +#pragma region private +CommitManager::Album CommitManager::retrieveMetadata(const std::string_view path) +{ + CommitManager::Album album; + const auto fileContent = retrieveFileContent(path); + cout<<"Parsing...\n"; + auto serialized = nlohmann::json::parse(fileContent); + cout<<"Parsed\n"; + + album.album = serialized["album"].get(); + album.albumArtist = serialized["album_artist"].get(); + album.genre = serialized["genre"].get(); + album.year = serialized["year"].get(); + album.trackCount = serialized["track_count"].get(); + album.discCount = serialized["disc_count"].get(); + album.songs.reserve(album.trackCount); + + for (auto &j : serialized["tracks"]) + { + Song song; + song.title = j["title"].get(); + song.track = j["track"].get(); + song.disc = j["disc"].get(); + song.artist = j["artist"].get(); + song.album = album.album; + song.year = album.year; + song.genre = album.genre; + + album.songs.push_back(song); + } + + return album; +} + +string CommitManager::retrieveFileContent(const std::string_view path) +{ + string path_str(path); + string value; + + std::stringstream buffer; + std::fstream file(path_str, std::ios::in); + buffer<album<<"\n"; + std::cout<<"Album Artist: "<albumArtist<<"\n"; + std::cout<<"Genre: "<genre<<"\n"; + std::cout<<"Year: "<year<<"\n"; + std::cout<<"Track count: "<trackCount<<"\n"; + std::cout<<"Disc count: "<discCount<<"\n"; + std::cout<<"\n"; +} + +#pragma region Functions + } diff --git a/src/Managers/FileManager.cpp b/src/Managers/FileManager.cpp index b47fe08..a2c5618 100644 --- a/src/Managers/FileManager.cpp +++ b/src/Managers/FileManager.cpp @@ -11,56 +11,63 @@ using std::string; namespace Managers { - FileManager::FileManager() {} - FileManager::FileManager(string filePath) - { - this->filePath = filePath; + +#pragma region Constructors +FileManager::FileManager() {} +FileManager::FileManager(string filePath) +{ + this->filePath = filePath; + readFile(); +} +#pragma endregion + + +#pragma region Functions +void FileManager::saveFile(string newFilePath) +{ + if (!fileRead) readFile(); - } - - void FileManager::saveFile(string newFilePath) - { - if (!fileRead) - readFile(); - - ofstream of{newFilePath, ofstream::binary}; - of.write(fileBuffer, fileBufferLength); - of.close(); - } - - void FileManager::readFile() - { - ifstream is{filePath, ifstream::binary}; - if (is) - { - is.seekg (0, is.end); - fileBufferLength = is.tellg(); - is.seekg (0, is.beg); - - fileBuffer = new char [fileBufferLength]; - - cout<< "Reading "<filePath = filePath; - } - - char* FileManager::retrieveFileBuffer() const - { - return fileBuffer; - } - - int FileManager::retrieveFileBufferLength() const { return fileBufferLength; } + ofstream of{newFilePath, ofstream::binary}; + of.write(fileBuffer, fileBufferLength); + of.close(); +} + +void FileManager::readFile() +{ + ifstream is{filePath, ifstream::binary}; + if (is) + { + is.seekg (0, is.end); + fileBufferLength = is.tellg(); + is.seekg (0, is.beg); + + fileBuffer = new char [fileBufferLength]; + + cout<< "Reading "<filePath = filePath; +} + +char* FileManager::retrieveFileBuffer() const +{ + return fileBuffer; +} + +int FileManager::retrieveFileBufferLength() const { return fileBufferLength; } + +#pragma endregion + } diff --git a/src/Managers/TokenManager.cpp b/src/Managers/TokenManager.cpp index 730e63c..44f1725 100644 --- a/src/Managers/TokenManager.cpp +++ b/src/Managers/TokenManager.cpp @@ -17,44 +17,46 @@ using Models::User; 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 - Token TokenManager::requestToken() - { - Token token{}; - json usrObj; - - usrObj["username"] = user.username; - usrObj["password"] = user.password; - - cout<<"Sending request for token"<user = user; +} +TokenManager::TokenManager(const User& user, API& api) +{ + this->user = user; + this->api = api; + this->api.endpoint = "api/" + api.version + + "/login"; +} +#pragma endregion + + +#pragma region Functions +Token TokenManager::requestToken() +{ + Token token{}; + json usrObj; + + usrObj["username"] = user.username; + usrObj["password"] = user.password; + + cout<<"Sending request for token"<user = user; - } - UserManager::UserManager(const IcarusAction icaAct) - { - this->icaAction = icaAct; - this->user = User{}; - parseUserFromActions(); - } - #pragma Constructors + +#pragma region Constructors +UserManager::UserManager(User user) +{ + this->user = user; +} +UserManager::UserManager(const IcarusAction icaAct) +{ + this->icaAction = icaAct; + this->user = User{}; + parseUserFromActions(); +} +#pragma endregion - #pragma - User UserManager::retrieveUser() const - { - return user; - } +#pragma region Functions +User UserManager::retrieveUser() const +{ + return user; +} - void UserManager::parseUserFromActions() - { - auto args = icaAction.flags; +void UserManager::parseUserFromActions() +{ + 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; - if (flag.compare("-u") == 0) - { - user.username = arg.value; - } - if (flag.compare("-p") == 0) - { - user.password = arg.value; - } + user.username = arg.value; + } + if (flag.compare("-p") == 0) + { + user.password = arg.value; } } - #pragma Functions +} +#pragma endregion + } diff --git a/src/Parsers/APIParser.cpp b/src/Parsers/APIParser.cpp index 3d62019..783e3ae 100644 --- a/src/Parsers/APIParser.cpp +++ b/src/Parsers/APIParser.cpp @@ -1,6 +1,6 @@ -#include"Parsers/APIParser.h" +#include "Parsers/APIParser.h" -#include +#include using std::cout; using std::endl; @@ -10,40 +10,44 @@ using Models::IcarusAction; namespace Parsers { - #pragma - APIParser::APIParser(IcarusAction icaAct) : icaAct(icaAct) - { - api = API{}; - parseAPI(); - } - #pragma endregion - - #pragma - API APIParser::retrieveAPI() const - { - return api; - } - - void APIParser::parseAPI() - { - auto flags = icaAct.flags; - cout<<"Parsing api"< -#include +#include +#include -#include +#include using std::cout; using std::endl; @@ -16,47 +16,49 @@ using Models::Token; namespace Syncers { - #pragma - Delete::Delete(API api) - { - this->api = api; - this->api.endpoint = "song/data"; - } - #pragma Constructors - - #pragma - void Delete::deleteSong(const Token token, Song song) - { - try - { - auto url = retrieveUrl(song); - string auth{token.tokenType}; - auth.append(" " + token.accessToken); - auto r = cpr::Delete(cpr::Url(url), - cpr::Header{{"authorization", auth}}); - - auto statusCode = r.status_code; - - cout<<"Status code "<api = api; + this->api.endpoint = "song/data"; +} +#pragma endregion + + +#pragma region Functions +void Delete::deleteSong(const Token token, Song song) +{ + try + { + auto url = retrieveUrl(song); + string auth{token.tokenType}; + auth.append(" " + token.accessToken); + auto r = cpr::Delete(cpr::Url(url), + cpr::Header{{"authorization", auth}}); + + auto statusCode = r.status_code; + + cout<<"Status code "< -#include -#include +#include +#include +#include -#include +#include using std::cout; using std::endl; @@ -18,74 +18,76 @@ using Models::Token; 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 - void Download::downloadSong(const Token token, Song song) - { - try - { - string url = retrieveUrl(song); - song.songPath.append("track.mp3"); - cout<<"song path "<api = api; + this->api.endpoint = "song/data"; +} +Download::Download(string filePath) +{ + downloadFilePath = filePath; +} +#pragma endregion + + +#pragma region Functions +void Download::downloadSong(const Token token, Song song) +{ + try + { + string url = retrieveUrl(song); + song.songPath.append("track.mp3"); + cout<<"song path "<api.endpoint = "song/data"; +} +#pragma endregion + + +#pragma region Functions +Song Upload::uploadSong(Song& song) +{ + try { - try - { - auto url = retrieveUrl(); + auto url = retrieveUrl(); - cout<<"url "<m_token.tokenType}; - auth.append(" " + this->m_token.accessToken); - auto r = cpr::Post(cpr::Url{url}, - cpr::Multipart{{"key", "small value"}, - {"file", cpr::File{song.songPath}}}, - 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"<(); - song.title = result["title"].get(); - song.artist = result["artist"].get(); - song.album = result["album"].get(); - song.genre = result["genre"].get(); - song.year = result["year"].get(); - song.duration = result["duration"].get(); - song.track = result["track"].get(); - - return song; - } - catch (exception& e) - { - auto msg = e.what(); - cout<> answer; - Utilities::Conversions::toLowerChar(answer); - - if (answer == 'y' || answer == 'Y') - { - confirmUpload = true; - break; - } - } - - if (!confirmUpload) - { - cout << "exiting...\n"; - std::exit(-1); - } - - cout << "uploading songs\n"; - for (auto& song: songs) - { - song = uploadSong(song); - } - } - catch (exception& e) - { - cout<api.endpoint.assign("song/data/upload/with/data"); - - try - { - auto url = retrieveUrl(); - - cout<<"url "<m_token.tokenType}; - auth.append(" " + this->m_token.accessToken); - - // const auto meta = song.toMetadataJson(); - nlohmann::json s; - s["title"] = song.title; - s["album"] = album.album; - s["album_artist"] = album.albumArtist; - s["artist"] = song.artist; - s["year"] = album.year; - s["genre"] = album.genre; - s["disc"] = song.disc; - s["track"] = song.track; - s["disc_count"] = album.discCount; - s["track_count"] = album.trackCount; - - const auto meta = s.dump(); - - cout<<"\n\nMeta:\n"<m_token.tokenType}; + auth.append(" " + this->m_token.accessToken); + auto r = cpr::Post(cpr::Url{url}, + cpr::Multipart{{"key", "small value"}, + {"file", cpr::File{song.songPath}}}, + cpr::Header{{"authorization", auth}} ); - cout << "status code: " << r.status_code<< std::endl; - cout << r.text << endl; - */ - } - catch (exception &e) - { - auto msg = e.what(); - cout<<"Error: "< Upload::retrieveAllSongsFromDirectory(const std::string& directory, - bool recursive) - { - std::vector 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; - } - - - 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())) - { - const auto ext = dirEntry.path().extension().string(); - if (ext.compare(mp3Ext) == 0) - { - cout << "found mp3 file" << endl; - song.songPath = dirEntry.path().string(); - } - } + cout << "status code: " << r.status_code<< std::endl; + cout << r.text << endl; + auto result = nlohmann::json::parse(r.text); + cout<<"Finished"<(); + song.title = result["title"].get(); + song.artist = result["artist"].get(); + song.album = result["album"].get(); + song.genre = result["genre"].get(); + song.year = result["year"].get(); + song.duration = result["duration"].get(); + song.track = result["track"].get(); return song; } + catch (exception& e) + { + auto msg = e.what(); + cout<> answer; + Utilities::Conversions::toLowerChar(answer); + + if (answer == 'y' || answer == 'Y') + { + confirmUpload = true; + break; + } + } + + if (!confirmUpload) + { + confirmUpload = false; + break; + } + } + + cout << "uploading songs\n"; + for (auto& song: songs) + { + song = uploadSong(song); + } + } + catch (exception& e) + { + cout<api.endpoint.assign("song/data/upload/with/data"); + + try + { + auto url = retrieveUrl(); + + cout<<"url "<m_token.tokenType}; + auth.append(" " + this->m_token.accessToken); + + // const auto meta = song.toMetadataJson(); + nlohmann::json s; + s["title"] = song.title; + s["album"] = album.album; + s["album_artist"] = album.albumArtist; + s["artist"] = song.artist; + s["year"] = album.year; + s["genre"] = album.genre; + s["disc"] = song.disc; + s["track"] = song.track; + s["disc_count"] = album.discCount; + s["track_count"] = album.trackCount; + + const auto meta = s.dump(); + + cout<<"\n\nMeta:\n"< Upload::retrieveAllSongsFromDirectory(const std::string& directory, + bool recursive) +{ + std::vector 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; +} + + +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())) + { + const auto ext = dirEntry.path().extension().string(); + if (ext.compare(mp3Ext) == 0) + { + cout << "found mp3 file" << endl; + song.songPath = dirEntry.path().string(); + } + } + + return song; +} + + +#pragma region Testing + +void Upload::printSongDetails(std::vector& songs) +{ + for (auto& song: songs) { cout<<"Song details: "<& songs) - { - for (auto& song: songs) - { - cout<<"Song details: "<{new QVBoxLayout}; - - appName = unique_ptr{new QLabel(tr("IcarusDownloadManager"))}; - actionButtonQt = unique_ptr{new QPushButton(tr("Close"))}; - - mainLayoutQt->addWidget(appName.get()); - mainLayoutQt->addWidget(actionButtonQt.get()); - - - setFixedWidth(windowWidth); - setFixedHeight(windowHeight); - - setLayout(mainLayoutQt.get()); - - setWindowTitle("About"); - - connections(); - } - void AboutWindow::connections() - { - QObject::connect(actionButtonQt.get(), SIGNAL(clicked()), this, - SLOT(closeWindow())); - } - - - void AboutWindow::closeWindow() - { - this->hide(); - } +#pragma region Constructors +AboutWindow::AboutWindow(QWidget* parent): QDialog(parent) +{ + setupWindow(); +} +#pragma endregion + + +#pragma region Functions +void AboutWindow::setupWindow() +{ + windowWidth = 250; + windowHeight = 300; + + mainLayoutQt = unique_ptr{new QVBoxLayout}; + + appName = unique_ptr{new QLabel(tr("IcarusDownloadManager"))}; + actionButtonQt = unique_ptr{new QPushButton(tr("Close"))}; + + mainLayoutQt->addWidget(appName.get()); + mainLayoutQt->addWidget(actionButtonQt.get()); + + + setFixedWidth(windowWidth); + setFixedHeight(windowHeight); + + setLayout(mainLayoutQt.get()); + + setWindowTitle("About"); + + connections(); +} +void AboutWindow::connections() +{ + QObject::connect(actionButtonQt.get(), SIGNAL(clicked()), this, + SLOT(closeWindow())); +} + + +void AboutWindow::closeWindow() +{ + this->hide(); +} +#pragma endregion + } diff --git a/src/UI/MainWindow.cpp b/src/UI/MainWindow.cpp index 08ec399..b44d6d3 100644 --- a/src/UI/MainWindow.cpp +++ b/src/UI/MainWindow.cpp @@ -1,11 +1,11 @@ -#include"UI/MainWindow.h" +#include "UI/MainWindow.h" -#include -#include +#include +#include -#include"Models/UploadForm.h" -#include"Syncers/Upload.h" -#include"Utilities/Conversions.h" +#include "Models/UploadForm.h" +#include "Syncers/Upload.h" +#include "Utilities/Conversions.h" using std::cout; using std::endl; @@ -17,158 +17,164 @@ using Syncers::Upload; namespace UI { - MainWindow::MainWindow() - { - setupMainWindow(); - aboutWindow = unique_ptr{new AboutWindow}; - } - - void MainWindow::configureDownloadSection() - { - } - void MainWindow::configureUploadSection() - { - uploadSongQt = unique_ptr{new QPushButton(tr("Upload"))}; - urlQt = unique_ptr{new QTextEdit()}; - sourceFilePathQt = unique_ptr{new QTextEdit()}; - - urlLabel = unique_ptr{new QLabel(tr("URL"))}; - songPath = unique_ptr{new QLabel(tr("Song Path"))}; - - urlPortion = unique_ptr{new QHBoxLayout}; - songPathPortion = unique_ptr{new QHBoxLayout}; - - urlPortion.get()->addWidget(urlLabel.get()); - urlPortion.get()->addWidget(urlQt.get()); - - songPathPortion->addWidget(songPath.get()); - songPathPortion->addWidget(sourceFilePathQt.get()); - - subLayoutOneQt = unique_ptr{new QVBoxLayout}; - subLayoutOneQt.get()->addLayout(urlPortion.get()); - subLayoutOneQt->addLayout(songPathPortion.get()); - mainLayoutQt.get()->addLayout(subLayoutOneQt.get()); - } - void MainWindow::configureWindowDimensions() - { - windowWidth = 450; - windowHeight = 450; - } - void MainWindow::configureWindowProperties() - { - setWindowTitle("IcarusDownloadManager"); - setFixedHeight(windowHeight); - setFixedWidth(windowWidth); - } - void MainWindow::connections() - { - QObject::connect(uploadSongQt.get(), SIGNAL(clicked()), this, SLOT(uploadSong())); - QObject::connect(closeApplicationQt.get(), SIGNAL(triggered()), this, - SLOT(exitApplication())); - QObject::connect(aboutApplicationQt.get(), SIGNAL(triggered()), this, - SLOT(displaySoftwareInformation())); - QObject::connect(windowComboBox.get(), SIGNAL(activated(int)), - this, SLOT(setCurrentIndex(int))); - } - void MainWindow::createMenus() - { - fileMenuQt = unique_ptr{menuBar()->addMenu(tr("File"))}; - editMenuQt = unique_ptr{menuBar()->addMenu(tr("Edit"))}; - helpMenuQt = unique_ptr{menuBar()->addMenu(tr("Help"))}; - - closeApplicationQt = unique_ptr{new QAction(new QObject(nullptr))}; - closeApplicationQt->setText("Exit Application"); - - aboutApplicationQt = unique_ptr{new QAction(new QObject(nullptr))}; - aboutApplicationQt->setText("About"); - - fileMenuQt->addAction(closeApplicationQt.get()); - helpMenuQt->addAction(aboutApplicationQt.get()); - - } - void MainWindow::setupMainWidget() - { - mainWidgetQt = unique_ptr{new QWidget}; - - windowComboBox = unique_ptr{new QComboBox}; - setupWindowLists(); - - - stackLayout = unique_ptr{new QVBoxLayout}; - stackLayout->addWidget(windowComboBox.get()); - - uploadSongWidgetQt = unique_ptr{new QWidget}; - uploadSongWidgetQt->setLayout(mainLayoutQt.get()); - - stackLayout->addWidget(uploadSongWidgetQt.get()); - - mainWidgetQt->setLayout(stackLayout.get()); - } - void MainWindow::setupMainWindow() - { - configureWindowDimensions(); - - mainLayoutQt = unique_ptr{new QVBoxLayout}; - widgetStack = unique_ptr{new QStackedWidget}; - - configureUploadSection(); - - setupMainWidget(); - - widgetStack->addWidget(mainWidgetQt.get()); - - MainDockWidgetQt = unique_ptr{new QDockWidget}; - MainDockWidgetQt.get()->setWindowTitle(tr("Music Manager")); - MainDockWidgetQt->setWidget(widgetStack.get()); - MainDockWidgetQt.get()->setFeatures(QDockWidget::NoDockWidgetFeatures); - - setCentralWidget(MainDockWidgetQt.get()); - - createMenus(); - - configureWindowProperties(); - - connections(); - } - void MainWindow::setupWindowLists() - { - windowComboBox->addItem(tr("Upload song")); - windowComboBox->addItem(tr("Download song")); - windowComboBox->addItem(tr("Display all songs")); - windowComboBox->addItem(tr("Display songs")); - } - - - void MainWindow::exitApplication() - { - exit(0); - } - void MainWindow::displaySoftwareInformation() - { - aboutWindow->show(); - } - void MainWindow::setCurrentIndex(int index) - { - cout<<"index "<itemText(index); - auto cnvert = Utilities::Conversions(qText); - auto convertedStr = cnvert.convertQStringToString(); - cout<<"item text"<setEnabled(false); - - string url = urlQt->toPlainText().toUtf8().constData(); - string filePath = sourceFilePathQt->toPlainText().toUtf8().constData(); - cout<<"URL endpoint: "<setEnabled(true); - } +#pragma region Constructors +MainWindow::MainWindow() +{ + setupMainWindow(); + aboutWindow = unique_ptr{new AboutWindow}; +} +#pragma endregion + + +#pragma region Functions +void MainWindow::configureDownloadSection() +{ +} +void MainWindow::configureUploadSection() +{ + uploadSongQt = unique_ptr{new QPushButton(tr("Upload"))}; + urlQt = unique_ptr{new QTextEdit()}; + sourceFilePathQt = unique_ptr{new QTextEdit()}; + + urlLabel = unique_ptr{new QLabel(tr("URL"))}; + songPath = unique_ptr{new QLabel(tr("Song Path"))}; + + urlPortion = unique_ptr{new QHBoxLayout}; + songPathPortion = unique_ptr{new QHBoxLayout}; + + urlPortion.get()->addWidget(urlLabel.get()); + urlPortion.get()->addWidget(urlQt.get()); + + songPathPortion->addWidget(songPath.get()); + songPathPortion->addWidget(sourceFilePathQt.get()); + + subLayoutOneQt = unique_ptr{new QVBoxLayout}; + subLayoutOneQt.get()->addLayout(urlPortion.get()); + subLayoutOneQt->addLayout(songPathPortion.get()); + mainLayoutQt.get()->addLayout(subLayoutOneQt.get()); +} +void MainWindow::configureWindowDimensions() +{ + windowWidth = 450; + windowHeight = 450; +} +void MainWindow::configureWindowProperties() +{ + setWindowTitle("IcarusDownloadManager"); + setFixedHeight(windowHeight); + setFixedWidth(windowWidth); +} +void MainWindow::connections() +{ + QObject::connect(uploadSongQt.get(), SIGNAL(clicked()), this, SLOT(uploadSong())); + QObject::connect(closeApplicationQt.get(), SIGNAL(triggered()), this, + SLOT(exitApplication())); + QObject::connect(aboutApplicationQt.get(), SIGNAL(triggered()), this, + SLOT(displaySoftwareInformation())); + QObject::connect(windowComboBox.get(), SIGNAL(activated(int)), + this, SLOT(setCurrentIndex(int))); +} +void MainWindow::createMenus() +{ + fileMenuQt = unique_ptr{menuBar()->addMenu(tr("File"))}; + editMenuQt = unique_ptr{menuBar()->addMenu(tr("Edit"))}; + helpMenuQt = unique_ptr{menuBar()->addMenu(tr("Help"))}; + + closeApplicationQt = unique_ptr{new QAction(new QObject(nullptr))}; + closeApplicationQt->setText("Exit Application"); + + aboutApplicationQt = unique_ptr{new QAction(new QObject(nullptr))}; + aboutApplicationQt->setText("About"); + + fileMenuQt->addAction(closeApplicationQt.get()); + helpMenuQt->addAction(aboutApplicationQt.get()); + +} +void MainWindow::setupMainWidget() +{ + mainWidgetQt = unique_ptr{new QWidget}; + + windowComboBox = unique_ptr{new QComboBox}; + setupWindowLists(); + + + stackLayout = unique_ptr{new QVBoxLayout}; + stackLayout->addWidget(windowComboBox.get()); + + uploadSongWidgetQt = unique_ptr{new QWidget}; + uploadSongWidgetQt->setLayout(mainLayoutQt.get()); + + stackLayout->addWidget(uploadSongWidgetQt.get()); + + mainWidgetQt->setLayout(stackLayout.get()); +} +void MainWindow::setupMainWindow() +{ + configureWindowDimensions(); + + mainLayoutQt = unique_ptr{new QVBoxLayout}; + widgetStack = unique_ptr{new QStackedWidget}; + + configureUploadSection(); + + setupMainWidget(); + + widgetStack->addWidget(mainWidgetQt.get()); + + MainDockWidgetQt = unique_ptr{new QDockWidget}; + MainDockWidgetQt.get()->setWindowTitle(tr("Music Manager")); + MainDockWidgetQt->setWidget(widgetStack.get()); + MainDockWidgetQt.get()->setFeatures(QDockWidget::NoDockWidgetFeatures); + + setCentralWidget(MainDockWidgetQt.get()); + + createMenus(); + + configureWindowProperties(); + + connections(); +} +void MainWindow::setupWindowLists() +{ + windowComboBox->addItem(tr("Upload song")); + windowComboBox->addItem(tr("Download song")); + windowComboBox->addItem(tr("Display all songs")); + windowComboBox->addItem(tr("Display songs")); +} + + +void MainWindow::exitApplication() +{ + exit(0); +} +void MainWindow::displaySoftwareInformation() +{ + aboutWindow->show(); +} +void MainWindow::setCurrentIndex(int index) +{ + cout<<"index "<itemText(index); + auto cnvert = Utilities::Conversions(qText); + auto convertedStr = cnvert.convertQStringToString(); + cout<<"item text"<setEnabled(false); + + string url = urlQt->toPlainText().toUtf8().constData(); + string filePath = sourceFilePathQt->toPlainText().toUtf8().constData(); + cout<<"URL endpoint: "<setEnabled(true); +} +#pragma endregion + } diff --git a/src/Utilities/Conversions.cpp b/src/Utilities/Conversions.cpp index 56839c2..704f09b 100644 --- a/src/Utilities/Conversions.cpp +++ b/src/Utilities/Conversions.cpp @@ -1,24 +1,26 @@ -#include"Utilities/Conversions.h" +#include "Utilities/Conversions.h" -#include +#include using std::string; using std::unique_ptr; namespace Utilities { - Conversions::Conversions() - { - initializeValues(); - } - void Conversions::initializeValues() - { - } - template - void Conversions::printValue(T val) - { - std::cout<<"going to print value"< +void Conversions::printValue(T val) +{ + std::cout<<"going to print value"<