thread for incoming file transfers
This commit is contained in:
parent
d1437b3445
commit
2a0895018a
4 changed files with 51 additions and 6 deletions
|
@ -9,6 +9,13 @@ from toxcore_enums_and_consts import *
|
|||
from toxav_enums import *
|
||||
from tox import bin_to_string
|
||||
from plugin_support import PluginLoader
|
||||
import queue
|
||||
import threading
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
# Threads
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class InvokeEvent(QtCore.QEvent):
|
||||
|
@ -33,6 +40,39 @@ _invoker = Invoker()
|
|||
def invoke_in_main_thread(fn, *args, **kwargs):
|
||||
QtCore.QCoreApplication.postEvent(_invoker, InvokeEvent(fn, *args, **kwargs))
|
||||
|
||||
|
||||
class FileTransfersThread(threading.Thread):
|
||||
|
||||
def __init__(self):
|
||||
self._queue = queue.Queue()
|
||||
self._timeout = 0.01
|
||||
self._continue = True
|
||||
super().__init__()
|
||||
|
||||
def execute(self, function, *args, **kwargs):
|
||||
self._queue.put((function, args, kwargs))
|
||||
|
||||
def stop(self):
|
||||
self._continue = False
|
||||
|
||||
def run(self):
|
||||
while self._continue:
|
||||
try:
|
||||
function, args, kwargs = self._queue.get(timeout=self._timeout)
|
||||
function(*args, **kwargs)
|
||||
except queue.Empty:
|
||||
pass
|
||||
except queue.Full:
|
||||
print('Full')
|
||||
|
||||
_thread = FileTransfersThread()
|
||||
_thread.start()
|
||||
|
||||
|
||||
def stop():
|
||||
_thread.stop()
|
||||
_thread.join()
|
||||
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
# Callbacks - current user
|
||||
# -----------------------------------------------------------------------------------------------------------------
|
||||
|
@ -204,7 +244,8 @@ def file_recv_chunk(tox, friend_number, file_number, position, chunk, length, us
|
|||
position,
|
||||
None)
|
||||
else:
|
||||
Profile.get_instance().incoming_chunk(friend_number, file_number, position, chunk[:length])
|
||||
_thread.execute(Profile.get_instance().incoming_chunk, friend_number, file_number, position, chunk[:length])
|
||||
#Profile.get_instance().incoming_chunk(friend_number, file_number, position, chunk[:length])
|
||||
|
||||
|
||||
def file_chunk_request(tox, friend_number, file_number, position, size, user_data):
|
||||
|
@ -212,6 +253,7 @@ def file_chunk_request(tox, friend_number, file_number, position, size, user_dat
|
|||
Outgoing chunk
|
||||
"""
|
||||
if size:
|
||||
#_thread.execute(Profile.get_instance().outgoing_chunk, friend_number, file_number, position, size)
|
||||
Profile.get_instance().outgoing_chunk(friend_number, file_number, position, size)
|
||||
else:
|
||||
invoke_in_main_thread(Profile.get_instance().outgoing_chunk,
|
||||
|
|
|
@ -8,7 +8,7 @@ except ImportError:
|
|||
from PyQt4 import QtCore, QtGui
|
||||
from bootstrap import node_generator
|
||||
from mainscreen import MainWindow
|
||||
from callbacks import init_callbacks
|
||||
from callbacks import init_callbacks, stop
|
||||
from util import curr_directory, program_version
|
||||
import styles.style
|
||||
import platform
|
||||
|
@ -281,6 +281,7 @@ class Toxygen:
|
|||
self.mainloop.stop = True
|
||||
self.avloop.stop = True
|
||||
plugin_helper.stop()
|
||||
stop()
|
||||
self.mainloop.wait()
|
||||
self.init.wait()
|
||||
self.avloop.wait()
|
||||
|
|
|
@ -93,6 +93,7 @@ class MainWindow(QtGui.QMainWindow, Singleton):
|
|||
def event(self, event):
|
||||
if event.type() == QtCore.QEvent.WindowActivate:
|
||||
self.tray.setIcon(QtGui.QIcon(curr_directory() + '/images/icon.png'))
|
||||
self.messages.repaint()
|
||||
return super(MainWindow, self).event(event)
|
||||
|
||||
def retranslateUi(self):
|
||||
|
|
|
@ -1072,6 +1072,7 @@ class Profile(contact.Contact, Singleton):
|
|||
os.path.basename(path),
|
||||
friend_number,
|
||||
st.get_file_number())
|
||||
if friend_number == self.get_active_number():
|
||||
item = self.create_file_transfer_item(tm)
|
||||
st.set_state_changed_handler(item.update)
|
||||
self._friends[self._active_friend].append_message(tm)
|
||||
|
|
Loading…
Reference in a new issue