From 24a111e8e995fe999c74a06f77202444379f4ba7 Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Tue, 30 Jul 2019 22:08:55 -0400 Subject: [PATCH] Changed C++ standard to C++17 and will implement functionality to retrieve songs, albums, artists, genres, cover art, and year records in json. Will add explicit versioning too --- CMakeLists.txt | 56 ++--- include/Managers/ActionManager.h | 43 ++++ include/Managers/CommitManager.h | 40 +++ include/Managers/FileManager.h | 29 +++ include/Managers/TokenManager.h | 23 ++ include/Managers/UserManager.h | 26 ++ include/Models/API.h | 16 ++ include/Models/Flags.h | 15 ++ {src => include}/Models/IcarusAction.h | 10 +- include/Models/Song.h | 24 ++ include/Models/Token.h | 16 ++ {src => include}/Models/UploadForm.h | 10 +- include/Models/User.h | 15 ++ include/Parsers/APIParser.h | 23 ++ include/Syncers/Delete.h | 23 ++ include/Syncers/Download.h | 32 +++ include/Syncers/SyncerBase.h | 20 ++ include/Syncers/Upload.h | 47 ++++ include/UI/AboutWindow.h | 34 +++ include/UI/CommonWindow.h | 27 +++ include/UI/MainWindow.h | 82 +++++++ include/Utilities/Conversions.h | 22 ++ src/Main.cpp | 3 - src/Managers/ActionManager.cpp | 324 ++++++++++++------------- src/Managers/ActionManager.h | 43 ---- src/Managers/CommitManager.cpp | 42 ++-- src/Managers/CommitManager.h | 35 --- src/Managers/FileManager.cpp | 88 +++---- src/Managers/FileManager.h | 29 --- src/Managers/TokenManager.cpp | 72 +++--- src/Managers/TokenManager.h | 23 -- src/Managers/UserManager.cpp | 70 +++--- src/Managers/UserManager.h | 26 -- src/Models/API.h | 16 -- src/Models/Flags.h | 15 -- src/Models/Song.h | 24 -- src/Models/Token.h | 17 -- src/Models/User.h | 15 -- src/Parsers/APIParser.cpp | 80 +++--- src/Parsers/APIParser.h | 23 -- src/Syncers/Delete.cpp | 74 +++--- src/Syncers/Delete.h | 23 -- src/Syncers/Download.cpp | 152 ++++++------ src/Syncers/Download.h | 32 --- src/Syncers/SyncerBase.h | 20 -- src/Syncers/Upload.cpp | 240 +++++++++--------- src/Syncers/Upload.h | 47 ---- src/UI/AboutWindow.cpp | 58 ++--- src/UI/AboutWindow.h | 34 --- src/UI/CommonWindow.h | 27 --- src/UI/MainWindow.cpp | 248 +++++++++---------- src/UI/MainWindow.h | 82 ------- src/Utilities/Conversions.cpp | 28 +-- src/Utilities/Conversions.h | 22 -- 54 files changed, 1334 insertions(+), 1331 deletions(-) create mode 100644 include/Managers/ActionManager.h create mode 100644 include/Managers/CommitManager.h create mode 100644 include/Managers/FileManager.h create mode 100644 include/Managers/TokenManager.h create mode 100644 include/Managers/UserManager.h create mode 100644 include/Models/API.h create mode 100644 include/Models/Flags.h rename {src => include}/Models/IcarusAction.h (57%) create mode 100644 include/Models/Song.h create mode 100644 include/Models/Token.h rename {src => include}/Models/UploadForm.h (51%) create mode 100644 include/Models/User.h create mode 100644 include/Parsers/APIParser.h create mode 100644 include/Syncers/Delete.h create mode 100644 include/Syncers/Download.h create mode 100644 include/Syncers/SyncerBase.h create mode 100644 include/Syncers/Upload.h create mode 100644 include/UI/AboutWindow.h create mode 100644 include/UI/CommonWindow.h create mode 100644 include/UI/MainWindow.h create mode 100644 include/Utilities/Conversions.h delete mode 100644 src/Managers/ActionManager.h delete mode 100644 src/Managers/CommitManager.h delete mode 100644 src/Managers/FileManager.h delete mode 100644 src/Managers/TokenManager.h delete mode 100644 src/Managers/UserManager.h delete mode 100644 src/Models/API.h delete mode 100644 src/Models/Flags.h delete mode 100644 src/Models/Song.h delete mode 100644 src/Models/Token.h delete mode 100644 src/Models/User.h delete mode 100644 src/Parsers/APIParser.h delete mode 100644 src/Syncers/Delete.h delete mode 100644 src/Syncers/Download.h delete mode 100644 src/Syncers/SyncerBase.h delete mode 100644 src/Syncers/Upload.h delete mode 100644 src/UI/AboutWindow.h delete mode 100644 src/UI/CommonWindow.h delete mode 100644 src/UI/MainWindow.h delete mode 100644 src/Utilities/Conversions.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ebb439b..25dc728 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.10) include("cmake/HunterGate.cmake") @@ -15,17 +15,17 @@ if(NOT ${CMAKE_VERSION} LESS 3.2) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) else() - message(STATUS "Checking compiler flags for C++11 support.") - # Set C++11 support flags for various compilers + message(STATUS "Checking compiler flags for C++117support.") + # Set C++17 support flags for various compilers include(CheckCXXCompilerFlag) - check_cxx_compiler_flag("-std=c++11" COMPILER_SUPPORTS_CXX11) + check_cxx_compiler_flag("-std=c++17" COMPILER_SUPPORTS_CXX17) check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X) - if(COMPILER_SUPPORTS_CXX11) - message(STATUS "C++11 is supported.") + if(COMPILER_SUPPORTS_CXX17) + message(STATUS "C++17 is supported.") if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -stdlib=libc++") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -stdlib=libc++") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17") endif() elseif(COMPILER_SUPPORTS_CXX0X) message(STATUS "C++0x is supported.") @@ -35,7 +35,7 @@ else() set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x") endif() else() - message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.") + message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++17 support. Please use a different C++ compiler.") endif() endif() @@ -54,24 +54,24 @@ set(SOURCES src/Utilities/Conversions.cpp ) set(HEADERS - src/Managers/ActionManager.h - src/Managers/CommitManager.h - src/Managers/FileManager.h - src/Managers/TokenManager.h - src/Managers/UserManager.h - src/Models/API.h - src/Models/Flags.h - src/Models/IcarusAction.h - src/Models/Song.h - src/Models/Token.h - src/Models/UploadForm.h - src/Models/User.h - src/Parsers/APIParser.h - src/Syncers/Delete.h - src/Syncers/Download.h - src/Syncers/SyncerBase.h - src/Syncers/Upload.h - src/Utilities/Conversions.h + include/Managers/ActionManager.h + include/Managers/CommitManager.h + include/Managers/FileManager.h + include/Managers/TokenManager.h + include/Managers/UserManager.h + include/Models/API.h + include/Models/Flags.h + include/Models/IcarusAction.h + include/Models/Song.h + include/Models/Token.h + include/Models/UploadForm.h + include/Models/User.h + include/Parsers/APIParser.h + include/Syncers/Delete.h + include/Syncers/Download.h + include/Syncers/SyncerBase.h + include/Syncers/Upload.h + include/Utilities/Conversions.h ) @@ -84,4 +84,4 @@ find_package(cpr CONFIG REQUIRED) add_executable(icd ${SOURCES} ${HEADERS}) target_link_libraries(icd PUBLIC nlohmann_json::nlohmann_json cpr::cpr) -include_directories(src/) +include_directories(include/) diff --git a/include/Managers/ActionManager.h b/include/Managers/ActionManager.h new file mode 100644 index 0000000..f63b2d4 --- /dev/null +++ b/include/Managers/ActionManager.h @@ -0,0 +1,43 @@ +#ifndef ACTIONMANAGER_H_ +#define ACTIONMANAGER_H_ + +#include +#include + +#include"Models/Flags.h" +#include"Models/IcarusAction.h" + +namespace Managers +{ + class ActionManager + { + public: + ActionManager(char**); + + Models::IcarusAction retrieveIcarusAction() const; + std::vector retrieveFlags() const; + std::string retrieveAction() const; + private: + bool isNumber(std::string); + + void initialize(); + void initializeSupportedActions(); + void initializeSupportedFlags(); + void validateAction(); + void validateFlags(); + + std::vector parsedFlags(); + + void printAction(); + void printFlags(std::vector); + void printFlags(); + + std::string action; + std::vector supportedActions; + std::vector supportedFlags; + std::vector flags; + char **params; + }; +} + +#endif diff --git a/include/Managers/CommitManager.h b/include/Managers/CommitManager.h new file mode 100644 index 0000000..975094f --- /dev/null +++ b/include/Managers/CommitManager.h @@ -0,0 +1,40 @@ +#ifndef COMMITMANAGER_H_ +#define COMMITMANAGER_H_ + +#include +#include + +#include"Models/API.h" +#include"Models/Token.h" +#include"Models/IcarusAction.h" + +namespace Managers +{ + class CommitManager + { + public: + CommitManager(Models::IcarusAction); + + void commitAction(); + private: + Models::Token parseToken(Models::API); + + void initializeMapActions(); + void deleteSong(); + void downloadSong(); + void uploadSong(); + + enum ActionValues + { + deleteAct, + downloadAct, + retrieveAct, + uploadAct + }; + + std::map mapActions; + Models::IcarusAction icaAction; + }; +} + +#endif diff --git a/include/Managers/FileManager.h b/include/Managers/FileManager.h new file mode 100644 index 0000000..db0fc68 --- /dev/null +++ b/include/Managers/FileManager.h @@ -0,0 +1,29 @@ +#ifndef FILEMANAGER_H_ +#define FILEMANAGER_H_ + +#include + +namespace Managers +{ + class FileManager + { + public: + FileManager(); + FileManager(std::string); + + 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; + }; +} + +#endif diff --git a/include/Managers/TokenManager.h b/include/Managers/TokenManager.h new file mode 100644 index 0000000..217874c --- /dev/null +++ b/include/Managers/TokenManager.h @@ -0,0 +1,23 @@ +#ifndef TOKENMANAGER_H_ +#define TOKENMANAGER_H_ + +#include"Models/API.h" +#include"Models/Token.h" +#include"Models/User.h" + +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; + }; +} + +#endif diff --git a/include/Managers/UserManager.h b/include/Managers/UserManager.h new file mode 100644 index 0000000..21b9755 --- /dev/null +++ b/include/Managers/UserManager.h @@ -0,0 +1,26 @@ +#ifndef USERMANAGER_H_ +#define USERMANAGER_H_ + +#include + +#include"Models/IcarusAction.h" +#include"Models/User.h" + +namespace Managers +{ + class UserManager + { + public: + UserManager(Models::User); + UserManager(const Models::IcarusAction); + + Models::User retrieveUser() const; + private: + void parseUserFromActions(); + + Models::User user; + Models::IcarusAction icaAction; + }; +} + +#endif diff --git a/include/Models/API.h b/include/Models/API.h new file mode 100644 index 0000000..cd7a5cd --- /dev/null +++ b/include/Models/API.h @@ -0,0 +1,16 @@ +#ifndef API_H_ +#define API_H_ + +#include + +namespace Models +{ + struct API + { + std::string url; + std::string endpoint; + std::string version; + }; +} + +#endif diff --git a/include/Models/Flags.h b/include/Models/Flags.h new file mode 100644 index 0000000..6772e10 --- /dev/null +++ b/include/Models/Flags.h @@ -0,0 +1,15 @@ +#ifndef FLAGS_H_ +#define FLAGS_H_ + +#include + +namespace Models +{ + struct Flags + { + std::string flag; + std::string value; + }; +} + +#endif diff --git a/src/Models/IcarusAction.h b/include/Models/IcarusAction.h similarity index 57% rename from src/Models/IcarusAction.h rename to include/Models/IcarusAction.h index 539adac..9a32775 100644 --- a/src/Models/IcarusAction.h +++ b/include/Models/IcarusAction.h @@ -8,11 +8,11 @@ namespace Models { - struct IcarusAction - { - std::string action; - std::vector flags; - }; + struct IcarusAction + { + std::string action; + std::vector flags; + }; } #endif diff --git a/include/Models/Song.h b/include/Models/Song.h new file mode 100644 index 0000000..11f2f02 --- /dev/null +++ b/include/Models/Song.h @@ -0,0 +1,24 @@ +#ifndef SONG_H_ +#define SONG_H_ + +#include + + +namespace Models +{ + struct Song + { + int id; + std::string title; + std::string artist; + std::string album; + std::string genre; + int year; + int duration; + char *songData; + std::string data; + std::string songPath; + }; +} + +#endif diff --git a/include/Models/Token.h b/include/Models/Token.h new file mode 100644 index 0000000..cc66a54 --- /dev/null +++ b/include/Models/Token.h @@ -0,0 +1,16 @@ +#ifndef TOKEN_H_ +#define TOKEN_H_ + +#include + +namespace Models +{ + struct Token + { + std::string accessToken; + std::string tokenType; + int expiration; + }; +} + +#endif diff --git a/src/Models/UploadForm.h b/include/Models/UploadForm.h similarity index 51% rename from src/Models/UploadForm.h rename to include/Models/UploadForm.h index fd45a62..cbdf950 100644 --- a/src/Models/UploadForm.h +++ b/include/Models/UploadForm.h @@ -6,11 +6,11 @@ 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 new file mode 100644 index 0000000..b64523a --- /dev/null +++ b/include/Models/User.h @@ -0,0 +1,15 @@ +#ifndef USER_H_ +#define USER_H_ + +#include + +namespace Models +{ + struct User + { + std::string username; + std::string password; + }; +} + +#endif diff --git a/include/Parsers/APIParser.h b/include/Parsers/APIParser.h new file mode 100644 index 0000000..ca24801 --- /dev/null +++ b/include/Parsers/APIParser.h @@ -0,0 +1,23 @@ +#ifndef APIPARSER_H_ +#define APIPARSER_H_ + +#include"Models/API.h" +#include"Models/IcarusAction.h" + +namespace Parsers +{ + class APIParser + { + public: + APIParser(Models::IcarusAction); + + Models::API retrieveAPI() const; + private: + void parseAPI(); + + Models::API api; + Models::IcarusAction icaAct; + }; +} + +#endif diff --git a/include/Syncers/Delete.h b/include/Syncers/Delete.h new file mode 100644 index 0000000..0546578 --- /dev/null +++ b/include/Syncers/Delete.h @@ -0,0 +1,23 @@ +#ifndef DELETE_H_ +#define DELETE_H_ + +#include"Models/API.h" +#include"Models/Song.h" +#include"Models/Token.h" + +#include"SyncerBase.h" + +namespace Syncers +{ + 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 new file mode 100644 index 0000000..1f8da52 --- /dev/null +++ b/include/Syncers/Download.h @@ -0,0 +1,32 @@ +#ifndef DOWNLOAD_H_ +#define DOWNLOAD_H_ + +#include +#include + +#include"Models/API.h" +#include"Models/Song.h" +#include"Models/Token.h" + +#include"SyncerBase.h" + +namespace Syncers +{ + class Download : SyncerBase + { + public: + Download(); + Download(Models::API); + Download(std::string); + + void downloadSong(int); + void downloadSong(const Models::Token token, Models::Song); + private: + std::string retrieveUrl(Models::Song); + + std::string downloadFilePath; + void saveSong(Models::Song*); + }; +} + +#endif diff --git a/include/Syncers/SyncerBase.h b/include/Syncers/SyncerBase.h new file mode 100644 index 0000000..499f11f --- /dev/null +++ b/include/Syncers/SyncerBase.h @@ -0,0 +1,20 @@ +#ifndef SYNCERBASE_H_ +#define SYNCERBASE_H_ + +#include + +#include"Models/API.h" + +namespace Syncers +{ + class SyncerBase + { + protected: + Models::API api; + const int OK = 200; + const int UNAUTHORIZED = 401; + const int NOTFOUND = 404; + }; +} + +#endif diff --git a/include/Syncers/Upload.h b/include/Syncers/Upload.h new file mode 100644 index 0000000..cbb8e3a --- /dev/null +++ b/include/Syncers/Upload.h @@ -0,0 +1,47 @@ +#ifndef UPLOAD_H_ +#define UPLOAD_H_ + +#include + +#include + +#include"Managers/FileManager.h" +#include"Models/API.h" +#include"Models/Song.h" +#include"Models/Token.h" +#include"Models/UploadForm.h" + + +namespace Syncers +{ + class Upload + { + public: + Upload(); + Upload(std::string); + Upload(Models::API); + Upload(Models::UploadForm); + + void uploadSong(); + void uploadSong(const Models::Token, Models::Song); + private: + Managers::FileManager fMgr; + Models::API api; + Models::Song song; + std::string apiUrl{""}; // Not being used + std::string apiEndPoint{""}; // Not being used + std::string songPath; // Not being used + std::string url; // Not being used + int port{9349}; // Not being used + + std::string retrieveUrl(); + + void configureSongDemo(); + void printSongDetails(); + void printJsonData(nlohmann::json); + + nlohmann::json serializeObject(); // Not being used + }; +} + +#endif diff --git a/include/UI/AboutWindow.h b/include/UI/AboutWindow.h new file mode 100644 index 0000000..e47194c --- /dev/null +++ b/include/UI/AboutWindow.h @@ -0,0 +1,34 @@ +#ifndef ABOUTWINDOW_H_ +#define ABOUTWINDOW_H_ + +#include + +#include +#include +#include +#include +#include + +#include"UI/CommonWindow.h" + +namespace UI +{ + class AboutWindow: public QDialog, public CommonWindow + { + Q_OBJECT + public: + AboutWindow(QWidget* parent=0); + ~AboutWindow() = default; + + private: + void connections(); + void setupWindow(); + + std::unique_ptr appName; + + private slots: + void closeWindow(); + }; +} + +#endif diff --git a/include/UI/CommonWindow.h b/include/UI/CommonWindow.h new file mode 100644 index 0000000..5b9fdd6 --- /dev/null +++ b/include/UI/CommonWindow.h @@ -0,0 +1,27 @@ +#ifndef COMMONWINDOW_H_ +#define COMMONWINDOW_H_ + +#include + +#include +#include +#include +#include +#include + + +class CommonWindow +{ +public: + CommonWindow() = default; + ~CommonWindow() = default; +protected: + virtual void connections()=0; + std::unique_ptr selectionBoxQt; + std::unique_ptr actionButtonQt; + std::unique_ptr mainLayoutQt; + std::unique_ptr subLayoutOneQt; + std::unique_ptr subLayoutTwoQt; + int windowHeight, windowWidth; +}; +#endif diff --git a/include/UI/MainWindow.h b/include/UI/MainWindow.h new file mode 100644 index 0000000..7c32369 --- /dev/null +++ b/include/UI/MainWindow.h @@ -0,0 +1,82 @@ +#ifndef MAINWINDOW_H_ +#define MAINWINDOW_H_ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include"UI/CommonWindow.h" +#include"UI/AboutWindow.h" + +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(); + + + std::unique_ptr widgetStack; + + std::unique_ptr stackLayout; + + std::unique_ptr urlPortion; + std::unique_ptr songPathPortion; + + std::unique_ptr mainWidgetQt; + std::unique_ptr uploadSongWidgetQt; + + std::unique_ptr MainDockWidgetQt; + + std::unique_ptr windowComboBox; + + std::unique_ptr uploadSongQt; + + std::unique_ptr urlQt; + std::unique_ptr sourceFilePathQt; + + std::unique_ptr urlLabel; + std::unique_ptr songPath; + + std::unique_ptr fileMenuQt; + std::unique_ptr editMenuQt; + std::unique_ptr helpMenuQt; + + std::unique_ptr closeApplicationQt; + std::unique_ptr aboutApplicationQt; + + 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 new file mode 100644 index 0000000..d92d060 --- /dev/null +++ b/include/Utilities/Conversions.h @@ -0,0 +1,22 @@ +#ifndef CONVERSIONS_H_ +#define CONVERSIONS_H_ + +#include +#include + +namespace Utilities +{ + class Conversions + { + public: + Conversions(); + + void initializeValues(); + + template + void printValue(T); + private: + }; +} + +#endif diff --git a/src/Main.cpp b/src/Main.cpp index f81a024..9b26e17 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -12,9 +12,6 @@ using std::string; using Managers::ActionManager; using Managers::CommitManager; -string songPath{}; -string newSongPath{}; - int main(int argc, char** argv) { if (argc < 2) diff --git a/src/Managers/ActionManager.cpp b/src/Managers/ActionManager.cpp index 1be285d..369b27d 100644 --- a/src/Managers/ActionManager.cpp +++ b/src/Managers/ActionManager.cpp @@ -1,4 +1,5 @@ -#include"ActionManager.h" +#include"Managers/ActionManager.h" + #include #include #include @@ -14,181 +15,180 @@ using Models::IcarusAction; namespace Managers { - #pragma - ActionManager::ActionManager(char **param) - { - this->params = param; + #pragma + ActionManager::ActionManager(char **param) + { + this->params = param; - action = string{params[1]}; - transform(action.begin(), action.end(), - action.begin(), ::tolower); + action = string{params[1]}; + transform(action.begin(), action.end(), + action.begin(), ::tolower); - initialize(); - } - #pragma Constructors + initialize(); + } + #pragma Constructors - #pragma - IcarusAction ActionManager::retrieveIcarusAction() const - { - auto icarusAction = IcarusAction{}; - icarusAction.flags = flags; - icarusAction.action = action; + #pragma + IcarusAction ActionManager::retrieveIcarusAction() const + { + auto icarusAction = IcarusAction{}; + icarusAction.flags = flags; + icarusAction.action = action; - return icarusAction; - } - vector ActionManager::retrieveFlags() const - { - return flags; - } + return icarusAction; + } + vector ActionManager::retrieveFlags() const + { + return flags; + } - string ActionManager::retrieveAction() const - { - return action; - } + string ActionManager::retrieveAction() const + { + return action; + } - bool ActionManager::isNumber(string val) - { - return !val.empty() && std::find_if(val.begin(), - val.end(), [](char c) - { - return !std::isdigit(c); - }) == val.end(); - } + bool ActionManager::isNumber(string val) + { + return !val.empty() && std::find_if(val.begin(), + val.end(), [](char c) + { + return !std::isdigit(c); + }) == val.end(); + } - void ActionManager::initialize() - { - initializeSupportedActions(); - validateAction(); - validateFlags(); - } - void ActionManager::initializeSupportedActions() - { - supportedActions = vector{ - "download", "delete", - "retrieve", "upload" - }; - } - void ActionManager::initializeSupportedFlags() - { - supportedFlags = vector{ - "-u", "-p", "-t", "-h", "-s", - "-d", "-D", "-b" - }; - } - void ActionManager::validateAction() - { - cout<<"Validating action"<{ + "download", "delete", + "retrieve", "upload" + }; + } + void ActionManager::initializeSupportedFlags() + { + supportedFlags = vector{ + "-u", "-p", "-t", "-h", "-s", + "-d", "-D", "-b" + }; + } + void ActionManager::validateAction() + { + cout<<"Validating action"< 3 || flg.flag.compare("-D")) - if (flag.size() > 3 || isNumber(flag)) - { - flg.value = flag; - cout<<"flag value "< 3 || isNumber(flag)) + { + flg.value = flag; + //cout<<"flag value "< ActionManager::parsedFlags() - { - auto parsed = vector{}; - try - { - for (auto i = 2; true; ++i) - { - string val{*(params + i)}; - cout<<"Parsed flag "< ActionManager::parsedFlags() + { + auto parsed = vector{}; + try + { + for (auto i = 2; true; ++i) + { + string val{*(params + i)}; + cout<<"Parsed flag "< flagVals) - { - if (flagVals.empty()) - { - printf("Flags and values are empty\n"); - } - else - { - printf("Printing flags and values..\n"); - for (auto flgVal : flagVals) - { - cout< flagVals) + { + if (flagVals.empty()) + { + printf("Flags and values are empty\n"); + } + else + { + printf("Printing flags and values..\n"); + for (auto flgVal : flagVals) + { + cout< -#include - -#include"Models/Flags.h" -#include"Models/IcarusAction.h" - -namespace Managers -{ - class ActionManager - { - public: - ActionManager(char**); - - Models::IcarusAction retrieveIcarusAction() const; - std::vector retrieveFlags() const; - std::string retrieveAction() const; - private: - bool isNumber(std::string); - - void initialize(); - void initializeSupportedActions(); - void initializeSupportedFlags(); - void validateAction(); - void validateFlags(); - - std::vector parsedFlags(); - - void printAction(); - void printFlags(std::vector); - void printFlags(); - - std::string action; - std::vector supportedActions; - std::vector supportedFlags; - std::vector flags; - char **params; - }; -} - -#endif diff --git a/src/Managers/CommitManager.cpp b/src/Managers/CommitManager.cpp index 16fdf0a..5c138b3 100644 --- a/src/Managers/CommitManager.cpp +++ b/src/Managers/CommitManager.cpp @@ -1,16 +1,17 @@ -#include"CommitManager.h" +#include"Managers/CommitManager.h" #include #include"Models/API.h" #include"Models/Song.h" +#include"Models/Token.h" #include"Parsers/APIParser.h" #include"Syncers/Delete.h" #include"Syncers/Download.h" #include"Syncers/Upload.h" -#include"TokenManager.h" -#include"UserManager.h" +#include"Managers/TokenManager.h" +#include"Managers/UserManager.h" using std::cout; using std::endl; @@ -21,6 +22,7 @@ using Managers::TokenManager; using Managers::UserManager; using Models::API; using Models::Song; +using Models::Token; using Parsers::APIParser; using Models::IcarusAction; using Syncers::Delete; @@ -59,6 +61,17 @@ namespace Managers } } + Token CommitManager::parseToken(API api) + { + cout<<"fetching token"<{ @@ -69,16 +82,10 @@ namespace Managers } void CommitManager::deleteSong() { - cout<<"Deleting song..."< -#include - -#include"Models/IcarusAction.h" - -namespace Managers -{ - class CommitManager - { - public: - CommitManager(Models::IcarusAction); - - void commitAction(); - private: - void initializeMapActions(); - void deleteSong(); - void downloadSong(); - void uploadSong(); - - enum ActionValues - { - deleteAct, - downloadAct, - retrieveAct, - uploadAct - }; - std::map mapActions; - Models::IcarusAction icaAction; - }; -} - -#endif diff --git a/src/Managers/FileManager.cpp b/src/Managers/FileManager.cpp index c7bd0de..b47fe08 100644 --- a/src/Managers/FileManager.cpp +++ b/src/Managers/FileManager.cpp @@ -1,7 +1,7 @@ #include #include -#include"FileManager.h" +#include"Managers/FileManager.h" using std::cout; using std::endl; @@ -11,56 +11,56 @@ using std::string; namespace Managers { - FileManager::FileManager() {} - FileManager::FileManager(string filePath) - { - this->filePath = filePath; - readFile(); - } + FileManager::FileManager() {} + FileManager::FileManager(string filePath) + { + this->filePath = filePath; + readFile(); + } - 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(); - } + 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); + 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]; + fileBuffer = new char [fileBufferLength]; - cout<< "Reading "<filePath = filePath; - } + if (is) + cout<<"all characters read successfully."; + else + cout<<"error: only "<filePath = filePath; + } - char* FileManager::retrieveFileBuffer() const - { - return fileBuffer; - } + char* FileManager::retrieveFileBuffer() const + { + return fileBuffer; + } - int FileManager::retrieveFileBufferLength() const { return fileBufferLength; } + int FileManager::retrieveFileBufferLength() const { return fileBufferLength; } } diff --git a/src/Managers/FileManager.h b/src/Managers/FileManager.h deleted file mode 100644 index 9e887ed..0000000 --- a/src/Managers/FileManager.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef FILEMANAGER_H_ -#define FILEMANAGER_H_ - -#include - -namespace Managers -{ - class FileManager - { - public: - FileManager(); - FileManager(std::string); - - 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; - }; -} - -#endif diff --git a/src/Managers/TokenManager.cpp b/src/Managers/TokenManager.cpp index d0d6f02..088ed96 100644 --- a/src/Managers/TokenManager.cpp +++ b/src/Managers/TokenManager.cpp @@ -1,4 +1,4 @@ -#include"TokenManager.h" +#include"Managers/TokenManager.h" #include @@ -17,46 +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 + 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; + #pragma + Token TokenManager::requestToken() + { + Token token{}; + json usrObj; - usrObj["username"] = user.username; - usrObj["password"] = user.password; - cout< #include @@ -12,42 +12,42 @@ using Models::User; namespace Managers { - #pragma - UserManager::UserManager(User user) - { - this->user = user; - } - UserManager::UserManager(const IcarusAction icaAct) - { - this->icaAction = icaAct; - this->user = User{}; - parseUserFromActions(); - } - #pragma Constructors + #pragma + UserManager::UserManager(User user) + { + this->user = user; + } + UserManager::UserManager(const IcarusAction icaAct) + { + this->icaAction = icaAct; + this->user = User{}; + parseUserFromActions(); + } + #pragma Constructors - #pragma - User UserManager::retrieveUser() const - { - return user; - } + #pragma + User UserManager::retrieveUser() const + { + return user; + } - void UserManager::parseUserFromActions() - { - auto args = icaAction.flags; + void UserManager::parseUserFromActions() + { + auto args = icaAction.flags; - for (auto arg : args) - { - auto flag = arg.flag; - if (flag.compare("-u") == 0) - { - user.username = arg.value; - } - if (flag.compare("-p") == 0) - { - user.password = arg.value; - } - } - } - #pragma Functions + for (auto arg : args) + { + auto flag = arg.flag; + if (flag.compare("-u") == 0) + { + user.username = arg.value; + } + if (flag.compare("-p") == 0) + { + user.password = arg.value; + } + } + } + #pragma Functions } diff --git a/src/Managers/UserManager.h b/src/Managers/UserManager.h deleted file mode 100644 index 0d4fb44..0000000 --- a/src/Managers/UserManager.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef USERMANAGER_H_ -#define USERMANAGER_H_ - -#include - -#include"Models/IcarusAction.h" -#include"Models/User.h" - -namespace Managers -{ - class UserManager - { - public: - UserManager(Models::User); - UserManager(const Models::IcarusAction); - - Models::User retrieveUser() const; - private: - void parseUserFromActions(); - - Models::User user; - Models::IcarusAction icaAction; - }; -} - -#endif diff --git a/src/Models/API.h b/src/Models/API.h deleted file mode 100644 index 74c53f3..0000000 --- a/src/Models/API.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef API_H_ -#define API_H_ - -#include - -namespace Models -{ - struct API - { - std::string url; - std::string endpoint; - std::string version; - }; -} - -#endif diff --git a/src/Models/Flags.h b/src/Models/Flags.h deleted file mode 100644 index 67b1aec..0000000 --- a/src/Models/Flags.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef FLAGS_H_ -#define FLAGS_H_ - -#include - -namespace Models -{ - struct Flags - { - std::string flag; - std::string value; - }; -} - -#endif diff --git a/src/Models/Song.h b/src/Models/Song.h deleted file mode 100644 index 085037c..0000000 --- a/src/Models/Song.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef SONG_H_ -#define SONG_H_ - -#include - - -namespace Models -{ - struct Song - { - int id; - std::string title; - std::string artist; - std::string album; - std::string genre; - int year; - int duration; - char *songData; - std::string data; - std::string songPath; - }; -} - -#endif diff --git a/src/Models/Token.h b/src/Models/Token.h deleted file mode 100644 index de55025..0000000 --- a/src/Models/Token.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef TOKEN_H_ -#define TOKEN_H_ - -#include - -namespace Models -{ - struct Token - { - std::string accessToken; - std::string tokenType; - int expiration; - - }; -} - -#endif diff --git a/src/Models/User.h b/src/Models/User.h deleted file mode 100644 index 90b018b..0000000 --- a/src/Models/User.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef USER_H_ -#define USER_H_ - -#include - -namespace Models -{ - struct User - { - std::string username; - std::string password; - }; -} - -#endif diff --git a/src/Parsers/APIParser.cpp b/src/Parsers/APIParser.cpp index 39a354e..5e37116 100644 --- a/src/Parsers/APIParser.cpp +++ b/src/Parsers/APIParser.cpp @@ -1,4 +1,4 @@ -#include"APIParser.h" +#include"Parsers/APIParser.h" #include @@ -10,50 +10,50 @@ using Models::IcarusAction; namespace Parsers { - #pragma - APIParser::APIParser(IcarusAction icaAct) - { - this->icaAct = icaAct; - api = API{}; - parseAPI(); - } - #pragma endregion + #pragma + APIParser::APIParser(IcarusAction icaAct) + { + this->icaAct = icaAct; + api = API{}; + parseAPI(); + } + #pragma endregion - #pragma - API APIParser::retrieveAPI() const - { - return api; - } + #pragma + API APIParser::retrieveAPI() const + { + return api; + } - void APIParser::parseAPI() - { - auto flags = icaAct.flags; - cout<<"Parsing api"< #include @@ -16,47 +16,47 @@ using Models::Token; namespace Syncers { - #pragma - Delete::Delete(API api) - { - this->api = api; - this->api.endpoint = "song/data"; - } - #pragma Constructors + #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}}); + #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; + auto statusCode = r.status_code; - cout<<"Status code "< #include @@ -18,92 +18,92 @@ 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 + 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 int id) - { - string urlRoot = "http://192.168.1.5"; - int port = 9349; - string endpoint = "api/song/data/" + std::to_string(id); - string url = urlRoot + ":" + std::to_string(port) + "/" + - endpoint; - auto r = cpr::Get(cpr::Url{url}); - const char* newBuff = r.text.c_str(); - int bufferLength = r.text.size(); + #pragma + void Download::downloadSong(const int id) + { + string urlRoot = "http://192.168.1.5"; + int port = 9349; + string endpoint = "api/song/data/" + std::to_string(id); + string url = urlRoot + ":" + std::to_string(port) + "/" + + endpoint; + auto r = cpr::Get(cpr::Url{url}); + const char* newBuff = r.text.c_str(); + int bufferLength = r.text.size(); - ofstream saveSong{downloadFilePath, ofstream::binary}; - saveSong.write(newBuff, bufferLength); + ofstream saveSong{downloadFilePath, ofstream::binary}; + saveSong.write(newBuff, bufferLength); - cout<<"HTTP status code: "<songPath<data.length(); - const char *data = song->data.c_str(); - cout<<"buff length "<songPath<data.length(); + const char *data = song->data.c_str(); + cout<<"buff length "<songPath, std::ios::binary}; - saveSong.write(data, bufferLength); - saveSong.close(); - } - #pragma Functions + ofstream saveSong{song->songPath, std::ios::binary}; + saveSong.write(data, bufferLength); + saveSong.close(); + } + #pragma Functions } diff --git a/src/Syncers/Download.h b/src/Syncers/Download.h deleted file mode 100644 index aae0bfd..0000000 --- a/src/Syncers/Download.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef DOWNLOAD_H_ -#define DOWNLOAD_H_ - -#include -#include - -#include"Models/API.h" -#include"Models/Song.h" -#include"Models/Token.h" - -#include"SyncerBase.h" - -namespace Syncers -{ - class Download : SyncerBase - { - public: - Download(); - Download(Models::API); - Download(std::string); - - void downloadSong(int); - void downloadSong(const Models::Token token, Models::Song); - private: - std::string retrieveUrl(Models::Song); - - std::string downloadFilePath; - void saveSong(Models::Song*); - }; -} - -#endif diff --git a/src/Syncers/SyncerBase.h b/src/Syncers/SyncerBase.h deleted file mode 100644 index 78ae5f1..0000000 --- a/src/Syncers/SyncerBase.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef SYNCERBASE_H_ -#define SYNCERBASE_H_ - -#include - -#include"Models/API.h" - -namespace Syncers -{ - class SyncerBase - { - protected: - Models::API api; - const int OK = 200; - const int UNAUTHORIZED = 401; - const int NOTFOUND = 404; - }; -} - -#endif diff --git a/src/Syncers/Upload.cpp b/src/Syncers/Upload.cpp index 476a4a4..f199498 100644 --- a/src/Syncers/Upload.cpp +++ b/src/Syncers/Upload.cpp @@ -5,7 +5,7 @@ #include #include -#include"Upload.h" +#include"Syncers/Upload.h" using std::cout; using std::endl; @@ -23,136 +23,136 @@ using namespace cpr; namespace Syncers { - Upload::Upload() { } - Upload::Upload(string filePath) - { - this->songPath = filePath; - this->fMgr = FileManager(songPath); - } - Upload::Upload(API api) - { - this->api = api; - this->api.endpoint = "song/data"; - } - Upload::Upload(UploadForm formData) - { - this->url = formData.url; - this->songPath = formData.filePath; - } + Upload::Upload() { } + Upload::Upload(string filePath) + { + this->songPath = filePath; + this->fMgr = FileManager(songPath); + } + Upload::Upload(API api) + { + this->api = api; + this->api.endpoint = "song/data"; + } + Upload::Upload(UploadForm formData) + { + this->url = formData.url; + this->songPath = formData.filePath; + } - void Upload::uploadSong() - { - try - { - auto r = cpr::Post(cpr::Url{url}, - cpr::Multipart{{"key", "small value"}, + void Upload::uploadSong() + { + try + { + auto r = cpr::Post(cpr::Url{url}, + cpr::Multipart{{"key", "small value"}, {"file", cpr::File{songPath}}}); - cout << r.status_code<< std::endl; + cout << r.status_code<< std::endl; - cout<<"Success"<song = Models::Song{}; - this->song.id = id; - this->song.title = title; - this->song.artist = artist; - this->song.album = album; - this->song.genre = genre; - this->song.year = year; - this->song.duration = duration; - this->song.songData = fMgr.retrieveFileBuffer(); - cout<<*song.songData<song = Models::Song{}; + this->song.id = id; + this->song.title = title; + this->song.artist = artist; + this->song.album = album; + this->song.genre = genre; + this->song.year = year; + this->song.duration = duration; + this->song.songData = fMgr.retrieveFileBuffer(); + cout<<*song.songData< - -#include - -#include"Managers/FileManager.h" -#include"Models/API.h" -#include"Models/Song.h" -#include"Models/Token.h" -#include"Models/UploadForm.h" - - -namespace Syncers -{ - class Upload - { - public: - Upload(); - Upload(std::string); - Upload(Models::API); - Upload(Models::UploadForm); - - void uploadSong(); - void uploadSong(const Models::Token, Models::Song); - private: - Managers::FileManager fMgr; - Models::API api; - Models::Song song; - std::string apiUrl{""}; // Not being used - std::string apiEndPoint{""}; // Not being used - std::string songPath; // Not being used - std::string url; // Not being used - int port{9349}; // Not being used - - std::string retrieveUrl(); - - void configureSongDemo(); - void printSongDetails(); - void printJsonData(nlohmann::json); - - nlohmann::json serializeObject(); // Not being used - }; -} - -#endif diff --git a/src/UI/AboutWindow.cpp b/src/UI/AboutWindow.cpp index a725140..7943b77 100644 --- a/src/UI/AboutWindow.cpp +++ b/src/UI/AboutWindow.cpp @@ -1,47 +1,47 @@ -#include"AboutWindow.h" +#include"UI/AboutWindow.h" using std::unique_ptr; namespace UI { - AboutWindow::AboutWindow(QWidget* parent): QDialog(parent) - { - setupWindow(); - } + AboutWindow::AboutWindow(QWidget* parent): QDialog(parent) + { + setupWindow(); + } - void AboutWindow::setupWindow() - { - windowWidth = 250; - windowHeight = 300; + void AboutWindow::setupWindow() + { + windowWidth = 250; + windowHeight = 300; - mainLayoutQt = unique_ptr{new QVBoxLayout}; + mainLayoutQt = unique_ptr{new QVBoxLayout}; - appName = unique_ptr{new QLabel(tr("IcarusDownloadManager"))}; - actionButtonQt = unique_ptr{new QPushButton(tr("Close"))}; + appName = unique_ptr{new QLabel(tr("IcarusDownloadManager"))}; + actionButtonQt = unique_ptr{new QPushButton(tr("Close"))}; - mainLayoutQt->addWidget(appName.get()); - mainLayoutQt->addWidget(actionButtonQt.get()); + mainLayoutQt->addWidget(appName.get()); + mainLayoutQt->addWidget(actionButtonQt.get()); - setFixedWidth(windowWidth); - setFixedHeight(windowHeight); + setFixedWidth(windowWidth); + setFixedHeight(windowHeight); - setLayout(mainLayoutQt.get()); + setLayout(mainLayoutQt.get()); - setWindowTitle("About"); + setWindowTitle("About"); - connections(); - } - void AboutWindow::connections() - { - QObject::connect(actionButtonQt.get(), SIGNAL(clicked()), this, - SLOT(closeWindow())); - } + connections(); + } + void AboutWindow::connections() + { + QObject::connect(actionButtonQt.get(), SIGNAL(clicked()), this, + SLOT(closeWindow())); + } - void AboutWindow::closeWindow() - { - this->hide(); - } + void AboutWindow::closeWindow() + { + this->hide(); + } } diff --git a/src/UI/AboutWindow.h b/src/UI/AboutWindow.h deleted file mode 100644 index f479ffc..0000000 --- a/src/UI/AboutWindow.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef ABOUTWINDOW_H_ -#define ABOUTWINDOW_H_ - -#include - -#include -#include -#include -#include -#include - -#include"UI/CommonWindow.h" - -namespace UI -{ - class AboutWindow: public QDialog, public CommonWindow - { - Q_OBJECT - public: - AboutWindow(QWidget* parent=0); - ~AboutWindow() = default; - - private: - void connections(); - void setupWindow(); - - std::unique_ptr appName; - - private slots: - void closeWindow(); - }; -} - -#endif diff --git a/src/UI/CommonWindow.h b/src/UI/CommonWindow.h deleted file mode 100644 index 5fb315f..0000000 --- a/src/UI/CommonWindow.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef COMMONWINDOW_H_ -#define COMMONWINDOW_H_ - -#include - -#include -#include -#include -#include -#include - - -class CommonWindow -{ -public: - CommonWindow() = default; - ~CommonWindow() = default; -protected: - virtual void connections()=0; - std::unique_ptr selectionBoxQt; - std::unique_ptr actionButtonQt; - std::unique_ptr mainLayoutQt; - std::unique_ptr subLayoutOneQt; - std::unique_ptr subLayoutTwoQt; - int windowHeight, windowWidth; -}; -#endif diff --git a/src/UI/MainWindow.cpp b/src/UI/MainWindow.cpp index a7f4bdc..08ec399 100644 --- a/src/UI/MainWindow.cpp +++ b/src/UI/MainWindow.cpp @@ -1,4 +1,4 @@ -#include"MainWindow.h" +#include"UI/MainWindow.h" #include #include @@ -17,158 +17,158 @@ using Syncers::Upload; namespace UI { - MainWindow::MainWindow() - { - setupMainWindow(); - aboutWindow = unique_ptr{new AboutWindow}; - } + 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()}; + 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"))}; + 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 = unique_ptr{new QHBoxLayout}; + songPathPortion = unique_ptr{new QHBoxLayout}; - urlPortion.get()->addWidget(urlLabel.get()); - urlPortion.get()->addWidget(urlQt.get()); + urlPortion.get()->addWidget(urlLabel.get()); + urlPortion.get()->addWidget(urlQt.get()); - songPathPortion->addWidget(songPath.get()); - songPathPortion->addWidget(sourceFilePathQt.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"))}; + 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"); + closeApplicationQt = unique_ptr{new QAction(new QObject(nullptr))}; + closeApplicationQt->setText("Exit Application"); - aboutApplicationQt = unique_ptr{new QAction(new QObject(nullptr))}; - aboutApplicationQt->setText("About"); + aboutApplicationQt = unique_ptr{new QAction(new QObject(nullptr))}; + aboutApplicationQt->setText("About"); - fileMenuQt->addAction(closeApplicationQt.get()); - helpMenuQt->addAction(aboutApplicationQt.get()); + fileMenuQt->addAction(closeApplicationQt.get()); + helpMenuQt->addAction(aboutApplicationQt.get()); - } - void MainWindow::setupMainWidget() - { - mainWidgetQt = unique_ptr{new QWidget}; + } + void MainWindow::setupMainWidget() + { + mainWidgetQt = unique_ptr{new QWidget}; - windowComboBox = unique_ptr{new QComboBox}; - setupWindowLists(); + windowComboBox = unique_ptr{new QComboBox}; + setupWindowLists(); - stackLayout = unique_ptr{new QVBoxLayout}; - stackLayout->addWidget(windowComboBox.get()); + stackLayout = unique_ptr{new QVBoxLayout}; + stackLayout->addWidget(windowComboBox.get()); - uploadSongWidgetQt = unique_ptr{new QWidget}; - uploadSongWidgetQt->setLayout(mainLayoutQt.get()); + uploadSongWidgetQt = unique_ptr{new QWidget}; + uploadSongWidgetQt->setLayout(mainLayoutQt.get()); - stackLayout->addWidget(uploadSongWidgetQt.get()); + stackLayout->addWidget(uploadSongWidgetQt.get()); - mainWidgetQt->setLayout(stackLayout.get()); - } - void MainWindow::setupMainWindow() - { - configureWindowDimensions(); + mainWidgetQt->setLayout(stackLayout.get()); + } + void MainWindow::setupMainWindow() + { + configureWindowDimensions(); - mainLayoutQt = unique_ptr{new QVBoxLayout}; - widgetStack = unique_ptr{new QStackedWidget}; + mainLayoutQt = unique_ptr{new QVBoxLayout}; + widgetStack = unique_ptr{new QStackedWidget}; - configureUploadSection(); + configureUploadSection(); - setupMainWidget(); + setupMainWidget(); - widgetStack->addWidget(mainWidgetQt.get()); + widgetStack->addWidget(mainWidgetQt.get()); - MainDockWidgetQt = unique_ptr{new QDockWidget}; - MainDockWidgetQt.get()->setWindowTitle(tr("Music Manager")); - MainDockWidgetQt->setWidget(widgetStack.get()); - MainDockWidgetQt.get()->setFeatures(QDockWidget::NoDockWidgetFeatures); + MainDockWidgetQt = unique_ptr{new QDockWidget}; + MainDockWidgetQt.get()->setWindowTitle(tr("Music Manager")); + MainDockWidgetQt->setWidget(widgetStack.get()); + MainDockWidgetQt.get()->setFeatures(QDockWidget::NoDockWidgetFeatures); - setCentralWidget(MainDockWidgetQt.get()); + setCentralWidget(MainDockWidgetQt.get()); - createMenus(); + createMenus(); - configureWindowProperties(); + 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")); - } + 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); + 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: "<toPlainText().toUtf8().constData(); + string filePath = sourceFilePathQt->toPlainText().toUtf8().constData(); + cout<<"URL endpoint: "<setEnabled(true); - } + uploadSongQt->setEnabled(true); + } } diff --git a/src/UI/MainWindow.h b/src/UI/MainWindow.h deleted file mode 100644 index 2ea41db..0000000 --- a/src/UI/MainWindow.h +++ /dev/null @@ -1,82 +0,0 @@ -#ifndef MAINWINDOW_H_ -#define MAINWINDOW_H_ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include"UI/CommonWindow.h" -#include"UI/AboutWindow.h" - -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(); - - - std::unique_ptr widgetStack; - - std::unique_ptr stackLayout; - - std::unique_ptr urlPortion; - std::unique_ptr songPathPortion; - - std::unique_ptr mainWidgetQt; - std::unique_ptr uploadSongWidgetQt; - - std::unique_ptr MainDockWidgetQt; - - std::unique_ptr windowComboBox; - - std::unique_ptr uploadSongQt; - - std::unique_ptr urlQt; - std::unique_ptr sourceFilePathQt; - - std::unique_ptr urlLabel; - std::unique_ptr songPath; - - std::unique_ptr fileMenuQt; - std::unique_ptr editMenuQt; - std::unique_ptr helpMenuQt; - - std::unique_ptr closeApplicationQt; - std::unique_ptr aboutApplicationQt; - - std::unique_ptr aboutWindow; - signals: - private slots: - void uploadSong(); - void exitApplication(); - void displaySoftwareInformation(); - void setCurrentIndex(int); - }; -} - -#endif diff --git a/src/Utilities/Conversions.cpp b/src/Utilities/Conversions.cpp index b663fef..56839c2 100644 --- a/src/Utilities/Conversions.cpp +++ b/src/Utilities/Conversions.cpp @@ -1,4 +1,4 @@ -#include"Conversions.h" +#include"Utilities/Conversions.h" #include @@ -7,18 +7,18 @@ using std::unique_ptr; namespace Utilities { - Conversions::Conversions() - { - initializeValues(); - } + 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"< -#include - -namespace Utilities -{ - class Conversions - { - public: - Conversions(); - - void initializeValues(); - - template - void printValue(T); - private: - }; -} - -#endif