Add queueing options to the Options tab

Add setting auto managed from the torrent menu
This commit is contained in:
Andrew Resch 2008-06-23 03:12:28 +00:00
parent f200cae0f0
commit e43f2370e1
9 changed files with 796 additions and 586 deletions

View File

@ -563,6 +563,22 @@ class Core(
"""Sets a higher priority to the first and last pieces""" """Sets a higher priority to the first and last pieces"""
return self.torrents[torrent_id].set_prioritize_first_last(value) return self.torrents[torrent_id].set_prioritize_first_last(value)
def export_set_torrent_auto_managed(self, torrent_id, value):
"""Sets the auto managed flag for queueing purposes"""
return self.torrents[torrent_id].set_auto_managed(value)
def export_set_torrent_stop_at_ratio(self, torrent_id, value):
"""Sets the torrent to stop at 'stop_ratio'"""
return self.torrents[torrent_id].set_stop_at_ratio(value)
def export_set_torrent_stop_ratio(self, torrent_id, value):
"""Sets the ratio when to stop a torrent if 'stop_at_ratio' is set"""
return self.torrents[torrent_id].set_stop_ratio(value)
def export_set_torrent_remove_at_ratio(self, torrent_id, value):
"""Sets the torrent to be removed at 'stop_ratio'"""
return self.torrents[torrent_id].set_remove_at_ratio(value)
def export_block_ip_range(self, range): def export_block_ip_range(self, range):
"""Block an ip range""" """Block an ip range"""
try: try:

View File

@ -75,7 +75,9 @@ class Torrent:
self.total_uploaded = 0 self.total_uploaded = 0
# Set default auto_managed value # Set default auto_managed value
self.set_auto_managed(options["auto_managed"]) self.auto_managed = options["auto_managed"]
if not handle.is_paused():
handle.auto_managed(self.auto_managed)
# We need to keep track if the torrent is finished in the state to prevent # We need to keep track if the torrent is finished in the state to prevent
# some weird things on state load. # some weird things on state load.
@ -90,6 +92,10 @@ class Torrent:
# Set the filename # Set the filename
self.filename = state.filename self.filename = state.filename
self.is_finished = state.is_finished self.is_finished = state.is_finished
# Set the per-torrent queue options
self.set_stop_at_ratio(state.stop_at_ratio)
self.set_stop_ratio(state.stop_ratio)
self.set_remove_at_ratio(state.remove_at_ratio)
else: else:
# Tracker list # Tracker list
self.trackers = [] self.trackers = []
@ -160,14 +166,22 @@ class Torrent:
def set_auto_managed(self, auto_managed): def set_auto_managed(self, auto_managed):
self.auto_managed = auto_managed self.auto_managed = auto_managed
if not self.handle.is_paused(): self.handle.auto_managed(auto_managed)
self.handle.auto_managed(auto_managed) self.update_state()
def set_stop_ratio(self, stop_ratio):
self.stop_ratio = stop_ratio
def set_stop_at_ratio(self, stop_at_ratio):
self.stop_at_ratio = stop_at_ratio
def set_remove_at_ratio(self, remove_at_ratio):
self.remove_at_ratio = remove_at_ratio
def set_file_priorities(self, file_priorities): def set_file_priorities(self, file_priorities):
log.debug("setting %s's file priorities: %s", self.torrent_id, file_priorities) log.debug("setting %s's file priorities: %s", self.torrent_id, file_priorities)
self.handle.prioritize_files(file_priorities) self.handle.prioritize_files(file_priorities)
# XXX: I don't think this is needed anymore since we have torrent_resumed alert
if 0 in self.file_priorities: if 0 in self.file_priorities:
# We have previously marked a file 'Do Not Download' # We have previously marked a file 'Do Not Download'
# Check to see if we have changed any 0's to >0 and change state accordingly # Check to see if we have changed any 0's to >0 and change state accordingly
@ -390,7 +404,10 @@ class Torrent:
"active_time": self.status.active_time, "active_time": self.status.active_time,
"seeding_time": self.status.seeding_time, "seeding_time": self.status.seeding_time,
"seed_rank": self.status.seed_rank, "seed_rank": self.status.seed_rank,
"is_auto_managed": self.auto_managed "is_auto_managed": self.auto_managed,
"stop_ratio": self.stop_ratio,
"stop_at_ratio": self.stop_at_ratio,
"remove_at_ratio": self.remove_at_ratio
} }
fns = { fns = {

View File

@ -65,7 +65,10 @@ class TorrentState:
file_priorities=None, file_priorities=None,
queue=None, queue=None,
auto_managed=None, auto_managed=None,
is_finished=False is_finished=False,
stop_ratio=2.00,
stop_at_ratio=False,
remove_at_ratio=True
): ):
self.torrent_id = torrent_id self.torrent_id = torrent_id
self.filename = filename self.filename = filename
@ -85,6 +88,9 @@ class TorrentState:
self.prioritize_first_last = prioritize_first_last self.prioritize_first_last = prioritize_first_last
self.file_priorities = file_priorities self.file_priorities = file_priorities
self.auto_managed = auto_managed self.auto_managed = auto_managed
self.stop_ratio = stop_ratio
self.stop_at_ratio = stop_at_ratio
self.remove_at_ratio = remove_at_ratio
class TorrentManagerState: class TorrentManagerState:
def __init__(self): def __init__(self):
@ -158,11 +164,12 @@ class TorrentManager(component.Component):
self.alerts.handle_alerts(True) self.alerts.handle_alerts(True)
def update(self): def update(self):
if self.config["stop_seed_at_ratio"]: for torrent in self.torrents:
for torrent in self.torrents: if self.config["stop_seed_at_ratio"] or torrent.stop_at_ratio:
if torrent.get_ratio() >= self.config["stop_seed_ratio"] and torrent.is_finished: if (torrent.get_ratio() >= self.config["stop_seed_ratio"] or\
torrent.get_ratio() > torrent.stop_ratio) and torrent.is_finished:
torrent.pause() torrent.pause()
if self.config["remove_seed_at_ratio"]: if self.config["remove_seed_at_ratio"] or torrent.remove_at_ratio:
self.remove(torrent.torrent_id) self.remove(torrent.torrent_id)
def __getitem__(self, torrent_id): def __getitem__(self, torrent_id):
@ -504,7 +511,10 @@ class TorrentManager(component.Component):
torrent.file_priorities, torrent.file_priorities,
torrent.get_queue_position(), torrent.get_queue_position(),
torrent.auto_managed, torrent.auto_managed,
torrent.is_finished torrent.is_finished,
torrent.stop_ratio,
torrent.stop_at_ratio,
torrent.remove_at_ratio
) )
state.torrents.append(torrent_state) state.torrents.append(torrent_state)

