r13323 - in software/ui: debian src
Petter Reinholdtsen
pere at alioth.debian.org
Mon Feb 27 10:19:42 UTC 2012
Author: pere
Date: 2012-02-27 10:19:42 +0000 (Mon, 27 Feb 2012)
New Revision: 13323
Added:
software/ui/src/URLFetcher.cpp
software/ui/src/URLFetcher.h
Modified:
software/ui/debian/changelog
software/ui/debian/control
software/ui/src/Makefile.am
software/ui/src/pkgbrowser.cpp
software/ui/src/pkgbrowser.h
Log:
Add code to download screen shots from screenshot.debian.net
(Closes: #659846). Add build dependency on libcurl4-gnutls-dev
to get HTTP download support.
Modified: software/ui/debian/changelog
===================================================================
--- software/ui/debian/changelog 2012-02-27 05:47:08 UTC (rev 13322)
+++ software/ui/debian/changelog 2012-02-27 10:19:42 UTC (rev 13323)
@@ -1,3 +1,11 @@
+goplay (0.5-2) UNRELEASED; urgency=low
+
+ * Add code to download screen shots from screenshot.debian.net
+ (Closes: #659846). Add build dependency on libcurl4-gnutls-dev
+ to get HTTP download support.
+
+ -- Petter Reinholdtsen <pere at debian.org> Mon, 27 Feb 2012 10:55:24 +0100
+
goplay (0.5-1) unstable; urgency=low
* Acknowledge NMU (Closes: #659534).
Modified: software/ui/debian/control
===================================================================
--- software/ui/debian/control 2012-02-27 05:47:08 UTC (rev 13322)
+++ software/ui/debian/control 2012-02-27 10:19:42 UTC (rev 13323)
@@ -10,6 +10,7 @@
Build-Depends: debhelper (>= 8), pkg-config,
libept-dev, libwibble-dev, libfltk1.1-dev, libtagcoll2-dev
,imagemagick
+ ,libcurl4-gnutls-dev
#, fluid
Vcs-Browser: http://anonscm.debian.org/viewvc/pkg-games/software/ui/
Vcs-Svn: svn://svn.debian.org/pkg-games/software/ui/
Modified: software/ui/src/Makefile.am
===================================================================
--- software/ui/src/Makefile.am 2012-02-27 05:47:08 UTC (rev 13322)
+++ software/ui/src/Makefile.am 2012-02-27 10:19:42 UTC (rev 13323)
@@ -14,6 +14,7 @@
common.h \
Engine.h \
Environment.h \
+ URLFetcher.h \
filter.h \
GamesOptions.h \
pkgbrowser.h \
@@ -23,6 +24,7 @@
goplay_SOURCES = \
Environment.cpp \
Engine.cpp \
+ URLFetcher.cpp \
ui.cpp \
pkgbrowser.cpp \
filter.cpp \
@@ -31,7 +33,8 @@
aux.cpp \
goplay.cpp
goplay_LDFLAGS = \
- `fltk-config --ldflags --use-images`
+ `fltk-config --ldflags --use-images` \
+ `curl-config --libs`
goplay_LDADD = \
../libxdgutils/libxdgutils.a \
$(LIBEPT_LIBS)
@@ -42,7 +45,7 @@
ui.h ui.cpp: ui.fld
fluid -c -o ui.cpp -h ui.h ui.fld
-INCLUDES = -I.. $(LIBEPT_CFLAGS) `fltk-config --cxxflags --use-images` -Wall -Werror -ggdb
+INCLUDES = -I.. $(LIBEPT_CFLAGS) `fltk-config --cxxflags --use-images` `curl-config --cflags` -Wall -Werror -ggdb
EXTRA_DIST = GamesOptions.h Environment.h Engine.h ui.fld ui.h ui.cpp pkgbrowser.h LICENSE \
Makefile.test CuTest.h CuTest.c CuTest.sh CuTest.txt \
Added: software/ui/src/URLFetcher.cpp
===================================================================
--- software/ui/src/URLFetcher.cpp (rev 0)
+++ software/ui/src/URLFetcher.cpp 2012-02-27 10:19:42 UTC (rev 13323)
@@ -0,0 +1,58 @@
+#include "URLFetcher.h"
+#include <string.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <iostream>
+#include <stdexcept>
+
+char *URLFetcher::tmpdir(NULL);
+
+URLFetcher::URLFetcher()
+ : curlref(NULL)
+{
+ curlref = curl_easy_init();
+ assert(curlref);
+ if (!tmpdir)
+ {
+ tmpdir = mkdtemp(strdup("/tmp/goplay.thumb.XXXXXX"));
+ assert(tmpdir);
+ }
+}
+
+const std::string URLFetcher::get(const std::string url,
+ const std::string basename)
+{
+ if (curlref)
+ {
+ curl_easy_setopt(curlref, CURLOPT_URL, url.c_str());
+ std::string path(tmpdir);
+ path += "/" + basename;
+ FILE *output = fopen(path.c_str(), "w");
+ curl_easy_setopt(curlref, CURLOPT_WRITEDATA, output);
+ CURLcode res = curl_easy_perform(curlref);
+ fflush(output);
+ fclose(output);
+ if (0 != res)
+ {
+ throw std::runtime_error(std::string("failed to fetch screen shot"));
+ }
+ return path;
+ }
+ throw std::runtime_error("unable to fetch screen shot");
+}
+
+URLFetcher::~URLFetcher()
+{
+ curl_easy_cleanup(curlref);
+}
+
+#ifdef TEST
+int main(int argc, char *argv[])
+{
+ URLFetcher fetcher;
+ const std::string path =
+ fetcher.get(std::string("http://www.debian.org"),
+ std::string("index.html"));
+ std::cout << path;
+}
+#endif
Added: software/ui/src/URLFetcher.h
===================================================================
--- software/ui/src/URLFetcher.h (rev 0)
+++ software/ui/src/URLFetcher.h 2012-02-27 10:19:42 UTC (rev 13323)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2012 Petter Reinholdtsen <pere at hungry.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _games_urlfetcher_h
+#define _games_urlfetcher_h
+
+#include <curl/curl.h>
+#include <string>
+
+class URLFetcher
+{
+ public:
+ URLFetcher();
+ ~URLFetcher();
+ const std::string get(const std::string url,
+ const std::string basename);
+ private:
+ CURL *curlref;
+ static char *tmpdir;
+};
+
+#endif
Modified: software/ui/src/pkgbrowser.cpp
===================================================================
--- software/ui/src/pkgbrowser.cpp 2012-02-27 05:47:08 UTC (rev 13322)
+++ software/ui/src/pkgbrowser.cpp 2012-02-27 10:19:42 UTC (rev 13323)
@@ -40,6 +40,7 @@
#include "Environment.h"
#include "GamesOptions.h"
#include "Engine.h"
+#include "URLFetcher.h"
#include "filter.h"
@@ -147,6 +148,20 @@
}
}
+Fl_Image *PackageBrowser::fetch_screenshot(std::string packagename)
+{
+ URLFetcher fetcher;
+ std::string url("http://screenshots.debian.net/thumbnail/");
+ // TODO: Scale image to fit frame
+ url += packagename;
+ cout << "fetching " << url << endl;
+ std::string imgname = fetcher.get(url, packagename);
+ cout << "Loading image " << imgname << endl;
+ Fl_Image *img = new Fl_PNG_Image(imgname.c_str());
+ unlink(imgname.c_str());
+ return img;
+}
+
void PackageBrowser::item_select(void *p, int s)
{
VersatileBrowser::item_select(p, s);
@@ -191,7 +206,8 @@
}
else
{ // TODO: Portable Anymap (PNM, PBM, PGM, PPM) image files
- img = NULL;
+ const char *packagename = (const char *)data;
+ img = fetch_screenshot(packagename);
}
if (img && !img->count())
{
Modified: software/ui/src/pkgbrowser.h
===================================================================
--- software/ui/src/pkgbrowser.h 2012-02-27 05:47:08 UTC (rev 13322)
+++ software/ui/src/pkgbrowser.h 2012-02-27 10:19:42 UTC (rev 13323)
@@ -216,6 +216,7 @@
const unsigned int num_bar_images;
Fl_Image *bar_images[2*2];
std::string pkgname;
+ Fl_Image *fetch_screenshot(std::string packagename);
};
class PackageView : public Fl_Help_View
More information about the Pkg-games-commits
mailing list