All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TL4ConnectorWizardPage.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/terralib4/TL4ConnectorWizardPage.cpp
22 
23  \brief A wizard page that provides the capability of connecting to a TerraLib 4.x database.
24 */
25 
26 // TerraLib
27 #include "ui_TL4ConnectorWizardPageForm.h"
28 #include "TL4ConnectorWizardPage.h"
29 
30 // Qt
31 #include <QFileDialog>
32 
33 // Boost
34 #include <boost/filesystem.hpp>
35 
37  : QWizardPage(parent),
38  m_ui(new Ui::TL4ConnectorWizardPageForm)
39 {
40 // setup controls
41  m_ui->setupUi(this);
42 
43 #if TE_PLATFORM == TE_PLATFORMCODE_MSWINDOWS
44  m_ui->m_databaseTypeComboBox->addItem("Access");
45 
46  //m_ui->m_databaseTypeComboBox->addItem("SQL Server");
47 
48  //m_ui->m_databaseTypeComboBox->addItem("SQL Server Spatial");
49 #endif
50 
51  /*
52  m_ui->m_databaseTypeComboBox->addItem("Oracle");
53  m_ui->m_databaseTypeComboBox->addItem("Oracle OCI");
54  m_ui->m_databaseTypeComboBox->addItem("Oracle Spatial");
55  m_ui->m_databaseTypeComboBox->addItem("MySQL");
56  m_ui->m_databaseTypeComboBox->addItem("PostgreSQL");
57  m_ui->m_databaseTypeComboBox->addItem("PostGIS");
58  m_ui->m_databaseTypeComboBox->addItem("Firebird");*/
59 
60  connect(m_ui->m_databaseTypeComboBox,
61  SIGNAL(currentIndexChanged(const QString&)),
62  SLOT(onDatabaseTypeComboBoxActivated(const QString&)));
63 
64  connect(m_ui->m_directoryPushButton,
65  SIGNAL(clicked()),
67 
68  if(m_ui->m_databaseTypeComboBox->count() > 0)
69  {
70  m_ui->m_databaseTypeComboBox->setCurrentIndex(0);
71  onDatabaseTypeComboBoxActivated(m_ui->m_databaseTypeComboBox->currentText());
72  }
73 }
74 
76 {
77 }
78 
80 {
81  m_ui->m_dbComboBox->clear();
82 
83  QString fileName = QFileDialog::getOpenFileName(this, tr("Open Database"), QString(""), tr("Database files (*.accdb *.mdb);; All Files (*.*)"), 0, QFileDialog::ReadOnly);
84 
85  if(fileName.isEmpty())
86  return;
87 
88  m_ui->m_dbComboBox->addItem(fileName);
89 
90  boost::filesystem::path p(fileName.toStdString());
91 
92  p = p.filename();
93 
94  m_ui->m_databaseNameLineEdit->setText(p.string().c_str());
95 }
96 
98 {
99  if(text == QString("Access"))
100  {
101  m_ui->m_hostTextLabel->setText(tr("Host:"));
102  m_ui->m_hostLineEdit->setEnabled(false);
103  m_ui->m_portLineEdit->setEnabled(false);
104  m_ui->m_userLineEdit->setEnabled(false);
105  m_ui->m_passwordLineEdit->setEnabled(false);
106  m_ui->m_directoryPushButton->setEnabled(true);
107  m_ui->m_dbComboBox->setEnabled(false);
108  m_ui->m_databaseNameLineEdit->setEnabled(false);
109  m_ui->m_encodingComboBox->setEnabled(false);
110 
111  return;
112  }
113 
114  if(text == QString("SQL Server") ||
115  text == QString("SQL Server Spatial"))
116  {
117  m_ui->m_hostTextLabel->setText(tr("Host:"));
118  m_ui->m_hostLineEdit->setEnabled(true);
119  m_ui->m_portLineEdit->setEnabled(true);
120  m_ui->m_userLineEdit->setEnabled(true);
121  m_ui->m_passwordLineEdit->setEnabled(true);
122  m_ui->m_directoryPushButton->setEnabled(false);
123  m_ui->m_dbComboBox->setEnabled(false);
124  m_ui->m_databaseNameLineEdit->setEnabled(true);
125  m_ui->m_encodingComboBox->setEnabled(true);
126 
127  return;
128  }
129 
130  // // Oracle, Oracle OCI, Oracle Spatial
131  // case 3:
132  // case 4:
133  // case 5:
134  // {
135  // m_ui->m_hostTextLabel->setText(tr("Service Name:"));
136  // m_ui->m_hostLineEdit->setEnabled(true);
137  // m_ui->m_portLineEdit->setEnabled(false);
138  // m_ui->m_userLineEdit->setEnabled(true);
139  // m_ui->m_passwordLineEdit->setEnabled(true);
140  // m_ui->m_directoryPushButton->setEnabled(false);
141  // m_ui->m_dbComboBox->setEnabled(false);
142  // m_ui->m_databaseNameLineEdit->setEnabled(false);
143  // m_ui->m_encodingComboBox->setEnabled(false);
144  // break;
145  // }
146 
147  // // MySQL, PostgreSQL, PostGIS
148  // case 6:
149  // case 7:
150  // case 8:
151  // {
152  // m_ui->m_hostTextLabel->setText(tr("Host:"));
153  // m_ui->m_hostLineEdit->setEnabled(true);
154  // m_ui->m_portLineEdit->setEnabled(true);
155  // m_ui->m_userLineEdit->setEnabled(true);
156  // m_ui->m_passwordLineEdit->setEnabled(true);
157  // m_ui->m_directoryPushButton->setEnabled(true);
158  // m_ui->m_dbComboBox->setEnabled(true);
159  // m_ui->m_databaseNameLineEdit->setEnabled(false);
160  // m_ui->m_encodingComboBox->setEnabled(false);
161  // break;
162  // }
163 
164  // // Firebird
165  // case 9:
166  // {
167  // m_ui->m_hostTextLabel->setText(tr("Host:"));
168  // m_ui->m_hostLineEdit->setEnabled(true);
169  // m_ui->m_portLineEdit->setEnabled(true);
170  // m_ui->m_userLineEdit->setEnabled(true);
171  // m_ui->m_passwordLineEdit->setEnabled(true);
172  // m_ui->m_directoryPushButton->setEnabled(true);
173  // m_ui->m_dbComboBox->setEnabled(false);
174  // m_ui->m_databaseNameLineEdit->setEnabled(false);
175  // m_ui->m_encodingComboBox->setEnabled(false);
176  // break;
177  // }
178 
179  // default:
180  // {
181  // break;
182  // }
183  //}
184 }
185 
187 {
188  std::map<std::string, std::string> connInfo;
189 
190  connInfo["T4_DRIVER"] = getDriverName(m_ui->m_databaseTypeComboBox->currentText().toStdString());
191  connInfo["T4_DB_NAME"] = m_ui->m_dbComboBox->currentText().toStdString();
192  connInfo["T4_HOST"] = m_ui->m_hostLineEdit->text().toStdString();
193  connInfo["T4_PORT"] = m_ui->m_portLineEdit->text().toStdString();
194  connInfo["T4_USER"] = m_ui->m_userLineEdit->text().toStdString();
195  connInfo["T4_PASSWORD"] = m_ui->m_passwordLineEdit->text().toStdString();
196 
197  return connInfo;
198 }
199 
200 std::string te::qt::plugins::terralib4::TL4ConnectorWizardPage::getDriverName(const std::string& displayName)
201 {
202  if("Access")
203  return "Ado";
204  else if("SQL Server")
205  return "";
206  else if("SQL Server Spatial")
207  return "";
208  else if("Oracle")
209  return "";
210  else if("Oracle OCI")
211  return "";
212  else if("Oracle Spatial")
213  return "";
214  else if("MySQL")
215  return "MySQL";
216  else if("PostgreSQL")
217  return "PostgreSQL";
218  else if("PostGIS")
219  return "PostGIS";
220  else if("Firebird")
221  return "Firebird";
222  else
223  return "";
224 }
std::map< std::string, std::string > getConnInfo()
std::string getDriverName(const std::string &displayName)
std::auto_ptr< Ui::TL4ConnectorWizardPageForm > m_ui