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 -*-->
<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--*- mode: xml -*-->
<glade-interface>
<widget class="GtkMenu" id="file_tab_menu">
<property name="visible">True</property>
<child>
<widget class="GtkImageMenuItem" id="select_all">
<property name="visible">True</property>
<property name="label" translatable="yes">Select All</property>
<property name="use_underline">True</property>
<signal name="activate" handler="select_all" last_modification_time="Mon, 11 Jun 2007 12:54:52 GMT"/>
<child internal-child="image">
<widget class="GtkImage" id="image22">
<property name="visible">True</property>
<property name="stock">gtk-select-all</property>
<property name="icon_size">1</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="unselect_all">
<property name="visible">True</property>
<property name="label" translatable="yes">Unselect All</property>
<property name="use_underline">True</property>
<signal name="activate" handler="unselect_all" last_modification_time="Mon, 11 Jun 2007 13:16:59 GMT"/>
<child internal-child="image">
<widget class="GtkImage" id="image23">
<property name="visible">True</property>
<property name="stock">gtk-file</property>
<property name="icon_size">1</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkSeparatorMenuItem" id="separator">
<property name="visible">True</property>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="check_selected">
<property name="visible">True</property>
<property name="label" translatable="yes">Check Selected</property>
<property name="use_underline">True</property>
<signal name="activate" handler="check_selected" last_modification_time="Mon, 11 Jun 2007 12:54:52 GMT"/>
<child internal-child="image">
<widget class="GtkImage" id="image24">
<property name="visible">True</property>
<property name="stock">gtk-ok</property>
<property name="icon_size">1</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="uncheck_selected">
<property name="visible">True</property>
<property name="label" translatable="yes">Uncheck Selected</property>
<property name="use_underline">True</property>
<signal name="activate" handler="uncheck_selected" last_modification_time="Mon, 11 Jun 2007 12:54:52 GMT"/>
<child internal-child="image">
<widget class="GtkImage" id="image25">
<property name="visible">True</property>
<property name="stock">gtk-remove</property>
<property name="icon_size">1</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
</child>
</widget>
<widget class="GtkMenu" id="file_tab_menu">
<property name="visible">True</property>
<child>
<widget class="GtkImageMenuItem" id="select_all">
<property name="visible">True</property>
<property name="label" translatable="yes">Select All</property>
<property name="use_underline">True</property>
<signal name="activate" handler="select_all"/>
<child internal-child="image">
<widget class="GtkImage" id="image22">
<property name="visible">True</property>
<property name="stock">gtk-select-all</property>
<property name="icon_size">1</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="unselect_all">
<property name="visible">True</property>
<property name="label" translatable="yes">Unselect All</property>
<property name="use_underline">True</property>
<signal name="activate" handler="unselect_all"/>
<child internal-child="image">
<widget class="GtkImage" id="image23">
<property name="visible">True</property>
<property name="stock">gtk-missing-image</property>
<property name="icon_size">1</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkSeparatorMenuItem" id="separator">
<property name="visible">True</property>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="priority_dont_download">
<property name="visible">True</property>
<property name="label" translatable="yes">Don't download</property>
<property name="use_underline">True</property>
<signal name="activate" handler="priority_dont_download"/>
<child internal-child="image">
<widget class="GtkImage" id="image24">
<property name="visible">True</property>
<property name="stock">gtk-ok</property>
<property name="icon_size">1</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="priority_normal">
<property name="visible">True</property>
<property name="label" translatable="yes">Normal</property>
<property name="use_underline">True</property>
<signal name="activate" handler="priority_normal"/>
<child internal-child="image">
<widget class="GtkImage" id="image25">
<property name="visible">True</property>
<property name="stock">gtk-ok</property>
<property name="icon_size">1</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="priority_high">
<property name="visible">True</property>
<property name="label" translatable="yes">High</property>
<property name="use_underline">True</property>
<signal name="activate" handler="priority_high"/>
<child internal-child="image">
<widget class="GtkImage" id="image26">
<property name="visible">True</property>
<property name="stock">gtk-ok</property>
<property name="icon_size">1</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="priority_highest">
<property name="visible">True</property>
<property name="label" translatable="yes">Highest</property>
<property name="use_underline">True</property>
<signal name="activate" handler="priority_highest"/>
<child internal-child="image">
<widget class="GtkImage" id="image27">
<property name="visible">True</property>
<property name="stock">gtk-ok</property>
<property name="icon_size">1</property>
</widget>
</child>
</widget>
</child>
</widget>
</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 'unknown'
def fpriority(priority):
return PRIORITY_DICT[priority]
def get_glade_file(fname):
return os.path.join(GLADE_DIR, fname)
@ -150,6 +153,9 @@ def fetch_url(url):
return None
def N_(arg):
return arg
# Encryption States
class EncState:
forced, enabled, disabled = range(3)
@ -159,3 +165,14 @@ class EncLevel:
class ProxyType:
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 time
from common import N_, PRIORITY_NORMAL
import deluge_core
import pref
@ -80,9 +81,6 @@ PREF_FUNCTIONS = {
"use_utpex" : deluge_core.use_utpex,
}
def N_(self):
return self
STATE_MESSAGES = (N_("Queued"),
N_("Checking"),
N_("Connecting"),
@ -634,7 +632,7 @@ class Manager:
num_files = self.get_core_torrent_state(unique_ID,
True)['num_files']
return [1] * num_files
return [PRIORITY_NORMAL] * num_files
# Called when a session starts, to apply existing priorities
def apply_all_file_priorities(self):

View File

@ -30,23 +30,27 @@
# this exception statement from your version. If you delete this exception
# statement from all source files in the program, then also delete it here.
import gtk
import dgtk
import common
from itertools import izip
import gobject
import gtk
import common
import dgtk
class FilesBaseManager(object):
def __init__(self, file_store):
self.file_glade = gtk.glade.XML(common.get_glade_file("file_tab_menu.glade"),
domain='deluge')
self.file_menu = self.file_glade.get_widget("file_tab_menu")
self.file_glade.signal_autoconnect({
"select_all": self.file_select_all,
"unselect_all": self.file_unselect_all,
"check_selected": self.file_check_selected,
"uncheck_selected": self.file_uncheck_selected,
})
file_glade = gtk.glade.XML(common.get_glade_file("file_tab_menu.glade"),
domain='deluge')
self.file_menu = file_glade.get_widget("file_tab_menu")
file_glade.signal_autoconnect({
"select_all": self.file_select_all,
"unselect_all": self.file_unselect_all,
"priority_dont_download": self.priority_clicked,
"priority_normal": self.priority_clicked,
"priority_high": self.priority_clicked,
"priority_highest": self.priority_clicked,
})
self.file_store = file_store
# 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):
self.file_view = file_view
self.file_selected = []
dgtk.add_toggle_column(self.file_view, _("Priority"), 0,
toggled_signal=self.file_toggled)
def priority(column, cell, model, iter, data):
priority = common.fpriority(model.get_value(iter, data))
cell.set_property("text", priority)
filename_column = dgtk.add_text_column(self.file_view, _("Filename"),
1)
0)
filename_column.set_expand(True)
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.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.file_view_clicked)
self.file_view.connect("button-press-event", self.mouse_clicked)
def clear_file_store(self):
self.file_store.clear()
@ -85,60 +90,37 @@ class FilesBaseManager(object):
def file_unselect_all(self, widget):
self.file_view.get_selection().unselect_all()
def file_check_selected(self, widget):
self.file_view.get_selection().selected_foreach(self.file_toggle_selected, True)
self.file_toggled_update_priorities()
def priority_clicked(self, widget):
widget_name = widget.get_name()
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):
self.file_view.get_selection().selected_foreach(self.file_toggle_selected, False)
self.file_toggled_update_priorities()
selected_paths = self.file_view.get_selection().get_selected_rows()[1]
for path in selected_paths:
child_path = self.file_store_sorted.\
convert_path_to_child_path(path)
def file_clicked(self, path):
return not self.file_selected
self.file_store.set_value(self.file_store.get_iter(child_path), 2,
priority)
def file_view_clicked(self, widget, event):
self.update_priorities()
def mouse_clicked(self, widget, event):
if event.button == 3:
self.file_menu.popup(None, None, None, event.button, event.time)
return True
else:
self.file_selected = False
return False
def file_toggle_selected(self, treemodel, path, selected_iter, value):
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):
def update_priorities(self):
pass
class FilesTabManager(FilesBaseManager):
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)
@ -161,16 +143,17 @@ class FilesTabManager(FilesBaseManager):
def set_unique_id(self, unique_id):
self.file_unique_id = unique_id
# From core to UI
def prepare_file_store(self):
if not self.file_store_dict:
all_files = self.manager.get_torrent_file_info(self.file_unique_id)
file_priorities = self.manager.get_priorities(self.file_unique_id)
for file, priority in izip(all_files, file_priorities):
iter = self.file_store.append([priority, file['path'],
file['size'],
round(file['progress'], 2)])
iter = self.file_store.append([file['path'], file['size'],
priority, round(file['progress'], 2)])
self.file_store_dict[file['path']] = iter
# From core to UI
def update_file_store(self):
new_file_info = self.manager.get_torrent_file_info(self.file_unique_id)
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):
self.file_store.set(iter, 3, file['progress'])
def file_toggled_update_priorities(self):
# From UI to core
def update_priorities(self):
file_priorities = []
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)
class FilesDialogManager(FilesBaseManager):
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)
self.dumped_torrent = dumped_torrent
def prepare_file_store(self):
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):
file_priorities = []
for x in self.file_store:
file_priorities.append(x[0])
file_priorities.append(x[2])
return file_priorities

View File

@ -955,6 +955,9 @@ class DelugeGTK:
# unique_id param
if unique_id is None:
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
if page_num is None:
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.update_file_store()
def calc_share_ratio(self, unique_id, torrent_state):
r = float(self.manager.calc_ratio(unique_id, torrent_state))
return r