upload progresso bar
This commit is contained in:
@@ -63,7 +63,7 @@ void App::initLog()
|
|||||||
LogRemote::I.file_init();
|
LogRemote::I.file_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
int progress_callback(void *clientp, curl_off_t dltotal,
|
int progress_callback_download(void *clientp, curl_off_t dltotal,
|
||||||
curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
|
curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
|
||||||
{
|
{
|
||||||
std::function<void(float)> progress = *(std::function<void(float)>*)clientp;
|
std::function<void(float)> progress = *(std::function<void(float)>*)clientp;
|
||||||
@@ -71,6 +71,14 @@ int progress_callback(void *clientp, curl_off_t dltotal,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int progress_callback_upload(void *clientp, curl_off_t dltotal,
|
||||||
|
curl_off_t dlnow, curl_off_t ultotal, curl_off_t ulnow)
|
||||||
|
{
|
||||||
|
std::function<void(float)> progress = *(std::function<void(float)>*)clientp;
|
||||||
|
progress((float)ulnow / (float)ultotal);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void App::download(std::string filename, std::function<void(float)> progress)
|
void App::download(std::string filename, std::function<void(float)> progress)
|
||||||
{
|
{
|
||||||
CURL *curl = curl_easy_init();
|
CURL *curl = curl_easy_init();
|
||||||
@@ -82,16 +90,19 @@ void App::download(std::string filename, std::function<void(float)> progress)
|
|||||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_data_write);
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_data_write);
|
||||||
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback);
|
if (progress)
|
||||||
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &progress);
|
{
|
||||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
|
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback_download);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &progress);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
|
||||||
|
}
|
||||||
auto err = curl_easy_perform(curl);
|
auto err = curl_easy_perform(curl);
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void App::upload(std::string filename, std::string name)
|
void App::upload(std::string filename, std::string name, std::function<void(float)> progress)
|
||||||
{
|
{
|
||||||
CURL *curl;
|
CURL *curl;
|
||||||
|
|
||||||
@@ -116,6 +127,12 @@ void App::upload(std::string filename, std::string name)
|
|||||||
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
|
curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &res);
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &res);
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_data_handler);
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_data_handler);
|
||||||
|
if (progress)
|
||||||
|
{
|
||||||
|
curl_easy_setopt(curl, CURLOPT_XFERINFOFUNCTION, progress_callback_upload);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_XFERINFODATA, &progress);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0);
|
||||||
|
}
|
||||||
auto err = curl_easy_perform(curl);
|
auto err = curl_easy_perform(curl);
|
||||||
std::cout << "\n\nUPLOAD RESULT\n" << res << "\n\n\n";
|
std::cout << "\n\nUPLOAD RESULT\n" << res << "\n\n\n";
|
||||||
curl_easy_cleanup(curl);
|
curl_easy_cleanup(curl);
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
#include "node_scroll.h"
|
#include "node_scroll.h"
|
||||||
#include "node_canvas.h"
|
#include "node_canvas.h"
|
||||||
#include "node_dialog_layer_rename.h"
|
#include "node_dialog_layer_rename.h"
|
||||||
|
#include "node_progress_bar.h"
|
||||||
|
|
||||||
#if defined(__OBJC__) && defined(__IOS__)
|
#if defined(__OBJC__) && defined(__IOS__)
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
@@ -129,8 +130,10 @@ public:
|
|||||||
void cloud_upload();
|
void cloud_upload();
|
||||||
void cloud_upload_all();
|
void cloud_upload_all();
|
||||||
void cloud_browse();
|
void cloud_browse();
|
||||||
void upload(std::string filename, std::string name = "");
|
void upload(std::string filename, std::string name = "", std::function<void(float)> progress = nullptr);
|
||||||
void download(std::string filename, std::function<void(float)> progress);
|
void download(std::string filename, std::function<void(float)> progress = nullptr);
|
||||||
|
|
||||||
|
std::shared_ptr<NodeProgressBar> show_progress(const std::string& title);
|
||||||
|
|
||||||
void brush_update();
|
void brush_update();
|
||||||
void title_update(std::string name, int resolution);
|
void title_update(std::string name, int resolution);
|
||||||
|
|||||||
@@ -25,8 +25,21 @@ void App::cloud_upload()
|
|||||||
std::thread([this] {
|
std::thread([this] {
|
||||||
std::string path = data_path + "/" + doc_name + ".pano";
|
std::string path = data_path + "/" + doc_name + ".pano";
|
||||||
Canvas::I->project_save_thread(path);
|
Canvas::I->project_save_thread(path);
|
||||||
upload(path);
|
|
||||||
async_start();
|
async_start();
|
||||||
|
auto pb = show_progress("Uploading");
|
||||||
|
async_redraw();
|
||||||
|
async_end();
|
||||||
|
|
||||||
|
upload(path, doc_name, [this,pb](float p){
|
||||||
|
async_start();
|
||||||
|
pb->m_progress->SetWidthP(p * 100.f);
|
||||||
|
async_redraw();
|
||||||
|
async_end();
|
||||||
|
});
|
||||||
|
|
||||||
|
async_start();
|
||||||
|
pb->destroy();
|
||||||
auto msgbox = new NodeMessageBox();
|
auto msgbox = new NodeMessageBox();
|
||||||
msgbox->m_manager = &layout;
|
msgbox->m_manager = &layout;
|
||||||
msgbox->init();
|
msgbox->init();
|
||||||
@@ -34,6 +47,7 @@ void App::cloud_upload()
|
|||||||
msgbox->m_message->set_text("This document has been succesfully uploaded.");
|
msgbox->m_message->set_text("This document has been succesfully uploaded.");
|
||||||
layout[main_id]->add_child(msgbox);
|
layout[main_id]->add_child(msgbox);
|
||||||
layout[main_id]->update();
|
layout[main_id]->update();
|
||||||
|
async_redraw();
|
||||||
async_end();
|
async_end();
|
||||||
}).detach();
|
}).detach();
|
||||||
}
|
}
|
||||||
@@ -41,24 +55,17 @@ void App::cloud_upload()
|
|||||||
|
|
||||||
void App::cloud_upload_all()
|
void App::cloud_upload_all()
|
||||||
{
|
{
|
||||||
std::thread([] {
|
std::thread([this] {
|
||||||
auto names = Asset::list_files(App::I.data_path, false, ".*\\.pano");
|
auto names = Asset::list_files(data_path, false, ".*\\.pano");
|
||||||
|
|
||||||
gl_state gl;
|
gl_state gl;
|
||||||
std::shared_ptr<NodeProgressBar> pb;
|
std::shared_ptr<NodeProgressBar> pb;
|
||||||
if (App::I.layout.m_loaded)
|
if (layout.m_loaded)
|
||||||
{
|
{
|
||||||
App::I.async_start();
|
async_start();
|
||||||
pb = std::make_shared<NodeProgressBar>();
|
pb = show_progress("Export Pano Image");
|
||||||
pb->m_manager = &App::I.layout;
|
async_redraw();
|
||||||
pb->init();
|
async_end();
|
||||||
pb->create();
|
|
||||||
pb->loaded();
|
|
||||||
pb->m_progress->SetWidthP(0);
|
|
||||||
pb->m_title->set_text("Export Pano Image");
|
|
||||||
App::I.layout[App::I.main_id]->add_child(pb);
|
|
||||||
App::I.async_update();
|
|
||||||
App::I.async_end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int progress = 0;
|
int progress = 0;
|
||||||
@@ -66,30 +73,30 @@ void App::cloud_upload_all()
|
|||||||
|
|
||||||
for (const auto& n : names)
|
for (const auto& n : names)
|
||||||
{
|
{
|
||||||
std::string path = App::I.data_path + "/" + n;
|
std::string path = data_path + "/" + n;
|
||||||
App::I.upload(path);
|
upload(path);
|
||||||
|
|
||||||
progress++;
|
progress++;
|
||||||
float p = (float)progress / total * 100.f;
|
float p = (float)progress / total * 100.f;
|
||||||
LOG("progress: %f", p);
|
LOG("progress: %f", p);
|
||||||
|
|
||||||
if (App::I.layout.m_loaded)
|
if (layout.m_loaded)
|
||||||
{
|
{
|
||||||
App::I.async_start();
|
async_start();
|
||||||
pb->m_progress->SetWidthP(p);
|
pb->m_progress->SetWidthP(p);
|
||||||
gl.save();
|
gl.save();
|
||||||
App::I.async_update();
|
async_redraw();
|
||||||
gl.restore();
|
gl.restore();
|
||||||
App::I.async_end();
|
async_end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (App::I.layout.m_loaded)
|
if (layout.m_loaded)
|
||||||
{
|
{
|
||||||
App::I.async_start();
|
async_start();
|
||||||
pb->destroy();
|
pb->destroy();
|
||||||
App::I.async_update();
|
async_redraw();
|
||||||
App::I.async_end();
|
async_end();
|
||||||
}
|
}
|
||||||
}).detach();
|
}).detach();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,19 @@
|
|||||||
#include "node_dialog_browse.h"
|
#include "node_dialog_browse.h"
|
||||||
#include "node_dialog_cloud.h"
|
#include "node_dialog_cloud.h"
|
||||||
|
|
||||||
|
std::shared_ptr<NodeProgressBar> App::show_progress(const std::string& title)
|
||||||
|
{
|
||||||
|
auto pb = std::make_shared<NodeProgressBar>();
|
||||||
|
pb->m_manager = &layout;
|
||||||
|
pb->init();
|
||||||
|
pb->create();
|
||||||
|
pb->loaded();
|
||||||
|
pb->m_progress->SetWidthP(0);
|
||||||
|
pb->m_title->set_text(title.c_str());
|
||||||
|
layout[main_id]->add_child(pb);
|
||||||
|
return pb;
|
||||||
|
}
|
||||||
|
|
||||||
void App::dialog_newdoc()
|
void App::dialog_newdoc()
|
||||||
{
|
{
|
||||||
if (canvas)
|
if (canvas)
|
||||||
|
|||||||
Reference in New Issue
Block a user