All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
43 te::qt::plugins::ado::ADOConnector::ADOConnector(QWidget* parent, Qt::WindowFlags f)
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::auto_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::DataSourcePtr driver = cdialog->getDriver();
69 
71  }
72 }
73 
74 void te::qt::plugins::ado::ADOConnector::create(std::list<te::da::DataSourceInfoPtr>& datasources)
75 {
76  std::auto_ptr<ADOCreatorDialog> cdialog(new ADOCreatorDialog(static_cast<QWidget*>(parent())));
77 
78  int retval = cdialog->exec();
79 
80  if(retval == QDialog::Rejected)
81  return;
82 
83  te::da::DataSourceInfoPtr ds = cdialog->getDataSource();
84 
85  if(ds.get() != 0)
86  {
88  datasources.push_back(ds);
89 
90  te::da::DataSourcePtr driver = cdialog->getDriver();
91 
93  }
94 }
95 
96 void te::qt::plugins::ado::ADOConnector::update(std::list<te::da::DataSourceInfoPtr>& datasources)
97 {
98  for(std::list<te::da::DataSourceInfoPtr>::iterator it = datasources.begin(); it != datasources.end(); ++it)
99  {
100  if(it->get() == 0)
101  continue;
102 
103  std::auto_ptr<ADOConnectorDialog> cdialog(new ADOConnectorDialog(static_cast<QWidget*>(parent()), 0, ADOConnectorDialog::UPDATE));
104 
105  cdialog->set(*it);
106 
107  int retval = cdialog->exec();
108 
109  if(retval == QDialog::Rejected)
110  continue;
111 
112 // don't forget to replace the driver
113  te::da::DataSourcePtr driver = cdialog->getDriver();
114 
115  if(driver.get() != 0)
116  {
117  if(te::da::DataSourceManager::getInstance().find(driver->getId()) != 0)
118  te::da::DataSourceManager::getInstance().detach(driver->getId());
119 
121  }
122  }
123 }
124 
125 void te::qt::plugins::ado::ADOConnector::remove(std::list<te::da::DataSourceInfoPtr>& datasources)
126 {
127  for(std::list<te::da::DataSourceInfoPtr>::iterator it = datasources.begin(); it != datasources.end(); ++it)
128  {
129  if(it->get() == 0)
130  continue;
131 
132 // first remove driver
134 
135  if(rds.get())
136  {
138  rds.reset();
139  }
140 
141 // then remove data source
142  te::da::DataSourceInfoManager::getInstance().remove((*it)->getId());
143  }
144 }
145 
void update(std::list< te::da::DataSourceInfoPtr > &datasources)
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
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