ADOConnector.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/widgets/datasource/connector/ado/ADOConnector.cpp
22 
23  \brief ....
24 */
25 
26 // TerraLib
27 #include "../../../../dataaccess/datasource/DataSource.h"
28 #include "../../../../dataaccess/datasource/DataSourceInfoManager.h"
29 #include "../../../../dataaccess/datasource/DataSourceManager.h"
30 #include "ADOConnector.h"
31 #include "ADOConnectorDialog.h"
32 #include "ADOCreatorDialog.h"
33 
34 // Boost
35 #include <boost/uuid/random_generator.hpp>
36 #include <boost/uuid/uuid_io.hpp>
37 #include <boost/filesystem.hpp>
38 
39 // Qt
40 #include <QFileDialog>
41 #include <QMessageBox>
42 
44  : AbstractDataSourceConnector(parent, f)
45 {
46 }
47 
49 {
50 }
51 
52 void te::qt::plugins::ado::ADOConnector::connect(std::list<te::da::DataSourceInfoPtr>& datasources)
53 {
54  std::unique_ptr<ADOConnectorDialog> cdialog(new ADOConnectorDialog(static_cast<QWidget*>(parent())));
55 
56  int retval = cdialog->exec();
57 
58  if(retval == QDialog::Rejected)
59  return;
60 
61  te::da::DataSourceInfoPtr ds = cdialog->getDataSource();
62 
63  if(ds.get() != 0)
64  {
66  datasources.push_back(ds);
67 
68  te::da::DataSourceManager::getInstance().make(ds->getId(), ds->getType(), ds->getConnInfo());
69  }
70 }
71 
72 void te::qt::plugins::ado::ADOConnector::create(std::list<te::da::DataSourceInfoPtr>& datasources)
73 {
74  std::unique_ptr<ADOCreatorDialog> cdialog(new ADOCreatorDialog(static_cast<QWidget*>(parent())));
75 
76  int retval = cdialog->exec();
77 
78  if(retval == QDialog::Rejected)
79  return;
80 
81  te::da::DataSourceInfoPtr ds = cdialog->getDataSource();
82 
83  if(ds.get() != 0)
84  {
86  datasources.push_back(ds);
87 
88  te::da::DataSourcePtr driver = cdialog->getDriver();
89 
91  }
92 }
93 
94 void te::qt::plugins::ado::ADOConnector::update(std::list<te::da::DataSourceInfoPtr>& datasources)
95 {
96  for(std::list<te::da::DataSourceInfoPtr>::iterator it = datasources.begin(); it != datasources.end(); ++it)
97  {
98  if(it->get() == 0)
99  continue;
100 
101  std::unique_ptr<ADOConnectorDialog> cdialog(new ADOConnectorDialog(static_cast<QWidget*>(parent()), 0, ADOConnectorDialog::UPDATE));
102 
103  cdialog->set(*it);
104 
105  int retval = cdialog->exec();
106 
107  if(retval == QDialog::Rejected)
108  continue;
109 
110 // don't forget to replace the driver
111  te::da::DataSourcePtr driver = cdialog->getDriver();
112 
113  if(driver.get() != 0)
114  {
115  if(te::da::DataSourceManager::getInstance().find(driver->getId()) != 0)
116  te::da::DataSourceManager::getInstance().detach(driver->getId());
117 
119  }
120  }
121 }
122 
123 void te::qt::plugins::ado::ADOConnector::remove(std::list<te::da::DataSourceInfoPtr>& datasources)
124 {
125  for(std::list<te::da::DataSourceInfoPtr>::iterator it = datasources.begin(); it != datasources.end(); ++it)
126  {
127  if(it->get() == 0)
128  continue;
129 
130 // first remove driver
132 
133  if(rds.get())
134  {
136  rds.reset();
137  }
138 
139 // then remove data source
140  te::da::DataSourceInfoManager::getInstance().remove((*it)->getId());
141  }
142 }
143 
void update(std::list< te::da::DataSourceInfoPtr > &datasources)
boost::shared_ptr< DataSource > DataSourcePtr
static te::dt::Date ds(2010, 01, 01)
void create(std::list< te::da::DataSourceInfoPtr > &datasources)
void connect(std::list< te::da::DataSourceInfoPtr > &datasources)
void remove(std::list< te::da::DataSourceInfoPtr > &datasources)
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
ADOConnector(QWidget *parent=0, Qt::WindowFlags f=0)
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr