45 |
46 |
46 def getFileName(self): |
47 def getFileName(self): |
47 """ |
48 """ |
48 Public method to get the file name of the user agents file. |
49 Public method to get the file name of the user agents file. |
49 |
50 |
50 @return name of the user agents file (string) |
51 @return name of the user agents file |
|
52 @rtype str |
51 """ |
53 """ |
52 return os.path.join( |
54 return os.path.join( |
53 Globals.getConfigDir(), "web_browser", "userAgentSettings.xml" |
55 Globals.getConfigDir(), "web_browser", "userAgentSettings.xml" |
54 ) |
56 ) |
55 |
57 |
116 |
118 |
117 def removeUserAgent(self, host): |
119 def removeUserAgent(self, host): |
118 """ |
120 """ |
119 Public method to remove a user agent entry. |
121 Public method to remove a user agent entry. |
120 |
122 |
121 @param host host name (string) |
123 @param host host name |
|
124 @type str |
122 """ |
125 """ |
123 if host in self.__agents: |
126 if host in self.__agents: |
124 del self.__agents[host] |
127 del self.__agents[host] |
125 self.changed.emit() |
128 self.changed.emit() |
126 |
129 |
127 def allHostNames(self): |
130 def allHostNames(self): |
128 """ |
131 """ |
129 Public method to get a list of all host names we a user agent setting |
132 Public method to get a list of all host names we a user agent setting |
130 for. |
133 for. |
131 |
134 |
132 @return sorted list of all host names (list of strings) |
135 @return sorted list of all host names |
|
136 @rtype list of str |
133 """ |
137 """ |
134 if not self.__loaded: |
138 if not self.__loaded: |
135 self.__load() |
139 self.__load() |
136 |
140 |
137 return sorted(self.__agents) |
141 return sorted(self.__agents) |
138 |
142 |
139 def hostsCount(self): |
143 def hostsCount(self): |
140 """ |
144 """ |
141 Public method to get the number of available user agent settings. |
145 Public method to get the number of available user agent settings. |
142 |
146 |
143 @return number of user agent settings (integer) |
147 @return number of user agent settings |
|
148 @rtype int |
144 """ |
149 """ |
145 if not self.__loaded: |
150 if not self.__loaded: |
146 self.__load() |
151 self.__load() |
147 |
152 |
148 return len(self.__agents) |
153 return len(self.__agents) |
149 |
154 |
150 def userAgent(self, host): |
155 def userAgent(self, host): |
151 """ |
156 """ |
152 Public method to get the user agent setting for a host. |
157 Public method to get the user agent setting for a host. |
153 |
158 |
154 @param host host name (string) |
159 @param host host name |
155 @return user agent string (string) |
160 @type str |
|
161 @return user agent string |
|
162 @rtype str |
156 """ |
163 """ |
157 if not self.__loaded: |
164 if not self.__loaded: |
158 self.__load() |
165 self.__load() |
159 |
166 |
160 for agentHost in self.__agents: |
167 for agentHost in self.__agents: |
165 |
172 |
166 def setUserAgent(self, host, agent): |
173 def setUserAgent(self, host, agent): |
167 """ |
174 """ |
168 Public method to set the user agent string for a host. |
175 Public method to set the user agent string for a host. |
169 |
176 |
170 @param host host name (string) |
177 @param host host name |
171 @param agent user agent string (string) |
178 @type str |
|
179 @param agent user agent string |
|
180 @type str |
172 """ |
181 """ |
173 if host != "" and agent != "": |
182 if host != "" and agent != "": |
174 self.__agents[host] = agent |
183 self.__agents[host] = agent |
175 self.changed.emit() |
184 self.changed.emit() |
176 |
185 |
177 def userAgentForUrl(self, url): |
186 def userAgentForUrl(self, url): |
178 """ |
187 """ |
179 Public method to determine the user agent for the given URL. |
188 Public method to determine the user agent for the given URL. |
180 |
189 |
181 @param url URL to determine user agent for (QUrl) |
190 @param url URL to determine user agent for |
182 @return user agent string (string) |
191 @type QUrl |
|
192 @return user agent string |
|
193 @rtype str |
183 """ |
194 """ |
184 if url.isValid(): |
195 if url.isValid(): |
185 host = url.host() |
196 host = url.host() |
186 return self.userAgent(host) |
197 return self.userAgent(host) |
187 |
198 |
189 |
200 |
190 def setUserAgentForUrl(self, url, agent): |
201 def setUserAgentForUrl(self, url, agent): |
191 """ |
202 """ |
192 Public method to set the user agent string for an URL. |
203 Public method to set the user agent string for an URL. |
193 |
204 |
194 @param url URL to register user agent setting for (QUrl) |
205 @param url URL to register user agent setting for |
195 @param agent new current user agent string (string) |
206 @type QUrl |
|
207 @param agent new current user agent string |
|
208 @type str |
196 """ |
209 """ |
197 if url.isValid(): |
210 if url.isValid(): |
198 host = url.host() |
211 host = url.host() |
199 self.setUserAgent(host, agent) |
212 self.setUserAgent(host, agent) |