mirror of
https://github.com/edeproject/ede.git
synced 2023-08-10 21:13:03 +03:00
Enable using parts of path in icon names (to work around KDEs stupid naming policies)
This commit is contained in:
parent
4598668767
commit
02fd5fcfd6
@ -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/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/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|
|
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|Archive||tar||archive| # Consider using the term "Compressed file(s)"
|
||||||
archive/bz2|Archive (BZ2)||tar|.bz2|bzip2 compressed data|application/x-gzip
|
archive/bz2|Archive (BZ2)||tar|.bz2|bzip2 compressed data|application/x-gzip
|
||||||
archive/gz|Archive (GZ)||tar|.gz|gzip 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
|
install/rpm|Program installation (RPM)|einstaller|rpm|.rpm|RPM|application/x-rpm
|
||||||
program|Program|elauncher|empty|||
|
program|Program|elauncher|empty|||
|
||||||
program/elf|Program|elauncher|empty||ELF 32-bit LSB executable|application/x-executable
|
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/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/java-class|Java program|java|empty|.class|compiled Java class data|
|
||||||
program/swf|Macromedia Flash program|mozilla-firefox|empty|.swf|Macromedia Flash data|
|
program/swf|Macromedia Flash program|mozilla-firefox|empty|.swf|Macromedia Flash data|
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fltk/Group.h>
|
#include <fltk/Group.h>
|
||||||
|
#include <fltk/filename.h>
|
||||||
|
|
||||||
#include "Icon.h"
|
#include "Icon.h"
|
||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
@ -64,63 +65,38 @@ void Icon::set_theme(const char *t)
|
|||||||
// never lived. So we simply flatten the KDE directory
|
// never lived. So we simply flatten the KDE directory
|
||||||
// structure.
|
// 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;
|
dirent **files;
|
||||||
struct dirent *my_dirent;
|
static char filename[PATH_MAX];
|
||||||
char filename[PATH_MAX];
|
|
||||||
|
|
||||||
// Buffer for stat()
|
|
||||||
struct stat *buf = (struct stat*)malloc(sizeof(struct stat));
|
|
||||||
|
|
||||||
if (!(my_dir = opendir(directory)))
|
snprintf (filename, PATH_MAX, "%s/%s", directory, name);
|
||||||
{
|
if (filename_exist(filename)) return filename;
|
||||||
// Directory doesn't exist!
|
snprintf (filename, PATH_MAX, "%s/%s.png", directory, name);
|
||||||
fprintf (stderr, "Edelib: ERROR: Theme %s is no more on disk :(\n", directory);
|
if (filename_exist(filename)) return filename;
|
||||||
free(buf);
|
snprintf (filename, PATH_MAX, "%s/%s.xpm", directory, name);
|
||||||
return 0;
|
if (filename_exist(filename)) return filename;
|
||||||
}
|
|
||||||
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
|
// Look in subdirectories
|
||||||
char *work = strdup(my_dirent->d_name);
|
const int num_files = filename_list(directory, &files);
|
||||||
char *d = strrchr(work,'.');
|
char dirname[PATH_MAX];
|
||||||
if (d && (strcmp(d, ".png") == 0))
|
for (int i=0; i<num_files; i++) {
|
||||||
{
|
if ((strcmp(files[i]->d_name,"./") == 0) || strcmp(files[i]->d_name,"../") == 0) continue;
|
||||||
*d = '\0';
|
snprintf (dirname, PATH_MAX, "%s/%s", directory, files[i]->d_name);
|
||||||
if (strcmp(work, name)==0)
|
if (filename_isdir(dirname)) {
|
||||||
{
|
// Cut last slash
|
||||||
//free(work); // this cause stack corruption sometimes!!
|
if (dirname[strlen(dirname)-1] == '/')
|
||||||
closedir(my_dir);
|
dirname[strlen(dirname)-1] = '\0';
|
||||||
free(buf);
|
const char *tmp = find_icon(name, dirname);
|
||||||
return strdup(filename); // found!
|
if (tmp) return tmp;
|
||||||
}
|
|
||||||
}
|
|
||||||
//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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,9 +112,9 @@ Icon* Icon::get(const char *name, int size)
|
|||||||
size=MEDIUM;
|
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
|
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);
|
//fprintf(stderr,"Ikona: %s\n",icon);
|
||||||
Icon* i = (Icon*)pngImage::get(icon);
|
Icon* i = (Icon*)pngImage::get(icon);
|
||||||
free(icon);
|
// free(icon); // no need to free icon
|
||||||
//i->transp_index(255);
|
//i->transp_index(255);
|
||||||
//fprintf (stderr, "Name: %s Transp_index: %d Pixel type: %d\n", name, i->transp_index(), i->pixel_type());
|
//fprintf (stderr, "Name: %s Transp_index: %d Pixel type: %d\n", name, i->transp_index(), i->pixel_type());
|
||||||
return i;
|
return i;
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
#include <magic.h>
|
#include <magic.h>
|
||||||
|
|
||||||
// I made this icon because on KDE there are stupidly two icons with same name
|
// 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 FOLDER_ICON "folder"
|
||||||
#define RECYCLED_ICON "recycled"
|
#define RECYCLED_ICON "recycled"
|
||||||
#define LOCKED_ICON "lockoverlay"
|
#define LOCKED_ICON "lockoverlay"
|
||||||
|
Loading…
Reference in New Issue
Block a user