contact list loading

This commit is contained in:
ingvar1995 2018-04-30 22:28:33 +03:00
parent c81d9a3696
commit ddf6cd8328
9 changed files with 310 additions and 287 deletions

View File

@ -25,6 +25,7 @@ from av.calls_manager import CallsManager
from history.database import Database
from ui.widgets_factory import WidgetsFactory
from smileys.smileys import SmileyLoader
from ui.items_factory import ItemsFactory
class App:
@ -34,83 +35,16 @@ class App:
self._app = self._settings = self._profile_manager = self._plugin_loader = None
self._tox = self._ms = self._init = self._main_loop = self._av_loop = None
self._uri = self._toxes = self._tray = self._file_transfer_handler = self._contacts_provider = None
self._friend_factory = self._calls_manager = self._contacts_manager = None
self._friend_factory = self._calls_manager = self._contacts_manager = self._smiley_loader = None
if uri is not None and uri.startswith('tox:'):
self._uri = uri[4:]
self._path = path_to_profile
def enter_pass(self, data):
"""
Show password screen
"""
p = password_screen.PasswordScreen(self._toxes, data)
p.show()
self._app.lastWindowClosed.connect(self._app.quit)
self._app.exec_()
if p.result is not None:
return p.result
raise SystemExit()
# -----------------------------------------------------------------------------------------------------------------
# App executing
# -----------------------------------------------------------------------------------------------------------------
def main(self):
"""
Main function of app. loads login screen if needed and starts main screen
"""
self._app = QtWidgets.QApplication([])
icon_file = os.path.join(get_images_directory(), 'icon.png')
self._app.setWindowIcon(QtGui.QIcon(icon_file))
if get_platform() == 'Linux':
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_X11InitThreads)
with open(os.path.join(get_styles_directory(), 'dark_style.qss')) as fl:
style = fl.read()
self._app.setStyleSheet(style)
encrypt_save = tox_encrypt_save.ToxEncryptSave()
self._toxes = user_data.toxes.ToxES(encrypt_save)
if self._path is not None: # toxygen was started with path to profile
self.load_existing_profile(self._path)
else:
auto_profile = Settings.get_auto_profile()
if auto_profile is None: # no default profile
result = self.select_profile()
if result is None:
return
if result.is_new_profile(): # create new profile
self.create_new_profile(result.profile_path)
else: # load existing profile
self.load_existing_profile(result.profile_path)
self._path = result.profile_path
else: # default profile
path, name = auto_profile
self._path = os.path.join(path, name + '.tox')
self.load_existing_profile(self._path)
if Settings.is_active_profile(self._path): # profile is in use
profile_name = get_profile_name_from_path(self._path)
title = util_ui.tr('Profile {}').format(profile_name)
text = util_ui.tr('Other instance of Toxygen uses this profile or profile was not properly closed. Continue?')
reply = util_ui.question(text, title)
if not reply:
return
self._settings.set_active_profile()
self.load_app_styles()
self.load_app_translations()
if self.try_to_update():
return
self.create_dependencies()
self.start_threads()
if self._uri is not None:
self._ms.add_contact(self._uri)
self._app.lastWindowClosed.connect(self._app.quit)
# main
def _execute_app(self):
while True:
try:
self._app.exec_()
@ -122,41 +56,177 @@ class App:
else:
break
self.stop_app()
def stop_app(self):
def _stop_app(self):
self._plugin_loader.stop()
self.stop_threads()
self._stop_threads()
self._tray.hide()
self.save_profile()
self._save_profile()
self._settings.close()
del self._tox
def reset(self):
# -----------------------------------------------------------------------------------------------------------------
# App loading
# -----------------------------------------------------------------------------------------------------------------
def _load_base_style(self):
with open(join_path(get_styles_directory(), 'dark_style.qss')) as fl:
style = fl.read()
self._app.setStyleSheet(style)
def _load_app_styles(self):
# application color scheme
for theme in self._settings.built_in_themes().keys():
if self._settings['theme'] == theme:
with open(curr_directory(__file__) + self._settings.built_in_themes()[theme]) as fl:
style = fl.read()
self._app.setStyleSheet(style)
def _load_login_screen_translations(self):
current_language, supported_languages = self._get_languages()
if current_language in supported_languages:
lang_path = supported_languages[current_language]
translator = QtCore.QTranslator()
translator.load(get_translations_directory() + lang_path)
self._app.installTranslator(translator)
self._app.translator = translator
def _load_icon(self):
icon_file = os.path.join(get_images_directory(), 'icon.png')
self._app.setWindowIcon(QtGui.QIcon(icon_file))
@staticmethod
def _get_languages():
current_locale = QtCore.QLocale()
curr_language = current_locale.languageToString(current_locale.language())
supported_languages = Settings.supported_languages()
return curr_language, supported_languages
def _load_app_translations(self):
lang = Settings.supported_languages()[self._settings['language']]
translator = QtCore.QTranslator()
translator.load(os.path.join(get_translations_directory(), lang))
self._app.installTranslator(translator)
self._app.translator = translator
# -----------------------------------------------------------------------------------------------------------------
# Threads
# -----------------------------------------------------------------------------------------------------------------
def _start_threads(self):
# init thread
self._init = threads.InitThread(self._tox, self._plugin_loader, self._settings)
self._init.start()
# starting threads for tox iterate and toxav iterate
self._main_loop = threads.ToxIterateThread(self._tox)
self._main_loop.start()
self._av_loop = threads.ToxAVIterateThread(self._tox.AV)
self._av_loop.start()
threads.start_file_transfer_thread()
def _stop_threads(self):
self._init.stop_thread()
self._av_loop.stop_thread()
self._main_loop.stop_thread()
threads.stop_file_transfer_thread()
# -----------------------------------------------------------------------------------------------------------------
# Profiles
# -----------------------------------------------------------------------------------------------------------------
def _select_profile(self):
self._load_login_screen_translations()
ls = LoginScreen()
profiles = ProfileManager.find_profiles()
ls.update_select(profiles)
ls.show()
self._app.exec_()
return ls.result
def _load_existing_profile(self, profile_path):
self._settings = Settings(self._toxes, profile_path.replace('.tox', '.json'))
self._profile_manager = ProfileManager(self._settings, self._toxes, profile_path)
data = self._profile_manager.open_profile()
if self._toxes.is_data_encrypted(data):
data = self._enter_pass(data)
self._tox = self._create_tox(data)
def _create_new_profile(self, profile_path):
name = get_profile_name_from_path(profile_path) or 'toxygen_user'
if os.path.isfile(profile_path):
util_ui.message_box(util_ui.tr('Profile with this name already exists'),
util_ui.tr('Error'))
return
self._tox = tox_factory()
self._tox.self_set_name(bytes(name, 'utf-8') if name else b'Toxygen User')
self._tox.self_set_status_message(b'Toxing on Toxygen')
# TODO: set profile password
self._settings = Settings(self._toxes, self._path.replace('.tox', '.json'))
self._profile_manager = ProfileManager(self._settings, self._toxes, profile_path)
try:
self._save_profile()
except Exception as ex:
print(ex)
log('Profile creation exception: ' + str(ex))
text = util_ui.tr('Profile saving error! Does Toxygen have permission to write to this directory?')
util_ui.message_box(text, util_ui.tr('Error'))
return
current_language, supported_languages = self._get_languages()
if current_language in supported_languages:
self._settings['language'] = current_language
self._settings.save()
def _save_profile(self, data=None):
data = data or self._tox.get_savedata()
self._profile_manager.save_profile(data)
# -----------------------------------------------------------------------------------------------------------------
# Other private methods
# -----------------------------------------------------------------------------------------------------------------
def _enter_pass(self, data):
"""
Show password screen
"""
p = password_screen.PasswordScreen(self._toxes, data)
p.show()
self._app.lastWindowClosed.connect(self._app.quit)
self._app.exec_()
if p.result is not None:
return p.result
raise SystemExit()
def _reset(self):
"""
Create new tox instance (new network settings)
:return: tox instance
"""
self.stop_threads()
self._stop_threads()
data = self._tox.get_savedata()
self.save_profile(data)
self._save_profile(data)
del self._tox
# create new tox instance
self._tox = self.create_tox(data)
self.start_threads()
self._tox = self._create_tox(data)
self._start_threads()
# TODO: foreach in list of tox savers set_tox
return self._tox
def create_dependencies(self):
def _create_dependencies(self):
self._smiley_loader = SmileyLoader(self._settings)
self._ms = MainWindow(self._settings, self._tox, self._tray)
db = Database(self._path.replace('.tox', '.db'), self._toxes)
self._friend_factory = FriendFactory(self._profile_manager, self._settings, self._tox, db)
self._contacts_provider = ContactProvider(self._tox, self._friend_factory)
profile = Profile(self._profile_manager, self._tox, self._ms, self._file_transfer_handler)
self._smiley_loader = SmileyLoader(self._settings)
self._plugin_loader = PluginLoader(self._tox, self._toxes, profile, self._settings) # plugins support
items_factory = ItemsFactory(self._settings, self._plugin_loader, self._smiley_loader, self._ms)
self._friend_factory = FriendFactory(self._profile_manager, self._settings, self._tox, db, items_factory)
self._contacts_provider = ContactProvider(self._tox, self._friend_factory)
widgets_factory = WidgetsFactory(self._settings, profile, self._contacts_manager, self._file_transfer_handler,
self._smiley_loader, self._plugin_loader, self._toxes)
self._contacts_manager = ContactsManager(self._tox, self._settings, self._ms, self._profile_manager,
@ -175,113 +245,78 @@ class App:
callbacks.init_callbacks(self._tox, profile, self._settings, self._plugin_loader, self._contacts_manager,
self._calls_manager, self._file_transfer_handler, self._ms, self._tray)
def load_app_styles(self):
# application color scheme
for theme in self._settings.built_in_themes().keys():
if self._settings['theme'] == theme:
with open(curr_directory(__file__) + self._settings.built_in_themes()[theme]) as fl:
style = fl.read()
self._app.setStyleSheet(style)
def load_login_screen_translations(self):
current_language, supported_languages = self.get_languages()
if current_language in supported_languages:
lang_path = supported_languages[current_language]
translator = QtCore.QTranslator()
translator.load(get_translations_directory() + lang_path)
self._app.installTranslator(translator)
self._app.translator = translator
@staticmethod
def get_languages():
current_locale = QtCore.QLocale()
curr_language = current_locale.languageToString(current_locale.language())
supported_languages = Settings.supported_languages()
return curr_language, supported_languages
def load_app_translations(self):
lang = Settings.supported_languages()[self._settings['language']]
translator = QtCore.QTranslator()
translator.load(os.path.join(get_translations_directory(), lang))
self._app.installTranslator(translator)
self._app.translator = translator
def try_to_update(self):
def _try_to_update(self):
updating = updater.start_update_if_needed(self._version, self._settings)
if updating:
self.save_profile()
self._save_profile()
self._settings.close()
del self._tox
return updating
def start_threads(self):
# init thread
self._init = threads.InitThread(self._tox, self._plugin_loader, self._settings)
self._init.start()
# starting threads for tox iterate and toxav iterate
self._main_loop = threads.ToxIterateThread(self._tox)
self._main_loop.start()
self._av_loop = threads.ToxAVIterateThread(self._tox.AV)
self._av_loop.start()
threads.start_file_transfer_thread()
def stop_threads(self):
self._init.stop_thread()
self._av_loop.stop_thread()
self._main_loop.stop_thread()
threads.stop_file_transfer_thread()
def create_tox(self, data):
def _create_tox(self, data):
return tox_factory(data, self._settings)
def select_profile(self):
self.load_login_screen_translations()
ls = LoginScreen()
profiles = ProfileManager.find_profiles()
ls.update_select(profiles)
ls.show()
self._app.exec_()
# -----------------------------------------------------------------------------------------------------------------
# Public methods
# -----------------------------------------------------------------------------------------------------------------
return ls.result
def main(self):
"""
Main function of app. loads login screen if needed and starts main screen
"""
self._app = QtWidgets.QApplication([])
self._load_icon()
def load_existing_profile(self, profile_path):
self._settings = Settings(self._toxes, profile_path.replace('.tox', '.json'))
self._profile_manager = ProfileManager(self._settings, self._toxes, profile_path)
data = self._profile_manager.open_profile()
if self._toxes.is_data_encrypted(data):
data = self.enter_pass(data)
self._tox = self.create_tox(data)
if get_platform() == 'Linux':
QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_X11InitThreads)
def create_new_profile(self, profile_path):
name = get_profile_name_from_path(profile_path) or 'toxygen_user'
if os.path.isfile(profile_path):
util_ui.message_box(util_ui.tr('Profile with this name already exists'),
util_ui.tr('Error'))
self._load_base_style()
encrypt_save = tox_encrypt_save.ToxEncryptSave()
self._toxes = user_data.toxes.ToxES(encrypt_save)
if self._path is not None: # toxygen was started with path to profile
self._load_existing_profile(self._path)
else:
auto_profile = Settings.get_auto_profile()
if auto_profile is None: # no default profile
result = self._select_profile()
if result is None:
return
self._tox = tox_factory()
self._tox.self_set_name(bytes(name, 'utf-8') if name else b'Toxygen User')
self._tox.self_set_status_message(b'Toxing on Toxygen')
# TODO: set profile password
self._settings = Settings(self._toxes, self._path.replace('.tox', '.json'))
self._profile_manager = ProfileManager(self._settings, self._toxes, profile_path)
try:
self.save_profile()
except Exception as ex:
print(ex)
log('Profile creation exception: ' + str(ex))
text = util_ui.tr('Profile saving error! Does Toxygen have permission to write to this directory?')
util_ui.message_box(text, util_ui.tr('Error'))
return
current_language, supported_languages = self.get_languages()
if current_language in supported_languages:
self._settings['language'] = current_language
self._settings.save()
if result.is_new_profile(): # create new profile
self._create_new_profile(result.profile_path)
else: # load existing profile
self._load_existing_profile(result.profile_path)
self._path = result.profile_path
else: # default profile
path, name = auto_profile
self._path = os.path.join(path, name + '.tox')
self._load_existing_profile(self._path)
def save_profile(self, data=None):
data = data or self._tox.get_savedata()
self._profile_manager.save_profile(data)
if Settings.is_active_profile(self._path): # profile is in use
profile_name = get_profile_name_from_path(self._path)
title = util_ui.tr('Profile {}').format(profile_name)
text = util_ui.tr('Other instance of Toxygen uses this profile or profile was not properly closed. Continue?')
reply = util_ui.question(text, title)
if not reply:
return
self._settings.set_active_profile()
self._load_app_styles()
self._load_app_translations()
if self._try_to_update():
return
self._create_dependencies()
self._start_threads()
if self._uri is not None:
self._ms.add_contact(self._uri)
self._app.lastWindowClosed.connect(self._app.quit)
self._execute_app()
self._stop_app()

