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
This commit is contained in:
+28
-28
@@ -1,4 +1,4 @@
|
|||||||
cmake_minimum_required(VERSION 3.2)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
|
||||||
|
|
||||||
include("cmake/HunterGate.cmake")
|
include("cmake/HunterGate.cmake")
|
||||||
@@ -15,17 +15,17 @@ if(NOT ${CMAKE_VERSION} LESS 3.2)
|
|||||||
set(CMAKE_CXX_STANDARD 11)
|
set(CMAKE_CXX_STANDARD 11)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
else()
|
else()
|
||||||
message(STATUS "Checking compiler flags for C++11 support.")
|
message(STATUS "Checking compiler flags for C++117support.")
|
||||||
# Set C++11 support flags for various compilers
|
# Set C++17 support flags for various compilers
|
||||||
include(CheckCXXCompilerFlag)
|
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)
|
check_cxx_compiler_flag("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
|
||||||
if(COMPILER_SUPPORTS_CXX11)
|
if(COMPILER_SUPPORTS_CXX17)
|
||||||
message(STATUS "C++11 is supported.")
|
message(STATUS "C++17 is supported.")
|
||||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
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()
|
else()
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
|
||||||
endif()
|
endif()
|
||||||
elseif(COMPILER_SUPPORTS_CXX0X)
|
elseif(COMPILER_SUPPORTS_CXX0X)
|
||||||
message(STATUS "C++0x is supported.")
|
message(STATUS "C++0x is supported.")
|
||||||
@@ -35,7 +35,7 @@ else()
|
|||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
|
||||||
endif()
|
endif()
|
||||||
else()
|
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()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@@ -54,24 +54,24 @@ set(SOURCES
|
|||||||
src/Utilities/Conversions.cpp
|
src/Utilities/Conversions.cpp
|
||||||
)
|
)
|
||||||
set(HEADERS
|
set(HEADERS
|
||||||
src/Managers/ActionManager.h
|
include/Managers/ActionManager.h
|
||||||
src/Managers/CommitManager.h
|
include/Managers/CommitManager.h
|
||||||
src/Managers/FileManager.h
|
include/Managers/FileManager.h
|
||||||
src/Managers/TokenManager.h
|
include/Managers/TokenManager.h
|
||||||
src/Managers/UserManager.h
|
include/Managers/UserManager.h
|
||||||
src/Models/API.h
|
include/Models/API.h
|
||||||
src/Models/Flags.h
|
include/Models/Flags.h
|
||||||
src/Models/IcarusAction.h
|
include/Models/IcarusAction.h
|
||||||
src/Models/Song.h
|
include/Models/Song.h
|
||||||
src/Models/Token.h
|
include/Models/Token.h
|
||||||
src/Models/UploadForm.h
|
include/Models/UploadForm.h
|
||||||
src/Models/User.h
|
include/Models/User.h
|
||||||
src/Parsers/APIParser.h
|
include/Parsers/APIParser.h
|
||||||
src/Syncers/Delete.h
|
include/Syncers/Delete.h
|
||||||
src/Syncers/Download.h
|
include/Syncers/Download.h
|
||||||
src/Syncers/SyncerBase.h
|
include/Syncers/SyncerBase.h
|
||||||
src/Syncers/Upload.h
|
include/Syncers/Upload.h
|
||||||
src/Utilities/Conversions.h
|
include/Utilities/Conversions.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -84,4 +84,4 @@ find_package(cpr CONFIG REQUIRED)
|
|||||||
|
|
||||||
add_executable(icd ${SOURCES} ${HEADERS})
|
add_executable(icd ${SOURCES} ${HEADERS})
|
||||||
target_link_libraries(icd PUBLIC nlohmann_json::nlohmann_json cpr::cpr)
|
target_link_libraries(icd PUBLIC nlohmann_json::nlohmann_json cpr::cpr)
|
||||||
include_directories(src/)
|
include_directories(include/)
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
#ifndef ACTIONMANAGER_H_
|
||||||
|
#define ACTIONMANAGER_H_
|
||||||
|
|
||||||
|
#include<string>
|
||||||
|
#include<vector>
|
||||||
|
|
||||||
|
#include"Models/Flags.h"
|
||||||
|
#include"Models/IcarusAction.h"
|
||||||
|
|
||||||
|
namespace Managers
|
||||||
|
{
|
||||||
|
class ActionManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ActionManager(char**);
|
||||||
|
|
||||||
|
Models::IcarusAction retrieveIcarusAction() const;
|
||||||
|
std::vector<Models::Flags> retrieveFlags() const;
|
||||||
|
std::string retrieveAction() const;
|
||||||
|
private:
|
||||||
|
bool isNumber(std::string);
|
||||||
|
|
||||||
|
void initialize();
|
||||||
|
void initializeSupportedActions();
|
||||||
|
void initializeSupportedFlags();
|
||||||
|
void validateAction();
|
||||||
|
void validateFlags();
|
||||||
|
|
||||||
|
std::vector<std::string> parsedFlags();
|
||||||
|
|
||||||
|
void printAction();
|
||||||
|
void printFlags(std::vector<std::string>);
|
||||||
|
void printFlags();
|
||||||
|
|
||||||
|
std::string action;
|
||||||
|
std::vector<std::string> supportedActions;
|
||||||
|
std::vector<std::string> supportedFlags;
|
||||||
|
std::vector<Models::Flags> flags;
|
||||||
|
char **params;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#ifndef COMMITMANAGER_H_
|
||||||
|
#define COMMITMANAGER_H_
|
||||||
|
|
||||||
|
#include<map>
|
||||||
|
#include<string>
|
||||||
|
|
||||||
|
#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<std::string, ActionValues> mapActions;
|
||||||
|
Models::IcarusAction icaAction;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
#ifndef FILEMANAGER_H_
|
||||||
|
#define FILEMANAGER_H_
|
||||||
|
|
||||||
|
#include<string>
|
||||||
|
|
||||||
|
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
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#ifndef USERMANAGER_H_
|
||||||
|
#define USERMANAGER_H_
|
||||||
|
|
||||||
|
#include<iostream>
|
||||||
|
|
||||||
|
#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
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef API_H_
|
||||||
|
#define API_H_
|
||||||
|
|
||||||
|
#include<string>
|
||||||
|
|
||||||
|
namespace Models
|
||||||
|
{
|
||||||
|
struct API
|
||||||
|
{
|
||||||
|
std::string url;
|
||||||
|
std::string endpoint;
|
||||||
|
std::string version;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef FLAGS_H_
|
||||||
|
#define FLAGS_H_
|
||||||
|
|
||||||
|
#include<string>
|
||||||
|
|
||||||
|
namespace Models
|
||||||
|
{
|
||||||
|
struct Flags
|
||||||
|
{
|
||||||
|
std::string flag;
|
||||||
|
std::string value;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -8,11 +8,11 @@
|
|||||||
|
|
||||||
namespace Models
|
namespace Models
|
||||||
{
|
{
|
||||||
struct IcarusAction
|
struct IcarusAction
|
||||||
{
|
{
|
||||||
std::string action;
|
std::string action;
|
||||||
std::vector<Flags> flags;
|
std::vector<Flags> flags;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef SONG_H_
|
||||||
|
#define SONG_H_
|
||||||
|
|
||||||
|
#include<string>
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#ifndef TOKEN_H_
|
||||||
|
#define TOKEN_H_
|
||||||
|
|
||||||
|
#include<string>
|
||||||
|
|
||||||
|
namespace Models
|
||||||
|
{
|
||||||
|
struct Token
|
||||||
|
{
|
||||||
|
std::string accessToken;
|
||||||
|
std::string tokenType;
|
||||||
|
int expiration;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -6,11 +6,11 @@
|
|||||||
|
|
||||||
namespace Models
|
namespace Models
|
||||||
{
|
{
|
||||||
struct UploadForm
|
struct UploadForm
|
||||||
{
|
{
|
||||||
std::string url;
|
std::string url;
|
||||||
std::string filePath;
|
std::string filePath;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#ifndef USER_H_
|
||||||
|
#define USER_H_
|
||||||
|
|
||||||
|
#include<string>
|
||||||
|
|
||||||
|
namespace Models
|
||||||
|
{
|
||||||
|
struct User
|
||||||
|
{
|
||||||
|
std::string username;
|
||||||
|
std::string password;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -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
|
||||||
@@ -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
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
#ifndef DOWNLOAD_H_
|
||||||
|
#define DOWNLOAD_H_
|
||||||
|
|
||||||
|
#include<iostream>
|
||||||
|
#include<string>
|
||||||
|
|
||||||
|
#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
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#ifndef SYNCERBASE_H_
|
||||||
|
#define SYNCERBASE_H_
|
||||||
|
|
||||||
|
#include<string>
|
||||||
|
|
||||||
|
#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
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
#ifndef UPLOAD_H_
|
||||||
|
#define UPLOAD_H_
|
||||||
|
|
||||||
|
#include<string>
|
||||||
|
|
||||||
|
#include<nlohmann/json.hpp>
|
||||||
|
|
||||||
|
#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
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#ifndef ABOUTWINDOW_H_
|
||||||
|
#define ABOUTWINDOW_H_
|
||||||
|
|
||||||
|
#include<memory>
|
||||||
|
|
||||||
|
#include<QDialog>
|
||||||
|
#include<QDockWidget>
|
||||||
|
#include<QLabel>
|
||||||
|
#include<QPushButton>
|
||||||
|
#include<QWidget>
|
||||||
|
|
||||||
|
#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<QLabel> appName;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void closeWindow();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
#ifndef COMMONWINDOW_H_
|
||||||
|
#define COMMONWINDOW_H_
|
||||||
|
|
||||||
|
#include<memory>
|
||||||
|
|
||||||
|
#include<QDialog>
|
||||||
|
#include<QHBoxLayout>
|
||||||
|
#include<QVBoxLayout>
|
||||||
|
#include<QComboBox>
|
||||||
|
#include<QPushButton>
|
||||||
|
|
||||||
|
|
||||||
|
class CommonWindow
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CommonWindow() = default;
|
||||||
|
~CommonWindow() = default;
|
||||||
|
protected:
|
||||||
|
virtual void connections()=0;
|
||||||
|
std::unique_ptr<QComboBox> selectionBoxQt;
|
||||||
|
std::unique_ptr<QPushButton> actionButtonQt;
|
||||||
|
std::unique_ptr<QVBoxLayout> mainLayoutQt;
|
||||||
|
std::unique_ptr<QVBoxLayout> subLayoutOneQt;
|
||||||
|
std::unique_ptr<QVBoxLayout> subLayoutTwoQt;
|
||||||
|
int windowHeight, windowWidth;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
#ifndef MAINWINDOW_H_
|
||||||
|
#define MAINWINDOW_H_
|
||||||
|
|
||||||
|
#include<iostream>
|
||||||
|
#include<memory>
|
||||||
|
|
||||||
|
#include<QAction>
|
||||||
|
#include<QComboBox>
|
||||||
|
#include<QDialog>
|
||||||
|
#include<QDockWidget>
|
||||||
|
#include<QLabel>
|
||||||
|
#include<QMenu>
|
||||||
|
#include<QMenuBar>
|
||||||
|
#include<QMainWindow>
|
||||||
|
#include<QPushButton>
|
||||||
|
#include<QStackedWidget>
|
||||||
|
#include<QTextEdit>
|
||||||
|
#include<QWidget>
|
||||||
|
|
||||||
|
#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<QStackedWidget> widgetStack;
|
||||||
|
|
||||||
|
std::unique_ptr<QVBoxLayout> stackLayout;
|
||||||
|
|
||||||
|
std::unique_ptr<QHBoxLayout> urlPortion;
|
||||||
|
std::unique_ptr<QHBoxLayout> songPathPortion;
|
||||||
|
|
||||||
|
std::unique_ptr<QWidget> mainWidgetQt;
|
||||||
|
std::unique_ptr<QWidget> uploadSongWidgetQt;
|
||||||
|
|
||||||
|
std::unique_ptr<QDockWidget> MainDockWidgetQt;
|
||||||
|
|
||||||
|
std::unique_ptr<QComboBox> windowComboBox;
|
||||||
|
|
||||||
|
std::unique_ptr<QPushButton> uploadSongQt;
|
||||||
|
|
||||||
|
std::unique_ptr<QTextEdit> urlQt;
|
||||||
|
std::unique_ptr<QTextEdit> sourceFilePathQt;
|
||||||
|
|
||||||
|
std::unique_ptr<QLabel> urlLabel;
|
||||||
|
std::unique_ptr<QLabel> songPath;
|
||||||
|
|
||||||
|
std::unique_ptr<QMenu> fileMenuQt;
|
||||||
|
std::unique_ptr<QMenu> editMenuQt;
|
||||||
|
std::unique_ptr<QMenu> helpMenuQt;
|
||||||
|
|
||||||
|
std::unique_ptr<QAction> closeApplicationQt;
|
||||||
|
std::unique_ptr<QAction> aboutApplicationQt;
|
||||||
|
|
||||||
|
std::unique_ptr<AboutWindow> aboutWindow;
|
||||||
|
signals:
|
||||||
|
private slots:
|
||||||
|
void uploadSong();
|
||||||
|
void exitApplication();
|
||||||
|
void displaySoftwareInformation();
|
||||||
|
void setCurrentIndex(int);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#ifndef CONVERSIONS_H_
|
||||||
|
#define CONVERSIONS_H_
|
||||||
|
|
||||||
|
#include<memory>
|
||||||
|
#include<string>
|
||||||
|
|
||||||
|
namespace Utilities
|
||||||
|
{
|
||||||
|
class Conversions
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Conversions();
|
||||||
|
|
||||||
|
void initializeValues();
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void printValue(T);
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -12,9 +12,6 @@ using std::string;
|
|||||||
using Managers::ActionManager;
|
using Managers::ActionManager;
|
||||||
using Managers::CommitManager;
|
using Managers::CommitManager;
|
||||||
|
|
||||||
string songPath{};
|
|
||||||
string newSongPath{};
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
|
|||||||
+162
-162
@@ -1,4 +1,5 @@
|
|||||||
#include"ActionManager.h"
|
#include"Managers/ActionManager.h"
|
||||||
|
|
||||||
#include<algorithm>
|
#include<algorithm>
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
#include<exception>
|
#include<exception>
|
||||||
@@ -14,181 +15,180 @@ using Models::IcarusAction;
|
|||||||
|
|
||||||
namespace Managers
|
namespace Managers
|
||||||
{
|
{
|
||||||
#pragma
|
#pragma
|
||||||
ActionManager::ActionManager(char **param)
|
ActionManager::ActionManager(char **param)
|
||||||
{
|
{
|
||||||
this->params = param;
|
this->params = param;
|
||||||
|
|
||||||
action = string{params[1]};
|
action = string{params[1]};
|
||||||
transform(action.begin(), action.end(),
|
transform(action.begin(), action.end(),
|
||||||
action.begin(), ::tolower);
|
action.begin(), ::tolower);
|
||||||
|
|
||||||
initialize();
|
initialize();
|
||||||
}
|
}
|
||||||
#pragma Constructors
|
#pragma Constructors
|
||||||
|
|
||||||
|
|
||||||
#pragma
|
#pragma
|
||||||
IcarusAction ActionManager::retrieveIcarusAction() const
|
IcarusAction ActionManager::retrieveIcarusAction() const
|
||||||
{
|
{
|
||||||
auto icarusAction = IcarusAction{};
|
auto icarusAction = IcarusAction{};
|
||||||
icarusAction.flags = flags;
|
icarusAction.flags = flags;
|
||||||
icarusAction.action = action;
|
icarusAction.action = action;
|
||||||
|
|
||||||
return icarusAction;
|
return icarusAction;
|
||||||
}
|
}
|
||||||
vector<Flags> ActionManager::retrieveFlags() const
|
vector<Flags> ActionManager::retrieveFlags() const
|
||||||
{
|
{
|
||||||
return flags;
|
return flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
string ActionManager::retrieveAction() const
|
string ActionManager::retrieveAction() const
|
||||||
{
|
{
|
||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ActionManager::isNumber(string val)
|
bool ActionManager::isNumber(string val)
|
||||||
{
|
{
|
||||||
return !val.empty() && std::find_if(val.begin(),
|
return !val.empty() && std::find_if(val.begin(),
|
||||||
val.end(), [](char c)
|
val.end(), [](char c)
|
||||||
{
|
{
|
||||||
return !std::isdigit(c);
|
return !std::isdigit(c);
|
||||||
}) == val.end();
|
}) == val.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ActionManager::initialize()
|
void ActionManager::initialize()
|
||||||
{
|
{
|
||||||
initializeSupportedActions();
|
initializeSupportedActions();
|
||||||
validateAction();
|
validateAction();
|
||||||
validateFlags();
|
validateFlags();
|
||||||
}
|
}
|
||||||
void ActionManager::initializeSupportedActions()
|
void ActionManager::initializeSupportedActions()
|
||||||
{
|
{
|
||||||
supportedActions = vector<string>{
|
supportedActions = vector<string>{
|
||||||
"download", "delete",
|
"download", "delete",
|
||||||
"retrieve", "upload"
|
"retrieve", "upload"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
void ActionManager::initializeSupportedFlags()
|
void ActionManager::initializeSupportedFlags()
|
||||||
{
|
{
|
||||||
supportedFlags = vector<string>{
|
supportedFlags = vector<string>{
|
||||||
"-u", "-p", "-t", "-h", "-s",
|
"-u", "-p", "-t", "-h", "-s",
|
||||||
"-d", "-D", "-b"
|
"-d", "-D", "-b"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
void ActionManager::validateAction()
|
void ActionManager::validateAction()
|
||||||
{
|
{
|
||||||
cout<<"Validating action"<<endl;
|
cout<<"Validating action"<<endl;
|
||||||
|
|
||||||
if (std::any_of(supportedActions.begin(), supportedActions.end(),
|
if (std::any_of(supportedActions.begin(), supportedActions.end(),
|
||||||
[&](string val)
|
[&](string val)
|
||||||
{
|
{
|
||||||
return !val.compare(action);
|
return !val.compare(action);
|
||||||
}))
|
}))
|
||||||
{
|
{
|
||||||
cout<<"Action: "<<action<<" is valid"<<endl;
|
//cout<<"Action: "<<action<<" is valid"<<endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cout<<"Action is not valid"<<endl;
|
cout<<"Action is not valid"<<endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ActionManager::validateFlags()
|
void ActionManager::validateFlags()
|
||||||
{
|
{
|
||||||
cout<<"Validating flags"<<endl;
|
cout<<"Validating flags"<<endl;
|
||||||
|
|
||||||
auto flagVals = parsedFlags();
|
auto flagVals = parsedFlags();
|
||||||
initializeSupportedFlags();
|
initializeSupportedFlags();
|
||||||
|
|
||||||
Flags flg{};
|
Flags flg{};
|
||||||
|
|
||||||
for (auto flag : flagVals)
|
for (auto flag : flagVals)
|
||||||
{
|
{
|
||||||
//if (flag.size() > 3 || flg.flag.compare("-D"))
|
if (flag.size() > 3 || isNumber(flag))
|
||||||
if (flag.size() > 3 || isNumber(flag))
|
{
|
||||||
{
|
flg.value = flag;
|
||||||
flg.value = flag;
|
//cout<<"flag value "<<flg.value<<endl;
|
||||||
cout<<"flag value "<<flg.value<<endl;
|
flags.push_back(flg);
|
||||||
flags.push_back(flg);
|
flg = Flags{};
|
||||||
flg = Flags{};
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (std::any_of(supportedFlags.begin(), supportedFlags.end(),
|
if (std::any_of(supportedFlags.begin(), supportedFlags.end(),
|
||||||
[&](string val)
|
[&](string val)
|
||||||
{
|
{
|
||||||
return !val.compare(flag);
|
return !val.compare(flag);
|
||||||
}))
|
}))
|
||||||
{
|
{
|
||||||
cout<<"flag "<<flag<<endl;
|
//cout<<"flag "<<flag<<endl;
|
||||||
flg.flag = flag;
|
flg.flag = flag;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cout<<"Action is not valid"<<endl;
|
cout<<"Action is not valid"<<endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<string> ActionManager::parsedFlags()
|
vector<string> ActionManager::parsedFlags()
|
||||||
{
|
{
|
||||||
auto parsed = vector<string>{};
|
auto parsed = vector<string>{};
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
for (auto i = 2; true; ++i)
|
for (auto i = 2; true; ++i)
|
||||||
{
|
{
|
||||||
string val{*(params + i)};
|
string val{*(params + i)};
|
||||||
cout<<"Parsed flag "<<val<<endl;
|
cout<<"Parsed flag "<<val<<endl;
|
||||||
parsed.push_back(val);
|
parsed.push_back(val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (std::exception e)
|
catch (std::exception e)
|
||||||
{
|
{
|
||||||
auto msg = e.what();
|
auto msg = e.what();
|
||||||
cout<<"This happend: "<<msg<<endl<<endl;
|
cout<<"This happend: "<<msg<<endl<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma
|
#pragma
|
||||||
void ActionManager::printAction()
|
void ActionManager::printAction()
|
||||||
{
|
{
|
||||||
if (action.empty())
|
if (action.empty())
|
||||||
{
|
{
|
||||||
printf("Action is empty\n");
|
printf("Action is empty\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
cout<<"Action is "<<action<<endl;
|
cout<<"Action is "<<action<<endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ActionManager::printFlags(vector<string> flagVals)
|
void ActionManager::printFlags(vector<string> flagVals)
|
||||||
{
|
{
|
||||||
if (flagVals.empty())
|
if (flagVals.empty())
|
||||||
{
|
{
|
||||||
printf("Flags and values are empty\n");
|
printf("Flags and values are empty\n");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Printing flags and values..\n");
|
printf("Printing flags and values..\n");
|
||||||
for (auto flgVal : flagVals)
|
for (auto flgVal : flagVals)
|
||||||
{
|
{
|
||||||
cout<<flgVal<<endl;
|
cout<<flgVal<<endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void ActionManager::printFlags()
|
void ActionManager::printFlags()
|
||||||
{
|
{
|
||||||
cout<<"\nPrinting flags..."<<endl;
|
cout<<"\nPrinting flags..."<<endl;
|
||||||
for (auto flag: flags)
|
for (auto flag: flags)
|
||||||
{
|
{
|
||||||
cout<<"flag "<<flag.flag<<endl;
|
cout<<"flag "<<flag.flag<<endl;
|
||||||
cout<<"value "<<flag.value<<endl;
|
cout<<"value "<<flag.value<<endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#pragma Testing
|
#pragma Testing
|
||||||
#pragma Functions
|
#pragma Functions
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,43 +0,0 @@
|
|||||||
#ifndef ACTIONMANAGER_H_
|
|
||||||
#define ACTIONMANAGER_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
#include<vector>
|
|
||||||
|
|
||||||
#include"Models/Flags.h"
|
|
||||||
#include"Models/IcarusAction.h"
|
|
||||||
|
|
||||||
namespace Managers
|
|
||||||
{
|
|
||||||
class ActionManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
ActionManager(char**);
|
|
||||||
|
|
||||||
Models::IcarusAction retrieveIcarusAction() const;
|
|
||||||
std::vector<Models::Flags> retrieveFlags() const;
|
|
||||||
std::string retrieveAction() const;
|
|
||||||
private:
|
|
||||||
bool isNumber(std::string);
|
|
||||||
|
|
||||||
void initialize();
|
|
||||||
void initializeSupportedActions();
|
|
||||||
void initializeSupportedFlags();
|
|
||||||
void validateAction();
|
|
||||||
void validateFlags();
|
|
||||||
|
|
||||||
std::vector<std::string> parsedFlags();
|
|
||||||
|
|
||||||
void printAction();
|
|
||||||
void printFlags(std::vector<std::string>);
|
|
||||||
void printFlags();
|
|
||||||
|
|
||||||
std::string action;
|
|
||||||
std::vector<std::string> supportedActions;
|
|
||||||
std::vector<std::string> supportedFlags;
|
|
||||||
std::vector<Models::Flags> flags;
|
|
||||||
char **params;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,16 +1,17 @@
|
|||||||
#include"CommitManager.h"
|
#include"Managers/CommitManager.h"
|
||||||
|
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
|
|
||||||
#include"Models/API.h"
|
#include"Models/API.h"
|
||||||
#include"Models/Song.h"
|
#include"Models/Song.h"
|
||||||
|
#include"Models/Token.h"
|
||||||
#include"Parsers/APIParser.h"
|
#include"Parsers/APIParser.h"
|
||||||
#include"Syncers/Delete.h"
|
#include"Syncers/Delete.h"
|
||||||
#include"Syncers/Download.h"
|
#include"Syncers/Download.h"
|
||||||
#include"Syncers/Upload.h"
|
#include"Syncers/Upload.h"
|
||||||
|
|
||||||
#include"TokenManager.h"
|
#include"Managers/TokenManager.h"
|
||||||
#include"UserManager.h"
|
#include"Managers/UserManager.h"
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
@@ -21,6 +22,7 @@ using Managers::TokenManager;
|
|||||||
using Managers::UserManager;
|
using Managers::UserManager;
|
||||||
using Models::API;
|
using Models::API;
|
||||||
using Models::Song;
|
using Models::Song;
|
||||||
|
using Models::Token;
|
||||||
using Parsers::APIParser;
|
using Parsers::APIParser;
|
||||||
using Models::IcarusAction;
|
using Models::IcarusAction;
|
||||||
using Syncers::Delete;
|
using Syncers::Delete;
|
||||||
@@ -59,6 +61,17 @@ namespace Managers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Token CommitManager::parseToken(API api)
|
||||||
|
{
|
||||||
|
cout<<"fetching token"<<endl;
|
||||||
|
UserManager usrMgr{icaAction};
|
||||||
|
auto user = usrMgr.retrieveUser();
|
||||||
|
|
||||||
|
TokenManager tk{user, api};
|
||||||
|
|
||||||
|
return tk.requestToken();
|
||||||
|
}
|
||||||
|
|
||||||
void CommitManager::initializeMapActions()
|
void CommitManager::initializeMapActions()
|
||||||
{
|
{
|
||||||
mapActions = map<string, ActionValues>{
|
mapActions = map<string, ActionValues>{
|
||||||
@@ -69,16 +82,10 @@ namespace Managers
|
|||||||
}
|
}
|
||||||
void CommitManager::deleteSong()
|
void CommitManager::deleteSong()
|
||||||
{
|
{
|
||||||
cout<<"Deleting song..."<<endl;
|
|
||||||
|
|
||||||
UserManager usrMgr{icaAction};
|
|
||||||
auto user = usrMgr.retrieveUser();
|
|
||||||
|
|
||||||
APIParser apiPrs{icaAction};
|
APIParser apiPrs{icaAction};
|
||||||
auto api = apiPrs.retrieveAPI();
|
auto api = apiPrs.retrieveAPI();
|
||||||
|
|
||||||
TokenManager tk{user, api};
|
auto token = parseToken(api);
|
||||||
auto token = tk.requestToken();
|
|
||||||
|
|
||||||
Song song{};
|
Song song{};
|
||||||
|
|
||||||
@@ -94,19 +101,17 @@ namespace Managers
|
|||||||
}
|
}
|
||||||
|
|
||||||
Delete del{api};
|
Delete del{api};
|
||||||
|
cout<<"Deleting song..."<<endl;
|
||||||
del.deleteSong(token, song);
|
del.deleteSong(token, song);
|
||||||
}
|
}
|
||||||
void CommitManager::downloadSong()
|
void CommitManager::downloadSong()
|
||||||
{
|
{
|
||||||
cout<<"Starting downloading process..."<<endl;
|
cout<<"Starting downloading process..."<<endl;
|
||||||
UserManager usrMgr{icaAction};
|
|
||||||
auto user = usrMgr.retrieveUser();
|
|
||||||
|
|
||||||
APIParser apiPrs{icaAction};
|
APIParser apiPrs{icaAction};
|
||||||
auto api = apiPrs.retrieveAPI();
|
auto api = apiPrs.retrieveAPI();
|
||||||
|
|
||||||
TokenManager tk{user, api};
|
auto token = parseToken(api);
|
||||||
auto token = tk.requestToken();
|
|
||||||
|
|
||||||
Song song{};
|
Song song{};
|
||||||
|
|
||||||
@@ -126,19 +131,15 @@ namespace Managers
|
|||||||
}
|
}
|
||||||
|
|
||||||
Download dnld{api};
|
Download dnld{api};
|
||||||
|
cout<<"downloading song"<<endl;
|
||||||
dnld.downloadSong(token, song);
|
dnld.downloadSong(token, song);
|
||||||
}
|
}
|
||||||
void CommitManager::uploadSong()
|
void CommitManager::uploadSong()
|
||||||
{
|
{
|
||||||
cout<<"Uploading song..."<<endl;
|
|
||||||
UserManager usrMgr{icaAction};
|
|
||||||
auto user = usrMgr.retrieveUser();
|
|
||||||
|
|
||||||
APIParser apiPrs{icaAction};
|
APIParser apiPrs{icaAction};
|
||||||
auto api = apiPrs.retrieveAPI();
|
auto api = apiPrs.retrieveAPI();
|
||||||
|
|
||||||
TokenManager tk{user, api};
|
auto token = parseToken(api);
|
||||||
auto token = tk.requestToken();
|
|
||||||
|
|
||||||
Song song{};
|
Song song{};
|
||||||
|
|
||||||
@@ -154,6 +155,7 @@ namespace Managers
|
|||||||
}
|
}
|
||||||
|
|
||||||
Upload upld{api};
|
Upload upld{api};
|
||||||
|
cout<<"Uploading song..."<<endl;
|
||||||
upld.uploadSong(token, song);
|
upld.uploadSong(token, song);
|
||||||
}
|
}
|
||||||
#pragma Functions
|
#pragma Functions
|
||||||
|
|||||||
@@ -1,35 +0,0 @@
|
|||||||
#ifndef COMMITMANAGER_H_
|
|
||||||
#define COMMITMANAGER_H_
|
|
||||||
|
|
||||||
#include<map>
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
#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<std::string, ActionValues> mapActions;
|
|
||||||
Models::IcarusAction icaAction;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
#include<iostream>
|
#include<iostream>
|
||||||
#include<fstream>
|
#include<fstream>
|
||||||
|
|
||||||
#include"FileManager.h"
|
#include"Managers/FileManager.h"
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
@@ -11,56 +11,56 @@ using std::string;
|
|||||||
|
|
||||||
namespace Managers
|
namespace Managers
|
||||||
{
|
{
|
||||||
FileManager::FileManager() {}
|
FileManager::FileManager() {}
|
||||||
FileManager::FileManager(string filePath)
|
FileManager::FileManager(string filePath)
|
||||||
{
|
{
|
||||||
this->filePath = filePath;
|
this->filePath = filePath;
|
||||||
readFile();
|
readFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void FileManager::saveFile(string newFilePath)
|
void FileManager::saveFile(string newFilePath)
|
||||||
{
|
{
|
||||||
if (!fileRead)
|
if (!fileRead)
|
||||||
readFile();
|
readFile();
|
||||||
|
|
||||||
ofstream of{newFilePath, ofstream::binary};
|
ofstream of{newFilePath, ofstream::binary};
|
||||||
of.write(fileBuffer, fileBufferLength);
|
of.write(fileBuffer, fileBufferLength);
|
||||||
of.close();
|
of.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileManager::readFile()
|
void FileManager::readFile()
|
||||||
{
|
{
|
||||||
ifstream is{filePath, ifstream::binary};
|
ifstream is{filePath, ifstream::binary};
|
||||||
if (is)
|
if (is)
|
||||||
{
|
{
|
||||||
is.seekg (0, is.end);
|
is.seekg (0, is.end);
|
||||||
fileBufferLength = is.tellg();
|
fileBufferLength = is.tellg();
|
||||||
is.seekg (0, is.beg);
|
is.seekg (0, is.beg);
|
||||||
|
|
||||||
fileBuffer = new char [fileBufferLength];
|
fileBuffer = new char [fileBufferLength];
|
||||||
|
|
||||||
cout<< "Reading "<<fileBufferLength<<" characters... "<<endl;;
|
cout<< "Reading "<<fileBufferLength<<" characters... "<<endl;;
|
||||||
is.read (fileBuffer,fileBufferLength);
|
is.read (fileBuffer,fileBufferLength);
|
||||||
|
|
||||||
if (is)
|
if (is)
|
||||||
cout<<"all characters read successfully.";
|
cout<<"all characters read successfully.";
|
||||||
else
|
else
|
||||||
cout<<"error: only "<<is.gcount()<<" could be read";
|
cout<<"error: only "<<is.gcount()<<" could be read";
|
||||||
cout<<endl;
|
cout<<endl;
|
||||||
is.close();
|
is.close();
|
||||||
fileRead = true;
|
fileRead = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void FileManager::modifyFilePath(string filePath)
|
void FileManager::modifyFilePath(string filePath)
|
||||||
{
|
{
|
||||||
this->filePath = filePath;
|
this->filePath = filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
char* FileManager::retrieveFileBuffer() const
|
char* FileManager::retrieveFileBuffer() const
|
||||||
{
|
{
|
||||||
return fileBuffer;
|
return fileBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
int FileManager::retrieveFileBufferLength() const { return fileBufferLength; }
|
int FileManager::retrieveFileBufferLength() const { return fileBufferLength; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
#ifndef FILEMANAGER_H_
|
|
||||||
#define FILEMANAGER_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
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
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include"TokenManager.h"
|
#include"Managers/TokenManager.h"
|
||||||
|
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
|
|
||||||
@@ -17,46 +17,46 @@ using Models::User;
|
|||||||
|
|
||||||
namespace Managers
|
namespace Managers
|
||||||
{
|
{
|
||||||
#pragma
|
#pragma
|
||||||
TokenManager::TokenManager(const User user)
|
TokenManager::TokenManager(const User user)
|
||||||
{
|
{
|
||||||
this->user = user;
|
this->user = user;
|
||||||
}
|
}
|
||||||
TokenManager::TokenManager(const User user, API api)
|
TokenManager::TokenManager(const User user, API api)
|
||||||
{
|
{
|
||||||
this->user = user;
|
this->user = user;
|
||||||
this->api = api;
|
this->api = api;
|
||||||
this->api.endpoint = "api/" + api.version
|
this->api.endpoint = "api/" + api.version
|
||||||
+ "/login";
|
+ "/login";
|
||||||
}
|
}
|
||||||
#pragma Constructors
|
#pragma Constructors
|
||||||
|
|
||||||
|
|
||||||
#pragma
|
#pragma
|
||||||
Token TokenManager::requestToken()
|
Token TokenManager::requestToken()
|
||||||
{
|
{
|
||||||
Token token{};
|
Token token{};
|
||||||
json usrObj;
|
json usrObj;
|
||||||
|
|
||||||
usrObj["username"] = user.username;
|
usrObj["username"] = user.username;
|
||||||
usrObj["password"] = user.password;
|
usrObj["password"] = user.password;
|
||||||
cout<<user.username<<" "<<user.password<<endl;
|
cout<<user.username<<" "<<user.password<<endl;
|
||||||
|
|
||||||
cout<<"Sending request for token"<<endl;
|
cout<<"Sending request for token"<<endl;
|
||||||
auto url = api.url + api.endpoint;
|
auto url = api.url + api.endpoint;
|
||||||
cout<<url<<endl;
|
cout<<url<<endl;
|
||||||
auto r = cpr::Post(cpr::Url{url},
|
auto r = cpr::Post(cpr::Url{url},
|
||||||
cpr::Body{usrObj.dump()},
|
cpr::Body{usrObj.dump()},
|
||||||
cpr::Header{{"Content-Type", "application/json"}});
|
cpr::Header{{"Content-Type", "application/json"}});
|
||||||
|
|
||||||
cout<<r.text<<endl;
|
cout<<r.text<<endl;
|
||||||
json res = json::parse(r.text);
|
json res = json::parse(r.text);
|
||||||
token.accessToken = res["token"];
|
token.accessToken = res["token"];
|
||||||
token.tokenType = res["token_type"];
|
token.tokenType = res["token_type"];
|
||||||
|
|
||||||
//cout<<"status code "<<r.status_code<<endl;
|
//cout<<"status code "<<r.status_code<<endl;
|
||||||
|
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
#pragma Functions
|
#pragma Functions
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
#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
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include"UserManager.h"
|
#include"Managers/UserManager.h"
|
||||||
|
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
#include<string>
|
#include<string>
|
||||||
@@ -12,42 +12,42 @@ using Models::User;
|
|||||||
|
|
||||||
namespace Managers
|
namespace Managers
|
||||||
{
|
{
|
||||||
#pragma
|
#pragma
|
||||||
UserManager::UserManager(User user)
|
UserManager::UserManager(User user)
|
||||||
{
|
{
|
||||||
this->user = user;
|
this->user = user;
|
||||||
}
|
}
|
||||||
UserManager::UserManager(const IcarusAction icaAct)
|
UserManager::UserManager(const IcarusAction icaAct)
|
||||||
{
|
{
|
||||||
this->icaAction = icaAct;
|
this->icaAction = icaAct;
|
||||||
this->user = User{};
|
this->user = User{};
|
||||||
parseUserFromActions();
|
parseUserFromActions();
|
||||||
}
|
}
|
||||||
#pragma Constructors
|
#pragma Constructors
|
||||||
|
|
||||||
|
|
||||||
#pragma
|
#pragma
|
||||||
User UserManager::retrieveUser() const
|
User UserManager::retrieveUser() const
|
||||||
{
|
{
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UserManager::parseUserFromActions()
|
void UserManager::parseUserFromActions()
|
||||||
{
|
{
|
||||||
auto args = icaAction.flags;
|
auto args = icaAction.flags;
|
||||||
|
|
||||||
for (auto arg : args)
|
for (auto arg : args)
|
||||||
{
|
{
|
||||||
auto flag = arg.flag;
|
auto flag = arg.flag;
|
||||||
if (flag.compare("-u") == 0)
|
if (flag.compare("-u") == 0)
|
||||||
{
|
{
|
||||||
user.username = arg.value;
|
user.username = arg.value;
|
||||||
}
|
}
|
||||||
if (flag.compare("-p") == 0)
|
if (flag.compare("-p") == 0)
|
||||||
{
|
{
|
||||||
user.password = arg.value;
|
user.password = arg.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#pragma Functions
|
#pragma Functions
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
#ifndef USERMANAGER_H_
|
|
||||||
#define USERMANAGER_H_
|
|
||||||
|
|
||||||
#include<iostream>
|
|
||||||
|
|
||||||
#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
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
#ifndef API_H_
|
|
||||||
#define API_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
namespace Models
|
|
||||||
{
|
|
||||||
struct API
|
|
||||||
{
|
|
||||||
std::string url;
|
|
||||||
std::string endpoint;
|
|
||||||
std::string version;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#ifndef FLAGS_H_
|
|
||||||
#define FLAGS_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
namespace Models
|
|
||||||
{
|
|
||||||
struct Flags
|
|
||||||
{
|
|
||||||
std::string flag;
|
|
||||||
std::string value;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
#ifndef SONG_H_
|
|
||||||
#define SONG_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
#ifndef TOKEN_H_
|
|
||||||
#define TOKEN_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
namespace Models
|
|
||||||
{
|
|
||||||
struct Token
|
|
||||||
{
|
|
||||||
std::string accessToken;
|
|
||||||
std::string tokenType;
|
|
||||||
int expiration;
|
|
||||||
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
#ifndef USER_H_
|
|
||||||
#define USER_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
namespace Models
|
|
||||||
{
|
|
||||||
struct User
|
|
||||||
{
|
|
||||||
std::string username;
|
|
||||||
std::string password;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
+40
-40
@@ -1,4 +1,4 @@
|
|||||||
#include"APIParser.h"
|
#include"Parsers/APIParser.h"
|
||||||
|
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
|
|
||||||
@@ -10,50 +10,50 @@ using Models::IcarusAction;
|
|||||||
|
|
||||||
namespace Parsers
|
namespace Parsers
|
||||||
{
|
{
|
||||||
#pragma
|
#pragma
|
||||||
APIParser::APIParser(IcarusAction icaAct)
|
APIParser::APIParser(IcarusAction icaAct)
|
||||||
{
|
{
|
||||||
this->icaAct = icaAct;
|
this->icaAct = icaAct;
|
||||||
api = API{};
|
api = API{};
|
||||||
parseAPI();
|
parseAPI();
|
||||||
}
|
}
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
|
|
||||||
#pragma
|
#pragma
|
||||||
API APIParser::retrieveAPI() const
|
API APIParser::retrieveAPI() const
|
||||||
{
|
{
|
||||||
return api;
|
return api;
|
||||||
}
|
}
|
||||||
|
|
||||||
void APIParser::parseAPI()
|
void APIParser::parseAPI()
|
||||||
{
|
{
|
||||||
auto flags = icaAct.flags;
|
auto flags = icaAct.flags;
|
||||||
cout<<"Parsing api"<<endl;
|
cout<<"Parsing api"<<endl;
|
||||||
|
|
||||||
//for (auto flag : flags)
|
//for (auto flag : flags)
|
||||||
for (auto i =0; i < flags.size(); ++i)
|
for (auto i =0; i < flags.size(); ++i)
|
||||||
{
|
{
|
||||||
auto arg = flags[i].flag;
|
auto arg = flags[i].flag;
|
||||||
auto value = flags[i].value;
|
auto value = flags[i].value;
|
||||||
|
|
||||||
if (arg.compare("-h") == 0)
|
if (arg.compare("-h") == 0)
|
||||||
|
|
||||||
{
|
{
|
||||||
api.url = value;
|
api.url = value;
|
||||||
}
|
}
|
||||||
if (value.compare("-h") == 0)
|
if (value.compare("-h") == 0)
|
||||||
{
|
{
|
||||||
api.url = flags[i + 1].value;
|
api.url = flags[i + 1].value;
|
||||||
}
|
}
|
||||||
|
|
||||||
cout<<"url is "<<api.url<<endl;
|
cout<<"url is "<<api.url<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: For now I will hard code
|
// TODO: For now I will hard code
|
||||||
// the api version since I am only
|
// the api version since I am only
|
||||||
// on version 1
|
// on version 1
|
||||||
api.version = "v1";
|
api.version = "v1";
|
||||||
}
|
}
|
||||||
#pragma functions
|
#pragma functions
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
#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
|
|
||||||
+37
-37
@@ -1,4 +1,4 @@
|
|||||||
#include"Delete.h"
|
#include"Syncers/Delete.h"
|
||||||
|
|
||||||
#include<exception>
|
#include<exception>
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
@@ -16,47 +16,47 @@ using Models::Token;
|
|||||||
|
|
||||||
namespace Syncers
|
namespace Syncers
|
||||||
{
|
{
|
||||||
#pragma
|
#pragma
|
||||||
Delete::Delete(API api)
|
Delete::Delete(API api)
|
||||||
{
|
{
|
||||||
this->api = api;
|
this->api = api;
|
||||||
this->api.endpoint = "song/data";
|
this->api.endpoint = "song/data";
|
||||||
}
|
}
|
||||||
#pragma Constructors
|
#pragma Constructors
|
||||||
|
|
||||||
|
|
||||||
#pragma
|
#pragma
|
||||||
void Delete::deleteSong(const Token token, Song song)
|
void Delete::deleteSong(const Token token, Song song)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto url = retrieveUrl(song);
|
auto url = retrieveUrl(song);
|
||||||
string auth{token.tokenType};
|
string auth{token.tokenType};
|
||||||
auth.append(" " + token.accessToken);
|
auth.append(" " + token.accessToken);
|
||||||
auto r = cpr::Delete(cpr::Url(url),
|
auto r = cpr::Delete(cpr::Url(url),
|
||||||
cpr::Header{{"authorization", auth}});
|
cpr::Header{{"authorization", auth}});
|
||||||
|
|
||||||
auto statusCode = r.status_code;
|
auto statusCode = r.status_code;
|
||||||
|
|
||||||
cout<<"Status code "<<statusCode<<endl;
|
cout<<"Status code "<<statusCode<<endl;
|
||||||
}
|
}
|
||||||
catch (exception e)
|
catch (exception e)
|
||||||
{
|
{
|
||||||
auto msg = e.what();
|
auto msg = e.what();
|
||||||
cout<<msg<<endl;
|
cout<<msg<<endl;
|
||||||
}
|
}
|
||||||
cout<<"Finished"<<endl;
|
cout<<"Finished"<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
string Delete::retrieveUrl(Song song)
|
string Delete::retrieveUrl(Song song)
|
||||||
{
|
{
|
||||||
string url{api.url + "api/" + api.version + "/" +
|
string url{api.url + "api/" + api.version + "/" +
|
||||||
api.endpoint + "/"};
|
api.endpoint + "/"};
|
||||||
|
|
||||||
url.append(std::to_string(song.id));
|
url.append(std::to_string(song.id));
|
||||||
cout<<"url "<<url<<endl;
|
cout<<"url "<<url<<endl;
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
#pragma Functions
|
#pragma Functions
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
#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
|
|
||||||
+76
-76
@@ -1,4 +1,4 @@
|
|||||||
#include"Download.h"
|
#include"Syncers/Download.h"
|
||||||
|
|
||||||
#include<exception>
|
#include<exception>
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
@@ -18,92 +18,92 @@ using Models::Token;
|
|||||||
|
|
||||||
namespace Syncers
|
namespace Syncers
|
||||||
{
|
{
|
||||||
#pragma
|
#pragma
|
||||||
Download::Download() { }
|
Download::Download() { }
|
||||||
Download::Download(API api)
|
Download::Download(API api)
|
||||||
{
|
{
|
||||||
this->api = api;
|
this->api = api;
|
||||||
this->api.endpoint = "song/data";
|
this->api.endpoint = "song/data";
|
||||||
}
|
}
|
||||||
Download::Download(string filePath)
|
Download::Download(string filePath)
|
||||||
{
|
{
|
||||||
downloadFilePath = filePath;
|
downloadFilePath = filePath;
|
||||||
}
|
}
|
||||||
#pragma Constructors
|
#pragma Constructors
|
||||||
|
|
||||||
|
|
||||||
#pragma
|
#pragma
|
||||||
void Download::downloadSong(const int id)
|
void Download::downloadSong(const int id)
|
||||||
{
|
{
|
||||||
string urlRoot = "http://192.168.1.5";
|
string urlRoot = "http://192.168.1.5";
|
||||||
int port = 9349;
|
int port = 9349;
|
||||||
string endpoint = "api/song/data/" + std::to_string(id);
|
string endpoint = "api/song/data/" + std::to_string(id);
|
||||||
string url = urlRoot + ":" + std::to_string(port) + "/" +
|
string url = urlRoot + ":" + std::to_string(port) + "/" +
|
||||||
endpoint;
|
endpoint;
|
||||||
auto r = cpr::Get(cpr::Url{url});
|
auto r = cpr::Get(cpr::Url{url});
|
||||||
const char* newBuff = r.text.c_str();
|
const char* newBuff = r.text.c_str();
|
||||||
int bufferLength = r.text.size();
|
int bufferLength = r.text.size();
|
||||||
|
|
||||||
ofstream saveSong{downloadFilePath, ofstream::binary};
|
ofstream saveSong{downloadFilePath, ofstream::binary};
|
||||||
saveSong.write(newBuff, bufferLength);
|
saveSong.write(newBuff, bufferLength);
|
||||||
|
|
||||||
cout<<"HTTP status code: "<<r.status_code<<endl;
|
cout<<"HTTP status code: "<<r.status_code<<endl;
|
||||||
cout<<"Header info: "<<r.header["content-type"]<<endl;
|
cout<<"Header info: "<<r.header["content-type"]<<endl;
|
||||||
cout<<"Header info: "<<endl;
|
cout<<"Header info: "<<endl;
|
||||||
cout<<r.header["content-type"]<<endl;
|
cout<<r.header["content-type"]<<endl;
|
||||||
cout<<r.header["content-disposition"]<<endl;
|
cout<<r.header["content-disposition"]<<endl;
|
||||||
}
|
}
|
||||||
void Download::downloadSong(const Token token, Song song)
|
void Download::downloadSong(const Token token, Song song)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string url = retrieveUrl(song);
|
string url = retrieveUrl(song);
|
||||||
song.songPath.append("track.mp3");
|
song.songPath.append("track.mp3");
|
||||||
cout<<"song path "<<song.songPath<<endl;
|
cout<<"song path "<<song.songPath<<endl;
|
||||||
string auth{token.tokenType};
|
string auth{token.tokenType};
|
||||||
auth.append(" " + token.accessToken);
|
auth.append(" " + token.accessToken);
|
||||||
auto r = cpr::Get(cpr::Url(url),
|
auto r = cpr::Get(cpr::Url(url),
|
||||||
cpr::Header{{"authorization", auth}});
|
cpr::Header{{"authorization", auth}});
|
||||||
|
|
||||||
int statusCode = r.status_code;
|
int statusCode = r.status_code;
|
||||||
|
|
||||||
if (statusCode == OK)
|
if (statusCode == OK)
|
||||||
{
|
{
|
||||||
song.data = r.text;
|
song.data = r.text;
|
||||||
saveSong(&song);
|
saveSong(&song);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
cout<<"finsihed with status code "<<statusCode<<endl;
|
cout<<"finsihed with status code "<<statusCode<<endl;
|
||||||
}
|
}
|
||||||
catch (exception e)
|
catch (exception e)
|
||||||
{
|
{
|
||||||
auto msg = e.what();
|
auto msg = e.what();
|
||||||
cout<<msg<<endl;
|
cout<<msg<<endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string Download::retrieveUrl(Song song)
|
string Download::retrieveUrl(Song song)
|
||||||
{
|
{
|
||||||
string url{api.url + "api/" + api.version + "/" +
|
string url{api.url + "api/" + api.version + "/" +
|
||||||
api.endpoint + "/"};
|
api.endpoint + "/"};
|
||||||
|
|
||||||
url.append(std::to_string(song.id));
|
url.append(std::to_string(song.id));
|
||||||
cout<<"url "<<url<<endl;
|
cout<<"url "<<url<<endl;
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Download::saveSong(Song *song)
|
void Download::saveSong(Song *song)
|
||||||
{
|
{
|
||||||
cout<<"\nSaving song to: "<<song->songPath<<endl;
|
cout<<"\nSaving song to: "<<song->songPath<<endl;
|
||||||
int bufferLength = song->data.length();
|
int bufferLength = song->data.length();
|
||||||
const char *data = song->data.c_str();
|
const char *data = song->data.c_str();
|
||||||
cout<<"buff length "<<bufferLength<<endl;
|
cout<<"buff length "<<bufferLength<<endl;
|
||||||
|
|
||||||
ofstream saveSong{song->songPath, std::ios::binary};
|
ofstream saveSong{song->songPath, std::ios::binary};
|
||||||
saveSong.write(data, bufferLength);
|
saveSong.write(data, bufferLength);
|
||||||
saveSong.close();
|
saveSong.close();
|
||||||
}
|
}
|
||||||
#pragma Functions
|
#pragma Functions
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +0,0 @@
|
|||||||
#ifndef DOWNLOAD_H_
|
|
||||||
#define DOWNLOAD_H_
|
|
||||||
|
|
||||||
#include<iostream>
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
#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
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
#ifndef SYNCERBASE_H_
|
|
||||||
#define SYNCERBASE_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
#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
|
|
||||||
+120
-120
@@ -5,7 +5,7 @@
|
|||||||
#include<cpr/cpr.h>
|
#include<cpr/cpr.h>
|
||||||
#include<nlohmann/json.hpp>
|
#include<nlohmann/json.hpp>
|
||||||
|
|
||||||
#include"Upload.h"
|
#include"Syncers/Upload.h"
|
||||||
|
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
@@ -23,136 +23,136 @@ using namespace cpr;
|
|||||||
|
|
||||||
namespace Syncers
|
namespace Syncers
|
||||||
{
|
{
|
||||||
Upload::Upload() { }
|
Upload::Upload() { }
|
||||||
Upload::Upload(string filePath)
|
Upload::Upload(string filePath)
|
||||||
{
|
{
|
||||||
this->songPath = filePath;
|
this->songPath = filePath;
|
||||||
this->fMgr = FileManager(songPath);
|
this->fMgr = FileManager(songPath);
|
||||||
}
|
}
|
||||||
Upload::Upload(API api)
|
Upload::Upload(API api)
|
||||||
{
|
{
|
||||||
this->api = api;
|
this->api = api;
|
||||||
this->api.endpoint = "song/data";
|
this->api.endpoint = "song/data";
|
||||||
}
|
}
|
||||||
Upload::Upload(UploadForm formData)
|
Upload::Upload(UploadForm formData)
|
||||||
{
|
{
|
||||||
this->url = formData.url;
|
this->url = formData.url;
|
||||||
this->songPath = formData.filePath;
|
this->songPath = formData.filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Upload::uploadSong()
|
void Upload::uploadSong()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto r = cpr::Post(cpr::Url{url},
|
auto r = cpr::Post(cpr::Url{url},
|
||||||
cpr::Multipart{{"key", "small value"},
|
cpr::Multipart{{"key", "small value"},
|
||||||
{"file", cpr::File{songPath}}});
|
{"file", cpr::File{songPath}}});
|
||||||
cout << r.status_code<< std::endl;
|
cout << r.status_code<< std::endl;
|
||||||
|
|
||||||
cout<<"Success"<<endl;
|
cout<<"Success"<<endl;
|
||||||
}
|
}
|
||||||
catch(std::exception& e)
|
catch(std::exception& e)
|
||||||
{
|
{
|
||||||
cout<<e.what()<<endl;
|
cout<<e.what()<<endl;
|
||||||
}
|
}
|
||||||
cout<<"Finished"<<endl;
|
cout<<"Finished"<<endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
void Upload::uploadSong(const Models::Token token, Song song)
|
void Upload::uploadSong(const Models::Token token, Song song)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
auto url = retrieveUrl();
|
auto url = retrieveUrl();
|
||||||
|
|
||||||
cout<<"url "<<url<<endl;
|
cout<<"url "<<url<<endl;
|
||||||
string auth{token.tokenType};
|
string auth{token.tokenType};
|
||||||
auth.append(" " + token.accessToken);
|
auth.append(" " + token.accessToken);
|
||||||
auto r = cpr::Post(cpr::Url{url},
|
auto r = cpr::Post(cpr::Url{url},
|
||||||
cpr::Multipart{{"key", "small value"},
|
cpr::Multipart{{"key", "small value"},
|
||||||
{"file", cpr::File{song.songPath}}},
|
{"file", cpr::File{song.songPath}}},
|
||||||
cpr::Header{{"authorization", auth}}
|
cpr::Header{{"authorization", auth}}
|
||||||
);
|
);
|
||||||
|
|
||||||
cout << r.status_code<< std::endl;
|
cout << r.status_code<< std::endl;
|
||||||
}
|
}
|
||||||
catch (exception e)
|
catch (exception e)
|
||||||
{
|
{
|
||||||
auto msg = e.what();
|
auto msg = e.what();
|
||||||
cout<<msg<<endl;
|
cout<<msg<<endl;
|
||||||
}
|
}
|
||||||
cout<<"Finished"<<endl;
|
cout<<"Finished"<<endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
string Upload::retrieveUrl()
|
string Upload::retrieveUrl()
|
||||||
{
|
{
|
||||||
string url = api.url + "api/" + api.version + "/" +
|
string url = api.url + "api/" + api.version + "/" +
|
||||||
api.endpoint;
|
api.endpoint;
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
#pragma
|
#pragma
|
||||||
void Upload::configureSongDemo()
|
void Upload::configureSongDemo()
|
||||||
{
|
{
|
||||||
int id = 0;
|
int id = 0;
|
||||||
string title = "What of it?";
|
string title = "What of it?";
|
||||||
string artist = "Kuoth";
|
string artist = "Kuoth";
|
||||||
string album = "I";
|
string album = "I";
|
||||||
string genre = "Untitled";
|
string genre = "Untitled";
|
||||||
int year = 2019;
|
int year = 2019;
|
||||||
int duration = 260;
|
int duration = 260;
|
||||||
|
|
||||||
this->song = Models::Song{};
|
this->song = Models::Song{};
|
||||||
this->song.id = id;
|
this->song.id = id;
|
||||||
this->song.title = title;
|
this->song.title = title;
|
||||||
this->song.artist = artist;
|
this->song.artist = artist;
|
||||||
this->song.album = album;
|
this->song.album = album;
|
||||||
this->song.genre = genre;
|
this->song.genre = genre;
|
||||||
this->song.year = year;
|
this->song.year = year;
|
||||||
this->song.duration = duration;
|
this->song.duration = duration;
|
||||||
this->song.songData = fMgr.retrieveFileBuffer();
|
this->song.songData = fMgr.retrieveFileBuffer();
|
||||||
cout<<*song.songData<<endl;
|
cout<<*song.songData<<endl;
|
||||||
}
|
}
|
||||||
void Upload::printSongDetails()
|
void Upload::printSongDetails()
|
||||||
{
|
{
|
||||||
cout<<"Song details: "<<endl;
|
cout<<"Song details: "<<endl;
|
||||||
cout<<"Id: "<<song.id<<endl;
|
cout<<"Id: "<<song.id<<endl;
|
||||||
cout<<"Title: "<<song.title<<endl;
|
cout<<"Title: "<<song.title<<endl;
|
||||||
cout<<"Artist: "<<song.artist<<endl;
|
cout<<"Artist: "<<song.artist<<endl;
|
||||||
cout<<"Album: "<<song.album<<endl;
|
cout<<"Album: "<<song.album<<endl;
|
||||||
cout<<"Genre: "<<song.genre<<endl;
|
cout<<"Genre: "<<song.genre<<endl;
|
||||||
cout<<"Year: "<<song.year<<endl;
|
cout<<"Year: "<<song.year<<endl;
|
||||||
cout<<"Duration: "<<song.duration<<endl;
|
cout<<"Duration: "<<song.duration<<endl;
|
||||||
}
|
}
|
||||||
void Upload::printJsonData(json obj)
|
void Upload::printJsonData(json obj)
|
||||||
{
|
{
|
||||||
cout<<endl<<endl<<"JSon data: "<<endl;
|
cout<<endl<<endl<<"JSon data: "<<endl;
|
||||||
cout<<"id: "<<obj["id"]<<endl;
|
cout<<"id: "<<obj["id"]<<endl;
|
||||||
cout<<"title: "<<obj["title"]<<endl;
|
cout<<"title: "<<obj["title"]<<endl;
|
||||||
cout<<"artist: "<<obj["artist"]<<endl;
|
cout<<"artist: "<<obj["artist"]<<endl;
|
||||||
cout<<"album: "<<obj["album"]<<endl;
|
cout<<"album: "<<obj["album"]<<endl;
|
||||||
cout<<"genre: "<<obj["genre"]<<endl;
|
cout<<"genre: "<<obj["genre"]<<endl;
|
||||||
cout<<"year: "<<obj["year"]<<endl;
|
cout<<"year: "<<obj["year"]<<endl;
|
||||||
cout<<"duration: "<<obj["duration"]<<endl;
|
cout<<"duration: "<<obj["duration"]<<endl;
|
||||||
cout<<"song_data: "<<obj["song_data"]<<endl;
|
cout<<"song_data: "<<obj["song_data"]<<endl;
|
||||||
|
|
||||||
cout<<endl<<endl;;
|
cout<<endl<<endl;;
|
||||||
}
|
}
|
||||||
|
|
||||||
json Upload::serializeObject()
|
json Upload::serializeObject()
|
||||||
{
|
{
|
||||||
json jObj{};
|
json jObj{};
|
||||||
jObj["id"] = song.id;
|
jObj["id"] = song.id;
|
||||||
jObj["title"] = song.title;
|
jObj["title"] = song.title;
|
||||||
jObj["artist"] = song.artist;
|
jObj["artist"] = song.artist;
|
||||||
jObj["album"] = song.album;
|
jObj["album"] = song.album;
|
||||||
jObj["genre"] = song.genre;
|
jObj["genre"] = song.genre;
|
||||||
jObj["year"] = song.year;
|
jObj["year"] = song.year;
|
||||||
jObj["duration"] = song.duration;
|
jObj["duration"] = song.duration;
|
||||||
jObj["song_data"] = *song.songData;
|
jObj["song_data"] = *song.songData;
|
||||||
|
|
||||||
return jObj;
|
return jObj;
|
||||||
}
|
}
|
||||||
#pragma Testing
|
#pragma Testing
|
||||||
#pragma Functions
|
#pragma Functions
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
#ifndef UPLOAD_H_
|
|
||||||
#define UPLOAD_H_
|
|
||||||
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
#include<nlohmann/json.hpp>
|
|
||||||
|
|
||||||
#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
|
|
||||||
+29
-29
@@ -1,47 +1,47 @@
|
|||||||
#include"AboutWindow.h"
|
#include"UI/AboutWindow.h"
|
||||||
|
|
||||||
using std::unique_ptr;
|
using std::unique_ptr;
|
||||||
|
|
||||||
namespace UI
|
namespace UI
|
||||||
{
|
{
|
||||||
AboutWindow::AboutWindow(QWidget* parent): QDialog(parent)
|
AboutWindow::AboutWindow(QWidget* parent): QDialog(parent)
|
||||||
{
|
{
|
||||||
setupWindow();
|
setupWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AboutWindow::setupWindow()
|
void AboutWindow::setupWindow()
|
||||||
{
|
{
|
||||||
windowWidth = 250;
|
windowWidth = 250;
|
||||||
windowHeight = 300;
|
windowHeight = 300;
|
||||||
|
|
||||||
mainLayoutQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
mainLayoutQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
||||||
|
|
||||||
appName = unique_ptr<QLabel>{new QLabel(tr("IcarusDownloadManager"))};
|
appName = unique_ptr<QLabel>{new QLabel(tr("IcarusDownloadManager"))};
|
||||||
actionButtonQt = unique_ptr<QPushButton>{new QPushButton(tr("Close"))};
|
actionButtonQt = unique_ptr<QPushButton>{new QPushButton(tr("Close"))};
|
||||||
|
|
||||||
mainLayoutQt->addWidget(appName.get());
|
mainLayoutQt->addWidget(appName.get());
|
||||||
mainLayoutQt->addWidget(actionButtonQt.get());
|
mainLayoutQt->addWidget(actionButtonQt.get());
|
||||||
|
|
||||||
|
|
||||||
setFixedWidth(windowWidth);
|
setFixedWidth(windowWidth);
|
||||||
setFixedHeight(windowHeight);
|
setFixedHeight(windowHeight);
|
||||||
|
|
||||||
setLayout(mainLayoutQt.get());
|
setLayout(mainLayoutQt.get());
|
||||||
|
|
||||||
setWindowTitle("About");
|
setWindowTitle("About");
|
||||||
|
|
||||||
connections();
|
connections();
|
||||||
}
|
}
|
||||||
void AboutWindow::connections()
|
void AboutWindow::connections()
|
||||||
{
|
{
|
||||||
QObject::connect(actionButtonQt.get(), SIGNAL(clicked()), this,
|
QObject::connect(actionButtonQt.get(), SIGNAL(clicked()), this,
|
||||||
SLOT(closeWindow()));
|
SLOT(closeWindow()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void AboutWindow::closeWindow()
|
void AboutWindow::closeWindow()
|
||||||
{
|
{
|
||||||
this->hide();
|
this->hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +0,0 @@
|
|||||||
#ifndef ABOUTWINDOW_H_
|
|
||||||
#define ABOUTWINDOW_H_
|
|
||||||
|
|
||||||
#include<memory>
|
|
||||||
|
|
||||||
#include<QDialog>
|
|
||||||
#include<QDockWidget>
|
|
||||||
#include<QLabel>
|
|
||||||
#include<QPushButton>
|
|
||||||
#include<QWidget>
|
|
||||||
|
|
||||||
#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<QLabel> appName;
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
void closeWindow();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
#ifndef COMMONWINDOW_H_
|
|
||||||
#define COMMONWINDOW_H_
|
|
||||||
|
|
||||||
#include<memory>
|
|
||||||
|
|
||||||
#include<QDialog>
|
|
||||||
#include<QHBoxLayout>
|
|
||||||
#include<QVBoxLayout>
|
|
||||||
#include<QComboBox>
|
|
||||||
#include<QPushButton>
|
|
||||||
|
|
||||||
|
|
||||||
class CommonWindow
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
CommonWindow() = default;
|
|
||||||
~CommonWindow() = default;
|
|
||||||
protected:
|
|
||||||
virtual void connections()=0;
|
|
||||||
std::unique_ptr<QComboBox> selectionBoxQt;
|
|
||||||
std::unique_ptr<QPushButton> actionButtonQt;
|
|
||||||
std::unique_ptr<QVBoxLayout> mainLayoutQt;
|
|
||||||
std::unique_ptr<QVBoxLayout> subLayoutOneQt;
|
|
||||||
std::unique_ptr<QVBoxLayout> subLayoutTwoQt;
|
|
||||||
int windowHeight, windowWidth;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
+124
-124
@@ -1,4 +1,4 @@
|
|||||||
#include"MainWindow.h"
|
#include"UI/MainWindow.h"
|
||||||
|
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
#include<string>
|
#include<string>
|
||||||
@@ -17,158 +17,158 @@ using Syncers::Upload;
|
|||||||
|
|
||||||
namespace UI
|
namespace UI
|
||||||
{
|
{
|
||||||
MainWindow::MainWindow()
|
MainWindow::MainWindow()
|
||||||
{
|
{
|
||||||
setupMainWindow();
|
setupMainWindow();
|
||||||
aboutWindow = unique_ptr<AboutWindow>{new AboutWindow};
|
aboutWindow = unique_ptr<AboutWindow>{new AboutWindow};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::configureDownloadSection()
|
void MainWindow::configureDownloadSection()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
void MainWindow::configureUploadSection()
|
void MainWindow::configureUploadSection()
|
||||||
{
|
{
|
||||||
uploadSongQt = unique_ptr<QPushButton>{new QPushButton(tr("Upload"))};
|
uploadSongQt = unique_ptr<QPushButton>{new QPushButton(tr("Upload"))};
|
||||||
urlQt = unique_ptr<QTextEdit>{new QTextEdit()};
|
urlQt = unique_ptr<QTextEdit>{new QTextEdit()};
|
||||||
sourceFilePathQt = unique_ptr<QTextEdit>{new QTextEdit()};
|
sourceFilePathQt = unique_ptr<QTextEdit>{new QTextEdit()};
|
||||||
|
|
||||||
urlLabel = unique_ptr<QLabel>{new QLabel(tr("URL"))};
|
urlLabel = unique_ptr<QLabel>{new QLabel(tr("URL"))};
|
||||||
songPath = unique_ptr<QLabel>{new QLabel(tr("Song Path"))};
|
songPath = unique_ptr<QLabel>{new QLabel(tr("Song Path"))};
|
||||||
|
|
||||||
urlPortion = unique_ptr<QHBoxLayout>{new QHBoxLayout};
|
urlPortion = unique_ptr<QHBoxLayout>{new QHBoxLayout};
|
||||||
songPathPortion = unique_ptr<QHBoxLayout>{new QHBoxLayout};
|
songPathPortion = unique_ptr<QHBoxLayout>{new QHBoxLayout};
|
||||||
|
|
||||||
urlPortion.get()->addWidget(urlLabel.get());
|
urlPortion.get()->addWidget(urlLabel.get());
|
||||||
urlPortion.get()->addWidget(urlQt.get());
|
urlPortion.get()->addWidget(urlQt.get());
|
||||||
|
|
||||||
songPathPortion->addWidget(songPath.get());
|
songPathPortion->addWidget(songPath.get());
|
||||||
songPathPortion->addWidget(sourceFilePathQt.get());
|
songPathPortion->addWidget(sourceFilePathQt.get());
|
||||||
|
|
||||||
subLayoutOneQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
subLayoutOneQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
||||||
subLayoutOneQt.get()->addLayout(urlPortion.get());
|
subLayoutOneQt.get()->addLayout(urlPortion.get());
|
||||||
subLayoutOneQt->addLayout(songPathPortion.get());
|
subLayoutOneQt->addLayout(songPathPortion.get());
|
||||||
mainLayoutQt.get()->addLayout(subLayoutOneQt.get());
|
mainLayoutQt.get()->addLayout(subLayoutOneQt.get());
|
||||||
}
|
}
|
||||||
void MainWindow::configureWindowDimensions()
|
void MainWindow::configureWindowDimensions()
|
||||||
{
|
{
|
||||||
windowWidth = 450;
|
windowWidth = 450;
|
||||||
windowHeight = 450;
|
windowHeight = 450;
|
||||||
}
|
}
|
||||||
void MainWindow::configureWindowProperties()
|
void MainWindow::configureWindowProperties()
|
||||||
{
|
{
|
||||||
setWindowTitle("IcarusDownloadManager");
|
setWindowTitle("IcarusDownloadManager");
|
||||||
setFixedHeight(windowHeight);
|
setFixedHeight(windowHeight);
|
||||||
setFixedWidth(windowWidth);
|
setFixedWidth(windowWidth);
|
||||||
}
|
}
|
||||||
void MainWindow::connections()
|
void MainWindow::connections()
|
||||||
{
|
{
|
||||||
QObject::connect(uploadSongQt.get(), SIGNAL(clicked()), this, SLOT(uploadSong()));
|
QObject::connect(uploadSongQt.get(), SIGNAL(clicked()), this, SLOT(uploadSong()));
|
||||||
QObject::connect(closeApplicationQt.get(), SIGNAL(triggered()), this,
|
QObject::connect(closeApplicationQt.get(), SIGNAL(triggered()), this,
|
||||||
SLOT(exitApplication()));
|
SLOT(exitApplication()));
|
||||||
QObject::connect(aboutApplicationQt.get(), SIGNAL(triggered()), this,
|
QObject::connect(aboutApplicationQt.get(), SIGNAL(triggered()), this,
|
||||||
SLOT(displaySoftwareInformation()));
|
SLOT(displaySoftwareInformation()));
|
||||||
QObject::connect(windowComboBox.get(), SIGNAL(activated(int)),
|
QObject::connect(windowComboBox.get(), SIGNAL(activated(int)),
|
||||||
this, SLOT(setCurrentIndex(int)));
|
this, SLOT(setCurrentIndex(int)));
|
||||||
}
|
}
|
||||||
void MainWindow::createMenus()
|
void MainWindow::createMenus()
|
||||||
{
|
{
|
||||||
fileMenuQt = unique_ptr<QMenu>{menuBar()->addMenu(tr("File"))};
|
fileMenuQt = unique_ptr<QMenu>{menuBar()->addMenu(tr("File"))};
|
||||||
editMenuQt = unique_ptr<QMenu>{menuBar()->addMenu(tr("Edit"))};
|
editMenuQt = unique_ptr<QMenu>{menuBar()->addMenu(tr("Edit"))};
|
||||||
helpMenuQt = unique_ptr<QMenu>{menuBar()->addMenu(tr("Help"))};
|
helpMenuQt = unique_ptr<QMenu>{menuBar()->addMenu(tr("Help"))};
|
||||||
|
|
||||||
closeApplicationQt = unique_ptr<QAction>{new QAction(new QObject(nullptr))};
|
closeApplicationQt = unique_ptr<QAction>{new QAction(new QObject(nullptr))};
|
||||||
closeApplicationQt->setText("Exit Application");
|
closeApplicationQt->setText("Exit Application");
|
||||||
|
|
||||||
aboutApplicationQt = unique_ptr<QAction>{new QAction(new QObject(nullptr))};
|
aboutApplicationQt = unique_ptr<QAction>{new QAction(new QObject(nullptr))};
|
||||||
aboutApplicationQt->setText("About");
|
aboutApplicationQt->setText("About");
|
||||||
|
|
||||||
fileMenuQt->addAction(closeApplicationQt.get());
|
fileMenuQt->addAction(closeApplicationQt.get());
|
||||||
helpMenuQt->addAction(aboutApplicationQt.get());
|
helpMenuQt->addAction(aboutApplicationQt.get());
|
||||||
|
|
||||||
}
|
}
|
||||||
void MainWindow::setupMainWidget()
|
void MainWindow::setupMainWidget()
|
||||||
{
|
{
|
||||||
mainWidgetQt = unique_ptr<QWidget>{new QWidget};
|
mainWidgetQt = unique_ptr<QWidget>{new QWidget};
|
||||||
|
|
||||||
windowComboBox = unique_ptr<QComboBox>{new QComboBox};
|
windowComboBox = unique_ptr<QComboBox>{new QComboBox};
|
||||||
setupWindowLists();
|
setupWindowLists();
|
||||||
|
|
||||||
|
|
||||||
stackLayout = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
stackLayout = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
||||||
stackLayout->addWidget(windowComboBox.get());
|
stackLayout->addWidget(windowComboBox.get());
|
||||||
|
|
||||||
uploadSongWidgetQt = unique_ptr<QWidget>{new QWidget};
|
uploadSongWidgetQt = unique_ptr<QWidget>{new QWidget};
|
||||||
uploadSongWidgetQt->setLayout(mainLayoutQt.get());
|
uploadSongWidgetQt->setLayout(mainLayoutQt.get());
|
||||||
|
|
||||||
stackLayout->addWidget(uploadSongWidgetQt.get());
|
stackLayout->addWidget(uploadSongWidgetQt.get());
|
||||||
|
|
||||||
mainWidgetQt->setLayout(stackLayout.get());
|
mainWidgetQt->setLayout(stackLayout.get());
|
||||||
}
|
}
|
||||||
void MainWindow::setupMainWindow()
|
void MainWindow::setupMainWindow()
|
||||||
{
|
{
|
||||||
configureWindowDimensions();
|
configureWindowDimensions();
|
||||||
|
|
||||||
mainLayoutQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
mainLayoutQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
||||||
widgetStack = unique_ptr<QStackedWidget>{new QStackedWidget};
|
widgetStack = unique_ptr<QStackedWidget>{new QStackedWidget};
|
||||||
|
|
||||||
configureUploadSection();
|
configureUploadSection();
|
||||||
|
|
||||||
setupMainWidget();
|
setupMainWidget();
|
||||||
|
|
||||||
widgetStack->addWidget(mainWidgetQt.get());
|
widgetStack->addWidget(mainWidgetQt.get());
|
||||||
|
|
||||||
MainDockWidgetQt = unique_ptr<QDockWidget>{new QDockWidget};
|
MainDockWidgetQt = unique_ptr<QDockWidget>{new QDockWidget};
|
||||||
MainDockWidgetQt.get()->setWindowTitle(tr("Music Manager"));
|
MainDockWidgetQt.get()->setWindowTitle(tr("Music Manager"));
|
||||||
MainDockWidgetQt->setWidget(widgetStack.get());
|
MainDockWidgetQt->setWidget(widgetStack.get());
|
||||||
MainDockWidgetQt.get()->setFeatures(QDockWidget::NoDockWidgetFeatures);
|
MainDockWidgetQt.get()->setFeatures(QDockWidget::NoDockWidgetFeatures);
|
||||||
|
|
||||||
setCentralWidget(MainDockWidgetQt.get());
|
setCentralWidget(MainDockWidgetQt.get());
|
||||||
|
|
||||||
createMenus();
|
createMenus();
|
||||||
|
|
||||||
configureWindowProperties();
|
configureWindowProperties();
|
||||||
|
|
||||||
connections();
|
connections();
|
||||||
}
|
}
|
||||||
void MainWindow::setupWindowLists()
|
void MainWindow::setupWindowLists()
|
||||||
{
|
{
|
||||||
windowComboBox->addItem(tr("Upload song"));
|
windowComboBox->addItem(tr("Upload song"));
|
||||||
windowComboBox->addItem(tr("Download song"));
|
windowComboBox->addItem(tr("Download song"));
|
||||||
windowComboBox->addItem(tr("Display all songs"));
|
windowComboBox->addItem(tr("Display all songs"));
|
||||||
windowComboBox->addItem(tr("Display songs"));
|
windowComboBox->addItem(tr("Display songs"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MainWindow::exitApplication()
|
void MainWindow::exitApplication()
|
||||||
{
|
{
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
void MainWindow::displaySoftwareInformation()
|
void MainWindow::displaySoftwareInformation()
|
||||||
{
|
{
|
||||||
aboutWindow->show();
|
aboutWindow->show();
|
||||||
}
|
}
|
||||||
void MainWindow::setCurrentIndex(int index)
|
void MainWindow::setCurrentIndex(int index)
|
||||||
{
|
{
|
||||||
cout<<"index "<<index<<endl;
|
cout<<"index "<<index<<endl;
|
||||||
QString qText = windowComboBox->itemText(index);
|
QString qText = windowComboBox->itemText(index);
|
||||||
auto cnvert = Utilities::Conversions(qText);
|
auto cnvert = Utilities::Conversions(qText);
|
||||||
auto convertedStr = cnvert.convertQStringToString();
|
auto convertedStr = cnvert.convertQStringToString();
|
||||||
cout<<"item text"<<endl;
|
cout<<"item text"<<endl;
|
||||||
}
|
}
|
||||||
void MainWindow::uploadSong()
|
void MainWindow::uploadSong()
|
||||||
{
|
{
|
||||||
uploadSongQt->setEnabled(false);
|
uploadSongQt->setEnabled(false);
|
||||||
|
|
||||||
string url = urlQt->toPlainText().toUtf8().constData();
|
string url = urlQt->toPlainText().toUtf8().constData();
|
||||||
string filePath = sourceFilePathQt->toPlainText().toUtf8().constData();
|
string filePath = sourceFilePathQt->toPlainText().toUtf8().constData();
|
||||||
cout<<"URL endpoint: "<<url<<endl;
|
cout<<"URL endpoint: "<<url<<endl;
|
||||||
cout<<"Music file path: "<<filePath<<endl;
|
cout<<"Music file path: "<<filePath<<endl;
|
||||||
UploadForm formData{url, filePath};
|
UploadForm formData{url, filePath};
|
||||||
|
|
||||||
Upload upld{formData};
|
Upload upld{formData};
|
||||||
upld.uploadSong();
|
upld.uploadSong();
|
||||||
|
|
||||||
uploadSongQt->setEnabled(true);
|
uploadSongQt->setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,82 +0,0 @@
|
|||||||
#ifndef MAINWINDOW_H_
|
|
||||||
#define MAINWINDOW_H_
|
|
||||||
|
|
||||||
#include<iostream>
|
|
||||||
#include<memory>
|
|
||||||
|
|
||||||
#include<QAction>
|
|
||||||
#include<QComboBox>
|
|
||||||
#include<QDialog>
|
|
||||||
#include<QDockWidget>
|
|
||||||
#include<QLabel>
|
|
||||||
#include<QMenu>
|
|
||||||
#include<QMenuBar>
|
|
||||||
#include<QMainWindow>
|
|
||||||
#include<QPushButton>
|
|
||||||
#include<QStackedWidget>
|
|
||||||
#include<QTextEdit>
|
|
||||||
#include<QWidget>
|
|
||||||
|
|
||||||
#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<QStackedWidget> widgetStack;
|
|
||||||
|
|
||||||
std::unique_ptr<QVBoxLayout> stackLayout;
|
|
||||||
|
|
||||||
std::unique_ptr<QHBoxLayout> urlPortion;
|
|
||||||
std::unique_ptr<QHBoxLayout> songPathPortion;
|
|
||||||
|
|
||||||
std::unique_ptr<QWidget> mainWidgetQt;
|
|
||||||
std::unique_ptr<QWidget> uploadSongWidgetQt;
|
|
||||||
|
|
||||||
std::unique_ptr<QDockWidget> MainDockWidgetQt;
|
|
||||||
|
|
||||||
std::unique_ptr<QComboBox> windowComboBox;
|
|
||||||
|
|
||||||
std::unique_ptr<QPushButton> uploadSongQt;
|
|
||||||
|
|
||||||
std::unique_ptr<QTextEdit> urlQt;
|
|
||||||
std::unique_ptr<QTextEdit> sourceFilePathQt;
|
|
||||||
|
|
||||||
std::unique_ptr<QLabel> urlLabel;
|
|
||||||
std::unique_ptr<QLabel> songPath;
|
|
||||||
|
|
||||||
std::unique_ptr<QMenu> fileMenuQt;
|
|
||||||
std::unique_ptr<QMenu> editMenuQt;
|
|
||||||
std::unique_ptr<QMenu> helpMenuQt;
|
|
||||||
|
|
||||||
std::unique_ptr<QAction> closeApplicationQt;
|
|
||||||
std::unique_ptr<QAction> aboutApplicationQt;
|
|
||||||
|
|
||||||
std::unique_ptr<AboutWindow> aboutWindow;
|
|
||||||
signals:
|
|
||||||
private slots:
|
|
||||||
void uploadSong();
|
|
||||||
void exitApplication();
|
|
||||||
void displaySoftwareInformation();
|
|
||||||
void setCurrentIndex(int);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include"Conversions.h"
|
#include"Utilities/Conversions.h"
|
||||||
|
|
||||||
#include<iostream>
|
#include<iostream>
|
||||||
|
|
||||||
@@ -7,18 +7,18 @@ using std::unique_ptr;
|
|||||||
|
|
||||||
namespace Utilities
|
namespace Utilities
|
||||||
{
|
{
|
||||||
Conversions::Conversions()
|
Conversions::Conversions()
|
||||||
{
|
{
|
||||||
initializeValues();
|
initializeValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Conversions::initializeValues()
|
void Conversions::initializeValues()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void Conversions::printValue(T val)
|
void Conversions::printValue(T val)
|
||||||
{
|
{
|
||||||
std::cout<<"going to print value"<<std::endl;
|
std::cout<<"going to print value"<<std::endl;
|
||||||
std::cout<<val<<std::endl;
|
std::cout<<val<<std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
#ifndef CONVERSIONS_H_
|
|
||||||
#define CONVERSIONS_H_
|
|
||||||
|
|
||||||
#include<memory>
|
|
||||||
#include<string>
|
|
||||||
|
|
||||||
namespace Utilities
|
|
||||||
{
|
|
||||||
class Conversions
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Conversions();
|
|
||||||
|
|
||||||
void initializeValues();
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
void printValue(T);
|
|
||||||
private:
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user