[GTKUI] Added detection of torrent URL on GTK UI focus
In case deluge GTK gets focus with a new torrent URL on the clipboard, the "Add Torrent from URL" dialog will pop up automatically Closes: deluge-torrent/deluge#306
This commit is contained in:
parent
de4fbd2e82
commit
d56636426e
|
@ -478,6 +478,23 @@
|
|||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="urldetect_toggle">
|
||||
<property name="label" translatable="yes">Detect torrent URLs from clipboard</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="tooltip_text" translatable="yes">Automatically open Add Torrent dialog when clipboard contains a torrent URL</property>
|
||||
<property name="halign">start</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<signal name="toggled" handler="on_urldetect_toggle_toggled" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkCheckButton" id="piecesbar_toggle">
|
||||
<property name="visible">True</property>
|
||||
|
@ -501,7 +518,7 @@ and daemon (does not apply in Standalone mode).</property>
|
|||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -697,7 +714,7 @@ and daemon (does not apply in Standalone mode).</property>
|
|||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">3</property>
|
||||
<property name="position">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
|
|
|
@ -130,6 +130,7 @@ DEFAULT_PREFS = {
|
|||
'show_rate_in_title': False,
|
||||
'createtorrent.trackers': [],
|
||||
'show_piecesbar': False,
|
||||
'detect_urls': True,
|
||||
'pieces_color_missing': [65535, 0, 0],
|
||||
'pieces_color_waiting': [4874, 56494, 0],
|
||||
'pieces_color_downloading': [65535, 55255, 0],
|
||||
|
|
|
@ -20,11 +20,11 @@ from twisted.internet import reactor
|
|||
from twisted.internet.error import ReactorNotRunning
|
||||
|
||||
import deluge.component as component
|
||||
from deluge.common import decode_bytes, fspeed, resource_filename
|
||||
from deluge.common import decode_bytes, fspeed, is_magnet, is_url, resource_filename
|
||||
from deluge.configmanager import ConfigManager
|
||||
from deluge.ui.client import client
|
||||
|
||||
from .common import get_deluge_icon, windowing
|
||||
from .common import get_clipboard_text, get_deluge_icon, windowing
|
||||
from .dialogs import PasswordDialog
|
||||
from .ipcinterface import process_args
|
||||
|
||||
|
@ -132,6 +132,7 @@ class MainWindow(component.Component):
|
|||
self.window.connect('configure-event', self.on_window_configure_event)
|
||||
self.window.connect('delete-event', self.on_window_delete_event)
|
||||
self.window.connect('drag-data-received', self.on_drag_data_received_event)
|
||||
self.window.connect('notify::is-active', self.on_focus)
|
||||
self.tabsbar_pane.connect(
|
||||
'notify::position', self.on_tabsbar_pane_position_event
|
||||
)
|
||||
|
@ -148,6 +149,9 @@ class MainWindow(component.Component):
|
|||
'NewVersionAvailableEvent', self.on_newversionavailable_event
|
||||
)
|
||||
|
||||
self.previous_clipboard_text = ''
|
||||
self.first_run = True
|
||||
|
||||
def connect_signals(self, mapping_or_class):
|
||||
self.gtk_builder_signals_holder.connect_signals(mapping_or_class)
|
||||
|
||||
|
@ -330,6 +334,19 @@ class MainWindow(component.Component):
|
|||
def on_expose_event(self, widget, event):
|
||||
component.get('SystemTray').blink(False)
|
||||
|
||||
def on_focus(self, window, param):
|
||||
if window.props.is_active and not self.first_run and self.config['detect_urls']:
|
||||
text = get_clipboard_text()
|
||||
if text == self.previous_clipboard_text:
|
||||
return
|
||||
self.previous_clipboard_text = text
|
||||
if text and (
|
||||
(is_url(text) and text.endswith('.torrent')) or is_magnet(text)
|
||||
):
|
||||
component.get('AddTorrentDialog').show()
|
||||
component.get('AddTorrentDialog').on_button_url_clicked(window)
|
||||
self.first_run = False
|
||||
|
||||
def stop(self):
|
||||
self.window.set_title('Deluge')
|
||||
|
||||
|
|
|
@ -570,6 +570,9 @@ class Preferences(component.Component):
|
|||
self.builder.get_object('piecesbar_toggle').set_active(
|
||||
self.gtkui_config['show_piecesbar']
|
||||
)
|
||||
self.builder.get_object('urldetect_toggle').set_active(
|
||||
self.gtkui_config['detect_urls']
|
||||
)
|
||||
self.__set_color('completed', from_config=True)
|
||||
self.__set_color('downloading', from_config=True)
|
||||
self.__set_color('waiting', from_config=True)
|
||||
|
@ -1461,6 +1464,9 @@ class Preferences(component.Component):
|
|||
colors_widget = self.builder.get_object('piecebar_colors_expander')
|
||||
colors_widget.set_visible(widget.get_active())
|
||||
|
||||
def on_urldetect_toggle_toggled(self, widget):
|
||||
self.gtkui_config['detect_urls'] = widget.get_active()
|
||||
|
||||
def on_checkbutton_language_toggled(self, widget):
|
||||
self.language_combo.set_visible(not self.language_checkbox.get_active())
|
||||
|
||||
|
|
Loading…
Reference in New Issue