2 // "$Id: Fl_File_Icon2.cxx 8063 2010-12-19 21:20:10Z matt $"
4 // Fl_File_Icon system icon routines.
6 // KDE icon code donated by Maarten De Boer.
8 // Copyright 1999-2010 by Michael Sweet.
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Library General Public
12 // License as published by the Free Software Foundation; either
13 // version 2 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Library General Public License for more details.
20 // You should have received a copy of the GNU Library General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 // Please report all bugs and problems on the following page:
27 // http://www.fltk.org/str.php
31 // Fl_File_Icon::load() - Load an icon file...
32 // Fl_File_Icon::load_fti() - Load an SGI-format FTI file...
33 // Fl_File_Icon::load_image() - Load an image icon file...
34 // Fl_File_Icon::load_system_icons() - Load the standard system icons/filetypes.
35 // load_kde_icons() - Load KDE icon files.
36 // load_kde_mimelnk() - Load a KDE "mimelnk" file.
37 // kde_to_fltk_pattern() - Convert a KDE pattern to a FLTK pattern.
38 // get_kde_val() - Get a KDE value.
42 // Include necessary header files...
47 #include <FL/fl_utf8.h>
52 #include <sys/types.h>
54 #if defined(WIN32) && !defined(__CYGWIN__)
57 // Visual C++ 2005 incorrectly displays a warning about the use of POSIX APIs
58 // on Windows, which is supposed to be POSIX compliant...
59 # define access _access
64 #include <FL/Fl_File_Icon.H>
65 #include <FL/Fl_Shared_Image.H>
66 #include <FL/Fl_Widget.H>
67 #include <FL/fl_draw.H>
68 #include <FL/filename.H>
72 // Define missing POSIX/XPG4 macros as needed...
76 # define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
77 # define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
78 # define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
79 # define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
80 # define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
88 static void load_kde_icons(const char *directory
, const char *icondir
);
89 static void load_kde_mimelnk(const char *filename
, const char *icondir
);
90 static char *kde_to_fltk_pattern(const char *kdepattern
);
91 static char *get_kde_val(char *str
, const char *key
);
98 static const char *kdedir
= NULL
;
102 Loads the specified icon image. The format is deduced from the filename.
103 \param[in] f filename
106 Fl_File_Icon::load(const char *f
) // I - File to read from
108 int i
; // Load status...
109 const char *ext
; // File extension
112 ext
= fl_filename_ext(f
);
114 if (ext
&& strcmp(ext
, ".fti") == 0)
121 Fl::warning("Fl_File_Icon::load(): Unable to load icon file \"%s\".", f
);
128 Loads an SGI icon file.
129 \param[in] fti icon filename
130 \return 0 on success, non-zero on error
132 int // O - 0 on success, non-zero on error
133 Fl_File_Icon::load_fti(const char *fti
) // I - File to read from
135 FILE *fp
; // File pointer
136 int ch
; // Current character
137 char command
[255], // Command string ("vertex", etc.)
138 params
[255], // Parameter string ("10.0,20.0", etc.)
139 *ptr
; // Pointer into strings
140 int outline
; // Outline polygon
143 // Try to open the file...
144 if ((fp
= fl_fopen(fti
, "rb")) == NULL
)
146 Fl::error("Fl_File_Icon::load_fti(): Unable to open \"%s\" - %s",
147 fti
, strerror(errno
));
151 // Read the entire file, adding data as needed...
154 while ((ch
= getc(fp
)) != EOF
)
160 // Skip comments starting with "#"...
163 while ((ch
= getc(fp
)) != EOF
)
173 // OK, this character better be a letter...
176 Fl::error("Fl_File_Icon::load_fti(): Expected a letter at file position %ld (saw '%c')",
181 // Scan the command name...
185 while ((ch
= getc(fp
)) != EOF
)
189 else if (ptr
< (command
+ sizeof(command
) - 1))
195 // Make sure we stopped on a parenthesis...
198 Fl::error("Fl_File_Icon::load_fti(): Expected a ( at file position %ld (saw '%c')",
203 // Scan the parameters...
206 while ((ch
= getc(fp
)) != EOF
)
210 else if (ptr
< (params
+ sizeof(params
) - 1))
216 // Make sure we stopped on a parenthesis...
219 Fl::error("Fl_File_Icon::load_fti(): Expected a ) at file position %ld (saw '%c')",
224 // Make sure the next character is a semicolon...
225 if ((ch
= getc(fp
)) != ';')
227 Fl::error("Fl_File_Icon::load_fti(): Expected a ; at file position %ld (saw '%c')",
232 // Now process the command...
233 if (strcmp(command
, "color") == 0)
235 // Set the color; for negative colors blend the two primaries to
236 // produce a composite color. Also, the following symbolic color
237 // names are understood:
240 // ------------- ----------
241 // iconcolor FL_ICON_COLOR; mapped to the icon color in
242 // Fl_File_Icon::draw()
243 // shadowcolor FL_DARK3
244 // outlinecolor FL_BLACK
245 if (strcmp(params
, "iconcolor") == 0)
246 add_color(FL_ICON_COLOR
);
247 else if (strcmp(params
, "shadowcolor") == 0)
249 else if (strcmp(params
, "outlinecolor") == 0)
253 int c
= atoi(params
); // Color value
258 // Composite color; compute average...
260 add_color(fl_color_average((Fl_Color
)(c
>> 4),
261 (Fl_Color
)(c
& 15), 0.5f
));
264 add_color((Fl_Color
)c
);
267 else if (strcmp(command
, "bgnline") == 0)
269 else if (strcmp(command
, "bgnclosedline") == 0)
271 else if (strcmp(command
, "bgnpolygon") == 0)
273 else if (strcmp(command
, "bgnoutlinepolygon") == 0)
276 outline
= add(0) - data_
;
279 else if (strcmp(command
, "endoutlinepolygon") == 0 && outline
)
281 unsigned cval
; // Color value
283 // Set the outline color; see above for valid values...
284 if (strcmp(params
, "iconcolor") == 0)
285 cval
= FL_ICON_COLOR
;
286 else if (strcmp(params
, "shadowcolor") == 0)
288 else if (strcmp(params
, "outlinecolor") == 0)
292 int c
= atoi(params
); // Color value
297 // Composite color; compute average...
299 cval
= fl_color_average((Fl_Color
)(c
>> 4), (Fl_Color
)(c
& 15), 0.5f
);
305 // Store outline color...
306 data_
[outline
] = cval
>> 16;
307 data_
[outline
+ 1] = cval
;
312 else if (strncmp(command
, "end", 3) == 0)
314 else if (strcmp(command
, "vertex") == 0)
316 float x
, y
; // Coordinates of vertex
319 if (sscanf(params
, "%f,%f", &x
, &y
) != 2)
322 add_vertex((short)(int)rint(x
* 100.0), (short)(int)rint(y
* 100.0));
326 Fl::error("Fl_File_Icon::load_fti(): Unknown command \"%s\" at file position %ld.",
327 command
, ftell(fp
) - 1);
332 // Close the file and return...
336 printf("Icon File \"%s\":\n", fti
);
337 for (int i
= 0; i
< num_data_
; i
++)
338 printf(" %d,\n", data_
[i
]);
346 Load an image icon file from an image filename.
347 \param[in] ifile image filename
348 \return 0 on success, non-zero on error
350 int Fl_File_Icon::load_image(const char *ifile
) // I - File to read from
352 Fl_Shared_Image
*img
; // Image file
355 img
= Fl_Shared_Image::get(ifile
);
356 if (!img
|| !img
->count() || !img
->w() || !img
->h()) return -1;
358 if (img
->count() == 1) {
359 int x
, y
; // X & Y in image
360 int startx
; // Starting X coord
361 Fl_Color c
, // Current color
362 temp
; // Temporary color
363 const uchar
*row
; // Pointer into image
366 // Loop through grayscale or RGB image...
367 for (y
= 0, row
= (const uchar
*)(*(img
->data())); y
< img
->h(); y
++, row
+= img
->ld())
369 for (x
= 0, startx
= 0, c
= (Fl_Color
)-1;
371 x
++, row
+= img
->d())
376 temp
= fl_rgb_color(row
[0], row
[0], row
[0]);
380 temp
= fl_rgb_color(row
[0], row
[0], row
[0]);
385 temp
= fl_rgb_color(row
[0], row
[1], row
[2]);
389 temp
= fl_rgb_color(row
[0], row
[1], row
[2]);
397 if (x
> startx
&& c
!= (Fl_Color
)-1)
401 add_vertex(startx
* 9000 / img
->w() + 1000, 9500 - y
* 9000 / img
->h());
402 add_vertex(x
* 9000 / img
->w() + 1000, 9500 - y
* 9000 / img
->h());
403 add_vertex(x
* 9000 / img
->w() + 1000, 9500 - (y
+ 1) * 9000 / img
->h());
404 add_vertex(startx
* 9000 / img
->w() + 1000, 9500 - (y
+ 1) * 9000 / img
->h());
413 if (x
> startx
&& c
!= (Fl_Color
)-1)
417 add_vertex(startx
* 9000 / img
->w() + 1000, 9500 - y
* 9000 / img
->h());
418 add_vertex(x
* 9000 / img
->w() + 1000, 9500 - y
* 9000 / img
->h());
419 add_vertex(x
* 9000 / img
->w() + 1000, 9500 - (y
+ 1) * 9000 / img
->h());
420 add_vertex(startx
* 9000 / img
->w() + 1000, 9500 - (y
+ 1) * 9000 / img
->h());
425 int i
, j
; // Looping vars
426 int ch
; // Current character
427 int newch
; // New character
428 int bg
; // Background color
429 char val
[16]; // Color value
430 const char *lineptr
, // Pointer into line
431 *const*ptr
; // Pointer into data array
432 int ncolors
, // Number of colors
433 chars_per_color
; // Characters per color
434 Fl_Color
*colors
; // Colors
435 int red
, green
, blue
; // Red, green, and blue values
436 int x
, y
; // X & Y in image
437 int startx
; // Starting X coord
440 // Get the pixmap data...
442 sscanf(*ptr
, "%*d%*d%d%d", &ncolors
, &chars_per_color
);
444 colors
= new Fl_Color
[1 << (chars_per_color
* 8)];
446 // Read the colormap...
447 memset(colors
, 0, sizeof(Fl_Color
) << (chars_per_color
* 8));
453 // Read compressed colormap...
454 const uchar
*cmapptr
;
458 for (i
= 0, cmapptr
= (const uchar
*)*ptr
; i
< ncolors
; i
++, cmapptr
+= 4)
459 colors
[cmapptr
[0]] = fl_rgb_color(cmapptr
[1], cmapptr
[2], cmapptr
[3]);
463 for (i
= 0; i
< ncolors
; i
++, ptr
++) {
464 // Get the color's character
468 if (chars_per_color
> 1) ch
= (ch
<< 8) | *lineptr
++;
470 // Get the color value...
471 if ((lineptr
= strstr(lineptr
, "c ")) == NULL
) {
472 // No color; make this black...
473 colors
[ch
] = FL_BLACK
;
474 } else if (lineptr
[2] == '#') {
475 // Read the RGB triplet...
477 for (j
= 0; j
< 12; j
++)
478 if (!isxdigit(lineptr
[j
]))
485 red
= green
= blue
= 0;
491 red
= 255 * strtol(val
, NULL
, 16) / 15;
495 green
= 255 * strtol(val
, NULL
, 16) / 15;
499 blue
= 255 * strtol(val
, NULL
, 16) / 15;
510 red
= strtol(val
, NULL
, 16);
512 val
[0] = lineptr
[j
+ 0];
513 val
[1] = lineptr
[j
+ 1];
515 green
= strtol(val
, NULL
, 16);
517 val
[0] = lineptr
[2 * j
+ 0];
518 val
[1] = lineptr
[2 * j
+ 1];
520 blue
= strtol(val
, NULL
, 16);
524 colors
[ch
] = fl_rgb_color((uchar
)red
, (uchar
)green
, (uchar
)blue
);
526 // Read a color name...
527 if (strncasecmp(lineptr
+ 2, "white", 5) == 0) colors
[ch
] = FL_WHITE
;
528 else if (strncasecmp(lineptr
+ 2, "black", 5) == 0) colors
[ch
] = FL_BLACK
;
529 else if (strncasecmp(lineptr
+ 2, "none", 4) == 0) {
530 colors
[ch
] = FL_BLACK
;
532 } else colors
[ch
] = FL_GRAY
;
537 // Read the image data...
538 for (y
= 0; y
< img
->h(); y
++, ptr
++) {
543 for (x
= 0; x
< img
->w(); x
++) {
546 if (chars_per_color
> 1) newch
= (newch
<< 8) | *lineptr
++;
550 add_color(colors
[ch
]);
552 add_vertex(startx
* 9000 / img
->w() + 1000, 9500 - y
* 9000 / img
->h());
553 add_vertex(x
* 9000 / img
->w() + 1000, 9500 - y
* 9000 / img
->h());
554 add_vertex(x
* 9000 / img
->w() + 1000, 9500 - (y
+ 1) * 9000 / img
->h());
555 add_vertex(startx
* 9000 / img
->w() + 1000, 9500 - (y
+ 1) * 9000 / img
->h());
565 add_color(colors
[ch
]);
567 add_vertex(startx
* 9000 / img
->w() + 1000, 9500 - y
* 9000 / img
->h());
568 add_vertex(x
* 9000 / img
->w() + 1000, 9500 - y
* 9000 / img
->h());
569 add_vertex(x
* 9000 / img
->w() + 1000, 9500 - (y
+ 1) * 9000 / img
->h());
570 add_vertex(startx
* 9000 / img
->w() + 1000, 9500 - (y
+ 1) * 9000 / img
->h());
575 // Free the colormap...
582 printf("Icon File \"%s\":\n", xpm
);
583 for (i
= 0; i
< num_data_
; i
++)
584 printf(" %d,\n", data_
[i
]);
592 Loads all system-defined icons. This call is useful when using the
593 FileChooser widget and should be used when the application starts:
596 Fl_File_Icon::load_system_icons();
600 Fl_File_Icon::load_system_icons(void) {
601 int i
; // Looping var
602 Fl_File_Icon
*icon
; // New icons
603 char filename
[FL_PATH_MAX
]; // Filename
604 char icondir
[FL_PATH_MAX
]; // Icon directory
605 static int init
= 0; // Have the icons been initialized?
606 const char * const icondirs
[] = {
607 "Bluecurve", // Icon directories to look for, in order
613 static short plain
[] = { // Plain file icon
614 COLOR
, -1, -1, OUTLINEPOLYGON
, 0, FL_GRAY
,
615 VERTEX
, 2000, 1000, VERTEX
, 2000, 9000,
616 VERTEX
, 6000, 9000, VERTEX
, 8000, 7000,
617 VERTEX
, 8000, 1000, END
, OUTLINEPOLYGON
, 0, FL_GRAY
,
618 VERTEX
, 6000, 9000, VERTEX
, 6000, 7000,
619 VERTEX
, 8000, 7000, END
,
620 COLOR
, 0, FL_BLACK
, LINE
, VERTEX
, 6000, 7000,
621 VERTEX
, 8000, 7000, VERTEX
, 8000, 1000,
622 VERTEX
, 2000, 1000, END
, LINE
, VERTEX
, 3000, 7000,
623 VERTEX
, 5000, 7000, END
, LINE
, VERTEX
, 3000, 6000,
624 VERTEX
, 5000, 6000, END
, LINE
, VERTEX
, 3000, 5000,
625 VERTEX
, 7000, 5000, END
, LINE
, VERTEX
, 3000, 4000,
626 VERTEX
, 7000, 4000, END
, LINE
, VERTEX
, 3000, 3000,
627 VERTEX
, 7000, 3000, END
, LINE
, VERTEX
, 3000, 2000,
628 VERTEX
, 7000, 2000, END
,
631 static short image
[] = { // Image file icon
632 COLOR
, -1, -1, OUTLINEPOLYGON
, 0, FL_GRAY
,
633 VERTEX
, 2000, 1000, VERTEX
, 2000, 9000,
634 VERTEX
, 6000, 9000, VERTEX
, 8000, 7000,
635 VERTEX
, 8000, 1000, END
, OUTLINEPOLYGON
, 0, FL_GRAY
,
636 VERTEX
, 6000, 9000, VERTEX
, 6000, 7000,
637 VERTEX
, 8000, 7000, END
,
638 COLOR
, 0, FL_BLACK
, LINE
, VERTEX
, 6000, 7000,
639 VERTEX
, 8000, 7000, VERTEX
, 8000, 1000,
640 VERTEX
, 2000, 1000, END
,
641 COLOR
, 0, FL_RED
, POLYGON
, VERTEX
, 3500, 2500,
642 VERTEX
, 3000, 3000, VERTEX
, 3000, 4000,
643 VERTEX
, 3500, 4500, VERTEX
, 4500, 4500,
644 VERTEX
, 5000, 4000, VERTEX
, 5000, 3000,
645 VERTEX
, 4500, 2500, END
,
646 COLOR
, 0, FL_GREEN
, POLYGON
, VERTEX
, 5500, 2500,
647 VERTEX
, 5000, 3000, VERTEX
, 5000, 4000,
648 VERTEX
, 5500, 4500, VERTEX
, 6500, 4500,
649 VERTEX
, 7000, 4000, VERTEX
, 7000, 3000,
650 VERTEX
, 6500, 2500, END
,
651 COLOR
, 0, FL_BLUE
, POLYGON
, VERTEX
, 4500, 3500,
652 VERTEX
, 4000, 4000, VERTEX
, 4000, 5000,
653 VERTEX
, 4500, 5500, VERTEX
, 5500, 5500,
654 VERTEX
, 6000, 5000, VERTEX
, 6000, 4000,
655 VERTEX
, 5500, 3500, END
,
658 static short dir
[] = { // Directory icon
659 COLOR
, -1, -1, POLYGON
, VERTEX
, 1000, 1000,
660 VERTEX
, 1000, 7500, VERTEX
, 9000, 7500,
661 VERTEX
, 9000, 1000, END
,
662 POLYGON
, VERTEX
, 1000, 7500, VERTEX
, 2500, 9000,
663 VERTEX
, 5000, 9000, VERTEX
, 6500, 7500, END
,
664 COLOR
, 0, FL_WHITE
, LINE
, VERTEX
, 1500, 1500,
665 VERTEX
, 1500, 7000, VERTEX
, 9000, 7000, END
,
666 COLOR
, 0, FL_BLACK
, LINE
, VERTEX
, 9000, 7500,
667 VERTEX
, 9000, 1000, VERTEX
, 1000, 1000, END
,
668 COLOR
, 0, FL_GRAY
, LINE
, VERTEX
, 1000, 1000,
669 VERTEX
, 1000, 7500, VERTEX
, 2500, 9000,
670 VERTEX
, 5000, 9000, VERTEX
, 6500, 7500,
671 VERTEX
, 9000, 7500, END
,
676 // Add symbols if they haven't been added already...
678 // This method requires the images library...
679 fl_register_images();
682 // Figure out where KDE is installed...
683 if ((kdedir
= getenv("KDEDIR")) == NULL
) {
684 if (!access("/opt/kde", F_OK
)) kdedir
= "/opt/kde";
685 else if (!access("/usr/local/share/mimelnk", F_OK
)) kdedir
= "/usr/local";
686 else kdedir
= "/usr";
690 snprintf(filename
, sizeof(filename
), "%s/share/mimelnk", kdedir
);
692 if (!access(filename
, F_OK
)) {
694 icon
= new Fl_File_Icon("*", Fl_File_Icon::PLAIN
);
696 for (i
= 0; icondirs
[i
]; i
++) {
697 snprintf(icondir
, sizeof(icondir
), "%s/share/icons/%s", kdedir
,
700 if (!access(icondir
, F_OK
)) break;
704 snprintf(filename
, sizeof(filename
), "%s/16x16/mimetypes/unknown.png",
707 snprintf(filename
, sizeof(filename
), "%s/share/icons/unknown.xpm",
711 if (!access(filename
, F_OK
)) icon
->load_image(filename
);
713 icon
= new Fl_File_Icon("*", Fl_File_Icon::LINK
);
715 snprintf(filename
, sizeof(filename
), "%s/16x16/filesystems/link.png",
718 if (!access(filename
, F_OK
)) icon
->load_image(filename
);
720 snprintf(filename
, sizeof(filename
), "%s/share/mimelnk", kdedir
);
721 load_kde_icons(filename
, icondir
);
722 } else if (!access("/usr/share/icons/folder.xpm", F_OK
)) {
723 // Load GNOME icons...
724 icon
= new Fl_File_Icon("*", Fl_File_Icon::PLAIN
);
725 icon
->load_image("/usr/share/icons/page.xpm");
727 icon
= new Fl_File_Icon("*", Fl_File_Icon::DIRECTORY
);
728 icon
->load_image("/usr/share/icons/folder.xpm");
729 } else if (!access("/usr/dt/appconfig/icons", F_OK
)) {
731 icon
= new Fl_File_Icon("*", Fl_File_Icon::PLAIN
);
732 icon
->load_image("/usr/dt/appconfig/icons/C/Dtdata.m.pm");
734 icon
= new Fl_File_Icon("*", Fl_File_Icon::DIRECTORY
);
735 icon
->load_image("/usr/dt/appconfig/icons/C/DtdirB.m.pm");
737 icon
= new Fl_File_Icon("core", Fl_File_Icon::PLAIN
);
738 icon
->load_image("/usr/dt/appconfig/icons/C/Dtcore.m.pm");
740 icon
= new Fl_File_Icon("*.{bmp|bw|gif|jpg|pbm|pcd|pgm|ppm|png|ras|rgb|tif|xbm|xpm}", Fl_File_Icon::PLAIN
);
741 icon
->load_image("/usr/dt/appconfig/icons/C/Dtimage.m.pm");
743 icon
= new Fl_File_Icon("*.{eps|pdf|ps}", Fl_File_Icon::PLAIN
);
744 icon
->load_image("/usr/dt/appconfig/icons/C/Dtps.m.pm");
746 icon
= new Fl_File_Icon("*.ppd", Fl_File_Icon::PLAIN
);
747 icon
->load_image("/usr/dt/appconfig/icons/C/DtPrtpr.m.pm");
748 } else if (!access("/usr/lib/filetype", F_OK
)) {
750 icon
= new Fl_File_Icon("*", Fl_File_Icon::PLAIN
);
751 icon
->load_fti("/usr/lib/filetype/iconlib/generic.doc.fti");
753 icon
= new Fl_File_Icon("*", Fl_File_Icon::DIRECTORY
);
754 icon
->load_fti("/usr/lib/filetype/iconlib/generic.folder.closed.fti");
756 icon
= new Fl_File_Icon("core", Fl_File_Icon::PLAIN
);
757 icon
->load_fti("/usr/lib/filetype/default/iconlib/CoreFile.fti");
759 icon
= new Fl_File_Icon("*.{bmp|bw|gif|jpg|pbm|pcd|pgm|ppm|png|ras|rgb|tif|xbm|xpm}", Fl_File_Icon::PLAIN
);
760 icon
->load_fti("/usr/lib/filetype/system/iconlib/ImageFile.fti");
762 if (!access("/usr/lib/filetype/install/iconlib/acroread.doc.fti", F_OK
)) {
763 icon
= new Fl_File_Icon("*.{eps|ps}", Fl_File_Icon::PLAIN
);
764 icon
->load_fti("/usr/lib/filetype/system/iconlib/PostScriptFile.closed.fti");
766 icon
= new Fl_File_Icon("*.pdf", Fl_File_Icon::PLAIN
);
767 icon
->load_fti("/usr/lib/filetype/install/iconlib/acroread.doc.fti");
769 icon
= new Fl_File_Icon("*.{eps|pdf|ps}", Fl_File_Icon::PLAIN
);
770 icon
->load_fti("/usr/lib/filetype/system/iconlib/PostScriptFile.closed.fti");
773 if (!access("/usr/lib/filetype/install/iconlib/html.fti", F_OK
)) {
774 icon
= new Fl_File_Icon("*.{htm|html|shtml}", Fl_File_Icon::PLAIN
);
775 icon
->load_fti("/usr/lib/filetype/iconlib/generic.doc.fti");
776 icon
->load_fti("/usr/lib/filetype/install/iconlib/html.fti");
779 if (!access("/usr/lib/filetype/install/iconlib/color.ps.idle.fti", F_OK
)) {
780 icon
= new Fl_File_Icon("*.ppd", Fl_File_Icon::PLAIN
);
781 icon
->load_fti("/usr/lib/filetype/install/iconlib/color.ps.idle.fti");
784 // Create the default icons...
785 new Fl_File_Icon("*", Fl_File_Icon::PLAIN
, sizeof(plain
) / sizeof(plain
[0]), plain
);
786 new Fl_File_Icon("*.{bm|bmp|bw|gif|jpg|pbm|pcd|pgm|ppm|png|ras|rgb|tif|xbm|xpm}", Fl_File_Icon::PLAIN
,
787 sizeof(image
) / sizeof(image
[0]), image
);
788 new Fl_File_Icon("*", Fl_File_Icon::DIRECTORY
, sizeof(dir
) / sizeof(dir
[0]), dir
);
791 // Mark things as initialized...
797 for (count
= 0, temp
= first_
; temp
; temp
= temp
->next_
, count
++);
798 printf("count of Fl_File_Icon's is %d...\n", count
);
805 // 'load_kde_icons()' - Load KDE icon files.
809 load_kde_icons(const char *directory
, // I - Directory to load
810 const char *icondir
) { // I - Location of icons
811 int i
; // Looping var
812 int n
; // Number of entries in directory
813 dirent
**entries
; // Entries in directory
814 char full
[FL_PATH_MAX
]; // Full name of file
817 entries
= (dirent
**)0;
818 n
= fl_filename_list(directory
, &entries
);
820 for (i
= 0; i
< n
; i
++) {
821 if (entries
[i
]->d_name
[0] != '.') {
822 snprintf(full
, sizeof(full
), "%s/%s", directory
, entries
[i
]->d_name
);
824 if (fl_filename_isdir(full
)) load_kde_icons(full
, icondir
);
825 else load_kde_mimelnk(full
, icondir
);
828 free((void *)entries
[i
]);
831 free((void*)entries
);
836 // 'load_kde_mimelnk()' - Load a KDE "mimelnk" file.
840 load_kde_mimelnk(const char *filename
, // I - mimelnk filename
841 const char *icondir
) { // I - Location of icons
844 char iconfilename
[FL_PATH_MAX
];
848 char full_iconfilename
[FL_PATH_MAX
];
854 iconfilename
[0] = '\0';
856 if ((fp
= fl_fopen(filename
, "rb")) != NULL
) {
857 while (fgets(tmp
, sizeof(tmp
), fp
)) {
858 if ((val
= get_kde_val(tmp
, "Icon")) != NULL
)
859 strlcpy(iconfilename
, val
, sizeof(iconfilename
));
860 else if ((val
= get_kde_val(tmp
, "MimeType")) != NULL
)
861 strlcpy(mimetype
, val
, sizeof(mimetype
));
862 else if ((val
= get_kde_val(tmp
, "Patterns")) != NULL
)
863 strlcpy(pattern
, val
, sizeof(pattern
));
869 printf("%s: Icon=\"%s\", MimeType=\"%s\", Patterns=\"%s\"\n", filename
,
870 iconfilename
, mimetype
, pattern
);
873 if (!pattern
[0] && strncmp(mimetype
, "inode/", 6)) return;
875 if (iconfilename
[0]) {
876 if (iconfilename
[0] == '/') {
877 strlcpy(full_iconfilename
, iconfilename
, sizeof(full_iconfilename
));
878 } else if (!access(icondir
, F_OK
)) {
879 // KDE 3.x and 2.x icons
880 int i
; // Looping var
881 static const char *paths
[] = { // Subdirs to look in...
937 for (i
= 0; i
< (int)(sizeof(paths
) / sizeof(paths
[0])); i
++) {
938 snprintf(full_iconfilename
, sizeof(full_iconfilename
),
939 "%s/%s/%s.png", icondir
, paths
[i
], iconfilename
);
941 if (!access(full_iconfilename
, F_OK
)) break;
944 if (i
>= (int)(sizeof(paths
) / sizeof(paths
[0]))) return;
947 snprintf(full_iconfilename
, sizeof(full_iconfilename
),
948 "%s/%s", tmp
, iconfilename
);
950 if (access(full_iconfilename
, F_OK
)) return;
953 if (strncmp(mimetype
, "inode/", 6) == 0) {
954 if (!strcmp(mimetype
+ 6, "directory"))
955 icon
= new Fl_File_Icon("*", Fl_File_Icon::DIRECTORY
);
956 else if (!strcmp(mimetype
+ 6, "blockdevice"))
957 icon
= new Fl_File_Icon("*", Fl_File_Icon::DEVICE
);
958 else if (!strcmp(mimetype
+ 6, "fifo"))
959 icon
= new Fl_File_Icon("*", Fl_File_Icon::FIFO
);
962 icon
= new Fl_File_Icon(kde_to_fltk_pattern(pattern
),
963 Fl_File_Icon::PLAIN
);
966 icon
->load(full_iconfilename
);
973 // 'kde_to_fltk_pattern()' - Convert a KDE pattern to a FLTK pattern.
977 kde_to_fltk_pattern(const char *kdepattern
) {
982 pattern
= (char *)malloc(strlen(kdepattern
) + 3);
983 strcpy(pattern
, "{");
984 strcpy(pattern
+ 1, kdepattern
);
986 if (pattern
[strlen(pattern
) - 1] == ';') pattern
[strlen(pattern
) - 1] = '\0';
988 strcat(pattern
, "}");
990 for (patptr
= pattern
; *patptr
; patptr
++) {
991 if (*patptr
== ';') *patptr
= '|';
999 // 'get_kde_val()' - Get a KDE value.
1003 get_kde_val(char *str
,
1005 while (*str
== *key
) {
1010 if (*key
== '\0' && *str
== '=') {
1011 if (str
[strlen(str
) - 1] == '\n') str
[strlen(str
) - 1] = '\0';
1021 // End of "$Id: Fl_File_Icon2.cxx 8063 2010-12-19 21:20:10Z matt $".