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

Add on_paste_event to handle pasting of magnet links #8008

Merged
merged 3 commits into from
May 3, 2024
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
10 changes: 10 additions & 0 deletions src/tribler/gui/tribler_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
connect,
create_api_key,
format_api_key,
get_clipboard_text,
get_font_path,
get_gui_setting,
get_image_path,
Expand Down Expand Up @@ -221,6 +222,9 @@ def __init__(
self.magnet_handler = MagnetHandler(self.window)
QDesktopServices.setUrlHandler("magnet", self.magnet_handler, "on_open_magnet_link")

self.paste = QShortcut(QKeySequence("Ctrl+v"), self)
connect(self.paste.activated, self.on_paste_event)

self.debug_pane_shortcut = QShortcut(QKeySequence("Ctrl+d"), self)
connect(self.debug_pane_shortcut.activated, self.clicked_debug_panel_button)

Expand Down Expand Up @@ -447,6 +451,12 @@ def on_torrent_finished(self, torrent_info):
if "hidden" not in torrent_info or not torrent_info["hidden"]:
self.tray_show_message(tr("Download finished"), tr("Download of %s has finished.") % {torrent_info['name']})

def on_paste_event(self):
txt = get_clipboard_text()
self._logger.info(f'Paste event: {txt}')
if txt.startswith("magnet:?xt=urn:btih:"):
self.start_download_from_uri(txt)

def show_loading_screen(self):
self.top_menu_button.setHidden(True)
self.left_menu.setHidden(True)
Expand Down
5 changes: 5 additions & 0 deletions src/tribler/gui/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ def copy_to_clipboard(message):
cb.setText(message, mode=cb.Clipboard)


def get_clipboard_text():
cb = QApplication.clipboard()
return cb.text(mode=cb.Clipboard)


def html_label(text, background="#e4e4e4", color="#222222", bold=True):
style = "background-color:" + background if background else ''
style = style + ";color:" + color if color else style
Expand Down