implement download and open from the cloud browser

This commit is contained in:
2017-11-06 10:07:19 +00:00
parent 05c5bd1bdb
commit fc402d584a
7 changed files with 54 additions and 27 deletions

View File

@@ -63,6 +63,23 @@ void App::initLog()
LogRemote::I.file_init(); LogRemote::I.file_init();
} }
void App::download(std::string filename)
{
CURL *curl = curl_easy_init();
if (curl)
{
auto dest = data_path + "/" + filename;
FILE* fp = fopen(dest.c_str(), "wb");
std::string url = "http://omigamedev.ddns.net:8080/panoview/cloud-dwl.php?file=" + filename;
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_data_write);
auto err = curl_easy_perform(curl);
curl_easy_cleanup(curl);
fclose(fp);
}
}
void App::upload(std::string filename) void App::upload(std::string filename)
{ {
CURL *curl; CURL *curl;

View File

@@ -92,7 +92,6 @@ public:
void initShaders(); void initShaders();
void initAssets(); void initAssets();
void initLayout(); void initLayout();
void upload(std::string filename);
void create(); void create();
void terminate(); void terminate();
void clear(); void clear();
@@ -129,6 +128,8 @@ public:
void cloud_upload_all(); void cloud_upload_all();
void cloud_browse(); void cloud_browse();
void upload(std::string filename);
void download(std::string filename);
void brush_update(); void brush_update();

View File

@@ -79,15 +79,21 @@ void App::cloud_browse()
dialog->btn_ok->on_click = [this, dialog](Node*) dialog->btn_ok->on_click = [this, dialog](Node*)
{ {
// canvas->reset_camera(); std::thread([this, dialog] {
// layers->clear(); download(dialog->selected_file);
// canvas->m_canvas->project_open(dialog->selected_path); async_start();
// doc_name = dialog->selected_name; canvas->reset_camera();
// if (auto docname = layout[main_id]->find<NodeText>("txt-docname")) layers->clear();
// docname->set_text(("Panodoc: " + doc_name).c_str()); canvas->m_canvas->project_open(dialog->selected_path);
// for (auto& i : canvas->m_canvas->m_order) doc_name = dialog->selected_name;
// layers->add_layer(canvas->m_canvas->m_layers[i].m_name.c_str()); if (auto docname = layout[main_id]->find<NodeText>("txt-docname"))
dialog->destroy(); docname->set_text(("Panodoc: " + doc_name).c_str());
ActionManager::clear(); for (auto& i : canvas->m_canvas->m_order)
layers->add_layer(canvas->m_canvas->m_layers[i].m_name.c_str());
dialog->destroy();
ActionManager::clear();
async_update();
async_end();
}).detach();
}; };
} }

View File

@@ -397,7 +397,7 @@ void App::init_menu_file()
std::smatch m; std::smatch m;
if (std::regex_search(doc_name, m, r)) if (std::regex_search(doc_name, m, r))
{ {
std::string base = m[1].str(); base = m[1].str();
current = atoi(m[2].str().c_str()); current = atoi(m[2].str().c_str());
} }

View File

@@ -89,7 +89,6 @@ void NodeDialogCloud::load_thumbs_thread()
thumb.create(width, height); thumb.create(width, height);
thumb.copy_from((uint8_t*)rgb.data()); thumb.copy_from((uint8_t*)rgb.data());
App::I.async_start(); App::I.async_start();
auto node = new NodeDialogCloudItem; auto node = new NodeDialogCloudItem;
node->m_manager = m_manager; node->m_manager = m_manager;
@@ -104,20 +103,16 @@ void NodeDialogCloud::load_thumbs_thread()
App::I.async_update(); App::I.async_update();
App::I.async_end(); App::I.async_end();
// node->on_selected = [&](NodeDialogCloudItem* target) { node->on_selected = [&](NodeDialogCloudItem* target) {
// if (target == current) if (target == current)
// return; return;
// selected_path = target->m_path; selected_path = target->m_path;
// selected_file = target->m_file_name; selected_file = target->m_file_name;
// selected_name = selected_file.substr(0, selected_file.length() - 5); selected_name = selected_file.substr(0, selected_file.length() - 5);
// if (current) if (current)
// current->m_selected = false; current->m_selected = false;
// current = target; current = target;
// }; };
// load thumb
// ui::Image thumb = ui::Canvas::I->thumbnail_read(node->m_path);
} }
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
} }

View File

@@ -132,6 +132,13 @@ size_t curl_data_handler(void *contents, size_t size, size_t nmemb, void *userp)
return size * nmemb; return size * nmemb;
} }
size_t curl_data_write(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
size_t written = fwrite(ptr, size, nmemb, stream);
return written;
}
#ifdef _DEBUG #ifdef _DEBUG
#define GL(stmt) stmt; CheckOpenGLError(#stmt, __FILE__, __LINE__); #define GL(stmt) stmt; CheckOpenGLError(#stmt, __FILE__, __LINE__);
#else #else

View File

@@ -17,6 +17,7 @@ glm::vec3 convert_hsv2rgb(const glm::vec3 c);
glm::vec3 convert_rgb2hsv(const glm::vec3 c); glm::vec3 convert_rgb2hsv(const glm::vec3 c);
size_t curl_data_handler(void *contents, size_t size, size_t nmemb, void *userp); size_t curl_data_handler(void *contents, size_t size, size_t nmemb, void *userp);
size_t curl_data_write(void *ptr, size_t size, size_t nmemb, FILE *stream);
void check_OpenGLError(const char* stmt, const char* fname, int line); void check_OpenGLError(const char* stmt, const char* fname, int line);
template<typename T, int N> struct cbuffer template<typename T, int N> struct cbuffer