14
14
# Alexander Bruy (alexander.bruy@gmail.com),
15
15
# Maxim Dubinin (sim@gis-lab.info)
16
16
#
17
- # Copyright (C) 2014 Tom Kralidis (tomkralidis@gmail.com)
17
+ # Copyright (C) 2017 Tom Kralidis (tomkralidis@gmail.com)
18
18
#
19
19
# This source is free software; you can redistribute it and/or modify it under
20
20
# the terms of the GNU General Public License as published by the Free
34
34
35
35
import json
36
36
import os .path
37
- from urllib .request import build_opener , install_opener , ProxyHandler
37
+ from urllib .request import build_opener , HTTPError , install_opener , HTTPBasicAuthHandler , HTTPHandler , ProxyHandler
38
38
39
39
from qgis .PyQt .QtCore import Qt
40
40
from qgis .PyQt .QtWidgets import QApplication , QDialog , QDialogButtonBox , QMessageBox , QTreeWidgetItem , QWidget
@@ -77,6 +77,8 @@ def __init__(self, iface):
77
77
self .settings = QgsSettings ()
78
78
self .catalog = None
79
79
self .catalog_url = None
80
+ self .catalog_username = None
81
+ self .catalog_password = None
80
82
self .context = StaticContext ()
81
83
82
84
version = self .context .metadata .get ('general' , 'version' )
@@ -149,6 +151,8 @@ def manageGui(self):
149
151
150
152
key = '/MetaSearch/%s' % self .cmbConnectionsSearch .currentText ()
151
153
self .catalog_url = self .settings .value ('%s/url' % key )
154
+ self .catalog_username = self .settings .value ('%s/username' % key )
155
+ self .catalog_password = self .settings .value ('%s/password' % key )
152
156
153
157
self .set_bbox_global ()
154
158
@@ -252,6 +256,8 @@ def save_connection(self):
252
256
253
257
if caller == 'cmbConnectionsSearch' : # bind to service in search tab
254
258
self .catalog_url = self .settings .value ('%s/url' % key )
259
+ self .catalog_username = self .settings .value ('%s/username' % key )
260
+ self .catalog_password = self .settings .value ('%s/password' % key )
255
261
256
262
if caller == 'cmbConnectionsServices' : # clear server metadata
257
263
self .textMetadata .clear ()
@@ -264,6 +270,8 @@ def connection_info(self):
264
270
current_text = self .cmbConnectionsServices .currentText ()
265
271
key = '/MetaSearch/%s' % current_text
266
272
self .catalog_url = self .settings .value ('%s/url' % key )
273
+ self .catalog_username = self .settings .value ('%s/username' % key )
274
+ self .catalog_password = self .settings .value ('%s/password' % key )
267
275
268
276
# connect to the server
269
277
if not self ._get_csw ():
@@ -301,6 +309,9 @@ def edit_connection(self):
301
309
conn_edit .setWindowTitle (self .tr ('Edit Catalogue service' ))
302
310
conn_edit .leName .setText (current_text )
303
311
conn_edit .leURL .setText (url )
312
+ conn_edit .leUsername .setText (self .settings .value ('/MetaSearch/%s/username' % current_text ))
313
+ conn_edit .lePassword .setText (self .settings .value ('/MetaSearch/%s/password' % current_text ))
314
+
304
315
if conn_edit .exec_ () == QDialog .Accepted : # update service list
305
316
self .populate_connection_list ()
306
317
@@ -433,6 +444,8 @@ def search(self):
433
444
current_text = self .cmbConnectionsSearch .currentText ()
434
445
key = '/MetaSearch/%s' % current_text
435
446
self .catalog_url = self .settings .value ('%s/url' % key )
447
+ self .catalog_username = self .settings .value ('%s/username' % key )
448
+ self .catalog_password = self .settings .value ('%s/password' % key )
436
449
437
450
# start position and number of records to return
438
451
self .startfrom = 0
@@ -771,7 +784,9 @@ def show_metadata(self):
771
784
772
785
try :
773
786
QApplication .setOverrideCursor (QCursor (Qt .WaitCursor ))
774
- cat = CatalogueServiceWeb (self .catalog_url , timeout = self .timeout )
787
+ cat = CatalogueServiceWeb (self .catalog_url , timeout = self .timeout ,
788
+ username = self .catalog_username ,
789
+ password = self .catalog_password )
775
790
cat .getrecordbyid (
776
791
[self .catalog .records [identifier ].identifier ])
777
792
except ExceptionReport as err :
@@ -850,7 +865,9 @@ def _get_csw(self):
850
865
try :
851
866
QApplication .setOverrideCursor (QCursor (Qt .WaitCursor ))
852
867
self .catalog = CatalogueServiceWeb (self .catalog_url ,
853
- timeout = self .timeout )
868
+ timeout = self .timeout ,
869
+ username = self .catalog_username ,
870
+ password = self .catalog_password )
854
871
return True
855
872
except ExceptionReport as err :
856
873
msg = self .tr ('Error connecting to service: {0}' ).format (err )
@@ -859,8 +876,8 @@ def _get_csw(self):
859
876
except Exception as err :
860
877
msg = self .tr ('Unknown Error: {0}' ).format (err )
861
878
862
- QMessageBox .warning (self , self .tr ('CSW Connection error' ), msg )
863
879
QApplication .restoreOverrideCursor ()
880
+ QMessageBox .warning (self , self .tr ('CSW Connection error' ), msg )
864
881
return False
865
882
866
883
def install_proxy (self ):
0 commit comments