All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DSCopyDialog.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/tools/dscopy/qt/DSCopyDialog.cpp
22 
23  \brief An utility class to provide methods to copy a Data Source
24  */
25 
26 // DSCopy
27 #include "DSCopyDialog.h"
28 #include "DSCopyDialogController.h"
29 
30 // Qt
31 #include <QtGui/QtGui>
32 #include <QtGui/QComboBox>
33 #include <QtGui/QMessageBox>
34 #include <QtGui/QFileDialog>
35 #include <QtGui/QListView>
36 
37 // STL
38 #include <string>
39 
40 te::tools::dscopy::DSCopyDialog::DSCopyDialog(QWidget * parent, Qt::WindowFlags f)
41  : QDialog(parent, f)
42 {
43  setupUi(this);
44 
46 
47  backPushButton->setEnabled(false);
48 
49  inComboBox->addItem("");
50  outComboBox->addItem("");
51 
52  mainStackedWidget->setCurrentIndex(0);
53 
54  connStackedWidget->setCurrentIndex(0);
55  connOutStackedWidget->setCurrentIndex(0);
56 
57  std::vector<std::string> dictionary = m_controller->getDictionary();
58 
59  for(size_t i = 0; i < dictionary.size(); i++)
60  {
61  inComboBox->addItem(dictionary[i].c_str());
62  outComboBox->addItem(dictionary[i].c_str());
63  }
64 
65  connect(helpPushButton, SIGNAL(clicked()), this, SLOT(helpPushButton_clicked()));
66  connect(backPushButton, SIGNAL(clicked()), this, SLOT(backPushButton_clicked()));
67  connect(nextPushButton, SIGNAL(clicked()), this, SLOT(nextPushButton_clicked()));
68  connect(cancelPushButton, SIGNAL(clicked()), this, SLOT(cancelPushButton_clicked()));
69 
70  connect(inComboBox, SIGNAL(activated(const QString&)), this, SLOT(inComboBox_activated(const QString&)));
71  connect(outComboBox, SIGNAL(activated(const QString&)), this, SLOT(outComboBox_activated(const QString&)));
72 
73  connect(inPathPushButton, SIGNAL(clicked()), this, SLOT(inPathPushButton_clicked()));
74  connect(outPathPushButton, SIGNAL(clicked()), this, SLOT(outPathPushButton_clicked()));
75 }
76 
78 {
79 }
80 
82 {
83 
84 }
85 
87 {
88  if(mainStackedWidget->currentIndex() == 2)
89  {
90  nextPushButton->setText(tr("&Next"));
91  mainStackedWidget->setCurrentIndex(1);
92  }
93  else if(mainStackedWidget->currentIndex() == 1)
94  {
95  backPushButton->setEnabled(false);
96  mainStackedWidget->setCurrentIndex(0);
97  }
98 }
99 
101 {
102  std::string errorMessage = std::string();
103 
104  // Input Data Source Connection Informations
105  if(mainStackedWidget->currentIndex() == 0)
106  {
107  dsListWidget->clear();
108 
109  if(inComboBox->currentText() == "")
110  return;
111 
112  if(connStackedWidget->currentIndex() == 1)
113  {
114  if(!inPathLineEdit->text().isEmpty())
115  {
116  if(!m_controller->setOriginConnectionInfo(inComboBox->currentText().toStdString(), inPathLineEdit->text().toStdString(), errorMessage))
117  {
118  QMessageBox::warning(this, tr("Warning"), errorMessage.c_str());
119  return;
120  }
121  }
122  else
123  {
124  QMessageBox::warning(this, tr("Warning"), tr("Select a path!"));
125  return;
126  }
127  }
128  else if(connStackedWidget->currentIndex() == 2)
129  {
130  if(hostLineEdit->text().isEmpty() || portLineEdit->text().isEmpty()
131  || dsNameLineEdit->text().isEmpty() || userLineEdit->text().isEmpty() || pwLineEdit->text().isEmpty())
132  {
133  QString warning = tr("Some required information is missing:");
134  if(hostLineEdit->text().isEmpty())
135  warning += tr("\n - Host");
136  if(portLineEdit->text().isEmpty())
137  warning += tr("\n - Port");
138  if(dsNameLineEdit->text().isEmpty())
139  warning += tr("\n - Data Source Name");
140  if(userLineEdit->text().isEmpty())
141  warning += tr("\n - User");
142  if(pwLineEdit->text().isEmpty())
143  warning += tr("\n - Password");
144 
145  QMessageBox::warning(this, tr("Warning"), warning);
146  return;
147  }
148  else
149  {
150 
151  if(!m_controller->setOriginConnectionInfo(inComboBox->currentText().toStdString(),
152  hostLineEdit->text().toStdString(),
153  portLineEdit->text().toStdString(),
154  dsNameLineEdit->text().toStdString(),
155  userLineEdit->text().toStdString(),
156  pwLineEdit->text().toStdString(), errorMessage))
157  {
158  QMessageBox::warning(this, tr("Warning"), errorMessage.c_str());
159  return;
160  }
161 
162  }
163  }
164 
165 
166  std::vector<std::string*> dataSetsNames = m_controller->getDatasetsName();
167 
168 
169  for(size_t i = 0; i < dataSetsNames.size(); i++)
170  {
171  dsListWidget->addItem(new QListWidgetItem((*dataSetsNames[i]).c_str()));
172  }
173 
174  mainStackedWidget->setCurrentIndex(1);
175 
176  }
177 
178  // DataSets informations
179  else if(mainStackedWidget->currentIndex() == 1)
180  {
181  if(dsListWidget->selectedItems().empty())
182  {
183  QMessageBox::warning(this, tr("Warnign"), tr("Select at least one Data Set"));
184  return;
185  }
186 
187  std::vector<std::string> datasetsToCopy;
188  for(size_t i = 0; i < dsListWidget->selectedItems().count(); i++)
189  {
190  datasetsToCopy.push_back(dsListWidget->selectedItems().at(i)->text().toStdString());
191  }
192 
193  m_controller->setDatasetsToCopy(datasetsToCopy);
194 
195  mainStackedWidget->setCurrentIndex(2);
196 
197  nextPushButton->setText(tr("Copy"));
198  }
199 
200  // Make the copy
201  else if(mainStackedWidget->currentIndex() == 2)
202  {
203  if(outComboBox->currentText() == "")
204  return;
205 
206  std::string errorMessage = std::string();
207 
208  if(connOutStackedWidget->currentIndex() == 1)
209  {
210  if(!outPathLineEdit->text().isEmpty())
211  {
212  if(!m_controller->setDestinationConnectionInfo(outComboBox->currentText().toStdString(), outPathLineEdit->text().toStdString(), errorMessage))
213  {
214  QMessageBox::warning(this, tr("Warning"), errorMessage.c_str());
215  return;
216  }
217  }
218  else
219  {
220  QMessageBox::warning(this, tr("Warning"), tr("Select a path!"));
221  return;
222  }
223  }
224  else if(connOutStackedWidget->currentIndex() == 2)
225  {
226  if(outHostLineEdit->text().isEmpty() || outPortLineEdit->text().isEmpty()
227  || outDsNameLineEdit->text().isEmpty() || outUserLineEdit->text().isEmpty() || outPwLineEdit->text().isEmpty())
228  {
229  QString warning = tr("Some required information is missing:");
230  if(outHostLineEdit->text().isEmpty())
231  warning += tr("\n - Host");
232  if(outPortLineEdit->text().isEmpty())
233  warning += tr("\n - Port");
234  if(outDsNameLineEdit->text().isEmpty())
235  warning += tr("\n - Data Source Name");
236  if(outUserLineEdit->text().isEmpty())
237  warning += tr("\n - User");
238  if(outPwLineEdit->text().isEmpty())
239  warning += tr("\n - Password");
240 
241  QMessageBox::warning(this, tr("Warning"), warning);
242  return;
243  }
244  else
245  {
246 
247  if(!m_controller->setDestinationConnectionInfo(outComboBox->currentText().toStdString(),
248  outHostLineEdit->text().toStdString(),
249  outPortLineEdit->text().toStdString(),
250  outDsNameLineEdit->text().toStdString(),
251  outUserLineEdit->text().toStdString(),
252  outPwLineEdit->text().toStdString(), errorMessage))
253  {
254  QMessageBox::warning(this, tr("Warning"), errorMessage.c_str());
255  return;
256  }
257 
258  }
259  }
260 
261  if(!m_controller->copy(errorMessage))
262  {
263  QMessageBox::warning(this, tr("ERROR"), errorMessage.c_str());
264  return;
265  }
266  else
267  QMessageBox::information(this, tr("Success"), tr("Copy executed successfully!"));
268 
269  }
270 
271  backPushButton->setEnabled(true);
272 
273 }
274 
276 {
277  close();
278 }
279 
281 {
282  if(type == "OGR" || type == "GDAL")
283  connStackedWidget->setCurrentIndex(1);
284  else if(type == "POSTGIS")
285  connStackedWidget->setCurrentIndex(2);
286  else
287  connStackedWidget->setCurrentIndex(0);
288 }
289 
291 {
292  if(type == "OGR" || type == "GDAL")
293  connOutStackedWidget->setCurrentIndex(1);
294  else if(type == "POSTGIS")
295  connOutStackedWidget->setCurrentIndex(2);
296  else
297  connOutStackedWidget->setCurrentIndex(0);
298 }
299 
301 {
302  std::string path;
303 
304  QFileDialog fd(this);
305  fd.setFileMode(QFileDialog::DirectoryOnly);
306 
307  path = QFileDialog::getExistingDirectory(this, tr("Open Directory"), "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks).toStdString();
308 
309  if(!path.empty())
310  if(connStackedWidget->currentIndex() == 1)
311  inPathLineEdit->setText(path.c_str());
312 
313 }
314 
316 {
317  std::string path;
318 
319  QFileDialog fd(this);
320  fd.setFileMode(QFileDialog::DirectoryOnly);
321 
322  path = QFileDialog::getExistingDirectory(this, tr("Open Directory"), "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks).toStdString();
323 
324  if(!path.empty())
325  if(connOutStackedWidget->currentIndex() == 1)
326  outPathLineEdit->setText(path.c_str());
327 }
328 
330 {
331  delete m_controller;
332 }
Data Source Copy GUI.
void outComboBox_activated(const QString &)
DSCopyDialog(QWidget *parent=0, Qt::WindowFlags f=0)
void closeEvent(QCloseEvent *e)
DSCopyDialogController * m_controller
Definition: DSCopyDialog.h:76
void inComboBox_activated(const QString &)
Data Source Copy GUI Controller.