mirror of
https://github.com/codex-storage/deluge.git
synced 2025-02-18 06:16:29 +00:00
[GTK] Refactor deluge.common usage
This commit is contained in:
parent
09d04aaac0
commit
25cfd58792
@ -18,8 +18,17 @@ from xml.sax.saxutils import unescape as xml_unescape
|
|||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
from gi.repository.GObject import TYPE_INT64, TYPE_UINT64
|
from gi.repository.GObject import TYPE_INT64, TYPE_UINT64
|
||||||
|
|
||||||
import deluge.common
|
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
|
from deluge.common import (
|
||||||
|
create_magnet_uri,
|
||||||
|
decode_bytes,
|
||||||
|
fsize,
|
||||||
|
get_magnet_info,
|
||||||
|
is_infohash,
|
||||||
|
is_magnet,
|
||||||
|
is_url,
|
||||||
|
resource_filename,
|
||||||
|
)
|
||||||
from deluge.configmanager import ConfigManager
|
from deluge.configmanager import ConfigManager
|
||||||
from deluge.httpdownloader import download_file
|
from deluge.httpdownloader import download_file
|
||||||
from deluge.ui.client import client
|
from deluge.ui.client import client
|
||||||
@ -40,19 +49,19 @@ class AddTorrentDialog(component.Component):
|
|||||||
self.builder = Gtk.Builder()
|
self.builder = Gtk.Builder()
|
||||||
# The base dialog
|
# The base dialog
|
||||||
self.builder.add_from_file(
|
self.builder.add_from_file(
|
||||||
deluge.common.resource_filename(
|
resource_filename(
|
||||||
__package__, os.path.join('glade', 'add_torrent_dialog.ui')
|
__package__, os.path.join('glade', 'add_torrent_dialog.ui')
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
# The infohash dialog
|
# The infohash dialog
|
||||||
self.builder.add_from_file(
|
self.builder.add_from_file(
|
||||||
deluge.common.resource_filename(
|
resource_filename(
|
||||||
__package__, os.path.join('glade', 'add_torrent_dialog.infohash.ui')
|
__package__, os.path.join('glade', 'add_torrent_dialog.infohash.ui')
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
# The url dialog
|
# The url dialog
|
||||||
self.builder.add_from_file(
|
self.builder.add_from_file(
|
||||||
deluge.common.resource_filename(
|
resource_filename(
|
||||||
__package__, os.path.join('glade', 'add_torrent_dialog.url.ui')
|
__package__, os.path.join('glade', 'add_torrent_dialog.url.ui')
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -281,7 +290,7 @@ class AddTorrentDialog(component.Component):
|
|||||||
already_added = 0
|
already_added = 0
|
||||||
|
|
||||||
for uri in uris:
|
for uri in uris:
|
||||||
magnet = deluge.common.get_magnet_info(uri)
|
magnet = get_magnet_info(uri)
|
||||||
if not magnet:
|
if not magnet:
|
||||||
log.error('Invalid magnet: %s', uri)
|
log.error('Invalid magnet: %s', uri)
|
||||||
continue
|
continue
|
||||||
@ -719,14 +728,14 @@ class AddTorrentDialog(component.Component):
|
|||||||
entry.grab_focus()
|
entry.grab_focus()
|
||||||
|
|
||||||
text = get_clipboard_text()
|
text = get_clipboard_text()
|
||||||
if text and deluge.common.is_url(text) or deluge.common.is_magnet(text):
|
if text and is_url(text) or is_magnet(text):
|
||||||
entry.set_text(text)
|
entry.set_text(text)
|
||||||
|
|
||||||
dialog.show_all()
|
dialog.show_all()
|
||||||
response = dialog.run()
|
response = dialog.run()
|
||||||
|
|
||||||
if response == Gtk.ResponseType.OK:
|
if response == Gtk.ResponseType.OK:
|
||||||
url = deluge.common.decode_bytes(entry.get_text())
|
url = decode_bytes(entry.get_text())
|
||||||
else:
|
else:
|
||||||
url = None
|
url = None
|
||||||
|
|
||||||
@ -737,9 +746,9 @@ class AddTorrentDialog(component.Component):
|
|||||||
# add it to the list.
|
# add it to the list.
|
||||||
log.debug('url: %s', url)
|
log.debug('url: %s', url)
|
||||||
if url:
|
if url:
|
||||||
if deluge.common.is_url(url):
|
if is_url(url):
|
||||||
self.add_from_url(url)
|
self.add_from_url(url)
|
||||||
elif deluge.common.is_magnet(url):
|
elif is_magnet(url):
|
||||||
self.add_from_magnets([url])
|
self.add_from_magnets([url])
|
||||||
else:
|
else:
|
||||||
ErrorDialog(
|
ErrorDialog(
|
||||||
@ -771,15 +780,11 @@ class AddTorrentDialog(component.Component):
|
|||||||
pb.set_fraction(percent)
|
pb.set_fraction(percent)
|
||||||
pb.set_text(
|
pb.set_text(
|
||||||
'%.2f%% (%s / %s)'
|
'%.2f%% (%s / %s)'
|
||||||
% (
|
% (percent * 100, fsize(current_length), fsize(total_length))
|
||||||
percent * 100,
|
|
||||||
deluge.common.fsize(current_length),
|
|
||||||
deluge.common.fsize(total_length),
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
pb.pulse()
|
pb.pulse()
|
||||||
pb.set_text('%s' % deluge.common.fsize(current_length))
|
pb.set_text('%s' % fsize(current_length))
|
||||||
|
|
||||||
def on_download_success(result):
|
def on_download_success(result):
|
||||||
self.add_from_files([result])
|
self.add_from_files([result])
|
||||||
@ -811,13 +816,13 @@ class AddTorrentDialog(component.Component):
|
|||||||
entry.grab_focus()
|
entry.grab_focus()
|
||||||
|
|
||||||
text = get_clipboard_text()
|
text = get_clipboard_text()
|
||||||
if deluge.common.is_infohash(text):
|
if is_infohash(text):
|
||||||
entry.set_text(text)
|
entry.set_text(text)
|
||||||
|
|
||||||
dialog.show_all()
|
dialog.show_all()
|
||||||
response = dialog.run()
|
response = dialog.run()
|
||||||
infohash = entry.get_text().strip()
|
infohash = entry.get_text().strip()
|
||||||
if response == Gtk.ResponseType.OK and deluge.common.is_infohash(infohash):
|
if response == Gtk.ResponseType.OK and is_infohash(infohash):
|
||||||
# Create a list of trackers from the textview buffer
|
# Create a list of trackers from the textview buffer
|
||||||
tview_buf = textview.get_buffer()
|
tview_buf = textview.get_buffer()
|
||||||
trackers_text = tview_buf.get_text(
|
trackers_text = tview_buf.get_text(
|
||||||
@ -829,7 +834,7 @@ class AddTorrentDialog(component.Component):
|
|||||||
# Convert the information to a magnet uri, this is just easier to
|
# Convert the information to a magnet uri, this is just easier to
|
||||||
# handle this way.
|
# handle this way.
|
||||||
log.debug('trackers: %s', trackers)
|
log.debug('trackers: %s', trackers)
|
||||||
magnet = deluge.common.create_magnet_uri(infohash, infohash, trackers)
|
magnet = create_magnet_uri(infohash, infohash, trackers)
|
||||||
log.debug('magnet uri: %s', magnet)
|
log.debug('magnet uri: %s', magnet)
|
||||||
self.add_from_magnets([magnet])
|
self.add_from_magnets([magnet])
|
||||||
|
|
||||||
@ -889,7 +894,7 @@ class AddTorrentDialog(component.Component):
|
|||||||
options,
|
options,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
elif deluge.common.is_magnet(filename):
|
elif is_magnet(filename):
|
||||||
client.core.add_torrent_magnet(filename, options)
|
client.core.add_torrent_magnet(filename, options)
|
||||||
|
|
||||||
row = self.torrent_liststore.iter_next(row)
|
row = self.torrent_liststore.iter_next(row)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user