00001 #include "mainpage.h"
00002 #include "ui_mainpage.h"
00003 #include <QTimer>
00004 #include <QtGui>
00005 #include "newconnection.h"
00006 #include "createdatabase.h"
00007 #include "about.h"
00008 MainPage::MainPage(QWidget *parent) :
00009 QMainWindow(parent),
00010 ui(new Ui::MainPage)
00011 {
00012 ui->setupUi(this);
00013
00014 windowMapper = new QSignalMapper(this);
00015 m_CboCurrentDb = new QComboBox(this);
00016 m_QueryEditorActions = new QActionGroup(this);
00017 connectionCounter = new QLabel(this);
00018 currentTime = new QLabel(this);
00019 tableToolBar = new QToolBar("Table Toolbar", this);
00020 m_cboThemes = new QComboBox(this);
00021
00022 ui->toolBar->setWindowTitle("Standard Toolbar");
00023
00024
00025 m_cboThemes->insertItem(0, "Cleanlooks");
00026 m_cboThemes->insertItem(1, "Plastique");
00027 m_cboThemes->insertItem(2, "WindowsVista");
00028 m_cboThemes->insertItem(3, "Windows");
00029 m_cboThemes->insertItem(4, "WindowsXP");
00030 m_cboThemes->insertItem(5, "Motif");
00031 m_cboThemes->insertItem(6, "CDE");
00032
00033 connectionCounter->setContextMenuPolicy(Qt::CustomContextMenu);
00034 currentTime->setText(tr("Connected Since: %1").arg(QTime::currentTime().toString("HH:mm:ss")));
00035
00036 windowStyle = new QActionGroup(this);
00037 mdi = new QAction(this);
00038 mdi->setText("Multiple windows view");
00039 mdi->setCheckable(true);
00040 mdi->setChecked(true);
00041 tabbed = new QAction(this);
00042 tabbed->setText("Tabbed windows view");
00043 tabbed->setCheckable(true);
00044 tabbed->setChecked(false);
00045 windowStyle->addAction(mdi);
00046 windowStyle->addAction(tabbed);
00047
00048 ui->actionUndo->setEnabled(false);
00049 ui->actionCut->setEnabled(false);
00050 ui->actionCopy->setEnabled(false);
00051 ui->actionRedo->setEnabled(false);
00052
00053 flags = 0;
00054 flags = Qt::Popup;
00055 flags |= Qt::MSWindowsFixedSizeDialogHint;
00056
00057 connect (ui->actionExit, SIGNAL(triggered()), qApp, SLOT(quit()));
00058 connect (ui->actionConnect_To_Server, SIGNAL(triggered()), this, SLOT(connectToServer()));
00059 connect (ui->mdiArea, SIGNAL(subWindowActivated(QMdiSubWindow*)), this, SLOT(refreshMenus()));
00060 connect (ui->actionClose_Connection, SIGNAL(triggered()), this, SLOT(closeConnection()));
00061 connect (ui->actionCascade, SIGNAL(triggered()), this, SLOT(cascade()));
00062 connect (ui->actionTile_Windows, SIGNAL(triggered()), this, SLOT(tileWindows()));
00063 connect (ui->menuWindows, SIGNAL(aboutToShow()), this, SLOT(showWindowMenu()));
00064 connect (windowMapper, SIGNAL(mapped(QWidget*)),this, SLOT(setActiveSubWindow(QWidget*)));
00065 connect (ui->actionCreate_Database, SIGNAL(triggered()), this, SLOT(newDatabase()));
00066 connect (ui->actionOpen, SIGNAL(triggered()), this, SLOT(openSqlFile()));
00067 connect (ui->actionSave, SIGNAL(triggered()), this, SLOT(saveSqlFile()));
00068 connect (ui->actionAbout, SIGNAL(triggered()), this, SLOT(showAbout()));
00069 connect (ui->actionCreate_Table, SIGNAL(triggered()), this, SLOT(newTable()));
00070 connect (ui->actionAlter_Table, SIGNAL(triggered()), this, SLOT(editTable()));
00071 connect (ui->actionRename_Table, SIGNAL(triggered()), this, SLOT(renameTable()));
00072 connect (m_cboThemes, SIGNAL(currentIndexChanged(QString)), this, SLOT(setTheme(QString)));
00073 connect (ui->actionTruncate_Table, SIGNAL(triggered()), this, SLOT(truncateTable()));
00074 connect (ui->actionAbout_Qt, SIGNAL(triggered()), this, SLOT(aboutQt()));
00075 connect (ui->actionDrop_Table, SIGNAL(triggered()), this, SLOT(dropTable()));
00076 connect (ui->actionBackup_Database_As_SQL_Dump, SIGNAL(triggered()), this, SLOT(dumpDbAsSQL()));
00077 connect (ui->actionBackup_Table_As_SQL_Dump, SIGNAL(triggered()), this, SLOT(dumpTableAsSQL()));
00078 connect (ui->actionExport_Table_as_CSV, SIGNAL(triggered()), this, SLOT(exportTable()));
00079 connect (ui->actionExport_View, SIGNAL(triggered()), this, SLOT(exportTable()));
00080 connect (ui->actionManage_Indexes, SIGNAL(triggered()), this, SLOT(manageIndexes()));
00081 connect (ui->actionCreate_View, SIGNAL(triggered()), this, SLOT(subCreateView()));
00082 connect (ui->actionAlter_View, SIGNAL(triggered()), this, SLOT(alterView()));
00083 connect (mdi, SIGNAL(triggered()), this, SLOT(setWindowMode()));
00084 connect (tabbed, SIGNAL(triggered()), this, SLOT(setWindowMode()));
00085 connect (ui->actionDrop_View, SIGNAL(triggered()), this, SLOT(dropView()));
00086
00087
00088 m_cboThemes->setVisible(true);
00089
00090 setUpToolBar();
00091 setUpStatusBar();
00092 this->showMaximized();
00093 connectToServer();
00094 refreshMenus();
00095 }
00096
00097 MainPage::~MainPage()
00098 {
00099 delete ui;
00100 }
00101
00102 void MainPage::connectToServer() {
00103 NewConnection conn(this);
00104 if (conn.exec())
00105 {
00106 ServerEditor *ed = new ServerEditor();
00107 ui->mdiArea->addSubWindow(ed);
00108 ed->db = conn.db;
00109 ed->db.open();
00110 ed->setWindowTitle(tr("Connected [%1@%2]").arg(ed->db.userName(), ed->db.hostName()));
00111 ed->refreshDbList();
00112 ed->reloadServerInformation();
00113 ui->actionUndo->setEnabled(false);
00114 ui->actionCut->setEnabled(false);
00115 ui->actionCopy->setEnabled(false);
00116 ui->actionRedo->setEnabled(false);
00117
00118 ed->show();
00119 }
00120 }
00121
00122 ServerEditor *MainPage::activeServerEditor() {
00123 if (ui->mdiArea->activeSubWindow() != 0) {
00124 QMdiSubWindow *activeSubWindow = ui->mdiArea->activeSubWindow();
00125 if (qobject_cast<ServerEditor *>(activeSubWindow->widget())) {
00126 return qobject_cast<ServerEditor *>(activeSubWindow->widget());
00127 }
00128 return 0;
00129 }
00130 return 0;
00131 }
00132
00133 SQLDump *MainPage::activeSqlDump() {
00134 if (QMdiSubWindow *activeSubWindow = ui->mdiArea->activeSubWindow()) {
00135 if (qobject_cast<SQLDump *>(activeSubWindow->widget()))
00136 return qobject_cast<SQLDump *>(activeSubWindow->widget());
00137 }
00138 return 0;
00139 }
00140
00141
00142 tableEditor *MainPage::activeTableEditor() {
00143 if (QMdiSubWindow *activeSubWindow = ui->mdiArea->activeSubWindow()) {
00144 if (qobject_cast<tableEditor *>(activeSubWindow->widget()))
00145 return qobject_cast<tableEditor *>(activeSubWindow->widget());
00146 }
00147 return 0;
00148 }
00149
00150 void MainPage::refreshMenus() {
00151 ui->actionClose_Connection->setEnabled(hasMdiChild());
00152 ui->menuDb->setEnabled(hasMdiChild());
00153 ui->menuTable->setEnabled(hasMdiChild());
00154 ui->menuObjects->setEnabled(hasMdiChild());
00155 ui->menuWindows->setEnabled(hasMdiChild());
00156 if (hasMdiChild() == false) {
00157 ui->menuWindows->setEnabled(hasTableEditor());
00158 }
00159 if (hasMdiChild() == false && hasTableEditor() == false) {
00160 ui->menuWindows->setEnabled(hasSQLDump());
00161 }
00162 ui->actionPaste->setEnabled(hasMdiChild());
00163 ui->actionOpen->setEnabled(hasMdiChild());
00164 ui->actionSave->setEnabled(hasMdiChild());
00165 ui->actionSave_As->setEnabled(hasMdiChild());
00166 ui->menuRecent_SQL_Files->setEnabled(hasMdiChild());
00167 ui->actionAlter_Table->setEnabled(hasMdiChild());
00168 ui->actionExecute_Current_Query->setEnabled(hasMdiChild());
00169 ui->actionExecute_Selected_Query->setEnabled(hasMdiChild());
00170 ui->actionRefresh_Object_Explorer->setEnabled(hasMdiChild());
00171 ui->actionView_Data->setEnabled(hasMdiChild());
00172
00173 QList<QMdiSubWindow *> windows = ui->mdiArea->subWindowList();
00174 m_CboCurrentDb->disconnect();
00175 for (int i = 0; i < windows.size(); ++i) {
00176 if (qobject_cast<ServerEditor *>(windows.at(i)->widget())){
00177 ServerEditor *child = qobject_cast<ServerEditor *>(windows.at(i)->widget());
00178 child->disconnect();
00179 }
00180 }
00181
00182 bool tableSel = false;
00183 if (hasMdiChild()){
00184 if (activeServerEditor()->currentTable != "")
00185 tableSel = true;
00186 }
00187 ui->actionAlter_Table->setEnabled(tableSel);
00188 ui->actionManage_Indexes->setEnabled(tableSel);
00189 ui->actionRelationships_Foreign_Keys->setEnabled(tableSel);
00190 ui->actionInsert_Update_Table_Data->setEnabled(tableSel);
00191 ui->menuBackup_Export->setEnabled(tableSel);
00192 ui->actionRename_Table->setEnabled(tableSel);
00193 ui->actionTruncate_Table->setEnabled(tableSel);
00194 ui->actionDrop_Table->setEnabled(tableSel);
00195 ui->actionView_Data->setEnabled(tableSel);
00196 ui->actionView_Advanced_Properties->setEnabled(tableSel);
00197
00198
00199 bool viewSel = false;
00200 if (hasMdiChild()){
00201 if (activeServerEditor()->currentView != "")
00202 viewSel = true;
00203 }
00204 ui->actionExport_View->setEnabled(viewSel);
00205 ui->actionAlter_View->setEnabled(viewSel);
00206 ui->actionDrop_View->setEnabled(viewSel);
00207
00208 connectionCounter->setText(tr("Open Windows: %1").arg(ui->mdiArea->subWindowList().count()));
00209 if (hasMdiChild()) {
00210 showDbList(activeServerEditor()->dbList);
00211 setCurrentDb(activeServerEditor()->currentDb);
00212 ui->actionRefresh_Object_Explorer->disconnect();
00213 ui->actionExecute_Current_Query->disconnect();
00214 ui->actionUndo->disconnect();
00215 ui->actionRedo->disconnect();
00216 ui->actionCut->disconnect();
00217 ui->actionCopy->disconnect();
00218 ui->actionPaste->disconnect();
00219 ui->actionDrop_Database->disconnect();
00220 ui->actionTruncate_Database->disconnect();
00221 ui->actionEmpty_Database->disconnect();
00222 ui->actionRestore_From_SQL_Dump->disconnect();
00223 ui->actionSelect_All->disconnect();
00224 m_CboCurrentDb->setEnabled(hasMdiChild());
00225
00226 connect(activeServerEditor(), SIGNAL(dbListChanged(QStringList)), this, SLOT(showDbList(QStringList)));
00227 connect (activeServerEditor(), SIGNAL(currentDbChanged(QString)), this, SLOT(setCurrentDb(QString)));
00228 connect (m_CboCurrentDb, SIGNAL(currentIndexChanged(QString)), activeServerEditor(), SLOT(setCurrentDb(QString)));
00229 connect (activeServerEditor(), SIGNAL(callPopupMenu(QString)), this, SLOT(showPopupMenu(QString)));
00230 connect (activeServerEditor()->queryEditor, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
00231 connect (activeServerEditor()->queryEditor, SIGNAL(copyAvailable(bool)), ui->actionCopy, SLOT(setEnabled(bool)));
00232
00233
00234 connect (activeServerEditor()->queryEditor, SIGNAL(copyAvailable(bool)), ui->actionCut, SLOT(setEnabled(bool)));
00235 connect (activeServerEditor(), SIGNAL(tableSelected(bool)), ui->actionAlter_Table, SLOT(setEnabled(bool)));
00236 connect (activeServerEditor(), SIGNAL(tableSelected(bool)), ui->actionManage_Indexes, SLOT(setEnabled(bool)));
00237 connect (activeServerEditor(), SIGNAL(tableSelected(bool)), ui->actionRelationships_Foreign_Keys, SLOT(setEnabled(bool)));
00238 connect (activeServerEditor(), SIGNAL(tableSelected(bool)), ui->actionInsert_Update_Table_Data, SLOT(setEnabled(bool)));
00239 connect (activeServerEditor(), SIGNAL(tableSelected(bool)), ui->menuBackup_Export, SLOT(setEnabled(bool)));
00240 connect (activeServerEditor(), SIGNAL(tableSelected(bool)), ui->actionRename_Table, SLOT(setEnabled(bool)));
00241 connect (activeServerEditor(), SIGNAL(tableSelected(bool)), ui->actionTruncate_Table, SLOT(setEnabled(bool)));
00242 connect (activeServerEditor(), SIGNAL(tableSelected(bool)), ui->actionDrop_Table, SLOT(setEnabled(bool)));
00243 connect (activeServerEditor(), SIGNAL(tableSelected(bool)), ui->actionView_Data, SLOT(setEnabled(bool)));
00244 connect (activeServerEditor(), SIGNAL(tableSelected(bool)), ui->actionView_Advanced_Properties, SLOT(setEnabled(bool)));
00245 connect (activeServerEditor(), SIGNAL(viewSelected(bool)), ui->actionAlter_View, SLOT(setEnabled(bool)));
00246 connect (activeServerEditor(), SIGNAL(viewSelected(bool)), ui->actionDrop_View, SLOT(setEnabled(bool)));
00247
00248 connect (ui->actionUndo, SIGNAL(triggered()), activeServerEditor()->queryEditor, SLOT(undo()));
00249 connect (ui->actionRedo, SIGNAL(triggered()), activeServerEditor()->queryEditor, SLOT(redo()));
00250 connect (ui->actionSelect_All, SIGNAL(triggered()), activeServerEditor()->queryEditor, SLOT(selectAll()));
00251 connect (ui->actionClear, SIGNAL(triggered()), activeServerEditor()->queryEditor, SLOT(clear()));
00252 connect (ui->actionCut, SIGNAL(triggered()), activeServerEditor()->queryEditor, SLOT(cut()));
00253 connect (ui->actionCopy, SIGNAL(triggered()), activeServerEditor()->queryEditor, SLOT(copy()));
00254 connect (ui->actionPaste, SIGNAL(triggered()), activeServerEditor()->queryEditor, SLOT(paste()));
00255 connect (ui->actionExecute_Current_Query, SIGNAL(triggered()), activeServerEditor(), SLOT(executeTypedQuery()));
00256 connect (ui->actionRefresh_Object_Explorer, SIGNAL(triggered()), activeServerEditor(), SLOT(refreshDbList()));
00257 connect (ui->actionDrop_Database, SIGNAL(triggered()), activeServerEditor(), SLOT(dropDb()));
00258 connect (ui->actionTruncate_Database, SIGNAL(triggered()), activeServerEditor(), SLOT(truncateDb()));
00259 connect (ui->actionEmpty_Database, SIGNAL(triggered()), activeServerEditor(), SLOT(emptyDb()));
00260 connect (ui->actionRestore_From_SQL_Dump, SIGNAL(triggered()), activeServerEditor(), SLOT(runSQLFile()));
00261 } else {
00262 m_CboCurrentDb->clear();
00263 }
00264 }
00265
00266 void MainPage::closeConnection() {
00267 ui->mdiArea->currentSubWindow()->close();
00268 }
00269
00270 void MainPage::cascade() {
00271 ui->mdiArea->cascadeSubWindows();
00272 }
00273
00274 void MainPage::selectionChanged() {
00275 bool en;
00276 en = false;
00277 if (hasMdiChild()) {
00278 if (activeServerEditor()->queryEditor->text().length() > 0) {
00279 en = true;
00280 } else {
00281 en = false;
00282 }
00283 ui->actionExecute_Current_Query->setEnabled(en);
00284 ui->actionExecute_Selected_Query->setEnabled(en);
00285 ui->actionSelect_All->setEnabled(en);
00286 ui->actionClear->setEnabled(en);
00287 }
00288 }
00289
00290 void MainPage::tileWindows() {
00291 ui->mdiArea->tileSubWindows();
00292 }
00293
00294 void MainPage::showWindowMenu() {
00295 ui->menuWindows->clear();
00296 ui->menuWindows->addAction(ui->actionCascade);
00297 ui->menuWindows->addAction(ui->actionTile_Windows);
00298 ui->menuWindows->addSeparator();
00299 ui->menuWindows->addAction(mdi);
00300 ui->menuWindows->addAction(tabbed);
00301 ui->menuWindows->addSeparator();
00302 QList<QMdiSubWindow *> windows = ui->mdiArea->subWindowList();
00303
00304 for (int i = 0; i < windows.size(); ++i) {
00305 if (qobject_cast<ServerEditor *>(windows.at(i)->widget())) {
00306
00307 ServerEditor *child = qobject_cast<ServerEditor *>(windows.at(i)->widget());
00308 QString text;
00309 if (i < 9) {
00310 text = tr("&%1 %2").arg(i + 1)
00311 .arg(child->windowTitle());
00312 } else {
00313 text = tr("%1 %2").arg(i + 1)
00314 .arg(child->windowTitle());
00315 }
00316 QAction *action = ui->menuWindows->addAction(text);
00317 action->setCheckable(true);
00318 action ->setChecked(child == activeServerEditor());
00319 connect(action, SIGNAL(triggered()), windowMapper, SLOT(map()));
00320 windowMapper->setMapping(action, windows.at(i));
00321 }else if (qobject_cast<tableEditor *>(windows.at(i)->widget())) {
00322
00323 tableEditor *child = qobject_cast<tableEditor *>(windows.at(i)->widget());
00324 QString text;
00325 if (i < 9) {
00326 text = tr("&%1 %2").arg(i + 1)
00327 .arg(child->windowTitle());
00328 } else {
00329 text = tr("%1 %2").arg(i + 1)
00330 .arg(child->windowTitle());
00331 }
00332 QAction *action = ui->menuWindows->addAction(text);
00333 action->setCheckable(true);
00334 action ->setChecked(child == activeTableEditor());
00335 connect(action, SIGNAL(triggered()), windowMapper, SLOT(map()));
00336 windowMapper->setMapping(action, windows.at(i));
00337 }else if (qobject_cast<SQLDump *>(windows.at(i)->widget())) {
00338
00339 SQLDump *child = qobject_cast<SQLDump *>(windows.at(i)->widget());
00340 QString text;
00341 if (i < 9) {
00342 text = tr("&%1 %2").arg(i + 1)
00343 .arg(child->windowTitle());
00344 } else {
00345 text = tr("%1 %2").arg(i + 1)
00346 .arg(child->windowTitle());
00347 }
00348 QAction *action = ui->menuWindows->addAction(text);
00349 action->setCheckable(true);
00350 action ->setChecked(child == activeSqlDump());
00351 connect(action, SIGNAL(triggered()), windowMapper, SLOT(map()));
00352 windowMapper->setMapping(action, windows.at(i));
00353 }
00354 }
00355 }
00356
00357 void MainPage::setUpToolBar() {
00358 ui->toolBar->setIconSize(QSize(16, 16));
00359 ui->toolBar->addAction(ui->actionView_Data);
00360 ui->toolBar->addAction(ui->actionRefresh_Object_Explorer);
00361 ui->toolBar->addSeparator();
00362 ui->toolBar->addWidget(m_CboCurrentDb);
00363 m_CboCurrentDb->setSizeAdjustPolicy(QComboBox::AdjustToContents);
00364 ui->toolBar->addSeparator();
00365 ui->toolBar->addAction(ui->actionUndo);
00366 ui->toolBar->addAction(ui->actionRedo);
00367 ui->toolBar->addSeparator();
00368 ui->toolBar->addAction(ui->actionCut);
00369 ui->toolBar->addAction(ui->actionCopy);
00370 ui->toolBar->addAction(ui->actionPaste);
00371 ui->toolBar->addSeparator();
00372
00373 this->addToolBar(tableToolBar);
00374 tableToolBar->setIconSize(QSize(16, 16));
00375 tableToolBar->addAction(ui->actionCreate_Table);
00376 tableToolBar->addAction(ui->actionAlter_Table);
00377 tableToolBar->addAction(ui->actionRename_Table);
00378 tableToolBar->addAction(ui->actionTruncate_Table);
00379 tableToolBar->addAction(ui->actionDrop_Table);
00380 tableToolBar->addSeparator();
00381 tableToolBar->addAction(ui->actionManage_Indexes);
00382 tableToolBar->addSeparator();
00383 tableToolBar->addAction(ui->actionRelationships_Foreign_Keys);
00384 tableToolBar->addAction(ui->actionInsert_Update_Table_Data);
00385 }
00386
00387 void MainPage::setUpStatusBar() {
00388 ui->statusbar->addWidget(connectionCounter);
00389 ui->statusbar->addWidget(currentTime);
00390 ui->statusbar->addWidget(m_cboThemes);
00391 }
00392
00393 void MainPage::setActiveSubWindow(QWidget *window)
00394 {
00395 if (!window)
00396 return;
00397 if (qobject_cast<QMdiSubWindow *>(window)) {
00398 ui->mdiArea->setActiveSubWindow(qobject_cast<QMdiSubWindow *>(window));
00399 }
00400 }
00401
00402 bool MainPage::hasMdiChild() {
00403 bool ret = activeServerEditor() != 0;
00404 return (ret);
00405 }
00406
00407 bool MainPage::hasSQLDump() {
00408 bool ret = activeSqlDump() != 0;
00409 return (ret);
00410 }
00411
00412 bool MainPage::hasTableEditor() {
00413 bool ret = activeTableEditor() != 0;
00414 return (ret);
00415 }
00416
00417 void MainPage::newDatabase() {
00418 CreateDatabase newDb(this);
00419 newDb.setWindowFlags(flags);
00420 if (hasMdiChild()) {
00421 if (newDb.exec()) {
00422
00423 activeServerEditor()->addNewDb(newDb.dbName);
00424 }
00425 }
00426 }
00427
00428 void MainPage::showDbList(QStringList dbList) {
00429 m_CboCurrentDb->clear();
00430 for (int i = 0; i < dbList.length(); i++) {
00431 m_CboCurrentDb->insertItem(i, QIcon("://icons/Icon_45.ico"), dbList.at(i));
00432 }
00433 }
00434
00435 void MainPage::setCurrentDb(QString curDb) {
00436 if (hasMdiChild()) {
00437 QStringList lst = activeServerEditor()->dbList;
00438 for (int i = 0; i < lst.length(); i++) {
00439 if (lst.at(i) == curDb) {
00440 m_CboCurrentDb->setCurrentIndex(i);
00441 return;
00442 }
00443 }
00444 }
00445 }
00446
00447 void MainPage::showPopupMenu(QString tag) {
00448 if (hasMdiChild()) {
00449 QMenu *popMenu;
00450 popMenu = new QMenu(this);
00451 popMenu->addAction(ui->actionConnect_To_Server);
00452 popMenu->addAction(ui->actionClose_Connection);
00453 popMenu->addSeparator();
00454 popMenu->addAction(ui->actionHelp);
00455 popMenu->addAction(ui->actionAbout);
00456 popMenu->addAction(ui->actionAbout_Qt);
00457 if (tag == "db") {
00458 popMenu = ui->menuDb;
00459 } else if (tag == "folTables") {
00460 popMenu = new QMenu(this);
00461 popMenu->addAction(ui->actionCreate_Table);
00462 }else if (tag == "folViews") {
00463 popMenu = new QMenu(this);
00464 popMenu->addAction(ui->actionCreate_View);
00465 }
00466 else if (tag == "folTriggers") {
00467 popMenu = new QMenu(this);
00468 popMenu->addAction(ui->actionCreate_Trigger);
00469 }
00470 else if (tag == "folEvents") {
00471 popMenu = new QMenu(this);
00472 popMenu->addAction(ui->actionCreate_Event);
00473 }
00474 else if (tag == "folFunctions") {
00475 popMenu = new QMenu(this);
00476 popMenu->addAction(ui->actionCreate_Function);
00477 }
00478 else if (tag == "folProcedures") {
00479 popMenu = new QMenu(this);
00480 popMenu->addAction(ui->actionCreate_Stored_Procedure);
00481 }
00482 else if (tag == "chilTable") {
00483 popMenu = ui->menuTable;
00484 }
00485 else if (tag == "chilView") {
00486 popMenu = ui->menuViews;
00487 } else if (tag == "grndCols") {
00488 popMenu = new QMenu(this);
00489 popMenu->addAction(ui->actionAlter_Table);
00490 } else if (tag == "grndIndexes") {
00491 popMenu = new QMenu(this);
00492 popMenu->addAction(ui->actionManage_Indexes);
00493 } else if (tag == "greatGrandCols") {
00494 popMenu = new QMenu(this);
00495 popMenu->addAction(ui->actionAlter_Table);
00496 } else if (tag == "greatGrandIndexes") {
00497 popMenu = new QMenu(this);
00498 popMenu->addAction(ui->actionManage_Indexes);
00499 }
00500 if (popMenu != 0) {
00501 popMenu->popup(QCursor::pos());
00502 }
00503 }
00504 }
00505
00506 void MainPage::openSqlFile() {
00507 if (hasMdiChild()) {
00508 activeServerEditor()->openSQLFile();
00509 }
00510 }
00511
00512 void MainPage::saveSqlFile() {
00513
00514 }
00515
00516 void MainPage::showAbout() {
00517 About ab(this);
00518 ab.exec();
00519 }
00520
00521 void MainPage::newTable() {
00522 if (hasMdiChild()) {
00523 tableEditor *tableToCreate = new tableEditor(this);
00524 tableToCreate->db = activeServerEditor()->db;
00525 tableToCreate->loadDatabaseList(activeServerEditor()->currentDb);
00526 ui->mdiArea->addSubWindow(tableToCreate);
00527 tableToCreate->setWindowTitle(tr("New Table in %1").arg(activeServerEditor()->currentDb));
00528 connect (tableToCreate, SIGNAL(closeMe()), this, SLOT(closeTableEditor()));
00529 tableToCreate->isEditing = false;
00530 tableToCreate->par = ui->mdiArea;
00531 tableToCreate->show();
00532 }
00533 }
00534
00535 void MainPage::editTable() {
00536 if (hasMdiChild()) {
00537 if (activeServerEditor()->currentTable != "") {
00538 tableEditor *tableToEdit = new tableEditor(this);
00539 tableToEdit->db = activeServerEditor()->db;
00540 tableToEdit->startEdit(activeServerEditor()->currentTable, activeServerEditor()->currentDb);
00541 ui->mdiArea->addSubWindow(tableToEdit);
00542 connect (tableToEdit, SIGNAL(closeMe()), this, SLOT(closeTableEditor()));
00543 tableToEdit->par = ui->mdiArea;
00544 tableToEdit->show();
00545 }
00546 }
00547 }
00548
00549 void MainPage::renameTable() {
00550 if (hasMdiChild()) {
00551 if (activeServerEditor()->currentTable != "") {
00552 activeServerEditor()->renameTable();
00553 }
00554 }
00555 }
00556
00557 void MainPage::closeTableEditor() {
00558 ui->mdiArea->closeActiveSubWindow();
00559 }
00560
00561 void MainPage::setTheme(QString theme) {
00562 qApp->setStyle(theme);
00563 }
00564
00565 void MainPage::truncateTable() {
00566 if (hasMdiChild()) {
00567 if (activeServerEditor()->currentTable != "") {
00568 activeServerEditor()->truncateTable();
00569 }
00570 }
00571 }
00572
00573 void MainPage::dropTable() {
00574 if (hasMdiChild()) {
00575 if (activeServerEditor()->currentTable != "") {
00576 activeServerEditor()->dropTable();
00577 }
00578 }
00579 }
00580
00581 void MainPage::aboutQt() {
00582 QMessageBox::aboutQt(this, "About Qt") ;
00583 }
00584
00585 void MainPage::dumpDbAsSQL() {
00586 if (hasMdiChild()) {
00587 SQLDump *dump = new SQLDump(this);
00588 dump->db = activeServerEditor()->db;
00589 dump->dbList = activeServerEditor()->dbList;
00590 dump->dbName = activeServerEditor()->currentDb;
00591 dump->startBackup();
00592 ui->mdiArea->addSubWindow(dump);
00593 connect (dump, SIGNAL(closeWindow()), ui->mdiArea, SLOT(closeActiveSubWindow()));
00594 dump->show();
00595 }
00596 }
00597
00598 void MainPage::dumpTableAsSQL() {
00599 if (hasMdiChild()) {
00600 if (activeServerEditor()->currentTable != "") {
00601 TableBackup tabBack(this);
00602 tabBack.db = activeServerEditor()->db;
00603 tabBack.dbName = activeServerEditor()->currentDb;
00604 tabBack.tableName = activeServerEditor()->currentTable;
00605 tabBack.refresh();
00606 tabBack.exec();
00607 }
00608 }
00609 }
00610
00611 void MainPage::exportTable() {
00612 if (hasMdiChild()) {
00613 if (activeServerEditor()->currentTable != "") {
00614 ExportTable exptab(this);
00615 exptab.db = activeServerEditor()->db;
00616 exptab.dbName = activeServerEditor()->currentDb;
00617 exptab.tableName = activeServerEditor()->currentTable;
00618 exptab.query = tr("SELECT * FROM `%1`.`%2`").arg(exptab.dbName, exptab.tableName);
00619 exptab.showColumns();
00620 exptab.exec();
00621 } else if(activeServerEditor()->currentView != "") {
00622 ExportTable exptab(this);
00623 exptab.db = activeServerEditor()->db;
00624 exptab.dbName = activeServerEditor()->currentDb;
00625 exptab.tableName = activeServerEditor()->currentView;
00626 exptab.query = tr("SELECT * FROM `%1`.`%2`").arg(exptab.dbName, exptab.tableName);
00627 exptab.showColumns();
00628 exptab.exec();
00629 }
00630 }
00631 }
00632
00633 void MainPage::manageIndexes() {
00634 if (hasMdiChild()) {
00635 if (activeServerEditor()->currentTable != "") {
00636 ManageIndexes indices(activeServerEditor());
00637 indices.db = activeServerEditor()->db;
00638 indices.dbName = activeServerEditor()->currentDb;
00639 indices.tableName = activeServerEditor()->currentTable;
00640 indices.refreshIndexes();
00641 if (indices.exec() )
00642 {
00643
00644 }
00645 }
00646 }
00647 }
00648
00649 void MainPage::subCreateView() {
00650 if (hasMdiChild()) {
00651 if (activeServerEditor()->currentDb != "") {
00652 CreateView newView(this);
00653 newView.db = activeServerEditor()->db;
00654 newView.dbName = activeServerEditor()->currentDb;
00655 newView.setDbName();
00656 if (newView.exec()) {
00657 activeServerEditor()->reloadCurrentDb();
00658 }
00659 }
00660 }
00661 }
00662
00663 void MainPage::alterView() {
00664 if (hasMdiChild()) {
00665 if (activeServerEditor()->currentView != "") {
00666 CreateView newView(this);
00667 newView.db = activeServerEditor()->db;
00668 newView.dbName = activeServerEditor()->currentDb;
00669 newView.viewToAlter = activeServerEditor()->currentView;
00670 newView.startAlter();
00671 if (newView.exec()) {
00672 activeServerEditor()->reloadCurrentDb();
00673 }
00674 }
00675 }
00676 }
00677
00678
00679 void MainPage::setWindowMode() {
00680 if (mdi->isChecked()) {
00681 ui->mdiArea->setViewMode(QMdiArea::SubWindowView);
00682 } else {
00683 ui->mdiArea->setViewMode(QMdiArea::TabbedView);
00684 }
00685 }
00686
00687
00688 void MainPage::dropView() {
00689 if (hasMdiChild()) {
00690 if (activeServerEditor()->currentView != "") {
00691 activeServerEditor()->dropView();
00692 }}
00693 }
00694
00695