Commit cda52677 authored by Dan Pascu's avatar Dan Pascu

Made IconManager thread safe

parent 2e3865b5
...@@ -2817,9 +2817,11 @@ class ContactModel(QAbstractListModel): ...@@ -2817,9 +2817,11 @@ class ContactModel(QAbstractListModel):
elif item.group.settings is all_contacts_group: elif item.group.settings is all_contacts_group:
removed_items.append(item.settings) 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] 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) icon = icon_manager.get(item.settings.id)
alternate_icon = icon_manager.get_image(item.settings.id + '_alt') icon_data = icon and icon.content
undo_operations.append(AddContactOperation(contact=RecallState(item.settings), group_ids=group_ids, icon=icon, alternate_icon=alternate_icon)) 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: elif item.group.settings not in removed_items:
item.group.settings.contacts.remove(item.settings) item.group.settings.contacts.remove(item.settings)
removed_members.append(item.group.settings) removed_members.append(item.group.settings)
......
...@@ -182,10 +182,10 @@ class PresencePublicationHandler(object): ...@@ -182,10 +182,10 @@ class PresencePublicationHandler(object):
state = BlinkPresenceState(account).offline_state state = BlinkPresenceState(account).offline_state
account.xcap_manager.set_offline_status(OfflineStatus(state) if state is not None else None) account.xcap_manager.set_offline_status(OfflineStatus(state) if state is not None else None)
if 'presence.icon' in notification.data.modified: if 'presence.icon' in notification.data.modified:
icon_data = IconManager().get_image('avatar') icon = IconManager().get('avatar')
icon = Icon(icon_data, 'image/png') if icon_data is not None else None 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): 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: 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): 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 account.presence_state = BlinkPresenceState(account).online_state
...@@ -242,9 +242,9 @@ class PresencePublicationHandler(object): ...@@ -242,9 +242,9 @@ class PresencePublicationHandler(object):
def _NH_SIPAccountDidDiscoverXCAPSupport(self, notification): def _NH_SIPAccountDidDiscoverXCAPSupport(self, notification):
account = notification.sender account = notification.sender
icon_data = IconManager().get_image('avatar') icon = IconManager().get('avatar')
if icon_data is not None: if icon is not None:
account.xcap_manager.set_status_icon(Icon(icon_data, 'image/png')) account.xcap_manager.set_status_icon(Icon(icon.content, icon.content_type))
@run_in_gui_thread @run_in_gui_thread
def _NH_XCAPManagerDidReloadData(self, notification): def _NH_XCAPManagerDidReloadData(self, notification):
......
...@@ -7,13 +7,12 @@ import os ...@@ -7,13 +7,12 @@ import os
import platform import platform
import sys import sys
from PyQt4.QtCore import Qt, QBuffer, QThread from PyQt4.QtCore import Qt, QBuffer
from PyQt4.QtGui import QApplication, QIcon, QPixmap from PyQt4.QtGui import QIcon, QPixmap
from application.python.descriptor import classproperty from application.python.descriptor import classproperty
from application.python.types import Singleton from application.python.types import Singleton
from application.system import makedirs, unlink from application.system import makedirs, unlink
from threading import Event
from sipsimple.configuration.datatypes import Path from sipsimple.configuration.datatypes import Path
from blink.util import run_in_gui_thread from blink.util import run_in_gui_thread
...@@ -92,6 +91,7 @@ class IconManager(object): ...@@ -92,6 +91,7 @@ class IconManager(object):
def __init__(self): def __init__(self):
self.iconmap = {} self.iconmap = {}
@run_in_gui_thread(wait=True)
def get(self, id): def get(self, id):
try: try:
return self.iconmap[id] return self.iconmap[id]
...@@ -107,31 +107,12 @@ class IconManager(object): ...@@ -107,31 +107,12 @@ class IconManager(object):
icon = QIcon(pixmap) icon = QIcon(pixmap)
icon.filename = filename icon.filename = filename
icon.content = data icon.content = data
icon.content_type = 'image/png'
else: else:
icon = None icon = None
return self.iconmap.setdefault(id, icon) return self.iconmap.setdefault(id, icon)
def get_image(self, id): @run_in_gui_thread(wait=True)
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
def store_data(self, id, data): def store_data(self, id, data):
directory = ApplicationData.get('images') directory = ApplicationData.get('images')
filename = os.path.join(directory, id + '.png') filename = os.path.join(directory, id + '.png')
...@@ -150,12 +131,14 @@ class IconManager(object): ...@@ -150,12 +131,14 @@ class IconManager(object):
icon = QIcon(pixmap) icon = QIcon(pixmap)
icon.filename = filename icon.filename = filename
icon.content = data icon.content = data
icon.content_type = 'image/png'
else: else:
unlink(filename) unlink(filename)
icon = None icon = None
self.iconmap[id] = icon self.iconmap[id] = icon
return icon return icon
@run_in_gui_thread(wait=True)
def store_file(self, id, file): def store_file(self, id, file):
directory = ApplicationData.get('images') directory = ApplicationData.get('images')
filename = os.path.join(directory, id + '.png') filename = os.path.join(directory, id + '.png')
...@@ -174,12 +157,14 @@ class IconManager(object): ...@@ -174,12 +157,14 @@ class IconManager(object):
icon = QIcon(pixmap) icon = QIcon(pixmap)
icon.filename = filename icon.filename = filename
icon.content = data icon.content = data
icon.content_type = 'image/png'
else: else:
unlink(filename) unlink(filename)
icon = None icon = None
self.iconmap[id] = icon self.iconmap[id] = icon
return icon return icon
@run_in_gui_thread(wait=True)
def remove(self, id): def remove(self, id):
self.iconmap.pop(id, None) self.iconmap.pop(id, None)
unlink(ApplicationData.get(os.path.join('images', id + '.png'))) 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