attic/src/qt/plugins/datasource/wcs/WCSConnectorDialog.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/qt/plugins/datasource/wcs/WCSConnectorDialog.cpp
22 
23  \brief A dialog window for showing the WCS connector widget.
24 */
25 
26 // TerraLib
27 #include "../../../../core/translator/Translator.h"
28 #include "../../../../core/uri/URI.h"
29 #include "../../../../core/uri/Utils.h"
30 #include "../../../../dataaccess/datasource/DataSource.h"
31 #include "../../../../dataaccess/datasource/DataSourceFactory.h"
32 #include "../../../../dataaccess/datasource/DataSourceInfo.h"
33 #include "../../../../dataaccess/datasource/DataSourceManager.h"
34 #include "../../../widgets/Exception.h"
35 #include "WCSConnectorDialog.h"
36 #include "ui_WCSConnectorDialogForm.h"
37 
38 // Boost
39 #include <boost/algorithm/string/case_conv.hpp>
40 #include <boost/uuid/random_generator.hpp>
41 #include <boost/uuid/uuid_io.hpp>
42 #include <boost/lexical_cast.hpp>
43 
44 // Qt
45 #include <QMessageBox>
46 
48  : QDialog(parent, f),
49  m_ui(new Ui::WCSConnectorDialogForm)
50 {
51 // add controls
52  m_ui->setupUi(this);
53 
54 // connect signal and slots
55  connect(m_ui->m_openPushButton, SIGNAL(pressed()), this, SLOT(openPushButtonPressed()));
56  connect(m_ui->m_testPushButton, SIGNAL(pressed()), this, SLOT(testPushButtonPressed()));
57  connect(m_ui->m_helpPushButton, SIGNAL(pressed()), this, SLOT(helpPushButtonPressed()));
58 }
59 
61 {
62 }
63 
65 {
66  return m_datasource;
67 }
68 
70 {
71  return m_driver;
72 }
73 
75 {
76  m_datasource = ds;
77 
78  if(m_datasource.get() != 0)
79  {
80  const te::core::URI& connInfo = m_datasource->getConnInfo();
81 
82  if(!connInfo.uri().empty())
83  m_ui->m_serverLineEdit->setText(QString::fromUtf8(connInfo.uri().c_str()));
84 
85  m_ui->m_datasourceTitleLineEdit->setText(QString::fromUtf8(m_datasource->getTitle().c_str()));
86 
87  m_ui->m_datasourceDescriptionTextEdit->setText(QString::fromUtf8(m_datasource->getDescription().c_str()));
88  }
89 }
90 
92 {
93  try
94  {
95  // Check if driver is loaded
96  if(te::da::DataSourceFactory::find("WCS") == 0)
97  throw te::qt::widgets::Exception(TE_TR("Sorry! No data access driver loaded for WCS data sources!"));
98 
99  // Get the data source connection info based on form data
100  std::string dsInfo = getConnectionInfo();
101 
102  // Perform connection
103  std::unique_ptr<te::da::DataSource> ds = te::da::DataSourceFactory::make("WCS", dsInfo);
104  ds->open();
105  m_driver.reset(ds.release());
106 
107  if(m_driver.get() == 0)
108  throw te::qt::widgets::Exception(TE_TR("Could not open WCS data source due to an unknown error!"));
109 
110  QString title = m_ui->m_datasourceTitleLineEdit->text().trimmed();
111 
112  if(title.isEmpty())
113  title = m_ui->m_serverLineEdit->text().trimmed();
114 
115  if(m_datasource.get() == 0)
116  {
117  // Create a new data source based on the form data
119 
120  m_datasource->setConnInfo(dsInfo);
121 
122  boost::uuids::basic_random_generator<boost::mt19937> gen;
123  boost::uuids::uuid u = gen();
124  std::string dsId = boost::uuids::to_string(u);
125 
126  m_datasource->setId(dsId);
127  m_driver->setId(dsId);
128  m_datasource->setTitle(title.toUtf8().data());
129  m_datasource->setDescription(m_ui->m_datasourceDescriptionTextEdit->toPlainText().trimmed().toUtf8().data());
130  m_datasource->setAccessDriver("WCS");
131  m_datasource->setType("WCS");
132  }
133  else
134  {
135  m_driver->setId(m_datasource->getId());
136  m_datasource->setConnInfo(dsInfo);
137  m_datasource->setTitle(title.toUtf8().data());
138  m_datasource->setDescription(m_ui->m_datasourceDescriptionTextEdit->toPlainText().trimmed().toUtf8().data());
139  }
140  }
141  catch(const std::exception& e)
142  {
143  QMessageBox::warning(this,
144  tr("TerraLib Qt Components"),
145  tr(e.what()));
146  return;
147  }
148  catch(...)
149  {
150  QMessageBox::warning(this,
151  tr("TerraLib Qt Components"),
152  tr("Unknown error while opening WCS data source!"));
153  return;
154  }
155 
156  accept();
157 }
158 
160 {
161  try
162  {
163  // Check if driver is loaded
164  if(te::da::DataSourceFactory::find("WCS") == 0)
165  throw te::qt::widgets::Exception(TE_TR("Sorry! No data access driver loaded for WCS data sources!"));
166 
167  // Perform connection
168  std::unique_ptr<te::da::DataSource> ds(te::da::DataSourceFactory::make("WCS", getConnectionInfo()));
169 
170  if(ds.get() == 0)
171  throw te::qt::widgets::Exception(TE_TR("Could not open WCS server!"));
172 
173  ds->open();
174 
175  QMessageBox::information(this,
176  tr("TerraLib Qt Components"),
177  tr("Data source is ok!"));
178 
179  ds->close();
180  }
181  catch(const std::exception& e)
182  {
183  QMessageBox::warning(this,
184  tr("TerraLib Qt Components"),
185  tr(e.what()));
186  }
187  catch(...)
188  {
189  QMessageBox::warning(this,
190  tr("TerraLib Qt Components"),
191  tr("Unknown error while testing WCS data source!"));
192  }
193 }
194 
196 {
197  QMessageBox::warning(this,
198  tr("TerraLib Qt Components"),
199  tr("Not implemented yet!\nWe will provide it soon!"));
200 }
201 
203 {
204  QString qstr; // Auxialiary string used to hold temporary data
205 
206  std::string strURI("WCS:"); // The base of the URI
207 
208  qstr = m_ui->m_serverLineEdit->text().trimmed();
209 
210  if (qstr.isEmpty())
211  throw te::qt::widgets::Exception(TE_TR("Please select a feature file first!"));
212 
213  strURI += qstr.toUtf8().data();
214 
215  return strURI;
216 }
static std::unique_ptr< DataSource > make(const std::string &driver, const te::core::URI &connInfo)
boost::shared_ptr< DataSource > DataSourcePtr
static te::dt::Date ds(2010, 01, 01)
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
const std::string & uri() const
Retrieving the full URI.
Definition: URI.cpp:88
A class for representing an Uniform Resource Identifier (URI).
Definition: URI.h:49
A class that represents a data source component.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr