diff --git a/deluge/ui/gtkui/addtorrentdialog.py b/deluge/ui/gtkui/addtorrentdialog.py index 045514061..c4e56421d 100644 --- a/deluge/ui/gtkui/addtorrentdialog.py +++ b/deluge/ui/gtkui/addtorrentdialog.py @@ -23,7 +23,7 @@ from deluge.configmanager import ConfigManager from deluge.httpdownloader import download_file from deluge.ui.client import client from deluge.ui.common import TorrentInfo -from deluge.ui.gtkui.common import listview_replace_treestore, reparent_iter +from deluge.ui.gtkui.common import get_clipboard_text, listview_replace_treestore, reparent_iter from deluge.ui.gtkui.dialogs import ErrorDialog from deluge.ui.gtkui.edittrackersdialog import trackers_tiers_from_text from deluge.ui.gtkui.path_chooser import PathChooser @@ -559,12 +559,9 @@ class AddTorrentDialog(component.Component): dialog.set_transient_for(self.dialog) entry.grab_focus() - text = (gtk.clipboard_get(selection='PRIMARY').wait_for_text() or - gtk.clipboard_get().wait_for_text()) - if text: - text = text.strip() - if deluge.common.is_url(text) or deluge.common.is_magnet(text): - entry.set_text(text) + text = get_clipboard_text() + if text and deluge.common.is_url(text) or deluge.common.is_magnet(text): + entry.set_text(text) dialog.show_all() response = dialog.run() @@ -646,8 +643,7 @@ class AddTorrentDialog(component.Component): dialog.set_transient_for(self.dialog) entry.grab_focus() - text = (gtk.clipboard_get(selection='PRIMARY').wait_for_text() or - gtk.clipboard_get().wait_for_text()).strip() + text = get_clipboard_text() if deluge.common.is_infohash(text): entry.set_text(text) diff --git a/deluge/ui/gtkui/common.py b/deluge/ui/gtkui/common.py index 21f311ae4..6bf8c4eae 100644 --- a/deluge/ui/gtkui/common.py +++ b/deluge/ui/gtkui/common.py @@ -17,8 +17,8 @@ import shutil import sys from gobject import GError -from gtk import SORT_ASCENDING, Menu, MenuItem, RadioMenuItem, SeparatorMenuItem, icon_theme_get_default -from gtk.gdk import COLORSPACE_RGB, Pixbuf, pixbuf_new_from_file, pixbuf_new_from_file_at_size +from gtk import SORT_ASCENDING, Menu, MenuItem, RadioMenuItem, SeparatorMenuItem, clipboard_get, icon_theme_get_default +from gtk.gdk import COLORSPACE_RGB, SELECTION_PRIMARY, Pixbuf, pixbuf_new_from_file, pixbuf_new_from_file_at_size from deluge.common import get_pixmap, osx_check, windows_check @@ -323,3 +323,8 @@ def listview_replace_treestore(listview): listview.set_model(treestore) listview.thaw_child_notify() + + +def get_clipboard_text(): + text = clipboard_get(selection=SELECTION_PRIMARY).wait_for_text() or clipboard_get().wait_for_text() + return text.strip() diff --git a/deluge/ui/gtkui/connectionmanager.py b/deluge/ui/gtkui/connectionmanager.py index 90b467ee5..28efb3fed 100644 --- a/deluge/ui/gtkui/connectionmanager.py +++ b/deluge/ui/gtkui/connectionmanager.py @@ -25,7 +25,7 @@ from deluge.configmanager import ConfigManager, get_config_dir from deluge.error import AuthenticationRequired, BadLoginError, IncompatibleClient from deluge.ui.client import Client, client from deluge.ui.common import get_localhost_auth -from deluge.ui.gtkui.common import get_deluge_icon, get_logo +from deluge.ui.gtkui.common import get_clipboard_text, get_deluge_icon, get_logo from deluge.ui.gtkui.dialogs import AuthenticationDialog, ErrorDialog log = logging.getLogger(__name__) @@ -237,7 +237,7 @@ class ConnectionManager(component.Component): self.__update_list() def on_entry_host_paste_clipboard(self, widget): - text = gtk.clipboard_get().wait_for_text().strip() + text = get_clipboard_text() log.debug('on_entry_proxy_host_paste-clipboard: got paste: %s', text) text = text if '//' in text else '//' + text parsed = urlparse(text) diff --git a/deluge/ui/gtkui/preferences.py b/deluge/ui/gtkui/preferences.py index 51aab29de..4a7952490 100644 --- a/deluge/ui/gtkui/preferences.py +++ b/deluge/ui/gtkui/preferences.py @@ -24,7 +24,7 @@ from deluge.configmanager import ConfigManager, get_config_dir from deluge.error import AuthManagerError, NotAuthorizedError from deluge.ui.client import client from deluge.ui.common import DISK_CACHE_KEYS -from deluge.ui.gtkui.common import associate_magnet_links, get_deluge_icon +from deluge.ui.gtkui.common import associate_magnet_links, get_clipboard_text, get_deluge_icon from deluge.ui.gtkui.dialogs import AccountDialog, ErrorDialog, InformationDialog, YesNoDialog from deluge.ui.gtkui.path_chooser import PathChooser from deluge.ui.translations_util import get_languages @@ -954,7 +954,7 @@ class Preferences(component.Component): self.builder.get_object(entry).hide() def on_entry_proxy_host_paste_clipboard(self, widget): - text = gtk.clipboard_get().wait_for_text().strip() + text = get_clipboard_text() log.debug('on_entry_proxy_host_paste-clipboard: got paste: %s', text) text = text if '//' in text else '//' + text parsed = urlparse(text)