refactor
This commit is contained in:
parent
44e5e7d0a6
commit
69a9c99e00
4 changed files with 23 additions and 25 deletions
|
@ -41,7 +41,7 @@ class MessageItem(QtGui.QListWidget):
|
||||||
def __init__(self, text, time, user='', message_type=TOX_MESSAGE_TYPE['NORMAL'], parent=None):
|
def __init__(self, text, time, user='', message_type=TOX_MESSAGE_TYPE['NORMAL'], parent=None):
|
||||||
QtGui.QListWidget.__init__(self, parent)
|
QtGui.QListWidget.__init__(self, parent)
|
||||||
self.name = QtGui.QLabel(self)
|
self.name = QtGui.QLabel(self)
|
||||||
self.name.setGeometry(QtCore.QRect(0, 0, 95, 20))
|
self.name.setGeometry(QtCore.QRect(0, 2, 95, 20))
|
||||||
self.name.setTextFormat(QtCore.Qt.PlainText)
|
self.name.setTextFormat(QtCore.Qt.PlainText)
|
||||||
font = QtGui.QFont()
|
font = QtGui.QFont()
|
||||||
font.setFamily("Times New Roman")
|
font.setFamily("Times New Roman")
|
||||||
|
|
|
@ -104,9 +104,9 @@ class Toxygen(object):
|
||||||
self.mainloop.start()
|
self.mainloop.start()
|
||||||
return self.tox
|
return self.tox
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Inner classes
|
# Inner classes
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
class InitThread(QtCore.QThread):
|
class InitThread(QtCore.QThread):
|
||||||
|
|
||||||
|
|
|
@ -173,7 +173,6 @@ class ProfileSettings(CenteredWidget):
|
||||||
Profile.get_instance().set_avatar(data)
|
Profile.get_instance().set_avatar(data)
|
||||||
|
|
||||||
def export_profile(self):
|
def export_profile(self):
|
||||||
# TODO: export history
|
|
||||||
directory = QtGui.QFileDialog.getExistingDirectory() + '/'
|
directory = QtGui.QFileDialog.getExistingDirectory() + '/'
|
||||||
ProfileHelper.export_profile(directory)
|
ProfileHelper.export_profile(directory)
|
||||||
settings = Settings.get_instance()
|
settings = Settings.get_instance()
|
||||||
|
@ -189,7 +188,6 @@ class ProfileSettings(CenteredWidget):
|
||||||
|
|
||||||
class NetworkSettings(CenteredWidget):
|
class NetworkSettings(CenteredWidget):
|
||||||
"""Network settings form: UDP, Ipv6 and proxy"""
|
"""Network settings form: UDP, Ipv6 and proxy"""
|
||||||
# TODO: add possibility to change network settings
|
|
||||||
def __init__(self, reset):
|
def __init__(self, reset):
|
||||||
super(NetworkSettings, self).__init__()
|
super(NetworkSettings, self).__init__()
|
||||||
self.reset = reset
|
self.reset = reset
|
||||||
|
|
|
@ -304,12 +304,12 @@ class Profile(Contact, Singleton):
|
||||||
screen.online_contacts.setChecked(self.show_online)
|
screen.online_contacts.setChecked(self.show_online)
|
||||||
aliases = settings['friends_aliases']
|
aliases = settings['friends_aliases']
|
||||||
data = tox.self_get_friend_list()
|
data = tox.self_get_friend_list()
|
||||||
self.history = History(tox.self_get_public_key()) # connection to db
|
self._history = History(tox.self_get_public_key()) # connection to db
|
||||||
self._friends, self._active_friend = [], -1
|
self._friends, self._active_friend = [], -1
|
||||||
for i in data: # creates list of friends
|
for i in data: # creates list of friends
|
||||||
tox_id = tox.friend_get_public_key(i)
|
tox_id = tox.friend_get_public_key(i)
|
||||||
if not self.history.friend_exists_in_db(tox_id):
|
if not self._history.friend_exists_in_db(tox_id):
|
||||||
self.history.add_friend_to_db(tox_id)
|
self._history.add_friend_to_db(tox_id)
|
||||||
try:
|
try:
|
||||||
alias = filter(lambda x: x[0] == tox_id, aliases)[0][1]
|
alias = filter(lambda x: x[0] == tox_id, aliases)[0][1]
|
||||||
except:
|
except:
|
||||||
|
@ -317,7 +317,7 @@ class Profile(Contact, Singleton):
|
||||||
item = self.create_friend_item()
|
item = self.create_friend_item()
|
||||||
name = alias or tox.friend_get_name(i) or tox_id
|
name = alias or tox.friend_get_name(i) or tox_id
|
||||||
status_message = tox.friend_get_status_message(i)
|
status_message = tox.friend_get_status_message(i)
|
||||||
message_getter = self.history.messages_getter(tox_id)
|
message_getter = self._history.messages_getter(tox_id)
|
||||||
friend = Friend(message_getter, i, name, status_message, item, tox_id)
|
friend = Friend(message_getter, i, name, status_message, item, tox_id)
|
||||||
friend.set_alias(alias)
|
friend.set_alias(alias)
|
||||||
self._friends.append(friend)
|
self._friends.append(friend)
|
||||||
|
@ -499,24 +499,24 @@ class Profile(Contact, Singleton):
|
||||||
if Settings.get_instance()['save_history']:
|
if Settings.get_instance()['save_history']:
|
||||||
for friend in self._friends:
|
for friend in self._friends:
|
||||||
messages = friend.get_corr_for_saving()
|
messages = friend.get_corr_for_saving()
|
||||||
self.history.save_messages_to_db(friend.tox_id, messages)
|
self._history.save_messages_to_db(friend.tox_id, messages)
|
||||||
del self.history
|
del self._history
|
||||||
|
|
||||||
def clear_history(self, num=None):
|
def clear_history(self, num=None):
|
||||||
if num is not None:
|
if num is not None:
|
||||||
friend = self._friends[num]
|
friend = self._friends[num]
|
||||||
friend.clear_corr()
|
friend.clear_corr()
|
||||||
self.history.delete_messages(friend.tox_id)
|
self._history.delete_messages(friend.tox_id)
|
||||||
else: # clear all history
|
else: # clear all history
|
||||||
for friend in self._friends:
|
for friend in self._friends:
|
||||||
friend.clear_corr()
|
friend.clear_corr()
|
||||||
self.history.delete_messages(friend.tox_id)
|
self._history.delete_messages(friend.tox_id)
|
||||||
self.history.delete_friend_from_db(friend.tox_id)
|
self._history.delete_friend_from_db(friend.tox_id)
|
||||||
if num is None or num == self.get_active_number():
|
if num is None or num == self.get_active_number():
|
||||||
self._messages.clear()
|
self._messages.clear()
|
||||||
|
|
||||||
def export_history(self, directory):
|
def export_history(self, directory):
|
||||||
self.history.export(directory)
|
self._history.export(directory)
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
# Factories for friend and message items
|
# Factories for friend and message items
|
||||||
|
@ -583,7 +583,7 @@ class Profile(Contact, Singleton):
|
||||||
"""
|
"""
|
||||||
friend = self._friends[num]
|
friend = self._friends[num]
|
||||||
self.clear_history(num)
|
self.clear_history(num)
|
||||||
self.history.delete_friend_from_db(friend.tox_id)
|
self._history.delete_friend_from_db(friend.tox_id)
|
||||||
self.tox.friend_delete(friend.number)
|
self.tox.friend_delete(friend.number)
|
||||||
del self._friends[num]
|
del self._friends[num]
|
||||||
self.screen.friends_list.takeItem(num)
|
self.screen.friends_list.takeItem(num)
|
||||||
|
@ -613,9 +613,9 @@ class Profile(Contact, Singleton):
|
||||||
result = self.tox.friend_add(tox_id, message.encode('utf-8'))
|
result = self.tox.friend_add(tox_id, message.encode('utf-8'))
|
||||||
tox_id = tox_id[:TOX_PUBLIC_KEY_SIZE * 2]
|
tox_id = tox_id[:TOX_PUBLIC_KEY_SIZE * 2]
|
||||||
item = self.create_friend_item()
|
item = self.create_friend_item()
|
||||||
if not self.history.friend_exists_in_db(tox_id):
|
if not self._history.friend_exists_in_db(tox_id):
|
||||||
self.history.add_friend_to_db(tox_id)
|
self._history.add_friend_to_db(tox_id)
|
||||||
message_getter = self.history.messages_getter(tox_id)
|
message_getter = self._history.messages_getter(tox_id)
|
||||||
friend = Friend(message_getter, result, tox_id, '', item, tox_id)
|
friend = Friend(message_getter, result, tox_id, '', item, tox_id)
|
||||||
self._friends.append(friend)
|
self._friends.append(friend)
|
||||||
return True
|
return True
|
||||||
|
@ -635,11 +635,11 @@ class Profile(Contact, Singleton):
|
||||||
if reply == QtGui.QMessageBox.Yes: # accepted
|
if reply == QtGui.QMessageBox.Yes: # accepted
|
||||||
num = self.tox.friend_add_norequest(tox_id) # num - friend number
|
num = self.tox.friend_add_norequest(tox_id) # num - friend number
|
||||||
item = self.create_friend_item()
|
item = self.create_friend_item()
|
||||||
if not self.history.friend_exists_in_db(tox_id):
|
if not self._history.friend_exists_in_db(tox_id):
|
||||||
self.history.add_friend_to_db(tox_id)
|
self._history.add_friend_to_db(tox_id)
|
||||||
if not self.history.friend_exists_in_db(tox_id):
|
if not self._history.friend_exists_in_db(tox_id):
|
||||||
self.history.add_friend_to_db(tox_id)
|
self._history.add_friend_to_db(tox_id)
|
||||||
message_getter = self.history.messages_getter(tox_id)
|
message_getter = self._history.messages_getter(tox_id)
|
||||||
friend = Friend(message_getter, num, tox_id, '', item, tox_id)
|
friend = Friend(message_getter, num, tox_id, '', item, tox_id)
|
||||||
self._friends.append(friend)
|
self._friends.append(friend)
|
||||||
except Exception as ex: # something is wrong
|
except Exception as ex: # something is wrong
|
||||||
|
|
Loading…
Reference in a new issue