diff --git a/toxygen/app.py b/toxygen/app.py
index 82d1618..53c4dff 100644
--- a/toxygen/app.py
+++ b/toxygen/app.py
@@ -141,6 +141,8 @@ class App:
def _load_app_styles(self):
# application color scheme
+ if self._settings['theme'] == 'dark':
+ return
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:
@@ -294,17 +296,17 @@ class App:
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._smiley_loader, self._plugin_loader, self._toxes, self._version)
self._contacts_manager = ContactsManager(self._tox, self._settings, self._ms, self._profile_manager,
self._contacts_provider, db)
self._messenger = Messenger(self._tox, self._plugin_loader, self._ms, self._contacts_manager,
- self._contacts_provider)
+ self._contacts_provider, items_factory)
self._tray = tray.init_tray(profile, self._settings, self._ms)
- self._ms.set_dependencies(widgets_factory, self._tray, self._contacts_manager, self._messenger)
+ self._ms.set_dependencies(widgets_factory, self._tray, self._contacts_manager, self._messenger, profile)
self._calls_manager = CallsManager(self._tox.AV, self._settings)
self._file_transfer_handler = FileTransfersHandler(self._tox, self._settings, self._contacts_provider)
- self._tray.show()
+ self._tray.show()
self._ms.show()
# callbacks initialization
diff --git a/toxygen/contacts/contacts_manager.py b/toxygen/contacts/contacts_manager.py
index 0f7b4bc..e468ecc 100644
--- a/toxygen/contacts/contacts_manager.py
+++ b/toxygen/contacts/contacts_manager.py
@@ -1,7 +1,6 @@
import util.util as util
import util.ui as util_ui
from contacts.friend import Friend
-import os
from PyQt5 import QtCore, QtGui
from messenger.messages import *
from wrapper.toxcore_enums_and_consts import *
@@ -9,10 +8,10 @@ from network.tox_dns import tox_dns
from history.history_loader import HistoryLoader
-# TODO: move messaging and typing notifications to other class
-
-
class ContactsManager:
+ """
+ Represents contacts list.
+ """
def __init__(self, tox, settings, screen, profile_manager, contact_provider, db):
self._tox = tox
@@ -134,12 +133,11 @@ class ContactsManager:
# self._screen.call_finished()
else:
friend = self.get_curr_contact()
-
+ # TODO: to separate method
self._screen.account_name.setText(friend.name)
self._screen.account_status.setText(friend.status_message)
self._screen.account_status.setToolTip(friend.get_full_status())
avatar_path = friend.get_avatar_path()
- os.chdir(os.path.dirname(avatar_path))
pixmap = QtGui.QPixmap(avatar_path)
self._screen.account_avatar.setPixmap(pixmap.scaled(64, 64, QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation))
@@ -171,6 +169,7 @@ class ContactsManager:
:param sorting: 0 - no sort, 1 - online only, 2 - online first, 4 - by name
:param filter_str: show contacts which name contains this substring
"""
+ # TODO: simplify?
filter_str = filter_str.lower()
number = self.get_active_number()
is_friend = self._is_active_a_friend()
@@ -196,16 +195,16 @@ class ContactsManager:
part1 = sorted(part1, key=lambda x: x.number)
part2 = sorted(part2, key=lambda x: x.number)
self._contacts = part1 + part2
- self._screen.friends_list.clear()
- for contact in self._contacts:
- contact.set_widget(self.create_friend_item())
+ # self._screen.friends_list.clear()
+ # for contact in self._contacts:
+ # contact.set_widget(self.create_friend_item())
for index, friend in enumerate(self._contacts):
friend.visibility = (friend.status is not None or not (sorting & 1)) and (filter_str in friend.name.lower())
friend.visibility = friend.visibility or friend.messages or friend.actions
- # if friend.visibility:
- # self._screen.friends_list.item(index).setSizeHint(QtCore.QSize(250, self._friend_item_height))
- # else:
- # self._screen.friends_list.item(index).setSizeHint(QtCore.QSize(250, 0))
+ if friend.visibility:
+ self._screen.friends_list.item(index).setSizeHint(QtCore.QSize(250, self._friend_item_height))
+ else:
+ self._screen.friends_list.item(index).setSizeHint(QtCore.QSize(250, 0))
self._sorting, self._filter_string = sorting, filter_str
self._settings['sorting'] = self._sorting
self._settings.save()
@@ -217,13 +216,6 @@ class ContactsManager:
"""
self.filtration_and_sorting(self._sorting, self._filter_string)
- def _create_friend_item(self):
- """
- Method-factory
- :return: new widget for friend instance
- """
- return self._factory.friend_item()
-
# -----------------------------------------------------------------------------------------------------------------
# Friend getters
# -----------------------------------------------------------------------------------------------------------------
@@ -233,7 +225,7 @@ class ContactsManager:
def get_last_message(self):
if self._active_contact + 1:
- return self.get_current_contact().get_last_message_text()
+ return self.get_curr_contact().get_last_message_text()
else:
return ''
@@ -241,12 +233,13 @@ class ContactsManager:
return self.get_curr_contact().number if self._active_contact + 1 else -1
def get_active_name(self):
- return self.get_current_contact().name if self._active_contact + 1 else ''
+ return self.get_curr_contact().name if self._active_contact + 1 else ''
def is_active_online(self):
- return self._active_contact + 1 and self.get_current_contact().status is not None
+ return self._active_contact + 1 and self.get_curr_contact().status is not None
def new_name(self, number, name):
+ # TODO: move to somewhere else?
friend = self.get_friend_by_number(number)
tmp = friend.name
friend.set_name(name)
@@ -254,7 +247,7 @@ class ContactsManager:
if friend.name == name and tmp != name:
message = util_ui.tr('User {} is now known as {}')
message = message.format(tmp, name)
- friend.append_message(InfoMessage(message, time.time()))
+ friend.append_message(InfoMessage(0, message, util.get_unix_time()))
friend.actions = True
if number == self.get_active_number():
self.create_message_item(message, time.time(), '', MESSAGE_TYPE['INFO_MESSAGE'])
@@ -293,12 +286,16 @@ class ContactsManager:
except:
pass
self._settings.save()
- if num == self.get_active_number() and self.is_active_a_friend():
- self.update()
+ # if num == self.get_active_number() and self.is_active_a_friend():
+ # self.update()
def friend_public_key(self, num):
return self._contacts[num].tox_id
+ def export_history(self, num, as_text):
+ contact = self._contacts[num]
+ return self._history.export_history(contact, as_text)
+
def delete_friend(self, num):
"""
Removes friend from contact list
@@ -313,17 +310,12 @@ class ContactsManager:
if friend.tox_id in self._settings['notes']:
del self._settings['notes'][friend.tox_id]
self._settings.save()
- self.clear_history(num)
- if self._history.friend_exists_in_db(friend.tox_id):
- self._history.delete_friend_from_db(friend.tox_id)
+ self._history.delete_history(friend)
self._tox.friend_delete(friend.number)
del self._contacts[num]
self._screen.friends_list.takeItem(num)
if num == self._active_contact: # active friend was deleted
- if not len(self._contacts): # last friend was deleted
- self.set_active(-1)
- else:
- self.set_active(0)
+ self.set_active(0 if len(self._contacts) else -1)
data = self._tox.get_savedata()
self._profile_manager.save_profile(data)
@@ -387,13 +379,9 @@ class ContactsManager:
text = util_ui.tr('Friend added without sending friend request')
util_ui.message_box(text, title)
else:
- result = self._tox.friend_add(tox_id, message.encode('utf-8'))
+ self._tox.friend_add(tox_id, message.encode('utf-8'))
tox_id = tox_id[:TOX_PUBLIC_KEY_SIZE * 2]
- item = self.create_friend_item()
- 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)
- friend = Friend(message_getter, result, tox_id, '', item, tox_id)
+ friend = self._contact_provider.get_friend_by_public_key(tox_id)
self._contacts.append(friend)
self.save_profile()
return True
@@ -420,7 +408,7 @@ class ContactsManager:
util.log('Accept friend request failed! ' + str(ex))
def can_send_typing_notification(self):
- return self._settings['typing_notifications'] and self._active_contact != -1
+ return self._settings['typing_notifications'] and self._active_contact + 1
# -----------------------------------------------------------------------------------------------------------------
# Private methods
diff --git a/toxygen/history/history_loader.py b/toxygen/history/history_loader.py
index 801125b..a380ddb 100644
--- a/toxygen/history/history_loader.py
+++ b/toxygen/history/history_loader.py
@@ -1,4 +1,4 @@
-from messenger.messages import *
+from history.history_logs_generators import *
# TODO: fix history loading and saving
@@ -96,65 +96,21 @@ class HistoryLoader:
return self._db.messages_getter(friend_public_key)
- @staticmethod
- def export_history(friend, as_text=True, _range=None):
- if _range is None:
- friend.load_all_corr()
- corr = friend.get_corr()
- elif _range[1] + 1:
- corr = friend.get_corr()[_range[0]:_range[1] + 1]
- else:
- corr = friend.get_corr()[_range[0]:]
+ def delete_history(self, friend):
+ self.clear_history(friend)
+ if self._db.friend_exists_in_db(friend.tox_id):
+ self._db.delete_friend_from_db(friend.tox_id)
- generator = TextHistoryGenerator(corr) if as_text else HtmlHistoryGenerator(corr)
+ @staticmethod
+ def export_history(contact, as_text=True, _range=None):
+ if _range is None:
+ contact.load_all_corr()
+ corr = contact.get_corr()
+ elif _range[1] + 1:
+ corr = contact.get_corr()[_range[0]:_range[1] + 1]
+ else:
+ corr = contact.get_corr()[_range[0]:]
+
+ generator = TextHistoryGenerator(corr, contact.name) if as_text else HtmlHistoryGenerator(corr, contact.name)
return generator.generate()
-
-
-class HistoryLogsGenerator:
-
- def __init__(self, history):
- self._history = history
-
- def generate(self):
- return str()
-
-
-class HtmlHistoryGenerator(HistoryLogsGenerator):
-
- def __init__(self, history):
- super().__init__(history)
-
- def generate(self):
- arr = []
- for message in self._history:
- if type(message) is TextMessage:
- data = message.get_data()
- x = '[{}] {}: {}
'
- arr.append(x.format(convert_time(data[2]) if data[1] != MESSAGE_OWNER['NOT_SENT'] else 'Unsent',
- friend.name if data[1] == MESSAGE_OWNER['FRIEND'] else self.name,
- data[0]))
- s = '
'.join(arr)
- s = '