Revert "avatars support fixed"

This reverts commit 47c115e699.
This commit is contained in:
ingvar1995 2018-07-02 22:50:46 +03:00
parent 0adb9c1e52
commit bc48537209
11 changed files with 28 additions and 22 deletions

2
.gitignore vendored
View File

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

View File

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

View File

@ -14,13 +14,14 @@ class BaseContact:
Base class for all contacts. Base class for all contacts.
""" """
def __init__(self, name, status_message, widget, tox_id): def __init__(self, profile_manager, name, status_message, widget, tox_id):
""" """
:param name: name, example: 'Toxygen user' :param name: name, example: 'Toxygen user'
:param status_message: status message, example: 'Toxing on Toxygen' :param status_message: status message, example: 'Toxing on Toxygen'
:param widget: ContactItem instance :param widget: ContactItem instance
:param tox_id: tox id of contact :param tox_id: tox id of contact
""" """
self._profile_manager = profile_manager
self._name, self._status_message = name, status_message self._name, self._status_message = name, status_message
self._status, self._widget = None, widget self._status, self._widget = None, widget
self._tox_id = tox_id self._tox_id = tox_id
@ -143,7 +144,7 @@ class BaseContact:
return avatar_path return avatar_path
def get_contact_avatar_path(self): def get_contact_avatar_path(self):
directory = util.join_path(Settings.get_default_path(), 'avatars') directory = util.join_path(self._profile_manager.get_dir(), 'avatars')
return util.join_path(directory, '{}.png'.format(self._tox_id[:TOX_PUBLIC_KEY_SIZE * 2])) 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 Properties: number, message getter, history etc. Base class for friend and gc classes
""" """
def __init__(self, message_getter, number, name, status_message, widget, tox_id): def __init__(self, profile_manager, message_getter, number, name, status_message, widget, tox_id):
""" """
:param message_getter: gets messages from db :param message_getter: gets messages from db
:param number: number of friend. :param number: number of friend.
""" """
super().__init__(name, status_message, widget, tox_id) super().__init__(profile_manager, name, status_message, widget, tox_id)
self._number = number self._number = number
self._new_messages = False self._new_messages = False
self._visible = True self._visible = True

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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