patch_to_1603.diff

gary's changes derived from the 'zip' ball (see http://lists.osgeo.org/pipermail/qgis-developer/2009-April/006680.html) - Jürgen Fischer, 2009-04-18 11:31 AM

Download (15.3 KB)

View differences:

src/app/qgsnewhttpconnection.cpp (working copy)
35 35
    QSettings settings;
36 36

  
37 37
    QString key = mBaseKey + connName;
38
    QString credentialsKey = "/Qgis/WMS/" + connName;
38 39
    txtName->setText( connName );
39 40
    txtUrl->setText( settings.value( key + "/url" ).toString() );
41
    txtUserName->setText( settings.value( credentialsKey + "/username" ).toString() );
42
    txtPassword->setText( settings.value( credentialsKey + "/password" ).toString() );
43

  
40 44
  }
41 45
  connect( buttonBox, SIGNAL( helpRequested() ), this, SLOT( helpRequested() ) );
42 46
}
......
49 53
{
50 54
  QSettings settings;
51 55
  QString key = mBaseKey + txtName->text();
56
  QString credentialsKey = "/Qgis/WMS/" + txtName->text();
52 57

  
53 58
  //delete original entry first
54 59
  if ( !mOriginalConnName.isNull() && mOriginalConnName != key )
55 60
  {
56 61
    settings.remove( mBaseKey + mOriginalConnName );
62
    settings.remove ( "/Qgis/WMS/" + mOriginalConnName );
57 63
  }
58 64
  settings.setValue( key + "/url", txtUrl->text().trimmed() );
65
  settings.setValue( credentialsKey + "/username", txtUserName->text() );
66
  settings.setValue( credentialsKey + "/password", txtPassword->text() );
59 67

  
60 68
  QDialog::accept();
61 69
}
src/app/qgsserversourceselect.cpp (working copy)
39 39
#include <QDomDocument>
40 40
#include <QHeaderView>
41 41
#include <QImageReader>
42
#include <QInputDialog>
42 43
#include <QMap>
43 44
#include <QMessageBox>
44 45
#include <QPicture>
......
363 364
  QSettings settings;
364 365

  
365 366
  QString key = "/Qgis/connections-wms/" + cmbConnections->currentText();
367
  QString credentialsKey = "/Qgis/WMS/" + cmbConnections->currentText();
366 368

  
367 369
  QStringList connStringParts;
368 370
  QString part;
......
372 374
  m_connName = cmbConnections->currentText();
373 375
  m_connectionInfo = connStringParts.join( " " );
374 376

  
377
  // Check for credentials and prepend to the connection info
378
  QString username = settings.value( credentialsKey + "/username" ).toString();
379
  QString password = settings.value( credentialsKey + "/password" ).toString();
380
  if ( !username.isEmpty() )
381
  {
382
    // check for a password, if none prompt to get it
383
    if ( password.isEmpty() )
384
    {
385
      password = QInputDialog::getText( this, tr( "WMS Password for " ) + m_connName, "Password", QLineEdit::Password ); 
386

  
387
    }
388
    m_connectionInfo = "username=" + username + ",password=" + password + ",url=" + m_connectionInfo;
389
  }
390

  
391

  
375 392
  QgsDebugMsg( QString( "Connection info: '%1'." ).arg( m_connectionInfo ) );
376 393

  
377 394

  
......
774 791
    }
775 792
#endif
776 793
  }
794
  // Get username/password from settings for protected WMS
777 795

  
778 796
  QUrl url( QString( "http://geopole.org/wms/search?search=%1&type=rss" ).arg( searchTerm ) );
779 797
  QgsHttpTransaction http( url.toEncoded(),
src/core/qgshttptransaction.h (working copy)
42 42
  public:
43 43
    /**
44 44
    * Constructor.
45
    * \note userName and password added in 1.1
45 46
    */
46 47
    QgsHttpTransaction( QString uri,
47 48
                        QString proxyHost = QString(),
48 49
                        int     proxyPort = 80,
49 50
                        QString proxyUser = QString(),
50 51
                        QString proxyPass = QString(),
51
                        QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy );
52
                        QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy,
53
                        QString userName = QString(),
54
                        QString password = QString() );
52 55

  
53 56
    //! Destructor
54 57
    virtual ~QgsHttpTransaction();
