CPictureViewer:: move download code to separate funktion DownloadImage

Origin commit data
------------------
Commit: 80d7cc186d
Author: Jacek Jendrzej <overx300@gmail.com>
Date: 2014-03-19 (Wed, 19 Mar 2014)
This commit is contained in:
Jacek Jendrzej
2014-03-19 18:32:34 +01:00
parent a27f7c3dfb
commit e88412e904
2 changed files with 25 additions and 21 deletions

View File

@@ -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)

View File

@@ -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);