Skip to content

Commit

Permalink
Merge pull request #4466 from grimadas/fix/hidden_notifier
Browse files Browse the repository at this point in the history
Fix notifier for hidden downloads
  • Loading branch information
devos50 authored Apr 17, 2019
2 parents d3b9e50 + 459a8bd commit 538ac36
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
5 changes: 3 additions & 2 deletions Tribler/Core/APIImplementation/LaunchManyCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,20 +540,21 @@ def sesscb_states_callback(self, states_list):
tdef = download.get_def()
safename = tdef.get_name_as_unicode()
infohash = tdef.get_infohash()
is_hidden = download.hidden

if state == DLSTATUS_DOWNLOADING:
new_active_downloads.append(infohash)
elif state == DLSTATUS_STOPPED_ON_ERROR:
self._logger.error("Error during download: %s", repr(ds.get_error()))
if self.download_exists(infohash):
self.get_download(infohash).stop()
self.session.notifier.notify(NTFY_TORRENT, NTFY_ERROR, infohash, repr(ds.get_error()))
self.session.notifier.notify(NTFY_TORRENT, NTFY_ERROR, infohash, repr(ds.get_error()), is_hidden)
elif state == DLSTATUS_SEEDING:
seeding_download_list.append({u'infohash': infohash,
u'download': download})

if infohash in self.previous_active_downloads:
self.session.notifier.notify(NTFY_TORRENT, NTFY_FINISHED, infohash, safename)
self.session.notifier.notify(NTFY_TORRENT, NTFY_FINISHED, infohash, safename, is_hidden)
do_checkpoint = True
elif download.get_hops() == 0 and download.get_safe_seeding():
# Re-add the download with anonymity enabled
Expand Down
6 changes: 4 additions & 2 deletions Tribler/Core/Modules/restapi/events_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,12 @@ def on_torrent_discovered(self, subject, changetype, objectID, *args):
self.write_data({"type": "torrent_discovered", "event": args[0]})

def on_torrent_finished(self, subject, changetype, objectID, *args):
self.write_data({"type": "torrent_finished", "event": {"infohash": hexlify(objectID), "name": args[0]}})
self.write_data({"type": "torrent_finished", "event": {"infohash": hexlify(objectID), "name": args[0],
"hidden": args[1]}})

def on_torrent_error(self, subject, changetype, objectID, *args):
self.write_data({"type": "torrent_error", "event": {"infohash": hexlify(objectID), "error": args[0]}})
self.write_data({"type": "torrent_error", "event": {"infohash": hexlify(objectID), "error": args[0],
"hidden": args[1]}})

def on_torrent_info_updated(self, subject, changetype, objectID, *args):
self.write_data({"type": "torrent_info_updated", "event": dict(infohash=hexlify(objectID), **args[0])})
Expand Down
4 changes: 2 additions & 2 deletions Tribler/Test/Core/Modules/RestApi/test_events_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ def send_notifications(_):
self.session.notifier.notify(NTFY_NEW_VERSION, NTFY_INSERT, None, None)
self.session.notifier.notify(NTFY_CHANNEL, NTFY_DISCOVERED, None, None)
self.session.notifier.notify(NTFY_TORRENT, NTFY_DISCOVERED, None, {'a': 'Invalid character \xa1'})
self.session.notifier.notify(NTFY_TORRENT, NTFY_FINISHED, 'a' * 10, None)
self.session.notifier.notify(NTFY_TORRENT, NTFY_ERROR, 'a' * 10, 'This is an error message')
self.session.notifier.notify(NTFY_TORRENT, NTFY_FINISHED, 'a' * 10, None, False)
self.session.notifier.notify(NTFY_TORRENT, NTFY_ERROR, 'a' * 10, 'This is an error message', False)
self.session.notifier.notify(NTFY_MARKET_ON_ASK, NTFY_UPDATE, None, {'a': 'b'})
self.session.notifier.notify(NTFY_MARKET_ON_BID, NTFY_UPDATE, None, {'a': 'b'})
self.session.notifier.notify(NTFY_MARKET_ON_ASK_TIMEOUT, NTFY_UPDATE, None, {'a': 'b'})
Expand Down
1 change: 1 addition & 0 deletions Tribler/Test/Core/test_launch_many_cores.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def create_fake_download_and_state():
fake_download.get_hops = lambda: 0
fake_download.get_safe_seeding = lambda: True
fake_download.get_peerlist = lambda: [fake_peer]
fake_download.hidden = False
dl_state = MockObject()
dl_state.get_infohash = lambda: 'aaaa'
dl_state.get_status = lambda: DLSTATUS_SEEDING
Expand Down
3 changes: 2 additions & 1 deletion TriblerGUI/tribler_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,8 @@ def on_low_storage(self):
close_dialog.show()

def on_torrent_finished(self, torrent_info):
self.tray_show_message("Download finished", "Download of %s has finished." % torrent_info["name"])
if "hidden" not in torrent_info or not torrent_info["hidden"]:
self.tray_show_message("Download finished", "Download of %s has finished." % torrent_info["name"])

def show_loading_screen(self):
self.top_menu_button.setHidden(True)
Expand Down

0 comments on commit 538ac36

Please sign in to comment.