View File

@ -164,7 +164,9 @@ class BaseClient(object):
"block_ip_range", "remove_torrent", "pause_torrent", "move_storage", "block_ip_range", "remove_torrent", "pause_torrent", "move_storage",
"resume_torrent", "force_reannounce", "force_recheck", "resume_torrent", "force_reannounce", "force_recheck",
"deregister_client", "register_client", "add_torrent_file", "deregister_client", "register_client", "add_torrent_file",
"set_torrent_prioritize_first_last"] "set_torrent_prioritize_first_last", "set_torrent_auto_managed",
"set_torrent_stop_ratio", "set_torrent_stop_at_ratio",
"set_torrent_remove_at_ratio"]
def __init__(self): def __init__(self):
self.core = _core self.core = _core

File diff suppressed because it is too large Load Diff

View File

@ -306,6 +306,13 @@
</child> </child>
</widget> </widget>
</child> </child>
<child>
<widget class="GtkMenuItem" id="menuitem_auto_managed">
<property name="visible">True</property>
<property name="label" translatable="yes">_Auto Managed</property>
<property name="use_underline">True</property>
</widget>
</child>
</widget> </widget>
<widget class="GtkMenu" id="queue_torrent_menu"> <widget class="GtkMenu" id="queue_torrent_menu">
<property name="visible">True</property> <property name="visible">True</property>

