Enable using parts of path in icon names (to work around KDEs stupid naming policies)

This commit is contained in:
Vedran Ljubovic 2006-08-26 15:47:41 +00:00
parent 4598668767
commit 02fd5fcfd6
3 changed files with 32 additions and 56 deletions

View File

@ -54,7 +54,7 @@ office/word|Word document|ooffice2.0|wordprocessing|||
office/word/doc|Word document (MS Word)|ooffice2.0|wordprocessing|.doc|Microsoft Office Document|application/msword
office/word/odt|Word document (OpenOffice.org 2.0)|ooffice2.0|wordprocessing|.odt|Zip archive data|
office/word/sxw|Word document (OpenOffice.org 1.x)|ooffice2.0|wordprocessing|.sxw|Zip archive data|
empty|Empty file|enotepad|misc-vedran||empty|
empty|Empty file|enotepad|mimetypes/misc||empty|
archive|Archive||tar||archive| # Consider using the term "Compressed file(s)"
archive/bz2|Archive (BZ2)||tar|.bz2|bzip2 compressed data|application/x-gzip
archive/gz|Archive (GZ)||tar|.gz|gzip compressed data|application/x-gzip
@ -68,7 +68,7 @@ install/makefile|Program instalation (source)|einstaller|make||make commands tex
install/rpm|Program installation (RPM)|einstaller|rpm|.rpm|RPM|application/x-rpm
program|Program|elauncher|empty|||
program/elf|Program|elauncher|empty||ELF 32-bit LSB executable|application/x-executable
program/elf/o|Program part||misc-vedran||ELF 32-bit LSB relocatable|application/x-object
program/elf/o|Program part||mimetypes/misc||ELF 32-bit LSB relocatable|application/x-object
program/jar|Java program|java -jar|empty|.jar|Zip archive data|application/x-zip
program/java-class|Java program|java|empty|.class|compiled Java class data|
program/swf|Macromedia Flash program|mozilla-firefox|empty|.swf|Macromedia Flash data|

View File

@ -13,6 +13,7 @@
#include <dirent.h>
#include <sys/stat.h>
#include <fltk/Group.h>
#include <fltk/filename.h>
#include "Icon.h"
#include "Config.h"
@ -64,63 +65,38 @@ void Icon::set_theme(const char *t)
// never lived. So we simply flatten the KDE directory
// structure.
// TODO: add support for xpm, use functions from fltk/filename.h
// Alternatively, if there are different icons in subdirs with
// same name, you can provide e.g. subdir/filename and it will
// work.
char *find_icon(const char *name, const char *directory)
const char *find_icon(const char *name, const char *directory)
{
DIR *my_dir;
struct dirent *my_dirent;
char filename[PATH_MAX];
dirent **files;
static char filename[PATH_MAX];
// Buffer for stat()
struct stat *buf = (struct stat*)malloc(sizeof(struct stat));
snprintf (filename, PATH_MAX, "%s/%s", directory, name);
if (filename_exist(filename)) return filename;
snprintf (filename, PATH_MAX, "%s/%s.png", directory, name);
if (filename_exist(filename)) return filename;
snprintf (filename, PATH_MAX, "%s/%s.xpm", directory, name);
if (filename_exist(filename)) return filename;
if (!(my_dir = opendir(directory)))
{
// Directory doesn't exist!
fprintf (stderr, "Edelib: ERROR: Theme %s is no more on disk :(\n", directory);
free(buf);
return 0;
// Look in subdirectories
const int num_files = filename_list(directory, &files);
char dirname[PATH_MAX];
for (int i=0; i<num_files; i++) {
if ((strcmp(files[i]->d_name,"./") == 0) || strcmp(files[i]->d_name,"../") == 0) continue;
snprintf (dirname, PATH_MAX, "%s/%s", directory, files[i]->d_name);
if (filename_isdir(dirname)) {
// Cut last slash
if (dirname[strlen(dirname)-1] == '/')
dirname[strlen(dirname)-1] = '\0';
const char *tmp = find_icon(name, dirname);
if (tmp) return tmp;
}
}
while ((my_dirent = readdir(my_dir)) != NULL)
{
// filename is a fully qualified path
snprintf (filename, sizeof(filename), "%s/%s", directory, my_dirent->d_name);
// strip .png part
char *work = strdup(my_dirent->d_name);
char *d = strrchr(work,'.');
if (d && (strcmp(d, ".png") == 0))
{
*d = '\0';
if (strcmp(work, name)==0)
{
//free(work); // this cause stack corruption sometimes!!
closedir(my_dir);
free(buf);
return strdup(filename); // found!
}
}
//free(work); // this cause stack corruption sometimes!!
// FIXME
// Let's try subdirectories
stat (filename, buf);
if (strcmp(my_dirent->d_name,".")!=0 && strcmp(my_dirent->d_name,"..")!=0 && S_ISDIR(buf->st_mode))
{
// filename is a directory, look inside:
char *tmp = find_icon(name, filename);
if (tmp) { // found
closedir(my_dir);
free(buf);
return tmp;
}
}
}
closedir(my_dir);
free(buf);
// not found
// Not found
return 0;
}
@ -136,9 +112,9 @@ Icon* Icon::get(const char *name, int size)
size=MEDIUM;
}
snprintf (directory, sizeof(directory), "%s/%s/%dx%d", iconspath, get_theme(), size, size);
snprintf (directory, PATH_MAX, "%s/%s/%dx%d", iconspath, get_theme(), size, size);
char *icon = find_icon(name, directory);
const char *icon = find_icon(name, directory);
if (!icon) // Fallback to icon from default theme, if not found
{
@ -157,7 +133,7 @@ Icon* Icon::get(const char *name, int size)
{
//fprintf(stderr,"Ikona: %s\n",icon);
Icon* i = (Icon*)pngImage::get(icon);
free(icon);
// free(icon); // no need to free icon
//i->transp_index(255);
//fprintf (stderr, "Name: %s Transp_index: %d Pixel type: %d\n", name, i->transp_index(), i->pixel_type());
return i;

View File

@ -27,7 +27,7 @@
#include <magic.h>
// I made this icon because on KDE there are stupidly two icons with same name
#define DEFAULT_ICON "misc-vedran"
#define DEFAULT_ICON "mimetypes/misc"
#define FOLDER_ICON "folder"
#define RECYCLED_ICON "recycled"
#define LOCKED_ICON "lockoverlay"