E5Network/E5NetworkMonitor.py

Mon, 31 May 2010 15:15:20 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 31 May 2010 15:15:20 +0200
changeset 317
f6b0163a21be
parent 168
3383117f894b
child 365
0686ac00256e
child 557
143bcdc7a959
permissions
-rw-r--r--

Fixed an issue in the network proxy factory class.

52
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2009 - 2010 Detlev Offenbach <detlev@die-offenbachs.de>
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing a network monitor dialog.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from PyQt4.QtGui import *
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 from PyQt4.QtCore import *
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from PyQt4.QtNetwork import QNetworkRequest, QNetworkAccessManager
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 import UI.PixmapCache
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 from .E5NetworkHeaderDetailsDialog import E5NetworkHeaderDetailsDialog
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 from .Ui_E5NetworkMonitor import Ui_E5NetworkMonitor
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 class E5NetworkRequest(object):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 Class for storing all data related to a specific request.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 def __init__(self):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 Constructor
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 self.op = -1
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 self.request = None
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 self.reply = None
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 self.response = ""
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 self.length = 0
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 self.contentType = ""
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 self.info = ""
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 self.replyHeaders = [] # list of tuple of two items
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 class E5NetworkMonitor(QDialog, Ui_E5NetworkMonitor):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 Class implementing a network monitor dialog.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 _monitor = None
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 @classmethod
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 def instance(cls, networkAccessManager):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 Class method to get a reference to our singleton.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 @param networkAccessManager reference to the network access manager
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 (QNetworkAccessManager)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 if cls._monitor is None:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 cls._monitor = E5NetworkMonitor(networkAccessManager)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 cls._monitor.setAttribute(Qt.WA_DeleteOnClose, True)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 return cls._monitor
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 @classmethod
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 def closeMonitor(cls):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 Class method to close the monitor dialog.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 if cls._monitor is not None:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 cls._monitor.close()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 def __init__(self, networkAccessManager, parent = None):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 Constructor
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 @param networkAccessManager reference to the network access manager
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 (QNetworkAccessManager)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 @param parent reference to the parent widget (QWidget)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 QDialog.__init__(self, parent)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 self.setupUi(self)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 self.clearButton.setIcon(UI.PixmapCache.getIcon("clearLeft.png"))
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 self.__requestHeaders = QStandardItemModel(self)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 self.__requestHeaders.setHorizontalHeaderLabels(
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 [self.trUtf8("Name"), self.trUtf8("Value")])
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 self.requestHeadersList.setModel(self.__requestHeaders)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 self.requestHeadersList.horizontalHeader().setStretchLastSection(True)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 self.connect(self.requestHeadersList,
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 SIGNAL("doubleClicked(const QModelIndex&)"),
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 self.__showHeaderDetails)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 self.__replyHeaders = QStandardItemModel(self)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 self.__replyHeaders.setHorizontalHeaderLabels(
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 [self.trUtf8("Name"), self.trUtf8("Value")])
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 self.responseHeadersList.setModel(self.__replyHeaders)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 self.responseHeadersList.horizontalHeader().setStretchLastSection(True)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 self.connect(self.responseHeadersList,
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 SIGNAL("doubleClicked(const QModelIndex&)"),
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 self.__showHeaderDetails)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 self.requestsList.horizontalHeader().setStretchLastSection(True)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 self.requestsList.verticalHeader().setMinimumSectionSize(-1)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 self.__proxyModel = QSortFilterProxyModel(self)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 self.__proxyModel.setFilterKeyColumn(-1)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 self.connect(self.searchEdit, SIGNAL("textChanged(QString)"),
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 self.__proxyModel.setFilterFixedString)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 self.connect(self.removeButton, SIGNAL("clicked()"),
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 self.requestsList.removeSelected)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 self.connect(self.removeAllButton, SIGNAL("clicked()"),
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 self.requestsList.removeAll)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110 self.__model = E5RequestModel(networkAccessManager, self)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 self.__proxyModel.setSourceModel(self.__model)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 self.requestsList.setModel(self.__proxyModel)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 self.connect(self.requestsList.selectionModel(),
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 SIGNAL("currentChanged(const QModelIndex&, const QModelIndex&)"),
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 self.__currentChanged)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 fm = self.fontMetrics()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 em = fm.width("m")
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 self.requestsList.horizontalHeader().resizeSection(0, em * 5)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 self.requestsList.horizontalHeader().resizeSection(1, em * 20)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 self.requestsList.horizontalHeader().resizeSection(3, em * 5)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 self.requestsList.horizontalHeader().resizeSection(4, em * 15)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 self.__headersDlg = None
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 def closeEvent(self, evt):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 Protected method called upon closing the dialog.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 @param evt reference to the close event object (QCloseEvent)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 self.__class__._monitor = None
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
133 QDialog.closeEvent(self, evt)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 def reject(self):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 Public slot to close the dialog with a Reject status.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 self.__class__._monitor = None
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
140 QDialog.reject(self)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 def __currentChanged(self, current, previous):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 Private slot to handle a change of the current index.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 @param current new current index (QModelIndex)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 @param previous old current index (QModelIndex)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 self.__requestHeaders.setRowCount(0)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 self.__replyHeaders.setRowCount(0)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 if not current.isValid():
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 return
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 row = self.__proxyModel.mapToSource(current).row()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 req = self.__model.requests[row].request
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
158
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 for header in req.rawHeaderList():
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 self.__requestHeaders.insertRows(0, 1, QModelIndex())
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 self.__requestHeaders.setData(
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 self.__requestHeaders.index(0, 0),
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 header)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 self.__requestHeaders.setData(
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 self.__requestHeaders.index(0, 1),
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 req.rawHeader(header))
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 self.__requestHeaders.item(0, 0).setFlags(
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 Qt.ItemIsSelectable | Qt.ItemIsEnabled)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 self.__requestHeaders.item(0, 1).setFlags(
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 Qt.ItemIsSelectable | Qt.ItemIsEnabled)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 for header in self.__model.requests[row].replyHeaders:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 self.__replyHeaders.insertRows(0, 1, QModelIndex())
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 self.__replyHeaders.setData(
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 self.__replyHeaders.index(0, 0),
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176 header[0])
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
177 self.__replyHeaders.setData(
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
178 self.__replyHeaders.index(0, 1),
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 header[1])
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 self.__replyHeaders.item(0, 0).setFlags(
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 Qt.ItemIsSelectable | Qt.ItemIsEnabled)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 self.__replyHeaders.item(0, 1).setFlags(
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
183 Qt.ItemIsSelectable | Qt.ItemIsEnabled)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
185 def __showHeaderDetails(self, index):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187 Private slot to show a dialog with the header details.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 @param index index of the entry to show (QModelIndex)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
191 if not index.isValid():
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 return
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
194 headerList = self.sender()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
195 if headerList is None:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
196 return
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
198 row = index.row()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
199 name = headerList.model().data(headerList.model().index(row, 0))
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
200 value = headerList.model().data(headerList.model().index(row, 1))
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
201 if self.__headersDlg is None:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
202 self.__headersDlg = E5NetworkHeaderDetailsDialog(self)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
203 self.__headersDlg.setData(name, value)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
204 self.__headersDlg.show()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 class E5RequestModel(QAbstractTableModel):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 Class implementing a model storing request objects.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 def __init__(self, networkAccessManager, parent = None):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 Constructor
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 @param networkAccessManager reference to the network access manager
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 (QNetworkAccessManager)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
216 @param parent reference to the parent object (QObject)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 QAbstractTableModel.__init__(self, parent)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220 self.__headerData = [
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 self.trUtf8("Method"),
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 self.trUtf8("Address"),
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 self.trUtf8("Response"),
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224 self.trUtf8("Length"),
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 self.trUtf8("Content Type"),
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 self.trUtf8("Info"),
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
227 ]
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
228
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
229 self.__operations = {
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
230 QNetworkAccessManager.HeadOperation : "HEAD",
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 QNetworkAccessManager.GetOperation : "GET",
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
232 QNetworkAccessManager.PutOperation : "PUT",
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 QNetworkAccessManager.PostOperation : "POST",
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
234 }
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
235
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 self.requests = []
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 self.connect(networkAccessManager,
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
238 SIGNAL("requestCreated(QNetworkAccessManager::Operation, const QNetworkRequest&, QNetworkReply*)"),
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239 self.__requestCreated)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 def __requestCreated(self, operation, request, reply):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 Private slot handling the creation of a network request.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
245 @param operation network operation (QNetworkAccessManager.Operation)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
246 @param request reference to the request object (QNetworkRequest)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
247 @param reply reference to the reply object(QNetworkReply)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
248 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
249 req = E5NetworkRequest()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
250 req.op = operation
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 req.request = QNetworkRequest(request)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
252 req.reply = reply
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
253 self.__addRequest(req)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 def __addRequest(self, req):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 Private method to add a request object to the model.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
259 @param req reference to the request object (E5NetworkRequest)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
260 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
261 self.beginInsertRows(QModelIndex(), len(self.requests), len(self.requests))
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
262 self.requests.append(req)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
263 self.connect(req.reply, SIGNAL("finished()"), self.__addReply)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
264 self.endInsertRows()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
265
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
266 def __addReply(self):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 Private slot to add the reply data to the model.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 reply = self.sender()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271 if reply is None:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 return
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
274 offset = len(self.requests) - 1
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275 while offset >= 0:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 if self.requests[offset].reply is reply:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 break
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 offset -= 1
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 if offset < 0:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280 return
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
281
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 # save the reply header data
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 for header in reply.rawHeaderList():
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284 self.requests[offset].replyHeaders.append((header, reply.rawHeader(header)))
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
285
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 # save reply info to be displayed
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
287 status = reply.attribute(QNetworkRequest.HttpStatusCodeAttribute) or 0
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
288 reason = reply.attribute(QNetworkRequest.HttpReasonPhraseAttribute) or ""
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
289 self.requests[offset].response = "%d %s" % (status, reason)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 self.requests[offset].length = reply.header(QNetworkRequest.ContentLengthHeader)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
291 self.requests[offset].contentType = reply.header(QNetworkRequest.ContentTypeHeader)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
292
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
293 if status == 302:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
294 target = reply.attribute(QNetworkRequest.RedirectionTargetAttribute) or QUrl()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295 self.requests[offset].info = \
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
296 self.trUtf8("Redirect: {0}").format(target.toString())
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
297
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
298 def headerData(self, section, orientation, role):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
299 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
300 Public method to get header data from the model.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
301
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
302 @param section section number (integer)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
303 @param orientation orientation (Qt.Orientation)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 @param role role of the data to retrieve (integer)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 @return requested data
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 if orientation == Qt.Horizontal and role == Qt.DisplayRole:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
308 return self.__headerData[section]
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 return QAbstractTableModel.headerData(self, section, orientation, role)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
311
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
312 def data(self, index, role):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
313 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
314 Public method to get data from the model.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
315
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
316 @param index index to get data for (QModelIndex)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
317 @param role role of the data to retrieve (integer)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
318 @return requested data
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
319 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 if index.row() < 0 or index.row() >= len(self.requests):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
321 return None
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
322
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 if role == Qt.DisplayRole or role == Qt.EditRole:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
324 col = index.column()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
325 if col == 0:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
326 try:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
327 return self.__operations[self.requests[index.row()].op]
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
328 except KeyError:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
329 return self.trUtf8("Unknown")
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
330 elif col == 1:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
331 return self.requests[index.row()].request.url().toEncoded()
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
332 elif col == 2:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
333 return self.requests[index.row()].response
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
334 elif col == 3:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
335 return self.requests[index.row()].length
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
336 elif col == 4:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
337 return self.requests[index.row()].contentType
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
338 elif col == 5:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
339 return self.requests[index.row()].info
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
340
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
341 return None
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343 def columnCount(self, parent):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 Public method to get the number of columns of the model.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
346
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
347 @param parent parent index (QModelIndex)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 @return number of columns (integer)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
349 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
350 if parent.column() > 0:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
351 return 0
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
352 else:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
353 return len(self.__headerData)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
354
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
355 def rowCount(self, parent):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
356 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
357 Public method to get the number of rows of the model.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
358
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
359 @param parent parent index (QModelIndex)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360 @return number of columns (integer)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
361 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 if parent.isValid():
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
363 return 0
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
364 else:
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
365 return len(self.requests)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
366
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
367 def removeRows(self, row, count, parent):
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
368 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
369 Public method to remove entries from the model.
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371 @param row start row (integer)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
372 @param count number of rows to remove (integer)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
373 @param parent parent index (QModelIndex)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 @return flag indicating success (boolean)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
375 """
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
376 if parent.isValid():
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
377 return False
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
378
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
379 lastRow = row + count - 1
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
380 self.beginRemoveRows(parent, row, lastRow)
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
381 del self.requests[row:lastRow + 1]
ba69827929ee Renamed E4Network to E5Network.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
382 self.endRemoveRows()
168
3383117f894b Fixed a few bugs in the web browser.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 52
diff changeset
383 return True

eric ide

mercurial