load history part #1

This commit is contained in:
ingvar1995 2016-03-25 00:15:07 +03:00
parent d557c7cf8f
commit 1315017fcc
3 changed files with 33 additions and 8 deletions

View file

@ -211,6 +211,12 @@ class MainWindow(QtGui.QMainWindow):
def setup_right_center(self, widget): def setup_right_center(self, widget):
self.messages = QtGui.QListWidget(widget) self.messages = QtGui.QListWidget(widget)
self.messages.setGeometry(0, 0, 620, 250) self.messages.setGeometry(0, 0, 620, 250)
def load(pos):
if not pos:
self.profile.load_history()
self.messages.verticalScrollBar().setValue(1)
self.messages.verticalScrollBar().valueChanged.connect(load)
self.messages.setVerticalScrollMode(QtGui.QAbstractItemView.ScrollPerPixel) self.messages.setVerticalScrollMode(QtGui.QAbstractItemView.ScrollPerPixel)
def initUI(self, tox): def initUI(self, tox):

View file

@ -217,6 +217,7 @@ class Friend(Contact):
def load_corr(self, first_time=True): def load_corr(self, first_time=True):
""" """
:param first_time: friend became active, load first part of messages :param first_time: friend became active, load first part of messages
:return: list ol loaded messages
""" """
if (first_time and self._history_loaded) or (not hasattr(self, '_message_getter')): if (first_time and self._history_loaded) or (not hasattr(self, '_message_getter')):
return return
@ -224,9 +225,10 @@ class Friend(Contact):
if data is not None and len(data): if data is not None and len(data):
data.reverse() data.reverse()
else: else:
return return []
self._corr = data + self._corr self._corr = data + self._corr
self._history_loaded = True self._history_loaded = True
return data
def get_corr_for_saving(self): def get_corr_for_saving(self):
""" """
@ -454,6 +456,7 @@ class Profile(Contact, Singleton):
self._screen.account_avatar.repaint() self._screen.account_avatar.repaint()
except: # no friend found. ignore except: # no friend found. ignore
log('Incorrect friend value: ' + str(value)) log('Incorrect friend value: ' + str(value))
raise
active_friend = property(get_active, set_active) active_friend = property(get_active, set_active)
@ -568,6 +571,21 @@ class Profile(Contact, Singleton):
self._messages.clear() self._messages.clear()
self._messages.repaint() self._messages.repaint()
def load_history(self):
"""
Tries to load next part of messages
"""
friend = self._friends[self._active_friend]
data = friend.load_corr(False)
if not data:
return
for message in data:
self.create_message_item(message[0],
convert_time(message[2]),
friend.name if message[1] else self._name,
message[3],
False)
def export_history(self, directory): def export_history(self, directory):
self._history.export(directory) self._history.export(directory)
@ -587,12 +605,15 @@ class Profile(Contact, Singleton):
self._screen.friends_list.setItemWidget(elem, item) self._screen.friends_list.setItemWidget(elem, item)
return item return item
def create_message_item(self, text, time, name, message_type): def create_message_item(self, text, time, name, message_type, append=True):
item = MessageItem(text, time, name, message_type, self._messages) item = MessageItem(text, time, name, message_type, self._messages)
elem = QtGui.QListWidgetItem(self._messages) elem = QtGui.QListWidgetItem(self._messages)
elem.setSizeHint(QtCore.QSize(600, item.getHeight())) elem.setSizeHint(QtCore.QSize(600, item.getHeight()))
self._messages.addItem(elem)
self._messages.setItemWidget(elem, item) self._messages.setItemWidget(elem, item)
if append:
self._messages.addItem(elem)
else:
self._messages.insertItem(3, elem)
self._messages.repaint() self._messages.repaint()
def create_file_transfer_item(self, file_name, size, friend_number, file_number, show_accept): def create_file_transfer_item(self, file_name, size, friend_number, file_number, show_accept):

View file

@ -1259,10 +1259,8 @@ QListWidget QListWidgetItem:selected
#friends_list:item:selected #friends_list:item:selected
{ {
background-color: #A9A9A9; border: 2px solid;
background-color: transparent;
border-color: green;
} }
#toxygen
{
color: #006400;
}