All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MySQLCreatorDialog.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/datasource/mysql/MySQLCreatorDialog.cpp
22 
23  \brief A dialog window for showing the MySQL creator widget.
24 */
25 
26 // TerraLib
27 #include "MySQLCreatorDialog.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_MySQLCreatorDialogForm.h"
34 
35 // Qt
36 #include <QtGui/QMessageBox>
37 
39  : QDialog(parent, f),
40  m_ui(new Ui::MySQLCreatorDialogForm)
41 {
42  // add controls
43  m_ui->setupUi(this);
44 
45 // init controls
46  m_ui->m_advancedOptionsGroupBox->hide();
47 
48 // connect signal and slots
49  connect(m_ui->m_advancedOptionsCheckBox, SIGNAL(toggled(bool)), this, SLOT(advancedCreationOptionsCheckBoxToggled(bool)));
50  connect(m_ui->m_applyPushButton, SIGNAL(pressed()), this, SLOT(applyPushButtonPressed()));
51  connect(m_ui->m_closePushButton, SIGNAL(pressed()), this, SLOT(closePushButtonPressed()));
52  connect(m_ui->m_helpPushButton, SIGNAL(pressed()), this, SLOT(helpPushButtonPressed()));
53  connect(m_ui->m_userNameLineEdit, SIGNAL(editingFinished()), this, SLOT(passwordLineEditEditingFinished()));
54  connect(m_ui->m_passwordLineEdit, SIGNAL(editingFinished()), this, SLOT(passwordLineEditEditingFinished()));
55 }
56 
58 {
59 
60 }
61 
63 {
64  try
65  {
66 // check if driver is loaded
67  if(te::da::DataSourceFactory::find("MYSQL") == 0)
68  throw te::qt::widgets::Exception(TR_QT_WIDGETS("Sorry! No data access driver loaded for MySQL data sources!"));
69 
70 // get data source connection info based on form data
71  std::map<std::string, std::string> dsInfo;
72 
73  getConnectionInfo(dsInfo);
74 
75 // create database
76  te::da::DataSource::create("MYSQL", dsInfo);
77 
78  }
79  catch(const std::exception& e)
80  {
81  QMessageBox::warning(this,
82  tr("TerraLib Qt Components"),
83  tr(e.what()));
84  return;
85  }
86  catch(...)
87  {
88  QMessageBox::warning(this,
89  tr("TerraLib Qt Components"),
90  tr("Unknown error while opening MySQL database!"));
91  return;
92  }
93 
94  accept();
95 }
96 
98 {
99  reject();
100 }
101 
103 {
104 
105 }
106 
108 {
109  m_ui->m_advancedOptionsGroupBox->setVisible(t);
110 }
111 
112 void te::qt::plugins::mysql::MySQLCreatorDialog::getConnectionInfo(std::map<std::string, std::string>& connInfo) const
113 {
114 // clear input
115  connInfo.clear();
116 
117 // get host
118  QString qstr = m_ui->m_hostNameLineEdit->text().trimmed();
119 
120  if(!qstr.isEmpty())
121  connInfo["MY_HOST_NAME"] = qstr.toStdString();
122 
123 // get port
124  qstr = m_ui->m_portLineEdit->text().trimmed();
125 
126  if(!qstr.isEmpty())
127  connInfo["MY_PORT"] = qstr.toStdString();
128 
129 // get user
130  qstr = m_ui->m_userNameLineEdit->text().trimmed();
131 
132  if(!qstr.isEmpty())
133  connInfo["MY_USER_NAME"] = qstr.toStdString();
134 
135 // get password
136  qstr = m_ui->m_passwordLineEdit->text().trimmed();
137 
138  if(!qstr.isEmpty())
139  connInfo["MY_PASSWORD"] = qstr.toStdString();
140 
141 // get dbname
142  qstr = m_ui->m_schemaNameComboBox->currentText().trimmed();
143  //qstr = m_ui->m_schemaNameLineEdit->text().trimmed();
144 
145  if(!qstr.isEmpty())
146  connInfo["MY_SCHEMA"] = qstr.toStdString();
147 
148 // get charset
149  qstr = m_ui->m_charsetComboBox->currentText().trimmed();
150 
151  if(!qstr.isEmpty())
152  connInfo["MY_OPT_CHARSET_NAME"] = qstr.toStdString();
153 
154 // get new host
155  qstr = m_ui->m_newHostNameLineEdit->text().trimmed();
156 
157  if(!qstr.isEmpty())
158  connInfo["MY_NEW_SCHEMA_HOST"] = qstr.toStdString();
159 
160 // get new port
161  qstr = m_ui->m_newPortLineEdit->text().trimmed();
162 
163  if(!qstr.isEmpty())
164  connInfo["MY_NEW_SCHEMA_PORT"] = qstr.toStdString();
165 
166 // get new user
167  qstr = m_ui->m_newUserNameLineEdit->text().trimmed();
168 
169  if(!qstr.isEmpty())
170  connInfo["MY_NEW_SCHEMA_USER_NAME"] = qstr.toStdString();
171 
172 // get new password
173  qstr = m_ui->m_newPasswordLineEdit->text().trimmed();
174 
175  if(!qstr.isEmpty())
176  connInfo["MY_NEW_SCHEMA_PASSWORD"] = qstr.toStdString();
177 
178 // get new dbname
179  qstr = m_ui->m_newSchemaNameLineEdit->text().trimmed();
180 
181  if(!qstr.isEmpty())
182  connInfo["MY_NEW_SCHEMA_NAME"] = qstr.toStdString();
183 
184 // get new charset
185  qstr = m_ui->m_newCharsetComboBox->currentText().trimmed();
186 
187  if(!qstr.isEmpty())
188  connInfo["MY_NEW_SCHEMA_CHARSET_NAME"] = qstr.toStdString();
189 
190 // get new collate
191  qstr = m_ui->m_newCollateComboBox->currentText().trimmed();
192 
193  if(!qstr.isEmpty())
194  connInfo["MY_NEW_SCHEMA_COLLATE_NAME"] = qstr.toStdString();
195 
196  if(m_ui->m_createRasterMetadataCheckBox->isChecked())
197  connInfo["MY_NEW_SCHEMA_CREATE_TERRALIB_RASTER_METADATA_TABLES"] = "TRUE";
198 
199  if(m_ui->m_createOGCMetadataCheckBox->isChecked())
200  connInfo["MY_NEW_SCHEMA_CREATE_OGC_METADATA_TABLES"] = "TRUE";
201 }
202 
204 {
205  return m_datasource;
206 }
207 
209 {
210  return m_driver;
211 }
212 
214 {
215  if(m_ui->m_userNameLineEdit->text() != "" && m_ui->m_passwordLineEdit->text() != "")
216  {
217  std::map<std::string, std::string> dsInfo;
218  getConnectionInfo(dsInfo);
219 
220  // Get DataSources
221  std::vector<std::string> dbNames = te::da::DataSource::getDataSources("MYSQL", dsInfo);
222  if(!dbNames.empty())
223  for(std::size_t i = 0; i < dbNames.size(); i++)
224  m_ui->m_schemaNameComboBox->addItem(dbNames[i].c_str());
225  }
226 }
static bool find(const std::string &dsType)
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
const te::da::DataSourceInfoPtr & getDataSource() const
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
const te::da::DataSourcePtr & getDriver() const
MySQLCreatorDialog(QWidget *parent=0, Qt::WindowFlags f=0)
void getConnectionInfo(std::map< std::string, std::string > &connInfo) const
std::auto_ptr< Ui::MySQLCreatorDialogForm > m_ui
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr