Fix #624 do not allow changing file priorities when using compact allocation

This commit is contained in:
Andrew Resch 2008-12-09 05:40:56 +00:00
parent be0c891dd8
commit 7065df205b
4 changed files with 763 additions and 734 deletions

View File

@ -124,6 +124,8 @@ class AddTorrentDialog(component.Component):
] ]
self.core_config = {} self.core_config = {}
self.glade.get_widget("notebook1").connect("switch-page", self._on_switch_page)
def start(self): def start(self):
self.update_core_config() self.update_core_config()
@ -157,20 +159,16 @@ class AddTorrentDialog(component.Component):
def update_core_config(self): def update_core_config(self):
self.core_config = {} self.core_config = {}
# Send requests to the core for these config values
for key in self.core_keys:
client.get_config_value(self._on_config_value, key)
def _on_config_values(config):
self.core_config = config
# Send requests to the core for these config values
client.get_config_values(_on_config_values, self.core_keys)
# 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 _on_config_value(self, value):
for key in self.core_keys:
if not self.core_config.has_key(key):
self.core_config[key] = value
break
def add_from_files(self, filenames): def add_from_files(self, filenames):
import os.path import os.path
new_row = None new_row = None
@ -188,6 +186,7 @@ class AddTorrentDialog(component.Component):
[info.info_hash, info.name, filename]) [info.info_hash, info.name, filename])
self.files[info.info_hash] = info.files self.files[info.info_hash] = info.files
self.infos[info.info_hash] = info.metadata self.infos[info.info_hash] = info.metadata
self.save_torrent_options(new_row)
(model, row) = self.listview_torrents.get_selection().get_selected() (model, row) = self.listview_torrents.get_selection().get_selected()
if not row and new_row: if not row and new_row:
@ -212,6 +211,8 @@ class AddTorrentDialog(component.Component):
[info_hash, name, uri]) [info_hash, name, uri])
self.files[info_hash] = [] self.files[info_hash] = []
self.infos[info_hash] = None self.infos[info_hash] = None
self.save_torrent_options(new_row)
(model, row) = self.listview_torrents.get_selection().get_selected() (model, row) = self.listview_torrents.get_selection().get_selected()
if not row and new_row: if not row and new_row:
self.listview_torrents.get_selection().select_iter(new_row) self.listview_torrents.get_selection().select_iter(new_row)
@ -239,6 +240,10 @@ class AddTorrentDialog(component.Component):
self.previous_selected_torrent = row self.previous_selected_torrent = row
def _on_switch_page(self, widget, page, page_num):
# Save the torrent options when switching notebook pages
self.save_torrent_options()
def prepare_file_store(self, files): def prepare_file_store(self, files):
self.listview_files.set_model(None) self.listview_files.set_model(None)
self.files_treestore.clear() self.files_treestore.clear()
@ -347,6 +352,14 @@ class AddTorrentDialog(component.Component):
self.glade.get_widget("entry_download_path").get_text() self.glade.get_widget("entry_download_path").get_text()
options["compact_allocation"] = \ options["compact_allocation"] = \
self.glade.get_widget("radio_compact").get_active() self.glade.get_widget("radio_compact").get_active()
if options["compact_allocation"]:
# We need to make sure all the files are set to download
def set_download_true(model, path, itr):
model[path][0] = True
self.files_treestore.foreach(set_download_true)
self.update_treeview_toggles(self.files_treestore.get_iter_first())
options["max_download_speed"] = \ options["max_download_speed"] = \
self.glade.get_widget("spin_maxdown").get_value() self.glade.get_widget("spin_maxdown").get_value()
options["max_upload_speed"] = \ options["max_upload_speed"] = \
@ -390,6 +403,8 @@ class AddTorrentDialog(component.Component):
self.glade.get_widget("radio_compact").set_active( self.glade.get_widget("radio_compact").set_active(
self.core_config["compact_allocation"]) self.core_config["compact_allocation"])
self.glade.get_widget("radio_full").set_active(
not self.core_config["compact_allocation"])
self.glade.get_widget("spin_maxdown").set_value( self.glade.get_widget("spin_maxdown").set_value(
self.core_config["max_download_speed_per_torrent"]) self.core_config["max_download_speed_per_torrent"])
self.glade.get_widget("spin_maxup").set_value( self.glade.get_widget("spin_maxup").set_value(
@ -416,6 +431,10 @@ class AddTorrentDialog(component.Component):
return files_list return files_list
def _on_file_toggled(self, render, path): def _on_file_toggled(self, render, path):
# Check to see if we can change file priorities
(model, row) = self.listview_torrents.get_selection().get_selected()
if self.options[model[row][0]]["compact_allocation"]:
return
(model, paths) = self.listview_files.get_selection().get_selected_rows() (model, paths) = self.listview_files.get_selection().get_selected_rows()
if len(paths) > 1: if len(paths) > 1:
for path in paths: for path in paths:

View File

@ -160,6 +160,14 @@ class FilesTab(Tab):
self.listview.get_selection().set_mode(gtk.SELECTION_MULTIPLE) self.listview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
self.file_menu = glade.get_widget("menu_file_tab") self.file_menu = glade.get_widget("menu_file_tab")
self.file_menu_priority_items = [
glade.get_widget("menuitem_donotdownload"),
glade.get_widget("menuitem_normal"),
glade.get_widget("menuitem_high"),
glade.get_widget("menuitem_highest"),
glade.get_widget("menuitem_priority_sep")
]
self.listview.connect("row-activated", self._on_row_activated) self.listview.connect("row-activated", self._on_row_activated)
self.listview.connect("button-press-event", self._on_button_press_event) self.listview.connect("button-press-event", self._on_button_press_event)
@ -271,26 +279,23 @@ class FilesTab(Tab):
self.clear() self.clear()
return return
status_keys = ["file_progress", "file_priorities"]
if torrent_id != self.torrent_id: if torrent_id != self.torrent_id:
# We only want to do this if the torrent_id has changed # We only want to do this if the torrent_id has changed
self.treestore.clear() self.treestore.clear()
self.torrent_id = torrent_id self.torrent_id = torrent_id
status_keys += ["compact"]
if self.torrent_id not in self.files_list.keys(): if self.torrent_id not in self.files_list.keys():
# We need to get the files list # We need to get the files list
log.debug("Getting file list from core..") log.debug("Getting file list from core..")
client.get_torrent_status( status_keys += ["files"]
self._on_get_torrent_files,
self.torrent_id,
["files", "file_progress", "file_priorities"])
client.force_call(block=True)
else: else:
# We already have the files list stored, so just update the view
self.update_files() self.update_files()
client.get_torrent_status(self._on_get_torrent_status, self.torrent_id, ["file_progress", "file_priorities"])
client.force_call(True) client.get_torrent_status(self._on_get_torrent_status, self.torrent_id, status_keys)
else: client.force_call(True)
client.get_torrent_status(self._on_get_torrent_status, self.torrent_id, ["file_progress", "file_priorities"])
client.force_call(True)
def clear(self): def clear(self):
self.treestore.clear() self.treestore.clear()
@ -381,11 +386,6 @@ class FilesTab(Tab):
return selected return selected
def _on_get_torrent_files(self, status):
self.files_list[self.torrent_id] = status["files"]
self.update_files()
self._on_get_torrent_status(status)
def get_files_from_tree(self, rows, files_list, indent): def get_files_from_tree(self, rows, files_list, indent):
if not rows: if not rows:
return None return None
@ -397,6 +397,14 @@ class FilesTab(Tab):
return None return None
def _on_get_torrent_status(self, status): def _on_get_torrent_status(self, status):
# Store this torrent's compact setting
if "compact" in status:
self.__compact = status["compact"]
if "files" in status:
self.files_list[self.torrent_id] = status["files"]
self.update_files()
# (index, iter) # (index, iter)
files_list = [] files_list = []
self.get_files_from_tree(self.treestore, files_list, 0) self.get_files_from_tree(self.treestore, files_list, 0)
@ -435,6 +443,9 @@ class FilesTab(Tab):
else: else:
self.listview.get_selection().select_iter(row) self.listview.get_selection().select_iter(row)
for widget in self.file_menu_priority_items:
widget.set_sensitive(not self.__compact)
self.file_menu.popup(None, None, None, event.button, event.time) self.file_menu.popup(None, None, None, event.button, event.time)
return True return True

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd"> <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.4.5 on Fri Nov 7 23:40:25 2008 --> <!--Generated with glade3 3.4.5 on Mon Dec 8 20:38:17 2008 -->
<glade-interface> <glade-interface>
<widget class="GtkDialog" id="dialog_add_torrent"> <widget class="GtkDialog" id="dialog_add_torrent">
<property name="height_request">560</property> <property name="height_request">560</property>
@ -472,7 +472,6 @@
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Full</property> <property name="label" translatable="yes">Full</property>
<property name="response_id">0</property> <property name="response_id">0</property>
<property name="active">True</property>
<property name="draw_indicator">True</property> <property name="draw_indicator">True</property>
</widget> </widget>
<packing> <packing>
@ -487,7 +486,6 @@
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="label" translatable="yes">Compact</property> <property name="label" translatable="yes">Compact</property>
<property name="response_id">0</property> <property name="response_id">0</property>
<property name="active">True</property>
<property name="draw_indicator">True</property> <property name="draw_indicator">True</property>
<property name="group">radio_full</property> <property name="group">radio_full</property>
</widget> </widget>
@ -538,7 +536,7 @@
<property name="n_columns">2</property> <property name="n_columns">2</property>
<property name="column_spacing">10</property> <property name="column_spacing">10</property>
<child> <child>
<widget class="GtkSpinButton" id="spin_maxupslots"> <widget class="GtkSpinButton" id="spin_maxdown">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
@ -548,26 +546,61 @@
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
<property name="right_attach">2</property> <property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options"></property> <property name="x_options"></property>
<property name="y_options"></property> <property name="y_options"></property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkSpinButton" id="spin_maxconnections"> <widget class="GtkLabel" id="label11">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">1</property> <property name="xalign">0</property>
<property name="adjustment">-1 -1 9999 1 10 0</property> <property name="label" translatable="yes">Max Down Speed:</property>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label12">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Max Up Speed:</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label13">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Max Connections:</property>
</widget> </widget>
<packing> <packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property> <property name="top_attach">2</property>
<property name="bottom_attach">3</property> <property name="bottom_attach">3</property>
<property name="x_options"></property> <property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label14">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Max Upload Slots:</property>
</widget>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property> <property name="y_options"></property>
</packing> </packing>
</child> </child>
@ -590,61 +623,7 @@
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkLabel" id="label14"> <widget class="GtkSpinButton" id="spin_maxconnections">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Max Upload Slots:</property>
</widget>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label13">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Max Connections:</property>
</widget>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label12">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Max Up Speed:</property>
</widget>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label11">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">Max Down Speed:</property>
</widget>
<packing>
<property name="x_options">GTK_FILL</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_maxdown">
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property> <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
@ -654,6 +633,25 @@
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
<property name="right_attach">2</property> <property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options"></property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkSpinButton" id="spin_maxupslots">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
<property name="xalign">1</property>
<property name="adjustment">-1 -1 9999 1 10 0</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
<property name="x_options"></property> <property name="x_options"></property>
<property name="y_options"></property> <property name="y_options"></property>
</packing> </packing>

File diff suppressed because it is too large Load Diff