SF.net SVN: fclient:[835] trunk/fclient/src/fclient/impl/ViewDownloads.py
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-07-31 16:45:16
|
Revision: 835
http://fclient.svn.sourceforge.net/fclient/?rev=835&view=rev
Author: jUrner
Date: 2008-07-31 16:45:24 +0000 (Thu, 31 Jul 2008)
Log Message:
-----------
adapt to fcp2.Client changes ++ roughly estimate dl size by CHK block size
Modified Paths:
--------------
trunk/fclient/src/fclient/impl/ViewDownloads.py
Modified: trunk/fclient/src/fclient/impl/ViewDownloads.py
===================================================================
--- trunk/fclient/src/fclient/impl/ViewDownloads.py 2008-07-31 16:44:10 UTC (rev 834)
+++ trunk/fclient/src/fclient/impl/ViewDownloads.py 2008-07-31 16:45:24 UTC (rev 835)
@@ -44,12 +44,17 @@
from .lib import fcp2
from .lib.fcp2.lib import pmstruct
from .lib.qt4ex import treewidgetwrap
+from .lib import numbers
from . import DlgDownloadKeyToDisk
from .tpls.Ui_ViewDownloadsWidgetTpl import Ui_ViewDownloadsWidget
#**********************************************************************************
#
+#**********************************************************************************
+BLOCK_SIZE = 32768 # from CHKBlock.java
+#**********************************************************************************
+#
#**********************************************************************************
class DownloadsViewObject(config.ViewObject):
@@ -197,9 +202,9 @@
#**********************************************************************************
class TreeItem(QtGui.QTreeWidgetItem):
- def __init__(self, fcpIdentifier, *params):
+ def __init__(self, fcpRequest, *params):
QtGui.QTreeWidgetItem.__init__(self, *params)
- self.fcpIdentifier = fcpIdentifier
+ self.fcpRequest = fcpRequest
# can be used to expose properties for stylesheets for example
@@ -252,13 +257,11 @@
self.fcHeadeLabels = {}
self.fcpRequests = {}
- self.foo = True
-
############################
## private methods
############################
def _createItemFromFcpRequest(self, fcpRequest):
- item= TreeItem(fcpRequest['Identifier'], self.tree)
+ item= TreeItem(fcpRequest, self.tree)
fileName = fcpRequest['Filename']
mimeType = mimetypes.guess_type(fileName)[0]
icon = config.fcResources.getIcon(
@@ -287,7 +290,7 @@
self.fcHeadeLabels = {
self.HeaderIndexName: self.trUtf8('Name'),
self.HeaderIndexSize: self.trUtf8('Size'),
- self.HeaderIndexMimeType: self.trUtf8('Type'),
+ self.HeaderIndexMimeType: self.trUtf8('MimeType'),
self.HeaderIndexStatus: self.trUtf8('Status'),
self.HeaderIndexProgress: self.trUtf8('Progress'),
}
@@ -324,14 +327,18 @@
def downloadFile(self, fcpKey, fileName, **kws):
""""""
+
fileName = unicode(fileName)
- fcpIdentifier = config.fcpClient.getFile(
+ fcpRequest = config.fcpClient.getFile(
fcpKey,
fileName,
persistentUserData=PersistentRequestData(ClientName=unicode(self.objectName())).dump(),
+ #handleFilenameCollision=True,
+ handlePermanentRedirect=True,
**kws
)
- item = self._createItemFromFcpRequest(config.fcpClient.getRequest(fcpIdentifier))
+ item = self._createItemFromFcpRequest(fcpRequest)
+
def populateMenu(self, menu):
menu.addAction(self.fcActions['ActionDownloadKeyToDisk'])
@@ -350,7 +357,6 @@
handleFilenameCollision=True,
)
-
def onRemoveSelectedRequests(self, action):
tree = self.controlById(self.IdTree)
for item in tree.selectedItems():
@@ -360,11 +366,11 @@
it = treewidgetwrap.TreeWidgetIterator(parent)
it.next()
for tmp_item in it:
- config.fcpClient.removeRequest(tmp_item.fcpIdentifier)
- del self.fcpRequests[tmp_item.fcpIdentifier]
+ del self.fcpRequests[tmp_item.fcpRequest['Identifier']]
+ config.fcpClient.removeRequest(tmp_item.fcpRequest)
+ tmp_item.fcpRequest = None
parent.removeChild(item)
-
-
+
def onTreeCustomContextMenuRequested(self, pt):
tree = self.controlById(self.IdTree)
pt = tree.viewport().mapToGlobal(pt)
@@ -388,35 +394,49 @@
def onFcpRequestCompleted(self, fcpEvent, fcpRequest):
- item = self.fcpRequests.get(fcpRequest['Identifier'], None)
+ requestIdentifier = fcpRequest['Identifier']
+
+ item = self.fcpRequests.get(requestIdentifier, None)
if item is not None:
progressBar = self.tree.itemWidget(item, self.HeaderIndexProgress)
progressBar.setRange(0, 1)
progressBar.setValue(progressBar.maximum())
+ item.setData(
+ self.HeaderIndexSize,
+ QtCore.Qt.DisplayRole,
+ QtCore.QVariant(numbers.format_num_bytes(fcpRequest['MetadataSize']))
+ )
+ item.setData(
+ self.HeaderIndexMimeType,
+ QtCore.Qt.DisplayRole,
+ QtCore.QVariant(fcpRequest['MetadataContentType'])
+ )
+
def onFcpRequestFailed(self, fcpEvent, fcpRequest):
pass
#TODO: not tested
def onFcpRequestModified(self, fcpEvent, fcpRequest):
- if fcp2.ConstRequestModified.Identifier in fcpRequest['Modified']:
- newFcpIdentifier = fcpRequest['Identifier']
- oldFcpIdentifier = fcpRequest['Modified'][fcp2.ConstRequestModified.Identifier]
- item = self.fcpRequests.get(oldFcpIdentifier, None)
- if item is not None:
- del self.fcpRequests[oldFcpIdentifier]
+
+ requestIdentifier = fcpRequest['Modified'].get(fcp2.ConstRequestModified.Identifier, None)
+ if requestIdentifier is None:
+ requestIdentifier = fcpRequest['Identifier']
+ item = self.fcpRequests.get(requestIdentifier, None)
+
+ if item is not None:
+ if fcp2.ConstRequestModified.Identifier in fcpRequest['Modified']:
+ newFcpIdentifier = fcpRequest['Identifier']
+ del self.fcpRequests[requestIdentifier]
self.fcpRequests[newFcpIdentifier] = item
- item.fcpIdentifier = newFcpIdentifier
-
- if fcp2.ConstRequestModified.Filename in fcpRequest['Modified']:
- item = self.fcpRequests.get(fcpRequest['Identifier'], None)
- if item is not None:
+
+ if fcp2.ConstRequestModified.Filename in fcpRequest['Modified']:
item.setData(
- self.HeaderIndexName,
- QtCore.Qt.DisplayRole,
- QtCore.QVariant(os.path.basename(fcpRequest['Filename']))
- )
+ self.HeaderIndexName,
+ QtCore.Qt.DisplayRole,
+ QtCore.QVariant(os.path.basename(fcpRequest['Filename']))
+ )
def onFcpRequestProgress(self, fcpEvent, fcpRequest):
@@ -426,6 +446,14 @@
progressBar.setRange(0, fcpRequest['ProgressRequired'])
progressBar.setValue(fcpRequest['ProgressSucceeded'])
+
+ #TODO: take a wild guess at the size. no other way to do it currently
+ estimatedSize = int((BLOCK_SIZE * fcpRequest['ProgressRequired']) + 1)
+ item.setData(
+ self.HeaderIndexSize,
+ QtCore.Qt.DisplayRole,
+ QtCore.QVariant(self.trUtf8('< ') + numbers.format_num_bytes(estimatedSize)),
+ )
def onFcpRequestRemoved(self, fcpEvent, fcpRequest):
@@ -440,8 +468,7 @@
else:
if requestData.get('ClientName', None) == self.objectName():
item = self._createItemFromFcpRequest(fcpRequest)
-
-
+
#**********************************************************************************
#
#**********************************************************************************
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|