View File

@ -84,6 +84,16 @@ class MenuBar(component.Component):
submenu.show_all() submenu.show_all()
self.torrentmenu_glade.get_widget(menuitem).set_submenu(submenu) self.torrentmenu_glade.get_widget(menuitem).set_submenu(submenu)
submenu = gtk.Menu()
item = gtk.MenuItem(_("On"))
item.connect("activate", self.on_menuitem_set_automanaged_on)
submenu.append(item)
item = gtk.MenuItem(_("Off"))
item.connect("activate", self.on_menuitem_set_automanaged_off)
submenu.append(item)
submenu.show_all()
self.torrentmenu_glade.get_widget("menuitem_auto_managed").set_submenu(submenu)
self.torrentmenu = self.torrentmenu_glade.get_widget("torrent_menu") self.torrentmenu = self.torrentmenu_glade.get_widget("torrent_menu")
self.menu_torrent = self.window.main_glade.get_widget("menu_torrent") self.menu_torrent = self.window.main_glade.get_widget("menu_torrent")
@ -422,3 +432,10 @@ class MenuBar(component.Component):
for torrent in component.get("TorrentView").get_selected_torrents(): for torrent in component.get("TorrentView").get_selected_torrents():
funcs[widget.name](torrent, value) funcs[widget.name](torrent, value)
def on_menuitem_set_automanaged_on(self, widget):
for torrent in component.get("TorrentView").get_selected_torrents():
client.set_torrent_auto_managed(torrent, True)
def on_menuitem_set_automanaged_off(self, widget):
for torrent in component.get("TorrentView").get_selected_torrents():
client.set_torrent_auto_managed(torrent, False)

View File

