Added files priorities.

This commit is contained in:
Alex Dedul 2007-07-18 12:47:24 +00:00
parent 9310c7dce5
commit 280f4dfb10
6 changed files with 520 additions and 510 deletions

View File

@ -1,100 +1,103 @@
<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> <!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--*- mode: xml -*-->
<glade-interface> <glade-interface>
<widget class="GtkMenu" id="file_tab_menu">
<widget class="GtkMenu" id="file_tab_menu"> <property name="visible">True</property>
<property name="visible">True</property> <child>
<widget class="GtkImageMenuItem" id="select_all">
<child> <property name="visible">True</property>
<widget class="GtkImageMenuItem" id="select_all"> <property name="label" translatable="yes">Select All</property>
<property name="visible">True</property> <property name="use_underline">True</property>
<property name="label" translatable="yes">Select All</property> <signal name="activate" handler="select_all"/>
<property name="use_underline">True</property> <child internal-child="image">
<signal name="activate" handler="select_all" last_modification_time="Mon, 11 Jun 2007 12:54:52 GMT"/> <widget class="GtkImage" id="image22">
<property name="visible">True</property>
<child internal-child="image"> <property name="stock">gtk-select-all</property>
<widget class="GtkImage" id="image22"> <property name="icon_size">1</property>
<property name="visible">True</property> </widget>
<property name="stock">gtk-select-all</property> </child>
<property name="icon_size">1</property> </widget>
<property name="xalign">0.5</property> </child>
<property name="yalign">0.5</property> <child>
<property name="xpad">0</property> <widget class="GtkImageMenuItem" id="unselect_all">
<property name="ypad">0</property> <property name="visible">True</property>
</widget> <property name="label" translatable="yes">Unselect All</property>
</child> <property name="use_underline">True</property>
</widget> <signal name="activate" handler="unselect_all"/>
</child> <child internal-child="image">
<widget class="GtkImage" id="image23">
<child> <property name="visible">True</property>
<widget class="GtkImageMenuItem" id="unselect_all"> <property name="stock">gtk-missing-image</property>
<property name="visible">True</property> <property name="icon_size">1</property>
<property name="label" translatable="yes">Unselect All</property> </widget>
<property name="use_underline">True</property> </child>
<signal name="activate" handler="unselect_all" last_modification_time="Mon, 11 Jun 2007 13:16:59 GMT"/> </widget>
</child>
<child internal-child="image"> <child>
<widget class="GtkImage" id="image23"> <widget class="GtkSeparatorMenuItem" id="separator">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-file</property> </widget>
<property name="icon_size">1</property> </child>
<property name="xalign">0.5</property> <child>
<property name="yalign">0.5</property> <widget class="GtkImageMenuItem" id="priority_dont_download">
<property name="xpad">0</property> <property name="visible">True</property>
<property name="ypad">0</property> <property name="label" translatable="yes">Don't download</property>
</widget> <property name="use_underline">True</property>
</child> <signal name="activate" handler="priority_dont_download"/>
</widget> <child internal-child="image">
</child> <widget class="GtkImage" id="image24">
<property name="visible">True</property>
<child> <property name="stock">gtk-ok</property>
<widget class="GtkSeparatorMenuItem" id="separator"> <property name="icon_size">1</property>
<property name="visible">True</property> </widget>
</widget> </child>
</child> </widget>
</child>
<child> <child>
<widget class="GtkImageMenuItem" id="check_selected"> <widget class="GtkImageMenuItem" id="priority_normal">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">Check Selected</property> <property name="label" translatable="yes">Normal</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<signal name="activate" handler="check_selected" last_modification_time="Mon, 11 Jun 2007 12:54:52 GMT"/> <signal name="activate" handler="priority_normal"/>
<child internal-child="image">
<child internal-child="image"> <widget class="GtkImage" id="image25">
<widget class="GtkImage" id="image24"> <property name="visible">True</property>
<property name="visible">True</property> <property name="stock">gtk-ok</property>
<property name="stock">gtk-ok</property> <property name="icon_size">1</property>
<property name="icon_size">1</property> </widget>
<property name="xalign">0.5</property> </child>
<property name="yalign">0.5</property> </widget>
<property name="xpad">0</property> </child>
<property name="ypad">0</property> <child>
</widget> <widget class="GtkImageMenuItem" id="priority_high">
</child> <property name="visible">True</property>
</widget> <property name="label" translatable="yes">High</property>
</child> <property name="use_underline">True</property>
<signal name="activate" handler="priority_high"/>
<child> <child internal-child="image">
<widget class="GtkImageMenuItem" id="uncheck_selected"> <widget class="GtkImage" id="image26">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">Uncheck Selected</property> <property name="stock">gtk-ok</property>
<property name="use_underline">True</property> <property name="icon_size">1</property>
<signal name="activate" handler="uncheck_selected" last_modification_time="Mon, 11 Jun 2007 12:54:52 GMT"/> </widget>
</child>
<child internal-child="image"> </widget>
<widget class="GtkImage" id="image25"> </child>
<property name="visible">True</property> <child>
<property name="stock">gtk-remove</property> <widget class="GtkImageMenuItem" id="priority_highest">
<property name="icon_size">1</property> <property name="visible">True</property>
<property name="xalign">0.5</property> <property name="label" translatable="yes">Highest</property>
<property name="yalign">0.5</property> <property name="use_underline">True</property>
<property name="xpad">0</property> <signal name="activate" handler="priority_highest"/>
<property name="ypad">0</property> <child internal-child="image">
</widget> <widget class="GtkImage" id="image27">
</child> <property name="visible">True</property>
</widget> <property name="stock">gtk-ok</property>
</child> <property name="icon_size">1</property>
</widget> </widget>
</child>
</widget>
</child>
</widget>
</glade-interface> </glade-interface>

