This commit is contained in:
@@ -51,6 +51,7 @@ set(SOURCES
|
||||
set(HEADERS
|
||||
src/Managers/FileManager.h
|
||||
src/Models/Song.h
|
||||
src/Models/UploadForm.h
|
||||
src/Syncers/Download.h
|
||||
src/Syncers/Upload.h
|
||||
src/UI/CommonWindow.h
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef UPLOADFORM_H_
|
||||
#define UPLOADFORM_H_
|
||||
|
||||
#include<string>
|
||||
|
||||
|
||||
namespace Models
|
||||
{
|
||||
struct UploadForm
|
||||
{
|
||||
std::string url;
|
||||
std::string filePath;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
+10
-6
@@ -12,6 +12,9 @@ using std::string;
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
using Managers::FileManager;
|
||||
using Models::UploadForm;
|
||||
|
||||
using namespace cpr;
|
||||
|
||||
namespace Syncers
|
||||
@@ -20,22 +23,23 @@ namespace Syncers
|
||||
Upload::Upload(string filePath)
|
||||
{
|
||||
this->songPath = filePath;
|
||||
this->fMgr = Managers::FileManager(songPath);
|
||||
this->fMgr = FileManager(songPath);
|
||||
}
|
||||
Upload::Upload(UploadForm formData)
|
||||
{
|
||||
this->url = formData.url;
|
||||
this->songPath = formData.filePath;
|
||||
}
|
||||
|
||||
|
||||
void Upload::uploadSong()
|
||||
{
|
||||
configureSongDemo();
|
||||
|
||||
string url = apiUrl + ":" + std::to_string(port) + apiEndPoint;
|
||||
|
||||
try
|
||||
{
|
||||
auto r = cpr::Post(cpr::Url{url},
|
||||
cpr::Multipart{{"key", "small value"},
|
||||
{"file", cpr::File{songPath}}});
|
||||
cout << r.text << std::endl;
|
||||
cout << r.status_code<< std::endl;
|
||||
|
||||
cout<<"Success"<<endl;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#include"Managers/FileManager.h"
|
||||
#include"Models/Song.h"
|
||||
#include"Models/UploadForm.h"
|
||||
|
||||
|
||||
namespace Syncers
|
||||
@@ -16,6 +17,7 @@ namespace Syncers
|
||||
public:
|
||||
Upload();
|
||||
Upload(std::string);
|
||||
Upload(Models::UploadForm);
|
||||
|
||||
void uploadSong();
|
||||
|
||||
@@ -25,6 +27,7 @@ namespace Syncers
|
||||
std::string apiUrl{"http://192.168.1.3"};
|
||||
std::string apiEndPoint{"/api/song/data"};
|
||||
std::string songPath;
|
||||
std::string url;
|
||||
int port{9349};
|
||||
|
||||
void configureSongDemo();
|
||||
|
||||
@@ -20,8 +20,8 @@ protected:
|
||||
std::unique_ptr<QComboBox> selectionBoxQt;
|
||||
std::unique_ptr<QPushButton> actionButtonQt;
|
||||
std::unique_ptr<QVBoxLayout> mainLayoutQt;
|
||||
std::unique_ptr<QHBoxLayout> subLayoutOneQt;
|
||||
std::unique_ptr<QHBoxLayout> subLayoutTwoQt;
|
||||
std::unique_ptr<QVBoxLayout> subLayoutOneQt;
|
||||
std::unique_ptr<QVBoxLayout> subLayoutTwoQt;
|
||||
int windowHeight, windowWidth;
|
||||
};
|
||||
#endif
|
||||
|
||||
+51
-25
@@ -1,7 +1,19 @@
|
||||
#include"MainWindow.h"
|
||||
|
||||
#include<iostream>
|
||||
#include<string>
|
||||
|
||||
#include"Models/UploadForm.h"
|
||||
#include"Syncers/Upload.h"
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
using std::string;
|
||||
using std::unique_ptr;
|
||||
|
||||
using Models::UploadForm;
|
||||
using Syncers::Upload;
|
||||
|
||||
namespace UI
|
||||
{
|
||||
MainWindow::MainWindow()
|
||||
@@ -16,11 +28,20 @@ namespace UI
|
||||
}
|
||||
void MainWindow::configureUploadSection()
|
||||
{
|
||||
uploadSongQt = unique_ptr<QPushButton>{new QPushButton(tr("Upload"))};
|
||||
urlQt = unique_ptr<QTextEdit>{new QTextEdit()};
|
||||
sourceFilePathQt = unique_ptr<QTextEdit>{new QTextEdit()};
|
||||
|
||||
subLayoutOneQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
||||
subLayoutOneQt.get()->addWidget(urlQt.get());
|
||||
subLayoutOneQt.get()->addWidget(sourceFilePathQt.get());
|
||||
subLayoutOneQt.get()->addWidget(uploadSongQt.get());
|
||||
mainLayoutQt.get()->addLayout(subLayoutOneQt.get());
|
||||
}
|
||||
void MainWindow::configureWindowDimensions()
|
||||
{
|
||||
windowWidth = 600;
|
||||
windowHeight = 600;
|
||||
windowWidth = 400;
|
||||
windowHeight = 400;
|
||||
}
|
||||
void MainWindow::configureWindowProperties()
|
||||
{
|
||||
@@ -30,7 +51,7 @@ namespace UI
|
||||
}
|
||||
void MainWindow::connections()
|
||||
{
|
||||
|
||||
QObject::connect(uploadSongQt.get(), SIGNAL(clicked()), this, SLOT(uploadSong()));
|
||||
}
|
||||
void MainWindow::createMenus()
|
||||
{
|
||||
@@ -41,11 +62,6 @@ namespace UI
|
||||
closeApplicationQt.get()->setText("Exit Application");
|
||||
|
||||
/**
|
||||
keyEdit = unique_ptr<QAction>{new QAction(new QObject(nullptr))};
|
||||
keyEdit.get()->setText("Key Management");
|
||||
passwordManage = unique_ptr<QAction>{new QAction{new QObject{nullptr}}};
|
||||
passwordManage.get()->setText("PasswordManagement");
|
||||
|
||||
fileMenu.get()->addAction(closeApplication.get());
|
||||
editMenu.get()->addAction(keyEdit.get());
|
||||
editMenu.get()->addAction(passwordManage.get());
|
||||
@@ -55,30 +71,40 @@ namespace UI
|
||||
void MainWindow::setupMainWindow()
|
||||
{
|
||||
configureWindowDimensions();
|
||||
actionButtonQt = unique_ptr<QPushButton>{new QPushButton(tr("upload"))};
|
||||
selectionBoxQt = unique_ptr<QComboBox>{new QComboBox{}};
|
||||
mainLayoutQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
||||
|
||||
buttonLayoutQt = unique_ptr<QVBoxLayout>{new QVBoxLayout};
|
||||
buttonWidgetQt = unique_ptr<QWidget>{new QWidget};
|
||||
buttonDockWidgetQt = unique_ptr<QDockWidget>{new QDockWidget};
|
||||
buttonDockWidgetQt.get()->setWindowTitle(tr("Music Manager"));
|
||||
buttonLayoutQt.get()->addWidget(selectionBoxQt.get());
|
||||
buttonLayoutQt.get()->addWidget(actionButtonQt.get());
|
||||
buttonWidgetQt.get()->setLayout(buttonLayoutQt.get());
|
||||
buttonDockWidgetQt.get()->setWidget(buttonWidgetQt.get());
|
||||
buttonDockWidgetQt.get()->setFeatures(QDockWidget::NoDockWidgetFeatures);
|
||||
setCentralWidget(buttonDockWidgetQt.get());
|
||||
configureUploadSection();
|
||||
|
||||
cryptionAreaQt = unique_ptr<QDockWidget>{new QDockWidget(tr("Cryption"))};
|
||||
cryptionAreaQt.get()->setFeatures(QDockWidget::NoDockWidgetFeatures);
|
||||
addDockWidget(Qt::LeftDockWidgetArea, cryptionAreaQt.get());
|
||||
mainWidgetQt = unique_ptr<QWidget>{new QWidget};
|
||||
mainWidgetQt.get()->setLayout(mainLayoutQt.get());
|
||||
|
||||
MainDockWidgetQt = unique_ptr<QDockWidget>{new QDockWidget};
|
||||
MainDockWidgetQt.get()->setWindowTitle(tr("Music Manager"));
|
||||
MainDockWidgetQt.get()->setWidget(mainWidgetQt.get());
|
||||
MainDockWidgetQt.get()->setFeatures(QDockWidget::NoDockWidgetFeatures);
|
||||
setCentralWidget(MainDockWidgetQt.get());
|
||||
|
||||
createMenus();
|
||||
|
||||
|
||||
configureWindowProperties();
|
||||
actionButtonQt.get()->setEnabled(false);
|
||||
|
||||
connections();
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-4
@@ -11,6 +11,7 @@
|
||||
#include<QMenu>
|
||||
#include<QMenuBar>
|
||||
#include<QMainWindow>
|
||||
#include<QPushButton>
|
||||
#include<QTextEdit>
|
||||
#include<QWidget>
|
||||
|
||||
@@ -33,13 +34,14 @@ namespace UI
|
||||
void createMenus();
|
||||
void setupMainWindow();
|
||||
|
||||
std::unique_ptr<QVBoxLayout> buttonLayoutQt;
|
||||
|
||||
std::unique_ptr<QWidget> buttonWidgetQt;
|
||||
std::unique_ptr<QWidget> mainWidgetQt;
|
||||
|
||||
std::unique_ptr<QDockWidget> buttonDockWidgetQt;
|
||||
std::unique_ptr<QDockWidget> cryptionAreaQt;
|
||||
std::unique_ptr<QDockWidget> MainDockWidgetQt;
|
||||
|
||||
std::unique_ptr<QPushButton> uploadSongQt;
|
||||
|
||||
std::unique_ptr<QTextEdit> urlQt;
|
||||
std::unique_ptr<QTextEdit> sourceFilePathQt;
|
||||
|
||||
std::unique_ptr<QMenu> fileMenuQt;
|
||||
@@ -47,6 +49,7 @@ namespace UI
|
||||
std::unique_ptr<QAction> closeApplicationQt;
|
||||
signals:
|
||||
private slots:
|
||||
void uploadSong();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user