......
86 89
    @param return true if proxy settings was applied, false else*/
87 90
    static bool applyProxySettings( QHttp& http, const QString& url );
88 91

  
92
    /**
93
     * Set the credentials (username and password)
94
     * \note added in 1.1
95
     */
89 96

  
97
    void setCredentials( const QString& username, const QString &password );
98

  
99

  
90 100
  public slots:
91 101

  
92 102
    void dataStarted( int id );
......
188 198
     */
189 199
    QString mError;
190 200

  
201
    /**
202
     * User name
203
     */
204
    QString mUserName;
205

  
206
    /**
207
     * Password
208
     */
209
    QString mPassword;
191 210
};
192 211

  
193 212
#endif
src/core/qgshttptransaction.cpp (working copy)
34 34
static int NETWORK_TIMEOUT_MSEC = ( 120 * 1000 );  // 120 seconds
35 35
static int HTTP_PORT_DEFAULT = 80;
36 36

  
37
//XXX Set the connection name when creating the provider instance
38
//XXX in qgswmsprovider. When creating a QgsHttpTransaction, pass
39
//XXX the user/pass combination to the constructor. Then set the
40
//XXX username and password using QHttp::setUser.
37 41
QgsHttpTransaction::QgsHttpTransaction( QString uri,
38 42
                                        QString proxyHost,
39 43
                                        int     proxyPort,
40 44
                                        QString proxyUser,
41 45
                                        QString proxyPass,
42
                                        QNetworkProxy::ProxyType proxyType )
46
                                        QNetworkProxy::ProxyType proxyType,
47
                                        QString userName,
48
                                        QString password )
43 49
    : httpresponsecontenttype( 0 ),
44 50
    httpurl( uri ),
45 51
    httphost( proxyHost ),
......
53 59
}
54 60

  
55 61

  
62
void QgsHttpTransaction::setCredentials( const QString& username, const QString& password )
63
{
64
  mUserName = username;
65
  mPassword = password;
66
}
56 67
void QgsHttpTransaction::getAsynchronously()
57 68
{
58 69

  
......
67 78

  
68 79
  QgsDebugMsg( "Entered." );
69 80
  QgsDebugMsg( "Using '" + httpurl + "'." );
81
  QgsDebugMsg( "Creds: " + mUserName + "/" + mPassword );
70 82

  
71 83
  int httpport;
72 84

  
......
88 100
  header.setValue( "User-agent", QString( "Quantum GIS - " ) + VERSION );
89 101
  // Set the host in the QHttp object
90 102
  http->setHost( qurl.host(), qurl.port( HTTP_PORT_DEFAULT ) );
103
  // Set the username and password if supplied for this connection
104
  // If we have username and password set in header
105
  if ( !mUserName.isEmpty() && !mPassword.isEmpty() )
106
  {
107
    http->setUser( mUserName, mPassword );
108
  }
91 109

  
92 110
  if ( !QgsHttpTransaction::applyProxySettings( *http, httpurl ) )
93 111
  {
src/providers/wms/qgswmsprovider.h (working copy)
422 422
     */
423 423
    void setImageCrs( QString const & crs );
424 424

  
425
    /**
426
     * Set the name of the connection for use in authentication where required
427
     * \note added in 1.1
428
     */
429
    void setConnectionName( QString const & connName);
430

  
425 431
    // TODO: Document this better.
426 432
    /** \brief   Renders the layer as an image
427 433
     *
......
687 693
    bool calculateExtent();
688 694

  
689 695
    /**
696
     * \brief Check for authentication information contained in the uri,
697
     * stripping and saving the username and password if present.
698
     *
699
     * \param uri uri to check
700
     *
701
     * \note added in 1.1
702
     */
703

  
704
    void setAuthentication( QString uri );
705

  
706
    /**
690 707
     * \brief Prepare the URI so that we can later simply append param=value
691 708
     * \param uri uri to prepare
692 709
     * \retval prepared uri
......
696 713
    //! Data source URI of the WMS for this layer
697 714
    QString httpuri;
698 715

  
716
    //! Name of the stored connection
717
    QString connectionName;
718

  
699 719
    //! URL part of URI (httpuri)
700 720
    QString baseUrl;
701 721

  
......
823 843
    QMap<int, int> mLayerParents;
824 844
    QMap<int, QStringList> mLayerParentNames;
825 845

  
846
    //! Username for basic http authentication
847
    QString mUserName;
848

  
849
    //! Password for basic http authentication
850
    QString mPassword;
851

  
826 852
};
827 853

  
828 854
#endif
src/providers/wms/qgswmsprovider.cpp (working copy)
62 62
    extentDirty( TRUE ),
63 63
    mGetFeatureInfoUrlBase( 0 ),
64 64
    mLayerCount( -1 )
65

  
65 66
{
66
  QgsDebugMsg( "QgsWmsProvider: constructing with uri '" + uri + "'." );
67
  // URL may contain username/password information for a WMS
68
  // requiring authentication. In this case the URL is prefixed
69
  // with username=user,password=pass,url=http://xxx.xxx.xx/yyy...
70
  mUserName= "";
71
  mPassword = "";
72
  setAuthentication( httpuri );
67 73

  
74
  QgsDebugMsg( "QgsWmsProvider: constructing with uri '" + httpuri + "'." );
75

  
68 76
  // assume this is a valid layer until we determine otherwise
69 77
  valid = true;
70 78

  
......
100 108
  QgsDebugMsg( "QgsWmsProvider: exiting constructor." );
101 109
}
102 110

  
111
void QgsWmsProvider::setAuthentication( QString uri )
112
{
113
  // Strip off and store the user name and password (if they exist)
114
  if ( ! uri.startsWith(" http:" ) )
115
  {
116
    // uri potentially contains username and password
117
    QStringList parts = uri.split( "," );
118
    QStringListIterator iter( parts );
119
    while ( iter.hasNext() )
120
    {
121
      QString item = iter.next();
122
      QgsDebugMsg( "QgsWmsProvider: Testing for creds: " + item );
123
      if ( item.startsWith( "username=" ) )
124
      {
125
        mUserName = item.mid( 9 );
126
        QgsDebugMsg( "QgsWmsProvider: Set username to " + mUserName );
127
      }
128
      else if ( item.startsWith( "password=" ) )
129
      {
130
        mPassword = item.mid( 9 );
131
        QgsDebugMsg( "QgsWmsProvider: Set password to " + mPassword );
132
      }
133
      else if ( item.startsWith( "url=" ) )
134
      {
135
        // strip the authentication information from the front of the uri
136
        httpuri = item.mid( 4 );
137
        QgsDebugMsg( "QgsWmsProvider: Set httpuri to " + httpuri );
138
      }
139
    }
140

  
141
  }
142

  
143
}
103 144
QString QgsWmsProvider::prepareUri( QString uri )
104 145
{
105 146
  if ( !( uri.contains( "?" ) ) )
......
221 262
  QgsDebugMsg( "Exiting." );
222 263
}
223 264

  
265
void QgsWmsProvider::setConnectionName( QString const &connName )
266
{
267
  connectionName = connName;
268
}
224 269

  
225 270
void QgsWmsProvider::setLayerOrder( QStringList const &layers )
226 271
{
......
640 685
{
641 686
  QgsDebugMsg( "WMS request Url: " + url );
642 687
  QgsHttpTransaction http( url );
643

  
688
  QgsDebugMsg( "Setting creds: " + mUserName + "/" + mPassword );
689
  http.setCredentials( mUserName, mPassword );
690
  
644 691
  // Do a passthrough for the status bar text
645 692
  connect(
646 693
    &http, SIGNAL( statusChanged( QString ) ),
src/ui/qgsnewhttpconnectionbase.ui (working copy)
5 5
   <rect>
6 6
    <x>0</x>
7 7
    <y>0</y>
8
    <width>431</width>
9
    <height>159</height>
8
    <width>606</width>
9
    <height>264</height>
10 10
   </rect>
11 11
  </property>
12 12
  <property name="windowTitle" >
......
24 24
     <property name="title" >
25 25
      <string>Connection details</string>
26 26
     </property>
27
     <widget class="QLabel" name="label" >
28
      <property name="geometry" >
29
       <rect>
30
        <x>14</x>
31
        <y>112</y>
32
        <width>553</width>
33
        <height>48</height>
34
       </rect>
35
      </property>
36
      <property name="text" >
37
       <string>If the WMS requires basic authentication, enter a user name and optional password</string>
38
      </property>
39
      <property name="textFormat" >
40
       <enum>Qt::PlainText</enum>
41
      </property>
42
      <property name="wordWrap" >
43
       <bool>true</bool>
44
      </property>
45
     </widget>
46
     <widget class="QWidget" name="" >
47
      <property name="geometry" >
48
       <rect>
49
        <x>15</x>
50
        <y>34</y>
51
        <width>552</width>
52
        <height>68</height>
53
       </rect>
54
      </property>
27 55
     <layout class="QGridLayout" >
28 56
      <item row="0" column="0" >
57
        <layout class="QVBoxLayout" >
58
         <item>
29 59
       <widget class="QLabel" name="TextLabel1_2" >
30 60
        <property name="text" >
31 61
         <string>Name</string>
......
38 68
        </property>
39 69
       </widget>
40 70
      </item>
71
         <item>
72
          <widget class="QLabel" name="TextLabel1" >
73
           <property name="text" >
74
            <string>URL</string>
75
           </property>
76
           <property name="margin" >
77
            <number>5</number>
78
           </property>
79
           <property name="buddy" >
80
            <cstring>txtUrl</cstring>
81
           </property>
82
          </widget>
83
         </item>
84
        </layout>
85
       </item>
41 86
      <item row="0" column="1" >
87
        <layout class="QVBoxLayout" >
88
         <item>
42 89
       <widget class="QLineEdit" name="txtName" >
43 90
        <property name="minimumSize" >
44 91
         <size>
......
54 101
        </property>
55 102
       </widget>
56 103
      </item>
57
      <item row="1" column="0" >
58
       <widget class="QLabel" name="TextLabel1" >
104
         <item>
105
          <widget class="QLineEdit" name="txtUrl" >
106
           <property name="toolTip" >
107
            <string>HTTP address of the Web Map Server</string>
108
           </property>
109
          </widget>
110
         </item>
111
        </layout>
112
       </item>
113
      </layout>
114
     </widget>
115
     <widget class="QWidget" name="" >
116
      <property name="geometry" >
117
       <rect>
118
        <x>20</x>
119
        <y>150</y>
120
        <width>68</width>
121
        <height>56</height>
122
       </rect>
123
      </property>
124
      <layout class="QVBoxLayout" >
125
       <item>
126
        <widget class="QLabel" name="label_2" >
59 127
        <property name="text" >
60
         <string>URL</string>
128
          <string>User name</string>
61 129
        </property>
62
        <property name="margin" >
63
         <number>5</number>
130
        </widget>
131
       </item>
132
       <item>
133
        <widget class="QLabel" name="label_3" >
134
         <property name="text" >
135
          <string>Password</string>
64 136
        </property>
65
        <property name="buddy" >
66
         <cstring>txtUrl</cstring>
137
        </widget>
138
       </item>
139
      </layout>
140
     </widget>
141
     <widget class="QWidget" name="" >
142
      <property name="geometry" >
143
       <rect>
144
        <x>98</x>
145
        <y>151</y>
146
        <width>122</width>
147
        <height>56</height>
148
       </rect>
149
      </property>
150
      <layout class="QVBoxLayout" >
151
       <item>
152
        <widget class="QLineEdit" name="txtUserName" >
153
         <property name="maximumSize" >
154
          <size>
155
           <width>120</width>
156
           <height>16777215</height>
157
          </size>
67 158
        </property>
68 159
       </widget>
69 160
      </item>
70
      <item row="1" column="1" >
71
       <widget class="QLineEdit" name="txtUrl" >
72
        <property name="toolTip" >
73
         <string>HTTP address of the Web Map Server</string>
161
       <item>
162
        <widget class="QLineEdit" name="txtPassword" >
163
         <property name="maximumSize" >
164
          <size>
165
           <width>120</width>
166
           <height>120</height>
167
          </size>
168
         </property>
169
         <property name="echoMode" >
170
          <enum>QLineEdit::Password</enum>
74 171
        </property>
75 172
       </widget>
76 173
      </item>
77 174
     </layout>
78 175
    </widget>
176
    </widget>
79 177
   </item>
80 178
   <item row="1" column="0" >
81 179
    <widget class="QDialogButtonBox" name="buttonBox" >