88 </div> |
88 </div> |
89 </body> |
89 </body> |
90 </html> |
90 </html> |
91 """ |
91 """ |
92 |
92 |
|
93 |
93 class FtpReply(QNetworkReply): |
94 class FtpReply(QNetworkReply): |
94 """ |
95 """ |
95 Class implementing a network reply for FTP resources. |
96 Class implementing a network reply for FTP resources. |
96 """ |
97 """ |
97 def __init__(self, url, parent = None): |
98 def __init__(self, url, parent=None): |
98 """ |
99 """ |
99 Constructor |
100 Constructor |
100 |
101 |
101 @param url requested FTP URL (QUrl) |
102 @param url requested FTP URL (QUrl) |
102 @param parent reference to the parent object (QObject) |
103 @param parent reference to the parent object (QObject) |
127 if proxy.type() == QNetworkProxy.NoProxy or \ |
128 if proxy.type() == QNetworkProxy.NoProxy or \ |
128 proxy.type() == QNetworkProxy.FtpCachingProxy: |
129 proxy.type() == QNetworkProxy.FtpCachingProxy: |
129 ftpProxy = proxy |
130 ftpProxy = proxy |
130 break |
131 break |
131 if ftpProxy.type() == QNetworkProxy.DefaultProxy: |
132 if ftpProxy.type() == QNetworkProxy.DefaultProxy: |
132 self.setError(QNetworkReply.ProxyNotFoundError, |
133 self.setError(QNetworkReply.ProxyNotFoundError, |
133 self.trUtf8("No suitable proxy found.")) |
134 self.trUtf8("No suitable proxy found.")) |
134 QTimer.singleShot(0, self.__errorSignals) |
135 QTimer.singleShot(0, self.__errorSignals) |
135 return |
136 return |
136 elif ftpProxy.type() == QNetworkProxy.FtpCachingProxy: |
137 elif ftpProxy.type() == QNetworkProxy.FtpCachingProxy: |
137 self.__ftp.setProxy(ftpProxy.hostName(), ftpProxy.port()) |
138 self.__ftp.setProxy(ftpProxy.hostName(), ftpProxy.port()) |
282 self.setHeader(QNetworkRequest.ContentLengthHeader, self.__items[0].size()) |
283 self.setHeader(QNetworkRequest.ContentLengthHeader, self.__items[0].size()) |
283 self.setAttribute(QNetworkRequest.HttpStatusCodeAttribute, 200) |
284 self.setAttribute(QNetworkRequest.HttpStatusCodeAttribute, 200) |
284 self.setAttribute(QNetworkRequest.HttpReasonPhraseAttribute, "Ok") |
285 self.setAttribute(QNetworkRequest.HttpReasonPhraseAttribute, "Ok") |
285 self.metaDataChanged.emit() |
286 self.metaDataChanged.emit() |
286 |
287 |
287 def __cssLinkClass(self, icon, size = 32): |
288 def __cssLinkClass(self, icon, size=32): |
288 """ |
289 """ |
289 Private method to generate a link class with an icon. |
290 Private method to generate a link class with an icon. |
290 |
291 |
291 @param icon icon to be included (QIcon) |
292 @param icon icon to be included (QIcon) |
292 @param size size of the icon to be generated (integer) |
293 @param size size of the icon to be generated (integer) |
305 # write a blank pixmap on error |
306 # write a blank pixmap on error |
306 pixmap = QPixmap(size, size) |
307 pixmap = QPixmap(size, size) |
307 pixmap.fill(Qt.transparent) |
308 pixmap.fill(Qt.transparent) |
308 imageBuffer.buffer().clear() |
309 imageBuffer.buffer().clear() |
309 pixmap.save(imageBuffer, "PNG") |
310 pixmap.save(imageBuffer, "PNG") |
310 return cssString.format(size + 4, |
311 return cssString.format(size + 4, |
311 str(imageBuffer.buffer().toBase64(), encoding="ascii")) |
312 str(imageBuffer.buffer().toBase64(), encoding="ascii")) |
312 |
313 |
313 def __setListContent(self): |
314 def __setListContent(self): |
314 """ |
315 """ |
315 Private method to prepare the content for the reader. |
316 Private method to prepare the content for the reader. |
382 icon = UI.PixmapCache.getIcon("dirClosed.png") |
383 icon = UI.PixmapCache.getIcon("dirClosed.png") |
383 linkClasses[linkClass] = \ |
384 linkClasses[linkClass] = \ |
384 self.__cssLinkClass(icon, iconSize).format(linkClass) |
385 self.__cssLinkClass(icon, iconSize).format(linkClass) |
385 table += row.format( |
386 table += row.format( |
386 i == 0 and "odd" or "even", |
387 i == 0 and "odd" or "even", |
387 linkClass, |
388 linkClass, |
388 child.toString(), |
389 child.toString(), |
389 Qt.escape(item.name()), |
390 Qt.escape(item.name()), |
390 sizeStr, |
391 sizeStr, |
391 item.lastModified().toString("yyyy-MM-dd hh:mm"), |
392 item.lastModified().toString("yyyy-MM-dd hh:mm"), |
392 ) |
393 ) |
393 i = 1 - i |
394 i = 1 - i |
394 |
395 |
395 content = ftpListPage_html.format( |
396 content = ftpListPage_html.format( |
396 Qt.escape(baseUrl), |
397 Qt.escape(baseUrl), |
397 "".join(linkClasses.values()), |
398 "".join(linkClasses.values()), |
398 self.trUtf8("Listing of {0}").format(basePath), |
399 self.trUtf8("Listing of {0}").format(basePath), |
399 parentStr, |
400 parentStr, |
400 table |
401 table |
401 ) |
402 ) |
402 self.__content = QByteArray(content.encode("utf8")) |
403 self.__content = QByteArray(content.encode("utf8")) |
403 |
404 |
404 self.open(QIODevice.ReadOnly | QIODevice.Unbuffered) |
405 self.open(QIODevice.ReadOnly | QIODevice.Unbuffered) |