QGIS API Documentation  3.2.0-Bonn (bc43194)
qgsgeonodeconnection.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgeonodeconnection.cpp
3  ---------------------
4  begin : Feb 2017
5  copyright : (C) 2017 by Muhammad Yarjuna Rohmat, Ismail Sunni
6  email : rohmat at kartoza dot com, ismail at kartoza dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgssettings.h"
17 #include "qgsgeonodeconnection.h"
18 #include "qgslogger.h"
19 #include "qgsdatasourceuri.h"
20 #include "qgsowsconnection.h"
21 
22 const QString QgsGeoNodeConnectionUtils::sPathGeoNodeConnection = QStringLiteral( "qgis/connections-geonode" );
23 const QString QgsGeoNodeConnectionUtils::sPathGeoNodeConnectionDetails = QStringLiteral( "qgis/GeoNode" );
24 
26  : mConnName( name )
27 {
28  QgsSettings settings;
29 
30 // settings.Section
31  QString key = settingsKey();
32  QString credentialsKey = QgsGeoNodeConnectionUtils::pathGeoNodeConnectionDetails() + QStringLiteral( "/" ) + mConnName;
33 
34  mUri.setParam( QStringLiteral( "url" ), settings.value( key + QStringLiteral( "/url" ), QString() ).toString() );
35 
36  // Check for credentials and prepend to the connection info
37  QString username = settings.value( credentialsKey + QStringLiteral( "/username" ), QString() ).toString();
38  QString password = settings.value( credentialsKey + QStringLiteral( "/password" ), QString() ).toString();
39  if ( !username.isEmpty() )
40  {
41  mUri.setParam( QStringLiteral( "username" ), username );
42  mUri.setParam( QStringLiteral( "password" ), password );
43  }
44 
45  QString authcfg = settings.value( credentialsKey + QStringLiteral( "/authcfg" ), QString() ).toString();
46  if ( !authcfg.isEmpty() )
47  {
48  mUri.setParam( QStringLiteral( "authcfg" ), authcfg );
49  }
50 
51  QgsDebugMsg( QString( "encodedUri: '%1'." ).arg( QString( mUri.encodedUri() ) ) );
52 }
53 
55 {
56  return mUri;
57 }
58 
60 {
61  return mConnName;
62 }
63 
64 void QgsGeoNodeConnection::setConnectionName( const QString &connName )
65 {
66  mConnName = connName;
67 }
68 
70 {
71  mUri = uri;
72 }
73 
75 {
76  return QgsOwsConnection::addWmsWcsConnectionSettings( uri, settingsKey() + QStringLiteral( "/wms" ) );
77 }
78 
80 {
81  return QgsOwsConnection::addWfsConnectionSettings( uri, settingsKey() + QStringLiteral( "/wfs" ) );
82 }
83 
84 QString QgsGeoNodeConnection::settingsKey() const
85 {
86  return QgsGeoNodeConnectionUtils::pathGeoNodeConnection() + QStringLiteral( "/" ) + mConnName;
87 }
88 
89 
90 //
91 // QgsGeoNodeConnectionUtils
92 //
93 
94 
96 {
97  QgsSettings settings;
98  // Add Section manually
99  settings.beginGroup( QStringLiteral( "qgis/connections-geonode" ) );
100  return settings.childGroups();
101 }
102 
104 {
105  QgsSettings settings;
106  // Add Section manually
107  settings.remove( QStringLiteral( "qgis/connections-geonode/" ) + name );
108  settings.remove( QStringLiteral( "qgis/geonode/" ) + name );
109 }
110 
112 {
113  return sPathGeoNodeConnection;
114 }
115 
117 {
118  return sPathGeoNodeConnectionDetails;
119 }
QStringList childGroups() const
Returns a list of all key top-level groups that contain keys that can be read using the QSettings obj...
static QgsDataSourceUri & addWmsWcsConnectionSettings(QgsDataSourceUri &uri, const QString &settingsKey)
Adds uri parameters relating to the settings for a WMS or WCS connection to a QgsDataSourceUri uri...
QgsDataSourceUri uri() const
Returns the URI for the GeoNode connection.
This class is a composition of two QSettings instances:
Definition: qgssettings.h:58
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
void remove(const QString &key, QgsSettings::Section section=QgsSettings::NoSection)
Removes the setting key and any sub-settings of key in a section.
QgsGeoNodeConnection(const QString &name)
Constructor for a QgsGeoNodeConnection with the specified name.
void setUri(const QgsDataSourceUri &uri)
Sets the uri for the GeoNode connection.
QgsDataSourceUri & addWmsConnectionSettings(QgsDataSourceUri &uri) const
Adds uri parameters relating to the settings for a WMS layer on the connection to a QgsDataSourceUri ...
QString connectionName() const
Returns the name of the connection.
static void deleteConnection(const QString &name)
Deletes the GeoNode connection with matching name.
void setParam(const QString &key, const QString &value)
Set generic param (generic mode)
void beginGroup(const QString &prefix, QgsSettings::Section section=QgsSettings::NoSection)
Appends prefix to the current group.
Definition: qgssettings.cpp:86
static QgsDataSourceUri & addWfsConnectionSettings(QgsDataSourceUri &uri, const QString &settingsKey)
Adds uri parameters relating to the settings for a WFS connection to a QgsDataSourceUri uri...
QByteArray encodedUri() const
Returns complete encoded uri (generic mode)
QgsDataSourceUri & addWfsConnectionSettings(QgsDataSourceUri &uri) const
Adds uri parameters relating to the settings for a WFS layer on the connection to a QgsDataSourceUri ...
static QString pathGeoNodeConnectionDetails()
Returns the base path for settings related to GeoNode connection details.
static QString pathGeoNodeConnection()
Returns the base path for settings related to GeoNode connections.
Class for storing the component parts of a PostgreSQL/RDBMS datasource URI.
static QStringList connectionList()
Returns a list of all known GeoNode connection names.
void setConnectionName(const QString &connectionName)
Sets the name of the connection.