diff --git a/src/file_transfers.py b/src/file_transfers.py index 04f7b99..32c3cb9 100644 --- a/src/file_transfers.py +++ b/src/file_transfers.py @@ -35,9 +35,9 @@ ALLOWED_FILES = ('toxygen_inline.png', 'utox-inline.png', 'sticker.png') class StateSignal(QtCore.QObject): try: - signal = QtCore.Signal(int, float) # state and progress + signal = QtCore.Signal(int, float, int) # state and progress except: - signal = QtCore.pyqtSignal(int, float) # state and progress - pyqt4 + signal = QtCore.pyqtSignal(int, float, int) # state and progress - pyqt4 class FileTransfer(QtCore.QObject): @@ -64,7 +64,12 @@ class FileTransfer(QtCore.QObject): self._state_changed.signal.connect(handler) def signal(self): - self._state_changed.signal.emit(self.state, self._done / self._size if self._size else 0) + percentage = self._done / self._size if self._size else 0 + if self._creation_time is None or not percentage: + t = -1 + else: + t = ((time() - self._creation_time) / percentage) * (1 - percentage) + self._state_changed.signal.emit(self.state, percentage, int(t)) def get_file_number(self): return self._file_number @@ -124,6 +129,8 @@ class SendTransfer(FileTransfer): :param position: start position in file :param size: chunk max size """ + if self._creation_time is None: + self._creation_time = time() if size: self._file.seek(position) data = self._file.read(size) @@ -166,6 +173,8 @@ class SendFromBuffer(FileTransfer): return self._data def send_chunk(self, position, size): + if self._creation_time is None: + self._creation_time = time() if size: data = self._data[position:position + size] self._tox.file_send_chunk(self._friend_number, self._file_number, position, data) @@ -210,11 +219,13 @@ class ReceiveTransfer(FileTransfer): :param position: position in file to save data :param data: raw data (string) """ + if self._creation_time is None: + self._creation_time = time() if data is None: self._file.close() self.state = TOX_FILE_TRANSFER_STATE['FINISHED'] self._state_changed.signal.emit(self.state, 1) - else: + else: # TODO: improve data = ''.join(chr(x) for x in data) if self._file_size < position: self._file.seek(0, 2) @@ -243,6 +254,8 @@ class ReceiveToBuffer(FileTransfer): return self._data def write_chunk(self, position, data): + if self._creation_time is None: + self._creation_time = time() if data is None: self.state = TOX_FILE_TRANSFER_STATE['FINISHED'] self._state_changed.signal.emit(self.state, 1) diff --git a/src/list_items.py b/src/list_items.py index 2f054c2..868d4ab 100644 --- a/src/list_items.py +++ b/src/list_items.py @@ -155,19 +155,19 @@ class ContactItem(QtGui.QWidget): self.avatar_label.setGeometry(QtCore.QRect(3, 3, 64, 64)) self.avatar_label.setScaledContents(True) self.name = DataLabel(self) - self.name.setGeometry(QtCore.QRect(75, 10, 160, 25)) + self.name.setGeometry(QtCore.QRect(75, 10, 150, 25)) font = QtGui.QFont() font.setFamily("Times New Roman") font.setPointSize(12) font.setBold(True) self.name.setFont(font) self.status_message = DataLabel(self) - self.status_message.setGeometry(QtCore.QRect(75, 30, 180, 20)) + self.status_message.setGeometry(QtCore.QRect(75, 30, 170, 20)) font.setPointSize(10) font.setBold(False) self.status_message.setFont(font) self.connection_status = StatusCircle(self) - self.connection_status.setGeometry(QtCore.QRect(243, 5, 32, 32)) + self.connection_status.setGeometry(QtCore.QRect(230, 5, 32, 32)) self.messages = UnreadMessagesCount(self) self.messages.setGeometry(QtCore.QRect(52, 50, 30, 20)) @@ -291,7 +291,7 @@ class FileTransferItem(QtGui.QListWidget): self.pb.setVisible(state in SHOW_PROGRESS_BAR) self.file_name = DataLabel(self) - self.file_name.setGeometry(QtCore.QRect(210, 7, width - 400, 20)) + self.file_name.setGeometry(QtCore.QRect(210, 7, width - 440, 20)) font.setPointSize(12) self.file_name.setFont(font) file_size = size / 1024 @@ -305,6 +305,11 @@ class FileTransferItem(QtGui.QListWidget): self.file_name.setText(file_data) self.file_name.setToolTip(file_name) self.saved_name = file_name + self.time_left = QtGui.QLabel(self) + self.time_left.setGeometry(QtCore.QRect(width - 83, 7, 30, 20)) + font.setPointSize(10) + self.time_left.setFont(font) + self.time_left.setVisible(state == TOX_FILE_TRANSFER_STATE['RUNNING']) self.setFocusPolicy(QtCore.Qt.NoFocus) self.paused = False @@ -345,9 +350,12 @@ class FileTransferItem(QtGui.QListWidget): self.accept_or_pause.setIcon(icon) self.accept_or_pause.setIconSize(QtCore.QSize(30, 30)) - @QtCore.Slot(int, float) - def update(self, state, progress): + @QtCore.Slot(int, float, int) + def update(self, state, progress, time): self.pb.setValue(int(progress * 100)) + if time + 1: + m, s = divmod(time, 60) + self.time_left.setText('{0:02d}:{0:02d}'.format(m, s)) if self.state != state: if state == TOX_FILE_TRANSFER_STATE['CANCELLED']: self.setStyleSheet('QListWidget { border: 1px solid #B40404; }') @@ -355,29 +363,36 @@ class FileTransferItem(QtGui.QListWidget): self.accept_or_pause.setVisible(False) self.pb.setVisible(False) self.state = state + self.time_left.setVisible(False) elif state == TOX_FILE_TRANSFER_STATE['FINISHED']: self.accept_or_pause.setVisible(False) self.pb.setVisible(False) self.cancel.setVisible(False) self.setStyleSheet('QListWidget { border: 1px solid green; }') self.state = state + self.time_left.setVisible(False) elif state == TOX_FILE_TRANSFER_STATE['PAUSED_BY_FRIEND']: self.accept_or_pause.setVisible(False) self.setStyleSheet('QListWidget { border: 1px solid #FF8000; }') self.state = state + self.time_left.setVisible(False) elif state == TOX_FILE_TRANSFER_STATE['PAUSED_BY_USER']: self.button_update('resume') # setup button continue self.setStyleSheet('QListWidget { border: 1px solid green; }') self.state = state + self.time_left.setVisible(False) elif state == TOX_FILE_TRANSFER_STATE['OUTGOING_NOT_STARTED']: self.setStyleSheet('QListWidget { border: 1px solid #FF8000; }') self.accept_or_pause.setVisible(False) + self.time_left.setVisible(False) self.pb.setVisible(False) elif not self.paused: # active + self.pb.setVisible(True) self.accept_or_pause.setVisible(True) # setup to pause self.button_update('pause') self.setStyleSheet('QListWidget { border: 1px solid green; }') self.state = state + self.time_left.setVisible(True) def mark_as_sent(self): return False diff --git a/src/mainscreen.py b/src/mainscreen.py index 1fac26b..9f26dec 100644 --- a/src/mainscreen.py +++ b/src/mainscreen.py @@ -182,7 +182,7 @@ class MainWindow(QtGui.QMainWindow): Form.status_message.setFont(font) Form.status_message.setObjectName("status_message") self.connection_status = Form.connection_status = StatusCircle(Form) - Form.connection_status.setGeometry(QtCore.QRect(245, 35, 32, 32)) + Form.connection_status.setGeometry(QtCore.QRect(230, 35, 32, 32)) self.avatar_label.mouseReleaseEvent = self.profile_settings self.status_message.mouseReleaseEvent = self.profile_settings self.name.mouseReleaseEvent = self.profile_settings @@ -256,7 +256,8 @@ class MainWindow(QtGui.QMainWindow): def initUI(self, tox): self.setMinimumSize(920, 500) - self.setGeometry(400, 400, 920, 500) + s = Settings.get_instance() + self.setGeometry(s['x'], s['y'], s['width'], s['height']) self.setWindowTitle('Toxygen') os.chdir(curr_directory() + '/images/') main = QtGui.QWidget() @@ -311,6 +312,12 @@ class MainWindow(QtGui.QMainWindow): def closeEvent(self, *args, **kwargs): self.profile.save_history() self.profile.close() + s = Settings.get_instance() + s['x'] = self.pos().x() + s['y'] = self.pos().y() + s['width'] = self.width() + s['height'] = self.height() + s.save() QtGui.QApplication.closeAllWindows() def resizeEvent(self, *args, **kwargs): diff --git a/src/settings.py b/src/settings.py index 279ed12..e0adce0 100644 --- a/src/settings.py +++ b/src/settings.py @@ -86,7 +86,11 @@ class Settings(Singleton, dict): 'notes': {}, 'smileys': True, 'smiley_pack': 'default', - 'mirror_mode': False + 'mirror_mode': False, + 'width': 920, + 'height': 500, + 'x': 400, + 'y': 400 } @staticmethod