avatars support fixed

This commit is contained in:
ingvar1995 2018-06-30 14:56:41 +03:00
parent b2ecf5314e
commit 47c115e699
11 changed files with 22 additions and 28 deletions

2
.gitignore vendored
View file

@ -24,3 +24,5 @@ html
Toxygen.egg-info
*.tox
.cache
*.db

View file

@ -332,11 +332,11 @@ class App:
db = Database(self._path.replace('.tox', '.db'), self._toxes)
contact_items_factory = ContactItemsFactory(self._settings, self._ms)
self._friend_factory = FriendFactory(self._profile_manager, self._settings,
self._friend_factory = FriendFactory(self._settings,
self._tox, db, contact_items_factory)
self._group_factory = GroupFactory(self._profile_manager, self._settings, self._tox, db, contact_items_factory)
self._group_factory = GroupFactory(self._settings, self._tox, db, contact_items_factory)
self._contacts_provider = ContactProvider(self._tox, self._friend_factory, self._group_factory)
self._profile = Profile(self._profile_manager, self._tox, self._ms, self._contacts_provider, self._reset)
self._profile = Profile(self._tox, self._ms, self._contacts_provider, self._reset)
self._plugin_loader = PluginLoader(self._tox, self._toxes, self._profile, self._settings)
history = None
messages_items_factory = MessagesItemsFactory(self._settings, self._plugin_loader, self._smiley_loader,

View file

@ -14,14 +14,13 @@ class BaseContact:
Base class for all contacts.
"""
def __init__(self, profile_manager, name, status_message, widget, tox_id):
def __init__(self, name, status_message, widget, tox_id):
"""
:param name: name, example: 'Toxygen user'
:param status_message: status message, example: 'Toxing on Toxygen'
:param widget: ContactItem instance
:param tox_id: tox id of contact
"""
self._profile_manager = profile_manager
self._name, self._status_message = name, status_message
self._status, self._widget = None, widget
self._tox_id = tox_id
@ -144,7 +143,7 @@ class BaseContact:
return avatar_path
def get_contact_avatar_path(self):
directory = util.join_path(self._profile_manager.get_dir(), 'avatars')
directory = util.join_path(Settings.get_default_path(), 'avatars')
return util.join_path(directory, '{}.png'.format(self._tox_id[:TOX_PUBLIC_KEY_SIZE * 2]))

View file

@ -12,12 +12,12 @@ class Contact(basecontact.BaseContact):
Properties: number, message getter, history etc. Base class for friend and gc classes
"""
def __init__(self, profile_manager, message_getter, number, name, status_message, widget, tox_id):
def __init__(self, message_getter, number, name, status_message, widget, tox_id):
"""
:param message_getter: gets messages from db
:param number: number of friend.
"""
super().__init__(profile_manager, name, status_message, widget, tox_id)
super().__init__(name, status_message, widget, tox_id)
self._number = number
self._new_messages = False
self._visible = True

View file

@ -9,8 +9,8 @@ class Friend(contact.Contact):
Friend in list of friends.
"""
def __init__(self, profile_manager, message_getter, number, name, status_message, widget, tox_id):
super().__init__(profile_manager, message_getter, number, name, status_message, widget, tox_id)
def __init__(self, message_getter, number, name, status_message, widget, tox_id):
super().__init__(message_getter, number, name, status_message, widget, tox_id)
self._receipts = 0
self._typing_notification_handler = common.FriendTypingNotificationHandler(number)

View file

@ -4,9 +4,8 @@ from common.tox_save import ToxSave
class FriendFactory(ToxSave):
def __init__(self, profile_manager, settings, tox, db, items_factory):
def __init__(self, settings, tox, db, items_factory):
super().__init__(tox)
self._profile_manager = profile_manager
self._settings = settings
self._db = db
self._items_factory = items_factory
@ -27,7 +26,7 @@ class FriendFactory(ToxSave):
name = alias or self._tox.friend_get_name(friend_number) or tox_id
status_message = self._tox.friend_get_status_message(friend_number)
message_getter = self._db.messages_getter(tox_id)
friend = Friend(self._profile_manager, message_getter, friend_number, name, status_message, item, tox_id)
friend = Friend(message_getter, friend_number, name, status_message, item, tox_id)
friend.set_alias(alias)
return friend

View file

@ -8,8 +8,8 @@ from common.tox_save import ToxSave
class GroupChat(contact.Contact, ToxSave):
def __init__(self, tox, profile_manager, message_getter, number, name, status_message, widget, tox_id):
super().__init__(profile_manager, message_getter, number, name, status_message, widget, tox_id)
def __init__(self, tox, message_getter, number, name, status_message, widget, tox_id):
super().__init__(message_getter, number, name, status_message, widget, tox_id)
ToxSave.__init__(self, tox)
self.set_status(constants.TOX_USER_STATUS['NONE'])
self._peers = []

View file

@ -4,9 +4,8 @@ from common.tox_save import ToxSave
class GroupFactory(ToxSave):
def __init__(self, profile_manager, settings, tox, db, items_factory):
def __init__(self, settings, tox, db, items_factory):
super().__init__(tox)
self._profile_manager = profile_manager
self._settings = settings
self._db = db
self._items_factory = items_factory
@ -27,7 +26,7 @@ class GroupFactory(ToxSave):
name = alias or self._tox.group_get_name(group_number) or tox_id
status_message = self._tox.group_get_topic(group_number)
message_getter = self._db.messages_getter(tox_id)
group = GroupChat(self._tox, self._profile_manager, message_getter, group_number, name, status_message,
group = GroupChat(self._tox, message_getter, group_number, name, status_message,
item, tox_id)
group.set_alias(alias)

View file

@ -3,8 +3,8 @@ import contacts.contact
class GroupPeerContact(contacts.contact.Contact):
def __init__(self, profile_manager, message_getter, peer_number, name, status_messsage, widget, tox_id, group_pk):
super().__init__(profile_manager, message_getter, peer_number, name, status_messsage, widget, tox_id)
def __init__(self, message_getter, peer_number, name, status_messsage, widget, tox_id, group_pk):
super().__init__(message_getter, peer_number, name, status_messsage, widget, tox_id)
self._group_pk = group_pk
def get_group_pk(self):

View file

@ -8,13 +8,12 @@ class Profile(basecontact.BaseContact, tox_save.ToxSave):
"""
Profile of current toxygen user. Contains friends list, tox instance
"""
def __init__(self, profile_manager, tox, screen, contacts_provider, reset_action):
def __init__(self, tox, screen, contacts_provider, reset_action):
"""
:param tox: tox instance
:param screen: ref to main screen
"""
basecontact.BaseContact.__init__(self,
profile_manager,
tox.self_get_name(),
tox.self_get_status_message(),
screen.user_info,

View file

@ -50,9 +50,6 @@ class FileTransfer:
self._finished_event = Event()
self._file_id = self._file = None
def set_tox(self, tox):
self._tox = tox
def set_state_changed_handler(self, handler):
self._state_changed_event += handler
@ -344,11 +341,10 @@ class ReceiveAvatar(ReceiveTransfer):
self.send_control(TOX_FILE_CONTROL['RESUME'])
def write_chunk(self, position, data):
super().write_chunk(position, data)
if self.state:
if data is None:
avatar_path = self._path[:-4]
if exists(avatar_path):
chdir(dirname(avatar_path))
remove(avatar_path)
rename(self._path, avatar_path)
self._finished()
super().write_chunk(position, data)