Module: deluge
Branch: master
Commit: 7053163f88b475b5121189e724bb402bf48d3e9b

Author: Damien Churchill <[email protected]>
Date:   Wed Mar 31 14:20:49 2010 +0100

use FileTree2 in the TorrentInfo class when specified
adjust the filetree walking functions to match the server side code

---

 deluge/ui/common.py                             |   43 +++++++++++++++++------
 deluge/ui/web/js/deluge-all/add/OptionsPanel.js |   22 ++++-------
 deluge/ui/web/json_api.py                       |    5 ++-
 3 files changed, 43 insertions(+), 27 deletions(-)

diff --git a/deluge/ui/common.py b/deluge/ui/common.py
index 3287230..caedef0 100644
--- a/deluge/ui/common.py
+++ b/deluge/ui/common.py
@@ -80,7 +80,7 @@ class TorrentInfo(object):
     :type filename: string
 
     """
-    def __init__(self, filename):
+    def __init__(self, filename, filetree=1):
         # Get the torrent data from the torrent file
         try:
             log.debug("Attempting to open %s.", filename)
@@ -108,6 +108,7 @@ class TorrentInfo(object):
 
         # Get list of files from torrent info
         paths = {}
+        dirs = {}
         if self.__m_metadata["info"].has_key("files"):
             prefix = ""
             if len(self.__m_metadata["info"]["files"]) > 1:
@@ -121,18 +122,38 @@ class TorrentInfo(object):
                 f["index"] = index
                 paths[path] = f
 
-            def walk(path, item):
-                if type(item) is dict:
-                    return item
-                return [paths[path]['index'], paths[path]['length'], True]
+                dirname = os.path.dirname(path)
+                while dirname:
+                    dirinfo = dirs.setdefault(dirname, {})
+                    dirinfo["length"] = dirinfo.get("length", 0) + f["length"]
+                    dirname = os.path.dirname(dirname)
+
+            if filetree == 2:
+                def walk(path, item):
+                    if item["type"] == "dir":
+                        item.update(dirs[path])
+                    else:
+                        item.update(paths[path])
+                    item["download"] = True
+
+                file_tree = FileTree2(paths.keys())
+                file_tree.walk(walk)
+            else:
+                def walk(path, item):
+                    if type(item) is dict:
+                        return item
+                    return [paths[path]["index"], paths[path]["length"], True]
 
-            file_tree = FileTree(paths)
-            file_tree.walk(walk)
+                file_tree = FileTree(paths)
+                file_tree.walk(walk)
             self.__m_files_tree = file_tree.get_tree()
         else:
-            self.__m_files_tree = {
-                self.__m_name: (0, self.__m_metadata["info"]["length"], True)
-            }
+            if filetree == 2:
+                pass
+            else:
+                self.__m_files_tree = {
+                    self.__m_name: (0, self.__m_metadata["info"]["length"], 
True)
+                }
 
         self.__m_files = []
         if self.__m_metadata["info"].has_key("files"):
diff --git a/deluge/ui/web/js/deluge-all/add/OptionsPanel.js 
b/deluge/ui/web/js/deluge-all/add/OptionsPanel.js
index eecd35a..57e6863 100644
--- a/deluge/ui/web/js/deluge-all/add/OptionsPanel.js
+++ b/deluge/ui/web/js/deluge-all/add/OptionsPanel.js
@@ -65,10 +65,6 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
                        }]
                }));
 
-               new Ext.tree.TreeSorter(this.files, {
-                       folderSort: true
-               });
-
                this.optionsManager = new Deluge.MultiOptionsManager();
        
                this.form = this.add({
@@ -200,7 +196,7 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
                var fileIndexes = {};
                this.walkFileTree(torrent['files_tree'], function(filename, 
type, entry, parent) {
                        if (type != 'file') return;
-                       fileIndexes[entry[0]] = entry[2];
+                       fileIndexes[entry.index] = entry.download;
                }, this);
 
                var priorities = [];
@@ -279,9 +275,9 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
 
                this.walkFileTree(this.torrents[torrentId]['files_tree'], 
function(filename, type, entry, parentNode) {
                        if (type == 'dir') {
-                               alert(Ext.encode(entry));
                                var folder = new Ext.tree.TreeNode({
                                        filename: filename,
+                                       size: entry.length,
                                        checked: true
                                });
                                folder.on('checkchange', this.onFolderCheck, 
this);
@@ -290,12 +286,10 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
                        } else {
                                var node = new Ext.tree.TreeNode({
                                        filename: filename,
-                                       fileindex: entry[0],
-                                       text: filename, // this needs to be 
here for sorting reasons
-                                       size: entry[1],
+                                       fileindex: entry.index,
+                                       size: entry.length,
                                        leaf: true,
-                                       checked: priorities[entry[0]],
-                                       iconCls: 'x-deluge-file',
+                                       checked: priorities[entry.index],
                                        uiProvider: Ext.tree.ColumnNodeUI
                                });
                                node.on('checkchange', this.onNodeCheck, this);
@@ -306,9 +300,9 @@ Deluge.add.OptionsPanel = Ext.extend(Ext.TabPanel, {
        },
 
        walkFileTree: function(files, callback, scope, parentNode) {
-               for (var filename in files) {
-                       var entry = files[filename];
-                       var type = (Ext.type(entry) == 'object') ? 'dir' : 
'file';
+               for (var filename in files.contents) {
+                       var entry = files.contents[filename];
+                       var type = entry.type;
 
                        if (scope) {
                                var ret = callback.apply(scope, [filename, 
type, entry, parentNode]);
diff --git a/deluge/ui/web/json_api.py b/deluge/ui/web/json_api.py
index ad36b82..f917c88 100644
--- a/deluge/ui/web/json_api.py
+++ b/deluge/ui/web/json_api.py
@@ -652,9 +652,10 @@ class WebApi(JSONComponent):
         :rtype: dictionary
         """
         try:
-            torrent_info = uicommon.TorrentInfo(filename.strip())
+            torrent_info = uicommon.TorrentInfo(filename.strip(), 2)
             return torrent_info.as_dict("name", "info_hash", "files_tree")
-        except:
+        except Exception, e:
+            log.exception(e)
             return False
 
     @export

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to