All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SQLiteConnector.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/sqlite/SQLiteConnector.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 "SQLiteConnector.h"
31 #include "SQLiteConnectorDialog.h"
32 #include "SQLiteCreatorDialog.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 <QtGui/QFileDialog>
41 #include <QtGui/QMessageBox>
42 
44  : AbstractDataSourceConnector(parent, f)
45 {
46 }
47 
49 {
50 }
51 
52 void te::qt::plugins::sqlite::SQLiteConnector::connect(std::list<te::da::DataSourceInfoPtr>& datasources)
53 {
54  std::auto_ptr<SQLiteConnectorDialog> cdialog(new SQLiteConnectorDialog(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::sqlite::SQLiteConnector::create(std::list<te::da::DataSourceInfoPtr>& datasources)
75 {
76  std::auto_ptr<SQLiteCreatorDialog> cdialog(new SQLiteCreatorDialog(static_cast<QWidget*>(parent())));
77 
78  int retval = cdialog->exec();
79 
80  if(retval == QDialog::Rejected)
81  return;
82 }
83 
84 void te::qt::plugins::sqlite::SQLiteConnector::update(std::list<te::da::DataSourceInfoPtr>& datasources)
85 {
86  for(std::list<te::da::DataSourceInfoPtr>::iterator it = datasources.begin(); it != datasources.end(); ++it)
87  {
88  if(it->get() == 0)
89  continue;
90 
91  std::auto_ptr<SQLiteConnectorDialog> cdialog(new SQLiteConnectorDialog(static_cast<QWidget*>(parent())));
92 
93  cdialog->set(*it);
94 
95  int retval = cdialog->exec();
96 
97  if(retval == QDialog::Rejected)
98  continue;
99 
100 // don't forget to replace the driver
101  te::da::DataSourcePtr driver = cdialog->getDriver();
102 
103  if(driver.get() != 0)
104  {
105  if(te::da::DataSourceManager::getInstance().find(driver->getId()) != 0)
106  te::da::DataSourceManager::getInstance().detach(driver->getId());
107 
109  }
110  }
111 }
112 
113 void te::qt::plugins::sqlite::SQLiteConnector::remove(std::list<te::da::DataSourceInfoPtr>& datasources)
114 {
115  for(std::list<te::da::DataSourceInfoPtr>::iterator it = datasources.begin(); it != datasources.end(); ++it)
116  {
117  if(it->get() == 0)
118  continue;
119 
120 // first remove driver
122 
123  if(rds.get())
124  {
126  rds.reset();
127  }
128 
129 // then remove data source
130  te::da::DataSourceInfoManager::getInstance().remove((*it)->getId());
131  }
132 }
133 
SQLiteConnector(QWidget *parent=0, Qt::WindowFlags f=0)
void create(std::list< te::da::DataSourceInfoPtr > &datasources)
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
void remove(std::list< te::da::DataSourceInfoPtr > &datasources)
void connect(std::list< te::da::DataSourceInfoPtr > &datasources)
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
void update(std::list< te::da::DataSourceInfoPtr > &datasources)
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr