r13325 - in software/ui: debian src
Petter Reinholdtsen
pere at alioth.debian.org
Mon Feb 27 19:21:58 UTC 2012
Author: pere
Date: 2012-02-27 19:21:58 +0000 (Mon, 27 Feb 2012)
New Revision: 13325
Modified:
software/ui/debian/changelog
software/ui/src/pkgbrowser.cpp
software/ui/src/pkgbrowser.h
Log:
Restructure code, move code to find screen shots to its own
function.
Modified: software/ui/debian/changelog
===================================================================
--- software/ui/debian/changelog 2012-02-27 10:41:33 UTC (rev 13324)
+++ software/ui/debian/changelog 2012-02-27 19:21:58 UTC (rev 13325)
@@ -3,6 +3,8 @@
* Add code to download screen shots from screenshot.debian.net
(Closes: #659846). Add build dependency on libcurl4-gnutls-dev
to get HTTP download support.
+ * Restructure code, move code to find screen shots to its own
+ function.
-- Petter Reinholdtsen <pere at debian.org> Mon, 27 Feb 2012 10:55:24 +0100
Modified: software/ui/src/pkgbrowser.cpp
===================================================================
--- software/ui/src/pkgbrowser.cpp 2012-02-27 10:41:33 UTC (rev 13324)
+++ software/ui/src/pkgbrowser.cpp 2012-02-27 19:21:58 UTC (rev 13325)
@@ -148,21 +148,77 @@
}
}
-Fl_Image *PackageBrowser::fetch_screenshot(std::string packagename)
+static bool fileexist(const std::string path)
{
- URLFetcher fetcher;
- std::string url("http://screenshots.debian.net/screenshot/");
- 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());
- Fl_Image *resizedimg = img->copy(320, 240);
- delete(img);
- return resizedimg;
+ struct stat fileinfo;
+ if (stat(path.c_str(), &fileinfo) == 0)
+ {
+ return true;
+ }
+ return false;
}
+Fl_Image *PackageBrowser::find_screenshot(const std::string packagename)
+{
+ Fl_Image *img = NULL;
+ string filename;
+ if (fileexist(filename = std::string(THUMBNAILSDIR) + "/" +
+ packagename + ".png"))
+ { // Portable Network Graphics (PNG) image files
+ // We were able to get the file attributes so the file obviously exists.
+ img = new Fl_PNG_Image(filename.c_str());
+ //printf(" PNG Screenshot : \"%s\"\n", filename);
+ }
+ else if (fileexist(filename = std::string(THUMBNAILSDIR) + "/" +
+ packagename + ".jpg"))
+ { // Joint Photographic Experts Group (JPEG) File Interchange Format (JFIF) images.
+ img = new Fl_JPEG_Image(filename.c_str());
+ //printf(" JPEG Screenshot : \"%s\"\n", filename);
+ }
+ else if (fileexist(filename = std::string(THUMBNAILSDIR) + "/" +
+ packagename + ".jpeg"))
+ {
+ img = new Fl_JPEG_Image(filename.c_str());
+ //printf(" JPEG Screenshot : \"%s\"\n", filename);
+ }
+ else if (fileexist(filename = std::string(THUMBNAILSDIR) + "/" +
+ packagename + ".bmp"))
+ { // Windows Bitmap (BMP) image files
+ img = new Fl_BMP_Image(filename.c_str());
+ //printf(" BMP Screenshot : \"%s\"\n", filename);
+ }
+ else
+ { // TODO: Portable Anymap (PNM, PBM, PGM, PPM) image files
+ // Currently only fetching using HTTP is implemented
+ URLFetcher fetcher;
+ std::string url("http://screenshots.debian.net/screenshot/");
+ url += packagename;
+ //cout << "fetching " << url << endl;
+ try {
+ std::string imgname = fetcher.get(url, packagename);
+ //cout << "Loading image " << imgname << endl;
+ Fl_Image *tmpimg = new Fl_PNG_Image(imgname.c_str());
+ unlink(imgname.c_str());
+ img = tmpimg->copy(320, 240);
+ delete(tmpimg);
+ } catch (std::exception &e) {
+ cout << "URLFetcher exception: " << e.what() << endl;
+ img = NULL;
+ }
+ }
+ if (img && !img->count())
+ {
+ printf(" Wrong Screenshot.\n");
+ delete img;
+ img = NULL;
+ }
+ if (!img)
+ {
+ img = new Fl_PNG_Image(FILE_NO_SCREENSHOT);
+ }
+ return img;
+}
+
void PackageBrowser::item_select(void *p, int s)
{
VersatileBrowser::item_select(p, s);
@@ -177,57 +233,14 @@
if (data)
{
- char filename[PATH_MAX];
- struct stat fileinfo;
- Fl_Image *img = NULL;
- if (snprintf(filename, PATH_MAX, "%s/%s.png", THUMBNAILSDIR, (const char *)data) &&
- stat(filename, &fileinfo) == 0)
- { // Portable Network Graphics (PNG) image files
- // We were able to get the file attributes so the file obviously exists.
- img = new Fl_PNG_Image(filename);
- //printf(" PNG Screenshot : \"%s\"\n", filename);
- }
- else if (snprintf(filename, PATH_MAX, "%s/%s.jpg", THUMBNAILSDIR, (const char *)data) &&
- stat(filename, &fileinfo) == 0)
- { // Joint Photographic Experts Group (JPEG) File Interchange Format (JFIF) images.
- img = new Fl_JPEG_Image(filename);
- //printf(" JPEG Screenshot : \"%s\"\n", filename);
- }
- else if (snprintf(filename, PATH_MAX, "%s/%s.jpeg", THUMBNAILSDIR, (const char *)data) &&
- stat(filename, &fileinfo) == 0)
- {
- img = new Fl_JPEG_Image(filename);
- //printf(" JPEG Screenshot : \"%s\"\n", filename);
- }
- else if (snprintf(filename, PATH_MAX, "%s/%s.bmp", THUMBNAILSDIR, (const char *)data) &&
- stat(filename, &fileinfo) == 0)
- { // Windows Bitmap (BMP) image files
- img = new Fl_BMP_Image(filename);
- //printf(" BMP Screenshot : \"%s\"\n", filename);
- }
- else
- { // TODO: Portable Anymap (PNM, PBM, PGM, PPM) image files
- const char *packagename = (const char *)data;
- img = fetch_screenshot(packagename);
- }
- if (img && !img->count())
- {
- printf(" Wrong Screenshot.\n");
- delete img;
- img = NULL;
- }
- if (!img)
- {
- strncpy(filename, FILE_NO_SCREENSHOT, PATH_MAX);
- img = new Fl_PNG_Image(FILE_NO_SCREENSHOT);
- }
-
+ const char *packagename = (const char *)data;
+ Fl_Image *img = find_screenshot(packagename);
Fl_Group *highest_parent=parent();
while (highest_parent->parent()) highest_parent = highest_parent->parent();
GamesUI *ui = highest_parent ? (GamesUI*)(highest_parent->user_data()) : NULL;
if (ui && img) ui->Screenshot(img);
- PackageRecord rec(ui->engine->apt().rawRecord((const char *)data));
+ PackageRecord rec(ui->engine->apt().rawRecord(packagename));
std::string pkg_desc;
if (ui)
@@ -245,7 +258,7 @@
ui->DebTagsBrowser->column_widths(widths);
ui->DebTagsBrowser->add(_("@B12 at C7@b at .FACET\t at B12@C7 at b@.TAG"));
- set<std::string> tags = ui->engine->debtags().getTagsOfItem((const char *)data);
+ set<std::string> tags = ui->engine->debtags().getTagsOfItem(packagename);
char *tag_txt = new char[512];
for (set<std::string>::const_iterator i = tags.begin(); i != tags.end(); ++i)
{
Modified: software/ui/src/pkgbrowser.h
===================================================================
--- software/ui/src/pkgbrowser.h 2012-02-27 10:41:33 UTC (rev 13324)
+++ software/ui/src/pkgbrowser.h 2012-02-27 19:21:58 UTC (rev 13325)
@@ -216,7 +216,7 @@
const unsigned int num_bar_images;
Fl_Image *bar_images[2*2];
std::string pkgname;
- Fl_Image *fetch_screenshot(std::string packagename);
+ Fl_Image *find_screenshot(const std::string packagename);
};
class PackageView : public Fl_Help_View
More information about the Pkg-games-commits
mailing list