@ -49,6 +49,10 @@ class OptionsTab(Tab):
self.spin_max_upload_slots = glade.get_widget("spin_max_upload_slots") self.spin_max_upload_slots = glade.get_widget("spin_max_upload_slots")
self.chk_private = glade.get_widget("chk_private") self.chk_private = glade.get_widget("chk_private")
self.chk_prioritize_first_last = glade.get_widget("chk_prioritize_first_last") self.chk_prioritize_first_last = glade.get_widget("chk_prioritize_first_last")
self.chk_auto_managed = glade.get_widget("chk_auto_managed")
self.chk_stop_at_ratio = glade.get_widget("chk_stop_at_ratio")
self.chk_remove_at_ratio = glade.get_widget("chk_remove_at_ratio")
self.spin_stop_ratio = glade.get_widget("spin_stop_ratio")
self.prev_torrent_id = None self.prev_torrent_id = None
self.prev_status = None self.prev_status = None
@ -78,11 +82,16 @@ class OptionsTab(Tab):
"max_connections", "max_connections",
"max_upload_slots", "max_upload_slots",
"private", "private",
"prioritize_first_last"]) "prioritize_first_last",
"is_auto_managed",
"stop_at_ratio",
"stop_ratio",
"remove_at_ratio"])
self.prev_torrent_id = torrent_id self.prev_torrent_id = torrent_id
def clear(self): def clear(self):
pass self.prev_torrent_id = None
self.prev_status = None
def _on_get_torrent_status(self, status): def _on_get_torrent_status(self, status):
# We only want to update values that have been applied in the core. This # We only want to update values that have been applied in the core. This
@ -90,7 +99,7 @@ class OptionsTab(Tab):
if self.prev_status == None: if self.prev_status == None:
self.prev_status = {}.fromkeys(status.keys(), None) self.prev_status = {}.fromkeys(status.keys(), None)
if status != self.prev_status and status.keys() == self.prev_status.keys(): if status != self.prev_status:
if status["max_download_speed"] != self.prev_status["max_download_speed"]: if status["max_download_speed"] != self.prev_status["max_download_speed"]:
self.spin_max_download.set_value(status["max_download_speed"]) self.spin_max_download.set_value(status["max_download_speed"])
if status["max_upload_speed"] != self.prev_status["max_upload_speed"]: if status["max_upload_speed"] != self.prev_status["max_upload_speed"]:
@ -103,6 +112,15 @@ class OptionsTab(Tab):
self.chk_private.set_active(status["private"]) self.chk_private.set_active(status["private"])
if status["prioritize_first_last"] != self.prev_status["prioritize_first_last"]: if status["prioritize_first_last"] != self.prev_status["prioritize_first_last"]:
self.chk_prioritize_first_last.set_active(status["prioritize_first_last"]) self.chk_prioritize_first_last.set_active(status["prioritize_first_last"])
if status["is_auto_managed"] != self.prev_status["is_auto_managed"]:
self.chk_auto_managed.set_active(status["is_auto_managed"])
if status["stop_at_ratio"] != self.prev_status["stop_at_ratio"]:
self.chk_stop_at_ratio.set_active(status["stop_at_ratio"])
if status["stop_ratio"] != self.prev_status["stop_ratio"]:
self.spin_stop_ratio.set_value(status["stop_ratio"])
if status["remove_at_ratio"] != self.prev_status["remove_at_ratio"]:
self.chk_remove_at_ratio.set_active(status["remove_at_ratio"])
self.prev_status = status self.prev_status = status
def _on_button_apply_clicked(self, button): def _on_button_apply_clicked(self, button):
@ -116,6 +134,15 @@ class OptionsTab(Tab):
client.set_torrent_max_upload_slots(self.prev_torrent_id, self.spin_max_upload_slots.get_value_as_int()) client.set_torrent_max_upload_slots(self.prev_torrent_id, self.spin_max_upload_slots.get_value_as_int())
if self.chk_prioritize_first_last.get_active() != self.prev_status["prioritize_first_last"]: if self.chk_prioritize_first_last.get_active() != self.prev_status["prioritize_first_last"]:
client.set_torrent_prioritize_first_last(self.prev_torrent_id, self.chk_prioritize_first_last.get_active()) client.set_torrent_prioritize_first_last(self.prev_torrent_id, self.chk_prioritize_first_last.get_active())
if self.chk_auto_managed.get_active() != self.prev_status["is_auto_managed"]:
client.set_torrent_auto_managed(self.prev_torrent_id, self.chk_auto_managed.get_active())
if self.chk_stop_at_ratio.get_active() != self.prev_status["stop_at_ratio"]:
client.set_torrent_stop_at_ratio(self.prev_torrent_id, self.chk_stop_at_ratio.get_active())
if self.spin_stop_ratio.get_value() != self.prev_status["stop_ratio"]:
client.set_torrent_stop_ratio(self.prev_torrent_id, self.spin_stop_ratio.get_value())
if self.chk_remove_at_ratio.get_active() != self.prev_status["remove_at_ratio"]:
client.set_torrent_remove_at_ratio(self.prev_torrent_id, self.chk_remove_at_ratio.get_active())
def _on_button_edit_trackers_clicked(self, button): def _on_button_edit_trackers_clicked(self, button):
from edittrackersdialog import EditTrackersDialog from edittrackersdialog import EditTrackersDialog

View File

@ -244,6 +244,7 @@ class TorrentDetails(component.Component):
except IndexError: except IndexError:
return return
# Update the tab that is in view # Update the tab that is in view
log.debug("tab_name: %s", name)
self.tabs[name].update() self.tabs[name].update()
def clear(self): def clear(self):