Fix MIME icon installation (#2458) and icon/mimetype info uninstallation
This commit is contained in:
parent
70940b8573
commit
8ff6cbab1e
@ -16,9 +16,13 @@
|
|||||||
|
|
||||||
import dbus
|
import dbus
|
||||||
import dbus.service
|
import dbus.service
|
||||||
|
import gnomevfs
|
||||||
|
import gtk
|
||||||
|
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
|
|
||||||
|
import bundleregistry
|
||||||
|
|
||||||
_REGISTRY_IFACE = "org.laptop.ObjectTypeRegistry"
|
_REGISTRY_IFACE = "org.laptop.ObjectTypeRegistry"
|
||||||
_REGISTRY_PATH = "/org/laptop/ObjectTypeRegistry"
|
_REGISTRY_PATH = "/org/laptop/ObjectTypeRegistry"
|
||||||
|
|
||||||
@ -53,6 +57,11 @@ class ObjectTypeRegistry(dbus.service.Object):
|
|||||||
'text-uri-list',
|
'text-uri-list',
|
||||||
['text/x-moz-url', 'text/uri-list'])
|
['text/x-moz-url', 'text/uri-list'])
|
||||||
|
|
||||||
|
self._activity_registry = bundleregistry.get_registry()
|
||||||
|
for bundle in self._activity_registry:
|
||||||
|
self._add_activity(self._activity_registry, bundle)
|
||||||
|
self._activity_registry.connect('bundle-added', self._add_activity)
|
||||||
|
|
||||||
def _add_primitive(self, type_id, name, icon, mime_types):
|
def _add_primitive(self, type_id, name, icon, mime_types):
|
||||||
object_type = {'type_id': type_id,
|
object_type = {'type_id': type_id,
|
||||||
'name': name,
|
'name': name,
|
||||||
@ -60,6 +69,30 @@ class ObjectTypeRegistry(dbus.service.Object):
|
|||||||
'mime_types': mime_types}
|
'mime_types': mime_types}
|
||||||
self._types[type_id] = object_type
|
self._types[type_id] = object_type
|
||||||
|
|
||||||
|
def _add_activity(self, activity_registry, bundle):
|
||||||
|
mime_types = bundle.get_mime_types()
|
||||||
|
if mime_types is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
icon_theme = gtk.icon_theme_get_default()
|
||||||
|
for mime_type in mime_types:
|
||||||
|
if self._get_type_for_mime(mime_type) is not None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
name = gnomevfs.mime_get_description(mime_type)
|
||||||
|
if name is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
icon = mime_type.replace('/', '-')
|
||||||
|
if icon_theme.lookup_icon(icon, gtk.ICON_SIZE_BUTTON, 0) is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
object_type = {'type_id': mime_type,
|
||||||
|
'name': name,
|
||||||
|
'icon': icon,
|
||||||
|
'mime_types': [mime_type]}
|
||||||
|
self._types[mime_type] = object_type
|
||||||
|
|
||||||
def _get_type_for_mime(self, mime_type):
|
def _get_type_for_mime(self, mime_type):
|
||||||
for object_type in self._types.values():
|
for object_type in self._types.values():
|
||||||
if mime_type in object_type['mime_types']:
|
if mime_type in object_type['mime_types']:
|
||||||
|
@ -213,8 +213,6 @@ class ActivityBundle(Bundle):
|
|||||||
self._unzip(install_dir)
|
self._unzip(install_dir)
|
||||||
|
|
||||||
install_path = os.path.join(install_dir, self._zip_root_dir)
|
install_path = os.path.join(install_dir, self._zip_root_dir)
|
||||||
if not activity.get_registry().add_bundle(install_path):
|
|
||||||
raise RegistrationException
|
|
||||||
|
|
||||||
xdg_data_home = os.getenv('XDG_DATA_HOME', os.path.expanduser('~/.local/share'))
|
xdg_data_home = os.getenv('XDG_DATA_HOME', os.path.expanduser('~/.local/share'))
|
||||||
|
|
||||||
@ -229,20 +227,54 @@ class ActivityBundle(Bundle):
|
|||||||
os.spawnlp(os.P_WAIT, 'update-mime-database',
|
os.spawnlp(os.P_WAIT, 'update-mime-database',
|
||||||
'update-mime-database', mime_dir)
|
'update-mime-database', mime_dir)
|
||||||
|
|
||||||
icons_dir = os.path.join(install_path, 'activity', 'mime-icons')
|
mime_types = self.get_mime_types()
|
||||||
if os.path.isdir(icons_dir):
|
if mime_types is not None:
|
||||||
installed_icons_dir = os.path.join(xdg_data_home, 'icons/sugar/scalable/mimetypes')
|
installed_icons_dir = os.path.join(xdg_data_home,
|
||||||
|
'icons/sugar/scalable/mimetypes')
|
||||||
if not os.path.isdir(installed_icons_dir):
|
if not os.path.isdir(installed_icons_dir):
|
||||||
os.makedirs(installed_icons_dir)
|
os.makedirs(installed_icons_dir)
|
||||||
for file in os.listdir(icons_dir):
|
|
||||||
if file.endswith('.svg') or file.endswith('.icon'):
|
for mime_type in mime_types:
|
||||||
os.symlink(os.path.join(icons_dir, file),
|
mime_icon_base = os.path.join(install_path, 'activity',
|
||||||
os.path.join(installed_icons_dir, file))
|
mime_type.replace('/', '-'))
|
||||||
|
svg_file = mime_icon_base + '.svg'
|
||||||
|
info_file = mime_icon_base + '.icon'
|
||||||
|
if os.path.isfile(svg_file):
|
||||||
|
os.symlink(svg_file,
|
||||||
|
os.path.join(installed_icons_dir,
|
||||||
|
os.path.basename(svg_file)))
|
||||||
|
if os.path.isfile(info_file):
|
||||||
|
os.symlink(info_file,
|
||||||
|
os.path.join(installed_icons_dir,
|
||||||
|
os.path.basename(info_file)))
|
||||||
|
|
||||||
|
if not activity.get_registry().add_bundle(install_path):
|
||||||
|
raise RegistrationException
|
||||||
|
|
||||||
def uninstall(self):
|
def uninstall(self):
|
||||||
if not self.is_installed():
|
if not self.is_installed():
|
||||||
raise NotInstalledException
|
raise NotInstalledException
|
||||||
|
|
||||||
|
xdg_data_home = os.getenv('XDG_DATA_HOME', os.path.expanduser('~/.local/share'))
|
||||||
|
|
||||||
|
mime_dir = os.path.join(xdg_data_home, 'mime')
|
||||||
|
installed_mime_path = os.path.join(mime_dir, 'packages', '%s.xml' % self._service_name)
|
||||||
|
if os.path.exists(installed_mime_path):
|
||||||
|
os.remove(installed_mime_path)
|
||||||
|
os.spawnlp(os.P_WAIT, 'update-mime-database',
|
||||||
|
'update-mime-database', mime_dir)
|
||||||
|
|
||||||
|
mime_types = self.get_mime_types()
|
||||||
|
if mime_types is not None:
|
||||||
|
installed_icons_dir = os.path.join(xdg_data_home,
|
||||||
|
'icons/sugar/scalable/mimetypes')
|
||||||
|
for file in os.listdir(installed_icons_dir):
|
||||||
|
path = os.path.join(installed_icons_dir, file)
|
||||||
|
if os.path.islink(path) and \
|
||||||
|
os.readlink(path).startswith(self._path):
|
||||||
|
os.remove(path)
|
||||||
|
|
||||||
self._uninstall()
|
self._uninstall()
|
||||||
|
|
||||||
# FIXME: notify shell
|
# FIXME: notify shell
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user