How about putting this stuff in a callback like this https://github.com/egbertbouman/tribler/commit/01abc1b5ec01e5408ae0b852b5728316a0d43c9f.