All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SQLiteCreatorDialog.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/connector/sqlite/SQLiteCreatorDialog.cpp
22 
23  \brief ....
24 */
25 
26 // TerraLib
27 #include "../../../../common/Translator.h"
28 #include "../../../../dataaccess/datasource/DataSource.h"
29 #include "../../../../dataaccess/datasource/DataSourceFactory.h"
30 #include "../../../../dataaccess/datasource/DataSourceInfo.h"
31 #include "../../../../dataaccess/datasource/DataSourceManager.h"
32 #include "../../../widgets/Exception.h"
33 #include "ui_SQLiteCreatorDialogForm.h"
34 #include "SQLiteCreatorDialog.h"
35 
36 // Boost
37 #include <boost/algorithm/string/case_conv.hpp>
38 #include <boost/lexical_cast.hpp>
39 #include <boost/uuid/random_generator.hpp>
40 #include <boost/uuid/uuid_io.hpp>
41 
42 // Qt
43 #include <QtGui/QFileDialog>
44 #include <QtGui/QMessageBox>
45 
47  : QDialog(parent, f),
48  m_ui(new Ui::SQLiteCreatorDialogForm)
49 {
50  m_ui->setupUi(this);
51 
52  connect(m_ui->m_applyPushButton, SIGNAL(pressed()), this, SLOT(applyPushButtonPressed()));
53  connect(m_ui->m_helpPushButton, SIGNAL(pressed()), this, SLOT(helpPushButtonPressed()));
54  connect(m_ui->m_searchDatabaseToolButton, SIGNAL(pressed()), this, SLOT(searchDatabaseToolButtonPressed()));
55 }
56 
58 {
59 }
60 
62 {
63  return m_datasource;
64 }
65 
67 {
68  return m_driver;
69 }
70 
72 {
73  try
74  {
75  if(te::da::DataSourceFactory::find("SQLITE") == 0)
76  throw te::qt::widgets::Exception(TR_QT_WIDGETS("Sorry! No data access driver loaded for SQLite data sources!"));
77 
78  std::map<std::string, std::string> dsInfo;
79 
80  getConnectionInfo(dsInfo);
81 
82  te::da::DataSource::create("SQLITE", dsInfo);
83 
84  }
85  catch(const std::exception& e)
86  {
87  QMessageBox::warning(this,
88  tr("TerraLib Qt Components"),
89  tr(e.what()));
90  return;
91  }
92  catch(...)
93  {
94  QMessageBox::warning(this,
95  tr("TerraLib Qt Components"),
96  tr("Unknown error while opening SQLite database!"));
97  return;
98  }
99 
100  accept();
101 }
102 
104 {
105  QMessageBox::warning(this,
106  tr("TerraLib Qt Components"),
107  tr("Not implemented yet!\nWe will provide it soon!"));
108 }
109 
111 {
112  QString fileName = QFileDialog::getSaveFileName(this, tr("Save SQLite Database"), QString(""), tr("Database files (*.sqlite *.db);; All Files (*.*)"), 0, QFileDialog::ReadOnly);
113 
114  if(fileName.isEmpty())
115  return;
116 
117  m_ui->m_fileLineEdit->setText(fileName);
118 }
119 
120 void te::qt::plugins::sqlite::SQLiteCreatorDialog::getConnectionInfo(std::map<std::string, std::string>& connInfo) const
121 {
122 // clear input
123  connInfo.clear();
124 
125  QString qstr = m_ui->m_fileLineEdit->text().trimmed();
126 
127  if(qstr.isEmpty())
128  connInfo["SQLITE_FILE"] = ":memory:";
129  else
130  connInfo["SQLITE_FILE"] = qstr.toStdString();
131 
132  connInfo["SQLITE_CREATE_INTERMEDIATE_DIR"] = m_ui->m_allowIntermediateDirCheckBox->isChecked() ? "TRUE" : "FALSE";
133 
134  connInfo["SQLITE_CREATE_SPATIALITE_METADATA_TABLES"] = "TRUE";
135 
136  connInfo["SQLITE_HIDE_SPATIAL_METADATA_TABLES"] = "TRUE";
137 }
static bool find(const std::string &dsType)
const te::da::DataSourcePtr & getDriver() const
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
static std::auto_ptr< DataSource > create(const std::string &dsType, const std::map< std::string, std::string > &dsInfo)
It creates a new repository for a data source.
Definition: DataSource.cpp:510
SQLiteCreatorDialog(QWidget *parent=0, Qt::WindowFlags f=0)
const te::da::DataSourceInfoPtr & getDataSource() const
void getConnectionInfo(std::map< std::string, std::string > &connInfo) const
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
std::auto_ptr< Ui::SQLiteCreatorDialogForm > m_ui