From e88412e904d98487e90b54a7956db9a91ea44afd Mon Sep 17 00:00:00 2001 From: Jacek Jendrzej Date: Wed, 19 Mar 2014 18:32:34 +0100 Subject: [PATCH] CPictureViewer:: move download code to separate funktion DownloadImage Origin commit data ------------------ Commit: https://github.com/neutrino-images/ni-neutrino/commit/80d7cc186d2ff88543f6b094282315191730d0d9 Author: Jacek Jendrzej Date: 2014-03-19 (Wed, 19 Mar 2014) --- src/driver/pictureviewer/pictureviewer.cpp | 45 ++++++++++++---------- src/driver/pictureviewer/pictureviewer.h | 1 + 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/driver/pictureviewer/pictureviewer.cpp b/src/driver/pictureviewer/pictureviewer.cpp index 439518cf7..809523849 100644 --- a/src/driver/pictureviewer/pictureviewer.cpp +++ b/src/driver/pictureviewer/pictureviewer.cpp @@ -102,6 +102,29 @@ CPictureViewer::CFormathandler * CPictureViewer::fh_getsize (const char *name, i } return (NULL); } +std::string CPictureViewer::DownloadImage(std::string url) +{ + if (strstr(url.c_str(), "://")) { + std::string tmpname = "/tmp/pictureviewer" + url.substr(url.find_last_of(".")); + FILE *tmpFile = fopen(tmpname.c_str(), "wb"); + if (tmpFile) { + CURL *ch = curl_easy_init(); + curl_easy_setopt(ch, CURLOPT_VERBOSE, 0L); + curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 1L); + curl_easy_setopt(ch, CURLOPT_NOSIGNAL, 1L); + curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, NULL); + curl_easy_setopt(ch, CURLOPT_WRITEDATA, tmpFile); + curl_easy_setopt(ch, CURLOPT_FAILONERROR, 1L); + curl_easy_setopt(ch, CURLOPT_URL, url.c_str()); + curl_easy_perform(ch); + curl_easy_cleanup(ch); + fclose(tmpFile); + url = true; + } + url = tmpname; + } + return url; +} bool CPictureViewer::DecodeImage (const std::string & _name, bool showBusySign, bool unscaled) { @@ -121,29 +144,9 @@ bool CPictureViewer::DecodeImage (const std::string & _name, bool showBusySign, if (showBusySign) showBusy (m_startx + 3, m_starty + 3, 10, 0xff, 00, 00); - std::string name = _name; bool url = false; - if (strstr(name.c_str(), "://")) { - std::string tmpname; - tmpname = "/tmp/pictureviewer" + name.substr(name.find_last_of(".")); - FILE *tmpFile = fopen(tmpname.c_str(), "wb"); - if (tmpFile) { - CURL *ch = curl_easy_init(); - curl_easy_setopt(ch, CURLOPT_VERBOSE, 0L); - curl_easy_setopt(ch, CURLOPT_NOPROGRESS, 1L); - curl_easy_setopt(ch, CURLOPT_NOSIGNAL, 1L); - curl_easy_setopt(ch, CURLOPT_WRITEFUNCTION, NULL); - curl_easy_setopt(ch, CURLOPT_WRITEDATA, tmpFile); - curl_easy_setopt(ch, CURLOPT_FAILONERROR, 1L); - curl_easy_setopt(ch, CURLOPT_URL, name.c_str()); - curl_easy_perform(ch); - curl_easy_cleanup(ch); - fclose(tmpFile); - url = true; - } - name = tmpname; - } + std::string name = DownloadImage(_name); CFormathandler *fh; if (unscaled) diff --git a/src/driver/pictureviewer/pictureviewer.h b/src/driver/pictureviewer/pictureviewer.h index 71d8d256f..4326c45d4 100644 --- a/src/driver/pictureviewer/pictureviewer.h +++ b/src/driver/pictureviewer/pictureviewer.h @@ -54,6 +54,7 @@ class CPictureViewer bool ShowImage(const std::string & filename, bool unscaled=false); bool DecodeImage(const std::string & name, bool showBusySign=false, bool unscaled=false); bool DisplayNextImage(); + std::string DownloadImage(std::string url); void SetScaling(ScalingMode s){m_scaling=s;} void SetAspectRatio(float aspect_ratio) {m_aspect=aspect_ratio;} void showBusy(int sx, int sy, int width, char r, char g, char b);