Commit f9e8ace7 authored by Saul Ibarra's avatar Saul Ibarra

Fixed handling file URLs on different platforms

parent 50351870
......@@ -3,10 +3,11 @@
"""Definitions of datatypes for use in settings extensions."""
__all__ = ['ApplicationDataPath', 'DefaultPath', 'SoundFile', 'CustomSoundFile', 'HTTPURL', 'AuthorizationToken', 'InvalidToken', 'IconDescriptor', 'PresenceState', 'PresenceStateList']
__all__ = ['ApplicationDataPath', 'DefaultPath', 'SoundFile', 'CustomSoundFile', 'HTTPURL', 'FileURL', 'AuthorizationToken', 'InvalidToken', 'IconDescriptor', 'PresenceState', 'PresenceStateList']
import os
import re
from urllib import pathname2url, url2pathname
from urlparse import urlparse
from sipsimple.configuration.datatypes import Hostname, List
......@@ -136,11 +137,18 @@ class AuthorizationToken(str):
InvalidToken = AuthorizationToken() # a valid token is never empty
class FileURL(unicode):
def __new__(cls, value):
if not value.startswith('file:'):
value = 'file:' + pathname2url(os.path.abspath(value))
return unicode.__new__(cls, value)
class ParsedURL(unicode):
fragment = property(lambda self: self.__parsed__.fragment)
netloc = property(lambda self: self.__parsed__.netloc)
params = property(lambda self: self.__parsed__.params)
path = property(lambda self: self.__parsed__.path)
path = property(lambda self: self.__parsed__.path if self.scheme != 'file' else url2pathname(self.__parsed__.path))
query = property(lambda self: self.__parsed__.query)
scheme = property(lambda self: self.__parsed__.scheme)
......
......@@ -39,7 +39,7 @@ from sipsimple.configuration.settings import SIPSimpleSettings
from sipsimple.threading import run_in_thread, run_in_twisted_thread
from sipsimple.threading.green import Command, call_in_green_thread, run_in_green_thread
from blink.configuration.datatypes import AuthorizationToken, InvalidToken, IconDescriptor
from blink.configuration.datatypes import AuthorizationToken, InvalidToken, IconDescriptor, FileURL
from blink.resources import ApplicationData, Resources, IconManager
from blink.sessions import SessionManager
from blink.util import QSingleton, call_in_gui_thread, call_later, run_in_gui_thread
......@@ -2173,7 +2173,7 @@ class ContactModel(QAbstractListModel):
contact.name = name
contact.preferred_media = preferred_media
contact.uris = [addressbook.ContactURI(uri=uri, type='SIP')]
contact.icon = IconDescriptor('file://' + icon, unicode(int(os.stat(icon).st_mtime)))
contact.icon = IconDescriptor(FileURL(icon), unicode(int(os.stat(icon).st_mtime)))
return contact
test_group = addressbook.Group(id='test')
test_group.name = 'Test'
......@@ -2188,7 +2188,7 @@ class ContactModel(QAbstractListModel):
except KeyError:
continue
icon = entry['icon']
icon_descriptor = IconDescriptor('file://' + icon, unicode(int(os.stat(icon).st_mtime)))
icon_descriptor = IconDescriptor(FileURL(icon), unicode(int(os.stat(icon).st_mtime)))
if contact.icon != icon_descriptor:
icon_manager.store_file(contact.id, icon)
contact.icon = icon_descriptor
......@@ -4035,7 +4035,7 @@ class ContactEditorDialog(base_class, ui_class):
icon_manager.remove(contact.id + '_alt')
contact.alternate_icon = None
else:
icon_descriptor = IconDescriptor('file://' + self.icon_selector.filename, unicode(int(os.stat(self.icon_selector.filename).st_mtime)))
icon_descriptor = IconDescriptor(FileURL(self.icon_selector.filename), unicode(int(os.stat(self.icon_selector.filename).st_mtime)))
if contact.alternate_icon != icon_descriptor:
icon_manager.store_file(contact.id + '_alt', icon_descriptor.url.path)
contact.alternate_icon = icon_descriptor
......
......@@ -27,7 +27,7 @@ from blink.contacts import BonjourNeighbour, Contact, ContactEditorDialog, Conta
from blink.history import HistoryManager
from blink.preferences import PreferencesWindow
from blink.sessions import ConferenceDialog, SessionManager, SessionModel
from blink.configuration.datatypes import IconDescriptor, InvalidToken, PresenceState
from blink.configuration.datatypes import IconDescriptor, FileURL, InvalidToken, PresenceState
from blink.configuration.settings import BlinkSettings
from blink.presence import PendingWatcherDialog
from blink.resources import IconManager, Resources
......@@ -388,7 +388,7 @@ class MainWindow(base_class, ui_class):
icon_contents = icon_manager.get_image('avatar')
if icon_contents is not None:
hash = hashlib.sha512(icon_contents).hexdigest()
blink_settings.presence.icon = IconDescriptor('file://' + icon.filename, hash)
blink_settings.presence.icon = IconDescriptor(FileURL(icon.filename), hash)
else:
icon_manager.remove('avatar')
blink_settings.presence.icon = None
......
......@@ -32,7 +32,7 @@ from sipsimple.payloads import cipid; cipid # needs to be imported to register i
from sipsimple.threading.green import run_in_green_thread
from sipsimple.util import ISOTimestamp
from blink.configuration.datatypes import IconDescriptor, PresenceState
from blink.configuration.datatypes import IconDescriptor, FileURL, PresenceState
from blink.configuration.settings import BlinkSettings
from blink.resources import IconManager, Resources
from blink.util import run_in_gui_thread
......@@ -262,7 +262,7 @@ class PresencePublicationHandler(object):
icon_hash = hashlib.sha512(status_icon.data).hexdigest()
if not blink_settings.presence.icon or blink_settings.presence.icon.etag != icon_hash:
icon = icon_manager.store_data('avatar', status_icon.data)
blink_settings.presence.icon = IconDescriptor('file://' + icon.filename, icon_hash) if icon is not None else None
blink_settings.presence.icon = IconDescriptor(FileURL(icon.filename), icon_hash) if icon is not None else None
blink_settings.save()
else:
icon_desc = None
......
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