add share button and implement AirDrop share in OSX, update info.plist to set on Mac OS the default app for PPI, on iOS include the Documents/Inbox subfolder used to store the received files from AirDrop
This commit is contained in:
@@ -208,15 +208,13 @@ int progress_callback_upload(void *clientp, curl_off_t dltotal,
|
||||
return 0;
|
||||
}
|
||||
|
||||
void App::download(std::string filename, std::function<void(float)> progress)
|
||||
void App::download(std::string url, std::string dest_filepath, std::function<void(float)> progress)
|
||||
{
|
||||
CURL *curl = curl_easy_init();
|
||||
if (curl)
|
||||
{
|
||||
auto dest = data_path + "/" + filename;
|
||||
FILE* fp = fopen(dest.c_str(), "wb");
|
||||
std::string url = "https://panopainter.com/cloud/cloud-dwl.php?file=" + filename;
|
||||
LOG("download %s to %s", url.c_str(), dest.c_str());
|
||||
FILE* fp = fopen(dest_filepath.c_str(), "wb");
|
||||
LOG("download %s to %s", url.c_str(), dest_filepath.c_str());
|
||||
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);
|
||||
|
||||
@@ -100,6 +100,7 @@ public:
|
||||
void pick_file(std::vector<std::string> types, std::function<void(std::string path)> callback);
|
||||
void pick_dir(std::function<void(std::string path)> callback);
|
||||
void display_file(std::string path);
|
||||
void share_file(std::string path);
|
||||
void showKeyboard();
|
||||
void hideKeyboard();
|
||||
void initLog();
|
||||
@@ -164,7 +165,7 @@ public:
|
||||
void cloud_upload_all();
|
||||
void cloud_browse();
|
||||
void upload(std::string filename, std::string name = "", std::function<void(float)> progress = nullptr);
|
||||
void download(std::string filename, std::function<void(float)> progress = nullptr);
|
||||
void download(std::string url, std::string dest_filepath, std::function<void(float)> progress = nullptr);
|
||||
bool check_license();
|
||||
|
||||
std::shared_ptr<NodeProgressBar> show_progress(const std::string& title);
|
||||
|
||||
@@ -146,7 +146,8 @@ void App::cloud_browse()
|
||||
m->m_message->set_text("Download in progress");
|
||||
async_redraw();
|
||||
async_end();
|
||||
download(dialog->selected_path, [this,m](float p){
|
||||
std::string url = "https://panopainter.com/cloud/cloud-dwl.php?file=" + dialog->selected_file;
|
||||
download(url, dialog->selected_path, [this,m](float p){
|
||||
static char progress[256];
|
||||
sprintf(progress, "Download in progress %.2f%%", p * 100.f);
|
||||
async_start();
|
||||
|
||||
@@ -253,7 +253,11 @@ void App::dialog_browse()
|
||||
// load thumbnail test
|
||||
auto dialog = std::make_shared<NodeDialogBrowse>();
|
||||
dialog->m_manager = &layout;
|
||||
dialog->search_path = work_path;
|
||||
#ifdef __IOS__
|
||||
dialog->search_paths = {work_path, data_path + "/Inbox"};
|
||||
#else
|
||||
dialog->search_paths = {work_path};
|
||||
#endif
|
||||
dialog->init();
|
||||
dialog->create();
|
||||
dialog->loaded();
|
||||
|
||||
@@ -151,6 +151,21 @@ void App::display_file(std::string path)
|
||||
#endif
|
||||
}
|
||||
|
||||
void App::share_file(std::string path)
|
||||
{
|
||||
if (path.empty())
|
||||
return;
|
||||
#ifdef __IOS__
|
||||
#elif __OSX__
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[osx_view share_file:[NSString stringWithUTF8String:path.c_str()]];
|
||||
});
|
||||
#elif __ANDROID__
|
||||
#elif _WIN32
|
||||
// not implemented
|
||||
#endif
|
||||
}
|
||||
|
||||
bool App::mouse_down(int button, float x, float y, float pressure, kEventSource source, bool eraser)
|
||||
{
|
||||
redraw = true;
|
||||
|
||||
@@ -420,6 +420,12 @@ void App::init_menu_file()
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
};
|
||||
if (auto b = popup->find<NodeButtonCustom>("file-share"))
|
||||
b->on_click = [this](Node*) {
|
||||
share_file(doc_path);
|
||||
popup->mouse_release();
|
||||
popup->destroy();
|
||||
};
|
||||
if (auto b = popup->find<NodeButtonCustom>("file-resize"))
|
||||
b->on_click = [this](Node*) {
|
||||
dialog_resize();
|
||||
|
||||
@@ -88,7 +88,7 @@ void NodeDialogBrowse::init_controls()
|
||||
realpath(path.c_str(), path_buffer);
|
||||
#endif
|
||||
working_path->set_text_format("Destination dir: %s", path_buffer);
|
||||
search_path = path;
|
||||
search_paths = {path};
|
||||
clear_list();
|
||||
init_list();
|
||||
async_update();
|
||||
@@ -122,19 +122,29 @@ void NodeDialogBrowse::clear_list()
|
||||
|
||||
void NodeDialogBrowse::init_list()
|
||||
{
|
||||
auto names = Asset::list_files(search_path, false, ".*\\.ppi");
|
||||
for (const auto& n : names)
|
||||
std::vector<std::tuple<std::string/*file-name*/, std::string/*path*/>> files;
|
||||
for (auto sp : search_paths)
|
||||
{
|
||||
ui::Image thumb = ui::Canvas::I->thumbnail_read(search_path + "/" + n);
|
||||
auto items = Asset::list_files(sp, false, ".*\\.ppi");
|
||||
for (const auto& i : items)
|
||||
{
|
||||
files.push_back({i, sp + '/' + i});
|
||||
}
|
||||
}
|
||||
for (const auto& f : files)
|
||||
{
|
||||
auto f_name = std::get<0>(f);
|
||||
auto f_path = std::get<1>(f);
|
||||
ui::Image thumb = ui::Canvas::I->thumbnail_read(f_path);
|
||||
if (thumb.width == 0 || thumb.height == 0)
|
||||
continue;
|
||||
|
||||
auto node = new NodeDialogBrowseItem;
|
||||
node->m_manager = m_manager;
|
||||
node->init();
|
||||
node->m_text->set_text(n.c_str());
|
||||
node->m_path = search_path + "/" + n;
|
||||
node->m_file_name = n;
|
||||
node->m_text->set_text(f_name.c_str());
|
||||
node->m_path = f_path;
|
||||
node->m_file_name = f_name;
|
||||
node->on_selected = [&](NodeDialogBrowseItem* target) {
|
||||
if (target == current)
|
||||
return;
|
||||
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
std::string selected_path;
|
||||
std::string selected_file;
|
||||
std::string selected_name;
|
||||
std::string search_path;
|
||||
std::vector<std::string> search_paths;
|
||||
virtual Node* clone_instantiate() const override;
|
||||
virtual void clone_finalize(Node* dest) const override;
|
||||
virtual void init() override;
|
||||
|
||||
Reference in New Issue
Block a user