From 3ac28a7d588a90714ab01dfbce50fe938461fb43 Mon Sep 17 00:00:00 2001 From: Kern Sibbald Date: Tue, 14 Dec 2010 18:18:31 +0100 Subject: [PATCH] Allow closing of all tabs + close tab clicked --- bacula/src/qt-console/mainwin.cpp | 39 ++++++++++++++++------ bacula/src/qt-console/mainwin.h | 3 +- bacula/src/qt-console/pages.cpp | 14 ++++++++ bacula/src/qt-console/pages.h | 1 + bacula/src/qt-console/restore/brestore.cpp | 1 + 5 files changed, 47 insertions(+), 11 deletions(-) diff --git a/bacula/src/qt-console/mainwin.cpp b/bacula/src/qt-console/mainwin.cpp index 5b1593a537..204d9af0b9 100644 --- a/bacula/src/qt-console/mainwin.cpp +++ b/bacula/src/qt-console/mainwin.cpp @@ -265,7 +265,7 @@ void MainWin::connectSignals() connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(treeItemClicked(QTreeWidgetItem *, int))); connect(treeWidget, SIGNAL(currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *))); connect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(stackItemChanged(int))); - connect(tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closePage())); + connect(tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closePage(int))); connect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows())); connect(actionLabel, SIGNAL(triggered()), this, SLOT(labelButtonClicked())); connect(actionRun, SIGNAL(triggered()), this, SLOT(runButtonClicked())); @@ -278,7 +278,7 @@ void MainWin::connectSignals() connect(actionRestore, SIGNAL(triggered()), this, SLOT(restoreButtonClicked())); connect(actionUndock, SIGNAL(triggered()), this, SLOT(undockWindowButton())); connect(actionToggleDock, SIGNAL(triggered()), this, SLOT(toggleDockContextWindow())); - connect(actionClosePage, SIGNAL(triggered()), this, SLOT(closePage())); + connect(actionClosePage, SIGNAL(triggered()), this, SLOT(closeCurrentPage())); connect(actionPreferences, SIGNAL(triggered()), this, SLOT(setPreferences())); connect(actionRepopLists, SIGNAL(triggered()), this, SLOT(repopLists())); connect(actionReloadRepop, SIGNAL(triggered()), this, SLOT(reloadRepopLists())); @@ -293,7 +293,7 @@ void MainWin::disconnectSignals() disconnect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this, SLOT(treeItemClicked(QTreeWidgetItem *, int))); disconnect(treeWidget, SIGNAL( currentItemChanged(QTreeWidgetItem *, QTreeWidgetItem *)), this, SLOT(treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *))); disconnect(tabWidget, SIGNAL(currentChanged(int)), this, SLOT(stackItemChanged(int))); - disconnect(tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closePage())); + disconnect(tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closePage(int))); disconnect(actionQuit, SIGNAL(triggered()), app, SLOT(closeAllWindows())); disconnect(actionLabel, SIGNAL(triggered()), this, SLOT(labelButtonClicked())); disconnect(actionRun, SIGNAL(triggered()), this, SLOT(runButtonClicked())); @@ -306,7 +306,7 @@ void MainWin::disconnectSignals() disconnect(actionRestore, SIGNAL(triggered()), this, SLOT(restoreButtonClicked())); disconnect(actionUndock, SIGNAL(triggered()), this, SLOT(undockWindowButton())); disconnect(actionToggleDock, SIGNAL(triggered()), this, SLOT(toggleDockContextWindow())); - disconnect(actionClosePage, SIGNAL(triggered()), this, SLOT(closePage())); + disconnect(actionClosePage, SIGNAL(triggered()), this, SLOT(closeCurrentPage())); disconnect(actionPreferences, SIGNAL(triggered()), this, SLOT(setPreferences())); disconnect(actionRepopLists, SIGNAL(triggered()), this, SLOT(repopLists())); disconnect(actionReloadRepop, SIGNAL(triggered()), this, SLOT(reloadRepopLists())); @@ -444,13 +444,16 @@ void MainWin::treeItemClicked(QTreeWidgetItem *item, int /*column*/) /* Is this a page that has been inserted into the hash */ if (getFromHash(item)) { Pages* page = getFromHash(item); - int stackindex=tabWidget->indexOf(page); + int stackindex = tabWidget->indexOf(page); if (stackindex >= 0) { tabWidget->setCurrentWidget(page); } + page->dockPage(); /* run the virtual function in case this class overrides it */ page->PgSeltreeWidgetClicked(); + } else { + Dmsg0(000, "Page not in hash"); } } @@ -757,19 +760,35 @@ QTreeWidgetItem* MainWin::getFromHash(Pages *page) return m_widgethash.value(page); } +void MainWin::closeCurrentPage() +{ + closePage(-1); +} + /* * Function to respond to action on page selector context menu to close the * current window. */ -void MainWin::closePage() +void MainWin::closePage(int item) { - QTreeWidgetItem *currentitem = treeWidget->currentItem(); + QTreeWidgetItem *currentitem; + Pages *page; + + if (item >= 0) { + page = (Pages *)tabWidget->widget(item); + } else { + currentitem = treeWidget->currentItem(); + /* Is this a page that has been inserted into the hash */ + if (getFromHash(currentitem)) { + page = getFromHash(currentitem); + } + } - /* Is this a page that has been inserted into the hash */ - if (getFromHash(currentitem)) { - Pages* page = getFromHash(currentitem); + if (page) { if (page->isCloseable()) { page->closeStackPage(); + } else { + page->hidePage(); } } } diff --git a/bacula/src/qt-console/mainwin.h b/bacula/src/qt-console/mainwin.h index addc501e02..b748da0baf 100644 --- a/bacula/src/qt-console/mainwin.h +++ b/bacula/src/qt-console/mainwin.h @@ -124,7 +124,8 @@ public slots: void treeItemChanged(QTreeWidgetItem *, QTreeWidgetItem *); void stackItemChanged(int); void toggleDockContextWindow(); - void closePage(); + void closePage(int item); + void closeCurrentPage(); void setPreferences(); void readPreferences(); void waitEnter(); diff --git a/bacula/src/qt-console/pages.cpp b/bacula/src/qt-console/pages.cpp index e1160a7a2a..096932e2cc 100644 --- a/bacula/src/qt-console/pages.cpp +++ b/bacula/src/qt-console/pages.cpp @@ -176,6 +176,20 @@ bool Pages::isCloseable() return m_closeable; } +void Pages::hidePage() +{ + if (!m_parent || (m_parent->indexOf(this) <= 0)) { + return; + } + /* Remove any tab that may exist */ + m_parent->removeTab(m_parent->indexOf(this)); + hide(); + /* Clear docked flag */ + m_docked = false; + /* The window has been undocked, lets change the context menu */ + setContextMenuDockText(); +} + /* * When a window is closed, this slot is called. The idea is to put it back in the * stack here, and it works. I wanted to get it to the top of the stack so that the diff --git a/bacula/src/qt-console/pages.h b/bacula/src/qt-console/pages.h index a31443d103..ea098546b1 100644 --- a/bacula/src/qt-console/pages.h +++ b/bacula/src/qt-console/pages.h @@ -58,6 +58,7 @@ public: Pages(); void dockPage(); void undockPage(); + void hidePage(); void togglePageDocking(); bool isDocked(); bool isOnceDocked(); diff --git a/bacula/src/qt-console/restore/brestore.cpp b/bacula/src/qt-console/restore/brestore.cpp index 84e5bea4e4..4613f1e617 100644 --- a/bacula/src/qt-console/restore/brestore.cpp +++ b/bacula/src/qt-console/restore/brestore.cpp @@ -47,6 +47,7 @@ bRestore::bRestore() QTreeWidgetItem* thisitem = mainWin->getFromHash(this); thisitem->setIcon(0, QIcon(QString::fromUtf8(":images/browse.png"))); m_populated = false; + m_closeable = false; m_current = NULL; RestoreList->setAcceptDrops(true); } -- 2.39.5