Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various small fixes #6372

Merged
merged 6 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/tribler-gui/tribler_gui/dialogs/startdownloaddialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ def on_reload_torrent_info(self, *args):
This method is called when user clicks the QLabel text showing loading or error message. Here, we reset
the number of retries to fetch the metainfo. Note color of QLabel is also reset to white.
"""
if self.has_metainfo:
return
self.dialog_widget.loading_files_label.setStyleSheet("color:#ffffff;")
self.metainfo_retries = 0
self.perform_files_request()
Expand Down
3 changes: 2 additions & 1 deletion src/tribler-gui/tribler_gui/tribler_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@
get_image_path,
get_ui_file_path,
is_dir_writable,
sanitize_for_fts,
tr,
)
from tribler_gui.widgets.channelsmenulistwidget import ChannelsMenuListWidget
from tribler_gui.widgets.tablecontentmodel import DiscoveredChannelsModel, PopularTorrentsModel
from tribler_gui.widgets.triblertablecontrollers import PopularContentTableViewController, sanitize_for_fts
from tribler_gui.widgets.triblertablecontrollers import PopularContentTableViewController

fc_loading_list_item, _ = uic.loadUiType(get_ui_file_path('loading_list_item.ui'))

Expand Down
12 changes: 12 additions & 0 deletions src/tribler-gui/tribler_gui/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,15 @@ def get_translator(language=None):
filename = ""
translator.load(locale, filename, directory=TRANSLATIONS_DIR)
return translator


def sanitize_for_fts(text):
return text.translate({ord("\""): "\"\"", ord("\'"): "\'\'"})


def to_fts_query(text):
if not text:
return ""
words = text.strip().split(" ")
query_list = ['\"' + sanitize_for_fts(word) + '\"*' for word in words]
return " AND ".join(query_list)
3 changes: 3 additions & 0 deletions src/tribler-gui/tribler_gui/widgets/downloadspage.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ def on_download_removed(self, json_result):
if json_result and "removed" in json_result:
self.load_downloads()
self.window().download_details_widget.hide()
self.window().core_manager.events_manager.node_info_updated.emit(
{"infohash": json_result["infohash"], "progress": None}
)

def on_force_recheck_download(self, checked):
for selected_item in self.selected_items:
Expand Down
3 changes: 2 additions & 1 deletion src/tribler-gui/tribler_gui/widgets/lazytableview.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from PyQt5.QtGui import QGuiApplication, QMovie
from PyQt5.QtWidgets import QAbstractItemView, QLabel, QTableView

from tribler_core.modules.metadata_store.orm_bindings.channel_node import LEGACY_ENTRY
from tribler_core.modules.metadata_store.serialization import CHANNEL_TORRENT, COLLECTION_NODE, REGULAR_TORRENT

from tribler_gui.defs import COMMIT_STATUS_COMMITTED
Expand Down Expand Up @@ -105,7 +106,7 @@ def redraw(self):
def on_subscribe_control_clicked(self, index):
item = index.model().data_items[index.row()]
# skip LEGACY entries, regular torrents and personal channel
if 'subscribed' not in item or item['status'] == 1000 or item['state'] == 'Personal':
if 'subscribed' not in item or item['status'] == LEGACY_ENTRY or item['state'] == 'Personal':
return

status = int(item['subscribed'])
Expand Down
3 changes: 1 addition & 2 deletions src/tribler-gui/tribler_gui/widgets/searchresultswidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
from tribler_core.modules.metadata_store.serialization import CHANNEL_TORRENT, COLLECTION_NODE, REGULAR_TORRENT

from tribler_gui.tribler_request_manager import TriblerNetworkRequest
from tribler_gui.utilities import connect, get_ui_file_path, tr
from tribler_gui.utilities import connect, get_ui_file_path, to_fts_query, tr
from tribler_gui.widgets.tablecontentmodel import SearchResultsModel
from tribler_gui.widgets.triblertablecontrollers import to_fts_query

widget_form, widget_class = uic.loadUiType(get_ui_file_path('search_results.ui'))

Expand Down
5 changes: 3 additions & 2 deletions src/tribler-gui/tribler_gui/widgets/tablecontentdelegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from tribler_common.simpledefs import CHANNEL_STATE

from tribler_core.modules.metadata_store.orm_bindings.channel_node import LEGACY_ENTRY
from tribler_core.modules.metadata_store.serialization import CHANNEL_TORRENT, COLLECTION_NODE, REGULAR_TORRENT

from tribler_gui.defs import (
Expand Down Expand Up @@ -265,7 +266,7 @@ def draw_subscribed_control(self, painter, option, index, data_item):

if 'type' in data_item and data_item['type'] != CHANNEL_TORRENT:
return True
if data_item['status'] == 1000: # LEGACY ENTRIES!
if data_item['status'] == LEGACY_ENTRY:
return True
if data_item['state'] == 'Personal':
return True
Expand All @@ -284,7 +285,7 @@ def draw_rating_control(self, painter, option, index, data_item):

if 'type' in data_item and data_item['type'] != CHANNEL_TORRENT:
return True
if data_item['status'] == 1000: # LEGACY ENTRIES!
if data_item['status'] == LEGACY_ENTRY:
return True

self.rating_control.paint(painter, option.rect, index, votes=data_item['votes'])
Expand Down
38 changes: 27 additions & 11 deletions src/tribler-gui/tribler_gui/widgets/tablecontentmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@

from tribler_gui.defs import BITTORRENT_BIRTHDAY, COMMIT_STATUS_TODELETE, HEALTH_CHECKING
from tribler_gui.tribler_request_manager import TriblerNetworkRequest
from tribler_gui.utilities import connect, format_size, format_votes, get_votes_rating_description, pretty_date, tr
from tribler_gui.utilities import (
connect,
format_size,
format_votes,
get_votes_rating_description,
pretty_date,
to_fts_query,
tr,
)

EXPANDING = 0

Expand Down Expand Up @@ -266,7 +274,7 @@ def perform_query(self, **kwargs):
kwargs.update({"sort_by": self.sort_by, "sort_desc": self.sort_desc})

if self.text_filter:
kwargs.update({"txt_filter": self.text_filter})
kwargs.update({"txt_filter": to_fts_query(self.text_filter)})

if self.max_rowid is not None:
kwargs["max_rowid"] = self.max_rowid
Expand Down Expand Up @@ -362,12 +370,14 @@ def endpoint_url(self):
def headerData(self, num, orientation, role=None):
if orientation == Qt.Horizontal and role == Qt.DisplayRole:
return self.columns[num].header
if role == Qt.InitialSortOrderRole and num != self.column_position.get('name'):
if role == Qt.InitialSortOrderRole and num != self.column_position.get(Column.NAME):
return Qt.DescendingOrder
if role == Qt.TextAlignmentRole:
alignment = Qt.AlignHCenter \
if num in [self.column_position.get('subscribed'), self.column_position.get('torrents')] \
alignment = (
Qt.AlignHCenter
if num in [self.column_position.get(Column.SUBSCRIBED), self.column_position.get(Column.TORRENTS)]
else Qt.AlignLeft
)
return alignment | Qt.AlignVCenter

return super().headerData(num, orientation, role)
Expand Down Expand Up @@ -418,9 +428,9 @@ def data(self, index, role):
if role in (Qt.DisplayRole, Qt.EditRole, Qt.ToolTipRole):
return self.item_txt(index, role)
if role == Qt.TextAlignmentRole:
if index.column() == self.column_position.get('votes', -1):
if index.column() == self.column_position.get(Column.VOTES, -1):
return Qt.AlignLeft | Qt.AlignVCenter
if index.column() == self.column_position.get('torrents', -1):
if index.column() == self.column_position.get(Column.TORRENTS, -1):
return Qt.AlignHCenter | Qt.AlignVCenter
return None

Expand Down Expand Up @@ -569,10 +579,16 @@ def delete_rows(self, rows):
{"public_key": entry['public_key'], "id": entry['id'], "status": COMMIT_STATUS_TODELETE}
)

if patch_data:
TriblerNetworkRequest("metadata", self.remove_items, raw_data=json.dumps(patch_data), method='PATCH')
if delete_data:
TriblerNetworkRequest("metadata", self.remove_items, raw_data=json.dumps(delete_data), method='DELETE')
# We don't wait for the Core to report back and emit
# the info_changed signal speculativley to prevent the race condition between
# Python object deletion and PyQT one. Otherwise, if the users e.g. clicks the back
# button, by the moment the request callback triggers some actions on the model,
# QT could have already deleted the underlying model object, which will result in
# "wrapped C/C++ object has been deleted" error (see e.g. https://github.com/Tribler/tribler/issues/6083)
for data, method in ((patch_data, "PATCH"), (delete_data, "DELETE")):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, unrolled for-loop looks a bit more clear here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that way I'd have to repeat the comment twice 😉

if data:
self.remove_items(data)
TriblerNetworkRequest("metadata", lambda _: None, raw_data=json.dumps(data), method=method)

def create_new_channel(self, channel_name=None):
url = (
Expand Down
18 changes: 3 additions & 15 deletions src/tribler-gui/tribler_gui/widgets/triblertablecontrollers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@
HEALTHCHECK_DELAY_MS = 500


def sanitize_for_fts(text):
return text.translate({ord("\""): "\"\"", ord("\'"): "\'\'"})


def to_fts_query(text):
if not text:
return ""
words = text.strip().split(" ")
query_list = ['\"' + sanitize_for_fts(word) + '\"*' for word in words]
return " AND ".join(query_list)


class TriblerTableViewController(QObject):
"""
Base controller for a table view that displays some data.
Expand Down Expand Up @@ -85,7 +73,7 @@ def _get_sort_parameters(self):
return sort_by, sort_asc

def _on_filter_input_change(self, _):
self.model.text_filter = to_fts_query(self.filter_input.text().lower())
self.model.text_filter = self.filter_input.text().lower()
self.model.reset()

def brain_dead_refresh(self):
Expand Down Expand Up @@ -314,8 +302,8 @@ def on_confirm_clicked(channel_id):
changes_list = [
{'public_key': entry['public_key'], 'id': entry['id'], 'origin_id': channel_id} for entry in entries
]
TriblerNetworkRequest("metadata", self.model.remove_items,
raw_data=json.dumps(changes_list), method='PATCH')
self.model.remove_items(entries)
TriblerNetworkRequest("metadata", lambda _: None, raw_data=json.dumps(changes_list), method='PATCH')

self.table_view.window().add_to_channel_dialog.show_dialog(
on_confirm_clicked, confirm_button_text=tr("Move")
Expand Down