| 1 |
/*
|
| 2 |
* Copyright (C) 2007 Miriam Ruiz <little_miry@yahoo.es>
|
| 3 |
*
|
| 4 |
* VersatileBrowser uses ColResizeBrowser, written by Greg Ercolano
|
| 5 |
* ColResizeBrowser (C) Greg Ercolano <erco@seriss.com>
|
| 6 |
* URL: http://seriss.com/people/erco/fltk/
|
| 7 |
*
|
| 8 |
* This program is free software; you can redistribute it and/or modify
|
| 9 |
* it under the terms of the GNU General Public License as published by
|
| 10 |
* the Free Software Foundation; either version 2 of the License, or
|
| 11 |
* (at your option) any later version.
|
| 12 |
*
|
| 13 |
* This program is distributed in the hope that it will be useful,
|
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 16 |
* GNU General Public License for more details.
|
| 17 |
*
|
| 18 |
* You should have received a copy of the GNU General Public License
|
| 19 |
* along with this program; if not, write to the Free Software
|
| 20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
| 21 |
*/
|
| 22 |
|
| 23 |
#include "pkgbrowser.h"
|
| 24 |
#include "ui.h"
|
| 25 |
#include "common.h"
|
| 26 |
|
| 27 |
#include "Environment.h"
|
| 28 |
#include "GamesOptions.h"
|
| 29 |
#include "Engine.h"
|
| 30 |
|
| 31 |
#include <ept/apt/packagerecord.h>
|
| 32 |
|
| 33 |
#include <stdio.h>
|
| 34 |
#include <string.h>
|
| 35 |
#include <limits.h>
|
| 36 |
#include <sys/stat.h>
|
| 37 |
|
| 38 |
#include <FL/Fl_PNG_Image.H>
|
| 39 |
#include <FL/Fl_JPEG_Image.H>
|
| 40 |
#include <FL/Fl_BMP_Image.H>
|
| 41 |
|
| 42 |
using namespace std;
|
| 43 |
using namespace ept;
|
| 44 |
using namespace ept::debtags;
|
| 45 |
using namespace ept::apt;
|
| 46 |
using namespace ept::textsearch;
|
| 47 |
|
| 48 |
PackageBrowser::PackageBrowser(int x, int y, int w, int h, const char *l)
|
| 49 |
: VersatileBrowser(x, y, w, h, l)
|
| 50 |
{
|
| 51 |
showcolsep(1);
|
| 52 |
//colsepcolor(FL_RED);
|
| 53 |
column_char('\t'); // tabs as column delimiters
|
| 54 |
}
|
| 55 |
|
| 56 |
void PackageBrowser::item_select(void *p, int s)
|
| 57 |
{
|
| 58 |
VersatileBrowser::item_select(p, s);
|
| 59 |
|
| 60 |
if (s)
|
| 61 |
{
|
| 62 |
int n = VersatileBrowser::lineno(p);
|
| 63 |
void *data = VersatileBrowser::data(n);
|
| 64 |
printf(" #%d : \"%s\"\n", n, (const char *)data);
|
| 65 |
fflush(stdout);
|
| 66 |
|
| 67 |
char filename[PATH_MAX];
|
| 68 |
struct stat fileinfo;
|
| 69 |
Fl_Image *img = NULL;
|
| 70 |
if (snprintf(filename, PATH_MAX, "%s/%s.png", THUMBNAILSDIR, (const char *)data) &&
|
| 71 |
stat(filename, &fileinfo) == 0)
|
| 72 |
{ // Portable Network Graphics (PNG) image files
|
| 73 |
// We were able to get the file attributes so the file obviously exists.
|
| 74 |
img = new Fl_PNG_Image(filename);
|
| 75 |
printf(" PNG Screenshot : \"%s\"\n", filename);
|
| 76 |
}
|
| 77 |
else if (snprintf(filename, PATH_MAX, "%s/%s.jpg", THUMBNAILSDIR, (const char *)data) &&
|
| 78 |
stat(filename, &fileinfo) == 0)
|
| 79 |
{ // Joint Photographic Experts Group (JPEG) File Interchange Format (JFIF) images.
|
| 80 |
img = new Fl_JPEG_Image(filename);
|
| 81 |
printf(" JPEG Screenshot : \"%s\"\n", filename);
|
| 82 |
}
|
| 83 |
else if (snprintf(filename, PATH_MAX, "%s/%s.jpeg", THUMBNAILSDIR, (const char *)data) &&
|
| 84 |
stat(filename, &fileinfo) == 0)
|
| 85 |
{
|
| 86 |
img = new Fl_JPEG_Image(filename);
|
| 87 |
printf(" JPEG Screenshot : \"%s\"\n", filename);
|
| 88 |
}
|
| 89 |
else if (snprintf(filename, PATH_MAX, "%s/%s.bmp", THUMBNAILSDIR, (const char *)data) &&
|
| 90 |
stat(filename, &fileinfo) == 0)
|
| 91 |
{ // Windows Bitmap (BMP) image files
|
| 92 |
img = new Fl_BMP_Image(filename);
|
| 93 |
printf(" BMP Screenshot : \"%s\"\n", filename);
|
| 94 |
}
|
| 95 |
else
|
| 96 |
{ // TODO: Portable Anymap (PNM, PBM, PGM, PPM) image files
|
| 97 |
img = NULL;
|
| 98 |
}
|
| 99 |
if (img && !img->count())
|
| 100 |
{
|
| 101 |
printf(" Wrong Screenshot.\n");
|
| 102 |
delete img;
|
| 103 |
img = NULL;
|
| 104 |
}
|
| 105 |
if (!img)
|
| 106 |
{
|
| 107 |
strncpy(filename, FILE_NO_SCREENSHOT, PATH_MAX);
|
| 108 |
img = new Fl_PNG_Image(FILE_NO_SCREENSHOT);
|
| 109 |
}
|
| 110 |
|
| 111 |
Fl_Group *highest_parent=parent();
|
| 112 |
while (highest_parent->parent()) highest_parent = highest_parent->parent();
|
| 113 |
GamesUI *ui = highest_parent ? (GamesUI*)(highest_parent->user_data()) : NULL;
|
| 114 |
if (ui && img) ui->Screenshot(img);
|
| 115 |
|
| 116 |
PackageRecord rec(ui->engine->apt().rawRecord((const char *)data));
|
| 117 |
|
| 118 |
char *pkg_txt = new char[4096];
|
| 119 |
if (ui)
|
| 120 |
{
|
| 121 |
Fl_Text_Buffer *buffer = ui->InfoBuffer();
|
| 122 |
snprintf(pkg_txt, 4096, "Package: %s\n", rec.package().c_str());
|
| 123 |
buffer->text(pkg_txt);
|
| 124 |
snprintf(pkg_txt, 4096, "Description: %s\n", rec.shortDescription().c_str());
|
| 125 |
buffer->append(pkg_txt);
|
| 126 |
snprintf(pkg_txt, 4096, "\n%s\n", rec.longDescription().c_str());
|
| 127 |
buffer->append(pkg_txt);
|
| 128 |
}
|
| 129 |
delete [] pkg_txt;
|
| 130 |
|
| 131 |
static int widths[] = { 80, 80, 0 }; // widths for each column
|
| 132 |
ui->DebTagsBrowser->clear();
|
| 133 |
ui->DebTagsBrowser->showcolsep(1);
|
| 134 |
ui->DebTagsBrowser->column_widths(widths);
|
| 135 |
ui->DebTagsBrowser->add("@B12@C7@b@.FACET\t@B12@C7@b@.TAG\t@B12@C7@b@.DESCRIPTION");
|
| 136 |
|
| 137 |
set<Tag> tags = ui->engine->debtags().getTagsOfItem((const char *)data);
|
| 138 |
char *tag_txt = new char[512];
|
| 139 |
for (set<Tag>::const_iterator i = tags.begin(); i != tags.end(); ++i)
|
| 140 |
{
|
| 141 |
snprintf(tag_txt, 512, "%s\t%s\t%s",
|
| 142 |
gettext(i->facet().name().c_str()),
|
| 143 |
gettext(i->name().c_str()),
|
| 144 |
gettext(i->shortDescription().c_str())
|
| 145 |
);
|
| 146 |
ui->DebTagsBrowser->add(tag_txt);
|
| 147 |
}
|
| 148 |
delete [] tag_txt;
|
| 149 |
|
| 150 |
fflush(stdout);
|
| 151 |
}
|
| 152 |
}
|
| 153 |
|
| 154 |
int PackageBrowser::handle(int e)
|
| 155 |
{
|
| 156 |
// printf("PackageBrowser::handle(int e = 0x%X)\n", e);
|
| 157 |
// fflush(stdout);
|
| 158 |
|
| 159 |
int ret = VersatileBrowser::handle(e);
|
| 160 |
|
| 161 |
switch(e)
|
| 162 |
{
|
| 163 |
case FL_PUSH:
|
| 164 |
break;
|
| 165 |
case FL_RELEASE:
|
| 166 |
break;
|
| 167 |
case FL_ENTER:
|
| 168 |
break;
|
| 169 |
case FL_LEAVE:
|
| 170 |
break;
|
| 171 |
case FL_DRAG:
|
| 172 |
break;
|
| 173 |
case FL_FOCUS:
|
| 174 |
break;
|
| 175 |
case FL_UNFOCUS:
|
| 176 |
break;
|
| 177 |
case FL_KEYDOWN:
|
| 178 |
break;
|
| 179 |
case FL_KEYUP:
|
| 180 |
break;
|
| 181 |
case FL_CLOSE:
|
| 182 |
break;
|
| 183 |
case FL_MOVE:
|
| 184 |
break;
|
| 185 |
case FL_SHORTCUT:
|
| 186 |
break;
|
| 187 |
case FL_DEACTIVATE:
|
| 188 |
break;
|
| 189 |
case FL_ACTIVATE:
|
| 190 |
break;
|
| 191 |
case FL_HIDE:
|
| 192 |
break;
|
| 193 |
case FL_SHOW:
|
| 194 |
break;
|
| 195 |
case FL_PASTE:
|
| 196 |
break;
|
| 197 |
case FL_SELECTIONCLEAR:
|
| 198 |
break;
|
| 199 |
case FL_MOUSEWHEEL:
|
| 200 |
break;
|
| 201 |
case FL_NO_EVENT:
|
| 202 |
break;
|
| 203 |
}
|
| 204 |
return ret;
|
| 205 |
}
|