Merge branch 'master' into multiuser-oldprefs

This commit is contained in:
Pedro Algarvio 2011-04-27 13:15:05 +01:00
commit e6773dfce1
3 changed files with 75 additions and 11 deletions

View file

@ -43,7 +43,23 @@ import deluge.common
import os,base64,glob
import logging
log = logging.getLogger(__name__)
def __bracket_fixup(path):
if (path.find("[") == -1 and
path.find("]") == -1):
return path
sentinal = 256
while (path.find(unichr(sentinal)) != -1):
sentinal+=1
if sentinal > 65535:
log.error("Can't fix brackets in path, path contains all possible sentinal characters")
return path
newpath = path.replace("]",unichr(sentinal))
newpath = newpath.replace("[","[[]")
newpath = newpath.replace(unichr(sentinal),"[]]")
return newpath
def add_torrent(t_file, options, success_cb, fail_cb, ress):
t_options = {}
@ -57,7 +73,7 @@ def add_torrent(t_file, options, success_cb, fail_cb, ress):
if is_url or is_mag:
files = [t_file]
else:
files = glob.glob(t_file)
files = glob.glob(__bracket_fixup(t_file))
num_files = len(files)
ress["total"] = num_files

View file

@ -81,7 +81,7 @@ this one) using the up/down arrows.
All popup windows can be closed/canceled by hitting the Esc key \
(you might need to wait a second for an Esc to register)
The actions you can perform and the keys to perform them are as follows: \
The actions you can perform and the keys to perform them are as follows:
{!info!}'h'{!normal!} - Show this help
@ -113,7 +113,7 @@ about the currently selected torrent, as well as a view of the \
files in the torrent and the ability to set file priorities.
{!info!}Enter{!normal!} - Show torrent actions popup. Here you can do things like \
pause/resume, remove, recheck and so one. These actions \
pause/resume, remove, recheck and so on. These actions \
apply to all currently marked torrents. The currently \
selected torrent is automatically marked when you press enter.
@ -274,6 +274,8 @@ class AllTorrents(BaseMode, component.Component):
self.__cols_to_show = [pref for pref in column_pref_names if self.config["show_%s"%pref]]
self.__columns = [prefs_to_names[col] for col in self.__cols_to_show]
self.__status_fields = column.get_required_fields(self.__columns)
for rf in ["state","name","queue"]: # we always need these, even if we're not displaying them
if not rf in self.__status_fields: self.__status_fields.append(rf)
self.__update_columns()
def __split_help(self):
@ -293,10 +295,11 @@ class AllTorrents(BaseMode, component.Component):
else:
rem = self.cols - req
var_cols = len(filter(lambda x: x < 0,self.column_widths))
vw = int(rem/var_cols)
for i in range(0, len(self.column_widths)):
if (self.column_widths[i] < 0):
self.column_widths[i] = vw
if (var_cols > 0):
vw = int(rem/var_cols)
for i in range(0, len(self.column_widths)):
if (self.column_widths[i] < 0):
self.column_widths[i] = vw
self.column_string = "{!header!}%s"%("".join(["%s%s"%(self.__columns[i]," "*(self.column_widths[i]-len(self.__columns[i]))) for i in range(0,len(self.__columns))]))
@ -813,8 +816,12 @@ class AllTorrents(BaseMode, component.Component):
effected_lines = [self.cursel-1]
elif chr(c) == 'M':
if self.last_mark >= 0:
self.marked.extend(range(self.last_mark,self.cursel+1))
effected_lines = range(self.last_mark,self.cursel)
if (self.cursel+1) > self.last_mark:
mrange = range(self.last_mark,self.cursel+1)
else:
mrange = range(self.cursel-1,self.last_mark)
self.marked.extend(mrange[1:])
effected_lines = mrange
else:
self._mark_unmark(self.cursel)
effected_lines = [self.cursel-1]

View file

@ -59,6 +59,35 @@ except ImportError:
import logging
log = logging.getLogger(__name__)
# Big help string that gets displayed when the user hits 'h'
HELP_STR = """\
This screen shows detailed information about a torrent, and also the \
information about the individual files in the torrent.
You can navigate the file list with the Up/Down arrows and use space to \
collapse/expand the file tree.
All popup windows can be closed/canceled by hitting the Esc key \
(you might need to wait a second for an Esc to register)
The actions you can perform and the keys to perform them are as follows:
{!info!}'h'{!normal!} - Show this help
{!info!}'a'{!normal!} - Show torrent actions popup. Here you can do things like \
pause/resume, remove, recheck and so on.
{!info!}'m'{!normal!} - Mark a file
{!info!}'c'{!normal!} - Un-mark all files
{!info!}Space{!normal!} - Expand/Collapse currently selected folder
{!info!}Enter{!normal!} - Show priority popup in which you can set the \
download priority of selected files.
{!info!}Left Arrow{!normal!} - Go back to torrent overview.
"""
class TorrentDetail(BaseMode, component.Component):
def __init__(self, alltorrentmode, torrentid, stdscr, encoding=None):
self.alltorrentmode = alltorrentmode
@ -106,6 +135,8 @@ class TorrentDetail(BaseMode, component.Component):
BaseMode.__init__(self, stdscr, encoding)
component.Component.__init__(self, "TorrentDetail", 1, depend=["SessionProxy"])
self.__split_help()
self.column_names = ["Filename", "Size", "Progress", "Priority"]
self._update_columns()
@ -137,6 +168,9 @@ class TorrentDetail(BaseMode, component.Component):
self.torrent_state = state
self.refresh()
def __split_help(self):
self.__help_lines = format_utils.wrap_string(HELP_STR,(self.cols/2)-2)
# split file list into directory tree. this function assumes all files in a
# particular directory are returned together. it won't work otherwise.
# returned list is a list of lists of the form:
@ -288,6 +322,7 @@ class TorrentDetail(BaseMode, component.Component):
def on_resize(self, *args):
BaseMode.on_resize_norefresh(self, *args)
self._update_columns()
self.__split_help()
if self.popup:
self.popup.handle_resize()
self.refresh()
@ -447,6 +482,10 @@ class TorrentDetail(BaseMode, component.Component):
self.back_to_overview()
return
if not self.torrent_state:
# actions below only makes sense if there is a torrent state
return
# Navigate the torrent list
if c == curses.KEY_UP:
self.file_list_up()
@ -470,10 +509,12 @@ class TorrentDetail(BaseMode, component.Component):
if chr(c) == 'm':
if self.current_file:
self._mark_unmark(self.current_file[1])
if chr(c) == 'c':
elif chr(c) == 'c':
self.marked = {}
if chr(c) == 'a':
elif chr(c) == 'a':
torrent_actions_popup(self,[self.torrentid],details=False)
return
elif chr(c) == 'h':
self.popup = Popup(self,"Help",init_lines=self.__help_lines)
self.refresh()