my python-script is ready. i reimplemented some moz-icon-parsing and i think that detecting the desktop-enviroment is also already implemented.
just port it, someone, and you are done (oh, and fix one minor TODO)
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys, os
from subprocess import Popen, PIPE
def detectDE():
if os.environ.get("KDE_FULL_SESSION") == "true":
return "kde"
elif os.environ.get("GNOME_DESKTOP_SESSION_ID"):
return "gnome"
elif os.environ.get("DISPLAY"):
return "x"
return None
url = sys.argv[1] + "?" #the "?" is a bugfix, since string.find() gives back a "-1" when nothing is found.
ext = url[url.find(".") : url.find("?")]
sizeindex = url.find("size=")
if sizeindex == -1: #"size=" not found => no size specified
size = 16
else:
sizeend = url.find("?",sizeindex)
size = int(url[sizeindex+5 : sizeend])
for s in [256,128,64,48,32,22,16]:
if size <= s:
sizestr = str(s) + "x" + str(s)
if detectDE() == "kde":
mime = Popen(["kmimetypefinder", "-f", ext], stdout=PIPE).communicate()[0] #finds mimetype for the extension on kde
if "\n" in mime: #a two-line-string is only the output if the mimetype is found
mime = mime[:mime.find("\n")] #remove the accuracy-line
mime = mime.replace("/","-") # using "-"-mimetypes is more bug-proof
iconpath = Popen(["kiconfinder", mime], stdout=PIPE).communicate()[0] #finds icon for mimetype
iconpath = iconpath.replace("\n","") #the line-end is removed
iconpath = iconpath.replace("48x48", sizestr) #replaces icon size 48×48 with the size specified
else:
iconpath = "generic icon path" #to be replaced
print(iconpath) #the output: you will want to change this to "return iconpath" after making all of this a c++-method ;)
#TODO: Check if requested image size exists and if not, try other sizes
my python-script is ready. i reimplemented some moz-icon-parsing and i think that detecting the desktop-enviroment is also already implemented.
just port it, someone, and you are done (oh, and fix one minor TODO)
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys, os
from subprocess import Popen, PIPE
def detectDE(): get("KDE_ FULL_SESSION" ) == "true": get("GNOME_ DESKTOP_ SESSION_ ID"): get("DISPLAY" ):
if os.environ.
return "kde"
elif os.environ.
return "gnome"
elif os.environ.
return "x"
return None
url = sys.argv[1] + "?" #the "?" is a bugfix, since string.find() gives back a "-1" when nothing is found.
ext = url[url.find(".") : url.find("?")]
sizeindex = url.find("size=") "?",sizeindex)
if sizeindex == -1: #"size=" not found => no size specified
size = 16
else:
sizeend = url.find(
size = int(url[sizeindex+5 : sizeend])
for s in [256,128, 64,48,32, 22,16]:
if size <= s:
sizestr = str(s) + "x" + str(s)
if detectDE() == "kde": "kmimetypefinde r", "-f", ext], stdout= PIPE).communica te()[0] #finds mimetype for the extension on kde find("\ n")] #remove the accuracy-line "/","-" ) # using "-"-mimetypes is more bug-proof "kiconfinder" , mime], stdout= PIPE).communica te()[0] #finds icon for mimetype replace( "\n","" ) #the line-end is removed replace( "48x48" , sizestr) #replaces icon size 48×48 with the size specified
mime = Popen([
if "\n" in mime: #a two-line-string is only the output if the mimetype is found
mime = mime[:mime.
mime = mime.replace(
iconpath = Popen([
iconpath = iconpath.
iconpath = iconpath.
else:
iconpath = "generic icon path" #to be replaced
print(iconpath) #the output: you will want to change this to "return iconpath" after making all of this a c++-method ;)
#TODO: Check if requested image size exists and if not, try other sizes