Go to the documentation of this file.00001 #include "tablebackup.h"
00002 #include "ui_tablebackup.h"
00003 #include <QFileDialog>
00004 #include <QMessageBox>
00005 TableBackup::TableBackup(QWidget *parent) :
00006 QDialog(parent),
00007 ui(new Ui::TableBackup)
00008 {
00009 ui->setupUi(this);
00010
00011 }
00012
00013 TableBackup::~TableBackup()
00014 {
00015 delete ui;
00016 }
00017
00018 void TableBackup::on_cmdCancel_clicked()
00019 {
00020 this->reject();
00021 }
00022
00023 void TableBackup::refresh() {
00024 ui->txtFileName->setText(tr("%1\\%2.%3.sql").arg(qApp->applicationDirPath(), dbName, tableName));
00025 }
00026
00027 void TableBackup::saveFile(QString query) {
00028 if (ui->txtFileName->text() != "") {
00029 QFile file(ui->txtFileName->text());
00030 if (!file.open(QFile::WriteOnly | QFile::Text)) {
00031 QMessageBox::warning(this, tr("Error"),
00032 tr("Cannot write file %1:\n%2.")
00033 .arg(file.fileName())
00034 .arg(file.errorString()));
00035 return;
00036 }
00037 QTextStream out(&file);
00038 QApplication::setOverrideCursor(Qt::WaitCursor);
00039 out << query;
00040 QApplication::restoreOverrideCursor();
00041 QMessageBox::information(this, "Success", tr("The backup for objects in %1 has been completed.").arg(dbName));
00042 this->accept();
00043 } else {
00044 QMessageBox::critical(this, "Error", "You did not specify a file to save into. Backup failed");
00045 }
00046 }
00047
00048 void TableBackup::on_cmdBackup_clicked()
00049 {
00050 if (ui->txtFileName->text() != "") {
00051 QStringList tableList;
00052 QStringList viewList;
00053 QStringList procList;
00054 tableList << tableName;
00055
00056 dumpThread = new SqlDumpThread(0);
00057 connect (dumpThread, SIGNAL(generatedQuery(QString)), this, SLOT(saveFile(QString)));
00058 dumpThread->db = db;
00059 dumpThread->dbName = dbName;
00060 dumpThread->tableList = tableList;
00061 dumpThread->viewList = viewList;
00062 dumpThread->procedureList = procList;
00063 dumpThread->drop = true;
00064 dumpThread->data = ui->chkData->isChecked();
00065 dumpThread->structure = true;
00066 dumpThread->createDb = false;
00067 dumpThread->useDb = true;
00068 dumpThread->start();
00069
00070 } else {
00071 QMessageBox::warning(this, "Error", "Please enter a file to use.");
00072 }
00073
00074 }
00075
00076 void TableBackup::on_cmdSelectFile_clicked()
00077 {
00078 QString fileName = QFileDialog::getSaveFileName(this, "Enter the SQL file to dump to.", QString(),"SQL Files (*.sql)");
00079 if (fileName != "") {
00080 ui->txtFileName->setText(fileName);
00081 }
00082 }