mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-12 20:44:50 +00:00
Implement 'Always show add torrent dialog' and 'Bring to focus' when
adding a torrent from an external source.
This commit is contained in:
parent
ebebdb7132
commit
3a482b2f19
@ -46,16 +46,15 @@ from deluge.configmanager import ConfigManager
|
|||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
import deluge.common
|
import deluge.common
|
||||||
|
|
||||||
class AddTorrentDialog:
|
class AddTorrentDialog(component.Component):
|
||||||
def __init__(self, parent=None):
|
def __init__(self):
|
||||||
|
component.Component.__init__(self, "AddTorrentDialog")
|
||||||
self.glade = gtk.glade.XML(
|
self.glade = gtk.glade.XML(
|
||||||
pkg_resources.resource_filename(
|
pkg_resources.resource_filename(
|
||||||
"deluge.ui.gtkui", "glade/add_torrent_dialog.glade"))
|
"deluge.ui.gtkui", "glade/add_torrent_dialog.glade"))
|
||||||
|
|
||||||
self.dialog = self.glade.get_widget("dialog_add_torrent")
|
self.dialog = self.glade.get_widget("dialog_add_torrent")
|
||||||
|
|
||||||
self.dialog.set_transient_for(component.get("MainWindow").window)
|
|
||||||
|
|
||||||
self.glade.signal_autoconnect({
|
self.glade.signal_autoconnect({
|
||||||
"on_button_file_clicked": self._on_button_file_clicked,
|
"on_button_file_clicked": self._on_button_file_clicked,
|
||||||
"on_button_url_clicked": self._on_button_url_clicked,
|
"on_button_url_clicked": self._on_button_url_clicked,
|
||||||
@ -128,7 +127,39 @@ class AddTorrentDialog:
|
|||||||
"default_private"
|
"default_private"
|
||||||
]
|
]
|
||||||
self.core_config = {}
|
self.core_config = {}
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
self.update_core_config()
|
||||||
|
|
||||||
|
def show(self, focus=False):
|
||||||
|
self.update_core_config()
|
||||||
|
|
||||||
|
if client.is_localhost():
|
||||||
|
self.glade.get_widget("button_location").show()
|
||||||
|
self.glade.get_widget("entry_download_path").hide()
|
||||||
|
else:
|
||||||
|
self.glade.get_widget("button_location").hide()
|
||||||
|
self.glade.get_widget("entry_download_path").show()
|
||||||
|
|
||||||
|
self.dialog.set_transient_for(component.get("MainWindow").window)
|
||||||
|
self.dialog.present()
|
||||||
|
if focus:
|
||||||
|
self.dialog.window.focus()
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
def hide(self):
|
||||||
|
self.dialog.hide()
|
||||||
|
self.files = {}
|
||||||
|
self.infos = {}
|
||||||
|
self.options = {}
|
||||||
|
self.previous_selected_torrent = None
|
||||||
|
self.torrent_liststore.clear()
|
||||||
|
self.files_treestore.clear()
|
||||||
|
self.dialog.set_transient_for(component.get("MainWindow").window)
|
||||||
|
return None
|
||||||
|
|
||||||
|
def update_core_config(self):
|
||||||
# Send requests to the core for these config values
|
# Send requests to the core for these config values
|
||||||
for key in self.core_keys:
|
for key in self.core_keys:
|
||||||
client.get_config_value(self._on_config_value, key)
|
client.get_config_value(self._on_config_value, key)
|
||||||
@ -136,29 +167,14 @@ class AddTorrentDialog:
|
|||||||
# Force a call to the core because we need this data now
|
# Force a call to the core because we need this data now
|
||||||
client.force_call()
|
client.force_call()
|
||||||
self.set_default_options()
|
self.set_default_options()
|
||||||
|
|
||||||
def show(self):
|
|
||||||
self.dialog.show_all()
|
|
||||||
if client.is_localhost():
|
|
||||||
self.glade.get_widget("button_location").show()
|
|
||||||
self.glade.get_widget("entry_download_path").hide()
|
|
||||||
else:
|
|
||||||
self.glade.get_widget("button_location").hide()
|
|
||||||
self.glade.get_widget("entry_download_path").show()
|
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
def hide(self):
|
|
||||||
self.dialog.destroy()
|
|
||||||
return None
|
|
||||||
|
|
||||||
def _on_config_value(self, value):
|
def _on_config_value(self, value):
|
||||||
for key in self.core_keys:
|
for key in self.core_keys:
|
||||||
if not self.core_config.has_key(key):
|
if not self.core_config.has_key(key):
|
||||||
self.core_config[key] = value
|
self.core_config[key] = value
|
||||||
break
|
break
|
||||||
|
|
||||||
def add_to_torrent_list(self, filenames):
|
def add_from_files(self, filenames):
|
||||||
import deluge.libtorrent as lt
|
import deluge.libtorrent as lt
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
@ -210,6 +226,9 @@ class AddTorrentDialog:
|
|||||||
|
|
||||||
self.prepare_file_store(files_list)
|
self.prepare_file_store(files_list)
|
||||||
|
|
||||||
|
if self.core_config == {}:
|
||||||
|
self.update_core_config()
|
||||||
|
|
||||||
# Save the previous torrents options
|
# Save the previous torrents options
|
||||||
self.save_torrent_options()
|
self.save_torrent_options()
|
||||||
# Update the options frame
|
# Update the options frame
|
||||||
@ -454,7 +473,7 @@ class AddTorrentDialog:
|
|||||||
return
|
return
|
||||||
|
|
||||||
chooser.destroy()
|
chooser.destroy()
|
||||||
self.add_to_torrent_list(result)
|
self.add_from_files(result)
|
||||||
|
|
||||||
def _on_button_url_clicked(self, widget):
|
def _on_button_url_clicked(self, widget):
|
||||||
log.debug("_on_button_url_clicked")
|
log.debug("_on_button_url_clicked")
|
||||||
@ -491,15 +510,18 @@ class AddTorrentDialog:
|
|||||||
# add it to the list.
|
# add it to the list.
|
||||||
log.debug("url: %s", url)
|
log.debug("url: %s", url)
|
||||||
if url != None:
|
if url != None:
|
||||||
gobject.idle_add(self.download_from_url, url)
|
self.add_from_url(url)
|
||||||
|
|
||||||
entry.set_text("")
|
entry.set_text("")
|
||||||
dialog.hide()
|
dialog.hide()
|
||||||
|
|
||||||
def download_from_url(self, url):
|
def add_from_url(self, url):
|
||||||
|
gobject.idle_add(self._download_from_url, url)
|
||||||
|
|
||||||
|
def _download_from_url(self, url):
|
||||||
import urllib
|
import urllib
|
||||||
filename, headers = urllib.urlretrieve(url)
|
filename, headers = urllib.urlretrieve(url)
|
||||||
self.add_to_torrent_list([filename])
|
self.add_from_files([filename])
|
||||||
|
|
||||||
def _on_button_hash_clicked(self, widget):
|
def _on_button_hash_clicked(self, widget):
|
||||||
log.debug("_on_button_hash_clicked")
|
log.debug("_on_button_hash_clicked")
|
||||||
@ -553,7 +575,7 @@ class AddTorrentDialog:
|
|||||||
|
|
||||||
client.add_torrent_file(torrent_filenames, torrent_options)
|
client.add_torrent_file(torrent_filenames, torrent_options)
|
||||||
client.force_call()
|
client.force_call()
|
||||||
self.dialog.destroy()
|
self.hide()
|
||||||
|
|
||||||
def _on_button_apply_clicked(self, widget):
|
def _on_button_apply_clicked(self, widget):
|
||||||
log.debug("_on_button_apply_clicked")
|
log.debug("_on_button_apply_clicked")
|
||||||
|
@ -48,11 +48,13 @@ elif dbus.version >= (0,80,0):
|
|||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
from deluge.ui.client import aclient as client
|
from deluge.ui.client import aclient as client
|
||||||
import deluge.common
|
import deluge.common
|
||||||
|
from deluge.configmanager import ConfigManager
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
class DbusInterface(dbus.service.Object, component.Component):
|
class DbusInterface(dbus.service.Object, component.Component):
|
||||||
def __init__(self, args, path="/org/deluge_torrent/Deluge"):
|
def __init__(self, args, path="/org/deluge_torrent/Deluge"):
|
||||||
component.Component.__init__(self, "DbusInterface")
|
component.Component.__init__(self, "DbusInterface")
|
||||||
|
self.config = ConfigManager("gtkui.conf")
|
||||||
# Check to see if the daemon is already running and if not, start it
|
# Check to see if the daemon is already running and if not, start it
|
||||||
bus = dbus.SessionBus()
|
bus = dbus.SessionBus()
|
||||||
obj = bus.get_object("org.freedesktop.DBus", "/org/freedesktop/DBus")
|
obj = bus.get_object("org.freedesktop.DBus", "/org/freedesktop/DBus")
|
||||||
@ -106,10 +108,18 @@ class DbusInterface(dbus.service.Object, component.Component):
|
|||||||
if deluge.common.is_url(arg):
|
if deluge.common.is_url(arg):
|
||||||
log.debug("Attempting to add %s from external source..",
|
log.debug("Attempting to add %s from external source..",
|
||||||
arg)
|
arg)
|
||||||
client.add_torrent_url(arg)
|
if self.config["interactive_add"]:
|
||||||
|
component.get("AddTorrentDialog").add_from_url(arg)
|
||||||
|
component.get("AddTorrentDialog").show(self.config["focus_add_dialog"])
|
||||||
|
else:
|
||||||
|
client.add_torrent_url(arg)
|
||||||
else:
|
else:
|
||||||
# Just a file
|
# Just a file
|
||||||
log.debug("Attempting to add %s from external source..",
|
log.debug("Attempting to add %s from external source..",
|
||||||
os.path.abspath(arg))
|
os.path.abspath(arg))
|
||||||
client.add_torrent_file([os.path.abspath(arg)])
|
if self.config["interactive_add"]:
|
||||||
|
component.get("AddTorrentDialog").add_from_files([os.path.abspath(arg)])
|
||||||
|
component.get("AddTorrentDialog").show(self.config["focus_add_dialog"])
|
||||||
|
else:
|
||||||
|
client.add_torrent_file([os.path.abspath(arg)])
|
||||||
|
|
||||||
|
@ -59,6 +59,7 @@ from signals import Signals
|
|||||||
from pluginmanager import PluginManager
|
from pluginmanager import PluginManager
|
||||||
from dbusinterface import DbusInterface
|
from dbusinterface import DbusInterface
|
||||||
from queuedtorrents import QueuedTorrents
|
from queuedtorrents import QueuedTorrents
|
||||||
|
from addtorrentdialog import AddTorrentDialog
|
||||||
from coreconfig import CoreConfig
|
from coreconfig import CoreConfig
|
||||||
import deluge.configmanager
|
import deluge.configmanager
|
||||||
import deluge.common
|
import deluge.common
|
||||||
@ -146,6 +147,7 @@ class GtkUI:
|
|||||||
self.preferences = Preferences()
|
self.preferences = Preferences()
|
||||||
self.systemtray = SystemTray()
|
self.systemtray = SystemTray()
|
||||||
self.statusbar = StatusBar()
|
self.statusbar = StatusBar()
|
||||||
|
self.addtorrentdialog = AddTorrentDialog()
|
||||||
|
|
||||||
# Start the signal receiver
|
# Start the signal receiver
|
||||||
self.signal_receiver = Signals()
|
self.signal_receiver = Signals()
|
||||||
|
@ -201,9 +201,7 @@ class MenuBar(component.Component):
|
|||||||
## File Menu ##
|
## File Menu ##
|
||||||
def on_menuitem_addtorrent_activate(self, data=None):
|
def on_menuitem_addtorrent_activate(self, data=None):
|
||||||
log.debug("on_menuitem_addtorrent_activate")
|
log.debug("on_menuitem_addtorrent_activate")
|
||||||
from addtorrentdialog import AddTorrentDialog
|
component.get("AddTorrentDialog").show()
|
||||||
#client.add_torrent_file(AddTorrentDialog().run())
|
|
||||||
AddTorrentDialog().show()
|
|
||||||
|
|
||||||
def on_menuitem_quitdaemon_activate(self, data=None):
|
def on_menuitem_quitdaemon_activate(self, data=None):
|
||||||
log.debug("on_menuitem_quitdaemon_activate")
|
log.debug("on_menuitem_quitdaemon_activate")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user