File diff suppressed because it is too large Load Diff

View File

@ -105,6 +105,9 @@ def ftime(seconds):
return '%dw %dd'%(weeks, days) return '%dw %dd'%(weeks, days)
return 'unknown' return 'unknown'
def fpriority(priority):
return PRIORITY_DICT[priority]
def get_glade_file(fname): def get_glade_file(fname):
return os.path.join(GLADE_DIR, fname) return os.path.join(GLADE_DIR, fname)
@ -150,6 +153,9 @@ def fetch_url(url):
return None return None
def N_(arg):
return arg
# Encryption States # Encryption States
class EncState: class EncState:
forced, enabled, disabled = range(3) forced, enabled, disabled = range(3)
@ -159,3 +165,14 @@ class EncLevel:
class ProxyType: class ProxyType:
none, socks4, socks5, socks5_pw, http, http_pw = range(6) none, socks4, socks5, socks5_pw, http, http_pw = range(6)
# Priorities
PRIORITY_DONT_DOWNLOAD = 0
PRIORITY_NORMAL = 1
PRIORITY_HIGH = 2
PRIORITY_HIGHEST = 6
PRIORITY_DICT = {PRIORITY_DONT_DOWNLOAD: N_("Don't download"),
PRIORITY_NORMAL: N_("Normal"),
PRIORITY_HIGH: N_("High"),
PRIORITY_HIGHEST: N_("Highest")}

View File

@ -53,6 +53,7 @@ import shutil
import statvfs import statvfs
import time import time
from common import N_, PRIORITY_NORMAL
import deluge_core import deluge_core
import pref import pref
@ -80,9 +81,6 @@ PREF_FUNCTIONS = {
"use_utpex" : deluge_core.use_utpex, "use_utpex" : deluge_core.use_utpex,
} }
def N_(self):
return self
STATE_MESSAGES = (N_("Queued"), STATE_MESSAGES = (N_("Queued"),
N_("Checking"), N_("Checking"),
N_("Connecting"), N_("Connecting"),
@ -634,7 +632,7 @@ class Manager:
num_files = self.get_core_torrent_state(unique_ID, num_files = self.get_core_torrent_state(unique_ID,
True)['num_files'] True)['num_files']
return [1] * num_files return [PRIORITY_NORMAL] * num_files
# Called when a session starts, to apply existing priorities # Called when a session starts, to apply existing priorities
def apply_all_file_priorities(self): def apply_all_file_priorities(self):

View File

@ -30,23 +30,27 @@
# this exception statement from your version. If you delete this exception # this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here. # statement from all source files in the program, then also delete it here.
import gtk
import dgtk
import common
from itertools import izip from itertools import izip
import gobject import gobject
import gtk
import common
import dgtk
class FilesBaseManager(object): class FilesBaseManager(object):
def __init__(self, file_store): def __init__(self, file_store):
self.file_glade = gtk.glade.XML(common.get_glade_file("file_tab_menu.glade"), file_glade = gtk.glade.XML(common.get_glade_file("file_tab_menu.glade"),
domain='deluge') domain='deluge')
self.file_menu = self.file_glade.get_widget("file_tab_menu") self.file_menu = file_glade.get_widget("file_tab_menu")
self.file_glade.signal_autoconnect({ file_glade.signal_autoconnect({
"select_all": self.file_select_all, "select_all": self.file_select_all,
"unselect_all": self.file_unselect_all, "unselect_all": self.file_unselect_all,
"check_selected": self.file_check_selected, "priority_dont_download": self.priority_clicked,
"uncheck_selected": self.file_uncheck_selected, "priority_normal": self.priority_clicked,
}) "priority_high": self.priority_clicked,
"priority_highest": self.priority_clicked,
})
self.file_store = file_store self.file_store = file_store
# We need file_store_sorted so original file_store keeps unchanged # We need file_store_sorted so original file_store keeps unchanged
@ -57,20 +61,21 @@ class FilesBaseManager(object):
def build_file_view(self, file_view): def build_file_view(self, file_view):
self.file_view = file_view self.file_view = file_view
self.file_selected = []
dgtk.add_toggle_column(self.file_view, _("Priority"), 0, def priority(column, cell, model, iter, data):
toggled_signal=self.file_toggled) priority = common.fpriority(model.get_value(iter, data))
cell.set_property("text", priority)
filename_column = dgtk.add_text_column(self.file_view, _("Filename"), filename_column = dgtk.add_text_column(self.file_view, _("Filename"),
1) 0)
filename_column.set_expand(True) filename_column.set_expand(True)
dgtk.add_func_column(self.file_view, _("Size"), dgtk.cell_data_size, dgtk.add_func_column(self.file_view, _("Size"), dgtk.cell_data_size,
2) 1)
dgtk.add_func_column(self.file_view, _("Priority"), priority, 2)
self.file_view.set_model(self.file_store_sorted) self.file_view.set_model(self.file_store_sorted)
self.file_view.get_selection().set_mode(gtk.SELECTION_MULTIPLE) self.file_view.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
self.file_view.get_selection().set_select_function(self.file_clicked) self.file_view.connect("button-press-event", self.mouse_clicked)
self.file_view.connect("button-press-event", self.file_view_clicked)
def clear_file_store(self): def clear_file_store(self):
self.file_store.clear() self.file_store.clear()
@ -85,60 +90,37 @@ class FilesBaseManager(object):
def file_unselect_all(self, widget): def file_unselect_all(self, widget):
self.file_view.get_selection().unselect_all() self.file_view.get_selection().unselect_all()
def file_check_selected(self, widget): def priority_clicked(self, widget):
self.file_view.get_selection().selected_foreach(self.file_toggle_selected, True) widget_name = widget.get_name()
self.file_toggled_update_priorities() priority = {'priority_dont_download': common.PRIORITY_DONT_DOWNLOAD,
'priority_normal': common.PRIORITY_NORMAL,
'priority_high': common.PRIORITY_HIGH,
'priority_highest': common.PRIORITY_HIGHEST}[widget_name]
def file_uncheck_selected(self, widget): selected_paths = self.file_view.get_selection().get_selected_rows()[1]
self.file_view.get_selection().selected_foreach(self.file_toggle_selected, False) for path in selected_paths:
self.file_toggled_update_priorities() child_path = self.file_store_sorted.\
convert_path_to_child_path(path)
def file_clicked(self, path): self.file_store.set_value(self.file_store.get_iter(child_path), 2,
return not self.file_selected priority)
def file_view_clicked(self, widget, event): self.update_priorities()
def mouse_clicked(self, widget, event):
if event.button == 3: if event.button == 3:
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
else: else:
self.file_selected = False
return False return False
def file_toggle_selected(self, treemodel, path, selected_iter, value): def update_priorities(self):
child_iter = self.file_store_sorted.convert_iter_to_child_iter(None,
selected_iter)
if value:
new_value = 1
else:
new_value = 0
self.file_store_sorted.get_model().set_value(child_iter, 0, new_value)
def file_toggled(self, renderer, path):
self.file_selected = True
value = not renderer.get_active()
if value:
new_value = 1
else:
new_value = 0
file_iter = self.file_store_sorted.get_iter_from_string(path)
selection = self.file_view.get_selection()
if selection.iter_is_selected(file_iter):
selection.selected_foreach(self.file_toggle_selected, value)
else:
child_iter = self.file_store_sorted.convert_iter_to_child_iter(
None, file_iter)
self.file_store_sorted.get_model().set_value(child_iter, 0,
new_value)
self.file_toggled_update_priorities()
def file_toggled_update_priorities(self):
pass pass
class FilesTabManager(FilesBaseManager): class FilesTabManager(FilesBaseManager):
def __init__(self, manager): def __init__(self, manager):
file_store = gtk.ListStore(int, str, gobject.TYPE_UINT64, float) file_store = gtk.ListStore(str, gobject.TYPE_UINT64,
gobject.TYPE_UINT, float)
super(FilesTabManager, self).__init__(file_store) super(FilesTabManager, self).__init__(file_store)
@ -161,16 +143,17 @@ class FilesTabManager(FilesBaseManager):
def set_unique_id(self, unique_id): def set_unique_id(self, unique_id):
self.file_unique_id = unique_id self.file_unique_id = unique_id
# From core to UI
def prepare_file_store(self): def prepare_file_store(self):
if not self.file_store_dict: if not self.file_store_dict:
all_files = self.manager.get_torrent_file_info(self.file_unique_id) all_files = self.manager.get_torrent_file_info(self.file_unique_id)
file_priorities = self.manager.get_priorities(self.file_unique_id) file_priorities = self.manager.get_priorities(self.file_unique_id)
for file, priority in izip(all_files, file_priorities): for file, priority in izip(all_files, file_priorities):
iter = self.file_store.append([priority, file['path'], iter = self.file_store.append([file['path'], file['size'],
file['size'], priority, round(file['progress'], 2)])
round(file['progress'], 2)])
self.file_store_dict[file['path']] = iter self.file_store_dict[file['path']] = iter
# From core to UI
def update_file_store(self): def update_file_store(self):
new_file_info = self.manager.get_torrent_file_info(self.file_unique_id) new_file_info = self.manager.get_torrent_file_info(self.file_unique_id)
for file in new_file_info: for file in new_file_info:
@ -178,26 +161,29 @@ class FilesTabManager(FilesBaseManager):
if self.file_store.get_value(iter, 3) != round(file['progress'], 2): if self.file_store.get_value(iter, 3) != round(file['progress'], 2):
self.file_store.set(iter, 3, file['progress']) self.file_store.set(iter, 3, file['progress'])
def file_toggled_update_priorities(self): # From UI to core
def update_priorities(self):
file_priorities = [] file_priorities = []
for x in self.file_store: for x in self.file_store:
file_priorities.append(x[0]) file_priorities.append(x[2])
self.manager.prioritize_files(self.file_unique_id, file_priorities) self.manager.prioritize_files(self.file_unique_id, file_priorities)
class FilesDialogManager(FilesBaseManager): class FilesDialogManager(FilesBaseManager):
def __init__(self, dumped_torrent): def __init__(self, dumped_torrent):
file_store = gtk.ListStore(int, str, gobject.TYPE_UINT64) file_store = gtk.ListStore(str, gobject.TYPE_UINT64,
gobject.TYPE_UINT)
super(FilesDialogManager, self).__init__(file_store) super(FilesDialogManager, self).__init__(file_store)
self.dumped_torrent = dumped_torrent self.dumped_torrent = dumped_torrent
def prepare_file_store(self): def prepare_file_store(self):
for file in self.dumped_torrent: for file in self.dumped_torrent:
self.file_store.append([1, file['path'], file['size']]) self.file_store.append([file['path'], file['size'],
common.PRIORITY_NORMAL])
def get_priorities(self): def get_priorities(self):
file_priorities = [] file_priorities = []
for x in self.file_store: for x in self.file_store:
file_priorities.append(x[0]) file_priorities.append(x[2])
return file_priorities return file_priorities

View File

@ -955,6 +955,9 @@ class DelugeGTK:
# unique_id param # unique_id param
if unique_id is None: if unique_id is None:
unique_id = self.get_selected_torrent() unique_id = self.get_selected_torrent()
# If no torrents added
if unique_id is None:
return
# page_num is to force update info when user just changes tab # page_num is to force update info when user just changes tab
if page_num is None: if page_num is None:
page_num = self.wtree.get_widget("torrent_info").get_current_page() page_num = self.wtree.get_widget("torrent_info").get_current_page()
@ -1023,7 +1026,6 @@ class DelugeGTK:
self.files_tab.prepare_file_store() self.files_tab.prepare_file_store()
self.files_tab.update_file_store() self.files_tab.update_file_store()
def calc_share_ratio(self, unique_id, torrent_state): def calc_share_ratio(self, unique_id, torrent_state):
r = float(self.manager.calc_ratio(unique_id, torrent_state)) r = float(self.manager.calc_ratio(unique_id, torrent_state))
return r return r