Blank slate
This commit is contained in:
@@ -1,79 +0,0 @@
|
||||
#include<iostream>
|
||||
#include<string>
|
||||
|
||||
#include"Managers/ActionManager.h"
|
||||
#include"Managers/CommitManager.h"
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
|
||||
using Managers::ActionManager;
|
||||
using Managers::CommitManager;
|
||||
|
||||
constexpr static auto IcarusDownloadManager_version()
|
||||
{
|
||||
return "v0.3.2";
|
||||
}
|
||||
|
||||
void printHelp()
|
||||
{
|
||||
cout<<"icd [Action] [flag]\n\n";
|
||||
|
||||
cout<<"Actions\n";
|
||||
cout<<"download\n";
|
||||
cout<<"upload\n";
|
||||
cout<<"upload-meta\n";
|
||||
cout<<"retrieve\n";
|
||||
cout<<"delete\n\n";
|
||||
|
||||
cout<<"Flags\n";
|
||||
cout<<"Required for all actions\n";
|
||||
cout<<"-u username\n";
|
||||
cout<<"-p password\n";
|
||||
cout<<"-h host\n\n";
|
||||
|
||||
cout<<"Required for upload\n";
|
||||
cout<<"-s path of song\n";
|
||||
cout<<"-sd directory where to search for songs to upload (Optional)\n";
|
||||
cout<<"-sr directory where to recursively search for songs to upload (Optional)\n";
|
||||
cout<<"-nc will not prompt the user when uploading from a directory\n\n";
|
||||
|
||||
cout<<"Required for upload with metadata\n";
|
||||
cout<<"-s path of song\n";
|
||||
cout<<"-t track number\n";
|
||||
cout<<"-m metadata filepath\n";
|
||||
cout<<"-ca coverart filepath\n";
|
||||
cout<<"-scma directory where songs, metadata, and cover art exists and will be uploaded (Optional)\n\n";
|
||||
|
||||
cout<<"Required for download\n";
|
||||
cout<<"-b song id\n";
|
||||
cout<<"-d path to download song (Optional)\n\n";
|
||||
|
||||
cout<<"Required for retrieving records\n";
|
||||
cout<<"-rt retrieve type (songs is only accepted)\n\n";
|
||||
|
||||
cout<<"Required for deleting a song\n";
|
||||
cout<<"-D song id\n\n";
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc < 2)
|
||||
{
|
||||
printHelp();
|
||||
return -1;
|
||||
}
|
||||
|
||||
ActionManager actMgr(argv, argc);
|
||||
auto chosenAction = actMgr.retrieveIcarusAction();
|
||||
|
||||
chosenAction.print_action_and_flags();
|
||||
|
||||
CommitManager commitMgr(chosenAction);
|
||||
commitMgr.commitAction();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
#include"Managers/ActionManager.h"
|
||||
|
||||
#include<algorithm>
|
||||
#include<iostream>
|
||||
#include<utility>
|
||||
#include<cstring>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
using std::string_view;
|
||||
using std::vector;
|
||||
|
||||
using Models::Flags;
|
||||
using Models::IcarusAction;
|
||||
|
||||
namespace Managers
|
||||
{
|
||||
|
||||
#pragma region Constructors
|
||||
ActionManager::ActionManager(char **param, int paramCount) :
|
||||
params(std::move(param)), paramCount(paramCount)
|
||||
{
|
||||
initialize();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
|
||||
#pragma region Functions
|
||||
IcarusAction ActionManager::retrieveIcarusAction() const
|
||||
{
|
||||
IcarusAction icarusAction;
|
||||
icarusAction.flags = flags;
|
||||
icarusAction.action = action;
|
||||
|
||||
return icarusAction;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ActionManager::initialize()
|
||||
{
|
||||
validateFlags();
|
||||
|
||||
action = std::move(string{params[1]});
|
||||
transform(action.begin(), action.end(),
|
||||
action.begin(), ::tolower);
|
||||
}
|
||||
void ActionManager::validateFlags()
|
||||
{
|
||||
cout<<"Validating flags\n";
|
||||
|
||||
const auto flagVals = parsedFlags();
|
||||
|
||||
for (auto flag = flagVals.begin(); flag != flagVals.end(); ++flag)
|
||||
{
|
||||
Flags flg;
|
||||
cout<<"Value: "<<*flag<<"\n";
|
||||
|
||||
if (isValidFlag<string>(*flag) && doesFlagHaveValue<string>(*flag))
|
||||
{
|
||||
cout<<"Flag has value\n";
|
||||
flg.flag = *flag;
|
||||
flg.value = *(++flag);
|
||||
}
|
||||
else if (isValidFlag<string>(*flag))
|
||||
{
|
||||
cout<<"Flag does not have a value\n";
|
||||
flg.flag = *flag;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<"Flag "<<*flag<<" is not valid"<<endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
flags.emplace_back(std::move(flg));
|
||||
}
|
||||
}
|
||||
|
||||
vector<string> ActionManager::parsedFlags()
|
||||
{
|
||||
auto parsed = vector<string>();
|
||||
|
||||
for (auto i = 2; i < paramCount; ++i)
|
||||
{
|
||||
const std::string flag(std::move(*(params + i)));
|
||||
parsed.push_back(std::move(flag));
|
||||
}
|
||||
|
||||
return parsed;
|
||||
}
|
||||
|
||||
#pragma region Testing
|
||||
void ActionManager::printAction() noexcept
|
||||
{
|
||||
if (action.empty())
|
||||
{
|
||||
printf("Action is empty\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<"Action is "<<action<<endl;
|
||||
}
|
||||
}
|
||||
void ActionManager::printFlags() noexcept
|
||||
{
|
||||
cout<<"\nPrinting flags..."<<endl;
|
||||
for (auto flag: flags)
|
||||
{
|
||||
cout<<"flag "<<flag.flag<<endl;
|
||||
cout<<"value "<<flag.value<<endl;
|
||||
}
|
||||
}
|
||||
#pragma endregion
|
||||
#pragma endregion
|
||||
|
||||
}
|
||||
@@ -1,457 +0,0 @@
|
||||
#include"Managers/CommitManager.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <filesystem>
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
#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/RetrieveRecords.h"
|
||||
#include "Syncers/Upload.h"
|
||||
|
||||
#include "Managers/TokenManager.h"
|
||||
#include "Managers/UserManager.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::map;
|
||||
using std::string;
|
||||
|
||||
using Managers::TokenManager;
|
||||
using Managers::UserManager;
|
||||
using Models::API;
|
||||
using Models::Song;
|
||||
using Models::Token;
|
||||
using Parsers::APIParser;
|
||||
using Models::IcarusAction;
|
||||
using Syncers::Delete;
|
||||
using Syncers::Download;
|
||||
using Syncers::RetrieveRecords;
|
||||
using Syncers::Upload;
|
||||
|
||||
namespace filesystem = std::filesystem;
|
||||
|
||||
namespace Managers
|
||||
{
|
||||
|
||||
#pragma region Constructors
|
||||
CommitManager::CommitManager(IcarusAction& icaAct) : icaAction(std::move(icaAct))
|
||||
{ }
|
||||
#pragma endregion
|
||||
|
||||
|
||||
#pragma region Functions
|
||||
void CommitManager::commitAction()
|
||||
{
|
||||
auto action = icaAction.action;
|
||||
cout<<"Commiting "<<action<<" action"<<endl;
|
||||
|
||||
switch (mapActions()[action])
|
||||
{
|
||||
case ActionValues::deleteAct:
|
||||
deleteSong();
|
||||
break;
|
||||
case ActionValues::downloadAct:
|
||||
downloadSong();
|
||||
break;
|
||||
case ActionValues::retrieveAct:
|
||||
retrieveObjects();
|
||||
break;
|
||||
case ActionValues::uploadAct:
|
||||
uploadSong();
|
||||
break;
|
||||
case ActionValues::UPLOAD_SONG_WITH_METADATA:
|
||||
uploadSongWithMetadata();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
std::map<std::string, CommitManager::ActionValues>
|
||||
CommitManager::mapActions() noexcept
|
||||
{
|
||||
const std::map<std::string, ActionValues> actions{
|
||||
{"delete", ActionValues::deleteAct},
|
||||
{"download", ActionValues::downloadAct},
|
||||
{"retrieve", ActionValues::retrieveAct},
|
||||
{"upload", ActionValues::uploadAct},
|
||||
{"upload-meta", ActionValues::UPLOAD_SONG_WITH_METADATA}
|
||||
};
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Token CommitManager::parseToken(API api)
|
||||
{
|
||||
cout<<"fetching token\n";
|
||||
UserManager usrMgr{icaAction};
|
||||
auto user = usrMgr.retrieveUser();
|
||||
|
||||
TokenManager tk{user, api};
|
||||
|
||||
return tk.requestToken();
|
||||
}
|
||||
|
||||
void CommitManager::deleteSong()
|
||||
{
|
||||
APIParser apiPrs{icaAction};
|
||||
auto api = apiPrs.retrieveAPI();
|
||||
|
||||
auto token = parseToken(api);
|
||||
|
||||
Song song{};
|
||||
|
||||
for (auto arg : icaAction.flags)
|
||||
{
|
||||
auto flag = arg.flag;
|
||||
auto value = arg.value;
|
||||
|
||||
if (flag.compare("-D") == 0)
|
||||
{
|
||||
song.id = atoi(value.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
Delete del{api};
|
||||
cout<<"Deleting song..."<<endl;
|
||||
del.deleteSong(token, song);
|
||||
}
|
||||
void CommitManager::downloadSong()
|
||||
{
|
||||
cout<<"Starting downloading process..."<<endl;
|
||||
|
||||
APIParser apiPrs{icaAction};
|
||||
auto api = apiPrs.retrieveAPI();
|
||||
|
||||
auto token = parseToken(api);
|
||||
|
||||
Song song{};
|
||||
|
||||
for (auto arg : icaAction.flags)
|
||||
{
|
||||
auto flag = arg.flag;
|
||||
auto value = arg.value;
|
||||
|
||||
if (flag.compare("-d") == 0)
|
||||
{
|
||||
song.songPath.assign(arg.value);
|
||||
}
|
||||
if (flag.compare("-b") == 0)
|
||||
{
|
||||
song.id = atoi(value.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
Download dnld{api};
|
||||
cout<<"downloading song"<<endl;
|
||||
dnld.downloadSong(token, song);
|
||||
}
|
||||
void CommitManager::retrieveObjects()
|
||||
{
|
||||
cout<<"Starting retrieve process..."<<endl;
|
||||
|
||||
APIParser apiPrs{icaAction};
|
||||
auto api = apiPrs.retrieveAPI();
|
||||
|
||||
auto token = parseToken(api);
|
||||
RetrieveTypes retrieveType;
|
||||
|
||||
for (auto arg : icaAction.flags)
|
||||
{
|
||||
auto flag = arg.flag;
|
||||
auto value = arg.value;
|
||||
|
||||
if (flag.compare("-rt") == 0)
|
||||
{
|
||||
if (value.compare("songs") == 0)
|
||||
{
|
||||
retrieveType = RetrieveTypes::songs;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RetrieveRecords songs{api, token};
|
||||
songs.retrieve(retrieveType);
|
||||
|
||||
}
|
||||
|
||||
void CommitManager::uploadSong()
|
||||
{
|
||||
auto uploadSingleSong = true;
|
||||
auto recursiveDirectory = false;
|
||||
const auto noConfirm = checkForNoConfirm();
|
||||
string songDirectory;
|
||||
APIParser apiPrs{icaAction};
|
||||
auto api = apiPrs.retrieveAPI();
|
||||
|
||||
auto token = parseToken(api);
|
||||
|
||||
Song song;
|
||||
|
||||
for (auto& arg : icaAction.flags)
|
||||
{
|
||||
auto flag = arg.flag;
|
||||
auto value = arg.value;
|
||||
|
||||
if (flag.compare("-s") == 0)
|
||||
{
|
||||
song.songPath.assign(arg.value);
|
||||
}
|
||||
else if (flag.compare("-sd") == 0)
|
||||
{
|
||||
songDirectory = value;
|
||||
uploadSingleSong = false;
|
||||
}
|
||||
else if (flag.compare("-sr") == 0)
|
||||
{
|
||||
songDirectory = value;
|
||||
uploadSingleSong = false;
|
||||
recursiveDirectory = true;
|
||||
}
|
||||
}
|
||||
|
||||
Upload upld{api, token};
|
||||
if (uploadSingleSong)
|
||||
{
|
||||
cout<<"Uploading song..."<<endl;
|
||||
upld.uploadSong(song);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout<<"Uploading songs from " << songDirectory << endl;
|
||||
upld.uploadSongsFromDirectory(songDirectory, noConfirm, recursiveDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CommitManager::uploadSongWithMetadata()
|
||||
{
|
||||
cout<<"Uploading single song with metadata\n\n";
|
||||
|
||||
// Either the set of "-s", "-m", "-ca", "-t" flags or "-smca" must exist with values
|
||||
// in order to be valid but not both
|
||||
const auto songPath = this->icaAction.retrieveFlagValue("-s");
|
||||
const auto metadataPath = this->icaAction.retrieveFlagValue("-m");
|
||||
const auto coverPath = this->icaAction.retrieveFlagValue("-ca");
|
||||
const auto trackID = this->icaAction.retrieveFlagValue("-t");
|
||||
const auto singleTarget = !songPath.empty() && !metadataPath.empty() &&
|
||||
!coverPath.empty() && !trackID.empty() ? true : false;
|
||||
|
||||
const auto uni = this->icaAction.retrieveFlagValue("-smca");
|
||||
const auto multiTarget = !uni.empty() ? true : false;
|
||||
|
||||
if (singleTarget && multiTarget)
|
||||
{
|
||||
cout<<"Cannot upload from source and directory\n";
|
||||
return;
|
||||
}
|
||||
|
||||
cout<<"Song path: "<<songPath<<"\n";
|
||||
cout<<"TrackID: "<<trackID<<"\n";
|
||||
cout<<"Metadata path: "<<metadataPath<<"\n";
|
||||
cout<<"Cover Art path: "<<coverPath<<"\n";
|
||||
|
||||
if (singleTarget)
|
||||
{
|
||||
singTargetUpload(songPath, trackID, metadataPath, coverPath);
|
||||
}
|
||||
else if (multiTarget)
|
||||
{
|
||||
multiTargetUpload(uni);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CommitManager::singTargetUpload(const std::string &songPath, const std::string &trackID,
|
||||
const std::string &metaPath, const std::string &coverPath)
|
||||
{
|
||||
APIParser apiPrs(icaAction);
|
||||
auto api = apiPrs.retrieveAPI();
|
||||
const auto token = parseToken(api);
|
||||
|
||||
auto album = retrieveMetadata(metaPath);
|
||||
album.printInfo();
|
||||
|
||||
Song song;
|
||||
song.track = 1;
|
||||
song.disc = 1;
|
||||
|
||||
cout<<"TrackID: "<<trackID<<"\n";
|
||||
|
||||
parseDiscAndTrack<Song, std::string>(song, trackID);
|
||||
|
||||
auto c = [](const Song &songA, const Song &songB) { return songA.track == songB.track && songA.disc == songB.disc; };
|
||||
auto sng = Utilities::Checks::itemIterInContainer<Song, std::vector<Song>>(album.songs, song, c);
|
||||
|
||||
if (sng == album.songs.end())
|
||||
{
|
||||
cout<<"Not found with disc "<<song.disc<<" track "<<song.track<<"\n";
|
||||
std::exit(-1);
|
||||
}
|
||||
|
||||
song = *sng;
|
||||
const auto p = filesystem::path(songPath);
|
||||
song.directory = p.parent_path().string();
|
||||
song.generate_filename_from_track();
|
||||
|
||||
Models::CoverArt cover;
|
||||
cover.title = song.title;
|
||||
cover.path = coverPath;
|
||||
|
||||
Upload up(api, token);
|
||||
up.uploadSongWithMetadata(album, song, cover);
|
||||
}
|
||||
|
||||
void CommitManager::multiTargetUpload(const std::string &sourcePath)
|
||||
{
|
||||
APIParser apiPrs(icaAction);
|
||||
auto api = apiPrs.retrieveAPI();
|
||||
const auto token = parseToken(api);
|
||||
|
||||
if (!fs::is_directory(sourcePath))
|
||||
{
|
||||
cout<<sourcePath<<" is not a directory\n";
|
||||
std::exit(-1);
|
||||
}
|
||||
|
||||
std::vector<Song> songs;
|
||||
Models::CoverArt cover;
|
||||
string metadataPath;
|
||||
|
||||
for (auto &p: fs::directory_iterator(sourcePath))
|
||||
{
|
||||
const auto &pp = p.path();
|
||||
const auto stem = pp.stem();
|
||||
const auto file = pp.filename();
|
||||
const auto extension = pp.extension();
|
||||
|
||||
cout<<"Stem "<<stem<<" Extension "<<extension<<"\n";
|
||||
|
||||
auto validImg = [](const std::string& ext)
|
||||
{
|
||||
std::vector<string> extensions;
|
||||
extensions.reserve(3);
|
||||
extensions.push_back(".jpg");
|
||||
extensions.push_back(".jpeg");
|
||||
extensions.push_back(".");
|
||||
|
||||
return ext.compare(extensions[0]) == 0 || ext.compare(extensions[1]) == 0 || ext.compare(extensions[2]) == 0;
|
||||
};
|
||||
|
||||
if (extension.compare(".mp3") == 0)
|
||||
{
|
||||
Song song;
|
||||
song.songPath = pp.string();
|
||||
|
||||
initializeDiscAndTrack<Song, std::string>(song);
|
||||
|
||||
songs.emplace_back(std::move(song));
|
||||
}
|
||||
// else if (extension.compare(".jpg") == 0 || extension.compare(".png") == 0)
|
||||
else if (validImg(extension.string()))
|
||||
{
|
||||
cover.path.assign(pp.string());
|
||||
}
|
||||
else if (extension.compare(".json") == 0)
|
||||
{
|
||||
metadataPath.assign(pp.string());
|
||||
}
|
||||
}
|
||||
|
||||
auto album = retrieveMetadata(metadataPath);
|
||||
songs.clear();
|
||||
songs.assign(album.songs.begin(), album.songs.end());
|
||||
|
||||
Upload up(api, token);
|
||||
|
||||
for (auto &song : songs)
|
||||
{
|
||||
up.uploadSongWithMetadata(album, song, cover);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma region private
|
||||
CommitManager::Album CommitManager::retrieveMetadata(const std::string_view path)
|
||||
{
|
||||
CommitManager::Album album;
|
||||
const auto fileContent = retrieveFileContent(path);
|
||||
cout<<"Parsing...\n";
|
||||
auto serialized = nlohmann::json::parse(fileContent);
|
||||
cout<<"Parsed\n";
|
||||
|
||||
album.album = serialized["album"].get<std::string>();
|
||||
album.albumArtist = serialized["album_artist"].get<std::string>();
|
||||
album.genre = serialized["genre"].get<std::string>();
|
||||
album.year = serialized["year"].get<int>();
|
||||
album.trackCount = serialized["track_count"].get<int>();
|
||||
album.discCount = serialized["disc_count"].get<int>();
|
||||
album.songs.reserve(album.trackCount);
|
||||
|
||||
for (auto &j : serialized["tracks"])
|
||||
{
|
||||
Song song;
|
||||
song.title = j["title"].get<std::string>();
|
||||
song.track = j["track"].get<int>();
|
||||
song.disc = j["disc"].get<int>();
|
||||
song.artist = j["artist"].get<std::string>();
|
||||
song.album = album.album;
|
||||
song.year = album.year;
|
||||
song.genre = album.genre;
|
||||
song.generate_filename_from_track();
|
||||
const auto p = fs::path(path);
|
||||
song.directory = p.parent_path().string();
|
||||
|
||||
album.songs.push_back(song);
|
||||
}
|
||||
|
||||
return album;
|
||||
}
|
||||
|
||||
string CommitManager::retrieveFileContent(const std::string_view path)
|
||||
{
|
||||
string path_str(path);
|
||||
string value;
|
||||
|
||||
std::stringstream buffer;
|
||||
std::fstream file(path_str, std::ios::in);
|
||||
buffer<<file.rdbuf();
|
||||
file.close();
|
||||
|
||||
value.assign(buffer.str());
|
||||
|
||||
return value;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
void CommitManager::Album::printInfo()
|
||||
{
|
||||
std::cout<<"Album: "<<this->album<<"\n";
|
||||
std::cout<<"Album Artist: "<<this->albumArtist<<"\n";
|
||||
std::cout<<"Genre: "<<this->genre<<"\n";
|
||||
std::cout<<"Year: "<<this->year<<"\n";
|
||||
std::cout<<"Track count: "<<this->trackCount<<"\n";
|
||||
std::cout<<"Disc count: "<<this->discCount<<"\n";
|
||||
std::cout<<"\n";
|
||||
}
|
||||
|
||||
#pragma region Functions
|
||||
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
#include<iostream>
|
||||
#include<fstream>
|
||||
|
||||
#include"Managers/FileManager.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::ifstream;
|
||||
using std::ofstream;
|
||||
using std::string;
|
||||
|
||||
namespace Managers
|
||||
{
|
||||
|
||||
#pragma region Constructors
|
||||
FileManager::FileManager() {}
|
||||
FileManager::FileManager(string filePath)
|
||||
{
|
||||
this->filePath = filePath;
|
||||
readFile();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
|
||||
#pragma region Functions
|
||||
void FileManager::saveFile(string newFilePath)
|
||||
{
|
||||
if (!fileRead)
|
||||
readFile();
|
||||
|
||||
ofstream of{newFilePath, ofstream::binary};
|
||||
of.write(fileBuffer, fileBufferLength);
|
||||
of.close();
|
||||
}
|
||||
|
||||
void FileManager::readFile()
|
||||
{
|
||||
ifstream is{filePath, ifstream::binary};
|
||||
if (is)
|
||||
{
|
||||
is.seekg (0, is.end);
|
||||
fileBufferLength = is.tellg();
|
||||
is.seekg (0, is.beg);
|
||||
|
||||
fileBuffer = new char [fileBufferLength];
|
||||
|
||||
cout<< "Reading "<<fileBufferLength<<" characters... "<<endl;;
|
||||
is.read (fileBuffer,fileBufferLength);
|
||||
|
||||
if (is)
|
||||
cout<<"all characters read successfully.";
|
||||
else
|
||||
cout<<"error: only "<<is.gcount()<<" could be read";
|
||||
cout<<endl;
|
||||
is.close();
|
||||
fileRead = true;
|
||||
}
|
||||
}
|
||||
void FileManager::modifyFilePath(string filePath)
|
||||
{
|
||||
this->filePath = filePath;
|
||||
}
|
||||
|
||||
char* FileManager::retrieveFileBuffer() const
|
||||
{
|
||||
return fileBuffer;
|
||||
}
|
||||
|
||||
int FileManager::retrieveFileBufferLength() const { return fileBufferLength; }
|
||||
|
||||
#pragma endregion
|
||||
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
#include"Managers/TokenManager.h"
|
||||
|
||||
#include<iostream>
|
||||
|
||||
#include<cpr/cpr.h>
|
||||
#include<nlohmann/json.hpp>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
using Managers::TokenManager;
|
||||
using Models::API;
|
||||
using Models::Token;
|
||||
using Models::User;
|
||||
|
||||
namespace Managers
|
||||
{
|
||||
|
||||
#pragma region Constructors
|
||||
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 endregion
|
||||
|
||||
|
||||
#pragma region Functions
|
||||
Token TokenManager::requestToken()
|
||||
{
|
||||
Token token{};
|
||||
json usrObj;
|
||||
|
||||
usrObj["username"] = user.username;
|
||||
usrObj["password"] = user.password;
|
||||
|
||||
cout<<"Sending request for token"<<endl;
|
||||
auto url = api.url + api.endpoint;
|
||||
cout<<url<<endl;
|
||||
auto r = cpr::Post(cpr::Url{url},
|
||||
cpr::Body{usrObj.dump()},
|
||||
cpr::Header{{"Content-Type", "application/json"}});
|
||||
|
||||
json res = json::parse(r.text);
|
||||
token.accessToken = res["token"];
|
||||
token.tokenType = res["token_type"];
|
||||
|
||||
cout<<"status code "<<r.status_code<<endl;
|
||||
|
||||
return token;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
#include"Managers/UserManager.h"
|
||||
|
||||
#include<iostream>
|
||||
#include<string>
|
||||
#include<vector>
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
using Models::IcarusAction;
|
||||
using Models::User;
|
||||
|
||||
namespace Managers
|
||||
{
|
||||
|
||||
#pragma region Constructors
|
||||
UserManager::UserManager(User user)
|
||||
{
|
||||
this->user = user;
|
||||
}
|
||||
UserManager::UserManager(const IcarusAction icaAct)
|
||||
{
|
||||
this->icaAction = icaAct;
|
||||
this->user = User{};
|
||||
parseUserFromActions();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
|
||||
#pragma region Functions
|
||||
User UserManager::retrieveUser() const
|
||||
{
|
||||
return user;
|
||||
}
|
||||
|
||||
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 endregion
|
||||
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
#include "Models/Song.h"
|
||||
|
||||
#include "nlohmann/json.hpp"
|
||||
|
||||
using std::string;
|
||||
|
||||
namespace Models
|
||||
{
|
||||
string Song::toMetadataJson()
|
||||
{
|
||||
nlohmann::json s;
|
||||
s["title"] = this->title;
|
||||
s["artist"] = this->artist;
|
||||
s["album"] = this->album;
|
||||
s["genre"] = this->genre;
|
||||
s["year"] = this->year;
|
||||
s["track"] = this->track;
|
||||
s["disc"] = this->disc;
|
||||
|
||||
return s.dump();
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
#include "Parsers/APIParser.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
using Models::API;
|
||||
using Models::IcarusAction;
|
||||
|
||||
namespace Parsers
|
||||
{
|
||||
|
||||
#pragma region Constructors
|
||||
APIParser::APIParser(IcarusAction icaAct) : icaAct(icaAct)
|
||||
{
|
||||
api = API{};
|
||||
parseAPI();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
|
||||
#pragma region Functions
|
||||
API APIParser::retrieveAPI() const
|
||||
{
|
||||
return api;
|
||||
}
|
||||
|
||||
void APIParser::parseAPI()
|
||||
{
|
||||
auto flags = icaAct.flags;
|
||||
cout << "Parsing api" << endl;
|
||||
|
||||
for (auto i =0; i < flags.size(); ++i)
|
||||
{
|
||||
auto arg = flags[i].flag;
|
||||
auto value = flags[i].value;
|
||||
|
||||
if (arg.compare("-h") == 0)
|
||||
{
|
||||
api.url = (value[value.size()-1] == '/') ? value : value + "/";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// NOTE: For now I will hard code
|
||||
// the api version since I am only
|
||||
// on version 1
|
||||
api.version = "v1";
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
#include "Syncers/Delete.h"
|
||||
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
|
||||
#include <cpr/cpr.h>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::exception;
|
||||
using std::string;
|
||||
|
||||
using Models::API;
|
||||
using Models::Song;
|
||||
using Models::Token;
|
||||
|
||||
namespace Syncers
|
||||
{
|
||||
|
||||
#pragma region Constructors
|
||||
Delete::Delete(API api)
|
||||
{
|
||||
this->api = api;
|
||||
this->api.endpoint = "song/data";
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
|
||||
#pragma region Functions
|
||||
void Delete::deleteSong(const Token token, Song song)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto url = retrieveUrl(song);
|
||||
string auth{token.tokenType};
|
||||
auth.append(" " + token.accessToken);
|
||||
auto r = cpr::Delete(cpr::Url(url),
|
||||
cpr::Header{{"authorization", auth}});
|
||||
|
||||
auto statusCode = r.status_code;
|
||||
|
||||
cout<<"Status code "<<statusCode<<endl;
|
||||
}
|
||||
catch (exception e)
|
||||
{
|
||||
auto msg = e.what();
|
||||
cout<<msg<<endl;
|
||||
}
|
||||
cout<<"Finished"<<endl;
|
||||
}
|
||||
|
||||
string Delete::retrieveUrl(Song song)
|
||||
{
|
||||
string url{api.url + "api/" + api.version + "/" +
|
||||
api.endpoint + "/"};
|
||||
|
||||
url.append(std::to_string(song.id));
|
||||
cout<<"url "<<url<<endl;
|
||||
|
||||
return url;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
#include "Syncers/Download.h"
|
||||
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include <cpr/cpr.h>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::exception;
|
||||
using std::ofstream;
|
||||
using std::string;
|
||||
|
||||
using Models::API;
|
||||
using Models::Song;
|
||||
using Models::Token;
|
||||
|
||||
namespace Syncers
|
||||
{
|
||||
|
||||
#pragma region Constructors
|
||||
Download::Download() { }
|
||||
Download::Download(API api)
|
||||
{
|
||||
this->api = api;
|
||||
this->api.endpoint = "song/data";
|
||||
}
|
||||
Download::Download(string filePath)
|
||||
{
|
||||
downloadFilePath = filePath;
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
|
||||
#pragma region Functions
|
||||
void Download::downloadSong(const Token token, Song song)
|
||||
{
|
||||
try
|
||||
{
|
||||
string url = retrieveUrl(song);
|
||||
song.songPath.append("track.mp3");
|
||||
cout<<"song path "<<song.songPath<<endl;
|
||||
string auth{token.tokenType};
|
||||
auth.append(" " + token.accessToken);
|
||||
|
||||
auto r = cpr::Get(cpr::Url(url),
|
||||
cpr::Header{{"Content-type", "audio/mpeg"},
|
||||
{"Authorization", auth}});
|
||||
|
||||
|
||||
int statusCode = r.status_code;
|
||||
|
||||
if (statusCode == OK) {
|
||||
song.data = r.text;
|
||||
saveSong(song);
|
||||
}
|
||||
|
||||
|
||||
cout<<"finsihed with status code "<<statusCode<<endl;
|
||||
}
|
||||
catch (exception e)
|
||||
{
|
||||
auto msg = e.what();
|
||||
cout<<msg<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
string Download::retrieveUrl(Song song)
|
||||
{
|
||||
string url{api.url + "api/" + api.version + "/" +
|
||||
api.endpoint + "/"};
|
||||
|
||||
url.append(std::to_string(song.id));
|
||||
cout<<"url "<<url<<endl;
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
void Download::saveSong(Song& song)
|
||||
{
|
||||
cout<<"\nSaving song to: "<<song.songPath<<endl;
|
||||
int bufferLength = song.data.length();
|
||||
const char *data = song.data.c_str();
|
||||
cout<<"buff length "<<bufferLength<<endl;
|
||||
|
||||
ofstream saveSong{song.songPath, std::ios::binary};
|
||||
saveSong.write(data, bufferLength);
|
||||
saveSong.close();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
#include "Syncers/RetrieveRecords.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include <cpr/cpr.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include "Utilities/Conversions.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::ofstream;
|
||||
|
||||
using Managers::CommitManager;
|
||||
using Models::API;
|
||||
using Models::Token;
|
||||
using Utilities::Conversions;
|
||||
|
||||
namespace Syncers
|
||||
{
|
||||
|
||||
#pragma region Constructors
|
||||
RetrieveRecords::RetrieveRecords() { }
|
||||
RetrieveRecords::RetrieveRecords(API api, Token token)
|
||||
: token(token), api(api) { }
|
||||
#pragma endregion
|
||||
|
||||
#pragma region Functions
|
||||
void RetrieveRecords::retrieve(CommitManager::RetrieveTypes type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case CommitManager::RetrieveTypes::songs:
|
||||
fetchSongs();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
void RetrieveRecords::fetchSongs()
|
||||
{
|
||||
cout<<"fetching songs"<<endl;
|
||||
auto url = api.url + "api/" + api.version + "/" + "song";
|
||||
|
||||
auto auth = token.tokenType;
|
||||
auth.append(" " + token.accessToken);
|
||||
auto r = cpr::Get(cpr::Url{url},
|
||||
cpr::Header{{"authorization", auth},
|
||||
});
|
||||
|
||||
if (r.status_code != (int)Result::OK) {
|
||||
cout<<"something went wrong\n";
|
||||
cout<<"status code: "<<r.status_code<<endl;
|
||||
cout<<"message: "<<r.text<<endl;
|
||||
return;
|
||||
}
|
||||
auto songData = nlohmann::json::parse(r.text);
|
||||
|
||||
ofstream writeData{};
|
||||
writeData.open("songs.json");
|
||||
writeData<<songData.dump(4);
|
||||
writeData.close();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
}
|
||||
@@ -1,243 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <filesystem>
|
||||
#include <exception>
|
||||
|
||||
#include "cpr/cpr.h"
|
||||
|
||||
#include "Syncers/Upload.h"
|
||||
#include "Utilities/Conversions.h"
|
||||
|
||||
using std::cout;
|
||||
using std::cin;
|
||||
using std::endl;
|
||||
using std::exception;
|
||||
using std::string;
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
using Managers::FileManager;
|
||||
using Models::API;
|
||||
using Models::Song;
|
||||
using Models::UploadForm;
|
||||
|
||||
using namespace cpr;
|
||||
|
||||
namespace Syncers
|
||||
{
|
||||
|
||||
#pragma region Constructors
|
||||
#pragma endregion
|
||||
|
||||
|
||||
#pragma region Functions
|
||||
Song Upload::uploadSong(Song& song)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto url = retrieveUrl();
|
||||
|
||||
cout<<"url "<<url<<endl;
|
||||
string auth{this->m_token.tokenType};
|
||||
auth.append(" " + this->m_token.accessToken);
|
||||
auto r = cpr::Post(cpr::Url{url},
|
||||
cpr::Multipart{{"key", "small value"},
|
||||
{"file", cpr::File{song.songPath}}},
|
||||
cpr::Header{{"authorization", auth}}
|
||||
);
|
||||
|
||||
cout << "status code: " << r.status_code<< std::endl;
|
||||
cout << r.text << endl;
|
||||
auto result = nlohmann::json::parse(r.text);
|
||||
cout<<"Finished"<<endl;
|
||||
song.id = result["id"].get<int>();
|
||||
song.title = result["title"].get<std::string>();
|
||||
song.artist = result["artist"].get<std::string>();
|
||||
song.album = result["album"].get<std::string>();
|
||||
song.genre = result["genre"].get<std::string>();
|
||||
song.year = result["year"].get<int>();
|
||||
song.duration = result["duration"].get<int>();
|
||||
song.track = result["track"].get<int>();
|
||||
|
||||
return song;
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
auto msg = e.what();
|
||||
cout<<msg<<endl;
|
||||
}
|
||||
|
||||
return song;
|
||||
}
|
||||
|
||||
void Upload::uploadSongsFromDirectory(const std::string& directory,
|
||||
const bool noConfirm, bool recursive = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto songs = retrieveAllSongsFromDirectory(directory, recursive);
|
||||
auto confirmUpload = true;
|
||||
|
||||
while (!noConfirm)
|
||||
{
|
||||
auto answer = 'a';
|
||||
cout << "are you sure you want to upload " << songs.size() << " songs? [y/n]";
|
||||
cin >> answer;
|
||||
Utilities::Conversions::toLowerChar(answer);
|
||||
|
||||
if (answer == 'y' || answer == 'Y')
|
||||
{
|
||||
confirmUpload = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cout << "uploading songs\n";
|
||||
for (auto& song: songs)
|
||||
{
|
||||
song = uploadSong(song);
|
||||
}
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
cout<<e.what()<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Upload::uploadSongWithMetadata(Managers::CommitManager::Album &album, Models::Song& song, Models::CoverArt &cover)
|
||||
{
|
||||
this->api.endpoint.assign("song/data/upload/with/data");
|
||||
|
||||
try
|
||||
{
|
||||
auto url = retrieveUrl();
|
||||
|
||||
cout << "url " << url << "\n";
|
||||
string auth(this->m_token.tokenType);
|
||||
auth.append(" " + this->m_token.accessToken);
|
||||
|
||||
nlohmann::json s;
|
||||
s["title"] = song.title;
|
||||
s["album"] = album.album;
|
||||
s["album_artist"] = album.albumArtist;
|
||||
s["artist"] = song.artist;
|
||||
s["year"] = album.year;
|
||||
s["genre"] = album.genre;
|
||||
s["disc"] = song.disc;
|
||||
s["track"] = song.track;
|
||||
s["disc_count"] = album.discCount;
|
||||
s["track_count"] = album.trackCount;
|
||||
|
||||
const auto meta = s.dump();
|
||||
|
||||
cout<<"\n\nMeta:\n"<<meta<<"\n";
|
||||
cout << "Filepath: " << song.song_path() << "\n";
|
||||
|
||||
auto multipart = cpr::Multipart{{"cover", cpr::File{cover.path}},
|
||||
{"metadata", meta},
|
||||
{"file", cpr::File{song.song_path()}}};
|
||||
|
||||
auto r = cpr::Post(cpr::Url{url}, multipart,
|
||||
cpr::Header{{"authorization", auth}}
|
||||
);
|
||||
|
||||
cout << "status code: " << r.status_code<< std::endl;
|
||||
cout << r.text << endl;
|
||||
}
|
||||
catch (exception &e)
|
||||
{
|
||||
auto msg = e.what();
|
||||
cout<<"Error: "<<msg<<"\n";
|
||||
}
|
||||
}
|
||||
std::vector<Song> Upload::retrieveAllSongsFromDirectory(const std::string& directory,
|
||||
bool recursive)
|
||||
{
|
||||
std::vector<Song> allSongs;
|
||||
|
||||
if (recursive)
|
||||
{
|
||||
for (auto p: fs::recursive_directory_iterator(directory))
|
||||
{
|
||||
auto song = retrieveSongPath(p);
|
||||
if (!song.songPath.empty())
|
||||
allSongs.push_back(song);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto p: fs::directory_iterator(directory))
|
||||
{
|
||||
auto song = retrieveSongPath(p);
|
||||
if (!song.songPath.empty())
|
||||
allSongs.push_back(song);
|
||||
}
|
||||
}
|
||||
|
||||
return allSongs;
|
||||
}
|
||||
|
||||
|
||||
string Upload::retrieveUrl()
|
||||
{
|
||||
const string url{api.url + "api/" + api.version + "/" +
|
||||
api.endpoint};
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
Song Upload::retrieveSongPath(fs::directory_entry& dirEntry)
|
||||
{
|
||||
constexpr auto mp3Ext = ".mp3";
|
||||
Song song;
|
||||
if (fs::is_regular_file(dirEntry.path()))
|
||||
{
|
||||
const auto ext = dirEntry.path().extension().string();
|
||||
if (ext.compare(mp3Ext) == 0)
|
||||
{
|
||||
cout << "found mp3 file" << endl;
|
||||
song.songPath = dirEntry.path().string();
|
||||
}
|
||||
}
|
||||
|
||||
return song;
|
||||
}
|
||||
|
||||
|
||||
#pragma region Testing
|
||||
|
||||
void Upload::printSongDetails(std::vector<Song>& songs)
|
||||
{
|
||||
for (auto& song: songs)
|
||||
{
|
||||
cout<<"Song details: "<<endl;
|
||||
cout<<"Id: "<<song.id<<endl;
|
||||
cout<<"Title: "<<song.title<<endl;
|
||||
cout<<"Artist: "<<song.artist<<endl;
|
||||
cout<<"Album: "<<song.album<<endl;
|
||||
cout<<"Genre: "<<song.genre<<endl;
|
||||
cout<<"Year: "<<song.year<<endl;
|
||||
cout<<"Duration: "<<song.duration<<endl;
|
||||
cout<<"Path: "<<song.songPath<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Upload::printJsonData(const json& obj)
|
||||
{
|
||||
cout<<endl<<endl<<"JSon data: "<<endl;
|
||||
cout<<"id: "<<obj["id"]<<endl;
|
||||
cout<<"title: "<<obj["title"]<<endl;
|
||||
cout<<"artist: "<<obj["artist"]<<endl;
|
||||
cout<<"album: "<<obj["album"]<<endl;
|
||||
cout<<"genre: "<<obj["genre"]<<endl;
|
||||
cout<<"year: "<<obj["year"]<<endl;
|
||||
cout<<"duration: "<<obj["duration"]<<endl;
|
||||
cout<<"song_data: "<<obj["song_data"]<<endl;
|
||||
|
||||
cout<<endl<<endl;
|
||||
}
|
||||
#pragma endregion
|
||||
#pragma endregion
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
#include "UI/AboutWindow.h"
|
||||
|
||||
using std::unique_ptr;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
#pragma region Constructors
|
||||
AboutWindow::AboutWindow(QWidget* parent): QDialog(parent)
|
||||
{
|
||||
setupWindow();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
|
||||
#pragma region Functions
|
||||
void AboutWindow::setupWindow()
|
||||
{
|
||||
windowWidth = 250;
|
||||
windowHeight = 300;
|
||||
|
||||
mainLayoutQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
||||
|
||||
appName = unique_ptr<QLabel>{new QLabel(tr("IcarusDownloadManager"))};
|
||||
actionButtonQt = unique_ptr<QPushButton>{new QPushButton(tr("Close"))};
|
||||
|
||||
mainLayoutQt->addWidget(appName.get());
|
||||
mainLayoutQt->addWidget(actionButtonQt.get());
|
||||
|
||||
|
||||
setFixedWidth(windowWidth);
|
||||
setFixedHeight(windowHeight);
|
||||
|
||||
setLayout(mainLayoutQt.get());
|
||||
|
||||
setWindowTitle("About");
|
||||
|
||||
connections();
|
||||
}
|
||||
void AboutWindow::connections()
|
||||
{
|
||||
QObject::connect(actionButtonQt.get(), SIGNAL(clicked()), this,
|
||||
SLOT(closeWindow()));
|
||||
}
|
||||
|
||||
|
||||
void AboutWindow::closeWindow()
|
||||
{
|
||||
this->hide();
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
}
|
||||
@@ -1,180 +0,0 @@
|
||||
#include "UI/MainWindow.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "Models/UploadForm.h"
|
||||
#include "Syncers/Upload.h"
|
||||
#include "Utilities/Conversions.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
using std::unique_ptr;
|
||||
|
||||
using Models::UploadForm;
|
||||
using Syncers::Upload;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
|
||||
#pragma region Constructors
|
||||
MainWindow::MainWindow()
|
||||
{
|
||||
setupMainWindow();
|
||||
aboutWindow = unique_ptr<AboutWindow>{new AboutWindow};
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
|
||||
#pragma region Functions
|
||||
void MainWindow::configureDownloadSection()
|
||||
{
|
||||
}
|
||||
void MainWindow::configureUploadSection()
|
||||
{
|
||||
uploadSongQt = unique_ptr<QPushButton>{new QPushButton(tr("Upload"))};
|
||||
urlQt = unique_ptr<QTextEdit>{new QTextEdit()};
|
||||
sourceFilePathQt = unique_ptr<QTextEdit>{new QTextEdit()};
|
||||
|
||||
urlLabel = unique_ptr<QLabel>{new QLabel(tr("URL"))};
|
||||
songPath = unique_ptr<QLabel>{new QLabel(tr("Song Path"))};
|
||||
|
||||
urlPortion = unique_ptr<QHBoxLayout>{new QHBoxLayout};
|
||||
songPathPortion = unique_ptr<QHBoxLayout>{new QHBoxLayout};
|
||||
|
||||
urlPortion.get()->addWidget(urlLabel.get());
|
||||
urlPortion.get()->addWidget(urlQt.get());
|
||||
|
||||
songPathPortion->addWidget(songPath.get());
|
||||
songPathPortion->addWidget(sourceFilePathQt.get());
|
||||
|
||||
subLayoutOneQt = unique_ptr<QVBoxLayout>{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<QMenu>{menuBar()->addMenu(tr("File"))};
|
||||
editMenuQt = unique_ptr<QMenu>{menuBar()->addMenu(tr("Edit"))};
|
||||
helpMenuQt = unique_ptr<QMenu>{menuBar()->addMenu(tr("Help"))};
|
||||
|
||||
closeApplicationQt = unique_ptr<QAction>{new QAction(new QObject(nullptr))};
|
||||
closeApplicationQt->setText("Exit Application");
|
||||
|
||||
aboutApplicationQt = unique_ptr<QAction>{new QAction(new QObject(nullptr))};
|
||||
aboutApplicationQt->setText("About");
|
||||
|
||||
fileMenuQt->addAction(closeApplicationQt.get());
|
||||
helpMenuQt->addAction(aboutApplicationQt.get());
|
||||
|
||||
}
|
||||
void MainWindow::setupMainWidget()
|
||||
{
|
||||
mainWidgetQt = unique_ptr<QWidget>{new QWidget};
|
||||
|
||||
windowComboBox = unique_ptr<QComboBox>{new QComboBox};
|
||||
setupWindowLists();
|
||||
|
||||
|
||||
stackLayout = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
||||
stackLayout->addWidget(windowComboBox.get());
|
||||
|
||||
uploadSongWidgetQt = unique_ptr<QWidget>{new QWidget};
|
||||
uploadSongWidgetQt->setLayout(mainLayoutQt.get());
|
||||
|
||||
stackLayout->addWidget(uploadSongWidgetQt.get());
|
||||
|
||||
mainWidgetQt->setLayout(stackLayout.get());
|
||||
}
|
||||
void MainWindow::setupMainWindow()
|
||||
{
|
||||
configureWindowDimensions();
|
||||
|
||||
mainLayoutQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
||||
widgetStack = unique_ptr<QStackedWidget>{new QStackedWidget};
|
||||
|
||||
configureUploadSection();
|
||||
|
||||
setupMainWidget();
|
||||
|
||||
widgetStack->addWidget(mainWidgetQt.get());
|
||||
|
||||
MainDockWidgetQt = unique_ptr<QDockWidget>{new QDockWidget};
|
||||
MainDockWidgetQt.get()->setWindowTitle(tr("Music Manager"));
|
||||
MainDockWidgetQt->setWidget(widgetStack.get());
|
||||
MainDockWidgetQt.get()->setFeatures(QDockWidget::NoDockWidgetFeatures);
|
||||
|
||||
setCentralWidget(MainDockWidgetQt.get());
|
||||
|
||||
createMenus();
|
||||
|
||||
configureWindowProperties();
|
||||
|
||||
connections();
|
||||
}
|
||||
void MainWindow::setupWindowLists()
|
||||
{
|
||||
windowComboBox->addItem(tr("Upload song"));
|
||||
windowComboBox->addItem(tr("Download song"));
|
||||
windowComboBox->addItem(tr("Display all songs"));
|
||||
windowComboBox->addItem(tr("Display songs"));
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::exitApplication()
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
void MainWindow::displaySoftwareInformation()
|
||||
{
|
||||
aboutWindow->show();
|
||||
}
|
||||
void MainWindow::setCurrentIndex(int index)
|
||||
{
|
||||
cout<<"index "<<index<<endl;
|
||||
QString qText = windowComboBox->itemText(index);
|
||||
auto cnvert = Utilities::Conversions(qText);
|
||||
auto convertedStr = cnvert.convertQStringToString();
|
||||
cout<<"item text"<<endl;
|
||||
}
|
||||
void MainWindow::uploadSong()
|
||||
{
|
||||
uploadSongQt->setEnabled(false);
|
||||
|
||||
string url = urlQt->toPlainText().toUtf8().constData();
|
||||
string filePath = sourceFilePathQt->toPlainText().toUtf8().constData();
|
||||
cout<<"URL endpoint: "<<url<<endl;
|
||||
cout<<"Music file path: "<<filePath<<endl;
|
||||
UploadForm formData{url, filePath};
|
||||
|
||||
Upload upld{formData};
|
||||
upld.uploadSong();
|
||||
|
||||
uploadSongQt->setEnabled(true);
|
||||
}
|
||||
#pragma endregion
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
#include "Utilities/Conversions.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using std::string;
|
||||
using std::unique_ptr;
|
||||
|
||||
namespace Utilities
|
||||
{
|
||||
|
||||
Conversions::Conversions()
|
||||
{
|
||||
initializeValues();
|
||||
}
|
||||
|
||||
void Conversions::initializeValues()
|
||||
{
|
||||
}
|
||||
template <typename T>
|
||||
void Conversions::printValue(T val)
|
||||
{
|
||||
std::cout<<"going to print value\n";
|
||||
std::cout<<val<< "\n";
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user