Skip to content

Commit

Permalink
Merge pull request #5879 from ichorid/fix/5867
Browse files Browse the repository at this point in the history
Fix/5867
  • Loading branch information
drew2a committed Dec 23, 2020
2 parents cee19a5 + 6c7a05a commit 6afcd6e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from tribler_core.modules.metadata_store.serialization import CHANNEL_TORRENT, COLLECTION_NODE, REGULAR_TORRENT
from tribler_core.restapi.rest_endpoint import RESTEndpoint

# This dict is used to translate JSON fields into the columns used in Pony for _sorting_.
# id_ is not in the list because there is not index on it, so we never really want to sort on it.
json2pony_columns = {
'category': "tags",
'id': "rowid",
'name': "title",
'size': "size",
'infohash': "infohash",
Expand All @@ -16,7 +17,7 @@
'health': 'HEALTH',
}

# TODO: use the same representation for metatada nodes as in the database
# TODO: use the same representation for metadata nodes as in the database
metadata_type_to_search_scope = {
'': frozenset((REGULAR_TORRENT, CHANNEL_TORRENT, COLLECTION_NODE)),
"channel": frozenset((CHANNEL_TORRENT, COLLECTION_NODE)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def sanitize_parameters(self, parameters):
sanitized["metadata_type"] = [str(mt) for mt in sanitized["metadata_type"] if mt]
if "channel_pk" in parameters:
sanitized["channel_pk"] = parameters["channel_pk"]
if "origin_id" in parameters:
sanitized["origin_id"] = parameters["origin_id"]

return sanitized

Expand Down
30 changes: 19 additions & 11 deletions src/tribler-gui/tribler_gui/widgets/channelcontentswidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ def push_channels_stack(self, model):
self.channels_stack.append(model)
connect(self.model.info_changed, self.on_model_info_changed)

connect(self.window().core_manager.events_manager.received_remote_query_results,
self.model.on_new_entry_received)
connect(
self.window().core_manager.events_manager.received_remote_query_results, self.model.on_new_entry_received
)
connect(self.window().core_manager.events_manager.node_info_updated, self.model.update_node_info)

with self.freeze_controls():
Expand Down Expand Up @@ -224,8 +225,8 @@ def initialize_root_model(self, root_model):
self.update_labels()
self.channel_torrents_filter_input.setText("")

def reset_view(self):
self.model.text_filter = ''
def reset_view(self, text_filter=None):
self.model.text_filter = text_filter or ''
self.model.category_filter = None

with self.freeze_controls():
Expand All @@ -239,8 +240,9 @@ def reset_view(self):
def disconnect_current_model(self):
self.model.info_changed.disconnect()
disconnect(self.window().core_manager.events_manager.node_info_updated, self.model.update_node_info)
disconnect(self.window().core_manager.events_manager.received_remote_query_results,
self.model.on_new_entry_received)
disconnect(
self.window().core_manager.events_manager.received_remote_query_results, self.model.on_new_entry_received
)
self.controller.unset_model() # Disconnect the selectionChanged signal

def go_back(self, checked=False):
Expand Down Expand Up @@ -268,7 +270,13 @@ def go_back(self, checked=False):
def on_breadcrumb_clicked(self, tgt_level):
if int(tgt_level) + 1 != len(self.channels_stack):
self.go_back_to_level(tgt_level)
elif isinstance(self.model, SearchResultsModel) and len(self.channels_stack) == 1:
# In case of remote search, when only the search results are on the stack,
# we must keep the txt_filter (which contains the search term) before resetting the view
text_filter = self.model.text_filter
self.reset_view(text_filter=text_filter)
else:
# Reset the view if the user clicks on the last part of the breadcrumb
self.reset_view()

def go_back_to_level(self, level):
Expand All @@ -288,12 +296,12 @@ def preview_clicked(self, checked=False):
params = dict()

if "public_key" in self.model.channel_info:
# This is a channel contents query, limit the search by channel_pk and torrent md type
params.update({'metadata_type': 'torrent', 'channel_pk': self.model.channel_info["public_key"]})
elif self.model.text_filter:
# GigaChannel Community v1.0 does not support searching for text in a specific channel
# This is a channel contents query, limit the search by channel_pk and origin_id
params.update(
{'channel_pk': self.model.channel_info["public_key"], 'origin_id': self.model.channel_info["id"]}
)
if self.model.text_filter:
params.update({'txt_filter': self.model.text_filter})

if self.model.hide_xxx is not None:
params.update({'hide_xxx': self.model.hide_xxx})
if self.model.sort_by is not None:
Expand Down

0 comments on commit 6afcd6e

Please sign in to comment.