#include <stdio.h>
#include <stdlib.h>
#include <FL/fl_utf8.h>
#include "flstring.h"
#include <ctype.h>
#include <errno.h>
#include <FL/math.h>
#include <FL/Fl_File_Icon.H>
#include <FL/Fl_Shared_Image.H>
#include <FL/Fl_Widget.H>
#include <FL/fl_draw.H>
#include <FL/filename.H>
#ifndef F_OK
# define F_OK 0
#endif
static void load_kde_icons(const char *directory, const char *icondir);
static void load_kde_mimelnk(const char *filename, const char *icondir);
static char *kde_to_fltk_pattern(const char *kdepattern);
static char *get_kde_val(char *str, const char *key);
static const char *kdedir = NULL;
void
Fl_File_Icon::load(const char *f) {
int i; const char *ext;
ext = fl_filename_ext(f);
if (ext && strcmp(ext, ".fti") == 0)
i = load_fti(f);
else
i = load_image(f);
if (i)
{
Fl::warning("Fl_File_Icon::load(): Unable to load icon file \"%s\".", f);
return;
}
}
int Fl_File_Icon::load_fti(const char *fti) {
FILE *fp; int ch; char command[255], params[255], *ptr; int outline;
if ((fp = fl_fopen(fti, "rb")) == NULL)
{
Fl::error("Fl_File_Icon::load_fti(): Unable to open \"%s\" - %s",
fti, strerror(errno));
return -1;
}
outline = 0;
while ((ch = getc(fp)) != EOF)
{
if (isspace(ch))
continue;
if (ch == '#')
{
while ((ch = getc(fp)) != EOF)
if (ch == '\n')
break;
if (ch == EOF)
break;
else
continue;
}
if (!isalpha(ch))
{
Fl::error("Fl_File_Icon::load_fti(): Expected a letter at file position %ld (saw '%c')",
ftell(fp) - 1, ch);
break;
}
ptr = command;
*ptr++ = ch;
while ((ch = getc(fp)) != EOF)
{
if (ch == '(')
break;
else if (ptr < (command + sizeof(command) - 1))
*ptr++ = ch;
}
*ptr++ = '\0';
if (ch != '(')
{
Fl::error("Fl_File_Icon::load_fti(): Expected a ( at file position %ld (saw '%c')",
ftell(fp) - 1, ch);
break;
}
ptr = params;
while ((ch = getc(fp)) != EOF)
{
if (ch == ')')
break;
else if (ptr < (params + sizeof(params) - 1))
*ptr++ = ch;
}
*ptr++ = '\0';
if (ch != ')')
{
Fl::error("Fl_File_Icon::load_fti(): Expected a ) at file position %ld (saw '%c')",
ftell(fp) - 1, ch);
break;
}
if ((ch = getc(fp)) != ';')
{
Fl::error("Fl_File_Icon::load_fti(): Expected a ; at file position %ld (saw '%c')",
ftell(fp) - 1, ch);
break;
}
if (strcmp(command, "color") == 0)
{
if (strcmp(params, "iconcolor") == 0)
add_color(FL_ICON_COLOR);
else if (strcmp(params, "shadowcolor") == 0)
add_color(FL_DARK3);
else if (strcmp(params, "outlinecolor") == 0)
add_color(FL_BLACK);
else
{
int c = atoi(params);
if (c < 0)
{
c = -c;
add_color(fl_color_average((Fl_Color)(c >> 4),
(Fl_Color)(c & 15), 0.5f));
}
else
add_color((Fl_Color)c);
}
}
else if (strcmp(command, "bgnline") == 0)
add(LINE);
else if (strcmp(command, "bgnclosedline") == 0)
add(CLOSEDLINE);
else if (strcmp(command, "bgnpolygon") == 0)
add(POLYGON);
else if (strcmp(command, "bgnoutlinepolygon") == 0)
{
add(OUTLINEPOLYGON);
outline = int(add(0) - data_);
add(0);
}
else if (strcmp(command, "endoutlinepolygon") == 0 && outline)
{
unsigned cval;
if (strcmp(params, "iconcolor") == 0)
cval = FL_ICON_COLOR;
else if (strcmp(params, "shadowcolor") == 0)
cval = FL_DARK3;
else if (strcmp(params, "outlinecolor") == 0)
cval = FL_BLACK;
else
{
int c = atoi(params);
if (c < 0)
{
c = -c;
cval = fl_color_average((Fl_Color)(c >> 4), (Fl_Color)(c & 15), 0.5f);
}
else
cval = c;
}
data_[outline] = cval >> 16;
data_[outline + 1] = cval;
outline = 0;
add(END);
}
else if (strncmp(command, "end", 3) == 0)
add(END);
else if (strcmp(command, "vertex") == 0)
{
float x, y;
if (sscanf(params, "%f,%f", &x, &y) != 2)
break;
add_vertex((short)(int)rint(x * 100.0), (short)(int)rint(y * 100.0));
}
else
{
Fl::error("Fl_File_Icon::load_fti(): Unknown command \"%s\" at file position %ld.",
command, ftell(fp) - 1);
break;
}
}
fclose(fp);
#ifdef DEBUG
printf("Icon File \"%s\":\n", fti);
for (int i = 0; i < num_data_; i ++)
printf(" %d,\n", data_[i]);
#endif
return 0;
}
int Fl_File_Icon::load_image(const char *ifile) {
Fl_Shared_Image *img;
img = Fl_Shared_Image::get(ifile);
if (!img || !img->count() || !img->w() || !img->h()) return -1;
if (img->count() == 1) {
int x, y; int startx; Fl_Color c, temp; const uchar *row;
const int extra_data = img->ld() ? (img->ld()-img->w()*img->d()) : 0;
for (y = 0, row = (const uchar *)(*(img->data())); y < img->h(); y ++, row += extra_data)
{
for (x = 0, startx = 0, c = (Fl_Color)-1;
x < img->w();
x ++, row += img->d())
{
switch (img->d())
{
case 1 :
temp = fl_rgb_color(row[0], row[0], row[0]);
break;
case 2 :
if (row[1] > 127)
temp = fl_rgb_color(row[0], row[0], row[0]);
else
temp = (Fl_Color)-1;
break;
case 3 :
temp = fl_rgb_color(row[0], row[1], row[2]);
break;
default :
if (row[3] > 127)
temp = fl_rgb_color(row[0], row[1], row[2]);
else
temp = (Fl_Color)-1;
break;
}
if (temp != c)
{
if (x > startx && c != (Fl_Color)-1)
{
add_color(c);
add(POLYGON);
add_vertex(startx * 9000 / img->w() + 1000, 9500 - y * 9000 / img->h());
add_vertex(x * 9000 / img->w() + 1000, 9500 - y * 9000 / img->h());
add_vertex(x * 9000 / img->w() + 1000, 9500 - (y + 1) * 9000 / img->h());
add_vertex(startx * 9000 / img->w() + 1000, 9500 - (y + 1) * 9000 / img->h());
add(END);
}
c = temp;
startx = x;
}
}
if (x > startx && c != (Fl_Color)-1)
{
add_color(c);
add(POLYGON);
add_vertex(startx * 9000 / img->w() + 1000, 9500 - y * 9000 / img->h());
add_vertex(x * 9000 / img->w() + 1000, 9500 - y * 9000 / img->h());
add_vertex(x * 9000 / img->w() + 1000, 9500 - (y + 1) * 9000 / img->h());
add_vertex(startx * 9000 / img->w() + 1000, 9500 - (y + 1) * 9000 / img->h());
add(END);
}
}
} else {
int i, j; int ch; int newch; int bg; char val[16]; const char *lineptr, *const*ptr; int ncolors, chars_per_color; Fl_Color *colors; int red, green, blue; int x, y; int startx;
ptr = img->data();
sscanf(*ptr, "%*d%*d%d%d", &ncolors, &chars_per_color);
colors = new Fl_Color[int(1 << (chars_per_color * 8))];
memset(colors, 0, sizeof(Fl_Color) << (chars_per_color * 8));
bg = ' ';
ptr ++;
if (ncolors < 0) {
const uchar *cmapptr;
ncolors = -ncolors;
for (i = 0, cmapptr = (const uchar *)*ptr; i < ncolors; i ++, cmapptr += 4)
colors[cmapptr[0]] = fl_rgb_color(cmapptr[1], cmapptr[2], cmapptr[3]);
ptr ++;
} else {
for (i = 0; i < ncolors; i ++, ptr ++) {
lineptr = *ptr;
ch = *lineptr++;
if (chars_per_color > 1) ch = (ch << 8) | *lineptr++;
if ((lineptr = strstr(lineptr, "c ")) == NULL) {
colors[ch] = FL_BLACK;
} else if (lineptr[2] == '#') {
lineptr += 3;
for (j = 0; j < 12; j ++)
if (!isxdigit(lineptr[j]))
break;
switch (j) {
case 0 :
bg = ch;
default :
red = green = blue = 0;
break;
case 3 :
val[0] = lineptr[0];
val[1] = '\0';
red = 255 * (int)strtol(val, NULL, 16) / 15;
val[0] = lineptr[1];
val[1] = '\0';
green = 255 * (int)strtol(val, NULL, 16) / 15;
val[0] = lineptr[2];
val[1] = '\0';
blue = 255 * (int)strtol(val, NULL, 16) / 15;
break;
case 6 :
case 9 :
case 12 :
j /= 3;
val[0] = lineptr[0];
val[1] = lineptr[1];
val[2] = '\0';
red = (int)strtol(val, NULL, 16);
val[0] = lineptr[j + 0];
val[1] = lineptr[j + 1];
val[2] = '\0';
green = (int)strtol(val, NULL, 16);
val[0] = lineptr[2 * j + 0];
val[1] = lineptr[2 * j + 1];
val[2] = '\0';
blue = (int)strtol(val, NULL, 16);
break;
}
colors[ch] = fl_rgb_color((uchar)red, (uchar)green, (uchar)blue);
} else {
if (strncasecmp(lineptr + 2, "white", 5) == 0) colors[ch] = FL_WHITE;
else if (strncasecmp(lineptr + 2, "black", 5) == 0) colors[ch] = FL_BLACK;
else if (strncasecmp(lineptr + 2, "none", 4) == 0) {
colors[ch] = FL_BLACK;
bg = ch;
} else colors[ch] = FL_GRAY;
}
}
}
for (y = 0; y < img->h(); y ++, ptr ++) {
lineptr = *ptr;
startx = 0;
ch = bg;
for (x = 0; x < img->w(); x ++) {
newch = *lineptr++;
if (chars_per_color > 1) newch = (newch << 8) | *lineptr++;
if (newch != ch) {
if (ch != bg) {
add_color(colors[ch]);
add(POLYGON);
add_vertex(startx * 9000 / img->w() + 1000, 9500 - y * 9000 / img->h());
add_vertex(x * 9000 / img->w() + 1000, 9500 - y * 9000 / img->h());
add_vertex(x * 9000 / img->w() + 1000, 9500 - (y + 1) * 9000 / img->h());
add_vertex(startx * 9000 / img->w() + 1000, 9500 - (y + 1) * 9000 / img->h());
add(END);
}
ch = newch;
startx = x;
}
}
if (ch != bg) {
add_color(colors[ch]);
add(POLYGON);
add_vertex(startx * 9000 / img->w() + 1000, 9500 - y * 9000 / img->h());
add_vertex(x * 9000 / img->w() + 1000, 9500 - y * 9000 / img->h());
add_vertex(x * 9000 / img->w() + 1000, 9500 - (y + 1) * 9000 / img->h());
add_vertex(startx * 9000 / img->w() + 1000, 9500 - (y + 1) * 9000 / img->h());
add(END);
}
}
delete[] colors;
}
img->release();
#ifdef DEBUG
{
int i;
printf("Icon File \"%s\":\n", ifile);
for (i = 0; i < num_data_; i ++)
{
printf(" %d,\n", data_[i]);
}
}
#endif
return 0;
}
void
Fl_File_Icon::load_system_icons(void) {
int i; Fl_File_Icon *icon; char filename[FL_PATH_MAX + 60]; char icondir[FL_PATH_MAX]; static int init = 0; const char * const icondirs[] = {
"Bluecurve", "crystalsvg",
"default.kde",
"hicolor",
NULL
};
static short plain[] = { COLOR, -1, -1, OUTLINEPOLYGON, 0, FL_GRAY,
VERTEX, 2000, 1000, VERTEX, 2000, 9000,
VERTEX, 6000, 9000, VERTEX, 8000, 7000,
VERTEX, 8000, 1000, END, OUTLINEPOLYGON, 0, FL_GRAY,
VERTEX, 6000, 9000, VERTEX, 6000, 7000,
VERTEX, 8000, 7000, END,
COLOR, 0, FL_BLACK, LINE, VERTEX, 6000, 7000,
VERTEX, 8000, 7000, VERTEX, 8000, 1000,
VERTEX, 2000, 1000, END, LINE, VERTEX, 3000, 7000,
VERTEX, 5000, 7000, END, LINE, VERTEX, 3000, 6000,
VERTEX, 5000, 6000, END, LINE, VERTEX, 3000, 5000,
VERTEX, 7000, 5000, END, LINE, VERTEX, 3000, 4000,
VERTEX, 7000, 4000, END, LINE, VERTEX, 3000, 3000,
VERTEX, 7000, 3000, END, LINE, VERTEX, 3000, 2000,
VERTEX, 7000, 2000, END,
END
};
static short image[] = { COLOR, -1, -1, OUTLINEPOLYGON, 0, FL_GRAY,
VERTEX, 2000, 1000, VERTEX, 2000, 9000,
VERTEX, 6000, 9000, VERTEX, 8000, 7000,
VERTEX, 8000, 1000, END, OUTLINEPOLYGON, 0, FL_GRAY,
VERTEX, 6000, 9000, VERTEX, 6000, 7000,
VERTEX, 8000, 7000, END,
COLOR, 0, FL_BLACK, LINE, VERTEX, 6000, 7000,
VERTEX, 8000, 7000, VERTEX, 8000, 1000,
VERTEX, 2000, 1000, END,
COLOR, 0, FL_RED, POLYGON, VERTEX, 3500, 2500,
VERTEX, 3000, 3000, VERTEX, 3000, 4000,
VERTEX, 3500, 4500, VERTEX, 4500, 4500,
VERTEX, 5000, 4000, VERTEX, 5000, 3000,
VERTEX, 4500, 2500, END,
COLOR, 0, FL_GREEN, POLYGON, VERTEX, 5500, 2500,
VERTEX, 5000, 3000, VERTEX, 5000, 4000,
VERTEX, 5500, 4500, VERTEX, 6500, 4500,
VERTEX, 7000, 4000, VERTEX, 7000, 3000,
VERTEX, 6500, 2500, END,
COLOR, 0, FL_BLUE, POLYGON, VERTEX, 4500, 3500,
VERTEX, 4000, 4000, VERTEX, 4000, 5000,
VERTEX, 4500, 5500, VERTEX, 5500, 5500,
VERTEX, 6000, 5000, VERTEX, 6000, 4000,
VERTEX, 5500, 3500, END,
END
};
static short dir[] = { COLOR, -1, -1, POLYGON, VERTEX, 1000, 1000,
VERTEX, 1000, 7500, VERTEX, 9000, 7500,
VERTEX, 9000, 1000, END,
POLYGON, VERTEX, 1000, 7500, VERTEX, 2500, 9000,
VERTEX, 5000, 9000, VERTEX, 6500, 7500, END,
COLOR, 0, FL_WHITE, LINE, VERTEX, 1500, 1500,
VERTEX, 1500, 7000, VERTEX, 9000, 7000, END,
COLOR, 0, FL_BLACK, LINE, VERTEX, 9000, 7500,
VERTEX, 9000, 1000, VERTEX, 1000, 1000, END,
COLOR, 0, FL_GRAY, LINE, VERTEX, 1000, 1000,
VERTEX, 1000, 7500, VERTEX, 2500, 9000,
VERTEX, 5000, 9000, VERTEX, 6500, 7500,
VERTEX, 9000, 7500, END,
END
};
if (!init) {
fl_register_images();
if (!kdedir) {
if ((kdedir = fl_getenv("KDEDIR")) == NULL) {
if (!fl_access("/opt/kde", F_OK)) kdedir = "/opt/kde";
else if (!fl_access("/usr/local/share/mimelnk", F_OK)) kdedir = "/usr/local";
else kdedir = "/usr";
}
}
snprintf(filename, sizeof(filename), "%s/share/mimelnk", kdedir);
if (!fl_access(filename, F_OK)) {
icon = new Fl_File_Icon("*", Fl_File_Icon::PLAIN);
for (i = 0; icondirs[i]; i ++) {
snprintf(icondir, sizeof(icondir), "%s/share/icons/%s", kdedir,
icondirs[i]);
if (!fl_access(icondir, F_OK)) break;
}
if (icondirs[i]) {
snprintf(filename, sizeof(filename), "%s/16x16/mimetypes/unknown.png",
icondir);
} else {
snprintf(filename, sizeof(filename), "%s/share/icons/unknown.xpm",
kdedir);
}
if (!fl_access(filename, F_OK)) icon->load_image(filename);
icon = new Fl_File_Icon("*", Fl_File_Icon::LINK);
snprintf(filename, sizeof(filename), "%s/16x16/filesystems/link.png",
icondir);
if (!fl_access(filename, F_OK)) icon->load_image(filename);
snprintf(filename, sizeof(filename), "%s/share/mimelnk", kdedir);
load_kde_icons(filename, icondir);
} else if (!fl_access("/usr/share/icons/folder.xpm", F_OK)) {
icon = new Fl_File_Icon("*", Fl_File_Icon::PLAIN);
icon->load_image("/usr/share/icons/page.xpm");
icon = new Fl_File_Icon("*", Fl_File_Icon::DIRECTORY);
icon->load_image("/usr/share/icons/folder.xpm");
} else if (!fl_access("/usr/dt/appconfig/icons", F_OK)) {
icon = new Fl_File_Icon("*", Fl_File_Icon::PLAIN);
icon->load_image("/usr/dt/appconfig/icons/C/Dtdata.m.pm");
icon = new Fl_File_Icon("*", Fl_File_Icon::DIRECTORY);
icon->load_image("/usr/dt/appconfig/icons/C/DtdirB.m.pm");
icon = new Fl_File_Icon("core", Fl_File_Icon::PLAIN);
icon->load_image("/usr/dt/appconfig/icons/C/Dtcore.m.pm");
icon = new Fl_File_Icon("*.{bmp|bw|gif|jpg|pbm|pcd|pgm|ppm|png|ras|rgb|tif|xbm|xpm}", Fl_File_Icon::PLAIN);
icon->load_image("/usr/dt/appconfig/icons/C/Dtimage.m.pm");
icon = new Fl_File_Icon("*.{eps|pdf|ps}", Fl_File_Icon::PLAIN);
icon->load_image("/usr/dt/appconfig/icons/C/Dtps.m.pm");
icon = new Fl_File_Icon("*.ppd", Fl_File_Icon::PLAIN);
icon->load_image("/usr/dt/appconfig/icons/C/DtPrtpr.m.pm");
} else if (!fl_access("/usr/lib/filetype", F_OK)) {
icon = new Fl_File_Icon("*", Fl_File_Icon::PLAIN);
icon->load_fti("/usr/lib/filetype/iconlib/generic.doc.fti");
icon = new Fl_File_Icon("*", Fl_File_Icon::DIRECTORY);
icon->load_fti("/usr/lib/filetype/iconlib/generic.folder.closed.fti");
icon = new Fl_File_Icon("core", Fl_File_Icon::PLAIN);
icon->load_fti("/usr/lib/filetype/default/iconlib/CoreFile.fti");
icon = new Fl_File_Icon("*.{bmp|bw|gif|jpg|pbm|pcd|pgm|ppm|png|ras|rgb|tif|xbm|xpm}", Fl_File_Icon::PLAIN);
icon->load_fti("/usr/lib/filetype/system/iconlib/ImageFile.fti");
if (!fl_access("/usr/lib/filetype/install/iconlib/acroread.doc.fti", F_OK)) {
icon = new Fl_File_Icon("*.{eps|ps}", Fl_File_Icon::PLAIN);
icon->load_fti("/usr/lib/filetype/system/iconlib/PostScriptFile.closed.fti");
icon = new Fl_File_Icon("*.pdf", Fl_File_Icon::PLAIN);
icon->load_fti("/usr/lib/filetype/install/iconlib/acroread.doc.fti");
} else {
icon = new Fl_File_Icon("*.{eps|pdf|ps}", Fl_File_Icon::PLAIN);
icon->load_fti("/usr/lib/filetype/system/iconlib/PostScriptFile.closed.fti");
}
if (!fl_access("/usr/lib/filetype/install/iconlib/html.fti", F_OK)) {
icon = new Fl_File_Icon("*.{htm|html|shtml}", Fl_File_Icon::PLAIN);
icon->load_fti("/usr/lib/filetype/iconlib/generic.doc.fti");
icon->load_fti("/usr/lib/filetype/install/iconlib/html.fti");
}
if (!fl_access("/usr/lib/filetype/install/iconlib/color.ps.idle.fti", F_OK)) {
icon = new Fl_File_Icon("*.ppd", Fl_File_Icon::PLAIN);
icon->load_fti("/usr/lib/filetype/install/iconlib/color.ps.idle.fti");
}
} else {
new Fl_File_Icon("*", Fl_File_Icon::PLAIN, sizeof(plain) / sizeof(plain[0]), plain);
new Fl_File_Icon("*.{bm|bmp|bw|gif|jpg|pbm|pcd|pgm|ppm|png|ras|rgb|tif|xbm|xpm}", Fl_File_Icon::PLAIN,
sizeof(image) / sizeof(image[0]), image);
new Fl_File_Icon("*", Fl_File_Icon::DIRECTORY, sizeof(dir) / sizeof(dir[0]), dir);
}
init = 1;
#ifdef DEBUG
int count;
Fl_File_Icon *temp;
for (count = 0, temp = first_; temp; temp = temp->next_, count ++);
printf("count of Fl_File_Icon's is %d...\n", count);
#endif }
}
static void
load_kde_icons(const char *directory, const char *icondir) { int i; int n; dirent **entries; char full[FL_PATH_MAX];
entries = (dirent **)0;
n = fl_filename_list(directory, &entries);
for (i = 0; i < n; i ++) {
if (entries[i]->d_name[0] != '.') {
snprintf(full, sizeof(full), "%s/%s", directory, entries[i]->d_name);
if (fl_filename_isdir(full)) load_kde_icons(full, icondir);
else load_kde_mimelnk(full, icondir);
}
free((void *)entries[i]);
}
free((void*)entries);
}
static void
load_kde_mimelnk(const char *filename, const char *icondir) { FILE *fp;
char tmp[1024];
char iconfilename[FL_PATH_MAX];
char pattern[1024];
char mimetype[1024];
char *val;
char full_iconfilename[2 * FL_PATH_MAX];
Fl_File_Icon *icon;
mimetype[0] = '\0';
pattern[0] = '\0';
iconfilename[0] = '\0';
if ((fp = fl_fopen(filename, "rb")) != NULL) {
while (fgets(tmp, sizeof(tmp), fp)) {
if ((val = get_kde_val(tmp, "Icon")) != NULL)
strlcpy(iconfilename, val, sizeof(iconfilename));
else if ((val = get_kde_val(tmp, "MimeType")) != NULL)
strlcpy(mimetype, val, sizeof(mimetype));
else if ((val = get_kde_val(tmp, "Patterns")) != NULL)
strlcpy(pattern, val, sizeof(pattern));
}
fclose(fp);
#ifdef DEBUG
printf("%s: Icon=\"%s\", MimeType=\"%s\", Patterns=\"%s\"\n", filename,
iconfilename, mimetype, pattern);
#endif
if (!pattern[0] && strncmp(mimetype, "inode/", 6)) return;
if (iconfilename[0]) {
if (iconfilename[0] == '/') {
strlcpy(full_iconfilename, iconfilename, sizeof(full_iconfilename));
} else if (!fl_access(icondir, F_OK)) {
int i; static const char *paths[] = { "16x16/actions",
"16x16/apps",
"16x16/devices",
"16x16/filesystems",
"16x16/mimetypes",
"32x32/actions",
"32x32/apps",
"32x32/devices",
"32x32/filesystems",
"32x32/mimetypes",
};
for (i = 0; i < (int)(sizeof(paths) / sizeof(paths[0])); i ++) {
snprintf(full_iconfilename, sizeof(full_iconfilename),
"%s/%s/%s.png", icondir, paths[i], iconfilename);
if (!fl_access(full_iconfilename, F_OK)) break;
}
if (i >= (int)(sizeof(paths) / sizeof(paths[0]))) return;
} else {
snprintf(full_iconfilename, sizeof(full_iconfilename),
"%s/%s", tmp, iconfilename);
if (fl_access(full_iconfilename, F_OK)) return;
}
if (strncmp(mimetype, "inode/", 6) == 0) {
if (!strcmp(mimetype + 6, "directory"))
icon = new Fl_File_Icon("*", Fl_File_Icon::DIRECTORY);
else if (!strcmp(mimetype + 6, "blockdevice"))
icon = new Fl_File_Icon("*", Fl_File_Icon::DEVICE);
else if (!strcmp(mimetype + 6, "fifo"))
icon = new Fl_File_Icon("*", Fl_File_Icon::FIFO);
else return;
} else {
icon = new Fl_File_Icon(kde_to_fltk_pattern(pattern),
Fl_File_Icon::PLAIN);
}
icon->load(full_iconfilename);
}
}
}
static char *
kde_to_fltk_pattern(const char *kdepattern) {
char *pattern,
*patptr;
pattern = (char *)malloc(strlen(kdepattern) + 3);
strcpy(pattern, "{");
strcpy(pattern + 1, kdepattern);
if (pattern[strlen(pattern) - 1] == ';') pattern[strlen(pattern) - 1] = '\0';
strcat(pattern, "}");
for (patptr = pattern; *patptr; patptr ++) {
if (*patptr == ';') *patptr = '|';
}
return (pattern);
}
static char *
get_kde_val(char *str,
const char *key) {
while (*str == *key) {
str ++;
key ++;
}
if (*key == '\0' && *str == '=') {
if (str[strlen(str) - 1] == '\n') str[strlen(str) - 1] = '\0';
return (str + 1);
}
return ((char *)0);
}