Commit cda52677 authored by Dan Pascu's avatar Dan Pascu

Made IconManager thread safe

parent 2e3865b5
......@@ -2817,9 +2817,11 @@ class ContactModel(QAbstractListModel):
elif item.group.settings is all_contacts_group:
removed_items.append(item.settings)
group_ids = [contact.group.settings.id for contact in self.iter_contacts() if contact.settings is item.settings and not contact.group.virtual]
icon = icon_manager.get_image(item.settings.id)
alternate_icon = icon_manager.get_image(item.settings.id + '_alt')
undo_operations.append(AddContactOperation(contact=RecallState(item.settings), group_ids=group_ids, icon=icon, alternate_icon=alternate_icon))
icon = icon_manager.get(item.settings.id)
icon_data = icon and icon.content
alternate_icon = icon_manager.get(item.settings.id + '_alt')
alternate_icon_data = alternate_icon and alternate_icon.content
undo_operations.append(AddContactOperation(contact=RecallState(item.settings), group_ids=group_ids, icon=icon_data, alternate_icon=alternate_icon_data))
elif item.group.settings not in removed_items:
item.group.settings.contacts.remove(item.settings)
removed_members.append(item.group.settings)
......
......@@ -182,10 +182,10 @@ class PresencePublicationHandler(object):
state = BlinkPresenceState(account).offline_state
account.xcap_manager.set_offline_status(OfflineStatus(state) if state is not None else None)
if 'presence.icon' in notification.data.modified:
icon_data = IconManager().get_image('avatar')
icon = Icon(icon_data, 'image/png') if icon_data is not None else None
icon = IconManager().get('avatar')
status_icon = Icon(icon.content, icon.content_type) if icon is not None else None
for account in (account for account in account_manager.get_accounts() if account.xcap_available):
account.xcap_manager.set_status_icon(icon)
account.xcap_manager.set_status_icon(status_icon)
if 'presence.current_state' in notification.data.modified:
for account in (account for account in account_manager.get_accounts() if account.enabled and account.presence.enabled):
account.presence_state = BlinkPresenceState(account).online_state
......@@ -242,9 +242,9 @@ class PresencePublicationHandler(object):
def _NH_SIPAccountDidDiscoverXCAPSupport(self, notification):
account = notification.sender
icon_data = IconManager().get_image('avatar')
if icon_data is not None:
account.xcap_manager.set_status_icon(Icon(icon_data, 'image/png'))
icon = IconManager().get('avatar')
if icon is not None:
account.xcap_manager.set_status_icon(Icon(icon.content, icon.content_type))
@run_in_gui_thread
def _NH_XCAPManagerDidReloadData(self, notification):
......
......@@ -7,13 +7,12 @@ import os
import platform
import sys
from PyQt4.QtCore import Qt, QBuffer, QThread
from PyQt4.QtGui import QApplication, QIcon, QPixmap
from PyQt4.QtCore import Qt, QBuffer
from PyQt4.QtGui import QIcon, QPixmap
from application.python.descriptor import classproperty
from application.python.types import Singleton
from application.system import makedirs, unlink
from threading import Event
from sipsimple.configuration.datatypes import Path
from blink.util import run_in_gui_thread
......@@ -92,6 +91,7 @@ class IconManager(object):
def __init__(self):
self.iconmap = {}
@run_in_gui_thread(wait=True)
def get(self, id):
try:
return self.iconmap[id]
......@@ -107,31 +107,12 @@ class IconManager(object):
icon = QIcon(pixmap)
icon.filename = filename
icon.content = data
icon.content_type = 'image/png'
else:
icon = None
return self.iconmap.setdefault(id, icon)
def get_image(self, id):
application = QApplication.instance()
if QThread.currentThread() is application.thread():
icon = self.get(id)
else:
@run_in_gui_thread
def get_icon(id, event):
try:
event.icon = self.get(id)
except:
event.icon = None
finally:
event.set()
event = Event()
get_icon(id, event)
event.wait()
icon = event.icon
if icon is None:
return None
return icon.content
@run_in_gui_thread(wait=True)
def store_data(self, id, data):
directory = ApplicationData.get('images')
filename = os.path.join(directory, id + '.png')
......@@ -150,12 +131,14 @@ class IconManager(object):
icon = QIcon(pixmap)
icon.filename = filename
icon.content = data
icon.content_type = 'image/png'
else:
unlink(filename)
icon = None
self.iconmap[id] = icon
return icon
@run_in_gui_thread(wait=True)
def store_file(self, id, file):
directory = ApplicationData.get('images')
filename = os.path.join(directory, id + '.png')
......@@ -174,12 +157,14 @@ class IconManager(object):
icon = QIcon(pixmap)
icon.filename = filename
icon.content = data
icon.content_type = 'image/png'
else:
unlink(filename)
icon = None
self.iconmap[id] = icon
return icon
@run_in_gui_thread(wait=True)
def remove(self, id):
self.iconmap.pop(id, None)
unlink(ApplicationData.get(os.path.join('images', id + '.png')))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment