2 #include "ui_WMSConnectorDialogForm.h" 5 #include "../../../../core/translator/Translator.h" 6 #include "../../../../core/uri/Utils.h" 7 #include "../../../../dataaccess/datasource/DataSource.h" 8 #include "../../../../dataaccess/datasource/DataSourceFactory.h" 9 #include "../../../../dataaccess/datasource/DataSourceInfo.h" 10 #include "../../../../dataaccess/datasource/DataSourceManager.h" 11 #include "../../../core/Exception.h" 12 #include "../../../core/CurlWrapper.h" 13 #include "../../../../qt/af/ApplicationController.h" 16 #include <boost/algorithm/string/case_conv.hpp> 17 #include <boost/uuid/random_generator.hpp> 18 #include <boost/uuid/uuid_io.hpp> 19 #include <boost/lexical_cast.hpp> 22 #include <QMessageBox> 26 m_ui(new
Ui::WMSConnectorDialogForm)
35 m_ui->m_authCheckBox->setCheckState(Qt::Unchecked);
36 m_ui->m_authUsernameLineEdit->setEnabled(
false);
37 m_ui->m_authPasswordLineEdit->setEnabled(
false);
62 std::string serviceURL = kvp[
"URI"];
66 if(!serviceURI.
user().empty() && !serviceURI.
password().empty())
68 std::string baseURL = serviceURI.
scheme() + std::string(
"://") + serviceURI.
host();
70 if(!serviceURI.
port().empty())
72 baseURL = baseURL + std::string(
":") + serviceURI.
port();
75 baseURL = baseURL + serviceURI.
path();
77 if(!serviceURI.
query().empty())
79 baseURL = baseURL + std::string(
"?") + serviceURI.
query();
84 baseURL = baseURL + std::string(
"#") + serviceURI.
fragment();
87 m_ui->m_serverLineEdit->setText(QString::fromUtf8(baseURL.c_str()));
90 m_ui->m_authCheckBox->setCheckState(Qt::Checked);
91 m_ui->m_authUsernameLineEdit->setEnabled(
true);
92 m_ui->m_authPasswordLineEdit->setEnabled(
true);
94 m_ui->m_authUsernameLineEdit->setText(QString::fromUtf8(serviceURI.
user().c_str()));
95 m_ui->m_authPasswordLineEdit->setText(QString::fromUtf8(serviceURI.
password().c_str()));
99 m_ui->m_serverLineEdit->setText(QString::fromUtf8(serviceURL.c_str()));
102 m_ui->m_datasourceTitleLineEdit->setText(QString::fromUtf8(
m_datasource->getTitle().c_str()));
104 m_ui->m_dataSourceDescriptionTextEdit->setText(QString::fromUtf8(
m_datasource->getDescription().c_str()));
128 QString title =
m_ui->m_datasourceTitleLineEdit->text().trimmed();
131 title =
m_ui->m_serverLineEdit->text().trimmed();
140 boost::uuids::basic_random_generator<boost::mt19937> gen;
141 boost::uuids::uuid u = gen();
142 std::string dsId = boost::uuids::to_string(u);
147 m_datasource->setDescription(
m_ui->m_dataSourceDescriptionTextEdit->toPlainText().trimmed().toUtf8().data());
156 m_datasource->setDescription(
m_ui->m_dataSourceDescriptionTextEdit->toPlainText().trimmed().toUtf8().data());
161 if(
const std::string*
d =
162 boost::get_error_info<te::ErrorDescription>(e))
164 QMessageBox::warning(
this,
165 tr(
"TerraLib Qt Components"),
172 QMessageBox::warning(
this,
173 tr(
"TerraLib Qt Components"),
174 tr(
"Unknown error while opening WMS data source!"));
195 if(ds.get() ==
nullptr)
200 QMessageBox::information(
this,
201 tr(
"TerraLib Qt Components"),
202 tr(
"Data source is ok!"));
208 if(
const std::string*
d =
209 boost::get_error_info<te::ErrorDescription>(e))
211 QMessageBox::warning(
this,
212 tr(
"TerraLib Qt Components"),
218 QMessageBox::warning(
this,
219 tr(
"TerraLib Qt Components"),
220 tr(
"Unknown error while testing WMS data source!"));
226 QMessageBox::warning(
this,
227 tr(
"TerraLib Qt Components"),
228 tr(
"Not implemented yet!\nWe will provide it soon!"));
233 Qt::CheckState checkState = (Qt::CheckState) state;
235 if(checkState == Qt::Checked)
237 m_ui->m_authUsernameLineEdit->setEnabled(
true);
238 m_ui->m_authPasswordLineEdit->setEnabled(
true);
242 m_ui->m_authUsernameLineEdit->setEnabled(
false);
243 m_ui->m_authPasswordLineEdit->setEnabled(
false);
244 m_ui->m_authUsernameLineEdit->clear();
245 m_ui->m_authPasswordLineEdit->clear();
251 std::string serviceURL;
253 std::string strURI(
"wms://");
256 serviceURL =
m_ui->m_serverLineEdit->text().trimmed().toUtf8().constData();
258 if (serviceURL.empty())
261 if(
m_ui->m_authCheckBox->checkState() == Qt::Checked)
264 if(
m_ui->m_authUsernameLineEdit->text().isEmpty() ||
m_ui->m_authPasswordLineEdit->text().isEmpty())
269 std::string username =
m_ui->m_authUsernameLineEdit->text().toUtf8().constData();
270 std::string password =
m_ui->m_authPasswordLineEdit->text().toUtf8().constData();
271 std::string userAndPassword = username + std::string(
":") + password;
275 serviceURL = aux.
scheme() + std::string(
"://") + userAndPassword + std::string(
"@")
278 if(!aux.
port().empty())
280 serviceURL = serviceURL + std::string(
":") + aux.
port();
283 serviceURL = serviceURL + aux.
path();
285 if(!aux.
query().empty())
287 serviceURL = serviceURL + std::string(
"?") + aux.
query();
292 serviceURL = serviceURL + std::string(
"#") + aux.
fragment();
300 strURI = strURI +
"?URI="+ encodedURL +
"&VERSION=1.1.1" +
"&USERDATADIR=" + usrDataDir;
WMSConnectorDialog(QWidget *parent=0, Qt::WindowFlags f=0)
std::unique_ptr< Ui::WMSConnectorDialogForm > m_ui
std::string path() const
Retrieving the path.
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
static bool find(const std::string &dsType)
te::da::DataSourceInfoPtr m_datasource
std::string scheme() const
Retrieving the scheme.
boost::shared_ptr< DataSource > DataSourcePtr
TECOREEXPORT std::string URIEncode(const std::string &srcUri)
Encodes an decoded URI. The algorithm implementation is based on http://www.codeguru.com/cpp/cpp/algorithms/strings/article.php/c12759/URI-Encoding-and-Decoding.htm.
void openPushButtonPressed()
const std::string getConnectionInfo() const
void helpPushButtonPressed()
std::string fragment() const
Retrieving the fragment.
std::string password() const
Retrieving the password information.
static te::dt::Date ds(2010, 01, 01)
#define TE_TR(message)
It marks a string in order to get translated.
A dialog window for showing the WMS connector widget.
std::string query() const
Retrieving the query.
boost::error_info< struct tag_error_description, std::string > ErrorDescription
The base type for error report messages.
static ApplicationController & getInstance()
It returns a reference to the singleton instance.
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
void authCheckBoxStateChanged(const int &state)
std::string port() const
Retrieving the port.
std::string host() const
Retrieving the host.
void testPushButtonPressed()
Base exception class for WS Core Runtime Library.
const te::da::DataSourcePtr & getDriver() const
A class for representing an Uniform Resource Identifier (URI).
const te::da::DataSourceInfoPtr & getDataSource() const
void set(const te::da::DataSourceInfoPtr &ds)
TECOREEXPORT std::map< std::string, std::string > Expand(const std::string &query_str)
Split a query string into its components.
A class that represents a data source component.
te::da::DataSourcePtr m_driver
std::string user() const
Retrieving the user information.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr