From 52bfacb97832e2b1628c125028f751e1b288051b Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sat, 19 Mar 2016 00:28:53 +0300 Subject: [PATCH] file transfer item #1 --- src/list_items.py | 36 ++++++++++++++++++++++++++++++++++++ src/profile.py | 18 +++++++++++++++--- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/list_items.py b/src/list_items.py index 79529cf..5072484 100644 --- a/src/list_items.py +++ b/src/list_items.py @@ -154,3 +154,39 @@ class StatusCircle(QtGui.QWidget): paint.setPen(color) paint.drawEllipse(center, rad_x + 3, rad_y + 3) paint.end() + + +class FileTransferItem(QtGui.QListWidget): + def __init__(self, file_name, time, user, friend_number, file_number, parent=None): + QtGui.QListWidget.__init__(self, parent) + self.name = QtGui.QLabel(self) + self.name.setGeometry(QtCore.QRect(0, 2, 95, 20)) + self.name.setTextFormat(QtCore.Qt.PlainText) + font = QtGui.QFont() + font.setFamily("Times New Roman") + font.setPointSize(11) + font.setBold(True) + self.name.setFont(font) + self.name.setObjectName("name") + self.name.setText(file_name) + + self.time = QtGui.QLabel(self) + self.time.setGeometry(QtCore.QRect(500, 0, 50, 25)) + font = QtGui.QFont() + font.setFamily("Times New Roman") + font.setPointSize(10) + font.setBold(False) + self.time.setFont(font) + self.time.setObjectName("time") + self.time.setText(time) + + self.cancel = QtGui.QPushButton(self) + self.cancel.setGeometry(QtCore.QRect(100, 2, 200, 20)) + self.cancel.setText("Cancel") + self.cancel.clicked.connect(lambda: self.click(friend_number, file_number)) + + def click(self, friend_number, file_number): + from profile import Profile + profile = Profile.get_instance() + profile.cancel_transfer(friend_number, file_number) + self.name.setText('Cancelled') diff --git a/src/profile.py b/src/profile.py index d7b45dc..a1a9d29 100644 --- a/src/profile.py +++ b/src/profile.py @@ -1,4 +1,4 @@ -from list_items import MessageItem, ContactItem +from list_items import MessageItem, ContactItem, FileTransferItem from PySide import QtCore, QtGui from tox import Tox import os @@ -557,7 +557,7 @@ class Profile(Contact, Singleton): self._history.export(directory) # ----------------------------------------------------------------------------------------------------------------- - # Factories for friend and message items + # Factories for friend, message and file transfer items # ----------------------------------------------------------------------------------------------------------------- def create_friend_item(self): @@ -580,6 +580,14 @@ class Profile(Contact, Singleton): self._messages.setItemWidget(elem, item) self._messages.repaint() + def create_file_transfer_item(self, file_name, friend_number, file_number): + item = FileTransferItem(file_name, curr_time(), '', friend_number, file_number) + elem = QtGui.QListWidgetItem(self._messages) + elem.setSizeHint(QtCore.QSize(500, 100)) + self._messages.addItem(elem) + self._messages.setItemWidget(elem, item) + self._messages.repaint() + # ----------------------------------------------------------------------------------------------------------------- # Work with friends (remove, set alias, get public key) # ----------------------------------------------------------------------------------------------------------------- @@ -713,9 +721,13 @@ class Profile(Contact, Singleton): self._file_transfers[(friend_number, file_number)] = rt self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['RESUME']) else: - self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['CANCEL']) + self.create_file_transfer_item(file_name + ' ' + str(size), friend_number, file_number) + #self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['CANCEL']) # TODO: show info about incoming transfer + def cancel_transfer(self, friend_number, file_number): + self._tox.file_control(friend_number, file_number, TOX_FILE_CONTROL['CANCEL']) + def incoming_avatar(self, friend_number, file_number, size): """ Friend changed avatar