27 #include "ui_WCSConnectorDialogForm2.h" 31 #include "../../../../core/translator/Translator.h" 32 #include "../../../../core/uri/URI.h" 33 #include "../../../../core/uri/Utils.h" 34 #include "../../../../dataaccess/datasource/DataSource.h" 35 #include "../../../../dataaccess/datasource/DataSourceFactory.h" 36 #include "../../../../dataaccess/datasource/DataSourceInfo.h" 37 #include "../../../../dataaccess/datasource/DataSourceManager.h" 38 #include "../dataaccess/Exception.h" 39 #include "../../../core/Exception.h" 40 #include "../../../../qt/af/ApplicationController.h" 44 #include <boost/algorithm/string/case_conv.hpp> 45 #include <boost/uuid/random_generator.hpp> 46 #include <boost/uuid/uuid_io.hpp> 47 #include <boost/lexical_cast.hpp> 50 #include <QMessageBox> 51 #include <QFileDialog> 55 m_ui(new
Ui::WCSConnectorDialogForm2)
61 m_ui->m_wcsDirToolButton->setIcon(QIcon::fromTheme(
"folder"));
70 m_ui->m_authCheckBox->setCheckState(Qt::Unchecked);
71 m_ui->m_authUsernameLineEdit->setEnabled(
false);
72 m_ui->m_authPasswordLineEdit->setEnabled(
false);
97 std::string serviceURL = kvp[
"URI"];
101 if(!serviceURI.
user().empty() && !serviceURI.
password().empty())
103 std::string baseURL = serviceURI.
scheme() + std::string(
"://") + serviceURI.
host();
105 if(!serviceURI.
port().empty())
107 baseURL = baseURL + std::string(
":") + serviceURI.
port();
110 baseURL = baseURL + serviceURI.
path();
112 if(!serviceURI.
query().empty())
114 baseURL = baseURL + std::string(
"?") + serviceURI.
query();
119 baseURL = baseURL + std::string(
"#") + serviceURI.
fragment();
122 m_ui->m_serverLineEdit->setText(QString::fromUtf8(baseURL.c_str()));
125 m_ui->m_authCheckBox->setCheckState(Qt::Checked);
126 m_ui->m_authUsernameLineEdit->setEnabled(
true);
127 m_ui->m_authPasswordLineEdit->setEnabled(
true);
129 m_ui->m_authUsernameLineEdit->setText(QString::fromUtf8(serviceURI.
user().c_str()));
130 m_ui->m_authPasswordLineEdit->setText(QString::fromUtf8(serviceURI.
password().c_str()));
134 m_ui->m_serverLineEdit->setText(QString::fromUtf8(serviceURL.c_str()));
137 m_ui->m_datasourceTitleLineEdit->setText(QString::fromUtf8(
m_datasource->getTitle().c_str()));
139 m_ui->m_datasourceDescriptionTextEdit->setText(QString::fromUtf8(
m_datasource->getDescription().c_str()));
141 std::string usrDataDir = kvp[
"USERDATADIR"];
143 m_ui->m_wcsDirLineEdit->setText(QString::fromUtf8(usrDataDir.c_str()));
153 throw te::ws::ogc::wcs::da::Exception(
TE_TR(
"Sorry! No data access driver loaded for WCS data sources!"));
164 throw te::ws::ogc::wcs::da::Exception(
TE_TR(
"Could not open WCS data source due to an unknown error!"));
166 QString title =
m_ui->m_datasourceTitleLineEdit->text().trimmed();
169 title =
m_ui->m_serverLineEdit->text().trimmed();
178 boost::uuids::basic_random_generator<boost::mt19937> gen;
179 boost::uuids::uuid u = gen();
180 std::string dsId = boost::uuids::to_string(u);
185 m_datasource->setDescription(
m_ui->m_datasourceDescriptionTextEdit->toPlainText().trimmed().toUtf8().data());
194 m_datasource->setDescription(
m_ui->m_datasourceDescriptionTextEdit->toPlainText().trimmed().toUtf8().data());
199 if(
const std::string*
d =
200 boost::get_error_info<te::ErrorDescription>(e))
202 QMessageBox::warning(
this,
203 tr(
"TerraLib Qt Components"),
210 QMessageBox::warning(
this,
211 tr(
"TerraLib Qt Components"),
212 tr(
"Unknown error while opening WCS data source!"));
225 throw te::ws::ogc::wcs::da::Exception(
TE_TR(
"Sorry! No data access driver loaded for WCS data sources!"));
230 if(ds.get() ==
nullptr)
235 QMessageBox::information(
this,
236 tr(
"TerraLib Qt Components"),
237 tr(
"Data source is ok!"));
243 if(
const std::string*
d =
244 boost::get_error_info<te::ErrorDescription>(e))
246 QMessageBox::warning(
this,
247 tr(
"TerraLib Qt Components"),
253 QMessageBox::warning(
this,
254 tr(
"TerraLib Qt Components"),
255 tr(
"Unknown error while testing WCS data source!"));
261 QMessageBox::warning(
this,
262 tr(
"TerraLib Qt Components"),
263 tr(
"Not implemented yet!\nWe will provide it soon!"));
268 Qt::CheckState checkState = (Qt::CheckState) state;
270 if(checkState == Qt::Checked)
272 m_ui->m_authUsernameLineEdit->setEnabled(
true);
273 m_ui->m_authPasswordLineEdit->setEnabled(
true);
277 m_ui->m_authUsernameLineEdit->setEnabled(
false);
278 m_ui->m_authPasswordLineEdit->setEnabled(
false);
279 m_ui->m_authUsernameLineEdit->clear();
280 m_ui->m_authPasswordLineEdit->clear();
286 QString folderName = QFileDialog::getExistingDirectory(
this, tr(
"Select a directory"),
"");
288 if (folderName.isEmpty())
291 m_ui->m_wcsDirLineEdit->setText(folderName);
296 std::string strURI(
"wcs://");
299 std::string serviceURL =
m_ui->m_serverLineEdit->text().trimmed().toUtf8().constData();
301 if (serviceURL.empty())
304 std::string usrDataDir =
m_ui->m_wcsDirLineEdit->text().trimmed().toUtf8().constData();
306 if (usrDataDir.empty())
309 if(
m_ui->m_authCheckBox->checkState() == Qt::Checked)
312 if(
m_ui->m_authUsernameLineEdit->text().isEmpty() ||
m_ui->m_authPasswordLineEdit->text().isEmpty())
317 std::string username =
m_ui->m_authUsernameLineEdit->text().toUtf8().constData();
318 std::string password =
m_ui->m_authPasswordLineEdit->text().toUtf8().constData();
319 std::string userAndPassword = username + std::string(
":") + password;
323 serviceURL = aux.
scheme() + std::string(
"://") + userAndPassword + std::string(
"@")
326 if(!aux.
port().empty())
328 serviceURL = serviceURL + std::string(
":") + aux.
port();
331 serviceURL = serviceURL + aux.
path();
333 if(!aux.
query().empty())
335 serviceURL = serviceURL + std::string(
"?") + aux.
query();
340 serviceURL = serviceURL + std::string(
"#") + aux.
fragment();
346 strURI = strURI +
"?URI="+ encodedURL +
"&VERSION=2.0.1" +
"&USERDATADIR=" + usrDataDir;
A dialog window for showing the WCS connector widget.
std::string path() const
Retrieving the path.
te::da::DataSourceInfoPtr m_datasource
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
static bool find(const std::string &dsType)
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.
std::string fragment() const
Retrieving the fragment.
void set(const te::da::DataSourceInfoPtr &ds)
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.
std::string query() const
Retrieving the query.
boost::error_info< struct tag_error_description, std::string > ErrorDescription
The base type for error report messages.
void testPushButtonPressed()
const std::string getConnectionInfo() const
std::unique_ptr< Ui::WCSConnectorDialogForm2 > m_ui
void helpPushButtonPressed()
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
std::string port() const
Retrieving the port.
std::string host() const
Retrieving the host.
te::da::DataSourcePtr m_driver
void authCheckBoxStateChanged(const int &state)
void wcsDirToolButtonClicked()
Base exception class for WS Core Runtime Library.
A class for representing an Uniform Resource Identifier (URI).
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.
const te::da::DataSourceInfoPtr & getDataSource() const
WCSConnectorDialog(QWidget *parent=0, Qt::WindowFlags f=0)
const te::da::DataSourcePtr & getDriver() const
void openPushButtonPressed()
std::string user() const
Retrieving the user information.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr