2016-03-01 22:17:22 +01:00
|
|
|
from list_items import MessageItem
|
2016-02-18 17:15:38 +01:00
|
|
|
from settings import Settings
|
2016-02-26 19:54:15 +01:00
|
|
|
from PySide import QtCore, QtGui
|
2016-02-18 17:15:38 +01:00
|
|
|
import os
|
2016-02-20 19:21:56 +01:00
|
|
|
from tox import Tox
|
|
|
|
from toxcore_enums_and_consts import *
|
|
|
|
from ctypes import *
|
2016-03-07 19:00:00 +01:00
|
|
|
from util import curr_time, log, Singleton, curr_directory
|
2016-02-18 17:15:38 +01:00
|
|
|
|
|
|
|
|
2016-02-25 21:40:00 +01:00
|
|
|
class ProfileHelper(object):
|
2016-02-26 15:32:36 +01:00
|
|
|
"""
|
|
|
|
Class with static methods for search, load and save profiles
|
|
|
|
"""
|
2016-02-18 17:15:38 +01:00
|
|
|
@staticmethod
|
|
|
|
def find_profiles():
|
|
|
|
path = Settings.get_default_path()
|
|
|
|
result = []
|
|
|
|
# check default path
|
|
|
|
for fl in os.listdir(path):
|
2016-02-18 17:52:12 +01:00
|
|
|
if fl.endswith('.tox'):
|
2016-02-18 17:15:38 +01:00
|
|
|
name = fl[:-4]
|
|
|
|
result.append((path, name))
|
|
|
|
path = os.path.dirname(os.path.abspath(__file__))
|
|
|
|
# check current directory
|
|
|
|
for fl in os.listdir(path):
|
2016-02-18 17:52:12 +01:00
|
|
|
if fl.endswith('.tox'):
|
2016-02-18 17:15:38 +01:00
|
|
|
name = fl[:-4]
|
|
|
|
result.append((path, name))
|
|
|
|
return result
|
|
|
|
|
2016-02-18 17:52:12 +01:00
|
|
|
@staticmethod
|
|
|
|
def open_profile(path, name):
|
2016-02-25 21:40:00 +01:00
|
|
|
ProfileHelper._path = path + name + '.tox'
|
|
|
|
with open(ProfileHelper._path, 'rb') as fl:
|
2016-02-18 17:52:12 +01:00
|
|
|
data = fl.read()
|
|
|
|
if data:
|
2016-02-25 21:40:00 +01:00
|
|
|
print 'Data loaded from: {}'.format(ProfileHelper._path)
|
2016-02-18 17:52:12 +01:00
|
|
|
return data
|
|
|
|
else:
|
2016-02-25 21:40:00 +01:00
|
|
|
raise IOError('Save file not found. Path: {}'.format(ProfileHelper._path))
|
2016-02-18 17:52:12 +01:00
|
|
|
|
|
|
|
@staticmethod
|
2016-02-25 10:35:42 +01:00
|
|
|
def save_profile(data, name=None):
|
|
|
|
if name is not None:
|
2016-02-25 21:40:00 +01:00
|
|
|
ProfileHelper._path = Settings.get_default_path() + name + '.tox'
|
|
|
|
with open(ProfileHelper._path, 'wb') as fl:
|
2016-02-18 17:52:12 +01:00
|
|
|
fl.write(data)
|
2016-02-25 21:40:00 +01:00
|
|
|
print 'Data saved to: {}'.format(ProfileHelper._path)
|
|
|
|
|
|
|
|
|
|
|
|
class Contact(object):
|
2016-02-26 15:32:36 +01:00
|
|
|
"""
|
|
|
|
Class encapsulating TOX contact
|
|
|
|
Properties: name (alias of contact or name), status_message, status (connection status)
|
|
|
|
number - unique number of friend in list, widget - widget for update
|
|
|
|
"""
|
2016-02-25 21:40:00 +01:00
|
|
|
|
2016-03-07 19:00:00 +01:00
|
|
|
def __init__(self, name, status_message, widget, tox_id):
|
2016-02-29 22:23:03 +01:00
|
|
|
self._name, self._status_message = name, status_message
|
2016-02-25 21:40:00 +01:00
|
|
|
self._status, self._widget = None, widget
|
|
|
|
widget.name.setText(name)
|
|
|
|
widget.status_message.setText(status_message)
|
2016-03-07 19:00:00 +01:00
|
|
|
self._tox_id = tox_id
|
2016-03-08 19:53:11 +01:00
|
|
|
self.load_avatar()
|
2016-02-25 21:40:00 +01:00
|
|
|
|
2016-03-04 20:03:20 +01:00
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
# name - current name or alias of user
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
def get_name(self):
|
2016-02-25 21:40:00 +01:00
|
|
|
return self._name
|
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
def set_name(self, value):
|
2016-02-29 22:23:03 +01:00
|
|
|
self._name = value.decode('utf-8')
|
|
|
|
self._widget.name.setText(self._name)
|
2016-02-28 22:33:35 +01:00
|
|
|
self._widget.name.repaint()
|
2016-02-25 21:40:00 +01:00
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
name = property(get_name, set_name)
|
2016-02-25 21:40:00 +01:00
|
|
|
|
2016-03-04 20:03:20 +01:00
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
# Status message
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
def get_status_message(self):
|
2016-02-25 21:40:00 +01:00
|
|
|
return self._status_message
|
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
def set_status_message(self, value):
|
2016-02-29 22:23:03 +01:00
|
|
|
self._status_message = value.decode('utf-8')
|
|
|
|
self._widget.status_message.setText(self._status_message)
|
2016-02-28 22:33:35 +01:00
|
|
|
self._widget.status_message.repaint()
|
2016-02-25 21:40:00 +01:00
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
status_message = property(get_status_message, set_status_message)
|
2016-02-25 21:40:00 +01:00
|
|
|
|
2016-03-04 20:03:20 +01:00
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
# Status
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
def get_status(self):
|
2016-02-25 21:40:00 +01:00
|
|
|
return self._status
|
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
def set_status(self, value):
|
2016-02-29 16:40:49 +01:00
|
|
|
self._widget.connection_status.data = self._status = value
|
|
|
|
self._widget.connection_status.repaint()
|
2016-02-25 21:40:00 +01:00
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
status = property(get_status, set_status)
|
2016-02-25 21:40:00 +01:00
|
|
|
|
2016-03-07 19:00:00 +01:00
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
# TOX ID. WARNING: for friend it will return public key, for profile - full address
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def get_tox_id(self):
|
|
|
|
return self._tox_id
|
|
|
|
|
|
|
|
tox_id = property(get_tox_id)
|
|
|
|
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
# Avatars
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def load_avatar(self):
|
|
|
|
avatar_path = (Settings.get_default_path() + 'avatars/{}.png').format(self._tox_id[:TOX_PUBLIC_KEY_SIZE * 2])
|
|
|
|
print 'Avatar', avatar_path
|
|
|
|
if not os.path.isfile(avatar_path): # load default image
|
|
|
|
avatar_path = curr_directory() + '/images/avatar.png'
|
|
|
|
pixmap = QtGui.QPixmap(QtCore.QSize(64, 64))
|
|
|
|
pixmap.scaled(64, 64, QtCore.Qt.KeepAspectRatio)
|
|
|
|
self._widget.avatar_label.setPixmap(avatar_path)
|
|
|
|
self._widget.avatar_label.repaint()
|
|
|
|
|
2016-02-25 21:40:00 +01:00
|
|
|
|
|
|
|
class Friend(Contact):
|
2016-02-26 15:32:36 +01:00
|
|
|
"""
|
2016-02-28 22:33:35 +01:00
|
|
|
Friend in list of friends. Can be hidden, property 'has unread messages' added
|
2016-02-26 15:32:36 +01:00
|
|
|
"""
|
2016-02-25 21:40:00 +01:00
|
|
|
|
2016-02-28 16:25:18 +01:00
|
|
|
def __init__(self, number, *args):
|
2016-02-25 21:40:00 +01:00
|
|
|
super(Friend, self).__init__(*args)
|
2016-02-28 16:25:18 +01:00
|
|
|
self._number = number
|
2016-02-25 21:40:00 +01:00
|
|
|
self._new_messages = False
|
2016-02-28 16:25:18 +01:00
|
|
|
self._visible = True
|
2016-03-08 19:53:11 +01:00
|
|
|
self._alias = False
|
2016-02-28 16:25:18 +01:00
|
|
|
|
2016-03-04 20:03:20 +01:00
|
|
|
def __del__(self):
|
|
|
|
self.set_visibility(False)
|
|
|
|
del self._widget
|
|
|
|
|
2016-03-08 19:53:11 +01:00
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
# Alias support
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def set_name(self, value):
|
|
|
|
if not self._alias:
|
|
|
|
super(self.__class__, self).set_name(value)
|
|
|
|
|
|
|
|
def set_alias(self, alias):
|
|
|
|
self._alias = bool(alias)
|
|
|
|
|
2016-03-04 20:03:20 +01:00
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
# Visibility in friends' list
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
def get_visibility(self):
|
2016-02-28 16:25:18 +01:00
|
|
|
return self._visible
|
2016-02-25 21:40:00 +01:00
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
def set_visibility(self, value):
|
2016-02-28 16:25:18 +01:00
|
|
|
self._visible = value
|
2016-03-02 17:05:03 +01:00
|
|
|
self._widget.setVisible(value)
|
2016-02-28 16:25:18 +01:00
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
visibility = property(get_visibility, set_visibility)
|
2016-02-25 21:40:00 +01:00
|
|
|
|
2016-03-04 20:03:20 +01:00
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
# Unread messages from friend
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
def get_messages(self):
|
|
|
|
return self._new_messages
|
|
|
|
|
|
|
|
def set_messages(self, value):
|
2016-03-05 17:44:44 +01:00
|
|
|
self._widget.connection_status.messages = self._new_messages = value
|
|
|
|
self._widget.connection_status.repaint()
|
2016-02-25 21:40:00 +01:00
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
messages = property(get_messages, set_messages)
|
2016-02-25 21:40:00 +01:00
|
|
|
|
2016-03-04 20:03:20 +01:00
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
# Friend's number (can be used in toxcore)
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
def get_number(self):
|
2016-02-25 21:40:00 +01:00
|
|
|
return self._number
|
|
|
|
|
2016-03-07 19:00:00 +01:00
|
|
|
def set_number(self, value):
|
|
|
|
self._number = value
|
|
|
|
|
|
|
|
number = property(get_number, set_number)
|
2016-02-25 21:40:00 +01:00
|
|
|
|
|
|
|
|
2016-03-06 13:44:52 +01:00
|
|
|
class Profile(Contact, Singleton):
|
2016-02-26 15:32:36 +01:00
|
|
|
"""
|
2016-02-28 22:33:35 +01:00
|
|
|
Profile of current toxygen user. Contains friends list, tox instance, list of messages
|
2016-02-26 15:32:36 +01:00
|
|
|
"""
|
2016-02-26 19:54:15 +01:00
|
|
|
def __init__(self, tox, widgets, widget, messages_list):
|
2016-03-07 19:00:00 +01:00
|
|
|
"""
|
|
|
|
:param tox: tox instance
|
|
|
|
:param widgets: list of widgets - friends' list
|
|
|
|
:param widget: widget in top-left corner with current user's data
|
|
|
|
:param messages_list: qlistwidget with messages
|
|
|
|
"""
|
2016-02-25 21:40:00 +01:00
|
|
|
self._widget = widget
|
2016-02-26 19:54:15 +01:00
|
|
|
self._messages = messages_list
|
2016-02-25 21:40:00 +01:00
|
|
|
self.tox = tox
|
2016-02-26 19:54:15 +01:00
|
|
|
self._name = tox.self_get_name()
|
|
|
|
self._status_message = tox.self_get_status_message()
|
|
|
|
self._status = None
|
2016-03-08 19:53:11 +01:00
|
|
|
settings = Settings.get_instance()
|
2016-03-03 20:19:09 +01:00
|
|
|
self.show_online = Settings.get_instance()['show_online_friends']
|
2016-03-08 19:53:11 +01:00
|
|
|
aliases = settings['friends_aliases']
|
2016-02-25 21:40:00 +01:00
|
|
|
data = tox.self_get_friend_list()
|
2016-02-29 16:40:49 +01:00
|
|
|
self._friends, num, self._active_friend = [], 0, -1
|
2016-02-25 21:40:00 +01:00
|
|
|
for i in data:
|
2016-03-07 19:00:00 +01:00
|
|
|
tox_id = tox.friend_get_public_key(i)
|
2016-03-08 19:53:11 +01:00
|
|
|
try:
|
|
|
|
alias = filter(lambda x: x[0] == tox_id, aliases)[0][1]
|
|
|
|
except:
|
|
|
|
alias = ''
|
|
|
|
name = alias or tox.friend_get_name(i) or tox_id
|
2016-02-25 21:40:00 +01:00
|
|
|
status_message = tox.friend_get_status_message(i)
|
2016-03-08 19:53:11 +01:00
|
|
|
friend = Friend(i, name, status_message, widgets[num], tox_id)
|
|
|
|
friend.set_alias(alias)
|
|
|
|
self._friends.append(friend)
|
2016-02-25 21:40:00 +01:00
|
|
|
num += 1
|
2016-02-29 22:23:03 +01:00
|
|
|
self.set_name(tox.self_get_name().encode('utf-8'))
|
|
|
|
self.set_status_message(tox.self_get_status_message().encode('utf-8'))
|
2016-03-02 17:05:03 +01:00
|
|
|
self.filtration(self.show_online)
|
2016-03-07 19:00:00 +01:00
|
|
|
self._tox_id = tox.self_get_address()
|
|
|
|
self.load_avatar()
|
2016-02-26 19:54:15 +01:00
|
|
|
|
2016-03-04 20:03:20 +01:00
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
# Edit current user's data
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
def change_status(self):
|
|
|
|
if self._status is not None:
|
2016-02-29 17:39:43 +01:00
|
|
|
status = (self._status + 1) % 3
|
|
|
|
super(self.__class__, self).set_status(status)
|
|
|
|
self.tox.self_set_status(status)
|
|
|
|
|
|
|
|
def set_name(self, value):
|
|
|
|
super(self.__class__, self).set_name(value)
|
2016-02-29 22:23:03 +01:00
|
|
|
self.tox.self_set_name(self._name.encode('utf-8'))
|
2016-02-29 17:39:43 +01:00
|
|
|
|
|
|
|
def set_status_message(self, value):
|
|
|
|
super(self.__class__, self).set_status_message(value)
|
2016-02-29 22:23:03 +01:00
|
|
|
self.tox.self_set_status_message(self._status_message.encode('utf-8'))
|
2016-02-28 22:33:35 +01:00
|
|
|
|
2016-03-04 20:03:20 +01:00
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
# Filtration
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
def filtration(self, show_online=True, filter_str=''):
|
2016-03-02 17:05:03 +01:00
|
|
|
# TODO: hide elements in list
|
2016-03-02 21:55:12 +01:00
|
|
|
filter_str = filter_str.lower()
|
2016-02-29 16:40:49 +01:00
|
|
|
for friend in self._friends:
|
2016-03-02 21:55:12 +01:00
|
|
|
friend.visibility = (friend.status is not None or not show_online) and (filter_str in friend.name.lower())
|
2016-03-02 17:05:03 +01:00
|
|
|
self.show_online, self.filter_string = show_online, filter_str
|
2016-02-28 22:33:35 +01:00
|
|
|
|
2016-03-07 19:00:00 +01:00
|
|
|
def update_filtration(self):
|
|
|
|
self.filtration(self.show_online, self.filter_string)
|
|
|
|
|
2016-02-29 16:40:49 +01:00
|
|
|
def get_friend_by_number(self, num):
|
|
|
|
return filter(lambda x: x.number == num, self._friends)[0]
|
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
# Work with active friend
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
def get_active(self):
|
2016-02-25 21:40:00 +01:00
|
|
|
return self._active_friend
|
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
def set_active(self, value):
|
2016-03-05 17:44:44 +01:00
|
|
|
# TODO: rewrite to work with filtering
|
|
|
|
if self._active_friend == value:
|
|
|
|
return False
|
2016-02-28 16:25:18 +01:00
|
|
|
try:
|
2016-02-29 16:40:49 +01:00
|
|
|
visible_friends = filter(lambda elem: elem[1].visibility, enumerate(self._friends))
|
2016-02-28 16:25:18 +01:00
|
|
|
self._active_friend = visible_friends[value][0]
|
2016-03-05 17:44:44 +01:00
|
|
|
self._friends[self._active_friend].set_messages(False)
|
2016-02-28 16:25:18 +01:00
|
|
|
# TODO: load history
|
|
|
|
except: # no friend found. ignore
|
|
|
|
log('Incorrect friend value: ' + str(value))
|
2016-03-05 17:44:44 +01:00
|
|
|
return True
|
2016-02-25 21:40:00 +01:00
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
active_friend = property(get_active, set_active)
|
2016-02-25 21:40:00 +01:00
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
def get_active_friend_data(self):
|
2016-02-29 16:40:49 +01:00
|
|
|
if self._active_friend != -1:
|
|
|
|
friend = self._friends[self._active_friend]
|
|
|
|
return friend.name, friend.status_message
|
|
|
|
else:
|
2016-02-29 17:39:43 +01:00
|
|
|
log('Something is wrong in get_active_friend_data')
|
2016-02-29 22:23:03 +01:00
|
|
|
return '', ''
|
2016-02-28 16:25:18 +01:00
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
def get_active_number(self):
|
2016-02-29 16:40:49 +01:00
|
|
|
return self._friends[self._active_friend].number
|
2016-02-25 21:40:00 +01:00
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
def get_active_name(self):
|
2016-02-29 16:40:49 +01:00
|
|
|
return self._friends[self._active_friend].name
|
2016-02-26 19:54:15 +01:00
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
def is_active_online(self):
|
2016-02-29 16:40:49 +01:00
|
|
|
return self._active_friend + 1 and self._friends[self._active_friend].status is not None
|
2016-02-18 17:52:12 +01:00
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
# Private messages
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
2016-02-28 16:25:18 +01:00
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
def new_message(self, id, message_type, message):
|
2016-03-07 19:00:00 +01:00
|
|
|
"""
|
|
|
|
Current user gets new message
|
|
|
|
:param id: id of friend who sent message
|
|
|
|
:param message_type: message type - plain text or actionmessage
|
|
|
|
:param message: text of message
|
|
|
|
"""
|
2016-02-26 19:54:15 +01:00
|
|
|
if id == self._active_friend: # add message to list
|
2016-02-28 22:33:35 +01:00
|
|
|
user_name = Profile.get_instance().get_active_name()
|
2016-03-04 18:52:52 +01:00
|
|
|
item = MessageItem(message.decode('utf-8'), curr_time(), user_name, message_type, self._messages)
|
2016-02-26 19:54:15 +01:00
|
|
|
elem = QtGui.QListWidgetItem(self._messages)
|
2016-03-04 18:52:52 +01:00
|
|
|
elem.setSizeHint(QtCore.QSize(500, item.getHeight()))
|
2016-02-26 19:54:15 +01:00
|
|
|
self._messages.addItem(elem)
|
|
|
|
self._messages.setItemWidget(elem, item)
|
|
|
|
self._messages.repaint()
|
|
|
|
else:
|
2016-02-29 16:40:49 +01:00
|
|
|
friend = filter(lambda x: x.number == id, self._friends)[0]
|
2016-02-28 22:33:35 +01:00
|
|
|
friend.set_messages(True)
|
2016-02-26 19:54:15 +01:00
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
def send_message(self, text):
|
2016-03-07 19:00:00 +01:00
|
|
|
"""
|
|
|
|
Send message to active friend
|
|
|
|
:param text: message text
|
|
|
|
:return: True on success
|
|
|
|
"""
|
2016-02-28 22:33:35 +01:00
|
|
|
if self.is_active_online() and text:
|
2016-03-04 18:52:52 +01:00
|
|
|
if text.startswith('/me '):
|
2016-02-28 16:25:18 +01:00
|
|
|
message_type = TOX_MESSAGE_TYPE['ACTION']
|
2016-03-04 18:52:52 +01:00
|
|
|
text = text[4:]
|
2016-02-28 16:25:18 +01:00
|
|
|
else:
|
|
|
|
message_type = TOX_MESSAGE_TYPE['NORMAL']
|
2016-02-28 22:33:35 +01:00
|
|
|
self.tox.friend_send_message(self._active_friend, message_type, text.encode('utf-8'))
|
2016-03-04 18:52:52 +01:00
|
|
|
item = MessageItem(text, curr_time(), self._name, message_type, self._messages)
|
2016-02-27 18:03:33 +01:00
|
|
|
elem = QtGui.QListWidgetItem(self._messages)
|
2016-03-04 18:52:52 +01:00
|
|
|
elem.setSizeHint(QtCore.QSize(500, item.getHeight()))
|
2016-02-27 18:03:33 +01:00
|
|
|
self._messages.addItem(elem)
|
|
|
|
self._messages.setItemWidget(elem, item)
|
|
|
|
self._messages.scrollToBottom()
|
|
|
|
self._messages.repaint()
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2016-02-28 22:33:35 +01:00
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
# Work with friends (add, remove)
|
|
|
|
# -----------------------------------------------------------------------------------------------------------------
|
|
|
|
|
2016-03-04 20:03:20 +01:00
|
|
|
# TODO: add friends
|
2016-02-28 22:33:35 +01:00
|
|
|
def delete_friend(self, num):
|
|
|
|
self.tox.friend_delete(num)
|
2016-02-29 16:40:49 +01:00
|
|
|
friend = filter(lambda x: x.number == num, self._friends)[0]
|
2016-02-28 22:33:35 +01:00
|
|
|
del friend
|
2016-02-26 19:54:15 +01:00
|
|
|
|
2016-02-20 19:21:56 +01:00
|
|
|
|
2016-02-23 22:03:50 +01:00
|
|
|
def tox_factory(data=None, settings=None):
|
2016-02-26 15:32:36 +01:00
|
|
|
"""
|
|
|
|
:param data: user data from .tox file. None = no saved data, create new profile
|
|
|
|
:param settings: current application settings. None = defaults settings will be used
|
|
|
|
:return: new tox instance
|
|
|
|
"""
|
2016-02-23 22:03:50 +01:00
|
|
|
if settings is None:
|
|
|
|
settings = Settings.get_default_settings()
|
2016-02-20 19:21:56 +01:00
|
|
|
tox_options = Tox.options_new()
|
|
|
|
tox_options.contents.udp_enabled = settings['udp_enabled']
|
|
|
|
tox_options.contents.proxy_type = settings['proxy_type']
|
|
|
|
tox_options.contents.proxy_host = settings['proxy_host']
|
|
|
|
tox_options.contents.proxy_port = settings['proxy_port']
|
|
|
|
tox_options.contents.start_port = settings['start_port']
|
|
|
|
tox_options.contents.end_port = settings['end_port']
|
|
|
|
tox_options.contents.tcp_port = settings['tcp_port']
|
2016-02-23 22:03:50 +01:00
|
|
|
if data: # load existing profile
|
|
|
|
tox_options.contents.savedata_type = TOX_SAVEDATA_TYPE['TOX_SAVE']
|
|
|
|
tox_options.contents.savedata_data = c_char_p(data)
|
|
|
|
tox_options.contents.savedata_length = len(data)
|
2016-02-25 12:22:15 +01:00
|
|
|
else: # create new profile
|
2016-02-23 22:03:50 +01:00
|
|
|
tox_options.contents.savedata_type = TOX_SAVEDATA_TYPE['NONE']
|
|
|
|
tox_options.contents.savedata_data = None
|
|
|
|
tox_options.contents.savedata_length = 0
|
2016-02-20 19:21:56 +01:00
|
|
|
return Tox(tox_options)
|