SF.net SVN: fclient:[771] trunk/fclient/src/fclient
Status: Pre-Alpha
Brought to you by:
jurner
|
From: <jU...@us...> - 2008-07-27 11:35:59
|
Revision: 771
http://fclient.svn.sourceforge.net/fclient/?rev=771&view=rev
Author: jUrner
Date: 2008-07-27 11:36:07 +0000 (Sun, 27 Jul 2008)
Log Message:
-----------
naming
Modified Paths:
--------------
trunk/fclient/src/fclient/fclient.py
trunk/fclient/src/fclient/impl/ViewBrowser.py
Added Paths:
-----------
trunk/fclient/src/fclient/impl/ViewDownloads.py
Removed Paths:
-------------
trunk/fclient/src/fclient/impl/Ui_ViewDownloads.py
Modified: trunk/fclient/src/fclient/fclient.py
===================================================================
--- trunk/fclient/src/fclient/fclient.py 2008-07-27 11:34:40 UTC (rev 770)
+++ trunk/fclient/src/fclient/fclient.py 2008-07-27 11:36:07 UTC (rev 771)
@@ -10,7 +10,7 @@
from .impl.View import ViewWidget
from .impl.ViewBrowser import ViewBrowserWidget
from .impl.ViewConnection import ViewConnectionWidget
-from .impl.Ui_ViewDownloads import ViewDownloadsWidget
+from .impl.ViewDownloads import ViewDownloadsWidget
from .impl.Ui_ViewLogger import ViewLoggerWidget
#*************************************************************
#
Deleted: trunk/fclient/src/fclient/impl/Ui_ViewDownloads.py
===================================================================
--- trunk/fclient/src/fclient/impl/Ui_ViewDownloads.py 2008-07-27 11:34:40 UTC (rev 770)
+++ trunk/fclient/src/fclient/impl/Ui_ViewDownloads.py 2008-07-27 11:36:07 UTC (rev 771)
@@ -1,276 +0,0 @@
-""""""
-
-#**************************************************************************************************************
-#TODO:
-#
-# x. prtty tricky to get dls right when the node or client may disconnect unexpectedly
-# problem: dls that we send and that have not reached the node
-# problem: what to do when the user wants to quit and we still have dls to push to the node
-#
-# solution would require keeping track of all requests
-# a. keep identifiers of requests that reached the node (have to do it anyways)
-# b. keep track of requests ahead of sending them to the node (feels not too good doubeling downloads.dat.gz)
-#
-# best idea seems to be to ignore the problem
-# 1. wait till (if ever) freenet devels fdrop node keeping track of client requests
-#
-# 2. a box thrown to the user (x. do not show this message again) to inform him about pendings
-# should be enough. maybe along with a separate widget or some separate color code for pendings
-#
-# x. performance
-# start with a standard model and improve it over time. no need to set any hard
-# limits. the user will find out by himself how many dls his machine can handle.
-# have to be carefrul though when adding dls, like from a *.frdx to provide appropriate
-# warnings
-#**************************************************************************************************************
-from __future__ import absolute_import
-if __name__ == '__main__': # see --> http://bugs.python.org/issue1510172 . works only current dir and below
- import os; __path__ = [os.path.dirname(__file__)]
-
-import os
-from PyQt4 import QtCore, QtGui
-
-from . import config
-from .lib import fcp2
-
-from .tpls.Ui_ViewDownloadsWidgetTpl import Ui_ViewDownloadsWidget
-#**********************************************************************************
-#
-#**********************************************************************************
-class DownloadsViewObject(config.ViewObject):
-
- def __init__(self, parent):
- config.ViewObject. __init__(self, parent)
-
- self.name=parent.objectName()
- self.displayName=self.trUtf8('Downloads')
- self.icon=QtGui.QIcon()
-
-#**********************************************************************************
-#
-#**********************************************************************************
-# from: network/torrent/mainwindow.cpp
-# TorrentViewDelegate is used to draw the progress bars.
-class DownloadTreeDelegate(QtGui.QItemDelegate):
-
- def __init__(self, parent):
- QtGui.QItemDelegate.__init__(self, parent)
-
- def paint(self, painter, option, index):
- if index.column() != self.parent().HeaderIndexProgress:
- return QtGui.QItemDelegate.paint(self, painter, option, index)
-
- application = QtGui.QApplication.instance()
- fcpRequest = self.parent().fcRequests.itemFromIndex(index.row()).fcpRequest
- progress = fcpRequest['ProgressSucceeeded']
- required = fcpRequest['ProgressRequired']
-
- # Set up a QprogressbarOptionProgressBar to precisely mimic the
- # environment of a progress bar.
- progressBarOption = QtGui.QStyleOptionProgressBar()
- progressBarOption.state = QtGui.QStyle.State_Enabled
- progressBarOption.direction = application.layoutDirection()
- progressBarOption.rect = option.rect
- progressBarOption.fontMetrics = application.fontMetrics()
- progressBarOption.minimum = 0
- progressBarOption.maximum = fcpRequest['ProgressRequired']
- progressBarOption.textAlignment = QtCore.Qt.AlignCenter
- progressBarOption.textVisible = True
-
- # Set the progress and text values of the style option.
- progressBarOption.progress = progress
- if required:
- progressBarOption.text = '%s%%' % round(progress * 100 / required, 2)
- else:
- progressBarOption.text = '0%'
-
- # Draw the progress bar onto the view.
- application.style().drawControl(QtGui.QStyle.CE_ProgressBar, progressBarOption, painter)
-
-#**********************************************************************************
-#
-#**********************************************************************************
-class TreeItem(QtGui.QTreeWidgetItem):
-
- def __init__(self, fcpIdentifier, *params):
- QtGui.QTreeWidgetItem.__init__(self, *params)
- self.fcpIdentifier = fcpIdentifier
-
-
-#**********************************************************************************
-#
-#**********************************************************************************
-class Requests(object):
-
- def __init__(self):
- self.identifiers = []
- self.items = []
-
- def addRequest(self, identifier, item):
- self.identifiers.append(identifier)
- self.items.append(item)
-
- def itemFromIndex(self, index):
- return self.items[index]
-
-
-class ViewDownloadsWidget(QtGui.QWidget, Ui_ViewDownloadsWidget):
-
- IdTree = 'tree'
-
-
- HeaderIndexName = 0
- HeaderIndexFoo = 1
- HeaderIndexProgress = 2
-
- def __init__(self, parent, idGlobalFeedback=config.IdMainWindow):
- QtGui.QWidget.__init__(self, parent)
- self._isCreated = False
-
- self.setupUi(self)
- config.ObjectRegistry.register(self)
-
- self.fcViewObject = DownloadsViewObject(self)
- self.fcpEvents = (
- (config.fcpClient.events.ConfigData, self.onFcpConfigData),
- (config.fcpClient.events.RequestCompleted, self.onFcpRequestCompleted),
- (config.fcpClient.events.RequestFailed, self.onFcpRequestFailed),
- (config.fcpClient.events.RequestModified, self.onFcpRequestModified),
- (config.fcpClient.events.RequestProgress, self.onFcpRequestProgress),
- (config.fcpClient.events.RequestStarted, self.onFcpRequestStarted),
- )
- config.fcpClient.events += self.fcpEvents
- self.fcHeadeLabels = {}
- self.fcpRequests = {}
-
- #XXX
- self.foo = False
-
-
- def retranslateUi(self, parent):
- self.fcHeadeLabels = {
- self.HeaderIndexName: self.trUtf8('Name'),
- self.HeaderIndexFoo: self.trUtf8('Foo'),
- self.HeaderIndexProgress: self.trUtf8('Progress'),
- }
- self.tree.setHeaderLabels([i[1] for i in sorted(self.fcHeadeLabels.items())])
-
-
- def closeEvent(self):
- self.viewClose()
-
-
- def viewClose(self):
- config.fcpClient.events -= self.fcpEvents
-
-
- def downloadFile(self, fcpKey, fileName, **kws):
- """"""
- fileName = unicode(fileName)
- fcpIdentifier = config.fcpClient.getFile(fcpKey, fileName, **kws)
- item= TreeItem(fcpIdentifier, self.tree)
-
- item.setData(
- self.HeaderIndexName,
- QtCore.Qt.DisplayRole,
- QtCore.QVariant(os.path.basename(fileName))
- )
-
- progressBar = QtGui.QProgressBar(self)
- progressBar.setRange(0, 0)
- self.tree.setItemWidget(item, self.HeaderIndexProgress, progressBar)
- self.fcpRequests[fcpIdentifier] = item
-
-
- #########################################
- ## methods
- #########################################
- def controlById(idGlobalFeedback, idControl):
- return getattr(idGlobalFeedback, idControl)
-
- #########################################
- ## fcp event handlers
- #########################################
- def onFcpConfigData(self, fcpEvent, fcpRequest):
- if not self.foo:
- self.foo = True
-
- return
- # for testing: dl some frost.zip
- key = fcp2.Key('CHK@tJ0qyIr8dwvYKoSkmR1N-soABstL0RjgiYqQm3Gtv8g,Pqj7jpPUBzRgnVTaA3fEw6gE8QHcJsTwA4liL9FZ-Fg,AAIC--8/frost-04-Mar-2008.zip')
- fileName = config.guessFileNameFromKey(key, default=self.trUtf8('Unknown.file'))
- directory = config.settings.value('DownloadDir')
- fpath = os.path.join(unicode(directory), unicode(fileName))
- self.downloadFile(key, fpath)
-
-
- def onFcpRequestCompleted(self, fcpEvent, fcpRequest):
- item = self.fcpRequests.get(fcpRequest['Identifier'], None)
- if item is not None:
- progressBar = self.tree.itemWidget(item, self.HeaderIndexProgress)
- progressBar.setValue(progressBar.maximum())
-
- 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]
- 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:
- item.setData(
- self.HeaderIndexName,
- QtCore.Qt.DisplayRole,
- QtCore.QVariant(os.path.basename(fcpRequest['Filename']))
- )
-
-
- def onFcpRequestProgress(self, fcpEvent, fcpRequest):
- item = self.fcpRequests.get(fcpRequest['Identifier'], None)
- if item is not None:
- progressBar = self.tree.itemWidget(item, self.HeaderIndexProgress)
-
- progressBar.setRange(0, fcpRequest['ProgressRequired'])
- progressBar.setValue(fcpRequest['ProgressSucceeded'])
-
-
- def onFcpRequestStarted(self, fcpEvent, fcpRequest):
- pass
-
-
-#**********************************************************************************
-#
-#**********************************************************************************
-if __name__ == '__main__':
- import sys
- from . import View
- from . import ViewConnection
- from . import Ui_ViewLogger
- from . import MainWindow
-
- app = QtGui.QApplication(sys.argv)
-
- mainWindow = Ui_MainWindow.MainWindow()
- viewWidget = Ui_View.ViewWidget(mainWindow)
- mainWindow.setCentralWidget(viewWidget)
-
-
- viewWidget.addTopViews(
- Ui_ViewConnection.ViewConnectionWidget(None),
- ViewDownloadsWidget(None),
- )
- viewWidget.addBottomViews(Ui_ViewLogger.ViewLoggerWidget(None))
-
- mainWindow.show()
- res = app.exec_()
- sys.exit(res)
\ No newline at end of file
Modified: trunk/fclient/src/fclient/impl/ViewBrowser.py
===================================================================
--- trunk/fclient/src/fclient/impl/ViewBrowser.py 2008-07-27 11:34:40 UTC (rev 770)
+++ trunk/fclient/src/fclient/impl/ViewBrowser.py 2008-07-27 11:36:07 UTC (rev 771)
@@ -978,7 +978,7 @@
from .MainWindow import MainWindow
from .View import ViewWidget
from .ViewConnection import ViewConnectionWidget
- from .Ui_ViewDownloads import ViewDownloadsWidget
+ from .ViewDownloads import ViewDownloadsWidget
app = QtGui.QApplication(sys.argv)
Added: trunk/fclient/src/fclient/impl/ViewDownloads.py
===================================================================
--- trunk/fclient/src/fclient/impl/ViewDownloads.py (rev 0)
+++ trunk/fclient/src/fclient/impl/ViewDownloads.py 2008-07-27 11:36:07 UTC (rev 771)
@@ -0,0 +1,276 @@
+""""""
+
+#**************************************************************************************************************
+#TODO:
+#
+# x. prtty tricky to get dls right when the node or client may disconnect unexpectedly
+# problem: dls that we send and that have not reached the node
+# problem: what to do when the user wants to quit and we still have dls to push to the node
+#
+# solution would require keeping track of all requests
+# a. keep identifiers of requests that reached the node (have to do it anyways)
+# b. keep track of requests ahead of sending them to the node (feels not too good doubeling downloads.dat.gz)
+#
+# best idea seems to be to ignore the problem
+# 1. wait till (if ever) freenet devels fdrop node keeping track of client requests
+#
+# 2. a box thrown to the user (x. do not show this message again) to inform him about pendings
+# should be enough. maybe along with a separate widget or some separate color code for pendings
+#
+# x. performance
+# start with a standard model and improve it over time. no need to set any hard
+# limits. the user will find out by himself how many dls his machine can handle.
+# have to be carefrul though when adding dls, like from a *.frdx to provide appropriate
+# warnings
+#**************************************************************************************************************
+from __future__ import absolute_import
+if __name__ == '__main__': # see --> http://bugs.python.org/issue1510172 . works only current dir and below
+ import os; __path__ = [os.path.dirname(__file__)]
+
+import os
+from PyQt4 import QtCore, QtGui
+
+from . import config
+from .lib import fcp2
+
+from .tpls.Ui_ViewDownloadsWidgetTpl import Ui_ViewDownloadsWidget
+#**********************************************************************************
+#
+#**********************************************************************************
+class DownloadsViewObject(config.ViewObject):
+
+ def __init__(self, parent):
+ config.ViewObject. __init__(self, parent)
+
+ self.name=parent.objectName()
+ self.displayName=self.trUtf8('Downloads')
+ self.icon=QtGui.QIcon()
+
+#**********************************************************************************
+#
+#**********************************************************************************
+# from: network/torrent/mainwindow.cpp
+# TorrentViewDelegate is used to draw the progress bars.
+class DownloadTreeDelegate(QtGui.QItemDelegate):
+
+ def __init__(self, parent):
+ QtGui.QItemDelegate.__init__(self, parent)
+
+ def paint(self, painter, option, index):
+ if index.column() != self.parent().HeaderIndexProgress:
+ return QtGui.QItemDelegate.paint(self, painter, option, index)
+
+ application = QtGui.QApplication.instance()
+ fcpRequest = self.parent().fcRequests.itemFromIndex(index.row()).fcpRequest
+ progress = fcpRequest['ProgressSucceeeded']
+ required = fcpRequest['ProgressRequired']
+
+ # Set up a QprogressbarOptionProgressBar to precisely mimic the
+ # environment of a progress bar.
+ progressBarOption = QtGui.QStyleOptionProgressBar()
+ progressBarOption.state = QtGui.QStyle.State_Enabled
+ progressBarOption.direction = application.layoutDirection()
+ progressBarOption.rect = option.rect
+ progressBarOption.fontMetrics = application.fontMetrics()
+ progressBarOption.minimum = 0
+ progressBarOption.maximum = fcpRequest['ProgressRequired']
+ progressBarOption.textAlignment = QtCore.Qt.AlignCenter
+ progressBarOption.textVisible = True
+
+ # Set the progress and text values of the style option.
+ progressBarOption.progress = progress
+ if required:
+ progressBarOption.text = '%s%%' % round(progress * 100 / required, 2)
+ else:
+ progressBarOption.text = '0%'
+
+ # Draw the progress bar onto the view.
+ application.style().drawControl(QtGui.QStyle.CE_ProgressBar, progressBarOption, painter)
+
+#**********************************************************************************
+#
+#**********************************************************************************
+class TreeItem(QtGui.QTreeWidgetItem):
+
+ def __init__(self, fcpIdentifier, *params):
+ QtGui.QTreeWidgetItem.__init__(self, *params)
+ self.fcpIdentifier = fcpIdentifier
+
+
+#**********************************************************************************
+#
+#**********************************************************************************
+class Requests(object):
+
+ def __init__(self):
+ self.identifiers = []
+ self.items = []
+
+ def addRequest(self, identifier, item):
+ self.identifiers.append(identifier)
+ self.items.append(item)
+
+ def itemFromIndex(self, index):
+ return self.items[index]
+
+
+class ViewDownloadsWidget(QtGui.QWidget, Ui_ViewDownloadsWidget):
+
+ IdTree = 'tree'
+
+
+ HeaderIndexName = 0
+ HeaderIndexFoo = 1
+ HeaderIndexProgress = 2
+
+ def __init__(self, parent, idGlobalFeedback=config.IdMainWindow):
+ QtGui.QWidget.__init__(self, parent)
+ self._isCreated = False
+
+ self.setupUi(self)
+ config.ObjectRegistry.register(self)
+
+ self.fcViewObject = DownloadsViewObject(self)
+ self.fcpEvents = (
+ (config.fcpClient.events.ConfigData, self.onFcpConfigData),
+ (config.fcpClient.events.RequestCompleted, self.onFcpRequestCompleted),
+ (config.fcpClient.events.RequestFailed, self.onFcpRequestFailed),
+ (config.fcpClient.events.RequestModified, self.onFcpRequestModified),
+ (config.fcpClient.events.RequestProgress, self.onFcpRequestProgress),
+ (config.fcpClient.events.RequestStarted, self.onFcpRequestStarted),
+ )
+ config.fcpClient.events += self.fcpEvents
+ self.fcHeadeLabels = {}
+ self.fcpRequests = {}
+
+ #XXX
+ self.foo = False
+
+
+ def retranslateUi(self, parent):
+ self.fcHeadeLabels = {
+ self.HeaderIndexName: self.trUtf8('Name'),
+ self.HeaderIndexFoo: self.trUtf8('Foo'),
+ self.HeaderIndexProgress: self.trUtf8('Progress'),
+ }
+ self.tree.setHeaderLabels([i[1] for i in sorted(self.fcHeadeLabels.items())])
+
+
+ def closeEvent(self):
+ self.viewClose()
+
+
+ def viewClose(self):
+ config.fcpClient.events -= self.fcpEvents
+
+
+ def downloadFile(self, fcpKey, fileName, **kws):
+ """"""
+ fileName = unicode(fileName)
+ fcpIdentifier = config.fcpClient.getFile(fcpKey, fileName, **kws)
+ item= TreeItem(fcpIdentifier, self.tree)
+
+ item.setData(
+ self.HeaderIndexName,
+ QtCore.Qt.DisplayRole,
+ QtCore.QVariant(os.path.basename(fileName))
+ )
+
+ progressBar = QtGui.QProgressBar(self)
+ progressBar.setRange(0, 0)
+ self.tree.setItemWidget(item, self.HeaderIndexProgress, progressBar)
+ self.fcpRequests[fcpIdentifier] = item
+
+
+ #########################################
+ ## methods
+ #########################################
+ def controlById(idGlobalFeedback, idControl):
+ return getattr(idGlobalFeedback, idControl)
+
+ #########################################
+ ## fcp event handlers
+ #########################################
+ def onFcpConfigData(self, fcpEvent, fcpRequest):
+ if not self.foo:
+ self.foo = True
+
+ return
+ # for testing: dl some frost.zip
+ key = fcp2.Key('CHK@tJ0qyIr8dwvYKoSkmR1N-soABstL0RjgiYqQm3Gtv8g,Pqj7jpPUBzRgnVTaA3fEw6gE8QHcJsTwA4liL9FZ-Fg,AAIC--8/frost-04-Mar-2008.zip')
+ fileName = config.guessFileNameFromKey(key, default=self.trUtf8('Unknown.file'))
+ directory = config.settings.value('DownloadDir')
+ fpath = os.path.join(unicode(directory), unicode(fileName))
+ self.downloadFile(key, fpath)
+
+
+ def onFcpRequestCompleted(self, fcpEvent, fcpRequest):
+ item = self.fcpRequests.get(fcpRequest['Identifier'], None)
+ if item is not None:
+ progressBar = self.tree.itemWidget(item, self.HeaderIndexProgress)
+ progressBar.setValue(progressBar.maximum())
+
+ 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]
+ 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:
+ item.setData(
+ self.HeaderIndexName,
+ QtCore.Qt.DisplayRole,
+ QtCore.QVariant(os.path.basename(fcpRequest['Filename']))
+ )
+
+
+ def onFcpRequestProgress(self, fcpEvent, fcpRequest):
+ item = self.fcpRequests.get(fcpRequest['Identifier'], None)
+ if item is not None:
+ progressBar = self.tree.itemWidget(item, self.HeaderIndexProgress)
+
+ progressBar.setRange(0, fcpRequest['ProgressRequired'])
+ progressBar.setValue(fcpRequest['ProgressSucceeded'])
+
+
+ def onFcpRequestStarted(self, fcpEvent, fcpRequest):
+ pass
+
+
+#**********************************************************************************
+#
+#**********************************************************************************
+if __name__ == '__main__':
+ import sys
+ from . import View
+ from . import ViewConnection
+ from . import Ui_ViewLogger
+ from . import MainWindow
+
+ app = QtGui.QApplication(sys.argv)
+
+ mainWindow = Ui_MainWindow.MainWindow()
+ viewWidget = Ui_View.ViewWidget(mainWindow)
+ mainWindow.setCentralWidget(viewWidget)
+
+
+ viewWidget.addTopViews(
+ Ui_ViewConnection.ViewConnectionWidget(None),
+ ViewDownloadsWidget(None),
+ )
+ viewWidget.addBottomViews(Ui_ViewLogger.ViewLoggerWidget(None))
+
+ mainWindow.show()
+ res = app.exec_()
+ sys.exit(res)
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|