View File

@ -12,7 +12,7 @@ class Contact(basecontact.BaseContact):
Properties: number, message getter, history etc. Base class for friend and gc classes
"""
def __init__(self, message_getter, number, profile_manager, 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 number: number of friend.

View File

@ -46,13 +46,13 @@ class ContactProvider(util.ToxSave):
# GC
# -----------------------------------------------------------------------------------------------------------------
def get_all_gc(self):
def get_all_groups(self):
return []
def get_gc_by_number(self):
def get_group_by_number(self):
pass
def get_gc_by_public_key(self):
def get_group_by_public_key(self):
pass
# -----------------------------------------------------------------------------------------------------------------

View File

@ -2,7 +2,7 @@ import util.util as util
import util.ui as util_ui
from contacts.friend import Friend
import os
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5 import QtCore, QtGui
from messenger.messages import *
from wrapper.toxcore_enums_and_consts import *
from network.tox_dns import tox_dns
@ -29,36 +29,25 @@ class ContactsManager:
def __del__(self):
del self._history
# -----------------------------------------------------------------------------------------------------------------
# Private methods
# -----------------------------------------------------------------------------------------------------------------
def _is_active_a_friend(self):
return type(self.get_curr_contact()) is Friend
def _load_contacts(self):
self._load_friends()
self._load_groups()
# if len(self._contacts):
# self.set_active(0)
if len(self._contacts):
self.set_active(0)
self.filtration_and_sorting(self._sorting)
def _load_friends(self):
aliases = self._settings['friends_aliases']
friend_numbers = self._tox.self_get_friend_list()
for friend_number in friend_numbers: # creates list of friends
tox_id = self._tox.friend_get_public_key(friend_number)
try:
alias = list(filter(lambda x: x[0] == tox_id, aliases))[0][1]
except:
alias = ''
item = self.create_friend_item()
name = alias or self._tox.friend_get_name(friend_number) or tox_id
status_message = self._tox.friend_get_status_message(friend_number)
self._history.get_message_getter(tox_id)
message_getter = self._history.get_message_getter(tox_id)
friend = Friend(self._profile_manager, message_getter, friend_number, name, status_message, item, tox_id)
friend.set_alias(alias)
self._contacts.append(friend)
self._contacts.extend(self._contact_provider.get_all_friends())
def _load_groups(self):
pass
self._contacts.extend(self._contact_provider.get_all_groups())
def get_friend(self, num):
if num < 0 or num >= len(self._contacts):
@ -101,7 +90,7 @@ class ContactsManager:
if value is not None:
if self._active_contact + 1 and self._active_contact != value:
try:
self.get_curr_friend().curr_text = self._screen.messageEdit.toPlainText()
self.get_curr_contact().curr_text = self._screen.messageEdit.toPlainText()
except:
pass
friend = self._contacts[value]
@ -113,49 +102,49 @@ class ContactsManager:
if not self._settings['save_history']:
friend.delete_old_messages()
self._messages.clear()
friend.load_corr()
messages = friend.get_corr()[-PAGE_SIZE:]
self._load_history = False
for message in messages:
if message.get_type() <= 1:
data = message.get_data()
self.create_message_item(data[0],
data[2],
data[1],
data[3])
elif message.get_type() == MESSAGE_TYPE['FILE_TRANSFER']:
if message.get_status() is None:
self.create_unsent_file_item(message)
continue
item = self.create_file_transfer_item(message)
if message.get_status() in ACTIVE_FILE_TRANSFERS: # active file transfer
try:
ft = self._file_transfers[(message.get_friend_number(), message.get_file_number())]
ft.set_state_changed_handler(item.update_transfer_state)
ft.signal()
except:
print('Incoming not started transfer - no info found')
elif message.get_type() == MESSAGE_TYPE['INLINE']: # inline
self.create_inline_item(message.get_data())
elif message.get_type() < 5: # info message
data = message.get_data()
self.create_message_item(data[0],
data[2],
'',
data[3])
# friend.load_corr()
# messages = friend.get_corr()[-PAGE_SIZE:]
# self._load_history = False
# for message in messages:
# if message.get_type() <= 1:
# data = message.get_data()
# self.create_message_item(data[0],
# data[2],
# data[1],
# data[3])
# elif message.get_type() == MESSAGE_TYPE['FILE_TRANSFER']:
# if message.get_status() is None:
# self.create_unsent_file_item(message)
# continue
# item = self.create_file_transfer_item(message)
# if message.get_status() in ACTIVE_FILE_TRANSFERS: # active file transfer
# try:
# ft = self._file_transfers[(message.get_friend_number(), message.get_file_number())]
# ft.set_state_changed_handler(item.update_transfer_state)
# ft.signal()
# except:
# print('Incoming not started transfer - no info found')
# elif message.get_type() == MESSAGE_TYPE['INLINE']: # inline
# self.create_inline_item(message.get_data())
# elif message.get_type() < 5: # info message
# data = message.get_data()
# self.create_message_item(data[0],
# data[2],
# '',
# data[3])
# else:
# data = message.get_data()
# self.create_gc_message_item(data[0], data[2], data[1], data[4], data[3])
# self._messages.scrollToBottom()
# self._load_history = True
# if value in self._call:
# self._screen.active_call()
# elif value in self._incoming_calls:
# self._screen.incoming_call()
# else:
# self._screen.call_finished()
else:
data = message.get_data()
self.create_gc_message_item(data[0], data[2], data[1], data[4], data[3])
self._messages.scrollToBottom()
self._load_history = True
if value in self._call:
self._screen.active_call()
elif value in self._incoming_calls:
self._screen.incoming_call()
else:
self._screen.call_finished()
else:
friend = self.get_curr_friend()
friend = self.get_curr_contact()
self._screen.account_name.setText(friend.name)
self._screen.account_status.setText(friend.status_message)
@ -239,12 +228,12 @@ class ContactsManager:
"""
self.filtration_and_sorting(self._sorting, self._filter_string)
def create_friend_item(self):
def _create_friend_item(self):
"""
Method-factory
:return: new widget for friend instance
"""
return None #self._factory.friend_item()
return self._factory.friend_item()
# -----------------------------------------------------------------------------------------------------------------
# Friend getters
@ -255,18 +244,18 @@ class ContactsManager:
def get_last_message(self):
if self._active_contact + 1:
return self.get_curr_friend().get_last_message_text()
return self.get_current_contact().get_last_message_text()
else:
return ''
def get_active_number(self):
return self.get_curr_friend().number if self._active_contact + 1 else -1
return self.get_curr_contact().number if self._active_contact + 1 else -1
def get_active_name(self):
return self.get_curr_friend().name if self._active_contact + 1 else ''
return self.get_current_contact().name if self._active_contact + 1 else ''
def is_active_online(self):
return self._active_contact + 1 and self.get_curr_friend().status is not None
return self._active_contact + 1 and self.get_current_contact().status is not None
def new_name(self, number, name):
friend = self.get_friend_by_number(number)
@ -274,7 +263,7 @@ class ContactsManager:
friend.set_name(name)
name = str(name, 'utf-8')
if friend.name == name and tmp != name:
message = QtWidgets.QApplication.translate("MainWindow", 'User {} is now known as {}')
message = util_ui.tr('User {} is now known as {}')
message = message.format(tmp, name)
friend.append_message(InfoMessage(message, time.time()))
friend.actions = True
@ -353,16 +342,8 @@ class ContactsManager:
"""
Adds friend to list
"""
num = self._tox.friend_add_norequest(tox_id) # num - friend number
item = self.create_friend_item()
try:
if not self._history.friend_exists_in_db(tox_id):
self._history.add_friend_to_db(tox_id)
message_getter = self._history.messages_getter(tox_id)
except Exception as ex: # something is wrong
util.log('Accept friend request failed! ' + str(ex))
message_getter = None
friend = Friend(message_getter, num, tox_id, '', item, tox_id)
self._tox.friend_add_norequest(tox_id)
friend = self._contact_provider.get_friend_by_public_key(tox_id)
self._contacts.append(friend)
def block_user(self, tox_id):
@ -459,9 +440,9 @@ class ContactsManager:
"""
if self._settings['typing_notifications'] and self._active_contact + 1:
try:
friend = self.get_curr_friend()
if friend.status is not None:
self._tox.self_set_typing(friend.number, typing)
contact = self.get_curr_contact()
if contact.status is not None and self._is_active_a_friend(): # TODO: fix - no type check
self._tox.self_set_typing(contact.number, typing)
except:
pass

View File

@ -3,10 +3,11 @@ from contacts.friend import Friend
class FriendFactory:
def __init__(self, profile_manager, settings, tox, db):
def __init__(self, profile_manager, settings, tox, db, items_factory):
self._profile_manager = profile_manager
self._settings, self._tox = settings, tox
self._db = db
self._factory = items_factory
def create_friend_by_number(self, friend_number):
aliases = self._settings['friends_aliases']

View File

@ -1,6 +1,6 @@
import app
from user_data.settings import *
from util.util import curr_directory, remove
from util.util import remove, get_libs_directory
import argparse
@ -10,8 +10,8 @@ __version__ = '0.5.0'
def clean():
"""Removes all windows libs from libs folder"""
d = os.path.join(curr_directory(__file__), 'libs')
remove(d)
directory = get_libs_directory()
remove(directory)
def reset():

View File

@ -8,11 +8,11 @@ class ItemsFactory:
self._smiley_loader, self._main_screen = smiley_loader, main_screen
def friend_item(self):
item = ContactItem()
elem = QtWidgets.QListWidgetItem(self._friends)
item = ContactItem(self._settings)
elem = QtWidgets.QListWidgetItem(self._main_screen.friends_list)
elem.setSizeHint(QtCore.QSize(250, item.height()))
self._friends.addItem(elem)
self._friends.setItemWidget(elem, item)
self._main_screen.friends_list.addItem(elem)
self._main_screen.friends_list.setItemWidget(elem, item)
return item
def message_item(self, text, time, name, sent, message_type, append, pixmap):

View File

@ -15,9 +15,9 @@ class ContactItem(QtWidgets.QWidget):
Contact in friends list
"""
def __init__(self, parent=None):
def __init__(self, settings, parent=None):
QtWidgets.QWidget.__init__(self, parent)
mode = settings.Settings.get_instance()['compact_mode']
mode = settings['compact_mode']
self.setBaseSize(QtCore.QSize(250, 40 if mode else 70))
self.avatar_label = QtWidgets.QLabel(self)
size = 32 if mode else 64
@ -27,7 +27,7 @@ class ContactItem(QtWidgets.QWidget):
self.name = DataLabel(self)
self.name.setGeometry(QtCore.QRect(50 if mode else 75, 3 if mode else 10, 150, 15 if mode else 25))
font = QtGui.QFont()
font.setFamily(settings.Settings.get_instance()['font'])
font.setFamily(settings['font'])
font.setPointSize(10 if mode else 12)
font.setBold(True)
self.name.setFont(font)
@ -38,7 +38,7 @@ class ContactItem(QtWidgets.QWidget):
self.status_message.setFont(font)
self.connection_status = StatusCircle(self)
self.connection_status.setGeometry(QtCore.QRect(230, -2 if mode else 5, 32, 32))
self.messages = UnreadMessagesCount(self)
self.messages = UnreadMessagesCount(settings, self)
self.messages.setGeometry(QtCore.QRect(20 if mode else 52, 20 if mode else 50, 30, 20))
@ -77,23 +77,24 @@ class StatusCircle(QtWidgets.QWidget):
class UnreadMessagesCount(QtWidgets.QWidget):
def __init__(self, parent=None):
super(UnreadMessagesCount, self).__init__(parent)
def __init__(self, settings, parent=None):
super().__init__(parent)
self._settings = settings
self.resize(30, 20)
self.label = QtWidgets.QLabel(self)
self.label.setGeometry(QtCore.QRect(0, 0, 30, 20))
self.label.setVisible(False)
font = QtGui.QFont()
font.setFamily(settings.Settings.get_instance()['font'])
font.setFamily(settings['font'])
font.setPointSize(12)
font.setBold(True)
self.label.setFont(font)
self.label.setAlignment(QtCore.Qt.AlignVCenter | QtCore.Qt.AlignCenter)
color = settings.Settings.get_instance()['unread_color']
color = settings['unread_color']
self.label.setStyleSheet('QLabel { color: white; background-color: ' + color + '; border-radius: 10; }')
def update(self, messages_count):
color = settings.Settings.get_instance()['unread_color']
color = self._settings['unread_color']
self.label.setStyleSheet('QLabel { color: white; background-color: ' + color + '; border-radius: 10; }')
if messages_count:
self.label.setVisible(True)

View File

@ -70,6 +70,11 @@ def get_plugins_directory():
return get_app_directory('plugins')
@cached
def get_libs_directory():
return get_app_directory('libs')
def get_app_directory(directory_name):
return os.path.join(get_base_directory(), directory_name)